Here is the sample data for my problem,

List<EMPINSURED> lstEmpIns = new List<EMPINSURED>{
new EMPINSURED{ EmpID = 558, TOTAL_INSURED_AMT = 50000},
new EMPINSURED{ EmpID = 559, TOTAL_INSURED_AMT = 75000}
};
List<EMP_ROUTINE_CHECKUP_HISTORY> lstEmpRoutineChkHist = new List<EMP_ROUTINE_CHECKUP_HISTORY>{
new EMP_ROUTINE_CHECKUP_HISTORY{ ID = 1, EmpID = 558, ROUTINE_CHECKUP = 1, CHECK_UP_CHARGE = 20000},
new EMP_ROUTINE_CHECKUP_HISTORY{ ID = 2, EmpID = 559, ROUTINE_CHECKUP = 1, CHECK_UP_CHARGE = 35000},
new EMP_ROUTINE_CHECKUP_HISTORY{ ID = 3, EmpID = 558, ROUTINE_CHECKUP = 2, CHECK_UP_CHARGE = 10000},
new EMP_ROUTINE_CHECKUP_HISTORY{ ID = 4, EmpID = 559, ROUTINE_CHECKUP = 2, CHECK_UP_CHARGE = 10000},
new EMP_ROUTINE_CHECKUP_HISTORY{ ID = 5, EmpID = 558, ROUTINE_CHECKUP = 3, CHECK_UP_CHARGE = 20000}
};

In a year, an Employee is allowed only 3(three) routine checkups. When an employee goes for routine checkup, his/her check up charges must be deducted from the total insured amount after every checkups. For the next routine check up, employee will be awarded check up charges only for the remainig amount he/she has from the total insured amount, any expenses more than that the company will not bear.

So for the logic for calculating REMAINING AMOUNT would be somewhat like this ::

int var = 0;
if(ROUTINE_CHECKUP == 1)
{
REMAINING_AMOUNT = TOTAL_INSURED_AMT - CHECK_UP_CHARGE;
var = CHECK_UP_CHARGE;
}
else if (ROUTINE_CHECKUP == 2)
{
REMAINING_AMOUNT = TOTAL_INSURED_AMT - (CHECK_UP_CHARGE + var);
var = CHECK_UP_CHARGE + var;
}
else if (ROUTINE_CHECKUP == 3)
{
REMAINING_AMOUNT = TOTAL_INSURED_AMT - (CHECK_UP_CHARGE + var);
var = CHECK_UP_CHARGE + var;
}

How to develop the LINQ query to get the below report data using this logic or there may some better way to do this.

Please see the link of the image for report format.

query — ImgBB[

^]

**What I have tried:**
I have no idea how to do this. Please help me with this problem.