497 lines
22 KiB
PHP
497 lines
22 KiB
PHP
<?php
|
|
include_once("modules/EcmInvoiceOutOlds/EcmInvoiceOutOld.php");
|
|
function createInvoiceXml($id){
|
|
$r=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select *, TRIM(order_no) as o_no from ecminvoiceoutolds 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, parent_shipping_address_name from ecmsales where id='".$r_wz['so_id']."'"));
|
|
$r_so_acc=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select iln from accounts where name like '".trim($r_so['parent_shipping_address_name'])."%'"));
|
|
if (!$r_so_acc || $r_so_acc['iln']=='') {
|
|
$r_so_acc=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select iln from accounts where id = '".trim($r_so['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=trim($r['o_no']);
|
|
$register_date=$r['register_date'];
|
|
$dp=$r['delivery_place'];
|
|
|
|
if($r['parent_id']==134)$codebybuyer="";
|
|
else $codebybuyer=$r['supplier_code'];
|
|
|
|
echo $r['o_no'].' - '.$r['document_no'].'<br>';
|
|
|
|
$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>'.trim($r['o_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 ecminvoiceoutolditems where deleted='0' and ecminvoiceoutold_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 TRIM(ean) as ean from ecmproduct_language_pl_view where ecmproduct_id='".$r['ecmproduct_id']."'"));
|
|
$ean=trim($rr['ean']);
|
|
|
|
if (strlen($ean) > 13)
|
|
$ean = substr($ean, 0,13);
|
|
|
|
$total_netto+=$r['subtotal'];
|
|
$total_vat+=($r['total']-$r['subtotal']);
|
|
$vats[$r['ecmvat_value']]=$r['ecmvat_value'];
|
|
$total_netto_arr[$r['ecmvat_value']]+=$r['subtotal'];
|
|
$total_vat_arr[$r['ecmvat_value']]+=($r['total']-$r['subtotal']);
|
|
|
|
if (strlen($r['name'])>=70)
|
|
$r['name'] = substr($r['name'], 0, 66).'...';
|
|
|
|
$i++;
|
|
$xml.='
|
|
<Line>
|
|
<Line-Item>
|
|
<LineNumber>'.$i.'</LineNumber>
|
|
<EAN>'.trim($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>'.$r['subprice'].'</InvoiceUnitNetPrice>
|
|
<TaxRate>'.$r['ecmvat_value'].'</TaxRate>
|
|
<TaxCategoryCode>S</TaxCategoryCode>
|
|
<TaxAmount>'.round($r['total']-$r['subtotal'],2).'</TaxAmount>
|
|
<NetAmount>'.$r['subtotal'].'</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>'.EcmInvoiceOutOld::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 *, TRIM(order_no) as o_no from ecminvoiceoutolds 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 ecminvoiceoutolds where id='".$r['ecminvoiceoutold_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, parent_shipping_address_name from ecmsales where id='".$r_wz['so_id']."'"));
|
|
if ($r_so['parent_shipping_address_name'] && $r_so['parent_shipping_address_name']!='')
|
|
$r_so_acc=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select iln from accounts where name like '".trim($r_so['parent_shipping_address_name'])."%'"));
|
|
if (!$r_so_acc || $r_so_acc['iln']=='') {
|
|
$r_so_acc=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select iln from accounts where id = '".trim($r_so['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 ecminvoiceoutolds where id='".$r['ecminvoiceoutold_id']."'"));
|
|
$cor_name=$rr['document_no'];
|
|
$cor_date=$rr['register_date'];
|
|
|
|
if($r['parent_id']==134)$codebybuyer="";
|
|
else $codebybuyer=23862;
|
|
|
|
echo $r['o_no'].' - '.$r['document_no'].'<br>';
|
|
|
|
$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>'.trim($r['o_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 ecminvoiceoutolditems where deleted='0' and ecminvoiceoutold_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 TRIM(ean) as ean from ecmproducts where id='".$r['ecmproduct_id']."'"));
|
|
$ean=trim($rr['ean']);
|
|
|
|
// bazujemy na old_ecminvoiceoutolditem_id, zero dynamicznych faktur
|
|
if (is_null ( $r ['old_ecminvoiceoutolditem_id'] ) || $r ['old_ecminvoiceoutolditem_id'] == '')
|
|
continue; // ten produkt nie był korygowany
|
|
$oi = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "SELECT quantity, subtotal, total, ecmvat_value, discount, dd_unit_id, subprice, price, ecmvat_value, ecmvat_name, ecmvat_id FROM ecminvoiceoutolditems WHERE id='" . $r ['old_ecminvoiceoutolditem_id'] . "'" ) );
|
|
|
|
$rrr = $oi;
|
|
|
|
$total_netto+=round($r['subtotal'],2);
|
|
$total_vat+=round($r['subtotal']*$r['ecmvat_value']/100,2);
|
|
$vats[$r['ecmvat_value']]=$r['ecmvat_value'];
|
|
$total_netto_arr[$r['ecmvat_value']]+=round($r['subtotal'],2);
|
|
$total_vat_arr[$r['ecmvat_value']]+=round($r['subtotal']*$r['ecmvat_value'],2);
|
|
|
|
$total_netto_c+=round($rrr['subtotal'],2);
|
|
$total_vat_c+=round($rrr['subtotal']*$rrr['ecmvat_value']/100,2);
|
|
$vats_c[$rrr['ecmvat_value']]=$rrr['ecmvat_value'];
|
|
$total_netto_arr_c[$rrr['ecmvat_value']]+=round($rrr['subtotal'],2);
|
|
$total_vat_arr_c[$rrr['ecmvat_value']]+=round($rrr['subtotal']*$rrr['ecmvat_value'],2);
|
|
|
|
if (strlen($r['name'])>=70)
|
|
$r['name'] = substr($r['name'], 0, 66).'...';
|
|
|
|
$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['subprice'],2).'</InvoiceUnitNetPrice>
|
|
<TaxRate>'.$r['ecmvat_value'].'</TaxRate>
|
|
<TaxCategoryCode>S</TaxCategoryCode>
|
|
<TaxReference>
|
|
<ReferenceType></ReferenceType>
|
|
<ReferenceNumber></ReferenceNumber>
|
|
</TaxReference>
|
|
<TaxAmount>'.round(($r['subtotal']*$r['ecmvat_value']/100),2).'</TaxAmount>
|
|
<NetAmount>'.round(($r['subtotal']),2).'</NetAmount>
|
|
<PreviousInvoiceQuantity>'.$rrr['quantity'].'</PreviousInvoiceQuantity>
|
|
<PreviousInvoiceUnitNetPrice>'.$rrr['subprice'].'</PreviousInvoiceUnitNetPrice>
|
|
<PreviousTaxRate>'.$rrr['ecmvat_value'].'</PreviousTaxRate>
|
|
<PreviousTaxCategoryCode>S</PreviousTaxCategoryCode>
|
|
<PreviousTaxAmount>'.round(($rrr['subtotal']*$rrr['ecmvat_value']/100),2).'</PreviousTaxAmount>
|
|
<PreviousNetAmount>'.round(($rrr['subtotal']),2).'</PreviousNetAmount>
|
|
<CorrectionInvoiceQuantity>'.($r['quantity']-$rrr['quantity']).'</CorrectionInvoiceQuantity>
|
|
<CorrectionInvoiceUnitNetPrice>'.($r['subprice']-$rrr['subprice']).'</CorrectionInvoiceUnitNetPrice>
|
|
<CorrectionTaxAmount>'.(round(($r['subtotal']*$r['ecmvat_value']/100),2)-round(($rrr['subtotal']*$rrr['ecmvat_value']/100),2)).'</CorrectionTaxAmount>
|
|
<CorrectionNetAmount>'.(round(($r['subtotal']),2)-round(($rrr['subtotal']),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","",EcmInvoiceOutOld::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;
|
|
}
|
|
?>
|