FIX_EXCEL_MERGE_AND_FEAT_CAL_SRI
This commit is contained in:
parent
de4433ad29
commit
1897b87607
@ -1801,7 +1801,7 @@ class LeadsController extends BaseController
|
||||
['file_path' => $temp_file_path, 'sheets' => []],
|
||||
['file_path' => $lead_file_path, 'sheets' => []]
|
||||
];
|
||||
$outputPath = dirname($temp_file_path) . '/' . 'merged_' . $temp_file_name;
|
||||
$outputPath = dirname($temp_file_path) . '/' . $temp_file_name;
|
||||
$result = ExcelMergeHelper::mergeExcelFiles($filePaths, $outputPath);
|
||||
// print_rr($result);
|
||||
}
|
||||
|
||||
@ -17,10 +17,13 @@ class ExcelMergeHelper {
|
||||
{
|
||||
try {
|
||||
log_message('debug', 'Attempting merge with original file order');
|
||||
// echo "Attempting merge with original file order\n";
|
||||
return self::processFiles($filePaths, $outputPath);
|
||||
} catch (Exception $e) {
|
||||
log_message('error', 'First attempt failed: ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine());
|
||||
// echo "First attempt failed: " . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . "\n";
|
||||
log_message('debug', 'Retrying with reversed file order');
|
||||
// echo "Retrying with reversed file order\n";
|
||||
|
||||
// Reverse the file order and try again
|
||||
$reversedFiles = array_reverse($filePaths);
|
||||
@ -29,6 +32,7 @@ class ExcelMergeHelper {
|
||||
return self::processFiles($reversedFiles, $outputPath);
|
||||
} catch (Exception $e2) {
|
||||
log_message('error', 'Both attempts failed. Last error: ' . $e2->getMessage() . ' in ' . $e2->getFile() . ' on line ' . $e2->getLine());
|
||||
// echo "Both attempts failed. Last error: " . $e2->getMessage() . ' in ' . $e2->getFile() . ' on line ' . $e2->getLine() . "\n";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -45,7 +49,9 @@ class ExcelMergeHelper {
|
||||
private static function processFiles(array $filePaths, string $outputPath): string
|
||||
{
|
||||
log_message('debug', 'Starting Excel merge process');
|
||||
// echo "Starting Excel merge process\n";
|
||||
log_message('debug', 'Files to process: ' . json_encode($filePaths));
|
||||
// echo "Files to process: " . json_encode($filePaths) . "\n";
|
||||
|
||||
if (empty($filePaths)) {
|
||||
throw new Exception("No files provided to merge");
|
||||
@ -66,6 +72,7 @@ class ExcelMergeHelper {
|
||||
|
||||
// Save the merged file
|
||||
log_message('debug', "Saving merged file to: {$outputPath}");
|
||||
// echo "Saving merged file to: {$outputPath}\n";
|
||||
$writer = IOFactory::createWriter($mergedSpreadsheet, 'Xlsx');
|
||||
$writer->setPreCalculateFormulas(false);
|
||||
$writer->save($outputPath);
|
||||
@ -76,6 +83,7 @@ class ExcelMergeHelper {
|
||||
gc_collect_cycles();
|
||||
|
||||
log_message('debug', 'Excel merge process completed successfully');
|
||||
// echo "Excel merge process completed successfully\n";
|
||||
return $outputPath;
|
||||
}
|
||||
|
||||
@ -87,15 +95,17 @@ class ExcelMergeHelper {
|
||||
* @param int|null $index
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function processSingleFile(array $fileInfo, Spreadsheet $mergedSpreadsheet, int $index = null)
|
||||
private static function processSingleFile(array $fileInfo, Spreadsheet $mergedSpreadsheet, ?int $index = null)
|
||||
{
|
||||
if (!isset($fileInfo['file_path']) || !file_exists($fileInfo['file_path'])) {
|
||||
$path = $fileInfo['file_path'] ?? 'undefined';
|
||||
log_message('error', "File " . ($index ?? 'base') . ": Invalid or missing file path: {$path}");
|
||||
// echo "File " . ($index ?? 'base') . ": Invalid or missing file path: {$path}\n";
|
||||
return;
|
||||
}
|
||||
|
||||
log_message('debug', "Processing file " . ($index ?? 'base') . ": " . $fileInfo['file_path']);
|
||||
// echo "Processing file " . ($index ?? 'base') . ": " . $fileInfo['file_path'] . "\n";
|
||||
|
||||
try {
|
||||
// Load the source spreadsheet
|
||||
@ -105,6 +115,7 @@ class ExcelMergeHelper {
|
||||
$worksheets = $sourceSpreadsheet->getAllSheets();
|
||||
$totalSheets = count($worksheets);
|
||||
log_message('debug', "Total sheets in file: " . $totalSheets);
|
||||
// echo "Total sheets in file: " . $totalSheets . "\n";
|
||||
|
||||
$sheetsToMerge = $fileInfo['sheets'] ?? [];
|
||||
|
||||
@ -114,26 +125,30 @@ class ExcelMergeHelper {
|
||||
try {
|
||||
$sheetName = $worksheet->getTitle();
|
||||
log_message('debug', "Processing sheet: {$sheetName}");
|
||||
// echo "Processing sheet: {$sheetName}\n";
|
||||
|
||||
// Generate unique sheet name before cloning
|
||||
$newName = $sheetName;
|
||||
$counter = 1;
|
||||
|
||||
while (in_array($newName, $mergedSpreadsheet->getSheetNames())) {
|
||||
$newName = $sheetName . "_" . $counter++;
|
||||
// $newName = $sheetName . "_" . $counter++;
|
||||
log_message('debug', "Sheet name already exists. Trying new name: {$newName}");
|
||||
// echo "Sheet name already exists. Trying new name: {$newName}\n";
|
||||
}
|
||||
|
||||
// Clone the worksheet and set the new name
|
||||
$clonedSheet = clone $worksheet;
|
||||
$clonedSheet->setTitle($newName);
|
||||
// $clonedSheet = clone $worksheet;
|
||||
// $clonedSheet->setTitle($newName);
|
||||
|
||||
// Add as external sheet
|
||||
$mergedSpreadsheet->addExternalSheet($clonedSheet);
|
||||
$mergedSpreadsheet->addExternalSheet($worksheet);
|
||||
|
||||
log_message('debug', "Successfully added sheet: {$newName}");
|
||||
// echo "Successfully added sheet: {$newName}\n";
|
||||
} catch (Exception $e) {
|
||||
log_message('error', "Error processing sheet {$sheetName} as new name {$newName}: " . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine());
|
||||
// echo "Error processing sheet {$sheetName} as new name {$newName}: " . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -145,6 +160,7 @@ class ExcelMergeHelper {
|
||||
|
||||
} catch (Exception $e) {
|
||||
log_message('error', "Error processing file {$fileInfo['file_path']}: " . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine());
|
||||
// echo "Error processing file {$fileInfo['file_path']}: " . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1064,7 +1064,7 @@
|
||||
console.log('incurredClaimDate', incurredClaimDate)
|
||||
|
||||
if (policyStartDate && incurredClaimDate) {
|
||||
var timeDiff = incurredClaimDate - policyStartDate; // Time difference in milliseconds
|
||||
var timeDiff = (policyStartDate - incurredClaimDate) + 1; // Time difference in milliseconds
|
||||
console.log('timeDiff', timeDiff);
|
||||
var daysDiff = Math.ceil(timeDiff / (1000 * 60 * 60 * 24)); // Convert to days and add 1
|
||||
console.log('daysDiff', daysDiff);
|
||||
@ -1145,6 +1145,69 @@
|
||||
$('#earned_premium_' + increment).val(earned_premium_roundoff);
|
||||
}
|
||||
|
||||
$(document).on("input", "#incept_emp_count, #incept_dept_count, #renewal_emp_count, #renewal_dept_count, #exp_emp_count, #exp_dept_count", function() {
|
||||
calculateTotalLives(this);
|
||||
});
|
||||
|
||||
function calculateTotalLives(input) {
|
||||
|
||||
var lead_type = $('#lead_type').val();
|
||||
|
||||
if (lead_type == 1) {
|
||||
|
||||
let formRow = input.closest('.form-row');
|
||||
|
||||
if (formRow) {
|
||||
// Get the employee count and dependent count within the same row
|
||||
let empCountInput = formRow.querySelector('[name="incept_emp_count[]"]');
|
||||
let depCountInput = formRow.querySelector('[name="incept_dept_count[]"]');
|
||||
let totalLivesInput = formRow.querySelector('[name="incept_no_of_lives[]"]');
|
||||
|
||||
// Parse the input values as integers, defaulting to 0 if empty
|
||||
let empCount = empCountInput ? parseInt(empCountInput.value) || 0 : 0;
|
||||
let depCount = depCountInput ? parseInt(depCountInput.value) || 0 : 0;
|
||||
|
||||
// Calculate total lives
|
||||
let totalLives = empCount + depCount;
|
||||
|
||||
// Set the total lives input value
|
||||
if (totalLivesInput) {
|
||||
totalLivesInput.value = totalLives;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
console.log("Function Called");
|
||||
|
||||
if (input.id === "incept_emp_count" || input.id === "incept_dept_count") {
|
||||
var incept_emp_count = parseInt($("#incept_emp_count").val()) || 0;
|
||||
var incept_dept_count = parseInt($("#incept_dept_count").val()) || 0;
|
||||
|
||||
var totalCount = incept_emp_count + incept_dept_count;
|
||||
$("#incept_no_of_lives").val(totalCount);
|
||||
|
||||
} else if (input.id === "renewal_emp_count" || input.id === "renewal_dept_count") {
|
||||
var renewal_emp_count = parseInt($("#renewal_emp_count").val()) || 0;
|
||||
var renewal_dept_count = parseInt($("#renewal_dept_count").val()) || 0;
|
||||
|
||||
var totalCount = renewal_emp_count + renewal_dept_count;
|
||||
$("#renewal_no_of_lives").val(totalCount);
|
||||
|
||||
} else {
|
||||
var exp_emp_count = parseInt($("#exp_emp_count").val()) || 0;
|
||||
var exp_dept_count = parseInt($("#exp_dept_count").val()) || 0;
|
||||
|
||||
var totalCount = exp_emp_count + exp_dept_count;
|
||||
$("#exp_no_of_lives").val(totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------ FORM SUBMIT ---------------------------------------------------------------------------------
|
||||
|
||||
$("#leads_form_id").submit(function(event) {
|
||||
|
||||
@ -116,14 +116,14 @@
|
||||
<label for="incept_emp_count" class="emp_title"> No of Employees at Inception <span
|
||||
class="text-danger">*</span></label>
|
||||
<input value="<?= isset($lead_edit_data['incept_emp_count']) ? $lead_edit_data['incept_emp_count'] : '' ?>" type="text" class="form-control" id="incept_emp_count" name="incept_emp_count[]"
|
||||
placeholder="Enter Lives" required>
|
||||
placeholder="Enter Lives" required oninput="calculateTotalLives(this)">
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-3">
|
||||
<label for="incept_dept_count" class="depnd_title"> No of Dependents at Inception <span
|
||||
class="text-danger">*</span></label>
|
||||
<input value="<?= isset($lead_edit_data['incept_dept_count']) ? $lead_edit_data['incept_dept_count'] : '' ?>" type="text" class="form-control" id="incept_dept_count" name="incept_dept_count[]"
|
||||
placeholder="Enter Lives" required>
|
||||
placeholder="Enter Lives" required oninput="calculateTotalLives(this)">
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-3">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user