From 56c761cad99192d96dfe6a0420969ffa3c10ffc6 Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Mon, 20 Sep 2021 13:33:45 +0200 Subject: [PATCH] Abilitazione generale esportazione tramite Azioni di gruppo esistenti Abilitazione dell'esportazione tramite Azioni di gruppo esistenti per Articoli, Anagrafiche, Fatture e Impianti. Aggiunta formattazione automatica sulla base del tipo del campo per l'esportazione. --- modules/anagrafiche/bulk.php | 23 +++--- modules/articoli/bulk.php | 29 +++++++- modules/articoli/src/Export/CSV.php | 109 ++++++++++++++++++++++++++++ modules/fatture/bulk.php | 22 +++--- modules/impianti/bulk.php | 20 +++-- modules/interventi/bulk.php | 2 +- src/Exporter/CSVExporter.php | 8 +- 7 files changed, 175 insertions(+), 38 deletions(-) create mode 100644 modules/articoli/src/Export/CSV.php diff --git a/modules/anagrafiche/bulk.php b/modules/anagrafiche/bulk.php index 911b371f0..621bd19e1 100755 --- a/modules/anagrafiche/bulk.php +++ b/modules/anagrafiche/bulk.php @@ -83,25 +83,26 @@ $operations = []; if (App::debug()) { $operations['delete-bulk'] = [ - 'text' => ' '.tr('Elimina selezionati').' beta', + 'text' => ' '.tr('Elimina selezionati').' beta', 'data' => [ 'msg' => tr('Vuoi davvero eliminare le anagrafiche selezionate?'), 'button' => tr('Procedi'), 'class' => 'btn btn-lg btn-danger', ], ]; - - $operations['export-csv'] = [ - 'text' => ' '.tr('Esporta selezionati').' beta', - 'data' => [ - 'msg' => tr('Vuoi davvero esportare un CSV con le anagrafiche selezionate?'), - 'button' => tr('Procedi'), - 'class' => 'btn btn-lg btn-danger', - 'blank' => true, - ], - ]; } +$operations['export-csv'] = [ + 'text' => ' '.tr('Esporta selezionati').'', + 'data' => [ + 'msg' => tr('Vuoi esportare un CSV con le anagrafiche selezionate?'), + 'button' => tr('Procedi'), + 'class' => 'btn btn-lg btn-success', + 'blank' => true, + ], +]; + + if (App::debug() && $google) { $operations['ricerca-coordinate'] = [ 'text' => ' '.tr('Ricerca coordinate').'', diff --git a/modules/articoli/bulk.php b/modules/articoli/bulk.php index 1de91a947..b2e74bbb2 100644 --- a/modules/articoli/bulk.php +++ b/modules/articoli/bulk.php @@ -17,15 +17,15 @@ * along with this program. If not, see . */ -include_once __DIR__.'/../../core.php'; -use Modules; use Modules\Anagrafiche\Anagrafica; use Modules\Articoli\Articolo; +use Modules\Articoli\Export\CSV; use Modules\Preventivi\Components\Articolo as ArticoloPreventivo; use Modules\Preventivi\Preventivo; use Modules\TipiIntervento\Tipo as TipoSessione; use Plugins\ListinoClienti\DettaglioPrezzo; -use Prints; + +include_once __DIR__.'/../../core.php'; switch (post('op')) { case 'change-acquisto': @@ -154,6 +154,19 @@ switch (post('op')) { exit(); break; + + case 'export-csv': + $file = temp_file(); + $exporter = new CSV($file); + + // Esportazione dei record selezionati + $anagrafiche = Articolo::whereIn('id', $id_records)->get(); + $exporter->setRecords($anagrafiche); + + $count = $exporter->exportRecords(); + + download($file, 'articoli.csv'); + break; } if (App::debug()) { @@ -167,6 +180,16 @@ if (App::debug()) { ]; } +$operations['export-csv'] = [ + 'text' => ' '.tr('Esporta selezionati').'', + 'data' => [ + 'msg' => tr('Vuoi esportare un CSV con le anagrafiche selezionate?'), + 'button' => tr('Procedi'), + 'class' => 'btn btn-lg btn-success', + 'blank' => true, + ], +]; + $operations['change-acquisto'] = [ 'text' => ' '.tr('Aggiorna prezzo di acquisto').'', 'data' => [ diff --git a/modules/articoli/src/Export/CSV.php b/modules/articoli/src/Export/CSV.php new file mode 100644 index 000000000..92f55fed6 --- /dev/null +++ b/modules/articoli/src/Export/CSV.php @@ -0,0 +1,109 @@ +. + */ + +namespace Modules\Articoli\Export; + +use Exporter\CSVExporter; +use Modules\Anagrafiche\Anagrafica; +use Modules\Articoli\Articolo; + +/** + * Struttura per la gestione delle operazioni di esportazione (in CSV) degli Articoli. + * + * @since 2.4.26 + */ +class CSV extends CSVExporter +{ + public function getAvailableFields() + { + return [ + [ + 'field' => 'codice', + 'label' => 'Codice', + 'primary_key' => true, + ], + [ + 'field' => 'descrizione', + 'label' => 'Descrizione', + ], + [ + 'field' => 'qta', + 'label' => 'Quantità', + 'type' => 'number', + ], + [ + 'field' => 'um', + 'label' => 'Unità di misura', + ], + [ + 'field' => 'prezzo_acquisto', + 'label' => 'Prezzo acquisto', + 'type' => 'number', + ], + [ + 'field' => 'prezzo_vendita', + 'label' => 'Prezzo vendita', + 'type' => 'number', + ], + [ + 'field' => 'peso_lordo', + 'label' => 'Peso lordo (KG)', + 'type' => 'number', + ], + [ + 'field' => 'volume', + 'label' => 'Volume (M3)', + 'type' => 'number', + ], + [ + 'field' => 'categoria.nome', + 'label' => 'Categoria', + ], + [ + 'field' => 'sottocategoria.nome', + 'label' => 'Sottocategoria', + ], + [ + 'field' => 'barcode', + 'label' => 'Barcode', + ], + [ + 'field' => 'id_fornitore', + 'label' => 'Fornitore predefinito', + ], + [ + 'field' => 'codice_iva_vendita', + 'label' => 'Codice IVA vendita', + ], + [ + 'field' => 'ubicazione', + 'label' => 'Ubicazione', + ], + [ + 'field' => 'note', + 'label' => 'Note', + ], + ]; + } + + public function getRecords() + { + return Articolo::all(); + } +} diff --git a/modules/fatture/bulk.php b/modules/fatture/bulk.php index d44c16028..e7d736a3d 100755 --- a/modules/fatture/bulk.php +++ b/modules/fatture/bulk.php @@ -381,20 +381,20 @@ switch (post('op')) { if (App::debug()) { $operations['delete-bulk'] = [ - 'text' => ' '.tr('Elimina selezionati').' beta', - ]; - - $operations['export-csv'] = [ - 'text' => ' '.tr('Esporta selezionati').' beta', - 'data' => [ - 'msg' => tr('Vuoi davvero esportare un CSV con le fatture selezionate?'), - 'button' => tr('Procedi'), - 'class' => 'btn btn-lg btn-danger', - 'blank' => true, - ], + 'text' => ' '.tr('Elimina selezionati').' beta', ]; } +$operations['export-csv'] = [ + 'text' => ' '.tr('Esporta selezionati').'', + 'data' => [ + 'msg' => tr('Vuoi esportare un CSV con le fatture selezionate?'), + 'button' => tr('Procedi'), + 'class' => 'btn btn-lg btn-success', + 'blank' => true, + ], +]; + $operations['copy-bulk'] = [ 'text' => ' '.tr('Duplica selezionati').'', 'data' => [ diff --git a/modules/impianti/bulk.php b/modules/impianti/bulk.php index 19727cca5..199f0b1ba 100644 --- a/modules/impianti/bulk.php +++ b/modules/impianti/bulk.php @@ -38,16 +38,14 @@ switch (post('op')) { break; } -if (App::debug()) { - $operations['export-csv'] = [ - 'text' => ' '.tr('Esporta selezionati').' beta', - 'data' => [ - 'msg' => tr('Vuoi davvero esportare un CSV con tutti gli impianti?'), - 'button' => tr('Procedi'), - 'class' => 'btn btn-lg btn-danger', - 'blank' => true, - ], - ]; -} +$operations['export-csv'] = [ + 'text' => ' '.tr('Esporta selezionati').'', + 'data' => [ + 'msg' => tr('Vuoi esportare un CSV con tutti gli impianti?'), + 'button' => tr('Procedi'), + 'class' => 'btn btn-lg btn-success', + 'blank' => true, + ], +]; return $operations; diff --git a/modules/interventi/bulk.php b/modules/interventi/bulk.php index 28ed16c65..fc5d1cf41 100755 --- a/modules/interventi/bulk.php +++ b/modules/interventi/bulk.php @@ -249,7 +249,7 @@ switch (post('op')) { if (App::debug()) { $operations['delete-bulk'] = [ - 'text' => ' '.tr('Elimina selezionati').' beta', + 'text' => ' '.tr('Elimina selezionati').' beta', ]; } diff --git a/src/Exporter/CSVExporter.php b/src/Exporter/CSVExporter.php index 26ef16bfe..fa0d89a23 100644 --- a/src/Exporter/CSVExporter.php +++ b/src/Exporter/CSVExporter.php @@ -89,7 +89,13 @@ abstract class CSVExporter implements ExporterInterface $dot_notation = explode('.', $nome); $contenuto = $record; foreach ($dot_notation as $segment) { - $contenuto = isset($contenuto[$segment]) ? $contenuto[$segment] : null; + $contenuto = $contenuto[$segment] ?? null; + } + + // Formattazione automatica del campo + $type = $field['type'] ?? 'string'; + if ($type == 'number') { + $contenuto = numberFormat($contenuto); } $row[] = $contenuto;