nhance/app/Views/view_deposit.php

569 lines
26 KiB
PHP
Executable File

<style>
.table th,
.table td {
padding: 8px;
}
table.dataTable tbody td {
padding: 4px 4px !important;
}
.deposit-header {
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
}
.deposit-summary-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
.metrics{
border:1px solid lightgrey;
border-radius:10px;
box-shadow: 0px 4px 4px 0px #00000040;
width: 100%;
max-width: 100%;
padding: 12px;
min-height: 64px;
}
.dataTables_length label {height: 21px !important;}
#scroll-horizontal-datatable tbody tr:hover { background-color: #e0e0e0; }
@media (max-width: 767.98px) {
.deposit-title {
font-size: 22px;
}
.deposit-account-title,
.deposit-summary-title {
font-size: 18px;
margin-bottom: 0;
}
}
</style>
<?php
$depositNavTitle = 'Transaction Details - ' . (isset($insurerName->name) ? $insurerName->name : '');
$depositBackUrl = base_url('client/deposit/' . (isset($clientData->id) ? $clientData->id : ''));
?>
<script>
var pageHideMainNavTitle = true;
var pageTitle = <?= json_encode($depositNavTitle, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE) ?>;
var pageBackButton = '<a href="<?= esc($depositBackUrl, 'attr') ?>" class="topbar-icon-btn" data-toggle="tooltip" data-placement="top" title="Back" aria-label="Back"><i class="ri-arrow-left-s-line"></i></a>';
</script>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="deposit-summary-row">
<div><h4 class="deposit-account-title">CD Account No : <?php echo isset($insurerName->cd_master_account_no) && !empty($insurerName->cd_master_account_no) ? $insurerName->cd_master_account_no : 'N/A' ?></h4></div>
<div><h4 class="deposit-summary-title">Deposit Summary Of <?php echo $clientData->short_name?></h4></div>
</div>
<div>
<div class="row text-center">
<div class="col-12 col-sm-6 col-lg-3 mt-2">
<div class="d-flex justify-content-between align-items-center metrics">
<span class="text-muted font-15 mb-1 text-truncate">Deposits</span>
<h4 style="font-size: 18px;display:inline;"><i
class="fe-arrow-up text-success mr-1" ></i>₹<?php echo $deposiamount->total_credit?>
</h4>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mt-2">
<div class="d-flex justify-content-between align-items-center metrics">
<span class="text-muted font-15 mb-1 text-truncate">Consumed</span>
<h4 style="font-size: 20px;display:inline;"><i
class="fe-arrow-down text-danger mr-1"></i>₹<?php echo $deposiamount->total_withdraw?>
</h4>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mt-2">
<div class="d-flex justify-content-between align-items-center metrics">
<span class="text-muted font-15 mb-1 text-truncate">Refund</span>
<h4 style="font-size: 20px;display:inline;"><i
class="fe-arrow-up text-success mr-1"></i>₹<?php echo $deposiamount->total_refund?>
</h4>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mt-2">
<div class="d-flex justify-content-between align-items-center metrics">
<span class="text-muted font-15 mb-1 text-truncate">Current Balance</span>
<h4 style="font-size: 20px;display:inline;"><i
class="fe-credit-card text-success mr-1"></i>₹<?php echo $deposiamount->balance?>
</h4>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row" id="List-page">
<div class="col-12">
<div class="card">
<div class="card-body">
<!-- <div class="row" style="margin-bottom:1rem;">
<div class="col-6" style="text-align: right; position: relative;top: 56px; z-index:999">
<button type="button" id="btnAdd" class="btn btn-primary waves-effect waves-light" data-toggle="modal" data-target="#addTransactionModal"> + Add</button>
</div>
</div> -->
<div class="table-responsive">
<table data-custom-table-css="table" class="table mb-0 nowrap w-100 table-centered" cellspacing="0" id="scroll-horizontal-datatable">
<thead class="bg-light">
<tr>
<th class="font-weight-medium">Date</th>
<th class="font-weight-medium">Record Date</th>
<th class="font-weight-medium">Unit</th>
<th class="font-weight-medium">Policy</th>
<th class="font-weight-medium">Endorsement No</th>
<th class="font-weight-medium">Sub Type</th>
<th class="font-weight-medium">Credit</th>
<th class="font-weight-medium">Debit</th>
<th class="font-weight-medium">Balance</th>
<th class="font-weight-medium">Description</th>
<th class="font-weight-medium">User</th>
</tr>
</thead>
<tbody>
<?php foreach($depositdata as $row) { ?>
<tr id="<?php echo $row->id;?>">
<td><?php echo date('d-M-Y h:i A', strtotime($row->created_at)); ?></td>
<td><?php echo isset($row->record_date)? date('d-M-Y', strtotime($row->record_date)):'-' ?></td>
<td><?php echo $row->unit ?? ' - '; ?></td>
<!-- <td><?php echo $row->policy_name ?? '<center> - </center>'; ?></td> -->
<td>
<?php
$policyType = $row->policy_type ?? '';
$policyNo = $row->policy_no ?? '';
if ($policyType || $policyNo) {
echo trim($policyType . ' - ' . $policyNo, ' -');
} else {
echo '<center> - </center>';
}
?>
</td>
<td><?php echo $row->endorsement_no ?? '<center> - </center>'; ?></td>
<td><?php echo isset($subTypeOptions[$row->sub_type]) ? $subTypeOptions[$row->sub_type] : ''; ?>
</td>
<td><?php echo ($row->transaction_type == 'Credit') ? $row->amount : '-'; ?></td>
<td><?php echo ($row->transaction_type == 'Debit') ? $row->amount : '-'; ?></td>
<td><?php echo $row->balance; ?></td>
<td><?php echo $row->description; ?></td>
<td><?php echo $row->username; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- end col -->
</div>
</div>
<!-- Add this modal markup at the end of your HTML body -->
<!-- Button to trigger modal -->
<!-- Add this modal markup at the end of your HTML body -->
<div class="modal fade" id="addTransactionModal" tabindex="-1" role="dialog" aria-labelledby="addTransactionModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addTransactionModalLabel">Add Transaction</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<h3>Transaction Mode</h3>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="form-check mt-2">
<input class="form-check-input" type="radio" name="transactionMode" id="addMode"value="1" checked>
<label class="form-check-label" for="addMode">Replenishment by Client</label>
</div>
<div class="form-check mt-2">
<input class="form-check-input" type="radio" name="transactionMode" id="refund_by_insurer"value="6">
<label class="form-check-label" for="addMode">Refund by Insurer</label>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<div class="form-check mt-2">
<input class="form-check-input" type="radio" name="transactionMode" id="assetpolicyadd"value="4">
<label class="form-check-label" for="adjustmentMode">Non EB Credit</label>
</div>
<div class="form-check mt-2">
<input class="form-check-input" type="radio" name="transactionMode" id="assetpolicyreduce"value="5">
<label class="form-check-label" for="adjustmentMode">No EB Debit</label>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="field-1" class="control-label">Amount<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="amount" placeholder="Amount" required
inputmode="decimal" maxlength="12"
data-parsley-pattern="^[0-9]+(\\.[0-9]{1,2})?$"
data-parsley-pattern-message="Amount must be a valid number."
data-parsley-required-message="Amount field is required.">
<div id="amount_error" class="text-danger small mt-1" style="display:none;"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="record_date">Record Date <span class="text-danger"></span></label>
<input type="text" class="form-control policy_start_date" id="record_date" name="record_date" placeholder="Record Date">
</div>
</div>
</div>
<!-- <div class="row" id="transactionTypeRow" style="display:none;">
<div class="col-md-6">
<div class="form-group">
<label for="transactionType" class="control-label">Transaction Type</label>
<select class="form-control" id="transactionType">
<option value="Credit">Add</option>
<option value="Debit">Reduce</option>
</select>
</div>
</div>
</div> -->
<div class="row">
<div class="col-md-12">
<div class="form-group no-margin">
<label for="description" class="control-label">Description<span class="text-danger">*</span></label>
<textarea class="form-control" id="description"
placeholder="Write something about the transaction" required></textarea>
<input type="hidden" id="cd_ac_pk" value="<?php echo $depositdata[0]->cd_ac_pk?>">
<input type="hidden" id="cd_ac_no" value="<?php echo $depositdata[0]->cd_ac_no?>">
</div>
</div>
</div>
<!-- <div class="form-group">
<label for="subType" class="control-label" style="display: none;">Transaction Sub Type</label>
<select class="form-control" id="subType" name="sub_type" style="display: none;">
<option value="Deposit" hidden>Replenishment</option>
<option value="Adjustment" hidden>Adjustment</option>
</select>
</div> -->
<div class="modal-footer">
<button type="button" class="btn cancel-btn" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary submit-btn" id="saveTransactionBtn">Submit</button>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('input[name="transactionMode"]').change(function() {
if ($(this).val() === 'adjustment') {
$('#transactionTypeRow').show();
} else {
$('#transactionTypeRow').hide();
}
});
});
</script>
<script>
$(document).ready(function() {
var record_date = flatpickr("#record_date", {
dateFormat: "d/m/Y",
allowInput: false,
});
$('#scroll-horizontal-datatable').DataTable({
scrollX: true,
// dom: "<'row'<'col-sm-2'f><'col-sm-10 text-right'B>>" +
// "<'row'<'col-sm-12'tr>>" +
// "<'row'<'col-sm-5'i><'col-sm-7'p>>",
// buttons: [
// {
// text: '+ add',
// className: 'btn btn-primary buttons-html5',
// action: function () {
// var myModal = new bootstrap.Modal(document.getElementById('addTransactionModal'));
// myModal.show();
// }
// }
// ,
// {
// extend: 'csv',
// text: 'CSV',
// title: 'CD TransactionDetails',
// exportOptions: {
// columns: ''
// }
// },
// {
// extend: 'pdf',
// text: 'PDF',
// title: 'TransactionDetails',
// exportOptions: {
// columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
// format: {
// body: function (data, row, column, node) {
// return data.replace(/<.*?>/g, '');
// }
// }
// },
// customize: function (doc) {
// doc.pageOrientation = 'landscape';
// doc.styles.tableHeader.alignment = 'left';
// doc.defaultStyle.alignment = 'left';
// doc.content[1].table.widths = [
// '9%', '9%', '8%', '9%', '10%',
// '9%', '9%', '9%', '9%', '11%', '8%'
// ];
// }
// }
// ],
dom: "<'row'<'col-sm-6'f><'col-sm-6 text-right'B>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
buttons: [
{
text: '<i class="mdi mdi-plus" ></i><span class=" btn-custom"> Add </span>',
className: 'btn app-btn-primary mr-2',
action: function () {
var myModal = new bootstrap.Modal(document.getElementById('addTransactionModal'));
myModal.show();
}
},
{
extend: 'collection',
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
className: 'btn app-btn-secondary ',
buttons: [
{
extend: 'csv',
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
title: 'CD TransactionDetails',
exportOptions: { columns: '' },
className: 'app-btn-primary ',
},
{
extend: 'excel',
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
title: 'CD TransactionDetails',
sheetName: 'CD TransactionDetails',
exportOptions: {
orthogonal: 'sort'
}
}
]
}
],
language: {
search: `
<div class="datatable-search-wrapper" style="position:relative; display:inline-block;">
_INPUT_
<i class="mdi mdi-magnify datatable-search-icon"
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666;"></i>
<i class="mdi mdi-close-circle datatable-clear-icon"
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666; display:none;"></i>
</div>`,
searchPlaceholder: "Search",
emptyTable: '<div class="text-center text-muted">No Data found</div>'
},
ordering: false,
paging: true
});
});
</script>
<script>
$(document).ready(function() {
// // Event listener for radio buttons
// $('input[name="transactionMode"]').change(function() {
// if ($(this).val() === 'add') {
// // Set the hidden input value to 'Deposit' when 'Deposit' radio button is selected
// $('#subType').val('Deposit');
// } else if ($(this).val() === 'adjustment') {
// // Set the hidden input value to 'Adjustment' when 'Adjustment' radio button is selected
// $('#subType').val('Adjustment');
// }
// });
$('#saveTransactionBtn').on('click', function() {
var amount = $('#amount').val();
var description = $('#description').val();
var clientId = '<?php echo $clientData->id; ?>';
var insurerId = '<?php echo $insurerName->id; ?>';
var transactionTypeValue = $('input[name="transactionMode"]:checked').val();
var subType = "";
var record_date = $('#record_date').val();
var cd_ac_no = $('#cd_ac_no').val();
var cd_ac_pk = $('#cd_ac_pk').val();
amount = (amount || '').trim();
var amountRegex = /^[0-9]+(\.[0-9]{1,2})?$/;
if (amount === "") {
$('#amount_error').text('Amount field is required.').show();
$('#amount').addClass('is-invalid');
toastr.warning('Amount field is required');
return;
}
if (!amountRegex.test(amount)) {
$('#amount_error').text('Amount must be a valid number.').show();
$('#amount').addClass('is-invalid');
toastr.warning('Amount must be a valid number.');
return;
}
$('#amount_error').hide().text('');
$('#amount').removeClass('is-invalid');
if (description == "") {
toastr.warning('Description field is required')
return;
}
//tranction type
if (transactionTypeValue == 1) {
transactionType = 'Credit';
subType = '1'; // Replenishment or Deposite
} else if (transactionTypeValue == 2) {
transactionType = 'Credit'
subType = '2'; // Adjustment add
} else if (transactionTypeValue == 3) {
transactionType = 'Debit'
subType = '2'; // Adjustment reduce
} else if (transactionTypeValue == 4) {
transactionType = 'Credit'
subType = '5'; // Asset Policy add
} else if (transactionTypeValue == 5) {
transactionType = 'Debit'
subType = '5'; // Asset Policy reduce
} else if (transactionTypeValue == 6) {
transactionType = 'Debit'
subType = '6'; // Refund by indurer
}
console.log('transactionTypeValue', transactionTypeValue)
console.log('transactionType', transactionType)
console.log('description ', description)
console.log('amount ', amount)
console.log('clientId ', clientId)
console.log('insurerId ', insurerId)
console.log('subType ', subType)
console.log('cd_ac_pk ', cd_ac_pk)
console.log('cd_ac_no ', cd_ac_no)
// Send data to the server using Ajax
$.ajax({
type: 'POST',
url: '<?= base_url() . "client/save_deposit" ?>',
data: {
amount: amount,
description: description,
transaction_type: transactionType,
sub_type_id: subType, // Include sub_type_id
client_id: clientId,
insurer_id: insurerId,
record_date: record_date,
cd_ac_pk: cd_ac_pk,
cd_ac_no: cd_ac_no
},
success: function(response) {
// Handle success response
toastr.success("Transaction saved successfully", "Success");
// Reload the page or perform other actions as needed
location.reload();
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
if (xhr.status === 400) {
let response = JSON.parse(xhr.responseText);
let errorMessages = "";
let seenMessages = []; // Array to store unique messages
if (response.errors) {
$.each(response.errors, function (field, message) {
if (!seenMessages.includes(message)) {
errorMessages += `• ${message}<br>`;
seenMessages.push(message); // Mark this message as "seen"
}
});
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
} else {
toastr.warning(response.message || 'Validation failed', 'Warning');
}
} else if (xhr.status === 403) {
let response = JSON.parse(xhr.responseText);
toastr.error(response.message, 'Security Policy');
} else if (xhr.status === 500) {
toastr.error('Something went wrong . Please try again later.', 'Server Error');
} else {
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
}
location.reload(); // Uncomment if you need to reload the page on error
}
});
});
});
</script>
<script>
$(document).on('input', '#amount', function () {
var value = $(this).val();
value = value.replace(/[^0-9.]/g, '');
var parts = value.split('.');
if (parts.length > 2) {
value = parts[0] + '.' + parts.slice(1).join('');
parts = value.split('.');
}
if (parts[1] && parts[1].length > 2) {
value = parts[0] + '.' + parts[1].slice(0, 2);
}
$(this).val(value);
if (value.length) {
$('#amount_error').hide().text('');
$(this).removeClass('is-invalid');
}
});
</script>