session_start(); $db = $GLOBALS['db']; $account=$_GET['account']; $account_id=$_GET['account_id']; $account_name=$_GET['account_name']; $type=$_GET['type']; 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"); ?>
Raport sprzedaży po kategorii |
'."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 ''.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; ?>