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
2019-07-16 12:27:36 +02:00
$abilita_genera = empty ( $fattura -> codice_stato_fe ) || in_array ( $fattura -> codice_stato_fe , [ 'GEN' , 'NS' , 'EC02' ]);
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
$send = Interaction :: isEnabled () && $generated && in_array ( $record [ 'codice_stato_fe' ], [ 'GEN' , 'ERVAL' ]);
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 ').'
2019-01-25 15:54:56 +01:00
</ button >< 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' ;
} elseif ( in_array ( $stato_fe [ 'codice' ], [ 'ERVAL' , 'GEN' , 'MC' , 'WAIT' ])) {
$class = 'warning' ;
} else {
$class = 'danger' ;
}
echo '
2019-02-02 08:11:59 +01:00
< div class = " alert text-left alert-'. $class .' " >
< big >< i class = " '. $stato_fe['icon'] .' " style = " color:#fff; " ></ i >
2019-02-12 11:42:48 +01:00
< b > '.$stato_fe[' codice '].' </ b > - '.$stato_fe[' descrizione '].' </ big > '.(!empty($record[' descrizione_ricevuta_fe ']) ? ' < br >< b > NOTE :</ b >< br > '.$record[' descrizione_ricevuta_fe '] : ' ').'
2019-02-02 08:11:59 +01:00
< div class = " pull-right " >
< i class = " fa fa-clock-o " ></ i > '.Translator::timestampToLocale($record[' data_stato_fe ']).'
</ 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-12-07 18:23:46 +01:00
< script >
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 );
2019-01-22 08:59:11 +01:00
if ( data . code == " 200 " ) {
swal ( " '.tr('Fattura inviata!').' " , data . message , " success " );
2018-12-07 18:23:46 +01:00
$ ( btn ) . attr ( " disabled " , true ) . addClass ( " disabled " );
} else {
2019-01-22 08:59:11 +01:00
swal ( " '.tr('Invio fallito').' " , data . code + " - " + data . message , " error " );
2018-12-07 18:23:46 +01:00
}
},
error : function ( data ) {
swal ( " '.tr('Errore').' " , " '.tr('Errore durante il salvataggio').' " , " error " );
buttonRestore ( btn , restore );
}
});
}
</ script > ' ;
2018-12-07 18:16:46 +01:00
echo '
2018-09-18 15:57:55 +02:00
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 >
$ ( " #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 );
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 '
$ ( " #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 > ' ;