This commit is contained in:
2024-04-27 09:23:34 +02:00
commit 11e713ca6f
11884 changed files with 3263371 additions and 0 deletions

View File

@@ -0,0 +1,121 @@
<?php
class ChartAnnualSalesHelper
{
private $outputOptions = null;
private $options = null;
private $db = null;
private $monthName = null;
private $comparativeData = null;
private $months;
public function ChartAnnualSalesHelper($db, $options, $lang, $comparativeData = null)
{
$this->options = $options;
$this->db = $db;
$this->comparativeData = $comparativeData;
$this->monthName = array($lang['LBL_JANUARY'],
$lang['LBL_FEBRUARY'],
$lang['LBL_MARCH'],
$lang['LBL_APRIL'],
$lang['LBL_MAY'],
$lang['LBL_JUNE'],
$lang['LBL_JULY'],
$lang['LBL_AUGUST'],
$lang['LBL_SEPTEMBER'],
$lang['LBL_OCTOBER'],
$lang['LBL_NOVEMBER'],
$lang['LBL_DECEMBER']);
}
// 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['MyChartsAnnualSalesDashlet'] = array(
'title' => 'Raport sprzedaży rocznej z podziałem na miesiące',
'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,152 @@
<?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('ChartAnnualSalesHelper.php');
class MyChartsAnnualSalesDashlet extends Dashlet {
var $savedText; // users's saved text
var $height = '300'; // height of the pad
var $firstLoad = 'yes';
function MyChartsAnnualSalesDashlet($id, $def = null) {
global $current_user, $mod_strings, $app_strings;
require('modules/EcmCharts/Dashlets/MyChartsAnnualSalesDashlet/MyChartsAnnualSalesDashlet.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 sprzedaży rocznej z podziałem na miesiące";
$this->title = $options["title"];
}
function display() {
global $current_user, $mod_strings, $app_strings;
$options = $this->loadOptions();
$comparativeData = null;
$options2 = null;
$db_connection_handler = $GLOBALS["db"];
$options = $this->loadOptions();
// Data od
if(!$options['year'])
$options['year'] = date("Y");
if(!$options["comparativeData"])
$options["comparativeData"] = 'disabled';
if(!$options["type"])
$options["type"] = '%';
if(!$options["chartType"])
$options["chartType"] = 'column';
if( $options["comparativeData"] == 'enabled')
{
$options2 = $this->loadOptions();
$options2["year"] -= 1;
$helper2 = new ChartAnnualSalesHelper($db_connection_handler, $options2, $mod_strings);
$helper2->getChartOptions();
// Pobieram dane sprzed roku
$comparativeData = $helper2->getMonthsArray();
$helper = new ChartAnnualSalesHelper($db_connection_handler, $options, $mod_strings, $comparativeData);
$data = $helper->getChartOptions();
} else {
$helper = new ChartAnnualSalesHelper($db_connection_handler, $options, $mod_strings);
$data = $helper->getChartOptions();
}
/*
* SMARTY
*/
$smarty = new Sugar_Smarty();
$smarty->assign('chartOptions', $data);
$smarty->assign('comparativeData', $options['comparativeData']);
$smarty->assign('year', $options["year"]);
$smarty->assign('chartType', $options["chartType"]);
$smarty->assign('LANG', $mod_strings);
if( $helper->haveComparativeData() )
$smarty->assign('comparative_data_on', 'true');
else
$smarty->assign('comparative_data_on', 'false');
// Pobieranie widoku
$output = $smarty->fetch('modules/EcmCharts/Dashlets/MyChartsAnnualSalesDashlet/MyChartsAnnualSalesDashlet.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
if(!$options['year'])
$options['year'] = date("Y");
if(!$options["comparativeData"])
$options["comparativeData"] = 'disabled';
if(!$options["type"])
$options["type"] = '%';
if(!$options["chartType"])
$options["chartType"] = 'column';
if(!$options["title"])
$options["title"] = "Raport sprzedaży w roku z podziałem na miesiące";
// Generowanie lat do selektora
$y = range(2000, date("Y"));
$years = array_reverse($y,true);
//The id must be assigned in all dashlet options pages
$smarty->assign('id', $this->id);
// Typ dokumentu: all, normal, correct
$smarty->assign('type', $options['type']);
$smarty->assign('year', $options['year']);
$smarty->assign('contractor_id', $options["contractor_id"]);;
$smarty->assign('contractor_name', $options["contractor_name"]);
$smarty->assign('chartType', $options["chartType"]);
$smarty->assign('years', $years);
$smarty->assign('LANG', $mod_strings);
$smarty->assign('title', $options["title"]);
// Pokazywać dane porównawcze? Tak: enabled, nie: disabled
$smarty->assign('comparativeData', $options['comparativeData']);
// Przekazuję widok opcji do metody displayOptions()
return parent::displayOptions() . $smarty->fetch('modules/EcmCharts/Dashlets/MyChartsAnnualSalesDashlet/MyChartsAnnualSalesDashletOptions.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,152 @@
{*
/**
* 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".
*/
*}
{if $chartOptions == ''}
{literal}
<style type="text/css">
.no-data {
display: table;
width: 100%;
height: 100%;
}
.textCenter {
display: table-cell;
vertical-align: middle;
text-align: center;
}
.textCenter span {
font-size: 16px;
border: 1px dashed #E03E3E;
padding: 10px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
box-shadow: 10px 10px 5px #AAAAAA;
background-color: #FFDEDE;
color: #E03E3E;
}
</style>
{/literal}
{/if}
{if $chartOptions == ''}
<div id='jotpsadad_{$id}' ondblclick='JotPad.edit(this, "{$id}")' style='overflow: auto; width: 100%; height: 200px; border: 1px #ddd solid'>
<div id="annual_sales_chart{$id}" style="width: 100%; height: 100%;">
<div class="no-data">
<div class="textCenter">
<span>
{$LANG.LBL_NO_DATA_CHANGE_FILTER}
</span>
</div>
</div>
</div>
</div>
{else}
<div style='overflow: auto; width: 100%; height: 800px; border: 1px #ddd solid'>
<div id="annual_sales_chart{$id}" style="width: 100%; height: 97%;"></div>
</div>
{/if}
<!-- GOOGLE CHARTS API -->
{if $chartOptions != ''}
{literal}
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="modules/EcmCharts/Dashlets/MyChartsSalesDashlet/js/salesChart.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart','geochart','table']});
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Rok', {/literal}'{$LANG.LBL_SALE}'
{if $comparativeData == 'enabled'} , '{$LANG.LBL_SALE_IN_PAST_YEAR}'{/if}
{literal}],
{/literal}
{$chartOptions}
{literal}
]);
var formatter = new google.visualization.NumberFormat({
suffix: 'zł'
});
formatter.format(data, 1); // Apply formatter to second column.
{/literal}
{if $comparative_data_on == 'true' }
formatter.format(data, 2); // Apply formatter to second column.
{/if}
{literal}
var options = {
{/literal}
title: '{ $LANG.LBL_SALES_CHART_IN }{$year}',
{literal}
legend: {position: 'bottom', textStyle: {fontSize: 10}},
tooltip:{textStyle:{fontSize:'10'}},
vAxis:{title: {/literal}'{$LANG.LBL_VALUEOFSALES}'{literal},textStyle:{color: '#000000',fontSize: '11', paddingRight: '100',marginRight: '100'}},
hAxis:{title:'',textStyle:{color: '#000000',fontSize: '10', paddingRight: '100',marginRight: '100'}}
};
{/literal}
{if $chartType == 'column' or $chartType == ''}
var chart = new google.visualization.ColumnChart(document.getElementById('annual_sales_chart{$id}'));
{elseif $chartType == 'pie'}
var chart = new google.visualization.PieChart(document.getElementById('annual_sales_chart{$id}'));
{elseif $chartType == 'line'}
var chart = new google.visualization.LineChart(document.getElementById('annual_sales_chart{$id}'));
{elseif $chartType == 'stepped'}
var chart = new google.visualization.SteppedAreaChart(document.getElementById('annual_sales_chart{$id}'));
{else}
var chart = new google.visualization.AreaChart(document.getElementById('annual_sales_chart{$id}'));
{/if}
{literal}
chart.draw(data, options);
}
// sekunda opóźnienia, żeby zdążył wczytać się moduł "visualization"
setTimeout(drawChart, 1000);
</script>
{/literal}
{/if}

View File

@@ -0,0 +1,160 @@
{*
/**
* 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".
*/
*}
<script type="text/javascript" src="modules/EcmCharts/javascript/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
{literal}
function listenerFunction() {
//location.reload();
};
$("#chartTypeSelector").change(function() {
if( $(this).val() == 'pie' )
{
$("#documentTypeSelector").val("normal");
}
});
$("#documentTypeSelector").change(function(){
if( $(this).val() == 'correct' && $("#chartTypeSelector").val() == 'pie' )
{
$("#chartTypeSelector").val("column");
}
});
{/literal}
</script>
<style type="text/css">
{literal}
table tr td {
padding-top: 20px;
}
table tr td select {
width: 140px;
}
{/literal}
</style>
<div style='width: 600px'>
<form name="configure_{$id}" action="index.php" method="post" onSubmit='return SUGAR.dashlets.postForm("configure_{$id}", SUGAR.mySugar.uncoverPage);'>
<input type='hidden' name='id' value='{$id}'>
<input type='hidden' name='module' value='Home'>
<input type='hidden' name='action' value='ConfigureDashlet'>
<input type='hidden' name='to_pdf' value='true'>
<input type='hidden' name='configure' value='true'>
<table width="600" cellpadding="0" cellspacing="0" border="0" class="tabForm" align="center">
<tr>
<td>{$LANG.LBL_TITLE}: </td>
<td>
<input type="text" value="{$title}" name="title" />
</td>
</tr>
<tr>
<td>{$LANG.LBL_SELECT_YEAR}: </td>
<td>
<select name="year">
{foreach from=$years item=y}
<option value="{$y}" { if $y == $year || $year == ""} selected="true" {/if}>{$y}</option>
{/foreach}
</select>
</td>
</tr>
<tr>
<td>{$LANG.LBL_INCLUDED_DOCUMENT_TYPE}: </td>
<td>
<select id="documentTypeSelector" name="type">
<option value="%" { if $type == "%" || $type == ""} selected="true" {/if}>{$LANG.LBL_NORMAL_AND_CORRECT}</option>
<option value="normal" { if $type == "normal"} selected="true" {/if}>{$LANG.LBL_NORMAL_ONLY}</option>
<option value="correct" { if $type == "correct"} selected="true" {/if}>{$LANG.LBL_CORRECT_ONLY}</option>
</select>
</td>
</tr>
<tr>
{* Search by contractor *}
<td>{$LANG.LBL_CONTRACTOR}</td>
<td>
<input id="search_account_name" type="text" value="{$contractor_name}" name="account_name">
<input id="search_account_id" type="hidden" value="{$contractor_id}" name="account_id">
<input class="button" type="button" value="{$LANG.LBL_SELECT}" accesskey="T" title="Select [Alt+T]" value="" name="btn_account_name" onClick="getContractor()">
{* Open popup window to select contractor *}
<script type="text/javascript">
function getContractor()
{ldelim}
open_popup("Accounts", 600, 400, "", true, false,
{ldelim}
"call_back_function":"set_return","form_name":"configure_{$id}","field_to_name_array":
{ldelim}"id":"search_account_id","name":"search_account_name"{rdelim}
{rdelim}, "single", true);
{rdelim};
</script>
</td>
</tr>
<tr>
<td>{$LANG.LBL_CHARTTYPE}: </td>
<td>
<select id="chartTypeSelector" name="chartType">
<option value="column" { if $chartType == "column" || $chartType == ""} selected="true" {/if}>{$LANG.LBL_CHARTTYPECOLUMN}</option>
<option value="pie" { if $chartType == "pie"} selected="true" {/if}>{$LANG.LBL_CHARTTYPEPIE}</option>
<option value="line" { if $chartType == "line"} selected="true" {/if}>{$LANG.LBL_CHARTTYPELINE}</option>
<option value="area" { if $chartType == "area"} selected="true" {/if}>{$LANG.LBL_CHARTTYPEAREA}</option>
<option value="stepped" { if $chartType == "stepped"} selected="true" {/if}>{$LANG.LBL_CHARTTYPESTEPPEDAREA}</option>
</select>
</td>
</tr>
<tr>
<td>{$LANG.LBL_VIEW_COMPARATIVE_DATA}: </td>
<td>
<input type="radio" name="comparativeData" value="enabled" { if $comparativeData == "enabled" || $comparativeData == "" } checked {/if}> {$LANG.LBL_YES}
<input type="radio" name="comparativeData" style="margin-left: 20px" value="disabled" { if $comparativeData == "disabled" || $comparativeData == "" } checked {/if}> {$LANG.LBL_NO}
</td>
</tr>
<tr>
<td colspan="4" style="text-align: center;">
<input id="submitButton" type="submit" class="button" style="margin-top: 30px;" value="{$LANG.LBL_SAVECHANGES}" onclick="setTimeout(listenerFunction, 1000);">
</td>
</tr>
</table>
</form>
</div>