loadLanguage('MyEcmReportDashlets'); $this->year = $def['year']; if(!$this->year)$this->year=date("Y"); $this->month = $def['month']; if(!$this->month)$this->month=date("m"); $this->sales = $def['sales']; $this->sales_year = $def['sales_year']; $this->percent = $def['percent']; $this->quotes = $def['quotes']; $this->orders = $def['orders']; $this->stocks = $def['stocks']; $this->products = $def['products']; $this->new_products = $def['new_products']; $this->payments = $def['payments']; $this->sales_title = $def['sales_title']; $this->sales_year_title = $def['sales_year_title']; $this->percent_title = $def['percent_title']; $this->quotes_title = $def['quotes_title']; $this->orders_title = $def['orders_title']; $this->stocks_title = $def['stocks_title']; $this->products_title = $def['products_title']; $this->new_products_title = $def['new_products_title']; $this->payments_title = $def['payments_title']; $this->sales_no = $def['sales_no']; $this->sales_year_no = $def['sales_year_no']; $this->percent_no = $def['percent_no']; $this->quotes_no = $def['quotes_no']; $this->orders_no = $def['orders_no']; $this->stocks_no = $def['stocks_no']; $this->products_no = $def['products_no']; $this->new_products_no = $def['new_products_no']; $this->payments_no = $def['payments_no']; parent::Dashlet($id); $this->isConfigurable = true; $this->hasScript = true; if(empty($def['title'])) $this->title = $this->dashletStrings['LBL_TITLE']; else $this->title = $def['title']; } function salesPercentRange($date1,$date2){ $w=$GLOBALS['db']->query("select sum(value_wz) as swz,sum(value_sale) as ssale from ecmproductcategories_realisation where date>='".$date1."' and date<='".$date2."'"); $r=$GLOBALS['db']->fetchByAssoc($w); if($r['ssale']>0)return @100*$r['swz']/$r['ssale']; } function salesPercent($date){ $w=$GLOBALS['db']->query("select * from ecmsales where delivery_date like '".$date."%' and deleted='0'"); while($r=$GLOBALS['db']->fetchByAssoc($w)){ $rsale=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(quantity*price) as qty from ecmsaleitems where ecmsale_id='".$r['id']."'")); $rwz=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select id from ecmstockdocouts where so_id='".$r['id']."'")); $rwzi=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(quantity*selling_price) as qty from ecmstockdocoutitems where ecmstockdocout_id='".$rwz['id']."'")); $ecmstockdocout_id=$rwz['id']; if($ecmstockdocout_id){ $sum_wz_qty+=$rwzi['qty']; $sum_sale_qty+=$rsale['qty']; } $qty_diff=$rwzi['qty']-$rsale['qty']; $diff_minus=$diff_plus=0; $rst=$rsale['qty']; $rwt=$rwzi['qty']; if($ecmstockdocout_id){ $wsale=$GLOBALS['db']->query("select quantity,price,code,ecmproduct_id from ecmsaleitems where deleted='0' and ecmsale_id='".$r['id']."' order by code"); while($rsale=$GLOBALS['db']->fetchByAssoc($wsale)){ $qty=0; $wwz=$GLOBALS['db']->query("select quantity,selling_price from ecmstockdocoutitems where deleted='0' and ecmproduct_id='".$rsale['ecmproduct_id']."' and ecmstockdocout_id='".$ecmstockdocout_id."'"); while($rwz=$GLOBALS['db']->fetchByAssoc($wwz)){ $qty+=$rwz['quantity']*$rwz['selling_price']; } if($rsale['quantity']*$rsale['price']>$qty)$diff_minus+=$qty-$rsale['quantity']*$rsale['price']; if($rsale['quantity']*$rsale['price']<$qty)$diff_plus+=$qty-$rsale['quantity']*$rsale['price']; $sum[$rsale['ecmproduct_id']]['wz']+=$qty; $sum[$rsale['ecmproduct_id']]['sale']+=$rsale['quantity']*$rsale['price']; } } } if($sum_sale_qty)return @100*$sum_wz_qty/$sum_sale_qty; } function getPrediction($product_id,$date,$arr){ $mmm=(int)date("m")-1; if($mmm==0)$mmm=1; $e=explode("-",$date); $w=$GLOBALS['db']->query("select value from ecmsalesreports_predictions_cat where type='sales' and year='".$e[0]."' and month='".(int)$e[1]."' and bean_id='".$product_id."'"); if($GLOBALS['db']->getRowCount($w)>0){ while($r=$GLOBALS['db']->fetchByAssoc($w)){ $sales+=$r['value']; } } else{ $s=getSum($arr,$e[0],$product_id); $sales+=$s['total']/$mmm; } return ($sales); } function getOrdersByDate($date){ if(!$no_inv)$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(i.price*i.quantity) as s from ecmsaleitems as i inner join ecmsales as e on e.id=i.ecmsale_id inner join ecmstockdocouts as w on w.so_id=e.id inner join ecminvoiceouts as inv on inv.wz_id=w.id inner join ecmproducts as p on i.ecmproduct_id=p.id where e.deleted='0' and i.deleted='0' and inv.register_date like '".$date."%' and p.product_category_id!='' and p.product_category_id is not null and e.type='sales_order' and e.status!='s10'")); return $r['s']; } function getOrdersBydateNoInv($date){ $w=$GLOBALS['db']->query("select i.price*i.quantity as s,e.id as id,e.register_date as d from ecmsaleitems as i inner join ecmsales as e on e.id=i.ecmsale_id inner join ecmproducts as p on i.ecmproduct_id=p.id where e.deleted='0' and i.deleted='0' and e.delivery_date like '".$date."%' and p.product_category_id!='' and p.product_category_id is not null and e.type='sales_order' and e.status!='s10'"); while($r=$GLOBALS['db']->fetchByAssoc($w)){ if($GLOBALS['db']->getRowCount($GLOBALS['db']->query("select id from ecmstockdocouts where so_id='".$r['id']."' and register_date>='".$r['d']."' and deleted='0'"))==0)$s+=$r['s']; } return $s; } function getOrdersBydateNoInv1($date){ $w=$GLOBALS['db']->query("select sum(CASE WHEN w.id is null THEN i.price*i.quantity ELSE 0 END) as s from ecmsaleitems as i inner join ecmsales as e on e.id=i.ecmsale_id inner join ecmproducts as p on i.ecmproduct_id=p.id left join ecmstockdocouts as w on w.so_id=e.id where w.so_id is null and (w.deleted='0' or w.deleted is null) and e.deleted='0' and i.deleted='0' and e.delivery_date like '".$date."%' and p.product_category_id!='' and p.product_category_id is not null and e.type='sales_order' and e.status!='s10'"); $r=$GLOBALS['db']->fetchByAssoc($w); return $r['s']; } function getSalesByDate1($date,$cor=0){ if($cor==1){ $w=$GLOBALS['db']->query("select i.ecminvoiceoutitem_id,i.price,i.quantity from ecminvoiceoutitems as i inner join ecminvoiceouts as e on e.id=i.ecminvoiceout_id where i.deleted='0' and e.deleted='0' and e.register_date like '".$date."%' and e.type='correct' and e.status='accepted'"); while($r=$GLOBALS['db']->fetchByAssoc($w)){ $rr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select price,quantity,purchase_price from ecminvoiceoutitems where id='".$r['ecminvoiceoutitem_id']."'")); $value_sale+=$r['quantity']*$r['price']-$rr['quantity']*$rr['price']; $value_pur+=$r['quantity']*$rr['purchase_price']-$rr['quantity']*$rr['purchase_price']; } } else{ $w=$GLOBALS['db']->query("select sum(i.quantity*i.price) as sale,sum(i.quantity*i.purchase_price) as purchase from ecminvoiceoutitems as i inner join ecminvoiceouts as e on e.id=i.ecminvoiceout_id inner join ecmstockdocouts as w on w.id=e.wz_id inner join ecmsales as s on s.id=w.so_id where i.deleted='0' and e.deleted='0' and e.register_date like '".$date."%' and e.type!='correct' and e.status='accepted' and s.status!='s10' and w.status='accepted'"); $r=$GLOBALS['db']->fetchByAssoc($w); $value_sale=$r['sale']; $value_pur=$r['purchase']; } return array("sale"=>$value_sale,"purchase"=>$value_pur); } function getSalesByDate($date,$cor=0){ if($cor==1)$type="correct"; else $type="normal"; $w=$GLOBALS['db']->query(" select sum( CASE WHEN e.type!='correct' THEN CASE WHEN e.currency_value is null or e.currency_value='' THEN i.price*i.quantity ELSE i.price*i.quantity*e.currency_value END ELSE CASE WHEN ci.price is null or ci.quantity is null THEN 0 ELSE i.price*i.quantity-ci.price*ci.quantity END END ) as sales, sum( CASE WHEN e.type!='correct' THEN i.purchase_price*i.quantity ELSE CASE WHEN ci.quantity is null THEN 0 ELSE ci.purchase_price*i.quantity-ci.purchase_price*ci.quantity END END ) as purchase from ecminvoiceoutitems as i left join ecminvoiceoutitems as ci on i.ecminvoiceoutitem_id=ci.id inner join ecminvoiceouts as e on e.id=i.ecminvoiceout_id left join ecmstockdocouts as w on e.wz_id=w.id left join ecmproducts as p on p.id=i.ecmproduct_id where i.deleted='0' and e.deleted='0' and e.register_date like '".$date."%' and e.type='".$type."'"); $r=$GLOBALS['db']->fetchByAssoc($w); return array("sale"=>$r['sales'],"purchase"=>$r['purchase']); } function display() { if($_REQUEST['action']!="summary" && $_REQUEST['to_pdf']!=1)return; $ss = new Sugar_Smarty(); $ss->assign('savedText', $this->savedText); $ss->assign('saving', $this->dashletStrings['LBL_SAVING']); $ss->assign('saved', $this->dashletStrings['LBL_SAVED']); $ss->assign('id', $this->id); $tds1=''; $tds1c=''; $trs=''; $tre=''; $tds=''; $tde=''; $tbs=''; $tbe='
'; $lock=1; //if($_REQUEST['action']=="summary"){ if($this->new_products){ $t='

'.$this->new_products_title.'


'.$tbs; $t.=$trs; $t.=$tds1c; $t.="Index"; $t.=$tde; $t.=$tds1; $t.="Name"; $t.=$tde; $t.=$tds1; $t.="Start Date"; $t.=$tde; $t.=$tre; $w=$GLOBALS['db']->query("select id,code,name,sales_start_date from ecmproducts where deleted='0' and sales_start_date>'".date("Y-m-d")."' order by sales_start_date asc"); echo mysql_error(); while($r=$GLOBALS['db']->fetchByAssoc($w)){ $t.=$trs; $t.=$tds; $t.=$r['code']; $t.=$tde; $t.=$tds; $t.=''.$r['name'].''; $t.=$tde; $t.=$tds; $t.=$GLOBALS['timedate']->to_display_date($r['sales_start_date']); $t.=$tde; $t.=$tre; } $t.=$tbe; $new_products=$t; } if($this->products){ $t='

'.$this->products_title.'

Period: '.$this->month.'.'.$this->year.'
'.$tbs; $t.=$trs; $t.=$tds1c; $t.="Index"; $t.=$tde; $t.=$tds1; $t.="Name"; $t.=$tde; $t.=$tds1; $t.="Sales qty"; $t.=$tde; $t.=$tds1; $t.="Sales PLN"; $t.=$tde; $t.=$tds1; $t.="Margin"; $t.=$tde; $t.=$tds1; $t.="Margin PLN"; $t.=$tde; $t.=$tds1; $t.="Inv qty"; $t.=$tde; $t.=$tds1; $t.="Ord qty"; $t.=$tde; $t.=$tds1; $t.="Sales forecast"; $t.=$tde; $t.=$tre; $w=$GLOBALS['db']->query("select e.currency_value,i.ecmproduct_id,i.price,i.quantity,i.purchase_price,e.status,e.type,e.ecminvoiceout_id,i.ecminvoiceoutitem_id as item from ecminvoiceoutitems as i inner join ecminvoiceouts as e on e.id=i.ecminvoiceout_id where e.register_date like '".$this->year.'-'.$this->month."%' and e.deleted='0' and e.status='accepted'"); $w=$GLOBALS['db']->query(" select sum( CASE WHEN e.type!='correct' THEN CASE WHEN e.currency_value is null or e.currency_value='' THEN i.price*i.quantity ELSE i.price*i.quantity*e.currency_value END ELSE CASE WHEN ci.price is null or ci.quantity is null THEN 0 ELSE i.price*i.quantity-ci.price*ci.quantity END END ) as sales, sum( CASE WHEN e.type!='correct' THEN i.purchase_price*i.quantity ELSE CASE WHEN ci.quantity is null THEN 0 ELSE i.purchase_price*i.quantity-i.purchase_price*ci.quantity END END ) as purchase, sum( CASE WHEN e.type!='correct' THEN i.quantity ELSE CASE WHEN ci.quantity is null THEN 0 ELSE i.quantity-ci.quantity END END ) as quantity, p.code, p.name, p.id, p.ordered, p.ems_qty_in_stock from ecminvoiceoutitems as i left join ecminvoiceoutitems as ci on i.ecminvoiceoutitem_id=ci.id inner join ecminvoiceouts as e on e.id=i.ecminvoiceout_id inner join ecmproducts as p on p.id=i.ecmproduct_id where i.deleted='0' and (ci.deleted='0' or ci.deleted is null) and e.deleted='0' and e.register_date like '".$this->year.'-'.$this->month."%' and e.status='accepted' group by p.id"); echo mysql_error(); while($r=$GLOBALS['db']->fetchByAssoc($w)){ $arr[$r['id']]['code']=$r['code']; $arr[$r['id']]['name']=$r['name']; $arr[$r['id']]['ordered']=$r['ordered']; $arr[$r['id']]['ems_qty_in_stock']=$r['ems_qty_in_stock']; $arr[$r['id']]['id']=$r['id']; $arr[$r['id']]['sales']+=$r['sales']; $arr[$r['id']]['margin']+=$r['purchase']; $arr[$r['id']]['quantity']+=$r['quantity']; /*if($r['type']!="correct"){ if($_REQUEST['die']==1 && $p['code']=="RE01332")echo $r['price']." ".$r['quantity']." ".$r['purchase_price']."
"; $arr[$p['id']]['sales']+=$currency_value*$r['price']*$r['quantity']; $arr[$p['id']]['margin']+=$r['purchase_price']*$r['quantity']; $arr[$p['id']]['quantity']+=$r['quantity']; } else{ $rr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select price,quantity,purchase_price from ecminvoiceoutitems where id='".$r['item']."'")); $arr[$p['id']]['sales']+=$currency_value*($r['price']*$r['quantity']-$rr['price']*$rr['quantity']); $arr[$p['id']]['margin']+=$rr['purchase_price']*($r['quantity']-$rr['quantity']); $arr[$p['id']]['quantity']+=$r['quantity']-$rr['quantity']; }*/ } $arr=$this->multisort($arr,array(array('key'=>'sales','sort'=>'desc'))); //echo '
';
				//print_r($arr);
				//echo '
