163 lines
7.2 KiB
PHP
163 lines
7.2 KiB
PHP
|
|
<?php
|
||
|
|
function createDecree($year,$month){
|
||
|
|
$xml='<?xml version="1.0" encoding="utf-8" ?>';
|
||
|
|
$xml.='<paczka miesiac="'.$year.'-'.$month.'" firma="E5" opis="FVS '.$year.'-'.$month.'" wersja="1.0">';
|
||
|
|
//normal
|
||
|
|
$db = $GLOBALS['db'];
|
||
|
|
$w=$db->query("select id,name,number,document_no,wz_id,name,register_date,payment_date,sell_date,to_nip,parent_id,parent_name,parent_address_street,parent_address_postalcode,parent_address_country,parent_address_city,currency_value from ecmreceipts where type!='correct' and register_date like '".$year."-".$month."%' and deleted='0' order by date_entered asc");
|
||
|
|
while($r=$db->fetchByAssoc($w)){
|
||
|
|
if($r['currency_value'])$waluta="USD";
|
||
|
|
else $waluta="PLN";
|
||
|
|
|
||
|
|
$r_nip=$db->fetchByAssoc($db->query("select vatid,sic_code from accounts where id='".$r['parent_id']."'"));
|
||
|
|
if($r_nip['vatid'])$nip=str_replace("-","",$r_nip['vatid']);
|
||
|
|
elseif($r_nip['sic_code'])$nip=str_replace("-","",$r_nip['sic_code']);
|
||
|
|
else $nip=str_replace("-","",$r['to_nip']);
|
||
|
|
|
||
|
|
$r_wz=$db->fetchByAssoc($db->query("select id,number,document_no from ecmstockdocouts where id='".$r['wz_id']."'"));
|
||
|
|
|
||
|
|
$xml.='<dokument rodzaj="FVS" id="'.$r['number'].'">
|
||
|
|
<data>'.$r['register_date'].'</data>
|
||
|
|
<dataWplywu>'.$r['register_date'].'</dataWplywu>
|
||
|
|
<dataOperacji>'.$r['register_date'].'</dataOperacji>
|
||
|
|
<numer>'.$r['document_no'].'</numer>
|
||
|
|
<idMagazynu>0</idMagazynu>
|
||
|
|
<kontrahent id="'.$r['parent_id'].'" kod="'.$nip.'">
|
||
|
|
<NIP>'.str_replace("-","",$nip).'</NIP>
|
||
|
|
<nazwa>'.str_replace("<","",str_replace(">","",$r['parent_name'])).'</nazwa>
|
||
|
|
<adres>'.$r['parent_address_street'].'</adres>
|
||
|
|
<kodPocztowy>'.$r['parent_address_postalcode'].'</kodPocztowy>
|
||
|
|
<miasto>'.$r['parent_address_city'].'</miasto>
|
||
|
|
</kontrahent>
|
||
|
|
<dokumentyMagazynowe>
|
||
|
|
<dokumentMagazynowy rodzaj="WZ" id="'.$r_wz['number'].'">
|
||
|
|
<numer>'.$r_wz['document_no'].'</numer>
|
||
|
|
</dokumentMagazynowy>
|
||
|
|
</dokumentyMagazynowe>
|
||
|
|
<opis>'.$r['name'].'</opis>
|
||
|
|
<dataPlatnosci>'.$r['payment_date'].'</dataPlatnosci>
|
||
|
|
<formaPlatnosci>0</formaPlatnosci>
|
||
|
|
<waluta>'.$waluta.'</waluta>';
|
||
|
|
$ww=$db->query("select quantity,price,ecmvat_value,ecmvat_name,ecmvat_id from ecmreceiptitems where ecmreceipt_id='".$r['id']."' and deleted='0'");
|
||
|
|
$sum_netto=0;
|
||
|
|
$sum_brutto=0;
|
||
|
|
$sum_vat=0;
|
||
|
|
$s_netto=array();
|
||
|
|
$s_brutto=array();
|
||
|
|
$s_vat=array();
|
||
|
|
while($rr=$db->fetchByAssoc($ww)){
|
||
|
|
$sum_netto+=$rr['quantity']*$rr['price'];
|
||
|
|
$sum_brutto+=$rr['quantity']*$rr['price']*(1+$rr['ecmvat_value']/100);
|
||
|
|
$sum_vat+=round($rr['quantity']*$rr['price']*$rr['ecmvat_value']/100,2);
|
||
|
|
$s_netto[$rr['ecmvat_name']]+=$rr['quantity']*$rr['price'];
|
||
|
|
$s_brutto[$rr['ecmvat_name']]+=$rr['quantity']*$rr['price']*(1+$rr['ecmvat_value']/100);
|
||
|
|
$s_vat[$rr['ecmvat_name']]+=round($rr['quantity']*$rr['price']*$rr['ecmvat_value']/100,2);
|
||
|
|
}
|
||
|
|
/*$xml.='
|
||
|
|
<platnosc>
|
||
|
|
<kwota>'.$sum_brutto.'</kwota>
|
||
|
|
<data>'.$r['payment_date'].'</data>
|
||
|
|
<forma>0</forma>
|
||
|
|
</platnosc>
|
||
|
|
';*/
|
||
|
|
$xml.='
|
||
|
|
<sumaNetto>'.$sum_netto.'</sumaNetto>
|
||
|
|
<sumaBrutto>'.round($sum_brutto,2).'</sumaBrutto>
|
||
|
|
<sumaVAT>'.(round($sum_brutto,2)-$sum_netto).'</sumaVAT>
|
||
|
|
<rejestr>';
|
||
|
|
|
||
|
|
foreach($s_netto as $key=>$value){
|
||
|
|
$xml.='
|
||
|
|
<rozbicie stawka="'.$key.'">
|
||
|
|
<netto>'.$s_netto[$key].'</netto>
|
||
|
|
<brutto>'.round($s_brutto[$key],2).'</brutto>
|
||
|
|
<VAT>'.round((round($s_brutto[$key],2)-$s_netto[$key]),2).'</VAT>
|
||
|
|
</rozbicie>';
|
||
|
|
}
|
||
|
|
$xml.='
|
||
|
|
</rejestr>
|
||
|
|
</dokument>';
|
||
|
|
|
||
|
|
}
|
||
|
|
//corrects
|
||
|
|
$w=$db->query("select id,name,document_no,name,register_date,payment_date,sell_date,to_nip,parent_id,parent_name,parent_address_street,parent_address_postalcode,parent_address_country,parent_address_city,ecmreceipt_id,ecmreceipt_name from ecmreceipts where type='correct' and register_date like '".$year."-".$month."%' and deleted='0' order by date_entered asc");
|
||
|
|
while($r=$db->fetchByAssoc($w)){
|
||
|
|
|
||
|
|
$r_nip=$db->fetchByAssoc($db->query("select vatid,sic_code from accounts where id='".$r['parent_id']."'"));
|
||
|
|
if($r_nip['vatid'])$nip=str_replace("-","",$r_nip['vatid']);
|
||
|
|
elseif($r_nip['sic_code'])$nip=str_replace("-","",$r_nip['sic_code']);
|
||
|
|
else $nip=str_replace("-","",$r['to_nip']);
|
||
|
|
|
||
|
|
$xml.='<dokument rodzaj="FKS" id="'.$r['id'].'" idRel="'.$r['ecmreceipt_id'].'">
|
||
|
|
<data>'.$r['register_date'].'</data>
|
||
|
|
<dataWplywu>'.$r['register_date'].'</dataWplywu>
|
||
|
|
<dataOperacji>'.$r['register_date'].'</dataOperacji>
|
||
|
|
<numer>'.$r['document_no'].'</numer>
|
||
|
|
<numerRel>'.$r['ecmreceipt_name'].'</numerRel>
|
||
|
|
<idMagazynu>0</idMagazynu>
|
||
|
|
<kontrahent id="'.$r['parent_id'].'" kod="'.$nip.'">
|
||
|
|
<NIP>'.str_replace("-","",$nip).'</NIP>
|
||
|
|
<nazwa>'.str_replace("<","",str_replace(">","",$r['parent_name'])).'</nazwa>
|
||
|
|
<adres>'.$r['parent_address_street'].'</adres>
|
||
|
|
<kodPocztowy>'.$r['parent_address_postalcode'].'</kodPocztowy>
|
||
|
|
<miasto>'.$r['parent_address_city'].'</miasto>
|
||
|
|
</kontrahent>
|
||
|
|
<opis>'.$r['name'].'</opis>
|
||
|
|
<dataPlatnosci>'.$r['payment_date'].'</dataPlatnosci>
|
||
|
|
<formaPlatnosci>0</formaPlatnosci>
|
||
|
|
<waluta>PLN</waluta>';
|
||
|
|
$ww=$db->query("select quantity,price,ecmvat_value,ecmvat_name,ecmvat_id,ecmreceiptitem_id from ecmreceiptitems where ecmreceipt_id='".$r['id']."' and deleted='0'");
|
||
|
|
$sum_netto=0;
|
||
|
|
$sum_brutto=0;
|
||
|
|
$sum_vat=0;
|
||
|
|
$s_netto=array();
|
||
|
|
$s_brutto=array();
|
||
|
|
$s_vat=array();
|
||
|
|
while($rr=$db->fetchByAssoc($ww)){
|
||
|
|
$sum_netto+=round($rr['quantity']*$rr['price'],2);
|
||
|
|
$sum_brutto+=round($rr['quantity']*$rr['price']*(1+$rr['ecmvat_value']/100),2);
|
||
|
|
$sum_vat+=round($rr['quantity']*$rr['price']*$rr['ecmvat_value']/100,2);
|
||
|
|
$s_netto[$rr['ecmvat_name']]+=round($rr['quantity']*$rr['price'],2);
|
||
|
|
$s_brutto[$rr['ecmvat_name']]+=round($rr['quantity']*$rr['price']*(1+$rr['ecmvat_value']/100),2);
|
||
|
|
$s_vat[$rr['ecmvat_name']]+=round($rr['quantity']*$rr['price']*$rr['ecmvat_value']/100,2);
|
||
|
|
|
||
|
|
$rrr=$db->fetchByAssoc($db->query("select price,quantity,ecmvat_value,ecmvat_name from ecmreceiptitems where id='".$rr['ecmreceiptitem_id']."'"));
|
||
|
|
$sum_netto-=round($rrr['quantity']*$rrr['price'],2);
|
||
|
|
$sum_brutto-=round($rrr['quantity']*$rrr['price']*(1+$rrr['ecmvat_value']/100),2);
|
||
|
|
$sum_vat-=round($rrr['quantity']*$rrr['price']*$rrr['ecmvat_value']/100,2);
|
||
|
|
$s_netto[$rrr['ecmvat_name']]-=round($rrr['quantity']*$rrr['price'],2);
|
||
|
|
$s_brutto[$rrr['ecmvat_name']]-=round($rrr['quantity']*$rrr['price']*(1+$rrr['ecmvat_value']/100),2);
|
||
|
|
$s_vat[$rrr['ecmvat_name']]-=round($rrr['quantity']*$rrr['price']*$rrr['ecmvat_value']/100,2);
|
||
|
|
|
||
|
|
}
|
||
|
|
/*$xml.='
|
||
|
|
<platnosc>
|
||
|
|
<kwota>'.$sum_brutto.'</kwota>
|
||
|
|
<data>'.$r['payment_date'].'</data>
|
||
|
|
<forma>0</forma>
|
||
|
|
</platnosc>
|
||
|
|
';*/
|
||
|
|
$xml.='
|
||
|
|
<sumaNetto>'.$sum_netto.'</sumaNetto>
|
||
|
|
<sumaBrutto>'.round($sum_brutto,2).'</sumaBrutto>
|
||
|
|
<sumaVAT>'.(round($sum_brutto,2)-$sum_netto).'</sumaVAT>
|
||
|
|
<rejestr>';
|
||
|
|
|
||
|
|
foreach($s_netto as $key=>$value){
|
||
|
|
$xml.='
|
||
|
|
<rozbicie stawka="'.$key.'">
|
||
|
|
<netto>'.$s_netto[$key].'</netto>
|
||
|
|
<brutto>'.round($s_brutto[$key],2).'</brutto>
|
||
|
|
<VAT>'.(round($s_brutto[$key],2)-$s_netto[$key]).'</VAT>
|
||
|
|
</rozbicie>';
|
||
|
|
}
|
||
|
|
$xml.='
|
||
|
|
</rejestr>
|
||
|
|
</dokument>';
|
||
|
|
|
||
|
|
}
|
||
|
|
$xml.='</paczka>';
|
||
|
|
return $xml;
|
||
|
|
}
|
||
|
|
//echo createDecree(2009,12)
|
||
|
|
?>
|