nhance-enrollment/tests/unit/PremiumCalculationTest.php

155 lines
12 KiB
PHP
Executable File

<?php
namespace App\Tests;
use CodeIgniter\Test\CIUnitTestCase;
use Config\App;
use Config\Services;
use Tests\Support\Libraries\ConfigReader;
// use App\Helpers\excel_util_helper;
use Kint\Kint;
class PremiumCalculationTest extends CIUnitTestCase
{
public function testPremiumCalculationWithPrimaryRackRateAndAdditionalRackRate($MY_PARAM = 'TATATATATA')
{
helper('excel_util_helper');
$param = getenv('MY_PARAM');
echo isset($param) && $param != NULL ? $param : $MY_PARAM;
$additional_relationship = '{"self":0,"spouse":0,"childrens":1,"parents":0,"parents-in-law":0,"either-parents-pil":0}';
$primary_grid_id = 11;
$additional_grid_id = 10;
$primary_grid_type = 2;
$addtional_grid_type = 2;
$primary_max_si = 35000000;
$slab_details = [ 'slab_rates' =>[
[ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 0, 'age_to' => 18, 'grade' => 'A', 'si' => 5000000, 'premium' => 500, 'max_si' => $primary_max_si,'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 19, 'age_to' => 25, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 26, 'age_to' => 35, 'grade' => 'C', 'si' => 5000000, 'premium' => 2000, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 36, 'age_to' => 45, 'grade' => 'D', 'si' => 5000000, 'premium' => 2500, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 46, 'age_to' => 55, 'grade' => 'E', 'si' => 5000000, 'premium' => 3000, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 56, 'age_to' => 75, 'grade' => 'F', 'si' => 5000000, 'premium' => 3500, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 76, 'age_to' => 85, 'grade' => 'G', 'si' => 5000000, 'premium' => 4000, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 5000000, 'premium' => 4500, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => $primary_max_si, 'premium' => 15000, 'max_si' => 0, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 30000000, 'premium' => 30000, 'max_si' => 0, 'premium_type' => $primary_grid_type, 'relationship' => null]
],
'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => $primary_grid_id,'policy_grid_type' => 'Employees + Relationship + max count','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0],
'additional_slab_info' => [
'slab_rates' =>[
[ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 0, 'age_to' => 18, 'grade' => 'A', 'si' => 5000000, 'premium' => 500, 'max_si' => 2500000,'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship ],
[ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 19, 'age_to' => 25, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => 2000000, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 26, 'age_to' => 35, 'grade' => 'C', 'si' => 5000000, 'premium' => 2000, 'max_si' => 1800000, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 36, 'age_to' => 45, 'grade' => 'D', 'si' => 5000000, 'premium' => 2500, 'max_si' => 150000, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 46, 'age_to' => 55, 'grade' => 'E', 'si' => 5000000, 'premium' => 3000, 'max_si' => 130000, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 56, 'age_to' => 75, 'grade' => 'F', 'si' => 5000000, 'premium' => 3500, 'max_si' => 10, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 76, 'age_to' => 85, 'grade' => 'G', 'si' => 5000000, 'premium' => 4000, 'max_si' => 5, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 5000000, 'premium' => 4500, 'max_si' => 5, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship]],
'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => $additional_grid_id,'policy_grid_type' => 'Employees + Relationship + max count','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0]]
];
// Sample family data
$family_details = [ 'TEST001' =>
[2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', NULL, '', '', 'G', '', '', '', '', '', '',''],
[1,'TEST001','Jane Doe', '01-Jan-1985', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', '0', '', '', ''],
[3,'TEST001','Peter Doe', '01-Jan-1955', 'M', 'Father', '', NULL, '', '', '', '', '', '', '', '', '',''],
[4,'TEST001','Mary Doe', '01-Jan-1953', 'F', 'Mother', '', NULL, '', '', '', '', '', '', '', '', '',''],
[5,'TEST001','Grace Doe', '01-Jan-1954', 'F', 'Mother in law', '', NULL, '', '', '', '', '', '', '', '', '',''],
[6,'TEST001','George Doe', '01-Jan-1948', 'M', 'Father in law', '', NULL, '', '', '', '', '', '', '', '', '',''],
[7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', '',''],
[6,'TEST001','Bob Doe', '01-Jan-1993', 'M', 'son', '50000', NULL, '', '', '', '', '', '', '', '', '',''],
];
// Sample policy terms
$policy_terms = [
'family_floater' => true,
'family_floaters' => [
'self' => 1,
'childrens' => 2,
'spouse' => 1,
'either-parents-pil' => 0,
'parents' => 2,
'parents-in-law' => 2,
],
];
$policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)];
$file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception'];
$data = calculate_premimum($family_details,$policy_details,$slab_details,$file);
$policy_created_count = 0;
echo "\n";
$result_to_display = [];
foreach ($data as $key => $value)
{
$result_to_display[$key]['emp_code'] = $value['emp_code'];
$result_to_display[$key]['name'] = $value['name'].'('.calculate_days_bw_dates($value['dob'])->y.')';
$result_to_display[$key]['relation'] = $value['relationship'];
$temp_grid = substr($value['temp']['grid_type'],0,1);
$temp_grid_type = ($temp_grid == 'p' ? $primary_grid_type : $addtional_grid_type);
$temp_grid_type = ($temp_grid_type == 1 ? 'S' : 'I');
$result_to_display[$key]['premium_type'] = $temp_grid.'#'.$value['temp']['grid_id'].'#'.
($value['temp']['additional_rack_rate_acting_self'] == true ? 'Y' : 'N' ) .'#'. ($temp_grid_type) ;
$result_to_display[$key]['si'] = $value['policy_details']['basic_cover_si'];
$result_to_display[$key]['premium'] = $value['policy_details']['premium'];
$result_to_display[$key]['policy days'] = calculate_days_bw_dates($policy_details['policy_start_date'],$policy_details['policy_end_date'])->days;
$result_to_display[$key]['no of days'] = $value['policy_details']['days'];
$result_to_display[$key]['rata_premimum'] = $value['policy_details']['rata_premimum'];
$result_to_display[$key]['gst'] = $value['policy_details']['gst'];
if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; }
}
TableDisplay::displayTable($result_to_display);
$this->assertTrue(($policy_created_count = 1 || $policy_created_count = 0));
}
}
class TableDisplay
{
public static function displayTable(array $data)
{
if (empty($data)) {
echo "No data to display.\n";
return;
}
// Calculate column widths
$columns = array_keys($data[0]);
$widths = array_map(function ($col) use ($data) {
$maxWidth = strlen($col);
foreach ($data as $row) {
$maxWidth = max($maxWidth, strlen($row[$col]));
}
return $maxWidth;
}, $columns);
// Print header
echo str_repeat('-', array_sum($widths) + count($columns) * 3) . PHP_EOL;
foreach ($columns as $i => $col) {
echo str_pad($col, $widths[$i]) . " | ";
}
echo PHP_EOL;
echo str_repeat('-', array_sum($widths) + count($columns) * 3) . PHP_EOL;
// Print rows
foreach ($data as $row) {
foreach ($columns as $i => $col) {
echo str_pad($row[$col], $widths[$i]) . " | ";
}
echo PHP_EOL;
}
echo str_repeat('-', array_sum($widths) + count($columns) * 3) . PHP_EOL;
}
}