Files
streamline-emr/docker/statistics/Modules/Banking/Resources/views/banking/reconcile/index.blade.php
T
2025-03-31 03:46:05 +03:00

573 lines
27 KiB
PHP
Executable File

@extends('layouts.main')
@push('styles')
<link href="{{ asset('elite/bower_components/bootstrap-datepicker/bootstrap-datepicker.min.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ asset('/elite/bower_components/datatables/jquery.dataTables.min.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ asset('elite/tables/css/buttons.dataTables.min.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ asset('elite/bower_components/select2/select2.min.css') }}" rel="stylesheet" />
<link href="{{ asset('elite/bower_components/select2/select2.min.css') }}" rel="stylesheet" />
<link href="{{ asset('elite/bower_components/icheck/skins/all.css') }}" rel="stylesheet">
<style>
.row_color {
background: gold;
}
</style>
@endpush
@section('content')
<div class="row bg-title">
<div class="col-lg-3 col-md-4 col-sm-4 col-xs-12">
<h4 class="page-title">Bank Reconciliation</h4>
</div>
<div class="col-lg-9 col-sm-8 col-md-8 col-xs-12">
<ol class="breadcrumb">
<li><a href="{{ route('home') }}"><i class="fa fa-home"></i> Home</a></li>
<li><a href="{{ route('finance') }}"><i class="fa fa-money"></i> Finance Home</a></li>
<li class="active"><i class="fa fa-bank"></i> Bank Reconciliation</li>
</ol>
</div>
</div>
@php
$balance = 0;
@endphp
<br />
@include('flash::message')
<div class="panel">
<div class="panel-body">
<div class="row">
<div class="col-md-12">
{{ Form::open(['route' => 'banking.reconcile', 'data-toggle' => 'validator']) }}
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label>Bank Account :</label>
<select class="form-control compulsory required" name="bank" id="bank" required>
<option value="">-select-</option>
@foreach($banks as $item)
<option value="{{ $item->id }}">{{ $item->name }}</option>
@endforeach
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Reconciliation Date :</label>
<div class="input-group">
<input class="center form-control" id="reconciliation_date" readonly style="padding: 2px;border: 1px solid #ddd;" name="reconciliation_date">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Opening Bank Balance (Stre@mline):</label>
<div class="input-group">
<input class="center form-control compulsory" required id="opening_balance" type="number" style="padding: 2px;border: 1px solid #ddd;" readonly name="opening_balance">
<span class="input-group-addon">.UGX</span>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Ending Balance (Bank Statement):</label>
<div class="input-group">
<input class="center form-control compulsory" required id="ending_balance_input" type="number" style="padding: 2px;border: 1px solid #ddd;" name="ending_balance_input">
<span class="input-group-addon">.UGX</span>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<button class="btn btn-success btn-block" style="margin-top: 25px;">Submit</button>
</div>
</div>
</div>
{{ Form::close() }}
</div>
</div>
<hr />
<br />
@if(!empty($request->all()))
{{ Form::open(['route' => 'banking.finish_reconciling', 'data-toggle' => 'validator', 'id'=>'finish_reconciliation_form']) }}
@if(isset($display))
<div class="row">
<div class="col-md-12 text-center">
<h3 class="label label-megna label-rounded"> {!! isset($display) ? $display : '' !!}</h3>
</div>
</div>
@endif
<br />
<div class="row">
<div class="table-bordered col-md-8">
<div class="row">
<div class="col-md-5 text-center">
<h3>Ending Bank Statement Balance: </h3><span id="ending_balance" style="font-size: 3vw; display: none;">{{ $request->ending_balance_input }}</span>
<span id="ending_balance_display" style="font-size: 3vw;">{{ ugandan_shillings($request->ending_balance_input) }}</span>
</div>
<div class="col-md-2 text-center">
<b><span style="font-size: 4vw;"> - </span></b>
</div>
<div class="col-md-5 text-center">
<h3>Opening Stre@mline Bank Balance: </h3> <b style="display: none;"><span id="balance" style="font-size: 3vw;">{{ is_null($request->opening_balance) ? 0 : $request->opening_balance }}</span></b>
<b><span id="balance_display" style="font-size: 3vw;">{{ is_null($request->opening_balance) ? 0 : ugandan_shillings($request->opening_balance) }}</span></b>
</div>
</div>
</div>
<div class="col-md-4 text-center">
<h3>Difference: </h3><b>
<span id="difference" style="font-size: 3vw; display: none">{{ (int)$request->ending_balance_input - (int)$request->opening_balance }}</span>
<span id="difference_display" style="font-size: 3vw;">{{ ugandan_shillings((int)$request->ending_balance_input - (int)$request->opening_balance) }}</span>
</b>
</div>
</div>
<input type="hidden" value="{{ is_null($request->opening_balance) ? 0 : $request->opening_balance }}" id="old_balance">
<input type="hidden" value="{{ (int)$request->ending_balance_input - (int)$request->opening_balance }}" id="old_difference">
<input type="hidden" name="ending_bank_statement_balance" value="{{ $request->ending_balance_input }}">
<input type="hidden" name="opening_streamline_balance" value="{{ $request->opening_balance }}">
<input type="hidden" name="reconciliation_period" value="{{ $reconciliation_end_date }}">
<input type="hidden" name="bank" value="{{ $request->bank }}">
<br />
<hr>
<div class="row">
<div class="col-md-9 b-r">
<div class="row">
<div class="col-md-12">
@php
$sum_balance = 0;
$sum_credit = 0;
$sum_debit = 0;
@endphp
<div class="table-responsive">
<table id="table" class="table color-bordered-table success-bordered-table">
<thead>
<tr>
<th>#</th>
<th>Transaction Date :</th>
<th>Record Date :</th>
<th>Staff In-Charge :</th>
<th>Type</th>
<th>Account</th>
<th>Memo</th>
<th>Debit</th>
<th>Credit</th>
<th>Balance</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
@php
$counter = 1;
@endphp
@if(count($banking_records) > 0)
@foreach($banking_records as $record)
@php
$sum_credit += $record->credit;
$sum_debit += $record->debit;
@endphp
<tr id="record_row_{{ $record->id }}">
<td>{{ $counter }}.</td>
<td>{{ streamline_date($record->trans_date) }}</td>
<td>{{ streamline_date($record->created_at) }}</td>
<td>{{ get_full_name($record->created_by, 'id', 'first_name', 'last_name', 'users') }}</td>
<td>{{ $record->trans_type }}</td>
@php
$banks = explode(',',$record->bank);
$other_accounts = explode(',',$record->other_accounts);
@endphp
<td>
@for($x = 0; $x
< count($other_accounts); $x++) {{ get_name($other_accounts[$x], 'id', 'name', 'chart_of_accounts') }} <br />
@endfor
</td>
<td>{{ $record->memo }}</td>
@if($record->debit != 0)
<td>{{ ugandan_shillings($record->debit) }}</td>
<input id="debit_amount_{{ $record->id }}" value="{{ $record->debit }}" type="hidden">
@else
<td>{{ ugandan_shillings(0) }}</td>
<input id="debit_amount_{{ $record->id }}" value="{{ 0 }}" type="hidden">
@endif
@if($record->credit != 0)
<td>{{ ugandan_shillings($record->credit) }}</td>
<input id="credit_amount_{{ $record->id }}" value="{{ $record->credit }}" type="hidden">
@else
<td>{{ ugandan_shillings(0) }}</td>
<input id="credit_amount_{{ $record->id }}" value="{{ 0 }}" type="hidden">
@endif
<td>{{ ugandan_shillings($record->account_balance) }}</td>
@if($loop->last)
@php $sum_balance = $record->account_balance; @endphp
@endif
<td class="text-center">
@if($record->debit != 0)
<input type="checkbox" name="reconciled_trans_ids[]" value="{{ $record->id }}" id="debit_checkbox_{{ $record->id }}">
@elseif($record->credit != 0)
<input type="checkbox" name="reconciled_trans_ids[]" value="{{ $record->id }}" id="credit_checkbox_{{ $record->id }}">
@elseif($record->debit == 0 && $record->credit == 0)
<input type="checkbox" name="reconciled_trans_ids[]" value="{{ $record->id }}" id="debit_checkbox_{{ $record->id }}">
@endif
<input type="hidden" name="unreconciled_trans_ids[]" value="{{ $record->id }}" id="unreconciled_checkbox_{{ $record->id }}" checked>
</td>
</tr>
@php $counter++; @endphp
@endforeach
@endif
</tbody>
</table>
</div>
</div>
<div class="col-md-12">
<hr>
<div class="form-group">
{{ Form::label('memo', 'Reconciliation Memo / Comment (Optional)', ['style' => 'font-size: 18px; font-weight: 400'])}}
{{ Form::textarea('memo','',['class' => 'form-control'])}}
</div>
</div>
<div class="col-md-12 pull-right text-right">
<button class="btn btn-primary btn-rounded" id="finish_reconciliation">Finish Reconciliation</button>
</div>
</div>
</div>
<br>
<div class="col-md-3">
<br />
<h3><strong>Previous Reconciliation Reports</strong></h3>
<ul>
@foreach($reconciliation_reports as $report)
<li>
<a target="_blank" href="{{ route('bank.reconciliation.report', $report->id) }}">
{{ streamline_date_time($report->reconciliation_period) }} by {{ get_full_name($report->created_by, "id", "first_name", "last_name", "users") }}
</a>
</li>
<br />
@endforeach
</ul>
</div>
</div>
{{ Form::close() }}
@else
<div class="row">
<div class="col-md-12 text-center">
<h3 class="label label-warning label-rounded"> Please Be Sure To Fill In All The Necessary Fields And Then Submit. </h3>
</div>
</div>
@endif
</div>
</div>
@include('banking::banking.reconcile.modals.finish_with_discrepancy')
@include('banking::banking.reconcile.modals.finish_reconciliation')
@include('banking::banking.reconcile.modals.perform_adjustment')
<div class="modal" id="complete_reconciliation" tabindex="-1" role="dialog" aria-labelledby="complete_reconciliation_label" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h5 class="modal-title" id="complete_reconciliation_label"><b>Confirm</b></h5>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-8 b-r">
<h3>
Are you sure you want to complete this reconciliation
</h3>
</div>
<div class="col-md-4">
<a class="btn-block btn btn-warning" id="cancel_the_reconciliation">Cancel</a>
<a class="btn-block btn btn-success" id="complete_the_reconciliation">Complete Reconciliation</a>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
@push('scripts')
<!-- Date Picker Plugin JavaScript -->
<script src="{{ asset('elite/bower_components/bootstrap-datepicker/bootstrap-datepicker.min.js') }}"></script>
<script src="{{ asset('elite/bower_components/icheck/icheck.min.js') }}"></script>
<script src="{{ asset('elite/bower_components/icheck/icheck.init.js') }}"></script>
<script src="{{ asset('elite/bower_components/datatables/jquery.dataTables.min.js') }}"></script>
<script src="{{ asset('elite/bower_components/select2/select2.min.js') }}"></script>
<script src="{{ asset('elite/tables/js/dataTables.buttons.min.js') }}"></script>
<script src="{{ asset('elite/tables/js/buttons.flash.min.js') }}"></script>
<script src="{{ asset('elite/tables/js/jszip.min.js') }}"></script>
<script src="{{ asset('elite/tables/js/pdfmake.min.js') }}"></script>
<script src="{{ asset('elite/tables/js/vfs_fonts.js') }}"></script>
<script src="{{ asset('elite/tables/js/buttons.html5.min.js') }}"></script>
<script src="{{ asset('elite/tables/js/buttons.print.min.js') }}"></script>
<script>
$('#finish_reconciliation').click(function(e) {
e.preventDefault();
var unreconciled_array = [];
var difference = $('#difference').text();
$("[id^=unreconciled_checkbox_]").each(function() {
var id = /\d+(?=\D*$)/.exec($(this).attr('id'));
var unreconciled = $('#unreconciled_checkbox_' + id).val();
if (unreconciled !== '') {
unreconciled_array.push(id[0]);
}
});
if (unreconciled_array.length === 0) {
if (parseInt(difference) === 0) {
$('#complete_reconciliation').modal('show');
//$('#finish_reconciliation_form').submit();
} else {
alert('It Appears There Is A Discrepancy Of ' + difference)
$('#finish_reconciliation_modal').modal('show');
}
} else {
var _confirm = confirm('You have a difference of ' + difference + ". There are some unreconciled (unticked) transactions. Do you want to continue ?");
if (_confirm) {
if (parseInt(difference) === 0) {
$('#complete_reconciliation').modal('show');
//$('#finish_reconciliation_form').submit();
} else {
$('#finish_reconciliation_modal').modal('show');
}
}
}
});
$('#complete_the_reconciliation').click(function(e) {
e.preventDefault();
$('#finish_reconciliation_form').submit();
});
$('#cancel_the_reconciliation').click(function(e) {
e.preventDefault();
$('#complete_reconciliation').modal('hide');
});
$('#finish_with_balance_btn').click(function(e) {
e.preventDefault();
var adjustment_balance = $('#difference').text();
var ending_balance = $('#ending_balance').text();
$('#__adjustment_difference_balance').val(parseInt(adjustment_balance));
$('#__ending_balance').val(parseInt(ending_balance));
console.log(adjustment_balance)
$('#finish_reconciliation_modal').modal('hide');
$('#finish_with_discrepancy_modal').modal('show');
});
$('#perform_adjustment').click(function(e) {
e.preventDefault();
var adjustment_balance = $('#difference').text();
$('#adjustment_difference_balance').val(parseInt(adjustment_balance));
$('#finish_reconciliation_modal').modal('hide');
$('#perform_adjustment_modal').modal('show');
})
function finish_adjustment() {
$('#performAdjustmentBtn').prop('disabled', true);//disable button to avoid double submission
var bank = $('#bank_id').val();
var account = $('#account').val();
var accountText = $('#account option:selected').text();
var amount = $('#adjustment_difference_balance').val();
var ending_balance = $('#ending_balance').text();//$('#_ending_balance').val();
var reconciliation_period = $('#_reconciliation_period').val();
if ((amount < 0 && accountText.indexOf("(Expense)") > 0) || (amount > 0 && accountText.indexOf("(Income)") > 0)) {
$.ajax({
method: 'post',
url: '/banking/finish_adjustment',
data: {
'account': account,
'bank': bank,
'amount': amount,
'ending_balance': ending_balance,
'reconciliation_period': reconciliation_period,
},
success: function(response) {
if (response == 'success') {
$('#difference').text(0);
$('#finish_reconciliation_form').submit();
} else {
alert("Action failed!")
}
},
error: function(error) {
alert(error);
console.log(error);
}
});
} else {
alert("If the 'Amount To Be Adjusted' is Negative, select an Expense account!\nIf the 'Amount To Be Adjusted' is Positive, select an Income account!");
}
}
function finish_with_discrepancy() {
var bank = $('#__bank_id').val();
var memo = $('#__memo').val();
var amount = $('#__adjustment_difference_balance').val();
var ending_balance = $('#__ending_balance').val();
var reconciliation_period = $('#__reconciliation_period').val();
$.ajax({
method: 'post',
url: '/banking/finish_with_balance',
data: {
'bank': bank,
'memo': memo,
'amount': amount,
'ending_balance': ending_balance,
'reconciliation_period': reconciliation_period,
},
success: function(response) {
if (response == 'success') {
$('#finish_reconciliation_form').submit();
}
},
error: function(error) {
console.log(error)
}
});
}
// when a row:
// - is checked
// - if it has a debit value, opening balance reduces by the debit amount
// - is then unchecked (if was previously checked)
// - if it has a debit value, opening balance increases by the debit amount
$("[id^='debit_checkbox_']").on("change", function() {
var id = /\d+(?=\D*$)/.exec($(this).attr('id'));
var amount = $('#debit_amount_' + id).val();
var balance = $('#balance').text();
var new_balance = parseInt(balance);
if (this.checked) {
new_balance = parseInt(balance) - parseInt(amount);
$('#record_row_' + id).children('td, th').css('background-color', 'gold');
$('#unreconciled_checkbox_' + id).checked = false;
$('#unreconciled_checkbox_' + id).val('');
} else {
new_balance = parseInt(balance) + parseInt(amount);
$('#record_row_' + id).children('td, th').css('background-color', 'white');
$('#unreconciled_checkbox_' + id).checked = true;
$('#unreconciled_checkbox_' + id).val(id);
}
var new_difference = parseInt(<?php echo json_encode((int)$request->ending_balance_input); ?>) - new_balance;
$('#balance').text(new_balance);
$('#difference').text(new_difference);
//display
$('#balance_display').text(numberWithCommas(new_balance));
$('#difference_display').text(numberWithCommas(new_difference));
});
// when a row:
// - is checked
// - if it has a credit value, opening balance increases by the credit amount
// - is then unchecked (if was previously checked)
// - if it has a credit value, opening balance reduces by the credit amount
$("[id^='credit_checkbox_']").on("change", function() {
var id = /\d+(?=\D*$)/.exec($(this).attr('id'));
var amount = $('#credit_amount_' + id).val();
var balance = $('#balance').text();
var new_balance = parseInt(balance);
if (this.checked) {
new_balance = parseInt(balance) + parseInt(amount);
$('#record_row_' + id).children('td, th').css('background-color', 'gold');
$('#unreconciled_checkbox_' + id).checked = false;
$('#unreconciled_checkbox_' + id).val('');
} else {
new_balance = parseInt(balance) - parseInt(amount);
$('#record_row_' + id).children('td, th').css('background-color', 'white');
$('#unreconciled_checkbox_' + id).checked = true;
$('#unreconciled_checkbox_' + id).val(id);
}
let new_difference = parseInt(<?php echo json_encode((int)$request->ending_balance_input); ?>) - new_balance;
$('#balance').text(new_balance);
$('#difference').text(new_difference);
//display
$('#balance_display').text(numberWithCommas(new_balance));
$('#difference_display').text(numberWithCommas(new_difference));
});
$('#reconciliation_date, #bank').change(function() {
let bank = $('#bank').val();
let reconciliation_date = $('#reconciliation_date').val();
let [dd, mm, yyyy] = reconciliation_date.split("-");
let formatted_reconciliation_date = `${yyyy}-${mm}-${dd}`;
if (bank !== '' && reconciliation_date !== '') {
$.ajax({
method: 'POST',
url: '/banking/get_last_reconciliation_balance',
data: {
'bank': bank,
'reconciliation_date': formatted_reconciliation_date
},
success: function(response) {
var record = JSON.parse(response);
if (record != null) {
$('#opening_balance').val(record);
// opening_balance
// if they had a reconciliation the previous month, opening_balance should pick that latest reconciliation balance
// else opening_balance must be the balance as of the end of the previous month
} else {
alert('No Opening Balance Registered As Of The Provided Date, Please Select Another Date.')
$('#reconciliation_date').val('');
}
},
error: function(error) {
console.log(error);
}
});
}
});
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
$('#reconciliation_date').datepicker({
autoclose: true,
todayHighlight: true,
format: 'dd-mm-yyyy'
});
$('#staff_member_cashier').select2({
placeholder: "-- select --"
});
$('#staff_member_accountant').select2({
placeholder: "-- select --"
});
</script>
@endpush