Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
velz 2024-11-28 18:11:04 +05:30
commit dcf9ef5316
12 changed files with 644 additions and 97 deletions

View File

@ -21,6 +21,7 @@ $routes->get("view", "EmployeeController::viewECard/$1");
// $routes->get("exportQCRandRFQ", "LeadsController::exportQCRandRFQ");
$routes->get("smapletest", "ClientController::smapletest");
$routes->get("testMailAttachments", "ClientController::testMailAttachments");
$routes->get("updatePolicyTermsKey", "ClientController::updatePolicyTermsKey");
$routes->post("add_advertise_image", "AppContentManagementController::add_advertise_image");
$routes->get("add_image_index", "AppContentManagementController::add_image_index");
@ -314,6 +315,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
$routes->get('log_list', 'EmployeeController::listLogs');
$routes->get('view_log/(:any)', 'EmployeeController::viewLog/$1');
$routes->get('download_log/(:any)', 'EmployeeController::downloadLog/$1');
$routes->post('checkDuplicateTableFieldValue', 'ClientController::checkDuplicateTableFieldValue');
});
$routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) {
@ -323,6 +325,7 @@ $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) {
$routes->post("create", "PolicyTransactionController::createInceptionPolicy");
$routes->get("list/(:any)", "PolicyTransactionController::getInceptionDataForEdit/$1");
$routes->get("remove/(:any)", "PolicyTransactionController::removeCDMaster/$1");
$routes->get("removePolicyTransaction/(:any)", "PolicyTransactionController::removePolicyTransaction/$1");
});
$routes->group("endorsement", ["filter" => "authMVC"], function ($routes) {

View File

@ -118,6 +118,23 @@ class ClientController extends AdminController
$this->leadsModel = new LeadsModel();
}
public function checkDuplicateTableFieldValue()
{
$table = $this->request->getPost('table');
$field = $this->request->getPost('field');
$value = $this->request->getPost('value');
// Load the database if not already loaded
$db = db_connect();
// Perform the query
$builder = $db->table($table);
$isDuplicate = $builder->where($field, $value)->countAllResults() > 0;
// Return the result
return $this->response->setJSON(['isDuplicate' => $isDuplicate]);
}
public function smapletest()
{
$headers = [
@ -3562,4 +3579,84 @@ class ClientController extends AdminController
dd($result);
}
public function updatePolicyTermsKey()
{
$data = $this->clientPolicyModel
->where("policy_terms IS NOT NULL AND policy_terms <> ''")
->where('policy_type_id', 2)
->where('is_active', 1)
->findAll();
for ($i = 0; $i < count($data); $i++) {
if (isset($data[$i]['policy_terms']) && !empty($data[$i]['policy_terms'])) {
$policyTerms = json_decode($data[$i]['policy_terms'], true);
} else {
continue;
}
// Set default value of copayzonewisecopay to "empty"
$ans = isset($policyTerms['copayzonewisecopay']) ? $policyTerms['copayzonewisecopay'] : 'empty';
// Initialize an empty array for the ordered policy terms
$orderedPolicyTerms = [];
// Add copayzonewisecopay and copayzonewisecopaydata if they exist_
if (isset($policyTerms['copayzonewisecopay'])) {
if(!isset($policyTerms['co_pay_details'])){
$co_pay_details_value = "";
if (strtolower($ans) == "nil" || $ans == 0) {
$policyTerms['copayzonewisecopay'] = 0;
$co_pay_details_value = "";
} elseif ($ans != 'empty' && $ans !== 'Nil' && $ans !== null && $ans != '' && $ans != 0) {
$policyTerms['copayzonewisecopay'] = 1;
$co_pay_details_value = $ans;
}
$co_pay_index = array_search('copayzonewisecopay', array_keys($policyTerms));
$orderedPolicyTerms[] = [
"key" => "co_pay_details",
"value" => $co_pay_details_value,
"position" => $co_pay_index + 1,
];
unset($policyTerms['optionalparentalcopay']);
}
}
// Add ailmentcapping and ailmentcappingdata if they exist_
if (isset($policyTerms['ailmentcapping'])) {
if(!isset($policyTerms['ailment_capping_details'])){
$aliment_index = array_search('ailmentcapping', array_keys($policyTerms));
$orderedPolicyTerms[] = [
"key" => "ailment_capping_details",
"value" => "",
"position" => $aliment_index + 2,
];
}
}
foreach ($orderedPolicyTerms as $term) {
$position = $term['position'];
$key = $term['key'];
$value = $term['value']; // Insert the key-value pair at the specified index
$policyTerms = array_merge(
array_slice($policyTerms, 0, $position, true),
[$key => $value],
array_slice($policyTerms, $position, null, true)
);
}
// Re-encode the ordered policy terms
$updatedPolicyTerms = json_encode($policyTerms);
// dd($orderedPolicyTerms, $updatedPolicyTerms);
$this->clientPolicyModel->update($data[$i]['id'], ['policy_terms' => $updatedPolicyTerms]);
}
}
}

View File

@ -734,11 +734,16 @@ class EmployeeController extends AdminController
employees.emp_status, auth_history.user_type')
->join('employees', $client_id .'= employees.client_id AND ' . $branch_id . '= employees.client_branch_id', 'left')
->join('auth_history', 'employees.id = auth_history.user_id AND "employee" = auth_history.user_type', 'left')
->where('employees.is_active', 1)
->where('employees.emp_status !=', 'truncated')
->groupBy('employees.id')
->findAll();
$groupedData = [];
$employeeId = '';
foreach ($results as $row) {
if($employeeId != $row['employee_id']){
$employeeId = $row['employee_id'];
}else{
@ -751,7 +756,8 @@ class EmployeeController extends AdminController
$employeeUserType = $row['user_type'];
if ($employeeId !== null && $employeeRelationship == 'Self') {
// if ($employeeId !== null && $employeeRelationship == 'Self') {
if ($employeeId !== null) {
// Append employee info to the branch's employees list
$groupedData[] = [
'employee_id' => $employeeId,

View File

@ -695,6 +695,7 @@ class EmployeeRestController extends AdminController
$decodedPayload = json_decode(base64_decode(explode('.', $token)[1]), true);
// get the employee id from token
$employee_id = $decodedPayload['id'];
// $employee_id = 1;
$client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->where('client_branch_id', $client_branch_id)->first();
if ($client_policy) {
$policy = $this->policesModel->where('id', $client_policy['policy_id'])->first();
@ -875,7 +876,10 @@ class EmployeeRestController extends AdminController
$basic_cover_si[]= $basic_cover_si_value;
}
}
$count = 0;
$wholeData=[];// Initialize an empty array to store employee email.
for ($a=0; $a <count($dataToInsert) ; $a++)
{
$date_coverage = $dataToInsert[$a]['date_coverage'];
@ -949,7 +953,7 @@ class EmployeeRestController extends AdminController
if (isset($notification) && $notification['enabled'] == 1 && !empty($notification['mail_content'])) {
//trigger
$wholeData=[];
// $wholeData=[];
if ($dataToInsert[$a]['relationship'] == 'Self' && isset($dataToInsert[$a]['email_corporate']) && !empty($dataToInsert[$a]['email_corporate'])) {
$params['dataToInsert'] = $dataToInsert[$a];
@ -959,20 +963,33 @@ class EmployeeRestController extends AdminController
$wholeData[] = sendMailNotification::sendMailNotification('member_welcome_mail', $params);
$count++;
}
if($count == 20 || $a == count($dataToInsert)-1){
if (count($wholeData) > 0) {
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $wholeData]);
$wholeData = [];
$count = 0;
}
}
// if($count == 20 || $a == count($dataToInsert)-1){
// if (count($wholeData) > 0) {
// $job_details = new Jobs();
// $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $wholeData]);
// $wholeData = [];
// $count = 0;
// }
// }
// if ($dataToInsert[$a]['email_corporate'] != null || $dataToInsert[$a]['email_corporate'] != '' && $dataToInsert[$a]['relationship'] == 'Self') {
}
}
// for bulk mail queue job push
if (!empty($wholeData) && count($wholeData) > 0) {
$wholeData = array_chunk($wholeData, 20);
foreach ($wholeData as $key => $value) {
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $value]);
}
}
$this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => '','error_data' => ''])->update();
return $this->respond(['status' => 'success', 'code' => 200, 'message' => "Success" ], 200);
}else{
@ -2502,7 +2519,7 @@ class EmployeeRestController extends AdminController
public function storeFireBase()
{
// try {
try {
$json = $this->request->getJSON();
$firebase_token = $json->firebase_token;
$mobile = $json->mobile;
@ -2548,39 +2565,39 @@ class EmployeeRestController extends AdminController
} else {
return $this->respond(['status' => 'failed', 'code' => 404, 'message' => 'Employee not found'], 404);
}
// } catch (\Throwable $th) {
// log_message('error', 'An error occurred: ' . $th->getMessage());
// return $this->respond(['status' => 'failed', 'code' => 500, 'message' => 'An error occurred', 'error' => $th->getMessage()], 500);
// }
}
public function sendPushNotification()
{
$deviceToken = 'cMVKESh8QzqIl8nh_yqbcl:APA91bHKm87Sh1goVJNKZtctV4etgLMQboI0eyDVn3MH1yf9cO-2RtQRlFnKLdataOxosoxm7a4JvATKjfI1_Bids46mGw5m8zesp90mR4odCbD_cJtGmBeMYt4hssSY0YtAht1emK_H';
$title = 'Nhance';
$body = 'All your policy enrolled successfully ..!';
// Initialize Firebase with the service account
$firebase = (new Factory)
->withServiceAccount(APPPATH . 'Config/google-services.json')
->createMessaging();
$notification = Notification::create($title, $body);
$message = CloudMessage::withTarget('token', $deviceToken)
->withNotification($notification);
try {
$firebase->send($message);
return $this->response->setJSON(['status' => 'success']);
} catch (MessagingException $e) {
//return $this->response->setJSON(['status' => 'error', 'message' => $e->getMessage()]);
log_message('error', $e->getMessage());
} catch (\Throwable $th) {
log_message('error', 'An error occurred: ' . $th->getMessage());
return $this->respond(['status' => 'failed', 'code' => 500, 'message' => 'An error occurred', 'error' => $th->getMessage()], 500);
}
}
// public function sendPushNotification()
// {
// $deviceToken = 'cMVKESh8QzqIl8nh_yqbcl:APA91bHKm87Sh1goVJNKZtctV4etgLMQboI0eyDVn3MH1yf9cO-2RtQRlFnKLdataOxosoxm7a4JvATKjfI1_Bids46mGw5m8zesp90mR4odCbD_cJtGmBeMYt4hssSY0YtAht1emK_H';
// $title = 'Nhance';
// $body = 'All your policy enrolled successfully ..!';
// // Initialize Firebase with the service account
// $firebase = (new Factory)
// ->withServiceAccount(APPPATH . 'Config/google-services.json')
// ->createMessaging();
// $notification = Notification::create($title, $body);
// $message = CloudMessage::withTarget('token', $deviceToken)
// ->withNotification($notification);
// try {
// $firebase->send($message);
// return $this->response->setJSON(['status' => 'success']);
// } catch (MessagingException $e) {
// //return $this->response->setJSON(['status' => 'error', 'message' => $e->getMessage()]);
// log_message('error', $e->getMessage());
// }
// }

View File

@ -1979,6 +1979,9 @@ public function employeesEnrollmentInsert($params)
// dd($notification);
$client_details = $this->clientModel->where('id', $file['client_id'])->first();
$emp_emails = []; // Initialize an empty array to store employee email.
foreach ($excel_data as $key => $row)
{
$is_row_empty = check_row_is_empty_or_null($row);
@ -2008,17 +2011,103 @@ public function employeesEnrollmentInsert($params)
$value['client_branch_id'] = $file['client_branch_id'];
$value['file_id'] = $file_id;
$value['temp']['emp_id'] = null; // dummy value for using exisitng funciton in model
if (strtolower(trim($value['relationship'])) === 'mother' || strtolower(trim($value['relationship'])) === 'father') {
$relation = 'parent';
} else if(strtolower(trim($value['relationship'])) === 'son' || strtolower(trim($value['relationship'])) === 'daughter'){
$relation = 'child';
}else if(strtolower(trim($value['relationship'])) === 'father in law' || strtolower(trim($value['relationship'])) === 'mother in law'){
$relation = 'parent_in_law';
}else if(strtolower(trim($value['relationship'])) === 'spouse'){
$relation = 'spouse';
}else{
$relation = 'self';
$value['temp']['emp_id'] = null; // dummy value for using exisitng funciton in model
if (strtolower(trim($value['relationship'])) === 'mother' || strtolower(trim($value['relationship'])) === 'father') {
$relation = 'parent';
} else if(strtolower(trim($value['relationship'])) === 'son' || strtolower(trim($value['relationship'])) === 'daughter'){
$relation = 'child';
}else if(strtolower(trim($value['relationship'])) === 'father in law' || strtolower(trim($value['relationship'])) === 'mother in law'){
$relation = 'parent_in_law';
}else if(strtolower(trim($value['relationship'])) === 'spouse'){
$relation = 'spouse';
}else{
$relation = 'self';
}
$value['family_floater_key'] = $relation;
$policy_data['basic_cover_si'] = $row[9];
$policy_data['date_coverage'] = $row[13];
$policy_data['client_policy_id'] = $file['policy_id'];
$employee = $this->employeeModel->checkExistingEmployee($value,$file['client_branch_id']);
unset($value['temp']);
//save employee table
// dd($employee['id']);
if($employee !== null)
{
$value['updated_by'] = $file['created_by'];
$value['id'] = $employee['id'];
$value['emp_status'] = 'draft';
$log_message = 'Enrollment Update Employee - '.$employee['name'].'('.$employee['emp_code'].') with PK '.$employee['id'];
}
else
{
$value['emp_status'] = 'draft';
$value['created_by'] = $file['created_by'];
$log_message = 'Enrollment Insert Employee- '.$value['name'] .'('.$value['emp_code'] .') with PK ';
}
$this->employeeModel->save($value);
if (isset($value['id']))
{ $emp_id = $value['id']; }
else { $emp_id = $this->employeeModel->getInsertID();
$log_message .= $emp_id;
}
// $emp_id = $this->employeeModel->getInsertID();
// if($emp_id != 0){ $log_message .= $emp_id; }
// else{ $emp_id = $employee['id']; }
$this->myLogger->logme('error',$log_message);
//save policy table
$employee_policy = $this->employeePolicyModel->checkExistingEmpPolicy(['employee_id' => $emp_id,'client_policy_id' => $file['policy_id']]);
if(count($employee_policy))
{
$policy_data['updated_by'] = $file['created_by'];
$policy_data['id'] = $employee_policy[0]['id'];
$policy_data['status'] = 'draft';
$log_message = 'Update Employee Policy for '. $value['name'].'('. $value['emp_code'].') with PK- ' . $employee_policy[0]['id'] .' client policy ID '.$employee_policy[0]['client_policy_id'].' with SI '.$policy_data['basic_cover_si'];
// echo 'insert policy';
}
else
{
$policy_data['employee_id'] = $emp_id;
$policy_data['client_policy_id'] = $file['policy_id'];
$policy_data['created_by'] = $file['created_by'];
$policy_data['status'] = 'draft';
$log_message = 'Insert Employee Policy for '. $value['name'].'('. $value['emp_code'].') - client policy id -'. $file['policy_id'].' - with SI '.$policy_data['basic_cover_si'];
// echo 'update policy';
}
$this->employeePolicyModel->save($policy_data);
$emp_policy_id = $this->employeePolicyModel->getInsertID();
$this->myLogger->logme('error',$log_message);
//save email of self for send mail later
if (isset($notification) && $notification['enabled'] == 1 && $notification['mail_content'] != '')
{
if(strtolower($value['relationship']) == 'self' && $value['email_corporate'] != "")
{
$params['dataToInsert'] = $value; //holds employee master data
$params['notification'] = $notification;
$params['client_data'] = $client_details;
//store email and mail content via helper to send notification
$emp_emails[] = sendMailNotification::sendMailNotification('member_welcome_mail', $params);
// Kint::dump($emp_emails);
// Kint::dump($key.'-'.count($excel_data));
// if mail count is 20 send bulk mail and reset emp_emails variable
// if (count($emp_emails) == 20 || $key == count($excel_data) ) {
// $job_details = new Jobs();
// $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $emp_emails]);
// // echo 'Mail triggered';
// $emp_emails = [];
// }
}
$value['family_floater_key'] = $relation;
@ -2109,7 +2198,18 @@ public function employeesEnrollmentInsert($params)
}// endof if row is empty check
} //end of for loop
// for bulk mail queue job push
if (!empty($emp_emails) && count($emp_emails) > 0) {
$emp_emails = array_chunk($emp_emails, 20);
foreach ($emp_emails as $key => $value) {
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $value]);
}
}
$this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => ''])->update();
$this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]);

