diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.php index 37746ccdde..fb38bcedb1 100644 --- a/app/Http/Controllers/Account/ReconcileController.php +++ b/app/Http/Controllers/Account/ReconcileController.php @@ -27,7 +27,9 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; +use FireflyIII\Models\Transaction; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; +use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Http\Request; use Illuminate\Support\Collection; use Navigation; @@ -68,16 +70,38 @@ class ReconcileController extends Controller */ public function overview(Request $request, Account $account, Carbon $start, Carbon $end) { - $startBalance = $request->get('startBalance'); - $endBalance = $request->get('endBalance'); - $transactions = $request->get('transactions'); + $startBalance = $request->get('startBalance'); + $endBalance = $request->get('endBalance'); + $transactionIds = $request->get('transactions') ?? []; + $clearedIds = $request->get('cleared') ?? []; + $amount = '0'; + $clearedAmount = '0'; + $route = route('accounts.reconcile.submit', [$account->id, $start->format('Ymd'), $end->format('Ymd')]); + // get sum of transaction amounts: + /** @var JournalRepositoryInterface $repository */ + $repository = app(JournalRepositoryInterface::class); + $transactions = $repository->getTransactionsById($transactionIds); + $cleared = $repository->getTransactionsById($clearedIds); + + /** @var Transaction $transaction */ + foreach ($transactions as $transaction) { + $amount = bcadd($amount, $transaction->amount); + } + + /** @var Transaction $transaction */ + foreach ($cleared as $transaction) { + $clearedAmount = bcadd($clearedAmount, $transaction->amount); + } $return = [ 'is_zero' => false, - 'post_uri' => route('accounts.reconcile.submit', [$account->id, $start->format('Ymd'), $end->format('Ymd')]), + 'post_uri' => $route, 'html' => '', ]; - $return['html'] = view('accounts.reconcile.overview', compact('account', 'start', 'end'))->render(); + $return['html'] = view( + 'accounts.reconcile.overview', + compact('account', 'start', 'end', 'clearedIds', 'transactionIds', 'clearedAmount', 'startBalance', 'endBalance', 'amount', 'route') + )->render(); return Response::json($return); } @@ -175,4 +199,13 @@ class ReconcileController extends Controller return Response::json(['html' => $html]); } + + /** + * @param Account $account + * @param Carbon $start + * @param Carbon $end + */ + public function submit(Request $request, Account $account, Carbon $start, Carbon $end) { + var_dump($request->all()); + } } diff --git a/app/Import/Converter/Amount.php b/app/Import/Converter/Amount.php index 8bf70ba9dd..4791c4e3c3 100644 --- a/app/Import/Converter/Amount.php +++ b/app/Import/Converter/Amount.php @@ -88,7 +88,7 @@ class Amount implements ConverterInterface Log::debug(sprintf('No decimal character found. Converted amount from "%s" to "%s".', $oldValue, $value)); } - $number = strval(number_format(round(floatval($value), 12), 12)); + $number = strval(number_format(round(floatval($value), 12), 12,'','')); return $number; } } diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index c1b3fee1cc..57700ad52d 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -177,6 +177,23 @@ class JournalRepository implements JournalRepositoryInterface return TransactionType::orderBy('type', 'ASC')->get(); } + /** + * @param array $transactionIds + * + * @return Collection + */ + public function getTransactionsById(array $transactionIds): Collection + { + $set = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') + ->whereIn('transactions.id', $transactionIds) + ->where('transaction_journals.user_id', $this->user->id) + ->whereNull('transaction_journals.deleted_at') + ->whereNull('transactions.deleted_at') + ->get( ['transactions.*']); + + return $set; + } + /** * @param TransactionJournal $journal * diff --git a/app/Repositories/Journal/JournalRepositoryInterface.php b/app/Repositories/Journal/JournalRepositoryInterface.php index 34efa0a649..694683e2f0 100644 --- a/app/Repositories/Journal/JournalRepositoryInterface.php +++ b/app/Repositories/Journal/JournalRepositoryInterface.php @@ -35,6 +35,15 @@ use Illuminate\Support\MessageBag; */ interface JournalRepositoryInterface { + + /** + * @param array $transactionIds + * + * @return Collection + */ + public function getTransactionsById(array $transactionIds): Collection; + + /** * @param TransactionJournal $journal * @param TransactionType $type diff --git a/public/js/ff/accounts/reconcile.js b/public/js/ff/accounts/reconcile.js index 8611b24f74..c2d7ce3843 100644 --- a/public/js/ff/accounts/reconcile.js +++ b/public/js/ff/accounts/reconcile.js @@ -68,12 +68,19 @@ function storeReconcile() { $.each($('.reconcile_checkbox:checked'), function (i, v) { ids.push($(v).data('id')); }); + var cleared = []; + $.each($('input[class="cleared"]'), function (i, v) { + var obj = $(v); + cleared.push(obj.data('id')); + }); + var variables = { startBalance: parseFloat($('input[name="start_balance"]').val()), endBalance: parseFloat($('input[name="end_balance"]').val()), startDate: $('input[name="start_date"]').val(), startEnd: $('input[name="end_date"]').val(), - transactions: ids + transactions: ids, + cleared: cleared, }; var uri = overviewUri.replace('%start%', $('input[name="start_date"]').val()).replace('%end%', $('input[name="end_date"]').val()); @@ -126,11 +133,15 @@ function calculateBalanceDifference() { var startBalance = parseFloat($('input[name="start_balance"]').val()); var endBalance = parseFloat($('input[name="end_balance"]').val()); balanceDifference = startBalance - endBalance; - if (balanceDifference < 0) { - balanceDifference = balanceDifference * -1; - } + //if (balanceDifference < 0) { + // balanceDifference = balanceDifference * -1; + //} } +/** + * Grab all transactions, update the URL and place the set of transactions in the box. + * This more or less resets the reconciliation. + */ function getTransactionsForRange() { // clear out the box: $('#transactions_holder').empty().append($('
').addClass('text-center').html('')); @@ -141,12 +152,31 @@ function getTransactionsForRange() { $.getJSON(uri).done(placeTransactions); } +/** + * Loop over all transactions that have already been cleared and add this to the selectedAmount. + * + */ +function includeClearedTransactions() { + $.each($('input[class="cleared"]'), function (i, v) { + var obj = $(v); + selectedAmount = selectedAmount - parseFloat(obj.val()); + }); +} + +/** + * Place the HTML for the transactions within the date range and update the balance difference. + * @param data + */ function placeTransactions(data) { $('#transactions_holder').empty().html(data.html); // as long as the dates are equal, changing the balance does not matter. calculateBalanceDifference(); + + // any already cleared transactions must be added to / removed from selectedAmount. + includeClearedTransactions(); + difference = balanceDifference; updateDifference(); diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 16a7b72be2..992cb1d2f9 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -647,6 +647,18 @@ return [ 'select_more_than_one_budget' => 'Please select more than one budget', 'select_more_than_one_tag' => 'Please select more than one tag', 'account_default_currency' => 'If you select another currency, new transactions from this account will have this currency pre-selected.', + 'reconcile_has_more' => 'Your Firefly III ledger has more money in it than your bank claims you should have. There are several options. Please choose what to do. Then, press "Confirm reconciliation".', + 'reconcile_has_less' => 'Your Firefly III ledger has less money in it than your bank claims you should have. There are several options. Please choose what to do. Then, press "Confirm reconciliation".', + 'reconcile_is_equal' => 'Your Firefly III ledger and your bank statements match. There is nothing to do. Please press "Confirm reconciliation" to confirm your input.', + 'create_pos_reconcile_transaction' => 'Clear the selected transactions, and create a correction adding :amount to this asset account.', + 'create_neg_reconcile_transaction' => 'Clear the selected transactions, and create a correction removing :amount from this asset account.', + 'reconcile_do_nothing' => 'Clear the selected transactions, but do not correct.', + 'reconcile_go_back' => 'You can always edit or delete a correction later.', + 'confirm_reconciliation' => 'Confirm reconciliation', + 'submitted_start_balance' => 'Submitted start balance', + 'selected_transactions' => 'Selected transactions (:count)', + 'already_cleared_transactions' => 'Already cleared transactions (:count)', + 'submitted_end_balance' => 'Submitted end balance', // categories: 'new_category' => 'New category', diff --git a/resources/views/accounts/reconcile/index.twig b/resources/views/accounts/reconcile/index.twig index a5aade3415..70b82ee4b2 100644 --- a/resources/views/accounts/reconcile/index.twig +++ b/resources/views/accounts/reconcile/index.twig @@ -7,7 +7,7 @@ {% block content %}
{{ 'difference'|_ }} | -{{ 'actions'|_ }} | -
---|---|
- - | -
-
-
-
- |
-