Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix transactions.
James Cole1a721ac6b53f
diff --git a/app/Api/V1/Controllers/TransactionController.php b/app/Api/V1/Controllers/TransactionController.phpindex 7510679f17..e49e2e4b09 100644--- a/app/Api/V1/Controllers/TransactionController.php+++ b/app/Api/V1/Controllers/TransactionController.php@@ -24,7 +24,6 @@ declare(strict_types=1);namespace FireflyIII\Api\V1\Controllers;use FireflyIII\Api\V1\Requests\TransactionRequest;-use FireflyIII\Factory\TransactionJournalFactory;use FireflyIII\Helpers\Collector\JournalCollectorInterface;use FireflyIII\Helpers\Filter\InternalTransferFilter;use FireflyIII\Helpers\Filter\NegativeAmountFilter;@@ -179,14 +178,11 @@ class TransactionController extends Controller* @return \Illuminate\Http\JsonResponse* @throws \FireflyIII\Exceptions\FireflyException*/- public function store(TransactionRequest $request)+ public function store(TransactionRequest $request, JournalRepositoryInterface $repository){$data = $request->getAll();$data['user'] = auth()->user()->id;- /** @var TransactionJournalFactory $factory */- $factory = app(TransactionJournalFactory::class);- $factory->setUser(auth()->user());- $journal = $factory->create($data);+ $journal = $repository->store($data);$manager = new Manager();$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';@@ -196,7 +192,6 @@ class TransactionController extends Controller$include = $request->get('include') ?? '';$manager->parseIncludes($include);- // needs a lot of extra data to match the journal collector. Or just expand that one.// collect transactions using the journal collector$collector = app(JournalCollectorInterface::class);$collector->setUser(auth()->user());diff --git a/app/Http/Controllers/Transaction/SingleController.php b/app/Http/Controllers/Transaction/SingleController.phpindex 9b2c43dfb7..68c96bcc21 100644--- a/app/Http/Controllers/Transaction/SingleController.php+++ b/app/Http/Controllers/Transaction/SingleController.php@@ -424,7 +424,16 @@ class SingleController extends Controller}// @codeCoverageIgnoreEnd- $data = $request->getJournalData();+ $data = $request->getJournalData();+ $data['transactions'][0]['currency_id'] = $journal->transaction_currency_id;+ if ($data['currency_id'] !== $journal->transaction_currency_id) {+ // currency ID is changed by user. Update transaction:++ $data['transactions'][0]['amount'] = $data['native_amount'];+ $data['transactions'][0]['foreign_currency_id'] = $data['currency_id'];+ $data['transactions'][0]['foreign_amount'] = $data['amount'];+ }+$journal = $repository->update($journal, $data);/** @var array $files */$files = $request->hasFile('attachments') ? $request->file('attachments') : null;diff --git a/app/Http/Requests/JournalFormRequest.php b/app/Http/Requests/JournalFormRequest.phpindex 5db610e704..8a3651bb07 100644--- a/app/Http/Requests/JournalFormRequest.php+++ b/app/Http/Requests/JournalFormRequest.php@@ -47,36 +47,56 @@ class JournalFormRequest extends Requestpublic function getJournalData(){$data = [- 'type' => $this->get('what'), // type. can be 'deposit', 'withdrawal' or 'transfer'- 'date' => $this->date('date'),- 'tags' => explode(',', $this->string('tags')),- 'currency_id' => $this->integer('amount_currency_id_amount'),+ 'type' => $this->get('what'), // type. can be 'deposit', 'withdrawal' or 'transfer'+ 'date' => $this->date('date'),+ 'tags' => explode(',', $this->string('tags')),+// all custom fields:- 'interest_date' => $this->date('interest_date'),- 'book_date' => $this->date('book_date'),- 'process_date' => $this->date('process_date'),- 'due_date' => $this->date('due_date'),- 'payment_date' => $this->date('payment_date'),- 'invoice_date' => $this->date('invoice_date'),- 'internal_reference' => $this->string('internal_reference'),- 'notes' => $this->string('notes'),-- // transaction / journal data:- 'description' => $this->string('description'),- 'amount' => $this->string('amount'),- 'budget_id' => $this->integer('budget_id'),- 'category' => $this->string('category'),- 'source_account_id' => $this->integer('source_account_id'),- 'source_account_name' => $this->string('source_account_name'),- 'destination_account_id' => $this->string('destination_account_id'),- 'destination_account_name' => $this->string('destination_account_name'),- 'piggy_bank_id' => $this->integer('piggy_bank_id'),+ 'interest_date' => $this->date('interest_date'),+ 'book_date' => $this->date('book_date'),+ 'process_date' => $this->date('process_date'),+ 'due_date' => $this->date('due_date'),+ 'payment_date' => $this->date('payment_date'),+ 'invoice_date' => $this->date('invoice_date'),+ 'internal_reference' => $this->string('internal_reference'),+ 'notes' => $this->string('notes'),++ // journal data:+ 'description' => $this->string('description'),+ 'piggy_bank_id' => $this->integer('piggy_bank_id'),+ 'bill_id' => null,+ 'bill_name' => null,// native amount and stuff like that:- 'native_amount' => $this->string('native_amount'),- 'source_amount' => $this->string('source_amount'),- 'destination_amount' => $this->string('destination_amount'),+ 'currency_id' => $this->integer('amount_currency_id_amount'),+ 'amount' => $this->string('amount'),+ 'native_amount' => $this->string('native_amount'),+ 'source_amount' => $this->string('source_amount'),+ 'destination_amount' => $this->string('destination_amount'),++ // transaction data:+ 'transactions' => [+ [+ 'currency_id' => null,+ 'currency_code' => null,+ 'description' => null,+ 'amount' => $this->string('amount'),+ 'budget_id' => $this->integer('budget_id'),+ 'budget_name' => null,+ 'category_id' => null,+ 'category_name' => $this->string('category'),+ 'source_id' => $this->integer('source_account_id'),+ 'source_name' => $this->string('source_account_name'),+ 'destination_id' => $this->integer('destination_account_id'),+ 'destination_name' => $this->string('destination_account_name'),+ 'foreign_currency_id' => null,+ 'foreign_currency_code' => null,+ 'foreign_amount' => null,+ 'reconciled' => false,+ 'identifier' => 0,+ ],+ ],];return $data;diff --git a/app/Rules/BelongsUser.php b/app/Rules/BelongsUser.phpindex 876d8967d2..57aa963e11 100644--- a/app/Rules/BelongsUser.php+++ b/app/Rules/BelongsUser.php@@ -1,5 +1,26 @@<?php++/**+ * BelongsUser.php+ * Copyright (c) 2018 [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/>.+ */+namespace FireflyIII\Rules;use FireflyIII\Exceptions\FireflyException;diff --git a/app/Rules/ValidTransactions.php b/app/Rules/ValidTransactions.phpindex 9d7ff7403f..be57f7dccd 100644--- a/app/Rules/ValidTransactions.php+++ b/app/Rules/ValidTransactions.php@@ -1,5 +1,26 @@<?php++/**+ * ValidTransactions.php+ * Copyright (c) 2018 [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/>.+ */+namespace FireflyIII\Rules;use FireflyIII\Models\Transaction;diff --git a/config/breadcrumbs.php b/config/breadcrumbs.phpindex dcfbba2987..66d8ac024d 100644--- a/config/breadcrumbs.php+++ b/config/breadcrumbs.php@@ -1,5 +1,26 @@<?php++/**+ * breadcrumbs.php+ * Copyright (c) 2018 [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/>.+ */+return [/*diff --git a/config/google2fa.php b/config/google2fa.phpindex e04f5e0b76..bf65120b83 100644--- a/config/google2fa.php+++ b/config/google2fa.php@@ -1,5 +1,26 @@<?php++/**+ * google2fa.php+ * Copyright (c) 2018 [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/>.+ */+return [/*diff --git a/config/localization-js.php b/config/localization-js.phpdeleted file mode 100644index 14d3a4c57e..0000000000--- a/config/localization-js.php+++ /dev/null@@ -1,23 +0,0 @@-<?php--return [-- /*- * Set the names of files you want to add to generated javascript.- * Otherwise all the files will be included.- *- * 'messages' => [- * 'validation',- * 'forum/thread',- * ],- */- 'messages' => [- 'components',- 'list',- ],-- /*- * The default path to use for the generated javascript.- */- 'path' => public_path('messages.js'),-];diff --git a/database/migrations/2018_01_01_000001_create_oauth_auth_codes_table.php b/database/migrations/2018_01_01_000001_create_oauth_auth_codes_table.phpindex 8060c72695..41dea9acbd 100644--- a/database/migrations/2018_01_01_000001_create_oauth_auth_codes_table.php+++ b/database/migrations/2018_01_01_000001_create_oauth_auth_codes_table.php@@ -1,5 +1,26 @@<?php++/**+ * 2018_01_01_000001_create_oauth_auth_codes_table.php+ * Copyright (c) 2018 [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/>.+ */+use Illuminate\Support\Facades\Schema;use Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;diff --git a/database/migrations/2018_01_01_000002_create_oauth_access_tokens_table.php b/database/migrations/2018_01_01_000002_create_oauth_access_tokens_table.phpindex e5096aeb11..8fdeaec3d4 100644--- a/database/migrations/2018_01_01_000002_create_oauth_access_tokens_table.php+++ b/database/migrations/2018_01_01_000002_create_oauth_access_tokens_table.php@@ -1,5 +1,26 @@<?php++/**+ * 2018_01_01_000002_create_oauth_access_tokens_table.php+ * Copyright (c) 2018 [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/>.+ */+use Illuminate\Support\Facades\Schema;use Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;diff --git a/database/migrations/2018_01_01_000003_create_oauth_refresh_tokens_table.php b/database/migrations/2018_01_01_000003_create_oauth_refresh_tokens_table.phpindex c6f714a55a..bc588d3c30 100644--- a/database/migrations/2018_01_01_000003_create_oauth_refresh_tokens_table.php+++ b/database/migrations/2018_01_01_000003_create_oauth_refresh_tokens_table.php@@ -1,5 +1,26 @@<?php++/**+ * 2018_01_01_000003_create_oauth_refresh_tokens_table.php+ * Copyright (c) 2018 [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/>.+ */+use Illuminate\Support\Facades\Schema;use Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;diff --git a/database/migrations/2018_01_01_000004_create_oauth_clients_table.php b/database/migrations/2018_01_01_000004_create_oauth_clients_table.phpindex c09b56c4a3..1e440e75b9 100644--- a/database/migrations/2018_01_01_000004_create_oauth_clients_table.php+++ b/database/migrations/2018_01_01_000004_create_oauth_clients_table.php@@ -1,5 +1,26 @@<?php++/**+ * 2018_01_01_000004_create_oauth_clients_table.php+ * Copyright (c) 2018 [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/>.+ */+use Illuminate\Support\Facades\Schema;use Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;diff --git a/database/migrations/2018_01_01_000005_create_oauth_personal_access_clients_table.php b/database/migrations/2018_01_01_000005_create_oauth_personal_access_clients_table.phpindex 3feaaeaf1d..fb7a22568a 100644--- a/database/migrations/2018_01_01_000005_create_oauth_personal_access_clients_table.php+++ b/database/migrations/2018_01_01_000005_create_oauth_personal_access_clients_table.php@@ -1,5 +1,26 @@<?php++/**+ * 2018_01_01_000005_create_oauth_personal_access_clients_table.php+ * Copyright (c) 2018 [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/>.+ */+use Illuminate\Support\Facades\Schema;use Illuminate\Database\Schema\Blueprint;use Illuminate\Database\Migrations\Migration;