FEAT_RFQ_AND_QCR_MODULE : RV

This commit is contained in:
VENKATESHWARAN 2024-10-29 15:16:31 +05:30
parent 34789897c9
commit 9699c6de72
9 changed files with 3212 additions and 29 deletions

View File

@ -18,6 +18,7 @@ $routes->get("update-policy-terms-for-corrections", "ClientController::updatePol
$routes->get("update_rack_rate_json", "ClientController::updateRackRateJson");
$routes->get("updatajson", "EmpDataServiceController::updatajson");
$routes->get("view", "EmployeeController::viewECard/$1");
// $routes->get("exportQCRandRFQ", "LeadsController::exportQCRandRFQ");
@ -343,6 +344,13 @@ $routes->group("leads", ["filter" => "authMVC"], function ($routes) {
$routes->get("list", "LeadsController::viewLeadsList");
$routes->post("create", "LeadsController::createLead");
$routes->get("list/(:any)", "LeadsController::getLeadDataForEdit/$1");
$routes->get("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1");
});
$routes->group("rfq", ["filter" => "authMVC"], function ($routes) {
$routes->post("create", "LeadsController::createRFQ");
$routes->post("createQCR", "LeadsController::createQCR");
$routes->get("list/(:any)", "LeadsController::viewRFQ/$1");
});
$routes->get("driveListFiles", "GoogleDriveController::listFiles");

View File

@ -4,6 +4,9 @@ namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use App\Models\UserModel;
use App\Models\ClientModel;
use App\Models\ClientBranchModel;
@ -15,6 +18,8 @@ use App\Models\KYCEntityTypeModel;
use App\Models\PolicyTransactionStatusModel;
use App\Models\InsurerBranchModel;
use App\Models\TPABranchModel;
use App\Models\RFQModel;
use App\Models\InsurerModel;
class LeadsController extends BaseController
{
@ -35,6 +40,8 @@ class LeadsController extends BaseController
protected $policyTransactionStatusModel;
protected $insurerBranchModel;
protected $tpaBranchModel;
protected $RFQModel;
protected $insurerModel;
//variables for storing array
protected $issuer;
@ -58,6 +65,8 @@ class LeadsController extends BaseController
$this->policyTransactionStatusModel = new PolicyTransactionStatusModel();
$this->insurerBranchModel = new InsurerBranchModel();
$this->tpaBranchModel = new TPABranchModel();
$this->RFQModel = new RFQModel();
$this->insurerModel = new InsurerModel();
$this->issuer = [1 => 'JIBS', 2 => 'Nhance'];
$this->clientType = [1 => 'Group', 2 => 'Individual'];
@ -296,4 +305,265 @@ class LeadsController extends BaseController
}
//--------RFQ-----------------------------------------------------------------------------------------------
public function viewRFQ($id, $type = 1){
$data['rfq_data'] = $this->RFQModel
->where('lead_id', $id)
->where('type', $type)
->where('is_active', 1)
->first();
$data['rfq_count'] = $this->RFQModel
->where('lead_id', $id)
->where('type', 1)
->where('is_active', 1)
->countAllResults();
$data['qcr_count'] = $this->RFQModel
->where('lead_id', $id)
->where('type', 2)
->where('is_active', 1)
->countAllResults();
// dd(count($data['rfq_data']));
$data['lead_id'] = $id;
$lead_data = $this->leadsModel
->select('policy_type.question_json')
->join('policy_type', 'leads.policy_type_id = policy_type.id')
->where('leads.id', $id)
->first();
$data['question_json'] = $lead_data['question_json'];
$data['page_name'] = isset($data['rfq_data']['type']) && $data['rfq_data']['type'] == 2 ? 'QCR' : 'RFQ';
$data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames();
// dd($data);
$this->loadLayout('view_rfq.php', $data);
}
public function createRFQ(){
$data = $this->request->getPost();
$lead_id = $data['lead_id'];
$data['type'] = 1;
$this->RFQModel
->where('lead_id', $lead_id)
->where('type', 1)
->where('is_active', 1)
->set('is_active', 0)
->update();
$result = $this->RFQModel->insert($data);
if ($result) {
return $this->respond(['status' => true, 'id' => $result, 'message' => 'New RFQ created successfully', 'data' =>$data], 200);
}
return $this->respond(['status' => false, 'id' => $result, 'message' => "Failed to create RFQ", 'data' =>$data], 200);
}
public function createQCR(){
$data = $this->request->getPost();
$lead_id = $data['lead_id'];
$data['type'] = 2;
$this->RFQModel
->where('lead_id', $lead_id)
->where('type', 2)
->where('is_active', 1)
->set('is_active', 0)
->update();
$result = $this->RFQModel->insert($data);
if ($result) {
return $this->respond(['status' => true, 'id' => $result, 'message' => 'New QCR created successfully', 'data' =>$data], 200);
}
return $this->respond(['status' => false, 'id' => $result, 'message' => "Failed to create QCR", 'data' =>$data], 200);
}
//-----RFQ and QCR EXPORT------------------------------------------------------------------------------------------------
//export main route function
public function exportQCRandRFQ($lead_id, $type, $export_type){
if($export_type == 'mail'){
$this-> exportMailForQCRandRFQ($lead_id, $type);
}else{
$this-> exportExcelForQCRandRFQ($lead_id, $type);
}
}
//FOR EXCEL
public function exportExcelForQCRandRFQ($lead_id, $type)
{
$filepath = $this->constructExcelToSaveTemp($lead_id, $type);
$filepath = $filepath['filePath'];
if (file_exists($filepath)) {
// Set headers to force download
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="' . basename($filepath) . '"');
header('Content-Length: ' . filesize($filepath));
header('Pragma: public');
// Output the file content
readfile($filepath);
// Delete the file after download
unlink($filepath);
exit;
} else {
echo "File does not exist.";
}
}
//FOR MAIL
public function exportMailForQCRandRFQ($lead_id, $type){
$filepath = $this->constructExcelToSaveTemp($lead_id, $type);
if ($filepath) {
return $this->respond(['status' => true, 'file_path' => $filepath, 'message' => 'Mail send successfully'], 200);
}
return $this->respond(['status' => false, 'file_path' => $filepath, 'message' => "Mail send failed"], 200);
}
//Construct excel file and save the file to the folder and return file path
public function constructExcelToSaveTemp($lead_id, $type)
{
$rfq_data = $this->RFQModel
->select('
leads.client_name,
leads.client_short_name,
insurers.name as insurer_name,
insurer_branch.branch_name as insurer_branch_name,
tpa.name as tpa_name,
tpa_branch.branch_name as tpa_branch_name,
policy_type.policy_type,
rfq.json
')
->join('leads', 'rfq.lead_id = leads.id')
->join('policy_type', 'leads.policy_type_id = policy_type.id')
->join('insurers', 'leads.insurer_id = insurers.id')
->join('insurer_branch', 'leads.insurer_branch_id = insurer_branch.id')
->join('tpa', 'leads.tpa_id = tpa.id')
->join('tpa_branch', 'leads.tpa_branch_id = tpa_branch.id')
->where('rfq.lead_id', $lead_id)
->where('rfq.type', $type)
->where('rfq.is_active', 1)
->first();
$lead_data = [
'Insured' => $rfq_data['client_name'],
'Insurer' => $rfq_data['insurer_name'] . ' - ' . $rfq_data['insurer_branch_name'],
'TPA' => $rfq_data['tpa_name'] . ' - ' . $rfq_data['tpa_branch_name'],
];
$jsonData = $rfq_data['json'];
$data = json_decode($jsonData, true);
// Initialize PhpSpreadsheet
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// Start with lead_data at the top
$rowNumber = 1;
foreach ($lead_data as $key => $value) {
$sheet->setCellValue("A{$rowNumber}", $key);
$sheet->setCellValue("B{$rowNumber}", $value);
// Apply bold style to the key
$sheet->getStyle("A{$rowNumber}")->applyFromArray([
'font' => [
'bold' => true,
],
]);
$rowNumber++;
}
// Leave two blank rows
$rowNumber += 2;
// Set headers and subheaders starting from current row
$headers = $data['table_data']['headers'];
$subHeaderRow = $rowNumber + 1;
$columnLetter = 'A';
// Add headers in the first row and subheaders in the second row
foreach ($headers as $header) {
if ($header['parentHeader'] === 'Item Key' || $header['parentHeader'] == 'Action') {
continue; // Skip "Item Key" and "Action" columns
}
if($header['parentHeader'] === 'Sno'){
$header['parentHeader'] = 'S.No.';
}
$sheet->setCellValue("{$columnLetter}{$rowNumber}", $header['parentHeader']);
// Apply bold style to the header
$sheet->getStyle("{$columnLetter}{$rowNumber}")->applyFromArray([
'font' => [
'bold' => true,
],
]);
foreach ($header['subHeaders'] as $subHeader) {
$sheet->setCellValue("{$columnLetter}{$subHeaderRow}", $subHeader);
// Apply bold style to the subheader
$sheet->getStyle("{$columnLetter}{$subHeaderRow}")->applyFromArray([
'font' => [
'bold' => true,
],
]);
$columnLetter++;
}
}
// Move to next row for data entries
$rowNumber = $subHeaderRow + 1;
// Add data rows
foreach ($data['table_data']['data'] as $dataRow) {
$columnLetter = 'A';
foreach ($dataRow['data'] as $cellData) {
if ($cellData['parentth'] === 'Item Key' || $cellData['parentth'] == 'Action') {
continue; // Skip "Item Key" data
}
$sheet->setCellValue("{$columnLetter}{$rowNumber}", $cellData['value']);
$columnLetter++;
}
$rowNumber++;
}
// Set filename based on type
$string = ($type == 2) ? 'QCR' : 'RFQ';
$filename = $string . '_' . $rfq_data['client_short_name'] . '_' . $rfq_data['policy_type'] . '_' . date('Ymdhis') . '.xlsx';
// Save to temporary location
$uploadFilePath = WRITEPATH . 'tmp/' . $filename;
$writer = new Xlsx($spreadsheet);
$writer->save($uploadFilePath);
return [
'filePath' => $uploadFilePath,
'fileName' => $filename,
]; // Return file path and file name
}
}

View File

@ -91,14 +91,27 @@ class LeadsModel extends Model
leads.*,
kyc_entity_type.name as entity_type,
policy_type.policy_type,
user_profiles.first_name as salse_person_name
user_profiles.first_name as salse_person_name,
(
SELECT COUNT(*) AS qcr_count
FROM rfq
WHERE type = 2
AND is_active = 1 and lead_id = leads.id
) AS qcr_count,
(
SELECT COUNT(*) AS rfq_count
FROM rfq
WHERE type = 1
AND is_active = 1 and lead_id = leads.id
) AS rfq_count
')
->join('kyc_entity_type', 'leads.entity_type_id = kyc_entity_type.id', 'left')
->join('user_profiles', 'leads.salse_person_id = user_profiles.id', 'left')
->join('policy_type', 'leads.policy_type_id = policy_type.id', 'left')
->where('leads.is_active', 1)
->where('leads.is_active', 1)
->where('leads.is_active', 1)
->orderBy('id', 'desc')
->findAll();

View File

@ -22,5 +22,6 @@ class PolicyTypeModel extends Model
"etp",
"iep",
"itp",
"question_json",
];
}

