Add php files

This commit is contained in:
2025-05-12 15:44:39 +00:00
parent c951760058
commit 82d5804ac4
9534 changed files with 2638137 additions and 0 deletions

View File

@@ -0,0 +1,178 @@
<?php
session_start();
include_once( '/var/www/html/e5crm/config.php');
mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
mysql_select_db($sugar_config['dbconfig']['db_name']);
mysql_query("set names utf8");
include_once( '/var/www/html/e5crm/include/ECM/open_flash_chart/ofc-library/open-flash-chart.php' );
include_once('/var/www/html/e5crm/modules/EcmReports/cache.php');
include_once('/var/www/html/e5crm/modules/EcmCharts/helperChart.php');
$sh=$_SESSION['EcmCharts_5_d_show'];
$ye=$_SESSION['EcmCharts_5_d_year'];
$temp=0;
$months=array('styczeń','luty','marzec','kwiecień','maj','czerwiec','lipiec','sierpień','wrzesień','październik','listopad','grudzień');
$s1=getSalesByProduct($_REQUEST['category'],$ye."-01-01",$ye."-12-31","",$_SESSION['EcmCharts_5_d_account']);
$s2=getSalesByProduct($_REQUEST['category'],($ye-1)."-01-01",($ye-1)."-12-31","",$_SESSION['EcmCharts_5_d_account']);
for($i=1;$i<=12;$i++){
if($i<10)$n="0".$i;
else $n=$i;
$value1=$s1[$i];
$value2=$s2[$i];
$dsc1+=$value1['dsc'];
$dsc2+=$value2['dsc'];
if(in_array("sales",$sh)){
if($value1['sales']>$temp)$temp=$value1['sales'];
if(!$value1['sales'])$value1n=0;
else $value1n=$value1['sales'];
if($value2['sales']>$temp)$temp=$value2['sales'];
if(!$value2['sales'])$value1b=0;
else $value1b=$value2['sales'];
}
if(in_array("quantity",$sh)){
if($value1['quantity']>$temp)$temp=$value1['quantity'];
if(!$value1['quantity'])$value2n=0;
else $value2n=$value1['quantity'];
if($value2['quantity']>$temp)$temp=$value2['quantity'];
if(!$value2['quantity'])$value2b=0;
else $value2b=$value2['quantity'];
}
//if(in_array("pln_margin",$sh)){
$pln_margin=$value1['sales']-$value1['purchase'];
if($pln_margin>$temp)$temp=$pln_margin;
if(!$pln_margin)$value3n=0;
$value3n=$pln_margin;
$pln_margin=$value2['sales']-$value2['purchase'];
if($pln_margin>$temp)$temp=$pln_margin;
if(!$pln_margin)$value3b=0;
$value3b=$pln_margin;
//}
if(in_array("margin",$sh)){
$mar++;
if($value1['sales']>0)$margin=100*($value1['sales']-$value1['purchase'])/$value1['sales'];
else $margin=0;
if($margin>$temp_margin)$temp_margin=$margin;
if(!$margin)$value4n=0;
$value4n=$margin;
$marb++;
if($value2['sales']>0)$margin=100*($value2['sales']-$value2['purchase'])/$value2['sales'];
else $margin=0;
if($margin>$temp_margin)$temp_margin=$margin;
if(!$margin)$value4b=0;
$value4b=$margin;
}
$arr[]=array(
"name"=>$months[$i-1],
"value1n"=>$value1n,
"value2n"=>$value2n,
"value3n"=>$value3n,
"value4n"=>$value4n,
"value1b"=>$value1b,
"value2b"=>$value2b,
"value3b"=>$value3b,
"value4b"=>$value4b,
);
}
foreach($arr as $a){
$sum1n+=$a['value1n'];
$sum2n+=$a['value2n'];
$sum3n+=$a['value3n'];
$sum4n+=$a['value4n'];
$sum1b+=$a['value1b'];
$sum2b+=$a['value2b'];
$sum3b+=$a['value3b'];
$sum4b+=$a['value4b'];
$data_1n[]=$a['value1n'];
$data_1b[]=$a['value1b'];
$data_2n[]=$a['value2n'];
$data_2b[]=$a['value2b'];
$data_3n[]=$a['value3n'];
$data_3b[]=$a['value3b'];
$data_4n[]=$a['value4n'];
$data_4b[]=$a['value4b'];
$labels[]=repl($a['name']);
}
$rdsc=mysql_fetch_array(mysql_query("select sum(discount) as d from ecminvoiceouts where discount>0 and deleted='0' and register_date like '".$ye."%'"));
$sum1n-=$rdsc['d']/1.22;
$rdsc=mysql_fetch_array(mysql_query("select sum(discount) as d from ecminvoiceouts where discount>0 and deleted='0' and register_date like '".($ye-1)."%'"));
$sum1b-=$rdsc['d']/1.22;
if($_SESSION['EcmCharts_5_d_account']){
$r=mysql_fetch_array(mysql_query("select name from accounts where id='".$_SESSION['EcmCharts_5_d_account']."'"));
$acc_name=" - ".$r['name'];
}
if($_REQUEST['category']){
$r=mysql_fetch_array(mysql_query("select name from ecmproductcategories where id='".$_REQUEST['category']."'"));
$cat_name=" - ".$r['name'];
}
$g = new graph();
if(in_array("sales",$sh))$g->set_data( $data_1b );
if(in_array("sales",$sh))$g->set_data( $data_1n );
if(in_array("quantity",$sh))$g->set_data( $data_2b );
if(in_array("quantity",$sh))$g->set_data( $data_2n );
if(in_array("pln_margin",$sh))$g->set_data( $data_3b );
if(in_array("pln_margin",$sh))$g->set_data( $data_3n );
if(in_array("margin",$sh))$g->set_data( $data_4b );
if(in_array("margin",$sh))$g->set_data( $data_4n );
$m=(int)date("m");
if($m==1){
$year--;
$m=12;
}
else $m--;
if($m<10)$m="0".$m;
$rp=0;
if(in_array("sales",$sh)){
$rp++;
$g->bar( 75, '#00CC00', "Sprzedaż ".($ye-1)." - ".number_format($sum1b,2,"."," "), 10 );
$g->bar( 75, '#006600', "Sprzedaż ".$ye." - ".number_format($sum1n,2,"."," "), 10 );
}
if(in_array("quantity",$sh)){
$rp++;
$g->bar( 75, '#999999', "Ilość ".($ye-1)." - ".number_format($sum2b,2,"."," "), 10 );
$g->bar( 75, '#000000', "Ilość ".$ye." - ".number_format($sum2n,2,"."," "), 10 );
}
if(in_array("pln_margin",$sh)){
$rp++;
$g->bar( 75, '#3334AD', "Margines PLN ".($ye-1)." - ".number_format($sum3b,2,"."," "), 10 );
$g->bar( 75, '#0000cc', "Margines PLN ".$ye." - ".number_format($sum3n,2,"."," "), 10 );
}
if(in_array("margin",$sh)){
$margb=100*$sum3b/$sum1b;
$margn=100*$sum3n/$sum1n;
$g->bar( 75, '#D54C78', "Margines ".($ye-1)." - ".round($margb,2)." ", 10 );
$g->bar( 75, '#882042', "Margines ".($ye)." - ".round($margn,2)." ", 10 );
}
if(in_array("margin",$sh)){
$g->attach_to_y_right_axis(2*($rp)+1);
$g->attach_to_y_right_axis(2*($rp)+2);
}
$g->x_axis_colour( '#909090', '#ADB5C7' );
$g->y_axis_colour( '#909090', '#ADB5C7' );
$g->set_x_labels( $labels );
$g->set_x_label_style( 10, '#000000', 2 );
$g->set_y_max( $temp );
$g->set_y_right_max( $temp_margin );
$g->y_label_steps( 20 );
$g->set_y_legend( '', 12, '#736AFF' );
$g->set_y_right_legend( '' ,12 , '#164166' );
echo $g->render();
mysql_close($sql);
?>

View File

@@ -0,0 +1,46 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*/
global $app_strings;
$dashletMeta['MyChartsAccountsDashlet'] = array(
'title' => 'Wykres: Kontrahenci',
'description' => 'A customizable view into Tasks',
'category' => 'Charts');
?>

View File

