mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
Make sure sorting doesnt break opening balance.
This commit is contained in:
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user