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>
<Filename Value="forms\analysis\financial\loanitunit.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="LoanItFrm"/>
<ComponentName Value="LoanItForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="LoanItUnit"/>

View File

@ -1,431 +1,368 @@
object LoanItFrm: TLoanItFrm
inherited LoanItForm: TLoanItForm
Left = 310
Height = 377
Height = 406
Top = 131
Width = 353
Width = 723
HelpType = htKeyword
HelpKeyword = 'html/LoanAmortizationSchedule.htm'
AutoSize = True
BorderStyle = bsDialog
Caption = 'Loan Calculation and Amortization'
ClientHeight = 377
ClientWidth = 353
OnActivate = FormActivate
OnShow = FormShow
Position = poMainFormCenter
LCLVersion = '2.1.0.0'
object Label1: TLabel
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
object Label2: TLabel
AnchorSideLeft.Control = Owner
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
object Label3: TLabel
AnchorSideTop.Control = YearsEdit
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
object Label4: TLabel
AnchorSideTop.Control = PayPerYrEdit
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
object Label5: TLabel
AnchorSideTop.Control = RePayEdit
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
object Label6: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = NameEdit
AnchorSideTop.Side = asrCenter
Left = 24
Height = 15
Top = 12
Width = 65
BorderSpacing.Left = 24
Caption = 'Your Name: '
ParentColor = False
end
object AmountEdit: TEdit
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.Side = asrBottom
AnchorSideTop.Control = Owner
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 97
Height = 23
Top = 8
Width = 232
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 24
TabOrder = 0
Text = 'NameEdit'
end
object PrintChk: TCheckBox
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
AnchorSideRight.Control = NameEdit
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Panel1
AnchorSideBottom.Side = asrBottom
Left = 294
Height = 25
Top = 58
Width = 35
Anchors = [akRight, akBottom]
AutoSize = True
Caption = '...'
OnClick = CalendarBtnClick
TabOrder = 2
end
object Panel1: TPanel
AnchorSideTop.Control = NameEdit
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = CalendarBtn
Left = 30
Height = 40
Top = 43
Width = 260
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Left = 24
BorderSpacing.Top = 12
BorderSpacing.Right = 4
BevelOuter = bvNone
ChildSizing.HorizontalSpacing = 12
ChildSizing.ControlsPerLine = 1
ClientHeight = 40
ClientWidth = 260
TabOrder = 1
object MonthLabel: TLabel
AnchorSideLeft.Control = Panel1
ClientHeight = 406
ClientWidth = 723
inherited ParamsPanel: TPanel
Height = 390
ClientHeight = 390
inherited CloseBtn: TButton
Top = 365
end
inherited ComputeBtn: TButton
Top = 365
end
inherited ResetBtn: TButton
Top = 365
end
inherited HelpBtn: TButton
Top = 365
end
inherited ButtonBevel: TBevel
Top = 349
end
object Label6: TLabel[5]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = NameEdit
AnchorSideTop.Side = asrCenter
Left = 24
Height = 15
Top = 4
Width = 65
BorderSpacing.Left = 24
Caption = 'Your Name: '
ParentColor = False
end
object NameEdit: TEdit[6]
AnchorSideLeft.Control = Label6
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ParamsPanel
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
Left = 97
Height = 23
Top = 0
Width = 194
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 8
TabOrder = 4
Text = 'NameEdit'
end
object CalendarBtn: TButton[7]
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = NameEdit
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Panel1
AnchorSideBottom.Side = asrBottom
Left = 256
Height = 25
Top = 50
Width = 35
Anchors = [akRight, akBottom]
AutoSize = True
Caption = '...'
OnClick = CalendarBtnClick
TabOrder = 5
end
object Panel1: TPanel[8]
AnchorSideTop.Control = NameEdit
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = CalendarBtn
Left = -8
Height = 40
Top = 35
Width = 260
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Left = 24
BorderSpacing.Top = 12
BorderSpacing.Right = 4
BevelOuter = bvNone
ChildSizing.HorizontalSpacing = 12
ChildSizing.ControlsPerLine = 1
ClientHeight = 40
ClientWidth = 260
TabOrder = 6
object MonthLabel: TLabel
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Panel1
AnchorSideRight.Side = asrBottom
Left = 0
Height = 15
Top = 0
Width = 98
Caption = 'Current Month No'
ParentColor = False
end
object DayLabel: TLabel
AnchorSideLeft.Control = MonthLabel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideRight.Side = asrBottom
Left = 110
Height = 15
Top = 0
Width = 73
Caption = 'Day of Month'
ParentColor = False
end
object YearLabel: TLabel
AnchorSideLeft.Control = DayLabel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
AnchorSideRight.Side = asrBottom
Left = 195
Height = 15
Top = 0
Width = 65
Caption = 'Current Year'
ParentColor = False
end
object MonthEdit: TEdit
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = MonthLabel
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = MonthLabel
AnchorSideRight.Side = asrBottom
Left = 38
Height = 23
Top = 17
Width = 60
Alignment = taRightJustify
Anchors = [akTop, akRight]
BorderSpacing.Top = 2
TabOrder = 0
Text = 'MonthEdit'
end
object DayEdit: TEdit
AnchorSideLeft.Control = DayLabel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = DayLabel
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
Left = 116
Height = 23
Top = 17
Width = 60
Alignment = taRightJustify
BorderSpacing.Top = 2
TabOrder = 1
Text = 'DayEdit'
end
object YearEdit: TEdit
AnchorSideLeft.Control = YearLabel
AnchorSideTop.Control = YearLabel
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
Left = 195
Height = 23
Top = 17
Width = 60
Alignment = taRightJustify
BorderSpacing.Top = 2
TabOrder = 2
Text = 'YearEdit'
end
end
object Bevel2: TBevel[9]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = Panel1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
Left = 0
Height = 15
Top = 0
Width = 98
Caption = 'Current Month No'
ParentColor = False
Height = 8
Top = 87
Width = 291
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 12
Shape = bsBottomLine
end
object DayLabel: TLabel
AnchorSideLeft.Control = MonthLabel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
object Label1: TLabel[10]
AnchorSideTop.Control = AmountEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom
Left = 110
Left = 103
Height = 15
Top = 0
Width = 73
Caption = 'Day of Month'
Top = 115
Width = 93
Anchors = [akTop, akRight]
BorderSpacing.Left = 8
Caption = 'Principal Amount'
ParentColor = False
end
object YearLabel: TLabel
AnchorSideLeft.Control = DayLabel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
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 = 195
Left = 59
Height = 15
Top = 0
Width = 65
Caption = 'Current Year'
Top = 181
Width = 137
Anchors = [akTop, akRight]
BorderSpacing.Left = 8
Caption = 'Number of Years to Repay'
ParentColor = False
end
object MonthEdit: TEdit
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = MonthLabel
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = MonthLabel
object Label4: TLabel[13]
AnchorSideTop.Control = PayPerYrEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom
Left = 38
Height = 23
Top = 17
Width = 60
Alignment = taRightJustify
Height = 15
Top = 208
Width = 158
Anchors = [akTop, akRight]
BorderSpacing.Top = 2
TabOrder = 0
Text = 'MonthEdit'
BorderSpacing.Left = 8
Caption = 'Number of Payments Per Year'
ParentColor = False
end
object DayEdit: TEdit
AnchorSideLeft.Control = DayLabel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = DayLabel
AnchorSideTop.Side = asrBottom
object Label5: TLabel[14]
AnchorSideTop.Control = RePayEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom
Left = 116
Height = 23
Top = 17
Width = 60
Alignment = taRightJustify
BorderSpacing.Top = 2
TabOrder = 1
Text = 'DayEdit'
Left = 149
Height = 15
Top = 251
Width = 47
Anchors = [akTop, akRight]
BorderSpacing.Left = 8
Caption = 'Payment'
ParentColor = False
end
object YearEdit: TEdit
AnchorSideLeft.Control = YearLabel
AnchorSideTop.Control = YearLabel
object AmountEdit: TEdit[15]
AnchorSideLeft.Control = InterestEdit
AnchorSideTop.Control = Bevel2
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = NameEdit
AnchorSideRight.Side = asrBottom
Left = 195
Left = 204
Height = 23
Top = 17
Width = 60
Top = 111
Width = 87
Alignment = taRightJustify
BorderSpacing.Top = 2
TabOrder = 2
Text = 'YearEdit'
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]
BorderSpacing.Top = 4
Shape = bsBottomLine
end
end
object Bevel2: TBevel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Panel1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 24
Height = 8
Top = 95
Width = 305
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 24
BorderSpacing.Top = 12
BorderSpacing.Right = 24
Shape = bsBottomLine
inherited ParamsSplitter: TSplitter
Height = 406
end
object Bevel4: TBevel
AnchorSideLeft.Control = Label5
AnchorSideTop.Control = PayPerYrEdit
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 149
Height = 8
Top = 239
Width = 180
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4
BorderSpacing.Right = 24
Shape = bsBottomLine
inherited PageControl: TPageControl
Height = 390
Width = 403
end
object CalendarDialog1: TCalendarDialog
object CalendarDialog1: TCalendarDialog[3]
Date = 43890
OKCaption = '&OK'
CancelCaption = 'Cancel'
Left = 40
Top = 312
Left = 56
Top = 264
end
end