@@ -0,0 +1,82 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/Dashlets/Dashlet.php');
require_once('include/Sugar_Smarty.php');
class MyChartsAccountsDashlet extends Dashlet {
var $savedText; // users's saved text
var $height = '300'; // height of the pad
function MyChartsAccountsDashlet($id, $def) {
global $current_user;
parent::Dashlet($id); // call parent constructor
$this->isConfigurable = true; // dashlet is configurable
$this->hasScript = false; // dashlet has java ipt attached to it
if($current_user->id=='2e72f487-d92b-954e-f50c-528b10ce81c9'){
}
// if no custom title, use default
if(empty($def['title'])) $this->title = 'Wykres: Sprzedaż ';
else $this->title = $def['title'];
}
function display() {
global $current_user;
$ss = new Sugar_Smarty();
$optionsArray = $this->loadOptions();
$ss->assign('account_id',$optionsArray['account_id']);
$ss->assign('id', $this->id);
$ss->assign('year', $optionsArray['year']);
$ss->assign('height', $this->height);
$_SESSION['EcmCharts_5_d_year']=$optionsArray['year'];
$_SESSION['EcmCharts_5_d_category']=$category;
$_SESSION['EcmCharts_5_d_show']=$optionsArray['show'];
$_SESSION['EcmCharts_5_d_account']=$optionsArray['account_id'];
if(!isset($_SESSION['EcmCharts_5_d_year']))$_SESSION['EcmCharts_5_d_year']=(int)date("Y");
if(!isset($_SESSION['EcmCharts_5_d_category']))$_SESSION['EcmCharts_5_d_category']='';
if(!isset($_SESSION['EcmCharts_5_d_account']))$_SESSION['EcmCharts_5_d_account']='';
if(!isset($_SESSION['EcmCharts_5_d_show']))$_SESSION['EcmCharts_5_d_show']=Array (0=>'sales');
//$_SESSION['EcmCharts_5_d_mmm']=$mmm;
//return parent::display("") . $str . '<br />';
$str = $ss->fetch('modules/EcmCharts/Dashlets/MyChartsAccountsDashlet/MyChartsAccountsDashlet.tpl');
return parent::display($this->dashletStrings['LBL_DBLCLICK_HELP']) . $str . '<br />'; // return parent::display for title and such
}
function displayOptions() {
global $app_strings,$current_user;
$ss = new Sugar_Smarty();
$ss->assign('year',$_SESSION['EcmCharts_5_d_year']);
$ss->assign('id', $this->id); //The id must be assigned in all dashlet options pages
return parent::displayOptions() . $ss->fetch('modules/EcmCharts/Dashlets/MyChartsAccountsDashlet/MyChartsAccountsDashletOptions.tpl');
}
function saveOptions($req) {
global $sugar_config, $timedate, $current_user, $theme;
$options = array();
$options['account_name']=$_REQUEST['account_name'];
$options['account_id']=$_REQUEST['account_id'];
$options['year']=$_REQUEST['year'];
$options['show']=$_REQUEST['show'];
$options['category']=$_REQUEST['category'];
return $options;
}
}
?>

View File

@@ -0,0 +1,151 @@
<?php
class ChartsAgreementsDashlet
{
private $outputOptions = null;
private $options = null;
private $db = null;
private $monthName = null;
private $comparativeData = null;
private $months;
public function getTable($db, $date_from)
{
$Calendar_daFormat = str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));
// Default value from date input
$dateq=date("Y-m-d",strtotime($date_from));
$total=0;
$total_o=0;
$total_p=0;
$total_r=0;
$q=$db->query("select payment_date,(interest_rate) as rate,sum(rate_of_commission) as rate2,sum(principal_value) as rate3,sum(rate_of_commission+principal_value+interest_rate) as total from ecmagreementitems
where payment_date>='".$dateq."'
group by payment_date asc");
$table=array();
$chart=array();
while($row=$db->fetchByAssoc($q)){
$row['payment_date']=$this->dateV('Y F',strtotime($row['payment_date']));
$total+=$row['total'];
$total_o+=$row['rate'];
$total_p+=$row['rate2'];
$total_r+=$row['rate3'];
$table[]=$row;
}
return $table;
}
function dateV($format,$timestamp=null){
$to_convert = array(
'l'=>array('dat'=>'N','str'=>array('Poniedziałek','Wtorek','Środa','Czwartek','Piątek','Sobota','Niedziela')),
'F'=>array('dat'=>'n','str'=>array('styczeń','luty','marzec','kwiecień','maj','czerwiec','lipiec','sierpień','wrzesień','październik','listopad','grudzień')),
'f'=>array('dat'=>'n','str'=>array('stycznia','lutego','marca','kwietnia','maja','czerwca','lipca','sierpnia','września','października','listopada','grudnia'))
);
if ($pieces = preg_split('#[:/.\-, ]#', $format)){
if ($timestamp === null) { $timestamp = time(); }
foreach ($pieces as $datepart){
if (array_key_exists($datepart,$to_convert)){
$replace[] = $to_convert[$datepart]['str'][(date($to_convert[$datepart]['dat'],$timestamp)-1)];
}else{
$replace[] = date($datepart,$timestamp);
}
}
$result = strtr($format,array_combine($pieces,$replace));
return $result;
}
}
// Zwraca ustawienia Google Charts
public function getChartOptions()
{
$months = $this->getMonths();
$data = "";
for( $i = 0; $i < count($months); $i++ )
{
if( $months[$i] != 0 && $months[$i] != null)
{
$value = sprintf("%.2f", (float)$months[$i]);
$data .= "['".$this->monthName[$i]."', ". $value;
if( $this->options["comparativeData"] == "enabled" )
$data .= ", ".$this->comparativeData[$i].'0';
$data .= "],";
}
}
$data = rtrim($data, ",");
return $data;
}
// Pobiera tablice z wartościami sum netto dla każdego roku
private function getMonths()
{
$months = array();
$thisYear = date("Y");
$thisMonth = date("m");
for( $i = 1; $i <= 12; $i++ )
{
$result = $this->getSubtotalByMonth(($i <= 9 ? '0'.$i : $i), $this->options['year']);
array_push($months, $result);
}
$this->months = $months;
return $months;
}
// Metoda zwraca cenę netto dla danego miesiąca w danym roku
private function getSubtotalByMonth($month, $year)
{
$type = $this->options["type"];
$query = "
SELECT
SUM(CASE WHEN e.currency_value = '0' OR e.currency_value = '' OR e.currency_value=0 OR e.currency_value is null
THEN
e.total_netto
ELSE
e.total_netto*e.currency_value
END
) as 'subtotal'
FROM
ecminvoiceouts e
WHERE e.canceled = '0'
AND e.deleted = '0'
AND e.type LIKE '$type'
AND e.register_date LIKE '$year-$month-%'
";
//echo $query."<br><br>";
if( $this->options["contractor_id"] && $this->options["contractor_name"])
{
$query .= "AND e.parent_id = '".$this->options["contractor_id"]."'";
}
$results = $this->db->query($query);
$result = $this->db->fetchByAssoc( $results );
return $result['subtotal'];
}
public function getMonthsArray()
{
return $this->months;
}
public function haveComparativeData()
{
if( $this->comparativeData != null )
return true;
else
return false;
}
}
?>

View File

@@ -0,0 +1,45 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*/
global $mod_strings;
$dashletMeta['MyChartsAgreementsDashlet'] = array(
'title' => 'Wykres należności',
'description' => 'Wykres słupkowy, w widoku poziomym przedstawiający sprzedaż w aktualnym roku z danymi porównawczymi sprzed roku i możliwością filtrowania',
'category' => 'Charts');
?>

View File

