2017-09-06 11:59:47 +02:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* 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 />.
*/
2017-09-06 11:59:47 +02:00
include_once __DIR__ . '/../../core.php' ;
2019-03-07 17:16:42 +01:00
use Modules\Fatture\Fattura ;
2020-07-24 10:02:58 +02:00
use Modules\Fatture\Stato ;
2019-06-13 15:57:55 +02:00
use Plugins\ExportFE\FatturaElettronica ;
2020-11-21 03:16:59 +01:00
use Util\XML ;
2019-08-29 16:01:49 +02:00
use Plugins\ExportFE\Interaction ;
2019-06-29 11:01:26 +02:00
use Util\Zip ;
2018-09-19 16:51:37 +02:00
2017-09-06 11:59:47 +02:00
switch ( post ( 'op' )) {
case 'export-bulk' :
2020-09-23 13:36:37 +02:00
$dir = base_dir () . '/files/export_fatture/' ;
2017-09-13 15:38:47 +02:00
directory ( $dir . 'tmp/' );
2017-09-06 11:59:47 +02:00
2019-03-07 17:16:42 +01:00
$dir = slashes ( $dir );
$zip = slashes ( $dir . 'fatture_' . time () . '.zip' );
2017-09-07 16:51:14 +02:00
// Rimozione dei contenuti precedenti
$files = glob ( $dir . '/*.zip' );
foreach ( $files as $file ) {
2017-09-11 17:49:03 +02:00
delete ( $file );
2017-09-07 16:51:14 +02:00
}
2017-09-06 11:59:47 +02:00
// Selezione delle fatture da stampare
2018-07-18 15:20:10 +02:00
$fatture = $dbo -> fetchArray ( 'SELECT co_documenti.id, numero_esterno, data, ragione_sociale, co_tipidocumento.descrizione FROM co_documenti INNER JOIN an_anagrafiche ON co_documenti.idanagrafica=an_anagrafiche.idanagrafica INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE co_documenti.id IN(' . implode ( ',' , $id_records ) . ')' );
2017-09-06 11:59:47 +02:00
2018-07-18 15:20:10 +02:00
if ( ! empty ( $fatture )) {
foreach ( $fatture as $r ) {
2018-09-26 10:49:38 +02:00
$print = Prints :: getModulePredefinedPrint ( $id_module );
2018-06-26 14:30:26 +02:00
2019-07-10 11:53:35 +02:00
Prints :: render ( $print [ 'id' ], $r [ 'id' ], $dir . 'tmp/' );
2017-09-13 18:47:42 +02:00
}
2017-09-06 11:59:47 +02:00
2017-09-13 18:47:42 +02:00
// Creazione zip
if ( extension_loaded ( 'zip' )) {
2019-03-07 17:16:42 +01:00
Zip :: create ( $dir . 'tmp/' , $zip );
2017-09-06 11:59:47 +02:00
2017-09-13 18:47:42 +02:00
// Invio al browser dello zip
2019-03-07 17:16:42 +01:00
download ( $zip );
2017-09-06 11:59:47 +02:00
2017-09-13 18:47:42 +02:00
// Rimozione dei contenuti
delete ( $dir . 'tmp/' );
}
2017-09-06 12:50:44 +02:00
}
2017-09-06 11:59:47 +02:00
break ;
2018-03-19 19:07:32 +01:00
2019-06-13 15:57:55 +02:00
case 'genera-xml' :
$failed = [];
2019-06-29 11:01:26 +02:00
$added = [];
2019-06-13 15:57:55 +02:00
2019-06-29 11:01:26 +02:00
foreach ( $id_records as $id ) {
2019-06-13 15:57:55 +02:00
$fattura = Fattura :: find ( $id );
2020-11-20 17:53:09 +01:00
2019-07-23 16:27:36 +02:00
try {
2020-11-20 17:53:09 +01:00
$fattura_elettronica = new FatturaElettronica ( $id );
2019-07-23 16:24:04 +02:00
2020-11-20 17:53:09 +01:00
if ( ! empty ( $fattura_elettronica ) && ! $fattura_elettronica -> isGenerated ()) {
$file = $fattura_elettronica -> save ( $upload_dir );
2019-06-13 15:57:55 +02:00
$added [] = $fattura -> numero_esterno ;
}
2019-07-23 16:27:36 +02:00
} catch ( UnexpectedValueException $e ) {
2019-06-13 15:57:55 +02:00
$failed [] = $fattura -> numero_esterno ;
}
}
if ( ! empty ( $failed )) {
flash () -> warning ( tr ( 'Le fatture elettroniche _LIST_ non sono state generate.' , [
'_LIST_' => implode ( ', ' , $failed ),
]));
}
if ( ! empty ( $added )) {
flash () -> info ( tr ( 'Le fatture elettroniche _LIST_ sono state generate.' , [
'_LIST_' => implode ( ', ' , $added ),
]));
}
break ;
2019-06-13 16:24:50 +02:00
2019-08-29 16:01:49 +02:00
case 'hook-send' :
foreach ( $id_records as $id ) {
$fattura = Fattura :: find ( $id );
2020-11-20 17:53:09 +01:00
try {
$fattura_elettronica = new FatturaElettronica ( $fattura -> id );
if ( ! empty ( $fattura_elettronica ) && $fattura_elettronica -> isGenerated () && $fattura -> codice_stato_fe == 'GEN' ) {
$fattura -> codice_stato_fe = 'QUEUE' ;
$fattura -> data_stato_fe = date ( 'Y-m-d H:i:s' );
$fattura -> hook_send = true ;
$fattura -> save ();
$added [] = $fattura -> numero_esterno ;
}
} catch ( UnexpectedValueException $e ) {
$failed [] = $fattura -> numero_esterno ;
2019-08-29 16:01:49 +02:00
}
}
flash () -> info ( tr ( 'Le fatture elettroniche sono state aggiunte alla coda di invio' ));
break ;
2019-03-07 17:16:42 +01:00
case 'export-xml-bulk' :
2020-09-23 13:36:37 +02:00
$dir = base_dir () . '/files/export_fatture/' ;
2019-03-07 17:16:42 +01:00
directory ( $dir . 'tmp/' );
$dir = slashes ( $dir );
$zip = slashes ( $dir . 'fatture_' . time () . '.zip' );
// Rimozione dei contenuti precedenti
$files = glob ( $dir . '/*.zip' );
foreach ( $files as $file ) {
delete ( $file );
}
2019-06-13 14:46:04 +02:00
// Selezione delle fatture da esportare
2019-05-10 17:30:00 +02:00
$fatture = $dbo -> fetchArray ( 'SELECT co_documenti.id, numero_esterno, data, ragione_sociale, co_tipidocumento.descrizione, co_tipidocumento.dir FROM co_documenti INNER JOIN an_anagrafiche ON co_documenti.idanagrafica=an_anagrafiche.idanagrafica INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id INNER JOIN co_statidocumento ON co_documenti.idstatodocumento=co_statidocumento.id WHERE co_documenti.id IN(' . implode ( ',' , $id_records ) . ')' );
2019-03-07 17:16:42 +01:00
$failed = [];
2019-06-13 14:46:04 +02:00
$added = 0 ;
2019-03-07 17:16:42 +01:00
if ( ! empty ( $fatture )) {
foreach ( $fatture as $r ) {
$fattura = Fattura :: find ( $r [ 'id' ]);
$include = true ;
try {
2019-03-28 13:00:49 +01:00
if ( $r [ 'dir' ] == 'entrata' ) {
2020-11-20 17:53:09 +01:00
$fe = new FatturaElettronica ( $fattura -> id );
2019-03-28 13:00:49 +01:00
$include = $fe -> isGenerated ();
} else {
$include = $fattura -> isFE ();
}
2019-03-07 17:16:42 +01:00
} catch ( UnexpectedValueException $e ) {
$include = false ;
2018-06-26 14:30:26 +02:00
}
2019-03-07 17:16:42 +01:00
if ( ! $include ) {
$failed [] = $fattura -> numero_esterno ;
} else {
2019-03-28 13:00:49 +01:00
if ( $r [ 'dir' ] == 'entrata' ) {
$src = $fe -> getFilename ();
$dst = $src ;
} else {
2019-04-04 17:30:58 +02:00
$src = basename ( $fattura -> uploads () -> where ( 'name' , 'Fattura Elettronica' ) -> first () -> filepath );
2019-07-19 18:11:07 +02:00
$dst = basename ( $fattura -> uploads () -> where ( 'name' , 'Fattura Elettronica' ) -> first () -> original_name );
2019-03-28 13:00:49 +01:00
}
2019-03-07 17:16:42 +01:00
2019-03-28 13:00:49 +01:00
$file = slashes ( $module -> upload_directory . '/' . $src );
$dest = slashes ( $dir . '/tmp/' . $dst );
2019-03-07 17:16:42 +01:00
$result = copy ( $file , $dest );
2019-06-13 14:46:04 +02:00
2019-03-07 17:16:42 +01:00
if ( $result ) {
2019-06-29 11:01:26 +02:00
++ $added ;
2019-08-29 10:25:14 +02:00
//operationLog('export-xml-bulk', ['id_record' => $r['id']]);
2019-03-07 17:16:42 +01:00
} else {
$failed [] = $fattura -> numero_esterno ;
}
}
}
// Creazione zip
2019-06-29 11:01:26 +02:00
if ( extension_loaded ( 'zip' ) and ! empty ( $added )) {
2019-03-07 17:16:42 +01:00
Zip :: create ( $dir . 'tmp/' , $zip );
// Invio al browser il file zip
download ( $zip );
// Rimozione dei contenuti
delete ( $dir . 'tmp/' );
2018-06-26 14:30:26 +02:00
}
2019-03-07 17:16:42 +01:00
if ( ! empty ( $failed )) {
2019-06-13 14:46:04 +02:00
flash () -> warning ( tr ( 'Le fatture elettroniche _LIST_ non sono state incluse poichè non ancora generate o non presenti sul server' , [
2019-03-07 17:16:42 +01:00
'_LIST_' => implode ( ', ' , $failed ),
]));
}
}
2018-03-22 15:40:20 +01:00
break ;
2020-01-17 15:23:32 +01:00
case 'copy-bulk' :
2020-07-30 18:08:02 +02:00
$list = [];
2020-01-28 14:06:33 +01:00
foreach ( $id_records as $id ) {
$fattura = Fattura :: find ( $id );
2020-07-24 10:02:58 +02:00
array_push ( $list , $fattura -> numero_esterno );
2020-01-17 15:23:32 +01:00
2020-01-28 14:06:33 +01:00
$id_segment = ( post ( 'id_segment' ) ? post ( 'id_segment' ) : $fattura -> id_segment );
2020-02-05 14:51:39 +01:00
$dir = $dbo -> fetchOne ( 'SELECT dir FROM co_tipidocumento WHERE id=' . prepare ( $fattura -> idtipodocumento ))[ 'dir' ];
2020-01-17 15:23:32 +01:00
2020-01-28 14:06:33 +01:00
//+ 1 giorno
2020-02-05 14:51:39 +01:00
if ( post ( 'skip_time' ) == 'Giorno' ) {
$data = date ( 'Y-m-d' , strtotime ( '+1 day' , strtotime ( $fattura -> data )));
2020-01-17 15:23:32 +01:00
}
//+ 1 settimana
2020-02-05 14:51:39 +01:00
if ( post ( 'skip_time' ) == 'Settimana' ) {
$data = date ( 'Y-m-d' , strtotime ( '+1 week' , strtotime ( $fattura -> data )));
2020-01-17 15:23:32 +01:00
}
//+ 1 mese
2020-02-05 14:51:39 +01:00
if ( post ( 'skip_time' ) == 'Mese' ) {
$data = date ( 'Y-m-d' , strtotime ( '+1 month' , strtotime ( $fattura -> data )));
2020-01-17 15:23:32 +01:00
}
//+ 1 anno
2020-02-05 14:51:39 +01:00
if ( post ( 'skip_time' ) == 'Anno' ) {
$data = date ( 'Y-m-d' , strtotime ( '+1 year' , strtotime ( $fattura -> data )));
2020-01-17 15:23:32 +01:00
}
2020-01-28 14:06:33 +01:00
$new = $fattura -> replicate ();
2020-08-04 19:07:04 +02:00
$new -> data = $data ;
2020-01-28 14:06:33 +01:00
$new -> id_segment = $id_segment ;
$new -> numero = Fattura :: getNextNumero ( $data , $dir , $id_segment );
2020-07-24 10:02:58 +02:00
if ( ! empty ( $fattura -> numero_esterno )) {
$new -> numero_esterno = Fattura :: getNextNumeroSecondario ( $data , $dir , $id_segment );
}
2020-08-04 19:07:04 +02:00
$new -> codice_stato_fe = null ;
$new -> progressivo_invio = null ;
$new -> data_stato_fe = null ;
$stato = Stato :: where ( 'descrizione' , 'Bozza' ) -> first ();
2020-07-24 10:02:58 +02:00
$new -> stato () -> associate ( $stato );
2020-08-04 19:07:04 +02:00
2020-01-28 14:06:33 +01:00
$new -> save ();
2020-01-17 15:23:32 +01:00
2020-01-28 14:06:33 +01:00
$righe = $fattura -> getRighe ();
foreach ( $righe as $riga ) {
$new_riga = $riga -> replicate ();
2020-09-22 20:28:37 +02:00
$new_riga -> setDocument ( $new );
2020-01-17 15:23:32 +01:00
2020-02-27 16:19:07 +01:00
if ( ! post ( 'riferimenti' )) {
$new_riga -> idpreventivo = 0 ;
$new_riga -> idcontratto = 0 ;
$new_riga -> idintervento = 0 ;
$new_riga -> idddt = 0 ;
$new_riga -> idordine = 0 ;
}
$new_riga -> qta_evasa = 0 ;
$new_riga -> original_type = null ;
$new_riga -> original_id = null ;
2020-01-28 14:06:33 +01:00
$new_riga -> save ();
2020-01-17 15:23:32 +01:00
2020-02-27 16:19:07 +01:00
if ( $new_riga -> isArticolo ()) {
$new_riga -> movimenta ( $new_riga -> qta );
2020-01-17 15:23:32 +01:00
}
}
}
2020-07-24 10:02:58 +02:00
flash () -> info ( tr ( 'Fatture _LIST_ duplicate correttamente!' , [
'_LIST_' => implode ( ',' , $list ),
]));
2020-01-17 15:23:32 +01:00
break ;
2020-11-21 03:16:59 +01:00
case 'check-bulk' :
$list = [];
$anomalie = collect ();
foreach ( $id_records as $id ) {
$fattura_vendita = Fattura :: vendita ()
-> whereNotIn ( 'codice_stato_fe' , [ 'ERR' , 'NS' , 'EC02' , 'ERVAL' ])
-> where ( 'data' , '>=' , $_SESSION [ 'period_start' ])
-> where ( 'data' , '<=' , $_SESSION [ 'period_end' ])
-> where ( 'id' , '=' , $id )
-> orderBy ( 'data' )
-> get ();
$fattura_vendita = $fattura_vendita [ 0 ];
2020-11-21 03:22:23 +01:00
if ( ! empty ( $fattura_vendita )){
try {
$xml = XML :: read ( $fattura_vendita -> getXML ());
$totale_documento_xml = null ;
// Totale basato sul campo ImportoTotaleDocumento
$dati_generali = $xml [ 'FatturaElettronicaBody' ][ 'DatiGenerali' ][ 'DatiGeneraliDocumento' ];
if ( isset ( $dati_generali [ 'ImportoTotaleDocumento' ])) {
$totale_documento_indicato = abs ( floatval ( $dati_generali [ 'ImportoTotaleDocumento' ]));
// Calcolo del totale basato sui DatiRiepilogo
if ( empty ( $totale_documento_xml ) && empty ( $dati_generali [ 'ScontoMaggiorazione' ])) {
$totale_documento_xml = 0 ;
$riepiloghi = $xml [ 'FatturaElettronicaBody' ][ 'DatiBeniServizi' ][ 'DatiRiepilogo' ];
if ( ! empty ( $riepiloghi ) && ! isset ( $riepiloghi [ 0 ])) {
$riepiloghi = [ $riepiloghi ];
}
foreach ( $riepiloghi as $riepilogo ) {
$totale_documento_xml = sum ([ $totale_documento_xml , $riepilogo [ 'ImponibileImporto' ], $riepilogo [ 'Imposta' ]]);
}
$totale_documento_xml = abs ( $totale_documento_xml );
} else {
$totale_documento_xml = $totale_documento_indicato ;
2020-11-21 03:16:59 +01:00
}
2020-11-21 03:22:23 +01:00
$totale_documento_xml = $fattura_vendita -> isNota () ? - $totale_documento_xml : $totale_documento_xml ;
}
2020-11-21 03:16:59 +01:00
2020-11-21 03:22:23 +01:00
// 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 ){
2020-11-21 03:16:59 +01:00
2020-11-21 03:22:23 +01:00
/* echo json_encode ([
'totale_documento_xml' => $totale_documento_xml ,
'totale_documento' => $totale_documento ,
]); */
$anomalie -> push ([
'fattura_vendita' => $fattura_vendita ,
'codice_fiscale_xml' => ! empty ( $xml [ 'FatturaElettronicaHeader' ][ 'CessionarioCommittente' ][ 'DatiAnagrafici' ][ 'CodiceFiscale' ]) ? $xml [ 'FatturaElettronicaHeader' ][ 'CessionarioCommittente' ][ 'DatiAnagrafici' ][ 'CodiceFiscale' ] : null ,
'codice_fiscale' => $fattura_vendita -> anagrafica -> codice_fiscale ,
'piva_xml' => ! empty ( $xml [ 'FatturaElettronicaHeader' ][ 'CessionarioCommittente' ][ 'DatiAnagrafici' ][ 'IdFiscaleIVA' ][ 'IdCodice' ]) ? $xml [ 'FatturaElettronicaHeader' ][ 'CessionarioCommittente' ][ 'DatiAnagrafici' ][ 'IdFiscaleIVA' ][ 'IdCodice' ] : null ,
'piva' => $fattura_vendita -> anagrafica -> piva ,
'totale_documento_xml' => moneyFormat ( $totale_documento_xml , 2 ),
'totale_documento' => moneyFormat ( $fattura_vendita -> totale , 2 ),
'have_xml' => 1 ,
]);
}
} catch ( Exception $e ) {
2020-11-21 03:16:59 +01:00
$anomalie -> push ([
'fattura_vendita' => $fattura_vendita ,
2020-11-21 03:22:23 +01:00
'have_xml' => 0 ,
2020-11-21 03:16:59 +01:00
]);
2020-11-21 03:22:23 +01:00
}
array_push ( $list , $fattura_vendita -> numero_esterno );
2020-11-21 03:16:59 +01:00
}
}
// Messaggi di risposta
if ( empty ( $list )){
flash () -> warning ( tr ( 'Nessuna fattura utile per il controllo!' ));
} else {
flash () -> info ( tr ( 'Fatture _LIST_ controllate.' , [
'_LIST_' => implode ( ',' , $list ),
]));
// Se ci sono anomalie
if ( $anomalie -> count () > 0 ) {
function diff ( $old , $new ){
$matrix = array ();
$maxlen = 0 ;
foreach ( $old as $oindex => $ovalue ){
$nkeys = array_keys ( $new , $ovalue );
foreach ( $nkeys as $nindex ){
$matrix [ $oindex ][ $nindex ] = isset ( $matrix [ $oindex - 1 ][ $nindex - 1 ]) ?
$matrix [ $oindex - 1 ][ $nindex - 1 ] + 1 : 1 ;
if ( $matrix [ $oindex ][ $nindex ] > $maxlen ){
$maxlen = $matrix [ $oindex ][ $nindex ];
$omax = $oindex + 1 - $maxlen ;
$nmax = $nindex + 1 - $maxlen ;
}
}
}
if ( $maxlen == 0 ) return array ( array ( 'd' => $old , 'i' => $new ));
return array_merge (
diff ( array_slice ( $old , 0 , $omax ), array_slice ( $new , 0 , $nmax )),
array_slice ( $new , $nmax , $maxlen ),
diff ( array_slice ( $old , $omax + $maxlen ), array_slice ( $new , $nmax + $maxlen )));
}
function htmlDiff ( $old , $new ){
$ret = '' ;
$diff = diff ( preg_split ( " /[ \ s]+/ " , $old ), preg_split ( " /[ \ s]+/ " , $new ));
foreach ( $diff as $k ){
if ( is_array ( $k ))
$ret .= ( ! empty ( $k [ 'd' ]) ? " <del> " . implode ( ' ' , $k [ 'd' ]) . " </del> " : '' ) .
( ! empty ( $k [ 'i' ]) ? " <span> " . implode ( ' ' , $k [ 'i' ]) . " </span> " : '' );
else $ret .= $k . ' ' ;
}
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>' ;
foreach ( $anomalie as $anomalia ) {
$riepilogo_anomalie .= '<ul><li>' . reference ( $anomalia [ 'fattura_vendita' ], $anomalia [ 'fattura_vendita' ] -> getReference ()) . '</li>' ;
if ( ! empty ( $anomalia [ 'have_xml' ])){
$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 > ' ;
$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>' ;
} else {
$riepilogo_anomalie .= ' <li>' . tr ( 'Impossibile verificare l\'XML di questa fattura.' ) . '</li>' ;
}
$riepilogo_anomalie .= '</ul><br>' ;
}
flash () -> warning ( $riepilogo_anomalie );
} else {
2020-11-24 17:26:37 +01:00
flash () -> info ( tr ( 'Nessuna anomalia!' ));
2020-11-21 03:16:59 +01:00
}
}
break ;
2020-11-24 17:25:07 +01:00
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 ;
2020-03-03 10:33:32 +01:00
case 'delete-bulk' :
foreach ( $id_records as $id ) {
$documento = Fattura :: find ( $id );
try {
$documento -> delete ();
} catch ( InvalidArgumentException $e ) {
}
}
flash () -> info ( tr ( 'Fatture eliminate!' ));
break ;
2017-09-06 11:59:47 +02:00
}
2019-05-13 17:01:43 +02:00
if ( App :: debug ()) {
2020-07-09 18:50:10 +02:00
$operations [ 'delete-bulk' ] = [
2020-11-24 17:25:07 +01:00
'text' => '<span><i class="fa fa-trash"></i> ' . tr ( 'Elimina selezionati' ) . '</span> <span class="label label-danger" >beta</span>' ,
2019-05-16 04:52:16 +02:00
];
2020-11-24 17:25:07 +01:00
$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 ,
],
];
2019-05-13 17:01:43 +02:00
}
2018-03-19 19:07:32 +01:00
2020-01-17 15:23:32 +01:00
$operations [ 'copy-bulk' ] = [
'text' => '<span><i class="fa fa-copy"></i> ' . tr ( 'Duplica selezionati' ) . '</span>' ,
'data' => [
2020-07-24 10:02:58 +02:00
'msg' => tr ( 'Vuoi davvero duplicare le righe selezionate?' ) . '<br><br>{[ "type": "select", "label": "' . tr ( 'Fattura in avanti di' ) . '", "name": "skip_time", "required": 1, "values": "list=\"Giorno\":\"' . tr ( 'Un giorno' ) . '\", \"Settimana\":\"' . tr ( 'Una settimana' ) . '\", \"Mese\":\"' . tr ( 'Un mese' ) . '\", \"Anno\":\"' . tr ( 'Un anno' ) . '\" ", "value": "Giorno" ]}<br>{[ "type": "select", "label": "' . tr ( 'Sezionale' ) . '", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module=' . $id_module . ' ORDER BY name", "value": "' . $_SESSION [ 'module_' . $id_module ][ 'id_segment' ] . '" ]}<br>{[ "type": "checkbox", "placeholder": "' . tr ( 'Aggiungere i riferimenti ai documenti esterni?' ) . '", "name": "riferimenti" ]}' ,
2020-01-17 15:23:32 +01:00
'button' => tr ( 'Procedi' ),
'class' => 'btn btn-lg btn-warning' ,
],
];
2019-07-25 15:06:07 +02:00
$operations [ 'registrazione-contabile' ] = [
2019-07-25 12:54:28 +02:00
'text' => '<span><i class="fa fa-calculator"></i> ' . tr ( 'Registrazione contabile' ) . '</span>' ,
'data' => [
'title' => tr ( 'Registrazione contabile' ),
'type' => 'modal' ,
'origine' => 'fatture' ,
2020-09-23 17:53:19 +02:00
'url' => base_path () . '/add.php?id_module=' . Modules :: get ( 'Prima nota' )[ 'id' ],
2019-07-25 12:54:28 +02:00
],
];
2019-06-13 15:57:55 +02:00
if ( $module -> name == 'Fatture di vendita' ) {
$operations [ 'genera-xml' ] = [
2019-07-25 12:54:28 +02:00
'text' => '<span><i class="fa fa-file-code-o"></i> ' . tr ( 'Genera fatture elettroniche' ) . '</span>' ,
2019-06-13 15:57:55 +02:00
'data' => [
'title' => '' ,
2020-11-21 03:16:59 +01:00
'msg' => tr ( 'Generare le fatture elettroniche per i documenti selezionati?<br><small>(le fatture dovranno trovarsi nello stato <i class="fa fa-clock-o text-info" title="Emessa"></i> <small>Emessa</small> e non essere mai state generate)</small>' ),
2019-06-13 15:57:55 +02:00
'button' => tr ( 'Procedi' ),
'class' => 'btn btn-lg btn-warning' ,
'blank' => true ,
],
];
2019-06-13 14:46:04 +02:00
2019-05-13 17:01:43 +02:00
$operations [ 'export-bulk' ] = [
2019-07-25 12:54:28 +02:00
'text' => '<span class="' . (( ! extension_loaded ( 'zip' )) ? 'text-muted disabled' : '' ) . '"><i class="fa fa-file-archive-o"></i> ' . tr ( 'Esporta stampe' ) . '</span>' ,
2017-09-06 11:59:47 +02:00
'data' => [
2019-06-13 14:46:04 +02:00
'title' => '' ,
'msg' => tr ( 'Vuoi davvero esportare i PDF delle fatture selezionate in un archivio ZIP?' ),
2017-09-06 11:59:47 +02:00
'button' => tr ( 'Procedi' ),
'class' => 'btn btn-lg btn-warning' ,
2017-09-07 16:51:14 +02:00
'blank' => true ,
2017-09-06 11:59:47 +02:00
],
2019-03-07 17:16:42 +01:00
];
2020-11-21 03:16:59 +01:00
$operations [ 'check-bulk' ] = [
'text' => '<span><i class="fa fa-list-alt"></i> ' . tr ( 'Controlla fatture elettroniche' ) . '</span>' ,
'data' => [
'title' => '' ,
'msg' => tr ( 'Controllare corrispondenza tra XML e fattura di vendita?<br><small>(le fatture dovranno essere state generate)</small>' ),
'button' => tr ( 'Procedi' ),
'class' => 'btn btn-lg btn-warning' ,
'blank' => true ,
],
];
2019-03-07 17:16:42 +01:00
}
2019-05-13 17:01:43 +02:00
$operations [ 'export-xml-bulk' ] = [
2019-07-25 12:54:28 +02:00
'text' => '<span class="' . (( ! extension_loaded ( 'zip' )) ? 'text-muted disabled' : '' ) . '"><i class="fa fa-file-archive-o"></i> ' . tr ( 'Esporta XML' ) . '</span>' ,
2019-03-28 13:00:49 +01:00
'data' => [
2019-06-13 14:46:04 +02:00
'title' => '' ,
'msg' => tr ( 'Vuoi davvero esportare le fatture elettroniche selezionate in un archivio ZIP?' ),
2019-03-28 13:00:49 +01:00
'button' => tr ( 'Procedi' ),
'class' => 'btn btn-lg btn-warning' ,
'blank' => true ,
],
];
2019-08-29 16:01:49 +02:00
if ( Interaction :: isEnabled ()) {
$operations [ 'hook-send' ] = [
'text' => '<span><i class="fa fa-paper-plane"></i> ' . tr ( 'Coda di invio FE' ) . '</span>' ,
'data' => [
'title' => '' ,
'msg' => tr ( 'Vuoi davvero aggiungere queste fatture alla coda di invio per le fatture elettroniche?' ),
'button' => tr ( 'Procedi' ),
'class' => 'btn btn-lg btn-warning' ,
],
];
}
2019-05-13 17:01:43 +02:00
return $operations ;