'; foreach($arr as $r){ $i++; if($i==20)break; @$margin=(100*($r['sales']-$r['margin'])/$r['sales']); $s=sum($this->products_year,"",$r['id'],"",""); $pr=$this->getPrediction($r['id'],$this->year.'-'.$this->month,$s); $t.=$trs; $t.=$tds; $t.=$r['code']; $t.=$tde; $t.=$tds; $t.=''.$r['name'].''; $t.=$tde; $t.=$tds; $t.=@number_format($r['quantity'],0,",","."); $t.=$tde; $t.=$tds; $t.=@number_format($r['sales'],2,",","."); $t.=$tde; $t.=$tds; $t.=@number_format($margin,2,",",".")."%"; $t.=$tde; $t.=$tds; $t.=@number_format($r['sales']-$r['margin'],2,",","."); $t.=$tde; $t.=$tds; $t.=@number_format($r['ems_qty_in_stock'],0,",","."); $t.=$tde; $t.=$tds; $t.=@number_format($r['ordered'],0,",","."); $t.=$tde; $t.=$tds; $t.=@number_format($pr,2,",","."); $t.=$tde; $t.=$tre; } $t.=$tbe; $products=$t; } if($this->stocks){ //echo open_flash_chart_object(800,600,'modules/Home/Dashlets/MyEcmReportDashlets/stocksChart.php',false,'include/ECM/open_flash_chart/'); $stocks='