@@ -0,0 +1,113 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/Dashlets/Dashlet.php');
require_once('include/Sugar_Smarty.php');
require_once('ChartsAgreementsDashlet.php');
class MyChartsAgreementsDashlet extends Dashlet {
var $savedText; // users's saved text
var $height = '300'; // height of the pad
var $firstLoad = 'yes';
function MyChartsAgreementsDashlet($id, $def = null) {
global $current_user, $mod_strings, $app_strings;
require('modules/EcmCharts/Dashlets/MyChartsAgreementsDashlet/MyChartsAgreementsDashlet.meta.php');
require('modules/EcmCharts/language/pl_pl.lang.php');
parent::Dashlet($id); // call parent constructor
$this->isConfigurable = true; // dashlet is configurable
$this->hasScript = false; // dashlet has java ipt attached to it
$options = $this->loadOptions();
// if no custom title, use default
if(!$options["title"])
$options["title"] = "Wykres należności";
$this->title = $options["title"];
}
function display() {
global $current_user, $mod_strings, $app_strings;
$Calendar_daFormat = str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));
$options = $this->loadOptions();
$comparativeData = null;
$options2 = null;
$db_connection_handler = $GLOBALS["db"];
$options = $this->loadOptions();
// Data od
if(!$options['date_from'])
$options['date_from'] = '01.01.2010';
/*
* SMARTY
*/
$n= New ChartsAgreementsDashlet();
$smarty = new Sugar_Smarty();
$smarty->assign('date_from', $options["date_from"]);
$smarty->assign("dateFormat", $Calendar_daFormat);
$smarty->assign('LANG', $mod_strings);
$smarty->assign('TABLE',$n->getTable($GLOBALS['db'],$options['date_from']));
// Pobieranie widoku
$output = $smarty->fetch('modules/EcmCharts/Dashlets/MyChartsAgreementsDashlet/MyChartsAgreementsDashlet.tpl');
// return parent::display for title and smarty template
return parent::display($this->dashletStrings['LBL_DBLCLICK_HELP']) . $output;
}
function displayOptions() {
global $mod_strings,$current_user;
// format daty
$smarty = new Sugar_Smarty();
// Pobieram ustawienia
$options = $this->loadOptions();
// Data od
$Calendar_daFormat = str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));
if(!$options['date_from'])
$options['date_from'] = '01.01.2010';
//The id must be assigned in all dashlet options pages
$smarty->assign('id', $this->id);
// Typ dokumentu: all, normal, correct
$smarty->assign('date_from', $options["date_from"]);
$smarty->assign("dateFormat", $Calendar_daFormat);
$smarty->assign('LANG', $mod_strings);
$smarty->assign('title', $options["title"]);
// Pokazywać dane porównawcze? Tak: enabled, nie: disabled
// Przekazuję widok opcji do metody displayOptions()
return parent::displayOptions() . $smarty->fetch('modules/EcmCharts/Dashlets/MyChartsAgreementsDashlet/MyChartsAgreementsDashletOptions.tpl');
}
// Zapisywanie opcji dashletu
function saveOptions($req) {
$options = array();
$options["year"] = $req["year"];
$options["comparativeData"] = $req["comparativeData"];
$options["type"] = $req["type"];
$options["chartType"] = $req["chartType"];
$options["title"] = $req["title"];
if( $req["account_name"] == '' )
{
$options["contractor_name"] = '';
$options["contractor_id"] = '';
} else {
$options["contractor_name"] = $req['account_name'];
$options["contractor_id"] = $req['account_id'];
}
return $options;
}
}
?>

View File

@@ -0,0 +1,46 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*/
global $app_strings;
$dashletMeta['MyChartsCallTimeDashlet'] = array(
'title' => 'Wykres: Produkty',
'description' => 'A customizable view into Tasks',
'category' => 'Charts');
?>

View File

@@ -0,0 +1,79 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/Dashlets/Dashlet.php');
require_once('include/Sugar_Smarty.php');
class MyChartsCallTimeDashlet extends Dashlet {
var $savedText; // users's saved text
var $height = '300'; // height of the pad
function MyChartsCallTimeDashlet($id, $def) {
global $current_user;
parent::Dashlet($id); // call parent constructor
$this->isConfigurable = true; // dashlet is configurable
$this->hasScript = false; // dashlet has java ipt attached to it
if($current_user->id=='2e72f487-d92b-954e-f50c-528b10ce81c9'){
}
// if no custom title, use default
if(empty($def['title'])) $this->title = 'Wykres: Produkty ';
else $this->title = $def['title'];
}
function display() {
global $current_user;
$ss = new Sugar_Smarty();
$optionsArray = $this->loadOptions();
//$ss->assign('account_id',$optionsArray['account_id']);
$ss->assign('id', $this->id);
$ss->assign('height', $this->height);
$_SESSION['EcmCharts_1_d_year']=$optionsArray['year'];
$_SESSION['EcmCharts_1_d_category']=$category;
$_SESSION['EcmCharts_1_d_show']=$optionsArray['show'];
$_SESSION['EcmCharts_1_d_account']=$optionsArray['account_id'];
if(!isset($_SESSION['EcmCharts_1_d_year']))$_SESSION['EcmCharts_1_d_year']=(int)date("Y");
if(!isset($_SESSION['EcmCharts_1_d_category']))$_SESSION['EcmCharts_1_d_category']='';
if(!isset($_SESSION['EcmCharts_1_d_account']))$_SESSION['EcmCharts_1_d_account']='';
if(!isset($_SESSION['EcmCharts_1_d_show']))$_SESSION['EcmCharts_1_d_show']=Array (0=>'sales');
//$_SESSION['EcmCharts_1_d_mmm']=$mmm;
include_once('include/ECM/open_flash_chart/ofc-library/open_flash_chart_object.php');
$str = $ss->fetch('modules/EcmCharts/Dashlets/MyChartsCallTimeDashlet/MyChartsCallTimeDashlet.tpl');
return parent::display($this->dashletStrings['LBL_DBLCLICK_HELP']) . $str . '<br />'; // return parent::display for title and such
}
function displayOptions() {
global $app_strings,$current_user;
$ss = new Sugar_Smarty();
$ss->assign('year',$_SESSION['EcmCharts_1_d_year']);
$ss->assign('id', $this->id); //The id must be assigned in all dashlet options pages
return parent::displayOptions() . $ss->fetch('modules/EcmCharts/Dashlets/MyChartsCallTimeDashlet/MyChartsCallTimeDashletOptions.tpl');
}
function saveOptions($req) {
global $sugar_config, $timedate, $current_user, $theme;
$options = array();
$options['account_name']=$_REQUEST['account_name'];
$options['account_id']=$_REQUEST['account_id'];
$options['year']=$_REQUEST['year'];
$options['show']=$_REQUEST['show'];
$options['category']=$_REQUEST['category'];
return $options;
}
}
?>

View File

@@ -0,0 +1,46 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*/
global $app_strings;
$dashletMeta['MyChartsCategoryDashlet'] = array(
'title' => 'Wykres: Kategorie',
'description' => 'A customizable view into Tasks',
'category' => 'Charts');
?>

View File

@@ -0,0 +1,79 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/Dashlets/Dashlet.php');
require_once('include/Sugar_Smarty.php');
class MyChartsCategoryDashlet extends Dashlet {
var $savedText; // users's saved text
var $height = '300'; // height of the pad
function MyChartsCategoryDashlet($id, $def) {
global $current_user;
parent::Dashlet($id); // call parent constructor
$this->isConfigurable = true; // dashlet is configurable
$this->hasScript = false; // dashlet has java ipt attached to it
if($current_user->id=='2e72f487-d92b-954e-f50c-528b10ce81c9'){
}
// if no custom title, use default
if(empty($def['title'])) $this->title = 'Wykres: Kategorie ';
else $this->title = $def['title'];
}
function display() {
global $current_user;
$ss = new Sugar_Smarty();
$optionsArray = $this->loadOptions();
//$ss->assign('account_id',$optionsArray['account_id']);
$ss->assign('id', $this->id);
$ss->assign('height', $this->height);
$_SESSION['EcmCharts_d_2_year']=$optionsArray['year'];
$_SESSION['EcmCharts_d_2_category']=$category;
$_SESSION['EcmCharts_d_2_show']=$optionsArray['show'];
$_SESSION['EcmCharts_d_2_account']=$optionsArray['account_id'];
if(!isset($_SESSION['EcmCharts_d_2_year']))$_SESSION['EcmCharts_d_2_year']=(int)date("Y");
if(!isset($_SESSION['EcmCharts_d_2_category']))$_SESSION['EcmCharts_d_2_category']='';
if(!isset($_SESSION['EcmCharts_d_2_account']))$_SESSION['EcmCharts_d_2_account']='';
if(!isset($_SESSION['EcmCharts_d_2_show']))$_SESSION['EcmCharts_d_2_show']=Array (0=>'sales');
//$_SESSION['EcmCharts_d_2_mmm']=$mmm;
$str = $ss->fetch('modules/EcmCharts/Dashlets/MyChartsCategoryDashlet/MyChartsCategoryDashlet.tpl');
return parent::display($this->dashletStrings['LBL_DBLCLICK_HELP']) . $str . '<br />'; // return parent::display for title and such
}
function displayOptions() {
global $app_strings,$current_user;
$ss = new Sugar_Smarty();
$ss->assign('year',$_SESSION['EcmCharts_d_2_year']);
$ss->assign('id', $this->id); //The id must be assigned in all dashlet options pages
return parent::displayOptions() . $ss->fetch('modules/EcmCharts/Dashlets/MyChartsCategoryDashlet/MyChartsCategoryDashletOptions.tpl');
}
function saveOptions($req) {
global $sugar_config, $timedate, $current_user, $theme;
$options = array();
$options['account_name']=$_REQUEST['account_name'];
$options['account_id']=$_REQUEST['account_id'];
$options['year']=$_REQUEST['year'];
$options['show']=$_REQUEST['show'];
$options['category']=$_REQUEST['category'];
return $options;
}
}
?>

