mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-16 19:40:44 +01:00
Correzionu sull'esportazione CSV da azioni di gruppo
This commit is contained in:
parent
eff17804e5
commit
c82165e6fa
@ -17,8 +17,8 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Util\FileSystem;
|
|
||||||
use Models\Cache;
|
use Models\Cache;
|
||||||
|
use Util\FileSystem;
|
||||||
|
|
||||||
include_once __DIR__.'/../core.php';
|
include_once __DIR__.'/../core.php';
|
||||||
|
|
||||||
@ -578,7 +578,6 @@ if (!Auth::check() && (!empty($messages['info']) || !empty($messages['warning'])
|
|||||||
$osm_size = Cache::pool('Spazio utilizzato')->content;
|
$osm_size = Cache::pool('Spazio utilizzato')->content;
|
||||||
|
|
||||||
if (!empty(setting('Soft quota')) && !empty($osm_size)) {
|
if (!empty(setting('Soft quota')) && !empty($osm_size)) {
|
||||||
|
|
||||||
// Controllo lo spazio disponibile
|
// Controllo lo spazio disponibile
|
||||||
//$osm_size = disk_free_space('.');
|
//$osm_size = disk_free_space('.');
|
||||||
//$osm_size = FileSystem::folderSize(base_dir(), ['htaccess']);
|
//$osm_size = FileSystem::folderSize(base_dir(), ['htaccess']);
|
||||||
|
30
lib/util.php
30
lib/util.php
@ -528,3 +528,33 @@ if (!function_exists('readSQLFile')) {
|
|||||||
return $queryLine;
|
return $queryLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!function_exists('temp_file')) {
|
||||||
|
/**
|
||||||
|
* Crea un file temporaneo e lo imposta per la rimozione alla fine dell'esecuzione.
|
||||||
|
*
|
||||||
|
* @param $name
|
||||||
|
* @param $content
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function temp_file($name = null, $content = null)
|
||||||
|
{
|
||||||
|
if (empty($name)) {
|
||||||
|
$name = secure_random_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = DIRECTORY_SEPARATOR.
|
||||||
|
trim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).
|
||||||
|
DIRECTORY_SEPARATOR.
|
||||||
|
ltrim($name, DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
|
file_put_contents($file, $content);
|
||||||
|
|
||||||
|
register_shutdown_function(function () use ($file) {
|
||||||
|
unlink($file);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -91,7 +91,6 @@ if (!function_exists('base_dir')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Aggiornamenti
|
// Aggiornamenti
|
||||||
if (setting('Attiva aggiornamenti')) {
|
if (setting('Attiva aggiornamenti')) {
|
||||||
$alerts = [];
|
$alerts = [];
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
use Geocoder\Provider\GoogleMaps;
|
use Geocoder\Provider\GoogleMaps;
|
||||||
use Ivory\HttpAdapter\CurlHttpAdapter;
|
use Ivory\HttpAdapter\CurlHttpAdapter;
|
||||||
use Modules\Anagrafiche\Anagrafica;
|
use Modules\Anagrafiche\Anagrafica;
|
||||||
|
use Modules\Anagrafiche\Export\CSV;
|
||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
$google = setting('Google Maps API key');
|
$google = setting('Google Maps API key');
|
||||||
@ -64,26 +65,18 @@ switch (post('op')) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'export-csv':
|
||||||
|
$file = temp_file();
|
||||||
|
$exporter = new CSV($file);
|
||||||
|
|
||||||
case 'download-csv':
|
// Esportazione dei record selezionati
|
||||||
|
$anagrafiche = Anagrafica::whereIn('id', $id_records)->get();
|
||||||
|
$exporter->setRecords($anagrafiche);
|
||||||
|
|
||||||
$dir = base_dir().'/files/export_anagrafiche/';
|
$count = $exporter->exportRecords();
|
||||||
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/');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
download($file, 'anagrafiche.csv');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$operations = [];
|
$operations = [];
|
||||||
@ -98,8 +91,8 @@ if (App::debug()) {
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$operations['download-csv'] = [
|
$operations['export-csv'] = [
|
||||||
'text' => '<span><i class="fa fa-download"></i> '.tr('Esporta tutto').'</span> <span class="label label-danger" >beta</span>',
|
'text' => '<span><i class="fa fa-download"></i> '.tr('Esporta selezionati').'</span> <span class="label label-danger" >beta</span>',
|
||||||
'data' => [
|
'data' => [
|
||||||
'msg' => tr('Vuoi davvero esportare un CSV con tutte le anagrafiche?'),
|
'msg' => tr('Vuoi davvero esportare un CSV con tutte le anagrafiche?'),
|
||||||
'button' => tr('Procedi'),
|
'button' => tr('Procedi'),
|
||||||
@ -107,7 +100,6 @@ if (App::debug()) {
|
|||||||
'blank' => true,
|
'blank' => true,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (App::debug() && $google) {
|
if (App::debug() && $google) {
|
||||||
|
@ -114,7 +114,7 @@ class CSV extends CSVExporter
|
|||||||
'label' => 'Note',
|
'label' => 'Note',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'field' => 'id_nazione',
|
'field' => 'nazione.nome',
|
||||||
'label' => 'Nazione',
|
'label' => 'Nazione',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
@ -36,7 +36,6 @@ switch (post('op')) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'delete-bulk':
|
case 'delete-bulk':
|
||||||
|
|
||||||
foreach ($id_records as $id) {
|
foreach ($id_records as $id) {
|
||||||
$elementi = $dbo->fetchArray('SELECT `co_documenti`.`id`, `co_documenti`.`data`, `co_documenti`.`numero`, `co_documenti`.`numero_esterno`, `co_tipidocumento`.`descrizione` AS tipo_documento, `co_tipidocumento`.`dir` FROM `co_documenti` JOIN `co_tipidocumento` ON `co_tipidocumento`.`id` = `co_documenti`.`idtipodocumento` WHERE `co_documenti`.`id` IN (SELECT `iddocumento` FROM `co_righe_documenti` WHERE `idarticolo` = '.prepare($id).')
|
$elementi = $dbo->fetchArray('SELECT `co_documenti`.`id`, `co_documenti`.`data`, `co_documenti`.`numero`, `co_documenti`.`numero_esterno`, `co_tipidocumento`.`descrizione` AS tipo_documento, `co_tipidocumento`.`dir` FROM `co_documenti` JOIN `co_tipidocumento` ON `co_tipidocumento`.`id` = `co_documenti`.`idtipodocumento` WHERE `co_documenti`.`id` IN (SELECT `iddocumento` FROM `co_righe_documenti` WHERE `idarticolo` = '.prepare($id).')
|
||||||
|
|
||||||
|
@ -19,11 +19,12 @@
|
|||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
|
use Modules\Fatture\Export\CSV;
|
||||||
use Modules\Fatture\Fattura;
|
use Modules\Fatture\Fattura;
|
||||||
use Modules\Fatture\Stato;
|
use Modules\Fatture\Stato;
|
||||||
use Plugins\ExportFE\FatturaElettronica;
|
use Plugins\ExportFE\FatturaElettronica;
|
||||||
use Util\XML;
|
|
||||||
use Plugins\ExportFE\Interaction;
|
use Plugins\ExportFE\Interaction;
|
||||||
|
use Util\XML;
|
||||||
use Util\Zip;
|
use Util\Zip;
|
||||||
|
|
||||||
switch (post('op')) {
|
switch (post('op')) {
|
||||||
@ -281,7 +282,6 @@ switch (post('op')) {
|
|||||||
$anomalie = collect();
|
$anomalie = collect();
|
||||||
|
|
||||||
foreach ($id_records as $id) {
|
foreach ($id_records as $id) {
|
||||||
|
|
||||||
$fattura_vendita = Fattura::vendita()
|
$fattura_vendita = Fattura::vendita()
|
||||||
->whereNotIn('codice_stato_fe', ['ERR', 'NS', 'EC02', 'ERVAL'])
|
->whereNotIn('codice_stato_fe', ['ERR', 'NS', 'EC02', 'ERVAL'])
|
||||||
->where('data', '>=', $_SESSION['period_start'])
|
->where('data', '>=', $_SESSION['period_start'])
|
||||||
@ -294,7 +294,6 @@ switch (post('op')) {
|
|||||||
|
|
||||||
if (!empty($fattura_vendita)) {
|
if (!empty($fattura_vendita)) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$xml = XML::read($fattura_vendita->getXML());
|
$xml = XML::read($fattura_vendita->getXML());
|
||||||
|
|
||||||
$totale_documento_xml = null;
|
$totale_documento_xml = null;
|
||||||
@ -326,7 +325,6 @@ switch (post('op')) {
|
|||||||
|
|
||||||
// Se riscontro un'anomalia
|
// Se riscontro un'anomalia
|
||||||
if ($fattura_vendita->anagrafica->piva != $xml['FatturaElettronicaHeader']['CessionarioCommittente']['DatiAnagrafici']['IdFiscaleIVA']['IdCodice'] || $fattura_vendita->anagrafica->codice_fiscale != $xml['FatturaElettronicaHeader']['CessionarioCommittente']['DatiAnagrafici']['CodiceFiscale'] || $fattura_vendita->totale != $totale_documento_xml) {
|
if ($fattura_vendita->anagrafica->piva != $xml['FatturaElettronicaHeader']['CessionarioCommittente']['DatiAnagrafici']['IdFiscaleIVA']['IdCodice'] || $fattura_vendita->anagrafica->codice_fiscale != $xml['FatturaElettronicaHeader']['CessionarioCommittente']['DatiAnagrafici']['CodiceFiscale'] || $fattura_vendita->totale != $totale_documento_xml) {
|
||||||
|
|
||||||
/*echo json_encode([
|
/*echo json_encode([
|
||||||
'totale_documento_xml' => $totale_documento_xml,
|
'totale_documento_xml' => $totale_documento_xml,
|
||||||
'totale_documento' => $totale_documento,
|
'totale_documento' => $totale_documento,
|
||||||
@ -341,17 +339,13 @@ switch (post('op')) {
|
|||||||
'totale_documento_xml' => moneyFormat($totale_documento_xml, 2),
|
'totale_documento_xml' => moneyFormat($totale_documento_xml, 2),
|
||||||
'totale_documento' => moneyFormat($fattura_vendita->totale, 2),
|
'totale_documento' => moneyFormat($fattura_vendita->totale, 2),
|
||||||
'have_xml' => 1,
|
'have_xml' => 1,
|
||||||
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|
||||||
$anomalie->push([
|
$anomalie->push([
|
||||||
'fattura_vendita' => $fattura_vendita,
|
'fattura_vendita' => $fattura_vendita,
|
||||||
'have_xml' => 0,
|
'have_xml' => 0,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
array_push($list, $fattura_vendita->numero_esterno);
|
array_push($list, $fattura_vendita->numero_esterno);
|
||||||
@ -360,20 +354,17 @@ switch (post('op')) {
|
|||||||
|
|
||||||
// Messaggi di risposta
|
// Messaggi di risposta
|
||||||
if (empty($list)) {
|
if (empty($list)) {
|
||||||
|
|
||||||
flash()->warning(tr('Nessuna fattura utile per il controllo!'));
|
flash()->warning(tr('Nessuna fattura utile per il controllo!'));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
flash()->info(tr('Fatture _LIST_ controllate.', [
|
flash()->info(tr('Fatture _LIST_ controllate.', [
|
||||||
'_LIST_' => implode(',', $list),
|
'_LIST_' => implode(',', $list),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
// Se ci sono anomalie
|
// Se ci sono anomalie
|
||||||
if ($anomalie->count() > 0) {
|
if ($anomalie->count() > 0) {
|
||||||
|
function diff($old, $new)
|
||||||
function diff($old, $new){
|
{
|
||||||
$matrix = array();
|
$matrix = [];
|
||||||
$maxlen = 0;
|
$maxlen = 0;
|
||||||
foreach ($old as $oindex => $ovalue) {
|
foreach ($old as $oindex => $ovalue) {
|
||||||
$nkeys = array_keys($new, $ovalue);
|
$nkeys = array_keys($new, $ovalue);
|
||||||
@ -387,77 +378,69 @@ switch (post('op')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new));
|
if ($maxlen == 0) {
|
||||||
|
return [['d' => $old, 'i' => $new]];
|
||||||
|
}
|
||||||
|
|
||||||
return array_merge(
|
return array_merge(
|
||||||
diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)),
|
diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)),
|
||||||
array_slice($new, $nmax, $maxlen),
|
array_slice($new, $nmax, $maxlen),
|
||||||
diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)));
|
diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function htmlDiff($old, $new){
|
function htmlDiff($old, $new)
|
||||||
|
{
|
||||||
$ret = '';
|
$ret = '';
|
||||||
$diff = diff(preg_split("/[\s]+/", $old), preg_split("/[\s]+/", $new));
|
$diff = diff(preg_split("/[\s]+/", $old), preg_split("/[\s]+/", $new));
|
||||||
foreach ($diff as $k) {
|
foreach ($diff as $k) {
|
||||||
if(is_array($k))
|
if (is_array($k)) {
|
||||||
$ret .= (!empty($k['d'])?"<del>".implode(' ',$k['d'])."</del> ":'').
|
$ret .= (!empty($k['d']) ? '<del>'.implode(' ', $k['d']).'</del> ' : '').
|
||||||
(!empty($k['i'])?"<span>".implode(' ',$k['i'])."</span> ":'');
|
(!empty($k['i']) ? '<span>'.implode(' ', $k['i']).'</span> ' : '');
|
||||||
else $ret .= $k . ' ';
|
} else {
|
||||||
|
$ret .= $k.' ';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
$riepilogo_anomalie .= tr('Attenzione: Trovate _NUM_ anomalie! Le seguenti fatture non trovano corrispondenza tra XML e dati nel documento:', ['_NUM_' => $anomalie->count()]).' </br></br>';
|
$riepilogo_anomalie .= tr('Attenzione: Trovate _NUM_ anomalie! Le seguenti fatture non trovano corrispondenza tra XML e dati nel documento:', ['_NUM_' => $anomalie->count()]).' </br></br>';
|
||||||
|
|
||||||
|
|
||||||
foreach ($anomalie as $anomalia) {
|
foreach ($anomalie as $anomalia) {
|
||||||
|
|
||||||
$riepilogo_anomalie .= '<ul><li>'.reference($anomalia['fattura_vendita'], $anomalia['fattura_vendita']->getReference()).'</li>';
|
$riepilogo_anomalie .= '<ul><li>'.reference($anomalia['fattura_vendita'], $anomalia['fattura_vendita']->getReference()).'</li>';
|
||||||
|
|
||||||
if (!empty($anomalia['have_xml'])) {
|
if (!empty($anomalia['have_xml'])) {
|
||||||
|
|
||||||
$riepilogo_anomalie .= '<li><table class="table table-bordered table-condensed">
|
$riepilogo_anomalie .= '<li><table class="table table-bordered table-condensed">
|
||||||
<tr><th>Sorgente</th><th>P. Iva</th><th>Cod. fiscale</th><th>Totale</th></tr>';
|
<tr><th>Sorgente</th><th>P. Iva</th><th>Cod. fiscale</th><th>Totale</th></tr>';
|
||||||
|
|
||||||
$riepilogo_anomalie .= '<tr><td>XML</td> <td>'.$anomalia['piva_xml'].'</td> <td>'.$anomalia['codice_fiscale_xml'].'</td> <td>'.$anomalia['totale_documento_xml'].'</td></tr>';
|
$riepilogo_anomalie .= '<tr><td>XML</td> <td>'.$anomalia['piva_xml'].'</td> <td>'.$anomalia['codice_fiscale_xml'].'</td> <td>'.$anomalia['totale_documento_xml'].'</td></tr>';
|
||||||
|
|
||||||
$riepilogo_anomalie .= '<tr><td>Gestionale</td> <td>'.htmlDiff($anomalia['piva_xml'], $anomalia['piva']).'</td> <td>'.htmlDiff($anomalia['codice_fiscale_xml'], $anomalia['codice_fiscale']).'</td> <td>'.htmlDiff($anomalia['totale_documento_xml'], $anomalia['totale_documento']).'</td></tr></table></li>';
|
$riepilogo_anomalie .= '<tr><td>Gestionale</td> <td>'.htmlDiff($anomalia['piva_xml'], $anomalia['piva']).'</td> <td>'.htmlDiff($anomalia['codice_fiscale_xml'], $anomalia['codice_fiscale']).'</td> <td>'.htmlDiff($anomalia['totale_documento_xml'], $anomalia['totale_documento']).'</td></tr></table></li>';
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$riepilogo_anomalie .= ' <li>'.tr('Impossibile verificare l\'XML di questa fattura.').'</li>';
|
$riepilogo_anomalie .= ' <li>'.tr('Impossibile verificare l\'XML di questa fattura.').'</li>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$riepilogo_anomalie .= '</ul><br>';
|
$riepilogo_anomalie .= '</ul><br>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flash()->warning($riepilogo_anomalie);
|
flash()->warning($riepilogo_anomalie);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
flash()->info(tr('Nessuna anomalia!'));
|
flash()->info(tr('Nessuna anomalia!'));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'download-csv':
|
case 'export-csv':
|
||||||
|
$file = temp_file();
|
||||||
|
$exporter = new CSV($file);
|
||||||
|
|
||||||
$dir = base_dir().'/files/export_fatture/';
|
// Esportazione dei record selezionati
|
||||||
directory($dir.'tmp/');
|
$fatture = Fattura::whereIn('id', $id_records)->get();
|
||||||
$file = secure_random_string().'.csv';
|
$exporter->setRecords($fatture);
|
||||||
$dir_csv = slashes($dir.'tmp/'.$file);
|
|
||||||
|
|
||||||
$filename = 'fatture.csv';
|
$count = $exporter->exportRecords();
|
||||||
|
|
||||||
$t = new Modules\Fatture\Export\CSV($dir_csv);
|
download($file, 'fatture.csv');
|
||||||
|
|
||||||
if($t->exportRecords()){
|
|
||||||
|
|
||||||
download($dir_csv, $filename);
|
|
||||||
delete($dir.'tmp/');
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -479,8 +462,8 @@ if (App::debug()) {
|
|||||||
'text' => '<span><i class="fa fa-trash"></i> '.tr('Elimina selezionati').'</span> <span class="label label-danger" >beta</span>',
|
'text' => '<span><i class="fa fa-trash"></i> '.tr('Elimina selezionati').'</span> <span class="label label-danger" >beta</span>',
|
||||||
];
|
];
|
||||||
|
|
||||||
$operations['download-csv'] = [
|
$operations['export-csv'] = [
|
||||||
'text' => '<span><i class="fa fa-download"></i> '.tr('Esporta tutto').'</span> <span class="label label-danger" >beta</span>',
|
'text' => '<span><i class="fa fa-download"></i> '.tr('Esporta selezionati').'</span> <span class="label label-danger" >beta</span>',
|
||||||
'data' => [
|
'data' => [
|
||||||
'msg' => tr('Vuoi davvero esportare un CSV con tutte le fatture?'),
|
'msg' => tr('Vuoi davvero esportare un CSV con tutte le fatture?'),
|
||||||
'button' => tr('Procedi'),
|
'button' => tr('Procedi'),
|
||||||
@ -488,7 +471,6 @@ if (App::debug()) {
|
|||||||
'blank' => true,
|
'blank' => true,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$operations['copy-bulk'] = [
|
$operations['copy-bulk'] = [
|
||||||
@ -543,7 +525,6 @@ if ($module->name == 'Fatture di vendita') {
|
|||||||
'blank' => true,
|
'blank' => true,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$operations['export-xml-bulk'] = [
|
$operations['export-xml-bulk'] = [
|
||||||
|
@ -46,7 +46,7 @@ class CSV extends CSVExporter
|
|||||||
'label' => 'Data',
|
'label' => 'Data',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'field' => 'idanagrafica',
|
'field' => 'anagrafica.ragione_sociale',
|
||||||
'label' => 'Ragione sociale',
|
'label' => 'Ragione sociale',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -54,7 +54,7 @@ class CSV extends CSVExporter
|
|||||||
'label' => 'Totale',
|
'label' => 'Totale',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'field' => 'idstatodocumento',
|
'field' => 'stato.descrizione',
|
||||||
'label' => 'Stato',
|
'label' => 'Stato',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -66,11 +66,6 @@ class CSV extends CSVExporter
|
|||||||
|
|
||||||
public function getRecords()
|
public function getRecords()
|
||||||
{
|
{
|
||||||
|
return Fattura::all();
|
||||||
$id_module = filter('id_module');
|
|
||||||
$results = Fattura::all()->where('id_segment', $_SESSION['module_'.$id_module]['id_segment']);
|
|
||||||
|
|
||||||
return $results;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,35 +17,30 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
use Modules\Impianti\Export\CSV;
|
||||||
|
|
||||||
use Modules\Impianti\Impianto;
|
use Modules\Impianti\Impianto;
|
||||||
|
|
||||||
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
switch (post('op')) {
|
switch (post('op')) {
|
||||||
|
case 'export-csv':
|
||||||
|
$file = temp_file();
|
||||||
|
$exporter = new CSV($file);
|
||||||
|
|
||||||
case 'download-csv':
|
// Esportazione dei record selezionati
|
||||||
|
$fatture = Impianto::whereIn('id', $id_records)->get();
|
||||||
|
$exporter->setRecords($fatture);
|
||||||
|
|
||||||
$dir = base_dir().'/files/export_impianti/';
|
$count = $exporter->exportRecords();
|
||||||
directory($dir.'tmp/');
|
|
||||||
$file = secure_random_string().'.csv';
|
|
||||||
$dir_csv = slashes($dir.'tmp/'.$file);
|
|
||||||
|
|
||||||
$filename = 'impianti.csv';
|
download($file, 'impianti.csv');
|
||||||
|
|
||||||
$t = new Modules\Impianti\Export\CSV($dir_csv);
|
|
||||||
|
|
||||||
if($t->exportRecords()){
|
|
||||||
|
|
||||||
download($dir_csv, $filename);
|
|
||||||
delete($dir.'tmp/');
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (App::debug()) {
|
if (App::debug()) {
|
||||||
$operations['download-csv'] = [
|
$operations['export-csv'] = [
|
||||||
'text' => '<span><i class="fa fa-download"></i> '.tr('Esporta tutto').'</span> <span class="label label-danger" >beta</span>',
|
'text' => '<span><i class="fa fa-download"></i> '.tr('Esporta selezionati').'</span> <span class="label label-danger" >beta</span>',
|
||||||
'data' => [
|
'data' => [
|
||||||
'msg' => tr('Vuoi davvero esportare un CSV con tutti gli impianti?'),
|
'msg' => tr('Vuoi davvero esportare un CSV con tutti gli impianti?'),
|
||||||
'button' => tr('Procedi'),
|
'button' => tr('Procedi'),
|
||||||
|
@ -19,16 +19,14 @@
|
|||||||
|
|
||||||
namespace Modules\StatoServizi;
|
namespace Modules\StatoServizi;
|
||||||
|
|
||||||
use Util\FileSystem;
|
|
||||||
use Hooks\CachedManager;
|
use Hooks\CachedManager;
|
||||||
|
use Util\FileSystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook dedicato all'individuazione di nuove versioni del gestionale, pubblicate sulla repository ufficiale di GitHub.
|
* Hook dedicato all'individuazione di nuove versioni del gestionale, pubblicate sulla repository ufficiale di GitHub.
|
||||||
*/
|
*/
|
||||||
class SpaceHook extends CachedManager
|
class SpaceHook extends CachedManager
|
||||||
{
|
{
|
||||||
|
|
||||||
public function getCacheName()
|
public function getCacheName()
|
||||||
{
|
{
|
||||||
return 'Spazio utilizzato';
|
return 'Spazio utilizzato';
|
||||||
@ -46,10 +44,9 @@ class SpaceHook extends CachedManager
|
|||||||
$soft_quota = setting('Soft quota'); //MB
|
$soft_quota = setting('Soft quota'); //MB
|
||||||
$space_limit = ($soft_quota / 100) * 95; //MB
|
$space_limit = ($soft_quota / 100) * 95; //MB
|
||||||
|
|
||||||
$message = tr("Attenzione: occupati _TOT_ dei _SOFTQUOTA_ previsti", [
|
$message = tr('Attenzione: occupati _TOT_ dei _SOFTQUOTA_ previsti', [
|
||||||
'_TOT_' => FileSystem::formatBytes($osm_size),
|
'_TOT_' => FileSystem::formatBytes($osm_size),
|
||||||
'_SOFTQUOTA_' => FileSystem::formatBytes($soft_quota * 1048576),
|
'_SOFTQUOTA_' => FileSystem::formatBytes($soft_quota * 1048576),
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@ -66,17 +63,12 @@ class SpaceHook extends CachedManager
|
|||||||
*/
|
*/
|
||||||
public static function isAvailable()
|
public static function isAvailable()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!empty(setting('Soft quota'))) {
|
if (!empty(setting('Soft quota'))) {
|
||||||
|
|
||||||
$osm_size = FileSystem::folderSize(base_dir(), ['htaccess']);
|
$osm_size = FileSystem::folderSize(base_dir(), ['htaccess']);
|
||||||
|
|
||||||
return $osm_size;
|
return $osm_size;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,10 @@ abstract class CSVExporter implements ExporterInterface
|
|||||||
|
|
||||||
public function exportRecords()
|
public function exportRecords()
|
||||||
{
|
{
|
||||||
|
// Esportazione header
|
||||||
|
$fields = $this->getAvailableFields();
|
||||||
|
$this->csv->insertOne(array_column($fields, 'label'));
|
||||||
|
|
||||||
$records = $this->records ?: $this->getRecords();
|
$records = $this->records ?: $this->getRecords();
|
||||||
foreach ($records as $record) {
|
foreach ($records as $record) {
|
||||||
// Esportazione del record
|
// Esportazione del record
|
||||||
@ -81,7 +85,14 @@ abstract class CSVExporter implements ExporterInterface
|
|||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$nome = $field['field'];
|
$nome = $field['field'];
|
||||||
|
|
||||||
$row[] = $record[$nome];
|
// Navigazione secondo dot notation
|
||||||
|
$dot_notation = explode('.', $nome);
|
||||||
|
$contenuto = $record;
|
||||||
|
foreach ($dot_notation as $segment) {
|
||||||
|
$contenuto = isset($contenuto[$segment]) ? $contenuto[$segment] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$row[] = $contenuto;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->csv->insertOne($row);
|
return $this->csv->insertOne($row);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user