Make sure sorting doesnt break opening balance.

This commit is contained in:
James Cole
2020-07-26 15:05:48 +02:00
parent c86673f3ec
commit fdea25051c
11 changed files with 162 additions and 9 deletions

View File

@@ -162,6 +162,27 @@ trait AccountServiceTrait
return false;
}
/**
* Returns true if the data in the array is submitted but empty.
*
* @param array $data
*
* @return bool
*/
public function isEmptyOBData(array $data): bool
{
if (!isset($data['opening_balance']) && !isset($data['opening_balance_date'])) {
// not set, so false.
return false;
}
// if isset, but is empty:
if ('' === $data['opening_balance'] && '' === $data['opening_balance_date']) {
return true;
}
return false;
}
/**
* @param Account $account
* @param array $data

View File

@@ -115,12 +115,14 @@ class AccountUpdateService
// if it can have a virtual balance, it can also have an opening balance.
if (in_array($type->type, $this->canHaveVirtual, true)) {
// check if is submitted as empty, that makes it valid:
if ($this->validOBData($data)) {
if ($this->validOBData($data) && !$this->isEmptyOBData($data)) {
$this->updateOBGroup($account, $data);
}
if (!$this->validOBData($data)) {
if (!$this->validOBData($data) && $this->isEmptyOBData($data)) {
$this->deleteOBGroup($account);
}
}