Code for reconcile.

This commit is contained in:
James Cole 2017-11-22 20:20:44 +01:00
parent 1fee62566b
commit 0faa599b4c
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
6 changed files with 40 additions and 8 deletions

View File

@ -89,15 +89,21 @@ class ReconcileController extends Controller
$repository = app(JournalRepositoryInterface::class); $repository = app(JournalRepositoryInterface::class);
$transactions = $repository->getTransactionsById($transactionIds); $transactions = $repository->getTransactionsById($transactionIds);
$cleared = $repository->getTransactionsById($clearedIds); $cleared = $repository->getTransactionsById($clearedIds);
$countCleared = 0;
/** @var Transaction $transaction */ /** @var Transaction $transaction */
foreach ($transactions as $transaction) { foreach ($transactions as $transaction) {
// {% if transaction.date > end %}
$amount = bcadd($amount, $transaction->amount); $amount = bcadd($amount, $transaction->amount);
} }
/** @var Transaction $transaction */ /** @var Transaction $transaction */
foreach ($cleared as $transaction) { foreach ($cleared as $transaction) {
if ($transaction->transactionJournal->date <= $end) {
$clearedAmount = bcadd($clearedAmount, $transaction->amount); $clearedAmount = bcadd($clearedAmount, $transaction->amount);
$countCleared++;
}
} }
// final difference: // final difference:
@ -114,7 +120,7 @@ class ReconcileController extends Controller
'accounts.reconcile.overview', 'accounts.reconcile.overview',
compact( compact(
'account', 'start', 'diffCompare', 'difference', 'end', 'clearedIds', 'transactionIds', 'clearedAmount', 'startBalance', 'endBalance', 'amount', 'account', 'start', 'diffCompare', 'difference', 'end', 'clearedIds', 'transactionIds', 'clearedAmount', 'startBalance', 'endBalance', 'amount',
'route' 'route','countCleared'
) )
)->render(); )->render();
@ -221,14 +227,19 @@ class ReconcileController extends Controller
'budget_id' => 0, 'budget_id' => 0,
'amount' => $difference, 'amount' => $difference,
'currency_id' => $account->getMeta('currency_id'), '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'), 'date' => $request->get('end'),
'notes' => join(',', $transactions->pluck('id')->toArray()),
]; ];
$journal = $repository->store($data); $journal = $repository->store($data);
// reconcile this transaction too: // reconcile this transaction too:
$transaction = $journal->transactions()->first(); $transaction = $journal->transactions()->first();
$repository->reconcile($transaction); $repository->reconcile($transaction);
} }
Session::flash('success', trans('firefly.reconciliation_stored')); Session::flash('success', trans('firefly.reconciliation_stored'));
return redirect(route('accounts.show', [$account->id])); return redirect(route('accounts.show', [$account->id]));

View File

@ -57,6 +57,11 @@ class Transaction extends Twig_Extension
$format = '%s'; $format = '%s';
$coloured = true; $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) { if (TransactionType::DEPOSIT === $transaction->transaction_type_type) {
$amount = bcmul($amount, '-1'); $amount = bcmul($amount, '-1');
} }
@ -285,6 +290,10 @@ class Transaction extends Twig_Extension
return $cache->get(); return $cache->get();
} }
if($transaction->transaction_type_type === TransactionType::RECONCILIATION) {
return '&mdash;';
}
$name = app('steam')->tryDecrypt($transaction->account_name); $name = app('steam')->tryDecrypt($transaction->account_name);
$transactionId = intval($transaction->account_id); $transactionId = intval($transaction->account_id);
$type = $transaction->account_type; $type = $transaction->account_type;
@ -387,6 +396,9 @@ class Transaction extends Twig_Extension
case TransactionType::OPENING_BALANCE: case TransactionType::OPENING_BALANCE:
$txt = sprintf('<i class="fa-fw fa fa-star-o" title="%s"></i>', trans('firefly.openingBalance')); $txt = sprintf('<i class="fa-fw fa fa-star-o" title="%s"></i>', trans('firefly.openingBalance'));
break; break;
case TransactionType::RECONCILIATION:
$txt = sprintf('<i class="fa-fw fa fa-calculator" title="%s"></i>', trans('firefly.reconciliation_transaction'));
break;
default: default:
$txt = ''; $txt = '';
break; break;
@ -464,6 +476,9 @@ class Transaction extends Twig_Extension
if ($cache->has()) { if ($cache->has()) {
return $cache->get(); return $cache->get();
} }
if($transaction->transaction_type_type === TransactionType::RECONCILIATION) {
return '&mdash;';
}
// if the amount is negative, assume that the current account (the one in $transaction) is indeed the source account. // 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); $name = app('steam')->tryDecrypt($transaction->account_name);

