GWM: payout upload
This commit is contained in:
parent
aaf0c81d11
commit
7c16121391
@ -1669,13 +1669,24 @@ class PolicyController extends ResourceController
|
||||
$errors = [];
|
||||
|
||||
for ($r = $headerRowNum + 1; $r <= $highestRow; $r++) {
|
||||
$policyNumber = trim((string) $sheet->getCell('B' . $r)->getFormattedValue());
|
||||
$payoutRaw = $sheet->getCell('C' . $r)->getCalculatedValue();
|
||||
$agentCodeExcel = trim((string) $sheet->getCell('A' . $r)->getFormattedValue());
|
||||
$policyNumber = trim((string) $sheet->getCell('B' . $r)->getFormattedValue());
|
||||
$payoutRaw = $sheet->getCell('C' . $r)->getCalculatedValue();
|
||||
|
||||
if ($policyNumber === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($agentCodeExcel === '') {
|
||||
$errors[] = [
|
||||
'row' => $r,
|
||||
'policy_number' => $policyNumber,
|
||||
'agent_code' => '',
|
||||
'message' => 'Agent code is empty for this policy',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($payoutRaw === null || $payoutRaw === '') {
|
||||
$skipped++;
|
||||
continue;
|
||||
@ -1688,13 +1699,42 @@ class PolicyController extends ResourceController
|
||||
}
|
||||
|
||||
if ($amount < 0 || is_nan($amount)) {
|
||||
$errors[] = "Row {$r}: invalid payout for policy {$policyNumber}";
|
||||
$errors[] = [
|
||||
'row' => $r,
|
||||
'policy_number' => $policyNumber,
|
||||
'agent_code' => $agentCodeExcel,
|
||||
'message' => 'Invalid payout amount',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$policy = $this->PolicyModel->where('policy_number', $policyNumber)->where('is_active', 1)->first();
|
||||
$policy = $db->table('partner_policy pp')
|
||||
->select('pp.id, pa.agent_code as db_agent_code')
|
||||
->join('partner_agent pa', 'pa.id = pp.agent_id', 'left')
|
||||
->where('pp.policy_number', $policyNumber)
|
||||
->where('pp.is_active', 1)
|
||||
->get()
|
||||
->getRowArray();
|
||||
|
||||
if (! $policy) {
|
||||
$errors[] = "Row {$r}: policy not found: {$policyNumber}";
|
||||
$errors[] = [
|
||||
'row' => $r,
|
||||
'policy_number' => $policyNumber,
|
||||
'agent_code' => $agentCodeExcel,
|
||||
'message' => 'Policy not found or inactive',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$dbAgentCode = trim((string) ($policy['db_agent_code'] ?? ''));
|
||||
if (strcasecmp($dbAgentCode, $agentCodeExcel) !== 0) {
|
||||
$errors[] = [
|
||||
'row' => $r,
|
||||
'policy_number' => $policyNumber,
|
||||
'agent_code' => $agentCodeExcel,
|
||||
'expected_agent_code' => $dbAgentCode,
|
||||
'message' => 'Agent code does not match this policy number',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1718,6 +1758,7 @@ class PolicyController extends ResourceController
|
||||
'data' => [
|
||||
'updated_rows' => $updated,
|
||||
'skipped_empty_payout' => $skipped,
|
||||
'error_count' => count($errors),
|
||||
'errors' => $errors,
|
||||
],
|
||||
], 200);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user