Częśc mojego kodu to:
procedure TForm30.Plik_JPK_FA;
var jpk:Schemat_JPK_FA1_v10.IXMLJPK;
xml:IXMLDocument;
i,j,k:integer;
a,b,c,d :extended;
begin
a:=0; b:=0;
xml:=NewXMLDocument;
xml.encoding:='utf-8';
xml.options:=xml.options+[doNodeAutoIndent];
jpk:=Schemat_JPK_FA1_v10.getjpk(xml);
jpk.DeclareNamespace('etd','http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/');
with datamodule1, jpk do
begin
table14.filter:='do_data1>='+d1+' and do_data1<='+d2+' and (do_typ=1 or do_typ=2)';
with Naglowek do
begin
KodFormularza.KodSystemowy:='JPK_FA (1)';
KodFormularza.WersjaSchemy:='1-0';
KodFormularza.Text:='JPK_FA';
WariantFormularza:=1;
CelZlozenia:=combobox4.itemindex+1;
DataWytworzeniaJPK:=datetostr(date)+'T'+timetostr(time);
DataOd:=d1;
DataDo:=d2;
DomyslnyKodWaluty:=table10['wa_symbol'];
KodUrzedu:=table12['po_us'];
end;
with Podmiot1 do
begin
IdentyfikatorPodmiotu.NIP:=table12['po_nip'];
IdentyfikatorPodmiotu.PelnaNazwa:=table12['po_nazwa1']+' '+table12['po_nazwa2'];
if table12['po_regon']<>null then IdentyfikatorPodmiotu.REGON:=table12['po_regon'];
table16.locate('kr_nr',table12['po_kraj'],[]);
AdresPodmiotu.KodKraju:=table16['kr_kod'];
table17.locate('wo_nr',table12['po_wojew'],[]);
AdresPodmiotu.Wojewodztwo:=table17['wo_nazwa'];
AdresPodmiotu.Powiat:=table12['po_powiat'];
AdresPodmiotu.Gmina:=table12['po_gmina'];
if table12['po_adres']<>null then AdresPodmiotu.Ulica:=table12['po_adres'];
if table12['po_nrdomu']<>null then AdresPodmiotu.NrDomu:=table12['po_nrdomu'] else AdresPodmiotu.NrDomu:='brak';
if table12['po_nrlokal']<>null then AdresPodmiotu.NrLokalu:=table12['po_nrlokal'];
AdresPodmiotu.Miejscowosc:=table12['po_miejsce'];
AdresPodmiotu.KodPocztowy:=table12['po_kodpocz'];
AdresPodmiotu.Poczta:=table12['po_poczta'];
end;
{w pętli pozycje faktury}
table14.first;
with Faktura do
for i:=1 to table14.recordcount do
begin
table4.locate('ko_nr',table14['do_nrko'],[]); {*}
Add.Typ:='G';
Items[i-1].P_1:=table14['do_data1'];
Items[i-1].P_2A:=table14['do_nrdok1'];
Items[i-1].P_3A:=table4['ko_nazwa1'];
if table4['ko_nazwa2']<>null then Items[i-1].P_3A:=Items[i-1].P_3A+' '+table4['ko_nazwa2'];
Items[i-1].P_3B:=table4['ko_kodpocz']+' '+table4['ko_miejsce']+', '+table4['ko_adres']; {*}
Items[i-1].P_3C:='Imię i nazwisko lub nazwa sprzedawcy';
Items[i-1].P_3D:='Adres sprzedawcy';
//Items[i-1].P_4A {*}
//Items[i-1].P_4B:='1111111111'; //pole opcjonalne
//Items[i-1].P_5A {*}
if table4['ko_nip']<>null then Items[i-1].P_5B:=table4['ko_nip']; {*}
//Items[i-1].P_6 {*}
{w poszczególnych stawkach - uprościć do jakiejś jednej pętli}
c:=0; d:=0;
table11.filter:='st_nrdo='+inttostr(table14['do_nr'])+' and st_vat=23';
if table11.recordcount>0 then
begin
for j:=1 to table11.recordcount do
begin
c:=c+(table11['st_ile1']*table11['st_cenasb']/(1+table11['st_vat']/100));
d:=d+(table11['st_ile1']*table11['st_cenasb']*table11['st_vat']/(100+table11['st_vat']));
table11.next;
end;
Items[i-1].P_13_1:=floattostrf(c,ffFixed,9,2); //netto 23%
Items[i-1].P_14_1:=floattostrf(d,ffFixed,9,2); // vat 23%
end;
c:=0; d:=0;
table11.filter:='st_nrdo='+inttostr(table14['do_nr'])+' and st_vat=8';
if table11.recordcount>0 then
begin
for j:=1 to table11.recordcount do
begin
c:=c+(table11['st_ile1']*table11['st_cenasb']/(1+table11['st_vat']/100));
d:=d+(table11['st_ile1']*table11['st_cenasb']*table11['st_vat']/(100+table11['st_vat']));
table11.next;
end;
Items[i-1].P_13_2:=floattostrf(c,ffFixed,9,2); //netto 8%
Items[i-1].P_14_2:=floattostrf(d,ffFixed,9,2); // vat 8%
end;
c:=0; d:=0;
table11.filter:='st_nrdo='+inttostr(table14['do_nr'])+' and st_vat=5';
if table11.recordcount>0 then
begin
for j:=1 to table11.recordcount do
begin
c:=c+(table11['st_ile1']*table11['st_cenasb']/(1+table11['st_vat']/100));
d:=d+(table11['st_ile1']*table11['st_cenasb']*table11['st_vat']/(100+table11['st_vat']));
table11.next;
end;
Items[i-1].P_13_3:=floattostrf(c,ffFixed,9,2); //netto 5%
Items[i-1].P_14_3:=floattostrf(d,ffFixed,9,2); // vat 5%
end;
//Items[1].P_13_4
//Items[1].P_14_4
//Items[1].P_13_5
//Items[1].P_14_5
//Items[1].P_13_6
//Items[1].P_13_7
Items[i-1].P_15:=floattostrf(table14['do_wartosc'],ffFixed,9,2);
Items[i-1].P_16:=false;
Items[i-1].P_17:=false;
Items[i-1].P_18:=false;
Items[i-1].P_19:=false;
//Items[1].P_19A
//Items[1].P_19B
//Items[1].P_19C
Items[i-1].P_20:=false; {To właśnie w plik XML wpisuje mi jako 'False' i walidacja pokazuje błąd}
//Items[1].P_20A
//Items[1].P_20B
Items[i-1].P_21:=false; {*}
//Items[1].P_21A
//Items[1].P_21B
//Items[1].P_21C
//Items[i-1].P_22A
//Items[i-1].P_22B
//Items[i-1].P_22C
Items[i-1].P_23:=false; {*}
Items[i-1].P_106E_2:=false; {*}
//Items[i-1].P_106E_3
//Items[1].P_106E_3A
if table14['do_typ']=1 then Items[i-1].RodzajFaktury:='VAT' else Items[i-1].RodzajFaktury:='KOREKTA'; {*}
//Items[1].PrzyczynaKorekty {*}
//Items[1].NrFaKorygowanej {*}
//Items[1].OkresFaKorygowanej {*}
//Items[1].ZALZaplata {*}
//Items[1].ZALPodatek {*}
a:=a+table14['do_wartosc'];
table14.next;
end;
FakturaCtrl.LiczbaFaktur:=inttostr(table14.recordcount); {*}
FakturaCtrl.WartoscFaktur:=floattostrf(a,ffFixed,9,2); {};
with StawkiPodatku do
begin
Stawka1:='0.23';
Stawka2:='0.08';
Stawka3:='0.05';
Stawka4:='0.00';
Stawka5:='0.00';
end;
table14.first; k:=0;
with FakturaWiersz do
for j:=1 to table14.recordcount do
begin
table11.filter:='st_nrdo='+inttostr(table14['do_nr']);
for i:=1 to table11.recordcount do
begin
table1.locate('to_nr',table11['st_nrto'],[]); {*}
inc(k);
Add.Typ:='G';
Items[k-1].P_2B:=table14['do_nrdok1']; {*}
Items[k-1].P_7:=table1['to_nazwa2']; {*}
Items[k-1].P_8A:=table1['jednostka']; {*}
Items[k-1].P_8B:=floattostr(table11['st_ile1']); {*}
Items[k-1].P_9A:=floattostrf(table11['st_cenasb']/(1+table11['st_vat']/100),fffixed,9,2); {}
Items[k-1].P_9B:=floattostrf(table11['st_cenasb'],fffixed,9,2); {}
//Items[k-1].P_10
Items[k-1].P_11:=floattostrf(table11['st_ile1']*table11['st_cenasb']/(1+table11['st_vat']/100),fffixed,9,2); {}
Items[k-1].P_11A:=floattostrf(table11['st_ile1']*table11['st_cenasb'],fffixed,9,2); {}
Items[k-1].P_12:=floattostr(table11['st_vat']); {}
b:=b+( table11['st_ile1']*table11['st_cenasb']/(1+table11['st_vat']/100) );
table11.next;
end;
table14.next;
end;
FakturaWierszCtrl.LiczbaWierszyFaktur:=inttostr(k);
FakturaWierszCtrl.WartoscWierszyFaktur:=floattostrf(b,fffixed,9,2);
xml.DocumentElement:=jpk;
xml.SaveToFile(edit1.text);
end;