MERGE_CODE_MERGE : RV
This commit is contained in:
commit
8bedc1ea9c
@ -365,6 +365,8 @@ $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) {
|
||||
$routes->get("deletePaymentEntry/(:any)", "PolicyTransactionController::deletePaymentEntry/$1");
|
||||
$routes->get("downloadSampleInsurerStatement", "PolicyTransactionController::downloadSampleInsurerStatement");
|
||||
$routes->get("getFileErr/(:any)", "PolicyTransactionController::getFileErr/$1");
|
||||
$routes->get("getInsurerStatementMonth", "PolicyTransactionController::getInsurerStatementMonth");
|
||||
$routes->get("deleteStatement/(:any)", "PolicyTransactionController::deleteStatement/$1");
|
||||
});
|
||||
|
||||
});
|
||||
@ -378,6 +380,7 @@ $routes->group("leads", ["filter" => "authMVC"], function ($routes) {
|
||||
$routes->get("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1");
|
||||
$routes->get("featchLeadDataAndInsertClient/(:any)", "LeadsController::featchLeadDataAndInsertClient/$1");
|
||||
$routes->get("featchClientPolicyFromLead/(:any)", "LeadsController::featchClientPolicyFromLead/$1");
|
||||
|
||||
});
|
||||
|
||||
$routes->group("rfq", ["filter" => "authMVC"], function ($routes) {
|
||||
|
||||
@ -1328,7 +1328,7 @@ class EmployeeServiceController extends AdminController
|
||||
// }
|
||||
// dd($row[4]);
|
||||
//for emp table
|
||||
$this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'emp_status','old_value' => $data['emp_status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
|
||||
// $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'emp_status','old_value' => $data['emp_status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
|
||||
// dd( $this->empEndorsementModel->getLastQuery());
|
||||
// $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'change_event','old_value' => $data['change_event'],'new_value' => 'deletion','created_by' => $file['created_by'],'remarks' => 'general deletion']);
|
||||
|
||||
|
||||
@ -126,6 +126,10 @@ class JobWorker extends AdminController
|
||||
'employeesEnrollmentInsert' => [
|
||||
'type' => 'CC', // Handler Category
|
||||
'handler' => 'App\Controllers\EmployeeServiceController',
|
||||
],
|
||||
'calculateMembersDemography' => [
|
||||
'type' => 'CC', // Handler Category
|
||||
'handler' => 'App\Controllers\LeadsController',
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
@ -4,10 +4,14 @@ namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
|
||||
use Exception;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
|
||||
use App\Models\UserModel;
|
||||
use App\Models\ClientModel;
|
||||
@ -24,6 +28,8 @@ use App\Models\RFQModel;
|
||||
use App\Models\InsurerModel;
|
||||
|
||||
use App\Helpers\MailHelper;
|
||||
use App\Helpers\ExcelMergeHelper;
|
||||
use Google\Service\CloudSearch\PushItem;
|
||||
use Kint;
|
||||
|
||||
|
||||
@ -92,7 +98,9 @@ class LeadsController extends BaseController
|
||||
{
|
||||
|
||||
// $d = $this->constructExcelToSaveTemp(24, 1, $propsal_and_insurer = null);
|
||||
// $d = $this->calculateMembersDemography(['lead_id' => 34]);
|
||||
$job_details = new Jobs();
|
||||
// $r = Jobs::addJob(['job_name' => 'calculateMembersDemography', 'payload' => ['lead_id' => 24]]);
|
||||
// $d = $this->calculateMembersDemography(['lead_id' => 24]);
|
||||
//$this->mergeQuoteExcelFileWithMembersListExcelFile(24, 1, $propsal_and_insurer = null);
|
||||
// dd($d);
|
||||
$data['page_name'] = 'Leads';
|
||||
@ -359,7 +367,6 @@ class LeadsController extends BaseController
|
||||
} else {
|
||||
return $this->respond(['status' => false], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function insertLeadStatus($primaryKey, $status, $statusType)
|
||||
@ -377,7 +384,8 @@ class LeadsController extends BaseController
|
||||
//--------RFQ-----------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
public function viewRFQ($id, $type = 1){
|
||||
public function viewRFQ($id, $type = 1)
|
||||
{
|
||||
|
||||
$data['rfq_data'] = $this->RFQModel
|
||||
->where('lead_id', $id)
|
||||
@ -445,10 +453,10 @@ class LeadsController extends BaseController
|
||||
}
|
||||
|
||||
return $this->respond(['status' => false, 'id' => $result, 'message' => "Failed to create RFQ", 'data' => $data], 200);
|
||||
|
||||
}
|
||||
|
||||
public function createQCR(){
|
||||
public function createQCR()
|
||||
{
|
||||
|
||||
$data = $this->request->getPost();
|
||||
$lead_id = $data['lead_id'];
|
||||
@ -475,7 +483,8 @@ class LeadsController extends BaseController
|
||||
|
||||
|
||||
//export main route function
|
||||
public function exportQCRandRFQ($lead_id, $type, $export_type){
|
||||
public function exportQCRandRFQ($lead_id, $type, $export_type)
|
||||
{
|
||||
$this->exportExcelForQCRandRFQ($lead_id, $type);
|
||||
}
|
||||
|
||||
@ -694,7 +703,6 @@ class LeadsController extends BaseController
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
// Auto-size columns
|
||||
@ -722,9 +730,7 @@ class LeadsController extends BaseController
|
||||
{
|
||||
$rfq_data = $this->RFQModel->getRFQTableDataWithLeadIDAndType($lead_id, $type);
|
||||
|
||||
if($source_file_path && $rfq_data['file_name'])
|
||||
{
|
||||
|
||||
if ($source_file_path && $rfq_data['file_name']) {
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -736,18 +742,15 @@ class LeadsController extends BaseController
|
||||
$lead_data = $this->leadsModel->find($lead_id);
|
||||
$file_name_with_path = WRITEPATH . "/uploads/lead_files/" . $lead_data['file_name'];
|
||||
|
||||
// print_rr($lead_data);
|
||||
if($lead_data['file_name'])
|
||||
{
|
||||
if ($lead_data['file_name']) {
|
||||
|
||||
//check physical file
|
||||
if(!file_exists($file_name_with_path))
|
||||
{
|
||||
if (!file_exists($file_name_with_path)) {
|
||||
//file not found update status and reason
|
||||
$message = "Lead Physcial file not found";
|
||||
// echo $message;
|
||||
$this->myLogger->logme('error', ($message . ' for file ' . $file_name_with_path));
|
||||
return ['status' => 'failed','message' => 'no physcial file'];
|
||||
return ['status' => 'failed', 'message' => 'no physical file'];
|
||||
}
|
||||
|
||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path);
|
||||
@ -757,17 +760,16 @@ class LeadsController extends BaseController
|
||||
$highestRowAndColumn = $members_sheet->getHighestRowAndColumn();
|
||||
// dd($highestRowAndColumn);
|
||||
$members = $members_sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
|
||||
// dd($members);
|
||||
// dd($members[6]);
|
||||
|
||||
//get age band data
|
||||
$age_band_sheet = $spreadsheet->getSheet(1);
|
||||
$highestRowAndColumn = $age_band_sheet->getHighestRowAndColumn();
|
||||
$age_band_data = $age_band_sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
|
||||
print_r($age_band_data);
|
||||
|
||||
|
||||
//check age or dob column
|
||||
$members_heading = $members[0];
|
||||
// Kint::dump($members_heading);
|
||||
$available_col = null;
|
||||
$col_index = null;
|
||||
|
||||
@ -784,16 +786,346 @@ class LeadsController extends BaseController
|
||||
$this->myLogger->logme('error', ($message . $file_name_with_path));
|
||||
return ['status' => 'failed', 'message' => $message];
|
||||
}
|
||||
|
||||
//convert age slab data into array
|
||||
|
||||
try {
|
||||
$classifiers = $this->getDemographyData($members, $age_band_data, $members_heading, $available_col, $col_index);
|
||||
} catch (Exception $e) {
|
||||
return ['status' => 'fail', 'message' => $e->getMessage()];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
try {
|
||||
$result = $this->generateClassifierSpreadsheet($classifiers, 'writable/uploads/lead_files');
|
||||
|
||||
if ($result['success']) {
|
||||
$this->myLogger->logme('error', "Spreadsheet generated successfully!");
|
||||
echo "Location: " . $result['fullpath'] . "\n";
|
||||
echo "Filename: " . $result['filename'] . "\n";
|
||||
$filePaths = [
|
||||
['file_path' => WRITEPATH . 'uploads/lead_files/' . $lead_data['file_name'], 'sheets' => [0, 1]],
|
||||
['file_path' => 'writable/uploads/lead_files/' . $result['filename'], 'sheets' => []],
|
||||
];
|
||||
$outputPath = WRITEPATH . 'uploads/lead_files/Member_Data.xlsx';
|
||||
$result = ExcelMergeHelper::mergeExcelFiles($filePaths, $outputPath);
|
||||
if ($result) {
|
||||
return ['status' => 'success', 'message' => 'Member_Data Merged Suceesfully'];
|
||||
}
|
||||
} else {
|
||||
echo "Error generating spreadsheet: " . $result['error'];
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo "Error: " . $e->getMessage();
|
||||
return ['status' => 'fail', 'message' => $e->getMessage()];
|
||||
}
|
||||
} else {
|
||||
$this->myLogger->logme('error', (' no file found ' . $file_name_with_path));
|
||||
return ['status' => 'failed', 'message' => 'no file found'];
|
||||
}
|
||||
}
|
||||
|
||||
public function getDemographyData($members, $age_band_data, $members_heading, $available_col, $col_index)
|
||||
{
|
||||
$first_loop = 0;
|
||||
$col_index_si = array_search('si enhancement', array_map('strtolower', $members_heading));
|
||||
$col_index_relationship = array_search('relationship', array_map('strtolower', $members_heading));
|
||||
$relations = [];
|
||||
$si_amt = ['general']; // Initialize with 'general' as per first loop condition
|
||||
|
||||
// First pass - collect unique relations and SI amounts
|
||||
foreach ($members as $member) {
|
||||
if ($first_loop == 0) {
|
||||
$first_loop++;
|
||||
continue;
|
||||
}
|
||||
if ($member == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!in_array($member[$col_index_relationship], $relations) && $member[$col_index_relationship] != null) {
|
||||
$relations[] = $member[$col_index_relationship];
|
||||
}
|
||||
|
||||
if (!in_array($member[$col_index_si], $si_amt) && $member[$col_index_si] != null) {
|
||||
$si_amt[] = $member[$col_index_si];
|
||||
}
|
||||
}
|
||||
// Initialize classifier array
|
||||
$classifiers = [];
|
||||
foreach ($si_amt as $si) {
|
||||
$classifiers[$si] = [];
|
||||
// Initialize relation counts including Grand Total row
|
||||
foreach ($relations as $relation) {
|
||||
$classifiers[$si][$relation] = [];
|
||||
foreach ($age_band_data as $age_bands) {
|
||||
foreach ($age_bands as $age_interval) {
|
||||
$classifiers[$si][$relation][$age_interval] = 0;
|
||||
}
|
||||
}
|
||||
// Add Grand Total column for each relation echo('test passed 3.5');
|
||||
|
||||
$classifiers[$si][$relation]['Grand Total'] = 0;
|
||||
}
|
||||
// Initialize Grand Total row
|
||||
$classifiers[$si]['Grand Total'] = [];
|
||||
foreach ($age_band_data as $age_bands) {
|
||||
foreach ($age_bands as $age_interval) {
|
||||
$classifiers[$si]['Grand Total'][$age_interval] = 0;
|
||||
}
|
||||
}
|
||||
// Add grand total of grand totals
|
||||
$classifiers[$si]['Grand Total']['Grand Total'] = 0;
|
||||
}
|
||||
// Process members and count them
|
||||
foreach ($members as $member) {
|
||||
if ($first_loop == 0) {
|
||||
$first_loop++;
|
||||
continue;
|
||||
}
|
||||
// Get age
|
||||
$age = $this->getAge($available_col, $member, $col_index);
|
||||
|
||||
|
||||
$relation = $member[$col_index_relationship];
|
||||
$member_si = $member[$col_index_si];
|
||||
|
||||
// Find the correct age band (only once per member)
|
||||
$found_band = false;
|
||||
foreach ($age_band_data as $age_bands) {
|
||||
if ($found_band) break;
|
||||
|
||||
foreach ($age_bands as $age_band) {
|
||||
//get Min and Max Age
|
||||
list($min_age, $max_age) = $this->getAgeRange($age_band);
|
||||
|
||||
// If age fits in this band
|
||||
if ($age >= $min_age && $age <= $max_age) {
|
||||
// Update counts for general category
|
||||
if (isset($classifiers['general'][$relation][$age_band])) {
|
||||
// Increment count for specific relation and age band
|
||||
$classifiers['general'][$relation][$age_band]++;
|
||||
// Update row total (Grand Total column)
|
||||
$classifiers['general'][$relation]['Grand Total']++;
|
||||
// Update column total (Grand Total row)
|
||||
$classifiers['general']['Grand Total'][$age_band]++;
|
||||
// Update grand total of grand totals
|
||||
$classifiers['general']['Grand Total']['Grand Total']++;
|
||||
}
|
||||
|
||||
// Update counts for specific SI category
|
||||
if (isset($classifiers[$member_si][$relation][$age_band])) {
|
||||
// Increment count for specific relation and age band
|
||||
$classifiers[$member_si][$relation][$age_band]++;
|
||||
// Update row total (Grand Total column)
|
||||
$classifiers[$member_si][$relation]['Grand Total']++;
|
||||
// Update column total (Grand Total row)
|
||||
$classifiers[$member_si]['Grand Total'][$age_band]++;
|
||||
// Update grand total of grand totals
|
||||
$classifiers[$member_si]['Grand Total']['Grand Total']++;
|
||||
}
|
||||
|
||||
$found_band = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $classifiers;
|
||||
}
|
||||
|
||||
public function generateClassifierSpreadsheet($classifiers, $outputDir = 'exports')
|
||||
{
|
||||
|
||||
if (!file_exists($outputDir)) {
|
||||
if (!mkdir($outputDir, 0755, true)) {
|
||||
throw new Exception("Failed to create directory: $outputDir");
|
||||
}
|
||||
}
|
||||
|
||||
// Check if directory is writable
|
||||
if (!is_writable($outputDir)) {
|
||||
throw new Exception("Directory is not writable: $outputDir");
|
||||
}
|
||||
|
||||
// Generate unique filename
|
||||
$timestamp = date('Y-m-d_His');
|
||||
$filename = "member_classification_{$timestamp}.xlsx";
|
||||
$filepath = $outputDir . DIRECTORY_SEPARATOR . $filename;
|
||||
|
||||
// Check if file already exists (shouldn't happen with timestamp, but just in case)
|
||||
if (file_exists($filepath)) {
|
||||
$counter = 1;
|
||||
while (file_exists($outputDir . DIRECTORY_SEPARATOR . "member_classification_{$timestamp}_{$counter}.xlsx")) {
|
||||
$counter++;
|
||||
}
|
||||
$filename = "member_classification_{$timestamp}_{$counter}.xlsx";
|
||||
$filepath = $outputDir . DIRECTORY_SEPARATOR . $filename;
|
||||
}
|
||||
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
// Get all age bands
|
||||
$age_bands = array_keys(reset($classifiers['general']));
|
||||
array_pop($age_bands); // Remove 'Grand Total'
|
||||
$age_bands[] = 'Grand Total'; // Add it back at the end
|
||||
|
||||
$currentRow = 5; // Start from row 5 to match the example
|
||||
|
||||
// Function to write section data
|
||||
$writeSectionData = function ($data, $sheet, &$currentRow) use ($age_bands) {
|
||||
// Set headers
|
||||
$sheet->setCellValue('B' . $currentRow, 'Relationship');
|
||||
$col = 'C';
|
||||
foreach ($age_bands as $band) {
|
||||
$sheet->setCellValue($col . $currentRow, $band);
|
||||
$col++;
|
||||
}
|
||||
|
||||
// Style headers
|
||||
$lastCol = chr(ord('B') + count($age_bands));
|
||||
$headerRange = 'B' . $currentRow . ':' . $lastCol . $currentRow;
|
||||
$sheet->getStyle($headerRange)->applyFromArray([
|
||||
'font' => ['bold' => true],
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
],
|
||||
'alignment' => [
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
],
|
||||
]);
|
||||
|
||||
$currentRow++;
|
||||
|
||||
// Write data rows
|
||||
foreach ($data as $relation => $values) {
|
||||
if ($relation !== 'Grand Total') {
|
||||
$sheet->setCellValue('B' . $currentRow, $relation);
|
||||
$col = 'C';
|
||||
foreach ($age_bands as $band) {
|
||||
$value = $values[$band] ?: ''; // Convert 0 to empty string
|
||||
$sheet->setCellValue($col . $currentRow, $value);
|
||||
$col++;
|
||||
}
|
||||
|
||||
// Style data row
|
||||
$dataRange = 'B' . $currentRow . ':' . $lastCol . $currentRow;
|
||||
$sheet->getStyle($dataRange)->applyFromArray([
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
],
|
||||
'alignment' => [
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
],
|
||||
]);
|
||||
|
||||
$currentRow++;
|
||||
}
|
||||
}
|
||||
|
||||
// Add Grand Total row
|
||||
$sheet->setCellValue('B' . $currentRow, 'Grand Total');
|
||||
$col = 'C';
|
||||
foreach ($age_bands as $band) {
|
||||
$sheet->setCellValue($col . $currentRow, $data['Grand Total'][$band]);
|
||||
$col++;
|
||||
}
|
||||
|
||||
// Style Grand Total row
|
||||
$totalRange = 'B' . $currentRow . ':' . $lastCol . $currentRow;
|
||||
$sheet->getStyle($totalRange)->applyFromArray([
|
||||
'font' => ['bold' => true],
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
],
|
||||
'fill' => [
|
||||
'fillType' => Fill::FILL_SOLID,
|
||||
'startColor' => ['rgb' => 'F2F2F2'],
|
||||
],
|
||||
'alignment' => [
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
],
|
||||
]);
|
||||
|
||||
$currentRow += 3; // Add gap after each section
|
||||
};
|
||||
|
||||
// Write each SI section with gaps
|
||||
foreach ($classifiers as $si_type => $data) {
|
||||
$writeSectionData($data, $sheet, $currentRow);
|
||||
}
|
||||
|
||||
// Auto-size columns
|
||||
foreach (range('B', chr(ord('B') + count($age_bands))) as $col) {
|
||||
$sheet->getColumnDimension($col)->setAutoSize(true);
|
||||
}
|
||||
|
||||
// Create Excel file
|
||||
try {
|
||||
// Create Excel file
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$writer->save($filepath);
|
||||
|
||||
// Verify file was created successfully
|
||||
if (!file_exists($filepath)) {
|
||||
throw new Exception("Failed to create file: $filepath");
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'filepath' => $filepath,
|
||||
'filename' => $filename,
|
||||
'fullpath' => realpath($filepath)
|
||||
];
|
||||
} catch (Exception $e) {
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function getAge($available_col, $member, $col_index)
|
||||
{
|
||||
if ($available_col == 'age') {
|
||||
$age = $member[$col_index];
|
||||
} else {
|
||||
$dob = $member[$col_index];
|
||||
if ($dob == 'DOB') {
|
||||
return;
|
||||
}
|
||||
$dobDate = \DateTime::createFromFormat('d-M-Y', $dob);
|
||||
$currentDate = new \DateTime();
|
||||
if ($dobDate == false) {
|
||||
$this->myLogger->logme('error', $dob . 'is not valid');
|
||||
return;
|
||||
}
|
||||
$age = $currentDate->diff($dobDate)->y;
|
||||
}
|
||||
return $age;
|
||||
}
|
||||
|
||||
public function getAgeRange($age_band)
|
||||
{
|
||||
$age_band = trim($age_band);
|
||||
// Parse age range
|
||||
if (strpos($age_band, '-') === false) {
|
||||
$min_age = (int)filter_var($age_band, FILTER_SANITIZE_NUMBER_INT);
|
||||
$max_age = PHP_INT_MAX;
|
||||
} else {
|
||||
$parts = explode("-", $age_band);
|
||||
$min_age = (int)$parts[0];
|
||||
$max_age = (int)$parts[1];
|
||||
}
|
||||
|
||||
return array($min_age, $max_age);
|
||||
}
|
||||
|
||||
|
||||
@ -802,7 +1134,7 @@ class LeadsController extends BaseController
|
||||
{
|
||||
helper('excel_util_helper');
|
||||
helper('MailHelper');
|
||||
|
||||
helper('ExcelMergeHelper');
|
||||
$params = $this->request->getGet();
|
||||
// print_r($params); die;
|
||||
$lead_id = $params['lead_id'];
|
||||
@ -870,12 +1202,28 @@ class LeadsController extends BaseController
|
||||
|
||||
//get file path to attach
|
||||
$file_info = $this->constructExcelToSaveTemp($lead_id, ($file_type == 'rfq' ? 1 : 2), $propsal_and_insurer);
|
||||
if ($lead_data['file_name'] != null && $lead_data['file_name'] != '') {
|
||||
$temp_file_path = $file_info['filePath'];
|
||||
$temp_file_name = $file_info['fileName'];
|
||||
$lead_file_path = WRITEPATH . 'uploads/lead_files/' . $lead_data['file_name'];
|
||||
if ($lead_file_path) {
|
||||
$filePaths = [
|
||||
['file_path' => $temp_file_path, 'sheets' => []],
|
||||
['file_path' => $lead_file_path, 'sheets' => []]
|
||||
];
|
||||
$outputPath = dirname($temp_file_path) . '/' . 'merged_' . $temp_file_name;
|
||||
$result = ExcelMergeHelper::mergeExcelFiles($filePaths, $outputPath);
|
||||
// print_rr($result);
|
||||
}
|
||||
}
|
||||
// print_rr($lead_data);
|
||||
// print_rr($file_info);
|
||||
// $file_path = WRITEPATH."uploads/excel/sample/correction.xls";
|
||||
// $file_name = $file_type.'.xlsx';
|
||||
// !dd($file_info);
|
||||
|
||||
$file_path = $file_info['filePath'];
|
||||
$file_name = $file_info['fileName'];
|
||||
$file_path = $result;
|
||||
$file_name = basename($result);
|
||||
$attachments = [['fileName' => $file_name, 'filePath' => $file_path]];
|
||||
|
||||
//get recipient address
|
||||
@ -956,7 +1304,6 @@ class LeadsController extends BaseController
|
||||
} else {
|
||||
return $this->respond(['status' => false], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getInsurerBranchContacts($insurer_and_branch_id)
|
||||
@ -1082,7 +1429,6 @@ class LeadsController extends BaseController
|
||||
$data['premium_data']['data'] = $premiumData;
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
public function convertJsonForQCR($json, $type)
|
||||
@ -1329,29 +1675,82 @@ class LeadsController extends BaseController
|
||||
private function convertQCRJsonToPolicyTerms($data, $policy_type, $proposel_name, $insurer_name)
|
||||
{
|
||||
$GMC_Keys = [
|
||||
"sum_insured", "family_floater", "family_floaters", "age_ratio", "waiverofpreexistingdiseases",
|
||||
"maternitycoverage", "twindelivery", "preandpostnatal", "babyday1cover", "9monthwaitingperiodwaived",
|
||||
"coverfromthedateofjoining", "waiverof1,2,3&4thyearexclusions", "waiverof30dayswaitingperiod",
|
||||
"prehospitalizationcover", "congenitaldiseasesinternal", "copayzonewisecopay",
|
||||
"bioabsorbablestenttoriclensmultifocallens", "roomrentlimit", "proportionatedeductionclause",
|
||||
"ailmentcapping", "ambulancecharges", "airambulance", "familytransportationbenefit",
|
||||
"reasonableandcustomarycharges", "ayudhtreatmentcover", "congenitaldiseasesexternal",
|
||||
"optionalparentalcopay", "posthospitalizationcover", "corporatebuffer", "sublimitofcorporatebuffer",
|
||||
"ayushTreatmentCoverData", "armdcovered", "suminsuredenhancement", "automaticsuminsuredreinstatement",
|
||||
"additionalsicknessbenefit", "lasiksurgery", "midterminclusion", "capd", "organdonorexpenses",
|
||||
"moderntreatmentsasperirdai", "Wellness", "days_of_discharge", "days_from_dod",
|
||||
"special_condition_label", "special_condition_input", "multiple_sum_insured",
|
||||
"cataract", "cataractData"
|
||||
"sum_insured",
|
||||
"family_floater",
|
||||
"family_floaters",
|
||||
"age_ratio",
|
||||
"waiverofpreexistingdiseases",
|
||||
"maternitycoverage",
|
||||
"twindelivery",
|
||||
"preandpostnatal",
|
||||
"babyday1cover",
|
||||
"9monthwaitingperiodwaived",
|
||||
"coverfromthedateofjoining",
|
||||
"waiverof1,2,3&4thyearexclusions",
|
||||
"waiverof30dayswaitingperiod",
|
||||
"prehospitalizationcover",
|
||||
"congenitaldiseasesinternal",
|
||||
"copayzonewisecopay",
|
||||
"bioabsorbablestenttoriclensmultifocallens",
|
||||
"roomrentlimit",
|
||||
"proportionatedeductionclause",
|
||||
"ailmentcapping",
|
||||
"ambulancecharges",
|
||||
"airambulance",
|
||||
"familytransportationbenefit",
|
||||
"reasonableandcustomarycharges",
|
||||
"ayudhtreatmentcover",
|
||||
"congenitaldiseasesexternal",
|
||||
"optionalparentalcopay",
|
||||
"posthospitalizationcover",
|
||||
"corporatebuffer",
|
||||
"sublimitofcorporatebuffer",
|
||||
"ayushTreatmentCoverData",
|
||||
"armdcovered",
|
||||
"suminsuredenhancement",
|
||||
"automaticsuminsuredreinstatement",
|
||||
"additionalsicknessbenefit",
|
||||
"lasiksurgery",
|
||||
"midterminclusion",
|
||||
"capd",
|
||||
"organdonorexpenses",
|
||||
"moderntreatmentsasperirdai",
|
||||
"Wellness",
|
||||
"days_of_discharge",
|
||||
"days_from_dod",
|
||||
"special_condition_label",
|
||||
"special_condition_input",
|
||||
"multiple_sum_insured",
|
||||
"cataract",
|
||||
"cataractData"
|
||||
];
|
||||
|
||||
$GPA_Keys = [
|
||||
"sumInsured2", "totalSumInsured", "age_ratio", "accidentalDeathBenefit", "permanentTotalDisablement",
|
||||
"permanentPartialDisablement", "temporaryTotalDisablementBenefit", "accidentalHospitalizationExpenses",
|
||||
"childrenEducationWelfareFund", "compassionateVisitExpenses", "compassionateVisitExpensesData",
|
||||
"brokenBoneExpenses", "brokenBoneExpensesData", "ambulanceCharges", "ambulanceChargesData",
|
||||
"burnExpenses", "burnExpensesData", "carriageOfDeadBody", "carriageOfDeadBodyData",
|
||||
"animalSnakeInsectBite", "terrorism", "worldwideCover", "gpa_special_condition_label",
|
||||
"gpa_special_condition_input", "multiple_sum_insured"
|
||||
"sumInsured2",
|
||||
"totalSumInsured",
|
||||
"age_ratio",
|
||||
"accidentalDeathBenefit",
|
||||
"permanentTotalDisablement",
|
||||
"permanentPartialDisablement",
|
||||
"temporaryTotalDisablementBenefit",
|
||||
"accidentalHospitalizationExpenses",
|
||||
"childrenEducationWelfareFund",
|
||||
"compassionateVisitExpenses",
|
||||
"compassionateVisitExpensesData",
|
||||
"brokenBoneExpenses",
|
||||
"brokenBoneExpensesData",
|
||||
"ambulanceCharges",
|
||||
"ambulanceChargesData",
|
||||
"burnExpenses",
|
||||
"burnExpensesData",
|
||||
"carriageOfDeadBody",
|
||||
"carriageOfDeadBodyData",
|
||||
"animalSnakeInsectBite",
|
||||
"terrorism",
|
||||
"worldwideCover",
|
||||
"gpa_special_condition_label",
|
||||
"gpa_special_condition_input",
|
||||
"multiple_sum_insured"
|
||||
];
|
||||
|
||||
// Select keys based on policy type
|
||||
@ -1383,8 +1782,10 @@ class LeadsController extends BaseController
|
||||
$value = $cellData['value'] ?? '';
|
||||
|
||||
// Skip unwanted keys
|
||||
if (in_array($parentth, ['Sno', 'Item Key', 'Particulars', 'Action']) ||
|
||||
in_array($subth, ['Quote Asked'])) {
|
||||
if (
|
||||
in_array($parentth, ['Sno', 'Item Key', 'Particulars', 'Action']) ||
|
||||
in_array($subth, ['Quote Asked'])
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1444,7 +1845,6 @@ class LeadsController extends BaseController
|
||||
}
|
||||
|
||||
return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => $data], 200);
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
|
||||
@ -4,90 +4,215 @@ namespace App\Helpers;
|
||||
use Exception;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class ExcelMergeHelper
|
||||
{
|
||||
/**
|
||||
* Merge multiple Excel files into a single spreadsheet.
|
||||
*
|
||||
* @param array $filesToMerge Array of files to merge.
|
||||
* @param string $outputPath Path to save the merged file.
|
||||
* @return bool True if merge successful, false otherwise.
|
||||
*/
|
||||
public static function mergeExcelFiles(array $filesToMerge, string $outputPath): bool
|
||||
|
||||
protected static $logger;
|
||||
|
||||
public static function initialize()
|
||||
{
|
||||
self::$logger = \Config\Services::mylogger();
|
||||
}
|
||||
public static function mergeExcelFiles(array $filesToMerge, string $outputPath)
|
||||
{
|
||||
try {
|
||||
// Validate input: If no files are provided, throw an error.
|
||||
self::initialize();
|
||||
if (empty($filesToMerge)) {
|
||||
throw new Exception("No files provided for merging");
|
||||
throw new Exception("No files provided for merging.");
|
||||
}
|
||||
|
||||
// Initialize the base spreadsheet (starting with null, will be created with the first file)
|
||||
$spreadsheet = null;
|
||||
|
||||
// Loop through the files to merge
|
||||
foreach ($filesToMerge as $filePath => $sheetsToMerge) {
|
||||
// Load the current file
|
||||
$currentSpreadsheet = IOFactory::load($filePath);
|
||||
|
||||
// Debugging: Log the number of sheets in the current file
|
||||
error_log("File: $filePath has " . $currentSpreadsheet->getSheetCount() . " sheets.");
|
||||
|
||||
// If this is the first file, initialize the base spreadsheet
|
||||
if ($spreadsheet === null) {
|
||||
$spreadsheet = $currentSpreadsheet;
|
||||
|
||||
// If specific sheets are provided for the first file, remove the others
|
||||
if (!is_null($sheetsToMerge) && !empty($sheetsToMerge)) {
|
||||
$sheetCount = $spreadsheet->getSheetCount();
|
||||
for ($i = $sheetCount - 1; $i >= 0; $i--) {
|
||||
if (!in_array($i, $sheetsToMerge)) {
|
||||
$spreadsheet->removeSheetByIndex($i);
|
||||
// Validate files exist and are readable
|
||||
foreach ($filesToMerge as $fileData) {
|
||||
if (!file_exists($fileData['file_path'])) {
|
||||
throw new Exception("File not found: " . $fileData['file_path']);
|
||||
}
|
||||
if (!is_readable($fileData['file_path'])) {
|
||||
throw new Exception("File not readable: " . $fileData['file_path']);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If we are not working with the first file, we need to merge specified sheets
|
||||
if (is_null($sheetsToMerge) || empty($sheetsToMerge)) {
|
||||
// If no specific sheets, merge all sheets
|
||||
$sheetsToMerge = range(0, $currentSpreadsheet->getSheetCount() - 1);
|
||||
|
||||
self::$logger->logme('error',"Creating new spreadsheet...");
|
||||
$mergedSpreadsheet = new Spreadsheet();
|
||||
$firstSheet = true;
|
||||
|
||||
foreach ($filesToMerge as $fileIndex => $fileData) {
|
||||
$filePath = $fileData['file_path'];
|
||||
$sheetsToMerge = $fileData['sheets'];
|
||||
self::$logger->logme('error',"Processing file $fileIndex: $filePath");
|
||||
|
||||
try {
|
||||
self::$logger->logme('error',"Attempting to load file: $filePath");
|
||||
$reader = IOFactory::createReaderForFile($filePath);
|
||||
$reader->setReadDataOnly(true); // This can help with memory usage
|
||||
self::$logger->logme('error',"Reader created successfully");
|
||||
|
||||
$currentSpreadsheet = $reader->load($filePath);
|
||||
self::$logger->logme('error',"File loaded successfully");
|
||||
|
||||
$sheetCount = $currentSpreadsheet->getSheetCount();
|
||||
self::$logger->logme('error',"File $filePath has $sheetCount sheets.");
|
||||
|
||||
if (empty($sheetsToMerge)) {
|
||||
$sheetsToMerge = range(0, $sheetCount - 1);
|
||||
}
|
||||
|
||||
// Merge the specified sheets from the current file
|
||||
foreach ($sheetsToMerge as $sheetIndex) {
|
||||
// Check if sheet index is within bounds
|
||||
if ($sheetIndex < 0 || $sheetIndex >= $currentSpreadsheet->getSheetCount()) {
|
||||
throw new Exception("Invalid sheet index $sheetIndex in file $filePath");
|
||||
foreach ($sheetsToMerge as $sourceSheetIndex) {
|
||||
self::$logger->logme('error',"Processing sheet index: $sourceSheetIndex");
|
||||
|
||||
if ($sourceSheetIndex < 0 || $sourceSheetIndex >= $sheetCount) {
|
||||
self::$logger->logme('error',"Invalid sheet index $sourceSheetIndex in file $filePath");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Retrieve the sheet to copy
|
||||
$sheetToCopy = $currentSpreadsheet->getSheet($sheetIndex);
|
||||
try {
|
||||
$sourceSheet = $currentSpreadsheet->getSheet($sourceSheetIndex);
|
||||
self::$logger->logme('error',"Source sheet loaded");
|
||||
|
||||
// Handle sheet name collision by renaming the sheet with a counter
|
||||
$baseName = $sheetToCopy->getTitle();
|
||||
$sheetName = $baseName;
|
||||
$baseName = $sourceSheet->getTitle();
|
||||
self::$logger->logme('error',"Processing sheet: $baseName");
|
||||
|
||||
$newSheetName = $baseName;
|
||||
$counter = 1;
|
||||
while ($spreadsheet->sheetNameExists($sheetName)) {
|
||||
$sheetName = $baseName . '_merged_' . $counter;
|
||||
|
||||
while ($mergedSpreadsheet->sheetNameExists($newSheetName)) {
|
||||
$newSheetName = $baseName . '_' . $fileIndex . '_' . $counter;
|
||||
$counter++;
|
||||
}
|
||||
$sheetToCopy->setTitle($sheetName);
|
||||
self::$logger->logme('error',"New sheet name will be: $newSheetName");
|
||||
|
||||
// Clone and add the sheet to the base spreadsheet
|
||||
$spreadsheet->addSheet(clone $sheetToCopy);
|
||||
if ($firstSheet) {
|
||||
$targetSheet = $mergedSpreadsheet->getActiveSheet();
|
||||
$targetSheet->setTitle($newSheetName);
|
||||
$firstSheet = false;
|
||||
self::$logger->logme('error',"Using first sheet");
|
||||
} else {
|
||||
$targetSheet = new Worksheet($mergedSpreadsheet, $newSheetName);
|
||||
$mergedSpreadsheet->addSheet($targetSheet);
|
||||
self::$logger->logme('error',"Created new sheet");
|
||||
}
|
||||
|
||||
self::$logger->logme('error',"Starting content copy for sheet: $newSheetName");
|
||||
self::copyWorksheetContent($sourceSheet, $targetSheet);
|
||||
self::$logger->logme('error',"Content copied successfully for sheet: $newSheetName");
|
||||
|
||||
} catch (Exception $e) {
|
||||
self::$logger->logme('error',"Error processing sheet $sourceSheetIndex: " . $e->getMessage());
|
||||
self::$logger->logme('error',"Error trace: " . $e->getTraceAsString());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Save the merged file
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
// Free up memory
|
||||
$currentSpreadsheet->disconnectWorksheets();
|
||||
unset($currentSpreadsheet);
|
||||
self::$logger->logme('error',"Cleaned up spreadsheet resources");
|
||||
|
||||
} catch (Exception $e) {
|
||||
self::$logger->logme('error',"Error processing file $filePath: " . $e->getMessage());
|
||||
self::$logger->logme('error',"Error trace: " . $e->getTraceAsString());
|
||||
continue;
|
||||
}
|
||||
|
||||
self::$logger->logme('error',"Current sheet names in merged spreadsheet:");
|
||||
foreach ($mergedSpreadsheet->getSheetNames() as $name) {
|
||||
self::$logger->logme('error'," - $name");
|
||||
}
|
||||
}
|
||||
|
||||
if ($mergedSpreadsheet->getSheetCount() === 0) {
|
||||
throw new Exception("No sheets were successfully merged.");
|
||||
}
|
||||
|
||||
self::$logger->logme('error',"Setting active sheet to index 0");
|
||||
$mergedSpreadsheet->setActiveSheetIndex(0);
|
||||
|
||||
self::$logger->logme('error',"Preparing to save merged file to: $outputPath");
|
||||
|
||||
// Ensure output directory exists
|
||||
$outputDir = dirname($outputPath);
|
||||
if (!is_dir($outputDir)) {
|
||||
mkdir($outputDir, 0777, true);
|
||||
}
|
||||
|
||||
if (!is_writable($outputDir)) {
|
||||
throw new Exception("Output directory is not writable: $outputDir");
|
||||
}
|
||||
|
||||
if (ob_get_length()) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
self::$logger->logme('error',"Creating Excel writer");
|
||||
$writer = new Xlsx($mergedSpreadsheet);
|
||||
|
||||
self::$logger->logme('error',"Saving file...");
|
||||
$writer->save($outputPath);
|
||||
|
||||
return true; // Return true if merge was successful
|
||||
// Free up memory
|
||||
$mergedSpreadsheet->disconnectWorksheets();
|
||||
unset($mergedSpreadsheet);
|
||||
|
||||
self::$logger->logme('error',"Merge successful. File saved at: $outputPath");
|
||||
return $outputPath;
|
||||
|
||||
} catch (Exception $e) {
|
||||
// Log the error (optional) and return false on failure
|
||||
error_log("Excel Merge Error: " . $e->getMessage());
|
||||
return false;
|
||||
self::$logger->logme('error',"Excel Merge Error: " . $e->getMessage());
|
||||
self::$logger->logme('error',"Error trace: " . $e->getTraceAsString());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
private static function copyWorksheetContent($sourceSheet, $targetSheet)
|
||||
{
|
||||
try {
|
||||
self::$logger->logme('error',"Starting copyWorksheetContent");
|
||||
|
||||
// Get the highest row and column indexes
|
||||
$highestRow = $sourceSheet->getHighestRow();
|
||||
$highestColumn = $sourceSheet->getHighestColumn();
|
||||
self::$logger->logme('error',"Copying data from range A1:{$highestColumn}{$highestRow}");
|
||||
|
||||
// Copy cell values only first for better performance
|
||||
foreach ($sourceSheet->getRowIterator() as $row) {
|
||||
$cellIterator = $row->getCellIterator();
|
||||
$cellIterator->setIterateOnlyExistingCells(true);
|
||||
foreach ($cellIterator as $cell) {
|
||||
$column = $cell->getColumn();
|
||||
$rowIndex = $cell->getRow();
|
||||
$targetSheet->setCellValue($column . $rowIndex, $cell->getValue());
|
||||
}
|
||||
}
|
||||
self::$logger->logme('error',"Basic cell values copied");
|
||||
|
||||
// Copy column dimensions
|
||||
foreach ($sourceSheet->getColumnDimensions() as $columnId => $sourceDim) {
|
||||
$targetSheet->getColumnDimension($columnId)
|
||||
->setWidth($sourceDim->getWidth())
|
||||
->setVisible($sourceDim->getVisible())
|
||||
->setAutoSize($sourceDim->getAutoSize());
|
||||
}
|
||||
self::$logger->logme('error',"Column dimensions copied");
|
||||
|
||||
// Copy row dimensions
|
||||
foreach ($sourceSheet->getRowDimensions() as $rowId => $sourceDim) {
|
||||
$targetSheet->getRowDimension($rowId)
|
||||
->setRowHeight($sourceDim->getRowHeight())
|
||||
->setVisible($sourceDim->getVisible());
|
||||
}
|
||||
self::$logger->logme('error',"Row dimensions copied");
|
||||
|
||||
// Copy basic worksheet properties
|
||||
$targetSheet->setShowGridlines($sourceSheet->getShowGridlines());
|
||||
$targetSheet->setShowRowColHeaders($sourceSheet->getShowRowColHeaders());
|
||||
self::$logger->logme('error',"Worksheet properties copied");
|
||||
|
||||
} catch (Exception $e) {
|
||||
self::$logger->logme('error',"Error in copyWorksheetContent: " . $e->getMessage());
|
||||
self::$logger->logme('error',"Error trace: " . $e->getTraceAsString());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
app/Models/COShareStmtDetailsModel.php
Normal file
38
app/Models/COShareStmtDetailsModel.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class COShareStmtDetailsModel extends Model
|
||||
{
|
||||
protected $table = 'co_share_stmt_details';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
'id',
|
||||
'co_share_id',
|
||||
'statement_id',
|
||||
'actual_bp_amt',
|
||||
'actual_tp_amt',
|
||||
'actual_tep_amt',
|
||||
'actual_bp_per',
|
||||
'actual_tp_per',
|
||||
'actual_tep_per',
|
||||
'actual_bp_brokerage_amt',
|
||||
'actual_tp_brokerage_amt',
|
||||
'actual_tep_brokerage_amt',
|
||||
'reward',
|
||||
'exp_amt',
|
||||
'variance',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'is_active'
|
||||
];
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -23,7 +23,11 @@ class InsurerStatements extends Model
|
||||
"invoice_no",
|
||||
"invoice_amount",
|
||||
"invoice_date",
|
||||
"updated_by"
|
||||
"updated_by",
|
||||
"stmt_sno",
|
||||
"gst_per",
|
||||
"gst_value",
|
||||
"invoice_value"
|
||||
|
||||
];
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ class InvPaymentDetailsModel extends Model
|
||||
'inv_amt',
|
||||
'utr_no',
|
||||
'tds',
|
||||
'gst',
|
||||
'received_date',
|
||||
'created_by',
|
||||
'is_active',
|
||||
|
||||
@ -67,8 +67,11 @@ class PTCOShareDetailsModel extends Model
|
||||
'follower_policy_no',
|
||||
];
|
||||
|
||||
public function getNonReconcileredPolicyTransactions(string $month,string $year,string $insurer_id,string $insurer_branch_id)
|
||||
public function getNonReconcileredPolicyTransactions(string $insurer_id,string $insurer_branch_id)
|
||||
{
|
||||
$currentDate = date('Y-m-d');
|
||||
$sixMonthsAgo = date('Y-m-01', strtotime('-6 months'));
|
||||
|
||||
return $this->db->table('pt_co_share_details pt_co')
|
||||
->select('
|
||||
pt_co.id,
|
||||
@ -94,12 +97,15 @@ class PTCOShareDetailsModel extends Model
|
||||
->join('policy_transaction pt', 'pt_co.pt_id = pt.id')
|
||||
->join('clients c', 'pt.client_id = c.id')
|
||||
->where('pt_co.is_active', 1)
|
||||
->where('MONTH(pt.month)', $month)
|
||||
->where('YEAR(pt.month)', $year)
|
||||
->where('pt.is_active', 1)
|
||||
// ->where('MONTH(pt.month)', $month)
|
||||
// ->where('YEAR(pt.month)', $year)
|
||||
->where('pt_co.insurer_id', $insurer_id)
|
||||
->where('pt_co.insurer_branch_id', $insurer_branch_id)
|
||||
->where('pt_co.statement_id is null')
|
||||
// ->where('pt_co.statement_id is null')
|
||||
->where('pt.status','completed')
|
||||
->where('DATE(pt.created_at) >=', $sixMonthsAgo)
|
||||
->where('DATE(pt.created_at) <=', $currentDate)
|
||||
// ->where('pt_co.exp_amt', 0.00)
|
||||
// ->orWhere('pt_co.exp_amt is null')
|
||||
->get()
|
||||
|
||||
@ -978,7 +978,7 @@ class PolicyTransactionModel extends Model
|
||||
return $builder->get()->getResultArray();
|
||||
}
|
||||
|
||||
public function getOutstandingReportList($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0)
|
||||
public function getOutstandingReportList_OLD($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0)
|
||||
{
|
||||
$builder = $this->db->table('policy_transaction')
|
||||
->select("
|
||||
@ -1076,4 +1076,52 @@ class PolicyTransactionModel extends Model
|
||||
return $builder->get()->getResultArray();
|
||||
}
|
||||
|
||||
public function getOutstandingReportList($start_date = 0, $end_date = 0, $insurer_id = 0,$insurer_branch_id = 0)
|
||||
{
|
||||
$builder = $this->db->table('insurer_statements s')
|
||||
->select('
|
||||
s.id,
|
||||
s.insurer_id,
|
||||
s.branch_id,
|
||||
ins.short_name,
|
||||
ib.branch_name,
|
||||
s.month,
|
||||
s.line_items,
|
||||
s.stmt_sno,
|
||||
s.invoice_status,
|
||||
s.invoice_date,
|
||||
s.invoice_no,
|
||||
s.invoice_amount,
|
||||
COALESCE(SUM(p.inv_amt) + SUM(p.tds) + SUM(p.gst), 0) AS total_paid,
|
||||
(s.invoice_amount - COALESCE(SUM(p.inv_amt) + SUM(p.tds) + SUM(p.gst), 0)) AS outstanding_amount
|
||||
')
|
||||
->join('inv_payment_details p', 's.id = p.statement_id', 'left')
|
||||
->join('insurers ins', 's.insurer_id = ins.id')
|
||||
->join('insurer_branch ib', 's.branch_id = ib.id')
|
||||
->where('s.is_active', 1)
|
||||
->where('p.is_active', 1)
|
||||
->groupBy('s.id, s.invoice_no, s.invoice_date, s.invoice_amount')
|
||||
->having('outstanding_amount >', 0);
|
||||
// ->get();
|
||||
|
||||
|
||||
// Date range filtering
|
||||
if ($start_date != 0 && $end_date != 0) {
|
||||
|
||||
$builder->where('s.month >=', $start_date)
|
||||
->where('s.month <=', $end_date);
|
||||
}
|
||||
|
||||
if ($insurer_id != 0) {
|
||||
$builder->where('s.insurer_id', $insurer_id);
|
||||
}
|
||||
if ($insurer_branch_id != 0) {
|
||||
$builder->where('s.branch_id', $insurer_branch_id);
|
||||
}
|
||||
|
||||
$builder->orderBy('s.id', 'desc');
|
||||
|
||||
return $builder->get()->getResultArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -103,6 +103,10 @@ table.dataTable tbody td {
|
||||
.slider.round:before {
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.disabled-option {
|
||||
color: gray;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="row" id="inception_list">
|
||||
@ -125,6 +129,7 @@ table.dataTable tbody td {
|
||||
<th></th>
|
||||
<th><div class="column-header">Insurer</div></th>
|
||||
<th><div class="column-header">Month</div></th>
|
||||
<th><div class="column-header">Statement<br>sno</div></th>
|
||||
<th><div class="column-header">Filename</div></th>
|
||||
<th><div class="column-header">Line<br>items</div></th>
|
||||
<th><div class="column-header">File<br>status</div></th>
|
||||
@ -140,6 +145,7 @@ table.dataTable tbody td {
|
||||
<td><input type="hidden" class="row-select" data-id="<?= $row['id']; ?>"></td>
|
||||
<td><?php echo $row['short_name'].'-'.$row['branch_code']; ?></td>
|
||||
<td><?php echo change_date_format($row['month'],'Y-m-d','M-Y'); ?></td>
|
||||
<td><?php echo $row['stmt_sno'] ?> </td>
|
||||
<td><?php echo $row['file_name'] ?> </td>
|
||||
<td><?php echo $row['line_items'] ?></td>
|
||||
<td><?php echo $row['file_status'];
|
||||
@ -172,6 +178,9 @@ table.dataTable tbody td {
|
||||
<a class="dropdown-item btnEdit" data-id="<?= $row['id'];?>" data-exp-amt="<?= $row['exp_inv_amt'];?>" data-received-amt="<?= $row['received_inv_amt'];?>" onclick="showInvoiceStatusModal(event)">
|
||||
<i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Invoice status
|
||||
</a>
|
||||
<a class="dropdown-item btnEdit" data-id="<?= $row['id'];?>"onclick="deleteStatement(<?= $row['id'];?>)">
|
||||
<i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
@ -218,8 +227,24 @@ table.dataTable tbody td {
|
||||
</div>
|
||||
<div class="form-group col-md-10">
|
||||
<label for="statement_month">Statement month</label>
|
||||
<input type="text" class="form-control" id="statement_month" name="statement_month" placeholder="" required readonly>
|
||||
<input type="text" class="form-control" id="statement_month" name="statement_month" placeholder="" required readonly onchange="getStatementNo()">
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-10">
|
||||
<label for="statement_no">Statement no</label>
|
||||
<select class="form-control" id="statement_no" name="statement_no" required >
|
||||
<option value="" selected>Select statement no</option>
|
||||
<?php
|
||||
$stmt_no = [1,2,3,4,5,6,7];
|
||||
if (isset($stmt_no) && count($stmt_no)) {
|
||||
foreach ($stmt_no as $key => $value) {
|
||||
echo "<option value=" . $value . ">" . $value . "</option>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-10" >
|
||||
<label for="statment">Statement </label> <span><a href="downloadSampleInsurerStatement" id="download_sample_file" style="font-size: small;">Download sample file</a></span>
|
||||
<input type="file" class="form-control" name="statement" required accept=" application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet">
|
||||
@ -255,7 +280,7 @@ table.dataTable tbody td {
|
||||
|
||||
<!-- Invoice status content modal-->
|
||||
<div class="modal fade" id="invoice_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-dialog modal-lg" style="max-width:1000px;">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" id="title">Update Invoice Status</h4>
|
||||
@ -286,32 +311,65 @@ table.dataTable tbody td {
|
||||
<label for="addon_policy">Exp Amount</label>
|
||||
<input type="text" class="form-control" id="modal_exp_amt" placeholder="" disabled>
|
||||
</div> -->
|
||||
<div class="form-group col-md-4" id="modal_received_amt_div">
|
||||
<label for="addon_policy">Total Received Amount</label>
|
||||
<input type="text" class="form-control" id="modal_received_amt" placeholder="" disabled>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Invoice Number and Invoice Date in same row -->
|
||||
<!-- <div id="invoice_no_div_modal" style="display: none;"> -->
|
||||
<div class="row" id="invoice_no_div_modal" style="display: none;">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="invoice_no">Invoice Number<span id="base_danger" class="text-danger"></span></label>
|
||||
<input type="text" class="form-control" id="invoice_no_modal" name="invoice_no" placeholder="Enter Invoice Number" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="invoice_no">Invoice Amount<span id="base_danger" class="text-danger"></span></label>
|
||||
<input type="number" class="form-control" id="invoice_amount_no_modal" name="invoice_amount" placeholder="Enter Invoice Amt" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="invoice_date">Invoice Date</label>
|
||||
<input type="text" class="form-control" id="invoice_date_modal" name="invoice_date" value="<?php echo date('Y-m-d'); ?>" readonly required>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="invoice_value_modal">Invoice value<span id="base_danger" class="text-danger"></span></label>
|
||||
<input type="number" class="form-control" id="invoice_value_modal" name="invoice_value" placeholder="Enter Invoice Value" readonly>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div class="row" id="invoice_no_div_modal2" style="display: none;">
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="gst_value_modal">GST %<span id="base_danger" class="text-danger"></span></label>
|
||||
<input type="number" class="form-control" id="gst_per_modal" name="invoice_gst_per" placeholder="Enter GST %" required onchange="calcGSTValue()">
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="gst_value_modal">GST Value<span id="base_danger" class="text-danger"></span></label>
|
||||
<input type="number" class="form-control" id="gst_value_modal" name="invoice_gst" placeholder="Enter Invoice Value" required readonly step="0.01">
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="invoice_no">Invoice Amount<span id="base_danger" class="text-danger"></span></label>
|
||||
<input type="number" class="form-control" id="invoice_amount_no_modal" name="invoice_amount" placeholder="Enter Invoice Amt" required readonly step="0.01">
|
||||
</div>
|
||||
|
||||
<!-- <div class="form-group col-md-3" id="modal_received_amt_div">
|
||||
<label for="addon_policy">Total Received Amount</label>
|
||||
<input type="text" class="form-control" id="modal_received_amt" placeholder="" disabled>
|
||||
</div> -->
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row" id="modal_received_amt_div">
|
||||
<div class="form-group col-md-4" >
|
||||
<label for="addon_policy">Total Received Amount</label>
|
||||
<input type="number" class="form-control" id="modal_received_amt" placeholder="" disabled>
|
||||
</div>
|
||||
</div>
|
||||
<!-- </div> -->
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Payment Received Table -->
|
||||
<div class="form-group col-md-12" style="display: none;" id="payment_table_div_modal">
|
||||
<div class="form-group col-md-12" style="display: none;" id="payment_table_div_modal" style="max-width: 800px;">
|
||||
<button type="button" id="add_row_btn" class="btn btn-secondary float-right"><i class="fa fa-plus"></i></button>
|
||||
|
||||
|
||||
@ -319,7 +377,8 @@ table.dataTable tbody td {
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="display: none;">pk</th>
|
||||
<th>Received Amount</th>
|
||||
<th>Invoice value</th>
|
||||
<th>GST</th>
|
||||
<th>TDS</th>
|
||||
<th>UTR Number</th>
|
||||
<th>Date</th>
|
||||
@ -330,6 +389,7 @@ table.dataTable tbody td {
|
||||
<tr>
|
||||
<td style="display: none;"><input type="hidden" class="form-control" name="pk[]" placeholder="Enter Amount"></td>
|
||||
<td><input type="number" class="form-control" name="received_amount[]" placeholder="Enter Amount" required onchange="checkInvAmont(event)"></td>
|
||||
<td><input type="number" class="form-control" name="gst_amount[]" placeholder="Enter GST" required step="0.01" onchange="checkInvAmont(event)"></td>
|
||||
<td><input type="number" class="form-control" name="tds[]" placeholder="Enter TDS" onchange="checkInvAmont(event)" required></td>
|
||||
<td><input type="text" class="form-control" name="utr_no[]" placeholder="Enter UTR No" required></td>
|
||||
<td><input type="text" class="form-control payment_date" name="payment_date[]" value="<?php echo date('d/m/Y'); ?>" placeholder="dd/mm/yyyy" required readonly></td>
|
||||
@ -358,12 +418,14 @@ table.dataTable tbody td {
|
||||
const invoiceStatus = this.value;
|
||||
console.log(invoiceStatus);
|
||||
const invoiceNoDiv = document.getElementById('invoice_no_div_modal');
|
||||
const invoiceNoDiv2 = document.getElementById('invoice_no_div_modal2');
|
||||
// const invoiceDateDiv = document.getElementById('invoice_date_div_modal');
|
||||
const paymentTableDiv = document.getElementById('payment_table_div_modal');
|
||||
const totalReceivedAmtDiv = document.getElementById('modal_received_amt_div');
|
||||
|
||||
// Hide everything initially
|
||||
invoiceNoDiv.style.display = 'none';
|
||||
invoiceNoDiv2.style.display = 'none';
|
||||
// invoiceDateDiv.style.display = 'none';
|
||||
paymentTableDiv.style.display = 'none';
|
||||
totalReceivedAmtDiv.style.display = 'none';
|
||||
@ -371,6 +433,7 @@ table.dataTable tbody td {
|
||||
// Show fields based on selected status
|
||||
if (invoiceStatus === 'generated' || invoiceStatus === 'sent') {
|
||||
invoiceNoDiv.style.display = 'flex';
|
||||
invoiceNoDiv2.style.display = 'flex';
|
||||
totalReceivedAmtDiv.style.display = 'none';
|
||||
switchRequired('invoice_no_modal',true);
|
||||
switchRequired('invoice_date_modal',true);
|
||||
@ -384,6 +447,7 @@ table.dataTable tbody td {
|
||||
// invoiceDateDiv.style.display = 'block';
|
||||
} else if (invoiceStatus === 'payment_received') {
|
||||
invoiceNoDiv.style.display = 'flex';
|
||||
invoiceNoDiv2.style.display = 'flex';
|
||||
paymentTableDiv.style.display = 'block';
|
||||
totalReceivedAmtDiv.style.display = 'block';
|
||||
switchRequired('invoice_no_modal',true);
|
||||
@ -399,6 +463,7 @@ table.dataTable tbody td {
|
||||
}else if(invoiceStatus === 'pending')
|
||||
{
|
||||
invoiceNoDiv.style.display = 'none';
|
||||
invoiceNoDiv2.style.display = 'none';
|
||||
paymentTableDiv.style.display = 'none';
|
||||
totalReceivedAmtDiv.style.display = 'none';
|
||||
// switchRequired('modal_received_amt_div',false);
|
||||
@ -435,6 +500,13 @@ table.dataTable tbody td {
|
||||
|
||||
$('#invoiceForm').on('submit', function (e) {
|
||||
e.preventDefault(); // Prevent default form submission
|
||||
|
||||
var res = checkInvAmont();
|
||||
if(!res)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var form = document.getElementById('invoiceForm');
|
||||
// alert(form.checkValidity());
|
||||
// alert($('#invoice_date_modal').val());
|
||||
@ -487,7 +559,7 @@ table.dataTable tbody td {
|
||||
|
||||
$('.close').click()
|
||||
// Reset the form data
|
||||
$('#invoiceForm')[0].reset();
|
||||
// $('#invoiceForm')[0].reset();
|
||||
|
||||
alert('Invoice updated successfully!');
|
||||
location.reload();
|
||||
@ -513,6 +585,7 @@ table.dataTable tbody td {
|
||||
newRow.innerHTML = `
|
||||
<td style="display: none;"><input type="hidden" class="form-control" name="pk[]" placeholder="Enter Amount"></td>
|
||||
<td><input type="number" class="form-control" name="received_amount[]" placeholder="Enter Amount" onchange="checkInvAmont(event)" required></td>
|
||||
<td><input type="number" class="form-control" name="gst_amount[]" placeholder="Enter GST" onchange="checkInvAmont(event)" required step="0.01"></td>
|
||||
<td><input type="number" class="form-control" name="tds[]" placeholder="Enter TDS" onchange="checkInvAmont(event)" required></td>
|
||||
<td><input type="text" class="form-control" name="utr_no[]" placeholder="Enter UTR No" required></td>
|
||||
<td><input type="text" class="form-control payment_date" value="<?php echo date('d/m/Y'); ?>" name="payment_date[]" placeholder="dd/mm/yyyy" required readonly></td>
|
||||
@ -628,6 +701,10 @@ function showInvoiceStatusModal(event)
|
||||
document.getElementById('invoice_date_modal').value = response.data.invoice_date === '' ? <?php echo date('d-m-Y')?> : response.data.invoice_date;
|
||||
document.getElementById('invoice_amount_no_modal').value = response.data.invoice_amount;
|
||||
|
||||
document.getElementById('invoice_value_modal').value = response.data.invoice_value;
|
||||
document.getElementById('gst_per_modal').value = response.data.gst_per;
|
||||
document.getElementById('gst_value_modal').value = response.data.gst_value;
|
||||
|
||||
if (!$('#invoice_date_modal').val()) {
|
||||
// alert('nope');
|
||||
// Set today's date as the default date
|
||||
@ -646,6 +723,7 @@ function showInvoiceStatusModal(event)
|
||||
row.innerHTML = `
|
||||
<td style="display: none;"><input type="hidden" class="form-control" name="pk[]" value="${payment.id}"></td>
|
||||
<td><input type="number" class="form-control" name="received_amount[]" placeholder="Enter Amount" value="${payment.inv_amt}" onchange="checkInvAmont(event)" required></td>
|
||||
<td><input type="number" class="form-control" name="gst_amount[]" placeholder="Enter Amount" value="${payment.gst}" onchange="checkInvAmont(event)" required step="0.01"></td>
|
||||
<td><input type="number" class="form-control" name="tds[]" placeholder="Enter Amount" value="${payment.tds}" onchange="checkInvAmont(event)" required></td>
|
||||
<td><input type="text" class="form-control" name="utr_no[]" placeholder="Enter UTR No" value="${payment.utr_no}" required></td>
|
||||
<td><input type="text" class="form-control payment_date" name="payment_date[]" value="${formatDateToDMY(payment.received_date)}" required readonly></td>
|
||||
@ -730,8 +808,6 @@ maxDate.setDate(today.getDate() + 180);
|
||||
}
|
||||
|
||||
$('#btnSubmit').prop('disabled', true).text('Submitting...');
|
||||
|
||||
|
||||
// Create FormData object
|
||||
var formData = new FormData($(this)[0]);
|
||||
for (var pair of formData.entries()) {
|
||||
@ -773,6 +849,9 @@ maxDate.setDate(today.getDate() + 180);
|
||||
toastr.error('Something went wrong! Try later', 'Error');
|
||||
window.location.reload(true);
|
||||
}
|
||||
$('.close').click()
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(10).fadeOut('slow');
|
||||
|
||||
$('#btnSubmit').prop('disabled', false).text('Submit');
|
||||
|
||||
@ -782,11 +861,13 @@ maxDate.setDate(today.getDate() + 180);
|
||||
console.error("Request failed:", status, error);
|
||||
toastr.error('Something went wrong! Try later', 'Error');
|
||||
$('#uploadForm')[0].reset();
|
||||
$('.close').click()
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(10).fadeOut('slow');
|
||||
window.location.reload(true);
|
||||
}
|
||||
});
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(10).fadeOut('slow');
|
||||
|
||||
});
|
||||
|
||||
function fetchFileError(file_id) {
|
||||
@ -810,7 +891,7 @@ maxDate.setDate(today.getDate() + 180);
|
||||
var file_error_html = "";
|
||||
|
||||
if (file_error_data['error_code'] == 1) {
|
||||
file_error_html += 'The following row no(s) from excel are <span style="font-weight:bold">either already mapped / not found with policy transactions / duplicates.</span>';
|
||||
file_error_html += 'The following row no(s) from excel are <span style="font-weight:bold">not found with policy transactions / duplicates.</span>';
|
||||
file_error_html += ' : ' + '<span style="font-weight:bolder">' + file_error_data['error_data'].join(',') + '</span>';
|
||||
}
|
||||
|
||||
@ -835,19 +916,21 @@ maxDate.setDate(today.getDate() + 180);
|
||||
}
|
||||
|
||||
|
||||
function checkInvAmont(event) {
|
||||
function checkInvAmont(event = null) {
|
||||
var total = 0;
|
||||
var receivedAmounts = document.querySelectorAll('input[name="received_amount[]"]');
|
||||
var receivedGST = document.querySelectorAll('input[name="gst_amount[]"]');
|
||||
var tdsAmounts = document.querySelectorAll('input[name="tds[]"]');
|
||||
// console.log();
|
||||
receivedAmounts.forEach(function(el, index) {
|
||||
// Get the received amount
|
||||
let receivedVal = parseFloat(el.value) || 0;
|
||||
// Get the corresponding tds amount (paired with the received amount)
|
||||
let gstVal = parseFloat(receivedGST[index].value) || 0;
|
||||
let tdsVal = parseFloat(tdsAmounts[index].value) || 0;
|
||||
// Add received amount and tds amount
|
||||
// console.log();
|
||||
total += (receivedVal + tdsVal);
|
||||
total += (receivedVal + tdsVal + gstVal);
|
||||
});
|
||||
// console.log(total);
|
||||
// Get the expected invoice amount
|
||||
@ -855,9 +938,16 @@ function checkInvAmont(event) {
|
||||
|
||||
// Check if the total exceeds the expected amount
|
||||
if (exp_amt < total) {
|
||||
alert('Exceeds Invoice amount');
|
||||
event.target.value = ''; // Reset the value of the element that triggered the event
|
||||
alert('Exceeds Invoice amount...Plz adjust numbers');
|
||||
if(event != null)
|
||||
{
|
||||
event.target.value = '';
|
||||
|
||||
}
|
||||
return false; // Reset the value of the element that triggered the event
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -889,5 +979,186 @@ function switchRequired(elementId, isRequired, type = 'id') {
|
||||
}
|
||||
}
|
||||
|
||||
function getStatementNo()
|
||||
{
|
||||
var insurer_id = $('#insurer').val();
|
||||
var statement_month = $('#statement_month').val();
|
||||
|
||||
console.log(insurer_id+' / '+statement_month);
|
||||
if(insurer_id == "")
|
||||
{
|
||||
alert('Choose insurer...!');
|
||||
$('#statement_month').val('');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$('.loader').fadeIn();
|
||||
$('.loader-mask').fadeIn();
|
||||
var apiURL = 'getInsurerStatementMonth?insurer_id=' +insurer_id+'&month='+statement_month ;
|
||||
$.ajax({
|
||||
url: apiURL,
|
||||
type: "GET",
|
||||
headers: {
|
||||
// "Content-Type":"multipart/form-data",
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
},
|
||||
success: function(response) {
|
||||
|
||||
console.log(response);
|
||||
// $('#insurer_statement_upload_form')[0].reset();
|
||||
|
||||
if (response.code === 200 && response.dataStatus === true && response
|
||||
.data !== "") {
|
||||
|
||||
disableStatementNo(response.data)
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(10).fadeOut('slow');
|
||||
} else if (response.code === 404 && response.dataStatus === false) {
|
||||
console.error('no data found', response);
|
||||
// alert(response.message);
|
||||
// toastr.error(response.message, 'Failed');
|
||||
// window.location.reload(true);
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(10).fadeOut('slow');
|
||||
} else {
|
||||
console.error('Something went wrong!');
|
||||
// alert('Something went wrong! Try later');
|
||||
toastr.error('Something went wrong! Try later', 'Error');
|
||||
// window.location.reload(true);
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(10).fadeOut('slow');
|
||||
}
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Request failed, handle error
|
||||
console.error("Request failed:", status, error);
|
||||
toastr.error('Something went wrong! Try later', 'Error');
|
||||
// $('#uploadForm')[0].reset();
|
||||
// window.location.reload(true);
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(10).fadeOut('slow');
|
||||
}
|
||||
});
|
||||
// $('.loader').fadeOut();
|
||||
// $('.loader-mask').delay(10).fadeOut('slow');
|
||||
|
||||
|
||||
}
|
||||
|
||||
function calcGSTValue()
|
||||
{
|
||||
// alert('calcGSTValue');
|
||||
var gst_per = document.getElementById('gst_per_modal').value;
|
||||
|
||||
var invoice_value_dom_obj = document.getElementById('invoice_value_modal');
|
||||
var invoice_value = invoice_value_dom_obj.value;
|
||||
|
||||
var gst_value_dom_obj = document.getElementById('gst_value_modal');
|
||||
var gst_value = gst_value_dom_obj.value;
|
||||
|
||||
var invoice_amount_dom_obj = document.getElementById('invoice_amount_no_modal');
|
||||
// var invoice_amount = invoice_amount_dom_obj.value();
|
||||
|
||||
gst_value_dom_obj.value = (parseFloat(gst_per) / 100 ) * invoice_value;
|
||||
invoice_amount_dom_obj.value = parseFloat(invoice_value_dom_obj.value) + parseFloat(gst_value_dom_obj.value);
|
||||
checkInvAmont();
|
||||
|
||||
|
||||
}
|
||||
|
||||
function disableStatementNo(arr)
|
||||
{
|
||||
// JavaScript array with values to disable
|
||||
// const disableValues = arr;
|
||||
const disableIds = arr.map(item => item.stmt_sno);
|
||||
console.log(disableIds);
|
||||
|
||||
// Get the select element
|
||||
const selectElement = document.getElementById("statement_no");
|
||||
// Variable to track if the first enabled option is selected
|
||||
let firstEnabledOptionSelected = false;
|
||||
// Iterate over the options in the select element
|
||||
Array.from(selectElement.options).forEach(option => {
|
||||
// If the option value is in the disableIds array, disable it
|
||||
console.log(option.value);
|
||||
option.disabled = false;
|
||||
option.style.backgroundColor = "";
|
||||
if (disableIds.includes((option.value))) {
|
||||
option.disabled = true;
|
||||
option.style.backgroundColor = "lightgray";
|
||||
}
|
||||
else if (!firstEnabledOptionSelected && option.value !== "") {
|
||||
// Automatically select the first enabled option
|
||||
option.selected = true;
|
||||
firstEnabledOptionSelected = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function deleteStatement(id)
|
||||
{
|
||||
//alert(id);
|
||||
Swal.fire({
|
||||
title: "Do you want to delete statement & it's invoice data if any?",
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "Delete",
|
||||
confirmButtonColor: "#ff3333",
|
||||
}).then((result) => {
|
||||
|
||||
console.log(result);
|
||||
|
||||
if (result.isConfirmed) {
|
||||
|
||||
$('.loader').fadeIn();
|
||||
$('.loader-mask').fadeIn();
|
||||
var apiURL = 'deleteStatement/' + id;
|
||||
// console.log('Truncate API URL : ', apiURL);
|
||||
|
||||
$.ajax({
|
||||
url: apiURL,
|
||||
method: 'GET',
|
||||
headers: {
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
},
|
||||
success: function(response) {
|
||||
// console.log('Truncate Response', response)
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(10).fadeOut('slow');
|
||||
if (response.code === 200 && response.dataStatus === true) {
|
||||
Swal.fire({
|
||||
title: "Deleted!",
|
||||
icon: "success"
|
||||
});
|
||||
window.location.reload(true);
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: "Failed!",
|
||||
text: 'Something went wrong! Try later',
|
||||
icon: "error"
|
||||
});
|
||||
|
||||
window.location.reload(true);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
|
||||
console.error(xhr.responseText);
|
||||
console.error(status, error);
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(10).fadeOut('slow');
|
||||
console.error('Error fetching data from API:', error);
|
||||
toastr.error('Something went wrong! Try later', 'Error');
|
||||
window.location.reload(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
@ -41,7 +41,7 @@ table.dataTable tbody td {
|
||||
<div class="form-group">
|
||||
<div class="form-row">
|
||||
|
||||
<div class="form-group col-md-3">
|
||||
<!-- <div class="form-group col-md-3">
|
||||
<label for="client_branch">Client<span class="text-danger"></span></label>
|
||||
<select class="form-control" id="client_id" name="client_id">
|
||||
<option value="0">Select Client</option>
|
||||
@ -53,7 +53,7 @@ table.dataTable tbody td {
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div class="form-group col-md-3">
|
||||
<label for="addon_policy"> Insurer <span id="base_danger"
|
||||
@ -69,6 +69,19 @@ table.dataTable tbody td {
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-3">
|
||||
<label for="addon_policy"> Insurer Branch<span id="base_danger"
|
||||
class="text-danger"></span></label>
|
||||
<select class="form-control" id="insurer_id" name="insurer_id">
|
||||
<option value="0" selected>Select Insurer</option>
|
||||
<?php if(isset($insurer) && count($insurer)){ ?>
|
||||
<?php foreach ($insurer as $value) { ?>
|
||||
<option value="<?= $value['id']?>"><?= $value['name']?></option>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- <div class="form-group col-md-3">
|
||||
<label for="email"> Policy Type <span class="text-danger"></span></label>
|
||||
<select class="form-control" id="policy_type_id" name="policy_type_id">
|
||||
<option value="0">Select Policy Type</option>
|
||||
@ -80,9 +93,9 @@ table.dataTable tbody td {
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div class="form-group col-md-3">
|
||||
<!-- <div class="form-group col-md-3">
|
||||
<label for="client_branch">Issuer<span class="text-danger">*</span></label>
|
||||
<select class="form-control" id="issuer" name="issuer" required>
|
||||
<option value="0">Select Issure</option>
|
||||
@ -94,13 +107,13 @@ table.dataTable tbody td {
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
</div>
|
||||
<!-- </div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-row"> -->
|
||||
|
||||
<div class="form-group col-md-3">
|
||||
<!-- <div class="form-group col-md-3">
|
||||
<label>Date Type<span class="text-danger"></span></label>
|
||||
<select class="form-control" id="date_type" name="date_type"
|
||||
onchange="hideDateField()">
|
||||
@ -113,10 +126,10 @@ table.dataTable tbody td {
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div class="form-group col-md-3" style="display: none;" id="date_div">
|
||||
<label>Date<span class="text-danger"></span></label>
|
||||
<div class="form-group col-md-3" style="display: true;" id="date_div">
|
||||
<label>Statement Month<span class="text-danger"></span></label>
|
||||
<div id="reportrange" class="form-control"
|
||||
style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 100%">
|
||||
<i class="fa fa-calendar"></i>
|
||||
@ -158,28 +171,36 @@ table.dataTable tbody td {
|
||||
<thead class="bg-light">
|
||||
<tr>
|
||||
<th>S.No</th>
|
||||
<th>Client Name</th>
|
||||
<!-- <th>Client Name</th> -->
|
||||
<th>Insurer</th>
|
||||
<th>Policy</th>
|
||||
<th>Endorsement No</th>
|
||||
<th>Insurer<br> Branch</th>
|
||||
<th>Statement<br> Month</th>
|
||||
<th>Statement<br> No</th>
|
||||
<th>Invoice No</th>
|
||||
<th>Invoice Status</th>
|
||||
<th>Invoice Date</th>
|
||||
<th>Invoice Amount</th>
|
||||
<th>Realization Amount</th>
|
||||
<th>Outstanding Amount</th>
|
||||
<th>Realization <br>Amount</th>
|
||||
<th>Outstanding <br>Amount</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (isset($outstanding_list)) { ?>
|
||||
<?php foreach($outstanding_list as $index => $row){ ?>
|
||||
<?php
|
||||
|
||||
// dd($outstanting_list);
|
||||
if (isset($outstanting_list)) { ?>
|
||||
<?php foreach($outstanting_list as $index => $row){ ?>
|
||||
<tr>
|
||||
<td><?= $index + 1 ?></td>
|
||||
<td><?php echo $row['client_name']; ?></td>
|
||||
<td><?php echo $row['insurer_name']; ?></td>
|
||||
<td><?php echo $row['policy_type'] .' - '. $row['policy_no']; ?></td>
|
||||
<td><?php echo $row['endorsement_no']; ?></td>
|
||||
<td><?php echo $row['short_name']; ?></td>
|
||||
<td><?php echo $row['branch_name']; ?></td>
|
||||
<td><?php echo change_date_format($row['month'],'Y-m-d','Y-m') ?></td>
|
||||
<td><?php echo $row['stmt_sno']; ?></td>
|
||||
<td><?php echo $row['invoice_no']; ?></td>
|
||||
<td class="center-align-input"><?php echo isset($row['invoice_status']) ? $row['invoice_status'] : ' - '; ?></td>
|
||||
<td><?php echo change_date_format($row['invoice_date'],'Y-m-d','d-M-Y'); ?></td>
|
||||
<td class="right-align-input"><?php echo isset($row['invoice_amount']) ? $row['invoice_amount'] : '0.00'; ?></td>
|
||||
<td class="right-align-input"><?php echo isset($row['realization_amount']) ? $row['realization_amount'] : '0.00'; ?></td>
|
||||
<td class="right-align-input"><?php echo isset($row['total_paid']) ? $row['total_paid'] : '0.00'; ?></td>
|
||||
<td class="right-align-input"><?php echo isset($row['outstanding_amount']) ? $row['outstanding_amount'] : '0.00'; ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
@ -364,10 +385,6 @@ $(function() {
|
||||
startDate: start,
|
||||
endDate: end,
|
||||
ranges: {
|
||||
'Today': [moment(), moment()],
|
||||
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
|
||||
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
|
||||
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
|
||||
'This Month': [moment().startOf('month'), moment().endOf('month')],
|
||||
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month')
|
||||
.endOf('month')
|
||||
|
||||
@ -10,8 +10,11 @@ class ExcelMergeHelperTest extends TestCase
|
||||
{
|
||||
// Use the paths you provided
|
||||
$filePaths = [
|
||||
'/home/venba/Downloads/Financial_Sample.xlsx' => [1,3,2],
|
||||
'/home/venba/Downloads/enrollment.xlsx' => []
|
||||
// ['file_path' =>WRITEPATH.'uploads/lead_files/Member_Data.xlsx','sheets' => []],
|
||||
// ['file_path' =>WRITEPATH.'/tmp/RFQ_ABC_GMC_20241220140640.xlsx','sheets' => []],
|
||||
|
||||
['file_path' =>'/home/venba/Downloads/enrollment (1).xlsx','sheets' => []],
|
||||
['file_path' =>'/home/venba/Downloads/Financial_Sample.xlsx','sheets' => []],
|
||||
];
|
||||
$outputPath = '/home/venba/Documents/merged_file.xlsx'; // Output path for the merged file
|
||||
|
||||
@ -23,3 +26,12 @@ class ExcelMergeHelperTest extends TestCase
|
||||
}
|
||||
|
||||
}
|
||||
// $temp_file_path = WRITEPATH.'tmp/RFQ_ABC_GMC_20241219172307.xlsx';
|
||||
// $temp_file_name = 'RFQ_ABC_GMC_20241219172307.xlsx';
|
||||
// $lead_file_path = WRITEPATH.'uploads/lead_files/Member_Data.xlsx';
|
||||
|
||||
// $filePaths = [
|
||||
// ['file_path' => $temp_file_path,'sheets' =>[]],
|
||||
// ['file_path' =>$lead_file_path ,'sheets' =>[]]
|
||||
// ];
|
||||
// $outputPath = dirname($temp_file_path).'/'.$temp_file_name.'_merged';
|
||||
|
||||
183
tests/unit/LeadsControllerTest.php
Normal file
183
tests/unit/LeadsControllerTest.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit;
|
||||
|
||||
use Exception;
|
||||
use CodeIgniter\Test\CIUnitTestCase;
|
||||
use App\Controllers\LeadsController;
|
||||
|
||||
class LeadsControllerTest extends CIUnitTestCase
|
||||
{
|
||||
protected $leadsController;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->leadsController = new LeadsController();
|
||||
}
|
||||
|
||||
public function testGetDemographyDataBasicScenario()
|
||||
{
|
||||
echo('passed 0');
|
||||
// Arrange
|
||||
$members = [
|
||||
// Header row
|
||||
['Name', 'Age', 'Relationship', 'SI Enhancement'],
|
||||
// Data rows
|
||||
['John', '25', 'Self', '100000'],
|
||||
['Jane', '23', 'Spouse', '100000'],
|
||||
['Kid', '5', 'Child', '50000']
|
||||
];
|
||||
echo('passed 1');
|
||||
$age_band_data = [
|
||||
['0-17', '18-35', '36-45', 'Above 46']
|
||||
];
|
||||
echo('passed 2');
|
||||
$members_heading = ['Name', 'Age', 'Relationship', 'SI Enhancement'];
|
||||
$available_col = 'age';print_rr($available_col);
|
||||
$col_index = 1;
|
||||
echo('passed 3');
|
||||
try{
|
||||
echo('Inside try');
|
||||
// Act
|
||||
echo('passed 3.5');
|
||||
$result = $this->leadsController->getDemographyData($members,$age_band_data,$members_heading,$available_col,$col_index);
|
||||
|
||||
echo('passed 4');
|
||||
} catch (Exception $e) {
|
||||
echo "Message: " . $e->getMessage() . "\n";
|
||||
echo "File: " . $e->getFile() . "\n";
|
||||
echo "Line: " . $e->getLine() . "\n";
|
||||
// Optionally, print the full stack trace
|
||||
echo "Stack trace: " . $e->getTraceAsString() . "\n";
|
||||
}
|
||||
var_dump($result);
|
||||
// Assert
|
||||
$this->assertIsArray($result);
|
||||
$this->assertArrayHasKey('general', $result);
|
||||
$this->assertArrayHasKey('100000', $result);
|
||||
$this->assertArrayHasKey('50000', $result);
|
||||
|
||||
// Check counts for general category
|
||||
$this->assertEquals(1, $result['general']['Self']['18-35']);
|
||||
$this->assertEquals(1, $result['general']['Spouse']['18-35']);
|
||||
$this->assertEquals(1, $result['general']['Child']['0-17']);
|
||||
}
|
||||
|
||||
public function testGetDemographyDataWithDOB()
|
||||
{
|
||||
// Arrange
|
||||
$members = [
|
||||
// Header row
|
||||
['Name', 'DOB', 'Relationship', 'SI Enhancement'],
|
||||
// Data rows
|
||||
['John', '01-Jan-1995', 'Self', '100000'],
|
||||
['Jane', '01-Jan-1998', 'Spouse', '100000']
|
||||
];
|
||||
|
||||
$age_band_data = [
|
||||
['18-35', '36-45', '46+']
|
||||
];
|
||||
|
||||
$members_heading = ['Name', 'DOB', 'Relationship', 'SI Enhancement'];
|
||||
$available_col = 'dob';
|
||||
$col_index = 1;
|
||||
|
||||
// Act
|
||||
$result = $this->leadsController->getDemographyData(
|
||||
$members,
|
||||
$age_band_data,
|
||||
$members_heading,
|
||||
$available_col,
|
||||
$col_index
|
||||
);
|
||||
|
||||
// Assert
|
||||
$this->assertIsArray($result);
|
||||
$this->assertArrayHasKey('general', $result);
|
||||
$this->assertArrayHasKey('100000', $result);
|
||||
|
||||
// Both members should be in 18-35 age band
|
||||
$this->assertEquals(1, $result['general']['Self']['18-35']);
|
||||
$this->assertEquals(1, $result['general']['Spouse']['18-35']);
|
||||
}
|
||||
|
||||
public function testGetDemographyDataWithEmptyMembers()
|
||||
{
|
||||
// Arrange
|
||||
$members = [
|
||||
// Only header row
|
||||
['Name', 'Age', 'Relationship', 'SI Enhancement']
|
||||
];
|
||||
|
||||
$age_band_data = [
|
||||
['0-17', '18-35', '36-45', '46+']
|
||||
];
|
||||
|
||||
$members_heading = ['Name', 'Age', 'Relationship', 'SI Enhancement'];
|
||||
$available_col = 'age';
|
||||
$col_index = 1;
|
||||
|
||||
// Act
|
||||
$result = $this->leadsController->getDemographyData(
|
||||
$members,
|
||||
$age_band_data,
|
||||
$members_heading,
|
||||
$available_col,
|
||||
$col_index
|
||||
);
|
||||
|
||||
// Assert
|
||||
$this->assertIsArray($result);
|
||||
$this->assertArrayHasKey('general', $result);
|
||||
|
||||
// Check that all totals are zero
|
||||
$this->assertEquals(0, $result['general']['Grand Total']['Grand Total']);
|
||||
}
|
||||
|
||||
public function testGetDemographyDataWithMultipleSIBands()
|
||||
{
|
||||
// Arrange
|
||||
$members = [
|
||||
// Header row
|
||||
['Name', 'Age', 'Relationship', 'SI Enhancement'],
|
||||
// Data rows with different SI amounts
|
||||
['John', '25', 'Self', '100000'],
|
||||
['Jane', '23', 'Spouse', '200000'],
|
||||
['Kid1', '5', 'Child', '100000'],
|
||||
['Kid2', '7', 'Child', '200000']
|
||||
];
|
||||
|
||||
$age_band_data = [
|
||||
['0-17', '18-35', '36-45', '46+']
|
||||
];
|
||||
|
||||
$members_heading = ['Name', 'Age', 'Relationship', 'SI Enhancement'];
|
||||
$available_col = 'age';
|
||||
$col_index = 1;
|
||||
|
||||
// Act
|
||||
$result = $this->leadsController->getDemographyData(
|
||||
$members,
|
||||
$age_band_data,
|
||||
$members_heading,
|
||||
$available_col,
|
||||
$col_index
|
||||
);
|
||||
|
||||
// Assert
|
||||
$this->assertIsArray($result);
|
||||
$this->assertArrayHasKey('100000', $result);
|
||||
$this->assertArrayHasKey('200000', $result);
|
||||
|
||||
// Check counts for different SI bands
|
||||
$this->assertEquals(1, $result['100000']['Self']['18-35']);
|
||||
$this->assertEquals(1, $result['200000']['Spouse']['18-35']);
|
||||
$this->assertEquals(1, $result['100000']['Child']['0-17']);
|
||||
$this->assertEquals(1, $result['200000']['Child']['0-17']);
|
||||
|
||||
// Check general category totals
|
||||
$this->assertEquals(2, $result['general']['Child']['0-17']);
|
||||
$this->assertEquals(2, $result['general']['Child']['Grand Total']);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user