Merge branch 'release/5.4.4' into main

This commit is contained in:
James Cole
2020-10-24 18:55:36 +02:00
752 changed files with 8106 additions and 57830 deletions

View File

@@ -60,7 +60,7 @@ class AboutController extends Controller
'driver' => $currentDriver, 'driver' => $currentDriver,
]; ];
return response()->json(['data' => $data])->header('Content-Type', 'application/vnd.api+json'); return response()->json(['data' => $data])->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -78,6 +78,6 @@ class AboutController extends Controller
$resource = new Item(auth()->user(), $transformer, 'users'); $resource = new Item(auth()->user(), $transformer, 'users');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -102,7 +102,7 @@ class AccountController extends Controller
$resource = new FractalCollection($attachments, $transformer, 'attachments'); $resource = new FractalCollection($attachments, $transformer, 'attachments');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -155,7 +155,7 @@ class AccountController extends Controller
$resource = new FractalCollection($accounts, $transformer, self::RESOURCE_KEY); $resource = new FractalCollection($accounts, $transformer, self::RESOURCE_KEY);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -191,7 +191,7 @@ class AccountController extends Controller
$resource = new FractalCollection($piggyBanks, $transformer, 'piggy_banks'); $resource = new FractalCollection($piggyBanks, $transformer, 'piggy_banks');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -211,7 +211,7 @@ class AccountController extends Controller
$transformer->setParameters($this->parameters); $transformer->setParameters($this->parameters);
$resource = new Item($account, $transformer, self::RESOURCE_KEY); $resource = new Item($account, $transformer, self::RESOURCE_KEY);
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -233,7 +233,7 @@ class AccountController extends Controller
$resource = new Item($account, $transformer, self::RESOURCE_KEY); $resource = new Item($account, $transformer, self::RESOURCE_KEY);
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -283,7 +283,7 @@ class AccountController extends Controller
$resource = new FractalCollection($groups, $transformer, 'transactions'); $resource = new FractalCollection($groups, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -306,6 +306,6 @@ class AccountController extends Controller
$transformer->setParameters($this->parameters); $transformer->setParameters($this->parameters);
$resource = new Item($account, $transformer, self::RESOURCE_KEY); $resource = new Item($account, $transformer, self::RESOURCE_KEY);
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -95,8 +95,8 @@ class AttachmentController extends Controller
* @param Attachment $attachment * @param Attachment $attachment
* *
* @codeCoverageIgnore * @codeCoverageIgnore
* @throws FireflyException
* @return LaravelResponse * @return LaravelResponse
* @throws FireflyException
*/ */
public function download(Attachment $attachment): LaravelResponse public function download(Attachment $attachment): LaravelResponse
{ {
@@ -160,7 +160,7 @@ class AttachmentController extends Controller
$resource = new FractalCollection($attachments, $transformer, 'attachments'); $resource = new FractalCollection($attachments, $transformer, 'attachments');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -179,7 +179,7 @@ class AttachmentController extends Controller
$resource = new Item($attachment, $transformer, 'attachments'); $resource = new Item($attachment, $transformer, 'attachments');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -187,8 +187,8 @@ class AttachmentController extends Controller
* *
* @param AttachmentStoreRequest $request * @param AttachmentStoreRequest $request
* *
* @throws FireflyException
* @return JsonResponse * @return JsonResponse
* @throws FireflyException
*/ */
public function store(AttachmentStoreRequest $request): JsonResponse public function store(AttachmentStoreRequest $request): JsonResponse
{ {
@@ -202,7 +202,7 @@ class AttachmentController extends Controller
$resource = new Item($attachment, $transformer, 'attachments'); $resource = new Item($attachment, $transformer, 'attachments');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -225,7 +225,7 @@ class AttachmentController extends Controller
$resource = new Item($attachment, $transformer, 'attachments'); $resource = new Item($attachment, $transformer, 'attachments');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**

View File

@@ -41,7 +41,6 @@ class AccountController extends Controller
use AccountFilter; use AccountFilter;
private array $balanceTypes; private array $balanceTypes;
private AccountRepositoryInterface $repository; private AccountRepositoryInterface $repository;
@@ -76,16 +75,14 @@ class AccountController extends Controller
$query = $data['query']; $query = $data['query'];
$date = $data['date'] ?? today(config('app.timezone')); $date = $data['date'] ?? today(config('app.timezone'));
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$return = []; $return = [];
$result = $repository->searchAccount((string) $query, $types, $data['limit']); $result = $this->repository->searchAccount((string) $query, $types, $data['limit']);
$defaultCurrency = app('amount')->getDefaultCurrency(); $defaultCurrency = app('amount')->getDefaultCurrency();
/** @var Account $account */ /** @var Account $account */
foreach ($result as $account) { foreach ($result as $account) {
$nameWithBalance = $account->name; $nameWithBalance = $account->name;
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency; $currency = $this->repository->getAccountCurrency($account) ?? $defaultCurrency;
if (in_array($account->accountType->type, $this->balanceTypes, true)) { if (in_array($account->accountType->type, $this->balanceTypes, true)) {
$balance = app('steam')->balance($account, $date); $balance = app('steam')->balance($account, $date);

View File

@@ -89,7 +89,7 @@ class CurrencyController extends Controller
*/ */
public function currencies(AutocompleteRequest $request): JsonResponse public function currencies(AutocompleteRequest $request): JsonResponse
{ {
$data = $request->getData(); $data = $request->getData();
$collection = $this->repository->searchCurrency($data['query'], $data['limit']); $collection = $this->repository->searchCurrency($data['query'], $data['limit']);
$result = []; $result = [];

View File

@@ -76,7 +76,7 @@ class PiggyBankController extends Controller
/** @var PiggyBank $piggy */ /** @var PiggyBank $piggy */
foreach ($piggies as $piggy) { foreach ($piggies as $piggy) {
$currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency; $currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency;
$response[] = [ $response[] = [
'id' => $piggy->id, 'id' => $piggy->id,
'name' => $piggy->name, 'name' => $piggy->name,
@@ -103,9 +103,9 @@ class PiggyBankController extends Controller
$response = []; $response = [];
/** @var PiggyBank $piggy */ /** @var PiggyBank $piggy */
foreach ($piggies as $piggy) { foreach ($piggies as $piggy) {
$currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency; $currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency;
$currentAmount = $this->piggyRepository->getRepetition($piggy)->currentamount ?? '0'; $currentAmount = $this->piggyRepository->getRepetition($piggy)->currentamount ?? '0';
$response[] = [ $response[] = [
'id' => $piggy->id, 'id' => $piggy->id,
'name' => $piggy->name, 'name' => $piggy->name,
'name_with_balance' => sprintf( 'name_with_balance' => sprintf(

View File

@@ -111,7 +111,7 @@ class AvailableBudgetController extends Controller
$resource = new FractalCollection($availableBudgets, $transformer, 'available_budgets'); $resource = new FractalCollection($availableBudgets, $transformer, 'available_budgets');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -132,7 +132,7 @@ class AvailableBudgetController extends Controller
$resource = new Item($availableBudget, $transformer, 'available_budgets'); $resource = new Item($availableBudget, $transformer, 'available_budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -165,7 +165,7 @@ class AvailableBudgetController extends Controller
$resource = new Item($availableBudget, $transformer, 'available_budgets'); $resource = new Item($availableBudget, $transformer, 'available_budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -205,7 +205,7 @@ class AvailableBudgetController extends Controller
$resource = new Item($availableBudget, $transformer, 'available_budgets'); $resource = new Item($availableBudget, $transformer, 'available_budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -103,7 +103,7 @@ class BillController extends Controller
$resource = new FractalCollection($attachments, $transformer, 'attachments'); $resource = new FractalCollection($attachments, $transformer, 'attachments');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -143,7 +143,7 @@ class BillController extends Controller
$resource = new FractalCollection($bills, $transformer, 'bills'); $resource = new FractalCollection($bills, $transformer, 'bills');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -178,7 +178,7 @@ class BillController extends Controller
$resource = new FractalCollection($rules, $transformer, 'rules'); $resource = new FractalCollection($rules, $transformer, 'rules');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -199,7 +199,7 @@ class BillController extends Controller
$resource = new Item($bill, $transformer, 'bills'); $resource = new Item($bill, $transformer, 'bills');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -207,8 +207,8 @@ class BillController extends Controller
* *
* @param BillRequest $request * @param BillRequest $request
* *
* @throws FireflyException
* @return JsonResponse * @return JsonResponse
* @throws FireflyException
*/ */
public function store(BillRequest $request): JsonResponse public function store(BillRequest $request): JsonResponse
{ {
@@ -221,7 +221,7 @@ class BillController extends Controller
$resource = new Item($bill, $transformer, 'bills'); $resource = new Item($bill, $transformer, 'bills');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -279,7 +279,7 @@ class BillController extends Controller
$resource = new FractalCollection($transactions, $transformer, 'transactions'); $resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -302,7 +302,7 @@ class BillController extends Controller
$resource = new Item($bill, $transformer, 'bills'); $resource = new Item($bill, $transformer, 'bills');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -23,8 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers; namespace FireflyIII\Api\V1\Controllers;
use Exception;
use FireflyIII\Api\V1\Requests\BudgetLimitRequest;
use FireflyIII\Api\V1\Requests\BudgetStoreRequest; use FireflyIII\Api\V1\Requests\BudgetStoreRequest;
use FireflyIII\Api\V1\Requests\BudgetUpdateRequest; use FireflyIII\Api\V1\Requests\BudgetUpdateRequest;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
@@ -109,7 +107,7 @@ class BudgetController extends Controller
$resource = new FractalCollection($budgetLimits, $transformer, 'budget_limits'); $resource = new FractalCollection($budgetLimits, $transformer, 'budget_limits');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -138,7 +136,7 @@ class BudgetController extends Controller
$resource = new FractalCollection($attachments, $transformer, 'attachments'); $resource = new FractalCollection($attachments, $transformer, 'attachments');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -185,7 +183,7 @@ class BudgetController extends Controller
$resource = new FractalCollection($budgets, $transformer, 'budgets'); $resource = new FractalCollection($budgets, $transformer, 'budgets');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -206,7 +204,7 @@ class BudgetController extends Controller
$resource = new Item($budget, $transformer, 'budgets'); $resource = new Item($budget, $transformer, 'budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -214,9 +212,9 @@ class BudgetController extends Controller
* *
* @param BudgetStoreRequest $request * @param BudgetStoreRequest $request
* *
* @return JsonResponse
* @throws FireflyException * @throws FireflyException
* *
* @return JsonResponse
*/ */
public function store(BudgetStoreRequest $request): JsonResponse public function store(BudgetStoreRequest $request): JsonResponse
{ {
@@ -229,7 +227,7 @@ class BudgetController extends Controller
$resource = new Item($budget, $transformer, 'budgets'); $resource = new Item($budget, $transformer, 'budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -293,7 +291,7 @@ class BudgetController extends Controller
$resource = new FractalCollection($transactions, $transformer, 'transactions'); $resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -316,7 +314,7 @@ class BudgetController extends Controller
$resource = new Item($budget, $transformer, 'budgets'); $resource = new Item($budget, $transformer, 'budgets');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }

View File

@@ -129,7 +129,7 @@ class BudgetLimitController extends Controller
$resource = new FractalCollection($budgetLimits, $transformer, 'budget_limits'); $resource = new FractalCollection($budgetLimits, $transformer, 'budget_limits');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -150,7 +150,7 @@ class BudgetLimitController extends Controller
$resource = new Item($budgetLimit, $transformer, 'budget_limits'); $resource = new Item($budgetLimit, $transformer, 'budget_limits');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -178,7 +178,7 @@ class BudgetLimitController extends Controller
$resource = new Item($budgetLimit, $transformer, 'budget_limits'); $resource = new Item($budgetLimit, $transformer, 'budget_limits');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -231,7 +231,7 @@ class BudgetLimitController extends Controller
$resource = new FractalCollection($transactions, $transformer, 'transactions'); $resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -244,9 +244,9 @@ class BudgetLimitController extends Controller
*/ */
public function update(BudgetLimitRequest $request, BudgetLimit $budgetLimit): JsonResponse public function update(BudgetLimitRequest $request, BudgetLimit $budgetLimit): JsonResponse
{ {
$data = $request->getAll(); $data = $request->getAll();
$budgetLimit = $this->blRepository->update($budgetLimit, $data); $budgetLimit = $this->blRepository->update($budgetLimit, $data);
$manager = $this->getManager(); $manager = $this->getManager();
/** @var BudgetLimitTransformer $transformer */ /** @var BudgetLimitTransformer $transformer */
$transformer = app(BudgetLimitTransformer::class); $transformer = app(BudgetLimitTransformer::class);
@@ -254,7 +254,7 @@ class BudgetLimitController extends Controller
$resource = new Item($budgetLimit, $transformer, 'budget_limits'); $resource = new Item($budgetLimit, $transformer, 'budget_limits');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -99,7 +99,7 @@ class CategoryController extends Controller
$resource = new FractalCollection($attachments, $transformer, 'attachments'); $resource = new FractalCollection($attachments, $transformer, 'attachments');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -147,7 +147,7 @@ class CategoryController extends Controller
$resource = new FractalCollection($categories, $transformer, 'categories'); $resource = new FractalCollection($categories, $transformer, 'categories');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -169,7 +169,7 @@ class CategoryController extends Controller
$resource = new Item($category, $transformer, 'categories'); $resource = new Item($category, $transformer, 'categories');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -177,8 +177,8 @@ class CategoryController extends Controller
* *
* @param CategoryRequest $request * @param CategoryRequest $request
* *
* @throws FireflyException
* @return JsonResponse * @return JsonResponse
* @throws FireflyException
*/ */
public function store(CategoryRequest $request): JsonResponse public function store(CategoryRequest $request): JsonResponse
{ {
@@ -191,7 +191,7 @@ class CategoryController extends Controller
$resource = new Item($category, $transformer, 'categories'); $resource = new Item($category, $transformer, 'categories');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -247,7 +247,7 @@ class CategoryController extends Controller
$resource = new FractalCollection($transactions, $transformer, 'transactions'); $resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -270,7 +270,7 @@ class CategoryController extends Controller
$resource = new Item($category, $transformer, 'categories'); $resource = new Item($category, $transformer, 'categories');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }

View File

@@ -31,7 +31,6 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface; use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
/** /**
* Class AvailableBudgetController * Class AvailableBudgetController

View File

@@ -58,13 +58,10 @@ class BudgetController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
//$this->generator = app(GeneratorInterface::class);
$this->repository = app(BudgetRepositoryInterface::class); $this->repository = app(BudgetRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class);
$this->blRepository = app(BudgetLimitRepositoryInterface::class); $this->blRepository = app(BudgetLimitRepositoryInterface::class);
//$this->nbRepository = app(NoBudgetRepositoryInterface::class);
return $next($request); return $next($request);
} }
); );
@@ -134,94 +131,6 @@ class BudgetController extends Controller
return $arr; return $arr;
} }
/**
* @param array $budgetNames
* @param array $currencyNames
*
* @return array
*/
private function createSets(array $budgetNames, array $currencyNames): array
{
$return = [];
foreach ($currencyNames as $currencyName) {
$entries = [];
foreach ($budgetNames as $budgetName) {
$label = sprintf('%s (%s)', $budgetName, $currencyName);
$entries[$label] = '0';
}
// left
$return['left'] = [
'label' => sprintf('%s (%s)', trans('firefly.left'), $currencyName),
'data_type' => 'left',
'currency_name' => $currencyName,
'type' => 'bar',
'yAxisID' => 0, // 0, 1, 2
'entries' => $entries,
];
// spent_capped
$return['spent_capped'] = [
'label' => sprintf('%s (%s)', trans('firefly.spent'), $currencyName),
'data_type' => 'spent_capped',
'currency_name' => $currencyName,
'type' => 'bar',
'yAxisID' => 0, // 0, 1, 2
'entries' => $entries,
];
// overspent
$return['overspent'] = [
'label' => sprintf('%s (%s)', trans('firefly.overspent'), $currencyName),
'data_type' => 'overspent',
'currency_name' => $currencyName,
'type' => 'bar',
'yAxisID' => 0, // 0, 1, 2
'entries' => $entries,
];
}
return $return;
}
/**
* @param array $basic
* @param array $sets
*
* @return array
*/
private function fillSets(array $basic, array $sets): array
{
foreach ($sets as $set) {
$label = $set['label'];
//$basic['spent']['entries'][$label] = $set['entries']['spent'];
$basic['spent_capped']['entries'][$label] = $set['entries']['spent_capped'];
$basic['left']['entries'][$label] = $set['entries']['left'];
$basic['overspent']['entries'][$label] = $set['entries']['overspent'];
}
return $basic;
}
/**
* @param array $expenses
*
* @return array
*/
private function filterNulls(array $expenses): array
{
$return = [];
/** @var array|null $arr */
foreach ($expenses as $arr) {
if ([] !== $arr) {
$return[] = $arr;
}
}
return $return;
}
/** /**
* @param Budget $budget * @param Budget $budget
* @param Carbon $start * @param Carbon $start
@@ -292,10 +201,97 @@ class BudgetController extends Controller
$return['entries']['spent'] = $sumSpent; $return['entries']['spent'] = $sumSpent;
$return['entries']['amount'] = $limit->amount; $return['entries']['amount'] = $limit->amount;
$return['entries']['spent_capped'] = 1 === bccomp($sumSpent, $limit->amount) ? $limit->amount : $sumSpent; $return['entries']['spent_capped'] = 1 === bccomp($sumSpent, $limit->amount) ? $limit->amount : $sumSpent;
$return['entries']['left'] = 1 === bccomp($limit->amount, $sumSpent) ? bcadd($set['sum'], $limit->amount) : '0'; // left $return['entries']['left'] = 1 === bccomp($limit->amount, $sumSpent) ? bcadd($set['sum'], $limit->amount) : '0'; // left
$return['entries']['overspent'] = 1 === bccomp($limit->amount, $sumSpent) ? '0' : bcmul(bcadd($set['sum'], $limit->amount), '-1'); // overspent $return['entries']['overspent'] = 1 === bccomp($limit->amount, $sumSpent) ? '0' : bcmul(bcadd($set['sum'], $limit->amount), '-1'); // overspent
return $return; return $return;
} }
/**
* @param array $expenses
*
* @return array
*/
private function filterNulls(array $expenses): array
{
$return = [];
/** @var array|null $arr */
foreach ($expenses as $arr) {
if ([] !== $arr) {
$return[] = $arr;
}
}
return $return;
}
/**
* @param array $budgetNames
* @param array $currencyNames
*
* @return array
*/
private function createSets(array $budgetNames, array $currencyNames): array
{
$return = [];
foreach ($currencyNames as $currencyName) {
$entries = [];
foreach ($budgetNames as $budgetName) {
$label = sprintf('%s (%s)', $budgetName, $currencyName);
$entries[$label] = '0';
}
// left
$return['left'] = [
'label' => sprintf('%s (%s)', trans('firefly.left'), $currencyName),
'data_type' => 'left',
'currency_name' => $currencyName,
'type' => 'bar',
'yAxisID' => 0, // 0, 1, 2
'entries' => $entries,
];
// spent_capped
$return['spent_capped'] = [
'label' => sprintf('%s (%s)', trans('firefly.spent'), $currencyName),
'data_type' => 'spent_capped',
'currency_name' => $currencyName,
'type' => 'bar',
'yAxisID' => 0, // 0, 1, 2
'entries' => $entries,
];
// overspent
$return['overspent'] = [
'label' => sprintf('%s (%s)', trans('firefly.overspent'), $currencyName),
'data_type' => 'overspent',
'currency_name' => $currencyName,
'type' => 'bar',
'yAxisID' => 0, // 0, 1, 2
'entries' => $entries,
];
}
return $return;
}
/**
* @param array $basic
* @param array $sets
*
* @return array
*/
private function fillSets(array $basic, array $sets): array
{
foreach ($sets as $set) {
$label = $set['label'];
$basic['spent_capped']['entries'][$label] = $set['entries']['spent_capped'];
$basic['left']['entries'][$label] = $set['entries']['left'];
$basic['overspent']['entries'][$label] = $set['entries']['overspent'];
}
return $basic;
}
} }

View File

@@ -88,17 +88,17 @@ class CategoryController extends Controller
$end = $dates['end']; $end = $dates['end'];
$tempData = []; $tempData = [];
$spentWith = $this->opsRepository->listExpenses($start, $end); $spentWith = $this->opsRepository->listExpenses($start, $end);
$spentWithout = $this->noCatRepository->listExpenses($start, $end); $spentWithout = $this->noCatRepository->listExpenses($start, $end);
$categories = []; $categories = [];
foreach ([$spentWith, $spentWithout, ] as $set) { foreach ([$spentWith, $spentWithout,] as $set) {
foreach ($set as $currency) { foreach ($set as $currency) {
foreach ($currency['categories'] as $category) { foreach ($currency['categories'] as $category) {
$categories[] = $category['name']; $categories[] = $category['name'];
$outKey = sprintf('%d-e', $currency['currency_id']); $outKey = sprintf('%d-e', $currency['currency_id']);
$tempData[$outKey] = $tempData[$outKey] ?? [ $tempData[$outKey] = $tempData[$outKey] ?? [
'currency_id' => $currency['currency_id'], 'currency_id' => $currency['currency_id'],
'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]), 'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]),

View File

@@ -71,24 +71,7 @@ class ConfigurationController extends Controller
{ {
$configData = $this->getConfigData(); $configData = $this->getConfigData();
return response()->json(['data' => $configData])->header('Content-Type', 'application/vnd.api+json'); return response()->json(['data' => $configData])->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Update the configuration.
*
* @param ConfigurationRequest $request
* @param string $name
*
* @return JsonResponse
*/
public function update(ConfigurationRequest $request, string $name): JsonResponse
{
$data = $request->getAll();
app('fireflyconfig')->set($name, $data['value']);
$configData = $this->getConfigData();
return response()->json(['data' => $configData])->header('Content-Type', 'application/vnd.api+json');
} }
/** /**
@@ -114,4 +97,21 @@ class ConfigurationController extends Controller
'single_user_mode' => null === $singleUser ? null : $singleUser->data, 'single_user_mode' => null === $singleUser ? null : $singleUser->data,
]; ];
} }
/**
* Update the configuration.
*
* @param ConfigurationRequest $request
* @param string $name
*
* @return JsonResponse
*/
public function update(ConfigurationRequest $request, string $name): JsonResponse
{
$data = $request->getAll();
app('fireflyconfig')->set($name, $data['value']);
$configData = $this->getConfigData();
return response()->json(['data' => $configData])->header('Content-Type', self::CONTENT_TYPE);
}
} }

View File

@@ -44,9 +44,9 @@ abstract class Controller extends BaseController
{ {
use AuthorizesRequests, DispatchesJobs, ValidatesRequests; use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected const CONTENT_TYPE = 'application/vnd.api+json';
protected ParameterBag $parameters; protected ParameterBag $parameters;
/** /**
* Controller constructor. * Controller constructor.
*/ */
@@ -60,46 +60,11 @@ abstract class Controller extends BaseController
$language = app('steam')->getLanguage(); $language = app('steam')->getLanguage();
app()->setLocale($language); app()->setLocale($language);
} }
return $next($request); return $next($request);
});
}
/**
* Method to help build URI's.
*
* @return string
*/
final protected function buildParams(): string
{
$return = '?';
$params = [];
foreach ($this->parameters as $key => $value) {
if ('page' === $key) {
continue;
} }
if ($value instanceof Carbon) { );
$params[$key] = $value->format('Y-m-d');
continue;
}
$params[$key] = $value;
}
$return .= http_build_query($params);
return $return;
}
/**
* @return Manager
*/
final protected function getManager(): Manager
{
// create some objects:
$manager = new Manager;
$baseUrl = request()->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
return $manager;
} }
/** /**
@@ -110,7 +75,7 @@ abstract class Controller extends BaseController
private function getParameters(): ParameterBag private function getParameters(): ParameterBag
{ {
$bag = new ParameterBag; $bag = new ParameterBag;
$page = (int) request()->get('page'); $page = (int)request()->get('page');
if (0 === $page) { if (0 === $page) {
$page = 1; $page = 1;
} }
@@ -137,11 +102,47 @@ abstract class Controller extends BaseController
foreach ($integers as $integer) { foreach ($integers as $integer) {
$value = request()->query->get($integer); $value = request()->query->get($integer);
if (null !== $value) { if (null !== $value) {
$bag->set($integer, (int) $value); $bag->set($integer, (int)$value);
} }
} }
return $bag; return $bag;
} }
/**
* Method to help build URI's.
*
* @return string
*/
final protected function buildParams(): string
{
$return = '?';
$params = [];
foreach ($this->parameters as $key => $value) {
if ('page' === $key) {
continue;
}
if ($value instanceof Carbon) {
$params[$key] = $value->format('Y-m-d');
continue;
}
$params[$key] = $value;
}
return $return . http_build_query($params);
}
/**
* @return Manager
*/
final protected function getManager(): Manager
{
// create some objects:
$manager = new Manager;
$baseUrl = request()->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
return $manager;
}
} }

View File

@@ -37,7 +37,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface; use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface; use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface; use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
@@ -68,11 +67,8 @@ class CurrencyController extends Controller
{ {
use AccountFilter, TransactionFilter; use AccountFilter, TransactionFilter;
/** @var CurrencyRepositoryInterface The currency repository */ private CurrencyRepositoryInterface $repository;
private $repository; private UserRepositoryInterface $userRepository;
/** @var UserRepositoryInterface The user repository */
private $userRepository;
/** /**
@@ -148,7 +144,7 @@ class CurrencyController extends Controller
$resource = new FractalCollection($accounts, $transformer, 'accounts'); $resource = new FractalCollection($accounts, $transformer, 'accounts');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -161,22 +157,14 @@ class CurrencyController extends Controller
*/ */
public function availableBudgets(TransactionCurrency $currency): JsonResponse public function availableBudgets(TransactionCurrency $currency): JsonResponse
{ {
/** @var User $admin */
$admin = auth()->user();
$manager = $this->getManager(); $manager = $this->getManager();
// types to get, page size: // types to get, page size:
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of available budgets. Count it and split it. // get list of available budgets. Count it and split it.
/** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class);
/** @var AvailableBudgetRepositoryInterface $abRepository */ /** @var AvailableBudgetRepositoryInterface $abRepository */
$abRepository = app(AvailableBudgetRepositoryInterface::class); $abRepository = app(AvailableBudgetRepositoryInterface::class);
$repository->setUser($admin);
$collection = $abRepository->getAvailableBudgetsByCurrency($currency); $collection = $abRepository->getAvailableBudgetsByCurrency($currency);
$count = $collection->count(); $count = $collection->count();
$availableBudgets = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $availableBudgets = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
@@ -193,7 +181,7 @@ class CurrencyController extends Controller
$resource = new FractalCollection($availableBudgets, $transformer, 'available_budgets'); $resource = new FractalCollection($availableBudgets, $transformer, 'available_budgets');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -208,10 +196,10 @@ class CurrencyController extends Controller
{ {
$manager = $this->getManager(); $manager = $this->getManager();
/** @var BillRepositoryInterface $repository */ /** @var BillRepositoryInterface $billRepos */
$repository = app(BillRepositoryInterface::class); $billRepos = app(BillRepositoryInterface::class);
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
$unfiltered = $repository->getBills(); $unfiltered = $billRepos->getBills();
// filter and paginate list: // filter and paginate list:
$collection = $unfiltered->filter( $collection = $unfiltered->filter(
@@ -233,7 +221,7 @@ class CurrencyController extends Controller
$resource = new FractalCollection($bills, $transformer, 'bills'); $resource = new FractalCollection($bills, $transformer, 'bills');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -264,7 +252,7 @@ class CurrencyController extends Controller
$resource = new FractalCollection($budgetLimits, $transformer, 'budget_limits'); $resource = new FractalCollection($budgetLimits, $transformer, 'budget_limits');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -295,7 +283,7 @@ class CurrencyController extends Controller
$resource = new FractalCollection($exchangeRates, $transformer, 'currency_exchange_rates'); $resource = new FractalCollection($exchangeRates, $transformer, 'currency_exchange_rates');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -303,9 +291,9 @@ class CurrencyController extends Controller
* *
* @param TransactionCurrency $currency * @param TransactionCurrency $currency
* *
* @return JsonResponse
* @throws FireflyException * @throws FireflyException
* @codeCoverageIgnore * @codeCoverageIgnore
* @return JsonResponse
*/ */
public function delete(TransactionCurrency $currency): JsonResponse public function delete(TransactionCurrency $currency): JsonResponse
{ {
@@ -354,7 +342,7 @@ class CurrencyController extends Controller
$resource = new Item($currency, $transformer, 'currencies'); $resource = new Item($currency, $transformer, 'currencies');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -380,7 +368,7 @@ class CurrencyController extends Controller
$resource = new Item($currency, $transformer, 'currencies'); $resource = new Item($currency, $transformer, 'currencies');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -412,7 +400,7 @@ class CurrencyController extends Controller
$resource = new FractalCollection($currencies, $transformer, 'currencies'); $resource = new FractalCollection($currencies, $transformer, 'currencies');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -440,7 +428,7 @@ class CurrencyController extends Controller
$resource = new Item($currency, $transformer, 'currencies'); $resource = new Item($currency, $transformer, 'currencies');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -459,9 +447,9 @@ class CurrencyController extends Controller
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it. // get list of budgets. Count it and split it.
/** @var RecurringRepositoryInterface $repository */ /** @var RecurringRepositoryInterface $recurringRepos */
$repository = app(RecurringRepositoryInterface::class); $recurringRepos = app(RecurringRepositoryInterface::class);
$unfiltered = $repository->getAll(); $unfiltered = $recurringRepos->getAll();
// filter selection // filter selection
$collection = $unfiltered->filter( $collection = $unfiltered->filter(
@@ -492,7 +480,7 @@ class CurrencyController extends Controller
$resource = new FractalCollection($piggyBanks, $transformer, 'recurrences'); $resource = new FractalCollection($piggyBanks, $transformer, 'recurrences');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -510,9 +498,9 @@ class CurrencyController extends Controller
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it. // get list of budgets. Count it and split it.
/** @var RuleRepositoryInterface $repository */ /** @var RuleRepositoryInterface $ruleRepos */
$repository = app(RuleRepositoryInterface::class); $ruleRepos = app(RuleRepositoryInterface::class);
$unfiltered = $repository->getAll(); $unfiltered = $ruleRepos->getAll();
$collection = $unfiltered->filter( $collection = $unfiltered->filter(
static function (Rule $rule) use ($currency) { static function (Rule $rule) use ($currency) {
@@ -541,7 +529,7 @@ class CurrencyController extends Controller
$resource = new FractalCollection($rules, $transformer, 'rules'); $resource = new FractalCollection($rules, $transformer, 'rules');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -565,7 +553,7 @@ class CurrencyController extends Controller
$resource = new Item($currency, $transformer, 'currencies'); $resource = new Item($currency, $transformer, 'currencies');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -586,7 +574,7 @@ class CurrencyController extends Controller
$resource = new Item($currency, $transformer, 'currencies'); $resource = new Item($currency, $transformer, 'currencies');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -594,8 +582,8 @@ class CurrencyController extends Controller
* *
* @param CurrencyRequest $request * @param CurrencyRequest $request
* *
* @throws FireflyException
* @return JsonResponse * @return JsonResponse
* @throws FireflyException
*/ */
public function store(CurrencyRequest $request): JsonResponse public function store(CurrencyRequest $request): JsonResponse
{ {
@@ -614,7 +602,7 @@ class CurrencyController extends Controller
$resource = new Item($currency, $transformer, 'currencies'); $resource = new Item($currency, $transformer, 'currencies');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -670,7 +658,7 @@ class CurrencyController extends Controller
$resource = new FractalCollection($transactions, $transformer, 'transactions'); $resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -702,7 +690,7 @@ class CurrencyController extends Controller
$resource = new Item($currency, $transformer, 'currencies'); $resource = new Item($currency, $transformer, 'currencies');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -69,8 +69,8 @@ class CurrencyExchangeRateController extends Controller
* *
* @param Request $request * @param Request $request
* *
* @throws FireflyException
* @return JsonResponse * @return JsonResponse
* @throws FireflyException
*/ */
public function index(Request $request): JsonResponse public function index(Request $request): JsonResponse
{ {
@@ -107,6 +107,6 @@ class CurrencyExchangeRateController extends Controller
$transformer->setParameters($this->parameters); $transformer->setParameters($this->parameters);
$resource = new Item($rate, $transformer, 'currency_exchange_rates'); $resource = new Item($rate, $transformer, 'currency_exchange_rates');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -160,31 +160,6 @@ class DestroyController extends Controller
return response()->json([], 204); return response()->json([], 204);
} }
/**
* @param array $types
*/
private function destroyAccounts(array $types): void
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$collection = $repository->getAccountsByType($types);
$service = app(AccountDestroyService::class);
/** @var Account $account */
foreach ($collection as $account) {
$service->destroy($account, null);
}
}
/**
*
*/
private function destroyBills(): void
{
/** @var BillRepositoryInterface $repository */
$repository = app(BillRepositoryInterface::class);
$repository->destroyAll();
}
/** /**
* *
*/ */
@@ -206,18 +181,11 @@ class DestroyController extends Controller
/** /**
* *
*/ */
private function destroyCategories(): void private function destroyBills(): void
{ {
/** @var CategoryRepositoryInterface $categoryRepos */ /** @var BillRepositoryInterface $repository */
$categoryRepos = app(CategoryRepositoryInterface::class); $repository = app(BillRepositoryInterface::class);
$categoryRepos->destroyAll(); $repository->destroyAll();
}
private function destroyObjectGroups(): void
{
/** @var ObjectGroupRepositoryInterface $repository */
$repository = app(ObjectGroupRepositoryInterface::class);
$repository->deleteAll();
} }
/** /**
@@ -230,16 +198,6 @@ class DestroyController extends Controller
$repository->destroyAll(); $repository->destroyAll();
} }
/**
*
*/
private function destroyRecurringTransactions(): void
{
/** @var RecurringRepositoryInterface $repository */
$repository = app(RecurringRepositoryInterface::class);
$repository->destroyAll();
}
/** /**
* *
*/ */
@@ -250,6 +208,26 @@ class DestroyController extends Controller
$repository->destroyAll(); $repository->destroyAll();
} }
/**
*
*/
private function destroyRecurringTransactions(): void
{
/** @var RecurringRepositoryInterface $repository */
$repository = app(RecurringRepositoryInterface::class);
$repository->destroyAll();
}
/**
*
*/
private function destroyCategories(): void
{
/** @var CategoryRepositoryInterface $categoryRepos */
$categoryRepos = app(CategoryRepositoryInterface::class);
$categoryRepos->destroyAll();
}
/** /**
* *
*/ */
@@ -260,6 +238,28 @@ class DestroyController extends Controller
$tagRepository->destroyAll(); $tagRepository->destroyAll();
} }
private function destroyObjectGroups(): void
{
/** @var ObjectGroupRepositoryInterface $repository */
$repository = app(ObjectGroupRepositoryInterface::class);
$repository->deleteAll();
}
/**
* @param array $types
*/
private function destroyAccounts(array $types): void
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$collection = $repository->getAccountsByType($types);
$service = app(AccountDestroyService::class);
/** @var Account $account */
foreach ($collection as $account) {
$service->destroy($account, null);
}
}
/** /**
* @param array $types * @param array $types
*/ */
@@ -267,10 +267,10 @@ class DestroyController extends Controller
{ {
/** @var JournalRepositoryInterface $repository */ /** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class); $repository = app(JournalRepositoryInterface::class);
$journals = $repository->findByType($types); $journals = $repository->findByType($types);
$service = app(JournalDestroyService::class); $service = app(JournalDestroyService::class);
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
foreach($journals as $journal) { foreach ($journals as $journal) {
$service->destroy($journal); $service->destroy($journal);
} }
} }

View File

@@ -80,9 +80,9 @@ class LinkTypeController extends Controller
* *
* @param LinkType $linkType * @param LinkType $linkType
* *
* @return JsonResponse
* @throws FireflyException * @throws FireflyException
* @codeCoverageIgnore * @codeCoverageIgnore
* @return JsonResponse
*/ */
public function delete(LinkType $linkType): JsonResponse public function delete(LinkType $linkType): JsonResponse
{ {
@@ -122,7 +122,7 @@ class LinkTypeController extends Controller
$resource = new FractalCollection($linkTypes, $transformer, 'link_types'); $resource = new FractalCollection($linkTypes, $transformer, 'link_types');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -143,7 +143,7 @@ class LinkTypeController extends Controller
$resource = new Item($linkType, $transformer, 'link_types'); $resource = new Item($linkType, $transformer, 'link_types');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -152,8 +152,8 @@ class LinkTypeController extends Controller
* *
* @param LinkTypeRequest $request * @param LinkTypeRequest $request
* *
* @throws FireflyException
* @return JsonResponse * @return JsonResponse
* @throws FireflyException
*/ */
public function store(LinkTypeRequest $request): JsonResponse public function store(LinkTypeRequest $request): JsonResponse
{ {
@@ -173,7 +173,7 @@ class LinkTypeController extends Controller
$transformer->setParameters($this->parameters); $transformer->setParameters($this->parameters);
$resource = new Item($linkType, $transformer, 'link_types'); $resource = new Item($linkType, $transformer, 'link_types');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -232,7 +232,7 @@ class LinkTypeController extends Controller
$resource = new FractalCollection($transactions, $transformer, 'transactions'); $resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -242,8 +242,8 @@ class LinkTypeController extends Controller
* @param LinkTypeRequest $request * @param LinkTypeRequest $request
* @param LinkType $linkType * @param LinkType $linkType
* *
* @throws FireflyException
* @return JsonResponse * @return JsonResponse
* @throws FireflyException
*/ */
public function update(LinkTypeRequest $request, LinkType $linkType): JsonResponse public function update(LinkTypeRequest $request, LinkType $linkType): JsonResponse
{ {
@@ -267,7 +267,7 @@ class LinkTypeController extends Controller
$resource = new Item($linkType, $transformer, 'link_types'); $resource = new Item($linkType, $transformer, 'link_types');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -111,7 +111,7 @@ class ObjectGroupController extends Controller
$resource = new FractalCollection($objectGroups, $transformer, 'object_groups'); $resource = new FractalCollection($objectGroups, $transformer, 'object_groups');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -147,7 +147,7 @@ class ObjectGroupController extends Controller
$resource = new FractalCollection($piggyBanks, $transformer, 'piggy_banks'); $resource = new FractalCollection($piggyBanks, $transformer, 'piggy_banks');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -167,7 +167,7 @@ class ObjectGroupController extends Controller
$transformer->setParameters($this->parameters); $transformer->setParameters($this->parameters);
$resource = new Item($objectGroup, $transformer, 'object_groups'); $resource = new Item($objectGroup, $transformer, 'object_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -190,6 +190,6 @@ class ObjectGroupController extends Controller
$transformer->setParameters($this->parameters); $transformer->setParameters($this->parameters);
$resource = new Item($objectGroup, $transformer, 'object_groups'); $resource = new Item($objectGroup, $transformer, 'object_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -109,7 +109,7 @@ class PiggyBankController extends Controller
$resource = new FractalCollection($attachments, $transformer, 'attachments'); $resource = new FractalCollection($attachments, $transformer, 'attachments');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -140,7 +140,7 @@ class PiggyBankController extends Controller
$resource = new FractalCollection($piggyBanks, $transformer, 'piggy_banks'); $resource = new FractalCollection($piggyBanks, $transformer, 'piggy_banks');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -173,7 +173,7 @@ class PiggyBankController extends Controller
$resource = new FractalCollection($events, $transformer, 'piggy_bank_events'); $resource = new FractalCollection($events, $transformer, 'piggy_bank_events');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -195,7 +195,7 @@ class PiggyBankController extends Controller
$resource = new Item($piggyBank, $transformer, 'piggy_banks'); $resource = new Item($piggyBank, $transformer, 'piggy_banks');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -204,8 +204,8 @@ class PiggyBankController extends Controller
* *
* @param PiggyBankStoreRequest $request * @param PiggyBankStoreRequest $request
* *
* @throws FireflyException
* @return JsonResponse * @return JsonResponse
* @throws FireflyException
*/ */
public function store(PiggyBankStoreRequest $request): JsonResponse public function store(PiggyBankStoreRequest $request): JsonResponse
{ {
@@ -218,7 +218,7 @@ class PiggyBankController extends Controller
$resource = new Item($piggyBank, $transformer, 'piggy_banks'); $resource = new Item($piggyBank, $transformer, 'piggy_banks');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -245,7 +245,7 @@ class PiggyBankController extends Controller
$resource = new Item($piggyBank, $transformer, 'piggy_banks'); $resource = new Item($piggyBank, $transformer, 'piggy_banks');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -101,7 +101,7 @@ class PreferenceController extends Controller
$resource = new FractalCollection($preferences, $transformer, 'preferences'); $resource = new FractalCollection($preferences, $transformer, 'preferences');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -122,7 +122,7 @@ class PreferenceController extends Controller
$resource = new Item($preference, $transformer, 'preferences'); $resource = new Item($preference, $transformer, 'preferences');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -161,7 +161,7 @@ class PreferenceController extends Controller
$resource = new Item($result, $transformer, 'preferences'); $resource = new Item($result, $transformer, 'preferences');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -119,7 +119,7 @@ class RecurrenceController extends Controller
$resource = new FractalCollection($piggyBanks, $transformer, 'recurrences'); $resource = new FractalCollection($piggyBanks, $transformer, 'recurrences');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -141,7 +141,7 @@ class RecurrenceController extends Controller
$resource = new Item($recurrence, $transformer, 'recurrences'); $resource = new Item($recurrence, $transformer, 'recurrences');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -151,8 +151,8 @@ class RecurrenceController extends Controller
* *
* @param RecurrenceStoreRequest $request * @param RecurrenceStoreRequest $request
* *
* @throws FireflyException
* @return JsonResponse * @return JsonResponse
* @throws FireflyException
*/ */
public function store(RecurrenceStoreRequest $request): JsonResponse public function store(RecurrenceStoreRequest $request): JsonResponse
{ {
@@ -166,7 +166,7 @@ class RecurrenceController extends Controller
$resource = new Item($recurrence, $transformer, 'recurrences'); $resource = new Item($recurrence, $transformer, 'recurrences');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -222,13 +222,13 @@ class RecurrenceController extends Controller
$resource = new FractalCollection($transactions, $transformer, 'transactions'); $resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
* @return JsonResponse
* @throws FireflyException * @throws FireflyException
* @codeCoverageIgnore * @codeCoverageIgnore
* @return JsonResponse
*/ */
public function trigger(): JsonResponse public function trigger(): JsonResponse
{ {
@@ -238,7 +238,7 @@ class RecurrenceController extends Controller
$result = $recurring->fire(); $result = $recurring->fire();
} catch (FireflyException $e) { } catch (FireflyException $e) {
Log::error($e->getMessage()); Log::error($e->getMessage());
throw new FireflyException('200022: Error in cron job.',0, $e); throw new FireflyException('200022: Error in cron job.', 0, $e);
} }
if (false === $result) { if (false === $result) {
return response()->json([], 204); return response()->json([], 204);
@@ -270,7 +270,7 @@ class RecurrenceController extends Controller
$resource = new Item($category, $transformer, 'recurrences'); $resource = new Item($category, $transformer, 'recurrences');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -122,7 +122,7 @@ class RuleController extends Controller
$resource = new FractalCollection($rules, $transformer, 'rules'); $resource = new FractalCollection($rules, $transformer, 'rules');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -143,7 +143,7 @@ class RuleController extends Controller
$resource = new Item($rule, $transformer, 'rules'); $resource = new Item($rule, $transformer, 'rules');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -164,7 +164,7 @@ class RuleController extends Controller
$resource = new Item($rule, $transformer, 'rules'); $resource = new Item($rule, $transformer, 'rules');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -185,7 +185,7 @@ class RuleController extends Controller
$resource = new Item($rule, $transformer, 'rules'); $resource = new Item($rule, $transformer, 'rules');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -206,7 +206,7 @@ class RuleController extends Controller
$resource = new Item($rule, $transformer, 'rules'); $resource = new Item($rule, $transformer, 'rules');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -255,7 +255,7 @@ class RuleController extends Controller
$resource = new FractalCollection($transactions, $transformer, 'transactions'); $resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -315,6 +315,6 @@ class RuleController extends Controller
$resource = new Item($rule, $transformer, 'rules'); $resource = new Item($rule, $transformer, 'rules');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -122,7 +122,7 @@ class RuleGroupController extends Controller
$resource = new FractalCollection($ruleGroups, $transformer, 'rule_groups'); $resource = new FractalCollection($ruleGroups, $transformer, 'rule_groups');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -142,7 +142,7 @@ class RuleGroupController extends Controller
$resource = new Item($ruleGroup, $transformer, 'rule_groups'); $resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -162,7 +162,7 @@ class RuleGroupController extends Controller
$resource = new Item($ruleGroup, $transformer, 'rule_groups'); $resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -193,7 +193,7 @@ class RuleGroupController extends Controller
$resource = new FractalCollection($rules, $transformer, 'rules'); $resource = new FractalCollection($rules, $transformer, 'rules');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -214,7 +214,7 @@ class RuleGroupController extends Controller
$resource = new Item($ruleGroup, $transformer, 'rule_groups'); $resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -236,7 +236,7 @@ class RuleGroupController extends Controller
$resource = new Item($ruleGroup, $transformer, 'rule_groups'); $resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -291,7 +291,7 @@ class RuleGroupController extends Controller
$resource = new FractalCollection($transactions, $transformer, 'transactions'); $resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -357,6 +357,6 @@ class RuleGroupController extends Controller
$resource = new Item($ruleGroup, $transformer, 'rule_groups'); $resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -97,6 +97,6 @@ class AccountController extends Controller
$resource = new FractalCollection($accounts, $transformer, 'accounts'); $resource = new FractalCollection($accounts, $transformer, 'accounts');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -45,7 +45,7 @@ class TransactionController extends Controller
*/ */
public function search(Request $request, SearchInterface $searcher): JsonResponse public function search(Request $request, SearchInterface $searcher): JsonResponse
{ {
$manager = $this->getManager(); $manager = $this->getManager();
$fullQuery = (string) $request->get('query'); $fullQuery = (string) $request->get('query');
$page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page'); $page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');
@@ -65,6 +65,6 @@ class TransactionController extends Controller
$resource = new Collection($transactions, $transformer, 'transactions'); $resource = new Collection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($groups)); $resource->setPaginator(new IlluminatePaginatorAdapter($groups));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -101,8 +101,8 @@ class SummaryController extends Controller
/** /**
* @param DateRequest $request * @param DateRequest $request
* *
* @throws Exception
* @return JsonResponse * @return JsonResponse
* @throws Exception
*/ */
public function basic(DateRequest $request): JsonResponse public function basic(DateRequest $request): JsonResponse
{ {
@@ -130,30 +130,6 @@ class SummaryController extends Controller
return response()->json($return); return response()->json($return);
} }
/**
* Check if date is outside session range.
*
* @param Carbon $date
*
* @param Carbon $start
* @param Carbon $end
*
* @return bool
*/
protected function notInDateRange(Carbon $date, Carbon $start, Carbon $end): bool // Validate a preference
{
$result = false;
if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) {
$result = true;
}
// start and end in the past? use $end
if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) {
$result = true;
}
return $result;
}
/** /**
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
@@ -322,8 +298,8 @@ class SummaryController extends Controller
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* *
* @throws Exception
* @return array * @return array
* @throws Exception
*/ */
private function getLeftToSpendInfo(Carbon $start, Carbon $end): array private function getLeftToSpendInfo(Carbon $start, Carbon $end): array
{ {
@@ -429,4 +405,28 @@ class SummaryController extends Controller
return $return; return $return;
} }
/**
* Check if date is outside session range.
*
* @param Carbon $date
*
* @param Carbon $start
* @param Carbon $end
*
* @return bool
*/
protected function notInDateRange(Carbon $date, Carbon $start, Carbon $end): bool // Validate a preference
{
$result = false;
if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) {
$result = true;
}
// start and end in the past? use $end
if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) {
$result = true;
}
return $result;
}
} }

View File

@@ -115,7 +115,7 @@ class TagController extends Controller
$resource = new FractalCollection($rules, $transformer, 'tags'); $resource = new FractalCollection($rules, $transformer, 'tags');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -145,7 +145,7 @@ class TagController extends Controller
$resource = new FractalCollection($attachments, $transformer, 'attachments'); $resource = new FractalCollection($attachments, $transformer, 'attachments');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -165,7 +165,7 @@ class TagController extends Controller
$resource = new Item($tag, $transformer, 'tags'); $resource = new Item($tag, $transformer, 'tags');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -186,7 +186,7 @@ class TagController extends Controller
$resource = new Item($rule, $transformer, 'tags'); $resource = new Item($rule, $transformer, 'tags');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -239,7 +239,7 @@ class TagController extends Controller
$resource = new FractalCollection($transactions, $transformer, 'transactions'); $resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -260,7 +260,7 @@ class TagController extends Controller
$resource = new Item($rule, $transformer, 'tags'); $resource = new Item($rule, $transformer, 'tags');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -50,6 +50,7 @@ use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item; use League\Fractal\Resource\Item;
use Log; use Log;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* Class TransactionController * Class TransactionController
*/ */
@@ -107,7 +108,7 @@ class TransactionController extends Controller
$resource = new FractalCollection($attachments, $transformer, 'attachments'); $resource = new FractalCollection($attachments, $transformer, 'attachments');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -127,7 +128,7 @@ class TransactionController extends Controller
$resource = new FractalCollection($journalLinks, $transformer, 'transaction_links'); $resource = new FractalCollection($journalLinks, $transformer, 'transaction_links');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -208,7 +209,7 @@ class TransactionController extends Controller
$resource = new FractalCollection($transactions, $transformer, 'transactions'); $resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -231,7 +232,20 @@ class TransactionController extends Controller
$resource = new FractalCollection($events, $transformer, 'piggy_bank_events'); $resource = new FractalCollection($events, $transformer, 'piggy_bank_events');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Show a single transaction, by transaction journal.
*
* @param TransactionJournal $transactionJournal
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function showByJournal(TransactionJournal $transactionJournal): JsonResponse
{
return $this->show($transactionJournal->transactionGroup);
} }
/** /**
@@ -266,20 +280,7 @@ class TransactionController extends Controller
$transformer->setParameters($this->parameters); $transformer->setParameters($this->parameters);
$resource = new Item($selectedGroup, $transformer, 'transactions'); $resource = new Item($selectedGroup, $transformer, 'transactions');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Show a single transaction, by transaction journal.
*
* @param TransactionJournal $transactionJournal
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function showByJournal(TransactionJournal $transactionJournal): JsonResponse
{
return $this->show($transactionJournal->transactionGroup);
} }
/** /**
@@ -352,7 +353,7 @@ class TransactionController extends Controller
$transformer->setParameters($this->parameters); $transformer->setParameters($this->parameters);
$resource = new Item($selectedGroup, $transformer, 'transactions'); $resource = new Item($selectedGroup, $transformer, 'transactions');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -395,6 +396,6 @@ class TransactionController extends Controller
$transformer->setParameters($this->parameters); $transformer->setParameters($this->parameters);
$resource = new Item($selectedGroup, $transformer, 'transactions'); $resource = new Item($selectedGroup, $transformer, 'transactions');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -126,7 +126,7 @@ class TransactionLinkController extends Controller
$resource = new FractalCollection($journalLinks, $transformer, 'transaction_links'); $resource = new FractalCollection($journalLinks, $transformer, 'transaction_links');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -148,7 +148,7 @@ class TransactionLinkController extends Controller
$resource = new Item($journalLink, $transformer, 'transaction_links'); $resource = new Item($journalLink, $transformer, 'transaction_links');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
@@ -157,8 +157,8 @@ class TransactionLinkController extends Controller
* *
* @param TransactionLinkRequest $request * @param TransactionLinkRequest $request
* *
* @throws FireflyException
* @return JsonResponse * @return JsonResponse
* @throws FireflyException
*/ */
public function store(TransactionLinkRequest $request): JsonResponse public function store(TransactionLinkRequest $request): JsonResponse
{ {
@@ -179,7 +179,7 @@ class TransactionLinkController extends Controller
$resource = new Item($journalLink, $transformer, 'transaction_links'); $resource = new Item($journalLink, $transformer, 'transaction_links');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -188,8 +188,8 @@ class TransactionLinkController extends Controller
* @param TransactionLinkRequest $request * @param TransactionLinkRequest $request
* @param TransactionJournalLink $journalLink * @param TransactionJournalLink $journalLink
* *
* @throws FireflyException
* @return JsonResponse * @return JsonResponse
* @throws FireflyException
*/ */
public function update(TransactionLinkRequest $request, TransactionJournalLink $journalLink): JsonResponse public function update(TransactionLinkRequest $request, TransactionJournalLink $journalLink): JsonResponse
{ {
@@ -209,7 +209,7 @@ class TransactionLinkController extends Controller
$resource = new Item($journalLink, $transformer, 'transaction_links'); $resource = new Item($journalLink, $transformer, 'transaction_links');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
} }

View File

@@ -68,9 +68,9 @@ class UserController extends Controller
* *
* @param User $user * @param User $user
* *
* @return JsonResponse
* @throws FireflyException * @throws FireflyException
* @codeCoverageIgnore * @codeCoverageIgnore
* @return JsonResponse
*/ */
public function delete(User $user): JsonResponse public function delete(User $user): JsonResponse
{ {
@@ -113,7 +113,7 @@ class UserController extends Controller
$resource = new FractalCollection($users, $transformer, 'users'); $resource = new FractalCollection($users, $transformer, 'users');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -135,7 +135,7 @@ class UserController extends Controller
$resource = new Item($user, $transformer, 'users'); $resource = new Item($user, $transformer, 'users');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -159,7 +159,7 @@ class UserController extends Controller
$resource = new Item($user, $transformer, 'users'); $resource = new Item($user, $transformer, 'users');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }
/** /**
@@ -182,7 +182,7 @@ class UserController extends Controller
$resource = new Item($user, $transformer, 'users'); $resource = new Item($user, $transformer, 'users');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
} }

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Middleware; namespace FireflyIII\Api\V1\Middleware;
use Closure; use Closure;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;

View File

@@ -132,8 +132,6 @@ class AccountStoreRequest extends FormRequest
'interest_period' => 'required_if:type,liability|in:daily,monthly,yearly', 'interest_period' => 'required_if:type,liability|in:daily,monthly,yearly',
'notes' => 'min:0|max:65536', 'notes' => 'min:0|max:65536',
]; ];
$rules = Location::requestRules($rules); return Location::requestRules($rules);
return $rules;
} }
} }

View File

@@ -38,6 +38,7 @@ use Illuminate\Foundation\Http\FormRequest;
class AccountUpdateRequest extends FormRequest class AccountUpdateRequest extends FormRequest
{ {
use ConvertsDataTypes, AppendsLocationData; use ConvertsDataTypes, AppendsLocationData;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *
@@ -133,8 +134,6 @@ class AccountUpdateRequest extends FormRequest
'interest_period' => 'required_if:type,liability|in:daily,monthly,yearly', 'interest_period' => 'required_if:type,liability|in:daily,monthly,yearly',
'notes' => 'min:0|max:65536', 'notes' => 'min:0|max:65536',
]; ];
$rules = Location::requestRules($rules); return Location::requestRules($rules);
return $rules;
} }
} }

View File

@@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest;
class AttachmentStoreRequest extends FormRequest class AttachmentStoreRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -34,6 +34,7 @@ use Illuminate\Foundation\Http\FormRequest;
class AttachmentUpdateRequest extends FormRequest class AttachmentUpdateRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Autocomplete; namespace FireflyIII\Api\V1\Requests\Autocomplete;
use FireflyIII\Models\AccountType;
use FireflyIII\Support\Request\ConvertsDataTypes; use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
@@ -58,6 +59,9 @@ class AutocompleteRequest extends FormRequest
$limit = $this->integer('limit'); $limit = $this->integer('limit');
$limit = 0 === $limit ? 10 : $limit; $limit = 0 === $limit ? 10 : $limit;
// remove 'initial balance' from allowed types. its internal
$array = array_diff($array, [AccountType::INITIAL_BALANCE]);
return [ return [
'types' => $array, 'types' => $array,
'query' => $this->string('query'), 'query' => $this->string('query'),

View File

@@ -34,6 +34,7 @@ use Illuminate\Foundation\Http\FormRequest;
class AvailableBudgetRequest extends FormRequest class AvailableBudgetRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -39,6 +39,7 @@ use Illuminate\Validation\Validator;
class BillRequest extends FormRequest class BillRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -37,6 +37,7 @@ use Illuminate\Validation\Validator;
class BudgetStoreRequest extends FormRequest class BudgetStoreRequest extends FormRequest
{ {
use ConvertsDataTypes, ValidatesAutoBudgetRequest; use ConvertsDataTypes, ValidatesAutoBudgetRequest;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -37,6 +37,7 @@ use Illuminate\Validation\Validator;
class BudgetUpdateRequest extends FormRequest class BudgetUpdateRequest extends FormRequest
{ {
use ConvertsDataTypes, ValidatesAutoBudgetRequest; use ConvertsDataTypes, ValidatesAutoBudgetRequest;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -36,6 +36,7 @@ use Illuminate\Foundation\Http\FormRequest;
class CategoryRequest extends FormRequest class CategoryRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -36,6 +36,7 @@ use Illuminate\Foundation\Http\FormRequest;
class ConfigurationRequest extends FormRequest class ConfigurationRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *
@@ -56,6 +57,8 @@ class ConfigurationRequest extends FormRequest
{ {
$name = $this->route()->parameter('configName'); $name = $this->route()->parameter('configName');
switch ($name) { switch ($name) {
default:
break;
case 'is_demo_site': case 'is_demo_site':
case 'single_user_mode': case 'single_user_mode':
return ['value' => $this->boolean('value')]; return ['value' => $this->boolean('value')];
@@ -75,6 +78,8 @@ class ConfigurationRequest extends FormRequest
{ {
$name = $this->route()->parameter('configName'); $name = $this->route()->parameter('configName');
switch ($name) { switch ($name) {
default:
break;
case 'is_demo_site': case 'is_demo_site':
case 'single_user_mode': case 'single_user_mode':
return ['value' => ['required', new IsBoolean]]; return ['value' => ['required', new IsBoolean]];

View File

@@ -37,6 +37,7 @@ use Illuminate\Foundation\Http\FormRequest;
class CurrencyRequest extends FormRequest class CurrencyRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -32,6 +32,7 @@ use Illuminate\Foundation\Http\FormRequest;
class DataDestroyRequest extends FormRequest class DataDestroyRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *
@@ -64,7 +65,7 @@ class DataDestroyRequest extends FormRequest
',accounts,asset_accounts,expense_accounts,revenue_accounts,liabilities,transactions,withdrawals,deposits,transfers'; ',accounts,asset_accounts,expense_accounts,revenue_accounts,liabilities,transactions,withdrawals,deposits,transfers';
return [ return [
'objects' => sprintf('min:1|string|in:%s', $valid), 'objects' => sprintf('required|min:1|string|in:%s', $valid),
]; ];
} }
} }

View File

@@ -36,6 +36,7 @@ use Illuminate\Foundation\Http\FormRequest;
class DateRequest extends FormRequest class DateRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -37,6 +37,7 @@ use Illuminate\Validation\Rule;
class LinkTypeRequest extends FormRequest class LinkTypeRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest;
class ObjectGroupUpdateRequest extends FormRequest class ObjectGroupUpdateRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest;
class PiggyBankStoreRequest extends FormRequest class PiggyBankStoreRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -40,6 +40,7 @@ use Illuminate\Validation\Validator;
class RecurrenceStoreRequest extends FormRequest class RecurrenceStoreRequest extends FormRequest
{ {
use ConvertsDataTypes, RecurrenceValidation, TransactionValidation, CurrencyValidation, GetRecurrenceData; use ConvertsDataTypes, RecurrenceValidation, TransactionValidation, CurrencyValidation, GetRecurrenceData;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *
@@ -83,6 +84,56 @@ class RecurrenceStoreRequest extends FormRequest
]; ];
} }
/**
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
*
* @return array
*/
private function getTransactionData(): array
{
$return = [];
// transaction data:
/** @var array $transactions */
$transactions = $this->get('transactions');
if (null === $transactions) {
return [];
}
/** @var array $transaction */
foreach ($transactions as $transaction) {
$return[] = $this->getSingleRecurrenceData($transaction);
}
return $return;
}
/**
* Returns the repetition data as it is found in the submitted data.
*
* @return array
*/
private function getRepetitionData(): array
{
$return = [];
// repetition data:
/** @var array $repetitions */
$repetitions = $this->get('repetitions');
if (null === $repetitions) {
return [];
}
/** @var array $repetition */
foreach ($repetitions as $repetition) {
$return[] = [
'type' => $repetition['type'],
'moment' => $repetition['moment'],
'skip' => (int) $repetition['skip'],
'weekend' => (int) $repetition['weekend'],
];
}
return $return;
}
/** /**
* The rules that the incoming request must be matched against. * The rules that the incoming request must be matched against.
* *
@@ -150,54 +201,4 @@ class RecurrenceStoreRequest extends FormRequest
} }
); );
} }
/**
* Returns the repetition data as it is found in the submitted data.
*
* @return array
*/
private function getRepetitionData(): array
{
$return = [];
// repetition data:
/** @var array $repetitions */
$repetitions = $this->get('repetitions');
if (null === $repetitions) {
return [];
}
/** @var array $repetition */
foreach ($repetitions as $repetition) {
$return[] = [
'type' => $repetition['type'],
'moment' => $repetition['moment'],
'skip' => (int) $repetition['skip'],
'weekend' => (int) $repetition['weekend'],
];
}
return $return;
}
/**
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
*
* @return array
*/
private function getTransactionData(): array
{
$return = [];
// transaction data:
/** @var array $transactions */
$transactions = $this->get('transactions');
if (null === $transactions) {
return [];
}
/** @var array $transaction */
foreach ($transactions as $transaction) {
$return[] = $this->getSingleRecurrenceData($transaction);
}
return $return;
}
} }

View File

@@ -85,6 +85,56 @@ class RecurrenceUpdateRequest extends FormRequest
]; ];
} }
/**
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
*
* @return array
*/
private function getTransactionData(): array
{
$return = [];
// transaction data:
/** @var array $transactions */
$transactions = $this->get('transactions');
if (null === $transactions) {
return [];
}
/** @var array $transaction */
foreach ($transactions as $transaction) {
$return[] = $this->getSingleRecurrenceData($transaction);
}
return $return;
}
/**
* Returns the repetition data as it is found in the submitted data.
*
* @return array
*/
private function getRepetitionData(): array
{
$return = [];
// repetition data:
/** @var array $repetitions */
$repetitions = $this->get('repetitions');
if (null === $repetitions) {
return [];
}
/** @var array $repetition */
foreach ($repetitions as $repetition) {
$return[] = [
'type' => $repetition['type'],
'moment' => $repetition['moment'],
'skip' => (int) $repetition['skip'],
'weekend' => (int) $repetition['weekend'],
];
}
return $return;
}
/** /**
* The rules that the incoming request must be matched against. * The rules that the incoming request must be matched against.
* *
@@ -153,54 +203,4 @@ class RecurrenceUpdateRequest extends FormRequest
} }
); );
} }
/**
* Returns the repetition data as it is found in the submitted data.
*
* @return array
*/
private function getRepetitionData(): array
{
$return = [];
// repetition data:
/** @var array $repetitions */
$repetitions = $this->get('repetitions');
if (null === $repetitions) {
return [];
}
/** @var array $repetition */
foreach ($repetitions as $repetition) {
$return[] = [
'type' => $repetition['type'],
'moment' => $repetition['moment'],
'skip' => (int) $repetition['skip'],
'weekend' => (int) $repetition['weekend'],
];
}
return $return;
}
/**
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
*
* @return array
*/
private function getTransactionData(): array
{
$return = [];
// transaction data:
/** @var array $transactions */
$transactions = $this->get('transactions');
if (null === $transactions) {
return [];
}
/** @var array $transaction */
foreach ($transactions as $transaction) {
$return[] = $this->getSingleRecurrenceData($transaction);
}
return $return;
}
} }

View File

@@ -37,6 +37,7 @@ use Illuminate\Foundation\Http\FormRequest;
class RuleGroupRequest extends FormRequest class RuleGroupRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -26,13 +26,9 @@ namespace FireflyIII\Api\V1\Requests;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Request\ConvertsDataTypes; use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log;
/** /**
* Class RuleGroupTestRequest * Class RuleGroupTestRequest
@@ -64,6 +60,24 @@ class RuleGroupTestRequest extends FormRequest
]; ];
} }
/**
* @param string $field
*
* @return Carbon|null
*/
private function getDate(string $field): ?Carbon
{
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
}
/**
* @return Collection
*/
private function getAccounts(): string
{
return (string) $this->query('accounts');
}
/** /**
* @return array * @return array
*/ */
@@ -77,25 +91,4 @@ class RuleGroupTestRequest extends FormRequest
]; ];
} }
/**
* @return Collection
*/
private function getAccounts(): string
{
return (string) $this->query('accounts');
}
/**
* @param string $field
*
* @return Carbon|null
*/
private function getDate(string $field): ?Carbon
{
/** @var Carbon $result */
$result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
return $result;
}
} }

View File

@@ -26,13 +26,8 @@ namespace FireflyIII\Api\V1\Requests;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Request\ConvertsDataTypes; use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Collection;
use Log;
/** /**
* Class RuleGroupTriggerRequest * Class RuleGroupTriggerRequest
@@ -65,14 +60,13 @@ class RuleGroupTriggerRequest extends FormRequest
} }
/** /**
* @return array * @param string $field
*
* @return Carbon|null
*/ */
public function rules(): array private function getDate(string $field): ?Carbon
{ {
return [ return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
'start' => 'date',
'end' => 'date|after:start',
];
} }
/** /**
@@ -84,14 +78,14 @@ class RuleGroupTriggerRequest extends FormRequest
} }
/** /**
* @param string $field * @return array
*
* @return Carbon|null
*/ */
private function getDate(string $field): ?Carbon public function rules(): array
{ {
/** @var Carbon $result */ return [
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field)); 'start' => 'date',
'end' => 'date|after:start',
];
} }
} }

View File

@@ -83,6 +83,48 @@ class RuleStoreRequest extends FormRequest
]; ];
} }
/**
* @return array
*/
private function getRuleTriggers(): array
{
$triggers = $this->get('triggers');
$return = [];
if (is_array($triggers)) {
foreach ($triggers as $trigger) {
$return[] = [
'type' => $trigger['type'],
'value' => $trigger['value'],
'active' => $this->convertBoolean((string) ($trigger['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string) ($trigger['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
/**
* @return array
*/
private function getRuleActions(): array
{
$actions = $this->get('actions');
$return = [];
if (is_array($actions)) {
foreach ($actions as $action) {
$return[] = [
'type' => $action['type'],
'value' => $action['value'],
'active' => $this->convertBoolean((string) ($action['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string) ($action['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
/** /**
* The rules that the incoming request must be matched against. * The rules that the incoming request must be matched against.
* *
@@ -134,21 +176,6 @@ class RuleStoreRequest extends FormRequest
); );
} }
/**
* Adds an error to the validator when there are no repetitions in the array of data.
*
* @param Validator $validator
*/
protected function atLeastOneAction(Validator $validator): void
{
$data = $validator->getData();
$actions = $data['actions'] ?? [];
// need at least one trigger
if (0 === count($actions)) {
$validator->errors()->add('title', (string) trans('validation.at_least_one_action'));
}
}
/** /**
* Adds an error to the validator when there are no repetitions in the array of data. * Adds an error to the validator when there are no repetitions in the array of data.
* *
@@ -165,44 +192,17 @@ class RuleStoreRequest extends FormRequest
} }
/** /**
* @return array * Adds an error to the validator when there are no repetitions in the array of data.
*
* @param Validator $validator
*/ */
private function getRuleActions(): array protected function atLeastOneAction(Validator $validator): void
{ {
$actions = $this->get('actions'); $data = $validator->getData();
$return = []; $actions = $data['actions'] ?? [];
if (is_array($actions)) { // need at least one trigger
foreach ($actions as $action) { if (0 === count($actions)) {
$return[] = [ $validator->errors()->add('title', (string) trans('validation.at_least_one_action'));
'type' => $action['type'],
'value' => $action['value'],
'active' => $this->convertBoolean((string) ($action['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string) ($action['stop_processing'] ?? 'false')),
];
}
} }
return $return;
}
/**
* @return array
*/
private function getRuleTriggers(): array
{
$triggers = $this->get('triggers');
$return = [];
if (is_array($triggers)) {
foreach ($triggers as $trigger) {
$return[] = [
'type' => $trigger['type'],
'value' => $trigger['value'],
'active' => $this->convertBoolean((string) ($trigger['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string) ($trigger['stop_processing'] ?? 'false')),
];
}
}
return $return;
} }
} }

View File

@@ -61,6 +61,33 @@ class RuleTestRequest extends FormRequest
]; ];
} }
/**
* @return int
*/
private function getPage(): int
{
return 0 === (int) $this->query('page') ? 1 : (int) $this->query('page');
}
/**
* @param string $field
*
* @return Carbon|null
*/
private function getDate(string $field): ?Carbon
{
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
}
/**
* @return string
*/
private function getAccounts(): string
{
return (string) $this->query('accounts');
}
/** /**
* @return array * @return array
*/ */
@@ -74,34 +101,4 @@ class RuleTestRequest extends FormRequest
]; ];
} }
/**
* @return string
*/
private function getAccounts(): string
{
return (string) $this->query('accounts');
}
/**
* @param string $field
*
* @return Carbon|null
*/
private function getDate(string $field): ?Carbon
{
/** @var Carbon $result */
$result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
return $result;
}
/**
* @return int
*/
private function getPage(): int
{
return 0 === (int) $this->query('page') ? 1 : (int) $this->query('page');
}
} }

View File

@@ -59,6 +59,24 @@ class RuleTriggerRequest extends FormRequest
]; ];
} }
/**
* @param string $field
*
* @return Carbon|null
*/
private function getDate(string $field): ?Carbon
{
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
}
/**
* @return string
*/
private function getAccounts(): string
{
return (string) $this->query('accounts');
}
/** /**
* @return array * @return array
*/ */
@@ -72,22 +90,4 @@ class RuleTriggerRequest extends FormRequest
]; ];
} }
/**
* @return string
*/
private function getAccounts(): string
{
return (string) $this->query('accounts');
}
/**
* @param string $field
*
* @return Carbon|null
*/
private function getDate(string $field): ?Carbon
{
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
}
} }

View File

@@ -37,6 +37,7 @@ use function is_array;
class RuleUpdateRequest extends FormRequest class RuleUpdateRequest extends FormRequest
{ {
use ConvertsDataTypes, GetRuleConfiguration; use ConvertsDataTypes, GetRuleConfiguration;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *
@@ -82,6 +83,54 @@ class RuleUpdateRequest extends FormRequest
]; ];
} }
/**
* @return array|null
*/
private function getRuleTriggers(): ?array
{
if (!$this->has('triggers')) {
return null;
}
$triggers = $this->get('triggers');
$return = [];
if (is_array($triggers)) {
foreach ($triggers as $trigger) {
$return[] = [
'type' => $trigger['type'],
'value' => $trigger['value'],
'active' => $this->convertBoolean((string) ($trigger['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string) ($trigger['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
/**
* @return array|null
*/
private function getRuleActions(): ?array
{
if (!$this->has('actions')) {
return null;
}
$actions = $this->get('actions');
$return = [];
if (is_array($actions)) {
foreach ($actions as $action) {
$return[] = [
'type' => $action['type'],
'value' => $action['value'],
'active' => $this->convertBoolean((string) ($action['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string) ($action['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
/** /**
* The rules that the incoming request must be matched against. * The rules that the incoming request must be matched against.
* *
@@ -134,21 +183,6 @@ class RuleUpdateRequest extends FormRequest
); );
} }
/**
* Adds an error to the validator when there are no repetitions in the array of data.
*
* @param Validator $validator
*/
protected function atLeastOneAction(Validator $validator): void
{
$data = $validator->getData();
$actions = $data['actions'] ?? null;
// need at least one action
if (is_array($actions) && 0 === count($actions)) {
$validator->errors()->add('title', (string) trans('validation.at_least_one_action'));
}
}
/** /**
* Adds an error to the validator when there are no repetitions in the array of data. * Adds an error to the validator when there are no repetitions in the array of data.
* *
@@ -165,50 +199,17 @@ class RuleUpdateRequest extends FormRequest
} }
/** /**
* @return array|null * Adds an error to the validator when there are no repetitions in the array of data.
*
* @param Validator $validator
*/ */
private function getRuleActions(): ?array protected function atLeastOneAction(Validator $validator): void
{ {
if (!$this->has('actions')) { $data = $validator->getData();
return null; $actions = $data['actions'] ?? null;
// need at least one action
if (is_array($actions) && 0 === count($actions)) {
$validator->errors()->add('title', (string) trans('validation.at_least_one_action'));
} }
$actions = $this->get('actions');
$return = [];
if (is_array($actions)) {
foreach ($actions as $action) {
$return[] = [
'type' => $action['type'],
'value' => $action['value'],
'active' => $this->convertBoolean((string) ($action['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string) ($action['stop_processing'] ?? 'false')),
];
}
}
return $return;
}
/**
* @return array|null
*/
private function getRuleTriggers(): ?array
{
if (!$this->has('triggers')) {
return null;
}
$triggers = $this->get('triggers');
$return = [];
if (is_array($triggers)) {
foreach ($triggers as $trigger) {
$return[] = [
'type' => $trigger['type'],
'value' => $trigger['value'],
'active' => $this->convertBoolean((string) ($trigger['active'] ?? 'false')),
'stop_processing' => $this->convertBoolean((string) ($trigger['stop_processing'] ?? 'false')),
];
}
}
return $return;
} }
} }

View File

@@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest;
class TagStoreRequest extends FormRequest class TagStoreRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -36,6 +36,7 @@ use Illuminate\Foundation\Http\FormRequest;
class TagUpdateRequest extends FormRequest class TagUpdateRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -36,6 +36,7 @@ use Illuminate\Validation\Validator;
class TransactionLinkRequest extends FormRequest class TransactionLinkRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -73,6 +73,106 @@ class TransactionStoreRequest extends FormRequest
]; ];
} }
/**
* Get transaction data.
*
* @return array
*/
private function getTransactionData(): array
{
$return = [];
/**
* @var int $index
* @var array $transaction
*/
foreach ($this->get('transactions') as $index => $transaction) {
$object = new NullArrayObject($transaction);
$return[] = [
'type' => $this->stringFromValue($object['type']),
'date' => $this->dateFromValue($object['date']),
'order' => $this->integerFromValue((string) $object['order']),
'currency_id' => $this->integerFromValue((string) $object['currency_id']),
'currency_code' => $this->stringFromValue($object['currency_code']),
// foreign currency info:
'foreign_currency_id' => $this->integerFromValue((string) $object['foreign_currency_id']),
'foreign_currency_code' => $this->stringFromValue((string) $object['foreign_currency_code']),
// amount and foreign amount. Cannot be 0.
'amount' => $this->stringFromValue((string) $object['amount']),
'foreign_amount' => $this->stringFromValue((string) $object['foreign_amount']),
// description.
'description' => $this->stringFromValue($object['description']),
// source of transaction. If everything is null, assume cash account.
'source_id' => $this->integerFromValue((string) $object['source_id']),
'source_name' => $this->stringFromValue((string) $object['source_name']),
'source_iban' => $this->stringFromValue((string) $object['source_iban']),
'source_number' => $this->stringFromValue((string) $object['source_number']),
'source_bic' => $this->stringFromValue((string) $object['source_bic']),
// destination of transaction. If everything is null, assume cash account.
'destination_id' => $this->integerFromValue((string) $object['destination_id']),
'destination_name' => $this->stringFromValue((string) $object['destination_name']),
'destination_iban' => $this->stringFromValue((string) $object['destination_iban']),
'destination_number' => $this->stringFromValue((string) $object['destination_number']),
'destination_bic' => $this->stringFromValue((string) $object['destination_bic']),
// budget info
'budget_id' => $this->integerFromValue((string) $object['budget_id']),
'budget_name' => $this->stringFromValue((string) $object['budget_name']),
// category info
'category_id' => $this->integerFromValue((string) $object['category_id']),
'category_name' => $this->stringFromValue((string) $object['category_name']),
// journal bill reference. Optional. Will only work for withdrawals
'bill_id' => $this->integerFromValue((string) $object['bill_id']),
'bill_name' => $this->stringFromValue((string) $object['bill_name']),
// piggy bank reference. Optional. Will only work for transfers
'piggy_bank_id' => $this->integerFromValue((string) $object['piggy_bank_id']),
'piggy_bank_name' => $this->stringFromValue((string) $object['piggy_bank_name']),
// some other interesting properties
'reconciled' => $this->convertBoolean((string) $object['reconciled']),
'notes' => $this->nlStringFromValue((string) $object['notes']),
'tags' => $this->arrayFromValue($object['tags']),
// all custom fields:
'internal_reference' => $this->stringFromValue((string) $object['internal_reference']),
'external_id' => $this->stringFromValue((string) $object['external_id']),
'original_source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')),
'recurrence_id' => $this->integerFromValue($object['recurrence_id']),
'bunq_payment_id' => $this->stringFromValue((string) $object['bunq_payment_id']),
'external_uri' => $this->stringFromValue((string) $object['external_uri']),
'sepa_cc' => $this->stringFromValue($object['sepa_cc']),
'sepa_ct_op' => $this->stringFromValue($object['sepa_ct_op']),
'sepa_ct_id' => $this->stringFromValue($object['sepa_ct_id']),
'sepa_db' => $this->stringFromValue($object['sepa_db']),
'sepa_country' => $this->stringFromValue($object['sepa_country']),
'sepa_ep' => $this->stringFromValue($object['sepa_ep']),
'sepa_ci' => $this->stringFromValue($object['sepa_ci']),
'sepa_batch_id' => $this->stringFromValue($object['sepa_batch_id']),
// custom date fields. Must be Carbon objects. Presence is optional.
'interest_date' => $this->dateFromValue($object['interest_date']),
'book_date' => $this->dateFromValue($object['book_date']),
'process_date' => $this->dateFromValue($object['process_date']),
'due_date' => $this->dateFromValue($object['due_date']),
'payment_date' => $this->dateFromValue($object['payment_date']),
'invoice_date' => $this->dateFromValue($object['invoice_date']),
];
}
return $return;
}
/** /**
* The rules that the incoming request must be matched against. * The rules that the incoming request must be matched against.
* *
@@ -175,6 +275,10 @@ class TransactionStoreRequest extends FormRequest
{ {
$validator->after( $validator->after(
function (Validator $validator) { function (Validator $validator) {
// must be valid array.
$this->validateTransactionArray($validator);
// must submit at least one transaction. // must submit at least one transaction.
$this->validateOneTransaction($validator); $this->validateOneTransaction($validator);
@@ -199,104 +303,4 @@ class TransactionStoreRequest extends FormRequest
} }
); );
} }
/**
* Get transaction data.
*
* @return array
*/
private function getTransactionData(): array
{
$return = [];
/**
* @var int $index
* @var array $transaction
*/
foreach ($this->get('transactions') as $index => $transaction) {
$object = new NullArrayObject($transaction);
$return[] = [
'type' => $this->stringFromValue($object['type']),
'date' => $this->dateFromValue($object['date']),
'order' => $this->integerFromValue((string) $object['order']),
'currency_id' => $this->integerFromValue((string) $object['currency_id']),
'currency_code' => $this->stringFromValue($object['currency_code']),
// foreign currency info:
'foreign_currency_id' => $this->integerFromValue((string) $object['foreign_currency_id']),
'foreign_currency_code' => $this->stringFromValue((string) $object['foreign_currency_code']),
// amount and foreign amount. Cannot be 0.
'amount' => $this->stringFromValue((string) $object['amount']),
'foreign_amount' => $this->stringFromValue((string) $object['foreign_amount']),
// description.
'description' => $this->stringFromValue($object['description']),
// source of transaction. If everything is null, assume cash account.
'source_id' => $this->integerFromValue((string) $object['source_id']),
'source_name' => $this->stringFromValue((string) $object['source_name']),
'source_iban' => $this->stringFromValue((string) $object['source_iban']),
'source_number' => $this->stringFromValue((string) $object['source_number']),
'source_bic' => $this->stringFromValue((string) $object['source_bic']),
// destination of transaction. If everything is null, assume cash account.
'destination_id' => $this->integerFromValue((string) $object['destination_id']),
'destination_name' => $this->stringFromValue((string) $object['destination_name']),
'destination_iban' => $this->stringFromValue((string) $object['destination_iban']),
'destination_number' => $this->stringFromValue((string) $object['destination_number']),
'destination_bic' => $this->stringFromValue((string) $object['destination_bic']),
// budget info
'budget_id' => $this->integerFromValue((string) $object['budget_id']),
'budget_name' => $this->stringFromValue((string) $object['budget_name']),
// category info
'category_id' => $this->integerFromValue((string) $object['category_id']),
'category_name' => $this->stringFromValue((string) $object['category_name']),
// journal bill reference. Optional. Will only work for withdrawals
'bill_id' => $this->integerFromValue((string) $object['bill_id']),
'bill_name' => $this->stringFromValue((string) $object['bill_name']),
// piggy bank reference. Optional. Will only work for transfers
'piggy_bank_id' => $this->integerFromValue((string) $object['piggy_bank_id']),
'piggy_bank_name' => $this->stringFromValue((string) $object['piggy_bank_name']),
// some other interesting properties
'reconciled' => $this->convertBoolean((string) $object['reconciled']),
'notes' => $this->nlStringFromValue((string) $object['notes']),
'tags' => $this->arrayFromValue($object['tags']),
// all custom fields:
'internal_reference' => $this->stringFromValue((string) $object['internal_reference']),
'external_id' => $this->stringFromValue((string) $object['external_id']),
'original_source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')),
'recurrence_id' => $this->integerFromValue($object['recurrence_id']),
'bunq_payment_id' => $this->stringFromValue((string) $object['bunq_payment_id']),
'external_uri' => $this->stringFromValue((string) $object['external_uri']),
'sepa_cc' => $this->stringFromValue($object['sepa_cc']),
'sepa_ct_op' => $this->stringFromValue($object['sepa_ct_op']),
'sepa_ct_id' => $this->stringFromValue($object['sepa_ct_id']),
'sepa_db' => $this->stringFromValue($object['sepa_db']),
'sepa_country' => $this->stringFromValue($object['sepa_country']),
'sepa_ep' => $this->stringFromValue($object['sepa_ep']),
'sepa_ci' => $this->stringFromValue($object['sepa_ci']),
'sepa_batch_id' => $this->stringFromValue($object['sepa_batch_id']),
// custom date fields. Must be Carbon objects. Presence is optional.
'interest_date' => $this->dateFromValue($object['interest_date']),
'book_date' => $this->dateFromValue($object['book_date']),
'process_date' => $this->dateFromValue($object['process_date']),
'due_date' => $this->dateFromValue($object['due_date']),
'payment_date' => $this->dateFromValue($object['payment_date']),
'invoice_date' => $this->dateFromValue($object['invoice_date']),
];
}
return $return;
}
} }

View File

@@ -146,6 +146,139 @@ class TransactionUpdateRequest extends FormRequest
return $data; return $data;
} }
/**
* Get transaction data.
*
* @return array
*/
private function getTransactionData(): array
{
Log::debug('Now in getTransactionData()');
$return = [];
/**
* @var int $index
* @var array $transaction
*/
foreach ($this->get('transactions') as $transaction) {
// default response is to update nothing in the transaction:
$current = [];
$current = $this->getIntegerData($current, $transaction);
$current = $this->getStringData($current, $transaction);
$current = $this->getNlStringData($current, $transaction);
$current = $this->getDateData($current, $transaction);
$current = $this->getBooleanData($current, $transaction);
$current = $this->getArrayData($current, $transaction);
$return[] = $current;
}
return $return;
}
/**
* For each field, add it to the array if a reference is present in the request:
*
* @param array $current
*
* @return array
*/
private function getIntegerData(array $current, array $transaction): array
{
foreach ($this->integerFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->integerFromValue((string) $transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getStringData(array $current, array $transaction): array
{
foreach ($this->stringFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->stringFromValue((string) $transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getNlStringData(array $current, array $transaction): array
{
foreach ($this->textareaFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->nlStringFromValue((string) $transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getDateData(array $current, array $transaction): array
{
foreach ($this->dateFields as $fieldName) {
Log::debug(sprintf('Now at date field %s', $fieldName));
if (array_key_exists($fieldName, $transaction)) {
Log::debug(sprintf('New value: "%s"', (string) $transaction[$fieldName]));
$current[$fieldName] = $this->dateFromValue((string) $transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getBooleanData(array $current, array $transaction): array
{
foreach ($this->booleanFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->convertBoolean((string) $transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getArrayData(array $current, array $transaction): array
{
foreach ($this->arrayFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->arrayFromValue($transaction[$fieldName]);
}
}
return $current;
}
/** /**
* The rules that the incoming request must be matched against. * The rules that the incoming request must be matched against.
* *
@@ -272,137 +405,4 @@ class TransactionUpdateRequest extends FormRequest
} }
); );
} }
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getArrayData(array $current, array $transaction): array
{
foreach ($this->arrayFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->arrayFromValue($transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getBooleanData(array $current, array $transaction): array
{
foreach ($this->booleanFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->convertBoolean((string) $transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getDateData(array $current, array $transaction): array
{
foreach ($this->dateFields as $fieldName) {
Log::debug(sprintf('Now at date field %s', $fieldName));
if (array_key_exists($fieldName, $transaction)) {
Log::debug(sprintf('New value: "%s"', (string) $transaction[$fieldName]));
$current[$fieldName] = $this->dateFromValue((string) $transaction[$fieldName]);
}
}
return $current;
}
/**
* For each field, add it to the array if a reference is present in the request:
*
* @param array $current
*
* @return array
*/
private function getIntegerData(array $current, array $transaction): array
{
foreach ($this->integerFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->integerFromValue((string) $transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getNlStringData(array $current, array $transaction): array
{
foreach ($this->textareaFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->nlStringFromValue((string) $transaction[$fieldName]);
}
}
return $current;
}
/**
* @param array $current
* @param array $transaction
*
* @return array
*/
private function getStringData(array $current, array $transaction): array
{
foreach ($this->stringFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
$current[$fieldName] = $this->stringFromValue((string) $transaction[$fieldName]);
}
}
return $current;
}
/**
* Get transaction data.
*
* @return array
*/
private function getTransactionData(): array
{
Log::debug('Now in getTransactionData()');
$return = [];
/**
* @var int $index
* @var array $transaction
*/
foreach ($this->get('transactions') as $transaction) {
// default response is to update nothing in the transaction:
$current = [];
$current = $this->getIntegerData($current, $transaction);
$current = $this->getStringData($current, $transaction);
$current = $this->getNlStringData($current, $transaction);
$current = $this->getDateData($current, $transaction);
$current = $this->getBooleanData($current, $transaction);
$current = $this->getArrayData($current, $transaction);
$return[] = $current;
}
return $return;
}
} }

View File

@@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest;
class UserStoreRequest extends FormRequest class UserStoreRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest;
class UserUpdateRequest extends FormRequest class UserUpdateRequest extends FormRequest
{ {
use ConvertsDataTypes; use ConvertsDataTypes;
/** /**
* Authorize logged in users. * Authorize logged in users.
* *

View File

@@ -32,6 +32,7 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use JsonException;
use Log; use Log;
/** /**
@@ -60,6 +61,7 @@ class CorrectOpeningBalanceCurrencies extends Command
*/ */
public function handle(): int public function handle(): int
{ {
Log::debug(sprintf('Now in %s', __METHOD__));
// get all OB journals: // get all OB journals:
$set = TransactionJournal $set = TransactionJournal
::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') ::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
@@ -70,16 +72,23 @@ class CorrectOpeningBalanceCurrencies extends Command
$count = 0; $count = 0;
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
foreach ($set as $journal) { foreach ($set as $journal) {
Log::debug(sprintf('Going to fix journal #%d', $journal->id));
$count += $this->correctJournal($journal); $count += $this->correctJournal($journal);
Log::debug(sprintf('Done, count is now %d', $count));
} }
if ($count > 0) { if ($count > 0) {
$this->line(sprintf('Corrected %d opening balance transactions.', $count)); $message = sprintf('Corrected %d opening balance transaction(s).', $count);
Log::debug($message);
$this->line($message);
} }
if (0 === $count) { if (0 === $count) {
$this->info('There was nothing to fix in the opening balance transactions.'); $message = 'There was nothing to fix in the opening balance transactions.';
Log::debug($message);
$this->info($message);
} }
Log::debug(sprintf('Done with %s', __METHOD__));
return 0; return 0;
} }
@@ -94,18 +103,18 @@ class CorrectOpeningBalanceCurrencies extends Command
// get the asset account for this opening balance: // get the asset account for this opening balance:
$account = $this->getAccount($journal); $account = $this->getAccount($journal);
if (null === $account) { if (null === $account) {
$this->warn(sprintf('Transaction journal #%d has no valid account. Cant fix this line.', $journal->id)); $message = sprintf('Transaction journal #%d has no valid account. Cant fix this line.', $journal->id);
Log::warning($message);
$this->warn($message);
return 0; return 0;
} }
Log::debug(sprintf('Found %s #%d "%s".', $account->accountType->type, $account->id, $account->name)); Log::debug(sprintf('Found "%s" #%d "%s".', $account->accountType->type, $account->id, $account->name));
$currency = $this->getCurrency($account); $currency = $this->getCurrency($account);
Log::debug(sprintf('Found currency #%d (%s)', $currency->id, $currency->code)); Log::debug(sprintf('Found currency #%d (%s)', $currency->id, $currency->code));
// update journal and all transactions: // update journal and all transactions:
$this->setCurrency($journal, $currency); return $this->setCurrency($journal, $currency);
return 1;
} }
/** /**
@@ -115,22 +124,27 @@ class CorrectOpeningBalanceCurrencies extends Command
*/ */
private function getAccount(TransactionJournal $journal): ?Account private function getAccount(TransactionJournal $journal): ?Account
{ {
$transactions = $journal->transactions()->with(['account', 'account.accountType'])->get(); $transactions = $journal->transactions()->get();
Log::debug(sprintf('Found %d transactions for journal #%d.', $transactions->count(), $journal->id));
/** @var Transaction $transaction */ /** @var Transaction $transaction */
foreach ($transactions as $transaction) { foreach ($transactions as $transaction) {
$account = $transaction->account; Log::debug(sprintf('Testing transaction #%d', $transaction->id));
if ((null !== $account) && AccountType::INITIAL_BALANCE !== $account->accountType->type) { /** @var Account $account */
$account = $transaction->account()->first();
if (null !== $account && AccountType::INITIAL_BALANCE !== $account->accountType()->first()->type) {
Log::debug(sprintf('Account of transaction #%d is opposite of IB account (%s).', $transaction->id, $account->accountType()->first()->type));
return $account; return $account;
} }
} }
Log::debug('Found no IB account in transactions of journal.');
return null; return null;
} }
/** /**
* @param Account $account * @param Account $account
*
* @return TransactionCurrency * @return TransactionCurrency
* @throws JsonException
*/ */
private function getCurrency(Account $account): TransactionCurrency private function getCurrency(Account $account): TransactionCurrency
{ {
@@ -144,16 +158,30 @@ class CorrectOpeningBalanceCurrencies extends Command
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* @param TransactionCurrency $currency * @param TransactionCurrency $currency
* @return int
*/ */
private function setCurrency(TransactionJournal $journal, TransactionCurrency $currency): void private function setCurrency(TransactionJournal $journal, TransactionCurrency $currency): int
{ {
$journal->transaction_currency_id = $currency->id; Log::debug('Now in setCurrency');
$journal->save(); $count = 0;
if ((int) $journal->transaction_currency_id !== (int) $currency->id) {
Log::debug(sprintf('Currency ID of journal #%d was #%d, now set to #%d', $journal->id, $journal->transaction_currency_id, $currency->id));
$journal->transaction_currency_id = $currency->id;
$journal->save();
$count = 1;
}
/** @var Transaction $transaction */ /** @var Transaction $transaction */
foreach ($journal->transactions as $transaction) { foreach ($journal->transactions as $transaction) {
$transaction->transaction_currency_id = $currency->id; if ((int) $transaction->transaction_currency_id !== (int) $currency->id) {
$transaction->save(); Log::debug(sprintf('Currency ID of transaction #%d was #%d, now set to #%d', $transaction->id, $transaction->transaction_currency_id, $currency->id));
$transaction->transaction_currency_id = $currency->id;
$transaction->save();
$count = 1;
}
} }
Log::debug(sprintf('Return %d', $count));
return $count;
} }
} }

View File

@@ -30,6 +30,7 @@ use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log;
/** /**
* Class EnableCurrencies * Class EnableCurrencies
@@ -75,9 +76,10 @@ class EnableCurrencies extends Command
// get all from transactions // get all from transactions
/** @var Collection $transactions */ /** @var Collection $transactions */
$transactions = Transaction::groupBy('transaction_currency_id')->get(['transaction_currency_id']); $transactions = Transaction::groupBy('transaction_currency_id', 'foreign_currency_id')->get(['transaction_currency_id','foreign_currency_id']);
foreach ($transactions as $entry) { foreach ($transactions as $entry) {
$found[] = (int) $entry->transaction_currency_id; $found[] = (int) $entry->transaction_currency_id;
$found[] = (int) $entry->foreign_currency_id;
} }
// get all from budget limits // get all from budget limits
@@ -87,8 +89,13 @@ class EnableCurrencies extends Command
$found[] = (int) $entry->transaction_currency_id; $found[] = (int) $entry->transaction_currency_id;
} }
$found = array_unique($found); $found = array_values(array_unique($found));
$this->info(sprintf('%d different currencies are currently in use.', count($found))); $found = array_values(array_filter($found, function (int $currencyId) {
return $currencyId !== 0;
}));
$message = sprintf('%d different currencies are currently in use.', count($found));
$this->info($message);
Log::debug($message, $found);
$disabled = TransactionCurrency::whereIn('id', $found)->where('enabled', false)->count(); $disabled = TransactionCurrency::whereIn('id', $found)->where('enabled', false)->count();
if ($disabled > 0) { if ($disabled > 0) {

View File

@@ -1,6 +1,6 @@
<?php <?php
/** /**
* FixAccountTypes.php * FixAccountOrder.php
* Copyright (c) 2020 james@firefly-iii.org * Copyright (c) 2020 james@firefly-iii.org
* *
* This file is part of Firefly III (https://github.com/firefly-iii). * This file is part of Firefly III (https://github.com/firefly-iii).
@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
@@ -53,7 +52,6 @@ class FixAccountOrder extends Command
/** /**
* Execute the console command. * Execute the console command.
* *
* @throws FireflyException
* @return int * @return int
*/ */
public function handle(): int public function handle(): int
@@ -69,6 +67,7 @@ class FixAccountOrder extends Command
[AccountType::EXPENSE, AccountType::BENEFICIARY], [AccountType::EXPENSE, AccountType::BENEFICIARY],
[AccountType::REVENUE], [AccountType::REVENUE],
[AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE],
[AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION],
]; ];
foreach ($sets as $set) { foreach ($sets as $set) {
$this->repository->resetAccountOrder($set); $this->repository->resetAccountOrder($set);

View File

@@ -46,14 +46,10 @@ class FixAccountTypes extends Command
* The name and signature of the console command. * The name and signature of the console command.
* @var string * @var string
*/ */
protected $signature = 'firefly-iii:fix-account-types'; protected $signature = 'firefly-iii:fix-account-types';
/** @var int */ private int $count;
private $count; private array $expected;
private array $expected; private AccountFactory $factory;
/** @var AccountFactory */
private $factory;
/** @var array */
private $fixable;
/** /**
@@ -65,22 +61,11 @@ class FixAccountTypes extends Command
{ {
$this->stupidLaravel(); $this->stupidLaravel();
Log::debug('Now in fix-account-types'); Log::debug('Now in fix-account-types');
$start = microtime(true); $start = microtime(true);
$this->factory = app(AccountFactory::class); $this->factory = app(AccountFactory::class);
// some combinations can be fixed by this script:
$this->fixable = [// transfers from asset to liability and vice versa
sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::LOAN), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::DEBT), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::MORTGAGE), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::LOAN, AccountType::ASSET), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::DEBT, AccountType::ASSET), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::MORTGAGE, AccountType::ASSET),
// withdrawals with a revenue account as destination instead of an expense account.
sprintf('%s%s%s', TransactionType::WITHDRAWAL, AccountType::ASSET, AccountType::REVENUE),
// deposits with an expense account as source instead of a revenue account.
sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET),];
$this->expected = config('firefly.source_dests'); $this->expected = config('firefly.source_dests');
$journals = TransactionJournal::with(['TransactionType', 'transactions', 'transactions.account', 'transactions.account.accounttype'])->get(); $journals = TransactionJournal::with(['TransactionType', 'transactions', 'transactions.account', 'transactions.account.accounttype'])->get();
Log::debug(sprintf('Found %d journals to fix.', $journals->count())); Log::debug(sprintf('Found %d journals to inspect.', $journals->count()));
foreach ($journals as $journal) { foreach ($journals as $journal) {
$this->inspectJournal($journal); $this->inspectJournal($journal);
} }
@@ -120,7 +105,9 @@ class FixAccountTypes extends Command
$withdrawal = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); $withdrawal = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
$journal->transactionType()->associate($withdrawal); $journal->transactionType()->associate($withdrawal);
$journal->save(); $journal->save();
$this->info(sprintf('Converted transaction #%d from a transfer to a withdrawal.', $journal->id)); $message = sprintf('Converted transaction #%d from a transfer to a withdrawal.', $journal->id);
$this->info($message);
Log::debug($message);
// check it again: // check it again:
$this->inspectJournal($journal); $this->inspectJournal($journal);
break; break;
@@ -131,7 +118,9 @@ class FixAccountTypes extends Command
$deposit = TransactionType::whereType(TransactionType::DEPOSIT)->first(); $deposit = TransactionType::whereType(TransactionType::DEPOSIT)->first();
$journal->transactionType()->associate($deposit); $journal->transactionType()->associate($deposit);
$journal->save(); $journal->save();
$this->info(sprintf('Converted transaction #%d from a transfer to a deposit.', $journal->id)); $message = sprintf('Converted transaction #%d from a transfer to a deposit.', $journal->id);
$this->info($message);
Log::debug($message);
// check it again: // check it again:
$this->inspectJournal($journal); $this->inspectJournal($journal);
@@ -143,7 +132,9 @@ class FixAccountTypes extends Command
$result = $this->factory->findOrCreate($dest->account->name, AccountType::EXPENSE); $result = $this->factory->findOrCreate($dest->account->name, AccountType::EXPENSE);
$dest->account()->associate($result); $dest->account()->associate($result);
$dest->save(); $dest->save();
$this->info(sprintf('Transaction journal #%d, destination account changed from #%d ("%s") to #%d ("%s").', $journal->id, $oldDest->id, $oldDest->name, $result->id, $result->name)); $message = sprintf('Transaction journal #%d, destination account changed from #%d ("%s") to #%d ("%s").', $journal->id, $oldDest->id, $oldDest->name, $result->id, $result->name);
$this->info($message);
Log::debug($message);
$this->inspectJournal($journal); $this->inspectJournal($journal);
break; break;
case sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET): case sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET):
@@ -154,12 +145,19 @@ class FixAccountTypes extends Command
$oldSource = $dest->account; $oldSource = $dest->account;
$source->account()->associate($result); $source->account()->associate($result);
$source->save(); $source->save();
$this->info(sprintf('Transaction journal #%d, source account changed from #%d ("%s") to #%d ("%s").', $journal->id, $oldSource->id, $oldSource->name, $result->id, $result->name)); $message = sprintf('Transaction journal #%d, source account changed from #%d ("%s") to #%d ("%s").', $journal->id, $oldSource->id, $oldSource->name, $result->id, $result->name);
$this->info($message);
Log::debug($message);
$this->inspectJournal($journal); $this->inspectJournal($journal);
break; break;
default: default:
$this->info(sprintf('The source account of %s #%d cannot be of type "%s".', $type, $journal->id, $source->account->accountType->type)); $message = sprintf('The source account of %s #%d cannot be of type "%s".', $type, $journal->id, $source->account->accountType->type);
$this->info(sprintf('The destination account of %s #%d cannot be of type "%s".', $type, $journal->id, $dest->account->accountType->type)); $this->info($message);
Log::debug($message);
$message = sprintf('The destination account of %s #%d cannot be of type "%s".', $type, $journal->id, $dest->account->accountType->type);
$this->info($message);
Log::debug($message);
break; break;
@@ -190,28 +188,16 @@ class FixAccountTypes extends Command
*/ */
private function inspectJournal(TransactionJournal $journal): void private function inspectJournal(TransactionJournal $journal): void
{ {
//Log::debug(sprintf('Now trying to fix journal #%d', $journal->id)); $transactions = $journal->transactions()->count();
$count = $journal->transactions()->count(); if (2 !== $transactions) {
if (2 !== $count) { Log::debug(sprintf('Journal has %d transactions, so can\'t fix.', $transactions));
Log::debug(sprintf('Journal has %d transactions, so cant fix.', $count)); $this->info(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $transactions));
$this->info(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $count));
return; return;
} }
$type = $journal->transactionType->type; $type = $journal->transactionType->type;
$sourceTransaction = $this->getSourceTransaction($journal); $sourceTransaction = $this->getSourceTransaction($journal);
$destTransaction = $this->getDestinationTransaction($journal); $destTransaction = $this->getDestinationTransaction($journal);
if (null === $sourceTransaction) {
Log::error('Source transaction is unexpectedly NULL. Wont fix this journal.');
return;
}
if (null === $destTransaction) {
Log::error('Destination transaction is unexpectedly NULL. Wont fix this journal.');
return;
}
$sourceAccount = $sourceTransaction->account; $sourceAccount = $sourceTransaction->account;
$sourceAccountType = $sourceAccount->accountType->type; $sourceAccountType = $sourceAccount->accountType->type;
$destAccount = $destTransaction->account; $destAccount = $destTransaction->account;
@@ -226,12 +212,14 @@ class FixAccountTypes extends Command
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
if (!array_key_exists($sourceAccountType, $this->expected[$type])) { if (!array_key_exists($sourceAccountType, $this->expected[$type])) {
Log::debug(sprintf('Going to fix journal #%d', $journal->id));
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction); $this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
return; return;
} }
$expectedTypes = $this->expected[$type][$sourceAccountType]; $expectedTypes = $this->expected[$type][$sourceAccountType];
if (!in_array($destAccountType, $expectedTypes, true)) { if (!in_array($destAccountType, $expectedTypes, true)) {
Log::debug(sprintf('Going to fix journal #%d', $journal->id));
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction); $this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
} }
} }

View File

@@ -57,7 +57,6 @@ class FixGroupAccounts extends Command
*/ */
public function handle(): int public function handle(): int
{ {
// select transaction_group_id, count(transaction_group_id) as the_count from transaction_journals group by transaction_group_id having the_count > 1
$groups = []; $groups = [];
$res = TransactionJournal $res = TransactionJournal
::groupBy('transaction_group_id') ::groupBy('transaction_group_id')

View File

@@ -76,7 +76,8 @@ class FixLongDescriptions extends Command
} }
} }
$end = round(microtime(true) - $start, 2); $end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified all transaction group and journal title lengths in %s seconds.', $end)); $this->info('Verified all transaction group and journal title lengths.');
$this->info(sprintf('Took %s seconds.', $end));
return 0; return 0;
} }

View File

@@ -86,7 +86,6 @@ class FixPiggies extends Command
$event->save(); $event->save();
$this->line(sprintf('Piggy bank #%d was referenced by an invalid event. This has been fixed.', $event->piggy_bank_id)); $this->line(sprintf('Piggy bank #%d was referenced by an invalid event. This has been fixed.', $event->piggy_bank_id));
$this->count++; $this->count++;
continue;
} }
} }
if (0 === $this->count) { if (0 === $this->count) {

View File

@@ -68,7 +68,7 @@ class FixRecurringTransactions extends Command
$end = round(microtime(true) - $start, 2); $end = round(microtime(true) - $start, 2);
$this->info(sprintf('Corrected recurring transactions %s seconds.', $end)); $this->info(sprintf('Corrected recurring transactions in %s seconds.', $end));
return 0; return 0;
} }
@@ -81,28 +81,7 @@ class FixRecurringTransactions extends Command
$users = $this->userRepos->all(); $users = $this->userRepos->all();
/** @var User $user */ /** @var User $user */
foreach ($users as $user) { foreach ($users as $user) {
$this->recurringRepos->setUser($user); $this->processUser($user);
$recurrences = $this->recurringRepos->get();
/** @var Recurrence $recurrence */
foreach ($recurrences as $recurrence) {
/** @var RecurrenceTransaction $transaction */
foreach ($recurrence->recurrenceTransactions as $transaction) {
$source = $transaction->sourceAccount;
$destination = $transaction->destinationAccount;
$type = $recurrence->transactionType;
$link = config(sprintf('firefly.account_to_transaction.%s.%s', $source->accountType->type, $destination->accountType->type));
if (null !== $link && strtolower($type->type) !== strtolower($link)) {
$this->warn(
sprintf('Recurring transaction #%d should be a "%s" but is a "%s" and will be corrected.', $recurrence->id, $link, $type->type)
);
$transactionType = TransactionType::whereType($link)->first();
if (null !== $transactionType) {
$recurrence->transaction_type_id = $transactionType->id;
$recurrence->save();
}
}
}
}
} }
} }
@@ -119,5 +98,49 @@ class FixRecurringTransactions extends Command
$this->userRepos = app(UserRepositoryInterface::class); $this->userRepos = app(UserRepositoryInterface::class);
} }
/**
* @param User $user
*/
private function processUser(User $user): void
{
$this->recurringRepos->setUser($user);
$recurrences = $this->recurringRepos->get();
/** @var Recurrence $recurrence */
foreach ($recurrences as $recurrence) {
$this->processRecurrence($recurrence);
}
}
/**
* @param Recurrence $recurrence
*/
private function processRecurrence(Recurrence $recurrence): void
{
/** @var RecurrenceTransaction $transaction */
foreach ($recurrence->recurrenceTransactions as $transaction) {
$this->processTransaction($recurrence, $transaction);
}
}
/**
* @param Recurrence $recurrence
* @param RecurrenceTransaction $transaction
*/
private function processTransaction(Recurrence $recurrence, RecurrenceTransaction $transaction): void
{
$source = $transaction->sourceAccount;
$destination = $transaction->destinationAccount;
$type = $recurrence->transactionType;
$link = config(sprintf('firefly.account_to_transaction.%s.%s', $source->accountType->type, $destination->accountType->type));
if (null !== $link && strtolower($type->type) !== strtolower($link)) {
$this->warn(
sprintf('Recurring transaction #%d should be a "%s" but is a "%s" and will be corrected.', $recurrence->id, $link, $type->type)
);
$transactionType = TransactionType::whereType($link)->first();
if (null !== $transactionType) {
$recurrence->transaction_type_id = $transactionType->id;
$recurrence->save();
}
}
}
} }

View File

@@ -44,8 +44,7 @@ class RenameMetaFields extends Command
*/ */
protected $signature = 'firefly-iii:rename-meta-fields'; protected $signature = 'firefly-iii:rename-meta-fields';
/** @var int */ private int $count;
private $count;
/** /**
@@ -93,9 +92,9 @@ class RenameMetaFields extends Command
*/ */
private function rename(string $original, string $update): void private function rename(string $original, string $update): void
{ {
$count = DB::table('journal_meta') $total = DB::table('journal_meta')
->where('name', '=', $original) ->where('name', '=', $original)
->update(['name' => $update]); ->update(['name' => $update]);
$this->count += $count; $this->count += $total;
} }
} }

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Log;
/** /**
* Class TransferBudgets * Class TransferBudgets
@@ -62,15 +63,21 @@ class TransferBudgets extends Command
$count = 0; $count = 0;
/** @var TransactionJournal $entry */ /** @var TransactionJournal $entry */
foreach ($set as $entry) { foreach ($set as $entry) {
$this->info(sprintf('Transaction journal #%d is a %s, so has no longer a budget.', $entry->id, $entry->transactionType->type)); $message = sprintf('Transaction journal #%d is a %s, so has no longer a budget.', $entry->id, $entry->transactionType->type);
$this->info($message);
Log::debug($message);
$entry->budgets()->sync([]); $entry->budgets()->sync([]);
$count++; $count++;
} }
if (0 === $count) { if (0 === $count) {
$this->info('No invalid budget/journal entries.'); $message = 'No invalid budget/journal entries.';
Log::debug($message);
$this->info($message);
} }
if (0 !== $count) { if (0 !== $count) {
$this->line(sprintf('Corrected %d invalid budget/journal entries (entry).', $count)); $message = sprintf('Corrected %d invalid budget/journal entries (entry).', $count);
Log::debug($message);
$this->line($message);
} }
$end = round(microtime(true) - $start, 2); $end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified budget/journals in %s seconds.', $end)); $this->info(sprintf('Verified budget/journals in %s seconds.', $end));

View File

@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace FireflyIII\Console\Commands;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
use Str;
/**
* Class CreateFirstUser
* @package FireflyIII\Console\Commands
*/
class CreateFirstUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:create-first-user {email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates a new user and gives admin rights. Outputs the password on the command line. Strictly for testing.';
private UserRepositoryInterface $repository;
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
if ('testing' !== env('APP_ENV', 'local')) {
$this->error('This command only works in the testing environment.');
return 1;
}
$this->stupidLaravel();
$count = $this->repository->count();
if ($count > 0) {
$this->error('Already have more than zero users in DB.');
return 1;
}
$data = [
'blocked' => false,
'blocked_code' => null,
'email' => $this->argument('email'),
'role' => 'owner',
];
$password = Str::random(24);
$user = $this->repository->store($data);
$user->password = Hash::make($password);
$user->save();
$user->setRememberToken(Str::random(60));
$this->info(sprintf('Created new admin user (ID #%d) with email address "%s" and password "%s".', $user->id, $user->email, $password));
$this->error('Change this password.');
return 0;
}
/**
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
* be called from the handle method instead of using the constructor to initialize the command.
*
* @codeCoverageIgnore
*/
private function stupidLaravel(): void
{
$this->repository = app(UserRepositoryInterface::class);
}
}

View File

@@ -32,6 +32,7 @@ use Illuminate\Console\Command;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
use JsonException; use JsonException;
use Log; use Log;
use stdClass;
/** /**
* Class DecryptDatabase * Class DecryptDatabase
@@ -51,11 +52,9 @@ class DecryptDatabase extends Command
*/ */
protected $signature = 'firefly-iii:decrypt-all'; protected $signature = 'firefly-iii:decrypt-all';
/** /**
* Execute the console command. * Execute the console command.
* *
* @throws FireflyException
* @return int * @return int
*/ */
public function handle(): int public function handle(): int
@@ -74,52 +73,12 @@ class DecryptDatabase extends Command
'transactions' => ['description'], 'transactions' => ['description'],
'journal_links' => ['comment'], 'journal_links' => ['comment'],
]; ];
/**
* @var string $table
* @var array $fields
*/
foreach ($tables as $table => $fields) { foreach ($tables as $table => $fields) {
if ($this->isDecrypted($table)) { $this->decryptTable($table, $fields);
$this->info(sprintf('No decryption required for table "%s".', $table));
continue;
}
foreach ($fields as $field) {
$rows = DB::table($table)->get(['id', $field]);
foreach ($rows as $row) {
$original = $row->$field;
if (null === $original) {
continue;
}
$id = $row->id;
$value = $this->tryDecrypt($original);
// A separate routine for preferences:
if ('preferences' === $table) {
// try to json_decrypt the value.
try {
$value = json_decode($value, true, 512, JSON_THROW_ON_ERROR) ?? $value;
} catch(JsonException $e) {
Log::error($e->getMessage());
}
//Log::debug(sprintf('Decrypted field "%s" "%s" to "%s" in table "%s" (row #%d)', $field, $original, print_r($value, true), $table, $id));
/** @var Preference $object */
$object = Preference::find((int) $id);
if (null !== $object) {
$object->data = $value;
$object->save();
}
continue;
}
if ($value !== $original) {
//Log::debug(sprintf('Decrypted field "%s" "%s" to "%s" in table "%s" (row #%d)', $field, $original, $value, $table, $id));
DB::table($table)->where('id', $id)->update([$field => $value]);
}
}
}
$this->line(sprintf('Decrypted the data in table "%s".', $table));
// mark as decrypted:
$configName = sprintf('is_decrypted_%s', $table);
app('fireflyconfig')->set($configName, true);
} }
$this->info('Done!'); $this->info('Done!');
@@ -134,7 +93,12 @@ class DecryptDatabase extends Command
private function isDecrypted(string $table): bool private function isDecrypted(string $table): bool
{ {
$configName = sprintf('is_decrypted_%s', $table); $configName = sprintf('is_decrypted_%s', $table);
$configVar = app('fireflyconfig')->get($configName, false); $configVar = null;
try {
$configVar = app('fireflyconfig')->get($configName, false);
} catch (FireflyException $e) {
Log::error($e->getMessage());
}
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool) $configVar->data;
} }
@@ -148,13 +112,13 @@ class DecryptDatabase extends Command
* *
* @param $value * @param $value
* *
* @throws FireflyException
* @return string * @return string
* @throws FireflyException
*/ */
private function tryDecrypt($value) private function tryDecrypt($value)
{ {
try { try {
$value = Crypt::decrypt($value); // verified $value = Crypt::decrypt($value);
} catch (DecryptException $e) { } catch (DecryptException $e) {
if ('The MAC is invalid.' === $e->getMessage()) { if ('The MAC is invalid.' === $e->getMessage()) {
throw new FireflyException($e->getMessage()); // @codeCoverageIgnore throw new FireflyException($e->getMessage()); // @codeCoverageIgnore
@@ -163,4 +127,96 @@ class DecryptDatabase extends Command
return $value; return $value;
} }
/**
* @param string $table
* @param array $fields
*/
private function decryptTable(string $table, array $fields): void
{
if ($this->isDecrypted($table)) {
$this->info(sprintf('No decryption required for table "%s".', $table));
return;
}
foreach ($fields as $field) {
$this->decryptField($table, $field);
}
$this->line(sprintf('Decrypted the data in table "%s".', $table));
// mark as decrypted:
$configName = sprintf('is_decrypted_%s', $table);
app('fireflyconfig')->set($configName, true);
}
/**
* @param string $table
* @param string $field
*/
private function decryptField(string $table, string $field): void
{
$rows = DB::table($table)->get(['id', $field]);
/** @var stdClass $row */
foreach ($rows as $row) {
$this->decryptRow($table, $field, $row);
}
}
/**
* @param string $table
* @param string $field
* @param stdClass $row
*/
private function decryptRow(string $table, string $field, stdClass $row): void
{
$original = $row->$field;
if (null === $original) {
return;
}
$id = (int) $row->id;
$value = '';
try {
$value = $this->tryDecrypt($original);
} catch (FireflyException $e) {
$message = sprintf('Could not decrypt field "%s" in row #%d of table "%s": %s', $field, $id, $table, $e->getMessage());
$this->error($message);
Log::error($message);
Log::error($e->getTraceAsString());
}
// A separate routine for preferences table:
if ('preferences' === $table) {
$this->decryptPreferencesRow($id, $value);
return;
}
if ($value !== $original) {
DB::table($table)->where('id', $id)->update([$field => $value]);
}
}
/**
* @param int $id
* @param string $value
*/
private function decryptPreferencesRow(int $id, string $value): void
{
// try to json_decrypt the value.
try {
$newValue = json_decode($value, true, 512, JSON_THROW_ON_ERROR) ?? $value;
} catch (JsonException $e) {
$message = sprintf('Could not JSON decode preference row #%d: %s', $id, $e->getMessage());
$this->error($message);
Log::error($message);
Log::error($value);
Log::error($e->getTraceAsString());
return;
}
/** @var Preference $object */
$object = Preference::find((int) $id);
if (null !== $object) {
$object->data = $newValue;
$object->save();
}
}
} }

View File

@@ -131,11 +131,11 @@ class ApplyRules extends Command
$ruleEngine->setUser($this->getUser()); $ruleEngine->setUser($this->getUser());
// add the accounts as filter: // add the accounts as filter:
$accounts = []; $filterAccountList = [];
foreach($this->accounts as $account) { foreach($this->accounts as $account) {
$accounts[] = $account->id; $filterAccountList[] = $account->id;
} }
$list = implode(',', $accounts); $list = implode(',', $filterAccountList);
$ruleEngine->addOperator(['type' => 'account_id', 'value' => $list]); $ruleEngine->addOperator(['type' => 'account_id', 'value' => $list]);
// add the date as a filter: // add the date as a filter:
@@ -295,7 +295,7 @@ class ApplyRules extends Command
private function verifyInputDates(): void private function verifyInputDates(): void
{ {
// parse start date. // parse start date.
$startDate = Carbon::now()->startOfMonth(); $inputStart = Carbon::now()->startOfMonth();
$startString = $this->option('start_date'); $startString = $this->option('start_date');
if (null === $startString) { if (null === $startString) {
/** @var JournalRepositoryInterface $repository */ /** @var JournalRepositoryInterface $repository */
@@ -303,26 +303,26 @@ class ApplyRules extends Command
$repository->setUser($this->getUser()); $repository->setUser($this->getUser());
$first = $repository->firstNull(); $first = $repository->firstNull();
if (null !== $first) { if (null !== $first) {
$startDate = $first->date; $inputStart = $first->date;
} }
} }
if (null !== $startString && '' !== $startString) { if (null !== $startString && '' !== $startString) {
$startDate = Carbon::createFromFormat('Y-m-d', $startString); $inputStart = Carbon::createFromFormat('Y-m-d', $startString);
} }
// parse end date // parse end date
$endDate = Carbon::now(); $inputEnd = Carbon::now();
$endString = $this->option('end_date'); $endString = $this->option('end_date');
if (null !== $endString && '' !== $endString) { if (null !== $endString && '' !== $endString) {
$endDate = Carbon::createFromFormat('Y-m-d', $endString); $inputEnd = Carbon::createFromFormat('Y-m-d', $endString);
} }
if ($startDate > $endDate) { if ($inputStart > $inputEnd) {
[$endDate, $startDate] = [$startDate, $endDate]; [$inputEnd, $inputStart] = [$inputStart, $inputEnd];
} }
$this->startDate = $startDate; $this->startDate = $inputStart;
$this->endDate = $endDate; $this->endDate = $inputEnd;
} }
/** /**

View File

@@ -72,8 +72,8 @@ class MigrateAttachments extends Command
foreach ($attachments as $att) { foreach ($attachments as $att) {
// move description: // move description:
$description = (string) $att->description; $attDescription = (string) $att->description;
if ('' !== $description) { if ('' !== $attDescription) {
// find or create note: // find or create note:
$note = $att->notes()->first(); $note = $att->notes()->first();
@@ -81,7 +81,7 @@ class MigrateAttachments extends Command
$note = new Note; $note = new Note;
$note->noteable()->associate($att); $note->noteable()->associate($att);
} }
$note->text = $description; $note->text = $attDescription;
$note->save(); $note->save();
// clear description: // clear description:

View File

@@ -58,23 +58,18 @@ class MigrateToGroups extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'firefly-iii:migrate-to-groups {--F|force : Force the migration, even if it fired before.}'; protected $signature = 'firefly-iii:migrate-to-groups {--F|force : Force the migration, even if it fired before.}';
/** @var JournalCLIRepositoryInterface */ private JournalCLIRepositoryInterface $cliRepository;
private $cliRepository; private int $count;
private $count; private TransactionGroupFactory $groupFactory;
/** @var TransactionGroupFactory */ private JournalRepositoryInterface $journalRepository;
private $groupFactory; private JournalDestroyService $service;
/** @var JournalRepositoryInterface */
private $journalRepository;
/** @var JournalDestroyService */
private $service;
/** /**
* Execute the console command. * Execute the console command.
* *
* @throws Exception
* @return int * @return int
* @throws Exception
*/ */
public function handle(): int public function handle(): int
{ {
@@ -254,16 +249,16 @@ class MigrateToGroups extends Command
private function makeGroupsFromAll(): void private function makeGroupsFromAll(): void
{ {
$orphanedJournals = $this->cliRepository->getJournalsWithoutGroup(); $orphanedJournals = $this->cliRepository->getJournalsWithoutGroup();
$count = count($orphanedJournals); $total = count($orphanedJournals);
if ($count > 0) { if ($total > 0) {
Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $count)); Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $total));
$this->line(sprintf('Going to convert %d transaction journals. Please hold..', $count)); $this->line(sprintf('Going to convert %d transaction journals. Please hold..', $total));
/** @var array $journal */ /** @var array $journal */
foreach ($orphanedJournals as $array) { foreach ($orphanedJournals as $array) {
$this->giveGroup($array); $this->giveGroup($array);
} }
} }
if (0 === $count) { if (0 === $total) {
$this->info('No need to convert transaction journals.'); $this->info('No need to convert transaction journals.');
} }
} }

View File

@@ -43,11 +43,13 @@ class OtherCurrenciesCorrections extends Command
public const CONFIG_NAME = '480_other_currencies'; public const CONFIG_NAME = '480_other_currencies';
/** /**
* The console command description. * The console command description.
*
* @var string * @var string
*/ */
protected $description = 'Update all journal currency information.'; protected $description = 'Update all journal currency information.';
/** /**
* The name and signature of the console command. * The name and signature of the console command.
*
* @var string * @var string
*/ */
protected $signature = 'firefly-iii:other-currencies {--F|force : Force the execution of this command.}'; protected $signature = 'firefly-iii:other-currencies {--F|force : Force the execution of this command.}';
@@ -67,6 +69,7 @@ class OtherCurrenciesCorrections extends Command
/** /**
* Execute the console command. * Execute the console command.
*
* @return int * @return int
*/ */
public function handle(): int public function handle(): int
@@ -93,6 +96,7 @@ class OtherCurrenciesCorrections extends Command
/** /**
* @param Account $account * @param Account $account
*
* @return TransactionCurrency|null * @return TransactionCurrency|null
*/ */
private function getCurrency(Account $account): ?TransactionCurrency private function getCurrency(Account $account): ?TransactionCurrency
@@ -120,7 +124,9 @@ class OtherCurrenciesCorrections extends Command
/** /**
* Gets the transaction that determines the transaction that "leads" and will determine * Gets the transaction that determines the transaction that "leads" and will determine
* the currency to be used by all transactions, and the journal itself. * the currency to be used by all transactions, and the journal itself.
*
* @param TransactionJournal $journal * @param TransactionJournal $journal
*
* @return Transaction|null * @return Transaction|null
*/ */
private function getLeadTransaction(TransactionJournal $journal): ?Transaction private function getLeadTransaction(TransactionJournal $journal): ?Transaction
@@ -128,6 +134,8 @@ class OtherCurrenciesCorrections extends Command
/** @var Transaction $lead */ /** @var Transaction $lead */
$lead = null; $lead = null;
switch ($journal->transactionType->type) { switch ($journal->transactionType->type) {
default:
break;
case TransactionType::WITHDRAWAL: case TransactionType::WITHDRAWAL:
$lead = $journal->transactions()->where('amount', '<', 0)->first(); $lead = $journal->transactions()->where('amount', '<', 0)->first();
break; break;
@@ -136,11 +144,15 @@ class OtherCurrenciesCorrections extends Command
break; break;
case TransactionType::OPENING_BALANCE: case TransactionType::OPENING_BALANCE:
// whichever isn't an initial balance account: // whichever isn't an initial balance account:
$lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')->where('account_types.type', '!=', AccountType::INITIAL_BALANCE)->first(['transactions.*']); $lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin(
'account_types', 'accounts.account_type_id', '=', 'account_types.id'
)->where('account_types.type', '!=', AccountType::INITIAL_BALANCE)->first(['transactions.*']);
break; break;
case TransactionType::RECONCILIATION: case TransactionType::RECONCILIATION:
// whichever isn't the reconciliation account: // whichever isn't the reconciliation account:
$lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')->where('account_types.type', '!=', AccountType::RECONCILIATION)->first(['transactions.*']); $lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin(
'account_types', 'accounts.account_type_id', '=', 'account_types.id'
)->where('account_types.type', '!=', AccountType::RECONCILIATION)->first(['transactions.*']);
break; break;
} }
@@ -172,6 +184,7 @@ class OtherCurrenciesCorrections extends Command
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is * Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should * executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
* be called from the handle method instead of using the constructor to initialize the command. * be called from the handle method instead of using the constructor to initialize the command.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
private function stupidLaravel(): void private function stupidLaravel(): void
@@ -209,27 +222,33 @@ class OtherCurrenciesCorrections extends Command
$currency = $this->getCurrency($account); $currency = $this->getCurrency($account);
if (null === $currency) { if (null === $currency) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$this->error(sprintf('Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected', $account->id, $account->name, $journal->id)); $this->error(
sprintf(
'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected', $account->id, $account->name, $journal->id
)
);
$this->count++; $this->count++;
return; return;
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
// fix each transaction: // fix each transaction:
$journal->transactions->each(static function (Transaction $transaction) use ($currency) { $journal->transactions->each(
if (null === $transaction->transaction_currency_id) { static function (Transaction $transaction) use ($currency) {
$transaction->transaction_currency_id = $currency->id; if (null === $transaction->transaction_currency_id) {
$transaction->save(); $transaction->transaction_currency_id = $currency->id;
} $transaction->save();
}
// when mismatch in transaction: // when mismatch in transaction:
if (!((int)$transaction->transaction_currency_id === (int)$currency->id)) { if ((int)$transaction->transaction_currency_id !== (int)$currency->id) {
$transaction->foreign_currency_id = (int)$transaction->transaction_currency_id; $transaction->foreign_currency_id = (int)$transaction->transaction_currency_id;
$transaction->foreign_amount = $transaction->amount; $transaction->foreign_amount = $transaction->amount;
$transaction->transaction_currency_id = $currency->id; $transaction->transaction_currency_id = $currency->id;
$transaction->save(); $transaction->save();
}
} }
}); );
// also update the journal, of course: // also update the journal, of course:
$journal->transaction_currency_id = $currency->id; $journal->transaction_currency_id = $currency->id;
$this->count++; $this->count++;
@@ -244,7 +263,9 @@ class OtherCurrenciesCorrections extends Command
*/ */
private function updateOtherJournalsCurrencies(): void private function updateOtherJournalsCurrencies(): void
{ {
$set = $this->cliRepos->getAllJournals([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]); $set = $this->cliRepos->getAllJournals(
[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]
);
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
foreach ($set as $journal) { foreach ($set as $journal) {

View File

@@ -87,7 +87,7 @@ trait VerifiesAccessToken
return false; return false;
} }
if (!($accessToken->data === $token)) { if ($accessToken->data !== $token) {
Log::error(sprintf('Invalid access token for user #%d.', $userId)); Log::error(sprintf('Invalid access token for user #%d.', $userId));
Log::error(sprintf('Token given is "%s", expected something else.', $token)); Log::error(sprintf('Token given is "%s", expected something else.', $token));

View File

@@ -56,14 +56,14 @@ class Kernel extends ConsoleKernel
$schedule->call( $schedule->call(
static function () { static function () {
Log::error( Log::error(
'Firefly III no longer users the Laravel scheduler to do cron jobs! Please read the instructions at https://firefly-iii.readthedocs.io/en/latest/' 'Firefly III no longer users the Laravel scheduler to do cron jobs! Please read the instructions at https://docs.firefly-iii.org/'
); );
echo "\n"; echo "\n";
echo '------------'; echo '------------';
echo "\n"; echo "\n";
echo wordwrap('Firefly III no longer users the Laravel scheduler to do cron jobs! Please read the instructions here:'); echo wordwrap('Firefly III no longer users the Laravel scheduler to do cron jobs! Please read the instructions here:');
echo "\n"; echo "\n";
echo 'https://firefly-iii.readthedocs.io/en/latest/'; echo 'https://docs.firefly-iii.org/';
echo "\n\n"; echo "\n\n";
echo 'Disable this cron job!'; echo 'Disable this cron job!';
echo "\n"; echo "\n";

View File

@@ -77,6 +77,8 @@ class GracefulNotFoundHandler extends ExceptionHandler
return $this->handleGroup($request, $exception); return $this->handleGroup($request, $exception);
case 'attachments.show': case 'attachments.show':
case 'attachments.edit': case 'attachments.edit':
case 'attachments.download':
case 'attachments.view':
// redirect to original attachment holder. // redirect to original attachment holder.
return $this->handleAttachment($request, $exception); return $this->handleAttachment($request, $exception);
break; break;
@@ -117,12 +119,10 @@ class GracefulNotFoundHandler extends ExceptionHandler
$request->session()->reflash(); $request->session()->reflash();
return redirect(route('categories.index')); return redirect(route('categories.index'));
break;
case 'rules.edit': case 'rules.edit':
$request->session()->reflash(); $request->session()->reflash();
return redirect(route('rules.index')); return redirect(route('rules.index'));
break;
case 'transactions.edit': case 'transactions.edit':
case 'transactions.mass.edit': case 'transactions.mass.edit':
case 'transactions.mass.delete': case 'transactions.mass.delete':

View File

@@ -29,7 +29,6 @@ use FireflyIII\Models\Note;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\User; use FireflyIII\User;
use Log;
/** /**
* Class AttachmentFactory * Class AttachmentFactory

View File

@@ -40,21 +40,7 @@ class BillFactory
{ {
use BillServiceTrait, CreatesObjectGroups; use BillServiceTrait, CreatesObjectGroups;
/** @var User */ private User $user;
private $user;
/**
* Constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
}
}
/** /**
* @param array $data * @param array $data
@@ -153,11 +139,7 @@ class BillFactory
*/ */
public function findByName(string $name): ?Bill public function findByName(string $name): ?Bill
{ {
$query = sprintf('%%%s%%', $name); return $this->user->bills()->where('name', 'LIKE', sprintf('%%%s%%', $name))->first();
/** @var Bill $first */
$first = $this->user->bills()->where('name', 'LIKE', $query)->first();
return $first;
} }
/** /**

View File

@@ -25,28 +25,13 @@ namespace FireflyIII\Factory;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\User; use FireflyIII\User;
use Log;
/** /**
* Class BudgetFactory. * Class BudgetFactory.
*/ */
class BudgetFactory class BudgetFactory
{ {
/** @var User */ private User $user;
private $user;
/**
* Constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
}
}
/** /**
* @param int|null $budgetId * @param int|null $budgetId

View File

@@ -35,21 +35,7 @@ use Log;
*/ */
class CategoryFactory class CategoryFactory
{ {
/** @var User */ private User $user;
private $user;
/**
* Constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
}
}
/** /**
* @param string $name * @param string $name

View File

@@ -37,18 +37,6 @@ use Log;
*/ */
class PiggyBankEventFactory class PiggyBankEventFactory
{ {
/**
* Constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
}
}
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* @param PiggyBank|null $piggyBank * @param PiggyBank|null $piggyBank

View File

@@ -26,28 +26,13 @@ namespace FireflyIII\Factory;
use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBank;
use FireflyIII\User; use FireflyIII\User;
use Log;
/** /**
* Class PiggyBankFactory * Class PiggyBankFactory
*/ */
class PiggyBankFactory class PiggyBankFactory
{ {
/** @var User */ private User $user;
private $user;
/**
* Constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
}
}
/** /**
* @param int|null $piggyBankId * @param int|null $piggyBankId

View File

@@ -27,7 +27,6 @@ namespace FireflyIII\Factory;
use FireflyIII\Models\Location; use FireflyIII\Models\Location;
use FireflyIII\Models\Tag; use FireflyIII\Models\Tag;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Support\Collection;
use Log; use Log;
/** /**
@@ -79,10 +78,12 @@ class TagFactory
public function findOrCreate(string $tag): ?Tag public function findOrCreate(string $tag): ?Tag
{ {
$tag = trim($tag); $tag = trim($tag);
Log::debug(sprintf('Now in TagFactory::findOrCreate("%s")', $tag));
/** @var Tag $dbTag */ /** @var Tag $dbTag */
$dbTag = $this->user->tags()->where('tag', $tag)->first(); $dbTag = $this->user->tags()->where('tag', $tag)->first();
if (null !== $dbTag) { if (null !== $dbTag) {
Log::debug(sprintf('Tag exists (#%d), return it.', $dbTag->id));
return $dbTag; return $dbTag;
} }
$newTag = $this->create( $newTag = $this->create(
@@ -95,6 +96,11 @@ class TagFactory
'zoom_level' => null, 'zoom_level' => null,
] ]
); );
if (null === $newTag) {
Log::error(sprintf('TagFactory::findOrCreate("%s") but tag is unexpectedly NULL!', $tag));
return null;
}
Log::debug(sprintf('Created new tag #%d ("%s")', $newTag->id, $newTag->tag));
return $newTag; return $newTag;
} }

View File

@@ -59,6 +59,7 @@ class TransactionGroupFactory
*/ */
public function create(array $data): TransactionGroup public function create(array $data): TransactionGroup
{ {
Log::debug('Now in TransactionGroupFactory::create()');
$this->journalFactory->setUser($this->user); $this->journalFactory->setUser($this->user);
$this->journalFactory->setErrorOnHash($data['error_if_duplicate_hash'] ?? false); $this->journalFactory->setErrorOnHash($data['error_if_duplicate_hash'] ?? false);
try { try {

View File

@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Factory; namespace FireflyIII\Factory;
use Carbon\Carbon;
use Exception; use Exception;
use FireflyIII\Exceptions\DuplicateTransactionException; use FireflyIII\Exceptions\DuplicateTransactionException;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
@@ -56,26 +55,17 @@ class TransactionJournalFactory
{ {
use JournalServiceTrait; use JournalServiceTrait;
private AccountRepositoryInterface $accountRepository; private AccountRepositoryInterface $accountRepository;
private AccountValidator $accountValidator; private AccountValidator $accountValidator;
private BillRepositoryInterface $billRepository; private BillRepositoryInterface $billRepository;
/** @var CurrencyRepositoryInterface */ private CurrencyRepositoryInterface $currencyRepository;
private $currencyRepository; private bool $errorOnHash;
/** @var bool */ private array $fields;
private $errorOnHash; private PiggyBankEventFactory $piggyEventFactory;
/** @var array */ private PiggyBankRepositoryInterface $piggyRepository;
private $fields; private TransactionFactory $transactionFactory;
/** @var PiggyBankEventFactory */ private TransactionTypeRepositoryInterface $typeRepository;
private $piggyEventFactory; private User $user;
/** @var PiggyBankRepositoryInterface */
private $piggyRepository;
/** @var TransactionFactory */
private $transactionFactory;
/** @var TransactionTypeRepositoryInterface */
private $typeRepository;
/** @var User The user */
private $user;
/** /**
* Constructor. * Constructor.
@@ -112,7 +102,6 @@ class TransactionJournalFactory
$this->currencyRepository = app(CurrencyRepositoryInterface::class); $this->currencyRepository = app(CurrencyRepositoryInterface::class);
$this->typeRepository = app(TransactionTypeRepositoryInterface::class); $this->typeRepository = app(TransactionTypeRepositoryInterface::class);
$this->transactionFactory = app(TransactionFactory::class);
$this->billRepository = app(BillRepositoryInterface::class); $this->billRepository = app(BillRepositoryInterface::class);
$this->budgetRepository = app(BudgetRepositoryInterface::class); $this->budgetRepository = app(BudgetRepositoryInterface::class);
$this->categoryRepository = app(CategoryRepositoryInterface::class); $this->categoryRepository = app(CategoryRepositoryInterface::class);
@@ -134,6 +123,7 @@ class TransactionJournalFactory
*/ */
public function create(array $data): Collection public function create(array $data): Collection
{ {
Log::debug('Now in TransactionJournalFactory::create()');
// convert to special object. // convert to special object.
$dataObject = new NullArrayObject($data); $dataObject = new NullArrayObject($data);
@@ -195,7 +185,6 @@ class TransactionJournalFactory
$this->user = $user; $this->user = $user;
$this->currencyRepository->setUser($this->user); $this->currencyRepository->setUser($this->user);
$this->tagFactory->setUser($user); $this->tagFactory->setUser($user);
$this->transactionFactory->setUser($this->user);
$this->billRepository->setUser($this->user); $this->billRepository->setUser($this->user);
$this->budgetRepository->setUser($this->user); $this->budgetRepository->setUser($this->user);
$this->categoryRepository->setUser($this->user); $this->categoryRepository->setUser($this->user);
@@ -328,7 +317,6 @@ class TransactionJournalFactory
Log::debug(sprintf('Created new journal #%d: "%s"', $journal->id, $journal->description)); Log::debug(sprintf('Created new journal #%d: "%s"', $journal->id, $journal->description));
/** Create two transactions. */ /** Create two transactions. */
/** @var TransactionFactory $transactionFactory */
$transactionFactory = app(TransactionFactory::class); $transactionFactory = app(TransactionFactory::class);
$transactionFactory->setUser($this->user); $transactionFactory->setUser($this->user);
$transactionFactory->setJournal($journal); $transactionFactory->setJournal($journal);

View File

@@ -209,7 +209,7 @@ class ChartJsGenerator implements GeneratorInterface
*/ */
public function singleSet(string $setLabel, array $data): array public function singleSet(string $setLabel, array $data): array
{ {
$chartData = [ return [
'count' => 1, 'count' => 1,
'labels' => array_keys($data), // take ALL labels from the first set. 'labels' => array_keys($data), // take ALL labels from the first set.
'datasets' => [ 'datasets' => [
@@ -219,7 +219,5 @@ class ChartJsGenerator implements GeneratorInterface
], ],
], ],
]; ];
return $chartData;
} }
} }

View File

@@ -41,12 +41,9 @@ use Throwable;
*/ */
class MonthReportGenerator implements ReportGeneratorInterface class MonthReportGenerator implements ReportGeneratorInterface
{ {
/** @var Collection The accounts used. */ private Collection $accounts;
private $accounts; private Carbon $end;
/** @var Carbon End date of the report. */ private Carbon $start;
private $end;
/** @var Carbon Start date of the report. */
private $start;
/** /**
* Generates the report. * Generates the report.
@@ -155,7 +152,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
} }
$locale = app('steam')->getLocale(); $locale = app('steam')->getLocale();
$return = [ return [
'journals' => $journals, 'journals' => $journals,
'currency' => $currency, 'currency' => $currency,
'exists' => count($journals) > 0, 'exists' => count($journals) > 0,
@@ -164,8 +161,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
'dayBefore' => $date->formatLocalized((string) trans('config.month_and_day', [], $locale)), 'dayBefore' => $date->formatLocalized((string) trans('config.month_and_day', [], $locale)),
'dayBeforeBalance' => $dayBeforeBalance, 'dayBeforeBalance' => $dayBeforeBalance,
]; ];
return $return;
} }
/** /**

View File

@@ -29,7 +29,6 @@ use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\Category; use FireflyIII\Models\Category;
use FireflyIII\Models\Tag; use FireflyIII\Models\Tag;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\JoinClause; use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;

View File

@@ -190,7 +190,9 @@ class GroupCollector implements GroupCollectorInterface
public function getPaginatedGroups(): LengthAwarePaginator public function getPaginatedGroups(): LengthAwarePaginator
{ {
$set = $this->getGroups(); $set = $this->getGroups();
if(0===$this->limit) {
$this->setLimit(50);
}
return new LengthAwarePaginator($set, $this->total, $this->limit, $this->page); return new LengthAwarePaginator($set, $this->total, $this->limit, $this->page);
} }
@@ -528,6 +530,7 @@ class GroupCollector implements GroupCollectorInterface
->where( ->where(
static function (EloquentBuilder $q1) { static function (EloquentBuilder $q1) {
$q1->where('attachments.attachable_type', TransactionJournal::class); $q1->where('attachments.attachable_type', TransactionJournal::class);
$q1->where('attachments.uploaded',1);
$q1->orWhereNull('attachments.attachable_type'); $q1->orWhereNull('attachments.attachable_type');
} }
); );

View File

@@ -186,7 +186,6 @@ class EditController extends Controller
$this->repository->update($account, $data); $this->repository->update($account, $data);
$request->session()->flash('success', (string) trans('firefly.updated_account', ['name' => $account->name])); $request->session()->flash('success', (string) trans('firefly.updated_account', ['name' => $account->name]));
app('preferences')->mark();
// store new attachment(s): // store new attachment(s):
$files = $request->hasFile('attachments') ? $request->file('attachments') : null; $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
@@ -209,6 +208,7 @@ class EditController extends Controller
$redirect = redirect(route('accounts.edit', [$account->id]))->withInput(['return_to_edit' => 1]); $redirect = redirect(route('accounts.edit', [$account->id]))->withInput(['return_to_edit' => 1]);
} }
app('preferences')->mark();
return $redirect; return $redirect;
} }

Some files were not shown because too many files have changed in this diff Show More