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"); ?>
EcmProducts

Raport sprzedaży po kategorii


Data od Enter Date Data do Enter Date Kategoria Typ dokumentu
0 && count($account)<2){ foreach ($account as $item){ $ids="&account[]=".$item.""; } } else { foreach ($account as $item){ $ids.="&account[]=".$item.""; } } echo ' '; unset($ids); ?>

'; $trs=''; $tre=''; $tds=''; $tde=''; $tbs=''; $tbe='
'; $t.=$tbs; $t.=$trs; $t.=$tds1; $t.="Produkt"; $t.=$tde; $t.=$tds1; $t.="Kod"; $t.=$tde; $t.=$tds1; $t.='

'."Ilość".'

'; $t.=$tde; $t.=$tds1; $t.='

'."Kwota".'

'; $t.=$tde; $t.=$tds1; $t.='

'."Szczegóły".'

'; $t.=$tde; $t.=$tds1; $t.='

'."Kategoria".'

'; $t.=$tde; $t.=$tre; $i=1; $wh[]="fk.deleted='0'"; $wh[]="fk.canceled='0'"; if($type)$wh[]="fk.type='".$type."'"; //note that sel1[] is now $sel1 $ids=array(); unset($_SESSION); if(count($account)>0 && count($account)<2){ foreach ($account as $item){ $wh[]="cat.id='".$item."'"; $_SESSION['zaznaczone'][]=$item; } } else { foreach ($account as $item){ $ids[]="'".$item."'"; } $ac=implode(",",$ids); $wh[]='cat.id IN ('.$ac.')'; } if($date_from)$wh[]="fk.register_date>='".$date_from."'"; if($date_to)$wh[]="fk.register_date<='".$date_to."'"; $where=implode(" and ",$wh); //Print out the selection $z="select fk.id,p.name,p.code,p.ecmproduct_id, sum( CASE WHEN fk.type!='correct' THEN CASE WHEN fk.currency_value is null or fk.currency_value='' or fk.currency_value=0 THEN p.subtotal ELSE p.subtotal*fk.currency_value END ELSE CASE WHEN p.old_subtotal IS null OR p.old_subtotal='' THEN 0 ELSE CASE WHEN fk.currency_value is null or fk.currency_value='' or fk.currency_value=0 THEN p.subtotal-p.old_subtotal ELSE (p.subtotal-p.old_subtotal)*fk.currency_value END END END ) as razem, sum( CASE WHEN fk.type!='correct' THEN p.quantity ELSE p.quantity-p.old_quantity END ) as quantity,p.subprice,cat.name as cname,cat.id as cid from ecminvoiceouts as fk inner join ecminvoiceoutitems as p on p.ecminvoiceout_id=fk.id inner join ecmproducts as pr on pr.id=p.ecmproduct_id inner join ecmproductcategories as cat on cat.id=pr.product_category_id where ".$where." group by p.ecmproduct_id order by pr.product_category_id,razem desc;"; $w=$db->query($z); echo '
'.$w->num_rows.'
'; echo mysql_error(); $ilosc=0; $razem=0; $microtime=str_replace(".","",str_replace(" ","",microtime())); $name='fakury_'.$microtime; $fp = fopen('modules/EcmReports/TXT/'.$name.'.txt', 'w'); fwrite($fp, 'RaportCat'."\n"); $abc=0; $note=""; $sum=array(); while($r=$db->fetchByAssoc($w)){ $z2="select fk.id,p.name,p.code,p.ecmproduct_id, sum( CASE WHEN fk.type!='correct' THEN CASE WHEN fk.currency_value is null or fk.currency_value='' or fk.currency_value=0 THEN p.subtotal ELSE p.subtotal*fk.currency_value END ELSE CASE WHEN p.old_subtotal IS null OR p.old_subtotal='' THEN 0 ELSE CASE WHEN fk.currency_value is null or fk.currency_value='' or fk.currency_value=0 THEN p.subtotal-p.old_subtotal ELSE (p.subtotal-p.old_subtotal)*fk.currency_value END END END ) as razem, sum( CASE WHEN fk.type!='correct' THEN p.quantity ELSE p.quantity-p.old_quantity END ) as quantity,p.subprice,fk.parent_id,fk.parent_name from ecminvoiceouts as fk inner join ecminvoiceoutitems as p on p.ecminvoiceout_id=fk.id inner join ecmproducts as pr on pr.id=p.ecmproduct_id inner join ecmproductcategories as cat on cat.id=pr.product_category_id where ".$where." and p.ecmproduct_id='".$r['ecmproduct_id']."' group by fk.parent_id order by razem desc;"; $w2=$db->query($z2); $note.=''; $b=$r['cid']; $sum[$b]['total']+=$r['razem']; $sum[$b]['quantity']+=$r['quantity']; $sum[$b]['cat']=$r['cname']; $sum[$b]['c']=0; foreach($sum as $k=>$v ){ if(($k!=$r['cid'] && $sum[$k]['c']==0)){ $t.=$trs; //if($sum_total_netto-$sum_total_margin>0)$sum_margin=100*$sum_total_margin/($sum_total_netto-$sum_total_margin); //else $sum_margin=0; $t.=$tds1; $t.="Podsumowanie ".$sum[$k]['cat']; $t.=$tde; $t.=$tds1; $t.=""; $t.=$tde; $t.=$tds1; $t.='

