nhance/app/Views/policy_transaction_endorsement_list.php

1027 lines
39 KiB
PHP

<style>
.table th,
.table td {
padding: 8px;
}
table.dataTable tbody td {
padding: 4px 4px !important;
}
/*
table.dataTable thead th {
padding: 4px 4px !important;
} */
.dataTables_filter {
position: absolute;
}
.column-header {
margin-right: 10px;
/* Adjust this value as needed */
}
.form-section {
border: 1px solid #ccc;
padding: 15px;
margin-bottom: 20px;
}
.row-box {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
}
.custom-dropdown-menu {
display: none;
position: fixed;
background-color: #ffffff !important;
border: 1px solid rgba(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;
clear: both !important;
font-weight: 400 !important;
color: #212529 !important;
text-align: inherit !important;
white-space: nowrap !important;
background-color: transparent !important;
border: 0 !important;
text-decoration: none !important;
position: relative !important;
}
.custom-dropdown-menu .dropdown-item:hover {
background-color: #f8f9fa !important;
color: #16181b !important;
cursor: pointer !important;
}
.custom-dropdown-menu .dropdown-item i {
margin-right: 8px !important;
vertical-align: middle !important;
}
.table tbody tr {
cursor: pointer;
}
/* Ensure the dropdown menu has a solid background */
.custom-dropdown-menu::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #ffffff;
z-index: -1;
}
/* Add a subtle backdrop effect */
.custom-dropdown-menu::after {
content: '';
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.05);
z-index: -2;
pointer-events: none;
}
</style>
<style>
.switch {
position: relative;
display: inline-block;
width: 54px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 19px;
width: 19px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked+.slider {
background-color: #2196F3;
}
input:focus+.slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked+.slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
<div class="container-fluid-min">
<div class="col-12" id="endorsement_filter">
<div class="card-body">
<div id="accordion" class="mb-3">
<div class="card mb-1">
<h4 class="m-1">
<span>Filter</span>
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseOne"
aria-expanded="true">
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
</a>
</h4>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-3">
<label for="client_branch">Client<span class="text-danger"></span></label>
<select class="form-control" id="client_id_for_search" name="client_id">
<option value="0">Select Client</option>
<?php
if (isset($client) && count($client)) {
foreach ($client as $key => $value) {
echo "<option value='" . $value['id'] . "'>" . $value['client_name'] . "</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-3">
<label for="addon_policy"> Insurer <span id="base_danger" class="text-danger"></span></label>
<select class="form-control" id="insurer_id_for_search" name="insurer_id">
<option value="0" selected>Select Insurer</option>
<?php foreach ($insurer as $value) { ?>
<option value="<?= $value['id'] ?>"><?= $value['name'] ?></option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-3">
<label for="email"> Policy Type <span class="text-danger"></span></label>
<select class="form-control" id="policy_type_for_search" name="policy_type_id">
<option value="0">Select Policy Type</option>
<?php
if (isset($policy_types) && count($policy_types)) {
foreach ($policy_types as $key => $value) {
echo "<option value='" . $value['id'] . "'>" . $value['policy_type'] . "</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-3">
<label for="client_branch">Issuer<span class="text-danger">*</span></label>
<select class="form-control" id="issuer_for_search" name="issuer" required>
<option value="0">Select Issure</option>
<?php
if (isset($issuer) && count($issuer)) {
foreach ($issuer as $key => $value) {
echo "<option value=" . $key . ">" . $value . "</option>";
}
}
?>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="email"> Status <span class="text-danger"></span></label>
<select class="form-control" id="policy_status_for_search" name="policy_type_id">
<option value="0">Select Status</option>
<?php
if (isset($policy_status) && count($policy_status)) {
foreach ($policy_status as $key => $value) {
echo "<option value='" . $key . "'>" . $value . "</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-3">
<label>Date Type<span class="text-danger"></span></label>
<select class="form-control" id="date_type" name="date_type" onchange="hideDateField()">
<option value="0">Select Date Type</option>
<?php
if (isset($date_type) && count($date_type)) {
foreach ($date_type as $key => $value) {
echo "<option value='" . $key . "'>" . $value . "</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-3" style="display: none;" id="date_div">
<label>Date<span class="text-danger"></span></label>
<div id="reportrange" class="form-control" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 100%">
<i class="mdi mdi-calendar-blank"></i>&nbsp;
<span></span> <i class="mdi mdi-menu-down"></i>
</div>
<input type="hidden" id="startDate">
<input type="hidden" id="endDate">
</div>
</div>
<div class="form-group text-right m-b-0">
<a href="<?= base_url("/policy_tranction/endorsement/list"); ?>" class="btn btn-secondary" id="clear-filters">Clear</a>
<a href="<?= base_url("/policy_tranction/endorsement/list"); ?>" class="btn btn-primary" id="get-emp-list" onclick="fetchEmpolyeeList(event);">Submit</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-12" id="endorsement_list">
<div class="card">
<div class="card-body">
<!-- <div class="row" style="margin-bottom:1rem;">
<div class="col-6" style="align-self: center;">
<h4 style="position: relative;">Endorsement List</h4>
</div>
<div class="col-3">
<button type="button" id="btnAdd" class="btn btn-primary waves-effect waves-light" onclick="hide_list_show_add()">Add</button>
</div>
</div> -->
<table data-custom-table-css="table" class="table table-striped mb-0 nowrap" cellspacing="0" id="tickets-table">
<thead class="bg-light">
<tr>
<th>Sno</th>
<th>Issuer</th>
<th>Client</th>
<th>Branch</th>
<th>Insurer</th>
<th>Policy</th>
<th>Endorsement Type</th>
<th>Endorsement No</th>
<th>Data Recived Date</th>
<th>No of Insured</th>
<th>No of Dependence</th>
<th>Policy Issue Date</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($endorsement_data_list as $index => $row) { ?>
<tr>
<td class="text-center"><?php echo $index + 1; ?></td>
<td><?php echo $issuer[$row['issuer']] ?? 'N/A'; ?></td><!-- Issuer -->
<td><?php echo $row['client_short_name'] ?: 'N/A'; ?></td><!-- Client -->
<td><?php echo $row['client_branch_name'] ?: 'N/A'; ?></td><!-- Branch -->
<td><?php echo $row['insurer_short_name'] ?: 'N/A'; ?></td><!-- Insurer -->
<td><?php echo $row['policy_type'] ?: 'N/A'; ?></td><!-- Policy -->
<td><?php echo $action_type[$row['action_type']] ?: 'N/A';?></td>
<td><?php echo $row['endorsement_no'] ?: 'N/A'; ?></td>
<td><?php echo empty($row['data_received_date']) ? 'N/A' : date('d/m/Y', strtotime($row['data_received_date'])); ?></td>
<td class="right-align-input"><?php echo $row['emp_count'] ?: '0'; ?></td>
<td class="right-align-input"><?php echo $row['dependent_count'] ?: '0'; ?></td>
<td><?php echo empty($row['policy_issue_date']) ? 'N/A' : date('d/m/Y', strtotime($row['policy_issue_date'])); ?></td>
<td><?php echo $policy_status[$row['status']] ?: 'N/A'; ?></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']; ?>" onclick="getPolicyTransactionDataForEndorsementEdit('<?= htmlspecialchars($row['id'], ENT_QUOTES) ?>')">
<i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit
</a>
<a class="dropdown-item delete" data-id="<?= $row['id'];?>" onclick="removePolicyTransaction(this, '<?= htmlspecialchars($row['id'], ENT_QUOTES) ?>', <?= $row['policy_type_id'] ?>)">
<i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete
</a>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table><!-- table -->
</div><!-- card-body -->
</div><!-- card -->
</div><!-- end col -->
</div>
<!-- end table row -->
<?php include('policy_transaction_endorsement_form.php'); ?>
<script>
document.addEventListener("DOMContentLoaded", function() {
const table = document.getElementById("tickets-table");
// 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;
// Remove inline onclick handlers and store them in data attributes
const originalItems = originalDropdown.querySelectorAll('.dropdown-item');
customDropdown.querySelectorAll('.dropdown-item').forEach((item, index) => {
const originalOnclick = originalItems[index].getAttribute('onclick');
item.removeAttribute('onclick'); // Remove the inline handler
item.setAttribute('data-onclick', originalOnclick); // Store in data attribute
});
return customDropdown;
}
let activeDropdown = null;
// Add click event listener to rows
table.querySelectorAll("tbody tr").forEach(row => {
const customDropdown = createCustomDropdown(row);
if (!customDropdown) return;
document.body.appendChild(customDropdown);
row.addEventListener("click", function(event) {
// Ignore clicks on the first column
if (event.target.closest('td:first-child')) return;
if (activeDropdown) activeDropdown.style.display = 'none';
const rect = event.target.getBoundingClientRect();
customDropdown.style.display = 'block';
customDropdown.style.position = 'fixed';
customDropdown.style.left = `${rect.left}px`;
customDropdown.style.top = `${rect.bottom + 5}px`;
activeDropdown = customDropdown;
event.stopPropagation();
});
// Handle custom dropdown clicks
customDropdown.querySelectorAll('.dropdown-item').forEach(item => {
item.addEventListener('click', function(e) {
e.preventDefault();
// Execute the original onclick from data attribute
const onclickAttr = this.getAttribute('data-onclick');
if (onclickAttr) eval(onclickAttr);
// Handle href navigation
const href = this.getAttribute('href');
if (href && href !== '#') window.location.href = href;
if (activeDropdown) {
activeDropdown.style.display = 'none';
activeDropdown = null;
}
e.stopPropagation();
});
});
});
// Close dropdown on outside click
document.addEventListener("click", function() {
if (activeDropdown) {
activeDropdown.style.display = 'none';
activeDropdown = null;
}
});
});
</script>
<script>
var client_list = '';
var branch_list = '';
var policy_list = <?= json_encode($endorsementPolicies) ?>;
// console.log("POLICY List",policy_list);
var policyListByClient = <?= json_encode($endorsementPolicyListByClient) ?>;
var branch_policy = '';
var unit_list = '';
// select2 document ready
$(document).ready(function() {
getClientAndBranchAndPolicy()
<?php if (session()->has('create_failed')) : ?>
toastr.error('<?= session()->getFlashdata('create_failed') ?>', 'Failed');
<?php endif; ?>
<?php if (session()->has('update_failed')) : ?>
toastr.error('<?= session()->getFlashdata('update_failed') ?>', 'Failed');
<?php endif; ?>
<?php if (session()->has('create_success')) : ?>
toastr.success('<?= session()->getFlashdata('create_success') ?>', 'success');
<?php endif; ?>
<?php if (session()->has('update_success')) : ?>
toastr.success('<?= session()->getFlashdata('update_success') ?>', 'success');
<?php endif; ?>
$('#client_id').select2();
$('#client_branch_id').select2();
$('#client_policy_id').select2();
})
//DataTable document ready
$(document).ready(function() {
var ticketsTable = $('#tickets-table');
if (ticketsTable.length) {
ticketsTable.DataTable({
scrollX: true,
dom: "<'row'<'col-sm-1'f><'col-sm-11 text-right'B>>" + // Filter left, buttons right
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>", // Pagination at the bottom, without page length selector
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) {
hide_list_show_add();
},
attr: { id: 'btnAdd' }
},
{
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: 'Policy-Tranction-Endorsement-List',
exportOptions: {
columns: ':not(:last-child)'
},
}
]
}
],
language: {
search: `
<div class="datatable-search-wrapper">
_INPUT_
<i class="mdi mdi-magnify datatable-search-icon"></i>
</div>`,
searchPlaceholder: "Search"
},
paging: true, // Enable pagination
pageLength: 10, // Set default number of rows per page (optional)
ordering: false,
});
} else {
console.error("Table not found.");
}
$('#btnAdd').wrap('<div id="status_change"></div>');
});
// Date document ready
$(document).ready(function() {
var today = new Date();
var data_received_date = flatpickr("#data_received_date", {
dateFormat: "d/m/Y",
allowInput: false,
parseDate: (datestr, format) => {
return new Date(datestr.replace(/(\d{2})-(\d{2})-(\d{4})/, "$2/$1/$3"));
},
onOpen: function(selectedDates, dateStr, instance) {
instance.setDate(instance.input.value, false);
},
onInput: function(selectedDates, dateStr, instance) {
let inputValue = instance.input.value;
let formattedDate = inputValue.replace(/(\d{2})-(\d{2})-(\d{4})/, "$2/$1/$3");
instance.input.value = formattedDate;
}
});
var last_action_date = flatpickr("#last_action_date", {
dateFormat: "d/m/Y", // Display format in DD/MM/YYYY
defaultDate: today, // Today's date as the default value
allowInput: false,
maxDate: today // Disallow future dates
});
var closure_date = flatpickr("#policy_issue_date", {
dateFormat: "d/m/Y",
allowInput: false
});
var install_due_date = flatpickr("#install_due_date", {
dateFormat: "d/m/Y",
allowInput: false
});
// var start_date = flatpickr("#policy_start_date", {
// dateFormat: "d/m/Y",
// allowInput: false
// });
// var end_date = flatpickr("#policy_end_date", {
// dateFormat: "d/m/Y",
// allowInput: false
// });
var endorse_eff_date = flatpickr("#endorse_eff_date", {
dateFormat: "d/m/Y",
allowInput: false
});
var month = flatpickr("#month", {
dateFormat: "M/Y",
allowInput: false,
});
});
function hide_list_show_add() {
removeAllColumnsExceptFirst('insurerTable');
$('.hideter').hide()
$('.hidetp').hide()
$('#endorsement_form_id')[0].reset();
$('#client_id').val('').change();
$('#client_policy_id').val('').change();
$('#endorsement_form').show();
$('#endorsement_list').hide();
$('#endorsement_filter').hide();
$('#invoice_no_div').hide();
$('#invoice_no').attr('required', false)
}
function show_list_hide_add() {
$('#endorsement_form').hide()
$('#endorsement_list').show()
$('#endorsement_filter').show()
}
function getClientAndBranchAndPolicy() {
$.ajax({
url: '<?= base_url("/util/getClientAndBranchAndPolicy") ?>',
type: "GET",
dataType: 'json',
success: function(res) {
console.log('getClientAndBranchAndPolicy', res);
if (res.status == true) {
branch_list = res.branch_data;
// policy_list = res.policy_data;
// policyListByClient = res.policyListByClient;
client_list = res.client_data;
unit_list = res.unit_data;
appendClients(res.client_data);
} else {
console.log('No data found');
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
});
}
function appendClients(data) {
$('#client_id').empty();
$('#client_id').append($('<option>', {
value: '',
text: 'Select Client'
}));
// $('#client_id').append($('<option>', {
// value: 'add_client',
// text: '+ Add Client'
// }));
$.each(data, function(index, item) {
if (item.client_policy_count > 0) {
var option = $('<option>', {
value: item.id,
text: item.client_name
});
$('#client_id').append(option);
}
});
}
function appendBranch(data) {
$('#client_branch_id').empty();
$('#client_branch_id').append($('<option>', {
value: '',
text: 'Select Branch'
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.branch_name
});
$('#client_branch_id').append(option);
});
}
function appendPolicies(data, policy_id=null) {
if (!data) {
toastr.warning("There are no policies in Inception for the selected client and branch.");
}
console.log('appendPolicies', data);
console.log('appendPolicies', $('#client_policy_id'));
$('#client_policy_id').empty();
$('#client_policy_id').append($('<option>', {
value: '',
text: 'Select Policy',
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.policy_type + '-' + item.policy_no,
'data-sd': item.policy_start_date,
'data-ed': item.policy_end_date,
'data-insurer': item.insurer_branch_id + '-' + item.insurer_id,
'data-policy': item.policy_no,
'data-cd': item.cd_ac_no,
'data-ebp': item.ebp,
'data-etp': item.etp,
'data-iep': item.iep,
'data-itp': item.itp,
'data-bap': item.bap,
'data-allocg': item.allocg,
'data-tpa': item.tpa_branch_id + '-' + item.tpa_id,
'data-ptid': item.policy_type_id,
});
if (policy_id == item.id) {
option.attr('selected', true);
}
$('#client_policy_id').append(option);
});
}
function logSelectedIds() {
var selectedIds = [];
$('.row-select:checked').each(function() {
selectedIds.push($(this).data('id'));
});
console.log('Selected IDs:', selectedIds);
return selectedIds;
}
//--------------------------------------------------------------------------------------------
$("#invoiceForm").submit(function(event) {
event.preventDefault();
var isValid = $('#invoiceForm').parsley().validate();
if (!isValid) {
console.log('Form is Empty', 'Warning');
return;
}
form_action = '<?= base_url("util/updateInvoiceStatus"); ?>';
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var ids = logSelectedIds();
console.log(ids);
var formData = new FormData($('#invoiceForm')[0]);
formData.append('ids', JSON.stringify(ids));
$.ajax({
data: formData,
url: form_action,
type: "POST",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (res.status == true) {
toastr.success(res.message, 'Success');
} else {
toastr.error(res.message, 'Error');
}
window.location.reload();
$('.close').click();
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}
});
});
$('#invoice_status').change(function() {
let value = $(this).val()
if (value == 'generated') {
$('#invoice_no_div').show()
$('#invoice_no').attr('required', true)
} else {
$('#invoice_no_div').hide()
$('#invoice_no').attr('required', false)
}
})
$('#invoice_status_modal').change(function() {
let value = $(this).val()
if (value == 'generated') {
$('#invoice_no_div_modal').show()
$('#invoice_no_modal').attr('required', true)
} else {
$('#invoice_no_div_modal').hide()
$('#invoice_no_modal').attr('required', false)
}
})
</script>
<script>
$(document).ready(function() {
getURLParams()
$('#client_id_for_search').select2();
$('#insurer_id_for_search').select2();
$('#policy_type_for_search').select2();
})
function fetchEmpolyeeList(event) {
event.preventDefault(); // Prevent default action
var start_date = $('#startDate').val();
var end_date = $('#endDate').val();
var client_id = $('#client_id_for_search').val();
var insurer_id = $('#insurer_id_for_search').val();
var policy_type_id = $('#policy_type_for_search').val();
var date_type = $('#date_type').val();
var issuer = $('#issuer_for_search').val();
var status = $('#policy_status_for_search').val();
console.log(start_date + '-' + end_date);
var queryParams = {
start_date: start_date,
end_date: end_date,
client_id: client_id,
insurer_id: insurer_id,
policy_type_id: policy_type_id,
date_type: date_type,
issuer: issuer,
status: status,
};
console.log(queryParams)
const queryString = objectToQueryString(queryParams);
const apiURL = $('#get-emp-list').attr('href') + "?" + queryString;
console.log(apiURL);
window.location.href = apiURL;
}
function objectToQueryString(obj) {
return Object.keys(obj).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`).join('&');
}
function getURLParams() {
const url = new URL(window.location.href);
const params = new URLSearchParams(url.search);
const startDate = params.get('start_date') || 0; // Default to 0 if not found
const endDate = params.get('end_date') || 0; // Default to 0 if not found
const client_id = params.get('client_id') || 0; // Default to 0 if not found
const insurer_id = params.get('insurer_id') || 0; // Default to 0 if not found
const policy_type_id = params.get('policy_type_id') || 0; // Default to 0 if not found
const date_type = params.get('date_type') || 0; // Default to 0 if not found
const issuer = params.get('issuer') || 0; // Default to 0 if not found
const status = params.get('status') || 0; // Default to 0 if not found
hideDateField(date_type)
// console.log('startDate', startDate)
// console.log('endDate', endDate)
// console.log('client_id', client_id)
// console.log('insurer_id', insurer_id)
// console.log('policy_type_id', policy_type_id)
// console.log('date_type', date_type)
// console.log('issuer', issuer)
// console.log('status', status)
// Log the values or use them as needed
// console.log('Start Date:', startDate);
// console.log('End Date:', endDate);
if (startDate != 0 && endDate != 0) {
setTimeout(function() {
$('#start_date').val(startDate)
$('#end_date').val(endDate)
$('#client_id_for_search').val(client_id).change()
$('#insurer_id_for_search').val(insurer_id).change()
$('#policy_type_for_search').val(policy_type_id).change()
$('#date_type').val(date_type)
$('#issuer_for_search').val(issuer)
$('#policy_status_for_search').val(status)
}, 1000)
}
}
$(function() {
const url = new URL(window.location.href);
const params = new URLSearchParams(url.search);
// Get start and end dates from URL parameters, or use default values
const startDateParam = params.get('start_date') || moment().subtract(29, 'days').format('DD/MM/YYYY');
const endDateParam = params.get('end_date') || moment().format('DD/MM/YYYY');
// Parse the dates to moment objects
var start = moment(startDateParam, 'DD/MM/YYYY');
var end = moment(endDateParam, 'DD/MM/YYYY');
// var start = moment().subtract(29, 'days');
// var end = moment();
function cb(start, end) {
$('#reportrange span').html(start.format('D/MM/YYYY') + ' - ' + end.format('D/MM/YYYY'));
$('#startDate').val(start.format('DD/MM/YYYY'));
$('#endDate').val(end.format('DD/MM/YYYY'));
}
$('#reportrange').daterangepicker({
startDate: start,
endDate: end,
locale: {
format: 'DD-MM-YYYY'
},
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
}, cb);
cb(start, end);
$('#clear-filters').on('click', function() {
// Reset all select dropdowns to the first option
$('#client_id_for_search').val('0').change();
$('#insurer_id_for_search').val('0').change();
$('#policy_type_for_search').val('0').change();
$('#date_type').val('0');
$('#issuer_for_search').val('0');
$('#policy_status_for_search').val('0');
$('#date_div').hide()
// Reset the date range picker to default
$('#reportrange').data('daterangepicker').setStartDate(moment().subtract(29, 'days'));
$('#reportrange').data('daterangepicker').setEndDate(moment());
cb(start, end); // Update the displayed date range
});
});
function hideDateField(input = null) {
let val = $('#date_type').val();
if (input) {
val = input;
}
if (val != 0) {
$('#date_div').show()
} else {
$('#date_div').hide()
}
}
function removePolicyTransaction(input, pt_id, policy_type_id) {
let string = "Do you want to delete this transaction?";
if(policy_type_id > 7){
string = "Do you want to delete this transaction? Deleting this will also remove the linked CRM policy entry.";
}
confirmActionSweertAlert(string, "Yes, Proceed!", "No, Cancel").then((confirmed) => {
if (confirmed) {
let type = '1';
let url = '<?= base_url('policy_tranction/inception/removePolicyTransaction/') ?>' + pt_id + '/' + type;
// Include `pt_id` in the AJAX request if necessary
let requestData = {
pt_id: pt_id ,
type: 1 ,
};
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
console.log('Data fetched successfully:', response);
if (response.status === true) {
toastr.success(response.message, 'SUCCESS');
window.location.reload();
} else {
toastr.warning(response.message, 'WARNING');
}
}, function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
});
}
});
}
</script>