Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions modules/SystemPayment/Entities/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,14 @@ class Payment extends \Unusualify\Payable\Models\Payment

protected static function booted(): void
{
static::addGlobalScope('price_currency_iso_4217', function (Builder $builder) {
$pricesTable = (new Price)->getTable();
static::addGlobalScope('currency_iso_4217', function (Builder $builder) {
$currenciesTable = (new Currency)->getTable();
$paymentTable = (new static)->getTable();

$builder->addSelect([
'price_currency_iso_4217' => Currency::query()
'currency_iso_4217' => Currency::query()
->select($currenciesTable . '.iso_4217')
->join($pricesTable, $pricesTable . '.currency_id', '=', $currenciesTable . '.id')
->whereColumn($pricesTable . '.id', $paymentTable . '.price_id')
->whereColumn($currenciesTable . '.id', $paymentTable . '.currency_id')
->limit(1),
]);
});
Expand Down Expand Up @@ -168,7 +166,7 @@ protected function amountFormatted(): Attribute
{
return Attribute::make(
get: function () {
return PriceService::formatAmount($this->amount, new \Money\Currency($this->price_currency_iso_4217 ?? $this->currency->iso_4217));
return PriceService::formatAmount($this->amount, new \Money\Currency($this->currency_iso_4217 ?? $this->currency->iso_4217));
},
);
}
Expand Down
Loading