mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 09:22:33 +00:00
Fix #
This commit is contained in:
@@ -152,8 +152,7 @@ class PiggyBankFactory
|
|||||||
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
|
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
|
||||||
->where('accounts.user_id', $this->user->id)
|
->where('accounts.user_id', $this->user->id)
|
||||||
->where('piggy_banks.id', $piggyBankId)
|
->where('piggy_banks.id', $piggyBankId)
|
||||||
->first(['piggy_banks.*'])
|
->first(['piggy_banks.*']);
|
||||||
;
|
|
||||||
if (null !== $piggyBank) {
|
if (null !== $piggyBank) {
|
||||||
return $piggyBank;
|
return $piggyBank;
|
||||||
}
|
}
|
||||||
@@ -177,8 +176,7 @@ class PiggyBankFactory
|
|||||||
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
|
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
|
||||||
->where('accounts.user_id', $this->user->id)
|
->where('accounts.user_id', $this->user->id)
|
||||||
->where('piggy_banks.name', $name)
|
->where('piggy_banks.name', $name)
|
||||||
->first(['piggy_banks.*'])
|
->first(['piggy_banks.*']);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setOrder(PiggyBank $piggyBank, array $data): PiggyBank
|
private function setOrder(PiggyBank $piggyBank, array $data): PiggyBank
|
||||||
@@ -206,8 +204,7 @@ class PiggyBankFactory
|
|||||||
'objectGroups',
|
'objectGroups',
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
->orderBy('piggy_banks.order', 'ASC')->get(['piggy_banks.*'])
|
->orderBy('piggy_banks.order', 'ASC')->get(['piggy_banks.*']);
|
||||||
;
|
|
||||||
$current = 1;
|
$current = 1;
|
||||||
foreach ($set as $piggyBank) {
|
foreach ($set as $piggyBank) {
|
||||||
if ($piggyBank->order !== $current) {
|
if ($piggyBank->order !== $current) {
|
||||||
@@ -231,6 +228,7 @@ class PiggyBankFactory
|
|||||||
// collect current current_amount so the sync does not remove them.
|
// collect current current_amount so the sync does not remove them.
|
||||||
// TODO this is a tedious check. Feels like a hack.
|
// TODO this is a tedious check. Feels like a hack.
|
||||||
$toBeLinked = [];
|
$toBeLinked = [];
|
||||||
|
$oldSavedAmount = $this->piggyBankRepository->getCurrentAmount($piggyBank);
|
||||||
foreach ($piggyBank->accounts as $account) {
|
foreach ($piggyBank->accounts as $account) {
|
||||||
Log::debug(sprintf('Checking account #%d', $account->id));
|
Log::debug(sprintf('Checking account #%d', $account->id));
|
||||||
foreach ($accounts as $info) {
|
foreach ($accounts as $info) {
|
||||||
@@ -290,7 +288,16 @@ class PiggyBankFactory
|
|||||||
}
|
}
|
||||||
Log::debug(sprintf('Link information: %s', json_encode($toBeLinked)));
|
Log::debug(sprintf('Link information: %s', json_encode($toBeLinked)));
|
||||||
if (0 !== count($toBeLinked)) {
|
if (0 !== count($toBeLinked)) {
|
||||||
|
Log::debug('Syncing accounts to piggy bank.');
|
||||||
$piggyBank->accounts()->sync($toBeLinked);
|
$piggyBank->accounts()->sync($toBeLinked);
|
||||||
|
$piggyBank->refresh();
|
||||||
|
$newSavedAmount = $this->piggyBankRepository->getCurrentAmount($piggyBank);
|
||||||
|
Log::debug(sprintf('Old saved amount: %s, new saved amount is %s', $oldSavedAmount, $newSavedAmount));
|
||||||
|
if (0 !== bccomp($oldSavedAmount, $newSavedAmount)) {
|
||||||
|
Log::debug('Amount changed, will create event for it.');
|
||||||
|
// create event for difference.
|
||||||
|
event(new ChangedAmount($piggyBank, bcsub($newSavedAmount, $oldSavedAmount), null, null));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (0 === count($toBeLinked)) {
|
if (0 === count($toBeLinked)) {
|
||||||
Log::warning('No accounts to link to piggy bank, will not change whatever is there now.');
|
Log::warning('No accounts to link to piggy bank, will not change whatever is there now.');
|
||||||
|
@@ -276,7 +276,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
|
|||||||
$amount = '' === $amount ? '0' : $amount;
|
$amount = '' === $amount ? '0' : $amount;
|
||||||
$sum = bcadd($sum, $amount);
|
$sum = bcadd($sum, $amount);
|
||||||
}
|
}
|
||||||
// Log::debug(sprintf('Current amount in piggy bank #%d ("%s") is %s', $piggyBank->id, $piggyBank->name, $sum));
|
Log::debug(sprintf('Current amount in piggy bank #%d ("%s") is %s', $piggyBank->id, $piggyBank->name, $sum));
|
||||||
|
|
||||||
return $sum;
|
return $sum;
|
||||||
}
|
}
|
||||||
|
@@ -73,8 +73,8 @@ class PiggyBankEventTransformer extends AbstractTransformer
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => (string) $event->id,
|
'id' => (string) $event->id,
|
||||||
'created_at' => $event->created_at->toAtomString(),
|
'created_at' => $event->created_at?->toAtomString(),
|
||||||
'updated_at' => $event->updated_at->toAtomString(),
|
'updated_at' => $event->updated_at?->toAtomString(),
|
||||||
'amount' => app('steam')->bcround($event->amount, $currency->decimal_places),
|
'amount' => app('steam')->bcround($event->amount, $currency->decimal_places),
|
||||||
'currency_id' => (string) $currency->id,
|
'currency_id' => (string) $currency->id,
|
||||||
'currency_code' => $currency->code,
|
'currency_code' => $currency->code,
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
<label for="{{ options.id }}" class="col-sm-4 control-label">{{ label }}</label>
|
<label for="{{ options.id }}" class="col-sm-4 control-label">{{ label }}</label>
|
||||||
|
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
{{ Html.multiselect(name~"[]", list, selected).id(options.id).class('form-control').attribute('autocomplete','off').attribute('spellcheck','false').attribute('placeholder', options.placeholder) }}
|
{{ Html.multiselect(name~"[]", list, selected).id(options.id).attribute('size',12).class('form-control').attribute('autocomplete','off').attribute('spellcheck','false').attribute('placeholder', options.placeholder) }}
|
||||||
{% include 'form.help' %}
|
{% include 'form.help' %}
|
||||||
{% include 'form.feedback' %}
|
{% include 'form.feedback' %}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user