if(!$_GET['date_from'])$date_from=date("Y-m-d");
else $date_from=$GLOBALS['timedate']->to_db_date($_GET['date_from']);
$exp=explode("-",$date_from);
$date_from=date("Y-m-d",mktime(0,0,0,$exp[1],$exp[2],$exp[0])+24*3600);
if(!$date_from)$date_from=date("Y-m-d");
if(!$_GET['date_to'])$date_to=date("Y-m-d");
else $date_to=$GLOBALS['timedate']->to_db_date($_GET['date_to']);
$exp=explode("-",$date_to);
$date_to=date("Y-m-d",mktime(0,0,0,$exp[1],$exp[2],$exp[0])+24*3600);
if(!$date_to)$date_to=date("Y-m-d");
?>
 | Faktury: Sprzedane produkty |
Data: echo $GLOBALS['timedate']->to_display_date($date);?>
';
$trs='';
$tre='
';
$tds='';
$tde=' | ';
$tbs='';
$t.=$tbs;
$t.=$trs;
$t.=$tds1;
$t.="Nr.";
$t.=$tde;
$t.=$tds1;
$t.="Index";
$t.=$tde;
$t.=$tds1;
$t.="Nazwa";
$t.=$tde;
$t.=$tds1;
$t.="Faktura";
$t.=$tde;
$t.=$tds1;
$t.="Ilość";
$t.=$tde;
$t.=$tds1;
$t.="Cena";
$t.=$tde;
$t.=$tds1;
$t.="Razem netto";
$t.=$tde;
$t.=$tds1;
$t.="Razem Vat";
$t.=$tde;
$t.=$tds1;
$t.="Razem brutto";
$t.=$tde;
$t.=$tre;
$i=1;
$z="select ecminvoiceoutolditems.*,ecminvoiceoutolds.document_no as dno,ecminvoiceoutolds.id as sid,ecminvoiceoutolds.type as type,ecminvoiceoutolds.currency_value as currency_value from ecminvoiceoutolditems inner join ecminvoiceoutolds on ecminvoiceoutolditems.ecminvoiceoutold_id=ecminvoiceoutolds.id where ecminvoiceoutolds.deleted='0' and ecminvoiceoutolds.register_date>='".$date_from."' and ecminvoiceoutolds.register_date<='".$date_to."' and ecminvoiceoutolditems.deleted='0'";
$db = $GLOBALS['db'];
$w=$db->query($z);
echo $db->error;
while($r=$db->fetchByAssoc($w)){
if(!$r['currency_value'])$currency_value=1;
else $currency_value=$r['currency_value'];
$total_netto=$currency_value*$r['price']*$r['quantity'];
$total_vat=$currency_value*$r['price']*$r['quantity']*($r['ecmvat_value']/100);
$total_brutto=$currency_value*$r['price']*$r['quantity']*(1+$r['ecmvat_value']/100);
if($r['type']=="correct"){
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select price,quantity,ecmvat_value from ecminvoiceoutolditems where id='".$r['ecminvoiceoutolditem_id']."'"));
$total_netto-=$currency_value*$rr['price']*$rr['quantity'];
$total_vat-=$currency_value*$rr['price']*$rr['quantity']*($rr['ecmvat_value']/100);
$total_brutto-=$currency_value*$rr['price']*$rr['quantity']*(1+$rr['ecmvat_value']/100);
$r['price']=$currency_value*$rr['price'];
$r['quantity']-=$rr['quantity'];
}
if($r['quantity']==0)continue;
$t.=$trs;
$t.=$tds;
$t.=$i;
$t.=$tde;
$t.=$tds;
$t.=$r['code'];
$t.=$tde;
$t.=$tds;
$t.=''.$r['name'].'';
$t.=$tde;
$t.=$tds;
$t.=''.$r['dno'].'';
$t.=$tde;
$t.=$tds;
$t.=((int)$r['quantity']);
$t.=$tde;
$t.=$tds;
$t.=number_format($r['price'],2,",",".");
$t.=$tde;
$t.=$tds;
$t.=number_format($total_netto,2,",",".");
$t.=$tde;
$t.=$tds;
$t.=number_format($total_vat,2,",",".");
$t.=$tde;
$t.=$tds;
$t.=number_format($total_brutto,2,",",".");
$t.=$tde;
$t.=$tre;
//$sum_price+=$r['price'];
$sum_total_netto+=$total_netto;
$sum_total_vat+=$total_vat;
$sum_total_brutto+=$total_brutto;
$sum_qty+=$r['quantity'];
$i++;
}
$t.=$trs;
$t.=$tds1;
$t.=$tde;
$t.=$tds1;
$t.=$tde;
$t.=$tds1;
$t.=$tde;
$t.=$tds1;
$t.=$tde;
$t.=$tds1;
$t.=(int)$sum_qty;
$t.=$tde;
$t.=$tds1;
$t.=@number_format(($sum_total/$sum_qty),2,",",".");
$t.=$tde;
$t.=$tds1;
$t.=number_format($sum_total_netto,2,",",".");
$t.=$tde;
$t.=$tds1;
$t.=number_format($sum_total_vat,2,",",".");
$t.=$tde;
$t.=$tds1;
$t.=number_format($sum_total_brutto,2,",",".");
$t.=$tde;
$t.=$tre;
$t.=$tbe;
echo $t;
?>