diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php
index 466a5cb3..f974bb37 100644
--- a/app/Controllers/ClientController.php
+++ b/app/Controllers/ClientController.php
@@ -418,12 +418,12 @@ class ClientController extends AdminController
$data['client_id'] = $this->request->getPost('client_id');
- $data['insured'] = $this->request->getPost('insured');
$data['no_of_lives'] = $this->request->getPost('no_of_lives');
$data['policy_status'] = $this->request->getPost('policy_status');
$data['no_of_employees'] = $this->request->getPost('no_of_employees');
$data['earned_premium_date'] = change_date_format($this->request->getPost('earned_premium_date'), 'd-m-Y', 'Y-m-d');
- $data['claims_incurred_date'] = change_date_format($this->request->getPost('claims_incurred_date'), 'd-m-Y', 'Y-m-d'); $data['incurred_claims_ratio'] = $this->request->getPost('incurred_claims_ratio');
+ $data['claims_incurred_date'] = change_date_format($this->request->getPost('claims_incurred_date'), 'd-m-Y', 'Y-m-d');
+ $data['incurred_claims_ratio'] = $this->request->getPost('incurred_claims_ratio');
$data['no_lives_at_inception'] = $this->request->getPost('no_lives_at_inception');
$data['premium_paid_at_inception'] = $this->request->getPost('premium_paid_at_inception');
$data['claims_experience_for_last_3_years'] = $this->request->getPost('claims_experience_for_last_3_years');
@@ -629,7 +629,7 @@ class ClientController extends AdminController
$client_policy_data = $this->clientPolicyModel->where(['id' => $id, 'is_active' => 1])->first();
$insurer_id = $client_policy_data['insurer_id'];
$polices = $this->policesModel->where(['insurer_id' => $insurer_id, 'is_active' => 1])->findAll();
- echo json_encode(array("status" => true , 'data' => $client_policy_data, 'policy' => $polices));
+ echo json_encode(array("insurer_id" => $client_policy_data['insurer_id'], "status" => true , 'data' => $client_policy_data, 'policy' => $polices));
}else{
echo json_encode(array("status" => false));
}
diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php
index 4ce12fb1..ef70ef5b 100644
--- a/app/Models/ClientPolicyModel.php
+++ b/app/Models/ClientPolicyModel.php
@@ -16,6 +16,8 @@ class ClientPolicyModel extends Model
"insurer_branch_id",
"tpa_id",
"tpa_branch_id",
+ "policy_type_id",
+
"policy_start_date",
"policy_end_date",
diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php
index 0d55acc5..ee9df7cf 100644
--- a/app/Views/client_policy.php
+++ b/app/Views/client_policy.php
@@ -38,7 +38,7 @@
-
+
@@ -115,20 +115,34 @@ var policy_client = $('#policy_PrimaryKey').val();
$(document).ready(function () {
- //Configure Flatpicker for the policy start date datepicker.
- flatpickr("#start_date", {
+ // Get today's date
+ var today = new Date();
+
+ // Initialize Flatpickr for the start date with today's date
+ var startDatePicker = flatpickr("#start_date", {
dateFormat: "d-m-Y",
- defaultDate: "today",
+ defaultDate: today,
allowInput: false,
+ onChange: function(selectedDates, dateStr, instance) {
+ var endDate = new Date(selectedDates[0]);
+ endDate.setFullYear(endDate.getFullYear() + 1);
+
+ endDatePicker.setDate(endDate);
+ }
});
- //Configure Flatpicker for the policy end date datepicker.
- flatpickr("#end_date", {
+ // Calculate the end date (today + 1 year)
+ var endDate = new Date(today);
+ endDate.setFullYear(endDate.getFullYear() + 1);
+
+ // Initialize Flatpickr for the end date with the calculated end date
+ var endDatePicker = flatpickr("#end_date", {
dateFormat: "d-m-Y",
- defaultDate: "today",
+ defaultDate: endDate,
allowInput: false
});
+
$('#add_form').hide();
$('.btnBack').hide();
@@ -188,79 +202,81 @@ $(document).ready(function () {
//for form submit using AJAX
$("#policy_form").submit(function(event) {
-event.preventDefault();
+ event.preventDefault();
- policy_PrimaryKey = $('#client_id_policy').val();
- policy_client = $('#policy_PrimaryKey').val();
+ policy_PrimaryKey = $('#client_id_policy').val();
+ policy_client = $('#policy_PrimaryKey').val();
-if (policy_PrimaryKey === '' && policy_client === '') {
- toastr.error('Client is required', 'Error');
- $('#insurer').val('');
- $('#tpa').val('');
- $('#policy').html('
');
- return;
-}
-
-var isValid = $('#policy_form').parsley().validate();
-if (!isValid) {
- console.log('Form is Empty', 'Warning');
- return ;
-}
-
-var formData = new FormData($('#policy_form')[0]);
-var policy_form_action = $('#policy_form_action').val();
-
-$.ajax({
- data: formData,
- url: policy_form_action,
- type: "POST",
- dataType: 'json',
- processData: false,
- contentType: false,
- success: function(res) {
-
- if (res.status === false) {
- toastr.error('Policy Dose Not Create', 'Error');
- return;
+ if (policy_PrimaryKey === '' && policy_client === '') {
+ toastr.error('Client is required', 'Error');
+ $('#insurer').val('');
+ $('#tpa').val('');
+ $('#policy').html('
');
+ return;
}
- console.log(res);
- var message = (policy_PrimaryKey === '') ? 'Policy Created successfully' : 'Policy Updated Successfully';
- toastr.success(message, 'Success');
+ var isValid = $('#policy_form').parsley().validate();
+ if (!isValid) {
+ console.log('Form is Empty', 'Warning');
+ return ;
+ }
- $('#policy_table tr').remove();
- var policyTable = '';
- $.each(res.data, function(index, item) {
- policyTable += `
-
- | ${item.insurer_short} - ${item.insurer_branch_name} |
- ${item.policy_name} |
- ${item.tpa_short} - ${item.tpa_branch_code} |
-
-
-
- |
-
- `;
+ var formData = new FormData($('#policy_form')[0]);
+ var policy_form_action = $('#policy_form_action').val();
+
+ $.ajax({
+ data: formData,
+ url: policy_form_action,
+ type: "POST",
+ dataType: 'json',
+ processData: false,
+ contentType: false,
+ success: function(res) {
+
+ if (res.status === false) {
+ toastr.error('Policy Dose Not Create', 'Error');
+ return;
+ }
+
+ console.log(res);
+ var message = (policy_PrimaryKey === '') ? 'Policy Created successfully' : 'Policy Updated Successfully';
+ toastr.success(message, 'Success');
+
+ $('#policy_table tr').remove();
+ var policyTable = '';
+ $.each(res.data, function(index, item) {
+ policyTable += `
+
+ | ${item.insurer_short} - ${item.insurer_branch_name} |
+ ${item.policy_name} |
+ ${item.tpa_short} - ${item.tpa_branch_code} |
+
+
+
+ |
+
+ `;
+ });
+ $('#policy_table').append(policyTable);
+ $('#add_form').hide();
+ $('#table_list').show();
+ $('.btnBack').hide();
+ $('.btnAdd').show();
+ },
+ error: function(xhr, status, error) {
+ console.error(xhr.responseText);
+ console.error(status, error);
+ }
});
- $('#policy_table').append(policyTable);
- $('#add_form').hide();
- $('#table_list').show();
- $('.btnBack').hide();
- $('.btnAdd').show();
- },
- error: function(xhr, status, error) {
- console.error(xhr.responseText);
- console.error(status, error);
- }
-});
-});
+ });
//To get th POLICY base on Insurer
$('#insurer').change(function() {
var id = $(this).val();
- var url = "= base_url("util/police-by-insurer/") ?>" + id;
+ var parts = id.split('-');
+ var secondPart = parts[1];
+ var url = "= base_url("util/police-by-insurer/") ?>" + secondPart;
$.get(url, function(res) {
res = JSON.parse(res)
@@ -281,13 +297,17 @@ $.ajax({
// set the Policy_Type_id for Form Submit
$('#policy').change(function(){
+
var dataId = $(this).children('option:selected').attr('data-id');
+ console.log('dataId', dataId)
$('#policy_type_id').val(dataId);
if(dataId == 1){
- appendPolicyFormFields(1)
- }else{
- appendPolicyFormFields(2)
+ appendPolicyFormFields(1);
+ }else if (dataId >= 1){
+ appendPolicyFormFields(2);
}
+
+ console.log('second', $('#policy_type_id').val());
});
@@ -295,16 +315,18 @@ $.ajax({
$('body').on('click', '.btnPolicyEdit', function () {
var policy_form_action = '';
- var policy_id = $(this).data('id');
- console.log('1', policy_id)
- var policyId = $(this).attr('data-id');
- console.log('2', policyId)
+ // var policy_id = $(this).data('id');
+ // console.log('1', policy_id)
+ var policy_id = $(this).attr('data-id');
+ console.log('2', policy_id)
$.ajax({
url: '= base_url("client/policy/list/") ?>' + policy_id,
type: "GET",
dataType: 'json',
success: function (res) {
+
+ console.log(res);
$('#policy_form_action').val('= base_url("client/policy/edit"); ?>');
@@ -328,12 +350,13 @@ $.ajax({
if(res.data.policy_type_id == 1){
appendPolicyFormFields(1, res.data);
- }else {
+ }else if(res.data.policy_type_id >= 2) {
appendPolicyFormFields(2, res.data);
}
var policeOptionHTML = '';
$.each(res.policy, function(index, item) {
+ console.log(item)
policeOptionHTML += '
';
});
$('#policy').html(policeOptionHTML);
@@ -345,7 +368,6 @@ $.ajax({
});
});
-
function appendPolicyFormFields(policy_type, data = false){
var html = '';
@@ -358,24 +380,6 @@ $.ajax({
html = `