2018-07-09 12:57:55 +02:00
< ? php
2018-09-18 15:57:55 +02:00
include_once __DIR__ . '/init.php' ;
2018-07-09 12:57:55 +02:00
2018-11-30 16:10:15 +01:00
use Plugins\ExportFE\FatturaElettronica ;
2018-12-07 18:16:46 +01:00
use Plugins\ExportFE\Interaction ;
2018-11-30 16:10:15 +01:00
2020-06-04 12:27:07 +02:00
/* per le PA EC02 e EC01 sono dei stati successivi a NE il quale a sua volta è successivo a RC. EC01 e EC02 sono definiti all'interno della ricevuta di NE che di fatto indica il rifiuto o l'accettazione.*/
2020-04-07 18:25:48 +02:00
$abilita_genera = empty ( $fattura -> codice_stato_fe ) || in_array ( $fattura -> codice_stato_fe , [ 'GEN' , 'NS' , 'EC02' , 'ERR' ]);
2019-07-16 12:27:36 +02:00
2018-09-21 15:50:42 +02:00
if ( ! empty ( $fattura_pa )) {
2018-07-09 15:01:11 +02:00
$disabled = false ;
2018-12-07 17:01:42 +01:00
$generated = $fattura_pa -> isGenerated ();
2018-09-18 15:57:55 +02:00
} else {
2018-07-09 15:01:11 +02:00
$disabled = true ;
2018-09-18 15:57:55 +02:00
$generated = false ;
2018-07-09 15:01:11 +02:00
}
2019-08-29 14:28:05 +02:00
$checks = FatturaElettronica :: controllaFattura ( $fattura );
if ( ! empty ( $checks )) {
2018-07-09 15:01:11 +02:00
echo '
< div class = " alert alert-warning " >
2019-08-29 14:28:05 +02:00
< p >< i class = " fa fa-warning " ></ i > '.tr(' Prima di procedere alla generazione della fattura elettronica completa le seguenti informazioni ').' :</ p > ' ;
foreach ( $checks as $check ) {
echo '
< p >< b > '.$check[' name '].' '.$check[' link '].' </ b ></ p >
< ul > ' ;
foreach ( $check [ 'errors' ] as $error ) {
if ( ! empty ( $error )) {
echo '
< li > '.$error.' </ li > ' ;
}
}
2018-11-12 13:14:41 +01:00
2019-08-29 14:28:05 +02:00
echo '
</ ul > ' ;
2018-07-09 15:01:11 +02:00
}
echo '
</ div > ' ;
}
2018-10-13 10:15:54 +02:00
echo '
< p > '.tr("Per effettuare la generazione dell' XML della fattura elettronica clicca sul pulsante _BTN_ " , [
2018-10-25 16:57:39 +02:00
'_BTN_' => '<b>Genera</b>' ,
2018-11-09 13:15:19 +01:00
]) . '. ' . tr ( 'Successivamente sarà possibile procedere alla visualizzazione e al download della fattura generata attraverso i pulsanti dedicati' ) . ' .</ p >
2019-07-16 10:01:16 +02:00
< p > '.tr("Tutti gli allegati inseriti all' interno della categoria \ " Allegati Fattura Elettronica \" saranno inclusi nell'XML " ) . ' .</ p >
2018-11-09 13:15:19 +01:00
< br > ' ;
2018-07-09 15:11:19 +02:00
2018-07-09 12:57:55 +02:00
echo '
2018-10-13 10:15:54 +02:00
< div class = " text-center " >
2018-11-08 13:11:50 +01:00
< form action = " " method = " post " role = " form " style = " display:inline-block " id = " form-xml " >
2018-10-13 10:15:54 +02:00
< input type = " hidden " name = " id_plugin " value = " '. $id_plugin .' " >
< input type = " hidden " name = " id_record " value = " '. $id_record .' " >
< input type = " hidden " name = " backto " value = " record-edit " >
< input type = " hidden " name = " op " value = " generate " >
2018-07-09 12:57:55 +02:00
2019-07-16 12:27:36 +02:00
< button id = " genera " type = " submit " class = " btn btn-primary btn-lg '.( $disabled || ! $abilita_genera ? 'disabled' : '').' " '.($disabled || !$abilita_genera ? ' disabled ' : null).' >
2018-10-13 10:15:54 +02:00
< i class = " fa fa-file " ></ i > '.tr(' Genera ').'
</ button >
</ form > ' ;
2019-03-08 15:18:52 +01:00
$file = $generated ? Models\Upload :: where ( 'filename' , $fattura_pa -> getFilename ()) -> where ( 'id_record' , $id_record ) -> first () : null ;
2019-01-17 16:11:10 +01:00
2018-10-13 10:15:54 +02:00
echo '
2018-12-07 18:16:46 +01:00
< i class = " fa fa-arrow-right fa-fw text-muted " ></ i >
2019-01-17 16:11:10 +01:00
< a href = " '.ROOTDIR.'/view.php?file_id='.( $file ? $file->id : null).' " class = " btn btn-info btn-lg '.( $generated ? '' : 'disabled').' " target = " _blank " '.($generated ? ' ' : ' disabled ').' >
2018-10-13 10:15:54 +02:00
< i class = " fa fa-eye " ></ i > '.tr(' Visualizza ').'
2018-12-07 18:16:46 +01:00
</ a > ' ;
2019-03-08 15:18:52 +01:00
// Scelgo quando posso inviarla
2020-01-20 19:03:10 +01:00
$send = Interaction :: isEnabled () && $generated && in_array ( $record [ 'codice_stato_fe' ], [ 'GEN' , 'ERVAL' , 'ERR' ]);
2019-03-08 15:18:52 +01:00
2019-02-26 12:13:51 +01:00
echo '
< i class = " fa fa-arrow-right fa-fw text-muted " ></ i >
2018-12-07 18:23:46 +01:00
2019-02-26 12:13:51 +01:00
< a href = " '. $structure->fileurl ('download.php').'?id_record='. $id_record .' " class = " btn btn-primary btn-lg '.( $generated ? '' : 'disabled').' " target = " _blank " '.($generated ? ' ' : ' disabled ').' >
< i class = " fa fa-download " ></ i > '.tr(' Scarica ').'
</ a > ' ;
2019-03-08 15:18:52 +01:00
2019-01-17 16:11:10 +01:00
echo '
2018-12-07 18:16:46 +01:00
< i class = " fa fa-arrow-right fa-fw text-muted " ></ i >
2019-01-22 10:09:22 +01:00
< button onclick = " if( confirm( \ ''.tr('Inviare la fattura al SDI?').' \ ') ) { send(this); } " class = " btn btn-success btn-lg '.( $send ? '' : 'disabled').' " target = " _blank " '.($send ? ' ' : ' disabled ').' >
2018-12-07 18:16:46 +01:00
< i class = " fa fa-paper-plane " ></ i > '.tr(' Invia ').'
2020-07-01 15:57:16 +02:00
</ button > ' ;
$verify = Interaction :: isEnabled () && $generated ;
echo '
< i class = " fa fa-arrow-right fa-fw text-muted " ></ i >
< button class = " btn btn-warning btn-lg '.( $verify ? '' : 'disabled').' " target = " _blank " '.($verify ? ' ' : ' disabled ').' onclick = " verify(this) " >
< i class = " fa fa-question-circle " ></ i > '.tr(' Verifica notifiche ').'
</ button > ' ;
echo '<br><br>' ;
2018-12-07 18:23:46 +01:00
2019-01-25 15:54:56 +01:00
// Messaggio esito invio
2019-02-02 11:23:34 +01:00
if ( ! empty ( $record [ 'codice_stato_fe' ])) {
2019-02-01 18:19:13 +01:00
if ( $record [ 'codice_stato_fe' ] == 'GEN' ) {
echo '
2019-02-26 12:13:51 +01:00
< div class = " alert alert-info text-left " >< i class = " fa fa-info-circle " ></ i > '.tr("La fattura è stata generata ed è pronta per l' invio " ).'.</div>
2019-01-30 16:42:28 +01:00
' ;
2019-02-01 18:19:13 +01:00
} else {
$stato_fe = database () -> fetchOne ( 'SELECT codice, descrizione, icon FROM fe_stati_documento WHERE codice=' . prepare ( $record [ 'codice_stato_fe' ]));
if ( in_array ( $stato_fe [ 'codice' ], [ 'EC01' , 'RC' ])) {
$class = 'success' ;
2020-06-04 12:27:07 +02:00
} elseif ( in_array ( $stato_fe [ 'codice' ], [ 'ERVAL' , 'GEN' , 'MC' , 'WAIT' , 'NE' ])) {
2019-02-01 18:19:13 +01:00
$class = 'warning' ;
} else {
$class = 'danger' ;
}
echo '
2019-02-02 08:11:59 +01:00
< div class = " alert text-left alert-'. $class .' " >
2020-07-01 15:57:16 +02:00
< big >< i class = " '. $stato_fe['icon'] .' " style = " color:#fff; " ></ i >
2020-02-25 16:12:06 +01:00
< b > '.$stato_fe[' codice '].' </ b > - '.$stato_fe[' descrizione '].' </ big > '.(!empty($record[' descrizione_ricevuta_fe ']) ? ' < br >< b > NOTE :</ b > '.$record[' descrizione_ricevuta_fe '] : ' ').'
2019-02-02 08:11:59 +01:00
< div class = " pull-right " >
2020-02-25 16:12:06 +01:00
< i class = " fa fa-clock-o tip " title = " '.tr('Data e ora ricezione').' " ></ i > '.Translator::timestampToLocale($record[' data_stato_fe ']).'
2019-02-02 08:11:59 +01:00
</ div >
</ small >
2019-01-30 16:42:28 +01:00
' ;
2019-02-01 18:19:13 +01:00
}
2019-02-02 08:11:59 +01:00
}
2019-01-25 15:54:56 +01:00
echo '
2018-07-09 12:57:55 +02:00
</ div > ' ;
2018-11-08 13:11:50 +01:00
2019-07-23 16:12:46 +02:00
echo '
2018-11-08 13:11:50 +01:00
< script >
2020-07-01 15:57:16 +02:00
function send ( btn ) {
var restore = buttonLoading ( btn );
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " post " ,
data : {
op : " send " ,
id_module : " '. $id_module .' " ,
id_plugin : " '. $id_plugin .' " ,
id_record : " '. $id_record .' " ,
},
success : function ( data ) {
data = JSON . parse ( data );
buttonRestore ( btn , restore );
if ( data . code == " 200 " ) {
swal ( " '.tr('Fattura inviata!').' " , data . message , " success " );
$ ( btn ) . attr ( " disabled " , true ) . addClass ( " disabled " );
} else {
swal ( " '.tr('Invio fallito').' " , data . code + " - " + data . message , " error " );
}
},
error : function ( data ) {
swal ( " '.tr('Errore').' " , " '.tr('Errore durante il salvataggio').' " , " error " );
buttonRestore ( btn , restore );
}
});
}
function verify ( btn ) {
var restore = buttonLoading ( btn );
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " post " ,
data : {
op : " verify " ,
id_module : " '. $id_module .' " ,
id_plugin : " '. $id_plugin .' " ,
id_record : " '. $id_record .' " ,
},
success : function ( data ) {
data = JSON . parse ( data );
buttonRestore ( btn , restore );
if ( data . code == " 200 " ) {
swal ( " '.tr('Fattura inviata!').' " , data . message , " success " );
$ ( btn ) . attr ( " disabled " , true ) . addClass ( " disabled " );
location . reload (); // Ricaricamento pagina
} else {
swal ( " '.tr('Verifica fallita').' " , data . code + " - " + data . message , " error " );
}
},
error : function ( data ) {
swal ( " '.tr('Errore').' " , " '.tr('Errore durante la verifica').' " , " error " );
buttonRestore ( btn , restore );
}
});
}
2018-11-08 13:11:50 +01:00
$ ( " #genera " ) . click ( function ( event ){
event . preventDefault ();
2018-12-07 18:16:46 +01:00
2019-07-23 16:12:46 +02:00
var form = $ ( " #edit-form " );
2019-10-28 12:49:12 +01:00
form . find ( " * " ) . prop ( " disabled " , false );
2019-07-23 16:12:46 +02:00
valid = submitAjax ( form );
2020-07-01 15:57:16 +02:00
2019-07-23 16:12:46 +02:00
if ( valid ) { ' ;
if ( $generated ) {
echo '
swal ({
title : " '.tr('Sei sicuro di rigenerare la fattura?').' " ,
html : " <p>'.tr('Attenzione: sarà generato un nuovo progressivo invio').'.</p><p class= \" text-danger \" >'.tr('Se stai attendendo una ricevuta dal sistema SdI, rigenerando la fattura elettronica non sarà possibile corrispondere la ricevuta una volta emessa').'.</p> " ,
type : " warning " ,
showCancelButton : true ,
confirmButtonColor : " #30d64b " ,
cancelButtonColor : " #d33 " ,
confirmButtonText : " Genera "
}) . then (( result ) => {
if ( result ) {
$ ( " #form-xml " ) . submit ();
}
}); ' ;
} else {
echo '
2020-07-01 15:57:16 +02:00
2019-07-23 16:12:46 +02:00
$ ( " #form-xml " ) . submit (); ' ;
}
echo '
} else {
swal ({
type : " error " ,
title : " '.tr('Errore').' " ,
text : " '.tr('Alcuni campi obbligatori non sono stati compilati correttamente').'. " ,
});
}
2018-12-07 18:16:46 +01:00
});
2018-11-08 13:11:50 +01:00
</ script > ' ;