mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
Miglioramento modulo Statistiche
This commit is contained in:
@ -89,21 +89,22 @@ if (Auth::check()) {
|
|||||||
'hookMultiple' => tr('Hai _NUM_ notifiche'),
|
'hookMultiple' => tr('Hai _NUM_ notifiche'),
|
||||||
'hookSingle' => tr('Hai 1 notifica'),
|
'hookSingle' => tr('Hai 1 notifica'),
|
||||||
'hookNone' => tr('Nessuna notifica'),
|
'hookNone' => tr('Nessuna notifica'),
|
||||||
|
'singleCalendar' => tr("E' presente un solo calendario!"),
|
||||||
];
|
];
|
||||||
foreach ($translations as $key => $value) {
|
foreach ($translations as $key => $value) {
|
||||||
echo '
|
echo '
|
||||||
'.$key.': \''.addslashes($value).'\',';
|
'.$key.': "'.addslashes($value).'",';
|
||||||
}
|
}
|
||||||
echo '
|
echo '
|
||||||
};
|
};
|
||||||
globals = {
|
globals = {
|
||||||
rootdir: \''.$rootdir.'\',
|
rootdir: "'.$rootdir.'",
|
||||||
js: \''.$paths['js'].'\',
|
js: "'.$paths['js'].'",
|
||||||
css: \''.$paths['css'].'\',
|
css: "'.$paths['css'].'",
|
||||||
img: \''.$paths['img'].'\',
|
img: "'.$paths['img'].'",
|
||||||
|
|
||||||
id_module: \''.$id_module.'\',
|
id_module: "'.$id_module.'",
|
||||||
id_record: \''.$id_record.'\',
|
id_record: "'.$id_record.'",
|
||||||
|
|
||||||
cifre_decimali: '.setting('Cifre decimali per importi').',
|
cifre_decimali: '.setting('Cifre decimali per importi').',
|
||||||
|
|
||||||
@ -113,17 +114,19 @@ if (Auth::check()) {
|
|||||||
|
|
||||||
search: search,
|
search: search,
|
||||||
translations: translations,
|
translations: translations,
|
||||||
locale: \''.$lang.'\',
|
locale: "'.$lang.'",
|
||||||
full_locale: \''.$lang.'_'.strtoupper($lang).'\',
|
full_locale: "'.$lang.'_'.strtoupper($lang).'",
|
||||||
|
|
||||||
start_date: \''.Translator::dateToLocale($_SESSION['period_start']).'\',
|
start_date: "'.$_SESSION['period_start'].'",
|
||||||
end_date: \''.Translator::dateToLocale($_SESSION['period_end']).'\',
|
start_date_formatted: "'.Translator::dateToLocale($_SESSION['period_start']).'",
|
||||||
|
end_date: "'.$_SESSION['period_end'].'",
|
||||||
|
end_date_formatted: "'.Translator::dateToLocale($_SESSION['period_end']).'",
|
||||||
|
|
||||||
ckeditorToolbar: [
|
ckeditorToolbar: [
|
||||||
["Undo","Redo","-","Cut","Copy","Paste","PasteText","PasteFromWord","-","Scayt", "-","Link","Unlink","-","Bold","Italic","Underline","Superscript","SpecialChar","HorizontalRule","-","JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock","-","NumberedList","BulletedList","Outdent","Indent","Blockquote","-","Styles","Format","Image","Table", "TextColor", "BGColor" ],
|
["Undo","Redo","-","Cut","Copy","Paste","PasteText","PasteFromWord","-","Scayt", "-","Link","Unlink","-","Bold","Italic","Underline","Superscript","SpecialChar","HorizontalRule","-","JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock","-","NumberedList","BulletedList","Outdent","Indent","Blockquote","-","Styles","Format","Image","Table", "TextColor", "BGColor" ],
|
||||||
],
|
],
|
||||||
|
|
||||||
order_manager_id: \''.($dbo->isInstalled() ? Modules::get('Stato dei servizi')['id'] : '').'\',
|
order_manager_id: "'.($dbo->isInstalled() ? Modules::get('Stato dei servizi')['id'] : '').'",
|
||||||
dataload_page_buffer: '.setting('Lunghezza in pagine del buffer Datatables').',
|
dataload_page_buffer: '.setting('Lunghezza in pagine del buffer Datatables').',
|
||||||
tempo_attesa_ricerche: '.setting('Tempo di attesa ricerche in secondi').',
|
tempo_attesa_ricerche: '.setting('Tempo di attesa ricerche in secondi').',
|
||||||
};
|
};
|
||||||
@ -132,13 +135,13 @@ if (Auth::check()) {
|
|||||||
echo '
|
echo '
|
||||||
<script>
|
<script>
|
||||||
globals = {
|
globals = {
|
||||||
rootdir: \''.$rootdir.'\',
|
rootdir: "'.$rootdir.'",
|
||||||
|
|
||||||
search: {},
|
search: {},
|
||||||
translations: {},
|
translations: {},
|
||||||
|
|
||||||
locale: \''.$lang.'\',
|
locale: "'.$lang.'",
|
||||||
full_locale: \''.$lang.'_'.strtoupper($lang).'\',
|
full_locale: "'.$lang.'_'.strtoupper($lang).'",
|
||||||
};
|
};
|
||||||
</script>';
|
</script>';
|
||||||
}
|
}
|
||||||
|
@ -108,8 +108,8 @@ $(document).ready(function () {
|
|||||||
toLabel: globals.translations.to,
|
toLabel: globals.translations.to,
|
||||||
},
|
},
|
||||||
ranges: ranges,
|
ranges: ranges,
|
||||||
startDate: globals.start_date,
|
startDate: globals.start_date_formatted,
|
||||||
endDate: globals.end_date,
|
endDate: globals.end_date_formatted,
|
||||||
applyClass: 'btn btn-success btn-sm',
|
applyClass: 'btn btn-success btn-sm',
|
||||||
cancelClass: 'btn btn-danger btn-sm',
|
cancelClass: 'btn btn-danger btn-sm',
|
||||||
linkedCalendars: false
|
linkedCalendars: false
|
||||||
|
38
modules/statistiche/actions.php
Normal file
38
modules/statistiche/actions.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Modules\Statistiche\Stats;
|
||||||
|
|
||||||
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
|
$calendar_id = filter('calendar_id');
|
||||||
|
$start = filter('start');
|
||||||
|
$end = filter('end');
|
||||||
|
|
||||||
|
switch (filter('op')) {
|
||||||
|
case 'fatturato':
|
||||||
|
$results = $dbo->fetchArray("SELECT ROUND(SUM(co_righe_documenti.subtotale - co_righe_documenti.sconto), 2) AS result, YEAR(co_documenti.data) AS year, MONTH(co_documenti.data) AS month FROM co_documenti INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id INNER JOIN co_righe_documenti ON co_righe_documenti.iddocumento=co_documenti.id WHERE co_tipidocumento.dir='entrata' AND co_tipidocumento.descrizione!='Bozza' AND co_documenti.data BETWEEN ".prepare($start).' AND '.prepare($end).' GROUP BY YEAR(co_documenti.data), MONTH(co_documenti.data) ORDER BY YEAR(co_documenti.data) ASC, MONTH(co_documenti.data) ASC');
|
||||||
|
|
||||||
|
$results = Stats::monthly($results, $start, $end);
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'label' => tr('Fatturato').' - '.tr('Periodo _NUM_', [
|
||||||
|
'_NUM_' => $calendar_id
|
||||||
|
]),
|
||||||
|
'results' => $results
|
||||||
|
]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'acquisti':
|
||||||
|
$results = $dbo->fetchArray("SELECT ROUND(SUM(co_righe_documenti.subtotale - co_righe_documenti.sconto), 2) AS result, YEAR(co_documenti.data) AS year, MONTH(co_documenti.data) AS month FROM co_documenti INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id INNER JOIN co_righe_documenti ON co_righe_documenti.iddocumento=co_documenti.id WHERE co_tipidocumento.dir='uscita' AND co_tipidocumento.descrizione!='Bozza' AND co_documenti.data BETWEEN ".prepare($start).' AND '.prepare($end).' GROUP BY YEAR(co_documenti.data), MONTH(co_documenti.data) ORDER BY YEAR(co_documenti.data) ASC, MONTH(co_documenti.data) ASC');
|
||||||
|
|
||||||
|
$results = Stats::monthly($results, $start, $end);
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'label' => tr('Acquisti').' - '.tr('Periodo _NUM_', [
|
||||||
|
'_NUM_' => $calendar_id
|
||||||
|
]),
|
||||||
|
'results' => $results
|
||||||
|
]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
@ -11,35 +11,25 @@ $start = $_SESSION['period_start'];
|
|||||||
$end = $_SESSION['period_end'];
|
$end = $_SESSION['period_end'];
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<h3 class="text-center">
|
<div class="box box-warning">
|
||||||
<span class="label label-primary">'.tr('Periodo dal _START_ al _END_', [
|
<div class="box-header">
|
||||||
'_START_' => Translator::dateToLocale($start),
|
<h4 class="box-title">
|
||||||
'_END_' => Translator::dateToLocale($end),
|
'.tr('Periodi temporali').'
|
||||||
]).'</span>
|
</h4>
|
||||||
</h3>
|
<div class="box-tools pull-right">
|
||||||
<hr>
|
<button class="btn btn-warning btn-xs" onclick="add_calendar()">
|
||||||
|
<i class="fa fa-plus"></i> '.tr('Aggiungi periodo').'
|
||||||
<script>
|
</button>
|
||||||
$(document).ready(function() {
|
<button type="button" class="btn btn-box-tool" data-widget="collapse">
|
||||||
start = moment("'.$start.'");
|
<i class="fa fa-minus"></i>
|
||||||
end = moment("'.$end.'");
|
</button>
|
||||||
|
</div>
|
||||||
months = [];
|
</div>
|
||||||
while(start.isSameOrBefore(end, "month")){
|
|
||||||
string = start.format("MMMM YYYY");
|
<div class="box-body collapse in" id="calendars">
|
||||||
|
|
||||||
months.push(string.charAt(0).toUpperCase() + string.slice(1));
|
</div>
|
||||||
|
</div>';
|
||||||
start.add(1, "months");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>';
|
|
||||||
|
|
||||||
$fatturato = $dbo->fetchArray("SELECT ROUND(SUM(co_righe_documenti.subtotale - co_righe_documenti.sconto), 2) AS totale, YEAR(co_documenti.data) AS year, MONTH(co_documenti.data) AS month FROM co_documenti INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id INNER JOIN co_righe_documenti ON co_righe_documenti.iddocumento=co_documenti.id WHERE co_tipidocumento.dir='entrata' AND co_tipidocumento.descrizione!='Bozza' AND co_documenti.data BETWEEN ".prepare($start).' AND '.prepare($end).' GROUP BY YEAR(co_documenti.data), MONTH(co_documenti.data) ORDER BY YEAR(co_documenti.data) ASC, MONTH(co_documenti.data) ASC');
|
|
||||||
$acquisti = $dbo->fetchArray("SELECT ROUND(SUM(co_righe_documenti.subtotale - co_righe_documenti.sconto), 2) AS totale, YEAR(co_documenti.data) AS year, MONTH(co_documenti.data) AS month FROM co_documenti INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id INNER JOIN co_righe_documenti ON co_righe_documenti.iddocumento=co_documenti.id WHERE co_tipidocumento.dir='uscita' AND co_tipidocumento.descrizione!='Bozza' AND co_documenti.data BETWEEN ".prepare($start).' AND '.prepare($end).' GROUP BY YEAR(co_documenti.data), MONTH(co_documenti.data) ORDER BY YEAR(co_documenti.data) ASC, MONTH(co_documenti.data) ASC');
|
|
||||||
|
|
||||||
$fatturato = Stats::monthly($fatturato, $start, $end);
|
|
||||||
$acquisti = Stats::monthly($acquisti, $start, $end);
|
|
||||||
|
|
||||||
// Fatturato
|
// Fatturato
|
||||||
echo '
|
echo '
|
||||||
@ -56,49 +46,86 @@ echo '
|
|||||||
<canvas class="box-body collapse in" id="fatturato" height="100"></canvas>
|
<canvas class="box-body collapse in" id="fatturato" height="100"></canvas>
|
||||||
</div>';
|
</div>';
|
||||||
|
|
||||||
|
echo '
|
||||||
|
<script src="'.$structure->fileurl('js/functions.js').'"></script>
|
||||||
|
<script src="'.$structure->fileurl('js/calendar.js').'"></script>
|
||||||
|
<script src="'.$structure->fileurl('js/manager.js').'"></script>
|
||||||
|
<script src="'.$structure->fileurl('js/stat.js').'"></script>
|
||||||
|
<script src="'.$structure->fileurl('js/stats/line_chart.js').'"></script>';
|
||||||
|
|
||||||
// Script per il grafico del fatturato
|
// Script per il grafico del fatturato
|
||||||
echo '
|
echo '
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
start = moment("'.$start.'");
|
||||||
new Chart(document.getElementById("fatturato").getContext("2d"), {
|
end = moment("'.$end.'");
|
||||||
type: "bar",
|
|
||||||
data: {
|
months = get_months(start, end);
|
||||||
labels: months,
|
|
||||||
datasets: [
|
var chart_options = {
|
||||||
{
|
type: "line",
|
||||||
label: "'.tr('Fatturato (iva esclusa)').'",
|
data: {
|
||||||
backgroundColor: "#63E360",
|
labels: [],
|
||||||
data: [
|
datasets: [],
|
||||||
'.implode(',', array_column($fatturato, 'totale')).'
|
},
|
||||||
]
|
options: {
|
||||||
},
|
responsive: true,
|
||||||
{
|
tooltips: {
|
||||||
label: "'.tr('Acquisti (iva esclusa)').'",
|
callbacks: {
|
||||||
backgroundColor: "#EE4B4B",
|
label: function(tooltipItem, data) {
|
||||||
data: [
|
var dataset = data.datasets[tooltipItem.datasetIndex];
|
||||||
'.implode(',', array_column($acquisti, 'totale')).'
|
var label = dataset.labels ? dataset.labels[tooltipItem.index] : "";
|
||||||
]
|
|
||||||
|
if (label) {
|
||||||
|
label += ": ";
|
||||||
|
}
|
||||||
|
|
||||||
|
label += tooltipItem.yLabel;
|
||||||
|
|
||||||
|
return label;
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
},
|
},
|
||||||
options: {
|
scales: {
|
||||||
responsive: true,
|
yAxes: [{
|
||||||
legend: {
|
ticks: {
|
||||||
position: "bottom",
|
// Include a dollar sign in the ticks
|
||||||
},
|
callback: function(value, index, values) {
|
||||||
scales: {
|
return \'€ \' + value;
|
||||||
yAxes: [{
|
}
|
||||||
ticks: {
|
}
|
||||||
// Include a dollar sign in the ticks
|
}]
|
||||||
callback: function(value, index, values) {
|
},
|
||||||
return \'€ \' + value;
|
}
|
||||||
}
|
};
|
||||||
}
|
|
||||||
}]
|
// Inzializzazione manager
|
||||||
},
|
var info = {
|
||||||
}
|
url: "'.str_replace('edit.php', '', $structure->fileurl('edit.php')).'",
|
||||||
});
|
id_module: globals.id_module,
|
||||||
|
id_record: globals.id_record,
|
||||||
|
start_date: globals.start_date,
|
||||||
|
end_date: globals.end_date,
|
||||||
|
}
|
||||||
|
var manager = new Manager(info);
|
||||||
|
|
||||||
|
var chart_fatturato, chart_acquisti;
|
||||||
|
$(document).ready(function(){
|
||||||
|
var fatturato_canvas = document.getElementById("fatturato").getContext("2d");
|
||||||
|
//var acquisti_canvas = document.getElementById("acquisti").getContext("2d");
|
||||||
|
|
||||||
|
chart_fatturato = new Chart(fatturato_canvas, chart_options);
|
||||||
|
//chart_acquisti = new Chart(fatturato_canvas, chart_options);
|
||||||
|
|
||||||
|
add_calendar();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function init_calendar(calendar) {
|
||||||
|
var fatturato = new LineChart(calendar, "actions.php", {op: "fatturato"}, chart_fatturato);
|
||||||
|
var acquisti = new LineChart(calendar, "actions.php", {op: "acquisti"}, chart_fatturato);
|
||||||
|
|
||||||
|
calendar.addElement(fatturato);
|
||||||
|
calendar.addElement(acquisti);
|
||||||
|
}
|
||||||
</script>';
|
</script>';
|
||||||
|
|
||||||
// Clienti top
|
// Clienti top
|
||||||
@ -206,7 +233,7 @@ $tipi = $dbo->fetchArray('SELECT * FROM `in_tipiintervento`');
|
|||||||
|
|
||||||
$dataset = '';
|
$dataset = '';
|
||||||
foreach ($tipi as $tipo) {
|
foreach ($tipi as $tipo) {
|
||||||
$interventi = $dbo->fetchArray('SELECT COUNT(*) AS totale, YEAR(in_interventi.data_richiesta) AS year, MONTH(in_interventi.data_richiesta) AS month FROM in_interventi WHERE in_interventi.idtipointervento = '.prepare($tipo['idtipointervento']).' AND in_interventi.data_richiesta BETWEEN '.prepare($start).' AND '.prepare($end).' GROUP BY YEAR(in_interventi.data_richiesta), MONTH(in_interventi.data_richiesta) ORDER BY YEAR(in_interventi.data_richiesta) ASC, MONTH(in_interventi.data_richiesta) ASC');
|
$interventi = $dbo->fetchArray('SELECT COUNT(*) AS result, YEAR(in_interventi.data_richiesta) AS year, MONTH(in_interventi.data_richiesta) AS month FROM in_interventi WHERE in_interventi.idtipointervento = '.prepare($tipo['idtipointervento']).' AND in_interventi.data_richiesta BETWEEN '.prepare($start).' AND '.prepare($end).' GROUP BY YEAR(in_interventi.data_richiesta), MONTH(in_interventi.data_richiesta) ORDER BY YEAR(in_interventi.data_richiesta) ASC, MONTH(in_interventi.data_richiesta) ASC');
|
||||||
|
|
||||||
$interventi = Stats::monthly($interventi, $start, $end);
|
$interventi = Stats::monthly($interventi, $start, $end);
|
||||||
|
|
||||||
@ -217,7 +244,7 @@ foreach ($tipi as $tipo) {
|
|||||||
label: "'.$tipo['descrizione'].'",
|
label: "'.$tipo['descrizione'].'",
|
||||||
backgroundColor: "'.$background.'",
|
backgroundColor: "'.$background.'",
|
||||||
data: [
|
data: [
|
||||||
'.implode(',', array_column($interventi, 'totale')).'
|
'.implode(',', array_column($interventi, 'result')).'
|
||||||
]
|
]
|
||||||
},';
|
},';
|
||||||
}
|
}
|
||||||
|
91
modules/statistiche/js/functions.js
Normal file
91
modules/statistiche/js/functions.js
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
var manager = manager ? manager : undefined;
|
||||||
|
|
||||||
|
function remove_calendar(button) {
|
||||||
|
var name = $(button).parent().find("input").attr("id");
|
||||||
|
|
||||||
|
if (manager.remove(name)) {
|
||||||
|
$("#group-" + name).remove();
|
||||||
|
} else {
|
||||||
|
swal({
|
||||||
|
title: globals.translations.singleCalendar,
|
||||||
|
type: "info",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_calendar() {
|
||||||
|
var last = $("#calendars").find("input").last().attr("id");
|
||||||
|
var last_id = last ? last.split("-")[1] : 0;
|
||||||
|
last_id = parseInt(last_id) + 1;
|
||||||
|
|
||||||
|
var name = "calendar-" + last_id;
|
||||||
|
|
||||||
|
$("#calendars").append(`<div class="col-md-4" id="group-` + name + `">
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon before">` + last_id + `</span>
|
||||||
|
<input class="form-control calendar-input text-center" type="text" name="` + name + `" id="` + name + `"/>
|
||||||
|
<span class="input-group-addon after clickable btn btn-danger" onclick="remove_calendar(this)">
|
||||||
|
<i class="fa fa-trash-o"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
</div>`);
|
||||||
|
|
||||||
|
// Calendario principale
|
||||||
|
ranges = {};
|
||||||
|
ranges[globals.translations.today] = [moment(), moment()];
|
||||||
|
ranges[globals.translations.firstThreemester] = [moment("01", "MM"), moment("03", "MM").endOf('month')];
|
||||||
|
ranges[globals.translations.secondThreemester] = [moment("04", "MM"), moment("06", "MM").endOf('month')];
|
||||||
|
ranges[globals.translations.thirdThreemester] = [moment("07", "MM"), moment("09", "MM").endOf('month')];
|
||||||
|
ranges[globals.translations.fourthThreemester] = [moment("10", "MM"), moment("12", "MM").endOf('month')];
|
||||||
|
ranges[globals.translations.firstSemester] = [moment("01", "MM"), moment("06", "MM").endOf('month')];
|
||||||
|
ranges[globals.translations.secondSemester] = [moment("06", "MM"), moment("12", "MM").endOf('month')];
|
||||||
|
ranges[globals.translations.thisMonth] = [moment().startOf('month'), moment().endOf('month')];
|
||||||
|
ranges[globals.translations.lastMonth] = [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')];
|
||||||
|
ranges[globals.translations.thisYear] = [moment().startOf('year'), moment().endOf('year')];
|
||||||
|
ranges[globals.translations.lastYear] = [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')];
|
||||||
|
|
||||||
|
|
||||||
|
$("#" + name).daterangepicker({
|
||||||
|
locale: {
|
||||||
|
customRangeLabel: globals.translations.custom,
|
||||||
|
applyLabel: globals.translations.apply,
|
||||||
|
cancelLabel: globals.translations.cancel,
|
||||||
|
fromLabel: globals.translations.from,
|
||||||
|
toLabel: globals.translations.to,
|
||||||
|
},
|
||||||
|
startDate: globals.start_date_formatted,
|
||||||
|
endDate: globals.end_date_formatted,
|
||||||
|
applyClass: "btn btn-success btn-sm",
|
||||||
|
cancelClass: "btn btn-danger btn-sm",
|
||||||
|
ranges: ranges,
|
||||||
|
linkedCalendars: false
|
||||||
|
}, function (start, end) {
|
||||||
|
var name = $(this.element).attr("id");
|
||||||
|
var start = start.format("YYYY-MM-DD");
|
||||||
|
var end = end.format("YYYY-MM-DD");
|
||||||
|
|
||||||
|
manager.update(name, start, end);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Inizializzazone calendario
|
||||||
|
var calendar = manager.add(last_id, name);
|
||||||
|
|
||||||
|
init_calendar(calendar);
|
||||||
|
|
||||||
|
manager.init(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_months(start, end) {
|
||||||
|
var months = [];
|
||||||
|
while (start.isSameOrBefore(end, "month")) {
|
||||||
|
string = start.format("MMMM YYYY");
|
||||||
|
|
||||||
|
months.push(string.charAt(0).toUpperCase() + string.slice(1));
|
||||||
|
|
||||||
|
start.add(1, "months");
|
||||||
|
}
|
||||||
|
|
||||||
|
return months;
|
||||||
|
}
|
||||||
|
|
11
modules/statistiche/js/init.js
Normal file
11
modules/statistiche/js/init.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Inzializzazione manager standard
|
||||||
|
var info = {
|
||||||
|
url: local_url,
|
||||||
|
id_module: globals.id_module,
|
||||||
|
id_record: globals.id_record,
|
||||||
|
start_date: globals.start_date,
|
||||||
|
end_date: globals.end_date,
|
||||||
|
};
|
||||||
|
|
||||||
|
var manager = new Manager(info);
|
||||||
|
add_calendar();
|
38
modules/statistiche/js/manager.js
Normal file
38
modules/statistiche/js/manager.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
class Manager {
|
||||||
|
constructor(info) {
|
||||||
|
this.info = info;
|
||||||
|
|
||||||
|
this.calendars = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(name) {
|
||||||
|
if (Object.keys(this.calendars).length > 1) {
|
||||||
|
this.calendars[name].remove();
|
||||||
|
delete this.calendars[name];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
add(id, name) {
|
||||||
|
var calendar = new Calendar(this.info, id);
|
||||||
|
this.calendars[name] = calendar;
|
||||||
|
|
||||||
|
return calendar;
|
||||||
|
}
|
||||||
|
|
||||||
|
init(name) {
|
||||||
|
var calendar = this.calendars[name];
|
||||||
|
|
||||||
|
var start = this.info.start_date;
|
||||||
|
var end = this.info.end_date;
|
||||||
|
|
||||||
|
calendar.update(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
update(name, start, end){
|
||||||
|
this.calendars[name].update(start, end);
|
||||||
|
}
|
||||||
|
}
|
36
modules/statistiche/js/stat.js
Normal file
36
modules/statistiche/js/stat.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
class Stat {
|
||||||
|
constructor(calendar, file, data = {}){
|
||||||
|
this.calendar = calendar;
|
||||||
|
|
||||||
|
this.file = file;
|
||||||
|
this.data = data;
|
||||||
|
|
||||||
|
this.data.id_module = this.calendar.info.id_module;
|
||||||
|
this.data.id_record = this.calendar.info.id_record;
|
||||||
|
this.data.calendar_id = this.calendar.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
getCalendarID(){
|
||||||
|
return this.calendar.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
getData(start, end, callback) {
|
||||||
|
var data = JSON.parse(JSON.stringify(this.data));
|
||||||
|
|
||||||
|
data.start = start;
|
||||||
|
data.end = end;
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: this.calendar.info.url + "/" + this.file,
|
||||||
|
type: "get",
|
||||||
|
data: data,
|
||||||
|
success: function(data){
|
||||||
|
callback(data)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
add(start, end){}
|
||||||
|
update(start, end){}
|
||||||
|
remove(){}
|
||||||
|
}
|
95
modules/statistiche/js/stats/line_chart.js
Normal file
95
modules/statistiche/js/stats/line_chart.js
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
class LineChart extends Stat {
|
||||||
|
constructor(calendar, file, data = {}, chart){
|
||||||
|
super(calendar, file, data);
|
||||||
|
|
||||||
|
this.chart = chart;
|
||||||
|
}
|
||||||
|
|
||||||
|
add(start, end, color = null) {
|
||||||
|
var calendar_id = this.calendar.id;
|
||||||
|
var chart = this.chart;
|
||||||
|
|
||||||
|
var color = color ? color : this.getRandomColor();
|
||||||
|
|
||||||
|
this.getData(start, end, function(response) {
|
||||||
|
var data = JSON.parse(response);
|
||||||
|
|
||||||
|
var label = data.label;
|
||||||
|
|
||||||
|
var dataset = [];
|
||||||
|
var labels = [];
|
||||||
|
|
||||||
|
data.results.forEach(function (item) {
|
||||||
|
dataset.push(item.result);
|
||||||
|
|
||||||
|
var date = moment().month(item.month - 1).year(item.year);
|
||||||
|
labels.push(date.format("MMMM YYYY"));
|
||||||
|
});
|
||||||
|
|
||||||
|
while (chart.data.labels.length < data.results.length) {
|
||||||
|
chart.data.labels.push("");
|
||||||
|
}
|
||||||
|
|
||||||
|
chart.data.datasets.push({
|
||||||
|
calendar_id: calendar_id,
|
||||||
|
label: label,
|
||||||
|
backgroundColor: color,
|
||||||
|
borderColor: color,
|
||||||
|
data: dataset,
|
||||||
|
labels: labels,
|
||||||
|
fill: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
chart.update();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
update(start, end) {
|
||||||
|
var color = this.remove();
|
||||||
|
|
||||||
|
this.add(start, end, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
getRandomColor() {
|
||||||
|
var letters = '0123456789ABCDEF';
|
||||||
|
var color = '#';
|
||||||
|
for (var i = 0; i < 6; i++) {
|
||||||
|
color += letters[Math.floor(Math.random() * 16)];
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
remove() {
|
||||||
|
var chart = this.chart;
|
||||||
|
var calendar_id = this.calendar.id;
|
||||||
|
|
||||||
|
var max_length = 0;
|
||||||
|
var dataset_index = undefined;
|
||||||
|
|
||||||
|
chart.data.datasets.forEach(function (item, index) {
|
||||||
|
if(item.calendar_id == calendar_id) {
|
||||||
|
dataset_index = index;
|
||||||
|
} else {
|
||||||
|
if (item.data.length > max_length) {
|
||||||
|
max_length = item.data.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var color = null;
|
||||||
|
if (dataset_index != undefined) {
|
||||||
|
color = chart.data.datasets[dataset_index].backgroundColor;
|
||||||
|
|
||||||
|
chart.data.datasets.splice(dataset_index, 1);
|
||||||
|
chart.data.labels.splice(dataset_index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (chart.data.labels.length > max_length) {
|
||||||
|
chart.data.labels.pop("");
|
||||||
|
}
|
||||||
|
|
||||||
|
chart.update();
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
}
|
33
modules/statistiche/js/stats/table.js
Normal file
33
modules/statistiche/js/stats/table.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
class Table extends Stat {
|
||||||
|
constructor(calendar, file, data = {}, id){
|
||||||
|
super(calendar, file, data);
|
||||||
|
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
add(start, end) {
|
||||||
|
var id = this.id;
|
||||||
|
var calendar_id = this.calendar.id;
|
||||||
|
|
||||||
|
this.getData(start, end, function(data) {
|
||||||
|
var row = $(id).find("#row-" + calendar_id);
|
||||||
|
|
||||||
|
if (!row.length) {
|
||||||
|
$(id).append(data);
|
||||||
|
} else {
|
||||||
|
row.after(data);
|
||||||
|
row.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
$(id).find("#row-" + calendar_id).effect("highlight", {}, 3000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
update(start, end) {
|
||||||
|
this.add(start, end)
|
||||||
|
}
|
||||||
|
|
||||||
|
remove() {
|
||||||
|
$(this.id).find("#row-" + this.calendar.id).remove();
|
||||||
|
}
|
||||||
|
}
|
3
modules/statistiche/js/stats/widget.js
Normal file
3
modules/statistiche/js/stats/widget.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class Widget extends Table {
|
||||||
|
|
||||||
|
}
|
@ -23,13 +23,17 @@ class Stats
|
|||||||
$d2 = new DateTime($end);
|
$d2 = new DateTime($end);
|
||||||
$count = $d1->diff($d2)->m + ($d1->diff($d2)->y * 12) + 1;
|
$count = $d1->diff($d2)->m + ($d1->diff($d2)->y * 12) + 1;
|
||||||
|
|
||||||
|
$year = $d1->format('Y');
|
||||||
$month = intval($d1->format('m')) - 1;
|
$month = intval($d1->format('m')) - 1;
|
||||||
for ($i = 0; $i < $count; ++$i) {
|
for ($i = 0; $i < $count; ++$i) {
|
||||||
|
$year = $month >= 12 ? $year + 1 : $year;
|
||||||
$month = $month % 12;
|
$month = $month % 12;
|
||||||
|
|
||||||
if (!isset($data[$i]) || intval($data[$i]['month']) != $month + 1) {
|
if (!isset($data[$i]) || intval($data[$i]['month']) != $month + 1) {
|
||||||
array_splice($data, $i, 0, [[
|
array_splice($data, $i, 0, [[
|
||||||
'totale' => 0,
|
'result' => 0,
|
||||||
|
'year' => $year,
|
||||||
|
'month' => $month + 1,
|
||||||
]]);
|
]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,91 +26,25 @@ echo '
|
|||||||
|
|
||||||
<div id="widgets">
|
<div id="widgets">
|
||||||
|
|
||||||
</div>
|
</div>';
|
||||||
|
|
||||||
<script src="'.$structure->fileurl('js/stat.js').'"></script>
|
$statistiche = Modules::get('Statistiche');
|
||||||
<script src="'.$structure->fileurl('js/calendar.js').'"></script>
|
echo '
|
||||||
<script src="'.$structure->fileurl('js/widget.js').'"></script>
|
<script src="'.$statistiche->fileurl('js/functions.js').'"></script>
|
||||||
|
<script src="'.$statistiche->fileurl('js/manager.js').'"></script>
|
||||||
|
<script src="'.$statistiche->fileurl('js/calendar.js').'"></script>
|
||||||
|
<script src="'.$statistiche->fileurl('js/stat.js').'"></script>
|
||||||
|
<script src="'.$statistiche->fileurl('js/stats/table.js').'"></script>
|
||||||
|
<script src="'.$statistiche->fileurl('js/stats/widget.js').'"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var calendars = {};
|
var local_url = "'.str_replace('edit.php', '', $structure->fileurl('edit.php')).'";
|
||||||
var info = {
|
|
||||||
url: "'.str_replace('edit.php', '', $structure->fileurl('edit.php')).'",
|
|
||||||
id_module: globals.id_module,
|
|
||||||
id_record: globals.id_record,
|
|
||||||
};
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
function init_calendar(calendar) {
|
||||||
add_calendar();
|
var widgets = new Widget(calendar, "info.php", {}, "#widgets");
|
||||||
});
|
|
||||||
|
|
||||||
function remove_calendar(button) {
|
|
||||||
if (Object.keys(calendars).length > 1){
|
|
||||||
var name = $(button).parent().find("input").attr("id");
|
|
||||||
|
|
||||||
calendars[name].remove();
|
|
||||||
delete calendars[name];
|
|
||||||
|
|
||||||
$("#group-" + name).remove();
|
|
||||||
} else {
|
|
||||||
swal({
|
|
||||||
title: "'.tr("E' presente un solo calendario!").'",
|
|
||||||
type: "info",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function add_calendar() {
|
|
||||||
var last = $("#calendars").find("input").last().attr("id");
|
|
||||||
var last_id = last ? last.split("-")[1] : 0;
|
|
||||||
last_id = parseInt(last_id) + 1;
|
|
||||||
|
|
||||||
var name = "calendar-" + last_id;
|
|
||||||
|
|
||||||
$("#calendars").append(`<div class="col-md-4" id="group-` + name + `">
|
|
||||||
<div class="input-group">
|
|
||||||
<span class="input-group-addon before">` + last_id + `</span>
|
|
||||||
<input class="form-control calendar-input text-center" type="text" name="` + name + `" id="` + name + `"/>
|
|
||||||
<span class="input-group-addon after clickable btn btn-danger" onclick="remove_calendar(this)">
|
|
||||||
<i class="fa fa-trash-o"></i>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<br>
|
|
||||||
</div>`);
|
|
||||||
|
|
||||||
$("#" + name).daterangepicker({
|
|
||||||
locale: {
|
|
||||||
customRangeLabel: globals.translations.custom,
|
|
||||||
applyLabel: globals.translations.apply,
|
|
||||||
cancelLabel: globals.translations.cancel,
|
|
||||||
fromLabel: globals.translations.from,
|
|
||||||
toLabel: globals.translations.to,
|
|
||||||
},
|
|
||||||
startDate: globals.start_date,
|
|
||||||
endDate: globals.end_date,
|
|
||||||
applyClass: "btn btn-success btn-sm",
|
|
||||||
cancelClass: "btn btn-danger btn-sm",
|
|
||||||
linkedCalendars: false
|
|
||||||
}, function (start, end) {
|
|
||||||
var name = $(this.element).attr("id");
|
|
||||||
var start = start.format("YYYY-MM-DD");
|
|
||||||
var end = end.format("YYYY-MM-DD");
|
|
||||||
|
|
||||||
calendars[name].update(start, end);
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#" + name).on("apply.daterangepicker", function(ev, picker) {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// Inizializzazone calendario
|
|
||||||
var calendar = new Calendar(info, last_id);
|
|
||||||
calendars[name] = calendar;
|
|
||||||
|
|
||||||
var widgets = new Widget(calendar, "#widgets");
|
|
||||||
|
|
||||||
calendar.addElement(widgets);
|
calendar.addElement(widgets);
|
||||||
|
|
||||||
calendar.update(globals.start_date, globals.end_date);
|
|
||||||
}
|
}
|
||||||
</script>';
|
</script>
|
||||||
|
|
||||||
|
<script src="'.$statistiche->fileurl('js/init.js').'"></script>';
|
||||||
|
@ -72,7 +72,7 @@ $totale_fatture_vendita = $fatture_vendita->sum('imponibile_scontato');
|
|||||||
echo '
|
echo '
|
||||||
<div class="box box-info" id="row-'.$calendar_id.'">
|
<div class="box box-info" id="row-'.$calendar_id.'">
|
||||||
<div class="box-header">
|
<div class="box-header">
|
||||||
<h3 class="box-title">'.tr('Periodo dal _START_ al _END_', [
|
<h3 class="box-title">'.tr('Dal _START_ al _END_', [
|
||||||
'_START_' => dateFormat($start),
|
'_START_' => dateFormat($start),
|
||||||
'_END_' => dateFormat($end),
|
'_END_' => dateFormat($end),
|
||||||
]).' - '.tr('Periodo _NUM_', [
|
]).' - '.tr('Periodo _NUM_', [
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
class Stat {
|
|
||||||
constructor(calendar, id){
|
|
||||||
this.calendar = calendar;
|
|
||||||
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
add(start, end){}
|
|
||||||
update(start, end){}
|
|
||||||
remove(){}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
class Widget extends Stat {
|
|
||||||
constructor(calendar, id){
|
|
||||||
super(calendar, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
getData(start, end, callback) {
|
|
||||||
$.ajax({
|
|
||||||
url: this.calendar.info.url + "/info.php",
|
|
||||||
type: "get",
|
|
||||||
data: {
|
|
||||||
id_module: this.calendar.info.id_module,
|
|
||||||
id_record: this.calendar.info.id_record,
|
|
||||||
calendar_id: this.calendar.id,
|
|
||||||
dir: this.direzione,
|
|
||||||
start: start,
|
|
||||||
end: end,
|
|
||||||
},
|
|
||||||
success: function(data){
|
|
||||||
callback(data)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
add(start, end) {
|
|
||||||
var id = this.id;
|
|
||||||
var calendar_id = this.calendar.id;
|
|
||||||
|
|
||||||
this.getData(start, end, function(data) {
|
|
||||||
var row = $(id).find("#row-" + calendar_id);
|
|
||||||
|
|
||||||
if (!row.length) {
|
|
||||||
$(id).append(data);
|
|
||||||
} else {
|
|
||||||
row.after(data);
|
|
||||||
row.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
$(id).find("#row-" + calendar_id).effect("highlight", {}, 3000);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
update(start, end) {
|
|
||||||
this.add(start, end)
|
|
||||||
}
|
|
||||||
|
|
||||||
remove(start, end) {
|
|
||||||
$(this.id).find("#row-" + this.calendar.id).remove();
|
|
||||||
}
|
|
||||||
}
|
|
@ -34,9 +34,9 @@ echo '
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="text-center">#</th>
|
<th class="text-center">#</th>
|
||||||
<th>'.tr('Perido').'</th>
|
<th>'.tr('Periodo').'</th>
|
||||||
<th>'.tr('Prezzo minimo').'</th>
|
<th>'.tr('Prezzo minimo').'</th>
|
||||||
<th>'.tr('Prezzio medio').'</th>
|
<th>'.tr('Prezzo medio').'</th>
|
||||||
<th>'.tr('Prezzo massimo').'</th>
|
<th>'.tr('Prezzo massimo').'</th>
|
||||||
<th>'.tr('Oscillazione').'</th>
|
<th>'.tr('Oscillazione').'</th>
|
||||||
<th>'.tr('Oscillazione in %').'</th>
|
<th>'.tr('Oscillazione in %').'</th>
|
||||||
@ -60,9 +60,9 @@ echo '
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>'.tr('Perido').'</th>
|
<th>'.tr('Periodo').'</th>
|
||||||
<th>'.tr('Prezzo minimo').'</th>
|
<th>'.tr('Prezzo minimo').'</th>
|
||||||
<th>'.tr('Prezzio medio').'</th>
|
<th>'.tr('Prezzo medio').'</th>
|
||||||
<th>'.tr('Prezzo massimo').'</th>
|
<th>'.tr('Prezzo massimo').'</th>
|
||||||
<th>'.tr('Oscillazione').'</th>
|
<th>'.tr('Oscillazione').'</th>
|
||||||
<th>'.tr('Oscillazione in %').'</th>
|
<th>'.tr('Oscillazione in %').'</th>
|
||||||
@ -74,89 +74,29 @@ echo '
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>';
|
||||||
|
|
||||||
|
$statistiche = Modules::get('Statistiche');
|
||||||
|
|
||||||
|
echo '
|
||||||
|
<script src="'.$statistiche->fileurl('js/functions.js').'"></script>
|
||||||
|
<script src="'.$statistiche->fileurl('js/manager.js').'"></script>
|
||||||
|
<script src="'.$statistiche->fileurl('js/calendar.js').'"></script>
|
||||||
|
<script src="'.$statistiche->fileurl('js/stat.js').'"></script>
|
||||||
|
<script src="'.$statistiche->fileurl('js/stats/table.js').'"></script>
|
||||||
|
|
||||||
<script src="'.$structure->fileurl('js/stat.js').'"></script>
|
|
||||||
<script src="'.$structure->fileurl('js/calendar.js').'"></script>
|
|
||||||
<script src="'.$structure->fileurl('js/prezzo.js').'"></script>
|
<script src="'.$structure->fileurl('js/prezzo.js').'"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var calendars = {};
|
var local_url = "'.str_replace('edit.php', '', $structure->fileurl('edit.php')).'";
|
||||||
var info = {
|
|
||||||
url: "'.str_replace('edit.php', '', $structure->fileurl('edit.php')).'",
|
|
||||||
id_module: globals.id_module,
|
|
||||||
id_record: globals.id_record,
|
|
||||||
};
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
add_calendar();
|
|
||||||
});
|
|
||||||
|
|
||||||
function remove_calendar(button) {
|
|
||||||
if (Object.keys(calendars).length > 1){
|
|
||||||
var name = $(button).parent().find("input").attr("id");
|
|
||||||
|
|
||||||
calendars[name].remove();
|
|
||||||
delete calendars[name];
|
|
||||||
|
|
||||||
$("#group-" + name).remove();
|
|
||||||
} else {
|
|
||||||
swal({
|
|
||||||
title: "'.tr("E' presente un solo calendario!").'",
|
|
||||||
type: "info",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function add_calendar() {
|
|
||||||
var last = $("#calendars").find("input").last().attr("id");
|
|
||||||
var last_id = last ? last.split("-")[1] : 0;
|
|
||||||
last_id = parseInt(last_id) + 1;
|
|
||||||
|
|
||||||
var name = "calendar-" + last_id;
|
|
||||||
|
|
||||||
$("#calendars").append(`<div class="col-md-4" id="group-` + name + `">
|
|
||||||
<div class="input-group">
|
|
||||||
<span class="input-group-addon before">` + last_id + `</span>
|
|
||||||
<input class="form-control calendar-input text-center" type="text" name="` + name + `" id="` + name + `"/>
|
|
||||||
<span class="input-group-addon after clickable btn btn-danger" onclick="remove_calendar(this)">
|
|
||||||
<i class="fa fa-trash-o"></i>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<br>
|
|
||||||
</div>`);
|
|
||||||
|
|
||||||
$("#" + name).daterangepicker({
|
|
||||||
locale: {
|
|
||||||
customRangeLabel: globals.translations.custom,
|
|
||||||
applyLabel: globals.translations.apply,
|
|
||||||
cancelLabel: globals.translations.cancel,
|
|
||||||
fromLabel: globals.translations.from,
|
|
||||||
toLabel: globals.translations.to,
|
|
||||||
},
|
|
||||||
startDate: globals.start_date,
|
|
||||||
endDate: globals.end_date,
|
|
||||||
applyClass: "btn btn-success btn-sm",
|
|
||||||
cancelClass: "btn btn-danger btn-sm",
|
|
||||||
linkedCalendars: false
|
|
||||||
}, function (start, end) {
|
|
||||||
var name = $(this.element).attr("id");
|
|
||||||
var start = start.format("YYYY-MM-DD");
|
|
||||||
var end = end.format("YYYY-MM-DD");
|
|
||||||
|
|
||||||
calendars[name].update(start, end);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Inizializzazone calendario
|
|
||||||
var calendar = new Calendar(info, last_id);
|
|
||||||
calendars[name] = calendar;
|
|
||||||
|
|
||||||
|
function init_calendar(calendar) {
|
||||||
var prezzo_acquisto = new Prezzo(calendar, "#prezzi_acquisto", "uscita");
|
var prezzo_acquisto = new Prezzo(calendar, "#prezzi_acquisto", "uscita");
|
||||||
var prezzo_vendita = new Prezzo(calendar, "#prezzi_vendita", "entrata");
|
var prezzo_vendita = new Prezzo(calendar, "#prezzi_vendita", "entrata");
|
||||||
|
|
||||||
calendar.addElement(prezzo_acquisto);
|
calendar.addElement(prezzo_acquisto);
|
||||||
calendar.addElement(prezzo_vendita);
|
calendar.addElement(prezzo_vendita);
|
||||||
|
|
||||||
calendar.update(globals.start_date, globals.end_date);
|
|
||||||
}
|
}
|
||||||
</script>';
|
</script>
|
||||||
|
|
||||||
|
<script src="'.$statistiche->fileurl('js/init.js').'"></script>';
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
class Calendar {
|
|
||||||
constructor(info, id){
|
|
||||||
this.info = info;
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
this.elements = new Array();
|
|
||||||
}
|
|
||||||
|
|
||||||
addElement(object){
|
|
||||||
this.elements.push(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
update(start, end) {
|
|
||||||
this.elements.forEach(function (element) {
|
|
||||||
element.update(start, end);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
remove() {
|
|
||||||
this.elements.forEach(function (element) {
|
|
||||||
element.remove();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,51 +1,7 @@
|
|||||||
class Prezzo extends Stat {
|
class Prezzo extends Table {
|
||||||
constructor(calendar, id, direzione){
|
constructor(calendar, id, direzione){
|
||||||
super(calendar, id);
|
super(calendar, "manage_prezzi.php", {
|
||||||
|
direzione: direzione
|
||||||
this.direzione = direzione;
|
}, id);
|
||||||
}
|
|
||||||
|
|
||||||
getData(start, end, callback) {
|
|
||||||
$.ajax({
|
|
||||||
url: this.calendar.info.url + "/manage_prezzi.php",
|
|
||||||
type: "get",
|
|
||||||
data: {
|
|
||||||
id_module: this.calendar.info.id_module,
|
|
||||||
id_record: this.calendar.info.id_record,
|
|
||||||
calendar_id: this.calendar.id,
|
|
||||||
dir: this.direzione,
|
|
||||||
start: start,
|
|
||||||
end: end,
|
|
||||||
},
|
|
||||||
success: function(data){
|
|
||||||
callback(data)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
add(start, end) {
|
|
||||||
var id = this.id;
|
|
||||||
var calendar_id = this.calendar.id;
|
|
||||||
|
|
||||||
this.getData(start, end, function(data) {
|
|
||||||
var row = $(id).find("#row-" + calendar_id);
|
|
||||||
|
|
||||||
if (!row.length) {
|
|
||||||
$(id).append(data);
|
|
||||||
} else {
|
|
||||||
row.after(data);
|
|
||||||
row.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
$(id).find("#row-" + calendar_id).effect("highlight", {}, 3000);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
update(start, end) {
|
|
||||||
this.add(start, end)
|
|
||||||
}
|
|
||||||
|
|
||||||
remove(start, end) {
|
|
||||||
$(this.id).find("#row-" + this.calendar.id).remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
class Stat {
|
|
||||||
constructor(calendar, id){
|
|
||||||
this.calendar = calendar;
|
|
||||||
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
add(start, end){}
|
|
||||||
update(start, end){}
|
|
||||||
remove(){}
|
|
||||||
}
|
|
Reference in New Issue
Block a user