mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Fix #1369
This commit is contained in:
@@ -104,6 +104,22 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
return bccomp($amount, $savedSoFar) <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Correct order of piggies in case of issues.
|
||||
*/
|
||||
public function correctOrder(): void
|
||||
{
|
||||
$set = $this->user->piggyBanks()->orderBy('order', 'ASC')->get();
|
||||
$current = 1;
|
||||
foreach ($set as $piggyBank) {
|
||||
if ((int)$piggyBank->order !== $current) {
|
||||
$piggyBank->order = $current;
|
||||
$piggyBank->save();
|
||||
}
|
||||
$current++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
@@ -327,7 +343,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
/** @var PiggyBank $current */
|
||||
foreach ($piggies as $current) {
|
||||
$repetition = $this->getRepetition($current);
|
||||
if(null !== $repetition) {
|
||||
if (null !== $repetition) {
|
||||
$balance = bcsub($balance, $repetition->currentamount);
|
||||
}
|
||||
}
|
||||
@@ -379,14 +395,10 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setOrder(int $piggyBankId, int $order): bool
|
||||
public function setOrder(PiggyBank $piggyBank, int $order): bool
|
||||
{
|
||||
$piggyBank = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', $this->user->id)
|
||||
->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);
|
||||
if ($piggyBank) {
|
||||
$piggyBank->order = $order;
|
||||
$piggyBank->save();
|
||||
}
|
||||
$piggyBank->order = $order;
|
||||
$piggyBank->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user