View File

@@ -0,0 +1,46 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*/
global $app_strings;
$dashletMeta['MyChartsCustomDashlet'] = array(
'title' => 'Raport summary',
'description' => 'A customizable view into Tasks',
'category' => 'Charts');
?>

View File

@@ -0,0 +1,944 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/Dashlets/Dashlet.php');
require_once('include/Sugar_Smarty.php');
include_once("modules/EcmReports/cache.php");
class MyChartsCustomDashlet extends Dashlet {
var $savedText; // users's saved text
var $height = '300'; // height of the pad
function MyChartsCustomDashlet($id, $def) {
global $current_user;
parent::Dashlet($id); // call parent constructor
$this->isConfigurable = true; // dashlet is configurable
$this->hasScript = false; // dashlet has java ipt attached to it
if($current_user->id=='2e72f487-d92b-954e-f50c-528b10ce81c9'){
}
// if no custom title, use default
if(empty($def['title'])) $this->title = 'Raport stary crm ';
else $this->title = $def['title'];
}
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 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() {
global $current_user;
$ss = new Sugar_Smarty();
$optionsArray = $this->loadOptions();
//$ss->assign('account_id',$optionsArray['account_id']);
$h=0;
$ss->assign('id', $this->id);
$ss->assign('id', $this->id);
$ss->assign('sales_year_title', $optionsArray['sales_year_title']);
$ss->assign('sales_title',$optionsArray['sales_title']);
$ss->assign('sales_year_title',$optionsArray['sales_year_title']);
$ss->assign('percent_title',$optionsArray['percent_title']);
$ss->assign('quotes_title',$optionsArray['quotes_title']);
$ss->assign('orders_title',$optionsArray['orders_title']);
$ss->assign('stocks_title',$optionsArray['stocks_title']);
$ss->assign('products_title',$optionsArray['products_title']);
$ss->assign('new_products_title',$optionsArray['new_products_title']);
$ss->assign('payments_title',$optionsArray['payments_title']);
$tds1='<td class="listViewThS1">';
$tds1c='<td class="listViewThS1" style="width:100px;">';
$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>';
$lock=1;
if($optionsArray['new_products']){
$t='<h2>'.$optionsArray['new_products_title'].'</h2><br>'.$tbs;
$t.=$trs;
$t.=$tds1c;
$t.="Indeks";
$t.=$tde;
$t.=$tds1;
$t.="Nazwa";
$t.=$tde;
$t.=$tds1;
$t.="Data Utworzenia";
$t.=$tde;
$t.=$tre;
$get=date("d");
$m=date("n");
if($m<10){
$m-1;
$m='0'.$m;
}
$w=$GLOBALS['db']->query("select id,code,name,date_entered
from ecmproducts where deleted='0'
and date_entered>'".date("Y")."-".$m."-01' order by date_entered desc limit 10");
echo mysql_error();
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$t.=$trs;
$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.=$GLOBALS['timedate']->to_display_date($r['date_entered']);
$t.=$tde;
$t.=$tre;
}
$t.=$tbe;
$as.=$t;
}
if(isset($optionsArray['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='<h2>'.$optionsArray['payments_title'].'</h2><br>'.$tbs;
$t.=$trs;
$t.=$tds1;
$t.="Bilans";
$t.=$tde;
$t.=$tds1;
$t.="Podsumowanie";
$t.=$tde;
$t.=$tds1;
$t.="Nie przeterminowane";
$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;
$as.=$t;
}
if($optionsArray['products']){
$t='<h2>'.$optionsArray['products_title'].'</h2>Period: '.$optionsArray['month'].'.'.$optionsArray['year'].'<br>'.$tbs;
$t.=$trs;
$t.=$tds1c;
$t.="Indeks";
$t.=$tde;
$t.=$tds1;
$t.="Nazwa";
$t.=$tde;
$t.=$tds1;
$t.="Sprzedana ilość";
$t.=$tde;
$t.=$tds1;
$t.="Sprzedaż PLN";
$t.=$tde;
$t.=$tds1;
$t.="Margines";
$t.=$tde;
$t.=$tds1;
$t.="Margines PLN";
$t.=$tde;
$t.=$tds1;
$t.="fak ilo";
$t.=$tde;
$t.=$tds1;
$t.="Zam ilo";
$t.=$tde;
$t.=$tds1;
$t.="Prognoza sprzedaży";
$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 '".$optionsArray['year'].'-'.$optionsArray['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 '".$optionsArray['year'].'-'.$optionsArray['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']."<br>";
$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 '<pre>';
//print_r($arr);
//echo '</pre>';
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'],$optionsArray['year'].'-'.$optionsArray['month'],$s);
$t.=$trs;
$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.=@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;
$as.=$t;
}
if(isset($optionsArray['percent'])){
$t='<h2>'.$this->percent_title.'</h2>Period: '.$optionsArray['year'].'.'.$optionsArray['month'].'<br>'.'<table class="listView" cellspacing="0" cellpadding="3" border="0" width="100%">';
$t.='<tr><td class="listViewThS1" width="40%"><strong>Category</strong></td><td class="listViewThS1"><strong>Inv value</strong></td><td class="listViewThS1"><strong>Order</strong></td><td class="listViewThS1"><strong>WZ</strong></td><td class="listViewThS1"><strong>%</strong></td></tr>';
$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='".$optionsArray['year'].'-'.$optionsArray['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.='<tr style="color:'.$color.';"><td style="color:'.$color.';"><a href="index.php?module=EcmProductCategories&action=DetailView&record='.$k.'">'.$rr['name']."</a></td><td>".@number_format($ri['s'],2,",",".")."</td><td style=\"color:".$color.";\">".number_format(($rr['value_sale']),2,",",".")."</td><td style=\"color:".$color.";\">".number_format($rr['value_wz'],2,",",".")."</td><td>".@number_format(100*$rr['value_wz']/$rr['value_sale'],2,",",".")."%</td></tr>";
}
$qty_diff=$rwt-$rst;
$t.='<tr style="color:black;font-weight:bold"><td>Total</td><td>'.@number_format($inv_value,2,",",".").'</td><td>'.number_format(($rst),2,",",".").'</td><td>'.number_format($rwt,2,",",".").'</td><td>'.@number_format(100*$rwt/$rst,2,",",".").'%</td></tr>';
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select value_sale from ecmproductcategories_realisation where date='".$optionsArray['year'].'-'.$optionsArray['month']."' and product_category_id='diff_minus'"));
$t.='<tr><td class="listViewThS1">&nbsp;</td><td class="listViewThS1">&nbsp;</td><td class="listViewThS1">&nbsp;</td><td class="listViewThS1"><span style="color:red;font-weight:bold">'.number_format($r['value_sale'],2,",",".").'</span></td><td class="listViewThS1">&nbsp;</td></tr>';
$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select value_sale from ecmproductcategories_realisation where date='".$optionsArray['year'].'-'.$optionsArray['month']."' and product_category_id='diff_plus'"));
$t.='<tr><td class="listViewThS1">&nbsp;</td><td class="listViewThS1">&nbsp;</td><td class="listViewThS1">&nbsp;</td><td class="listViewThS1"><span style="color:green;font-weight:bold">'.number_format($r['value_sale'],2,",",".").'</span></td><td class="listViewThS1">&nbsp;</td></tr>';
$t.='</table>';
$as.=$t;
}
$a.=$percent;
if($optionsArray['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 '".$optionsArray['year'].'-'.$optionsArray['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<'".$optionsArray['year'].'-'.$optionsArray['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<'".$optionsArray['year'].'-'.$optionsArray['month']."' and deleted='0'"))==0){
$new_won++;
}
}
}
$t='<h2>'.$optionsArray['quotes_title'].'</h2>Okres: '.$optionsArray['month'].'.'.$optionsArray['year'].'<br>'.$tbs;
$t.=$trs;
$t.=$tds1;
$t.='<strong>Sent</strong>';
$t.=$tde;
$t.=$tds;
$t.=$send;
$t.=$tde;
$t.=$tre;
$t.=$trs;
$t.=$tds1;
$t.='<strong>New sent</strong>';
$t.=$tde;
$t.=$tds;
$t.=$new_send;
$t.=$tde;
$t.=$tre;
/*$t.=$trs;
$t.=$tds1;
$t.='<strong>Won</strong>';
$t.=$tde;
$t.=$tds;
$t.=$won;
$t.=$tde;
$t.=$tre;
$t.=$trs;
$t.=$tds1;
$t.='<strong>New won</strong>';
$t.=$tde;
$t.=$tds;
$t.=$new_won;
$t.=$tde;
$t.=$tre;
*/
$t.=$tbe;
$as.=$t;
}
if($optionsArray['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='<h2>'.$this->$optionsArray['orders_title'].'</h2>'.$tbs;
$t.=$trs;
$t.=$tds1;
$t.="&nbsp;";
$t.=$tde;
$t.=$tds1;
$t.="Ile";
$t.=$tde;
$t.=$tds1;
$t.="Zamówień PLN";
$t.=$tde;
$t.=$tds1;
$t.="Sprzedaz PLN";
$t.=$tde;
$t.=$tds1;
$t.="Margines PLN";
$t.=$tde;
$t.=$tds1;
$t.="Margines %";
$t.=$tde;
$t.=$tds1;
$t.="Wypełnione";
$t.=$tde;
$t.=$tre;
$t.=$trs;
$t.=$tds;
$t.="Dzisiaj";
$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.="Wczoraj";
$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.="Miesięcznie";
$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.="Rocznie";
$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;
$as.=$t;
}
//echo $optionsArray['year'];
//echo $optionsArray['month'];
if(!isset($_SESSION['test_y']))$_SESSION['test_y']='2012';
if(!isset($_SESSION['test_m']))$_SESSION['test_m']='12';
$_SESSION['EcmReports_Dashlet_sales_year']=$optionsArray['year'].'-'.$optionsArray['month'];
$_SESSION['test_y']=$optionsArray['year'];
$_SESSION['test_m']=$optionsArray['month'];
$_SESSION['salesy']=$optionsArray['sales_year'];
$_SESSION['sales']=$optionsArray['sales'];
$_SESSION['stocksd']=$optionsArray['stocks'];
if(!isset($optionsArray['stocks']))$_SESSION['stocksd']=0; else $h+=600;
if(!isset($optionsArray['sales_year']))$_SESSION['salesy']=0;else $h+=600;
if(!isset($optionsArray['sales']))$_SESSION['sales']=0;else $h+=600;
//$_SESSION['EcmCharts_d_2_mmm']=$mmm;
$ss->assign('h', $h);
$str = $ss->fetch('modules/EcmCharts/Dashlets/MyChartsCustomDashlet/MyChartsCustomDashlet.tpl');
return parent::display($this->dashletStrings['LBL_DBLCLICK_HELP']) . $str .$as. '<br />'; // return parent::display for title and such
}
function selectDate(){
$s="year";
$ss="month";
$t='<select name="year">';
for($i=date("Y");$i>=2000;$i--){
$t.='<option value="'.$i.'"';
if($this->$s==$i)$t.=' selected';
$t.='>'.$i.'</option>';
}
$t.='</select>';
$t.='<select name="month">';
for($i=1;$i<=12;$i++){
if($i<10)$n="0".$i;
else $n=$i;
$t.='<option value="'.$n.'"';
if($this->$ss==$n)$t.=' selected';
$t.='>'.$n.'</option>';
}
$t.='</select>';
return $t;
}
function displayOptions() {
global $app_strings,$current_user;
$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', '<input style="width:220px;" type="text" name="sales_title" id="sales_title" value="'.$this->sales_title.'">');
$ss->assign('sales_year_title', '<input style="width:220px;" type="text" name="sales_year_title" id="sales_year_title" value="'.$this->sales_year_title.'">');
$ss->assign('percent_title', '<input style="width:220px;" type="text" name="percent_title" id="percent_title" value="'.$this->percent_title.'">');
$ss->assign('quotes_title', '<input style="width:220px;" type="text" name="quotes_title" id="quotes_title" value="'.$this->quotes_title.'">');
$ss->assign('orders_title', '<input style="width:220px;" type="text" name="orders_title" id="orders_title" value="'.$this->orders_title.'">');
$ss->assign('stocks_title', '<input style="width:220px;" type="text" name="stocks_title" id="stocks_title" value="'.$this->stocks_title.'">');
$ss->assign('products_title', '<input style="width:220px;" type="text" name="products_title" id="products_title" value="'.$this->products_title.'">');
$ss->assign('new_products_title', '<input style="width:220px;" type="text" name="new_products_title" id="new_products_title" value="'.$this->new_products_title.'">');
$ss->assign('payments_title', '<input style="width:220px;" type="text" name="payments_title" id="payments_title" value="'.$this->payments_title.'">');
$ss->assign('sales_no', '<input style="width:30px;" type="text" name="sales_no" id="sales_no" value="'.$this->sales_no.'">');
$ss->assign('sales_year_no', '<input style="width:30px;" type="text" name="sales_year_no" id="sales_year_no" value="'.$this->sales_year_no.'">');
$ss->assign('percent_no', '<input style="width:30px;" type="text" name="percent_no" id="percent_no" value="'.$this->percent_no.'">');
$ss->assign('quotes_no', '<input style="width:30px;" type="text" name="quotes_no" id="quotes_no" value="'.$this->quotes_no.'">');
$ss->assign('orders_no', '<input style="width:30px;" type="text" name="orders_no" id="orders_no" value="'.$this->orders_no.'">');
$ss->assign('stocks_no', '<input style="width:30px;" type="text" name="stocks_no" id="stocks_no" value="'.$this->stocks_no.'">');
$ss->assign('products_no', '<input style="width:30px;" type="text" name="products_no" id="products_no" value="'.$this->products_no.'">');
$ss->assign('new_products_no', '<input style="width:30px;" type="text" name="new_products_no" id="new_products_no" value="'.$this->new_products_no.'">');
$ss->assign('payments_no', '<input style="width:30px;" type="text" name="payments_no" id="payments_no" value="'.$this->payments_no.'">');
$ss->assign('date', $this->selectDate());
$ss->assign('sales', '<input type="checkbox" name="sales" id="sales" '.$sales.' value="1">');
$ss->assign('sales_year', '<input type="checkbox" name="sales_year" id="sales_year" '.$sales_year.' value="1">');
$ss->assign('percent', '<input type="checkbox" name="percent" id="percent" '.$percent.' value="1">');
$ss->assign('quotes', '<input type="checkbox" name="quotes" id="quotes" '.$quotes.' value="1">');
$ss->assign('orders', '<input type="checkbox" name="orders" id="orders" '.$orders.' value="1">');
$ss->assign('stocks', '<input type="checkbox" name="stocks" id="stocks" '.$stocks.' value="1">');
$ss->assign('products', '<input type="checkbox" name="products" id="products" '.$products.' value="1">');
$ss->assign('new_products', '<input type="checkbox" name="new_products" id="new_products" '.$new_products.' value="1">');
$ss->assign('payments', '<input type="checkbox" name="payments" id="payments" '.$payments.' value="1">');
$ss->assign('id', $this->id); //The id must be assigned in all dashlet options pages
return parent::displayOptions() . $ss->fetch('modules/EcmCharts/Dashlets/MyChartsCustomDashlet/MyChartsCustomDashletOptions.tpl');
}
function saveOptions($req) {
global $sugar_config, $timedate, $current_user, $theme;
$options = array();
$options['account_name']=$_REQUEST['account_name'];
$options['account_id']=$_REQUEST['account_id'];
$options['year']=$_REQUEST['year'];
$options['month'] = $_REQUEST['month'];
$options['show']=$_REQUEST['show'];
$options['category']=$_REQUEST['category'];
$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'];
return $options;
}
}
?>

View File

@@ -0,0 +1,150 @@
<?php
session_start();
$startTime = microtime(true);
require_once('/var/www/html/e5crm/include/entryPoint.php');
ob_start();
require_once("/var/www/html/e5crm/config.php");
require_once('/var/www/html/e5crm/include/MVC/SugarApplication.php');
$mm = new MysqlManager();
$mm->connect();
/*$app = new SugarApplication();
$app->startSession();
$app->execute();
*/
include_once( '/var/www/html/e5crm/include/ECM/open_flash_chart/ofc-library/open-flash-chart.php' );
include_once("/var/www/html/e5crm/modules/EcmReports/cache.php");
include_once("/var/www/html/e5crm/modules/EcmReports/class.sales.php");
$mmm=(int)date("m")-1;
if($mmm==0)$mmm=12;
$year=$_SESSION['test_y'];
$month=$_SESSION['test_m'];
$year_month=$_SESSION['test_y'].'-'.$_SESSION['test_m'];
$s=new Sales();
$s->date_from=$year."-".$month."-01";
$s->date_to=$year."-".$month."-31";
$sdata=$s->getSalesByCategory();
$pred=new Sales();
$pred->date_from=$year."-01-01";
$pred->date_to=$year."-12-31";
$pred=$pred->getSalesByCategory();
function repl($t){
$a1=array("ą","ś","ę","ż","ź","ć","ń","ó","ł","Ą","Ś","Ę","Ż","Ź","Ć","Ń","Ó","Ł");
$a2=array("a","s","e","z","z","c","n","o","l","A","S","E","Z","Z","C","N","O","L");
return str_replace($a1,$a2,$t);
}
function salesPercent($category_id,$date){
$w=$GLOBALS['db']->query("select value_wz as swz,value_sale as ssale from ecmproductcategories_realisation where product_category_id='".$category_id."' and date='".$date."'");
$r=$GLOBALS['db']->fetchByAssoc($w);
return @100*$r['swz']/$r['ssale'];
}
$s=sum($year_month,"","","","");
$sy=sum($year,"","","","");
$w=$GLOBALS['db']->query("select id,name from ecmproductcategories where deleted='0' and name!='' order by name asc");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
$ss=$sdata[$month][$r['id']];
$pp=$pred[$month][$r['id']];
$v_s=$ss['sales'];
if($v_s>$temp)$temp=$v_s;
$sum_s+=$v_s;
$v_p=$ss['purchase'];
if($v_p>$temp)$temp=$v_p;
$sum_p+=$v_p;
$v_l=$pp['sales']/$mmm;
if($v_l>$temp)$temp=$v_l;
$sum_l+=$v_l;
$v_r=salesPercent($r['id'],$year_month);
$arr_s[]=array(
"name"=>repl($r['name']),
"value"=>$v_s,
);
$arr_p[]=array(
"value"=>$v_p,
);
$arr_l[]=array(
"value"=>$v_l,
);
$arr_r[]=array(
"value"=>$v_r,
);
}
//$arr_s=multisort($arr_s,array(array('key'=>'value','sort'=>'desc')));
for($i=0;$i<count($arr_s);$i++){
$data_1[]=$arr_l[$i]['value'];
$data_2[]=$arr_s[$i]['value'];
$data_3[]=$arr_p[$i]['value'];
$data_4[]=$arr_r[$i]['value'];
$cats[]=$arr_s[$i]['name'];
}
$g = new graph();
//$g->title( 'Sales: '.$year_month, '{font-size:20px; color: #000000; margin: 5px; background-color: #ffffff; padding:5px; padding-left: 20px; padding-right: 20px;}' );
$g->bg_colour = '#ffffff';
$d1 = new bar( 75, '#999999' );
$d2 = new bar( 75, '#D54C78' );
$d3 = new bar( 75, '#3334AD' );
$d1->key( 'Forecast', 10 );
$d2->key( 'Sales', 10 );
$d3->key( 'Margin', 10 );
for($i=0;$i<count($data_1);$i++){
$d1->add_data_tip($data_1[$i],"Margin: ".round($data_3[$i],2)."\nSales: ".round($data_2[$i],2)."\nForecast: ".round($data_1[$i],2)."\nFullfillment: ".round($data_4[$i],2)."%");
$d2->add_data_tip($data_2[$i],"Margin: ".round($data_3[$i],2)."\nSales: ".round($data_2[$i],2)."\nForecast: ".round($data_1[$i],2)."\nFullfillment: ".round($data_4[$i],2)."%");
$d3->add_data_tip($data_3[$i],"Margin: ".round($data_3[$i],2)."\nSales: ".round($data_2[$i],2)."\nForecast: ".round($data_1[$i],2)."\nFullfillment: ".round($data_4[$i],2)."%");
}
$g->data_sets[]=$d1;
$g->data_sets[]=$d2;
$g->data_sets[]=$d3;
$g->set_tool_tip( '#x_label#<br>#tip#<br>' );
//$g->set_data($data_1);
//$g->bar( 75, '#D54C78', '', 10 );
//$g->set_data($data_2);
//$g->bar( 75, '#3334AD', '', 10 );
//$g->attach_to_y_right_axis(2);
$g->x_axis_colour( '#909090', '#ADB5C7' );
$g->y_axis_colour( '#909090', '#ADB5C7' );
$g->y_right_axis_colour( '#909090' );
$g->set_x_labels( $cats );
$g->set_x_label_style( 10, '#000000', 2 );
$g->set_y_max( $temp );
$g->set_y_right_max( $temp);
$g->y_label_steps( 20 );
//$g->y_right_label_steps( 5 );
$g->set_y_legend( '', 12, '#736AFF' );
$g->set_y_right_legend( 'Free Ram (MB)' ,12 , '#164166' );
echo $g->render();
$exit_on_cleanup = true;
sugar_cleanup($exit_on_cleanup);
?>

