Skip to content

Commit

Permalink
Merge pull request #95 from bildvitta/feature/documents
Browse files Browse the repository at this point in the history
Adicionando timezone nos preços das unidades
  • Loading branch information
zerossB authored Oct 30, 2024
2 parents 22030fd + 4e20ebd commit 9c01550
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/Models/RealEstateDevelopment/Unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,35 +150,27 @@ public function prices(): HasMany
public function tablePrice(): Attribute
{
return Attribute::get(function () {
$period = date('Y-m-01');
$query = $this->prices()->where('period', $period);
$period = now('America/Sao_Paulo')->format('Y-m-01');
$price = $this->prices()->where('period', $period)->value('table_price');

if ($query->exists()) {
return $query->first()->table_price;
}

return '0.00';
return $price ?? '0.00';
});
}

public function fixedPrice(): Attribute
{
return Attribute::get(function () {
$period = date('Y-m-01');
$query = $this->prices()->where('period', $period);

if ($query->exists()) {
return $query->first()->fixed_price;
}
$period = now('America/Sao_Paulo')->format('Y-m-01');
$price = $this->prices()->where('period', $period)->value('fixed_price');

return '0.00';
return $price ?? '0.00';
});
}

public function hasPriceTablePeriod(): Attribute
{
return Attribute::get(function () {
$period = date('Y-m-01');
$period = now('America/Sao_Paulo')->format('Y-m-01');

return $this->prices()->where('period', $period)->exists();
});
Expand Down

0 comments on commit 9c01550

Please sign in to comment.