Skip to content

Commit 946f062

Browse files
feat: bulk esportazione stampe viaggi automezzi
1 parent 356829c commit 946f062

4 files changed

Lines changed: 120 additions & 4 deletions

File tree

modules/automezzi/bulk.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 Models\Module;
24+
use Util\Zip;
25+
26+
switch (post('op')) {
27+
case 'export_bulk':
28+
$dir = base_dir().'/files/export_viaggi/';
29+
directory($dir.'tmp/');
30+
31+
// Rimozione dei contenuti precedenti
32+
$files = glob($dir.'/*.zip');
33+
foreach ($files as $file) {
34+
delete($file);
35+
}
36+
37+
// Selezione dei viaggi da stampare
38+
$viaggi = $dbo->fetchArray('SELECT id FROM an_sedi WHERE id IN('.implode(',', $id_records).')');
39+
$_SESSION[$id_module]['data_inizio'] = post('data_inizio');
40+
$_SESSION[$id_module]['data_fine'] = post('data_fine');
41+
42+
if (!empty($viaggi)) {
43+
foreach ($viaggi as $r) {
44+
$print = Prints::getModulePredefinedPrint($id_module);
45+
Prints::render($print['id'], $r['id'], $dir.'tmp/', false, false);
46+
}
47+
48+
$dir = slashes($dir);
49+
$file = slashes($dir.'viaggi_'.time().'.zip');
50+
51+
// Creazione zip
52+
if (extension_loaded('zip')) {
53+
Zip::create($dir.'tmp/', $file);
54+
55+
// Invio al browser dello zip
56+
download($file);
57+
58+
// Rimozione dei contenuti
59+
delete($dir.'tmp/');
60+
}
61+
}
62+
63+
break;
64+
}
65+
66+
$operations['export_bulk'] = [
67+
'text' => '<span><i class="fa fa-file-archive-o"></i> '.tr('Esporta viaggi'),
68+
'data' => [
69+
'title' => tr('Vuoi davvero esportare queste stampe viaggio in un archivio ZIP?'),
70+
'msg' => '{[ "type": "date", "label": "'.tr('Data inizio').'", "name": "data_inizio", "required": 1, "value": "-now-" ]}
71+
{[ "type": "date", "label": "'.tr('Data fine').'", "name": "data_fine", "required": 1, "value": "-now-" ]}',
72+
'button' => tr('Procedi'),
73+
'class' => 'btn btn-lg btn-warning',
74+
'blank' => true,
75+
],
76+
];
77+
78+
return $operations;

modules/automezzi/variables.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
$r = $dbo->fetchOne('
22+
SELECT
23+
`an_sedi`.*
24+
FROM
25+
`an_sedi`
26+
WHERE
27+
`an_sedi`.`id`='.prepare($id_record));
28+
29+
// Variabili da sostituire
30+
return [
31+
'nome' => $r['nome'],
32+
'targa' => $r['targa']
33+
];

templates/registro_viaggio/init.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
include_once __DIR__.'/../../core.php';
2222

2323
// Recupero parametri
24-
$data_inizio = filter('data_inizio');
25-
$data_fine = filter('data_fine');
24+
$data_inizio = filter('data_inizio') ?: $_SESSION[$id_module]['data_inizio'];
25+
$data_fine = filter('data_fine') ?: $_SESSION[$id_module]['data_fine'];
2626

2727
// Recupero dati automezzo
2828
$automezzo = $dbo->fetchOne('SELECT * FROM an_sedi WHERE id='.prepare($id_record));
@@ -37,8 +37,8 @@
3737
LEFT JOIN an_anagrafiche t ON v.idtecnico = t.idanagrafica
3838
WHERE
3939
v.idsede = '.prepare($id_record).'
40-
AND v.data_inizio >= '.prepare($data_inizio).'
41-
AND v.data_fine <= '.prepare($data_fine).'
40+
AND v.data_inizio >= '.prepare($data_inizio.' 00:00:00').'
41+
AND v.data_fine <= '.prepare($data_fine.' 23:59:59').'
4242
ORDER BY
4343
v.data_inizio ASC';
4444

update/2_10.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,8 @@ INSERT INTO `zz_settings` (`nome`, `valore`, `tipo`, `editable`, `sezione`) VALU
449449
INSERT INTO `zz_settings_lang` (`id_lang`, `id_record`, `title`, `help`) VALUES
450450
(1, (SELECT MAX(`id`) FROM `zz_settings`), 'Durata sessione (minuti)', ''),
451451
(2, (SELECT MAX(`id`) FROM `zz_settings`), 'Session duration (minutes)', '');
452+
453+
-- Fix stampa registro viaggi
454+
UPDATE `zz_prints` SET `predefined` = '1' WHERE `zz_prints`.`name` = 'Registro viaggio';
455+
UPDATE `zz_prints_lang` SET `filename` = 'Registro viaggio {nome} {targa}' WHERE `zz_prints_lang`.`title` = 'Registro viaggio';
456+
UPDATE `zz_prints_lang` SET `filename` = 'Travel register {nome} {targa}' WHERE `zz_prints_lang`.`title` = 'Travel register';

0 commit comments

Comments
 (0)