mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code for reconcile.
This commit is contained in:
@@ -89,15 +89,21 @@ class ReconcileController extends Controller
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$transactions = $repository->getTransactionsById($transactionIds);
|
||||
$cleared = $repository->getTransactionsById($clearedIds);
|
||||
$countCleared = 0;
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
// {% if transaction.date > end %}
|
||||
|
||||
$amount = bcadd($amount, $transaction->amount);
|
||||
}
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($cleared as $transaction) {
|
||||
$clearedAmount = bcadd($clearedAmount, $transaction->amount);
|
||||
if ($transaction->transactionJournal->date <= $end) {
|
||||
$clearedAmount = bcadd($clearedAmount, $transaction->amount);
|
||||
$countCleared++;
|
||||
}
|
||||
}
|
||||
|
||||
// final difference:
|
||||
@@ -114,7 +120,7 @@ class ReconcileController extends Controller
|
||||
'accounts.reconcile.overview',
|
||||
compact(
|
||||
'account', 'start', 'diffCompare', 'difference', 'end', 'clearedIds', 'transactionIds', 'clearedAmount', 'startBalance', 'endBalance', 'amount',
|
||||
'route'
|
||||
'route','countCleared'
|
||||
)
|
||||
)->render();
|
||||
|
||||
@@ -221,14 +227,19 @@ class ReconcileController extends Controller
|
||||
'budget_id' => 0,
|
||||
'amount' => $difference,
|
||||
'currency_id' => $account->getMeta('currency_id'),
|
||||
'description' => 'Reconciliation [period]',
|
||||
'description' => trans(
|
||||
'firefly.reconcilliation_transaction_title',
|
||||
['from' => $start->formatLocalized($this->monthAndDayFormat), 'to' => $end->formatLocalized($this->monthAndDayFormat)]
|
||||
),
|
||||
'date' => $request->get('end'),
|
||||
'notes' => join(',', $transactions->pluck('id')->toArray()),
|
||||
];
|
||||
$journal = $repository->store($data);
|
||||
// reconcile this transaction too:
|
||||
$transaction = $journal->transactions()->first();
|
||||
$repository->reconcile($transaction);
|
||||
}
|
||||
|
||||
Session::flash('success', trans('firefly.reconciliation_stored'));
|
||||
|
||||
return redirect(route('accounts.show', [$account->id]));
|
||||
|
||||
@@ -57,6 +57,11 @@ class Transaction extends Twig_Extension
|
||||
$format = '%s';
|
||||
$coloured = true;
|
||||
|
||||
// at this point amount is always negative.
|
||||
if ($transaction->transaction_type_type === TransactionType::RECONCILIATION && bccomp(strval($transaction->transaction_amount),'0') === 1) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
|
||||
if (TransactionType::DEPOSIT === $transaction->transaction_type_type) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
@@ -285,6 +290,10 @@ class Transaction extends Twig_Extension
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
if($transaction->transaction_type_type === TransactionType::RECONCILIATION) {
|
||||
return '—';
|
||||
}
|
||||
|
||||
$name = app('steam')->tryDecrypt($transaction->account_name);
|
||||
$transactionId = intval($transaction->account_id);
|
||||
$type = $transaction->account_type;
|
||||
@@ -387,6 +396,9 @@ class Transaction extends Twig_Extension
|
||||
case TransactionType::OPENING_BALANCE:
|
||||
$txt = sprintf('<i class="fa-fw fa fa-star-o" title="%s"></i>', trans('firefly.openingBalance'));
|
||||
break;
|
||||
case TransactionType::RECONCILIATION:
|
||||
$txt = sprintf('<i class="fa-fw fa fa-calculator" title="%s"></i>', trans('firefly.reconciliation_transaction'));
|
||||
break;
|
||||
default:
|
||||
$txt = '';
|
||||
break;
|
||||
@@ -464,6 +476,9 @@ class Transaction extends Twig_Extension
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
if($transaction->transaction_type_type === TransactionType::RECONCILIATION) {
|
||||
return '—';
|
||||
}
|
||||
|
||||
// if the amount is negative, assume that the current account (the one in $transaction) is indeed the source account.
|
||||
$name = app('steam')->tryDecrypt($transaction->account_name);
|
||||
|
||||
Reference in New Issue
Block a user