View File

@ -690,6 +690,7 @@ class PolicyTransactionController extends BaseController
->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left')
->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left')
->where('policy_transaction.id', $id)
->where('policy_transaction.is_active', 1)
->first();
// $data['policy_issue_date'] = (isset($data['policy_issue_date']) && $data['policy_issue_date'] !== null && $data['policy_issue_date'] !== '')
@ -810,6 +811,21 @@ class PolicyTransactionController extends BaseController
}
public function removePolicyTransaction($id)
{
if ($id) {
$data['is_active'] = 0;
$this->policyTransactionModel->where('id', $id)->set($data)->update();
$this->PTCOShareDetailsModel->where('pt_id', $id)->set($data)->update();
return $this->respond(['status' => true, 'code' => 200, 'message' => 'Policy Transaction removed successfully'], 200);
} else {
return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to remove policy transaction'], 200);
}
}
//------------------------------------------------------------------------------------------------
// Policy Transaction Endorsement
@ -962,6 +978,7 @@ class PolicyTransactionController extends BaseController
->where('action_type', 'inception')
->where('client_id', $this->request->getPost('client_id'))
->where('client_policy_id', $this->request->getPost('client_policy_id'))
->where('policy_transaction.is_active', 1)
->first();
$data['tsi'] = generate_tsi_code($issue_type['issue_type'] ?? 1);
@ -1089,6 +1106,7 @@ class PolicyTransactionController extends BaseController
->join('clients', 'clients.id = policy_transaction.client_id')
->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left')
->where('policy_transaction.id', $id)
->where('policy_transaction.is_active', 1)
->first();
// $data['policy_start_date'] = empty($data['policy_start_date']) ? '' : date('d/m/Y', strtotime($data['s_date']));
@ -1278,6 +1296,8 @@ class PolicyTransactionController extends BaseController
->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id')
->join('insurer_statements', 'pt_co_share_details.statement_id = insurer_statements.id')
->where('policy_transaction.id', $pt_id)
->where('policy_transaction.is_active', 1)
->where('pt_co_share_details.is_active', 1)
->where('pt_co_share_details.statement_id IS NOT NULL')
->where('insurer_statements.invoice_no IS NOT NULL')
->countAllResults();

