LazStats: Inherit form of LoanItUnit from report&chart template. Add chart of amortization.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7783 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-19 13:21:37 +00:00
parent b93c6936bf
commit ad2b13edcf
4 changed files with 513 additions and 530 deletions

View File

@ -865,7 +865,7 @@
<Unit95> <Unit95>
<Filename Value="forms\analysis\financial\loanitunit.pas"/> <Filename Value="forms\analysis\financial\loanitunit.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<ComponentName Value="LoanItFrm"/> <ComponentName Value="LoanItForm"/>
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="LoanItUnit"/> <UnitName Value="LoanItUnit"/>

View File

@ -1,302 +1,81 @@
object LoanItFrm: TLoanItFrm inherited LoanItForm: TLoanItForm
Left = 310 Left = 310
Height = 377 Height = 406
Top = 131 Top = 131
Width = 353 Width = 723
HelpType = htKeyword HelpType = htKeyword
HelpKeyword = 'html/LoanAmortizationSchedule.htm' HelpKeyword = 'html/LoanAmortizationSchedule.htm'
AutoSize = True
BorderStyle = bsDialog
Caption = 'Loan Calculation and Amortization' Caption = 'Loan Calculation and Amortization'
ClientHeight = 377 ClientHeight = 406
ClientWidth = 353 ClientWidth = 723
OnActivate = FormActivate inherited ParamsPanel: TPanel
OnShow = FormShow Height = 390
Position = poMainFormCenter ClientHeight = 390
LCLVersion = '2.1.0.0' inherited CloseBtn: TButton
object Label1: TLabel Top = 365
AnchorSideTop.Control = AmountEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom
Left = 103
Height = 15
Top = 123
Width = 93
Anchors = [akTop, akRight]
BorderSpacing.Left = 8
Caption = 'Principal Amount'
ParentColor = False
end end
object Label2: TLabel inherited ComputeBtn: TButton
AnchorSideLeft.Control = Owner Top = 365
AnchorSideTop.Control = InterestEdit
AnchorSideTop.Side = asrCenter
Left = 24
Height = 15
Top = 162
Width = 172
BorderSpacing.Left = 24
Caption = 'Annual Percentage Rate (APR %)'
ParentColor = False
end end
object Label3: TLabel inherited ResetBtn: TButton
AnchorSideTop.Control = YearsEdit Top = 365
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom
Left = 59
Height = 15
Top = 189
Width = 137
Anchors = [akTop, akRight]
BorderSpacing.Left = 8
Caption = 'Number of Years to Repay'
ParentColor = False
end end
object Label4: TLabel inherited HelpBtn: TButton
AnchorSideTop.Control = PayPerYrEdit Top = 365
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom
Left = 38
Height = 15
Top = 216
Width = 158
Anchors = [akTop, akRight]
BorderSpacing.Left = 8
Caption = 'Number of Payments Per Year'
ParentColor = False
end end
object Label5: TLabel inherited ButtonBevel: TBevel
AnchorSideTop.Control = RePayEdit Top = 349
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom
Left = 149
Height = 15
Top = 259
Width = 47
Anchors = [akTop, akRight]
BorderSpacing.Left = 8
Caption = 'Payment'
ParentColor = False
end end
object Label6: TLabel object Label6: TLabel[5]
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = NameEdit AnchorSideTop.Control = NameEdit
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 24 Left = 24
Height = 15 Height = 15
Top = 12 Top = 4
Width = 65 Width = 65
BorderSpacing.Left = 24 BorderSpacing.Left = 24
Caption = 'Your Name: ' Caption = 'Your Name: '
ParentColor = False ParentColor = False
end end
object AmountEdit: TEdit object NameEdit: TEdit[6]
AnchorSideLeft.Control = InterestEdit
AnchorSideTop.Control = Bevel2
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = NameEdit
AnchorSideRight.Side = asrBottom
Left = 204
Height = 23
Top = 119
Width = 125
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 16
TabOrder = 3
Text = 'AmountEdit'
end
object InterestEdit: TEdit
AnchorSideLeft.Control = Label2
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = AmountEdit
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = AmountEdit
AnchorSideRight.Side = asrBottom
Left = 204
Height = 23
Top = 158
Width = 125
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 8
BorderSpacing.Top = 16
TabOrder = 4
Text = 'InterestEdit'
end
object YearsEdit: TEdit
AnchorSideLeft.Control = InterestEdit
AnchorSideTop.Control = InterestEdit
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = InterestEdit
AnchorSideRight.Side = asrBottom
Left = 204
Height = 23
Top = 185
Width = 125
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4
TabOrder = 5
Text = 'YearsEdit'
end
object PayPerYrEdit: TEdit
AnchorSideLeft.Control = InterestEdit
AnchorSideTop.Control = YearsEdit
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = InterestEdit
AnchorSideRight.Side = asrBottom
Left = 204
Height = 23
Top = 212
Width = 125
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4
TabOrder = 6
Text = 'PayPerYrEdit'
end
object RePayEdit: TEdit
AnchorSideLeft.Control = InterestEdit
AnchorSideTop.Control = Bevel4
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = AmountEdit
AnchorSideRight.Side = asrBottom
Left = 204
Height = 23
Top = 255
Width = 125
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 8
Font.Style = [fsBold]
ParentFont = False
ReadOnly = True
TabOrder = 7
Text = 'RePayEdit'
end
object ResetBtn: TButton
AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = AmortizeBtn
Left = 144
Height = 25
Top = 333
Width = 54
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 9
end
object AmortizeBtn: TButton
AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = CloseBtn
Left = 206
Height = 25
Top = 333
Width = 76
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Compute'
OnClick = AmortizeBtnClick
TabOrder = 10
end
object CloseBtn: TButton
AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 290
Height = 25
Top = 333
Width = 55
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Top = 8
BorderSpacing.Right = 8
Caption = 'Close'
ModalResult = 11
TabOrder = 11
end
object NameEdit: TEdit
AnchorSideLeft.Control = Label6 AnchorSideLeft.Control = Label6
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Owner AnchorSideTop.Control = ParamsPanel
AnchorSideRight.Control = Owner AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 97 Left = 97
Height = 23 Height = 23
Top = 8 Top = 0
Width = 232 Width = 194
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Top = 8 TabOrder = 4
BorderSpacing.Right = 24
TabOrder = 0
Text = 'NameEdit' Text = 'NameEdit'
end end
object PrintChk: TCheckBox object CalendarBtn: TButton[7]
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = RePayEdit
AnchorSideTop.Side = asrBottom
Left = 24
Height = 19
Top = 290
Width = 188
BorderSpacing.Left = 24
BorderSpacing.Top = 12
Caption = 'Print the Amortization Schedule'
TabOrder = 8
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = PrintChk
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 0
Height = 8
Top = 317
Width = 353
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 8
Shape = bsBottomLine
end
object CalendarBtn: TButton
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = NameEdit AnchorSideRight.Control = NameEdit
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Panel1 AnchorSideBottom.Control = Panel1
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 294 Left = 256
Height = 25 Height = 25
Top = 58 Top = 50
Width = 35 Width = 35
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
AutoSize = True AutoSize = True
Caption = '...' Caption = '...'
OnClick = CalendarBtnClick OnClick = CalendarBtnClick
TabOrder = 2 TabOrder = 5
end end
object Panel1: TPanel object Panel1: TPanel[8]
AnchorSideTop.Control = NameEdit AnchorSideTop.Control = NameEdit
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = CalendarBtn AnchorSideRight.Control = CalendarBtn
Left = 30 Left = -8
Height = 40 Height = 40
Top = 43 Top = 35
Width = 260 Width = 260
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
AutoSize = True AutoSize = True
@ -308,7 +87,7 @@ object LoanItFrm: TLoanItFrm
ChildSizing.ControlsPerLine = 1 ChildSizing.ControlsPerLine = 1
ClientHeight = 40 ClientHeight = 40
ClientWidth = 260 ClientWidth = 260
TabOrder = 1 TabOrder = 6
object MonthLabel: TLabel object MonthLabel: TLabel
AnchorSideLeft.Control = Panel1 AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Panel1 AnchorSideTop.Control = Panel1
@ -390,42 +169,200 @@ object LoanItFrm: TLoanItFrm
Text = 'YearEdit' Text = 'YearEdit'
end end
end end
object Bevel2: TBevel object Bevel2: TBevel[9]
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = Panel1 AnchorSideTop.Control = Panel1
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 24 Left = 0
Height = 8 Height = 8
Top = 95 Top = 87
Width = 305 Width = 291
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 24
BorderSpacing.Top = 12 BorderSpacing.Top = 12
BorderSpacing.Right = 24
Shape = bsBottomLine Shape = bsBottomLine
end end
object Bevel4: TBevel object Label1: TLabel[10]
AnchorSideLeft.Control = Label5 AnchorSideTop.Control = AmountEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom
Left = 103
Height = 15
Top = 115
Width = 93
Anchors = [akTop, akRight]
BorderSpacing.Left = 8
Caption = 'Principal Amount'
ParentColor = False
end
object Label2: TLabel[11]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = InterestEdit
AnchorSideTop.Side = asrCenter
Left = 24
Height = 15
Top = 154
Width = 172
BorderSpacing.Left = 24
Caption = 'Annual Percentage Rate (APR %)'
ParentColor = False
end
object Label3: TLabel[12]
AnchorSideTop.Control = YearsEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom
Left = 59
Height = 15
Top = 181
Width = 137
Anchors = [akTop, akRight]
BorderSpacing.Left = 8
Caption = 'Number of Years to Repay'
ParentColor = False
end
object Label4: TLabel[13]
AnchorSideTop.Control = PayPerYrEdit AnchorSideTop.Control = PayPerYrEdit
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Owner AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom
Left = 38
Height = 15
Top = 208
Width = 158
Anchors = [akTop, akRight]
BorderSpacing.Left = 8
Caption = 'Number of Payments Per Year'
ParentColor = False
end
object Label5: TLabel[14]
AnchorSideTop.Control = RePayEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 149 Left = 149
Height = 8 Height = 15
Top = 239 Top = 251
Width = 180 Width = 47
Anchors = [akTop, akRight]
BorderSpacing.Left = 8
Caption = 'Payment'
ParentColor = False
end
object AmountEdit: TEdit[15]
AnchorSideLeft.Control = InterestEdit
AnchorSideTop.Control = Bevel2
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = NameEdit
AnchorSideRight.Side = asrBottom
Left = 204
Height = 23
Top = 111
Width = 87
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 16
TabOrder = 7
Text = 'AmountEdit'
end
object InterestEdit: TEdit[16]
AnchorSideLeft.Control = Label2
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = AmountEdit
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = AmountEdit
AnchorSideRight.Side = asrBottom
Left = 204
Height = 23
Top = 150
Width = 87
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 8
BorderSpacing.Top = 16
TabOrder = 8
Text = 'InterestEdit'
end
object YearsEdit: TEdit[17]
AnchorSideLeft.Control = InterestEdit
AnchorSideTop.Control = InterestEdit
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = InterestEdit
AnchorSideRight.Side = asrBottom
Left = 204
Height = 23
Top = 177
Width = 87
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4
TabOrder = 9
Text = 'YearsEdit'
end
object PayPerYrEdit: TEdit[18]
AnchorSideLeft.Control = InterestEdit
AnchorSideTop.Control = YearsEdit
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = InterestEdit
AnchorSideRight.Side = asrBottom
Left = 204
Height = 23
Top = 204
Width = 87
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4
TabOrder = 10
Text = 'PayPerYrEdit'
end
object RePayEdit: TEdit[19]
AnchorSideLeft.Control = InterestEdit
AnchorSideTop.Control = Bevel4
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = AmountEdit
AnchorSideRight.Side = asrBottom
Left = 204
Height = 23
Top = 247
Width = 87
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 8
Font.Style = [fsBold]
ParentFont = False
ReadOnly = True
TabOrder = 11
Text = 'RePayEdit'
end
object Bevel4: TBevel[20]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = PayPerYrEdit
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
Left = 0
Height = 8
Top = 231
Width = 291
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4 BorderSpacing.Top = 4
BorderSpacing.Right = 24
Shape = bsBottomLine Shape = bsBottomLine
end end
object CalendarDialog1: TCalendarDialog end
inherited ParamsSplitter: TSplitter
Height = 406
end
inherited PageControl: TPageControl
Height = 390
Width = 403
end
object CalendarDialog1: TCalendarDialog[3]
Date = 43890 Date = 43890
OKCaption = '&OK' OKCaption = '&OK'
CancelCaption = 'Cancel' CancelCaption = 'Cancel'
Left = 40 Left = 56
Top = 312 Top = 264
end end
end end

