mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 22:21:42 +00:00
Create reconciliation transaction.
This commit is contained in:
@@ -22,6 +22,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\Account;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\User;
|
||||
@@ -222,4 +223,37 @@ trait FindAccountsTrait
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Account|null
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getReconciliation(Account $account): ?Account
|
||||
{
|
||||
if ($account->accountType->type !== AccountType::ASSET) {
|
||||
throw new FireflyException(sprintf('%s is not an asset account.', $account->name));
|
||||
}
|
||||
$name = $account->name . ' reconciliation';
|
||||
$type = AccountType::where('type', AccountType::RECONCILIATION)->first();
|
||||
$accounts = $this->user->accounts()->where('account_type_id', $type->id)->get();
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
if ($account->name === $name) {
|
||||
return $account;
|
||||
}
|
||||
}
|
||||
// assume nothing was found. create it!
|
||||
$data = [
|
||||
'accountType' => 'reconcile',
|
||||
'name' => $name,
|
||||
'iban' => null,
|
||||
'virtualBalance' => null,
|
||||
'active' => true,
|
||||
];
|
||||
$account = $this->storeAccount($data);
|
||||
|
||||
return $account;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user