View File

@ -73,7 +73,9 @@ class RestAuthenticationController extends AdminController
$employeeData = $this->employeeModel->where('mobile', $mobile_number)
->where('relationship', 'self')
->where('is_active', 1)->first();
->where('emp_status !=', 'truncated')
->where('is_active', 1)
->first();
if ($employeeData) {
@ -137,7 +139,8 @@ class RestAuthenticationController extends AdminController
$HrData = $this->hrModel->where('mobile', $mobile_number)
->where('contact_type', 'client')
->where('is_active', 1)->first();
->where('is_active', 1)
->first();
if ($HrData) {

View File

@ -386,7 +386,11 @@ class PolicyTransactionModel extends Model
$builder->orderBy('policy_transaction.id', 'desc');
return $builder->get()->getResultArray();
$result = $builder->get()->getResultArray();
// dd($this->db->getLastQuery());
return $result;
}
public function getEndorsementTranctionListData($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0)

View File

@ -180,6 +180,7 @@
<th class="font-weight-medium">SNO</th>
<th class="font-weight-medium">Name</th>
<th class="font-weight-medium">Emp Code</th>
<th class="font-weight-medium">Relationship</th>
<th class="font-weight-medium">Enroled</th>
<th class="font-weight-medium">Logged-In</th>
</tr>
@ -336,6 +337,7 @@
index + 1,
employee.employee_name,
employee.emp_code,
employee.relationship,
enrolled,
loggedIn
]);