'.$this->stocks_title.'


'.'
'; } if($this->sales){ $_SESSION['EcmReports_Dashlet_sales']=$this->year."-".$this->month; $sales='

'.$this->sales_title.'

Period: '.$this->month.'.'.$this->year.'
'. '
'; } if($this->sales_year){ $_SESSION['EcmReports_Dashlet_sales_year']=$this->year."-".$this->month; $sales_year='

'.$this->sales_year_title.'

Period: '.$this->year.'
'.'
'; } if($this->percent){ $t='

'.$this->percent_title.'

Period: '.$this->month.'.'.$this->year.'
'.''; $t.=''; $rst=0; $rwt=0; $ww=$GLOBALS['db']->query("select c.id,c.name,t.value_sale,t.value_wz from ecmproductcategories as c inner join ecmproductcategories_realisation as t on t.product_category_id=c.id where t.date='".$this->year.'-'.$this->month."' and c.deleted='0' order by c.name asc"); echo mysql_error(); while($rr=$GLOBALS['db']->fetchByAssoc($ww)){ $k=$rr['id']; $rwt+=$rr['value_wz']; $rst+=$rr['value_sale']; if($rr['value_wz']<$rr['value_sale'])$color="red"; elseif($rr['value_wz']>$rr['value_sale'])$color="green"; else $color="black"; $ri=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(s.quantity*s.price) as s from ecmstockstates as s inner join ecmproducts as p on p.id=s.product_id where p.product_category_id='".$rr['id']."' and p.deleted='0' and s.deleted='0'")); $inv_value+=$ri['s']; $t.='"; } $qty_diff=$rwt-$rst; $t.=''; $r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select value_sale from ecmproductcategories_realisation where date='".$this->year.'-'.$this->month."' and product_category_id='diff_minus'")); $t.=''; $r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select value_sale from ecmproductcategories_realisation where date='".$this->year.'-'.$this->month."' and product_category_id='diff_plus'")); $t.=''; $t.='
CategoryInv valueOrderWZ%
'.$rr['name']."".@number_format($ri['s'],2,",",".")."".number_format(($rr['value_sale']),2,",",".")."".number_format($rr['value_wz'],2,",",".")."".@number_format(100*$rr['value_wz']/$rr['value_sale'],2,",",".")."%
Total'.@number_format($inv_value,2,",",".").''.number_format(($rst),2,",",".").''.number_format($rwt,2,",",".").''.@number_format(100*$rwt/$rst,2,",",".").'%
   '.number_format($r['value_sale'],2,",",".").' 
   '.number_format($r['value_sale'],2,",",".").' 