60
app/Models/RFQModel.php Normal file
View File

@ -0,0 +1,60 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class RFQModel extends Model
{
protected $table = 'rfq';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = [
'id',
'type',
'lead_id',
'json',
'created_at',
'created_by',
'updated_at',
'updated_by',
'is_active'
];
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = ["checkAndADDCreatedByValue"];
protected $afterInsert = [];
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
protected function checkAndADDCreatedByValue(array $data)
{
// Check if 'updated_by' value is null or empty
if (empty($data['data']['created_by'])) {
// Set 'updated_by' value to the current session user ID
$data['data']['created_by'] = get_session_userid();
}
return $data;
}
protected function checkAndUpdateUpdatedByValue(array $data)
{
// Check if 'updated_by' value is null or empty
if (empty($data['data']['updated_by'])) {
// Set 'updated_by' value to the current session user ID
$data['data']['updated_by'] = get_session_userid();
}
return $data;
}
}

View File

@ -98,9 +98,14 @@ table.dataTable tbody td {
<a class="dropdown-item btnEdit" data-id="<?= $row['id']; ?>" onclick="getLeadsDataForEdit('<?= 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 btnEdit" data-id="<?= $row['id']; ?>" onclick="getLeadsDataForEdit('<?= htmlspecialchars($row['id'], ENT_QUOTES) ?>')">
<a href="<?= base_url('/rfq/list/').$row['id'] . '/' . 1; ?>" class="dropdown-item btnEdit" data-id="<?= $row['id']; ?>">
<i class="mdi mdi-note-text mr-2 text-muted font-18 vertical-middle"></i>RFQ
</a>
<?php if($row['qcr_count'] > 0) { ?>
<a href="<?= base_url('/rfq/list/').$row['id'] . '/' . 2; ?>" class="dropdown-item btnEdit" data-id="<?= $row['id']; ?>">
<i class="mdi mdi-note-text mr-2 text-muted font-18 vertical-middle"></i>QCR
</a>
<?php } ?>
</div>
</div>
</td>

View File

@ -799,7 +799,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 PAN No" name="aadhar">
<input type="text" class="form-control" id="aadhar" placeholder="Enter Aadher No" name="aadhar">
</div>
</div>
@ -858,7 +858,7 @@
</div><!-- /.modal-dialog -->
</div>
<!-- Client form content modal-->
<!-- Vehicle form content modal-->
<div class="modal fade" id="vehicle_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="false">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
@ -1595,8 +1595,8 @@ function getPolicyTransactionDataForEdit(input) {
$('#policy_start_date').prop('required', true);
$('#policy_end_date').prop('required', true);
// $('#tpa').prop('required', true);
$('#emp_count').prop('required', true);
$('#dependent_count').prop('required', true);
// $('#emp_count').prop('required', true);
// $('#dependent_count').prop('required', true);
$('.follow_insurer').prop('required', true);
} else {
$('#sales_row').hide();
@ -1605,8 +1605,8 @@ function getPolicyTransactionDataForEdit(input) {
$('#policy_start_date').prop('required', false);
$('#policy_end_date').prop('required', false);
// $('#tpa').prop('required', false);
$('#emp_count').prop('required', false);
$('#dependent_count').prop('required', false);
// $('#emp_count').prop('required', false);
// $('#dependent_count').prop('required', false);
$('.follow_insurer').prop('required', false);
}
@ -2703,6 +2703,7 @@ $("#client_form").submit(function(event) {
toastr.error(res.message, 'Error');
}
$('#client_form')[0].reset();
$('.close').click();
},
error: function (xhr, status, error) {
@ -2771,6 +2772,7 @@ $("#vehicle_form").submit(function(event) {
toastr.error(res.message, 'Error');
}
$('#vehicle_form')[0].reset();
$('.close').click();
},
error: function (xhr, status, error) {
@ -2830,6 +2832,7 @@ $("#CDMasterForm").submit(function(event) {
toastr.error(res.message, 'Error');
}
$('#CDMasterForm')[0].reset();
$('.close').click();
},
error: function (xhr, status, error) {
@ -3024,8 +3027,8 @@ $('#policy_status').change(function(){
$('#policy_start_date').prop('required', true);
$('#policy_end_date').prop('required', true);
// $('#tpa').prop('required', true);
$('#emp_count').prop('required', true);
$('#dependent_count').prop('required', true);
// $('#emp_count').prop('required', true);
// $('#dependent_count').prop('required', true);
$('.follow_insurer').prop('required', true);
if(policy_type_id == 3 || policy_type_id == 4 || policy_type_id == 5){
@ -3053,8 +3056,8 @@ $('#policy_status').change(function(){
$('#policy_start_date').prop('required', false)
$('#policy_end_date').prop('required', false)
// $('#tpa').prop('required', false)
$('#emp_count').prop('required', false)
$('#dependent_count').prop('required', false)
// $('#emp_count').prop('required', false)
// $('#dependent_count').prop('required', false)
$('.follow_insurer').prop('required', false)
}
@ -3125,6 +3128,12 @@ $('#policy_no').change(function(){
// }
// });
$('.close').on('click', function(){
$('#client_form')[0].reset();
$('#vehicle_form')[0].reset();
$('#CDMasterForm')[0].reset();
});
//------------------------------------------------------------------------------------------------------------
var insurerCount = 0;

View File

@ -115,15 +115,19 @@
var PrimaryKey = $('#tpa_General_PrimaryKey').val();
var form_action = '';
console.log('tpa_General_PrimaryKey', PrimaryKey);
if (isValid) {
if (PrimaryKey === '') {
if (PrimaryKey === "") {
form_action = '<?= base_url("master/tpa/createpost"); ?>';
} else {
form_action = '<?= base_url("master/tpa/edit"); ?>';
}
console.log('tpa_General_form_action', form_action);
var formData = new FormData($('#tpa_general_form')[0]);
var OptionsHTML1 = '';
$('.loader').fadeIn();
@ -138,7 +142,6 @@
success: function(res) {
if($('#tpa_General_PrimaryKey').val() == ""){
window.location.href = '<?= base_url("master/tpa/list/"); ?>' + res.data.id;
}
@ -149,7 +152,6 @@
console.log(res);
$('#tpa_id').val(res.data.id);
$('#tpa_General_PrimaryKey').val(res.data.id);
$('#tpa_id_branch').val(res.data.id);
$('#tpa_branch_contacts_id').click();
@ -157,14 +159,6 @@
var message = "TPA General Info";
toastr.success(message, 'Success');
// $.toast({
// text: 'Insurer General Info',
// heading: "Submitted Sucessfully",
// position: 'top-right',
// icon: 'success',
// bgColor: !1,
// });
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
@ -172,7 +166,8 @@
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.log('Something Wrong!', 'warning'); }, 1000);
console.log('Something Wrong!', 'warning');
}, 1000);
}
});
}
@ -228,7 +223,6 @@
};
};
function PreviewImage3() {
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("bc").files[0]);
@ -238,8 +232,6 @@
};
};
$('#preview').click(function() {
var ecardContent = $('#ecard_content').val();
$('#Preview_data').html(ecardContent);

2825
app/Views/view_rfq.php Normal file

File diff suppressed because it is too large Load Diff