Files
2025-05-12 15:44:39 +00:00

145 lines
8.2 KiB
PHP
Executable File

<?php
set_time_limit(9999999);
function sum($year,$account_id="",$product_id="",$category_id="",$product_active=""){
$wh[]="e.register_date like '".$year."%'";
$wh[]="e.deleted='0'";
$wh[]="i.deleted='0'";
$wh[]="p.deleted='0'";
$wh[]="e.status='accepted'";
if($account_id)$wh[]="(e.parent_id='".$account_id."' or w.parent_id='".$account_id."')";
if($product_id)$wh[]="i.ecmproduct_id='".$product_id."'";
if($category_id)$wh[]="p.product_category_id='".$category_id."'";
if($product_active && $product_active=="active")$wh[]="p.product_active='1'";
elseif($product_active && $product_active=="inactive")$wh[]="p.product_active='0'";
$where="where ".implode(" and ",$wh);
$z="select distinct i.id as iditem,w.parent_id as wz_parent_id,i.ecminvoiceoutitem_id as item_id,i.ecmvat_value,i.ecmproduct_id,i.quantity,i.price,i.purchase_price,e.ecminvoiceout_id as correct_id,e.id as invoice_id,e.wz_id,e.document_no,e.currency_value,e.id,e.type as type,e.register_date,e.parent_id,e.parent_name,p.carton_volume_meter as cvm,p.pieces_per_carton as ppc,p.product_category_id,p.code from (((ecminvoiceouts as e inner join ecminvoiceoutitems as i on e.id=i.ecminvoiceout_id) left join ecmproducts as p on p.id=i.ecmproduct_id) left join ecmstockdocouts as w on w.id=e.wz_id) ".$where;
//echo $z;
$w=mysql_query($z);
while($r=mysql_fetch_array($w)){
$arr=array();
if(!$r['currency_value'])$currency_value=1;
else $currency_value=$r['currency_value'];
$arr['invoice_id']=$r['invoice_id'];
$arr['correct_id']=$r['correct_id'];
$arr['product_id']=$r['ecmproduct_id'];
//$arr['product_name']=$r['product_name'];
$arr['category_id']=$r['product_category_id'];
//if(!$r['product_category_id'])echo $r['code'].'<br>';
//$arr['category_name']=$r['product_category_name'];
//$arr['product_code']=$r['code'];
$arr['date']=$r['register_date'];
$arr['account_id']=$r['parent_id'];
//$arr['account_name']=$r['parent_name'];
$arr['cvm']=$r['cvm'];
$arr['ppc']=$r['ppc'];
$arr['currency_value']=$currency_value;
$arr['wz']=$r['wz_id'];
$arr['parent_account_id']=$r['wz_parent_id'];
if($r['ppc']>0)$arr['cbm']=$r['quantity']*($r['cvm']/$r['ppc']);
if($r['type']!="correct"){
$purchase_price=$r['purchase_price'];
$total_price=$currency_value*($r['price']*$r['quantity']);
$total_qty=$r['quantity'];
$total_purchase_price=$purchase_price*$r['quantity'];
if($r['ppc']>0)$arr['cbm']=$r['quantity']*($r['cvm']/$r['ppc']);
}
else{
$zz="select price,quantity,purchase_price from ecminvoiceoutitems where id='".$r['item_id']."'";
$rcor=mysql_fetch_array(mysql_query($zz));
$purchase_price=$rcor['purchase_price'];
$total_price=$currency_value*($r['price']*$r['quantity']-$rcor['price']*$rcor['quantity']);
$total_qty=$r['quantity']-$rcor['quantity'];
$total_purchase_price=$purchase_price*($r['quantity']-$rcor['quantity']);
if($r['ppc']>0)$arr['cbm']=($r['quantity']-$rcor['quantity'])*($r['cvm']/$r['ppc']);
}
$arr['price']=$r['price'];
$arr['purchase_price']=$purchase_price;
$arr['total_price']=$total_price;
$arr['total_purchase_price']=$total_purchase_price;
$arr['total_qty']=$total_qty;
//if(eregi("2010-01",$arr['date']))echo $arr['purchase_price'].' '.$r['iditem'].' '.$arr['price'].' '.$arr['total_qty'].'<br>';
$row[]=$arr;
}
return $row;
}
function ajaxWindow($id,$i,$value,$account,$type,$year,$price=0){
if($price){
$pp='mintajaxget(\'index.php?to_pdf=1&module=EcmReports&action=setValRep&account_id='.$account.'&year='.$year.'&month='.$i.'&type=sale&bean_id='.$id.'&value=\'+(parseInt(document.getElementById(\'value'.$id.'_'.$i.'_qty\').value)*'.((float)$price).'),\'new'.$id.'_'.$i.'_sale\');document.getElementById(\'div'.$id.'_'.$i.'_sale\').style.display=\'none\';';
}
else $pp='';
$ajax='<div id="new'.$id.'_'.$i.'_'.$type.'" style="display:inline;">'.number_format($value,2,",",".").'</div>&nbsp;<a style="cursor:pointer;display:inline;" onclick="if(document.getElementById(\'div'.$id.'_'.$i.'_'.$type.'\').style.display==\'none\'){document.getElementById(\'div'.$id.'_'.$i.'_'.$type.'\').style.display=\'block\';}else{document.getElementById(\'div'.$id.'_'.$i.'_'.$type.'\').style.display=\'none\';}"><img src="modules/EcmQuotes/images/search.gif" border="0" /></a><div id="div'.$id.'_'.$i.'_'.$type.'" style="display:none; border: 1px solid #cccccc;background-color:#e6e6e6;padding:3px;text-align:center;"><input id=\'value'.$id.'_'.$i.'_'.$type.'\' value=\''.number_format($value,2,".","").'\' style="width:80px;"><input type="button" onclick="mintajaxget(\'index.php?to_pdf=1&module=EcmReports&action=setValRep&account_id='.$account.'&year='.$year.'&month='.$i.'&type='.$type.'&bean_id='.$id.'&value=\'+document.getElementById(\'value'.$id.'_'.$i.'_'.$type.'\').value,\'new'.$id.'_'.$i.'_'.$type.'\');document.getElementById(\'div'.$id.'_'.$i.'_'.$type.'\').style.display=\'none\';'.$pp.'" value="Save" class="button"></div>';
return $ajax;
}
function getSum($arr,$year,$product_id="",$category_id=""){
if(count($arr)>0){
foreach($arr as $a){
if($product_id && $product_id!=$a['product_id'])continue;
if($category_id && $category_id!=$a['category_id'])continue;
if(!eregi($year,$a['date']))continue;
$total+=$a['total_price'];
$qty+=$a['total_qty'];
$total_purchase+=$a['total_purchase_price'];
$cbm+=$a['cbm'];
}
}
return array("total"=>$total,"qty"=>$qty,"total_purchase"=>$total_purchase,"cbm"=>$cbm);
}
function sumCat($year,$month,$account,$type){
$w=mysql_query("select id from ecmproductcategories where deleted='0'");
while($r=mysql_fetch_array($w)){
$arr[]="bean_id='".$r['id']."'";
}
$r=mysql_fetch_array(mysql_query("select sum(value) as sum from ecmsalesreports_predictions_cat where deleted='0' and type='".$type."' and account_id='".$account."' and month='".$month."' and year='".$year."' and (".implode(" or ",$arr).")"));
return $r['sum'];
}
$year=$_GET['year'];
if(!$year)$year=(int)date("Y");
if($year==date("Y")){
$mmm=(int)date("m")-1;
}
else $mmm=12;
if(!$mmm)$mmm=1;
//if(!$_REQUEST['account'])$_REQUEST['account']=134;
//if(!$_REQUEST['active'])$_REQUEST['active']="active";
$trs='<tr>';
$tre='</tr>';
$trs_cat='<tr style="background-color: #e6e6e6;">';
$tds='<td class="oddListRowS1">';
$tdsf1='<td class="oddListRowS1" style="text-align:center;border-left: 1px solid #cccccc;">';
$tdsf2='<td class="oddListRowS1" style="text-align:center;">';
$tdsf3='<td class="oddListRowS1" style="text-align:center;border-right: 1px solid #cccccc;">';
$tdsfs1='<td class="oddListRowS1" style="background-color: #BBDDFF;text-align:center;border-left: 1px solid #cccccc;">';
$tdsfs2='<td class="oddListRowS1" style="background-color: #BBDDFF;text-align:center;">';
$tdsfs3='<td class="oddListRowS1" style="background-color: #BBDDFF;text-align:center;border-right: 1px solid #cccccc;">';
$tds_cat='<td class="oddListRowS1">';
$tds_cat1='<td class="oddListRowS1" style="width:250px;">';
$tbs='<table cellpadding="0" cellspacing="0" border="0" class="ListView" style="width:670px;">';
$tbs1='<table cellpadding="0" cellspacing="0" border="0" style="">';
$tbs2='<table cellpadding="0" cellspacing="0" border="0" class="ListView" style="width:810px">';
$tds11='<td class="listViewThS1" style="width:300px;height:48px;">';
$tds12='<td class="listViewThS1" style="width:50px;height:48px;">';
$tds13='<td class="listViewThS1" style="width:50px;height:48px;">';
$tds13='<td class="listViewThS1" style="width:60px;height:48px;">';
$tds2='<td colspan="2" class="listViewThS1" style="text-align:center;border-left: 1px solid #cccccc;border-right: 1px solid #cccccc;min-width:100px;">';
$tds22='<td class="listViewThS1" style="text-align:center;border-left: 1px solid #cccccc;border-right: 1px solid #cccccc;min-width:100px;">';
$tds3='<td colspan="3" class="listViewThS1" style="text-align:center;border-left: 1px solid #cccccc;border-right: 1px solid #cccccc;min-width:100px;">';
$tds4='<td colspan="10" class="listViewThS1" style="text-align:center;border-left: 1px solid #cccccc;border-right: 1px solid #cccccc;min-width:100px;">';
$tbe='</table>';
$tde='</td>';
$tdr='</tr>';
$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");
?>