View File

@@ -0,0 +1,116 @@
<?php
session_start();
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors', '1');
//error_reporting(0);
include_once( '/var/www/html/e5crm/config.php');
$sql=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
mysql_select_db($sugar_config['dbconfig']['db_name']);
mysql_query("set names utf8");
include_once( '/var/www/html/e5crm/include/ECM/open_flash_chart/ofc-library/open-flash-chart.php' );
include_once("/var/www/html/e5crm/modules/EcmReports/cache.php");
function repl($t){
$a1=array("ą","ś","ę","ż","ź","ć","ń","ó","ł","Ą","Ś","Ę","Ż","Ź","Ć","Ń","Ó","Ł");
$a2=array("a","s","e","z","z","c","n","o","l","A","S","E","Z","Z","C","N","O","L");
return str_replace($a1,$a2,$t);
}
$year=$_SESSION['test_y'];
$month=$_SESSION['test_m'];
for($i=1;$i<=12;$i++){
if($i<10)$n="0".$i;
else $n=$i;
$r=mysql_fetch_array(mysql_query("select if(e.currency_value>0 and e.currency_value is not null,sum(i.quantity*i.price*e.currency_value),sum(i.quantity*i.price)) as s,sum(i.quantity*i.purchase_price) as p from ecminvoiceouts as e inner join ecminvoiceoutitems as i on e.id=i.ecminvoiceout_id inner join ecmproducts as p on p.id=i.ecmproduct_id inner join ecmstockdocouts as w on w.id=e.wz_id inner join ecmproductcategories as pc on pc.id=p.product_category_id where e.register_date like '".$year."-".$n."%' and e.type!='correct' and e.status='accepted' and i.deleted='0' and e.deleted='0'"));
$arr[$i]=$r;
$w=mysql_query("select i.price,i.quantity,i.ecminvoiceoutitem_id,e.currency_value from ecminvoiceouts as e inner join ecminvoiceoutitems as i on e.id=i.ecminvoiceout_id inner join ecmproducts as p on p.id=i.ecmproduct_id inner join ecmproductcategories as pc on pc.id=p.product_category_id where e.register_date like '".$year."-".$n."%' and e.type='correct' and e.status='accepted' and i.deleted='0' and e.deleted='0'");
while($r=mysql_fetch_array($w)){
if(!$r['currency_value'])$r['currency_value']=1;
echo $arr[$i]['s']+=$r['currency_value']*$r['price']*$r['quantity'];
$rr=mysql_fetch_array(mysql_query("select price,quantity,purchase_price from ecminvoiceoutitems where id='".$r['ecminvoiceoutitem_id']."'"));
$arr[$i]['s']-=$rr['price']*$rr['quantity'];
$arr[$i]['p']+=$rr['purchase_price']*$r['quantity'];
$arr[$i]['p']-=$rr['purchase_price']*$rr['quantity'];
}
}
$year_month=$_SESSION['EcmReports_Dashlet_sales_year'];
$e=explode("-",$_SESSION['EcmReports_Dashlet_sales_year']);
$months=array("January","February","March","April","May","June","July","August","September","October","November","Dezember");
echo $year;
for($i=1;$i<=12;$i++){
$s=$arr;
if($temp<$s[$i]['s'])$temp=$s[$i]['s'];
$arr_s[]=array(
"name"=>repl($months[$i-1]),
"value"=>$s[$i]['s'],
);
$arr_p[]=array(
"name"=>repl($months[$i-1]),
"value"=>$s[$i]['p'],
);
}
for($i=0;$i<count($arr_s);$i++){
$data_1[]=$arr_s[$i]['value'];
$data_2[]=$arr_s[$i]['value']-$arr_p[$i]['value'];
$cats[]=$arr_s[$i]['name']." ".$year;
}
$g = new graph();
//$g->title( 'Sales: '.$year_month, '{font-size:20px; color: #000000; margin: 5px; background-color: #ffffff; padding:5px; padding-left: 20px; padding-right: 20px;}' );
$g->bg_colour = '#ffffff';
//$g->bg_colour = '#000000';
$d1 = new bar( 75, '#D54C78' );
$d2 = new bar( 75, '#3334AD' );
$d1->key( 'Sales', 10 );
$d2->key( 'PLN Margin', 10 );
for($i=0;$i<count($data_1);$i++){
$d1->add_data_tip($data_1[$i],"Sales: ".round($data_1[$i],2)."\nPLN Margin: ".round($data_2[$i],2)."\nMargin: ".@round(100*($data_2[$i])/$data_1[$i],2)."%");
$d2->add_data_tip($data_2[$i],"Sales: ".round($data_1[$i],2)."\nPLN Margin: ".round($data_2[$i],2)."\nMargin: ".@round(100*($data_2[$i])/$data_1[$i],2)."%");
}
$g->data_sets[]=$d1;
$g->data_sets[]=$d2;
$g->set_tool_tip( '#x_label#<br>#tip#<br>' );
//$g->set_data($data_1);
//$g->bar( 75, '#D54C78', '', 10 );
//$g->set_data($data_2);
//$g->bar( 75, '#3334AD', '', 10 );
//$g->attach_to_y_right_axis(2);
$g->x_axis_colour( '#909090', '#ADB5C7' );
$g->y_axis_colour( '#909090', '#ADB5C7' );
$g->y_right_axis_colour( '#909090' );
$g->set_x_labels( $cats );
$g->set_x_label_style( 10, '#000000', 2 );
$g->set_y_max( $temp );
$g->set_y_right_max( $temp);
$g->y_label_steps( 20 );
//$g->y_right_label_steps( 5 );
$g->set_y_legend( '', 12, '#736AFF' );
$g->set_y_right_legend( '' ,12 , '#164166' );
echo $g->render();
mysql_close($sql);
?>

