diff --git a/app/Jobs/Banking/CreateReconciliation.php b/app/Jobs/Banking/CreateReconciliation.php index 58565abee..bf54d7711 100644 --- a/app/Jobs/Banking/CreateReconciliation.php +++ b/app/Jobs/Banking/CreateReconciliation.php @@ -4,6 +4,7 @@ namespace App\Jobs\Banking; use App\Abstracts\Job; use App\Models\Banking\Reconciliation; +use App\Models\Banking\Transaction; class CreateReconciliation extends Job { @@ -40,10 +41,13 @@ class CreateReconciliation extends Job if ($transactions) { foreach ($transactions as $key => $value) { - $t = explode('_', $key); - $m = '\\' . $t['1']; + if (empty($value)) { + continue; + } - $transaction = $m::find($t[0]); + $t = explode('_', $key); + + $transaction = Transaction::find($t[1]); $transaction->reconciled = 1; $transaction->save(); } diff --git a/app/Jobs/Banking/UpdateReconciliation.php b/app/Jobs/Banking/UpdateReconciliation.php index ddc57ca45..b7fa2f413 100644 --- a/app/Jobs/Banking/UpdateReconciliation.php +++ b/app/Jobs/Banking/UpdateReconciliation.php @@ -4,6 +4,7 @@ namespace App\Jobs\Banking; use App\Abstracts\Job; use App\Models\Banking\Reconciliation; +use App\Models\Banking\Transaction; class UpdateReconciliation extends Job { @@ -38,10 +39,13 @@ class UpdateReconciliation extends Job if ($transactions) { foreach ($transactions as $key => $value) { + if (empty($value)) { + continue; + } + $t = explode('_', $key); - $m = '\\' . $t['1']; - $transaction = $m::find($t[0]); + $transaction = Transaction::find($t[1]); $transaction->reconciled = 1; $transaction->save(); } diff --git a/resources/assets/js/views/banking/reconciliations.js b/resources/assets/js/views/banking/reconciliations.js index b3eeb42d1..475f4fe81 100644 --- a/resources/assets/js/views/banking/reconciliations.js +++ b/resources/assets/js/views/banking/reconciliations.js @@ -28,7 +28,79 @@ const app = new Vue({ data: function () { return { form: new Form('reconciliation'), - bulk_action: new BulkAction('reconciliations') + bulk_action: new BulkAction('reconciliations'), + reconcile: true, + difference: null, + totals: { + closing_balance: 0, + cleared_amount: 0, + difference: 0, + }, + currency: null, } - } + }, + + mounted() { + this.totals.closing_balance = parseFloat(document.getElementById('closing_balance').value); + }, + + methods:{ + onReconcilition() { + let form = document.getElementById('form-create-reconciliation'); + + let path = form.action +'?started_at=' + this.form.started_at + '&ended_at=' + this.form.ended_at + '&closing_balance=' + this.form.closing_balance + '&account_id=' + this.form.account_id; + + window.location.href = path; + }, + + onCalculate() { + this.reconcile = true; + this.difference = null; + + let transactions = this.form.transactions; + + let cleared_amount = 0; + let difference = 0; + let income_total = 0; + let expense_total = 0; + + if (transactions) { + // get all transactions. + Object.keys(transactions).forEach(function(transaction) { + if (!transactions[transaction]) { + return; + } + + let type = transaction.split('_'); + + if (type[0] == 'income') { + income_total += parseFloat(document.getElementById('transaction-' + type[1] + '-' + type[0]).value); + } else { + expense_total += parseFloat(document.getElementById('transaction-' + type[1] + '-' + type[0]).value); + } + }); + + cleared_amount = parseFloat(this.form.opening_balance) + parseFloat(income_total - expense_total); + } + + difference = parseFloat(this.form.closing_balance) - cleared_amount; + + if (difference != 0) { + this.difference = 'table-danger'; + this.reconcile = true; + } else { + this.difference = 'table-success'; + this.reconcile = false; + } + + this.totals.cleared_amount = cleared_amount; + this.totals.difference = difference; + }, + + onReconcileSubmit() { + this.form.reconcile = 1; + + this.form.submit(); + } + }, }); diff --git a/resources/views/banking/reconciliations/create.blade.php b/resources/views/banking/reconciliations/create.blade.php index 618690f27..126f2df40 100644 --- a/resources/views/banking/reconciliations/create.blade.php +++ b/resources/views/banking/reconciliations/create.blade.php @@ -5,10 +5,9 @@ @section('content')
{{ trans('general.date') }} | +|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
{{ trans('general.date') }} | {{ trans('general.description') }} | {{ trans_choice('general.contacts', 1) }} | {{ trans('reconciliations.deposit') }} | @@ -39,58 +42,91 @@||||||||
@date($item->paid_at) | {{ $item->description }} | -{{ $item->contact->name }} | +{{ $item->contact->name }} | @if ($item->type == 'income')@money($item->amount, $item->currency_code, true) | -+ | N/A | @else -+ | N/A | @money($item->amount, $item->currency_code, true) | @endif -{{ Form::checkbox('transactions['. $item->id . '_'. $item->type . ']', $item->amount, $item->reconciled) }} | +
+
+ {{ Form::checkbox($item->type . '_' . $item->id, $item->amount, $item->reconciled, [
+ 'data-field' => 'transactions',
+ 'v-model' => 'form.transactions.' . $item->type . '_' . $item->id,
+ 'id' => 'transaction-' . $item->id . '-'. $item->type,
+ 'class' => 'custom-control-input',
+ '@change' => 'onCalculate'
+ ]) }}
+
+
+ |
{{ trans('reconciliations.closing_balance') }}: | -@money($reconciliation->closing_balance, $account->currency_code, true) | -
---|---|
{{ trans('reconciliations.cleared_amount') }}: | -@money('0', $account->currency_code, true) | -
{{ trans('general.difference') }}: | -@money('0', $account->currency_code, true) | -
{{ trans('reconciliations.closing_balance') }}: | ++ {{ Form::moneyGroup('closing_balance_total', '', '', ['disabled' => 'disabled', 'required' => 'required', 'v-model' => 'totals.closing_balance', 'currency' => $currency, 'dynamic-currency' => 'currency', 'masked' => 'true'], $reconciliation->closing_balance, 'text-right d-none') }} + + @money($reconciliation->closing_balance, $account->currency_code, true) + | +
---|---|
{{ trans('reconciliations.cleared_amount') }}: | ++ {{ Form::moneyGroup('cleared_amount_total', '', '', ['disabled' => 'disabled', 'required' => 'required', 'v-model' => 'totals.cleared_amount', 'currency' => $currency, 'dynamic-currency' => 'currency', 'masked' => 'true'], 0.00, 'text-right d-none') }} + + @money(0, $account->currency_code, true) + | +
{{ trans('general.difference') }}: | ++ {{ Form::moneyGroup('difference_total', '', '', ['disabled' => 'disabled', 'required' => 'required', 'v-model' => 'totals.difference', 'currency' => $currency, 'dynamic-currency' => 'currency', 'masked' => 'true'], 0.00, 'text-right d-none') }} + + @money(0, $account->currency_code, true) + | +