403 lines
16 KiB
PHP
Executable File
403 lines
16 KiB
PHP
Executable File
<?
|
|
include_once("modules/EcmProductReports/vtigerConnector.php");
|
|
|
|
function getSales($code){
|
|
$sale0=0;
|
|
$sale30=0;
|
|
$sale90=0;
|
|
$sale180=0;
|
|
$qty0=0;
|
|
$qty30=0;
|
|
$qty90=0;
|
|
$qty180=0;
|
|
$ddate=date("Y-m-d",mktime()-365*24*3600);
|
|
//echo "select l.price as price,l.quantity as quantity,e.register_date as date from ecminvoiceoutitems as l inner join ecminvoiceouts as e on l.ecminvoiceout_id=e.id where l.code='".$code."' and e.type!='correct' and e.register_date>'".$ddate."' limit 100";
|
|
$w=mysql_query("select ecminvoiceoutitems.price as price,ecminvoiceoutitems.quantity as quantity,ecminvoiceouts.register_date as date from ecminvoiceoutitems inner join ecminvoiceouts on ecminvoiceoutitems.ecminvoiceout_id=ecminvoiceouts.id where ecminvoiceoutitems.ecmproduct_id='".$code."' and ecminvoiceouts.type!='correct' and ecminvoiceouts.register_date>'".$ddate."'");
|
|
//$w=mysql_query("select ecmproducts_fk_list.price as price,ecmproducts_fk_list.quantity as quantity,ecmproducts_fk_list.no as no,ecmproducts_fk_list.date as date from ecmproducts_fk_list where ecmproducts_fk_list.code like '".$code."'");
|
|
while($r=mysql_fetch_array($w)){
|
|
$date=date("Y-m");
|
|
$m=(int)date("m");
|
|
|
|
$date1=date("Y-m",mktime(0,0,0,($m-1),1,date("Y")));
|
|
$date2=date("Y-m",mktime(0,0,0,($m-2),1,date("Y")));
|
|
$date3=date("Y-m",mktime(0,0,0,($m-3),1,date("Y")));
|
|
|
|
$d=explode("-",$r['date']);
|
|
|
|
$dd=$d[0]."-".$d[1];
|
|
|
|
if($dd==$date){
|
|
$sale0+=$r['price']*$r['quantity'];
|
|
$qty0+=$r['quantity'];
|
|
$aq0[$r['no']]+=$r['quantity'];
|
|
}
|
|
if($dd==$date1 || $dd==$date2 || $dd==$date3){
|
|
$sale90+=$r['price']*$r['quantity'];
|
|
$qty90+=$r['quantity'];
|
|
$aq90[$r['no']]+=$r['quantity'];
|
|
}
|
|
//if($dd==$date1 || $dd==$date2 || $dd==$date3){
|
|
$sale1+=$r['price']*$r['quantity'];
|
|
$qty1+=$r['quantity'];
|
|
$aq1[$r['no']]+=$r['quantity'];
|
|
//}
|
|
}
|
|
|
|
if($qty0>0)$SALE_AVG_PRICE0=round($sale0/$qty0,2);
|
|
if($qty90>0)$SALE_AVG_PRICE90=round($sale90/$qty90,2);
|
|
|
|
return array(
|
|
"qty0"=>$qty0,
|
|
"qty90"=>($qty90/3),
|
|
"qty1"=>($qty1/12),
|
|
"sale0"=>$sale0,
|
|
"sale90"=>$sale90,
|
|
"sale1"=>$sale1,
|
|
"avg0"=>$SALE_AVG_PRICE0,
|
|
"avg90"=>$SALE_AVG_PRICE90,
|
|
);
|
|
}
|
|
|
|
$vc=new vtigerConnector();
|
|
$vc->start=$_GET['start']+1;
|
|
|
|
//$wc[]="purchaseorder.tracking_no=''";
|
|
$wh[]="1=1";
|
|
if($_GET['submit']){
|
|
if($_GET['product_category_id'])$wh[]="product_category_id='".$_GET['product_category_id']."'";
|
|
if($_GET['product_name'])$wh[]="name like '".$_GET['product_name']."%'";
|
|
if($_GET['product_code'])$wh[]="code like '".$_GET['product_code']."%'";
|
|
if($_GET['active']){
|
|
if($_GET['active']=="yes")$wh[]="product_active='1'";
|
|
if($_GET['active']=="no")$wh[]="product_active='0'";
|
|
}
|
|
if($_GET['production']){
|
|
if($_GET['production']=="yes")$wh[]="production='1'";
|
|
if($_GET['production']=="no")$wh[]="production='0'";
|
|
}
|
|
if($_GET['end_of_line']){
|
|
if($_GET['end_of_line']=="yes")$wh[]="end_of_line='1'";
|
|
if($_GET['end_of_line']=="no")$wh[]="end_of_line='0'";
|
|
}
|
|
}
|
|
//$vc->where=@implode(" and ",$wc);
|
|
if(!$_GET['start'])$limit="0,".$vc->pp;
|
|
else $limit=$_GET['start'].",".$vc->pp;
|
|
if($_GET['order_by'])$order_by=$_GET['order_by'];
|
|
else $order_by="name";
|
|
if($_GET['sorder'])$sorder=$_GET['sorder'];
|
|
else $sorder="desc";
|
|
|
|
//$vc->where=@implode(" and ",$wc);
|
|
$vc->getData();
|
|
$cnt=$vc->getCount();
|
|
$data=$vc->data;
|
|
|
|
|
|
for($i=0;$i<count($data);$i++){
|
|
if(!$dd_pom[strtoupper($data[$i]['productcode'])])$dd_pom[strtoupper($data[$i]['productcode'])]="9999-99-99";
|
|
if($_REQUEST['product_category_id'] || $_REQUEST['active']){
|
|
$cat=mysql_fetch_array(mysql_query("select product_category_id as cid,product_active from ecmproducts where code='".$data[$i]['productcode']."'"));
|
|
if($cat['cid']!=$_REQUEST['product_category_id'])continue;
|
|
if($cat['product_active']==0 && $_REQUEST['active']=="yes")continue;
|
|
if($cat['product_active']==1 && $_REQUEST['active']=="no")continue;
|
|
}
|
|
//if(strtoupper($data[$i]['productcode'])=="RE01633")echo $dat[strtoupper($data[$i]['productcode'])]['quantity']." <br>";
|
|
$qty_pom=$dat[strtoupper($data[$i]['productcode'])]['quantity'];
|
|
if($dat[strtoupper($data[$i]['productcode'])]['deliverydate'])$dd_pom[strtoupper($data[$i]['productcode'])]=$dat[strtoupper($data[$i]['productcode'])]['deliverydate'];
|
|
$dat[strtoupper($data[$i]['productcode'])]=$data[$i];
|
|
|
|
//$dat[strtoupper($data[$i]['productcode'])]['deliverydate']=$data[$i]['deliverydate'];
|
|
|
|
$dat[strtoupper($data[$i]['productcode'])]['quantity']=$qty_pom+$dat[strtoupper($data[$i]['productcode'])]['quantity'];
|
|
|
|
if($dd_pom[strtoupper($data[$i]['productcode'])]>$data[$i]['deliverydate'])$dat[strtoupper($data[$i]['productcode'])]['deliverydate']=$data[$i]['deliverydate'];
|
|
}
|
|
$data=$dat;
|
|
if($_REQUEST['die']==1){
|
|
echo '<pre>';
|
|
print_r($data);
|
|
echo '</pre>';
|
|
die();
|
|
}
|
|
|
|
|
|
$_SESSION['EcmProductReportsData']=$data;
|
|
?>
|
|
<table cellspacing="0" cellpadding="0" border="0"><tr><td width="19"><img src="themes/Sugar/images/EcmProducts.gif" style="margin-top: 3px; margin-right: 3px;" alt="EcmProducts" width="16" border="0" height="16"></td>
|
|
<td width="544"><h2>Products Reports: Products to orders </h2></td></tr></table><br />
|
|
<ul class="tablist">
|
|
<li>
|
|
<a class="current" href="#">Basic Search</a>
|
|
</li>
|
|
</ul>
|
|
<form action="index.php" method="get">
|
|
<input type="hidden" name="module" value="EcmProductReports" />
|
|
<input type="hidden" name="action" value="index1" />
|
|
<table style="border-top: 0px none; margin-bottom: 4px;" class="tabForm" width="100%" border="0" cellpadding="0" cellspacing="0">
|
|
<tbody>
|
|
<tr>
|
|
<td class="dataLabel" width="10%" nowrap="nowrap">
|
|
Product </td>
|
|
<td class="dataField" width="30%" nowrap="nowrap">
|
|
<input name="product_name" id="product_name" size="30" maxlength="255" value="<? echo $_GET['product_name'];?>" title="" tabindex="" type="text"> </td>
|
|
<td class="dataLabel" width="10%" nowrap="nowrap">
|
|
Code </td>
|
|
<td class="dataField" width="30%" nowrap="nowrap">
|
|
<input name="product_code" id="product_code" size="30" maxlength="255" value="<? echo $_GET['product_code'];?>" title="" tabindex="" type="text"> </td>
|
|
<td class="dataLabel" width="10%" nowrap="nowrap">
|
|
Category </td>
|
|
<td class="dataField" width="30%" nowrap="nowrap">
|
|
<select name="product_category_id">
|
|
<option value="">select</option>
|
|
<?php
|
|
$w=mysql_query("select id,name from ecmproductcategories where deleted='0' order by name");
|
|
while($r=mysql_fetch_array($w)){
|
|
echo '<option value="'.$r['id'].'"';
|
|
if($r['id']==$_GET['product_category_id'])echo " selected";
|
|
echo '>'.$r['name'].'</option>';
|
|
}
|
|
?>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="dataLabel" width="10%" nowrap="nowrap">
|
|
Active </td>
|
|
<td class="dataField" width="30%" nowrap="nowrap">
|
|
<select name="active">
|
|
<option value=""></option>
|
|
<option value="yes"<? if($_REQUEST['active']=="yes")echo " selected";?>>Yes</option>
|
|
<option value="no"<? if($_REQUEST['active']=="no")echo " selected";?>>No</option>
|
|
</select>
|
|
</td>
|
|
<td class="dataLabel" width="10%" nowrap="nowrap">
|
|
Production </td>
|
|
<td class="dataField" width="30%" nowrap="nowrap">
|
|
<select name="production">
|
|
<option value=""></option>
|
|
<option value="yes"<? if($_REQUEST['production']=="yes")echo " selected";?>>Yes</option>
|
|
<option value="no"<? if($_REQUEST['production']=="no")echo " selected";?>>No</option>
|
|
</select>
|
|
</td>
|
|
<td class="dataLabel" width="10%" nowrap="nowrap">
|
|
End of line </td>
|
|
<td class="dataField" width="30%" nowrap="nowrap">
|
|
<select name="end_of_line">
|
|
<option value=""></option>
|
|
<option value="yes"<? if($_REQUEST['end_of_line']=="yes")echo " selected";?>>Yes</option>
|
|
<option value="no"<? if($_REQUEST['end_of_line']=="no")echo " selected";?>>No</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<input class="button" name="submit" value="Search" type="submit">
|
|
<input class="button" name="clear" value="Clear" type="button" onclick="location.href='index.php?module=EcmProductReports&action=index';">
|
|
</form>
|
|
<table class="h3Row" width="100%" border="0" cellpadding="0" cellspacing="0">
|
|
<tbody>
|
|
<tr>
|
|
<td nowrap="nowrap">
|
|
<h3>Products List</h3>
|
|
</td>
|
|
<td width="100%">
|
|
<img src="include/images/blank.gif" alt="" width="1" height="1">
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<?
|
|
if($_GET['start']+$vc->pp>=$vc->count && $_GET['start']-$vc->pp>0){ // >= >=
|
|
$btns=array(0,0,0,0);
|
|
}
|
|
elseif($_GET['start']+$vc->pp<$vc->count && $_GET['start']-$vc->pp>=0){ // < >=
|
|
$btns=array(1,1,1,1);
|
|
}
|
|
elseif($_GET['start']+$vc->pp>=$vc->count){ // >= <
|
|
$btns=array(1,1,0,0);
|
|
}
|
|
elseif($_GET['start']+$vc->pp<$vc->count && $_GET['start']-$vc->pp<0){ // < <
|
|
$btns=array(0,0,1,1);
|
|
}
|
|
|
|
print '<form action="index.php" method="post">';
|
|
|
|
print '<input type="hidden" value="EcmProductReports" name="module">';
|
|
print '<input type="hidden" value="CreateXLS1" name="action">';
|
|
print '<input type="hidden" name="where" value="'.$vc->where.'">';
|
|
print '<input type="hidden" name="order_by" value="'.$order_by.'">';
|
|
print '<input type="hidden" name="sorder" value="'.$sorder.'">';
|
|
print '<input type="hidden" name="limit" value="'.$vc->limit.'">';
|
|
print '<input type="hidden" name="start" value="'.($vc->start-1).'">';
|
|
print '<input type="hidden" name="to_pdf" value="1">';
|
|
print '<div id="products_list">';
|
|
print '<script language="javascript">
|
|
function check_all_products(v){
|
|
var ch=document.getElementsByTagName("input");
|
|
for(var i=0;i<ch.length;i++){
|
|
if(ch[i].id!="chall"){
|
|
if(v==true){
|
|
ch[i].checked=true;
|
|
}
|
|
else{
|
|
ch[i].checked=false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>';
|
|
print '<table cellpadding="0" cellspacing="0" width="1300" border="0" class="ListView">';
|
|
?>
|
|
<tr>
|
|
<td colspan="9">
|
|
<table width="100%">
|
|
|
|
<tr>
|
|
<td width="50%">
|
|
<?
|
|
foreach($_GET as $k=>$v)$link.=$k."=".$v."&";
|
|
print '<input type="submit" value="Create XLS" class="button" onclick="location.href=\'index.php?'.$link.'&action=CreateXLS1"> ';
|
|
?>
|
|
</td>
|
|
<!--<td id="listViewPaginationButtons" class="listViewPaginationTdS1" width="100%" align="right" nowrap="nowrap">
|
|
<? //echo $vc->generateButtons($btns); ?>
|
|
</td>-->
|
|
</tr>
|
|
</table>
|
|
</td></tr>
|
|
<?
|
|
print '<tr>';
|
|
print '<td class="listViewThS1" width="1%"><input type="checkbox" id="chall" onclick="check_all_products(this.checked)" checked></td>';
|
|
|
|
print $vc->sortableColumn("Product","name",$_GET['sorder'],20,"index");
|
|
print $vc->sortableColumn("Code","code",$_GET['sorder'],5,"index");
|
|
print $vc->sortableColumn("Category","product_category_name",$_GET['sorder'],10,"index");
|
|
print $vc->sortableColumn("Inv pcs","ems_qty_in_stock",$_GET['sorder'],5,"index");
|
|
print $vc->sortableColumn("Ord pcs","name",$_GET['sorder'],7,"index");
|
|
print $vc->sortableColumn("Delivery Date","deliverydate",$_GET['sorder'],10,"index");
|
|
print $vc->sortableColumn("Inv+Ord","ems_qty_in_stock",$_GET['sorder'],7,"index");
|
|
print $vc->sortableColumn("Qty 12m","qty90",$_GET['sorder'],10,"index");
|
|
print $vc->sortableColumn("Qty this m","qty0",$_GET['sorder'],10,"index");
|
|
print $vc->sortableColumn("Stock m + ord","stock_month",$_GET['sorder'],7,"index");
|
|
print $vc->sortableColumn("Pricebook","name",$_GET['sorder'],10,"index");
|
|
print $vc->sortableColumn("Bestsell","name",$_GET['sorder'],7,"index");
|
|
print '</tr>';
|
|
|
|
include_once('modules/EcmCharts/chartHelper.php');
|
|
$s=sum(2009);
|
|
if($_GET['product_category_id'])$wh_cat=" and product_category_id='".$_GET['product_category_id']."'";
|
|
else $wh_cat="";
|
|
if($_GET['active']){
|
|
if($_GET['active']=="yes")$wh_act=" and product_active='1'";
|
|
if($_GET['active']=="no")$wh_act=" and product_active='0'";
|
|
}
|
|
else $wh_act="";
|
|
if($_GET['production']){
|
|
if($_GET['production']=="yes")$wh_p=" and production='1'";
|
|
if($_GET['production']=="no")$wh_p=" and production='0'";
|
|
}
|
|
else $wh_p="";
|
|
if($_GET['end_of_line']){
|
|
if($_GET['end_of_line']=="yes")$wh_e=" and end_of_line='1'";
|
|
if($_GET['end_of_line']=="no")$wh_e=" and end_of_line='0'";
|
|
}
|
|
else $wh_e="";
|
|
$w=mysql_query("select id,code,name from ecmproducts where deleted='0' and product_category_id is not null ".$wh_e." ".$wh_p." ".$wh_act." ".$wh_cat);
|
|
$i=0;
|
|
$sum=0;
|
|
echo mysql_error();
|
|
while($r=mysql_fetch_array($w)){
|
|
$ss=$s[2009];
|
|
|
|
if($ss['product_sum_'.$r['id']]-$ss['product_pur_sum_'.$r['id']]<0)$value=0;
|
|
else $value=$ss['product_sum_'.$r['id']]-$ss['product_pur_sum_'.$r['id']];
|
|
|
|
$sum+=$value;
|
|
$ii++;
|
|
|
|
$arr[]=array(
|
|
"name"=>$r['code'],
|
|
"name1"=>$r['name'],
|
|
"value"=>$value,
|
|
);
|
|
}
|
|
$arr=multisort($arr,array(array('key'=>'value','sort'=>'desc')));
|
|
$i=0;
|
|
if(count($arr)>0){
|
|
foreach($arr as $best){
|
|
if($best['value']>$sum/$ii)$bests[]=$best['name'];
|
|
$i++;
|
|
}
|
|
}
|
|
$w=mysql_query("select * from ecmproducts where deleted='0' and product_category_id is not null and ".implode(" and ",$wh)." order by ".$order_by." ".$sorder);
|
|
print '<tbody style="overflow: auto;height:500px;">';
|
|
while($r=mysql_fetch_array($w)){
|
|
$id=$r['id'];
|
|
//if(mysql_num_rows(mysql_query("select id from ecmproductcomponents where ecmproduct_id='".$id."' and deleted='0'"))>0)continue;
|
|
$gs=getSales($id);
|
|
|
|
$inv_value=$r['ems_qty_in_stock'];
|
|
$inv_qty=$r['ems_qty_in_stock'];
|
|
$inv_price=$r['ems_price'];
|
|
|
|
|
|
$deliverydate=$data[strtoupper($r['code'])]['deliverydate'];
|
|
|
|
$_ord=0;
|
|
//if(!$data[$r['code']."_S"]['quantity']){
|
|
//$ww=mysql_query("select ordered from ecmproducts where code like '".$r['code']."_S' and deleted='0'");
|
|
//while($rr=mysql_fetch_array($ww))$_ord+=$rr['ordered'];
|
|
//}
|
|
//else{
|
|
//$_ord+=$data[$r['code']."_S"]['quantity'];
|
|
//$_ord+=$data[$r['code']."_s"]['quantity'];
|
|
//}
|
|
$_ord+=$data[strtoupper($r['code'])."_S"]['quantity'];
|
|
$_ord+=$data[strtoupper($r['code'])."_s"]['quantity'];
|
|
$_ord+=$data[strtoupper($r['code'])]['quantity'];
|
|
|
|
print '<tr>';
|
|
print '<td class="oddListRowS1" width="1%"><input type="checkbox" value="1" name="check['.$i.']" checked></td>';
|
|
print '<td class="oddListRowS1" width="20%"><a href="index.php?module=EcmProducts&action=DetailView&record='.$id.'">'.$r['name'].'</a></td>';
|
|
print '<td class="oddListRowS1" width="5%">'.$r['code'].'</td>';
|
|
print '<td class="oddListRowS1" width="10%"><a href="index.php?module=EcmProductCategories&action=DetailView&record='.$r['product_category_id'].'">'.$r['product_category_name'].'</a></td>';
|
|
if(@in_array($r['code'],$bests))$b="B";
|
|
else $b="";
|
|
print '<td class="oddListRowS1" width="5%">'.number_format($inv_value,0,"","").'</td>';
|
|
print '<td class="oddListRowS1" width="7%">'.number_format($_ord,0,"","").'</td>';
|
|
print '<td class="oddListRowS1" width="10%">'.$vc->timeDate($deliverydate).'</td>';
|
|
print '<td class="oddListRowS1" width="5%">'.number_format(($inv_qty+$_ord),0,"","").'</td>';
|
|
print '<td class="oddListRowS1" width="10%">'.number_format(($gs['qty1']),0,"","").'</td>';
|
|
print '<td class="oddListRowS1" width="10%">'.number_format(($gs['qty0']),0,"","").'</td>';
|
|
if($gs['qty1']>$gs['qty0'])$avg=$gs['qty1'];
|
|
else $avg=$gs['qty0'];
|
|
if($avg)@$stockm=number_format(floor(($inv_value+$_ord)/($avg)),0,"","");
|
|
else $stockm="err";
|
|
mysql_query("update ecmproducts set stock_month='".$stockm."',qty0='".$gs['qty0']."',qty90='".$gs['qty1']."' where id='".$r['id']."'");
|
|
|
|
//if(($deliverydate<$pom[$r['id']] || !$pom[$r['id']]) && $deliverydate)$pom[$r['id']]=$deliverydate;
|
|
|
|
//if($pom[$r['id']])mysql_query("update ecmproducts set deliverydate='".$pom[$r['id']]."' where id='".$r['id']."'");
|
|
|
|
print '<td class="oddListRowS1" width="7%">'.$stockm.'</td>';
|
|
//pricebook
|
|
$accounts=array("Auchan","Carrefour","Euro","Real");
|
|
$dig=array();
|
|
foreach($accounts as $account){
|
|
$www=mysql_query("select p.id from ecmpricebooks_ecmproducts as p inner join ecmpricebooks as e on e.id=p.ecmpricebook_id where p.ecmproduct_id='".$id."' and e.name='".$account."' and e.deleted='0' and p.deleted='0'");
|
|
if(mysql_num_rows($www)>0)$dig[]=$account[0];
|
|
}
|
|
print '<td class="oddListRowS1" width="10%">'.implode(",",$dig).'</td>';
|
|
print '<td class="oddListRowS1" width="7%">'.$b.'</td>';
|
|
|
|
|
|
print '</tr>';
|
|
}
|
|
print '</tbody>';
|
|
print '</table>';
|
|
print '</div>';
|
|
print '</form>';
|
|
|
|
?>
|