Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev

This commit is contained in:
VENKATESHWARAN 2025-11-18 18:40:48 +05:30
commit 7eb3dbaf99

View File

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