-
Notifications
You must be signed in to change notification settings - Fork 0
/
taxcalform.pas
138 lines (112 loc) · 3.02 KB
/
taxcalform.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
unit taxcalform;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
btn1: TButton;
edValue: TEdit;
edVat: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ledGross: TLabeledEdit;
ledGrossFromVat: TLabeledEdit;
ledNet: TLabeledEdit;
ledNetFromVat: TLabeledEdit;
ledVat: TLabeledEdit;
ledVatFromGross: TLabeledEdit;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
pnlgross: TPanel;
pnlgrossfromvat: TPanel;
pnlnet: TPanel;
pnlnetfromvat: TPanel;
pnlvalue: TPanel;
pnlvatamount: TPanel;
pnlvatfromgross: TPanel;
procedure btn1Click(Sender: TObject);
procedure edValueChange(Sender: TObject);
procedure FormShow(Sender: TObject);
private
fVatRate: double;
{ private declarations }
public
property VatRate : double read fVatRate;
constructor Create (const vatValue : double);
function Vat(const netValue : double) : double;
function Gross(const netValue : double) : double;
function Net(const grossValue : double) : double;
function VatFromGross(const grossValue : double) : double;
function NetFromVat(const vatValue : double) : double;
function GrossFromVat(const vatValue : double) : double;
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.btn1Click(Sender: TObject);
var
vc : Tform1;
valueIn : double;
begin
valueIn := StrToFloat(edValue.Text) ;
vc := Tform1.Create(StrToFloat(edVat.Text));
try
ledVat.Text := FormatFloat('.00',vc.Vat(valueIn));
ledGross.Text := FormatFloat('.00',vc.Gross(valueIn));
ledNet.Text := FormatFloat('.00',vc.Net(valueIn));
ledVatFromGross.Text := FormatFloat('.00',vc.VatFromGross(valueIn));
ledNetFromVat.Text := FormatFloat('.00',vc.NetFromVat(valueIn));
ledGrossFromVat.Text := FormatFloat('.00',vc.GrossFromVat(valueIn));
finally
vc.Free;
end;
end;
procedure TForm1.edValueChange(Sender: TObject);
begin
if (edVat.Text <> '') and (edValue.Text <> '')
then
begin
btn1.Click;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
edValue.SetFocus;
end;
constructor TForm1.Create(const vatValue: double);
begin
fVatRate := vatValue;
end;
function TForm1.Vat(const netValue: double): double;
begin
result := VatRate * netValue / 100 ;
end;
function TForm1.Gross(const netValue: double): double;
begin
result := netValue + Vat(netValue);
end;
function TForm1.Net(const grossValue: double): double;
begin
result := 100 / (100 + VatRate) * grossValue;
end;
function TForm1.VatFromGross(const grossValue: double): double;
begin
result := grossValue - Net(grossValue);
end;
function TForm1.NetFromVat(const vatValue: double): double;
begin
result := vatValue * 100 / VatRate;
end;
function TForm1.GrossFromVat(const vatValue: double): double;
begin
result := vatValue + NetFromVat(vatValue);
end;
end.