View File

@ -862,6 +862,69 @@
}
</script>
<script>
function checkDuplicateTableFieldValue(tableName, fieldName, value, callback) {
$.ajax({
url: '<?= base_url('util/checkDuplicateTableFieldValue') ?>', // Adjust this to your endpoint in CodeIgniter
type: 'POST',
data: {
table: tableName,
field: fieldName,
value: value
},
dataType: 'json',
success: function(response) {
if (typeof callback === 'function') {
callback(response.isDuplicate); // Pass the result to the callback
}
},
error: function(xhr, status, error) {
console.error('AJAX Error:', error);
}
});
}
function sendAjaxRequestForGlobal(url, method, data = {}, successCallback = null, errorCallback = null) {
$.ajax({
url: url,
method: method,
data: data,
dataType: 'json', // Expected response type
success: function(response) {
// If a success callback is provided, call it with the response
if (successCallback) {
successCallback(response);
}
},
error: function(xhr, status, error) {
// Handle errors if provided error callback
if (errorCallback) {
errorCallback(xhr, status, error);
} else {
console.error('AJAX Error:', error);
}
}
});
}
function confirmActionSweertAlert(message = "Are you sure?", confirmText = "Yes, Proceed!", cancelText = "Cancel", icon = "warning") {
return Swal.fire({
title: message,
icon: icon,
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: confirmText,
cancelButtonText: cancelText
}).then((result) => {
return result.isConfirmed; // Returns true if confirmed, false otherwise
});
}
</script>
</body>
</html>

