diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.php index f615d61c92..9e662ae441 100644 --- a/app/Http/Controllers/Account/ReconcileController.php +++ b/app/Http/Controllers/Account/ReconcileController.php @@ -89,15 +89,21 @@ class ReconcileController extends Controller $repository = app(JournalRepositoryInterface::class); $transactions = $repository->getTransactionsById($transactionIds); $cleared = $repository->getTransactionsById($clearedIds); + $countCleared = 0; /** @var Transaction $transaction */ foreach ($transactions as $transaction) { + // {% if transaction.date > end %} + $amount = bcadd($amount, $transaction->amount); } /** @var Transaction $transaction */ foreach ($cleared as $transaction) { - $clearedAmount = bcadd($clearedAmount, $transaction->amount); + if ($transaction->transactionJournal->date <= $end) { + $clearedAmount = bcadd($clearedAmount, $transaction->amount); + $countCleared++; + } } // final difference: @@ -114,7 +120,7 @@ class ReconcileController extends Controller 'accounts.reconcile.overview', compact( 'account', 'start', 'diffCompare', 'difference', 'end', 'clearedIds', 'transactionIds', 'clearedAmount', 'startBalance', 'endBalance', 'amount', - 'route' + 'route','countCleared' ) )->render(); @@ -221,14 +227,19 @@ class ReconcileController extends Controller 'budget_id' => 0, 'amount' => $difference, 'currency_id' => $account->getMeta('currency_id'), - 'description' => 'Reconciliation [period]', + 'description' => trans( + 'firefly.reconcilliation_transaction_title', + ['from' => $start->formatLocalized($this->monthAndDayFormat), 'to' => $end->formatLocalized($this->monthAndDayFormat)] + ), 'date' => $request->get('end'), + 'notes' => join(',', $transactions->pluck('id')->toArray()), ]; $journal = $repository->store($data); // reconcile this transaction too: $transaction = $journal->transactions()->first(); $repository->reconcile($transaction); } + Session::flash('success', trans('firefly.reconciliation_stored')); return redirect(route('accounts.show', [$account->id])); diff --git a/app/Support/Twig/Extension/Transaction.php b/app/Support/Twig/Extension/Transaction.php index bb2e9d6365..d93b22026d 100644 --- a/app/Support/Twig/Extension/Transaction.php +++ b/app/Support/Twig/Extension/Transaction.php @@ -57,6 +57,11 @@ class Transaction extends Twig_Extension $format = '%s'; $coloured = true; + // at this point amount is always negative. + if ($transaction->transaction_type_type === TransactionType::RECONCILIATION && bccomp(strval($transaction->transaction_amount),'0') === 1) { + $amount = bcmul($amount, '-1'); + } + if (TransactionType::DEPOSIT === $transaction->transaction_type_type) { $amount = bcmul($amount, '-1'); } @@ -285,6 +290,10 @@ class Transaction extends Twig_Extension return $cache->get(); } + if($transaction->transaction_type_type === TransactionType::RECONCILIATION) { + return '—'; + } + $name = app('steam')->tryDecrypt($transaction->account_name); $transactionId = intval($transaction->account_id); $type = $transaction->account_type; @@ -387,6 +396,9 @@ class Transaction extends Twig_Extension case TransactionType::OPENING_BALANCE: $txt = sprintf('', trans('firefly.openingBalance')); break; + case TransactionType::RECONCILIATION: + $txt = sprintf('', trans('firefly.reconciliation_transaction')); + break; default: $txt = ''; break; @@ -464,6 +476,9 @@ class Transaction extends Twig_Extension if ($cache->has()) { return $cache->get(); } + if($transaction->transaction_type_type === TransactionType::RECONCILIATION) { + return '—'; + } // if the amount is negative, assume that the current account (the one in $transaction) is indeed the source account. $name = app('steam')->tryDecrypt($transaction->account_name); diff --git a/public/js/ff/accounts/reconcile.js b/public/js/ff/accounts/reconcile.js index c2d7ce3843..9a29ab036e 100644 --- a/public/js/ff/accounts/reconcile.js +++ b/public/js/ff/accounts/reconcile.js @@ -134,7 +134,7 @@ function calculateBalanceDifference() { var endBalance = parseFloat($('input[name="end_balance"]').val()); balanceDifference = startBalance - endBalance; //if (balanceDifference < 0) { - // balanceDifference = balanceDifference * -1; + // balanceDifference = balanceDifference * -1; //} } @@ -153,13 +153,15 @@ function getTransactionsForRange() { } /** - * Loop over all transactions that have already been cleared and add this to the selectedAmount. + * Loop over all transactions that have already been cleared (in the range) and add this to the selectedAmount. * */ function includeClearedTransactions() { $.each($('input[class="cleared"]'), function (i, v) { var obj = $(v); - selectedAmount = selectedAmount - parseFloat(obj.val()); + if (obj.data('younger') === false) { + selectedAmount = selectedAmount - parseFloat(obj.val()); + } }); } diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index e23103c1f3..bd5bda1caf 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -631,6 +631,8 @@ return [ 'date_change_instruction' => 'If you change the date range now, any progress will be lost.', 'update_selection' => 'Update selection', 'store_reconcile' => 'Store reconciliation', + 'reconciliation_transaction' => 'Reconciliation transaction', + 'Reconciliation' => 'Reconciliation', 'reconcile_options' => 'Reconciliation options', 'reconcile_range' => 'Reconciliation range', 'start_reconcile' => 'Start reconciling', @@ -656,6 +658,7 @@ return [ 'reconcile_go_back' => 'You can always edit or delete a correction later.', 'must_be_asset_account' => 'You can only reconcile asset accounts', 'reconciliation_stored' => 'Reconciliation stored', + 'reconcilliation_transaction_title' => 'Reconciliation (:from to :to)', 'reconcile_this_account' => 'Reconcile this account', 'confirm_reconciliation' => 'Confirm reconciliation', 'submitted_start_balance' => 'Submitted start balance', diff --git a/resources/views/accounts/reconcile/overview.twig b/resources/views/accounts/reconcile/overview.twig index b8b33e0cb0..abc2fe9af3 100644 --- a/resources/views/accounts/reconcile/overview.twig +++ b/resources/views/accounts/reconcile/overview.twig @@ -28,7 +28,7 @@