FIX_COMMISSION_CALC_API

This commit is contained in:
velz 2025-11-18 17:23:28 +05:30
parent 8099ef3373
commit da08eeacb5

View File

@ -118,26 +118,28 @@ class InsuranceCommissionController extends AdminController
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \Exception('Invalid JSON in rules file: ' . json_last_error_msg());
}
// print_r($parsed);die();
// Normalise department keys to lowercase for consistent lookups
$this->rules = [];
foreach ($parsed as $dept => $rules) {
$this->rules[strtolower($dept)] = $rules;
}
// print_r($this->rules);die();
}
public function calculateCommission(array $policyData)
{
$department = $policyData['department'] ?? '';
$deptKey = strtolower($department);
if (!isset($this->rules[$deptKey])) {
throw new \Exception("No rules found for department: {$department}");
}
// print_r($this->rules);die();
// if (!isset($this->rules[$deptKey])) {
// throw new \Exception("No rules found for department: {$department}");
// }
$matchingRules = [];
foreach ($this->rules[$deptKey] as $rule) {
foreach ($this->rules as $rule) {
if ($this->evaluateConditions($rule['conditions'] ?? [], $policyData)) {
$matchingRules[] = $rule;
}
@ -146,7 +148,7 @@ class InsuranceCommissionController extends AdminController
if (empty($matchingRules)) {
throw new \Exception('No matching rules found for the policy data');
}
// print_r($matchingRules);die;
// Use the first matching rule. In future you can implement priority/weighting
$applicableRule = $matchingRules[0];