diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php
index 2a3e5782..01f35d7c 100644
--- a/app/Controllers/ClientController.php
+++ b/app/Controllers/ClientController.php
@@ -2206,7 +2206,7 @@ class ClientController extends AdminController
}
- public function checkPolicyType($client_policy_id, $policy_type_id, $client_branch_id, $client_id){
+ public function checkPolicyType($policy_type_id, $client_branch_id, $client_id){
$policyCount = $this->clientPolicyModel
->where('policy_type_id', $policy_type_id)
diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php
index a27e1d92..fd79a58b 100644
--- a/app/Views/client_policy.php
+++ b/app/Views/client_policy.php
@@ -40,6 +40,7 @@
+
@@ -259,7 +260,6 @@
tpaValue = item.tpa_short + '-' + item.tpa_branch_code;
}
-
policyTable += `
| ${item.insurer_short} - ${item.insurer_branch_name} |
@@ -316,6 +316,8 @@
$('#policy_form_action').val('= base_url("client/policy/create"); ?>');
$('#policy_status_field').hide()
$('#base_policy_id').hide();
+ $('#policy_PrimaryKey').val("");
+ $('#insurer_policy_id').val("");
$('#first').hide();
@@ -635,6 +637,7 @@
});
+
});
$(document).ready(function() {
@@ -649,28 +652,35 @@
console.log('client_id', client_id)
console.log('branch_id', branch_id)
console.log('policy_type_id', dataId)
+ console.log('client_policy_id', $('#policy_PrimaryKey').val())
+
+
$('#policy_type_id').val(dataId);
- var url = '' + id + '/' + dataId + '/' + branch_id + '/' + client_id
+ var url = '' + dataId + '/' + branch_id + '/' + client_id;
- $.get(url, function(response){
+ if (dataId && branch_id && client_id) { // Check if all parameters exist
+ if ($('#policy_PrimaryKey').val() == "" || id != $('#insurer_policy_id').val()) {
+ $.get(url, function(response) {
+ console.log(response);
+ console.log(response.count);
- console.log(response)
- //console.log(response.data)
+ if (response.count > 0) {
+ console.log('Policy already exist in the branch');
+ toastr.error('Policy already exist in the branch', 'Error');
+ $('#policy').val('').change();
+ }
+ console.log('outer');
- if(response.count > 0){
- console.log('Policy already exist in the branch')
- toastr.error('Policy already exist in the branch', 'Error');
- $('#policy').val('').change();
+ }).fail(function(xhr, status, error) {
+ console.error(xhr.responseText);
+ console.error(status, error);
+ });
}
- console.log('outer')
-
-
- }).fail(function(xhr, status, error) {
- console.error(xhr.responseText);
- console.error(status, error);
- });
+ } else {
+ console.log('Missing parameter(s): dataId, branch_id, or client_id');
+ }
if (dataId == 1) {
@@ -741,7 +751,7 @@
dataType: 'json',
success: function(res) {
- //console.log('client_policy_res', res)
+ console.log('client_policy_res', res)
setTimeout(function() {
$('.loader').fadeOut();
@@ -774,6 +784,7 @@
$('#policy_type_id').val(res.data.policy_type_id);
$('#policy_PrimaryKey').val(res.data.id);
+ $('#insurer_policy_id').val(res.data.policy_id);
$('#policy_no').val(res.data.policy_no);
$('#start_date').val(rearrangeDateFormat(res.data.policy_start_date));
$('#end_date').val(rearrangeDateFormat(res.data.policy_end_date));
@@ -1305,8 +1316,6 @@
});
}
-
-
if ($(this).val() == 3) {
toastr.warning('Please Change the Policy Terms after Submit the Policy!', 'INFO');
}
@@ -1440,54 +1449,58 @@
contentType: false,
success: function(res) {
- //console.log(res)
+ console.log(res)
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 500);
+
+ if(res.status == true){
- $('#insurer').val(res.data.insurer_branch_id + '-' + res.data.insurer_id)
- .change();
- $('#tpa').val(res.data.tpa_branch_id + '-' + res.data.tpa_id).change();
- $('#policy_no').val(res.data.policy_no).change();
- $('#start_date').val(rearrangeDateFormat(res.data.policy_start_date))
- .change();
- $('#end_date').val(rearrangeDateFormat(res.data.policy_end_date)).change();
+ $('#insurer').val(res.data.insurer_branch_id + '-' + res.data.insurer_id)
+ .change();
+ $('#tpa').val(res.data.tpa_branch_id + '-' + res.data.tpa_id).change();
+ $('#policy_no').val(res.data.policy_no).change();
+ $('#start_date').val(rearrangeDateFormat(res.data.policy_start_date))
+ .change();
+ $('#end_date').val(rearrangeDateFormat(res.data.policy_end_date)).change();
- var policeOptionHTML = '';
- $policy_type_value = $('#policy_type').val();
- $.each(res.policy, function(index, item) {
+ var policeOptionHTML = '';
+ $policy_type_value = $('#policy_type').val();
+ $.each(res.policy, function(index, item) {
- // //console.log(item);
+ // //console.log(item);
- policeOptionHTML += '';
+ policeOptionHTML += '';
- });
+ });
- $('#policy').html(policeOptionHTML);
+ $('#policy').html(policeOptionHTML);
- if (dataId == 3 || policy_type == 1) {
+ if (dataId == 3 || policy_type == 1) {
- // //console.log('step 1')
+ // //console.log('step 1')
+
+ setTimeout(function() {
+ // //console.log('step 2')
+ var $option = $('#policy').find('option[data-id="3"]');
+ if ($option.length > 0) {
+ // //console.log('step 3')
+ $option.prop('selected', true).change();
+ } else {
+ // //console.log('step 4');
+ toastr.warning(
+ 'The insurer does not have a GMC-Parents policy.',
+ 'Warning');
+ }
+ }, 1500);
+ }
- setTimeout(function() {
- // //console.log('step 2')
- var $option = $('#policy').find('option[data-id="3"]');
- if ($option.length > 0) {
- // //console.log('step 3')
- $option.prop('selected', true).change();
- } else {
- // //console.log('step 4');
- toastr.warning(
- 'The insurer does not have a GMC-Parents policy.',
- 'Warning');
- }
- }, 1500);
}
},