Introduzione esportazione CSV anagrafiche e fatture

This commit is contained in:
Luca 2020-11-24 17:25:07 +01:00
parent dbddb460bb
commit dff6d65952
5 changed files with 165 additions and 15 deletions

View File

@ -63,19 +63,51 @@ switch (post('op')) {
}
break;
case 'download-csv':
$dir = base_dir().'/files/export_anagrafiche/';
directory($dir.'tmp/');
$file = secure_random_string().'.csv';
$dir_csv = slashes($dir.'tmp/'.$file);
$filename = 'anagrafiche.csv';
$t = new Modules\Anagrafiche\Export\CSV($dir_csv);
if($t->exportRecords()){
download($dir_csv, $filename);
delete($dir.'tmp/');
}
break;
}
$operations = [];
if (App::debug()) {
$operations['delete-bulk'] = [
'text' => '<span><i class="fa fa-trash"></i> '.tr('Elimina selezionati').'</span>',
'text' => '<span><i class="fa fa-trash"></i> '.tr('Elimina selezionati').'</span> <span class="label label-danger" >beta</span>',
'data' => [
'msg' => tr('Vuoi davvero eliminare le anagrafiche selezionate?'),
'button' => tr('Procedi'),
'class' => 'btn btn-lg btn-danger',
],
];
$operations['download-csv'] = [
'text' => '<span><i class="fa fa-download"></i> '.tr('Esporta tutto').'</span> <span class="label label-danger" >beta</span>',
'data' => [
'msg' => tr('Vuoi davvero esportare un CSV con tutte le anagrafiche?'),
'button' => tr('Procedi'),
'class' => 'btn btn-lg btn-danger',
'blank' => true,
],
];
}
if (App::debug() && $google) {

View File

@ -442,6 +442,24 @@ switch (post('op')) {
}
break;
case 'download-csv':
$dir = base_dir().'/files/export_fatture/';
directory($dir.'tmp/');
$file = secure_random_string().'.csv';
$dir_csv = slashes($dir.'tmp/'.$file);
$filename = 'fatture.csv';
$t = new Modules\Fatture\Export\CSV($dir_csv);
if($t->exportRecords()){
download($dir_csv, $filename);
delete($dir.'tmp/');
}
break;
case 'delete-bulk':
foreach ($id_records as $id) {
@ -458,8 +476,19 @@ switch (post('op')) {
if (App::debug()) {
$operations['delete-bulk'] = [
'text' => '<span><i class="fa fa-trash"></i> '.tr('Elimina selezionati').'</span>',
'text' => '<span><i class="fa fa-trash"></i> '.tr('Elimina selezionati').'</span> <span class="label label-danger" >beta</span>',
];
$operations['download-csv'] = [
'text' => '<span><i class="fa fa-download"></i> '.tr('Esporta tutto').'</span> <span class="label label-danger" >beta</span>',
'data' => [
'msg' => tr('Vuoi davvero esportare un CSV con tutte le fatture?'),
'button' => tr('Procedi'),
'class' => 'btn btn-lg btn-danger',
'blank' => true,
],
];
}
$operations['copy-bulk'] = [

View File

@ -0,0 +1,76 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.n.c.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 <https://www.gnu.org/licenses/>.
*/
namespace Modules\Fatture\Export;
use Exporter\CSVExporter;
use Modules\Fatture\Fattura;
/**
* Struttura per la gestione delle operazioni di esportazione (in CSV) delle Fatture.
*
* @since 2.4.18
*/
class CSV extends CSVExporter
{
public function getAvailableFields()
{
return [
[
'field' => 'id',
'label' => 'ID',
'primary_key' => true,
],
[
'field' => 'numero_esterno',
'label' => 'Numero',
],
[
'field' => 'data',
'label' => 'Data',
],
[
'field' => 'idanagrafica',
'label' => 'Ragione sociale',
],
[
'field' => 'totale',
'label' => 'Totale',
],
[
'field' => 'idstatodocumento',
'label' => 'Stato',
],
[
'field' => 'codice_stato_fe',
'label' => 'Stato FE',
],
];
}
public function getRecords()
{
$id_module = filter('id_module');
$results = Fattura::all()->where('id_segment', $_SESSION['module_'.$id_module]['id_segment']);
return $results;
}
}

View File

@ -18,32 +18,41 @@
*/
include_once __DIR__.'/../../core.php';
use Modules\Impianti\Impianto;
switch (post('op')) {
case 'download-csv':
$dir = base_dir().'/files/export_impianti/';
directory($dir.'tmp/');
$file = secure_random_string().'.csv';
$dir_csv = slashes($dir.'tmp/'.$file);
case 'export-bulk':
$filename = 'impianti.csv';
$t = new Modules\Impianti\Export\CSV(__DIR__.'\..\..\files\impianti\Impianti.csv');
if($t->exportRecords())
flash()->info(tr('Esportazione riuscita!'));
$t = new Modules\Impianti\Export\CSV($dir_csv);
if($t->exportRecords()){
download($dir_csv, $filename);
delete($dir.'tmp/');
}
break;
}
if (App::debug()) {
$operations['export-bulk'] = [
'text' => '<span><i class="fa fa-upload"></i> '.tr('Esporta tutto').'</span>',
$operations['download-csv'] = [
'text' => '<span><i class="fa fa-download"></i> '.tr('Esporta tutto').'</span> <span class="label label-danger" >beta</span>',
'data' => [
'msg' => tr('Vuoi davvero esportare un CSV degli impianti?'),
'msg' => tr('Vuoi davvero esportare un CSV con tutti gli impianti?'),
'button' => tr('Procedi'),
'class' => 'btn btn-lg btn-danger',
'blank' => true,
],
];
}
return $operations;
return $operations;

View File

@ -23,7 +23,7 @@ use Exporter\CSVExporter;
use Modules\Impianti\Impianto;
/**
* Struttura per la gestione delle operazioni di esportazione (in CSV) delle Impianti.
* Struttura per la gestione delle operazioni di esportazione (in CSV) degli impianti.
*
* @since 2.4.18
*/
@ -32,10 +32,14 @@ class CSV extends CSVExporter
public function getAvailableFields()
{
return [
[
'field' => 'id',
'label' => 'ID',
'primary_key' => true,
],
[
'field' => 'matricola',
'label' => 'Matricola',
'primary_key' => true,
],
[
'field' => 'nome',