This commit is contained in:
James Cole
2018-10-27 05:10:49 +02:00
parent 749d373c95
commit 970cc91938
3 changed files with 49 additions and 12 deletions

View File

@@ -113,13 +113,41 @@ class ReconcileController extends Controller
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
$amount = bcadd($amount, $transaction->amount);
}
// find the account and opposing account for this transaction
$srcAccount = $this->accountRepos->findNull((int)$transaction->account_id);
$dstAccount = $this->accountRepos->findNull((int)$transaction->opposing_account_id);
$srcCurrency = (int)$this->accountRepos->getMetaValue($srcAccount, 'currency_id');
$dstCurrency = (int)$this->accountRepos->getMetaValue($dstAccount, 'currency_id');
// is $account source or destination?
if ($account->id === $srcAccount->id) {
// source, and it matches the currency id or is 0
if ($srcCurrency === $transaction->transaction_currency_id || 0 === $srcCurrency) {
$amount = bcadd($amount, $transaction->transaction_amount);
}
// destination, and it matches the foreign currency ID.
if ($srcCurrency === $transaction->foreign_currency_id) {
$amount = bcadd($amount, $transaction->transaction_foreign_amount);
}
}
if ($account->id === $dstAccount->id) {
// destination, and it matches the currency id or is 0
if ($dstCurrency === $transaction->transaction_currency_id || 0 === $dstCurrency) {
$amount = bcadd($amount, $transaction->transaction_amount);
}
// destination, and it matches the foreign currency ID.
if ($dstCurrency === $transaction->foreign_currency_id) {
$amount = bcadd($amount, $transaction->transaction_foreign_amount);
}
}
}
// make sure amount is positive.
$amount = app('steam')->positive($amount);
/** @var Transaction $transaction */
foreach ($cleared as $transaction) {
if ($transaction->transactionJournal->date <= $end) {
$clearedAmount = bcadd($clearedAmount, $transaction->amount); // @codeCoverageIgnore
if ($transaction->date <= $end) {
$clearedAmount = bcadd($clearedAmount, $transaction->transaction_amount); // @codeCoverageIgnore
++$countCleared;
}
}
@@ -201,6 +229,7 @@ class ReconcileController extends Controller
Log::debug(sprintf('Could not render: %s', $e->getMessage()));
$html = 'Could not render accounts.reconcile.transactions';
}
// @codeCoverageIgnoreEnd
return response()->json(['html' => $html, 'startBalance' => $startBalance, 'endBalance' => $endBalance]);