FIX_BDS_UPLOAD_NEW_VEHICLE

This commit is contained in:
VENKATESHWARAN 2025-12-19 16:56:29 +05:30
parent 31d4a3228b
commit 611ce09e51

View File

@ -3742,6 +3742,103 @@
return array('status' => $ret_status, 'error_code' => $error_data['error_code'], 'error_data' => $error_data['error_data']);
}
public function validateInsurerStatementNew($params)
{
helper('excel_util_helper');
//get file info
$file_id = $params['file_id'];
$file = $this->insurerStatements->find($file_id);
// dd($file);
$date = new \DateTime($file['month']);
$month = $date->format('m');
$year = $date->format('Y');
$error_data = ['error_code' => '', 'error_data' => []];
$status = 'success';
$ret_status = true;
$return = [];
if (!isset($file)) {
//file not found in DB
return array('status' => false, 'msg' => 'statement file not found in DB');
}
$file_name_with_path = WRITEPATH . "/uploads/statements/" . $file['file_name'];
//check physical file
if (!file_exists($file_name_with_path)) {
//file not found update status and reason
$message = "Physcial file not found";
// echo $message;
$this->myLogger->logme('error', ($message . ' for statement file id ' . $file_id));
$this->insurerStatements->where('id', $file_id)->set(['file_status' => 'failed', 'reason' => json_encode(['error_code' => 0, 'error_data' => $message])])->update();
return array('status' => false, 'error_code' => 0); //0 - Physcial file not found
}
//get excel data to php array
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path);
$sheet = $spreadsheet->getActiveSheet();
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$excel_data = $sheet->rangeToArray('A1:' . $highestColumn . $highestRow, null, true, true, true);
unset($excel_data[0]);
$excel_data = ExcelSanitizeHelper::sanitizeArrayData($excel_data);
//get no of line items and update in DB
$line_items = 0;
// get uploaded month transactions data
$source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id: $file['insurer_id'], insurer_branch_id: $file['branch_id']);
// check policy no,insurer and etc in DB for this month
// if all good return true, otherwise return false with messssage
foreach ($excel_data as $excel_key => $excel_row) {
$is_row_empty = check_row_is_empty_or_null($excel_row);
if (!$is_row_empty) {
$is_source_found = 0;
$policy_no = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[1]); //policy_number from excel
$policy_no = preg_replace( '/[\x{200B}\x{200C}\x{200D}\x{FEFF}\x{00A0}\x{200E}\x{200F}\x{202A}-\x{202E}]/u', '', $excel_row[1]); //policy_number from excel
$endorsement_no = preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $excel_row[2]??''); //endorsement number from excel
$endorsement_no = preg_replace( '/[\x{200B}\x{200C}\x{200D}\x{FEFF}\x{00A0}\x{200E}\x{200F}\x{202A}-\x{202E}]/u', '', $excel_row[2]??''); //endorsement number from excel
foreach ($source_data as $source_key => $source_row) {
$source_endorsement_no = $source_row['endorsement_no'] !== null ? $source_row['endorsement_no'] : null;
if (($policy_no == $source_row['policy_no']) && $endorsement_no == $source_endorsement_no) {
$is_source_found = 1;
$line_items = $line_items + 1;
unset($source_data[$source_key]);
continue 2;
}
}
if ($is_source_found == 0) {
$error_data['error_code'] = 1; //match not found
$error_data['error_data'] = array_merge($error_data['error_data'], [$excel_row[0]]); //match not found
}
}
}
if ($error_data['error_code']) {
$status = 'failed';
$ret_status = false;
}
//update in DB
$this->insurerStatements->where('id', $file_id)->set(['line_items' => $line_items, 'file_status' => $status, 'reason' => json_encode($error_data)])->update();
return array('status' => $ret_status, 'error_code' => $error_data['error_code'], 'error_data' => $error_data['error_data']);
}
public function updateInsurerStatement($params)
{
@ -5357,11 +5454,14 @@
// -------------------------------------------
// 1. First Stage: Check if vehicle already exists
// -------------------------------------------
foreach ($vehicle_data as $v) {
if (strcasecmp(trim($v['vehicle_no']), $vehicle_number) === 0) {
$vehicle_id = $v['id'];
$client_id = $v['owner'];
break;
if(strtolower(trim($vehicle_number)) != 'new'){
foreach ($vehicle_data as $v) {
if (strcasecmp(trim($v['vehicle_no']), $vehicle_number) === 0) {
$vehicle_id = $v['id'];
$client_id = $v['owner'];
break;
}
}
}