View File

@@ -0,0 +1,106 @@
<?php
session_start();
include_once( '/var/www/html/e5crm/config.php');
$sql=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
mysql_select_db($sugar_config['dbconfig']['db_name']);
mysql_query("set names utf8");
include_once( '/var/www/html/e5crm/include/ECM/open_flash_chart/ofc-library/open-flash-chart.php' );
//include_once('/var/www/html/e5crm/modules/EcmCharts/chartHelper.php');
include_once("/var/www/html/e5crm/modules/EcmReports/cache.php");
function repl($t){
$a1=array("ą","ś","ę","ż","ź","ć","ń","ó","ł","Ą","Ś","Ę","Ż","Ź","Ć","Ń","Ó","Ł");
$a2=array("a","s","e","z","z","c","n","o","l","A","S","E","Z","Z","C","N","O","L");
return str_replace($a1,$a2,$t);
}
function getStock($category_id){
$ww=mysql_query("select sum(h.value) as sum from ecmproducts_history_states as h inner join ecmproducts as p on p.id=h.ecmproduct_id where p.product_category_id='".$category_id."' and p.deleted='0' and h.ecmstock_id='c7afd71a-4c3a-bde4-138d-4acaee1644e4' and p.product_active='1'");
$rr=mysql_fetch_array($ww);
$i=mysql_num_rows(mysql_query("select distinct date from ecmproducts_history_states"));
$v=$rr['sum'];
return $v/$i;
}
if((int)date("m")==1){
$mmm=12;
$year=date("Y")-1;
}
else{
$mmm=(int)date("m")-1;
$year=date("Y");
}
$s=sum($year,"","","","");
//$w=mysql_query("select id,name from ecmproductcategories where deleted='0' and name!=''");
//while($r=mysql_fetch_array($w)){
//$ss=getSum($s,$year,"",$r['id']);
//@$rot[$r['id']]=12*($ss['total_purchase']/$mmm)/getStock($r['id']);
//if($tempr<$rot[$r['id']])$tempr=$rot[$r['id']];
//}
//echo '<pre>';
//print_r($rot);
//echo '</pre>';m
$w=mysql_query("select p.id,p.product_category_id from ecmproducts as p inner join ecmproductcategories as c on c.id=p.product_category_id where p.deleted='0' order by c.name asc");
while($r=mysql_fetch_array($w)){
$qty=0;
$ww=mysql_query("select quantity,price from ecmstockstates where deleted='0' and product_id='".$r['id']."'");
while($rrr=mysql_fetch_array($ww)){
$qty+=$rrr['quantity']*$rrr['price'];
}
$cats[$r['product_category_id']]+=$qty;
if($cats[$r['product_category_id']]>$temp)$temp=$cats[$r['product_category_id']];
}
//$arr_s=multisort($arr_s,array(array('key'=>'value','sort'=>'desc')));
$i=0;
foreach($cats as $k=>$v){
$r=mysql_fetch_array(mysql_query("select name from ecmproductcategories where id='".$k."' and deleted='0'"));
if($r['name']){
$data_1[$i]=$v;
if($v)$data_2[$i]=$rot[$k];
else $data_2[$i]=0;
$cn[$i]=repl($r['name']);
$i++;
}
}
$g = new graph();
//$g->title( 'Stocks', '{font-size:20px; color: #000000; margin: 5px; background-color: #ffffff; padding:5px; padding-left: 20px; padding-right: 20px;}' );
$g->bg_colour = '#ffffff';
$d1 = new bar( 75, '#D54C78' );
$d2 = new bar( 75, '#3334AD' );
$d1->key( 'Inventory valueee', 10 );
$d2->key( 'Rotation', 10 );
for($i=0;$i<count($data_1);$i++){
$d1->add_data_tip($data_1[$i],"Value: ".$data_1[$i]."\nRotation: ".round($data_2[$i],2));
//$d2->add_data_tip($data_2[$i],"Value: ".$data_1[$i]."\nRotation: ".round($data_2[$i],2));
}
$g->data_sets[]=$d1;
//$g->data_sets[]=$d2;
$g->set_tool_tip( '#x_label#<br>#tip#<br>' );
$g->attach_to_y_right_axis(2);
$g->x_axis_colour( '#909090', '#ADB5C7' );
$g->y_axis_colour( '#909090', '#ADB5C7' );
$g->y_right_axis_colour( '#909090' );
$g->set_x_labels( $cn );
$g->set_x_label_style( 10, '#000000', 2 );
$g->set_y_max( $temp );
$g->set_y_right_max( $tempr);
$g->y_label_steps( 20 );
//$g->y_right_label_steps( 5 );
$g->set_y_legend( 'Inventory value', 12, '#D54C78' );
$g->set_y_right_legend( 'Rotation' ,12 , '#3334AD' );
echo $g->render();
mysql_close($sql);
?>

