Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev

This commit is contained in:
VENKATESHWARAN 2026-02-17 10:27:35 +05:30
commit 4532571429
3 changed files with 145 additions and 10 deletions

View File

@ -472,7 +472,7 @@ class LeadsController extends BaseController
// print_r($rules); die;
if (isset($data['lead_form_type']) && (int)$data['lead_form_type'] === 2) {
if ((int)$this->request->getPost('lead_form_type') === 2) {
$rules['client_type'] = [
'rules' => 'required',
'errors' => ['required' => 'Client Type is required']
@ -489,6 +489,51 @@ class LeadsController extends BaseController
'rules' => 'required',
'errors' => ['required' => 'Date of Expiry is required']
];
if ((int)$this->request->getPost('claim_history') === 1) {
$rules['first_year.*'] = [
'rules' => 'required|regex_match[/^\d{4}-\d{4}$/]',
'errors' => ['required' => 'Claim Year is required for all entries.','regex_match' => 'Year must be in format YYYY-YYYY.']
];
$rules['first_policy_type_.*'] = [
'rules' => 'required|regex_match[/^[a-zA-Z0-9_-]+$/]',
'errors' => ['required' => 'Policy Type is required in Claim History.',
'regex_match' => 'Policy Type only letters, numbers, space, hyphens and underscores are allowed'
]
];
$rules['first_date_of_loss_.*'] = [
'rules' => 'required|regex_match[/^[0-9]{2}-[0-9]{2}-[0-9]{4}$/]',
'errors' => ['required' => 'Date of Loss is required.',
'regex_match' => 'Date of Loss must be inValid format.']
];
$rules['first_cause_of_loss.*'] = [
'rules' => 'required|regex_match[/^[a-zA-Z0-9\s_-]+$/]',
'errors' => [
'required' => 'Cause of Loss is required.',
'regex_match' => 'Cause of Loss only letters, numbers, space, hyphens and underscores are allowed'
]
];
$rules['first_claim_amount.*'] = [
'rules' => 'required|numeric',
'errors' => [
'required' => 'Claim Amount is required.',
'numeric' => 'Claim Amount must be a number.'
]
];
$rules['first_settled_amount.*'] = [
'rules' => 'required|numeric',
'errors' => ['required' => 'Settled Amount is required.',
'numeric' => 'Settled Amount must be a number.']
];
$rules['first_claim_status.*'] = [
'rules' => 'required|alpha_space',
'errors' => [
'required' => 'Claim Status is required.',
'alpha_space' => 'Claim Status should only contain letters and spaces.'
]
];
}
}
// 1. MANUALLY VALIDATE FILES BEFORE PROCESSING
@ -523,7 +568,41 @@ class LeadsController extends BaseController
// }
// }
if (!$this->validate($rules)) {
$isValid = $this->validate($rules);
$start_dates = $this->request->getPost('policy_start_date');
$end_dates = $this->request->getPost('policy_end_date');
if ($start_dates && $end_dates) {
$starts = is_array($start_dates) ? $start_dates : [$start_dates];
$ends = is_array($end_dates) ? $end_dates : [$end_dates];
foreach ($starts as $index => $s_date) {
$e_date = $ends[$index] ?? null;
if ($s_date && $e_date) {
$f_start = change_date_format($s_date, 'd/m/Y', 'Y-m-d');
$f_end = change_date_format($e_date, 'd/m/Y', 'Y-m-d');
if ($f_start && $f_end && ($f_end < $f_start)) {
$isValid = false;
// Determine the error key name
// If it's an array, we use index (e.g., policy_end_date.0)
$errorKey = is_array($start_dates) ? "policy_end_date.$index" : "policy_end_date";
$this->validator->setError($errorKey, 'Date of Expiry cannot be before Date of Commencement.');
}
}
}
}
if (!$isValid) {
return $this->response->setStatusCode(400)->setJSON([
'status' => false,
'message' => 'Input validation failed',

View File

@ -1052,7 +1052,47 @@ class PolicyTransactionController extends BaseController
'exp_amt.*' => ['label' => 'Expected Amount', 'rules' => 'permit_empty|decimal', 'errors' => ['decimal' => 'The Expected Amount field must contain a valid number.']]
];
if (!$this->validate($rules)) {
$isValid = $this->validate($rules);
// $Date_of_commencement = $this->request->getPost('policy_start_date');
// $Date_of_expiry = $this->request->getPost('policy_end_date');
// if ($Date_of_commencement && $Date_of_expiry && ($Date_of_expiry < $Date_of_commencement)) {
// $this->validator->setError('policy_end_date', '$Date of Commencement and Date of Expiry are mismatched (Date of Expiry cannot be before $Date of Commencement).');
// $isValid = false;
// }
$start_dates = $this->request->getPost('policy_start_date');
$end_dates = $this->request->getPost('policy_end_date');
if ($start_dates && $end_dates) {
// Standardize: If it's a single string (Type 2), wrap it in an array
$starts = is_array($start_dates) ? $start_dates : [$start_dates];
$ends = is_array($end_dates) ? $end_dates : [$end_dates];
foreach ($starts as $index => $s_date) {
$e_date = $ends[$index] ?? null;
if ($s_date && $e_date) {
$f_start = change_date_format($s_date, 'Y-m-d', 'Y-m-d'); // be carefully here we made so many times mistakes on here
$f_end = change_date_format($e_date, 'Y-m-d', 'Y-m-d');// be carefully here we made so many times mistakes on here
if ($f_start && $f_end && ($f_end < $f_start)) {
$isValid = false;
// Determine the error key name
// If it's an array, we use index (e.g., policy_end_date.0)
$errorKey = is_array($start_dates) ? "policy_end_date.$index" : "policy_end_date";
$this->validator->setError($errorKey, 'D.O.E(Date of Expiry) cannot be before D.O.C(Date of Commencement).');
}
}
}
}
if (!$isValid) {
return $this->response->setStatusCode(400)->setJSON([
'status' => false,
'message' => 'Input validation failed',

View File

@ -1027,7 +1027,7 @@
<div class="form-group col-md-2">
<label for="first_year_${increment}">Year<span class="text-danger">*</span></label>
<select class="form-control first_year_" id="first_year_${increment}" name="first_year[]">
<select class="form-control claim-input first_year_" id="first_year_${increment}" name="first_year[]">
<option value="">Select Year</option>
<?php foreach ($lastFiveYears as $year) {
echo "<option value='$year'>$year</option>";
@ -1036,27 +1036,27 @@
</div>
<div class="form-group col-md-2">
<label for="first_policy_type_${increment}">Policy Type<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_policy_type_${increment}" name="first_policy_type_[]">
<input type="text" class="form-control claim-input" id="first_policy_type_${increment}" name="first_policy_type_[]">
</div>
<div class="form-group col-md-2">
<label for="first_date_of_loss_${increment}">Date of Loss<span class="text-danger">*</span></label>
<input type="text" class="form-control loss_date" id="first_date_of_loss_${increment}" name="first_date_of_loss_[]">
<input type="text" class="form-control loss_date claim-input" id="first_date_of_loss_${increment}" name="first_date_of_loss_[]">
</div>
<div class="form-group col-md-2">
<label for="first_cause_of_death_${increment}">Cause Of Loss <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_cause_of_loss_${increment}" name="first_cause_of_loss[]">
<input type="text" class="form-control claim-input" id="first_cause_of_loss_${increment}" name="first_cause_of_loss[]">
</div>
<div class="form-group col-md-2">
<label for="first_claim_amount_${increment}">Claim Amount<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_claim_amount_${increment}" name="first_claim_amount[]">
<input type="text" class="form-control claim-input" id="first_claim_amount_${increment}" name="first_claim_amount[]">
</div>
<div class="form-group col-md-2">
<label for="first_claim_amount_${increment}">Settled Amount<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_settled_amount_${increment}" name="first_settled_amount[]">
<input type="text" class="form-control claim-input" id="first_settled_amount_${increment}" name="first_settled_amount[]">
</div>
<div class="form-group col-md-2">
<label for="first_claim_status_${increment}">Claim Status<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_claim_status_${increment}" name="first_claim_status[]">
<input type="text" class="form-control claim-input" id="first_claim_status_${increment}" name="first_claim_status[]">
</div>
<div class="form-group col-md-2">
<div class="" style="position: relative; top: 28px; float: right; text-align: end;">
@ -1072,6 +1072,16 @@
referenceDiv.insertAdjacentHTML('beforeend', claimsFields);
let isChecked = $("#claim_history").length > 0 ? $("#claim_history").prop("checked") : true;
let lastRow = $(".claim-row").last();
if (isChecked) {
lastRow.show();
lastRow.find(".claim-input").attr("required", true);
} else {
lastRow.hide();
lastRow.find(".claim-input").removeAttr("required");
}
// Increment claim index
increment = increment + 1;
@ -1143,9 +1153,15 @@
// No rows yet, so create them
appendThreeYearsClaims();
}
$(".claim-input").attr("required", true);
} else {
$(".claim-row").hide();
$(".claim-input").removeAttr("required"); // Required Attributes Remove
$(".claim-input").val(""); // Value Reset
$(".claim-input").each(function() {
$(this).parsley().reset(); // Validation Reset
});
}
}