View File

@ -317,7 +317,7 @@
</div>
<div class="form-group col-md-3" id="renewal" style="display: none;">
<label for="addon_policy"> Renewal Source Policy <span id="base_danger"class="text-danger">*</span></label>
<label for="addon_policy"> Renewal Source Policy <span id="base_danger"class="text-danger"></span></label>
<select class="form-control" id="source_client_policy_id"name="source_client_policy_id" onchange="setRenewalPolicyData(this)">
<option value="" selected>Select Renewal Source Policy</option>
</select>
@ -748,7 +748,7 @@
<!-- end form row -->
<!-- Client form content modal-->
<div class="modal fade" id="upload_enrollment_model" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="false" data-backdrop="static" data-keyboard="false">
<div class="modal fade" id="upload_enrollment_model" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
@ -759,7 +759,6 @@
<form class="parsley-examples" method="post" id="client_form" enctype="multipart/form-data">
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-12">
<label for="client_name">Client Name<span class="text-danger">*</span></label>
@ -772,7 +771,7 @@
<div class="form-group col-md-12">
<label for="cost_center">PAN<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="pan" placeholder="Enter PAN No" name="pan">
<input type="text" class="form-control" id="pan" placeholder="Enter PAN No" name="pan" onchange="validateInput(this, 'clients', 'pan')" required>
</div>
</div>
@ -789,7 +788,7 @@
<div class="form-group col-md-6">
<label for="cost_center">Mobile<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="phone" placeholder="Enter Mobile Number" maxlength="10" name="phone"
onkeypress="return onlyNumbers(event)">
onkeypress="return onlyNumbers(event)" onchange="validateInput(this, 'clients', 'phone')">
</div>
<div class="form-group col-md-12">
@ -799,7 +798,7 @@
<div class="form-group col-md-12">
<label for="aadhar">Aadhar<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="aadhar" placeholder="Enter Aadher No" name="aadhar">
<input type="text" class="form-control" id="aadhar" placeholder="Enter Aadher No" name="aadhar" maxlength="12" onchange="validateInput(this, 'clients', 'aadhar')">
</div>
</div>
@ -809,7 +808,7 @@
<div class="form-group col-md-12">
<label for="short_name">Entity Type<span class="text-danger">*</span></label>
<select class="form-control" id="entity_type_id" name="entity_type_id">
<select class="form-control" id="entity_type_id_for_client" name="entity_type_id">
<option value="" selected>Select Entity</option>
<?php
if (isset($entity) && count($entity)) {
@ -843,7 +842,8 @@
<div class="form-group col-md-12">
<label for="gst">GST<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="gst" placeholder="Enter GST Number" data-parsley-error-message="Invalid GST Number. Example: 12ABCDE1234F5Z6" name="gst" data-parsley-trigger="change" data-parsley-pattern="^\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}[Z]{1}[A-Z\d]{1}$" required>
<input type="text" class="form-control" id="gst" placeholder="Enter GST Number" onchange="validateInput(this, 'client_branch', 'gst')"
data-parsley-error-message="Invalid GST Number. Example: 12ABCDE1234F5Z6" name="gst" data-parsley-trigger="change" data-parsley-pattern="^\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}[Z]{1}[A-Z\d]{1}$" required>
</div>
</div>
@ -859,21 +859,21 @@
</div>
<!-- Vehicle form content modal-->
<div class="modal fade" id="vehicle_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="false">
<div class="modal fade" id="vehicle_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myCenterModalLabel">Add New Vehicle</h4>
<button type="button" id="close_btn" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<button type="button" id="vehicle_close_btn" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="modal-body" style="overflow-y: auto;height: 90vh;">
<form class="parsley-examples" method="post" id="vehicle_form" enctype="multipart/form-data">
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-6 client_type_div">
<label for="client_type">Owner Type<span class="text-danger">*</span></label>
<label for="Owner_type">Owner Type<span class="text-danger">*</span></label>
<select class="form-control" id="Owner_type" name="Owner_type" required>
<option value="">Select Owner type</option>
<option value="1">Group</option>
@ -883,12 +883,12 @@
<div class="form-group col-md-6">
<label for="cost_center">Vehicle No<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="modal_vehicle_no" placeholder="Enter Vehicle No" name="vehicle_no" required>
<input type="text" class="form-control" id="modal_vehicle_no" placeholder="Enter Vehicle No" name="vehicle_no" onchange="validateInput(this, 'vehicle', 'vehicle_no')" required>
</div>
<div class="form-group col-md-6">
<label for="rc">RC Book <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="rc" placeholder="Enter RC Book No" name="rc" required>
<input type="text" class="form-control" id="rc" placeholder="Enter RC Book No" name="rc" onchange="validateInput(this, 'vehicle', 'rc')" required>
</div>
<div class="form-group col-md-6">
@ -946,7 +946,7 @@
</div>
<!-- CD No form content modal-->
<div class="modal fade" id="cd_form_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal fade" id="cd_form_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
@ -994,7 +994,6 @@
</div>
</div>
</div>
<script>
var team_id = [];
@ -1020,7 +1019,7 @@ $(document).ready(function(){
e.preventDefault();
}
}
});
});
team_id = <?php echo json_encode(user_team()); ?>;
@ -1089,6 +1088,7 @@ $(document).ready(function(){
$(document).ready(function(){
$('#vehicle_no').change(function(){
var val = $(this).val()
var selectedOption = $(this).find('option:selected');
var client_id = selectedOption.data('cid')
@ -1116,9 +1116,12 @@ $(document).ready(function(){
}
if(val == 'add_vehicle'){
$('#modal_vehicle_no').val('');
var myModal = new bootstrap.Modal(document.getElementById('vehicle_modal'));
myModal.show();
$(this).val('').select2();
}
})
@ -1127,6 +1130,65 @@ $(document).ready(function(){
let owner_id = $(this).val();
console.log('owner_id', owner_id);
if(owner_id == 'add_client'){
if($('#client_type').val()){
$('#vehicle_close_btn').click();
if ($('#client_type').val() == 2) {
$('.branchdiv').hide();
$('.clienttypediv').show();
$('#entity_type_id_for_client').prop('required', false);
$('#branch_name').prop('required', false);
$('#client_branch_id').prop('required', false);
$('#branch_code').prop('required', false);
$('#name').prop('required', false);
$('#mobile').prop('required', false);
$('#gst').prop('required', false);
$('#dob').prop('required', true);
$('#phone').prop('required', true);
$('#email').prop('required', true);
$('#aadhar').prop('required', true);
} else {
$('.branchdiv').show();
$('.clienttypediv').hide();
$('#entity_type_id_for_client').prop('required', true);
$('#branch_name').prop('required', true);
$('#client_branch_id').prop('required', true);
$('#branch_code').prop('required', true);
$('#name').prop('required', true);
$('#mobile').prop('required', true);
$('#gst').prop('required', true);
$('#dob').prop('required', false);
$('#phone').prop('required', false);
$('#email').prop('required', false);
$('#aadhar').prop('required', false);
}
var myModal = new bootstrap.Modal(document.getElementById('upload_enrollment_model'));
myModal.show();
}else{
toastr.warning('Please select the Owner type', 'WARNING');
}
$('#client_form').attr('data-id', 1);
// Save form data from the #vehicle_form to localStorage
saveFormDataToLocalStorage("#vehicle_form", "vehicleFormData");
}
if(branch_list != '') {
// console.log(branch_list[client_id]);
let data = branch_list[owner_id];
@ -1552,10 +1614,10 @@ function getPolicyTransactionDataForEdit(input) {
// Additional form handling logic
if (res.data.issue_type == 2) {
$('#renewal').show();
$('#source_client_policy_id').attr('required', true);
// $('#source_client_policy_id').attr('required', true);
} else {
$('#renewal').hide();
$('#source_client_policy_id').attr('required', false);
// $('#source_client_policy_id').attr('required', false);
}
// Handle base policy visibility
@ -1680,6 +1742,7 @@ function checkAndDistributeTax(input)
let cgst = parseFloat($('#cgst_' + input).val());
let sgst = parseFloat($('#sgst_' + input).val());
let igst = parseFloat($('#igst_' + input).val());
if(((event.target.id).startsWith('cgst') || (event.target.id).startsWith('sgst') ))
{
if(cgst !== 0) { $('#sgst_' + input).val(cgst.toFixed(2)); }
@ -1687,7 +1750,7 @@ function checkAndDistributeTax(input)
$('#igst_' + input).val(0.00);
}
else
else if((event.target.id).startsWith('igst'))
{
$('#cgst_' + input).val(0.00);
$('#sgst_' + input).val(0.00);
@ -2177,12 +2240,21 @@ function removeRemoveInsured(element) {
}
function appendOwner(data) {
$('#owner').empty();
$('#owner').append($('<option>', {
value: '',
text: 'Select Owner'
}));
}));
$('#owner').append(
$('<option>', {
value: 'add_client',
text: ' + Add Owner',
})
);
$.each(data, function(index, item) {
var option = $('<option>', {
@ -2707,6 +2779,12 @@ $("#inception_form_id").submit(function(event) {
$("#client_form").submit(function(event) {
let form_type = $(this).data('id') || 0;
console.log('onsubmit event', this)
console.log('onsubmit event get data value',form_type)
console.log('client_type', $('#client_type').val());
event.preventDefault();
isClientFormSubmitting = true;
var isValid = $('#client_form').parsley().validate();
@ -2719,10 +2797,13 @@ $("#client_form").submit(function(event) {
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var client_type = $('#client_type').val();
var client_type = $('#client_type').val() || $('#Owner_type').val();
console.log('client_type:', client_type);
//FORM Data
var formData = new FormData($('#client_form')[0]);
formData.append('client_type', client_type)
formData.append('client_type', client_type);
$.ajax({
data:formData,
@ -2740,21 +2821,48 @@ $("#client_form").submit(function(event) {
if(res.status == true){
getClientAndBranchAndPolicy(res.client_id, res.branch_id);
setTimeout(function(){
$('#client_id').val(res.client_id).change();
if(form_type != 1){
setTimeout(function(){
$('#client_branch_id').val(res.branch_id).change();
}, 1000)
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 2000)
$('#client_id').val(res.client_id).change();
setTimeout(function(){
$('#client_branch_id').val(res.branch_id).change();
}, 1000)
}, 2000)
}else{
setTimeout(function(){
$('#owner').val(res.client_id).change();
$('#owner_branch').val(res.branch_id).change();
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 2000)
}
toastr.success(res.message, 'Success');
}else{
toastr.error(res.message, 'Error');
}
$('#client_form')[0].reset();
$('.close').click();
if(form_type == 1){
var myModal = new bootstrap.Modal(document.getElementById('vehicle_modal'));
myModal.show();
$('#client_form').removeAttr('data-id');
// Load form data into #vehicle_form from localStorage
setFormDataFromLocalStorage("#vehicle_form", "vehicleFormData");
}
isClientFormSubmitting = false;
},
error: function (xhr, status, error) {
@ -2898,6 +3006,7 @@ $("#CDMasterForm").submit(function(event) {
//-----------------------------------------------------------------------------------------------------------
$('#cop_yes').change(function() {
if ($(this).is(':checked')) {
$('#add_more_row').removeClass('d-none');
$('.payby').removeClass('d-none');
@ -2927,9 +3036,10 @@ $('#client_type').change(function() {
}
if ($(this).val() == 2) {
$('.branchdiv').hide();
$('.clienttypediv').show();
$('#entity_type_id').prop('required', false);
$('#entity_type_id_for_client').prop('required', false);
$('#branch_name').prop('required', false);
$('#client_branch_id').prop('required', false);
$('#branch_code').prop('required', false);
@ -2949,7 +3059,7 @@ $('#client_type').change(function() {
} else {
$('.branchdiv').show();
$('.clienttypediv').hide();
$('#entity_type_id').prop('required', true);
$('#entity_type_id_for_client').prop('required', true);
$('#branch_name').prop('required', true);
$('#client_branch_id').prop('required', true);
$('#branch_code').prop('required', true);
@ -3025,6 +3135,8 @@ $('#Owner_type').on('change', function() {
var selectedClientType = $(this).val();
$('#client_type').val(selectedClientType).change();
if ($(this).val() == 2) {
$('.ownerbranchdiv').hide();
$('#owner_branch').prop('required', false);
@ -3040,17 +3152,40 @@ $('#Owner_type').on('change', function() {
value: '',
text: 'Select Owner'
}))
$('#owner').append(
$('<option>', {
value: 'add_client',
text: ' + Add Owner',
})
);
// Populate client options based on selected client type
if (selectedClientType) {
// Populate vehicle options based on selected client type
$.each(client_list, function(index, owner) {
if (owner.client_type == selectedClientType) {
var option = $('<option>', {
value: owner.id,
text: owner.client_name,
});
$('#owner').append(option);
if(selectedClientType == '2'){
var option = $('<option>', {
value: owner.id,
text: (owner.client_name + ' - ' + (owner.pan ?? ''))
});
$('#owner').append(option);
}else{
var option = $('<option>', {
value: owner.id,
text: owner.client_name,
});
$('#owner').append(option);
}
}
});
}
@ -3945,4 +4080,69 @@ function getURLParamsForReport() {
console.log('pt_id', pt_id); // Retain the log if necessary
}
function validateInput(input, table, field){
let value = $(input).val();
let label = $(input).closest('.form-group').find('label').text().replace('*', '').trim();
let message = "Value is duplicate!";
if(label){
message = label + " already exists!";
}
checkDuplicateTableFieldValue(table, field, value, function(isDuplicate) {
if (isDuplicate) {
toastr.warning(message, 'WARNING');
$(input).val('')
}
});
}
function saveFormDataToLocalStorage(formSelector, storageKey) {
// Initialize an empty object to store form data
let formData = {};
// Iterate over all inputs in the form
$(formSelector + " :input").each(function() {
let input = $(this);
let name = input.attr("name"); // Get the input's name attribute
let value = input.val(); // Get the input's value
if (name) {
if (name !== 'owner' && name !== 'branch_id') {
formData[name] = value; // Add to the formData object if the input has a name
}
}
});
// Save the form data to local storage with the provided key
localStorage.setItem(storageKey, JSON.stringify(formData));
console.log("Form data saved to local storage:", formData);
}
function setFormDataFromLocalStorage(formSelector, storageKey) {
// Retrieve the saved form data from localStorage
let savedData = JSON.parse(localStorage.getItem(storageKey));
// If there's no saved data, do nothing
if (!savedData) return;
// Iterate through the saved data and set the form inputs accordingly
$.each(savedData, function(name, value) {
let input = $(formSelector + " :input[name='" + name + "']");
// Check if the input is a checkbox or radio button
if (input.is(':checkbox') || input.is(':radio')) {
input.prop('checked', value); // Set the checked property
} else {
input.val(value); // Set the value for other input types
}
});
console.log("Form data loaded from local storage:", savedData);
}
</script>

View File

@ -289,6 +289,9 @@ table.dataTable tbody td {
<a class="dropdown-item btnEdit" data-id="<?= $row['id'];?>" onclick="getPolicyTransactionDataForEdit('<?= htmlspecialchars($row['id'], ENT_QUOTES) ?>')">
<i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit
</a>
<a class="dropdown-item" data-id="<?= $row['id'];?>" onclick="removePolicyTransaction(this, '<?= htmlspecialchars($row['id'], ENT_QUOTES) ?>')">
<i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete
</a>
</div>
</div>
</td>
@ -1071,6 +1074,7 @@ $(document).ready(function(){
$('#policy_holder_name').val(client_name);
if(client_id == 'add_client') {
if($('#client_type').val()){
$('#client_id').val('').change();
var myModal = new bootstrap.Modal(document.getElementById('upload_enrollment_model'));
@ -1118,11 +1122,11 @@ $('#issue_type').change(function(){
$('#revenue_type').val('EA')
$('#renewal').show()
// $('.sded_dates').show()
$('#source_client_policy_id').attr('required', true)
// $('#source_client_policy_id').attr('required', true)
}else{
$('#renewal').hide()
// $('.sded_dates').hide()
$('#source_client_policy_id').attr('required', false)
// $('#source_client_policy_id').attr('required', false)
$('#policy_start_date').val('');
$('#policy_end_date').val('');
}
@ -1243,7 +1247,7 @@ $('#cd_ac_no_data').change(function(){
// $('#policy_type_id').change(function() {
// var policy_type_id = $(this).val();
// var policy_type_id = $(this).val();
// var client_id = $('#client_id').val();
// var client_branch_id = $('#client_branch_id').val();
@ -1501,4 +1505,32 @@ function hideDateField(input = null)
}
}
function removePolicyTransaction(input, pt_id) {
confirmActionSweertAlert("Do you want to delete this transaction?", "Yes, Proceed!", "No, Cancel").then((confirmed) => {
if (confirmed) {
let url = '<?= base_url('policy_tranction/inception/removePolicyTransaction/') ?>' + pt_id;
// Include `pt_id` in the AJAX request if necessary
let requestData = { pt_id: pt_id };
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
console.log('Data fetched successfully:', response);
if (response.status === true) {
toastr.success(response.message, 'SUCCESS');
window.location.reload();
} else {
toastr.warning(response.message, 'WARNING');
}
}, function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
});
}
});
}
</script>