View File

@@ -0,0 +1,121 @@
<?php
session_start();
include_once( '/var/www/html/e5crm/config.php');
$sql=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
mysql_select_db($sugar_config['dbconfig']['db_name']);
mysql_query("set names utf8");
include_once( '/var/www/html/e5crm/include/ECM/open_flash_chart/ofc-library/open-flash-chart.php' );
//include_once('/var/www/html/e5crm/modules/EcmCharts/chartHelper.php');
include_once("/var/www/html/e5crm/modules/EcmReports/cache.php");
function repl($t){
$a1=array("ą","ś","ę","ż","ź","ć","ń","ó","ł","Ą","Ś","Ę","Ż","Ź","Ć","Ń","Ó","Ł");
$a2=array("a","s","e","z","z","c","n","o","l","A","S","E","Z","Z","C","N","O","L");
return str_replace($a1,$a2,$t);
}
function getCallTime($id,$year){
if($id){$acc_ids=array();
$acc_ids[]="e.bean_id='".$id."'";
$w=mysql_query("select contact_id from accounts_contacts where deleted='0' and account_id='".$id."'");
while($r=mysql_fetch_array($w)){
$acc_ids[]="e.bean_id='".$r['contact_id']."'";
}
$w=mysql_query("select id from accounts where deleted='0' and parent_id='".$id."'");
while($r=mysql_fetch_array($w)){
$acc_ids[]="e.bean_id='".$r['id']."'";
}
}
if(count($acc_ids)>0)$where="(".implode(" or ",$acc_ids).") and ";
else $where="";
$z="select sum(c.duration) as d,Month(e.date_modified) as m from ecmcalls_beans as e inner join cdr as c on c.id=e.ecmcall_id where ".$where."e.date_modified like '".$year."%' group by Month(e.date_modified)";
$w=mysql_query($z);
while($r=mysql_fetch_array($w)){
$d[$year."-".$r['m']]+=$r['d'];
}
return $d;
}
function getMinSec($v){
$min=floor($v/60);
$min1=$min;
$h=floor($min/60);
$min-=$h*60;
$sec=$v-$min1*60;
if($min1>0 || $sec>0 || $h>0)$str=$h."h ".$min."m ".$sec."s";
return $str;
}
$year=$_SESSION['EcmCharts_6_year'];
$category=$_SESSION['EcmCharts_6_category'];
$account=$_SESSION['EcmCharts_6_account'];
$months=array('styczeń','luty','marzec','kwiecień','maj','czerwiec','lipiec','sierpień','wrzesień','październik','listopad','grudzień');
$s=sum($year,$account,$category);
$time=getCallTime($account,$year);
for($i=1;$i<=12;$i++){
if($i<10)$n="0".$i;
else $n=$i;
$ss=getSum($s,$year."-".$n,"",$category);
if($temp<$ss['total'])$temp=$ss['total'];
$arr_s[]=array(
"name"=>repl($months[$i-1]),
"value"=>$ss['total'],
);
if($tempr<$time[$year."-".$i])$tempr=$time[$year."-".$i];
$arr_c[]=array(
"name"=>repl($months[$i-1]),
"value"=>$time[$year."-".$i],
);
}
for($i=0;$i<count($arr_s);$i++){
$data_1[]=$arr_s[$i]['value'];
$data_2[]=$arr_c[$i]['value'];
$cats[]=$arr_s[$i]['name'];
}
$g = new graph();
//$g->title( 'Sales: '.$year_month, '{font-size:20px; color: #000000; margin: 5px; background-color: #ffffff; padding:5px; padding-left: 20px; padding-right: 20px;}' );
$g->bg_colour = '#ffffff';
$d1 = new bar( 75, '#D54C78' );
$d2 = new bar( 75, '#3334AD' );
$d2->key( 'Czas rozmowy', 10 );
$d1->key( 'Sprzedaż', 10 );
for($i=0;$i<count($data_1);$i++){
$d1->add_data_tip($data_1[$i],"Sprzedaż: ".round($data_1[$i],2)."\nCzas rozmowy: ".getMinSec(round($data_2[$i],2)));
$d2->add_data_tip($data_2[$i],"Sprzedaż: ".round($data_1[$i],2)."\nCzas rozmowy ".getMinSec(round($data_2[$i],2)));
}
$g->data_sets[]=$d1;
$g->data_sets[]=$d2;
$g->set_tool_tip( '#x_label#<br>#tip#<br>' );
//$g->set_data($data_1);
//$g->bar( 75, '#D54C78', '', 10 );
//$g->set_data($data_2);
//$g->bar( 75, '#3334AD', '', 10 );
$g->attach_to_y_right_axis(2);
$g->x_axis_colour( '#909090', '#ADB5C7' );
$g->y_axis_colour( '#909090', '#ADB5C7' );
$g->y_right_axis_colour( '#909090' );
$g->set_x_labels( $cats );
$g->set_x_label_style( 10, '#000000', 2 );
$g->set_y_max( $temp );
$g->set_y_right_max( $tempr );
$g->y_label_steps( 20 );
//$g->y_right_label_steps( 20 );
$g->set_y_legend( '', 12, '#736AFF' );
$g->set_y_right_legend( '' ,12 , '#164166' );
echo $g->render();
mysql_close($sql);
?>

