-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathglobalvalues.pas
1448 lines (1255 loc) · 38.6 KB
/
globalvalues.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit globalvalues;
interface
uses Forms, Windows, sysutils, Classes, contnrs, dateutils,
comobj, shellapi, ShlObj, FileCtrl, db, jlcommon;
Const
Application_Firm = 'Fuerza Development';
Application_Name = Application_Firm + ' - Torro';
Application_Title = Application_Name + ' Faktura';
GROUP_ALLE = 0;
GROUP_LEVERANDORER = 1;
GROUP_PRODUKTER = 2;
GROUP_KUNDER = 3;
GROUP_FAKTURA = 4;
FAKTURA_IKKEFAKTURERT = 0;
FAKTURA_FAKTURERT = 1;
FAKTURA_KREDITNOTA = 2;
FAKTURA_BETALT = 3;
PREFS_FAKTURAID = 'fakturaid';
PREFS_KUNDEID = 'kundeid';
PREFS_LEVERANDORID = 'leverandorid';
PREFS_PRODUKTID = 'produktid';
PREFS_FIRMA = 'firmanavn';
PREFS_ADRESSE_A = 'firma_adresse_a';
PREFS_ADRESSE_B = 'firma_adresse_b';
PREFS_POSTNR = 'firma_postnummer';
PREFS_STED = 'firma_sted';
PREFS_TELEFON = 'firma_telefon';
PREFS_FAX = 'firma_fax';
PREFS_EMAIL = 'firma_email';
PREFS_WWW = 'firma_web';
PREFS_ORGID = 'firma_orgid';
PREFS_KONTIE = 'firma_kontie';
PREFS_FAKTURATEXT = 'firma_faktura_text';
PREFS_PURRETEXT = 'firma_purring_text';
PREFS_INKASSOTEXT = 'firma_inkasso_text';
PREFS_KREDITTERETEXT = 'firma_kredittere_text';
PREFS_PURREGEBYR = 'firma_purregebyr';
PREFS_RENTESATS = 'firma_rentesats';
PREFS_REFERANSE_NAVN = 'firma_referanse_navn';
PREFS_AVANSE = 'app_avanse_option';
PREFS_MVA = 'app_mva_option';
PREFS_LASTRUN = 'app_run_last';
PREFS_ROWSELECT = 'app_rowselect_option';
PREFS_LASTOMSETTING = 'firma_omsetting';
PREFS_LASTMVA = 'firma_mva';
PREFS_LASTRABATT = 'firma_rabatt';
DEFAULT_FAKTURA_NUMBER = 1001;
DEFAULT_KUNDE_NUMBER = 1001;
DEFAULT_LEVERANDOR_NUMBER = 1001;
DEFAULT_PRODUKT_NUMBER = 1001;
Const
ERR_HEX_FailedReadProperty = 'Failed to read property: %s';
ERR_HEX_FailedWriteProperty = 'Failed to write property: %s';
type
TJLPropertyBag = Class(TObject)
Private
FData: TStringlist;
Function EncodeValue(Value:String):String;
Function DecodeValue(Value:String):String;
Function GetEmpty:Boolean;
Function GetCount:Integer;
Function GetValue(index:Integer):String;
Function BinStreamToString(Stream:TStream):String;
Function BinStringToStream(Value:String):TStream;
Function ConvertToBinString(Value:String):String;
Function ConvertFromBinString(Value:String):String;
Public
Property Empty:Boolean read GetEmpty;
Property Count:Integer read GetCount;
Property Properties[index:Integer]:String read GetValue;
Procedure WriteCurrency(AName:String;Value:Currency);
Function ReadCurrency(AName:String):Currency;
Procedure WriteBoolean(AName:String;Value:Boolean);
Procedure WriteInteger(AName:String;Value:Integer);
Procedure WriteString(AName:String;Value:String);
Procedure WriteDate(AName:String;Value:TDateTime);
Procedure WriteStream(AName:String;Value:TStream);
Function ReadStream(AName:String):TStream;
Function ReadDate(AName:String):TDateTime;
Function ReadInteger(AName:String):Integer;
Function ReadBoolean(AName:String):Boolean;
Function ReadString(AName:String):String;
Function ToString:String;
Procedure SaveToStream(Stream:TStream);
Procedure SaveToFile(Const Filename:String);
Procedure LoadFromFile(Const Filename:String);
Procedure LoadFromStream(Stream:TStream);
//Procedure SaveToRegistry(Key:HKey;Path,KeyName:String);
//Procedure LoadFromRegistry(Key:HKey;Path,KeyName:String);
Procedure AssignTo(Target:TJLPropertyBag);
Procedure Clear;
Constructor Create;Virtual;
Destructor Destroy;Override;
End;
TJLInvoice = Class;
TJLInvoiceItems = Class;
TJLInvoiceItem = Class(TObject)
private
FProduct: String;
FItems: Double;
FPrice: Currency;
FVat: Integer;
FDiscount: Integer;
FExVat: Currency;
FIncVat: Currency;
FUpdating: Integer;
FParent: TJLInvoiceItems;
Protected
Function GetUpdating:Boolean;
Procedure SetCount(Value:Double);
Procedure SetPrice(Value:Currency);
Procedure SetVat(Value:Integer);
Procedure SetDiscount(Value:Integer);
Procedure SetProduct(Value:String);
Function GetVatOnly:Currency;
Public
Property Parent:TJLInvoiceItems read FParent;
Property Product:String read FProduct write SetProduct;
Property Count:Double read FItems write SetCount;
Property ItemPrice:Currency read FPrice write SetPrice;
property Vat:Integer read FVat write SetVat;
Property Discount:Integer read FDiscount write SetDiscount;
Property SumExVat:Currency read FExVat write FExVat;
Property SumIncVat:Currency read FIncVat write FIncVat;
Property SumVatOnly:Currency read GetVatOnly;
Procedure BeginUpdate;
Procedure EndUpdate;
Procedure UpdateFinalFigures;
Function toString:String;
Constructor Create(AOwner:TJLInvoiceItems);virtual;
End;
TJLInvoiceItems = Class(TObject)
Private
FParent: TJLInvoice;
FObjects: TObjectList;
Function GetCount:Integer;
Function GetItem(index:Integer):TJLInvoiceItem;
Public
Property Items[index:Integer]:TJLInvoiceItem read GetItem;default;
Property Count:Integer read GetCount;
Procedure Clear;
Function Add(out Value:TJLInvoiceItem):Boolean;
Function toString:String;
Function CalcVatOnly:Currency;
Function CalcSubTotal(IncVat:Boolean=False):Currency;
Constructor Create(AOwner:TJLInvoice);virtual;
Destructor Destroy;Override;
End;
TJLInvoiceAdresse = Class(TObject)
Private
FNavn: String;
FAddr1: String;
FAddr2: String;
FSted: String;
FStedsNavn: String;
Public
Property Kunde:String read FNavn write FNavn;
property Adresse1:String read FAddr1 write FAddr1;
Property Adresse2:String read FAddr2 write FAddr2;
Property Sted:String read FSted write FSted;
Property Stedsnavn:String read FStedsnavn write FStedsnavn;
Procedure Clear;
Function Validate:Boolean;
Function toString(aHeader:String=''):String;
end;
TJLInvoiceState = (isNotIssued=0,isIssued,isCredited,isPayed);
TJLInvoice = Class(TObject)
Private
FAltered: Integer;
FUpdating: Integer;
FItems: TJLInvoiceItems;
FFaktAddr: TJLInvoiceAdresse;
FMotAddr: TJLInvoiceAdresse;
Fid: Integer;
FFaktDato: TDateTime;
FForfdager: Integer;
FForfallt: Boolean;
FState: TJLInvoiceState;
FReminders: Integer;
FWarnings: Integer;
FDaysOverDue: Integer;
FOnChanged: TNotifyEvent;
FRenteSats: Double;
FGebyr: Currency;
Function GetDueDate:TDateTime;
Protected
Function GetAltered:Boolean;
Function GetUpdating:Boolean;
Procedure SetId(Value:Integer);
Procedure SetDate(Value:TDateTime);
Procedure SetForfallsdager(Value:integer);
Procedure SetForfallt(Value:Boolean);
Procedure SetState(Value:TJLInvoiceState);
Procedure SetReminders(Value:Integer);
Procedure SetWarnings(Value:Integer);
Procedure SetRentesats(Value:Double);
procedure SetGebyr(Value:Currency);
Protected
Procedure SignalInvoiceAltered;virtual;
Public
Property Altered:Boolean read GetAltered;
Property Updating:Boolean read GetUpdating;
Property Reminders:Integer read FReminders write SetReminders;
Property Warnings:Integer read FWarnings write SetWarnings;
Property Id:Integer read FId write SetId;
Property FakturaDato:TDateTime read FFaktDato write SetDate;
Property Forfallsdager:Integer read FForfdager write SetForfallsdager;
Property Forfallt:Boolean read FForfallt write SetForfallt;
Property State:TJLInvoiceState read FState write SetState;
Property Items:TJLInvoiceItems read FItems;
Property FakturaAdresse:TJLInvoiceAdresse read FFaktAddr;
Property MotakerAdresse:TJLInvoiceAdresse read FMotAddr;
Property RenteSats:Double read FRenteSats write SetRenteSats;
Property Gebyr:Currency read FGebyr write SetGebyr;
Property DaysOverdue:Integer read FDaysOverDue;
Property DueDate:TDateTime read GetDueDate;
Function Validate:Boolean;
Function toString:String;virtual;
Procedure BeginUpdate;
Procedure EndUpdate;
Procedure Update;
Procedure Clear;
Constructor Create;virtual;
Destructor Destroy;Override;
Published
Property OnAltered:TNotifyEvent
read FOnChanged write FOnChanged;
End;
Const
CHARSET_NUMERIC = '0123456789'+#8;
ResourceString
TEXT_DATASTORENOTACTIVE = 'Et register må være åpnet for at denne handlingen skal utføres.';
TEXT_DATATABLENOTREADY = 'Kan ikke utføre funksjonen. %s tabellen er ikke klar.';
//TEXT_PIRACY = 'Kjære kunde.'#13#13'Det er funnet et program som brukes til å knekke'#13'koden på lisenser ulovelig aktiv i systemet.'#13#13'Programmet vil nå avsluttes.';
//TEXT_LICENSEEXPIRED = 'Kjære kunde.'#13#13'Lisensen for denne utgaven av programmet er'#13'desverre ikke lenger gyldig.'#13#13'Som kunde hos JuraSoft skal du motta regelmessige'#13'oppdateringer i henhold til din lisensavtale.'#13#13'Du vil nå kun ha muligheten til å lese data.';
//TEXT_WARNING = 'Kjære kunde.'#13#13'Det er nå under en måned igjen av tiden hvor'#13'du ikke behøver den obligatoriske serviceavtalen.'#13#13'Hvis du ikke registrerer din serviceavtale'#13'innen %s dager, vil deler av programmet'#13'slutte å fungere.';
TEXT_FakturaIkkeFakturert = 'Fakturaen er ikke fakturert';
TEXT_FakturaErBetalt = 'Fakturaen er betalt';
TEXT_FakturaForandreStatus = 'Er du sikker du vil forandre status på denne fakturaen?'#13#13'Forandre fra %s til %s?';
TEXT_FakturaErKreditert = 'Faktura er kreditert';
TEXT_FakturaIkkeForfallt = 'Fakturaen er ikke forfallt';
TEXT_DataError = 'En feil oppstod i datamodulen, funksjon %s';
TEXT_FAKTURASTATE = 'Kan ikke forandre faktura status:'#13;
TEXT_PURREFEIL = 'Kan ikke utføre purring:'#13;
TEXT_QUERYPURRING = 'Er du sikker på at du vil generere purringen?'#13#13'Dette er purring %d.';
TEXT_QUERYINKASSO = 'Er du sikker på at du vil generere inkasso varsel?'#13#13'Dette er varsel %d.';
TEXT_QUERYDELETELEVERANDOR = 'Du kan ikke slette en leverandør hvor det er'#13'et eller flere produkter registrert!';
TEXT_SLETTELEVERANDOR = 'Slette leverandør?';
TEXT_FAKTURA = 'Faktura';
TEXT_PURRING = 'Purring';
TEXT_VARSEL = 'Varsel';
TEXT_BETALING = 'Betale faktura';
TEXT_KANIKKEBETALE = 'Det eksisterer en kreditnota for denne fakturaen!'#13'Kan ikke sette status til betalt.';
//TEXT_RAPTOR = 'Raptor faktura';
TEXT_KREDITTNOTA = 'Kredittnota';
TEXT_QUERYKREDITTNOTA = 'Er du sikker du vil kredittere denne fakturaen?';
TEXT_KREDITTNOTAREGISTRERT = 'Det eksisterer allerede en kredittnota for denne fakturaen!';
DIALOG_KanIkkeOpenDbMappe = 'Det oppstod problemer med å åpne database mappe:'+#13+'%s';
DIALOG_FANTIKKEFAKTURATITTEL = 'Ingen faktura funnet';
DIALOG_FANTIKKEFAKTURA = 'Fant ingen faktura i systemet som'#13'har et slikt Id nummer.'#13#10'Husk at du også kan bruke søke funksjonen.';
DIALOG_FANTIKKEKUNDETITTEL = 'Ingen kunde funnet';
DIALOG_FANTIKKEKUNDE = 'Fant ingen kunde i systemet som'#13'har et slikt Id nummer.'#13#10'Husk at du også kan bruke søke funksjonen.';
DIALOG_FANTIKKEPRODUKTTITTEL = 'Ingen produkter funnet';
DIALOG_FANTIKKEPRODUKT = 'Fant ingen produkter i systemet som'#13'har et slikt Id nummer.'#13#10'Husk at du også kan bruke søke funksjonen.';
DIALOG_FANTIKKELEVERANDORTITTEL = 'Ingen leverandør funnet';
DIALOG_FANTIKKELEVERANDOR = 'Fant ingen leverandør i systemet som'#13'har et slikt Id nummer.'#13#10'Husk at du også kan bruke søke funksjonen.';
DIALOG_LEVERANDOR_TOPIC = 'leverandør';
DIALOG_LEVERANDOR_TITLEAppend = 'Ny leverandør';
DIALOG_LEVERANDOR_TITLEEdit = 'Redigere leverandør';
DIALOG_PRODUKT_TOPIC = 'produkt';
DIALOG_PRODUKT_TITLEAppend = 'Nytt produkt';
DIALOG_PRODUKT_TITLEEdit = 'Redigere produkt';
DIALOG_KUNDE_TOPIC = 'kunde';
DIALOG_KUNDE_TITLEAppend = 'Ny kunde';
DIALOG_KUNDE_TITLEEdit = 'Redigere kunde';
DIALOG_FAKTURA_TOPIC = 'faktura';
DIALOG_FAKTURA_TITLEAppend = 'Ny faktura';
DIALOG_FAKTURA_TITLEEdit = 'Redigere faktura';
DIALOG_KUNDEGRUPPE_TOPIC = 'kunde gruppe';
DIALOG_KUNDEGRUPPE_TITLEAppend = 'Ny kunde gruppe';
DIALOG_KUNDEGRUPPE_TITLEEdit = 'Redigere kunde gruppe';
CNT_DATASTORE_MESSAGE_ANALYZINGDB
= 'Analyserer database..';
CNT_DATASTORE_MESSAGE_NOINVOICETOPROCESS
='Ingen faktura å behandle';
CNT_DATASTORE_MESSAGE_NRINVOICEDPROCESSED
='%d faktura behandlet';
CNT_DATASTORE_ERROR_NOTDELETECUSTOMERGROUP
='Denne kundegruppen kan ikke slettes';
Type
//TAppState = Set of (stApplication);
TAppRecordMode = (arAppend,arEdit);
{ function IsLeapYear( nYear: Integer ): Boolean;
function MonthDays( nMonth, nYear: Integer ): Integer;
function WeekOfYear( dDate: TDateTime ): Integer; }
//function DaysBetween(const ANow, AThen: TDateTime): Integer;
Function StatusToStr(Status:Integer):String;
function StatusToPrintStr(Status:Integer):String;
Procedure ErrorDialog(AForm,AName,ACause:String);
function GetMyDocumentsPath: string;
function GetAppDataPath: string;
Function GetPathForSystem:String;
Function GetPathForDatabases:String;
type
TPercent = 1..100;
Function PercentOf(PCent:TPercent;Value:Double):Double;
var
FFindGroup: Integer;
FFindId: Integer;
FAvanser: Array[0..3] of Currency;
FHeaders: Array[GROUP_ALLE..GROUP_FAKTURA] of String;
FHeaderNames: Array[GROUP_LEVERANDORER..GROUP_FAKTURA] of String;
{ Const
MVA_VALUES: Array[0..3] of Integer = (25,14,8,0); }
implementation
uses data;
var
_SeekCharset: String;
Function PercentOf(PCent:TPercent;Value:Double):Double;
Begin
result:=( (Value * PCent) / 100 );
end;
//###############################################################
// TJLInvoice
//###############################################################
Constructor TJLInvoice.Create;
Begin
inherited Create;
FItems:=TJLInvoiceItems.Create(self);
FFaktAddr:=TJLInvoiceAdresse.Create;
FMotAddr:=TJLInvoiceAdresse.Create;
end;
Destructor TJLInvoice.Destroy;
Begin
FreeAndNIL(FItems);
FreeAndNIL(FFaktAddr);
FreeAndNIL(FMotAddr);
inherited;
end;
Function TJLInvoice.GetDueDate:TDateTime;
Begin
result:=dateutils.IncDay(FFaktDato,FForfdager);
end;
Procedure TJLInvoice.Update;
var
FDueDate: TDateTime;
Begin
FDaysOverDue:=0;
FForfallt:=False;
(* Check if this invoice is overdue for payment *)
if not dateutils.WithinPastDays(Now,FFaktDato,FForfdager) then
Begin
(* Mark as forclosed *)
FForfallt:=True;
(* Calculate last day of credit *)
FDueDate:=dateutils.IncDay(FFaktDato,FForfdager);
(* Calculate days overdue *)
FDaysOverDue:=dateutils.DaysBetween(Now,FDueDate);
(* Calculate interest rates for overdue time *)
If FRenteSats>0 then
Begin
FGebyr:=PercentOf(TPercent(trunc(FRenteSats)),Items.CalcSubTotal());
end;
end;
end;
Function TJLInvoice.toString:String;
Begin
result:=
'ID:' + IntToStr(self.FId)
+ #13 + #13 + FFaktAddr.toString('Fakturert til:')
+ #13 + #13 + self.FMotAddr.toString('Sendt til:')
+ #13 + #13 + FItems.toString
+ #13 + #13 + CurrToStr(FItems.CalcSubTotal());
end;
Function TJLInvoice.GetAltered:Boolean;
Begin
result:=FAltered>0;
end;
Function TJLInvoice.GetUpdating:Boolean;
Begin
result:=FUpdating>0;
end;
Procedure TJLInvoice.BeginUpdate;
Begin
inc(FUpdating);
end;
Procedure TJLInvoice.EndUpdate;
Begin
if FUpdating>0 then
Begin
dec(FUpdating);
If FUpdating=0 then
Begin
Update;
SignalInvoiceAltered;
end;
end;
end;
Procedure TJLInvoice.Clear;
Begin
FAltered:=0;
FUpdating:=0;
FFaktAddr.Clear;
FMotAddr.Clear;
FItems.clear;
end;
Function TJLInvoice.Validate:Boolean;
Begin
result:=FFaktAddr.Validate
and FMotAddr.Validate
and (FItems.Count>0);
end;
Procedure TJLInvoice.SignalInvoiceAltered;
Begin
If (FAltered>0)
and assigned(FOnChanged) then
FOnChanged(self);
end;
Procedure TJLInvoice.SetReminders(Value:Integer);
Begin
if Value<>FReminders then
Begin
FReminders:=Value;
if not GetUpdating then
inc(FAltered);
end;
end;
Procedure TJLInvoice.SetWarnings(Value:Integer);
Begin
if Value<>FWarnings then
Begin
FWarnings:=Value;
if not GetUpdating then
inc(FAltered);
end;
end;
Procedure TJLInvoice.SetState(Value:TJLInvoiceState);
Begin
if Value<>FState then
begin
FState:=Value;
if not GetUpdating then
inc(FAltered);
end;
end;
Procedure TJLInvoice.SetId(Value:Integer);
Begin
if Value<>Fid then
Begin
FId:=Value;
if not GetUpdating then
inc(FAltered);
end;
end;
Procedure TJLInvoice.SetDate(Value:TDateTime);
Begin
if Value<>FFaktDato then
Begin
FFaktDato:=Value;
if not GetUpdating then
inc(FAltered);
end;
end;
Procedure TJLInvoice.SetForfallsdager(Value:integer);
Begin
if Value<>FForfdager then
Begin
FForfdager:=Value;
if not GetUpdating then
inc(FAltered);
end;
end;
Procedure TJLInvoice.SetForfallt(Value:Boolean);
Begin
if Value<>FForfallt then
Begin
FForfallt:=Value;
if not GetUpdating then
inc(FAltered);
end;
end;
Procedure TJLInvoice.SetRentesats(Value:Double);
Begin
if Value<>FRenteSats then
Begin
FRentesats:=Value;
if not GetUpdating then
inc(FAltered);
end;
end;
procedure TJLInvoice.SetGebyr(Value:Currency);
Begin
if Value<>FGebyr then
Begin
FGebyr:=Value;
if not GetUpdating then
inc(FAltered);
end;
end;
//###############################################################
// TJLInvoiceAdresse
//###############################################################
Procedure TJLInvoiceAdresse.Clear;
Begin
FNavn:='';
FAddr1:='';
FAddr2:='';
FSted:='';
FStedsNavn:='';
end;
Function TJLInvoiceAdresse.Validate:Boolean;
Begin
result:=(length(trim(FNavn))>0)
and (length(trim(FAddr1))>0)
and (length(trim(FAddr2))>0)
and (length(trim(FSted))>0)
and (length(trim(FStedsnavn))>0);
end;
Function TJLInvoiceAdresse.toString(aHeader:String=''):String;
Begin
If Length(aHeader)>0 then
Result:=AHeader + #13 else
result:='';
Result:=Result + FNavn + #13;
If (length(FAddr1)>0)
and (FAddr1<>'-') then
Result:=Result + FAddr1 + #13;
If (length(FAddr2)>0)
and (FAddr2<>'-') then
Result:=Result + FAddr2 + #13;
result:=result + FSted + ' ' + FStedsnavn;
end;
//###############################################################
// TJLInvoiceItems
//###############################################################
Constructor TJLInvoiceItems.Create(AOwner:TJLInvoice);
Begin
inherited Create;
FParent:=AOwner;
FObjects:=TObjectlist.Create(True);
end;
Destructor TJLInvoiceItems.Destroy;
Begin
FObjects.free;
inherited;
end;
Procedure TJLInvoiceItems.Clear;
Begin
FObjects.Clear;
end;
Function TJLInvoiceItems.GetCount:Integer;
Begin
result:=FObjects.Count;
end;
Function TJLInvoiceItems.toString:String;
var
x: Integer;
Begin
result:='';
for x:=1 to FObjects.Count do
result:=Result + Items[x-1].toString;
end;
Function TJLInvoiceItems.CalcVatOnly:Currency;
var
x: Integer;
FItem: TJLInvoiceItem;
Begin
result:=0;
for x:=1 to FObjects.Count do
Begin
FItem:=Items[x-1];
result:=result + FItem.GetVatOnly
end;
end;
Function TJLInvoiceItems.CalcSubTotal(IncVat:Boolean=False):Currency;
var
x: Integer;
FItem: TJLInvoiceItem;
Begin
result:=0;
for x:=1 to FObjects.Count do
Begin
FItem:=Items[x-1];
FItem.UpdateFinalFigures;
if IncVat then
Result:=Result + FItem.SumIncVat else
Result:=Result + FItem.SumExVat;
end;
end;
Function TJLInvoiceItems.GetItem(index:Integer):TJLInvoiceItem;
Begin
result:=TJLInvoiceItem(FObjects[index]);
end;
Function TJLInvoiceItems.Add(out Value:TJLInvoiceItem):Boolean;
Begin
try
Value:=TJLInvoiceItem.Create(self);
except
on e: exception do
Begin
result:=False;
exit;
end;
end;
try
FObjects.Add(Value);
except
on e: exception do
Begin
FreeAndNIL(Value);
result:=False;
exit;
end;
end;
result:=True;
end;
//###############################################################
// TJLInvoiceItem
//###############################################################
Constructor TJLInvoiceItem.Create(AOwner:TJLInvoiceItems);
Begin
inherited Create;
if AOwner<>NIL then
FParent:=AOwner else
Raise Exception.Create('Invoiceitem parent cannot be NIL error');
end;
Function TJLInvoiceItem.GetUpdating:Boolean;
Begin
result:=FUpdating>0;
end;
Function TJLInvoiceItem.toString:String;
Begin
UpdateFinalFigures;
result:='[' + FProduct + ']'
+ ' x ' + FloatToStr(FItems) + ' @ '
+ CurrToStr(FPrice) + ' (' + IntToStr(Vat) + '%) '
+ ' = ' + CurrToStr(FIncVat) + ' (' + CurrToStr(FExVat) + ')' + #13;
end;
Procedure TJLInvoiceItem.BeginUpdate;
Begin
inc(FUpdating);
end;
Procedure TJLInvoiceItem.EndUpdate;
Begin
if FUpdating>0 then
Begin
dec(FUpdating);
If FUpdating=0 then
UpdateFinalFigures;
end;
end;
Procedure TJLInvoiceItem.SetCount(Value:Double);
Begin
if Value<>FItems then
Begin
FItems:=Value;
if not GetUpdating then
UpdateFinalFigures;
end;
end;
Procedure TJLInvoiceItem.SetPrice(Value:Currency);
Begin
if Value<>FPrice then
Begin
FPrice:=Value;
if not GetUpdating then
UpdateFinalFigures;
end;
end;
Procedure TJLInvoiceItem.SetVat(Value:Integer);
Begin
if Value<>FVat then
Begin
FVat:=Value;
if not GetUpdating then
UpdateFinalFigures;
end;
end;
Procedure TJLInvoiceItem.SetDiscount(Value:Integer);
Begin
If Value<>FDiscount then
Begin
FDiscount:=Value;
if not GetUpdating then
UpdateFinalFigures;
end;
end;
Procedure TJLInvoiceItem.SetProduct(Value:String);
Begin
if Value<>FProduct then
Begin
FProduct:=Value;
if not GetUpdating then
UpdateFinalFigures;
end;
end;
Function TJLInvoiceItem.GetVatOnly:Currency;
Begin
result:=FIncVat - FExVat;
end;
Procedure TJLInvoiceItem.UpdateFinalFigures;
Procedure FlushTotals;
begin
FExVat:=0;
FIncVat:=0;
end;
var
FTemp: Currency;
FWork: Currency;
Begin
If FItems>0 then
Begin
If FPrice>0 then
Begin
(* Calc total *)
FTemp:=FPrice * Count;
(* Subtract any discounts involved *)
If FDiscount>0 then
Begin
FWork:=PercentOf(FDiscount,FTemp);
FTemp:=FTemp - FWork;
end;
(* Set Price EX vat *)
FExVat:=FTemp;
(* Add Vat to the price *)
If FVat>0 then
Begin
FWork:=PercentOf(FVat,FTemp);
FTemp:=FTemp + FWork;
end;
(* Set Price INC vat *)
FIncVat:=FTemp;
end else
FlushTotals;
end else
FlushTotals;
end;
//###############################################################
// Helper Functions
//###############################################################
Function ExceptFormat(Instance:TObject;Source,Cause:AnsiString):String;
Begin
result:=#13 + 'Class [' + Instance.ClassName + '] threw exception:'#13;
result:=Result + 'Source: ' + source + #13;
result:=result + 'Cause: ' + cause + #13 + #13;
End;
//###########################################################################
// TJLPropertyBag
//###########################################################################
Constructor TJLPropertyBag.Create;
begin
inherited;
FData:=TStringList.Create;
end;
Destructor TJLPropertyBag.Destroy;
begin
FData.free;
inherited;
end;
Function TJLPropertyBag.ConvertToBinString(Value:String):String;
var
x: Integer;
Begin
result:='';
for x:=1 to length(Value) do
result:=result + IntToHex(Byte(Value[x]),2);
end;
Function TJLPropertyBag.ConvertFromBinString(Value:String):String;
var
x: Integer;
FSeg: String;
Begin
result:='';
x:=1;
while x<length(value) do
begin
FSeg:=Copy(Value,x,2);
inc(x,2);
result:=result + chr(StrToInt('$' + FSeg));
end;
end;
Function TJLPropertyBag.BinStreamToString(Stream:TStream):String;
var
x: Integer;
FData: Char;
Begin
Stream.seek(0,0);
for x:=1 to Stream.Size do
Begin
Stream.Read(PChar(@FData)^,1);
result:=result + IntToHex(byte(FData),2);
end;
end;
Function TJLPropertyBag.BinStringToStream(Value:String):TStream;
var
x: Integer;
FData: Char;
Begin
result:=TMemoryStream.Create;
x:=1;
while x<Length(Value) do
Begin
FData:=chr(StrToInt('$' + copy(value,x,2)));
result.write(pointer(@FData)^,1);
inc(x,2);
end;
result.seek(0,0);
end;
Procedure TJLPropertyBag.WriteDate(AName:String;Value:TDateTime);
Begin
try
FData.Values[AName]:=EncodeValue(DateToStr(Value));
except
on e: exception do
raise Exception.CreateFmt('Failed to encode data [%s]',[Value]);
end;
end;
Procedure TJLPropertyBag.WriteStream(AName:String;Value:TStream);
Begin
try
FData.Values[AName]:=BinStreamToString(Value);
except
on e: exception do
Raise Exception.CreateFmt('Failed to encode data [%s]',[value]);
end;
end;
Function TJLPropertyBag.ReadStream(AName:String):TStream;
Begin
try
result:=BinStringToStream(FData.Values[AName]);
except
on e: exception do
Raise Exception.CreateFmt('Failed to decode data [%s]',[AName]);
end;
end;
Function TJLPropertyBag.ReadDate(AName:String):TDateTime;
Begin
try
result:=StrToDate(DecodeValue(FData.Values[AName]));
except
on e: exception do
Raise Exception.CreateFmt('Failed to decode data [%s]',[AName]);
end;
end;
Procedure TJLPropertyBag.LoadFromFile(Const Filename:String);
Begin
FData.LoadFromFile(filename);
end;
Procedure TJLPropertyBag.LoadFromStream(Stream:TStream);
Begin
FData.LoadFromStream(stream);
end;
{Procedure TJLPropertyBag.SaveToRegistry(Key:HKey;Path,KeyName:String);
var