mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-09 23:15:45 -06:00
Code for reconcile.
This commit is contained in:
parent
1fee62566b
commit
0faa599b4c
@ -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);
|
||||
|
8
public/js/ff/accounts/reconcile.js
vendored
8
public/js/ff/accounts/reconcile.js
vendored
@ -134,7 +134,7 @@ function calculateBalanceDifference() {
|
||||
var endBalance = parseFloat($('input[name="end_balance"]').val());
|
||||
balanceDifference = startBalance - endBalance;
|
||||
//if (balanceDifference < 0) {
|
||||
// balanceDifference = balanceDifference * -1;
|
||||
// balanceDifference = balanceDifference * -1;
|
||||
//}
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
$.each($('input[class="cleared"]'), function (i, v) {
|
||||
var obj = $(v);
|
||||
selectedAmount = selectedAmount - parseFloat(obj.val());
|
||||
if (obj.data('younger') === false) {
|
||||
selectedAmount = selectedAmount - parseFloat(obj.val());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -631,6 +631,8 @@ return [
|
||||
'date_change_instruction' => 'If you change the date range now, any progress will be lost.',
|
||||
'update_selection' => 'Update selection',
|
||||
'store_reconcile' => 'Store reconciliation',
|
||||
'reconciliation_transaction' => 'Reconciliation transaction',
|
||||
'Reconciliation' => 'Reconciliation',
|
||||
'reconcile_options' => 'Reconciliation options',
|
||||
'reconcile_range' => 'Reconciliation range',
|
||||
'start_reconcile' => 'Start reconciling',
|
||||
@ -656,6 +658,7 @@ return [
|
||||
'reconcile_go_back' => 'You can always edit or delete a correction later.',
|
||||
'must_be_asset_account' => 'You can only reconcile asset accounts',
|
||||
'reconciliation_stored' => 'Reconciliation stored',
|
||||
'reconcilliation_transaction_title' => 'Reconciliation (:from to :to)',
|
||||
'reconcile_this_account' => 'Reconcile this account',
|
||||
'confirm_reconciliation' => 'Confirm reconciliation',
|
||||
'submitted_start_balance' => 'Submitted start balance',
|
||||
|
@ -28,7 +28,7 @@
|
||||
<td>{{ formatAmountByAccount(account, amount) }}</td>
|
||||
</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>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -84,7 +84,8 @@
|
||||
<td>
|
||||
{% if transaction.reconciled %}
|
||||
{{ 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 %}
|
||||
<input type="checkbox" name="reconciled[]"
|
||||
data-younger="{% if transaction.date > end %}true{% else %}false{% endif %}"
|
||||
|
Loading…
Reference in New Issue
Block a user