2018-12-14 12:50:44 +01: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 />.
*/
2018-12-14 12:50:44 +01:00
include_once __DIR__ . '/../../core.php' ;
2020-10-30 16:03:05 +01:00
use Carbon\Carbon ;
use Modules\Fatture\Fattura ;
2018-12-14 12:50:44 +01:00
use Plugins\ReceiptFE\Interaction ;
echo '
2019-11-13 22:11:12 +01:00
< p > '.tr(' Le ricevute delle Fatture Elettroniche permettono di individuare se una determinata fattura tramessa è stata accettata dal Sistema Di Interscambio ').' .</ p > ' ;
2020-10-30 16:03:05 +01:00
2019-11-13 22:11:12 +01:00
if ( Interaction :: isEnabled ()) {
2019-11-15 15:11:20 +01:00
echo '
2019-06-04 20:45:40 +02:00
< p > '.tr(' Tramite il pulsante _BTN_ è possibile procedere al recupero delle ricevute , aggiornando automaticamente lo stato delle relative fatture e allegandole ad esse ' , [
2020-05-29 18:54:57 +02:00
'_BTN_' => '<i class="fa fa-refresh"></i> <b>' . tr ( 'Ricerca ricevute' ) . '</b>' ,
2019-11-13 22:11:12 +01:00
]) . '.</p>' ;
2020-05-29 18:54:57 +02:00
2020-10-30 16:03:05 +01:00
// Controllo se ci sono fatture in elaborazione da più di 7 giorni per le quali non ho ancora una ricevuta
$data_limite = ( new Carbon ()) -> subDays ( 7 );
2020-11-03 17:35:43 +01:00
$fatture_generate = Fattura :: vendita ()
2020-10-30 16:03:05 +01:00
-> where ( 'codice_stato_fe' , 'WAIT' )
-> where ( 'data_stato_fe' , '>=' , $_SESSION [ 'period_start' ])
-> where ( 'data_stato_fe' , '<' , $data_limite )
-> orderBy ( 'data_stato_fe' )
-> get ();
2020-05-29 18:54:57 +02:00
2020-11-06 10:46:42 +01:00
if ( ! empty ( $fatture_generate )) {
2020-06-09 16:59:26 +02:00
echo '
2020-10-30 16:03:05 +01:00
< div class = " alert alert-warning " >
< p >< i class = " fa fa-warning " ></ i > '.tr(' Attenzione : le seguenti fatture sono in attesa di una ricevuta ').' .</ p >
< ul > ' ;
foreach ( $fatture_generate as $fattura_generata ) {
echo '<li>' . reference ( $fattura_generata , $fattura_generata -> getReference ()) . ' [' . timestampFormat ( $fattura_generata [ 'data_stato_fe' ]) . ']</li>' ;
}
echo '
</ ul >
</ div > ' ;
2020-06-09 16:59:26 +02:00
}
2019-11-13 22:11:12 +01:00
}
2020-10-30 16:03:05 +01:00
2019-11-13 22:11:12 +01:00
echo '
2019-07-10 15:02:09 +02:00
< div class = " box box-success " >
< div class = " box-header with-border " >
< h3 class = " box-title " >
'.tr(' Carica un XML ').'
2020-02-24 18:30:05 +01:00
2019-07-10 15:02:09 +02:00
< span class = " tip " title = " '.tr('Formati supportati: XML e P7M').'. " >
< i class = " fa fa-question-circle-o " ></ i >
</ span >
</ h3 >
</ div >
< div class = " box-body " id = " upload " >
< div class = " row " >
< div class = " col-md-9 " >
{[ " type " : " file " , " name " : " blob " , " required " : 1 ]}
</ div >
< div class = " col-md-3 " >
< button type = " button " class = " btn btn-primary pull-right " onclick = " upload(this) " >
< i class = " fa fa-upload " ></ i > '.tr(' Carica ricevuta ').'
</ button >
</ div >
</ div >
</ div >
</ div > ' ;
2018-12-14 12:50:44 +01:00
echo '
2019-07-10 15:02:09 +02:00
< div class = " box box-info " >
< div class = " box-header with-border " >
< h3 class = " box-title " >
'.tr(' Ricevute da importare ').' </ span >
</ h3 > ' ;
// Ricerca automatica
if ( Interaction :: isEnabled ()) {
echo '
< div class = " pull-right " >
< button type = " button " class = " btn btn-warning " onclick = " importAll(this) " >
2019-07-24 17:39:11 +02:00
< i class = " fa fa-cloud-download " ></ i > '.tr(' Importa tutte le ricevute ').'
2019-07-10 15:02:09 +02:00
</ button >
2020-02-24 18:30:05 +01:00
2019-07-10 15:02:09 +02:00
< button type = " button " class = " btn btn-primary " onclick = " search(this) " >
< i class = " fa fa-refresh " ></ i > '.tr(' Ricerca ricevute ').'
</ button >
</ div > ' ;
}
echo '
</ div >
< div class = " box-body " id = " list " > ' ;
if ( Interaction :: isEnabled ()) {
echo '
< p > '.tr(' Per vedere le ricevute da importare utilizza il pulsante _BUTTON_ ' , [
2020-05-29 18:54:57 +02:00
'_BUTTON_' => '<i class="fa fa-refresh"></i> <b>' . tr ( 'Ricerca ricevute' ) . '</b>' ,
2019-07-10 15:02:09 +02:00
]) . '.</p>' ;
} else {
include $structure -> filepath ( 'list.php' );
}
2018-12-14 12:50:44 +01:00
2019-07-10 15:02:09 +02:00
echo '
</ div >
2018-12-14 12:50:44 +01:00
</ div > ' ;
echo '
< script >
2019-07-10 15:02:09 +02:00
function search ( button ) {
var restore = buttonLoading ( button );
$ ( " #list " ) . load ( " '. $structure->fileurl ('list.php').'?id_module='. $id_module .'&id_plugin='. $id_plugin .' " , function () {
buttonRestore ( button , restore );
});
}
function upload ( btn ) {
if ( $ ( " #blob " ) . val ()) {
2018-12-14 12:50:44 +01:00
var restore = buttonLoading ( btn );
2019-07-10 15:02:09 +02:00
$ ( " #upload " ) . ajaxSubmit ({
2018-12-14 12:50:44 +01:00
url : globals . rootdir + " /actions.php " ,
data : {
2019-07-10 15:02:09 +02:00
op : " save " ,
2018-12-14 12:50:44 +01:00
id_module : " '. $id_module .' " ,
id_plugin : " '. $id_plugin .' " ,
},
type : " post " ,
success : function ( data ){
2019-07-10 15:02:09 +02:00
importMessage ( data );
2020-02-24 18:30:05 +01:00
2018-12-14 12:50:44 +01:00
buttonRestore ( btn , restore );
},
2019-07-10 15:02:09 +02:00
error : function ( xhr ) {
alert ( " '.tr('Errore').': " + xhr . responseJSON . error . message );
2018-12-14 12:50:44 +01:00
buttonRestore ( btn , restore );
}
});
2019-07-10 15:02:09 +02:00
} else {
swal ({
title : " '.tr('Selezionare un file!').' " ,
type : " error " ,
})
}
}
function importMessage ( data ) {
data = JSON . parse ( data );
var ricevuta = " <br>'.tr('Ricevuta').': " + data . file ;
2020-02-24 18:30:05 +01:00
2019-07-10 15:02:09 +02:00
if ( data . fattura ) {
swal ({
title : " '.tr('Importazione completata!').' " ,
html : " '.tr('Fattura aggiornata correttamente').': " + data . fattura + ricevuta ,
type : " success " ,
});
} else {
swal ({
title : " '.tr('Importazione fallita!').' " ,
html : " <i>'.tr('Fattura relativa alla ricevuta non rilevata. Controlla che esista una fattura di vendita corrispondente caricata a gestionale.').'</i> " + ricevuta ,
type : " error " ,
});
2018-12-14 12:50:44 +01:00
}
2019-07-10 15:02:09 +02:00
}
2018-12-14 12:50:44 +01:00
2019-07-10 15:02:09 +02:00
function importAll ( btn ) {
swal ({
title : " '.tr('Importare tutte le ricevute?').' " ,
html : " '.tr('Importando le ricevute, verranno aggiornati gli stati di invio delle fatture elettroniche. Continuare?').' " ,
showCancelButton : true ,
confirmButtonText : " '.tr('Procedi').' " ,
type : " info " ,
}) . then ( function ( result ) {
2018-12-14 12:50:44 +01:00
var restore = buttonLoading ( btn );
2020-02-24 18:30:05 +01:00
$ ( " #main_loading " ) . show ();
2018-12-14 12:50:44 +01:00
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
data : {
op : " import " ,
id_module : " '. $id_module .' " ,
id_plugin : " '. $id_plugin .' " ,
},
type : " post " ,
success : function ( data ){
data = JSON . parse ( data );
2020-02-24 18:30:05 +01:00
2019-07-24 17:54:50 +02:00
if ( data . length == 0 ){
var html = " '.tr('Non sono state trovate ricevute da importare').'. " ;
} else {
var html = " '.tr('Sono state elaborate le seguenti ricevute:').' " ;
2020-02-24 18:30:05 +01:00
2019-07-24 17:54:50 +02:00
data . forEach ( function ( element ) {
var text = " " ;
if ( element . fattura ) {
text += element . fattura ;
} else {
text += " <i>'.tr('Fattura relativa alla ricevuta non rilevata. Controlla che esista una fattura di vendita corrispondente caricata a gestionale.').'</i> " ;
}
2020-02-24 18:30:05 +01:00
2019-07-24 17:54:50 +02:00
text += " ( " + element . file + " ) " ;
2020-02-24 18:30:05 +01:00
2019-07-24 17:54:50 +02:00
html += " <small><li> " + text + " </li></small> " ;
});
2020-02-24 18:30:05 +01:00
2019-07-24 17:54:50 +02:00
html += " <br><small>'.tr( " Se si sono verificati degli errori durante la procedura e il problema continua a verificarsi , contatta l 'assistenza ufficiale").' </ small > " ;
}
2020-02-24 18:30:05 +01:00
2019-11-13 22:11:12 +01:00
$ ( " #list " ) . load ( " '. $structure->fileurl ('list.php').'?id_module='. $id_module .'&id_plugin='. $id_plugin .' " , function () {
2020-02-24 18:30:05 +01:00
swal ({
title : " '.tr('Operazione completata!').' " ,
html : html ,
type : " info " ,
});
2020-08-11 13:04:36 +02:00
buttonRestore ( btn , restore );
2020-02-24 18:30:05 +01:00
$ ( " #main_loading " ) . fadeOut ();
2019-11-13 22:11:12 +01:00
});
2020-02-24 18:30:05 +01:00
2018-12-14 12:50:44 +01:00
},
error : function ( data ) {
alert ( " '.tr('Errore').': " + data );
2020-02-24 18:30:05 +01:00
2018-12-14 12:50:44 +01:00
buttonRestore ( btn , restore );
}
});
2019-07-10 15:02:09 +02:00
});
}
2018-12-14 12:50:44 +01:00
</ script > ' ;