James Cole
2021-11-26 06:16:21 +01:00
parent 35bc92bb49
commit b85b32560c
3 changed files with 4 additions and 2 deletions

View File

@@ -122,7 +122,7 @@ class EditController extends Controller
} }
$request->session()->forget('accounts.edit.fromUpdate'); $request->session()->forget('accounts.edit.fromUpdate');
$openingBalanceAmount = app('steam')->positive((string)$repository->getOpeningBalanceAmount($account)); $openingBalanceAmount = (string)$repository->getOpeningBalanceAmount($account);
if ('0' === $openingBalanceAmount) { if ('0' === $openingBalanceAmount) {
$openingBalanceAmount = ''; $openingBalanceAmount = '';
} }

View File

@@ -530,6 +530,7 @@ trait AccountServiceTrait
if (null === $obGroup) { if (null === $obGroup) {
return $this->createOBGroupV2($account, $openingBalance, $openingBalanceDate); return $this->createOBGroupV2($account, $openingBalance, $openingBalanceDate);
} }
Log::debug('Update OB group');
// if exists, update: // if exists, update:
$currency = $this->accountRepository->getAccountCurrency($account); $currency = $this->accountRepository->getAccountCurrency($account);
@@ -547,6 +548,7 @@ trait AccountServiceTrait
// if amount is negative: // if amount is negative:
if (1 === bccomp('0', $openingBalance)) { if (1 === bccomp('0', $openingBalance)) {
Log::debug('Amount is negative.');
// account transaction loses money: // account transaction loses money:
$accountTransaction->amount = app('steam')->negative($openingBalance); $accountTransaction->amount = app('steam')->negative($openingBalance);
$accountTransaction->transaction_currency_id = $currency->id; $accountTransaction->transaction_currency_id = $currency->id;
@@ -556,6 +558,7 @@ trait AccountServiceTrait
$obTransaction->transaction_currency_id = $currency->id; $obTransaction->transaction_currency_id = $currency->id;
} }
if (-1 === bccomp('0', $openingBalance)) { if (-1 === bccomp('0', $openingBalance)) {
Log::debug('Amount is positive.');
// account gains money: // account gains money:
$accountTransaction->amount = app('steam')->positive($openingBalance); $accountTransaction->amount = app('steam')->positive($openingBalance);
$accountTransaction->transaction_currency_id = $currency->id; $accountTransaction->transaction_currency_id = $currency->id;

View File

@@ -292,7 +292,6 @@ class AccountUpdateService
*/ */
private function updateOpeningBalance(Account $account, array $data): void private function updateOpeningBalance(Account $account, array $data): void
{ {
// has valid initial balance (IB) data? // has valid initial balance (IB) data?
$type = $account->accountType; $type = $account->accountType;
if (in_array($type->type, $this->canHaveOpeningBalance, true)) { if (in_array($type->type, $this->canHaveOpeningBalance, true)) {