FIX_Changes and Additional Requirements ( GRID Updated API )
This commit is contained in:
parent
0fb92252dc
commit
b792d4c058
@ -75,6 +75,7 @@ $routes->group('api', ['filter' => ["jwtAuth:1,2,3,4,agent","appSignature"] ], f
|
||||
$routes->get('agent/downloadAgentIncentiveFile', 'AgentController::downloadAgentIncentiveFile');
|
||||
|
||||
$routes->post('agent/uploadGrid', 'AgentIncentiveController::uploadPayoutGridFile');
|
||||
$routes->post('agent/updateGrid', 'AgentIncentiveController::updateGrid');
|
||||
$routes->get('agent/payoutGrid', 'AgentIncentiveController::getPayoutGrid');
|
||||
$routes->get('agent/downloadGrid', 'AgentIncentiveController::downloadGridInExcel');
|
||||
$routes->get('agent/loadGrid', 'AgentIncentiveController::loadGrid');
|
||||
|
||||
@ -526,10 +526,12 @@ class AgentIncentiveController extends ResourceController
|
||||
|
||||
// Handle dynamic column selection (comp/tp/od)
|
||||
if (!empty($plan_type) && in_array($plan_type, ['comp', 'tp', 'od'])) {
|
||||
$builder->select("id, insurer, vehicle_type, segment, rto, $plan_type as payout");
|
||||
$builder->select("id, insurer, vehicle_type, segment, rto, $plan_type as payout,fuel,broker_name,comp,tp,od,remarks,broker_excel_comp,
|
||||
broker_excel_tp,broker_excel_od,partner_comp,partner_tp,partner_od,created_by,created_at,updated_by,updated_at");
|
||||
} else {
|
||||
// Default selection if no plan_type or invalid plan_type
|
||||
$builder->select('id, insurer, vehicle_type, segment, rto, comp, tp, od');
|
||||
$builder->select('id, insurer, vehicle_type, segment, rto, comp, tp, od, fuel,broker_name,comp,tp,od,remarks,broker_excel_comp,
|
||||
broker_excel_tp,broker_excel_od,partner_comp,partner_tp,partner_od,created_by,created_at,updated_by,updated_at');
|
||||
}
|
||||
}
|
||||
|
||||
@ -579,6 +581,90 @@ class AgentIncentiveController extends ResourceController
|
||||
return array_column($results, $column);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Update grid row by id
|
||||
// Route: POST /agent/updateGrid
|
||||
// -------------------------------------------------------------------------
|
||||
public function updateGrid()
|
||||
{
|
||||
try {
|
||||
$jsonData = (array) ($this->request->getJSON(true) ?? []);
|
||||
$postData = $this->request->getPost() ?? [];
|
||||
$data = !empty($jsonData) ? $jsonData : $postData;
|
||||
|
||||
$id = isset($data['id']) ? (int) $data['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 400,
|
||||
'data' => 'id is required.',
|
||||
], 200);
|
||||
}
|
||||
|
||||
$existing = $this->PayoutGridModel->find($id);
|
||||
if (empty($existing)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 404,
|
||||
'data' => 'Grid record not found.',
|
||||
], 200);
|
||||
}
|
||||
|
||||
$updateData = [
|
||||
'vehicle_type' => array_key_exists('vehicle_type', $data) ? $data['vehicle_type'] : null,
|
||||
'fuel' => array_key_exists('fuel', $data) ? $data['fuel'] : null,
|
||||
'rto' => array_key_exists('rto', $data) ? $data['rto'] : null,
|
||||
'segment' => array_key_exists('segment', $data) ? $data['segment'] : null,
|
||||
'broker_name' => array_key_exists('broker_name', $data) ? $data['broker_name'] : null,
|
||||
'comp' => array_key_exists('comp', $data) ? $data['comp'] : null,
|
||||
'tp' => array_key_exists('tp', $data) ? $data['tp'] : null,
|
||||
'od' => array_key_exists('od', $data) ? $data['od'] : null,
|
||||
'broker_excel_comp' => array_key_exists('broker_excel_comp', $data) ? $data['broker_excel_comp'] : null,
|
||||
'broker_excel_tp' => array_key_exists('broker_excel_tp', $data) ? $data['broker_excel_tp'] : null,
|
||||
'broker_excel_od' => array_key_exists('broker_excel_od', $data) ? $data['broker_excel_od'] : null,
|
||||
'partner_comp' => array_key_exists('partner_comp', $data) ? $data['partner_comp'] : null,
|
||||
'partner_tp' => array_key_exists('partner_tp', $data) ? $data['partner_tp'] : null,
|
||||
'partner_od' => array_key_exists('partner_od', $data) ? $data['partner_od'] : null,
|
||||
'remarks' => array_key_exists('remarks', $data) ? $data['remarks'] : null,
|
||||
];
|
||||
|
||||
$hasAnyField = false;
|
||||
foreach (array_keys($updateData) as $field) {
|
||||
if (array_key_exists($field, $data)) {
|
||||
$hasAnyField = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$hasAnyField) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 400,
|
||||
'data' => 'No update fields provided.',
|
||||
], 200);
|
||||
}
|
||||
|
||||
if (array_key_exists('updated_by', $data)) {
|
||||
$updateData['updated_by'] = $data['updated_by'];
|
||||
}
|
||||
|
||||
$this->PayoutGridModel->updateGridById($id, $updateData);
|
||||
$updated = $this->PayoutGridModel->find($id);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => $updated,
|
||||
], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 500,
|
||||
'data' => $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 2. Download Filtered Grid in Excel
|
||||
|
||||
@ -126,4 +126,12 @@ class PartnerInsurancePayoutGridModel extends Model
|
||||
->orderBy('vehicle_type', 'ASC')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Update a grid row by id
|
||||
// -------------------------------------------------------------------------
|
||||
public function updateGridById(int $id, array $data): bool
|
||||
{
|
||||
return $this->update($id, $data);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user