mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
use journal repository instead of direct calls.
This commit is contained in:
parent
99983a5c8f
commit
1b304bf85e
@ -28,6 +28,7 @@ use FireflyIII\Models\Budget;
|
|||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,6 +183,9 @@ class PopupReport implements PopupReportInterface
|
|||||||
*/
|
*/
|
||||||
public function byIncome(Account $account, array $attributes): Collection
|
public function byIncome(Account $account, array $attributes): Collection
|
||||||
{
|
{
|
||||||
|
/** @var JournalRepositoryInterface $repository */
|
||||||
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$repository->setUser($account->user);
|
||||||
/** @var JournalCollectorInterface $collector */
|
/** @var JournalCollectorInterface $collector */
|
||||||
$collector = app(JournalCollectorInterface::class);
|
$collector = app(JournalCollectorInterface::class);
|
||||||
$collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])
|
$collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])
|
||||||
@ -191,9 +195,10 @@ class PopupReport implements PopupReportInterface
|
|||||||
|
|
||||||
// filter the set so the destinations outside of $attributes['accounts'] are not included.
|
// filter the set so the destinations outside of $attributes['accounts'] are not included.
|
||||||
$journals = $journals->filter(
|
$journals = $journals->filter(
|
||||||
function (Transaction $transaction) use ($report) {
|
function (Transaction $transaction) use ($report, $repository) {
|
||||||
// get the destinations:
|
// get the destinations:
|
||||||
$destinations = $transaction->transactionJournal->destinationAccountList()->pluck('id')->toArray();
|
$journal = $transaction->transactionJournal;
|
||||||
|
$destinations = $repository->getJournalDestinationAccounts($journal)->pluck('id')->toArray();
|
||||||
|
|
||||||
// do these intersect with the current list?
|
// do these intersect with the current list?
|
||||||
return !empty(array_intersect($report, $destinations));
|
return !empty(array_intersect($report, $destinations));
|
||||||
|
@ -52,6 +52,9 @@ use Session;
|
|||||||
*/
|
*/
|
||||||
class ReconcileController extends Controller
|
class ReconcileController extends Controller
|
||||||
{
|
{
|
||||||
|
/** @var JournalRepositoryInterface */
|
||||||
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -64,6 +67,7 @@ class ReconcileController extends Controller
|
|||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
app('view')->share('mainTitleIcon', 'fa-credit-card');
|
app('view')->share('mainTitleIcon', 'fa-credit-card');
|
||||||
app('view')->share('title', trans('firefly.accounts'));
|
app('view')->share('title', trans('firefly.accounts'));
|
||||||
|
$this->repository = app(JournalRepositoryInterface::class);
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
@ -84,10 +88,10 @@ class ReconcileController extends Controller
|
|||||||
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
|
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
|
||||||
|
|
||||||
// journal related code
|
// journal related code
|
||||||
$pTransaction = $journal->positiveTransaction(); // TODO replace
|
$pTransaction = $this->repository->getFirstPosTransaction($journal);
|
||||||
$preFilled = [
|
$preFilled = [
|
||||||
'date' => $journal->dateAsString(),
|
'date' => $this->repository->getJournalDate($journal, null),
|
||||||
'category' => $journal->categoryAsString(),
|
'category' => $this->repository->getJournalCategoryName($journal),
|
||||||
'tags' => join(',', $journal->tags->pluck('tag')->toArray()),
|
'tags' => join(',', $journal->tags->pluck('tag')->toArray()),
|
||||||
'amount' => $pTransaction->amount,
|
'amount' => $pTransaction->amount,
|
||||||
];
|
];
|
||||||
@ -130,10 +134,8 @@ class ReconcileController extends Controller
|
|||||||
$clearedAmount = '0';
|
$clearedAmount = '0';
|
||||||
$route = route('accounts.reconcile.submit', [$account->id, $start->format('Ymd'), $end->format('Ymd')]);
|
$route = route('accounts.reconcile.submit', [$account->id, $start->format('Ymd'), $end->format('Ymd')]);
|
||||||
// get sum of transaction amounts:
|
// get sum of transaction amounts:
|
||||||
/** @var JournalRepositoryInterface $repository */
|
$transactions = $this->repository->getTransactionsById($transactionIds);
|
||||||
$repository = app(JournalRepositoryInterface::class);
|
$cleared = $this->repository->getTransactionsById($clearedIds);
|
||||||
$transactions = $repository->getTransactionsById($transactionIds);
|
|
||||||
$cleared = $repository->getTransactionsById($clearedIds);
|
|
||||||
$countCleared = 0;
|
$countCleared = 0;
|
||||||
|
|
||||||
/** @var Transaction $transaction */
|
/** @var Transaction $transaction */
|
||||||
@ -224,12 +226,11 @@ class ReconcileController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param JournalRepositoryInterface $repository
|
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public function show(JournalRepositoryInterface $repository, TransactionJournal $journal)
|
public function show(TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (TransactionType::RECONCILIATION !== $journal->transactionType->type) {
|
if (TransactionType::RECONCILIATION !== $journal->transactionType->type) {
|
||||||
@ -238,7 +239,7 @@ class ReconcileController extends Controller
|
|||||||
$subTitle = trans('firefly.reconciliation') . ' "' . $journal->description . '"';
|
$subTitle = trans('firefly.reconciliation') . ' "' . $journal->description . '"';
|
||||||
|
|
||||||
// get main transaction:
|
// get main transaction:
|
||||||
$transaction = $repository->getAssetTransaction($journal);
|
$transaction = $this->repository->getAssetTransaction($journal);
|
||||||
$account = $transaction->account;
|
$account = $transaction->account;
|
||||||
|
|
||||||
return view('accounts.reconcile.show', compact('journal', 'subTitle', 'transaction', 'account'));
|
return view('accounts.reconcile.show', compact('journal', 'subTitle', 'transaction', 'account'));
|
||||||
@ -384,12 +385,11 @@ class ReconcileController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ReconciliationUpdateRequest $request
|
* @param ReconciliationUpdateRequest $request
|
||||||
* @param JournalRepositoryInterface $repository
|
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
*/
|
*/
|
||||||
public function update(ReconciliationUpdateRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
|
public function update(ReconciliationUpdateRequest $request, TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
if (TransactionType::RECONCILIATION !== $journal->transactionType->type) {
|
if (TransactionType::RECONCILIATION !== $journal->transactionType->type) {
|
||||||
return redirect(route('transactions.show', [$journal->id]));
|
return redirect(route('transactions.show', [$journal->id]));
|
||||||
@ -403,8 +403,8 @@ class ReconcileController extends Controller
|
|||||||
$submitted = $request->getJournalData();
|
$submitted = $request->getJournalData();
|
||||||
|
|
||||||
// amount pos neg influences the accounts:
|
// amount pos neg influences the accounts:
|
||||||
$source = $repository->getSourceAccount($journal);
|
$source = $this->repository->getSourceAccount($journal);
|
||||||
$destination = $repository->getDestinationAccount($journal);
|
$destination = $this->repository->getDestinationAccount($journal);
|
||||||
if (bccomp($submitted['amount'], '0') === 1) {
|
if (bccomp($submitted['amount'], '0') === 1) {
|
||||||
// amount is positive, switch accounts:
|
// amount is positive, switch accounts:
|
||||||
list($source, $destination) = [$destination, $source];
|
list($source, $destination) = [$destination, $source];
|
||||||
@ -443,10 +443,10 @@ class ReconcileController extends Controller
|
|||||||
'category_name' => $submitted['category'],
|
'category_name' => $submitted['category'],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'notes' => $repository->getNote($journal),
|
'notes' => $this->repository->getNoteText($journal),
|
||||||
];
|
];
|
||||||
|
|
||||||
$repository->update($journal, $data);
|
$this->repository->update($journal, $data);
|
||||||
|
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
if (1 === intval($request->get('return_to_edit'))) {
|
if (1 === intval($request->get('return_to_edit'))) {
|
||||||
|
@ -43,6 +43,8 @@ use View;
|
|||||||
*/
|
*/
|
||||||
class BulkController extends Controller
|
class BulkController extends Controller
|
||||||
{
|
{
|
||||||
|
/** @var JournalRepositoryInterface */
|
||||||
|
private $repository;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,6 +56,7 @@ class BulkController extends Controller
|
|||||||
|
|
||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
|
$this->repository = app(JournalRepositoryInterface::class);
|
||||||
app('view')->share('title', trans('firefly.transactions'));
|
app('view')->share('title', trans('firefly.transactions'));
|
||||||
app('view')->share('mainTitleIcon', 'fa-repeat');
|
app('view')->share('mainTitleIcon', 'fa-repeat');
|
||||||
|
|
||||||
@ -77,8 +80,8 @@ class BulkController extends Controller
|
|||||||
$messages = [];
|
$messages = [];
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$sources = $journal->sourceAccountList();
|
$sources = $this->repository->getJournalSourceAccounts($journal);
|
||||||
$destinations = $journal->destinationAccountList();
|
$destinations = $this->repository->getJournalDestinationAccounts($journal);
|
||||||
if ($sources->count() > 1) {
|
if ($sources->count() > 1) {
|
||||||
$messages[] = trans('firefly.cannot_edit_multiple_source', ['description' => $journal->description, 'id' => $journal->id]);
|
$messages[] = trans('firefly.cannot_edit_multiple_source', ['description' => $journal->description, 'id' => $journal->id]);
|
||||||
continue;
|
continue;
|
||||||
@ -88,13 +91,13 @@ class BulkController extends Controller
|
|||||||
$messages[] = trans('firefly.cannot_edit_multiple_dest', ['description' => $journal->description, 'id' => $journal->id]);
|
$messages[] = trans('firefly.cannot_edit_multiple_dest', ['description' => $journal->description, 'id' => $journal->id]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (TransactionType::OPENING_BALANCE === $journal->transactionType->type) {
|
if (TransactionType::OPENING_BALANCE === $this->repository->getTransactionType($journal)) {
|
||||||
$messages[] = trans('firefly.cannot_edit_opening_balance');
|
$messages[] = trans('firefly.cannot_edit_opening_balance');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cannot edit reconciled transactions / journals:
|
// cannot edit reconciled transactions / journals:
|
||||||
if ($journal->transactions->first()->reconciled) {
|
if ($this->repository->isJournalReconciled($journal)) {
|
||||||
$messages[] = trans('firefly.cannot_edit_reconciled', ['description' => $journal->description, 'id' => $journal->id]);
|
$messages[] = trans('firefly.cannot_edit_reconciled', ['description' => $journal->description, 'id' => $journal->id]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,9 @@ class ConvertController extends Controller
|
|||||||
/** @var AccountRepositoryInterface */
|
/** @var AccountRepositoryInterface */
|
||||||
private $accounts;
|
private $accounts;
|
||||||
|
|
||||||
|
/** @var JournalRepositoryInterface */
|
||||||
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConvertController constructor.
|
* ConvertController constructor.
|
||||||
*/
|
*/
|
||||||
@ -54,6 +57,7 @@ class ConvertController extends Controller
|
|||||||
$this->middleware(
|
$this->middleware(
|
||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
$this->accounts = app(AccountRepositoryInterface::class);
|
$this->accounts = app(AccountRepositoryInterface::class);
|
||||||
|
$this->repository = app(JournalRepositoryInterface::class);
|
||||||
|
|
||||||
app('view')->share('title', trans('firefly.transactions'));
|
app('view')->share('title', trans('firefly.transactions'));
|
||||||
app('view')->share('mainTitleIcon', 'fa-exchange');
|
app('view')->share('mainTitleIcon', 'fa-exchange');
|
||||||
@ -76,8 +80,7 @@ class ConvertController extends Controller
|
|||||||
return $this->redirectToAccount($journal);
|
return $this->redirectToAccount($journal);
|
||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
|
$positiveAmount = $this->repository->getJournalTotal($journal);
|
||||||
$positiveAmount = $journal->amountPositive();
|
|
||||||
$assetAccounts = ExpandedForm::makeSelectList($this->accounts->getActiveAccountsByType([AccountType::DEFAULT, AccountType::ASSET]));
|
$assetAccounts = ExpandedForm::makeSelectList($this->accounts->getActiveAccountsByType([AccountType::DEFAULT, AccountType::ASSET]));
|
||||||
$sourceType = $journal->transactionType;
|
$sourceType = $journal->transactionType;
|
||||||
$subTitle = trans('firefly.convert_to_' . $destinationType->type, ['description' => $journal->description]);
|
$subTitle = trans('firefly.convert_to_' . $destinationType->type, ['description' => $journal->description]);
|
||||||
@ -98,8 +101,8 @@ class ConvertController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get source and destination account:
|
// get source and destination account:
|
||||||
$sourceAccount = $journal->sourceAccountList()->first();
|
$sourceAccount = $this->repository->getJournalSourceAccounts($journal)->first();
|
||||||
$destinationAccount = $journal->destinationAccountList()->first();
|
$destinationAccount = $this->repository->getJournalDestinationAccounts($journal)->first();
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
'transactions.convert',
|
'transactions.convert',
|
||||||
@ -183,8 +186,8 @@ class ConvertController extends Controller
|
|||||||
{
|
{
|
||||||
/** @var AccountRepositoryInterface $accountRepository */
|
/** @var AccountRepositoryInterface $accountRepository */
|
||||||
$accountRepository = app(AccountRepositoryInterface::class);
|
$accountRepository = app(AccountRepositoryInterface::class);
|
||||||
$sourceAccount = $journal->sourceAccountList()->first();
|
$sourceAccount = $this->repository->getJournalSourceAccounts($journal)->first();
|
||||||
$destinationAccount = $journal->destinationAccountList()->first();
|
$destinationAccount = $this->repository->getJournalDestinationAccounts($journal)->first();
|
||||||
$sourceType = $journal->transactionType;
|
$sourceType = $journal->transactionType;
|
||||||
$joined = $sourceType->type . '-' . $destinationType->type;
|
$joined = $sourceType->type . '-' . $destinationType->type;
|
||||||
switch ($joined) {
|
switch ($joined) {
|
||||||
@ -239,8 +242,8 @@ class ConvertController extends Controller
|
|||||||
{
|
{
|
||||||
/** @var AccountRepositoryInterface $accountRepository */
|
/** @var AccountRepositoryInterface $accountRepository */
|
||||||
$accountRepository = app(AccountRepositoryInterface::class);
|
$accountRepository = app(AccountRepositoryInterface::class);
|
||||||
$sourceAccount = $journal->sourceAccountList()->first();
|
$sourceAccount = $this->repository->getJournalSourceAccounts($journal)->first();
|
||||||
$destinationAccount = $journal->destinationAccountList()->first();
|
$destinationAccount = $this->repository->getJournalDestinationAccounts($journal)->first();
|
||||||
$sourceType = $journal->transactionType;
|
$sourceType = $journal->transactionType;
|
||||||
$joined = $sourceType->type . '-' . $destinationType->type;
|
$joined = $sourceType->type . '-' . $destinationType->type;
|
||||||
switch ($joined) {
|
switch ($joined) {
|
||||||
|
@ -43,6 +43,9 @@ use View;
|
|||||||
*/
|
*/
|
||||||
class MassController extends Controller
|
class MassController extends Controller
|
||||||
{
|
{
|
||||||
|
/** @var JournalRepositoryInterface */
|
||||||
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -54,6 +57,7 @@ class MassController extends Controller
|
|||||||
function ($request, $next) {
|
function ($request, $next) {
|
||||||
app('view')->share('title', trans('firefly.transactions'));
|
app('view')->share('title', trans('firefly.transactions'));
|
||||||
app('view')->share('mainTitleIcon', 'fa-repeat');
|
app('view')->share('mainTitleIcon', 'fa-repeat');
|
||||||
|
$this->repository = app(JournalRepositoryInterface::class);
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
@ -77,11 +81,10 @@ class MassController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param MassDeleteJournalRequest $request
|
* @param MassDeleteJournalRequest $request
|
||||||
* @param JournalRepositoryInterface $repository
|
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function destroy(MassDeleteJournalRequest $request, JournalRepositoryInterface $repository)
|
public function destroy(MassDeleteJournalRequest $request)
|
||||||
{
|
{
|
||||||
$ids = $request->get('confirm_mass_delete');
|
$ids = $request->get('confirm_mass_delete');
|
||||||
$set = new Collection;
|
$set = new Collection;
|
||||||
@ -89,7 +92,7 @@ class MassController extends Controller
|
|||||||
/** @var int $journalId */
|
/** @var int $journalId */
|
||||||
foreach ($ids as $journalId) {
|
foreach ($ids as $journalId) {
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
$journal = $repository->find(intval($journalId));
|
$journal = $this->repository->find(intval($journalId));
|
||||||
if (null !== $journal->id && intval($journalId) === $journal->id) {
|
if (null !== $journal->id && intval($journalId) === $journal->id) {
|
||||||
$set->push($journal);
|
$set->push($journal);
|
||||||
}
|
}
|
||||||
@ -100,7 +103,7 @@ class MassController extends Controller
|
|||||||
|
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
foreach ($set as $journal) {
|
foreach ($set as $journal) {
|
||||||
$repository->delete($journal);
|
$this->repository->delete($journal);
|
||||||
++$count;
|
++$count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,8 +137,8 @@ class MassController extends Controller
|
|||||||
$messages = [];
|
$messages = [];
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$sources = $journal->sourceAccountList();
|
$sources = $this->repository->getJournalSourceAccounts($journal);
|
||||||
$destinations = $journal->destinationAccountList();
|
$destinations = $this->repository->getJournalDestinationAccounts($journal);
|
||||||
if ($sources->count() > 1) {
|
if ($sources->count() > 1) {
|
||||||
$messages[] = trans('firefly.cannot_edit_multiple_source', ['description' => $journal->description, 'id' => $journal->id]);
|
$messages[] = trans('firefly.cannot_edit_multiple_source', ['description' => $journal->description, 'id' => $journal->id]);
|
||||||
continue;
|
continue;
|
||||||
@ -172,8 +175,8 @@ class MassController extends Controller
|
|||||||
$transaction = $journal->positiveTransaction();
|
$transaction = $journal->positiveTransaction();
|
||||||
$currency = $transaction->transactionCurrency;
|
$currency = $transaction->transactionCurrency;
|
||||||
$journal->amount = floatval($transaction->amount);
|
$journal->amount = floatval($transaction->amount);
|
||||||
$sources = $journal->sourceAccountList();
|
$sources = $this->repository->getJournalSourceAccounts($journal);
|
||||||
$destinations = $journal->destinationAccountList();
|
$destinations = $this->repository->getJournalDestinationAccounts($journal);
|
||||||
$journal->transaction_count = $journal->transactions()->count();
|
$journal->transaction_count = $journal->transactions()->count();
|
||||||
$journal->currency_symbol = $currency->symbol;
|
$journal->currency_symbol = $currency->symbol;
|
||||||
$journal->transaction_type_type = $journal->transactionType->type;
|
$journal->transaction_type_type = $journal->transactionType->type;
|
||||||
|
@ -104,13 +104,13 @@ class SingleController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function cloneTransaction(TransactionJournal $journal)
|
public function cloneTransaction(TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
$source = $journal->sourceAccountList()->first();
|
$source = $this->repository->getJournalSourceAccounts($journal)->first();
|
||||||
$destination = $journal->destinationAccountList()->first();
|
$destination = $this->repository->getJournalDestinationAccounts($journal)->first();
|
||||||
$budget = $journal->budgets()->first();
|
$budgetId = $this->repository->getJournalBudgetId($journal);
|
||||||
$budgetId = null === $budget ? 0 : $budget->id;
|
$categoryName = $this->repository->getJournalCategoryName($journal);
|
||||||
$category = $journal->categories()->first();
|
|
||||||
$categoryName = null === $category ? '' : $category->name;
|
$tags = join(',',$this->repository->getTags($journal));
|
||||||
$tags = join(',', $journal->tags()->get()->pluck('tag')->toArray());
|
// todo less direct database access. Use collector?
|
||||||
/** @var Transaction $transaction */
|
/** @var Transaction $transaction */
|
||||||
$transaction = $journal->transactions()->first();
|
$transaction = $journal->transactions()->first();
|
||||||
$amount = app('steam')->positive($transaction->amount);
|
$amount = app('steam')->positive($transaction->amount);
|
||||||
|
@ -124,7 +124,8 @@ class SplitController extends Controller
|
|||||||
|
|
||||||
return view(
|
return view(
|
||||||
'transactions.split.edit', compact(
|
'transactions.split.edit', compact(
|
||||||
'subTitleIcon', 'currencies', 'optionalFields', 'preFilled', 'subTitle', 'uploadSize', 'assetAccounts', 'budgets', 'journal', 'accountArray',
|
'subTitleIcon', 'currencies', 'optionalFields', 'preFilled', 'subTitle', 'uploadSize', 'assetAccounts', 'budgets',
|
||||||
|
'journal', 'accountArray',
|
||||||
'previous'
|
'previous'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -186,7 +187,7 @@ class SplitController extends Controller
|
|||||||
$destinationAccounts = $this->repository->getJournalDestinationAccounts($journal);
|
$destinationAccounts = $this->repository->getJournalDestinationAccounts($journal);
|
||||||
$array = [
|
$array = [
|
||||||
'journal_description' => $request->old('journal_description', $journal->description),
|
'journal_description' => $request->old('journal_description', $journal->description),
|
||||||
'journal_amount' => $journal->amountPositive(),
|
'journal_amount' => $this->repository->getJournalTotal($journal),
|
||||||
'sourceAccounts' => $sourceAccounts,
|
'sourceAccounts' => $sourceAccounts,
|
||||||
'journal_source_account_id' => $request->old('journal_source_account_id', $sourceAccounts->first()->id),
|
'journal_source_account_id' => $request->old('journal_source_account_id', $sourceAccounts->first()->id),
|
||||||
'journal_source_account_name' => $request->old('journal_source_account_name', $sourceAccounts->first()->name),
|
'journal_source_account_name' => $request->old('journal_source_account_name', $sourceAccounts->first()->name),
|
||||||
|
@ -103,24 +103,6 @@ class Tag extends Model
|
|||||||
throw new NotFoundHttpException;
|
throw new NotFoundHttpException;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Tag $tag
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @throws \FireflyIII\Exceptions\FireflyException
|
|
||||||
*/
|
|
||||||
public static function tagSum(Tag $tag): string
|
|
||||||
{
|
|
||||||
$sum = '0';
|
|
||||||
/** @var TransactionJournal $journal */
|
|
||||||
foreach ($tag->transactionjournals as $journal) {
|
|
||||||
bcadd($sum, $journal->amount());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*
|
*
|
||||||
|
@ -29,6 +29,7 @@ use FireflyIII\Models\Bill;
|
|||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Services\Internal\Destroy\BillDestroyService;
|
use FireflyIII\Services\Internal\Destroy\BillDestroyService;
|
||||||
use FireflyIII\Services\Internal\Update\BillUpdateService;
|
use FireflyIII\Services\Internal\Update\BillUpdateService;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
@ -253,12 +254,15 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getOverallAverage(Bill $bill): string
|
public function getOverallAverage(Bill $bill): string
|
||||||
{
|
{
|
||||||
|
/** @var JournalRepositoryInterface $repos */
|
||||||
|
$repos = app(JournalRepositoryInterface::class);
|
||||||
|
$repos->setUser($this->user);
|
||||||
$journals = $bill->transactionJournals()->get();
|
$journals = $bill->transactionJournals()->get();
|
||||||
$sum = '0';
|
$sum = '0';
|
||||||
$count = strval($journals->count());
|
$count = strval($journals->count());
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$sum = bcadd($sum, $journal->amountPositive());
|
$sum = bcadd($sum, $repos->getJournalTotal($journal));
|
||||||
}
|
}
|
||||||
$avg = '0';
|
$avg = '0';
|
||||||
if ($journals->count() > 0) {
|
if ($journals->count() > 0) {
|
||||||
@ -376,15 +380,19 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getYearAverage(Bill $bill, Carbon $date): string
|
public function getYearAverage(Bill $bill, Carbon $date): string
|
||||||
{
|
{
|
||||||
|
/** @var JournalRepositoryInterface $repos */
|
||||||
|
$repos = app(JournalRepositoryInterface::class);
|
||||||
|
$repos->setUser($this->user);
|
||||||
|
|
||||||
$journals = $bill->transactionJournals()
|
$journals = $bill->transactionJournals()
|
||||||
->where('date', '>=', $date->year . '-01-01 00:00:00')
|
->where('date', '>=', $date->year . '-01-01 00:00:00')
|
||||||
->where('date', '<=', $date->year . '-12-31 00:00:00')
|
->where('date', '<=', $date->year . '-12-31 23:59:59')
|
||||||
->get();
|
->get();
|
||||||
$sum = '0';
|
$sum = '0';
|
||||||
$count = strval($journals->count());
|
$count = strval($journals->count());
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$sum = bcadd($sum, $journal->amountPositive());
|
$sum = bcadd($sum, $repos->getJournalTotal($journal));
|
||||||
}
|
}
|
||||||
$avg = '0';
|
$avg = '0';
|
||||||
if ($journals->count() > 0) {
|
if ($journals->count() > 0) {
|
||||||
@ -494,15 +502,20 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
if (false === $journal->isWithdrawal()) {
|
if (false === $journal->isWithdrawal()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$destinationAccounts = $journal->destinationAccountList();
|
|
||||||
$sourceAccounts = $journal->sourceAccountList();
|
/** @var JournalRepositoryInterface $repos */
|
||||||
|
$repos = app(JournalRepositoryInterface::class);
|
||||||
|
$repos->setUser($this->user);
|
||||||
|
|
||||||
|
$destinationAccounts = $repos->getJournalDestinationAccounts($journal);
|
||||||
|
$sourceAccounts = $repos->getJournalDestinationAccounts($journal);
|
||||||
$matches = explode(',', $bill->match);
|
$matches = explode(',', $bill->match);
|
||||||
$description = strtolower($journal->description) . ' ';
|
$description = strtolower($journal->description) . ' ';
|
||||||
$description .= strtolower(join(' ', $destinationAccounts->pluck('name')->toArray()));
|
$description .= strtolower(join(' ', $destinationAccounts->pluck('name')->toArray()));
|
||||||
$description .= strtolower(join(' ', $sourceAccounts->pluck('name')->toArray()));
|
$description .= strtolower(join(' ', $sourceAccounts->pluck('name')->toArray()));
|
||||||
|
|
||||||
$wordMatch = $this->doWordMatch($matches, $description);
|
$wordMatch = $this->doWordMatch($matches, $description);
|
||||||
$amountMatch = $this->doAmountMatch($journal->amountPositive(), $bill->amount_min, $bill->amount_max);
|
$amountMatch = $this->doAmountMatch($repos->getJournalTotal($journal), $bill->amount_min, $bill->amount_max);
|
||||||
|
|
||||||
// when both, update!
|
// when both, update!
|
||||||
if ($wordMatch && $amountMatch) {
|
if ($wordMatch && $amountMatch) {
|
||||||
@ -561,6 +574,7 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* TODO refactor
|
||||||
* @param float $amount
|
* @param float $amount
|
||||||
* @param float $min
|
* @param float $min
|
||||||
* @param float $max
|
* @param float $max
|
||||||
@ -577,6 +591,7 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* TODO refactor
|
||||||
* @param array $matches
|
* @param array $matches
|
||||||
* @param $description
|
* @param $description
|
||||||
*
|
*
|
||||||
|
@ -356,6 +356,30 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return total amount of journal. Is always positive.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getJournalTotal(TransactionJournal $journal): string
|
||||||
|
{
|
||||||
|
$cache = new CacheProperties;
|
||||||
|
$cache->addProperty($journal->id);
|
||||||
|
$cache->addProperty('amount-positive');
|
||||||
|
if ($cache->has()) {
|
||||||
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
|
// saves on queries:
|
||||||
|
$amount = $journal->transactions()->where('amount', '>', 0)->get()->sum('amount');
|
||||||
|
$amount = strval($amount);
|
||||||
|
$cache->store($amount);
|
||||||
|
|
||||||
|
return $amount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return value of a meta field (or NULL) as a string.
|
* Return value of a meta field (or NULL) as a string.
|
||||||
*
|
*
|
||||||
@ -475,6 +499,24 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
return $set;
|
return $set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will tell you if journal is reconciled or not.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isJournalReconciled(TransactionJournal $journal): bool
|
||||||
|
{
|
||||||
|
foreach ($journal->transactions as $transaction) {
|
||||||
|
if ($transaction->reconciled) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Transaction $transaction
|
* @param Transaction $transaction
|
||||||
*
|
*
|
||||||
|
@ -36,7 +36,6 @@ use Illuminate\Support\MessageBag;
|
|||||||
*/
|
*/
|
||||||
interface JournalRepositoryInterface
|
interface JournalRepositoryInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
* @param TransactionType $type
|
* @param TransactionType $type
|
||||||
@ -165,6 +164,15 @@ interface JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getJournalSourceAccounts(TransactionJournal $journal): Collection;
|
public function getJournalSourceAccounts(TransactionJournal $journal): Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return total amount of journal. Is always positive.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getJournalTotal(TransactionJournal $journal): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return value of a meta field (or NULL).
|
* Return value of a meta field (or NULL).
|
||||||
*
|
*
|
||||||
@ -230,6 +238,15 @@ interface JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getTransactionsById(array $transactionIds): Collection;
|
public function getTransactionsById(array $transactionIds): Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will tell you if journal is reconciled or not.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isJournalReconciled(TransactionJournal $journal): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Transaction $transaction
|
* @param Transaction $transaction
|
||||||
*
|
*
|
||||||
|
@ -28,6 +28,7 @@ use FireflyIII\Models\PiggyBank;
|
|||||||
use FireflyIII\Models\PiggyBankEvent;
|
use FireflyIII\Models\PiggyBankEvent;
|
||||||
use FireflyIII\Models\PiggyBankRepetition;
|
use FireflyIII\Models\PiggyBankRepetition;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
@ -222,8 +223,12 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getExactAmount(PiggyBank $piggyBank, PiggyBankRepetition $repetition, TransactionJournal $journal): string
|
public function getExactAmount(PiggyBank $piggyBank, PiggyBankRepetition $repetition, TransactionJournal $journal): string
|
||||||
{
|
{
|
||||||
$amount = $journal->amountPositive();
|
/** @var JournalRepositoryInterface $repos */
|
||||||
$sources = $journal->sourceAccountList()->pluck('id')->toArray();
|
$repos = app(JournalRepositoryInterface::class);
|
||||||
|
$repos->setUser($this->user);
|
||||||
|
|
||||||
|
$amount = $repos->getJournalTotal($journal);
|
||||||
|
$sources = $repos->getJournalSourceAccounts($journal)->pluck('id')->toArray();
|
||||||
$room = bcsub(strval($piggyBank->targetamount), strval($repetition->currentamount));
|
$room = bcsub(strval($piggyBank->targetamount), strval($repetition->currentamount));
|
||||||
$compare = bcmul($repetition->currentamount, '-1');
|
$compare = bcmul($repetition->currentamount, '-1');
|
||||||
|
|
||||||
|
@ -63,66 +63,6 @@ trait TransactionJournalTrait
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function amount(): string
|
|
||||||
{
|
|
||||||
$cache = new CacheProperties;
|
|
||||||
$cache->addProperty($this->id);
|
|
||||||
$cache->addProperty('transaction-journal');
|
|
||||||
$cache->addProperty('amount');
|
|
||||||
if ($cache->has()) {
|
|
||||||
return $cache->get(); // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
|
|
||||||
// saves on queries:
|
|
||||||
$amount = $this->transactions()->where('amount', '>', 0)->get()->sum('amount');
|
|
||||||
|
|
||||||
if ($this->isWithdrawal()) {
|
|
||||||
$amount = $amount * -1;
|
|
||||||
}
|
|
||||||
$amount = strval($amount);
|
|
||||||
$cache->store($amount);
|
|
||||||
|
|
||||||
return $amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function amountPositive(): string
|
|
||||||
{
|
|
||||||
$cache = new CacheProperties;
|
|
||||||
$cache->addProperty($this->id);
|
|
||||||
$cache->addProperty('transaction-journal');
|
|
||||||
$cache->addProperty('amount-positive');
|
|
||||||
if ($cache->has()) {
|
|
||||||
return $cache->get(); // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
|
|
||||||
// saves on queries:
|
|
||||||
$amount = $this->transactions()->where('amount', '>', 0)->get()->sum('amount');
|
|
||||||
|
|
||||||
$amount = strval($amount);
|
|
||||||
$cache->store($amount);
|
|
||||||
|
|
||||||
return $amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function budgetId(): int
|
|
||||||
{
|
|
||||||
$budget = $this->budgets()->first();
|
|
||||||
if (null !== $budget) {
|
|
||||||
return $budget->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||||
*/
|
*/
|
||||||
@ -133,51 +73,6 @@ trait TransactionJournalTrait
|
|||||||
*/
|
*/
|
||||||
abstract public function categories(): BelongsToMany;
|
abstract public function categories(): BelongsToMany;
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function categoryAsString(): string
|
|
||||||
{
|
|
||||||
$category = $this->categories()->first();
|
|
||||||
if (null !== $category) {
|
|
||||||
return $category->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $dateField
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function dateAsString(string $dateField = ''): string
|
|
||||||
{
|
|
||||||
if ('' === $dateField) {
|
|
||||||
return $this->date->format('Y-m-d');
|
|
||||||
}
|
|
||||||
if (null !== $this->$dateField && $this->$dateField instanceof Carbon) {
|
|
||||||
// make field NULL
|
|
||||||
$carbon = clone $this->$dateField;
|
|
||||||
$this->$dateField = null;
|
|
||||||
$this->save();
|
|
||||||
|
|
||||||
// create meta entry
|
|
||||||
$this->setMeta($dateField, $carbon);
|
|
||||||
|
|
||||||
// return that one instead.
|
|
||||||
return $carbon->format('Y-m-d');
|
|
||||||
}
|
|
||||||
$metaField = $this->getMeta($dateField);
|
|
||||||
if (null !== $metaField) {
|
|
||||||
$carbon = new Carbon($metaField);
|
|
||||||
|
|
||||||
return $carbon->format('Y-m-d');
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
|
@ -349,29 +349,4 @@ class General extends Twig_Extension
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Twig_SimpleFunction
|
|
||||||
*/
|
|
||||||
protected function steamPositive()
|
|
||||||
{
|
|
||||||
return new Twig_SimpleFunction(
|
|
||||||
'steam_positive',
|
|
||||||
function (string $str): string {
|
|
||||||
return Steam::positive($str);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Twig_SimpleFunction
|
|
||||||
*/
|
|
||||||
private function getAmountFromJournal()
|
|
||||||
{
|
|
||||||
return new Twig_SimpleFunction(
|
|
||||||
'getAmount',
|
|
||||||
function (TransactionJournal $journal): string {
|
|
||||||
return $journal->amount();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\TransactionRules\Triggers;
|
namespace FireflyIII\TransactionRules\Triggers;
|
||||||
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,7 +66,12 @@ final class AmountExactly extends AbstractTrigger implements TriggerInterface
|
|||||||
*/
|
*/
|
||||||
public function triggered(TransactionJournal $journal): bool
|
public function triggered(TransactionJournal $journal): bool
|
||||||
{
|
{
|
||||||
$amount = $journal->destination_amount ?? $journal->amountPositive();
|
/** @var JournalRepositoryInterface $repos */
|
||||||
|
$repos = app(JournalRepositoryInterface::class);
|
||||||
|
$repos->setUser($journal->user);
|
||||||
|
|
||||||
|
|
||||||
|
$amount = $journal->destination_amount ?? $repos->getJournalTotal($journal);
|
||||||
$compare = $this->triggerValue;
|
$compare = $this->triggerValue;
|
||||||
$result = bccomp($amount, $compare);
|
$result = bccomp($amount, $compare);
|
||||||
if (0 === $result) {
|
if (0 === $result) {
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\TransactionRules\Triggers;
|
namespace FireflyIII\TransactionRules\Triggers;
|
||||||
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,7 +66,11 @@ final class AmountLess extends AbstractTrigger implements TriggerInterface
|
|||||||
*/
|
*/
|
||||||
public function triggered(TransactionJournal $journal): bool
|
public function triggered(TransactionJournal $journal): bool
|
||||||
{
|
{
|
||||||
$amount = $journal->destination_amount ?? $journal->amountPositive();
|
/** @var JournalRepositoryInterface $repos */
|
||||||
|
$repos = app(JournalRepositoryInterface::class);
|
||||||
|
$repos->setUser($journal->user);
|
||||||
|
|
||||||
|
$amount = $journal->destination_amount ?? $repos->getJournalTotal($journal);
|
||||||
$compare = $this->triggerValue;
|
$compare = $this->triggerValue;
|
||||||
$result = bccomp($amount, $compare);
|
$result = bccomp($amount, $compare);
|
||||||
if ($result === -1) {
|
if ($result === -1) {
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\TransactionRules\Triggers;
|
namespace FireflyIII\TransactionRules\Triggers;
|
||||||
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,7 +72,11 @@ final class AmountMore extends AbstractTrigger implements TriggerInterface
|
|||||||
*/
|
*/
|
||||||
public function triggered(TransactionJournal $journal): bool
|
public function triggered(TransactionJournal $journal): bool
|
||||||
{
|
{
|
||||||
$amount = $journal->destination_amount ?? $journal->amountPositive();
|
/** @var JournalRepositoryInterface $repos */
|
||||||
|
$repos = app(JournalRepositoryInterface::class);
|
||||||
|
$repos->setUser($journal->user);
|
||||||
|
|
||||||
|
$amount = $journal->destination_amount ?? $repos->getJournalTotal($journal);
|
||||||
$compare = $this->triggerValue;
|
$compare = $this->triggerValue;
|
||||||
$result = bccomp($amount, $compare);
|
$result = bccomp($amount, $compare);
|
||||||
if (1 === $result) {
|
if (1 === $result) {
|
||||||
|
@ -316,15 +316,6 @@ class SplitControllerTest extends TestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$journalRepos->shouldReceive('first')->once()->andReturn($opening);
|
$journalRepos->shouldReceive('first')->once()->andReturn($opening);
|
||||||
// $journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]));
|
|
||||||
// $journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]));
|
|
||||||
//$journalRepos->shouldReceive('getTransactionType')->once()->andReturn('Opening balance');
|
|
||||||
// $journalRepos->shouldReceive('getJournalDate')->andReturn('2018-01-01')->once();
|
|
||||||
// $journalRepos->shouldReceive('getMetaField')->andReturn('');
|
|
||||||
// $journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->once();
|
|
||||||
// $journalRepos->shouldReceive('getJournalBudgetId')->andReturn(0);
|
|
||||||
// $journalRepos->shouldReceive('getCategoryName')->andReturn('');
|
|
||||||
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('transactions.split.update', [$opening->id]), $data);
|
$response = $this->post(route('transactions.split.update', [$opening->id]), $data);
|
||||||
|
Loading…
Reference in New Issue
Block a user