diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 2c6946d5..041caaa3 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -247,6 +247,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get("get_cd_ac/(:any)", "ClientController::get_cd_ac/$1"); $routes->get("check_policy_type/(:any)", "ClientController::checkPolicyType/$1"); $routes->get("getPolicyTerms/(:any)", "ClientController::getPolicyTerms/$1"); + $routes->get("getPolicyTermsFormJson/(:any)", "ClientController::getPolicyTermsFormJson/$1"); }); $routes->cli('cli/processjob', 'JobWorker::processJob'); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 8d69abfb..13be8344 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -32,6 +32,8 @@ use App\Models\EmployeeModel; use App\Models\EmployeePolicyModel; use App\Models\NotificationModel; use App\Models\CDMasterModel; +use App\Models\PolicyTypeModel; + @@ -65,13 +67,14 @@ class ClientController extends AdminController protected $employeePolicyModel; protected $notificationModel; protected $CDMasterModel; + protected $policyTypeModel; public function __construct() { set_session_context('Client'); $this->myLogger = \Config\Services::mylogger(); - + $this->clientModel = new ClientModel(); $this->userModel = new UserModel(); $this->clientBranchModel = new ClientBranchModel(); @@ -93,8 +96,10 @@ class ClientController extends AdminController $this->policyPremium2Model = new PolicyPremium2Model(); $this->employeeModel = new EmployeeModel(); $this->employeePolicyModel = new EmployeePolicyModel(); - $this->notificationModel = new NotificationModel(); - $this->CDMasterModel = new CDMasterModel(); + $this->notificationModel = new NotificationModel(); + $this->CDMasterModel = new CDMasterModel(); + $this->policyTypeModel = new PolicyTypeModel(); + @@ -2231,4 +2236,11 @@ class ClientController extends AdminController return $this->respond(['status' => true, 'data'=>$multi_si], 200); } + + public function getPolicyTermsFormJson($policy_type_id){ + + $JSON = $this->policyTypeModel->where('id', $policy_type_id)->first(); + return $this->respond(['status' => true, 'data' => $JSON], 200); + } + } \ No newline at end of file diff --git a/app/Views/policy_grid.php b/app/Views/policy_grid.php index 0cd0acda..927895d0 100644 --- a/app/Views/policy_grid.php +++ b/app/Views/policy_grid.php @@ -319,7 +319,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -348,7 +348,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -391,7 +391,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -421,7 +421,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -442,7 +442,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -466,7 +466,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -501,7 +501,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -534,7 +534,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -569,7 +569,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -604,7 +604,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -633,7 +633,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -654,7 +654,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -687,7 +687,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -721,7 +721,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -759,7 +759,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -827,11 +827,11 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa }; -$("#GridForm").submit(function(event) { +$("#GridForm").submit(async function(event) { var check = checkDuplicate(0); - - + console.log(check) + event.preventDefault(); if ($('#grid_emp_count').val() == 'false') { @@ -845,6 +845,7 @@ $("#GridForm").submit(function(event) { return; } + $('.loader').fadeIn(); $('.loader-mask').fadeIn(); @@ -852,45 +853,63 @@ $("#GridForm").submit(function(event) { var policy_form_action = ''; - if (check) { - $('.loader').fadeOut(); - $('.loader-mask').delay(350).fadeOut('slow'); - } else { - $.ajax({ - data: formData, - url: policy_form_action, - type: "POST", - dataType: 'json', - processData: false, - contentType: false, - success: function(res) { - - //console.log("Response", res); - - if (res.status === false) { - toastr.error('Policy Dose Not Create', 'Error'); - return; - } + checkPolicyTermsSI(function(result) { + if (!result) { + if (check) { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); - var message = (policy_PrimaryKey === '') ? 'Policy Premium Added successfully' :'Policy Premium Added Successfully'; - toastr.success(message, 'Success'); + } else { + + $.ajax({ + data: formData, + url: policy_form_action, + type: "POST", + dataType: 'json', + processData: false, + contentType: false, + success: function(res) { - if($('#grid').val() == 1 || $('#grid').val() == 2){ - $('.close').click(); - } + //console.log("Response", res); - }, - error: function(xhr, status, error) { + if (res.status === false) { + toastr.error('Policy Dose Not Create', 'Error'); + return; + } - console.error(xhr.responseText); - console.error(status, error); - $('.loader').fadeOut(); - $('.loader-mask').delay(350).fadeOut('slow'); + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + var message = (policy_PrimaryKey === '') ? 'Policy Premium Added successfully' :'Policy Premium Added Successfully'; + toastr.success(message, 'Success'); + + if($('#grid').val() == 1 || $('#grid').val() == 2){ + $('.close').click(); + } + + }, + error: function(xhr, status, error) { + + console.error(xhr.responseText); + console.error(status, error); + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + } + }); } - }); - } + + }else{ + + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + toastr.warning(`Value does not exist in the Policy Terms.`); + + } + +}).catch(function(error) { + console.error('Error checking policy terms:', error); + // Handle error if necessary + toastr.error(`Error checking policy terms: ${error}`); + }); }); @@ -1552,7 +1571,7 @@ function appendGridtHtml(ui_type = false, secondary = 0, data = false) { html = `
- +
@@ -1580,7 +1599,7 @@ function appendGridtHtml(ui_type = false, secondary = 0, data = false) {
- +
@@ -1609,7 +1628,7 @@ function appendGridtHtml(ui_type = false, secondary = 0, data = false) {
- +
@@ -1634,7 +1653,7 @@ function appendGridtHtml(ui_type = false, secondary = 0, data = false) {
- +
@@ -1680,7 +1699,7 @@ function appendGridtHtml(ui_type = false, secondary = 0, data = false) {
- +
@@ -1731,7 +1750,7 @@ function appendGridtHtml(ui_type = false, secondary = 0, data = false) {
- +
@@ -1759,7 +1778,7 @@ function appendGridtHtml(ui_type = false, secondary = 0, data = false) {
- +
@@ -1783,7 +1802,7 @@ function appendGridtHtml(ui_type = false, secondary = 0, data = false) {
- +
@@ -1807,7 +1826,7 @@ function appendGridtHtml(ui_type = false, secondary = 0, data = false) {
- +
@@ -1835,7 +1854,7 @@ function appendGridtHtml(ui_type = false, secondary = 0, data = false) {
- +
@@ -1863,7 +1882,7 @@ function appendGridtHtml(ui_type = false, secondary = 0, data = false) {
- +
@@ -1895,7 +1914,7 @@ function appendGridtHtml(ui_type = false, secondary = 0, data = false) {
- +
@@ -2917,5 +2936,126 @@ function checkTermsSISameAsRackRateSI(input) { } + function checkPolicyTermsSI(callback) { + + + console.log('r function called'); + + var id = $('#additional_grid')[0]; + var container = $('#additional_grid_content_input'); + + var val = 0; + + if (val == 0) { + id = $('#grid')[0]; + container = $('#grid_content_input'); + } + + + console.log(id); + console.log(container); + + var siInputs = 0; + + if (id.value === '2') { + siInputs = container.find('input[name="gpa_si"]'); + } else if (id.value === '3') { + siInputs = container.find('input[name="3_si[]"]'); + } else if (id.value === '4') { + siInputs = container.find('input[name="4_si[]"]'); + } else if (id.value === '5') { + siInputs = container.find('input[name="5_si[]"]'); + } else if (id.value === '6') { + siInputs = container.find('input[name="6_si[]"]'); + } else if (id.value === '7') { + siInputs = container.find('input[name="7_si[]"]'); + } else if (id.value === '8') { + siInputs = container.find('input[name="8_si[]"]'); + } else if (id.value === '9') { + siInputs = container.find('input[name="9_si[]"]'); + } else if (id.value === '10') { + siInputs = container.find('input[name="10_si[]"]'); + } else if (id.value === '11') { + siInputs = container.find('input[name="11_si[]"]'); + } else if (id.value === '1') { + var selectedValue = $('#si_or_bp').val(); + + if (selectedValue == 1) { + siInputs = container.find('input[name="gpa_sum_si[]"]'); + } else if (selectedValue == 3) { + siInputs = container.find('input[name="gpa_sum_si2[]"]'); + } + } + + var client_policy_id = $('#client_policy_id').val(); + console.log('client_policy_id', client_policy_id) + + var url = '' + client_policy_id; + + var arrayLength = 0; + + $.ajax({ + url: url, + type: 'GET', + dataType: 'json', + success: function(response) { + console.log(response); + console.log(response.data); + + var array1 = response.data; + var array2 = []; + + siInputs.each(function() { + var input = $(this).val(); + array2.push(input.replace(/,/g, '')); + }); + + console.log('array1', array1) + console.log('array2', array2) + + + function intersection(arr1, arr2) { + return arr1.filter(value => arr2.includes(value)); + } + + var commonElements = intersection(array1, array2); + + function removeCommonElements(arr, common) { + return arr.filter(value => !common.includes(value)); + } + + array1 = removeCommonElements(array1, commonElements); + array2 = removeCommonElements(array2, commonElements); + + console.log('array1', array1) + console.log('array2', array2) + + + // var result = array1.concat(array2); + var result = array1; + + console.log('result', result) + + arrayLength = result.length; + + console.log('arrayLength', arrayLength) + + if (arrayLength > 0) { + callback(true); + } else { + callback(false); + } + + }, + error: function(xhr, status, error) { + console.error(xhr.responseText); + console.error(status, error); + toastr.error(`Failed to retrieve Policy Terms. Error: ${error}`); + callback(false); + } + }); + + +} \ No newline at end of file