updated streamline-setup v2

This commit is contained in:
2025-01-15 08:53:49 -08:00
committed by alec.turner
parent a2ce9248f0
commit 4b569f81b0
20228 changed files with 2932048 additions and 63204 deletions
@@ -0,0 +1,309 @@
@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/tables/css/buttons.dataTables.min.css') }}" rel="stylesheet" type="text/css" />
@endpush
@section('content')
@php
$patient_id = "";
$episode_id = "";
$patient_category = "";
$items_amounts = "";
$items_ids = "";
$patient_amount = "";
$receipt_number = "";
$tag_id = "";
$invoice_generated ="";
$start_date = "";
$total = 0;
$end_date = "";
$invoice_date = "";
$invoice_number = "";
$created_by = "";
$created_at = "";
$reason ="";
$donor_id = "";
@endphp
<div class="row bg-title">
<div class="col-lg-3 col-md-4 col-sm-4 col-xs-12">
<h4 class="page-title">{{ __('invoices.view_donor_invoices') }}</h4>
</div>
<div class="col-lg-9 col-sm-8 col-md-8 col-xs-12">
<ol class="breadcrumb">
<li><a href="/invoices">{{ __('invoices.invoices_dashboard') }}</a></li>
<li class="active">{{ __('invoices.payments') }}</li>
</ol>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="panel panel-default col-md-10 offset-1">
<div class="panel-heading">
<div class="panel-title">
<h3><strong>{{ __('invoices.donor_invoices') }}</strong></h3>
</div>
</div>
<div class="panel-body panel-primary">
<div class="table-responsive">
<table id="table" class="table color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('invoices.donor') }}</th>
<th>{{ __('invoices.date_generated') }}</th>
<th>{{ __('invoices.for_period') }}</th>
<th>{{ __('invoices.amount') }}</th>
<th>{{ __('invoices.invoice_number') }}</th>
<th colspan="2"></th>
</tr>
</thead>
<tbody>
@if(count($uncleared_invoices) > 0)
@foreach($uncleared_invoices as $item)
@php
$sum_total = 0;
$total = 0;
@endphp
<tr>
<td>{{ get_name($item->donor_id, 'id', 'name', 'donors') }}</td>
<td>{{ streamline_date($item->created_at) }}</td>
<td>
@php
$dates = explode('/',$item->invoice_date);
@endphp
{{ streamline_date($dates[0])." to ".streamline_date($dates[1]) }}
</td>
<td>
{{ ugandan_shillings($item->sum) }}
</td>
<td>
{{ $item->invoice_number }}
</td>
<td>
{{ Form::open(['method'=>'post','route'=>'invoices.donor_invoice_payment' ]) }}
{{ Form::hidden('id', $item->id) }}
{{ Form::hidden('donor_id', $item->donor_id) }}
{{ Form::hidden('created_by', $item->created_by) }}
{{ Form::hidden('created_at', $item->created_at) }}
{{ Form::hidden('status', 'new') }}
{{ Form::hidden('total', $item->sum) }}
{{ Form::hidden('invoice_date', $item->invoice_date) }}
{{ Form::hidden('invoice_number', $item->invoice_number) }}
{{ Form::hidden('receipt_number',$item->receipt_number ) }}
<button id="update_payment" class="btn btn-success">{{ __('invoices.receive_payment') }}</button>
{{ Form::close() }}
</td>
<td>
<button id="print_invoice" class="btn btn-success">{{ __('invoices.print_invoice') }}</button>
</td>
</tr>
@php
$donor_id = $item->donor_id;
$patient_id = $item->patient_id;
$episode_id = $item->episode_id;
$patient_category = $item->patient_category;
$items_amounts = $sum_total;
$receipt_number = $item->receipt_number;
$invoice_generated = $item->invoice_generated;
$total = $item->sum;
$start_date = $dates[0];
$end_date = $dates[1];
$invoice_date = $item->invoice_date;
$invoice_number = (string)$item->invoice_number;
$created_by = $item->created_by;
$created_at = $item->updated_at;
@endphp
@endforeach
@else
<tr>
<td colspan="7">{{ __('invoices.no_records_found') }}</td>
</tr>
@endif
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-default col-md-10 offset-1">
<div class="panel-heading">
<div class="panel-title">
<h3><strong>{{ __('invoices.donor_invoices_with_balance') }}</strong></h3>
</div>
</div>
<div class="panel-body panel-primary">
<div class="table-responsive">
<table id="table" class="table color-bordered-table success-bordered-table">
<thead>
<tr>
<th>{{ __('invoices.patient_category') }}</th>
<th>{{ __('invoices.last_payment_date') }}</th>
<th>{{ __('invoices.total') }}</th>
<th>{{ __('invoices.amount') }}</th>
<th>{{ __('invoices.balance') }}</th>
<th>{{ __('invoices.invoice_number') }}</th>
<th colspan="3"></th>
</tr>
</thead>
@foreach($invoices_with_balance as $item)
@php
$sum_total = 0;
$total = 0;
@endphp
<tbody>
<tr>
<td>{{ get_name($item->donor_id, 'id', 'name', 'donors') }}</td>
<td>{{ streamline_date($item->created_at) }}</td>
<td>{{ ugandan_shillings($item->total) }}</td>
<td>{{ ugandan_shillings($item->amount_paid) }}</td>
<td>{{ ugandan_shillings($item->balance) }}</td>
<td>{{ $item->invoice_number }}</td>
<td>
{{ Form::open(['method'=>'post','route'=>'invoices.donor_invoice_payment' ]) }}
{{ Form::hidden('id', $item->id) }}
{{ Form::hidden('total', $item->total) }}
{{ Form::hidden('amount_paid', $item->amount_paid) }}
{{ Form::hidden('donor_id', $item->donor_id) }}
{{ Form::hidden('balance', $item->balance) }}
{{ Form::hidden('created_by', $item->created_by) }}
{{ Form::hidden('created_at', $item->created_at) }}
{{ Form::hidden('status', 'update') }}
{{ Form::hidden('invoice_date', $item->invoice_date) }}
{{ Form::hidden('invoice_number', $item->invoice_number) }}
{{ Form::hidden('receipt_number',$item->receipt_number ) }}
{{ Form::hidden('amount_paid_history', $item->amount_paid_history) }}
{{ Form::hidden('date_paid_history', $item->date_paid_history) }}
{{ Form::hidden('staff_incharge_history', $item->staff_incharge_history) }}
<button id="update_payment" class="btn btn-success">Receive Payment</button>
{{ Form::close() }}
</td>
<td>
{{ Form::open(['method'=>'post','route'=>'invoices.generate_donor_invoice' ]) }}
{{ Form::hidden('invoice_number', $item->invoice_number) }}
{{ Form::hidden('invoice_date', $item->invoice_date) }}
{{ Form::hidden('status', 'reprint') }}
<button id="update_payment" class="btn btn-success">{{ __('invoices.print_invoice') }}</button>
{{ Form::close() }}
</td>
<td>
{{ Form::open(['method'=>'post', 'route'=>'invoices.donor_payments_history' ]) }}
{{ Form::hidden('id', $item->id) }}
<button id="update_payment" class="btn btn-success">{{ __('invoices.payment_history') }}</button>
{{ Form::close() }}
</td>
</tr>
@endforeach
</tbody>
</table>
</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 type="text/javascript">
$('#receive_payment').click(function (e) {
e.preventDefault();
let amount = $('#amount').val();
$('#invoice_payment_modal').modal('show');
$('#amount_paid').change(function () {
let bal = amount - this.value;
$('#balance').val(bal);
})
});
$('#save_payment').click(function (e) {
let invoice_date = "<?php echo $invoice_date ?>";
let total = "<?php echo $total ?>";
let balance = $('#balance').val();
let donor_id = "<?php echo $donor_id ?>";
let invoice_number = "<?php echo $invoice_number ?>";
let patient_category = "<?php echo $patient_category ?>";
let generated_date = "<?php echo $created_at ?>";
let receipt_number = "<?php echo $receipt_number ?>";
let amount_paid = $('#amount_paid').val();
let staff_in_charge = "<?php echo Auth::id() ?>";
let payment_received_on = "<?php echo \Carbon\Carbon::now()->toDateTimeString() ?>";
let data = {
'invoice_date':invoice_date,
'total': total,
'balance':balance,
'donor_id': donor_id,
'invoice_number':invoice_number,
'patient_category' :patient_category,
'generated_date' :generated_date,
'receipt_number' :receipt_number,
'amount_paid' :amount_paid,
'staff_in_charge' :staff_in_charge,
'payment_received_on' :payment_received_on,
};
$.ajax({
method: 'POST',
url: '/invoices/process_donor_payment',
data: data,
success: function (response) {
// if(parseInt(response) === 1){
$('#invoice_payment_modal').modal('hide');
//console.log(JSON.stringify(data));
location.reload();
alert('Payment has Successfully been made.');
},
error: function (response) {
$('#invoice_payment_modal').modal('show');
console.log(JSON.stringify(data));
alert('payment not made, try again.');
}
// location.reload();
})
});
</script>
<script type="text/javascript">
jQuery('#end_date').datepicker({
autoclose: true,
todayHighlight: true,
format: 'dd-mm-yyyy'
});
</script>
<script type="text/javascript">
jQuery('#start_date').datepicker({
autoclose: true,
todayHighlight: true,
format: 'dd-mm-yyyy'
});
</script>
@endpush
@@ -0,0 +1,635 @@
@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" />
@endpush
@section('content')
<div class="row bg-title">
<div class="col-md-6">
<h4 class="page-title">{{ __('finance.patient_category_invoices') }}</h4>
</div>
<div class="col-md-6">
<ol class="breadcrumb">
<li><a href="{{ route('home') }}"><i class="fa fa-home"></i> {{ __('finance.home') }}</a></li>
<li><a href="{{ route('finance') }}"><i class="fa fa-money"></i> {{ __('finance.finance_home') }}</a></li>
<li><a href="{{ route('invoices') }}"><i class="fa fa-file"></i> {{ __('finance.invoices_home') }}</a></li>
<li class="active">{{ __('finance.payments') }}</li>
</ol>
</div>
</div>
{{ Form::open(['route' => 'invoices.receive_patient_invoices' , 'data-toggle' => 'validator']) }}
<div class="white-box">
<div class="row">
<div class="col-md-3">
<div class="form-group" id="lab_numbers">
{{ Form::label('patient_category',__('finance.patient_category')) }}
<select class="form-control required" name="patient_category" id="patient_category" required>
<option value="">{{ __('finance.select') }}</option>
<option value="0">{{ __('invoices.all_patient_categories') }}</option>
@foreach($patient_categories as $id)
<option value="{{ $id }}">{{ get_name($id, 'id', 'name', 'patient_categories') }}</option>
@endforeach
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
{{ Form::label('start_date', __('invoices.from')) }}
{{ Form::text('start_date','',['class' => 'form-control', 'readonly','id'=>'start_date']) }}
</div>
</div>
<div class="col-md-3">
<div class="form-group">
{{ Form::label('end_date', __('invoices.to')) }}
{{ Form::text('end_date','',['class' => 'form-control', 'readonly','id'=>'end_date']) }}
</div>
</div>
<div class="col-md-3">
<br>
{{ Form::button(__('invoices.search'),['type'=>'submit','class'=>'btn btn-rounded btn-success waves-effect waves-light m-r-10 btn-block', 'style'=>'margin-top: 5px;']) }}
</div>
</div>
</div>
{{ Form::close() }}
<div class="white-box">
@include('flash::message')
@php
$total_amount_to_pay = 0;
$balance_to_pay = 0;
$total_amount_paid = 0;
$payments_sum_total = 0;
$payments_balances = 0;
$payments_amount_paid = 0;
$back_date = \Streamline\Models\HospitalInformation::first()->pluck('back_date');
@endphp
<h3>{{ __('invoices.patient_category') }}: {{ $searched_patient_category }} Date: {{ __('invoices.from') }} {{ streamline_date($start_date) }} {{ __('invoices.to') }} {{ streamline_date($end_date) }}</h3>
<div class="table-responsive">
<table id="invoice_table" class="table color-bordered-table success-bordered-table">
<thead>
<tr>
<th class="show_checkboxes" style="display: none;"></th>
<th>{{ __('finance.patient_category') }}</th>
<th>{{ __('finance.date_generated') }}</th>
<th>{{ __('finance.for_period') }}</th>
<th>{{ __('invoices.amount_to_pay') }}</th>
<th>{{ __('invoices.amount_paid') }}</th>
<th>{{ __('invoices.balance') }}</th>
<th>{{ __('finance.invoice_number') }}</th>
<th>{{ __('finance.action') }}</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
@if(count($invoices) > 0)
@foreach($invoices as $item)
<tr id="invoice_number_{{ $item['invoice_number'] }}">
<td class="show_checkboxes" style="display: none;">
<input id='checkbox_{{ $item['invoice_number'] }}' type='checkbox'/>
</td>
<td>{{ get_name($item['patient_category'], 'id', 'name', 'patient_categories') }}</td>
<input type="hidden" id="invoice_number_patient_category_{{ $item['invoice_number'] }}" value="{{$item['patient_category']}}"/>
<td>
@if(!is_null($item['updated_at']))
{{ streamline_date($item['updated_at']) }}
@else
{{ streamline_date($item['created_at']) }}
@endif
</td>
<td>
@php
$dates = explode('/',$item['invoice_date']);
@endphp
{{ ($dates[0] ?? "")." to ".($dates[1] ?? "") }}
</td>
<td>
@php $total_amount_to_pay += $item['patient_amount']; @endphp
{{ ugandan_shillings($item['patient_amount']) }}
</td>
<td>
@php $total_amount_paid += $item['amount_paid']; @endphp
{{ ugandan_shillings($item['amount_paid']) }}
</td>
<td>
@if($item['has_payment'] == 1)
@php
$balance_to_pay += $item['patient_amount'] - $item['amount_paid'];
@endphp
{{ ugandan_shillings($item['patient_amount'] - $item['amount_paid']) }}
<input type='hidden' value='{{ $item['patient_amount'] - $item['amount_paid'] }}' id='invoice_balance_{{ $item['invoice_number'] }}' />
@else
@php $balance_to_pay += $item['patient_amount']; @endphp
{{--N/A--}}
{{ ugandan_shillings($item['patient_amount']) }}
<input type='hidden' value='{{ $item['patient_amount'] }}' id='invoice_balance_{{ $item['invoice_number'] }}' />
@endif
</td>
<td>
{{ $item['invoice_number'] }}
</td>
<td>
@if($item['has_payment'] == 1)
{{ Form::open(['method'=>'post','route'=>'invoices.patient_invoice_payment' ]) }}
{{ Form::hidden('total', $item['patient_amount']) }}
{{ Form::hidden('amount_paid', $item['amount_paid']) }}
{{ Form::hidden('patient_category', $item['patient_category']) }}
{{ Form::hidden('balance', $item['balance']) }}
{{ Form::hidden('status', 'update') }}
{{ Form::hidden('invoice_date', $item['invoice_date']) }}
{{ Form::hidden('invoice_number', $item['invoice_number']) }}
{{ Form::hidden('generated_on', $item['updated_at']) }}
<button id="update_payment" class="btn btn-success btn-sm">{{ __('finance.update_payment') }}</button>
{{ Form::close() }}
@else
{{ Form::open(['method'=>'post','route'=>'invoices.patient_invoice_payment' ]) }}
{{ Form::hidden('patient_category', $item['patient_category']) }}
{{ Form::hidden('status', 'new') }}
{{ Form::hidden('total', $item['patient_amount']) }}
{{ Form::hidden('amount_paid', 0) }}
{{ Form::hidden('balance', $item['patient_amount']) }}
{{ Form::hidden('invoice_date', $item['invoice_date']) }}
{{ Form::hidden('invoice_number', $item['invoice_number']) }}
{{ Form::hidden('generated_on', $item['updated_at']) }}
<button class="btn btn-success btn-sm">{{ __('finance.receive_payment') }}</button>
{{ Form::close() }}
@endif
</td>
<td>
{{ Form::open(['method'=>'post','route'=>'invoices.generate_invoice' ]) }}
{{ Form::hidden('invoice_number', $item['invoice_number']) }}
{{ Form::hidden('invoice_date', $item['invoice_date']) }}
{{ Form::hidden('patient_category', $item['patient_category']) }}
{{ Form::hidden('status', 'reprint') }}
<button id="update_payment" class="btn btn-success btn-sm">{{ __('finance.print_invoice') }}</button>
{{ Form::close() }}
</td>
<td>
@if($item['has_payment'] == 1)
{{ Form::open(['method'=>'post', 'route'=>'invoices.patient_payments_history' ]) }}
{{ Form::hidden('invoice_number', $item['invoice_number']) }}
<button id="update_payment" class="btn btn-success btn-sm">{{ __('finance.payment_history') }}</button>
{{ Form::close() }}
@endif
</td>
<td>
@if($item['has_payment'] != 1)
<a role="button" class="btn btn-danger btn-sm" style="color: white" href="{{ route('invoices.delete', $item['invoice_number']) }}"><i class="fa fa-trash"></i></a>
@endif
</td>
</tr>
@endforeach
@if(count($payments) > 0)
@foreach($payments as $item)
<tr id="invoice_number_{{ $item->invoice_number }}">
<td class="show_checkboxes" style="display: none;">
<input id='checkbox_{{ $item->invoice_number }}' type='checkbox'/>
</td>
<td>{{ get_name($item->patient_category, 'id', 'name', 'patient_categories') }}</td>
<input type="hidden" id="invoice_number_patient_category_{{ $item->invoice_number }}" value="{{$item->patient_category}}"/>
<td>{{ streamline_date(get_name($item->invoice_number, 'invoice_number', 'updated_at', 'patient_category_invoices')) }}</td>
<td>
@php
$payments_sum_total += $item->total;
$dates = explode('/', $item->invoice_date);
echo streamline_date($dates[0]). " to " .streamline_date($dates[0]);
$amount_paid = $item->amount_paid;
$payments_amount_paid += $amount_paid;
@endphp
</td>
<td>{{ ugandan_shillings($item->total) }}</td>
<td>{{ ugandan_shillings($amount_paid) }}</td>
<td>
{{ ugandan_shillings($item->balance) }}
<input type='hidden' value='{{ $item->balance }}' id='invoice_balance_{{ $item->invoice_number }}' />
</td>
@php $payments_balances += $item->balance; @endphp
<td>{{ $item->invoice_number }}</td>
<td>
</td>
<td>
{{ Form::open(['method'=>'post','route'=>'invoices.generate_invoice' ]) }}
{{ Form::hidden('invoice_number', $item->invoice_number) }}
{{ Form::hidden('invoice_date', $item->invoice_date) }}
{{ Form::hidden('patient_category', $item->patient_category) }}
{{ Form::hidden('status', 'reprint') }}
<button id="update_payment" class="btn btn-success btn-sm">{{ __('invoices.print_invoice') }}</button>
{{ Form::close() }}
</td>
<td>
{{ Form::open(['method'=>'post', 'route'=>'invoices.patient_payments_history' ]) }}
{{ Form::hidden('invoice_number', $item->invoice_number) }}
<button class="btn btn-success btn-sm">{{ __('invoices.payment_history') }}</button>
{{ Form::close() }}
</td>
<td></td>
</tr>
@endforeach
@endif
@else
<tr>
<td colspan="10">{{ __('finance.no_records_available') }}</td>
</tr>
@endif
</tbody>
</table>
</div>
<br><br>
<div class="table-responsive">
<table class="table table-bordered table-striped">
<tbody>
<tr>
<td><b>{{ __('invoices.total_amount_to_pay') }}</b></td>
<td>{{ ugandan_shillings($total_amount_to_pay + $payments_sum_total) }}</td>
</tr>
<tr>
<td><b>{{ __('invoices.total_amount_paid') }}</b></td>
<td>{{ ugandan_shillings($total_amount_paid + $payments_amount_paid) }}</td>
</tr>
<tr>
<td><b>{{ __('invoices.balance_left_to_pay') }}</b></td>
<td>{{ ugandan_shillings($balance_to_pay + $payments_balances) }}</td>
</tr>
</tbody>
</table>
</div>
@if(Auth::user()->can('make-bulk-invoice-payments'))
<hr>
<button class="btn btn-warning btn-rounded" onclick="show_bulk_pay_div()">{{ __('payments.perform_bulk_payment') }}</button>
<br>
@endif
<div id="bulk_pay_div" style="display: none; border:3px solid rgb(148, 146, 146); padding: 5px;">
{{ Form::open(['method'=>'post', 'route'=>'payments.invoices_bulk_pay', 'id'=>'invoice_bulk_pay_form'])}}
<div class='row'>
<div class="col-md-2">
<div class="form-group">
{{ Form::label('amount_to_pay', __('payments.amount_to_be_paid')) }}
{{ Form::number('amount_to_pay', 0, ['class'=>'form-control compulsory', 'required', 'id'=>'bulk_amount_to_pay']) }}
</div>
</div>
<div class="col-md-2">
<div class="form-group">
{{ Form::label('payment_received_on_label', __('finance.payment_received_on')) }}
<div class="input-group">
{{ Form::text('payment_date', \Carbon\Carbon::today()->format('d-m-Y'), ['class'=>'form-control','required','autocomplete'=>'off', 'id'=>'bulk_payment_date']) }}
</div>
</div>
</div>
<div class="col-md-2">
<div id="payment_methods_div">
<div class="form-group">
{{ Form::label('cash_to_pay',__('patient_finance.cash_to_pay')) }}
{{ Form::number('cash_to_pay',0,['class' => 'form-control','id'=>'cash_to_pay','readonly']) }}
</div>
<label class="label label-primary" onclick="add_payment_method();">{{ __('patient_finance.add_payment_method') }}</label>
<br><br>
</div>
</div>
<input type="hidden" name="selected_invoice_numbers" id="selected_invoice_numbers">
<input type="hidden" name="total_amount_paid_off" value="0" id="total_amount_paid_off">
<div class="col-md-4">
<div class="form-group">
<label>{{ __('invoices.do_you_want_receive_bank') }}</label>
<br>
{{ Form::radio('receive_to_bank', 1, false, ['onclick' => 'show_banking_details(1)']) }} Yes &nbsp;&nbsp;
{{ Form::radio('receive_to_bank', 0, true, ['onclick' => 'show_banking_details(0)']) }} No
</div>
<div id="banking_div" style="display: none;">
<div class="form-group">
{{ Form::label('bank', __('invoices.bank')) }}
{{ Form::select('bank', $banks, '', ['class'=>'form-control', 'id'=>'bulk_bank_account']) }}
</div>
<div class="form-group">
{{ Form::label('bank_balance', __('invoices.bank_balance')) }}
<div class="input-group">
{{ Form::text('bank_balance', '', ['class'=>'form-control','readonly', 'id'=>'bank_balance']) }}
{{ Form::hidden('undeposited_funds_bank_balance', '', ['id'=>'undeposited_funds_bank_balance']) }}
</div>
</div>
<div class="form-group">
{{ Form::label('memo',__('invoices.memo')) }}
{{ Form::textarea('memo', '',['class' => 'form-control compulsory banking_memo']) }}
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<button class='btn btn-success btn-rounded btn-block pull-right' id="validate_bulk_pay">{{ __('payments.make_bulk_payment') }}</button>
</div>
</div>
<div class="col-md-4">
<div id="amounts_per_invoice_div">
<h4 id="bulk_title" style="font-weight: bolder; color: blue;"></h4>
</div>
</div>
<div class="col-md-8"></div>
</div>
{{ Form::close() }}
</div>
</div>
{{-- bulk payment message modal --}}
<div class="modal fade" id="bulkPaymentMessage" tabindex="-1" role="dialog" aria-labelledby="bulkPaymentMessageTitle" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" style="margin-top: 50px;">
<div class="modal-header">
<span class="label label-info">Please note:</span>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
<div class="row" style="padding: 10px;">
<div class="col-sm-12">
<h3>Please Be Sure To Select The Invoices That You Wish To Clear</h3>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" data-dismiss="modal" id="confirmsToSelect">{{ __('payments.ok') }}</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">{{ __('payments.cancel') }}</button>
</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/datatables/jquery.dataTables.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>
$('#uncleared_invoice_table').DataTable({
dom: 'Bfrtip',
pageLength: 100,
buttons: [
'copy', 'csv', 'excel',
],
"aoColumnDefs": [{
"aTargets": [2,3],
"defaultContent": "",
}]
});
let min_days = <?php echo $back_date[0]; ?>;
var min_date = new Date();
min_date.setDate(min_date.getDate()-min_days);
$('#start_date,#end_date').datepicker({
autoclose: true,
todayHighlight: true,
format: 'dd-mm-yyyy'
});
$('#bulk_payment_date').datepicker({
autoclose: true,
todayHighlight: true,
endDate: new Date(),
startDate: min_date,
format: 'dd-mm-yyyy'
});
$('#invoice_table').DataTable({
dom: 'Bfrtip',
pageLength: 100,
buttons: [
'csv', 'excel',
],
"aoColumnDefs": [{
"aTargets": [2,3],
"defaultContent": "",
}]
});
$('#receive_payment').click(function (e) {
e.preventDefault();
let amount = $('#amount').val();
$('#invoice_payment_modal').modal('show');
$('#amount_paid').change(function () {
let bal = amount - this.value;
$('#balance').val(bal);
})
});
$('#confirmsToSelect').click(function (e){
$('#bulk_pay_div').show();
$('.show_checkboxes').show();
});
function show_bulk_pay_div() {
$('#bulkPaymentMessage').modal('show');
}
var ticked_off_invoices_array = [];
var ticked_off_patient_categories_array = [];
$('#bulk_bank_account').on('change', function() {
var transfer_to = $('#bulk_bank_account').val();
var transfer_from = '10';
var transfer_date = $('#payment_received_on').val();
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); // January is 0!
var yyyy = today.getFullYear();
var today_formatted = dd + '-' + mm + '-' + yyyy;
$.ajax({
method: 'POST',
url: '/banking/get_latest_bank_balance',
data: {
'to': transfer_to,
'from': transfer_from,
'date': today_formatted, // transfer_date,
},
success: function(response) {
$('#bank_balance').val(parseInt(response[0]));
$('#undeposited_funds_bank_balance').val(parseInt(response[1]));
},
error: function(error) {
console.log(error);
}
});
});
$('#validate_bulk_pay').click(function(e) {
e.preventDefault();
let payment_date = $('#bulk_payment_date').val();
let bank_account = $('#bulk_bank_account').val();
let account_balance = $('#bulk_account_balance').val();
let amount_to_pay = $('#bulk_amount_to_pay').val();
let receive_money_directly = $('input[name="receive_to_bank"]:checked').val();
if (payment_date === "") {
alert('Please Select A Payment Date.')
} else if (bank_account === "" && receive_money_directly == 1) {
alert('Please Select A Bank Account.')
} else {
if (ticked_off_invoices_array.length !== 0) {
if (confirm("Are you sure ?")) {
$('#invoice_bulk_pay_form').submit();
}
} else {
alert('Please Select The Invoices That You Wish To Pay Off Fully Or Partially')
}
}
});
$("[id^='checkbox_']").on("change", function() {
var id = /\d+(?=\D*$)/.exec($(this).attr('id'));
let amount_to_pay = $('#bulk_amount_to_pay').val();
let invoice_balance = $('#invoice_balance_' + id).val();
let amount_paid_off = $('#amount_paid_off_' + id).val();
let total_amount_paid_off = $('#total_amount_paid_off').val();
let new_amount_to_pay = parseInt(amount_to_pay) + parseInt(invoice_balance);
let new_total_amount_paid_off = parseInt(total_amount_paid_off) + parseFloat(amount_paid_off);
if (this.checked) {
$('#invoice_number_' + id).children('td, th').css('background-color', 'gold');
$('#bulk_amount_to_pay').val(new_amount_to_pay);
ticked_off_invoices_array.push(id[0]);
let invoice_patient_category = $('#invoice_number_patient_category_'+id[0]).val();
ticked_off_patient_categories_array.push(invoice_patient_category);
//add the invoice to the dynamic to pay invoices DOM
add_invoice_to_dom(id[0], invoice_patient_category);
} else {
$('#invoice_number_' + id).children('td, th').css('background-color', 'white');
$('#bulk_amount_to_pay').val(parseInt(amount_to_pay) - parseInt(invoice_balance));
const index = ticked_off_invoices_array.indexOf(id);
ticked_off_invoices_array.splice(index, 1);
ticked_off_patient_categories_array.splice(index, 1);
//remove the invoice from dynamic to pay invoices DOM
//console.log("invoice to remove "+id);
remove_invoice_from_dom(id);
}
$('#selected_invoice_numbers').val(ticked_off_invoices_array);
total_balances_for_invoices = calculate_invoice_balances(ticked_off_invoices_array);
//console.log("total balances for ticked invoices === "+total_balances_for_invoices);
$('#cash_to_pay').val(total_balances_for_invoices);
$('#bulk_title').text("Selected invoices to be cleared");
});
$('#amounts_per_invoice_div').on('change','.bulk_invoice_amount_to_pay', function() {
let recalculated_total = 0;
$('.bulk_invoice_amount_to_pay').each(function () {
recalculated_total += +$(this).val();
});
//reculate amount to be paid after editing the amounts for each invoice to be paid
//console.log('the recalculated total after editing amount to pay on each invoice = '+recalculated_total);
$('#bulk_amount_to_pay').val(recalculated_total);
});
function calculate_invoice_balances(ticked_off_invoices_array){
//loop through all the ticked invoice array arrays
let total_balances_to_clear = 0;
//console.log(ticked_off_invoices_array);
console.log(ticked_off_patient_categories_array);
for(let i=0; i<ticked_off_invoices_array.length; i++) {
let invoice_number = ticked_off_invoices_array[i];
invoice_balance = $('#invoice_balance_' + invoice_number).val();
//console.log("single invoice balance == "+invoice_balance);
total_balances_to_clear += parseInt(invoice_balance);
}
return total_balances_to_clear;
}
function add_payment_method() {
$('#cash_to_pay_div').show();
$('#payment_methods_div').append('<div class="row"><div class="col-md-6"><label>Method</label><select class="form-control payment_method" name="payment_method[]"><option value="0">--select method--</option><?php echo $patient_payment_methods_options ?></select></div><div class="col-md-6"><label>Amount</label><input name="payment_methods_amount[]" type="number" class="form-control payment_methods_amount" onkeyup="payment_methods_amount_calculate()"></div></div><br>');
}
function show_banking_details(choice) {
if (choice === 1) {
$('#banking_div').show();
$('.banking_memo').prop('required', true);
$('#bulk_bank_account').prop('required', true);
} else {
$('#banking_div').hide();
$('.banking_memo').removeAttr('required');
$('#bulk_bank_account').removeAttr('required');
}
}
function payment_methods_amount_calculate() {
// tally up all the entered values
let total_amount_payment_methods = 0;
$('.payment_methods_amount').each(function () {
total_amount_payment_methods += +$(this).val();
});
let amount_to_pay = $('#bulk_amount_to_pay').val();
let cash_to_pay = amount_to_pay;
cash_to_pay -= total_amount_payment_methods;
if (cash_to_pay < 0) {
alert("You have entered more money in the payment methods than is supposed to be paid");
$('.payment_methods_amount').each(function () {
$(this).val(0);
});
$('#cash_to_pay').val(amount_to_pay);
} else {
$('#cash_to_pay').val(cash_to_pay);
}
}
function add_invoice_to_dom(invoice_number, invoice_patient_category) {
invoice_balance = $('#invoice_balance_' + invoice_number).val();
$('#amounts_per_invoice_div').append('<div class="row" id="bulk_row_'+invoice_number+'"><div class="col-md-6"><label>Invoice Number</label><input name="bulk_invoices[]" type="text" value="'+invoice_number+'" class="form-control bulk_invoices" readonly><input type="hidden" value="'+invoice_patient_category+'" name="bulk_patient_category[]"/></div><div class="col-md-6"><label>Invoice Amount To Be Paid</label><input name="bulk_invoice_amount_to_pay[]" type="number" class="form-control bulk_invoice_amount_to_pay" value="'+invoice_balance+'"></div></div><br>');
}
function remove_invoice_from_dom(invoice_number){
$('#bulk_row_'+invoice_number).remove();
}
/* $('#show_alert').click(function(e) {
e.preventDefault();
$('#banking_div').show();
$('#dismiss_alert').hide();
}); */
</script>
@endpush