query("select id from ecmproducts where product_active='1' and deleted='0' order by product_category_name asc,code asc"); while($r=$db->fetchByAssoc($w)){ $ww=$db->query("select id from accounts where deleted='0' and core_client='1' order by name asc"); while($rr=$db->fetchByAssoc($ww)){ $rrr=$db->fetchByAssoc($db->query("select count(*) as cnt from ecmforecasts where ecmproduct_id='".$r['id']."' and account_id='".$rr['id']."'")); if($_REQUEST['pred'][$r['id']][$rr['id']]!=0){ $value=$_REQUEST['pred'][$r['id']][$rr['id']]; if($rrr['cnt']>0){ $db->query("update ecmforecasts set value='".$value."' where ecmproduct_id='".$r['id']."' and account_id='".$rr['id']."'"); } else{ $db->query("insert into ecmforecasts set id='".create_guid()."',ecmproduct_id='".$r['id']."',account_id='".$rr['id']."',value='".$value."'"); } } } $rrr=$db->fetchByAssoc($db->query("select count(*) as cnt from ecmforecasts where ecmproduct_id='".$r['id']."' and account_id='new'")); if($_REQUEST['pred'][$r['id']]["new"]!=0){ $value=$_REQUEST['pred'][$r['id']]["new"]; if($rrr['cnt']>0){ $db->query("update ecmforecasts set value='".$value."' where ecmproduct_id='".$r['id']."' and account_id='new'"); } else{ $db->query("insert into ecmforecasts set id='".create_guid()."',ecmproduct_id='".$r['id']."',account_id='new',value='".$value."'"); } } } header("Location: index.php?module=EcmReports&action=Forecast&category=".$_REQUEST['category']); } ?>
EcmProducts

Charts: Products


Year Category

'; $tre=''; $tds=''; $tds_left=''; $tds_l=''; $tds_cat=''; $tds_inv=''; $tds_name=''; $tds_index=''; $tds_total=''; $tds_account=''; $tds_account_new=''; $tbs=''; $tbe='
'; $tde=''; $tdr=''; include_once("modules/EcmReports/class.sales.php"); $w=$db->query("select id from accounts where deleted='0' and core_client='1'"); if(!$_REQUEST['year'])$_REQUEST['year']=date("Y"); while($r=$db->fetchByAssoc($w)){ $s=new Sales(); $s->date_from=$_REQUEST['year']."-01-01"; $s->date_to=$_REQUEST['year']."-12-31"; $s->account_id=$r['id']; $s->product_active="active"; $sdata[$r['id']]=$s->getSalesByProductForecast(); } echo ''; echo ''; echo ''; $t.='


