mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-23 19:51:24 +00:00
Expand tests and API code.
This commit is contained in:
@@ -98,7 +98,7 @@ class BillController extends Controller
|
||||
$resource = new FractalCollection($bills, new BillTransformer($this->parameters), 'bills');
|
||||
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray());
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ class BillController extends Controller
|
||||
|
||||
$resource = new Item($bill, new BillTransformer($this->parameters), 'bills');
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray());
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +137,7 @@ class BillController extends Controller
|
||||
|
||||
$resource = new Item($bill, new BillTransformer($this->parameters), 'bills');
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray());
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ class BillController extends Controller
|
||||
|
||||
$resource = new Item($bill, new BillTransformer($this->parameters), 'bills');
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray());
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
/**
|
||||
* Class Controller.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Controller extends BaseController
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Controllers;
|
||||
use FireflyIII\Api\V1\Requests\TransactionRequest;
|
||||
use FireflyIII\Factory\TransactionJournalFactory;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
||||
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
|
||||
@@ -107,7 +108,7 @@ class TransactionController extends Controller
|
||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||
|
||||
// collect transactions using the journal collector
|
||||
$collector = new JournalCollector;
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser(auth()->user());
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
@@ -130,7 +131,7 @@ class TransactionController extends Controller
|
||||
$resource = new FractalCollection($transactions, new TransactionTransformer($this->parameters), 'transactions');
|
||||
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray());
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +153,7 @@ class TransactionController extends Controller
|
||||
|
||||
// needs a lot of extra data to match the journal collector. Or just expand that one.
|
||||
// collect transactions using the journal collector
|
||||
$collector = new JournalCollector;
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser(auth()->user());
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
||||
// filter on specific journals.
|
||||
@@ -167,11 +168,10 @@ class TransactionController extends Controller
|
||||
$collector->addFilter(NegativeAmountFilter::class);
|
||||
}
|
||||
|
||||
$transaction = $collector->getJournals();
|
||||
$transactions = $collector->getJournals();
|
||||
$resource = new Item($transactions->first(), new TransactionTransformer($this->parameters), 'transactions');
|
||||
|
||||
$resource = new FractalCollection($transaction, new TransactionTransformer($this->parameters), 'transactions');
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray());
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,7 +199,7 @@ class TransactionController extends Controller
|
||||
|
||||
// needs a lot of extra data to match the journal collector. Or just expand that one.
|
||||
// collect transactions using the journal collector
|
||||
$collector = new JournalCollector;
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser(auth()->user());
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
||||
// filter on specific journals.
|
||||
@@ -214,10 +214,10 @@ class TransactionController extends Controller
|
||||
$collector->addFilter(NegativeAmountFilter::class);
|
||||
}
|
||||
|
||||
$transaction = $collector->getJournals();
|
||||
$resource = new FractalCollection($transaction, new TransactionTransformer($this->parameters), 'transactions');
|
||||
$transactions = $collector->getJournals();
|
||||
$resource = new Item($transactions->first(), new TransactionTransformer($this->parameters), 'transactions');
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray());
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ class TransactionController extends Controller
|
||||
|
||||
$resource = new Item($bill, new BillTransformer($this->parameters), 'bills');
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray());
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ class TransactionController extends Controller
|
||||
return $types[$type];
|
||||
}
|
||||
|
||||
return $types['default'];
|
||||
return $types['default']; // @codeCoverageIgnore
|
||||
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Requests;
|
||||
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
/**
|
||||
* Class BillRequest
|
||||
*/
|
||||
@@ -93,4 +95,25 @@ class BillRequest extends Request
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator instance.
|
||||
*
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(
|
||||
function (Validator $validator) {
|
||||
$data = $validator->getData();
|
||||
$min = floatval($data['amount_min']);
|
||||
$max = floatval($data['amount_max']);
|
||||
if ($min > $max) {
|
||||
$validator->errors()->add('amount_min', trans('validation.amount_min_over_max'));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -77,27 +77,26 @@ class TransactionRequest extends Request
|
||||
];
|
||||
foreach ($this->get('transactions') as $transaction) {
|
||||
$array = [
|
||||
'description' => $transaction['description'] ?? null,
|
||||
'amount' => $transaction['amount'],
|
||||
'currency_id' => isset($transaction['currency_id']) ? intval($transaction['currency_id']) : null,
|
||||
'currency_code' => isset($transaction['currency_code']) ? $transaction['currency_code'] : null,
|
||||
'foreign_amount' => $transaction['foreign_amount'] ?? null,
|
||||
'foreign_currency_id' => isset($transaction['foreign_currency_id']) ? intval($transaction['foreign_currency_id']) : null,
|
||||
'foreign_currency_code' => $transaction['foreign_currency_code'] ?? null,
|
||||
'budget_id' => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : null,
|
||||
'budget_name' => $transaction['budget_name'] ?? null,
|
||||
'category_id' => isset($transaction['category_id']) ? intval($transaction['category_id']) : null,
|
||||
'category_name' => $transaction['category_name'] ?? null,
|
||||
'source_account_id' => isset($transaction['source_account_id']) ? intval($transaction['source_account_id']) : null,
|
||||
'source_account_name' => $transaction['source_account_name'] ?? null,
|
||||
'destination_account_id' => isset($transaction['destination_account_id']) ? intval($transaction['destination_account_id']) : null,
|
||||
'destination_account_name' => $transaction['destination_account_name'] ?? null,
|
||||
'reconciled' => intval($transaction['reconciled'] ?? 0) === 1 ? true : false,
|
||||
'identifier' => isset($transaction['identifier']) ? intval($transaction['identifier']) : 0,
|
||||
'description' => $transaction['description'] ?? null,
|
||||
'amount' => $transaction['amount'],
|
||||
'currency_id' => isset($transaction['currency_id']) ? intval($transaction['currency_id']) : null,
|
||||
'currency_code' => isset($transaction['currency_code']) ? $transaction['currency_code'] : null,
|
||||
'foreign_amount' => $transaction['foreign_amount'] ?? null,
|
||||
'foreign_currency_id' => isset($transaction['foreign_currency_id']) ? intval($transaction['foreign_currency_id']) : null,
|
||||
'foreign_currency_code' => $transaction['foreign_currency_code'] ?? null,
|
||||
'budget_id' => isset($transaction['budget_id']) ? intval($transaction['budget_id']) : null,
|
||||
'budget_name' => $transaction['budget_name'] ?? null,
|
||||
'category_id' => isset($transaction['category_id']) ? intval($transaction['category_id']) : null,
|
||||
'category_name' => $transaction['category_name'] ?? null,
|
||||
'source_id' => isset($transaction['source_id']) ? intval($transaction['source_id']) : null,
|
||||
'source_name' => $transaction['source_name'] ?? null,
|
||||
'destination_id' => isset($transaction['destination_id']) ? intval($transaction['destination_id']) : null,
|
||||
'destination_name' => $transaction['destination_name'] ?? null,
|
||||
'reconciled' => intval($transaction['reconciled'] ?? 0) === 1 ? true : false,
|
||||
'identifier' => isset($transaction['identifier']) ? intval($transaction['identifier']) : 0,
|
||||
];
|
||||
$data['transactions'][] = $array;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -108,44 +107,44 @@ class TransactionRequest extends Request
|
||||
{
|
||||
return [
|
||||
// basic fields for journal:
|
||||
'type' => 'required|in:withdrawal,deposit,transfer',
|
||||
'date' => 'required|date',
|
||||
'description' => 'between:1,255',
|
||||
'piggy_bank_id' => ['numeric', 'nullable', 'mustExist:piggy_banks,id', new BelongsUser],
|
||||
'piggy_bank_name' => ['between:1,255', 'nullable', new BelongsUser],
|
||||
'bill_id' => ['numeric', 'nullable', 'mustExist:bills,id', new BelongsUser],
|
||||
'bill_name' => ['between:1,255', 'nullable', new BelongsUser],
|
||||
'tags' => 'between:1,255',
|
||||
'type' => 'required|in:withdrawal,deposit,transfer',
|
||||
'date' => 'required|date',
|
||||
'description' => 'between:1,255',
|
||||
'piggy_bank_id' => ['numeric', 'nullable', 'mustExist:piggy_banks,id', new BelongsUser],
|
||||
'piggy_bank_name' => ['between:1,255', 'nullable', new BelongsUser],
|
||||
'bill_id' => ['numeric', 'nullable', 'mustExist:bills,id', new BelongsUser],
|
||||
'bill_name' => ['between:1,255', 'nullable', new BelongsUser],
|
||||
'tags' => 'between:1,255',
|
||||
|
||||
// then, custom fields for journal
|
||||
'interest_date' => 'date|nullable',
|
||||
'book_date' => 'date|nullable',
|
||||
'process_date' => 'date|nullable',
|
||||
'due_date' => 'date|nullable',
|
||||
'payment_date' => 'date|nullable',
|
||||
'invoice_date' => 'date|nullable',
|
||||
'internal_reference' => 'min:1,max:255|nullable',
|
||||
'notes' => 'min:1,max:50000|nullable',
|
||||
'interest_date' => 'date|nullable',
|
||||
'book_date' => 'date|nullable',
|
||||
'process_date' => 'date|nullable',
|
||||
'due_date' => 'date|nullable',
|
||||
'payment_date' => 'date|nullable',
|
||||
'invoice_date' => 'date|nullable',
|
||||
'internal_reference' => 'min:1,max:255|nullable',
|
||||
'notes' => 'min:1,max:50000|nullable',
|
||||
|
||||
// transaction rules (in array for splits):
|
||||
'transactions.*.description' => 'nullable|between:1,255',
|
||||
'transactions.*.amount' => 'required|numeric|more:0',
|
||||
'transactions.*.currency_id' => 'numeric|exists:transaction_currencies,id|required_without:transactions.*.currency_code',
|
||||
'transactions.*.currency_code' => 'min:3|max:3|exists:transaction_currencies,code|required_without:transactions.*.currency_id',
|
||||
'transactions.*.foreign_amount' => 'numeric|more:0',
|
||||
'transactions.*.foreign_currency_id' => 'numeric|exists:transaction_currencies,id',
|
||||
'transactions.*.foreign_currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
|
||||
'transactions.*.budget_id' => ['mustExist:budgets,id', new BelongsUser],
|
||||
'transactions.*.budget_name' => ['between:1,255', 'nullable', new BelongsUser],
|
||||
'transactions.*.category_id' => ['mustExist:categories,id', new BelongsUser],
|
||||
'transactions.*.category_name' => 'between:1,255|nullable',
|
||||
'transactions.*.reconciled' => 'boolean|nullable',
|
||||
'transactions.*.identifier' => 'numeric|nullable',
|
||||
'transactions.*.description' => 'nullable|between:1,255',
|
||||
'transactions.*.amount' => 'required|numeric|more:0',
|
||||
'transactions.*.currency_id' => 'numeric|exists:transaction_currencies,id|required_without:transactions.*.currency_code',
|
||||
'transactions.*.currency_code' => 'min:3|max:3|exists:transaction_currencies,code|required_without:transactions.*.currency_id',
|
||||
'transactions.*.foreign_amount' => 'numeric|more:0',
|
||||
'transactions.*.foreign_currency_id' => 'numeric|exists:transaction_currencies,id',
|
||||
'transactions.*.foreign_currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
|
||||
'transactions.*.budget_id' => ['mustExist:budgets,id', new BelongsUser],
|
||||
'transactions.*.budget_name' => ['between:1,255', 'nullable', new BelongsUser],
|
||||
'transactions.*.category_id' => ['mustExist:categories,id', new BelongsUser],
|
||||
'transactions.*.category_name' => 'between:1,255|nullable',
|
||||
'transactions.*.reconciled' => 'boolean|nullable',
|
||||
'transactions.*.identifier' => 'numeric|nullable',
|
||||
// basic rules will be expanded later.
|
||||
'transactions.*.source_account_id' => ['numeric', 'nullable', new BelongsUser],
|
||||
'transactions.*.source_account_name' => 'between:1,255|nullable',
|
||||
'transactions.*.destination_account_id' => ['numeric', 'nullable', new BelongsUser],
|
||||
'transactions.*.destination_account_name' => 'between:1,255|nullable',
|
||||
'transactions.*.source_id' => ['numeric', 'nullable', new BelongsUser],
|
||||
'transactions.*.source_name' => 'between:1,255|nullable',
|
||||
'transactions.*.destination_id' => ['numeric', 'nullable', new BelongsUser],
|
||||
'transactions.*.destination_name' => 'between:1,255|nullable',
|
||||
|
||||
// todo tags
|
||||
|
||||
@@ -377,37 +376,37 @@ class TransactionRequest extends Request
|
||||
$transactions = $data['transactions'] ?? [];
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
|
||||
$sourceId = isset($transaction['source_account_id']) ? intval($transaction['source_account_id']) : null;
|
||||
$sourceName = $transaction['source_account_name'] ?? null;
|
||||
$destinationId = isset($transaction['destination_account_id']) ? intval($transaction['destination_account_id']) : null;
|
||||
$destinationName = $transaction['destination_account_name'] ?? null;
|
||||
$sourceId = isset($transaction['source_id']) ? intval($transaction['source_id']) : null;
|
||||
$sourceName = $transaction['source_name'] ?? null;
|
||||
$destinationId = isset($transaction['destination_id']) ? intval($transaction['destination_id']) : null;
|
||||
$destinationName = $transaction['destination_name'] ?? null;
|
||||
|
||||
switch ($data['type']) {
|
||||
case 'withdrawal':
|
||||
$idField = 'transactions.' . $index . '.source_account_id';
|
||||
$nameField = 'transactions.' . $index . '.source_account_name';
|
||||
$idField = 'transactions.' . $index . '.source_id';
|
||||
$nameField = 'transactions.' . $index . '.source_name';
|
||||
$this->assetAccountExists($validator, $sourceId, $sourceName, $idField, $nameField);
|
||||
|
||||
$idField = 'transactions.' . $index . '.destination_account_id';
|
||||
$nameField = 'transactions.' . $index . '.destination_account_name';
|
||||
$idField = 'transactions.' . $index . '.destination_id';
|
||||
$nameField = 'transactions.' . $index . '.destination_name';
|
||||
$this->opposingAccountExists($validator, AccountType::EXPENSE, $destinationId, $destinationName, $idField, $nameField);
|
||||
break;
|
||||
case 'deposit':
|
||||
$idField = 'transactions.' . $index . '.source_account_id';
|
||||
$nameField = 'transactions.' . $index . '.source_account_name';
|
||||
$idField = 'transactions.' . $index . '.source_id';
|
||||
$nameField = 'transactions.' . $index . '.source_name';
|
||||
$this->opposingAccountExists($validator, AccountType::REVENUE, $sourceId, $sourceName, $idField, $nameField);
|
||||
|
||||
$idField = 'transactions.' . $index . '.destination_account_id';
|
||||
$nameField = 'transactions.' . $index . '.destination_account_name';
|
||||
$idField = 'transactions.' . $index . '.destination_id';
|
||||
$nameField = 'transactions.' . $index . '.destination_name';
|
||||
$this->assetAccountExists($validator, $destinationId, $destinationName, $idField, $nameField);
|
||||
break;
|
||||
case 'transfer':
|
||||
$idField = 'transactions.' . $index . '.source_account_id';
|
||||
$nameField = 'transactions.' . $index . '.source_account_name';
|
||||
$idField = 'transactions.' . $index . '.source_id';
|
||||
$nameField = 'transactions.' . $index . '.source_name';
|
||||
$this->assetAccountExists($validator, $sourceId, $sourceName, $idField, $nameField);
|
||||
|
||||
$idField = 'transactions.' . $index . '.destination_account_id';
|
||||
$nameField = 'transactions.' . $index . '.destination_account_name';
|
||||
$idField = 'transactions.' . $index . '.destination_id';
|
||||
$nameField = 'transactions.' . $index . '.destination_name';
|
||||
$this->assetAccountExists($validator, $destinationId, $destinationName, $idField, $nameField);
|
||||
break;
|
||||
default:
|
||||
|
||||
88
app/Factory/PiggyBankEventFactory.php
Normal file
88
app/Factory/PiggyBankEventFactory.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* PiggyBankEventFactory.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Factory;
|
||||
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class PiggyBankEventFactory
|
||||
*/
|
||||
class PiggyBankEventFactory
|
||||
{
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param PiggyBank|null $piggyBank
|
||||
*
|
||||
* @return PiggyBankEvent|null
|
||||
*/
|
||||
public function create(TransactionJournal $journal, ?PiggyBank $piggyBank): ?PiggyBankEvent
|
||||
{
|
||||
if (is_null($piggyBank)) {
|
||||
return null;
|
||||
}
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
/** @var PiggyBankRepositoryInterface $piggyRepos */
|
||||
$piggyRepos = app(PiggyBankRepositoryInterface::class);
|
||||
$repository->setUser($journal->user);
|
||||
$piggyRepos->setUser($journal->user);
|
||||
|
||||
|
||||
// is a transfer?
|
||||
if (!$repository->isTransfer($journal)) {
|
||||
Log::info(sprintf('Will not connect %s #%d to a piggy bank.', $journal->transactionType->type, $journal->id));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// repetition exists?
|
||||
$repetition = $piggyRepos->getRepetition($piggyBank, $journal->date);
|
||||
if (null === $repetition->id) {
|
||||
Log::error(sprintf('No piggy bank repetition on %s!', $journal->date->format('Y-m-d')));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// get the amount
|
||||
$amount = $piggyRepos->getExactAmount($piggyBank, $repetition, $journal);
|
||||
if (0 === bccomp($amount, '0')) {
|
||||
Log::debug('Amount is zero, will not create event.');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// update amount
|
||||
$piggyRepos->addAmountToRepetition($repetition, $amount);
|
||||
$event = $piggyRepos->createEventWithJournal($piggyBank, $amount, $journal);
|
||||
|
||||
Log::debug(sprintf('Created piggy bank event #%d', $event->id));
|
||||
|
||||
return $event;
|
||||
}
|
||||
}
|
||||
@@ -46,9 +46,31 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
class TransactionFactory
|
||||
{
|
||||
/** @var AccountRepositoryInterface */
|
||||
private $accountRepository;
|
||||
/** @var BudgetRepositoryInterface */
|
||||
private $budgetRepository;
|
||||
/** @var CategoryRepositoryInterface */
|
||||
private $categoryRepository;
|
||||
/** @var CurrencyRepositoryInterface */
|
||||
private $currencyRepository;
|
||||
/** @var JournalRepositoryInterface */
|
||||
private $repository;
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* TransactionFactory constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->repository = app(JournalRepositoryInterface::class);
|
||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||
$this->budgetRepository = app(BudgetRepositoryInterface::class);
|
||||
$this->categoryRepository = app(CategoryRepositoryInterface::class);
|
||||
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
@@ -68,12 +90,10 @@ class TransactionFactory
|
||||
'foreign_currency_id' => $foreignCurrencyId,
|
||||
'identifier' => $data['identifier'],
|
||||
];
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$transaction = $repository->storeBasicTransaction($values);
|
||||
$transaction = $this->repository->storeBasicTransaction($values);
|
||||
|
||||
// todo: add budget, category, etc.
|
||||
|
||||
// todo link budget, category
|
||||
|
||||
return $transaction;
|
||||
}
|
||||
@@ -94,21 +114,23 @@ class TransactionFactory
|
||||
$foreignCurrency = $this->findCurrency($data['foreign_currency_id'], $data['foreign_currency_code']);
|
||||
$budget = $this->findBudget($data['budget_id'], $data['budget_name']);
|
||||
$category = $this->findCategory($data['category_id'], $data['category_name']);
|
||||
|
||||
$description = $journal->description === $data['description'] ? null : $data['description'];
|
||||
|
||||
// type of source account depends on journal type:
|
||||
$sourceType = $this->accountType($journal, 'source');
|
||||
$sourceAccount = $this->findAccount($sourceType, $data['source_account_id'], $data['source_account_name']);
|
||||
$sourceAccount = $this->findAccount($sourceType, $data['source_id'], $data['source_name']);
|
||||
$sourceFa = is_null($data['foreign_amount']) ? null : app('steam')->negative(strval($data['foreign_amount']));
|
||||
|
||||
// same for destination account:
|
||||
$destinationType = $this->accountType($journal, 'destination');
|
||||
$destinationAccount = $this->findAccount($destinationType, $data['destination_account_id'], $data['destination_account_name']);
|
||||
$destinationAccount = $this->findAccount($destinationType, $data['destination_id'], $data['destination_name']);
|
||||
$destinationFa = is_null($data['foreign_amount']) ? null : app('steam')->positive(strval($data['foreign_amount']));
|
||||
|
||||
// first make a "negative" (source) transaction based on the data in the array.
|
||||
$sourceTransactionData = [
|
||||
'description' => $journal->description === $data['description'] ? null : $data['description'],
|
||||
'description' => $description,
|
||||
'amount' => app('steam')->negative(strval($data['amount'])),
|
||||
'foreign_amount' => is_null($data['foreign_amount']) ? null : app('steam')->negative(strval($data['foreign_amount'])),
|
||||
'foreign_amount' => $sourceFa,
|
||||
'currency' => $currency,
|
||||
'foreign_currency' => $foreignCurrency,
|
||||
'budget' => $budget,
|
||||
@@ -124,7 +146,7 @@ class TransactionFactory
|
||||
$destTransactionData = [
|
||||
'description' => $sourceTransactionData['description'],
|
||||
'amount' => app('steam')->positive(strval($data['amount'])),
|
||||
'foreign_amount' => is_null($data['foreign_amount']) ? null : app('steam')->positive(strval($data['foreign_amount'])),
|
||||
'foreign_amount' => $destinationFa,
|
||||
'currency' => $currency,
|
||||
'foreign_currency' => $foreignCurrency,
|
||||
'budget' => $budget,
|
||||
@@ -136,8 +158,6 @@ class TransactionFactory
|
||||
];
|
||||
$dest = $this->create($destTransactionData);
|
||||
|
||||
// todo link budget, category
|
||||
|
||||
return new Collection([$source, $dest]);
|
||||
}
|
||||
|
||||
@@ -147,6 +167,11 @@ class TransactionFactory
|
||||
public function setUser(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->repository->setUser($user);
|
||||
$this->accountRepository->setUser($user);
|
||||
$this->budgetRepository->setUser($user);
|
||||
$this->categoryRepository->setUser($user);
|
||||
$this->currencyRepository->setUser($user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,45 +220,42 @@ class TransactionFactory
|
||||
{
|
||||
$accountId = intval($accountId);
|
||||
$accountName = strval($accountName);
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
|
||||
switch ($expectedType) {
|
||||
case AccountType::ASSET:
|
||||
if ($accountId > 0) {
|
||||
// must be able to find it based on ID. Validator should catch invalid ID's.
|
||||
return $repository->findNull($accountId);
|
||||
return $this->accountRepository->findNull($accountId);
|
||||
}
|
||||
|
||||
// alternatively, return by name. Validator should catch invalid names.
|
||||
return $repository->findByName($accountName, [AccountType::ASSET]);
|
||||
return $this->accountRepository->findByName($accountName, [AccountType::ASSET]);
|
||||
break;
|
||||
case AccountType::EXPENSE:
|
||||
if ($accountId > 0) {
|
||||
// must be able to find it based on ID. Validator should catch invalid ID's.
|
||||
return $repository->findNull($accountId);
|
||||
return $this->accountRepository->findNull($accountId);
|
||||
}
|
||||
if (strlen($accountName) > 0) {
|
||||
// alternatively, return by name. Validator should catch invalid names.
|
||||
return $repository->findByName($accountName, [AccountType::EXPENSE]);
|
||||
return $this->accountRepository->findByName($accountName, [AccountType::EXPENSE]);
|
||||
}
|
||||
|
||||
// return cash account:
|
||||
return $repository->getCashAccount();
|
||||
return $this->accountRepository->getCashAccount();
|
||||
break;
|
||||
case AccountType::REVENUE:
|
||||
if ($accountId > 0) {
|
||||
// must be able to find it based on ID. Validator should catch invalid ID's.
|
||||
return $repository->findNull($accountId);
|
||||
return $this->accountRepository->findNull($accountId);
|
||||
}
|
||||
if (strlen($accountName) > 0) {
|
||||
// alternatively, return by name. Validator should catch invalid names.
|
||||
return $repository->findByName($accountName, [AccountType::REVENUE]);
|
||||
return $this->accountRepository->findByName($accountName, [AccountType::REVENUE]);
|
||||
}
|
||||
|
||||
// return cash account:
|
||||
return $repository->getCashAccount();
|
||||
return $this->accountRepository->getCashAccount();
|
||||
|
||||
default:
|
||||
throw new FireflyException(sprintf('Cannot find account of type "%s".', $expectedType));
|
||||
@@ -254,21 +276,17 @@ class TransactionFactory
|
||||
if (strlen($budgetName) === 0 && $budgetId === 0) {
|
||||
return null;
|
||||
}
|
||||
/** @var BudgetRepositoryInterface $repository */
|
||||
$repository = app(BudgetRepositoryInterface::class);
|
||||
$budget = null;
|
||||
$repository->setUser($this->user);
|
||||
|
||||
// first by ID:
|
||||
if ($budgetId > 0) {
|
||||
$budget = $repository->findNull($budgetId);
|
||||
$budget = $this->budgetRepository->findNull($budgetId);
|
||||
if (!is_null($budget)) {
|
||||
return $budget;
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen($budgetName) > 0) {
|
||||
$budget = $repository->findByName($budgetName);
|
||||
$budget = $this->budgetRepository->findByName($budgetName);
|
||||
if (!is_null($budget)) {
|
||||
return $budget;
|
||||
}
|
||||
@@ -291,25 +309,21 @@ class TransactionFactory
|
||||
if (strlen($categoryName) === 0 && $categoryId === 0) {
|
||||
return null;
|
||||
}
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
$category = null;
|
||||
$repository->setUser($this->user);
|
||||
|
||||
// first by ID:
|
||||
if ($categoryId > 0) {
|
||||
$category = $repository->findNull($categoryId);
|
||||
$category = $this->categoryRepository->findNull($categoryId);
|
||||
if (!is_null($category)) {
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen($categoryName) > 0) {
|
||||
$category = $repository->findByName($categoryName);
|
||||
$category = $this->categoryRepository->findByName($categoryName);
|
||||
if (!is_null($category)) {
|
||||
return $category;
|
||||
}
|
||||
// create it?
|
||||
die('create category');
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -329,21 +343,17 @@ class TransactionFactory
|
||||
if (strlen($currencyCode) === 0 && intval($currencyId) === 0) {
|
||||
return null;
|
||||
}
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
$currency = null;
|
||||
$repository->setUser($this->user);
|
||||
|
||||
// first by ID:
|
||||
if ($currencyId > 0) {
|
||||
$currency = $repository->findNull($currencyId);
|
||||
$currency = $this->currencyRepository->findNull($currencyId);
|
||||
if (!is_null($currency)) {
|
||||
return $currency;
|
||||
}
|
||||
}
|
||||
// then by code:
|
||||
if (strlen($currencyCode) > 0) {
|
||||
$currency = $repository->findByCodeNull($currencyCode);
|
||||
$currency = $this->currencyRepository->findByCodeNull($currencyCode);
|
||||
if (!is_null($currency)) {
|
||||
return $currency;
|
||||
}
|
||||
|
||||
@@ -23,12 +23,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Factory;
|
||||
|
||||
use FireflyIII\Events\StoredTransactionJournal;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Repositories\TransactionType\TransactionTypeRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
|
||||
@@ -37,6 +40,14 @@ use FireflyIII\User;
|
||||
*/
|
||||
class TransactionJournalFactory
|
||||
{
|
||||
/** @var BillRepositoryInterface */
|
||||
private $billRepository;
|
||||
/** @var PiggyBankRepositoryInterface */
|
||||
private $piggyRepository;
|
||||
/** @var JournalRepositoryInterface */
|
||||
private $repository;
|
||||
/** @var TransactionTypeRepositoryInterface */
|
||||
private $ttRepository;
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
@@ -45,6 +56,10 @@ class TransactionJournalFactory
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->repository = app(JournalRepositoryInterface::class);
|
||||
$this->billRepository = app(BillRepositoryInterface::class);
|
||||
$this->piggyRepository = app(PiggyBankRepositoryInterface::class);
|
||||
$this->ttRepository = app(TransactionTypeRepositoryInterface::class);
|
||||
|
||||
}
|
||||
|
||||
@@ -60,11 +75,9 @@ class TransactionJournalFactory
|
||||
{
|
||||
$type = $this->findTransactionType($data['type']);
|
||||
$bill = $this->findBill($data['bill_id'], $data['bill_name']);
|
||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUser(auth()->user());
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
|
||||
$values = [
|
||||
$piggyBank = $this->findPiggyBank($data['piggy_bank_id'], $data['piggy_bank_name']);
|
||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($this->user);
|
||||
$values = [
|
||||
'user_id' => $data['user'],
|
||||
'transaction_type_id' => $type->id,
|
||||
'bill_id' => is_null($bill) ? null : $bill->id,
|
||||
@@ -76,20 +89,28 @@ class TransactionJournalFactory
|
||||
'completed' => 0,
|
||||
];
|
||||
|
||||
$journal = $repository->storeBasic($values);
|
||||
$journal = $this->repository->storeBasic($values);
|
||||
|
||||
// todo link other stuff to journal (meta-data etc). tags
|
||||
|
||||
// todo
|
||||
// start creating transactions:
|
||||
|
||||
$factory = app(TransactionFactory::class);
|
||||
$factory->setUser($this->user);
|
||||
|
||||
/** @var array $trData */
|
||||
foreach ($data['transactions'] as $trData) {
|
||||
$factory = new TransactionFactory();
|
||||
$factory->setUser($this->user);
|
||||
|
||||
$trData['reconciled'] = $data['reconciled'] ?? false;
|
||||
$factory->createPair($journal, $trData);
|
||||
}
|
||||
$repository->markCompleted($journal);
|
||||
$this->repository->markCompleted($journal);
|
||||
|
||||
// link piggy bank:
|
||||
if ($type->type === TransactionType::TRANSFER && !is_null($piggyBank)) {
|
||||
/** @var PiggyBankEventFactory $factory */
|
||||
$factory = app(PiggyBankEventFactory::class);
|
||||
$factory->create($journal, $piggyBank);
|
||||
}
|
||||
|
||||
return $journal;
|
||||
}
|
||||
@@ -102,6 +123,9 @@ class TransactionJournalFactory
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->repository->setUser($user);
|
||||
$this->billRepository->setUser($user);
|
||||
$this->piggyRepository->setUser($user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,14 +141,10 @@ class TransactionJournalFactory
|
||||
if (strlen($billName) === 0 && $billId === 0) {
|
||||
return null;
|
||||
}
|
||||
/** @var BillRepositoryInterface $repository */
|
||||
$repository = app(BillRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
|
||||
// first find by ID:
|
||||
if ($billId > 0) {
|
||||
/** @var Bill $bill */
|
||||
$bill = $repository->find($billId);
|
||||
$bill = $this->billRepository->find($billId);
|
||||
if (!is_null($bill)) {
|
||||
return $bill;
|
||||
}
|
||||
@@ -132,7 +152,7 @@ class TransactionJournalFactory
|
||||
|
||||
// then find by name:
|
||||
if (strlen($billName) > 0) {
|
||||
$bill = $repository->findByName($billName);
|
||||
$bill = $this->billRepository->findByName($billName);
|
||||
if (!is_null($bill)) {
|
||||
return $bill;
|
||||
}
|
||||
@@ -141,6 +161,41 @@ class TransactionJournalFactory
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the given bill based on the ID or the name. ID takes precedence over the name.
|
||||
*
|
||||
* @param int $piggyBankId
|
||||
* @param string $piggyBankName
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
protected function findPiggyBank(int $piggyBankId, string $piggyBankName): ?PiggyBank
|
||||
{
|
||||
if (strlen($piggyBankName) === 0 && $piggyBankId === 0) {
|
||||
return null;
|
||||
}
|
||||
// first find by ID:
|
||||
if ($piggyBankId > 0) {
|
||||
/** @var PiggyBank $piggyBank */
|
||||
$piggyBank = $this->piggyRepository->find($piggyBankId);
|
||||
if (!is_null($piggyBank)) {
|
||||
return $piggyBank;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// then find by name:
|
||||
if (strlen($piggyBankName) > 0) {
|
||||
/** @var PiggyBank $piggyBank */
|
||||
$piggyBank = $this->piggyRepository->findByName($piggyBankName);
|
||||
if (!is_null($piggyBank)) {
|
||||
return $piggyBank;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transaction type. Since this is mandatory, will throw an exception when nothing comes up. Will always
|
||||
* use TransactionType repository.
|
||||
@@ -150,11 +205,9 @@ class TransactionJournalFactory
|
||||
* @return TransactionType
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function findTransactionType(string $type): TransactionType
|
||||
protected function findTransactionType(string $type): TransactionType
|
||||
{
|
||||
/** @var TransactionTypeRepositoryInterface $repository */
|
||||
$repository = app(TransactionTypeRepositoryInterface::class);
|
||||
$transactionType = $repository->findByType($type);
|
||||
$transactionType = $this->ttRepository->findByType($type);
|
||||
if (is_null($transactionType)) {
|
||||
throw new FireflyException(sprintf('Could not find transaction type for "%s"', $type));
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class StoredJournalEventHandler
|
||||
}
|
||||
|
||||
// piggy exists?
|
||||
if (null === $piggyBank->id) {
|
||||
if (null === $piggyBank) {
|
||||
Log::error(sprintf('There is no piggy bank with ID #%d', $piggyBankId));
|
||||
|
||||
return true;
|
||||
|
||||
@@ -230,7 +230,7 @@ class SingleController extends Controller
|
||||
$type = $transactionJournal->transactionTypeStr();
|
||||
Session::flash('success', strval(trans('firefly.deleted_' . strtolower($type), ['description' => $transactionJournal->description])));
|
||||
|
||||
$this->repository->delete($transactionJournal);
|
||||
$this->repository->destroy($transactionJournal);
|
||||
|
||||
Preferences::mark();
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(TransactionJournal $journal): bool
|
||||
public function destroy(TransactionJournal $journal): bool
|
||||
{
|
||||
$journal->delete();
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ interface JournalRepositoryInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete(TransactionJournal $journal): bool;
|
||||
public function destroy(TransactionJournal $journal): bool;
|
||||
|
||||
/**
|
||||
* Find a specific journal.
|
||||
|
||||
@@ -163,6 +163,26 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
return new PiggyBank();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find by name or return NULL.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function findByName(string $name): ?PiggyBank
|
||||
{
|
||||
$set = $this->user->piggyBanks()->get(['piggy_banks.*']);
|
||||
/** @var PiggyBank $piggy */
|
||||
foreach ($set as $piggy) {
|
||||
if ($piggy->name === $name) {
|
||||
return $piggy;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current amount saved in piggy bank.
|
||||
*
|
||||
|
||||
@@ -102,6 +102,15 @@ interface PiggyBankRepositoryInterface
|
||||
*/
|
||||
public function find(int $piggyBankid): PiggyBank;
|
||||
|
||||
/**
|
||||
* Find by name or return NULL.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return PiggyBank|null
|
||||
*/
|
||||
public function findByName(string $name): ?PiggyBank;
|
||||
|
||||
/**
|
||||
* Get current amount saved in piggy bank.
|
||||
*
|
||||
|
||||
@@ -83,8 +83,8 @@ class BelongsUser implements Rule
|
||||
|
||||
return $count === 1;
|
||||
break;
|
||||
case 'source_account_id':
|
||||
case 'destination_account_id':
|
||||
case 'source_id':
|
||||
case 'destination_id':
|
||||
$count = Account::where('id', '=', intval($value))->where('user_id', '=', auth()->user()->id)->count();
|
||||
|
||||
return $count === 1;
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace FireflyIII\Transformers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Note;
|
||||
@@ -100,7 +101,7 @@ class AccountTransformer extends TransformerAbstract
|
||||
$pageSize = intval(app('preferences')->getForUser($account->user, 'listPageSize', 50)->data);
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
$collector = new JournalCollector;
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser($account->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
||||
if ($account->accountType->type === AccountType::ASSET) {
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace FireflyIII\Transformers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
@@ -96,7 +97,7 @@ class BillTransformer extends TransformerAbstract
|
||||
$pageSize = intval(app('preferences')->getForUser($bill->user, 'listPageSize', 50)->data);
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
$collector = new JournalCollector;
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser($bill->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\Budget;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
@@ -78,7 +79,7 @@ class BudgetTransformer extends TransformerAbstract
|
||||
$pageSize = intval(app('preferences')->getForUser($budget->user, 'listPageSize', 50)->data);
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
$collector = new JournalCollector;
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser($budget->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\Category;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
@@ -78,7 +79,7 @@ class CategoryTransformer extends TransformerAbstract
|
||||
$pageSize = intval(app('preferences')->getForUser($category->user, 'listPageSize', 50)->data);
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
$collector = new JournalCollector;
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser($category->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\TransactionJournalMeta;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
@@ -78,7 +79,7 @@ class JournalMetaTransformer extends TransformerAbstract
|
||||
$pageSize = intval(app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data);
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
$collector = new JournalCollector;
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser($journal->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -94,7 +95,7 @@ class PiggyBankEventTransformer extends TransformerAbstract
|
||||
$pageSize = intval(app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data);
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
$collector = new JournalCollector;
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser($journal->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\Tag;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
@@ -77,7 +78,7 @@ class TagTransformer extends TransformerAbstract
|
||||
$pageSize = intval(app('preferences')->getForUser($tag->user, 'listPageSize', 50)->data);
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
$collector = new JournalCollector;
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser($tag->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
|
||||
Reference in New Issue
Block a user