nhance/app/Views/cd_master_list.php

392 lines
15 KiB
PHP
Executable File

<style>
.table th,
.table td {
padding: 8px;
}
table.dataTable tbody td {
padding: 4px 4px !important;
}
table.dataTable thead th {
padding: 4px 4px !important;
}
.col-12 {
max-width: 98% !important;
}
.custom-dropdown-menu {
display: none;
position: absolute;
background-color: #ffffff !important;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 0.25rem;
padding: 0.5rem 0;
min-width: 10rem;
z-index: 9999;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.custom-dropdown-menu .dropdown-item {
display: block !important;
width: 100% !important;
padding: 0.5rem 1rem !important;
color: #212529 !important;
text-decoration: none !important;
background-color: transparent !important;
}
.custom-dropdown-menu .dropdown-item:hover {
background-color: #f8f9fa !important;
color: #16181b !important;
cursor: pointer !important;
}
.dataTables_filter {
position: absolute;
}
</style>
<div class="row" id="client_list">
<div class="col-12">
<div class="card">
<div class="card-body maincard">
<!-- <div class="row" style="margin-bottom:1rem;">
<div class="col-6" style="align-self: center;">
<h4 style="position: relative;">CD Master</h4>
</div>
<div class="col-6" style="text-align: right; position: relative;top: 56px;">
<!- <button type="button" id="btnAdd" class="btn btn-primary waves-effect waves-light"
data-toggle="modal" data-target="#con-close-modal" data-placement="top" title="Add"
data-trigger="hover">ADD</button> ->
</div>
</div> -->
<table data-custom-table-css="table" id="scroll-horizontal-datatable" class="table w-100 nowrap text-custom-black text-custom app-datatable">
<thead class="bg-light">
<tr>
<th class="font-weight-medium">S.No&nbsp;</th>
<th class="font-weight-medium">Client Name&nbsp;</th>
<th class="font-weight-medium">Insurer Name&nbsp;</th>
<th class="font-weight-medium">Insurer Branch Name&nbsp;</th>
<th class="font-weight-medium">Opening Date&nbsp;</th>
<th class="font-weight-medium">CD Account No&nbsp;</th>
<th class="font-weight-medium">Opening Amount&nbsp;</th>
<th class="font-weight-medium">Date/User&nbsp;</th>
<th class="font-weight-medium">Action&nbsp;</th>
</tr>
</thead>
<tbody class="app-table-body">
<?php foreach($CD_Master_Data as $index => $row){ ?>
<tr>
<td class="text-center"><?= $index + 1; ?></td>
<td><?php echo $row['client_name']; ?>( <?= $row['short_name'] ?> )</td>
<td><?php echo $row['insurer_name']; ?></td>
<td><?php echo $row['insurer_branch_name']; ?></td>
<td><?php echo date('d-m-Y', strtotime($row['opening_date'])); ?></td>
<td><?php echo $row['cd_ac_no']; ?></td>
<td><?php echo $row['opening_bal']; ?></td>
<td><?php echo date('d-M-Y h:i A', strtotime($row['created_at'])) ?> <br>by <?php echo $row['user_name']; ?></td>
<td>
<div class="btn-group dropdown">
<a href="javascript: void(0);"class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown"aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item btnEdit" data-id="<?= $row['id'];?>" data-toggle="modal" data-target="#con-close-modal"> <i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<?php if($row['cd_ac_no_count'] == 0) { ?>
<a class="dropdown-item" data-id="<?= $row['id'];?>" onclick="removeCDMaster(this)"><i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete</a>
<?php } ?>
</div>
</div>
</td>
<?php } ?>
</tr>
</tbody>
</table>
</div>
</div>
</div><!-- end col -->
</div>
<!-- end row -->
<?php include("cd_master_add_modal.php"); ?>
<script>
document.addEventListener("DOMContentLoaded", function () {
const table = document.getElementById("scroll-horizontal-datatable");
// Create custom dropdown
function createCustomDropdown(row) {
const originalDropdown = row.querySelector('.dropdown-menu');
if (!originalDropdown) return null;
const customDropdown = document.createElement('div');
customDropdown.className = 'custom-dropdown-menu';
customDropdown.innerHTML = originalDropdown.innerHTML;
return customDropdown;
}
let activeDropdown = null;
// Add click event listener to rows
table.querySelectorAll("tbody tr").forEach(row => {
const customDropdown = createCustomDropdown(row);
if (!customDropdown) return;
row.customDropdown = customDropdown;
document.body.appendChild(customDropdown);
row.addEventListener("click", function(event) {
// Ignore clicks on the last column (action column)
if (event.target.closest('td') === row.lastElementChild) {
return;
}
// Hide any active dropdown
if (activeDropdown && activeDropdown !== customDropdown) {
activeDropdown.style.display = 'none';
}
// Toggle the dropdown display
const isActive = customDropdown.style.display === 'block';
customDropdown.style.display = isActive ? 'none' : 'block';
// Set the position of the dropdown
const rect = event.target.closest('td').getBoundingClientRect();
customDropdown.style.position = 'absolute';
customDropdown.style.left = `${rect.left}px`;
customDropdown.style.top = `${rect.bottom + 5}px`;
// Set as active dropdown
activeDropdown = isActive ? null : customDropdown;
event.stopPropagation();
});
// Preserve click handlers for modal actions
customDropdown.querySelectorAll('.dropdown-item').forEach(item => {
item.addEventListener('click', function(e) {
const isModalAction = this.hasAttribute('data-toggle') && this.getAttribute('data-toggle') === 'modal';
if (isModalAction) {
return; // Allow modal to function normally
}
// Close the dropdown if it's not related to modal
if (activeDropdown) {
activeDropdown.style.display = 'none';
activeDropdown = null;
}
const onclickAttr = this.getAttribute('onclick');
if (onclickAttr) {
eval(onclickAttr);
}
const href = this.getAttribute('href');
if (href && href !== '#') {
window.location.href = href;
}
e.stopPropagation();
});
});
});
// Close dropdown when clicking outside
document.addEventListener("click", function() {
if (activeDropdown) {
activeDropdown.style.display = 'none';
activeDropdown = null;
}
});
});
</script>
<script>
$(document).ready(function() {
$('#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: '<i class="mdi mdi-plus" ></i><span class=" btn-custom"> Add </span>',
className: 'btn app-btn-primary mr-2',
action: function (e, dt, node, config) {
showCdMasterAddModal();
}
},
{
extend: 'collection',
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
className: 'btn app-btn-secondary ',
buttons: [
{
extend: 'csv',
title: 'CD-Master-List',
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
className: 'app-btn-primary my_class',
exportOptions: {
columns: ':not(:last-child)'
},
},
{
extend: 'excel',
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
exportOptions: {
orthogonal: 'sort'
},
className: 'app-btn-primary ',
}
]
}
],
language: {
search: `
<div class="datatable-search-wrapper">
_INPUT_
<i class="mdi mdi-magnify datatable-search-icon"></i>
</div>`,
searchPlaceholder: "Search"
},
paging: true,
pageLength: 10,
order: [[0, 'desc']]
// scrollX: true,
// dom: "<'row'<'col-sm-6'f><'col-sm-6 text-right'B>>" +
// "<'row'<'col-sm-12'tr>>" +
// "<'row'<'col-sm-5'i><'col-sm-7'p>>",
// buttons: [
// {
// extend: 'csv',
// text: 'CSV',
// title: 'CD-Master-List',
// className: 'my_class',
// exportOptions: {
// columns: ':not(:last-child)'
// },
// },
// {
// text: 'Add',
// className: 'buttons-html5 ',
// action: function (e, dt, node, config) {
// showCdMasterAddModal();
// }
// }
// ],
// language: {
// search: "_INPUT_",
// searchPlaceholder: "Search..."
// },
// paging: true,
});
})
$(document).ready(function(){
<?php if (session()->has('error')) : ?>
toastr.error('<?= session()->getFlashdata('error') ?>', 'Failed');
<?php endif; ?>
<?php if (session()->has('success')) : ?>
toastr.success('<?= session()->getFlashdata('success') ?>', 'success');
<?php endif; ?>
})
$('body').on('click', '.btnEdit', function () {
var cd_id = $(this).attr('data-id');
$('#title').html('Update Opening Amount');
$.ajax({
url: '<?php echo base_url('master/cash_deposite/list/');?>'+cd_id,
type: "GET",
dataType: 'json',
success: function (res) {
console.log(res)
$('#updateModal').modal('show');
$('#CDMasterForm').attr('action', '<?php echo base_url('master/cash_deposite/edit');?>');
$('#CD_Master_ID').val(res.data.id);
$('#cd_client_id').val(res.data.client_id).change();
$('#cd_client_id').prop("disabled", true);
$('#insurer_id_for_cd').val(res.data.insurer_id).change();
$('#insurer_id_for_cd').prop("disabled", true);
$('#insurer_branch_id').val(res.data.insurer_branch_id).select2();
$('#insurer_branch_id').prop("disabled", true);
$('#opening_date').val(res.data.opening_date);
$('#cd_ac_no_for_cd_master').val(res.data.cd_ac_no);
//$('#cd_ac_no_for_cd_master').prop("disabled", true);
$('#opening_bal').val(res.data.opening_bal);
if(res.cd_transaction_count <= 1){
$('#opening_bal').prop("disabled", false)
}else{
$('#opening_bal').prop("disabled", true)
}
$('#cd_master_btn_Submit').html('Update');
},
error: function (xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
});
});
function removeCDMaster(element) {
Swal.fire({
title: "Are you sure?",
text: "You need to remove this CD.",
icon: "info",
showCancelButton: true,
confirmButtonColor: "#3085d6",
confirmButtonText: "Yes",
}).then((result) => {
if (result.isConfirmed) {
var id = element.getAttribute('data-id');
var form_action = '<?= base_url("master/cash_deposite/remove/") ?>' + id;
$.ajax({
url: form_action,
type: "GET",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
// console.log(res.status == true);
if(res){
if (res.status == true) {
toastr.success('CD removed successfully.', 'success');
location.reload();
} else {
toastr.warning('Failed to remove CD.', 'warning');
}
}
},
error: function (xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.log('Something Wrong!', 'warning');
}
});
}
});
}
</script>