View File

@ -5,21 +5,20 @@ unit LoanItUnit;
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls, ExtDlgs;
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls, ExtDlgs, ComCtrls, TACustomSeries, TAIntervalSources,
ChartFrameUnit, BasicStatsReportAndChartFormUnit;
type
{ TLoanItFrm }
{ TLoanItForm }
TLoanItFrm = class(TForm)
Bevel1: TBevel;
TLoanItForm = class(TBasicStatsReportAndChartForm)
Bevel2: TBevel;
Bevel4: TBevel;
CalendarBtn: TButton;
CalendarDialog1: TCalendarDialog;
Panel1: TPanel;
PrintChk: TCheckBox;
DayEdit: TEdit;
YearEdit: TEdit;
MonthEdit: TEdit;
@ -28,9 +27,6 @@ type
YearLabel: TLabel;
NameEdit: TEdit;
Label6: TLabel;
ResetBtn: TButton;
AmortizeBtn: TButton;
CloseBtn: TButton;
AmountEdit: TEdit;
InterestEdit: TEdit;
YearsEdit: TEdit;
@ -41,131 +37,99 @@ type
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
procedure AmortizeBtnClick(Sender: TObject);
procedure CalendarBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
private
{ private declarations }
function Validate(out AMsg: String; out AControl: TWinControl): boolean;
FBalanceRemainSeries: TChartSeries;
FTotalInterestSeries: TChartSeries;
FTotalPaidSeries: TChartSeries;
protected
procedure AdjustConstraints; override;
procedure Compute; override;
function Validate(out AMsg: String; out AControl: TWinControl): boolean; override;
public
{ public declarations }
constructor Create(AOwner: TComponent); override;
procedure Reset; override;
end;
var
LoanItFrm: TLoanItFrm;
LoanItForm: TLoanItForm;
implementation
{$R *.lfm}
uses
Math, DateUtils, OutputUnit;
Math, DateUtils,
TAChartUtils, TALegend, TASeries;
{ TLoanItFrm }
{ TLoanItForm }
procedure TLoanItFrm.ResetBtnClick(Sender: TObject);
constructor TLoanItForm.Create(AOwner: TComponent);
begin
NameEdit.Text := '';
MonthEdit.Text := '';
DayEdit.Text := '';
YearEdit.Text := '';
YearsEdit.Text := '';
AmountEdit.Text := '';
InterestEdit.Text := '';
PayPerYrEdit.Text := '';
RepayEdit.Text := '';
end;
inherited;
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: 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;
FBalanceRemainSeries := TLineSeries.Create(FChartFrame);
with TLineSeries(FBalanceRemainSeries) do
begin
LinePen.Color := DATA_COLORS[0];
LinePen.Width := 2;
Title := 'Remaining balance';
end;
FChartFrame.Chart.AddSeries(FBalanceRemainSeries);
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;
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;
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;
procedure TLoanItFrm.CalendarBtnClick(Sender: TObject);
procedure TLoanItForm.AdjustConstraints;
begin
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;
procedure TLoanItForm.CalendarBtnClick(Sender: TObject);
var
d: TDate;
dy, mn, yr: Integer;
@ -186,23 +150,108 @@ begin
end;
end;
procedure TLoanItFrm.FormActivate(Sender: TObject);
procedure TLoanItForm.Compute;
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
w := MaxValue([ResetBtn.Width, AmortizeBtn.Width, CloseBtn.Width]);
ResetBtn.Constraints.MinWidth := w;
AmortizeBtn.Constraints.MinWidth := w;
CloseBtn.Constraints.MinWidth := w;
{
w := DayEdit.Width;
DayEdit.Constraints.MaxWidth := w;
MonthEdit.Constraints.MaxWidth := w;
YearEdit.Constraints.MaxWidth := w;
}
FBalanceRemainSeries.Clear;
FTotalInterestSeries.Clear;
FTotalPaidSeries.Clear;
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;
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;
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
n: Integer;
x: Double;
@ -315,9 +364,6 @@ begin
Result := true;
end;
initialization
{$I loanitunit.lrs}
end.

View File

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