mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-25 06:51:08 +00:00
Simplify method.
This commit is contained in:
@@ -46,12 +46,10 @@ use Throwable;
|
|||||||
class ReconcileController extends Controller
|
class ReconcileController extends Controller
|
||||||
{
|
{
|
||||||
use UserNavigation;
|
use UserNavigation;
|
||||||
/** @var AccountRepositoryInterface The account repository */
|
|
||||||
private $accountRepos;
|
private AccountRepositoryInterface $accountRepos;
|
||||||
/** @var CurrencyRepositoryInterface The currency repository */
|
private CurrencyRepositoryInterface $currencyRepos;
|
||||||
private $currencyRepos;
|
private JournalRepositoryInterface $repository;
|
||||||
/** @var JournalRepositoryInterface Journals and transactions overview */
|
|
||||||
private $repository;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ReconcileController constructor.
|
* ReconcileController constructor.
|
||||||
@@ -196,6 +194,7 @@ class ReconcileController extends Controller
|
|||||||
$currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
$currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
||||||
$startBalance = round(app('steam')->balance($account, $startDate), $currency->decimal_places);
|
$startBalance = round(app('steam')->balance($account, $startDate), $currency->decimal_places);
|
||||||
$endBalance = round(app('steam')->balance($account, $end), $currency->decimal_places);
|
$endBalance = round(app('steam')->balance($account, $end), $currency->decimal_places);
|
||||||
|
|
||||||
// get the transactions
|
// get the transactions
|
||||||
$selectionStart = clone $start;
|
$selectionStart = clone $start;
|
||||||
$selectionStart->subDays(3);
|
$selectionStart->subDays(3);
|
||||||
@@ -210,36 +209,7 @@ class ReconcileController extends Controller
|
|||||||
->setRange($selectionStart, $selectionEnd)
|
->setRange($selectionStart, $selectionEnd)
|
||||||
->withBudgetInformation()->withCategoryInformation()->withAccountInformation();
|
->withBudgetInformation()->withCategoryInformation()->withAccountInformation();
|
||||||
$array = $collector->getExtractedJournals();
|
$array = $collector->getExtractedJournals();
|
||||||
$journals = [];
|
$journals = $this->processTransactions($account, $array);
|
||||||
// "fix" amounts to make it easier on the reconciliation overview:
|
|
||||||
/** @var array $journal */
|
|
||||||
foreach ($array as $journal) {
|
|
||||||
$inverse = false;
|
|
||||||
// @codeCoverageIgnoreStart
|
|
||||||
if (TransactionType::DEPOSIT === $journal['transaction_type_type']) {
|
|
||||||
$inverse = true;
|
|
||||||
}
|
|
||||||
// transfer to this account? then positive amount:
|
|
||||||
if (TransactionType::TRANSFER === $journal['transaction_type_type'] && $account->id === $journal['destination_account_id']) {
|
|
||||||
$inverse = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// opening balance into account? then positive amount:
|
|
||||||
if (TransactionType::OPENING_BALANCE === $journal['transaction_type_type']
|
|
||||||
&& $account->id === $journal['destination_account_id']) {
|
|
||||||
$inverse = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (true === $inverse) {
|
|
||||||
$journal['amount'] = app('steam')->positive($journal['amount']);
|
|
||||||
if (null !== $journal['foreign_amount']) {
|
|
||||||
$journal['foreign_amount'] = app('steam')->positive($journal['foreign_amount']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
|
|
||||||
$journals[] = $journal;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$html = view(
|
$html = view(
|
||||||
@@ -296,4 +266,45 @@ class ReconcileController extends Controller
|
|||||||
|
|
||||||
return $amount;
|
return $amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "fix" amounts to make it easier on the reconciliation overview:
|
||||||
|
*
|
||||||
|
* @param Account $account
|
||||||
|
* @param array $array
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function processTransactions(Account $account, array $array): array
|
||||||
|
{
|
||||||
|
$journals = [];
|
||||||
|
/** @var array $journal */
|
||||||
|
foreach ($array as $journal) {
|
||||||
|
$inverse = false;
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
|
if (TransactionType::DEPOSIT === $journal['transaction_type_type']) {
|
||||||
|
$inverse = true;
|
||||||
|
}
|
||||||
|
// transfer to this account? then positive amount:
|
||||||
|
if (TransactionType::TRANSFER === $journal['transaction_type_type'] && $account->id === $journal['destination_account_id']) {
|
||||||
|
$inverse = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// opening balance into account? then positive amount:
|
||||||
|
if (TransactionType::OPENING_BALANCE === $journal['transaction_type_type']
|
||||||
|
&& $account->id === $journal['destination_account_id']) {
|
||||||
|
$inverse = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true === $inverse) {
|
||||||
|
$journal['amount'] = app('steam')->positive($journal['amount']);
|
||||||
|
if (null !== $journal['foreign_amount']) {
|
||||||
|
$journal['foreign_amount'] = app('steam')->positive($journal['foreign_amount']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
|
$journals[] = $journal;
|
||||||
|
}
|
||||||
|
return $journals;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user