85 lines
3.5 KiB
PHP
85 lines
3.5 KiB
PHP
|
|
<?php
|
||
|
|
$months=array("01","02","03","04","05","06","07","08","09","10","11","12");
|
||
|
|
$months_names=array("01"=>"January","02"=>"February","03"=>"March","04"=>"April","05"=>"May","06"=>"June","07"=>"July","08"=>"August","09"=>"September","10"=>"October","11"=>"November","12"=>"December");
|
||
|
|
include_once("modules/EcmReports/cache.php");
|
||
|
|
$as=sum($_REQUEST['year'],$_REQUEST['account'],"",$_REQUEST['id'],$_REQUEST['active']);
|
||
|
|
$_REQUEST['mmm']=(int)date("m")-1;
|
||
|
|
$act="";
|
||
|
|
if($_REQUEST['active']=="active")$act=" and product_active='1'";
|
||
|
|
elseif($_REQUEST['active']=="active")$act=" and product_active='0'";
|
||
|
|
$zz="select id,name,code from ecmproducts where product_category_id='".$_REQUEST['id']."' and deleted='0'".$act." order by code asc";
|
||
|
|
$ww=$GLOBALS['db']->query($zz);
|
||
|
|
while($rr=$GLOBALS['db']->fetchByAssoc($ww)){
|
||
|
|
$t.=$trs;
|
||
|
|
|
||
|
|
$avg_p=0;
|
||
|
|
$avg_p_qty=0;
|
||
|
|
$avg_p_pur=0;
|
||
|
|
|
||
|
|
$sumy=getSum($as,$_REQUEST['year'],$rr['id'],$_REQUEST['id']);
|
||
|
|
//for($i=0;$i<count($months);$i++){
|
||
|
|
$avg_p_qty+=$sumy["qty"];
|
||
|
|
$avg_p+=$sumy["total"];
|
||
|
|
$avg_p_pur+=$sumy["total_purchase"];
|
||
|
|
//}
|
||
|
|
|
||
|
|
for($i=0;$i<count($months);$i++){
|
||
|
|
$sum=getSum($as,$_REQUEST['year']."-".$months[$i],$rr['id'],$_REQUEST['id']);
|
||
|
|
$p_pur=$sum["total_purchase"];
|
||
|
|
$p_qty=$sum["qty"];
|
||
|
|
$p=$sum["total"];
|
||
|
|
$cbm=$sum["cbm"];
|
||
|
|
|
||
|
|
|
||
|
|
if($p)$margin=100*($p-$p_pur)/$p;
|
||
|
|
else $margin=0;
|
||
|
|
|
||
|
|
if(!$p)$p=number_format(0,2,",",".");
|
||
|
|
|
||
|
|
|
||
|
|
$rvs=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select value from ecmsalesreports_predictions_cat where account_id='".$_REQUEST['account']."' and year='".$_REQUEST['year']."' and month='".$i."' and bean_id='".$rr['id']."' and type='sale'"));
|
||
|
|
$rvq=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select value from ecmsalesreports_predictions_cat where account_id='".$_REQUEST['account']."' and year='".$_REQUEST['year']."' and month='".$i."' and bean_id='".$rr['id']."' and type='qty'"));
|
||
|
|
|
||
|
|
$ajax_cat=ajaxWindow($rr['id'],$i,$rvs['value'],$_REQUEST['account'],"sale",$year);
|
||
|
|
$ajax_cat_qty=ajaxWindow($rr['id'],$i,$rvq['value'],$_REQUEST['account'],"qty",$year);
|
||
|
|
|
||
|
|
$t.=$tdsf1.number_format($p_qty,2,",",".").$tde;
|
||
|
|
$t.=$tdsf2.number_format($avg_p_qty/$_REQUEST['mmm'],0,"","").$tde;
|
||
|
|
|
||
|
|
|
||
|
|
$t.=$tdsf2.number_format($p,2,",",".").$tde;
|
||
|
|
$t.=$tdsf2.number_format($avg_p/$_REQUEST['mmm'],2,",",".").$tde;
|
||
|
|
$t.=$tdsf2.number_format($p_pur,2,",",".").$tde;
|
||
|
|
$t.=$tdsf2.number_format($avg_p_pur/$_REQUEST['mmm'],2,",",".").$tde;
|
||
|
|
$t.=$tdsf2.number_format($margin,2,",",".")."%".$tde;
|
||
|
|
$t.=$tdsf2.number_format($cbm,2,",",".").$tde;
|
||
|
|
$t.=$tdsf2.$ajax_cat.$tde;
|
||
|
|
$t.=$tdsf2.$ajax_cat_qty.$tde;
|
||
|
|
}
|
||
|
|
|
||
|
|
$s_pur=$sumy["total_purchase"];
|
||
|
|
$s_qty=$sumy["total_qty"];
|
||
|
|
$s=$sumy["total"];
|
||
|
|
$cbm=$sumy["cbm"];
|
||
|
|
|
||
|
|
if($s)$margin=100*($s-$s_pur)/$s;
|
||
|
|
else $margin=0;
|
||
|
|
|
||
|
|
if(!$s)$s=number_format(0,2,",",".");
|
||
|
|
|
||
|
|
$t.=$tdsfs1.'<strong>'.number_format(($sumy["qty"]),0,"","").'</strong>'.$tde;
|
||
|
|
$t.=$tdsfs2.number_format($avg_p_qty/$_REQUEST['mmm'],0,"","").$tde;
|
||
|
|
$t.=$tdsfs2.'<strong>'.number_format($s,2,",",".").'</strong>'.$tde;
|
||
|
|
$t.=$tdsfs2.number_format($avg_p/$_REQUEST['mmm'],2,",",".").$tde;
|
||
|
|
$t.=$tdsfs2.'<strong>'.number_format($s_pur,2,",",".").'</strong>'.$tde;
|
||
|
|
$t.=$tdsfs2.number_format($avg_p_pur/$_REQUEST['mmm'],2,",",".").$tde;
|
||
|
|
$t.=$tdsfs2.'<strong>'.number_format($margin,2,",",".").'%</strong>'.$tde;
|
||
|
|
$t.=$tdsfs2.'<strong>'.number_format($cbm,2,",",".").'</strong>'.$tde;
|
||
|
|
$t.=$tdsfs2.number_format($avg_p/$_REQUEST['mmm'],2,",",".").$tde;
|
||
|
|
$t.=$tdsfs2.number_format($avg_p_qty/$_REQUEST['mmm'],0,"","").$tde;
|
||
|
|
|
||
|
|
|
||
|
|
$t.=$tre;
|
||
|
|
}
|
||
|
|
echo $t;
|
||
|
|
?>
|