1 | unit UMainForm;
|
---|
2 |
|
---|
3 | {$mode objfpc}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
|
---|
9 |
|
---|
10 | type
|
---|
11 |
|
---|
12 | { TForm1 }
|
---|
13 |
|
---|
14 | TForm1 = class(TForm)
|
---|
15 | Memo1: TMemo;
|
---|
16 | procedure FormShow(Sender: TObject);
|
---|
17 | private
|
---|
18 | { private declarations }
|
---|
19 | public
|
---|
20 | function CheckVAT(VAT: string): Boolean;
|
---|
21 | end;
|
---|
22 |
|
---|
23 | var
|
---|
24 | Form1: TForm1;
|
---|
25 |
|
---|
26 | implementation
|
---|
27 |
|
---|
28 | {$R *.lfm}
|
---|
29 |
|
---|
30 | { TForm1 }
|
---|
31 |
|
---|
32 | procedure TForm1.FormShow(Sender: TObject);
|
---|
33 | var
|
---|
34 | Source, Dest: TStringList;
|
---|
35 | I: Integer;
|
---|
36 | P: Integer;
|
---|
37 | DestLine: TStringList;
|
---|
38 | Line: TStringList;
|
---|
39 | VAT: string;
|
---|
40 | begin
|
---|
41 | try
|
---|
42 | Source := TStringList.Create;
|
---|
43 | Dest := TStringList.Create;
|
---|
44 | Line := TStringList.Create;
|
---|
45 | DestLine := TStringList.Create;
|
---|
46 |
|
---|
47 | Source.LoadFromFile('..\dodav.csv');
|
---|
48 |
|
---|
49 | DestLine.Add('name');
|
---|
50 | DestLine.Add('address/street');
|
---|
51 | DestLine.Add('address/street2');
|
---|
52 | DestLine.Add('address/city');
|
---|
53 | DestLine.Add('vatin');
|
---|
54 | //DestLine.Add('vat');
|
---|
55 | DestLine.Add('address/zip');
|
---|
56 | //DestLine.Add('address/country_id');
|
---|
57 | DestLine.Add('address/phone');
|
---|
58 | DestLine.Add('address/fax');
|
---|
59 | DestLine.Add('address/name');
|
---|
60 | Dest.Add(DestLine.CommaText);
|
---|
61 |
|
---|
62 | for I := 1 to Source.Count - 1 do begin
|
---|
63 | DestLine.Clear;
|
---|
64 | Line.CommaText := Source[I];
|
---|
65 |
|
---|
66 | //VAT := Trim(Line[8]);
|
---|
67 | //if not CheckVAT(VAT) then VAT := '';
|
---|
68 |
|
---|
69 | DestLine.Add('' + Line[3] + '');
|
---|
70 | DestLine.Add('' + Line[4] + '');
|
---|
71 | DestLine.Add('' + Line[5] + '');
|
---|
72 | DestLine.Add('' + Line[6] + '');
|
---|
73 | DestLine.Add('' + Line[7] + '');
|
---|
74 | //DestLine.Add('' + VAT + '');
|
---|
75 | DestLine.Add('' + Line[14] + '');
|
---|
76 | //DestLine.Add('' + Line[15] + '');
|
---|
77 | DestLine.Add('' + Line[16] + '');
|
---|
78 | DestLine.Add('' + Line[17] + '');
|
---|
79 | DestLine.Add('' + Line[19] + '');
|
---|
80 |
|
---|
81 | Dest.Add(DestLine.CommaText);
|
---|
82 | end;
|
---|
83 | Dest.SaveToFile('..\import.csv');
|
---|
84 | finally
|
---|
85 | Source.Free;
|
---|
86 | Dest.Free;
|
---|
87 | Line.Free;
|
---|
88 | end;
|
---|
89 | end;
|
---|
90 |
|
---|
91 | function TForm1.CheckVAT(VAT: string): Boolean;
|
---|
92 | var
|
---|
93 | VATNum: string;
|
---|
94 | Checksum: Integer;
|
---|
95 | VATChecksum: Integer;
|
---|
96 | P: Integer;
|
---|
97 | begin
|
---|
98 | VATNum := '';
|
---|
99 | Checksum := 0;
|
---|
100 |
|
---|
101 | P := 1;
|
---|
102 | while (P < Length(VAT)) and not ((VAT[P] >= '0') and (VAT[P] <= '9')) do Inc(P);
|
---|
103 | if (P < Length(VAT)) then VATNum := Copy(VAT, P, 255);
|
---|
104 | Memo1.Lines.Add(VAT + ': ' + IntToStr(P) + ': ' + VATNum);
|
---|
105 | VATChecksum := StrToInt(Copy(VATNum, Length(VATNum) - 1, 2));
|
---|
106 | VATNum := Copy(VATNum, 1, Length(VATNum) - 2);
|
---|
107 | if VATNum <> '' then begin
|
---|
108 | for P := 1 to Length(VATNum) do begin
|
---|
109 | if P > 7 then begin
|
---|
110 | Result := False;
|
---|
111 | Break;
|
---|
112 | end;
|
---|
113 | Checksum := Checksum + StrToInt(VATNum[P]) * (9 - P);
|
---|
114 | end;
|
---|
115 | while Checksum >= 0 do Checksum := Checksum - 97;
|
---|
116 | Result := Abs(CheckSum) = VATChecksum;
|
---|
117 | end else Result := False;
|
---|
118 | end;
|
---|
119 |
|
---|
120 | end.
|
---|
121 |
|
---|