mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
Code cleanup [skip ci]
This commit is contained in:
@@ -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 = [];
|
||||||
|
|
||||||
|
@@ -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(
|
||||||
|
@@ -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
|
||||||
|
@@ -131,93 +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_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
|
||||||
@@ -288,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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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']]),
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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');
|
||||||
|
|
||||||
|
@@ -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;
|
||||||
|
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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,27 +60,6 @@ class RuleGroupTestRequest extends FormRequest
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function rules(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'start' => 'date',
|
|
||||||
'end' => 'date|after:start',
|
|
||||||
'accounts' => '',
|
|
||||||
'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
private function getAccounts(): string
|
|
||||||
{
|
|
||||||
return (string) $this->query('accounts');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $field
|
* @param string $field
|
||||||
*
|
*
|
||||||
@@ -98,4 +73,25 @@ class RuleGroupTestRequest extends FormRequest
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
private function getAccounts(): string
|
||||||
|
{
|
||||||
|
return (string) $this->query('accounts');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'start' => 'date',
|
||||||
|
'end' => 'date|after:start',
|
||||||
|
'accounts' => '',
|
||||||
|
'accounts.*' => 'exists:accounts,id|belongsToUser:accounts',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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,14 @@ class RuleGroupTriggerRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @param string $field
|
||||||
|
*
|
||||||
|
* @return Carbon|null
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
private function getDate(string $field): ?Carbon
|
||||||
{
|
{
|
||||||
return [
|
/** @var Carbon $result */
|
||||||
'start' => 'date',
|
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field));
|
||||||
'end' => 'date|after:start',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,14 +79,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',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -62,24 +62,12 @@ class RuleTestRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
private function getPage(): int
|
||||||
{
|
{
|
||||||
return [
|
return 0 === (int) $this->query('page') ? 1 : (int) $this->query('page');
|
||||||
'start' => 'date',
|
|
||||||
'end' => 'date|after:start',
|
|
||||||
'accounts' => '',
|
|
||||||
'accounts.*' => 'required|exists:accounts,id|belongsToUser:accounts',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function getAccounts(): string
|
|
||||||
{
|
|
||||||
return (string) $this->query('accounts');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,12 +84,24 @@ class RuleTestRequest extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function getPage(): int
|
private function getAccounts(): string
|
||||||
{
|
{
|
||||||
return 0 === (int) $this->query('page') ? 1 : (int) $this->query('page');
|
return (string) $this->query('accounts');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'start' => 'date',
|
||||||
|
'end' => 'date|after:start',
|
||||||
|
'accounts' => '',
|
||||||
|
'accounts.*' => 'required|exists:accounts,id|belongsToUser:accounts',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
@@ -199,104 +299,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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
@@ -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.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user