'; $percent=$t; } if($this->payments){ include_once("modules/EcmPaymentStates/helper1.php"); $w=$GLOBALS['db']->query("select distinct account_id from ecmpayments_ecminvoiceouts where account_id!='' and account_id is not null"); while($r=$GLOBALS['db']->fetchByAssoc($w))$acc[$r['account_id']]="id='".$r['account_id']."'"; $t='

'.$this->payments_title.'


'.$tbs; $t.=$trs; $t.=$tds1; $t.="Ballance"; $t.=$tde; $t.=$tds1; $t.="Summary"; $t.=$tde; $t.=$tds1; $t.="Not overdue"; $t.=$tde; $t.=$tds1; $t.="1-30"; $t.=$tde; $t.=$tds1; $t.="30-60"; $t.=$tde; $t.=$tds1; $t.="60-90"; $t.=$tde; $t.=$tds1; $t.="90-180"; $t.=$tde; $t.=$tds1; $t.="180-..."; $t.=$tde; $t.=$tre; $z="select * from accounts where deleted='0' and (".implode(" or ",$acc).") order by name asc"; $w=$GLOBALS['db']->query($z); while($r=$GLOBALS['db']->fetchByAssoc($w)){ $l_summary=getSummary($r['id']); $l_ballance=getBallance($r['id']); $l_actual_sum=getActualSum($r['id']); $l_sum_1_30=getSum1($r['id'],1,30); $l_sum_30_60=getSum1($r['id'],30,60); $l_sum_60_90=getSum1($r['id'],60,90); $l_sum_90_180=getSum1($r['id'],90,180); $l_sum_180=getSum1($r['id'],180); if(round($l_summary+$l_ballance+$l_actual_sum+$l_sum_1_30+$l_sum_30_60+$l_sum_60_90+$l_sum_90_180+$l_sum_180,2)==0.00)continue; $summary+=$l_summary; $ballance+=$l_ballance; $actual_sum+=$l_actual_sum; $sum_1_30+=$l_sum_1_30; $sum_30_60+=$l_sum_30_60; $sum_60_90+=$l_sum_60_90; $sum_90_180+=$l_sum_90_180; $sum_180+=$l_sum_180; $i++; } $t.=$trs; $t.=$tds; $t.=number_format($ballance,2,",","."); $t.=$tde; $t.=$tds; $t.=number_format($summary,2,",","."); $t.=$tde; $t.=$tds; $t.=number_format($actual_sum,2,",","."); $t.=$tde; $t.=$tds; $t.=number_format($sum_1_30,2,",","."); $t.=$tde; $t.=$tds; $t.=number_format($sum_30_60,2,",","."); $t.=$tde; $t.=$tds; $t.=number_format($sum_60_90,2,",","."); $t.=$tde; $t.=$tds; $t.=number_format($sum_90_180,2,",","."); $t.=$tde; $t.=$tds; $t.=number_format($sum_180,2,",","."); $t.=$tde; $t.=$tre; $t.=$tbe; $payments=$t; } if($this->quotes){ $send=0; $won=0; $new_send=0; $new_won=0; $w=$GLOBALS['db']->query("select status,parent_id from ecmquotes where deleted='0' and register_date like '".$this->year.'-'.$this->month."%'"); while($r=$GLOBALS['db']->fetchByAssoc($w)){ if($r['status']=="s50" || $r['status']=="s30"){ $send++; if($GLOBALS['db']->getRowCount($GLOBALS['db']->query("select id from ecmquotes where (status='s50' or status='s30') and parent_id='".$r['parent_id']."' and register_date<'".$this->year.'-'.$this->month."' and deleted='0'"))==0){ $new_send++; } } if($r['status']=="s60"){ $won++; if($GLOBALS['db']->getRowCount($GLOBALS['db']->query("select id from ecmquotes where status='s60' and parent_id='".$r['parent_id']."' and register_date<'".$this->year.'-'.$this->month."' and deleted='0'"))==0){ $new_won++; } } } $t='

