382 lines
13 KiB
PHP
Executable File
382 lines
13 KiB
PHP
Executable File
<?
|
|
if(!$_REQUEST['date'])$date=date("Y-m-d");
|
|
else $date=$GLOBALS['timedate']->to_db_date($_REQUEST['date']);
|
|
$exp=explode("-",$date);
|
|
$date=date("Y-m-d",mktime(0,0,0,$exp[1],$exp[2],$exp[0])+24*3600);
|
|
|
|
//$date = null;
|
|
if(!$date)$date=date("Y-m-d");
|
|
include_once("modules/EcmProductReports/vtigerConnector.php");
|
|
include_once('modules/EcmCharts/chartHelper.php');
|
|
$vc=new vtigerConnector();
|
|
set_include_path('include/PHPExcel/');
|
|
|
|
include 'PHPExcel.php';
|
|
//include 'PHPExcel/Writer/Excel2007.php';
|
|
include 'PHPExcel/Writer/Excel5.php';
|
|
include 'PHPExcel/IOFactory.php';
|
|
|
|
$objPHPExcel = new PHPExcel();
|
|
$objPHPExcel->getProperties()->setCreator("E5 CRM");
|
|
$objPHPExcel->getProperties()->setLastModifiedBy("E5 CRM");
|
|
$objPHPExcel->getProperties()->setTitle("Office 2007 STATES");
|
|
$objPHPExcel->getProperties()->setSubject("Office 2007 STATES");
|
|
$objPHPExcel->getProperties()->setDescription("STATES");
|
|
|
|
$alf="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
|
|
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
|
|
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
|
|
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
|
|
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
|
|
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
|
|
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
|
|
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
|
|
|
|
|
|
$objPHPExcel->getActiveSheet()->setTitle('Simple');
|
|
$objPHPExcel->setActiveSheetIndex(0);
|
|
|
|
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("A1","Inventory states: ".$dat);
|
|
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("A2","Index");
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("B2","Name");
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("C2","Category");
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("D2","Quantity");
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("E2","Unit");
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("F2","Price");
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("G2","Value");
|
|
?>
|
|
<table cellspacing="0" cellpadding="0" border="0"><tr><td><img src="themes/Sugar/images/EcmProducts.gif" style="margin-top: 3px; margin-right: 3px;" alt="EcmProducts" width="16" border="0" height="16"></td><td><h2>Inventory States:</h2></td></tr></table><br />
|
|
<ul class="tablist" style="width:100%;">
|
|
<li>
|
|
<a class="current" href="#">Basic Search</a>
|
|
</li>
|
|
</ul>
|
|
<form action="index.php" method="get">
|
|
<input type="hidden" name="module" value="EcmStockStates" />
|
|
<input type="hidden" name="action" value="ListStates" />
|
|
<input type="hidden" name="order_by" value="<?php echo $_REQUEST['order_by'];?>" />
|
|
<input type="hidden" name="sorder" value="<?php echo $_REQUEST['sorder'];?>" />
|
|
<table style="border-top: 0px none; margin-bottom: 4px;width:100%" class="tabForm" border="0" cellpadding="0" cellspacing="0">
|
|
<tbody>
|
|
<tr>
|
|
<td class="dataLabel" width="10%" nowrap="nowrap">
|
|
Inventory</td>
|
|
<td class="dataField" width="30%" nowrap="nowrap">
|
|
<select name="stock_id">
|
|
<option value="">select</option>
|
|
<?php
|
|
$w=$GLOBALS['db']->query("select id,name from ecmstocks where deleted='0' order by name asc");
|
|
while($r=$GLOBALS['db']->fetchByAssoc($w)){
|
|
echo '<option value="'.$r['id'].'"';
|
|
if($r['id']==$_GET['stock_id'])echo ' selected';
|
|
echo '>'.$r['name'].'</option>';
|
|
}
|
|
?>
|
|
</select> </td>
|
|
<td class="dataLabel" width="10%" nowrap="nowrap">
|
|
Category</td>
|
|
<td class="dataField" width="30%" nowrap="nowrap">
|
|
<select name="category_id">
|
|
<option value="">select</option>
|
|
<?php
|
|
$w=$GLOBALS['db']->query("select id,name from ecmproductcategories where deleted='0' order by name asc");
|
|
while($r=$GLOBALS['db']->fetchByAssoc($w)){
|
|
echo '<option value="'.$r['id'].'"';
|
|
if($r['id']==$_GET['category_id'])echo ' selected';
|
|
echo '>'.$r['name'].'</option>';
|
|
}
|
|
?>
|
|
</select> </td>
|
|
<td class="dataLabel" width="10%" nowrap="nowrap">
|
|
Date</td>
|
|
<td class="dataField" width="30%" nowrap="nowrap">
|
|
<input autocomplete="off" name="date" id="date" value="<? echo $GLOBALS['timedate']->to_display_date($date);?>" title="" tabindex="" size="11" maxlength="10" type="text">
|
|
<img src="themes/default/images/jscalendar.gif" alt="Enter Date" id="date_trigger" align="absmiddle" border="0">
|
|
<script type="text/javascript">
|
|
Calendar.setup ({
|
|
inputField : "date",
|
|
daFormat : "<? echo str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));?>",
|
|
button : "date_trigger",
|
|
singleClick : true,
|
|
dateStr : "",
|
|
step : 1
|
|
}
|
|
);
|
|
</script> </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="dataLabel" width="10%" nowrap="nowrap">
|
|
Active</td>
|
|
<td class="dataField" width="30%" nowrap="nowrap">
|
|
<select name="active">
|
|
<option value="">All</option>
|
|
<option value="active" <?php if($_REQUEST['active']=="active")echo "selected";?>>Yes</option>
|
|
<option value="inactive" <?php if($_REQUEST['active']=="inactive")echo "selected";?>>No</option>
|
|
</select>
|
|
</td>
|
|
<td class="dataLabel" width="10%" nowrap="nowrap">
|
|
Not empty states only</td>
|
|
<td class="dataField" width="30%" nowrap="nowrap">
|
|
<select name="empty">
|
|
<option value="">All</option>
|
|
<option value="yes" <?php if($_REQUEST['empty']=="yes")echo "selected";?>>Yes</option>
|
|
<option value="no" <?php if($_REQUEST['empty']=="no")echo "selected";?>>No</option>
|
|
</select> </td>
|
|
<td class="dataLabel" width="10%" nowrap="nowrap"> </td>
|
|
<td class="dataField" width="30%" nowrap="nowrap"> </td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<input class="button" name="submit" value="Search" type="submit" onclick="this.form.action.value='ListStates';">
|
|
<input class="button" name="clear" value="Clear" type="button" onclick="location.href='index.php?module=EcmStockStates&action=ListStates';">
|
|
<input type="submit" class="button" name="CreateXLS" value="Create XLS">
|
|
<br />
|
|
<?php
|
|
|
|
$tds1='<td class="listViewThS1">';
|
|
|
|
$trs='<tr>';
|
|
$tre='</tr>';
|
|
|
|
$tds='<td class="oddListRowS1">';
|
|
$tde='</td>';
|
|
|
|
$tbs='<table cellpadding="0" cellspacing="0" border="0" class="ListView" style="width:100%;">';
|
|
$tbe='</table>';
|
|
|
|
$t.=$tbs;
|
|
$t.=$trs;
|
|
$t.=$tds1;
|
|
$t.=" ";
|
|
$t.=$tde;
|
|
$t.=$vc->sortableColumn("Index","code",$_GET['sorder'],15,"index");
|
|
$t.=$vc->sortableColumn("Name","name",$_GET['sorder'],30,"index");
|
|
$t.=$vc->sortableColumn("Category","product_category_name",$_GET['sorder'],20,"index");
|
|
$t.=$vc->sortableColumn("Quantity","qty",$_GET['sorder'],10,"index");
|
|
$t.=$vc->sortableColumn("Unit","unit",$_GET['sorder'],10,"index");
|
|
$t.=$vc->sortableColumn("Price","price",$_GET['sorder'],15,"index");
|
|
$t.=$vc->sortableColumn("Value","value",$_GET['sorder'],15,"index");
|
|
$t.=$tre;
|
|
$i=1;
|
|
$ac=3;
|
|
|
|
$wh[]="deleted='0'";
|
|
if($_GET['category_id'])$wh[]="product_category_id='".$_GET['category_id']."'";
|
|
if($_GET['active']=="active")$wh[]="product_active='1'";
|
|
if($_GET['active']=="inactive")$wh[]="product_active='0'";
|
|
|
|
$who[]="deleted='0'";
|
|
if($date)$who[]="date_entered<='".$date." 23:59:59'";
|
|
if($_GET['stock_id'])$who[]="stock_id='".$_GET['stock_id']."'";
|
|
|
|
$where=implode(" and ",$wh);
|
|
$z="select id,name,code,product_category_name,product_category_id, unit_id from ecmproducts where ".$where." order by code asc, name asc";
|
|
$w=$GLOBALS['db']->query($z);
|
|
echo mysql_error();
|
|
$sum_qty=0;
|
|
$sum_price=0;
|
|
|
|
global $app_list_strings;
|
|
|
|
|
|
while($r=$GLOBALS['db']->fetchByAssoc($w)){
|
|
$value=0;
|
|
$qty=0;
|
|
$price=0;
|
|
|
|
if($date!=date("Y-m-d",mktime()+24*3600)){
|
|
$arr=array();
|
|
$pp1=0;
|
|
$q1=0;
|
|
$ww=$GLOBALS['db']->query("select quantity as qty,id,price from ecmstockoperations where deleted='0' and type='0' and (in_id IS NULL or in_id='') and product_id='".$r['id']."' and (".implode(" and ",$who).") order by product_code");
|
|
//echo "select quantity as qty,id,price from ecmstockoperations where deleted='0' and type='0' and (in_id IS NULL or in_id='') and product_id='".$r['id']."' and (".implode(" and ",$who).") order by code<br><br>";
|
|
while($rrr=$GLOBALS['db']->fetchByAssoc($ww)){
|
|
$www=$GLOBALS['db']->query("select quantity from ecmstockoperations where in_id='".$rrr['id']."' and type='1' and in_id IS NOT NULL and in_id!='' and product_id='".$r['id']."' and (".implode(" and ",$who).") and deleted='0'");
|
|
$rqty=0;
|
|
while($rrp=$GLOBALS['db']->fetchByAssoc($www)){
|
|
$rqty+=$rrp['quantity'];
|
|
}
|
|
$qty=$rrr['qty']-$rqty;
|
|
if($qty>0){
|
|
$arr[]=array("qty"=>$qty,"id"=>$rrr['id'],"price"=>$rrr['price']);
|
|
}
|
|
}
|
|
|
|
if(count($arr)>0){
|
|
foreach($arr as $v){
|
|
$q1+=$v['qty'];
|
|
$pp1+=$v['qty']*$v['price'];
|
|
}
|
|
}
|
|
$qty=$q1;
|
|
$value=$pp1;
|
|
|
|
@$price=$value/$qty;
|
|
}
|
|
else{
|
|
$whs=array();
|
|
$whs[]="deleted='0'";
|
|
$whs[]="product_id='".$r['id']."'";
|
|
if($_GET['stock_id'])$whs[]="stock_id='".$_GET['stock_id']."'";
|
|
$whes=implode(" and ",$whs);
|
|
$wss=$GLOBALS['db']->query("select quantity,price from ecmstockstates where ".$whes);
|
|
while($rss=$GLOBALS['db']->fetchByAssoc($wss)){
|
|
$qty+=$rss['quantity'];
|
|
@$value+=$rss['quantity']*$rss['price'];
|
|
}
|
|
@$price=$value/$qty;
|
|
}
|
|
$arr1[]=array(
|
|
"id"=>$r['id'],
|
|
"qty"=>round($qty,2),
|
|
"code"=>$r['code'],
|
|
"name"=>$r['name'],
|
|
"product_category_id"=>$r['product_category_id'],
|
|
"product_category_name"=>$r['product_category_name'],
|
|
"price"=>$price,
|
|
"value"=>$value,
|
|
"unit_id" => $r['unit_id'],
|
|
);
|
|
}
|
|
if(!$_GET['order_by'])$_GET['order_by']="code";
|
|
if(!$_GET['sorder'])$_GET['sorder']="asc";
|
|
//$arr1=multisort($arr1,array(array('key'=>$_GET['order_by'],'sort'=>$_GET['sorder'])));
|
|
|
|
if(count($arr1)>0){
|
|
foreach($arr1 as $r){
|
|
if($_REQUEST['empty']=="yes" && ($r['qty']==0 || $r['qty']==""))continue;
|
|
if($_REQUEST['empty']=="no" && $r['qty']!=0 && $r['qty']!="")continue;
|
|
$t.=$trs;
|
|
$t.=$tds;
|
|
$t.='<input type="checkbox" value="'.$r['id'].'" name="check[]">';
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.=$r['code'];
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<a href="index.php?module=EcmProducts&action=DetailView&record='.$r['id'].'">'.$r['name'].'</a>';
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.='<a href="index.php?module=EcmProductCategories&action=DetailView&record='.$r['product_category_id'].'">'.$r['product_category_name'].'</a>';
|
|
$t.=$tde;
|
|
|
|
$t.=$tds;
|
|
$t.=number_format($r['qty'],4,",",".");
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.=$app_list_strings['ecmproducts_unit_dom'][$r['unit_id']];
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.=number_format($r['price'],2,",",".");
|
|
$t.=$tde;
|
|
$t.=$tds;
|
|
$t.=number_format($r['value'],2,",",".");
|
|
$t.=$tde;
|
|
$t.=$tre;
|
|
|
|
$sum_qty+=$r['qty'];
|
|
$sum_price+=$r['value'];
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("A".$ac,$r['code']);
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("B".$ac,$r['name']);
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("C".$ac,$r['product_category_name']);
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("D".$ac,$r['qty']);
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("E".$ac,$app_list_strings['ecmproducts_unit_dom'][$r['unit_id']]);
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("F".$ac,$r['price']);
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("G".$ac,$r['value']);
|
|
$i++;
|
|
$ac++;
|
|
}
|
|
}
|
|
$t.=$trs;
|
|
$t.=$tds1;
|
|
$t.=" ";
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.=" ";
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.=" ";
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.=" ";
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.=number_format($sum_qty,0,"","");
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.=" ";
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.=@number_format($sum_price/$sum_qty,2,",",".");
|
|
$t.=$tde;
|
|
$t.=$tds1;
|
|
$t.=number_format($sum_price,2,",",".");
|
|
$t.=$tde;
|
|
$t.=$tre;
|
|
|
|
$t.=$tbe;
|
|
echo $t;
|
|
|
|
|
|
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("D".$ac,$sum_qty);
|
|
@$objPHPExcel->getActiveSheet()->SetCellValue("F".$ac,$sum_price/$sum_qty);
|
|
$objPHPExcel->getActiveSheet()->SetCellValue("G".$ac,$sum_price);
|
|
|
|
$objPHPExcel->getActiveSheet()->duplicateStyleArray(
|
|
array(
|
|
'fill' => array(
|
|
'type' => PHPExcel_Style_Fill::FILL_SOLID,
|
|
'color' => array('argb' => 'F0F0F0')
|
|
),
|
|
'borders' => array(
|
|
'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
|
|
'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
|
|
)
|
|
),
|
|
"A1:G1"
|
|
);
|
|
$objPHPExcel->getActiveSheet()->duplicateStyleArray(
|
|
array(
|
|
'fill' => array(
|
|
'type' => PHPExcel_Style_Fill::FILL_SOLID,
|
|
'color' => array('argb' => 'F0F0F0')
|
|
),
|
|
'borders' => array(
|
|
'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
|
|
'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
|
|
)
|
|
),
|
|
"A2:G2"
|
|
);
|
|
$objPHPExcel->getActiveSheet()->duplicateStyleArray(
|
|
array(
|
|
'fill' => array(
|
|
'type' => PHPExcel_Style_Fill::FILL_SOLID,
|
|
'color' => array('argb' => 'F0F0F0')
|
|
),
|
|
'borders' => array(
|
|
'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
|
|
'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
|
|
)
|
|
),
|
|
"A".($ac).":G".($ac)
|
|
);
|
|
if($_REQUEST['CreateXLS']){
|
|
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
|
|
//$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
|
|
chmod("cache/upload",0777);
|
|
$microtime=str_replace(".","",str_replace(" ","",microtime()));
|
|
$name="cache/upload/States".$microtime.".xls";
|
|
$objWriter->save($name);
|
|
chmod($name,0777);
|
|
|
|
header("Location: ".$name);
|
|
}
|
|
?>
|
|
</form>
|