CHANGE_ROLL_OVER_TO_FRESH_TYPE_HANDLE

This commit is contained in:
VENKATESHWARAN 2026-04-17 16:33:19 +05:30
parent 6cb08ad32e
commit 88b60780b8
3 changed files with 37 additions and 71 deletions

View File

@ -447,7 +447,7 @@ class LeadsController extends BaseController
],
];
if (isset($postData['lead_type']) && $postData['lead_type'] == 1) {
if (isset($postData['lead_type']) && in_array((int) $postData['lead_type'], [1, 3], true)) {
$rules['entity_type_id'] = [
'rules' => 'required',
@ -659,14 +659,7 @@ class LeadsController extends BaseController
$request_data = $this->request->getPost();
$data = sanitizeInputArrayAdvanced($request_data);
$data['client_type'] = 1;
$actual_lead_id = $data['actual_lead_id'] ?? null; // adjust to however you get this
$isType1Flow = $data['lead_type'] == 1 || (!empty($actual_lead_id) && $actual_lead_id != 0 && $data['lead_type'] == 3);
// if ($data['lead_type'] != 1)
if (!$isType1Flow) {
// lead_type != 1 (and not the special type-3 override) → fetch client data
if (! in_array((int) $data['lead_type'], [1, 3], true)) {
$client_data = $this->clientModel->where('id', $data['client_id'])->where('is_active', 1)->first();
$data['client_name'] = $client_data['client_name'];
$data['client_short_name'] = $client_data['short_name'];
@ -957,15 +950,10 @@ class LeadsController extends BaseController
$insertCount[] = $insert;
$this->insertLeadStatus($insert, $value['status'], 3);
$actual_lead_id = $value['actual_lead_id'] ?? null;
$isType1Flow = $value['lead_type'] == 1
|| (! empty($actual_lead_id) && $actual_lead_id != 0 && $value['lead_type'] == 3);
if ($isType1Flow && $value['status'] == 'won') {
$leadDataForClient = $this->leadsModel->find($insert);
$this->createClientWithLeadData($leadDataForClient);
}
if (in_array((int) $value['lead_type'], [1, 3], true) && $value['status'] == 'won') {
$leadDataForClient = $this->leadsModel->find($insert);
$this->createClientWithLeadData($leadDataForClient);
}
if ($value['lead_form_type'] == 1) {
//for this push the job to the calculateMembersDemography() function
@ -990,16 +978,10 @@ class LeadsController extends BaseController
{
if ($this->leadsModel->where('id', $id)->set($data[0])->update()) {
// Define these FIRST before using them
$actual_lead_id = $data[0]['actual_lead_id'] ?? null;
$isType1Flow = $data[0]['lead_type'] == 1
|| (!empty($actual_lead_id) && $actual_lead_id != 0 && $data[0]['lead_type'] == 3);
$this->insertMultiFilesData($data[0]['multi_file_data'], $id, $data[0]['lead_form_type']);
$this->insertLeadStatus($id, $data[0]['status'], 3);
if ($isType1Flow && $data[0]['status'] == 'won') {
if (in_array((int) $data[0]['lead_type'], [1, 3], true) && $data[0]['status'] == 'won') {
$leadDataForClient = $this->leadsModel->find($id);
if (empty($leadDataForClient['is_client_created'])) {
$this->createClientWithLeadData($leadDataForClient);
@ -1420,7 +1402,7 @@ class LeadsController extends BaseController
}
// 4. Conditional query - only fetch if needed
if ($lead_data['lead_type'] != 1) {
if (! in_array((int) $lead_data['lead_type'], [1, 3], true)) {
$client_policy_data = $this->clientPolicyModel
->select('policy_terms, placement_json')
->where('is_active', 1)
@ -2183,7 +2165,7 @@ class LeadsController extends BaseController
} // dd($data);
$lead_data = [];
if ($rfq_data['lead_type'] == 1) {
if (in_array((int) $rfq_data['lead_type'], [1, 3], true)) {
if (in_array($rfq_data['policy_type_id'], [2, 3, 4, 5])) {
$lead_data = [
@ -4860,7 +4842,7 @@ class LeadsController extends BaseController
$data['lead_edit_data']['multi_file_html'] = trim($html) !== '' ? $html : null;
}
if ($data['lead_edit_data']['lead_type'] != 1 && $data['lead_edit_data']['lead_form_type'] == 2) {
if (! in_array((int) $data['lead_edit_data']['lead_type'], [1, 3], true) && $data['lead_edit_data']['lead_form_type'] == 2) {
$data['lead_edit_data']['claims_details_html'] = view('rfq/claims_details_non_eb', $data['lead_edit_data']);
} else {
$data['lead_edit_data']['claims_details_html'] = "";

View File

@ -541,8 +541,8 @@
var lead_type = $(this).val();
var increment = 1; // Example increment value (modify as needed)
var start_date_id = lead_type == "1" ? `policy_start_date_${increment}` : "policy_start_date";
var end_date_id = lead_type == "1" ? `policy_end_date_${increment}` : "policy_end_date";
var start_date_id = (lead_type == "1" || lead_type == "3") ? `policy_start_date_${increment}` : "policy_start_date";
var end_date_id = (lead_type == "1" || lead_type == "3") ? `policy_end_date_${increment}` : "policy_end_date";
$(".policy_start_date").attr("id", start_date_id);
// $("label[for]").attr("for", start_date_id);
@ -553,7 +553,7 @@
// $('#leads_form_id')[0].reset();
// console.log("Updated ID:", newId);
if (lead_type == 1) {
if (lead_type == 1 || lead_type == 3) {
var policy_start_datePicker = flatpickr("#policy_start_date_" + increment, {
dateFormat: "d/m/Y",
@ -585,32 +585,7 @@
// }
}
});
} else if (lead_type == 3) {
if ($('#client_id option[value="add_client"]').length === 0) {
$('#client_id').prepend($('<option>', {
value: 'add_client',
text: '+ Add Client'
}));
}
$("#source_policy_id").removeAttr("required");
$("#source_policy_id").closest("div").find("label .text-danger").remove();
$("#source_policy_id").hide();
$('#source_policy_id').closest('.form-group').hide();
$("#source_policy_start_date").removeAttr("required");
$("#source_policy_start_date").closest("div").find("label .text-danger").remove();
$("#source_policy_start_date").hide();
$('#source_policy_start_date').closest('.form-group').hide();
$("#source_policy_end_date").removeAttr("required");
$("#source_policy_end_date").closest("div").find("label .text-danger").remove();
$("#source_policy_end_date").hide();
$('#source_policy_end_date').closest('.form-group').hide();
} else if (lead_type != 3) {
} else if (lead_type != 1 && lead_type != 3) {
$("#source_policy_id").prop("required", true);
$("#source_policy_start_date").prop("required", true);
$("#source_policy_end_date").prop("required", true);
@ -649,7 +624,7 @@
}
if (lead_type != 1) {
if (lead_type != 1 && lead_type != 3) {
dataIncrement = 1;
// updateRenewalFields(dataIncrement);
@ -757,7 +732,7 @@
leadTypeBsedHideAndShow(lead_type)
if (lead_type == 1) {
if (lead_type == 1 || lead_type == 3) {
$('.claim-row').hide();
@ -835,8 +810,19 @@
$('#lost_reason').val(res.data.lost_reason || '');
$('#notes').val(res.data.notes);
let existingClientId = res.data.client_id || res.data.is_client_created || 0;
console.log('existingClientId', existingClientId);
if (lead_type == 3) {
if (existingClientId && existingClientId != 0) {
$('#exixting_client').prop('checked', true).trigger('change');
} else {
$('#exixting_client').prop('checked', false).trigger('change');
}
}
setTimeout(function() {
$('#client_id').val(res.data.client_id).change();
$('#client_id').val(existingClientId).change();
setTimeout(function() {
$('#client_branch_id').val(res.data.client_branch_id).change();
setTimeout(function() {
@ -1132,7 +1118,7 @@
leadTypeBsedHideAndShow(lead_type)
if (lead_type == 1) {
if (lead_type == 1 || lead_type == 3) {
$('.claim-row').hide();
@ -1148,7 +1134,7 @@
$('.lifeClaimFields').show();
} else {
if (lead_type == 1) {
if (lead_type == 1 || lead_type == 3) {
updateRenewalFields(dataIncrement);
}
@ -1352,7 +1338,7 @@
// $(".policy_end_date").attr("id", end_date_id);
// Initialize date pickers
if (lead_type == 1) {
if (lead_type == 1 || lead_type == 3) {
var policy_start_datePicker = flatpickr("#policy_start_date_" + increment, {
dateFormat: "d/m/Y",
@ -1566,7 +1552,7 @@
console.log('Lead Type:', lead_type);
let increment = input.id.split('_').pop(); // Extract increment
if (lead_type == 1) {
if (lead_type == 1 || lead_type == 3) {
return;
}
@ -1684,7 +1670,7 @@
var lead_type = $('#lead_type').val();
if (lead_type == 1) {
if (lead_type == 1 || lead_type == 3) {
let formRow = input.closest('.form-row');
@ -1857,7 +1843,7 @@
let value = $(this).val()
leadTypeBsedHideAndShow(value, true)
if (value != 1) {
if (value != 1 && value != 3) {
removeExtraForms();
}
@ -2302,9 +2288,7 @@
function leadTypeBsedHideAndShow(value, resetValues = false) {
var actual_lead_id = $('#actual_lead_id').val();
if (value == 1 || (actual_lead_id && actual_lead_id != 0 && value == 3)) {
if (value == 1 || value == 3) {
$('.btnDiv').show();
$('.claim-row').hide();

View File

@ -839,7 +839,7 @@ if (isset($selected_lead_type)) {
$('.loader-mask').fadeIn();
if (lead_type == 1) {
if (lead_type == 1 || lead_type == 3) {
$('.claim-row').hide();
if(data.is_client_created == null || data.is_client_created == 0 || data.is_client_created == ""){
@ -1088,7 +1088,7 @@ if (isset($selected_lead_type)) {
temp_client_id = data.client_id
}
if(lead_type == 1){
if(lead_type == 1 || lead_type == 3){
if(data.is_client_created == null || data.is_client_created == 0 || data.is_client_created == ""){
$('#exixting_client').prop('checked', false);