Skip to content

Commit 5d260b4

Browse files
committed
refactor: ripristino plugin
1 parent eae9a29 commit 5d260b4

File tree

4 files changed

+260
-0
lines changed

4 files changed

+260
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
3+
/*
4+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
5+
* Copyright (C) DevCode s.r.l.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
include_once __DIR__.'/../../core.php';
22+
use Models\Module;
23+
24+
echo '
25+
<hr>
26+
<div class="card card-warning">
27+
<div class="card-header">
28+
<h4 class="card-title">
29+
'.tr('Periodi temporali').'
30+
</h4>
31+
<div class="card-tools pull-right">
32+
<button class="btn btn-warning btn-xs" onclick="add_calendar()">
33+
<i class="fa fa-plus"></i> '.tr('Aggiungi periodo').'
34+
</button>
35+
<button type="button" class="btn btn-tool" data-card-widget="collapse">
36+
<i class="fa fa-plus"></i>
37+
</button>
38+
</div>
39+
</div>
40+
41+
<div class="card-body collapse in" id="calendars">
42+
43+
</div>
44+
</div>
45+
46+
<div class="card card-primary">
47+
<div class="card-header">
48+
<h3 class="card-title">
49+
<span class="tip" title="'.tr('La statistica considera le fatture di acquisto nel periodo temporale definito').'"><i class="fa fa-question-circle"></i></span>
50+
'.tr('Prezzo medio acquisto').'
51+
</h3>
52+
</div>
53+
54+
<div class="card-body">
55+
<table class="table table-striped table-sm table-bordered">
56+
<thead>
57+
<tr>
58+
<th class="text-center">#</th>
59+
<th>'.tr('Periodo').'</th>
60+
<th>'.tr('Prezzo minimo').'</th>
61+
<th>'.tr('Prezzo medio').'</th>
62+
<th>'.tr('Prezzo massimo').'</th>
63+
<th>'.tr('Oscillazione').'</th>
64+
<th>'.tr('Oscillazione in %').'</th>
65+
<th>'.tr('Andamento prezzo').'</th>
66+
</tr>
67+
</thead>
68+
<tbody id="prezzi_acquisto">
69+
70+
</tbody>
71+
</table>
72+
</div>
73+
</div>
74+
75+
<div class="card card-primary">
76+
<div class="card-header">
77+
<h3 class="card-title">
78+
<span class="tip" title="'.tr('La statistica considera le fatture di vendita nel periodo temporale definito').'"><i class="fa fa-question-circle"></i></span>
79+
'.tr('Prezzo medio vendita').'
80+
</h3>
81+
</div>
82+
83+
<div class="card-body">
84+
<table class="table table-striped table-sm table-bordered">
85+
<thead>
86+
<tr>
87+
<th>#</th>
88+
<th>'.tr('Periodo').'</th>
89+
<th>'.tr('Prezzo minimo').'</th>
90+
<th>'.tr('Prezzo medio').'</th>
91+
<th>'.tr('Prezzo massimo').'</th>
92+
<th>'.tr('Oscillazione').'</th>
93+
<th>'.tr('Oscillazione in %').'</th>
94+
<th>'.tr('Andamento prezzo').'</th>
95+
</tr>
96+
</thead>
97+
<tbody id="prezzi_vendita">
98+
99+
</tbody>
100+
</table>
101+
</div>
102+
</div>';
103+
104+
$statistiche = Module::where('name', 'Statistiche')->first();
105+
106+
if ($statistiche != null) {
107+
echo '
108+
<script src="'.$statistiche->fileurl('js/functions.js').'"></script>
109+
<script src="'.$statistiche->fileurl('js/manager.js').'"></script>
110+
<script src="'.$statistiche->fileurl('js/calendar.js').'"></script>
111+
<script src="'.$statistiche->fileurl('js/stat.js').'"></script>
112+
<script src="'.$statistiche->fileurl('js/stats/table.js').'"></script>';
113+
}
114+
115+
echo '
116+
117+
<script src="'.$structure->fileurl('js/prezzo.js').'"></script>
118+
119+
<script>
120+
var local_url = "'.str_replace('edit.php', '', $structure->fileurl('edit.php')).'";
121+
122+
function init_calendar(calendar) {
123+
var prezzo_acquisto = new Prezzo(calendar, "#prezzi_acquisto", "uscita");
124+
var prezzo_vendita = new Prezzo(calendar, "#prezzi_vendita", "entrata");
125+
126+
calendar.addElement(prezzo_acquisto);
127+
calendar.addElement(prezzo_vendita);
128+
}
129+
</script>';
130+
131+
if ($statistiche != null) {
132+
echo '
133+
<script src="'.$statistiche->fileurl('js/init.js').'"></script>';
134+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
3+
* Copyright (C) DevCode s.r.l.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
class Prezzo extends Table {
20+
constructor(calendar, id, direzione){
21+
super(calendar, "manage_prezzi.php", {
22+
direzione: direzione
23+
}, id);
24+
}
25+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
5+
* Copyright (C) DevCode s.r.l.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
include_once __DIR__.'/../../core.php';
22+
23+
use Plugins\StatisticheArticoli\Stats;
24+
25+
$calendar_id = filter('calendar_id');
26+
$direzione = filter('direzione');
27+
$start = filter('start');
28+
$end = filter('end');
29+
30+
$prezzi = Stats::prezzi($id_record, $start, $end, $direzione);
31+
$prezzo_min = $prezzi['min'];
32+
$prezzo_max = $prezzi['max'];
33+
$prezzo_medio = $prezzi['media'];
34+
35+
$oscillazione = $prezzo_max['prezzo'] - $prezzo_min['prezzo'];
36+
$oscillazione_percentuale = $prezzo_medio ? $oscillazione * 100 / ($prezzo_medio ?: 1) : 0;
37+
38+
$data_min = $prezzo_min['data'] ? strtotime((string) $prezzo_min['data']) : '';
39+
$data_max = $prezzo_max['data'] ? strtotime((string) $prezzo_max['data']) : '';
40+
if ($data_min == $data_max) {
41+
$andamento = tr('N.D.');
42+
} elseif ($data_min < $data_max) {
43+
$andamento = tr('In aumento');
44+
} else {
45+
$andamento = tr('In diminuzione');
46+
}
47+
48+
echo '
49+
<tr id="row-'.$calendar_id.'">
50+
<td class="text-center">'.$calendar_id.'</td>
51+
<td>'.dateFormat($start).' - '.dateFormat($end).'</td>
52+
<td class="text-right">'.moneyFormat($prezzo_min['prezzo']).'</td>
53+
<td class="text-right">'.moneyFormat($prezzo_medio).'</td>
54+
<td class="text-right">'.moneyFormat($prezzo_max['prezzo']).'</td>
55+
<td class="text-right">'.moneyFormat($oscillazione).'</td>
56+
<td class="text-right">'.Translator::numberToLocale($oscillazione_percentuale, '2').' %</td>
57+
<td>'.$andamento.'</td>
58+
</tr>';
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
5+
* Copyright (C) DevCode s.r.l.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
namespace Plugins\StatisticheArticoli;
22+
23+
class Stats
24+
{
25+
public static function prezzi($id_articolo, $start, $end, $dir = 'uscita')
26+
{
27+
$database = database();
28+
29+
$from = 'FROM `co_righe_documenti` INNER JOIN `co_documenti` ON `co_righe_documenti`.`iddocumento` = `co_documenti`.`id` INNER JOIN `zz_segments` ON `co_documenti`.`id_segment`=`zz_segments`.`id` INNER JOIN `co_tipidocumento` ON `co_documenti`.`idtipodocumento` = `co_tipidocumento`.`id` WHERE `co_righe_documenti`.`subtotale` != 0 AND `dir` ='.prepare($dir).' AND `co_documenti`.`data` BETWEEN '.prepare($start).' AND '.prepare($end).' AND `co_righe_documenti`.`idarticolo`='.prepare($id_articolo).' AND `zz_segments`.`autofatture`=0';
30+
31+
$prezzo_medio = $database->fetchOne('SELECT (SUM(subtotale) - SUM(sconto)) / SUM(qta) AS prezzo '.$from)['prezzo'];
32+
33+
$prezzo = 'SELECT (subtotale - sconto) / qta AS prezzo, co_documenti.data '.$from.' ORDER BY prezzo';
34+
$prezzo_min = $database->fetchOne($prezzo.' ASC');
35+
$prezzo_max = $database->fetchOne($prezzo.' DESC');
36+
37+
return [
38+
'media' => $prezzo_medio,
39+
'max' => $prezzo_max,
40+
'min' => $prezzo_min,
41+
];
42+
}
43+
}

0 commit comments

Comments
 (0)