mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expand API, add new migration.
This commit is contained in:
parent
77e7af75dc
commit
cb65999124
@ -241,7 +241,6 @@ class PiggyBankController extends Controller
|
|||||||
$this->repository->setCurrentAmount($piggyBank, $data['current_amount']);
|
$this->repository->setCurrentAmount($piggyBank, $data['current_amount']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$manager = $this->getManager();
|
$manager = $this->getManager();
|
||||||
/** @var PiggyBankTransformer $transformer */
|
/** @var PiggyBankTransformer $transformer */
|
||||||
$transformer = app(PiggyBankTransformer::class);
|
$transformer = app(PiggyBankTransformer::class);
|
||||||
|
@ -63,6 +63,7 @@ class PiggyBankRequest extends Request
|
|||||||
'startdate' => $this->date('start_date'),
|
'startdate' => $this->date('start_date'),
|
||||||
'targetdate' => $this->date('target_date'),
|
'targetdate' => $this->date('target_date'),
|
||||||
'notes' => $this->nlString('notes'),
|
'notes' => $this->nlString('notes'),
|
||||||
|
'order' => $this->integer('order'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ use FireflyIII\Http\Controllers\Controller;
|
|||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\ObjectGroup\OrganisesObjectGroups;
|
||||||
use FireflyIII\Transformers\BillTransformer;
|
use FireflyIII\Transformers\BillTransformer;
|
||||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
|
|||||||
*/
|
*/
|
||||||
class IndexController extends Controller
|
class IndexController extends Controller
|
||||||
{
|
{
|
||||||
|
use OrganisesObjectGroups;
|
||||||
private BillRepositoryInterface $repository;
|
private BillRepositoryInterface $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,6 +67,10 @@ class IndexController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
$this->cleanupObjectGroups();
|
||||||
|
$this->repository->correctOrder();
|
||||||
|
|
||||||
|
|
||||||
$start = session('start');
|
$start = session('start');
|
||||||
$end = session('end');
|
$end = session('end');
|
||||||
$collection = $this->repository->getBills();
|
$collection = $this->repository->getBills();
|
||||||
|
@ -190,7 +190,10 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
public function getBills(): Collection
|
public function getBills(): Collection
|
||||||
{
|
{
|
||||||
/** @var Collection $set */
|
/** @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]);
|
$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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,11 @@ interface BillRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function unlinkAll(Bill $bill): void;
|
public function unlinkAll(Bill $bill): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add correct order to bills.
|
||||||
|
*/
|
||||||
|
public function correctOrder(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Bill $bill
|
* @param Bill $bill
|
||||||
*
|
*
|
||||||
|
@ -26,6 +26,7 @@ namespace FireflyIII\Repositories\PiggyBank;
|
|||||||
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use DB;
|
||||||
use Exception;
|
use Exception;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Note;
|
use FireflyIII\Models\Note;
|
||||||
@ -34,6 +35,7 @@ use FireflyIII\Models\PiggyBankEvent;
|
|||||||
use FireflyIII\Models\PiggyBankRepetition;
|
use FireflyIII\Models\PiggyBankRepetition;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
|
use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
|
||||||
|
use FireflyIII\User;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
@ -351,6 +353,14 @@ trait ModifiesPiggyBanks
|
|||||||
|
|
||||||
$this->updateNote($piggyBank, $data['notes'] ?? '');
|
$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,
|
// if the piggy bank is now smaller than the current relevant rep,
|
||||||
// remove money from the rep.
|
// remove money from the rep.
|
||||||
$repetition = $this->getRepetition($piggyBank);
|
$repetition = $this->getRepetition($piggyBank);
|
||||||
@ -415,4 +425,38 @@ trait ModifiesPiggyBanks
|
|||||||
return true;
|
return 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -143,9 +143,9 @@ return [
|
|||||||
],
|
],
|
||||||
|
|
||||||
//'encryption' => null === env('USE_ENCRYPTION') || true === env('USE_ENCRYPTION'),
|
//'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',
|
'api_version' => '1.2.0',
|
||||||
'db_version' => 14,
|
'db_version' => 15,
|
||||||
'maxUploadSize' => 1073741824, // 1 GB
|
'maxUploadSize' => 1073741824, // 1 GB
|
||||||
'send_error_message' => env('SEND_ERROR_MESSAGE', true),
|
'send_error_message' => env('SEND_ERROR_MESSAGE', true),
|
||||||
'site_owner' => env('SITE_OWNER', ''),
|
'site_owner' => env('SITE_OWNER', ''),
|
||||||
|
@ -1,5 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2020_03_13_201950_changes_for_v520.php
|
||||||
|
* Copyright (c) 2020 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* 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);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
@ -1,4 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2020_06_07_063612_changes_for_v530.php
|
||||||
|
* Copyright (c) 2020 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* 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);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
@ -41,6 +62,7 @@ class ChangesForV530 extends Migration
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!Schema::hasTable('object_groupables')) {
|
if (!Schema::hasTable('object_groupables')) {
|
||||||
Schema::create(
|
Schema::create(
|
||||||
'object_groupables', static function (Blueprint $table) {
|
'object_groupables', static function (Blueprint $table) {
|
||||||
|
61
database/migrations/2020_06_30_202620_changes_for_v530a.php
Normal file
61
database/migrations/2020_06_30_202620_changes_for_v530a.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2020_06_30_202620_changes_for_v530a.php
|
||||||
|
* Copyright (c) 2020 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ConfigSeeder.php
|
||||||
|
* Copyright (c) 2020 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* 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);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user