View File

@@ -0,0 +1,46 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*/
global $current_user;
?>

View File

@@ -0,0 +1,46 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
*/
global $app_strings;
$dashletMeta['MyChartsProductsDashlet'] = array(
'title' => 'Wykres: Czas rozmów & Sprzedaż',
'description' => 'A customizable view into Tasks',
'category' => 'Charts');
?>

View File

@@ -0,0 +1,77 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/Dashlets/Dashlet.php');
require_once('include/Sugar_Smarty.php');
include_once('include/ECM/open_flash_chart/ofc-library/open_flash_chart_object.php');
class MyChartsProductsDashlet extends Dashlet {
var $savedText; // users's saved text
var $height = '300'; // height of the pad
function MyChartsProductsDashlet($id, $def) {
global $current_user;
parent::Dashlet($id); // call parent constructor
$this->isConfigurable = true; // dashlet is configurable
$this->hasScript = false; // dashlet has java ipt attached to it
if($current_user->id=='2e72f487-d92b-954e-f50c-528b10ce81c9'){
}
// if no custom title, use default
if(empty($def['title'])) $this->title = 'Wykres: Czas rozmów & Sprzedaż ';
else $this->title = $def['title'];
}
function display() {
global $current_user;
$ss = new Sugar_Smarty();
$optionsArray = $this->loadOptions();
//$ss->assign('account_id',$optionsArray['account_id']);
$ss->assign('id', $this->id);
$ss->assign('height', $this->height);
$ss->assign('year', $optionsArray['year']);
$_SESSION['EcmCharts_6_year']=$optionsArray['year'];
$_SESSION['EcmCharts_6_category']=$category;
$_SESSION['EcmCharts_6_account']=$optionsArray['account_id'];
if(!isset($_SESSION['EcmCharts_6_year']))$_SESSION['EcmCharts_6_year']=(int)date("Y");
if(!isset($_SESSION['EcmCharts_6_category']))$_SESSION['EcmCharts_6_category']='';
if(!isset($_SESSION['EcmCharts_6_account']))$_SESSION['EcmCharts_6_account']='';
//$_SESSION['EcmCharts_6_mmm']=$mmm;
$str = $ss->fetch('modules/EcmCharts/Dashlets/MyChartsProductsDashlet/MyChartsProductsDashlet.tpl');
return parent::display('') . $str . '<br />'; // return parent::display for title and such
}
function displayOptions() {
global $app_strings,$current_user;
$ss = new Sugar_Smarty();
$ss->assign('year',$_SESSION['EcmCharts_6_year']);
$ss->assign('id', $this->id); //The id must be assigned in all dashlet options pages
return parent::displayOptions() . $ss->fetch('modules/EcmCharts/Dashlets/MyChartsProductsDashlet/MyChartsProductsDashletOptions.tpl');
}
function saveOptions($req) {
global $sugar_config, $timedate, $current_user, $theme;
$options = array();
$options['account_name']=$_REQUEST['account_name'];
$options['account_id']=$_REQUEST['account_id'];
$options['year']=$_REQUEST['year'];
$options['category']=$_REQUEST['category'];
return $options;
}
}
?>