mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some negative sums were failing regarding transfers.
This commit is contained in:
@@ -33,18 +33,24 @@ class Expense
|
|||||||
*/
|
*/
|
||||||
public function addOrCreateExpense(TransactionJournal $entry)
|
public function addOrCreateExpense(TransactionJournal $entry)
|
||||||
{
|
{
|
||||||
|
bcscale(2);
|
||||||
|
|
||||||
$accountId = $entry->account_id;
|
$accountId = $entry->account_id;
|
||||||
|
$amount = strval(round($entry->amount, 2));
|
||||||
|
if (bccomp('0', $amount) === 1) {
|
||||||
|
$amount = bcmul($amount, '-1');
|
||||||
|
}
|
||||||
|
|
||||||
if (!$this->expenses->has($accountId)) {
|
if (!$this->expenses->has($accountId)) {
|
||||||
$newObject = new stdClass;
|
$newObject = new stdClass;
|
||||||
$newObject->amount = strval(round($entry->amount, 2));
|
$newObject->amount = $amount;
|
||||||
$newObject->name = $entry->name;
|
$newObject->name = $entry->name;
|
||||||
$newObject->count = 1;
|
$newObject->count = 1;
|
||||||
$newObject->id = $accountId;
|
$newObject->id = $accountId;
|
||||||
$this->expenses->put($accountId, $newObject);
|
$this->expenses->put($accountId, $newObject);
|
||||||
} else {
|
} else {
|
||||||
bcscale(2);
|
|
||||||
$existing = $this->expenses->get($accountId);
|
$existing = $this->expenses->get($accountId);
|
||||||
$existing->amount = bcadd($existing->amount, $entry->amount);
|
$existing->amount = bcadd($existing->amount, $amount);
|
||||||
$existing->count++;
|
$existing->count++;
|
||||||
$this->expenses->put($accountId, $existing);
|
$this->expenses->put($accountId, $existing);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user