'.$this->quotes_title.'

Period: '.$this->month.'.'.$this->year.'
'.$tbs; $t.=$trs; $t.=$tds1; $t.='Sent'; $t.=$tde; $t.=$tds; $t.=$send; $t.=$tde; $t.=$tre; $t.=$trs; $t.=$tds1; $t.='New sent'; $t.=$tde; $t.=$tds; $t.=$new_send; $t.=$tde; $t.=$tre; $t.=$trs; $t.=$tds1; $t.='Won'; $t.=$tde; $t.=$tds; $t.=$won; $t.=$tde; $t.=$tre; $t.=$trs; $t.=$tds1; $t.='New won'; $t.=$tde; $t.=$tds; $t.=$new_won; $t.=$tde; $t.=$tre; $t.=$tbe; $quotes=$t; } if($this->orders){ $date=date("Y-m-d",mktime()-3600*24); if(date("l",strtotime($date))=="Sunday")$date=date("Y-m-d",mktime()-3*3600*24); if(date("l",strtotime($date))=="Saturday")$date=date("Y-m-d",mktime()-2*3600*24); if(date("l",strtotime(date("Y-m-d")))=="Friday")$today1=date("Y-m-d",mktime()+3*3600*24); else $today1=date("Y-m-d",mktime()+3600*24); $today=date("Y-m-d"); $nt=$GLOBALS['db']->getRowCount($GLOBALS['db']->query("select e.id from ecmsales as e inner join ecmstockdocouts as w on w.so_id=e.id inner join ecminvoiceouts as inv on inv.wz_id=w.id where e.deleted='0' and inv.register_date like '".$today."' and e.type='sales_order' and e.status!='s10'")); $valuet=$this->getOrdersByDate($today); $valuets=$this->getOrdersByDateNoInv($today1); $n=$GLOBALS['db']->getRowCount($GLOBALS['db']->query("select e.id from ecmsales as e inner join ecmstockdocouts as w on w.so_id=e.id inner join ecminvoiceouts as inv on inv.wz_id=w.id where e.deleted='0' and inv.register_date like '".$date."' and e.type='sales_order' and e.status!='s10'")); $value=$this->getOrdersByDate($date); $values=$this->getOrdersByDateNoInv($date); $ny=$GLOBALS['db']->getRowCount($GLOBALS['db']->query("select e.id from ecmsales as e inner join ecmstockdocouts as w on w.so_id=e.id inner join ecminvoiceouts as inv on inv.wz_id=w.id where e.deleted='0' and inv.register_date like '".date("Y")."%' and e.type='sales_order' and e.status!='s10'")); $valuey=$this->getOrdersByDate(date("Y")); //$valueys=$this->getOrdersByDateNoInv(date("Y")); $nm=$GLOBALS['db']->getRowCount($GLOBALS['db']->query("select e.id from ecmsales as e inner join ecmstockdocouts as w on w.so_id=e.id inner join ecminvoiceouts as inv on inv.wz_id=w.id where e.deleted='0' and inv.register_date like '".date("Y-m")."%' and e.type='sales_order' and e.status!='s10'")); $valuem=$this->getOrdersByDate(date("Y-m")); $valuems=$this->getOrdersByDateNoInv(date("Y-m")); $valuet_sale=$this->getSalesBydate($today); $value_sale=$this->getSalesBydate($date); $valuey_sale=$this->getSalesBydate(date("Y")); $valuem_sale=$this->getSalesBydate(date("Y-m")); $valuet_salec=$this->getSalesBydate(date("Y-m-d"),1); $value_salec=$this->getSalesBydate($date,1); $valuey_salec=$this->getSalesBydate(date("Y"),1); $valuem_salec=$this->getSalesBydate(date("Y-m"),1); $t='

