185 lines
6.4 KiB
PHP
185 lines
6.4 KiB
PHP
<?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('MyContractorChartSalesHelper.php');
|
|
|
|
|
|
class MyContractorsChartsSalesDashlet extends Dashlet {
|
|
|
|
var $savedText; // users's saved text
|
|
var $height = '300'; // height of the pad
|
|
function MyContractorsChartsSalesDashlet($id, $def) {
|
|
|
|
global $current_user, $mod_strings, $app_strings;
|
|
require('modules/EcmCharts/Dashlets/MyContractorsChartsSalesDashlet/MyContractorsChartsSalesDashlet.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( !$options["title"] )
|
|
$options["title"] = "Wykres z podziałem na kontrahentów";
|
|
|
|
// if no custom title, use default
|
|
$this->title = $options["title"];
|
|
|
|
}
|
|
|
|
function display() {
|
|
global $current_user, $mod_strings, $app_strings;
|
|
|
|
$options = $this->loadOptions();
|
|
|
|
// Data od
|
|
if(!$options['date_from'])
|
|
$options['date_from'] = date("01.m.Y");
|
|
|
|
// Data do
|
|
if(!$options['date_to'])
|
|
$options['date_to'] = date("d.m.Y");
|
|
|
|
if(!$options['type'])
|
|
$options['type'] = "%";
|
|
|
|
if(!$options['comparativeData'])
|
|
$options['comparativeData'] = "disabled";
|
|
|
|
if(!$options['chartType'])
|
|
$options['chartType'] = "column";
|
|
|
|
if(!$options['count'])
|
|
$options['count'] = "10";
|
|
|
|
if(!$options["title"])
|
|
$options["title"] = "Wykres sprzedaży z podziałem na kontrahentów";
|
|
|
|
$optionsForComparativeData = $options;
|
|
$optionsForComparativeData["date_from"] = date("Y-m-d",strtotime(date("Y-m-d", strtotime($optionsForComparativeData["date_from"]))." -1 year"));
|
|
$optionsForComparativeData["date_to"] = date("Y-m-d",strtotime(date("Y-m-d", strtotime($optionsForComparativeData["date_to"]))." -1 year"));
|
|
|
|
$db_connection_handler = $GLOBALS["db"];
|
|
|
|
/*
|
|
* DATA
|
|
*/
|
|
$cd = null;
|
|
|
|
if( $options["comparativeData"] == "enabled" )
|
|
{
|
|
$comparativeData = new MyContractorChartSalesHelper( $db_connection_handler, $optionsForComparativeData);
|
|
$cd = $comparativeData->getContractors();
|
|
}
|
|
|
|
$helper = new MyContractorChartSalesHelper( $db_connection_handler, $options, $cd );
|
|
|
|
$data = $helper->renderGoogleChartOptions();
|
|
|
|
/*
|
|
* SMARTY
|
|
*/
|
|
$smarty = new Sugar_Smarty();
|
|
//$ss->assign('account_id',$optionsArray['account_id']);
|
|
if( $helper->haveComparativeData() )
|
|
$smarty->assign('comparative_data_on', 'true');
|
|
else
|
|
$smarty->assign('comparative_data_on', 'false');
|
|
$smarty->assign('id', $this->id);
|
|
$smarty->assign('height', $this->height);
|
|
$smarty->assign('date_from', $options["date_from"]);
|
|
$smarty->assign('date_to', $options["date_to"]);
|
|
$smarty->assign('chartOptions', $data);
|
|
$smarty->assign('comparativeData', $options['comparativeData']);
|
|
$smarty->assign('chartType', $options['chartType']);
|
|
$smarty->assign('contractorsCount', $options['count']);
|
|
$smarty->assign('group_media_saturn_holding', $options["group_media_saturn_holding"]);
|
|
$smarty->assign('LANG', $mod_strings);
|
|
|
|
|
|
// Pobieranie widoku
|
|
$output = $smarty->fetch('modules/EcmCharts/Dashlets/MyContractorsChartsSalesDashlet/MyContractorsChartsSalesDashlet.tpl');
|
|
// return parent::display for title and smarty template
|
|
return parent::display($this->dashletStrings['LBL_DBLCLICK_HELP']) . $output;
|
|
}
|
|
|
|
function displayOptions() {
|
|
global $current_user, $mod_strings, $app_strings;
|
|
// format daty
|
|
$smarty = new Sugar_Smarty();
|
|
// Pobieram ustawienia
|
|
$options = $this->loadOptions();
|
|
|
|
// Data od
|
|
if(!$options['date_from'])
|
|
$options['date_from'] = date("01.m.Y");
|
|
|
|
// Data do
|
|
if(!$options['date_to'])
|
|
$options['date_to'] = date("d.m.Y");
|
|
|
|
if(!$options['type'])
|
|
$options['type'] = "%";
|
|
|
|
if(!$options['comparativeData'])
|
|
$options['comparativeData'] = "disabled";
|
|
|
|
if(!$options['chartType'])
|
|
$options['chartType'] = "column";
|
|
|
|
if(!$options["title"])
|
|
$options["title"] = "Wykres sprzedaży z podziałem na kategorie/podkategorie";
|
|
|
|
if(!$options["count"])
|
|
$options["count"] = "10";
|
|
|
|
$numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
|
|
// Format daty
|
|
$Calendar_daFormat = str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));
|
|
$smarty->assign("dateFormat", $Calendar_daFormat);
|
|
//The id must be assigned in all dashlet options pages
|
|
$smarty->assign('id', $this->id);
|
|
$smarty->assign('date_from', $options['date_from']);
|
|
$smarty->assign('date_to', $options['date_to']);
|
|
// Typ dokumentu: all, normal, correct
|
|
$smarty->assign('type', $options['type']);
|
|
// Pokazywać dane porównawcze? Tak: enabled, nie: disabled
|
|
$smarty->assign('comparativeData', $options['comparativeData']);
|
|
// Typ wykresu
|
|
$smarty->assign('chartType', $options['chartType']);
|
|
// Tytuł
|
|
$smarty->assign('title', $options['title']);
|
|
// Ilość kontrahentów na wykresie
|
|
$smarty->assign('contractorsCount', $options['count']);
|
|
// Liczby do wyboru ilości kontrahentów
|
|
$smarty->assign('numbers', $numbers);
|
|
// Ilość kontrahentów
|
|
$smarty->assign('count', $options['count']);
|
|
// Grupowanie mediaków i saturnów
|
|
$smarty->assign('group_media_saturn_holding', $options["group_media_saturn_holding"]);
|
|
// Lang
|
|
$smarty->assign('LANG', $mod_strings);
|
|
|
|
// Przekazuję widok opcji do metody displayOptions()
|
|
return parent::displayOptions() . $smarty->fetch('modules/EcmCharts/Dashlets/MyContractorsChartsSalesDashlet/MyContractorsChartsSalesDashletOptions.tpl');
|
|
|
|
}
|
|
|
|
// Zapisywanie opcji dashletu
|
|
function saveOptions($req) {
|
|
$options = array();
|
|
$options["date_from"] = $req["date_from"];
|
|
$options["date_to"] = $req["date_to"];
|
|
$options["comparativeData"] = $req["comparativeData"];
|
|
$options["type"] = $req["type"];
|
|
$options["chartType"] = $req["chartType"];
|
|
$options["count"] = $req["contractorsCount"];
|
|
$options["title"] = $req["title"];
|
|
$options["group_media_saturn_holding"] = $req["group_media_saturn_holding"];
|
|
|
|
return $options;
|
|
}
|
|
}
|
|
?>
|