I have five fields in which users can input Start Date, Number of Installments, End Date (calculates based on a number of installments and start date), Monthly EMI, and Lump Sum Payment. I am trying to create a custom EMI Payment Schedule that shows all the monthly payments based on Monthly EMI and every 6th EMI should be the Lump Sum Entry that the user inputs. For example:
StartDate = 02-05-2022
NumberofInstallments = 36
EndDate = 02-05-2025
MonthlyEMI = 10,000
LumpSum = 1,00,000
Based on the above inputs, the GridView should show the following data:
Sl. No. EMI Date Amount Payable
1 02-06-2022 10000
2 02-07-2022 10000
3 02-08-2022 10000
4 02-09-2022 10000
5 02-10-2022 10000
6 02-11-2022 100000
7 02-12-2022 10000
. . . . . . . . . .
36 02-05-2025 10000
I have achieved the Monthly EMI part but don't know what to do about the Lump Sum Payment (Every 6th Installment).
Please find my code below and come up with some help.
My ASPX Code:
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div class="mt-2">
<asp:TextBox ID="txtStartDate" runat="server" CssClass="txt" placeholder="start date" AutoCompleteType="Disabled" autocomplete="off"></asp:TextBox>
<ajax:CalendarExtender ID="aceStartDate" runat="server" Format="dd-MM-yyyy" TodaysDateFormat="dd-MM-yyyy" TargetControlID="txtStartDate" PopupPosition="BottomRight" />
<asp:TextBox ID="txtInstallments" runat="server" CssClass="txt" placeholder="number of installments" AutoCompleteType="Disabled" autocomplete="off" OnTextChanged="InstallmentsChanged" AutoPostBack="true" TextMode="Number"></asp:TextBox>
<asp:TextBox ID="txtEndDate" runat="server" placeholder="end date" CssClass="txt" AutoCompleteType="Disabled" autocomplete="off" Enabled="false"></asp:TextBox>
</div>
<asp:TextBox ID="txtEMI" runat="server" CssClass="txt" placeholder="monthly emi" AutoCompleteType="Disabled" autocomplete="off" TextMode="Number"></asp:TextBox>
<asp:TextBox ID="txtLumpSum" runat="server" CssClass="txt" placeholder="lump sum payment" AutoCompleteType="Disabled" autocomplete="off" TextMode="Number"></asp:TextBox>
<asp:LinkButton ID="btnShow" runat="server" CssClass="btn btn-dark btn-sm" OnClick="GenerateAmortization">Show</asp:LinkButton>
<br />
<asp:GridView ID="gvDates" runat="server" CssClass="table table-sm mt-4 m-1" style="max-width:400px;" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="Sl. No." DataField="Id" />
<asp:BoundField HeaderText="Due Date" DataField="DueDate" />
<asp:BoundField HeaderText="Amount Payable" DataField="DueAmount" />
</Columns>
</asp:GridView>
</div>
</form>
My C# Code:
protected void InstallmentsChanged(object sender, EventArgs e)
{
if (txtInstallments.Text != "" && txtStartDate.Text != "")
{
if (Convert.ToInt32(txtInstallments.Text) > 0)
{
txtEndDate.Text = Convert.ToDateTime(txtStartDate.Text).AddMonths(Convert.ToInt32(txtInstallments.Text)).ToString("dd-MM-yyyy", System.Globalization.DateTimeFormatInfo.CurrentInfo);
}
}
}
protected void GenerateAmortization(object sender, EventArgs e)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[]
{
new System.Data.DataColumn("Id", typeof(int)),
new System.Data.DataColumn("DueDate", typeof(string)),
new System.Data.DataColumn("DueAmount", typeof(string))
});
DateTime startDate = Convert.ToDateTime(txtStartDate.Text);
DateTime endDate = Convert.ToDateTime(txtEndDate.Text);
int i = 1;
while (startDate < endDate)
{
startDate = startDate.AddMonths(1);
dt.Rows.Add(i, startDate.ToString("dd-MM-yyyy"), txtEMI.Text);
i++;
}
gvDates.DataSource = dt;
gvDates.DataBind();
}
Thanks in advance.