unit LoanItUnit; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, OutPutUnit, math; type { TLoanItFrm } TLoanItFrm = class(TForm) PrintChk: TCheckBox; DayEdit: TEdit; YearEdit: TEdit; MonthEdit: TEdit; Label7: TLabel; Label8: TLabel; Label9: TLabel; NameEdit: TEdit; Label6: TLabel; ResetBtn: TButton; AmortizeBtn: TButton; ReturnBtn: TButton; AmountEdit: TEdit; InterestEdit: TEdit; YearsEdit: TEdit; PayPerYrEdit: TEdit; RePayEdit: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; procedure AmortizeBtnClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure ResetBtnClick(Sender: TObject); procedure Heading(Sender: TObject); private { private declarations } public { public declarations } end; var LoanItFrm: TLoanItFrm; implementation { TLoanItFrm } procedure TLoanItFrm.ResetBtnClick(Sender: TObject); begin NameEdit.Text := ''; MonthEdit.Text := ''; DayEdit.Text := ''; YearEdit.Text := ''; YearsEdit.Text := '30'; AmountEdit.Text := '10000'; InterestEdit.Text := '6.5'; PayPerYrEdit.Text := '12'; RepayEdit.Text := ''; end; procedure TLoanItFrm.FormShow(Sender: TObject); begin ResetBtnClick(self); end; procedure TLoanItFrm.AmortizeBtnClick(Sender: TObject); VAR no_per_year, year_payed, month_payed, day, month, j, k : integer; fraction, interest, numerator, denominator, payment, total_interest : double; amount, interest_payment, total_payed, pcnt_interest, years, no_years : double; aname, astring : string; outline : string; begin aname := NameEdit.Text; no_per_year := StrToInt(PayPerYrEdit.Text); day := StrToInt(DayEdit.Text); month := StrToInt(MonthEdit.Text); years := StrToFloat(YearEdit.Text); amount := StrToFloat(AmountEdit.Text); no_years := StrToFloat(YearsEdit.Text); pcnt_interest := StrToFloat(InterestEdit.Text); interest := pcnt_interest / 100.0; numerator := interest * amount / no_per_year ; denominator := 1.0 - (1.0 / power((interest / no_per_year + 1.0), (no_per_year * no_years) ) ); payment := numerator / denominator; outline := format('%10.2f',[payment]); repayEdit.Text := outline; if PrintChk.Checked = false then exit; OutPutFrm.RichEdit.Clear; // OutPutFrm.RichEdit.Lines.Add(outline); if (no_per_year < 12) then fraction := 12.0 / no_per_year else fraction := 1.0; OutPutFrm.RichEdit.Lines.Add('Payment Schedule Program by W. G. Miller'); OutPutFrm.RichEdit.Lines.Add(''); OutPutFrm.RichEdit.Lines.Add('----------------------------------------------------------------------------'); OutPutFrm.RichEdit.Lines.Add(''); astring := 'Name of Borrower : '; astring := astring + aname; OutPutFrm.RichEdit.Lines.Add(astring); outline := format('Amount borrowed := $%12.2f at %5.2f percent over %2.1f years.', [amount,pcnt_interest,no_years]); total_interest := 0.0; total_payed := 0.0; for j := 1 to round(no_years) do begin Heading(self); for k := 1 to no_per_year do begin year_payed := round(years) + j - 1 ; month_payed := round(k * fraction + (month - fraction)); if (month_payed > 12) then begin year_payed := year_payed + 1; month_payed := month_payed - 12; end; interest_payment := amount * interest / no_per_year; amount := amount - payment + interest_payment; total_interest := total_interest + interest_payment; total_payed := total_payed + payment; outline := format(' %2d/%2d/%2d %12.2f %12.2f %12.2f %12.2f %12.2f', [month_payed,day,year_payed,payment,interest_payment, amount,total_interest,total_payed]); OutPutFrm.RichEdit.Lines.Add(outline); end; // next k OutPutFrm.RichEdit.Lines.Add(''); OutPutFrm.RichEdit.Lines.Add('----------------------------------------------------------------------------'); end; // next j OutPutFrm.ShowModal; end; procedure TLoanItFrm.Heading(Sender: TObject); begin OutPutFrm.RichEdit.Lines.Add('----------------------------------------------------------------------------'); OutPutFrm.RichEdit.Lines.Add('PAYMENT PAYMENT INTEREST BALANCE TOTAL TOTAL'); OutPutFrm.RichEdit.Lines.Add('NUMBER AMOUNT PAYED REMAINING INTEREST PAID'); OutPutFrm.RichEdit.Lines.Add('----------------------------------------------------------------------------'); end; initialization {$I loanitunit.lrs} end.