'.format_number($sum[$k]['quantity']).'

'; $t.=$tde; $t.=$tds1; $t.='

'.format_number($sum[$k]['total']).'

'; $t.=$tde; $t.=$tds; $t.=''; $t.=$tde; $t.=$tre; $sum[$k]['c']=1; } } $t.=$trs; $t.=$tds; $t.=''.$r['name'].''; $t.=$tde; $t.=$tds; $t.=$r['code']; $t.=$tde; $t.=$tds; $t.='

'.format_number($r['quantity']).'

'; $t.=$tde; $t.=$tds; $t.='

'.format_number($r['razem']).'

'; $t.=$tde; $t.=$tds; $show='

'; $t.=$show; $t.=$tde; $t.=$tds; $t.='

'.$r['cname'].'

'; $t.=$tde; $t.=$tre; $ilosc+=$r['quantity']; $razem+=$r['razem']; foreach($sum as $k=>$v ){ if(($w->num_rows==$i && $sum[$k]['c']==0)){ $t.=$trs; //if($sum_total_netto-$sum_total_margin>0)$sum_margin=100*$sum_total_margin/($sum_total_netto-$sum_total_margin); //else $sum_margin=0; $t.=$tds1; $t.="Podsumowanie ".$sum[$k]['cat']; $t.=$tde; $t.=$tds1; $t.=""; $t.=$tde; $t.=$tds1; $t.='

'.format_number($sum[$k]['quantity']).'

'; $t.=$tde; $t.=$tds1; $t.='

'.format_number($sum[$k]['total']).'

'; $t.=$tde; $t.=$tds; $t.=''; $t.=$tde; $t.=$tre; $sum[$k]['c']=1; } } $i++; $abc++; } fclose($fp); $t.=$trs; //if($sum_total_netto-$sum_total_margin>0)$sum_margin=100*$sum_total_margin/($sum_total_netto-$sum_total_margin); //else $sum_margin=0; $t.=$tds1; $t.="Podsumowanie"; $t.=$tde; $t.=$tds1; $t.=" "; $t.=$tde; $t.=$tds1; $t.='

'.format_number($ilosc).'

'; $t.=$tde; $t.=$tds1; $t.='

'.format_number($razem).'

'; $t.=$tde; $t.=$tre; $t.=$tbe; echo $t; if(isset($_REQUEST['txt'])){ // send the right headers header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename('modules/EcmReports/TXT/'.$name.'.txt')); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize('modules/EcmReports/TXT/'.$name.'.txt')); ob_clean(); flush(); readfile('modules/EcmReports/TXT/'.$name.'.txt'); exit; // dump the picture and stop the script } echo $note; ?>