'; $t.=$tbs; $t.=$trs; $t.=$tds_index."Index".$tde; $t.=$tds_name."Name".$tde; $t.=$tds_cat."Category".$tde; $t.=$tds_inv."Inventory".$tde; $t.=$tds_cat."SRP price".$tde; $t.=$tds_total."Total".$tde; $w=$db->query("select name from accounts where deleted='0' and core_client='1' order by name asc"); while($r=$db->fetchByAssoc($w)){ $t.=$tds_account.$r['name'].$tde; } $t.=$tds_account_new."New clients".$tde; $t.=$tre; $t.=$trs; $t.=$tds_index." ".$tde; $t.=$tds_name." ".$tde; $t.=$tds_cat." ".$tde; $t.=$tds_cat."Qty".$tde; $t.=$tds_cat."Price".$tde; $t.=$tds_cat."Value".$tde; $t.=$tds_cat." ".$tde; $t.=$tds_cat."Sales".$tde; $t.=$tds_cat."Qty".$tde; $t.=$tds_cat."Pred. sales".$tde; $t.=$tds_cat."Pred. qty".$tde; $w=$db->query("select name from accounts where deleted='0' and core_client='1' order by name asc"); while($r=$db->fetchByAssoc($w)){ $t.=$tds_l."Avg. price".$tde; $t.=$tds_l."Qty".$tde; $t.=$tds_l."Sales".$tde; $t.=$tds_l."Pred. qty".$tde; $t.=$tds_l."Pred. sales".$tde; } $t.=$tds_l."Avg. price".$tde; $t.=$tds_l."Qty".$tde; $t.=$tds_l."Prediction".$tde; $t.=$tre; function getTotalFromAccounts($d,$id,$type="sales"){ global $db; $ww=$db->query("select name,id from accounts where deleted='0' and core_client='1' order by name asc"); while($rr=$db->fetchByAssoc($ww)){ $total+=$d[$rr['id']][$id][$type]; } return $total; } if($_REQUEST['category'])$wh_cat=" and product_category_id='".$_REQUEST['category']."'"; else $wh_cat=""; $w=$db->query("select ems_price,ems_qty_in_stock,id,name,code,product_category_name,product_category_id,srp_price from ecmproducts where product_active='1' and production!='1'".$wh_cat." and deleted='0' order by product_category_name asc,code asc"); while($r=$db->fetchByAssoc($w)){ $m++; $t.=$trs; $t.=$tds_left.$r['code'].$tde; $t.=$tds_left.''.$r['name'].''.$tde; $t.=$tds.''.$r['product_category_name'].''.$tde; $t.=$tds.number_format($r['ems_qty_in_stock'],0,",",".").$tde; $t.=$tds.number_format($r['ems_price'],2,",",".").$tde; $t.=$tds.number_format($r['ems_price']*$r['ems_qty_in_stock'],2,",",".").$tde; $t.=$tds.'
'.number_format($r['srp_price'],2,",",".").'
'.$tde; $t.=$tds.number_format(getTotalFromAccounts($sdata,$r['id']),2,",",".").$tde; $t.=$tds.number_format(getTotalFromAccounts($sdata,$r['id'],"quantity"),0,",",".").$tde; $t.=$tds.'
'.$tde; $t.=$tds.'
'.$tde; $total_srp_price+=$r['srp_price']; $total_ems_qty+=$r['ems_qty_in_stock']; $total_ems_price+=$r['ems_qty_in_stock']; $total_ems_value+=$r['ems_qty_in_stock']*$r['ems_price']; $total_sales+=getTotalFromAccounts($sdata,$r['id']); $total_qty+=getTotalFromAccounts($sdata,$r['id'],"quantity"); $ww=$db->query("select name,id from accounts where deleted='0' and core_client='1' order by name asc"); while($rr=$db->fetchByAssoc($ww)){ if($sdata[$rr['id']][$r['id']]['quantity']>0)$aprice=$sdata[$rr['id']][$r['id']]['sales']/$sdata[$rr['id']][$r['id']]['quantity']; else $aprice=0; if($aprice==0){ $rpb=$db->fetchByAssoc($db->query("select price from ecmpricebooks_ecmproducts where active=1 and account_id='".$rr['id']."' and ecmproduct_id='".$r['id']."' and deleted='0'")); $aprice=$rpb['price']; } if($aprice==0){ $rpb=$db->fetchByAssoc($db->query("select price from ecmpricebooks_ecmproducts where ecmpricebook_id='7b840616-a226-4a15-a831-4d11f116995a' and ecmproduct_id='".$r['id']."' and deleted='0'")); $aprice=$rpb['price']; } $t.=$tds.''.number_format($aprice,2,",",".").$tde; $t.=$tds.number_format($sdata[$rr['id']][$r['id']]['quantity'],0,",",".").$tde; $t.=$tds.number_format($sdata[$rr['id']][$r['id']]['sales'],2,",",".").$tde; $rrr=$db->fetchByAssoc($db->query("select value from ecmforecasts where ecmproduct_id='".$r['id']."' and account_id='".$rr['id']."'")); $pred=(int)$rrr['value']; $t.=$tds.''.$tde; $t.=$tds.'
'.number_format($rrr['value']*round($aprice,2),2,",",".").'
'.$tde; $totals_quantity[$rr['id']]+=$sdata[$rr['id']][$r['id']]['quantity']; $totals_sales[$rr['id']]+=$sdata[$rr['id']][$r['id']]['sales']; $totals_pred[$rr['id']]+=$rrr['value']*round($aprice,2); $totals_pred_qty[$rr['id']]+=$rrr['value']; } if(getTotalFromAccounts($sdata,$r['id'],"quantity")>0)$avg_price=getTotalFromAccounts($sdata,$r['id'])/getTotalFromAccounts($sdata,$r['id'],"quantity"); else $avg_price=0; if($avg_price==0){ $rpb=$db->fetchByAssoc($db->query("select price from ecmpricebooks_ecmproducts where ecmpricebook_id='7b840616-a226-4a15-a831-4d11f116995a' and ecmproduct_id='".$r['id']."' and deleted='0'")); $avg_price=$rpb['price']; } $t.=$tds.''.number_format($avg_price,2,",",".").$tde; $rrr=$db->fetchByAssoc($db->query("select value from ecmforecasts where ecmproduct_id='".$r['id']."' and account_id='new'")); $pred=(int)$rrr['value']; $t.=$tds.''.$tde; $t.=$tds.'
'.number_format($rrr['value']*round($avg_price,2),2,",",".").'
'.$tde; $totals_pred["new"]+=$rrr['value']*round($avg_price,2); $totals_pred_qty["new"]+=$rrr['value']; $t.=$tre; } $t.=''; $t.=$tds_left." ".$tde; $t.=$tds_left." ".$tde; $t.=$tds." ".$tde; $t.=$tds.number_format($total_ems_qty,0,",",".").$tde; $t.=$tds.number_format($total_ems_value/$total_ems_qty,2,",",".").$tde; $t.=$tds.number_format($total_ems_value,2,",",".").$tde; $t.=$tds.number_format($total_srp_price/$m,2,",",".").$tde; $t.=$tds.number_format($total_sales,2,",",".").$tde; $t.=$tds.number_format($total_qty,0,",",".").$tde; $t.=$tds.'
'.$tde; $t.=$tds.'
'.$tde; $ww=$db->query("select name,id from accounts where deleted='0' and core_client='1' order by name asc"); while($rr=$db->fetchByAssoc($ww)){ $t.=$tds.@number_format($totals_sales[$rr['id']]/$totals_quantity[$rr['id']],2,",",".").$tde; $t.=$tds.number_format($totals_quantity[$rr['id']],0,",",".").$tde; $t.=$tds.number_format($totals_sales[$rr['id']],2,",",".").$tde; $t.=$tds.'
'.number_format($totals_pred_qty[$rr['id']],0,",",".").'
'.$tde; $t.=$tds.'
'.number_format($totals_pred[$rr['id']],2,",",".").'
'.$tde; } $t.=$tds.@number_format($totals_pred["new"]/$totals_pred_qty["new"],2,",",".").$tde; $t.=$tds.number_format($totals_pred_qty["new"],0,",",".").$tde; $t.=$tds.number_format($totals_pred["new"],2,",",".").$tde; $t.=$tre; $t.=$tbe; $t.=''; echo $t; ?>