2020-02-24 12:21:47 +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 />.
*/
2020-02-24 12:21:47 +01:00
echo '
2020-03-09 11:11:12 +01:00
< button type = " button " class = " btn btn-primary tip " '.(!empty($anagrafica) ? ' ' : ' disabled ').' id = " compilazione_automatica " onclick = " compile(this) " title = " '.tr('Tenta la compilazione automatica delle informazioni delle fattura elettronica sulla base delle precedenti fatture del Fornitore').'. " >
2020-02-24 12:21:47 +01:00
< i class = " fa fa-address-book " ></ i > '.tr(' Compila automaticamente ').'
</ button >
< script >
2020-03-09 11:11:12 +01:00
$ ( document ) . ready ( function () {
var btn = $ ( " #compilazione_automatica " );
2020-09-07 15:04:06 +02:00
2020-05-15 15:45:49 +02:00
if ( ! $ ( " #compilazione_automatica " ) . not ( " disabled " )) {
2020-03-09 11:11:12 +01:00
btn . click ();
}
});
2020-02-24 12:21:47 +01:00
function compile ( btn ) {
var restore = buttonLoading ( btn );
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
cache : false ,
type : " GET " ,
data : {
id_module : " '. $id_module .' " ,
id_plugin : " '. $id_plugin .' " ,
id_record : " '. $id_record .' " ,
op : " compile " ,
},
success : function ( response ) {
var data = JSON . parse ( response );
2020-03-13 10:27:20 +01:00
if ( data . length == 0 ){
2020-08-03 12:38:05 +02:00
buttonRestore ( btn , restore );
2020-03-13 10:27:20 +01:00
return ;
}
2020-02-24 12:21:47 +01:00
$ ( " #id_tipo " ) . selectSet ( data . id_tipo );
$ ( " #pagamento " ) . selectSetNew ( data . pagamento . id , data . pagamento . descrizione );
$ ( " select[name^=iva] " ) . each ( function (){
var aliquota = $ ( this ) . closest ( " tr " ) . find ( " [id^=aliquota] " ) . text ();
2020-02-28 17:45:49 +01:00
if ( data . iva [ aliquota ] !== undefined ){
$ ( this ) . selectSet ( data . iva [ aliquota ] . id );
}
2020-02-24 12:21:47 +01:00
});
$ ( " select[name^=conto] " ) . each ( function (){
$ ( this ) . selectSetNew ( data . conto . id , data . conto . descrizione );
});
buttonRestore ( btn , restore );
},
error : function ( data ) {
swal ( " '.tr('Errore').' " , " '.tr('La compilazione automatica dei campi non è andata a buon fine').'. " , " error " );
buttonRestore ( btn , restore );
}
});
}
</ script > ' ;