Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix reconciliation.
James Cole940a730827c0
diff --git a/app/Handlers/Events/StoredGroupEventHandler.php b/app/Handlers/Events/StoredGroupEventHandler.phpindex 4d800904c2..7faa916c3a 100644--- a/app/Handlers/Events/StoredGroupEventHandler.php+++ b/app/Handlers/Events/StoredGroupEventHandler.php@@ -25,6 +25,7 @@ namespace FireflyIII\Handlers\Events;use FireflyIII\Events\StoredTransactionGroup;use FireflyIII\Models\TransactionJournal;use FireflyIII\TransactionRules\Engine\RuleEngine;+use Log;/*** Class StoredGroupEventHandler@@ -41,6 +42,7 @@ class StoredGroupEventHandlerif (false === $storedJournalEvent->applyRules) {return;}+ Log::debug('Now in StoredGroupEventHandler::processRules()');/** @var RuleEngine $ruleEngine */$ruleEngine = app(RuleEngine::class);diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.phpindex 69bd4f07f3..2ab0f03d16 100644--- a/app/Http/Controllers/Account/ReconcileController.php+++ b/app/Http/Controllers/Account/ReconcileController.php@@ -24,15 +24,12 @@ declare(strict_types=1);namespace FireflyIII\Http\Controllers\Account;use Carbon\Carbon;-use FireflyIII\Exceptions\FireflyException;+use Exception;use FireflyIII\Http\Controllers\Controller;use FireflyIII\Http\Requests\ReconciliationStoreRequest;-use FireflyIII\Http\Requests\ReconciliationUpdateRequest;use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;use FireflyIII\Models\Transaction;-use FireflyIII\Models\TransactionJournal;-use FireflyIII\Models\TransactionType;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;use FireflyIII\Repositories\Journal\JournalRepositoryInterface;@@ -41,8 +38,6 @@ use Log;/*** Class ReconcileController.- *- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)*/class ReconcileController extends Controller{@@ -56,6 +51,7 @@ class ReconcileController extends Controller/*** ReconcileController constructor.+ * @codeCoverageIgnore*/public function __construct(){@@ -75,54 +71,15 @@ class ReconcileController extends Controller);}- /**- * Edit a reconciliation.- *- * @param TransactionJournal $journal- *- * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector- */- public function edit(TransactionJournal $journal)- {- if (TransactionType::RECONCILIATION !== $journal->transactionType->type) {- return redirect(route('transactions.edit', [$journal->id]));- }- // view related code- $subTitle = (string)trans('breadcrumbs.edit_journal', ['description' => $journal->description]);-- // journal related code- $pTransaction = $this->repository->getFirstPosTransaction($journal);- $preFilled = [- 'date' => $this->repository->getJournalDate($journal, null),- 'category' => $this->repository->getJournalCategoryName($journal),- 'tags' => implode(',', $journal->tags->pluck('tag')->toArray()),- 'amount' => $pTransaction->amount,- ];-- session()->flash('preFilled', $preFilled);-- // put previous url in session if not redirect from store (not "return_to_edit").- if (true !== session('reconcile.edit.fromUpdate')) {- $this->rememberPreviousUri('reconcile.edit.uri');- }- session()->forget('reconcile.edit.fromUpdate');-- return view(- 'accounts.reconcile.edit',- compact('journal', 'subTitle')- )->with('data', $preFilled);- }-/*** Reconciliation overview.*- * @param Account $account+ * @param Account $account* @param Carbon|null $start* @param Carbon|null $end** @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View- * @SuppressWarnings(PHPMD.CyclomaticComplexity)- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)+ * @throws Exception*/public function reconcile(Account $account, Carbon $start = null, Carbon $end = null){@@ -132,13 +89,9 @@ class ReconcileController extends Controllerif (AccountType::ASSET !== $account->accountType->type) {session()->flash('error', (string)trans('firefly.must_be_asset_account'));- return redirect(route('accounts.index', [config('firefly.shortNamesByFullName.' . $account->accountType->type)]));- }- $currencyId = (int)$this->accountRepos->getMetaValue($account, 'currency_id');- $currency = $this->currencyRepos->findNull($currencyId);- if (null === $currency) {- $currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore+ return redirect(route('accounts.index', [config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type))]));}+ $currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();// no start or end:$range = app('preferences')->get('viewRange', '1M')->data;@@ -156,65 +109,33 @@ class ReconcileController extends Controller}$startDate = clone $start;- $startDate->subDays(1);+ $startDate->subDay();$startBalance = round(app('steam')->balance($account, $startDate), $currency->decimal_places);$endBalance = round(app('steam')->balance($account, $end), $currency->decimal_places);- $subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);+ $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));$subTitle = (string)trans('firefly.reconcile_account', ['account' => $account->name]);// various links$transactionsUri = route('accounts.reconcile.transactions', [$account->id, '%start%', '%end%']);$overviewUri = route('accounts.reconcile.overview', [$account->id, '%start%', '%end%']);$indexUri = route('accounts.reconcile', [$account->id, '%start%', '%end%']);+ $objectType = 'asset';- return view(- 'accounts.reconcile.index', compact(- 'account', 'currency', 'subTitleIcon', 'start', 'end', 'subTitle', 'startBalance', 'endBalance', 'transactionsUri',- 'overviewUri', 'indexUri'- )- );+ return view('accounts.reconcile.index',+ compact('account', 'currency', 'objectType',+ 'subTitleIcon', 'start', 'end', 'subTitle', 'startBalance', 'endBalance',+ 'transactionsUri', 'overviewUri', 'indexUri'));}- /**- * Show a single reconciliation.- *- * @param TransactionJournal $journal- *- * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View- * @throws FireflyException- */- public function show(TransactionJournal $journal)- {-- if (TransactionType::RECONCILIATION !== $journal->transactionType->type) {- return redirect(route('transactions.show', [$journal->id]));- }- $subTitle = trans('firefly.reconciliation') . ' "' . $journal->description . '"';-- // get main transaction:- $transaction = $this->repository->getAssetTransaction($journal);- if (null === $transaction) {- throw new FireflyException('The transaction data is incomplete. This is probably a bug. Apologies.');- }- $account = $transaction->account;-- return view('accounts.reconcile.show', compact('journal', 'subTitle', 'transaction', 'account'));- }-- /** @noinspection MoreThanThreeArgumentsInspection *//*** Submit a new reconciliation.** @param ReconciliationStoreRequest $request- * @param Account $account- * @param Carbon $start- * @param Carbon $end+ * @param Account $account+ * @param Carbon $start+ * @param Carbon $end** @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector- * @throws FireflyException- *- * @SuppressWarnings(PHPMD.CyclomaticComplexity)- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/public function submit(ReconciliationStoreRequest $request, Account $account, Carbon $start, Carbon $end){@@ -287,88 +208,4 @@ class ReconcileController extends Controllerreturn redirect(route('accounts.show', [$account->id]));}--- /**- * Update a reconciliation.- *- * @param ReconciliationUpdateRequest $request- * @param TransactionJournal $journal- *- * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector- *- * @SuppressWarnings(PHPMD.CyclomaticComplexity)- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)- */- public function update(ReconciliationUpdateRequest $request, TransactionJournal $journal)- {- if (TransactionType::RECONCILIATION !== $journal->transactionType->type) {- return redirect(route('transactions.show', [$journal->id]));- }- if (0 === bccomp('0', $request->get('amount'))) {- session()->flash('error', (string)trans('firefly.amount_cannot_be_zero'));-- return redirect(route('accounts.reconcile.edit', [$journal->id]))->withInput();- }- // update journal using account repository. Keep it consistent.- $submitted = $request->getJournalData();-- // amount pos neg influences the accounts:- $source = $this->repository->getJournalSourceAccounts($journal)->first();- $destination = $this->repository->getJournalDestinationAccounts($journal)->first();- if (1 === bccomp($submitted['amount'], '0')) {- // amount is positive, switch accounts:- [$source, $destination] = [$destination, $source];-- }- // expand data with journal data:- $data = [- 'type' => $journal->transactionType->type,- 'description' => $journal->description,- 'user' => $journal->user_id,- 'date' => $journal->date,- 'bill_id' => null,- 'bill_name' => null,- 'piggy_bank_id' => null,- 'piggy_bank_name' => null,- 'tags' => $submitted['tags'],- 'interest_date' => null,- 'book_date' => null,- 'transactions' => [[- 'currency_id' => (int)$journal->transaction_currency_id,- 'currency_code' => null,- 'description' => null,- 'amount' => app('steam')->positive($submitted['amount']),- 'source_id' => $source->id,- 'source_name' => null,- 'destination_id' => $destination->id,- 'destination_name' => null,- 'reconciled' => true,- 'identifier' => 0,- 'foreign_currency_id' => null,- 'foreign_currency_code' => null,- 'foreign_amount' => null,- 'budget_id' => null,- 'budget_name' => null,- 'category_id' => null,- 'category_name' => $submitted['category'],- ],- ],- 'notes' => $this->repository->getNoteText($journal),- ];-- $this->repository->update($journal, $data);--- // @codeCoverageIgnoreStart- if (1 === (int)$request->get('return_to_edit')) {- session()->put('reconcile.edit.fromUpdate', true);-- return redirect(route('accounts.reconcile.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);- }- // @codeCoverageIgnoreEnd-- // redirect to previous URL.- return redirect($this->getPreviousUri('reconcile.edit.uri'));- }}diff --git a/app/Http/Controllers/Json/ReconcileController.php b/app/Http/Controllers/Json/ReconcileController.phpindex 00ed10edb2..722612e9b4 100644--- a/app/Http/Controllers/Json/ReconcileController.php+++ b/app/Http/Controllers/Json/ReconcileController.php@@ -25,12 +25,11 @@ namespace FireflyIII\Http\Controllers\Json;use Carbon\Carbon;-use FireflyIII\Exceptions\FireflyException;use FireflyIII\Helpers\Collector\GroupCollectorInterface;use FireflyIII\Http\Controllers\Controller;use FireflyIII\Models\Account;-use FireflyIII\Models\AccountType;-use FireflyIII\Models\Transaction;+use FireflyIII\Models\TransactionCurrency;+use FireflyIII\Models\TransactionType;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;use FireflyIII\Repositories\Journal\JournalRepositoryInterface;@@ -44,8 +43,6 @@ use Throwable;/**** Class ReconcileController- * TODO needs a full rewrite- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)*/class ReconcileController extends Controller{@@ -59,6 +56,7 @@ class ReconcileController extends Controller/*** ReconcileController constructor.+ * @codeCoverageIgnore*/public function __construct(){@@ -78,7 +76,6 @@ class ReconcileController extends Controller);}- /** @noinspection MoreThanThreeArgumentsInspection *//*** Overview of reconciliation.*@@ -88,86 +85,61 @@ class ReconcileController extends Controller* @param Carbon $end** @return JsonResponse- *- * @throws FireflyException- *- * @SuppressWarnings(PHPMD.CyclomaticComplexity)- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/public function overview(Request $request, Account $account, Carbon $start, Carbon $end): JsonResponse{+ $startBalance = $request->get('startBalance');+ $endBalance = $request->get('endBalance');+ $accountCurrency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();+ $amount = '0';+ $clearedAmount = '0';+ $route = route('accounts.reconcile.submit', [$account->id, $start->format('Ymd'), $end->format('Ymd')]);+ $selectedIds = $request->get('journals') ?? [];+ $clearedJournals = [];+ $clearedIds = $request->get('cleared') ?? [];+ $journals = [];+ /* Collect all submitted journals */+ if (count($selectedIds) > 0) {+ /** @var GroupCollectorInterface $collector */+ $collector = app(GroupCollectorInterface::class);+ $collector->setJournalIds($selectedIds);+ $journals = $collector->getExtractedJournals();+ }- if (AccountType::ASSET !== $account->accountType->type) {- throw new FireflyException(sprintf('Account %s is not an asset account.', $account->name));+ /* Collect all journals already reconciled */+ if (count($clearedIds) > 0) {+ /** @var GroupCollectorInterface $collector */+ $collector = app(GroupCollectorInterface::class);+ $collector->setJournalIds($clearedIds);+ $clearedJournals = $collector->getExtractedJournals();}- $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:- // TODO these methods no longer exist:- $transactions = $this->repository->getTransactionsById($transactionIds);- $cleared = $this->repository->getTransactionsById($clearedIds);- $countCleared = 0;Log::debug('Start transaction loop');- /** @var Transaction $transaction */- foreach ($transactions as $transaction) {- // find the account and opposing account for this transaction- Log::debug(sprintf('Now at transaction #%d: %s', $transaction->journal_id, $transaction->description));- $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) {- Log::debug(sprintf('Source matches currency: %s', $transaction->transaction_amount));- $amount = bcadd($amount, $transaction->transaction_amount);- }- // destination, and it matches the foreign currency ID.- if ($srcCurrency === $transaction->foreign_currency_id) {- Log::debug(sprintf('Source matches foreign currency: %s', $transaction->transaction_foreign_amount));- $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) {- Log::debug(sprintf('Destination matches currency: %s', app('steam')->negative($transaction->transaction_amount)));- $amount = bcadd($amount, app('steam')->negative($transaction->transaction_amount));- }- // destination, and it matches the foreign currency ID.- if ($dstCurrency === $transaction->foreign_currency_id) {- Log::debug(sprintf('Destination matches foreign currency: %s', $transaction->transaction_foreign_amount));- $amount = bcadd($amount, $transaction->transaction_foreign_amount);- }- }- Log::debug(sprintf('Amount is now %s', $amount));+ /** @var array $journal */+ foreach ($journals as $journal) {+ $amount = $this->processJournal($account, $accountCurrency, $journal, $amount);}+ Log::debug(sprintf('Final amount is %s', $amount));Log::debug('End transaction loop');- /** @var Transaction $transaction */- foreach ($cleared as $transaction) {- if ($transaction->date <= $end) {- $clearedAmount = bcadd($clearedAmount, $transaction->transaction_amount); // @codeCoverageIgnore- ++$countCleared;++ /** @var array $journal */+ foreach ($clearedJournals as $journal) {+ if ($journal['date'] <= $end) {+ $clearedAmount = $this->processJournal($account, $accountCurrency, $journal, $clearedAmount);}}- $difference = bcadd(bcadd(bcsub($startBalance, $endBalance), $clearedAmount), $amount);- $diffCompare = bccomp($difference, '0');+ $difference = bcadd(bcadd(bcsub($startBalance, $endBalance), $clearedAmount), $amount);+ $diffCompare = bccomp($difference, '0');+ $countCleared = count($clearedJournals);++ $reconSum = bcadd(bcadd($startBalance, $amount), $clearedAmount);try {$view = view('accounts.reconcile.overview', compact(- 'account', 'start', 'diffCompare', 'difference', 'end', 'clearedIds', 'transactionIds', 'clearedAmount',+ 'account', 'start', 'diffCompare', 'difference', 'end', 'clearedAmount','startBalance', 'endBalance', 'amount',- 'route', 'countCleared'+ 'route', 'countCleared', 'reconSum'))->render();// @codeCoverageIgnoreStart@@ -199,22 +171,12 @@ class ReconcileController extends Controller*/public function transactions(Account $account, Carbon $start, Carbon $end){- if (AccountType::INITIAL_BALANCE === $account->accountType->type) {- return $this->redirectToOriginalAccount($account);- }-$startDate = clone $start;- $startDate->subDays(1);-- $currencyId = (int)$this->accountRepos->getMetaValue($account, 'currency_id');- $currency = $this->currencyRepos->findNull($currencyId);- if (0 === $currencyId) {- $currency = app('amount')->getDefaultCurrency(); // @codeCoverageIgnore- }+ $startDate->subDay();+ $currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();$startBalance = round(app('steam')->balance($account, $startDate), $currency->decimal_places);$endBalance = round(app('steam')->balance($account, $end), $currency->decimal_places);-// get the transactions$selectionStart = clone $start;$selectionStart->subDays(3);@@ -226,20 +188,78 @@ class ReconcileController extends Controller$collector = app(GroupCollectorInterface::class);$collector->setAccounts(new Collection([$account]))- ->setRange($selectionStart, $selectionEnd)->withBudgetInformation()->withCategoryInformation();- $groups = $collector->getGroups();+ ->setRange($selectionStart, $selectionEnd)+ ->withBudgetInformation()->withCategoryInformation()->withAccountInformation();+ $array = $collector->getExtractedJournals();+ $journals = [];+ // "fix" amounts to make it easier on the reconciliation overview:+ /** @var array $journal */+ foreach ($array as $journal) {+ $inverse = false;+ if (TransactionType::DEPOSIT === $journal['transaction_type_type']) {+ $inverse = true;+ }+ // transfer to this account? then positive amount:+ if (TransactionType::TRANSFER === $journal['transaction_type_type']+ && $account->id === $journal['destination_account_id']+ ) {+ $inverse = true;+ }+ if (true === $inverse) {+ $journal['amount'] = app('steam')->positive($journal['amount']);+ if (null !== $journal['foreign_amount']) {+ $journal['foreign_amount'] = app('steam')->positive($journal['foreign_amount']);+ }+ }++ $journals[] = $journal;+ }+try {- $html = view(- 'accounts.reconcile.transactions', compact('account', 'groups', 'currency', 'start', 'end', 'selectionStart', 'selectionEnd')- )->render();+ $html = view('accounts.reconcile.transactions',+ compact('account', 'journals', 'currency', 'start', 'end', 'selectionStart', 'selectionEnd'))->render();// @codeCoverageIgnoreStart} catch (Throwable $e) {Log::debug(sprintf('Could not render: %s', $e->getMessage()));- $html = 'Could not render accounts.reconcile.transactions';+ $html = sprintf('Could not render accounts.reconcile.transactions: %s', $e->getMessage());}// @codeCoverageIgnoreEndreturn response()->json(['html' => $html, 'startBalance' => $startBalance, 'endBalance' => $endBalance]);}++ /**+ * @param Account $account+ * @param TransactionCurrency $currency+ * @param array $journal+ * @param string $amount+ * @return string+ */+ private function processJournal(Account $account, TransactionCurrency $currency, array $journal, string $amount): string+ {+ $toAdd = '0';+ Log::debug(sprintf('User submitted %s #%d: "%s"', $journal['transaction_type_type'], $journal['transaction_journal_id'], $journal['description']));+ if ($account->id === $journal['source_account_id']) {+ if ($currency->id === $journal['currency_id']) {+ $toAdd = $journal['amount'];+ }+ if (null !== $journal['foreign_currency_id'] && $journal['foreign_currency_id'] === $currency->id) {+ $toAdd = $journal['foreign_amount'];+ }+ }+ if ($account->id === $journal['destination_account_id']) {+ if ($currency->id === $journal['currency_id']) {+ $toAdd = bcmul($journal['amount'], '-1');+ }+ if (null !== $journal['foreign_currency_id'] && $journal['foreign_currency_id'] === $currency->id) {+ $toAdd = bcmul($journal['foreign_amount'], '-1');+ }+ }+ Log::debug(sprintf('Going to add %s to %s', $toAdd, $amount));+ $amount = bcadd($amount, $toAdd);+ Log::debug(sprintf('Result is %s', $amount));++ return $amount;+ }}diff --git a/app/Rules/ValidJournals.php b/app/Rules/ValidJournals.phpnew file mode 100644index 0000000000..41f47d060a--- /dev/null+++ b/app/Rules/ValidJournals.php@@ -0,0 +1,75 @@+<?php++/**+ * ValidJournals.php+ * Copyright (c) 2019 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++declare(strict_types=1);+++namespace FireflyIII\Rules;++use FireflyIII\Models\TransactionJournal;+use Illuminate\Contracts\Validation\Rule;+use Log;++/**+ * Class ValidJournals+ */+class ValidJournals implements Rule+{+ /**+ * Get the validation error message.+ *+ * @return string+ */+ public function message(): string+ {+ return (string)trans('validation.invalid_selection');+ }++ /**+ * Determine if the validation rule passes.+ *+ * @param string $attribute+ * @param mixed $value+ *+ * @return bool+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function passes($attribute, $value): bool+ {+ Log::debug('In ValidJournals::passes');+ if (!is_array($value)) {+ return true;+ }+ $userId = auth()->user()->id;+ foreach ($value as $journalId) {+ $count = TransactionJournal::where('id', $journalId)->where('user_id', $userId)->count();+ if (0 === $count) {+ Log::debug(sprintf('Count for transaction #%d and user #%d is zero! Return FALSE', $journalId, $userId));++ return false;+ }+ }+ Log::debug('Return true!');++ return true;+ }+}diff --git a/app/Rules/ValidTransactions.php b/app/Rules/ValidTransactions.phpindex 29fd7baaef..048c16d656 100644--- a/app/Rules/ValidTransactions.php+++ b/app/Rules/ValidTransactions.php@@ -66,7 +66,7 @@ class ValidTransactions implements Rulepublic function passes($attribute, $value): bool{Log::debug('In ValidTransactions::passes');- if (!\is_array($value)) {+ if (!is_array($value)) {return true;}$userId = auth()->user()->id;diff --git a/app/TransactionRules/Engine/RuleEngine.php b/app/TransactionRules/Engine/RuleEngine.phpindex 460b19bdd3..c0a797e389 100644--- a/app/TransactionRules/Engine/RuleEngine.php+++ b/app/TransactionRules/Engine/RuleEngine.php@@ -219,6 +219,9 @@ class RuleEngine{/** @var RuleTrigger $trigger */$trigger = $rule->ruleTriggers()->where('trigger_type', 'user_action')->first();+ if (null === $trigger) {+ return false;+ }$validTrigger = ('store-journal' === $trigger->trigger_value && self::TRIGGER_STORE === $this->triggerMode) ||('update-journal' === $trigger->trigger_value && self::TRIGGER_UPDATE === $this->triggerMode);diff --git a/public/v1/js/ff/accounts/reconcile.js b/public/v1/js/ff/accounts/reconcile.jsindex fe4b9d8b37..90251fe890 100644--- a/public/v1/js/ff/accounts/reconcile.js+++ b/public/v1/js/ff/accounts/reconcile.js@@ -77,9 +77,9 @@ function storeReconcile() {var ids = [];$.each($('.reconcile_checkbox:checked'), function (i, v) {var obj = $(v);- if(obj.data('inrange') === true){- console.log('Added item with amount to list of checked ' + obj.val());- ids.push(obj.data('id'));+ if (obj.data('inrange') === true) {+ console.log('Added item with amount to list of checked ' + obj.val());+ ids.push(obj.data('id'));} else {console.log('Ignored item with amount because is not in range ' + obj.val());}@@ -97,7 +97,7 @@ function storeReconcile() {endBalance: parseFloat($('input[name="end_balance"]').val()),startDate: $('input[name="start_date"]').val(),startEnd: $('input[name="end_date"]').val(),- transactions: ids,+ journals: ids,cleared: cleared,};var uri = overviewUri.replace('%start%', $('input[name="start_date"]').val()).replace('%end%', $('input[name="end_date"]').val());diff --git a/resources/views/v1/accounts/reconcile/overview.twig b/resources/views/v1/accounts/reconcile/overview.twigindex a7c9287d36..33758ecf6b 100644--- a/resources/views/v1/accounts/reconcile/overview.twig+++ b/resources/views/v1/accounts/reconcile/overview.twig@@ -36,6 +36,10 @@<td>{{ 'submitted_end_balance'|_ }} ({{ end.formatLocalized(monthAndDayFormat) }})</td><td>{{ formatAmountByAccount(account, endBalance) }}</td></tr>+ <tr>+ <td>{{ 'sum_of_reconciliation'|_ }}</td>+ <td>{{ formatAmountByAccount(account, reconSum) }}</td>+ </tr><tr><td>{{ 'difference'|_ }}</td>diff --git a/resources/views/v1/accounts/reconcile/transactions.twig b/resources/views/v1/accounts/reconcile/transactions.twigindex 6a041ad85b..7851342972 100644--- a/resources/views/v1/accounts/reconcile/transactions.twig+++ b/resources/views/v1/accounts/reconcile/transactions.twig@@ -1 +1,171 @@-<h1 style="color:red;">REPLACE ME</h1>\ No newline at end of file+<table class="table table-striped table-condensed">+ <thead>+ <tr class="ignore">+ <th class="hidden-xs" colspan="2"> </th>+ <th>{{ trans('list.description') }}</th>+ <th style="text-align:right;">{{ trans('list.amount') }}</th>+ <th class="hidden-xs hidden-sm hidden-md">{{ trans('list.reconcile') }}</th>+ <th class="hidden-xs hidden-sm">{{ trans('list.date') }}</th>+ <th class="hidden-xs hidden-sm hidden-md">{{ trans('list.from') }}</th>+ <th class="hidden-xs hidden-sm hidden-md">{{ trans('list.to') }}</th>+ <th class="hidden-xs"><i class="fa fa-tasks fa-fw" title="{{ trans('list.budget') }}"></i></th>+ <th class="hidden-xs"><i class="fa fa-bar-chart fa-fw" title="{{ trans('list.category') }}"></i></th>+ </tr>+ </thead>+ <tbody>+ {# data for previous/next markers #}+ {% set endSet = false %}+ {% set startSet = false %}+ {% for journal in journals %}+ {# start marker #}+ {% if journal.date < start and startSet == false %}+ <tr>+ <td colspan="5">+ + </td>+ <td colspan="3">+ <span class="label label-default">+ {{ trans('firefly.start_of_reconcile_period', {period: start.formatLocalized(monthAndDayFormat) }) }}+ </span>+ </td>+ <td colspan="2">+ + </td>+ </tr>+ {% set startSet = true %}+ {% endif %}++ {# end marker #}+ {% if journal.date <= end and endSet == false %}+ <tr>+ <td colspan="5">+ + </td>+ <td colspan="3">+ <span class="label label-default">+ {{ trans('firefly.end_of_reconcile_period', {period: end.formatLocalized(monthAndDayFormat) }) }}+ </span>+ </td>+ <td colspan="2">+ + </td>+ </tr>+ {% set endSet = true %}+ {% endif %}+ <tr data-date="{{ journal.date.format('Y-m-d') }}" data-id="{{ journal.transaction_journal_id }}">+ <td class="hidden-xs">+ <div class="btn-group btn-group-xs">+ <a href="{{ route('transactions.edit', [journal.transaction_group_id]) }}" class="btn btn-xs btn-default"><i+ class="fa fa-fw fa-pencil"></i></a>+ </div>++ </td>++ <!-- icon -->+ <td class="hidden-xs">+ {% if journal.transaction_type_type == 'Withdrawal' %}+ <i class="fa fa-long-arrow-left fa-fw" title="{{ trans('firefly.Withdrawal') }}"></i>+ {% endif %}++ {% if journal.transaction_type_type == 'Deposit' %}+ <i class="fa fa-long-arrow-right fa-fw" title="{{ trans('firefly.Deposit') }}"></i>+ {% endif %}++ {% if journal.transaction_type_type == 'Transfer' %}+ <i class="fa fa-exchange fa-fw" title="{{ trans('firefly.Deposit') }}"></i>+ {% endif %}++ {% if journal.transaction_type_type == 'Reconciliation' %}+ <i class="fa-fw fa fa-calculator" title="{{ trans('firefly.reconciliation_transaction') }}"></i>+ {% endif %}+ {% if journal.transaction_type_type == 'Opening balance' %}+ <i class="fa-fw fa fa-star-o" title="{{ trans('firefly.Opening balance') }}"></i>+ {% endif %}+ </td>++ <!-- description -->+ <td>+ <a href="{{ route('transactions.show', [journal.transaction_group_id]) }}" title="{{ journal.description }}">+ {% if journal.group_title %}+ <span class="text-muted"><i class="fa fa-fw fa-share-alt" aria-hidden="true"></i></span> {{ journal.group_title }}:+ {% endif %}+ {{ journal.description }}</a>+ </td>++ <td style="text-align: right;">+ <span style="margin-right:5px;">+ {{ formatAmountBySymbol(journal.amount, journal.currency_symbol, journal.currency_symbol_decimal_places) }}+ {% if null != journal.foreign_amount %}+ ({{ formatAmountBySymbol(journal.foreign_amount, journal.foreign_currency_symbol, journal.foreign_currency_symbol_decimal_places) }})+ {% endif %}+ </span>+ </td>++ <td>++ {% if journal.date >= start and journal.date <= end %}+ {% if journal.reconciled %}+ <i class="fa fa-check" aria-hidden="true"></i>+ <input type="hidden" name="cleared[]" data-younger="{% if journal.date < start %}true{% else %}false{% endif %}"+ data-inrange="{% if journal.date >= start and journal.date <= end %}true{% else %}false"{% endif %}"+ class="cleared" data-id="{{ journal.transaction_journal_id }}" value="{{ journal.amount }}">+ {% else %}+ <input type="checkbox" name="reconciled[]"+ data-younger="{% if journal.date < start %}true{% else %}false{% endif %}"+ data-inrange="{% if journal.date >= start and journal.date <= end %}true{% else %}false"{% endif %}"+ value="{{ journal.amount }}" data-id="{{ journal.transaction_journal_id }}" disabled class="reconcile_checkbox">+ {% endif %}+ {% else %}+ <!-- if not in range, just show reconciliation status -->+ {% if journal.reconciled %}+ <i class="fa fa-check" aria-hidden="true"></i>+ {% else %}+ <!-- TODO include icon -->+ {% endif %}++ {% endif %}++ </td>++ <td class="hidden-sm hidden-xs">+ {{ journal.date.formatLocalized(monthAndDayFormat) }}+ </td>++ <td class="hidden-xs hidden-sm hidden-md">+ <a href="{{ route('accounts.show', [journal.source_account_id]) }}" title="{{ journal.source_account_iban|default(journal.source_account_name) }}">{{ journal.source_account_name }}</a>+ </td>++ <td class="hidden-xs hidden-sm hidden-md">+ <a href="{{ route('accounts.show', [journal.destination_account_id]) }}" title="{{ journal.destination_account_iban|default(journal.destination_account_name) }}">{{ journal.destination_account_name }}</a>+ </td>+ {#+ <td class="hidden-xs">+ {{ transaction|transactionBudgets }}+ </td>+ <td class="hidden-xs">+ {{ transaction|transactionCategories }}+ </td>+ #}+ </tr>++ {% endfor %}++ {# if the start marker has not been generated yet, do it now, at the end of the loop. #}+ {% if startSet == false %}+ <tr>+ <td colspan="5">+ + </td>+ <td colspan="3">+ <span class="label label-default">+ {{ trans('firefly.start_of_reconcile_period', {period: start.formatLocalized(monthAndDayFormat) }) }}+ </span>+ </td>+ <td colspan="2">+ + </td>+ </tr>+ {% set startSet = true %}+ {% endif %}+ </tbody>+</table>diff --git a/resources/views/v1/list/groups.twig b/resources/views/v1/list/groups.twigindex 0b2bfda10a..d1800f7048 100644--- a/resources/views/v1/list/groups.twig+++ b/resources/views/v1/list/groups.twig@@ -45,24 +45,23 @@ TODO: hide and show columns{% endif %}<tr><td {{ style|raw }}>- {% if transaction.transaction_type_type == 'Withdrawal' %}+ {% if journal.transaction_type_type == 'Withdrawal' %}<i class="fa fa-long-arrow-left fa-fw" title="{{ trans('firefly.Withdrawal') }}"></i>{% endif %}- {% if transaction.transaction_type_type == 'Deposit' %}+ {% if journal.transaction_type_type == 'Deposit' %}<i class="fa fa-long-arrow-right fa-fw" title="{{ trans('firefly.Deposit') }}"></i>{% endif %}- {% if transaction.transaction_type_type == 'Transfer' %}+ {% if journal.transaction_type_type == 'Transfer' %}<i class="fa fa-exchange fa-fw" title="{{ trans('firefly.Deposit') }}"></i>{% endif %}- {% if transaction.transaction_type_type == 'Reconciliation' %}- XX+ {% if journal.transaction_type_type == 'Reconciliation' %}+ <i class="fa-fw fa fa-calculator" title="{{ trans('firefly.reconciliation_transaction') }}"></i>{% endif %}-- {% if transaction.transaction_type_type == 'Opening balance' %}- XX+ {% if journal.transaction_type_type == 'Opening balance' %}+ <i class="fa-fw fa fa-star-o" title="{{ trans('firefly.Opening balance') }}"></i>{% endif %}</td>