'.$this->orders_title.'

'.$tbs; $t.=$trs; $t.=$tds1; $t.=" "; $t.=$tde; $t.=$tds1; $t.="No"; $t.=$tde; $t.=$tds1; $t.="Orders PLN"; $t.=$tde; $t.=$tds1; $t.="Sales PLN"; $t.=$tde; $t.=$tds1; $t.="Margin PLN"; $t.=$tde; $t.=$tds1; $t.="Margin %"; $t.=$tde; $t.=$tds1; $t.="Fullfillment"; $t.=$tde; $t.=$tre; $t.=$trs; $t.=$tds; $t.="Today"; $t.=$tde; $t.=$tds; $t.=$nt; $t.=$tde; $t.=$tds; $t.=number_format($valuet,2,",",".")." (".number_format($valuets,2,",",".").")"; $t.=$tde; $t.=$tds; $t.=number_format($valuet_sale['sale']+$valuet_salec['sale'],2,",","."); $t.=$tde; $t.=$tds; $t.=number_format(($valuet_sale['sale']+$valuet_salec['sale'])-($valuet_sale['purchase']+$valuet_salec['purchase']),2,",","."); $t.=$tde; $t.=$tds; $t.=@number_format(100*($valuet_sale['sale']-$valuet_sale['purchase'])/($valuet_sale['sale']),2,",",".")."%"; $t.=$tde; $t.=$tds; $t.=@number_format(100*$valuet_sale['sale']/$valuet,2,",",".")."%"; $t.=$tde; $t.=$tre; $t.=$trs; $t.=$tds; $t.="Last day"; $t.=$tde; $t.=$tds; $t.=$n; $t.=$tde; $t.=$tds; $t.=number_format($value,2,",",".")." (".number_format($values,2,",",".").")"; $t.=$tde; $t.=$tds; $t.=number_format($value_sale['sale']+$value_salec['sale'],2,",","."); $t.=$tde; $t.=$tds; $t.=number_format(($value_sale['sale']+$value_salec['sale'])-($value_sale['purchase']+$value_salec['purchase']),2,",","."); $t.=$tde; $t.=$tds; $t.=@number_format(100*($value_sale['sale']-$value_sale['purchase'])/($value_sale['sale']),2,",",".")."%"; $t.=$tde; $t.=$tds; $t.=@number_format(100*$value_sale['sale']/$value,2,",",".")."%"; $t.=$tde; $t.=$tre; $t.=$trs; $t.=$tds; $t.="Month"; $t.=$tde; $t.=$tds; $t.=$nm; $t.=$tde; $t.=$tds; $t.=number_format($valuem,2,",",".")." (".number_format($valuems,2,",",".").")"; $t.=$tde; $t.=$tds; $t.=number_format($valuem_sale['sale']+$valuem_salec['sale'],2,",","."); $t.=$tde; $t.=$tds; $t.=number_format(($valuem_sale['sale']+$valuem_salec['sale'])-($valuem_sale['purchase']+$valuem_salec['purchase']),2,",","."); $t.=$tde; $t.=$tds; $t.=@number_format(100*($valuem_sale['sale']-$valuem_sale['purchase'])/($valuem_sale['sale']),2,",",".")."%"; $t.=$tde; $t.=$tds; $t.=@number_format(100*$valuem_sale['sale']/$valuem,2,",",".")."%"; $t.=$tde; $t.=$tre; $t.=$trs; $t.=$tds; $t.="Year"; $t.=$tde; $t.=$tds; $t.=$ny; $t.=$tde; $t.=$tds; $t.=number_format($valuey,2,",","."); $t.=$tde; $rr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(discount) as d from ecminvoiceouts where deleted='0' and register_date like '".date("Y")."%' and type!='correct'")); $sale_year=$valuey_sale['sale']+$valuey_salec['sale']-$rr['d']/1.22; //else $sale_year=$valuey_sale['sale']+$valuey_salec['sale']; $t.=$tds; $t.=number_format($sale_year,2,",","."); $t.=$tde; $t.=$tds; $t.=number_format(($valuey_sale['sale']+$valuey_salec['sale'])-($valuey_sale['purchase']+$valuey_salec['purchase']),2,",","."); $t.=$tde; $t.=$tds; $t.=@number_format(100*($valuey_sale['sale']+$valuey_salec['sale']-($valuey_sale['purchase']+$valuey_salec['purchase']))/($valuey_sale['sale']+$valuey_salec['sale']),2,",",".")."%"; $t.=$tde; $t.=$tds; $t.=@number_format(100*$valuey_sale['sale']/$valuey,2,",",".")."%"; $t.=$tde; $t.=$tre; $t.=$tbe; $orders=$t; } //} $oa[]=array("type"=>"sales","no"=>$this->sales_no); $oa[]=array("type"=>"sales_year","no"=>$this->sales_year_no); $oa[]=array("type"=>"products","no"=>$this->products_no); $oa[]=array("type"=>"new_products","no"=>$this->new_products_no); $oa[]=array("type"=>"quotes","no"=>$this->quotes_no); $oa[]=array("type"=>"orders","no"=>$this->orders_no); $oa[]=array("type"=>"percent","no"=>$this->payments_no); $oa[]=array("type"=>"stocks","no"=>$this->stocks_no); $oa[]=array("type"=>"payments","no"=>$this->payments_no); $oa=$this->multisort($oa,array(array('key'=>'no','sort'=>'asc'))); if(count($oa)>0){ foreach($oa as $o){ if($$o['type'])$str.=$$o['type'].'
'; } } return parent::display("") . $str . '
'; } /** * Displays the javascript for the dashlet * * @return string javascript to use with this dashlet */ function multisort($data,$keys) { if(count($data)>0) { foreach($data as $key => $row) { foreach($keys as $k) { $cols[$k['key']][$key] = $row[$k['key']]; } } $idkeys=@array_keys($data); $i=0; foreach($keys as $k) { if($i>0)$sort.=','; $sort.='$cols['.$k['key'].']'; if($k['sort'])$sort.=',SORT_'.strtoupper($k['sort']); if($k['type'])$sort.=',SORT_'.strtoupper($k['type']); $i++; } $sort.=',$idkeys'; $sort='@array_multisort('.$sort.');'; eval($sort); foreach($idkeys as $idkey) { $result[$idkey]=$data[$idkey]; } return $result; } } function displayScript() { $ss = new Sugar_Smarty(); $ss->assign('saving', $this->dashletStrings['LBL_SAVING']); $ss->assign('saved', $this->dashletStrings['LBL_SAVED']); $ss->assign('id', $this->id); $str = $ss->fetch('modules/Home/Dashlets/MyEcmReportDashlets/MyEcmReportDashletsScript.tpl'); return $str; // return parent::display for title and such } /** * Displays the configuration form for the dashlet * * @return string html to display form */ function selectDate(){ $s="year"; $ss="month"; $t=''; $t.=''; return $t; } function displayOptions() { global $app_strings; $ss = new Sugar_Smarty(); $ss->assign('titleLbl', $this->dashletStrings['LBL_CONFIGURE_TITLE']); $ss->assign('saveLbl', $this->dashletStrings['LBL_CONFIGURE_SAVE']); $ss->assign('title', $this->title); if($this->sales)$sales=" checked"; if($this->sales_year)$sales_year=" checked"; if($this->percent)$percent=" checked"; if($this->quotes)$quotes=" checked"; if($this->orders)$orders=" checked"; if($this->stocks)$stocks=" checked"; if($this->products)$products=" checked"; if($this->new_products)$new_products=" checked"; if($this->payments)$payments=" checked"; if(!$this->sales_title)$this->sales_title="Sales"; if(!$this->sales_year_title)$this->sales_year_title="Sales in this year"; if(!$this->orders_title)$this->orders_title="Orders"; if(!$this->percent_title)$this->percent_title="Fullfillment"; if(!$this->quotes_title)$this->quotes_title="Quotes"; if(!$this->stocks_title)$this->stocks_title="Stocks"; if(!$this->products_title)$this->products_title="Products"; if(!$this->new_products_title)$this->new_products_title="New products"; if(!$this->payments_title)$this->payments_title="Payments"; if(!$this->sales_no)$this->sales_no=1; if(!$this->sales_year_no)$this->sales_year_no=2; if(!$this->orders_no)$this->orders_no=3; if(!$this->percent_no)$this->percent_no=4; if(!$this->quotes_no)$this->quotes_no=5; if(!$this->stocks_no)$this->stocks_no=6; if(!$this->products_no)$this->products_no=7; if(!$this->new_products_no)$this->new_products_no=8; if(!$this->payments_no)$this->payments_no=9; $ss->assign('sales_title', ''); $ss->assign('sales_year_title', ''); $ss->assign('percent_title', ''); $ss->assign('quotes_title', ''); $ss->assign('orders_title', ''); $ss->assign('stocks_title', ''); $ss->assign('products_title', ''); $ss->assign('new_products_title', ''); $ss->assign('payments_title', ''); $ss->assign('sales_no', ''); $ss->assign('sales_year_no', ''); $ss->assign('percent_no', ''); $ss->assign('quotes_no', ''); $ss->assign('orders_no', ''); $ss->assign('stocks_no', ''); $ss->assign('products_no', ''); $ss->assign('new_products_no', ''); $ss->assign('payments_no', ''); $ss->assign('date', $this->selectDate()); $ss->assign('sales', ''); $ss->assign('sales_year', ''); $ss->assign('percent', ''); $ss->assign('quotes', ''); $ss->assign('orders', ''); $ss->assign('stocks', ''); $ss->assign('products', ''); $ss->assign('new_products', ''); $ss->assign('payments', ''); $ss->assign('id', $this->id); return parent::displayOptions() . $ss->fetch('modules/Home/Dashlets/MyEcmReportDashlets/MyEcmReportDashletOptions.tpl'); } function saveOptions($req) { global $sugar_config, $timedate, $current_user, $theme; $options = array(); $options['month'] = $_REQUEST['month']; $options['year'] = $_REQUEST['year']; $options['title'] = $_REQUEST['title']; $options['sales'] = $_REQUEST['sales']; $options['sales_year'] = $_REQUEST['sales_year']; $options['percent'] = $_REQUEST['percent']; $options['quotes'] = $_REQUEST['quotes']; $options['orders'] = $_REQUEST['orders']; $options['stocks'] = $_REQUEST['stocks']; $options['products'] = $_REQUEST['products']; $options['new_products'] = $_REQUEST['new_products']; $options['payments'] = $_REQUEST['payments']; $options['sales_title'] = $_REQUEST['sales_title']; $options['sales_year_title'] = $_REQUEST['sales_year_title']; $options['percent_title'] = $_REQUEST['percent_title']; $options['quotes_title'] = $_REQUEST['quotes_title']; $options['orders_title'] = $_REQUEST['orders_title']; $options['stocks_title'] = $_REQUEST['stocks_title']; $options['products_title'] = $_REQUEST['products_title']; $options['new_products_title'] = $_REQUEST['new_products_title']; $options['payments_title'] = $_REQUEST['payments_title']; $options['sales_no'] = $_REQUEST['sales_no']; $options['sales_year_no'] = $_REQUEST['sales_year_no']; $options['percent_no'] = $_REQUEST['percent_no']; $options['quotes_no'] = $_REQUEST['quotes_no']; $options['orders_no'] = $_REQUEST['orders_no']; $options['stocks_no'] = $_REQUEST['stocks_no']; $options['products_no'] = $_REQUEST['products_no']; $options['new_products_no'] = $_REQUEST['new_products_no']; $options['payments_no'] = $_REQUEST['payments_no']; return $options; } } ?>