GWM: payout upload
This commit is contained in:
parent
aaf0c81d11
commit
7c16121391
@ -1669,6 +1669,7 @@ class PolicyController extends ResourceController
|
|||||||
$errors = [];
|
$errors = [];
|
||||||
|
|
||||||
for ($r = $headerRowNum + 1; $r <= $highestRow; $r++) {
|
for ($r = $headerRowNum + 1; $r <= $highestRow; $r++) {
|
||||||
|
$agentCodeExcel = trim((string) $sheet->getCell('A' . $r)->getFormattedValue());
|
||||||
$policyNumber = trim((string) $sheet->getCell('B' . $r)->getFormattedValue());
|
$policyNumber = trim((string) $sheet->getCell('B' . $r)->getFormattedValue());
|
||||||
$payoutRaw = $sheet->getCell('C' . $r)->getCalculatedValue();
|
$payoutRaw = $sheet->getCell('C' . $r)->getCalculatedValue();
|
||||||
|
|
||||||
@ -1676,6 +1677,16 @@ class PolicyController extends ResourceController
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($agentCodeExcel === '') {
|
||||||
|
$errors[] = [
|
||||||
|
'row' => $r,
|
||||||
|
'policy_number' => $policyNumber,
|
||||||
|
'agent_code' => '',
|
||||||
|
'message' => 'Agent code is empty for this policy',
|
||||||
|
];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($payoutRaw === null || $payoutRaw === '') {
|
if ($payoutRaw === null || $payoutRaw === '') {
|
||||||
$skipped++;
|
$skipped++;
|
||||||
continue;
|
continue;
|
||||||
@ -1688,13 +1699,42 @@ class PolicyController extends ResourceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($amount < 0 || is_nan($amount)) {
|
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;
|
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) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1718,6 +1758,7 @@ class PolicyController extends ResourceController
|
|||||||
'data' => [
|
'data' => [
|
||||||
'updated_rows' => $updated,
|
'updated_rows' => $updated,
|
||||||
'skipped_empty_payout' => $skipped,
|
'skipped_empty_payout' => $skipped,
|
||||||
|
'error_count' => count($errors),
|
||||||
'errors' => $errors,
|
'errors' => $errors,
|
||||||
],
|
],
|
||||||
], 200);
|
], 200);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user