Files
crm.twinpol.com/modules/EcmReceipts2/createXML.php
2025-05-12 15:44:39 +00:00

468 lines
21 KiB
PHP
Executable File

<?php
include_once("modules/EcmReceipts/EcmInvoiceOut.php");
function createInvoiceXml($id){
$r=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select * from ecmreceipts where id='".$id."'"));
$r_wz=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select document_no,so_id,parent_id from ecmstockdocouts where id='".$r['wz_id']."'"));
$r_so=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select register_date,parent_id from ecmsales where id='".$r_wz['so_id']."'"));
$r_so_acc=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select iln from accounts where id='".$r_wz['parent_id']."'"));
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select iln from accounts where id='".$r['parent_id']."'"));
$buyer_iln=$rr['iln'];
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select account_id,account_number from ecmdocumenttemplates where id='".$r['template_id']."'"));
$seller_account_number=$rr['account_number'];
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select iln,name,id,sic_code,billing_address_street,billing_address_city,billing_address_postalcode,billing_address_country from accounts where id='".$rr['account_id']."'"));
$seller_iln=$rr['iln'];
$seller_id=$rr['id'];
$seller_name=$rr['name'];
$seller_nip=$rr['sic_code'];
$seller_street=$rr['billing_address_street'];
$seller_city=$rr['billing_address_city'];
$seller_postalcode=$rr['billing_address_postalcode'];
$seller_country=$rr['billing_address_country'];
if(strlen($r['currency_id'])<36)$currency=$r['currency_id'];
else{
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select iso4217 from currencies where id='".$r['currency_id']."'"));
$currency=$rr['iso4217'];
}
if(!$currency)$currency="PLN";
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select days from ecmpaymentconditions where id='".$r['ecmpaymentcondition_id']."'"));
$days=$rr['days'];
$order_no=$r['order_no'];
$register_date=$r['register_date'];
$dp=$r['delivery_place'];
if($r['parent_id']==134)$codebybuyer="";
else $codebybuyer=$r['supplier_code'];
$dpp=array(
"10"=>"5900000900100",
"11"=>"5900000900117",
"12"=>"5900000900124",
"13"=>"5900000900131",
"14"=>"5900000900148",
"15"=>"5900000900155",
"16"=>"5900000900162",
"17"=>"5900000900179",
"18"=>"5900000900186",
"19"=>"5900000900193",
"20"=>"5900000900209",
"21"=>"5900000900216",
"22"=>"5900000900223",
"23"=>"5900000900230",
"24"=>"5900000900247",
"25"=>"5900000900254",
"26"=>"5900000900261",
"27"=>"5900000900278",
"28"=>"5900000900285",
"29"=>"5900000900292",
"30"=>"5900000900308",
"31"=>"5900000900315",
"32"=>"5900000900322",
"33"=>"5900000900339",
"34"=>"5900000900346",
"35"=>"5900000900353",
"36"=>"5900000900360",
"37"=>"5900000900377",
"38"=>"5900000900384",
"39"=>"5900000900391",
"41"=>"5900000900414",
"42"=>"5900000900421",
"43"=>"5900000900438",
"44"=>"5900000900445",
"45"=>"5900000900452",
"46"=>"5900000900469",
"47"=>"5900000900476",
"48"=>"5900000900483",
"49"=>"5900000900490",
"50"=>"5900000900506",
"51"=>"5900000900513",
"52"=>"5900000900520",
"53"=>"5900000900537",
"54"=>"5900000900544",
"55"=>"5900000900551",
"56"=>"5900000900568",
"57"=>"5900000900575",
"58"=>"5900000900582",
"59"=>"5900000900599",
"60"=>"5900000900605",
"61"=>"5900000900612",
"63"=>"5900000900636",
"64"=>"5900000900643",
"65"=>"5900000900650",
);
$prod_iln=$r_so_acc['iln'];
$xml='<Document-Invoice>
<Invoice-Header>
<InvoiceNumber>'.$r['document_no'].'</InvoiceNumber>
<InvoiceDate>'.$r['register_date'].'</InvoiceDate>
<SalesDate>'.$r['sell_date'].'</SalesDate>';
if($_REQUEST['duplicate']==1){
$xml.='<InvoiceDuplicateDate>'.date("Y-m-d").'</InvoiceDuplicateDate>';
$dfc="D";
}
else{
$dfc="O";
}
$xml.='<InvoiceCurrency>'.$currency.'</InvoiceCurrency>
<InvoicePaymentDueDate>'.$r['payment_date'].'</InvoicePaymentDueDate>
<InvoicePaymentTerms>'.$days.'</InvoicePaymentTerms>
<InvoicePostDate>'.$r['register_date'].'</InvoicePostDate>
<DocumentFunctionCode>'.$dfc.'</DocumentFunctionCode>
<Order>
<BuyerOrderNumber>'.str_replace(" ","",$r['order_no']).'</BuyerOrderNumber>
<BuyerOrderDate>'.$r_so['register_date'].'</BuyerOrderDate>
</Order>
<Delivery>
<DeliveryLocationNumber>'.str_replace(" ","",$prod_iln).'</DeliveryLocationNumber>
<DespatchNumber>'.$r_wz['document_no'].'</DespatchNumber>
<DeliveryDate>'.$r['register_date'].'</DeliveryDate>
</Delivery>
</Invoice-Header>
<Invoice-Parties>
<Buyer>
<ILN>'.str_replace(" ","",$buyer_iln).'</ILN>
<TaxID>'.str_replace("-","",$r['to_nip']).'</TaxID>
<Name>'.$r['parent_name'].'</Name>
<StreetAndNumber>'.$r['parent_address_street'].'</StreetAndNumber>
<CityName>'.$r['parent_address_city'].'</CityName>
<PostalCode>'.$r['parent_address_postalcode'].'</PostalCode>
<Country>PL</Country>
</Buyer>
<Payer>
<ILN>'.str_replace(" ","",$buyer_iln).'</ILN>
<TaxID>'.str_replace("-","",$r['to_nip']).'</TaxID>
<Name>'.$r['parent_name'].'</Name>
<StreetAndNumber>'.$r['parent_address_street'].'</StreetAndNumber>
<CityName>'.$r['parent_address_city'].'</CityName>
<PostalCode>'.$r['parent_address_postalcode'].'</PostalCode>
<Country>PL</Country>
</Payer>
<Invoicee>
<ILN>'.str_replace(" ","",$buyer_iln).'</ILN>
<TaxID>'.str_replace("-","",$r['to_nip']).'</TaxID>
<Name>'.$r['parent_name'].'</Name>
<StreetAndNumber>'.$r['parent_address_street'].'</StreetAndNumber>
<CityName>'.$r['parent_address_city'].'</CityName>
<PostalCode>'.$r['parent_address_postalcode'].'</PostalCode>
<Country>PL</Country>
</Invoicee>
<Seller>
<ILN>'.str_replace(" ","",$seller_iln).'</ILN>
<TaxID>'.str_replace("-","",$seller_nip).'</TaxID>
<AccountNumber>'.$seller_account_number.'</AccountNumber>
<Name>'.$seller_name.'</Name>
<StreetAndNumber>'.$seller_street.'</StreetAndNumber>
<CityName>'.$seller_city.'</CityName>
<PostalCode>'.$seller_postalcode.'</PostalCode>
<Country>PL</Country>
<CodeByBuyer>'.$codebybuyer.'</CodeByBuyer>
<UtilizationRegisterNumber></UtilizationRegisterNumber>
</Seller>
<Payee>
<ILN>'.str_replace(" ","",$seller_iln).'</ILN>
<TaxID>'.str_replace("-","",$seller_nip).'</TaxID>
<AccountNumber>'.$seller_account_number.'</AccountNumber>
<Name>'.$seller_name.'</Name>
<StreetAndNumber>'.$seller_street.'</StreetAndNumber>
<CityName>'.$seller_city.'</CityName>
<PostalCode>'.$seller_postalcode.'</PostalCode>
<Country>PL</Country>
<CodeByBuyer>'.$codebybuyer.'</CodeByBuyer>
<UtilizationRegisterNumber></UtilizationRegisterNumber>
</Payee>
<SellerHeadquarters>
<ILN>'.str_replace(" ","",$seller_iln).'</ILN>
<TaxID>'.str_replace("-","",$seller_nip).'</TaxID>
<AccountNumber>'.$seller_account_number.'</AccountNumber>
<Name>'.$seller_name.'</Name>
<StreetAndNumber>'.$seller_street.'</StreetAndNumber>
<CityName>'.$seller_city.'</CityName>
<PostalCode>'.$seller_postalcode.'</PostalCode>
<Country>PL</Country>
<CodeByBuyer>'.$codebybuyer.'</CodeByBuyer>
<UtilizationRegisterNumber></UtilizationRegisterNumber>
</SellerHeadquarters>
</Invoice-Parties>
<Invoice-Lines>';
$w=$GLOBALS[db]->query("select * from ecmreceiptitems where deleted='0' and ecmreceipt_id='".$id."'");
$i=0;
$total_netto=0;
$total_vat=0;
$total_netto_arr=array();
$vats=array();
while($r=$GLOBALS[db]->fetchByAssoc($w)){
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select ean from ecmproduct_language_pl_view where ecmproduct_id='".$r['ecmproduct_id']."'"));
$ean=$rr['ean'];
$total_netto+=round($r['price']*$r['quantity'],2);
$total_vat+=round($r['price']*$r['quantity']*$r['ecmvat_value']/100,2);
$vats[$r['ecmvat_value']]=$r['ecmvat_value'];
$total_netto_arr[$r['ecmvat_value']]+=round($r['price']*$r['quantity'],2);
$total_vat_arr[$r['ecmvat_value']]+=round($r['price']*$r['quantity']*$r['ecmvat_value']/100,2);
$i++;
$xml.='
<Line>
<Line-Item>
<LineNumber>'.$i.'</LineNumber>
<EAN>'.$ean.'</EAN>
<BuyerItemCode>'.$r['recipient_code'].'</BuyerItemCode>
<SupplierItemCode>'.$r['code'].'</SupplierItemCode>
<ItemDescription>'.$r['name'].'</ItemDescription>
<ItemType>CU</ItemType>
<InvoiceQuantity>'.$r['quantity'].'</InvoiceQuantity>
<UnitOfMeasure>PCE</UnitOfMeasure>
<InvoiceUnitPacksize>1.000</InvoiceUnitPacksize>
<PackItemUnitOfMeasure>PCE</PackItemUnitOfMeasure>
<InvoiceUnitNetPrice>'.round($r['price'],2).'</InvoiceUnitNetPrice>
<TaxRate>'.$r['ecmvat_value'].'</TaxRate>
<TaxCategoryCode>S</TaxCategoryCode>
<TaxAmount>'.round(($r['quantity']*$r['price']*$r['ecmvat_value']/100),2).'</TaxAmount>
<NetAmount>'.round(($r['quantity']*$r['price']),2).'</NetAmount>
</Line-Item>
<Line-Order>
<BuyerOrderNumber>'.$order_no.'</BuyerOrderNumber>
<BuyerOrderDate>'.$r_so['register_date'].'</BuyerOrderDate>
</Line-Order>
<Line-Delivery>
<DeliveryLocationNumber>'.$prod_iln.'</DeliveryLocationNumber>
<DespatchNumber>'.$r_wz['document_no'].'</DespatchNumber>
<DeliveryDate>'.$register_date.'</DeliveryDate>
</Line-Delivery>
</Line>';
}
$xml.='</Invoice-Lines>
<Invoice-Summary>
<TotalLines>'.$i.'</TotalLines>
<TotalNetAmount>'.round($total_netto,2).'</TotalNetAmount>
<TotalTaxableBasis>'.round($total_netto,2).'</TotalTaxableBasis>
<TotalTaxAmount>'.round($total_vat,2).'</TotalTaxAmount>
<TotalGrossAmount>'.round(($total_netto+$total_vat),2).'</TotalGrossAmount>
<GrossAmountInWords>'.EcmReceipt::slowniePL(number_format(($total_netto+$total_vat),2,",",".")).'</GrossAmountInWords>
<Tax-Summary>';
foreach($vats as $vat){
$xml.='
<Tax-Summary-Line>
<TaxRate>'.$vat.'</TaxRate>
<TaxCategoryCode>S</TaxCategoryCode>
<TaxAmount>'.round(($total_vat_arr[$vat]),2).'</TaxAmount>
<TaxableBasis>'.round(($total_netto_arr[$vat]),2).'</TaxableBasis>
<TaxableAmount>'.round(($total_netto_arr[$vat]),2).'</TaxableAmount>
<GrossAmount>'.round(($total_netto_arr[$vat]+$total_vat_arr[$vat]),2).'</GrossAmount>
</Tax-Summary-Line>';
}
$xml.='
</Tax-Summary>
</Invoice-Summary>
</Document-Invoice>';
return $xml;
}
function createCorrectInvoiceXml($id){
$r=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select * from ecmreceipts where id='".$id."'"));
$supplier_code=$r['supplier_code'];
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select iln from accounts where id='".$r['parent_id']."'"));
$buyer_iln=$rr['iln'];
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select account_id,account_number from ecmdocumenttemplates where id='".$r['template_id']."'"));
$seller_account_numer=$rr['account_number'];
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select iln,name,id,sic_code,billing_address_street,billing_address_city,billing_address_postalcode,billing_address_country from accounts where id='".$rr['account_id']."'"));
$seller_iln=$rr['iln'];
$seller_id=$rr['id'];
$seller_name=$rr['name'];
$seller_nip=$rr['sic_code'];
$seller_street=$rr['billing_address_street'];
$seller_city=$rr['billing_address_city'];
$seller_postalcode=$rr['billing_address_postalcode'];
$seller_country=$rr['billing_address_country'];
$r_inv=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select wz_id,register_date from ecmreceipts where id='".$r['ecmreceipt_id']."'"));
$r_wz=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select document_no,so_id,parent_id from ecmstockdocouts where id='".$r_inv['wz_id']."'"));
$r_so=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select register_date,parent_id,order_no from ecmsales where id='".$r_wz['so_id']."'"));
$r_so_acc=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select iln from accounts where id='".$r_wz['parent_id']."'"));
$prod_iln=$r_so_acc['iln'];
if(strlen($r['currency_id'])<36)$currency=$r['currency_id'];
else{
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select iso4217 from currencies where id='".$r['currency_id']."'"));
$currency=$rr['iso4217'];
}
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select days from ecmpaymentconditions where id='".$r['ecmpaymentcondition_id']."'"));
$days=$rr['days'];
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select document_no,register_date from ecmreceipts where id='".$r['ecmreceipt_id']."'"));
$cor_name=$rr['document_no'];
$cor_date=$rr['register_date'];
if($r['parent_id']==134)$codebybuyer="";
else $codebybuyer=23862;
$xml='<Document-Invoice>
<Invoice-Header>
<InvoiceNumber>'.$r['document_no'].'</InvoiceNumber>
<InvoiceDate>'.$r['register_date'].'</InvoiceDate>
<SalesDate>'.$r['sell_date'].'</SalesDate>';
if($r['parent_id']==134)$xml.='<CorrectionReason>KOREKTA CENOWA LUB ILOSCIOWA</CorrectionReason>';
if($_REQUEST['duplicate']==1){
$xml.='<InvoiceDuplicateDate>'.date("Y-m-d").'</InvoiceDuplicateDate>';
$dfc="R";
}
else{
$dfc="C";
}
$xml.='<InvoiceCurrency>'.$currency.'</InvoiceCurrency>
<InvoicePaymentDueDate>'.$r['payment_date'].'</InvoicePaymentDueDate>
<InvoicePaymentTerms>'.$days.'</InvoicePaymentTerms>
<InvoicePostDate>'.$r['register_date'].'</InvoicePostDate>
<DocumentFunctionCode>'.$dfc.'</DocumentFunctionCode>
<Reference>
<InvoiceReferenceNumber>'.$cor_name.'</InvoiceReferenceNumber>
<InvoiceReferenceDate>'.$cor_date.'</InvoiceReferenceDate>
</Reference>
<Delivery>
<DeliveryLocationNumber>'.str_replace(" ","",$prod_iln).'</DeliveryLocationNumber>
<DespatchNumber>'.$r_wz['document_no'].'</DespatchNumber>
<DeliveryDate>'.$r_inv['register_date'].'</DeliveryDate>
</Delivery>
<Order>
<BuyerOrderNumber>'.str_replace(" ","",$r_so['order_no']).'</BuyerOrderNumber>
<BuyerOrderDate>'.$r_so['register_date'].'</BuyerOrderDate>
</Order>
</Invoice-Header>
<Invoice-Parties>
<Buyer>
<ILN>'.str_replace(" ","",$buyer_iln).'</ILN>
<TaxID>'.str_replace("-","",$r['to_nip']).'</TaxID>
<Name>'.$r['parent_name'].'</Name>
<StreetAndNumber>'.$r['parent_address_street'].'</StreetAndNumber>
<CityName>'.$r['parent_address_city'].'</CityName>
<PostalCode>'.$r['parent_address_postalcode'].'</PostalCode>
<Country>PL</Country>
</Buyer>
<Seller>
<ILN>'.str_replace(" ","",$seller_iln).'</ILN>
<TaxID>'.str_replace("-","",$seller_nip).'</TaxID>
<AccountNumber>'.$seller_account_number.'</AccountNumber>
<Name>'.$seller_name.'</Name>
<StreetAndNumber>'.$seller_street.'</StreetAndNumber>
<CityName>'.$seller_city.'</CityName>
<PostalCode>'.$seller_postalcode.'</PostalCode>
<Country>PL</Country>
<CodeByBuyer>'.$codebybuyer.'</CodeByBuyer>
</Seller>
</Invoice-Parties>
<Invoice-Lines>';
$w=$GLOBALS[db]->query("select * from ecmreceiptitems where deleted='0' and ecmreceipt_id='".$id."'");
$i=0;
$total_netto=0;
$total_vat=0;
$total_netto_arr=array();
$vats=array();
while($r=$GLOBALS[db]->fetchByAssoc($w)){
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select ean from ecmproduct_language_pl_view where ecmproduct_id='".$r['ecmproduct_id']."'"));
$ean=$rr['ean'];
$rrr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select price,quantity,ecmvat_value from ecmreceiptitems where id='".$r['ecmreceiptitem_id']."'"));
$total_netto+=round($r['price']*$r['quantity'],2);
$total_vat+=round($r['price']*$r['quantity']*$r['ecmvat_value']/100,2);
$vats[$r['ecmvat_value']]=$r['ecmvat_value'];
$total_netto_arr[$r['ecmvat_value']]+=round($r['price']*$r['quantity'],2);
$total_vat_arr[$r['ecmvat_value']]+=round($r['price']*$r['quantity']*$r['ecmvat_value'],2);
$total_netto_c+=round($rrr['price']*$rrr['quantity'],2);
$total_vat_c+=round($rrr['price']*$rrr['quantity']*$rrr['ecmvat_value']/100,2);
$vats_c[$rrr['ecmvat_value']]=$rrr['ecmvat_value'];
$total_netto_arr_c[$rrr['ecmvat_value']]+=round($rrr['price']*$rrr['quantity'],2);
$total_vat_arr_c[$rrr['ecmvat_value']]+=round($rrr['price']*$rrr['quantity']*$rrr['ecmvat_value'],2);
if($rrr['price']==$r['price'] && $rrr['quantity']==$r['quantity'])continue;
$i++;
$xml.='
<Line>
<Line-Item>
<LineNumber>'.$i.'</LineNumber>
<EAN>'.$ean.'</EAN>
<BuyerItemCode>'.$r['recipient_code'].'</BuyerItemCode>
<SupplierItemCode>'.$r['code'].'</SupplierItemCode>
<ItemDescription>'.$r['name'].'</ItemDescription>
<ItemType>CU</ItemType>
<InvoiceQuantity>'.$r['quantity'].'</InvoiceQuantity>
<UnitOfMeasure>PCE</UnitOfMeasure>
<InvoiceUnitPacksize>1.000</InvoiceUnitPacksize>
<InvoiceUnitNetPrice>'.round($r['price'],2).'</InvoiceUnitNetPrice>
<TaxRate>'.$r['ecmvat_value'].'</TaxRate>
<TaxCategoryCode>S</TaxCategoryCode>
<TaxReference>
<ReferenceType></ReferenceType>
<ReferenceNumber></ReferenceNumber>
</TaxReference>
<TaxAmount>'.round(($r['quantity']*$r['price']*$r['ecmvat_value']/100),2).'</TaxAmount>
<NetAmount>'.round(($r['quantity']*$r['price']),2).'</NetAmount>
<PreviousInvoiceQuantity>'.$rrr['quantity'].'</PreviousInvoiceQuantity>
<PreviousInvoiceUnitNetPrice>'.$rrr['price'].'</PreviousInvoiceUnitNetPrice>
<PreviousTaxRate>'.$rrr['ecmvat_value'].'</PreviousTaxRate>
<PreviousTaxCategoryCode>S</PreviousTaxCategoryCode>
<PreviousTaxAmount>'.round(($rrr['price']*$rrr['quantity']*$rrr['ecmvat_value']/100),2).'</PreviousTaxAmount>
<PreviousNetAmount>'.round(($rrr['price']*$rrr['quantity']),2).'</PreviousNetAmount>
<CorrectionInvoiceQuantity>'.($r['quantity']-$rrr['quantity']).'</CorrectionInvoiceQuantity>
<CorrectionInvoiceUnitNetPrice>'.($r['price']-$rrr['price']).'</CorrectionInvoiceUnitNetPrice>
<CorrectionTaxAmount>'.(round(($r['price']*$r['quantity']*$r['ecmvat_value']/100),2)-round(($rrr['price']*$rrr['quantity']*$rrr['ecmvat_value']/100),2)).'</CorrectionTaxAmount>
<CorrectionNetAmount>'.(round(($r['price']*$r['quantity']),2)-round(($rrr['price']*$rrr['quantity']),2)).'</CorrectionNetAmount>
</Line-Item>
<Line-Order>
<BuyerOrderNumber></BuyerOrderNumber>
<BuyerOrderDate></BuyerOrderDate>
</Line-Order>
<Line-Delivery>
<DeliveryLocationNumber></DeliveryLocationNumber>
<DeliveryDate></DeliveryDate>
<DespatchNumber></DespatchNumber>
</Line-Delivery>
</Line>';
}
$xml.='</Invoice-Lines>
<Invoice-Summary>
<TotalLines>'.$i.'</TotalLines>
<TotalNetAmount>'.round($total_netto,2).'</TotalNetAmount>
<TotalTaxableBasis>'.round($total_netto,2).'</TotalTaxableBasis>
<TotalTaxAmount>'.round($total_vat,2).'</TotalTaxAmount>
<TotalGrossAmount>'.round(($total_netto+$total_vat),2).'</TotalGrossAmount>
<PreviousTotalNetAmount>'.round($total_netto_c,2).'</PreviousTotalNetAmount>
<PreviousTotalTaxableBasis>'.round($total_netto_c,2).'</PreviousTotalTaxableBasis>
<PreviousTotalTaxAmount>'.round($total_vat_c,2).'</PreviousTotalTaxAmount>
<PreviousTotalGrossAmount>'.round(($total_netto_c+$total_vat_c),2).'</PreviousTotalGrossAmount>
<CorrectionTotalNetAmount>'.round(($total_netto-$total_netto_c),2).'</CorrectionTotalNetAmount>
<CorrectionTotalTaxableBasis>'.round(($total_netto-$total_netto_c),2).'</CorrectionTotalTaxableBasis>
<CorrectionTotalTaxAmount>'.round(($total_vat-$total_vat_c),2).'</CorrectionTotalTaxAmount>
<CorrectionTotalGrossAmount>'.round((($total_netto+$total_vat)-($total_netto_c+$total_vat_c)),2).'</CorrectionTotalGrossAmount>
<GrossAmountInWords>'.str_replace("minus","",EcmReceipt::slowniePL(number_format(($total_netto+$total_vat),2,",","."))).'</GrossAmountInWords>';
$xml.='<Tax-Summary>';
foreach($vats as $vat){
$xml.='
<Tax-Summary-Line>
<TaxRate>'.$vat.'</TaxRate>
<TaxCategoryCode>S</TaxCategoryCode>
<TaxAmount>'.round(($total_netto_arr[$vat]*$vat/100),2).'</TaxAmount>';
//<TaxableBasis>'.round(($total_netto_arr[$vat]),2).'</TaxableBasis>
$xml.='<TaxableAmount>'.round(($total_netto_arr[$vat]),2).'</TaxableAmount>';
//<GrossAmount>'.(round(($total_netto_arr[$vat]*$vat/100),2)+round(($total_netto_arr[$vat]),2)).'</GrossAmount>
$xml.='<PreviousTaxRate>'.$vat.'</PreviousTaxRate>
<PreviousTaxCategoryCode>S</PreviousTaxCategoryCode>
<PreviousTaxAmount>'.round(($total_netto_arr_c[$vat]*$vat/100),2).'</PreviousTaxAmount>
<PreviousTaxableAmount>'.round(($total_netto_arr_c[$vat]),2).'</PreviousTaxableAmount>
<CorrectionTaxAmount>'.round(round(($total_netto_arr[$vat]*$vat/100),2)-round(($total_netto_arr_c[$vat]*$vat/100),2),2).'</CorrectionTaxAmount>
<CorrectionTaxableAmount>'.round(round($total_netto_arr[$vat],2)-round($total_netto_arr_c[$vat],2),2).'</CorrectionTaxableAmount>
</Tax-Summary-Line>';
}
$xml.='
</Tax-Summary>
</Invoice-Summary>
</Document-Invoice>';
return $xml;
}
?>