Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Expand API, add new migration.
James Colecb65999124a5
diff --git a/app/Api/V1/Controllers/PiggyBankController.php b/app/Api/V1/Controllers/PiggyBankController.phpindex 185a37636f..b9b115d140 100644--- a/app/Api/V1/Controllers/PiggyBankController.php+++ b/app/Api/V1/Controllers/PiggyBankController.php@@ -241,7 +241,6 @@ class PiggyBankController extends Controller$this->repository->setCurrentAmount($piggyBank, $data['current_amount']);}-$manager = $this->getManager();/** @var PiggyBankTransformer $transformer */$transformer = app(PiggyBankTransformer::class);diff --git a/app/Api/V1/Requests/PiggyBankRequest.php b/app/Api/V1/Requests/PiggyBankRequest.phpindex 59c1c23d9e..5c61da6e20 100644--- a/app/Api/V1/Requests/PiggyBankRequest.php+++ b/app/Api/V1/Requests/PiggyBankRequest.php@@ -63,6 +63,7 @@ class PiggyBankRequest extends Request'startdate' => $this->date('start_date'),'targetdate' => $this->date('target_date'),'notes' => $this->nlString('notes'),+ 'order' => $this->integer('order'),];}diff --git a/app/Http/Controllers/Bill/IndexController.php b/app/Http/Controllers/Bill/IndexController.phpindex 8e46fd82cd..e169953d46 100644--- a/app/Http/Controllers/Bill/IndexController.php+++ b/app/Http/Controllers/Bill/IndexController.php@@ -30,6 +30,7 @@ use FireflyIII\Http\Controllers\Controller;use FireflyIII\Models\Bill;use FireflyIII\Models\TransactionCurrency;use FireflyIII\Repositories\Bill\BillRepositoryInterface;+use FireflyIII\Repositories\ObjectGroup\OrganisesObjectGroups;use FireflyIII\Transformers\BillTransformer;use Symfony\Component\HttpFoundation\ParameterBag;@@ -38,6 +39,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;*/class IndexController extends Controller{+ use OrganisesObjectGroups;private BillRepositoryInterface $repository;/**@@ -65,6 +67,10 @@ class IndexController extends Controller*/public function index(){+ $this->cleanupObjectGroups();+ $this->repository->correctOrder();++$start = session('start');$end = session('end');$collection = $this->repository->getBills();diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.phpindex fbe300a841..1fb3a1c0bf 100644--- a/app/Repositories/Bill/BillRepository.php+++ b/app/Repositories/Bill/BillRepository.php@@ -190,7 +190,10 @@ class BillRepository implements BillRepositoryInterfacepublic function getBills(): Collection{/** @var Collection $set */- return $this->user->bills()->orderBy('active', 'DESC')->orderBy('name', 'ASC')->get();+ return $this->user->bills()+ ->orderBy('order', 'ASC')+ ->orderBy('active', 'DESC')+ ->orderBy('name', 'ASC')->get();}/**@@ -711,4 +714,20 @@ class BillRepository implements BillRepositoryInterface{$this->user->transactionJournals()->where('bill_id', $bill->id)->update(['bill_id' => null]);}++ /**+ * Correct order of piggies in case of issues.+ */+ public function correctOrder(): void+ {+ $set = $this->user->bills()->orderBy('order', 'ASC')->get();+ $current = 1;+ foreach ($set as $bill) {+ if ((int) $bill->order !== $current) {+ $bill->order = $current;+ $bill->save();+ }+ $current++;+ }+ }}diff --git a/app/Repositories/Bill/BillRepositoryInterface.php b/app/Repositories/Bill/BillRepositoryInterface.phpindex c5156b676c..dd5a090c57 100644--- a/app/Repositories/Bill/BillRepositoryInterface.php+++ b/app/Repositories/Bill/BillRepositoryInterface.php@@ -40,6 +40,11 @@ interface BillRepositoryInterface*/public function unlinkAll(Bill $bill): void;+ /**+ * Add correct order to bills.+ */+ public function correctOrder(): void;+/*** @param Bill $bill*diff --git a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php b/app/Repositories/PiggyBank/ModifiesPiggyBanks.phpindex 7fd9ec4864..5914066a91 100644--- a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php+++ b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php@@ -26,6 +26,7 @@ namespace FireflyIII\Repositories\PiggyBank;use Carbon\Carbon;+use DB;use Exception;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Models\Note;@@ -34,6 +35,7 @@ use FireflyIII\Models\PiggyBankEvent;use FireflyIII\Models\PiggyBankRepetition;use FireflyIII\Models\TransactionJournal;use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;+use FireflyIII\User;use Illuminate\Database\QueryException;use Log;@@ -351,6 +353,14 @@ trait ModifiesPiggyBanks$this->updateNote($piggyBank, $data['notes'] ?? '');+ // update the order of the piggy bank:+ $oldOrder = (int) $piggyBank->order;+ $newOrder = (int) ($data['order'] ?? $oldOrder);+ if ($oldOrder !== $newOrder) {+ $this->updateOrder($piggyBank, $oldOrder, $newOrder);+ }++// if the piggy bank is now smaller than the current relevant rep,// remove money from the rep.$repetition = $this->getRepetition($piggyBank);@@ -415,4 +425,38 @@ trait ModifiesPiggyBanksreturn true;}+ /**+ * @param PiggyBank $piggyBank+ * @param int $oldOrder+ * @param int $newOrder+ */+ private function updateOrder(PiggyBank $piggyBank, int $oldOrder, int $newOrder): void+ {+ if ($newOrder > $oldOrder) {+ // Iedereen [7 en lager] [hoger dan 3] behalve piggy zelf, puntje er af:+ //piggy zelf naar 7+ /** @var User $user */+ $user = $this->user;+ $user->piggyBanks()->where('order', '<=', $newOrder)->where('order', '>', $oldOrder)+ ->where('piggy_banks.id', '!=', $piggyBank->id)+ ->update(['order' => DB::raw('piggy_banks.order-1')]);+ $piggyBank->order = $newOrder;+ $piggyBank->save();+ }+ if ($newOrder < $oldOrder) {+ //+ //Van 8 naar 2+ // iedereen [2 of hoger] en [kleiner dan 8] puntje er bij.+ // 8 naar 2+ /** @var User $user */+ $user = $this->user;+ $user->piggyBanks()->where('order', '>=', $newOrder)->where('order', '<', $oldOrder)+ ->where('piggy_banks.id', '!=', $piggyBank->id)+ ->update(['order' => DB::raw('piggy_banks.order+1')]);+ $piggyBank->order = $newOrder;+ $piggyBank->save();+ }++ }+}diff --git a/config/firefly.php b/config/firefly.phpindex 4bb7636141..da63dac5f7 100644--- a/config/firefly.php+++ b/config/firefly.php@@ -143,9 +143,9 @@ return [],//'encryption' => null === env('USE_ENCRYPTION') || true === env('USE_ENCRYPTION'),- 'version' => '5.3.0-beta.1',+ 'version' => '5.3.0-beta.2','api_version' => '1.2.0',- 'db_version' => 14,+ 'db_version' => 15,'maxUploadSize' => 1073741824, // 1 GB'send_error_message' => env('SEND_ERROR_MESSAGE', true),'site_owner' => env('SITE_OWNER', ''),diff --git a/database/migrations/2020_03_13_201950_changes_for_v520.php b/database/migrations/2020_03_13_201950_changes_for_v520.phpindex ce0720fb6f..b2a675bdec 100644--- a/database/migrations/2020_03_13_201950_changes_for_v520.php+++ b/database/migrations/2020_03_13_201950_changes_for_v520.php@@ -1,5 +1,26 @@<?php++/**+ * 2020_03_13_201950_changes_for_v520.php+ * Copyright (c) 2020 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program 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 Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */+declare(strict_types=1);use Illuminate\Database\Migrations\Migration;diff --git a/database/migrations/2020_06_07_063612_changes_for_v530.php b/database/migrations/2020_06_07_063612_changes_for_v530.phpindex 13de0ff70b..72d792bd1f 100644--- a/database/migrations/2020_06_07_063612_changes_for_v530.php+++ b/database/migrations/2020_06_07_063612_changes_for_v530.php@@ -1,4 +1,25 @@<?php++/**+ * 2020_06_07_063612_changes_for_v530.php+ * Copyright (c) 2020 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program 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 Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */+declare(strict_types=1);use Illuminate\Database\Migrations\Migration;@@ -41,6 +62,7 @@ class ChangesForV530 extends Migration);}+if (!Schema::hasTable('object_groupables')) {Schema::create('object_groupables', static function (Blueprint $table) {diff --git a/database/migrations/2020_06_30_202620_changes_for_v530a.php b/database/migrations/2020_06_30_202620_changes_for_v530a.phpnew file mode 100644index 0000000000..df17f9b62b--- /dev/null+++ b/database/migrations/2020_06_30_202620_changes_for_v530a.php@@ -0,0 +1,61 @@+<?php++/**+ * 2020_06_30_202620_changes_for_v530a.php+ * Copyright (c) 2020 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program 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 Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++declare(strict_types=1);++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++/**+ * Class ChangesForV530a+ */+class ChangesForV530a extends Migration+{+ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down(): void+ {+ Schema::table(+ 'bills', static function (Blueprint $table) {+ $table->dropColumn('order');+ }+ );+ }++ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up(): void+ {+ Schema::table(+ 'bills', static function (Blueprint $table) {+ $table->integer('order', false, true)->default(0);+ }+ );+ }+}diff --git a/database/seeds/ConfigSeeder.php b/database/seeds/ConfigSeeder.phpindex f040556b8e..9dc03d7e6b 100644--- a/database/seeds/ConfigSeeder.php+++ b/database/seeds/ConfigSeeder.php@@ -1,5 +1,26 @@<?php++/**+ * ConfigSeeder.php+ * Copyright (c) 2020 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program 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 Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */+declare(strict_types=1);/**