Manual commission calculation : GWM
This commit is contained in:
parent
4430e822f5
commit
70b8298ed6
@ -116,6 +116,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
|
||||
$routes->get('policy/downloadPolicyFile', 'PolicyController::downloadPolicyFile');
|
||||
$routes->post('policy/uploadPolicyFile', 'PolicyController::uploadPolicyFile');
|
||||
$routes->get("policy/searchThePolicies", "PolicyController::searchThePolicies");
|
||||
$routes->post('policy/calculateCommissionRequest', 'PolicyController::calculateCommissionRequest');
|
||||
|
||||
|
||||
//claims
|
||||
|
||||
@ -973,8 +973,8 @@ class PolicyController extends ResourceController
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function searchThePolicies() {
|
||||
public function searchThePolicies()
|
||||
{
|
||||
|
||||
try{
|
||||
|
||||
@ -1011,17 +1011,110 @@ class PolicyController extends ResourceController
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function resolveVehicleTypeTier1(string $incoming)
|
||||
{
|
||||
|
||||
public function resolveVehicleTypeTier1(string $incoming)
|
||||
$value = strtolower(trim($incoming));
|
||||
$value = preg_replace('/\s+/', ' ', $value); // normalize spaces
|
||||
|
||||
return $this->phraseMap[$value] ?? 'UN_IDEN_TYPE';
|
||||
}
|
||||
|
||||
public function calculateCommissionRequest()
|
||||
{
|
||||
$postRequest = $this->request->getJSON(true);
|
||||
|
||||
$apiUrl = getenv('COMMISSION_CALCULATION_URL');
|
||||
|
||||
$token = getenv('COMMISSION_CALCULATION_TOKEN');
|
||||
|
||||
$manufactureYear = (int) $postRequest['year_of_manufacture'];
|
||||
$currentYear = (int) date("Y");
|
||||
$vehicleAge = $currentYear - $manufactureYear;
|
||||
|
||||
$postData = [
|
||||
"department" => "Motor",
|
||||
"policy_business_type" => "retail",
|
||||
"product" => "",
|
||||
"renewal_type" => "fresh",
|
||||
"renewal_sub_type" => "fresh",
|
||||
"vehicle_type" => $postRequest['vehicle_type'],
|
||||
"policy_type" => $postRequest['insurance_plan_type'],
|
||||
"premium" => $postRequest['premium_amount'],
|
||||
"od_premium" => $postRequest['od'],
|
||||
"tp_premium" => $postRequest['tp'],
|
||||
"cubic_capacity" => $postRequest['cubic_capacity'],
|
||||
"weight" => $postRequest['weight'],
|
||||
"make" => $postRequest['make'],
|
||||
"model" => $postRequest['model'],
|
||||
"manufacture_year" => $postRequest['year_of_manufacture'],
|
||||
"vehicle_age" => $vehicleAge,
|
||||
"date_of_registration" => $postRequest['date_of_registration'],
|
||||
"fuel_type" => $postRequest['fuel_type'],
|
||||
"geo_rto_state" => $postRequest['rto_state_code'],
|
||||
"geo_rto_city" => $postRequest['rto_city_code'],
|
||||
"policy_issue_date" => $postRequest['issued_date'],
|
||||
"insurer_id" => $postRequest['insurer_id']
|
||||
];
|
||||
|
||||
log_message('debug', 'API Request Payload: ' . json_encode($postData));
|
||||
|
||||
$ch = curl_init($apiUrl);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
// Headers
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/json",
|
||||
"Authorization: Bearer " . $token
|
||||
]);
|
||||
|
||||
// POST Data
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$error = curl_error($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
if ($error)
|
||||
{
|
||||
log_message('error', 'cURL Error: ' . $error);
|
||||
|
||||
return $this->respond( ['status'=>"failed", 'message'=> 'cURL Error: ' . $error], 200);
|
||||
|
||||
} else {
|
||||
|
||||
$value = strtolower(trim($incoming));
|
||||
$value = preg_replace('/\s+/', ' ', $value); // normalize spaces
|
||||
log_message('debug', 'API Response: ' . $response);
|
||||
|
||||
return $this->phraseMap[$value] ?? 'UN_IDEN_TYPE';
|
||||
$result = json_decode($response, true);
|
||||
|
||||
|
||||
if (!empty($result) && isset($result['success']) && $result['success'] === true) {
|
||||
|
||||
// Safely extract values
|
||||
$policyData = [
|
||||
'commission_amount' => $result['data']['payout'] ?? null,
|
||||
'commission_applied_rule' => $result['data']['rule']['id'] ?? null,
|
||||
];
|
||||
|
||||
log_message('debug', 'Updating Policy (ID=75) With: ' . json_encode($policyData));
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $policyData ], 200);
|
||||
|
||||
} else {
|
||||
log_message('debug', 'calculateCommission() - Invalid API Response');
|
||||
|
||||
return $this->respond( ['status'=>"failed", 'message'=> "Invalid API Response!"], 200);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
60
app/Models/PartnerPosModel.php
Normal file
60
app/Models/PartnerPosModel.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class PartnerPosModel extends Model
|
||||
{
|
||||
|
||||
protected $table = 'partner_pos';
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $returnType = 'array'; // Can be 'array' or 'object' (e.g., \App\Entities\PartnerPos)
|
||||
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
protected $useTimestamps = true;
|
||||
|
||||
protected $createdField = 'created_on';
|
||||
|
||||
protected $updatedField = 'updated_on';
|
||||
|
||||
protected $allowedFields = [
|
||||
'name',
|
||||
'email',
|
||||
'mobile',
|
||||
'pos_code',
|
||||
'certificate_file_name',
|
||||
'aadhar',
|
||||
'pan',
|
||||
'is_active',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'manager_id',
|
||||
];
|
||||
|
||||
protected $validationRules = [
|
||||
'name' => 'required|min_length[3]',
|
||||
'email' => 'permit_empty|valid_email|is_unique[partner_pos.email,id,{id}]',
|
||||
'mobile' => 'permit_empty|numeric|max_length[20]|is_unique[partner_pos.mobile,id,{id}]',
|
||||
'manager_id' => 'required|integer',
|
||||
];
|
||||
|
||||
protected $validationMessages = [
|
||||
'email' => [
|
||||
'is_unique' => 'Sorry, that email address is already registered.',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* @var bool Whether to skip validation during inserts and updates.
|
||||
*/
|
||||
protected $skipValidation = false;
|
||||
|
||||
/**
|
||||
* @var bool Whether to clean data for SQL Injection.
|
||||
*/
|
||||
protected $cleanValidationRules = true;
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user