Refactor some code for recurrences.

This commit is contained in:
James Cole
2019-06-08 06:19:21 +02:00
parent 7c2c24d330
commit 85f9c256a1
21 changed files with 369 additions and 468 deletions

View File

@@ -112,7 +112,7 @@ class AccountFactory
$data['currency_id'] = $currency->id;
// remove virtual balance when not an asset account or a liability
$canHaveVirtual = [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD];
if (!\in_array($type->type, $canHaveVirtual, true)) {
if (!in_array($type->type, $canHaveVirtual, true)) {
$databaseData['virtual_balance'] = '0';
}
@@ -124,7 +124,7 @@ class AccountFactory
$return = Account::create($databaseData);
$this->updateMetaData($return, $data);
if (\in_array($type->type, $canHaveVirtual, true)) {
if (in_array($type->type, $canHaveVirtual, true)) {
if ($this->validIBData($data)) {
$this->updateIB($return, $data);
}

View File

@@ -93,7 +93,7 @@ class BillFactory
}
/**
* @param int|null $billId
* @param int|null $billId
* @param null|string $billName
*
* @return Bill|null
@@ -126,8 +126,10 @@ class BillFactory
public function findByName(string $name): ?Bill
{
$query = sprintf('%%%s%%', $name);
/** @var Bill $first */
$first = $this->user->bills()->where('name', 'LIKE', $query)->first();
return $this->user->bills()->where('name', 'LIKE', $query)->first();
return $first;
}
/**

View File

@@ -246,6 +246,10 @@ class TransactionJournalFactory
$destinationAccount = $this->getAccount($type->type, 'destination', (int)$row['destination_id'], $row['destination_name']);
/** double check currencies. */
$sourceCurrency = $currency;
$destCurrency = $currency;
$sourceForeignCurrency = $foreignCurrency;
$destForeignCurrency = $foreignCurrency;
if ($type->type === 'Withdrawal') {
// make sure currency is correct.