@@ -32,6 +32,27 @@ function xml2pdfParse($xmlString) { // parcurge un XML eFactură și extrage câ
32
32
'TR ' =>'Teleorman ' ,'TM ' =>'Timis ' ,'TL ' =>'Tulcea ' ,'VL ' =>'Valcea ' ,'VS ' =>'Vaslui ' ,'VN ' =>'Vrancea '
33
33
);
34
34
35
+ // cele mai comune tipuri de documente, instrumente de plată și unități de măsură, la restul se afișează doar codul
36
+
37
+ $ tipuriDocument =array ('- ' =>'Nedefinit ' ,'380 ' =>'Factură ' ,'751 ' =>'Factură - informații în scopuri contabile ' );
38
+ $ instrumentePlata =array ('1 ' =>'Nespecificat ' ,'10 ' =>'Numerar ' ,'42 ' =>'Ordin de plată ' ,'48 ' =>'Card bancar ' ,'54 ' =>'Card de credit ' ,'55 ' =>'Card de debit ' ,'68 ' =>'Plata online ' ,'ZZZ ' =>'Instrument agreat ' );
39
+ $ unitati =array (
40
+ 'C62 ' =>'unitate ' ,
41
+ 'EA ' =>'unitate ' ,
42
+ 'GRM ' =>'gr. ' ,
43
+ 'H87 ' =>'buc. ' ,
44
+ 'HUR ' =>'oră ' ,
45
+ 'KGM ' =>'kg. ' ,
46
+ 'KWH ' =>'kw. oră ' ,
47
+ 'M4 ' =>'val. monetară ' ,
48
+ 'MON ' =>'lună ' ,
49
+ 'MTQ ' =>'metru cub ' ,
50
+ 'MTR ' =>'metru ' ,
51
+ 'SET ' =>'set ' ,
52
+ 'XBE ' =>'pachet ' ,
53
+ 'XPP ' =>'buc. ' ,
54
+ );
55
+
35
56
$ xmlString =preg_replace ('/( (xmlns|xsi)(:[a-zA-Z0-9]+){0,1}="[^"]+")/ ' ,'' ,$ xmlString );
36
57
$ xmlString =str_replace (array ('<cbc: ' ,'</cbc: ' ,'<cac: ' ,'</cac: ' ,'<ubl: ' ,'</ubl: ' ),array ('< ' ,'</ ' ,'< ' ,'</ ' ,'< ' ,'</ ' ),$ xmlString );
37
58
$ xml =simplexml_load_string ($ xmlString );
@@ -66,7 +87,13 @@ function xml2pdfParse($xmlString) { // parcurge un XML eFactură și extrage câ
66
87
$ factura ['dataFactura ' ]=$ dataFactura ;
67
88
$ factura ['numar ' ]=$ numar ;
68
89
$ factura ['tip ' ]=(string )$ xml ->xpath ('//InvoiceTypeCode ' )[0 ][0 ];
90
+ if (isset ($ tipuriDocument [$ factura ['tip ' ]])) {
91
+ $ factura ['tipText ' ]=$ tipuriDocument [$ factura ['tip ' ]];
92
+ }
69
93
$ factura ['instrumentPlata ' ]=count ($ xml ->xpath ('//PaymentMeans/PaymentMeansCode ' ))?(string )$ xml ->xpath ('//PaymentMeans/PaymentMeansCode ' )[0 ][0 ]:'- ' ;
94
+ if (isset ($ instrumentePlata [$ factura ['instrumentPlata ' ]])) {
95
+ $ factura ['instrumentPlataText ' ]=$ instrumentePlata [$ factura ['instrumentPlata ' ]];
96
+ }
70
97
if (count ($ xml ->xpath ('/Invoice/Note ' ))) {
71
98
$ factura ['nota ' ]='' ;
72
99
for ($ i =0 ; $ i <count ($ xml ->xpath ('/Invoice/Note ' )); $ i ++) {
@@ -108,7 +135,7 @@ function xml2pdfParse($xmlString) { // parcurge un XML eFactură și extrage câ
108
135
$ factura ['produse ' ]=array ();
109
136
$ lines =$ xml ->xpath ('//InvoiceLine ' );
110
137
foreach ($ lines as $ line ) {
111
- $ factura [ ' produse ' ][] =array (
138
+ $ produs =array (
112
139
'produs ' =>trim ((string )$ line ->Item ->Name ),
113
140
'descriere ' =>trim ((string )$ line ->Item ->Description ),
114
141
'nota ' =>trim ((string )$ line ->Note ),
@@ -120,6 +147,10 @@ function xml2pdfParse($xmlString) { // parcurge un XML eFactură și extrage câ
120
147
'TVA ' =>(float )$ line ->Item ->ClassifiedTaxCategory ->Percent ,
121
148
'totalFaraTVA ' =>(float )$ line ->LineExtensionAmount ,
122
149
);
150
+ if (isset ($ unitati [$ produs ['um ' ]])) {
151
+ $ produs ['umText ' ]=$ unitati [$ produs ['um ' ]];
152
+ }
153
+ $ factura ['produse ' ][]=$ produs ;
123
154
}
124
155
125
156
$ factura ['fisiere ' ]=array ();
0 commit comments