Technical Round: EMI Processing
Note:
The code must be follow repository and service pattern.
There should be a separate screen(form) for calculating Loan EMI.
The data should be stored dynamically in DB.
1) Create a table named loan_details with the following fields using migrations
clientid-- This is client id
num_of_payment-- This is the total number of payments client has to make (Like EMI)
first_payment_date-- This is the start date of payment(YYYY-MM-DD)
last_payment_date-- This is the end date of payment(YYYY-MM-DD)
loan_amount-- This is the total amount to be paid by client (Sum of all EMI)
2) Add data to the table loan_details using seeds.
clientid num_of_payment first_payment_date last_payment_date loan_amount
1001 12 2018-06-29 2019-05-29 1550.00
1003 7 2019-02-15 2019-08-15 6851.94
1005 17 2017-11-09 2019-03-09 1800.01
3) Create a User table named user
4) Add a user to the user table using seeds.
username: developer
password: Test@Password123#
5) Create a basic Laravel based admin page that logs in with this user - Using Laravel Auth Login.
6) Create a page where we display the data of table loan_details
7) Create a page that initially has a button named Process Data.
a) Initially the page will be blank.
b) When the Process Data button is clicked, we need to create a table named
emi_details dynamically with the below details. If the table already exists, delete the table
and recreate it. Use RAW Query. Not Laravel Query.
Column 1 – clientid
Dynamic columns - We need to create columns for all months - based on the
min first_payment_date and max last_payment_date of all the entire loan_details table.
NOTE:
The below given example is just for your understanding of the logic and not connected with the
actual loan_details table.
Consider the below row in loan_details as example
Clientid num_of_payment first_payment_date last_payment_date loan_amount
1 2 2019-02-15 2019-03-15 100
2 3 2019-03-16 2019-05-16 200
Here min first_payment_date= 2019-02-15 and max last_payment_date= 2019-05-16,
the resulting columns will be:
2019_Feb
2019_Mar
2019_Apr
2019_May
c) Next we process each row in the loan_details table, and add it into the emi_details table
as row.
- EMI amount =loan_amount/num_of_payment.
- We then save each EMI amount into the corresponding months
- For Clientid 1: EMI = 100/2 = 50
- For Clientid 2: EMI = 200/3 = 66.67
Therefore, values for columns emi_details table for the client would be
Clientid 2019_Feb 2019_Mar 2019_Apr 2019_May
1 50.00 50.00 0.00 0.00
2 0.00 66.67 66.67 66.66 (Adjusted)
NOTE:
We need to make sure that the total EMI amount should be exactly equal to the total
loan amount.
In this example it is adjusted to 66.66 in the last month for client id 2.
d) Display the data of table emi_details in the page.
e) When the Process Data button is clicked, again the Steps 6 & 7 should be repeated.