mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-25 21:16:47 +00:00
Final touches for the balance and transactions.
This commit is contained in:
@@ -226,6 +226,24 @@ trait AccountServiceTrait
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete TransactionGroup with liability credit in it.
|
||||
*
|
||||
* @param Account $account
|
||||
*/
|
||||
protected function deleteCreditTransaction(Account $account): void
|
||||
{
|
||||
Log::debug(sprintf('deleteCreditTransaction() for account #%d', $account->id));
|
||||
$creditGroup = $this->getCreditTransaction($account);
|
||||
|
||||
if (null !== $creditGroup) {
|
||||
Log::debug('Credit journal found, delete journal.');
|
||||
/** @var TransactionGroupDestroyService $service */
|
||||
$service = app(TransactionGroupDestroyService::class);
|
||||
$service->destroy($creditGroup);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the opening balance group, or NULL if it does not exist.
|
||||
*
|
||||
|
||||
@@ -306,20 +306,25 @@ class AccountUpdateService
|
||||
*/
|
||||
private function updateCreditLiability(Account $account, array $data): void
|
||||
{
|
||||
$type = $account->accountType;
|
||||
$type = $account->accountType;
|
||||
$valid = config('firefly.valid_liabilities');
|
||||
if (in_array($type->type, $valid, true)) {
|
||||
$direction = array_key_exists('liability_direction', $data) ? $data['liability_direction'] : 'empty';
|
||||
// check if is submitted as empty, that makes it valid:
|
||||
if ($this->validOBData($data) && !$this->isEmptyOBData($data)) {
|
||||
$openingBalance = $data['opening_balance'];
|
||||
$openingBalanceDate = $data['opening_balance_date'];
|
||||
|
||||
$this->updateCreditTransaction($account, $openingBalance, $openingBalanceDate);
|
||||
if ('credit' === $data['liability_direction']) {
|
||||
$this->updateCreditTransaction($account, $openingBalance, $openingBalanceDate);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->validOBData($data) && $this->isEmptyOBData($data)) {
|
||||
$this->deleteCreditTransaction($account);
|
||||
}
|
||||
if ($this->validOBData($data) && !$this->isEmptyOBData($data) && 'credit' !== $direction) {
|
||||
$this->deleteCreditTransaction($account);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user