From d49809c939abe3b11c729742c9e0dabbb6d891b3 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 23 Jul 2022 20:15:55 +0200 Subject: [PATCH 1/3] Fix https://github.com/firefly-iii/firefly-iii/issues/6260 --- app/Http/Controllers/Chart/AccountController.php | 8 ++++---- app/Transformers/TransactionGroupTransformer.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 806b4b8a04..a7f97e8c1d 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -119,8 +119,8 @@ class AccountController extends Controller // see if there is an accompanying start amount. // grab the difference and find the currency. - $startAmount = $startBalances[$accountId][$currencyId] ?? '0'; - $diff = bcsub($endAmount, $startAmount); + $startAmount = (string) ($startBalances[$accountId][$currencyId] ?? '0') + $diff = bcsub((string)$endAmount, $startAmount); $currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->find($currencyId); if (0 !== bccomp($diff, '0')) { // store the values in a temporary array. @@ -578,8 +578,8 @@ class AccountController extends Controller // see if there is an accompanying start amount. // grab the difference and find the currency. - $startAmount = $startBalances[$accountId][$currencyId] ?? '0'; - $diff = bcsub($endAmount, $startAmount); + $startAmount = (string)($startBalances[$accountId][$currencyId] ?? '0'); + $diff = bcsub((string) $endAmount, $startAmount); $currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->find($currencyId); if (0 !== bccomp($diff, '0')) { // store the values in a temporary array. diff --git a/app/Transformers/TransactionGroupTransformer.php b/app/Transformers/TransactionGroupTransformer.php index b60fab159b..70c2814bb6 100644 --- a/app/Transformers/TransactionGroupTransformer.php +++ b/app/Transformers/TransactionGroupTransformer.php @@ -353,7 +353,7 @@ class TransactionGroupTransformer extends AbstractTransformer $destination = $this->getDestinationTransaction($journal); $type = $journal->transactionType->type; $amount = $this->getAmount($type, (string) $source->amount); - $foreignAmount = $this->getForeignAmount($type, $source->foreign_amount); + $foreignAmount = $this->getForeignAmount($type, null === $source->foreign_amount ? null : (string) $source->foreign_amount); $metaFieldData = $this->groupRepos->getMetaFields($journal->id, $this->metaFields); $metaDates = $this->getDates($this->groupRepos->getMetaDateFields($journal->id, $this->metaDateFields)); $currency = $source->transactionCurrency; From d8506c4361ca84729f4184efe56fc43671d12879 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 23 Jul 2022 21:50:16 +0200 Subject: [PATCH 2/3] Fix https://github.com/firefly-iii/firefly-iii/issues/6260 --- app/Http/Controllers/Chart/AccountController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index a7f97e8c1d..dba8f5e4d8 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -119,7 +119,7 @@ class AccountController extends Controller // see if there is an accompanying start amount. // grab the difference and find the currency. - $startAmount = (string) ($startBalances[$accountId][$currencyId] ?? '0') + $startAmount = (string) ($startBalances[$accountId][$currencyId] ?? '0'); $diff = bcsub((string)$endAmount, $startAmount); $currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->find($currencyId); if (0 !== bccomp($diff, '0')) { From 76dadd1cabc9f700241df4c89fc8c7e70939cfe8 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 24 Jul 2022 05:44:35 +0200 Subject: [PATCH 3/3] Fix https://github.com/firefly-iii/firefly-iii/issues/6260 --- app/Models/Bill.php | 25 +++++++++++++++++++++++++ app/Models/BudgetLimit.php | 13 +++++++++++++ app/Models/Transaction.php | 25 +++++++++++++++++++++++++ app/Support/Steam.php | 2 +- 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/app/Models/Bill.php b/app/Models/Bill.php index ecd0cc1d7b..3d76819c94 100644 --- a/app/Models/Bill.php +++ b/app/Models/Bill.php @@ -24,6 +24,7 @@ namespace FireflyIII\Models; use Eloquent; use FireflyIII\User; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -223,4 +224,28 @@ class Bill extends Model { return $this->belongsTo(User::class); } + + /** + * Get the max amount + * + * @return Attribute + */ + protected function amountMax(): Attribute + { + return Attribute::make( + get: fn($value) => (string) $value, + ); + } + + /** + * Get the min amount + * + * @return Attribute + */ + protected function amountMin(): Attribute + { + return Attribute::make( + get: fn($value) => (string) $value, + ); + } } diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php index 2c398d4223..aff5ed5157 100644 --- a/app/Models/BudgetLimit.php +++ b/app/Models/BudgetLimit.php @@ -24,6 +24,7 @@ namespace FireflyIII\Models; use Eloquent; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Support\Carbon; @@ -119,4 +120,16 @@ class BudgetLimit extends Model { return $this->belongsTo(TransactionCurrency::class); } + + /** + * Get the amount + * + * @return Attribute + */ + protected function amount(): Attribute + { + return Attribute::make( + get: fn($value) => (string) $value, + ); + } } diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 58d4d9a6cf..346a521db7 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -25,6 +25,7 @@ namespace FireflyIII\Models; use Carbon\Carbon; use Eloquent; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -256,4 +257,28 @@ class Transaction extends Model { return $this->belongsTo(TransactionJournal::class); } + + /** + * Get the amount + * + * @return Attribute + */ + protected function amount(): Attribute + { + return Attribute::make( + get: fn($value) => (string) $value, + ); + } + + /** + * Get the foreign amount + * + * @return Attribute + */ + protected function foreignAmount(): Attribute + { + return Attribute::make( + get: fn($value) => (string) $value, + ); + } } diff --git a/app/Support/Steam.php b/app/Support/Steam.php index 1f2ebc9777..a74f16a2b9 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -338,7 +338,7 @@ class Steam $return = []; /** @var stdClass $entry */ foreach ($balances as $entry) { - $return[(int) $entry->transaction_currency_id] = $entry->sum_for_currency; + $return[(int) $entry->transaction_currency_id] = (string) $entry->sum_for_currency; } $cache->store($return);