View File

@ -153,13 +153,15 @@ function getTransactionsForRange() {
} }
/** /**
* Loop over all transactions that have already been cleared and add this to the selectedAmount. * Loop over all transactions that have already been cleared (in the range) and add this to the selectedAmount.
* *
*/ */
function includeClearedTransactions() { function includeClearedTransactions() {
$.each($('input[class="cleared"]'), function (i, v) { $.each($('input[class="cleared"]'), function (i, v) {
var obj = $(v); var obj = $(v);
if (obj.data('younger') === false) {
selectedAmount = selectedAmount - parseFloat(obj.val()); selectedAmount = selectedAmount - parseFloat(obj.val());
}
}); });
} }

View File

@ -631,6 +631,8 @@ return [
'date_change_instruction' => 'If you change the date range now, any progress will be lost.', 'date_change_instruction' => 'If you change the date range now, any progress will be lost.',
'update_selection' => 'Update selection', 'update_selection' => 'Update selection',
'store_reconcile' => 'Store reconciliation', 'store_reconcile' => 'Store reconciliation',
'reconciliation_transaction' => 'Reconciliation transaction',
'Reconciliation' => 'Reconciliation',
'reconcile_options' => 'Reconciliation options', 'reconcile_options' => 'Reconciliation options',
'reconcile_range' => 'Reconciliation range', 'reconcile_range' => 'Reconciliation range',
'start_reconcile' => 'Start reconciling', 'start_reconcile' => 'Start reconciling',
@ -656,6 +658,7 @@ return [
'reconcile_go_back' => 'You can always edit or delete a correction later.', 'reconcile_go_back' => 'You can always edit or delete a correction later.',
'must_be_asset_account' => 'You can only reconcile asset accounts', 'must_be_asset_account' => 'You can only reconcile asset accounts',
'reconciliation_stored' => 'Reconciliation stored', 'reconciliation_stored' => 'Reconciliation stored',
'reconcilliation_transaction_title' => 'Reconciliation (:from to :to)',
'reconcile_this_account' => 'Reconcile this account', 'reconcile_this_account' => 'Reconcile this account',
'confirm_reconciliation' => 'Confirm reconciliation', 'confirm_reconciliation' => 'Confirm reconciliation',
'submitted_start_balance' => 'Submitted start balance', 'submitted_start_balance' => 'Submitted start balance',

View File

@ -28,7 +28,7 @@
<td>{{ formatAmountByAccount(account, amount) }}</td> <td>{{ formatAmountByAccount(account, amount) }}</td>
</tr> </tr>
<tr> <tr>
<td>{{ trans('firefly.already_cleared_transactions', {count: clearedIds|length}) }}</td> <td>{{ trans('firefly.already_cleared_transactions', {count: countCleared}) }}</td>
<td>{{ formatAmountByAccount(account, clearedAmount) }}</td> <td>{{ formatAmountByAccount(account, clearedAmount) }}</td>
</tr> </tr>
<tr> <tr>

View File

@ -84,7 +84,8 @@
<td> <td>
{% if transaction.reconciled %} {% if transaction.reconciled %}
{{ transaction|transactionReconciled }} {{ transaction|transactionReconciled }}
<input type="hidden" name="cleared[]" class="cleared" data-id="{{ transaction.id }}" value="{{ transaction.transaction_amount }}"> <input type="hidden" name="cleared[]" data-younger="{% if transaction.date > end %}true{% else %}false{% endif %}"
class="cleared" data-id="{{ transaction.id }}" value="{{ transaction.transaction_amount }}">
{% else %} {% else %}
<input type="checkbox" name="reconciled[]" <input type="checkbox" name="reconciled[]"
data-younger="{% if transaction.date > end %}true{% else %}false{% endif %}" data-younger="{% if transaction.date > end %}true{% else %}false{% endif %}"