View File

@ -5,21 +5,20 @@ unit LoanItUnit;
interface interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls, ExtDlgs; StdCtrls, ExtCtrls, ExtDlgs, ComCtrls, TACustomSeries, TAIntervalSources,
ChartFrameUnit, BasicStatsReportAndChartFormUnit;
type type
{ TLoanItFrm } { TLoanItForm }
TLoanItFrm = class(TForm) TLoanItForm = class(TBasicStatsReportAndChartForm)
Bevel1: TBevel;
Bevel2: TBevel; Bevel2: TBevel;
Bevel4: TBevel; Bevel4: TBevel;
CalendarBtn: TButton; CalendarBtn: TButton;
CalendarDialog1: TCalendarDialog; CalendarDialog1: TCalendarDialog;
Panel1: TPanel; Panel1: TPanel;
PrintChk: TCheckBox;
DayEdit: TEdit; DayEdit: TEdit;
YearEdit: TEdit; YearEdit: TEdit;
MonthEdit: TEdit; MonthEdit: TEdit;
@ -28,9 +27,6 @@ type
YearLabel: TLabel; YearLabel: TLabel;
NameEdit: TEdit; NameEdit: TEdit;
Label6: TLabel; Label6: TLabel;
ResetBtn: TButton;
AmortizeBtn: TButton;
CloseBtn: TButton;
AmountEdit: TEdit; AmountEdit: TEdit;
InterestEdit: TEdit; InterestEdit: TEdit;
YearsEdit: TEdit; YearsEdit: TEdit;
@ -41,131 +37,99 @@ type
Label3: TLabel; Label3: TLabel;
Label4: TLabel; Label4: TLabel;
Label5: TLabel; Label5: TLabel;
procedure AmortizeBtnClick(Sender: TObject);
procedure CalendarBtnClick(Sender: TObject); procedure CalendarBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
private private
{ private declarations } FBalanceRemainSeries: TChartSeries;
function Validate(out AMsg: String; out AControl: TWinControl): boolean; FTotalInterestSeries: TChartSeries;
FTotalPaidSeries: TChartSeries;
protected
procedure AdjustConstraints; override;
procedure Compute; override;
function Validate(out AMsg: String; out AControl: TWinControl): boolean; override;
public public
{ public declarations } constructor Create(AOwner: TComponent); override;
procedure Reset; override;
end; end;
var var
LoanItFrm: TLoanItFrm; LoanItForm: TLoanItForm;
implementation implementation
{$R *.lfm}
uses uses
Math, DateUtils, OutputUnit; Math, DateUtils,
TAChartUtils, TALegend, TASeries;
{ TLoanItFrm } { TLoanItForm }
procedure TLoanItFrm.ResetBtnClick(Sender: TObject); constructor TLoanItForm.Create(AOwner: TComponent);
begin begin
NameEdit.Text := ''; inherited;
MonthEdit.Text := '';
DayEdit.Text := ''; FBalanceRemainSeries := TLineSeries.Create(FChartFrame);
YearEdit.Text := ''; with TLineSeries(FBalanceRemainSeries) do
YearsEdit.Text := ''; begin
AmountEdit.Text := ''; LinePen.Color := DATA_COLORS[0];
InterestEdit.Text := ''; LinePen.Width := 2;
PayPerYrEdit.Text := ''; Title := 'Remaining balance';
RepayEdit.Text := ''; end;
FChartFrame.Chart.AddSeries(FBalanceRemainSeries);
FTotalInterestSeries := TLineSeries.Create(FChartFrame);
with TLineSeries(FTotalInterestSeries) do
begin
LinePen.Color := DATA_COLORS[1];
Title := 'Total interest';
end;
FChartFrame.Chart.AddSeries(FTotalInterestSeries);
FTotalPaidSeries := TLineSeries.Create(FChartFrame);
with TLineSeries(FTotalPaidSeries) do
begin
LinePen.Color := DATA_COLORS[2];
Title := 'Total paid';
end;
FChartFrame.Chart.AddSeries(FTotalPaidSeries);
FChartFrame.Chart.Legend.Visible := true;
FChartFrame.Chart.Legend.ColumnCount := 3;
FChartFrame.Chart.Legend.Alignment := laBottomCenter;
FChartFrame.Chart.BottomAxis.Marks.Source := TDateTimeIntervalchartSource.Create(FChartFrame);
with TDateTimeIntervalChartSource(FChartFrame.Chart.BottomAxis.Marks.Source) do
begin
Params.MaxLength := 120;
Params.MinLength := 50;
end;
FChartFrame.Chart.BottomAxis.Marks.Style := smsLabel;
FChartFrame.Chart.LeftAxis.Marks.Format := '%.0n';
FChartFrame.SetXTitle('Date');
FChartFrame.SetYTitle('Amounts');
FChartFrame.SetTitle('Amortization Schedule');
PageControl.ActivePageIndex := 0;
end; end;
procedure TLoanItFrm.FormShow(Sender: TObject);
procedure TLoanItForm.AdjustConstraints;
begin begin
ResetBtnClick(self); inherited;
ParamsPanel.Constraints.MinWidth := Max(
Panel1.Width + Panel1.BorderSpacing.Right + CalendarBtn.Width,
4 * CloseBtn.Width + 3 * CloseBtn.BorderSpacing.Left
);
ParamsPanel.Constraints.MinHeight := RepayEdit.Top + RepayEdit.Height +
ButtonBevel.Height + CloseBtn.BorderSpacing.Top + CloseBtn.Height;
end; 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: string;
msg: String;
C: TWinControl;
lReport: TStrings;
begin
if not Validate(msg, C) then begin
C.SetFocus;
MessageDlg(msg, mtError, [mbOk], 0);
ModalResult := mrNone;
exit;
end;
aname := NameEdit.Text; procedure TLoanItForm.CalendarBtnClick(Sender: TObject);
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;
RePayEdit.Text := Format('%.2f', [payment]);
if not PrintChk.Checked then
exit;
if (no_per_year < 12) then
fraction := 12.0 / no_per_year else fraction := 1.0;
lReport := TStringList.Create;
try
lReport.Add( 'PAYMENT SCHEDULE PROGRAM by W. G. Miller');
lReport.Add( '');
lReport.Add( '---------------------------------------------------------------------------');
lReport.Add( '');
lReport.Add( 'Name of Borrower: ' + aname);
lReport.Add( 'Amount borrowed: $%.2f at %.2f percent over %.1f years.', [amount, pcnt_interest, no_years]);
lReport.Add( '');
total_interest := 0.0;
total_payed := 0.0;
for j := 1 to round(no_years) do
begin
lReport.Add('---------------------------------------------------------------------------');
lReport.Add(' PAYMENT PAYMENT INTEREST BALANCE TOTAL TOTAL');
lReport.Add(' DATE AMOUNT PAYED REMAINING INTEREST PAID');
lReport.Add('---------------------------------------------------------------------------');
// 'xx/xx/xxxx xxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxx
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;
lReport.Add('%2d/%2d/%4d %12.2f %12.2f %12.2f %12.2f %12.2f', [
month_payed, day, year_payed, payment, interest_payment,
amount, total_interest, total_payed
]);
end; // next k
lReport.Add('');
end; // next j
DisplayReport(lReport);
finally
lReport.Free;
end;
end;
procedure TLoanItFrm.CalendarBtnClick(Sender: TObject);
var var
d: TDate; d: TDate;
dy, mn, yr: Integer; dy, mn, yr: Integer;
@ -186,23 +150,108 @@ begin
end; end;
end; end;
procedure TLoanItFrm.FormActivate(Sender: TObject);
procedure TLoanItForm.Compute;
var var
w: Integer; no_per_year, year_paid, month_paid, day, month, j, k: integer;
fraction, interest, numerator, denominator, payment, total_interest: double;
amount, interest_payment, total_paid, pcnt_interest, years, no_years: double;
aname: string;
paymentDate: TDate;
lReport: TStrings;
begin begin
w := MaxValue([ResetBtn.Width, AmortizeBtn.Width, CloseBtn.Width]); FBalanceRemainSeries.Clear;
ResetBtn.Constraints.MinWidth := w; FTotalInterestSeries.Clear;
AmortizeBtn.Constraints.MinWidth := w; FTotalPaidSeries.Clear;
CloseBtn.Constraints.MinWidth := w;
{ aname := NameEdit.Text;
w := DayEdit.Width; no_per_year := StrToInt(PayPerYrEdit.Text);
DayEdit.Constraints.MaxWidth := w; day := StrToInt(DayEdit.Text);
MonthEdit.Constraints.MaxWidth := w; month := StrToInt(MonthEdit.Text);
YearEdit.Constraints.MaxWidth := w; 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;
RePayEdit.Text := Format('%.2f', [payment]);
if (no_per_year < 12) then
fraction := 12.0 / no_per_year
else
fraction := 1.0;
lReport := TStringList.Create;
try
lReport.Add( 'PAYMENT SCHEDULE PROGRAM by W. G. Miller');
lReport.Add( '');
lReport.Add( '---------------------------------------------------------------------------');
lReport.Add( '');
lReport.Add( 'Name of Borrower: ' + aname);
lReport.Add( 'Amount borrowed: $%.2f at %.2f percent over %.1f years.', [amount, pcnt_interest, no_years]);
lReport.Add( '');
total_interest := 0.0;
total_paid := 0.0;
for j := 1 to round(no_years) do
begin
lReport.Add('---------------------------------------------------------------------------');
lReport.Add(' PAYMENT PAYMENT INTEREST BALANCE TOTAL TOTAL');
lReport.Add(' DATE AMOUNT PAYED REMAINING INTEREST PAID');
lReport.Add('---------------------------------------------------------------------------');
// 'xx/xx/xxxx xxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxx
for k := 1 to no_per_year do
begin
year_paid := round(years) + j - 1 ;
month_paid := round(k * fraction + (month - fraction));
if (month_paid > 12) then
begin
year_paid := year_paid + 1;
month_paid := month_paid - 12;
end;
interest_payment := amount * interest / no_per_year;
amount := amount - payment + interest_payment;
total_interest := total_interest + interest_payment;
total_paid := total_paid + payment;
lReport.Add('%.2d/%.2d/%4d %12.2f %12.2f %12.2f %12.2f %12.2f', [
month_paid, day, year_paid, payment, interest_payment,
amount, total_interest, total_paid
]);
paymentDate := EncodeDate(year_paid, month_paid, day);
FBalanceRemainSeries.AddXY(paymentDate, amount);
FTotalInterestSeries.AddXY(paymentDate, total_interest);
FTotalPaidSeries.AddXY(paymentDate, total_paid);
end; // next k
lReport.Add('');
end; // next j
FReportFrame.DisplayReport(lReport);
finally
lReport.Free;
end;
end; end;
function TLoanItFrm.Validate(out AMsg: String; out AControl: TWinControl): Boolean;
procedure TLoanItForm.Reset;
begin
inherited;
NameEdit.Text := '';
MonthEdit.Text := '';
DayEdit.Text := '';
YearEdit.Text := '';
YearsEdit.Text := '';
AmountEdit.Text := '';
InterestEdit.Text := '';
PayPerYrEdit.Text := '';
RepayEdit.Text := '';
end;
function TLoanItForm.Validate(out AMsg: String; out AControl: TWinControl): Boolean;
var var
n: Integer; n: Integer;
x: Double; x: Double;
@ -315,9 +364,6 @@ begin
Result := true; Result := true;
end; end;
initialization
{$I loanitunit.lrs}
end. end.

View File

@ -1817,9 +1817,9 @@ end;
// Menu "Analysis" > "Financial" > "Loan Amortization Schedule" // Menu "Analysis" > "Financial" > "Loan Amortization Schedule"
procedure TOS3MainFrm.MenuItem10Click(Sender: TObject); procedure TOS3MainFrm.MenuItem10Click(Sender: TObject);
begin begin
if LoanItFrm = nil then if LoanItForm = nil then
Application.CreateForm(TLoanItFrm, LoanItFrm); Application.CreateForm(TLoanItForm, LoanItForm);
LoanItFrm.ShowModal; LoanItForm.Show;
end; end;
// Menu "Analysis" > "Nonparametric" > "Cochran Q Test" // Menu "Analysis" > "Nonparametric" > "Cochran Q Test"