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
2021-01-20 15:08:51 +01:00
* Copyright ( C ) DevCode s . r . l .
2020-09-07 15:04:06 +02:00
*
* 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 '
2024-05-16 18:02:50 +02:00
< div class = " tip " data - widget = " tooltip " title = " '.tr('Tenta la compilazione automatica delle informazioni delle fattura elettronica sulla base delle precedenti fatture del Fornitore').'. " >
2020-09-16 15:57:49 +02:00
< button type = " button " class = " btn btn-primary " '.(!empty($anagrafica) ? ' ' : ' disabled ').' id = " compilazione_automatica " onclick = " compile(this) " >
< i class = " fa fa-address-book " ></ i > '.tr(' Compila automaticamente ').'
</ button >
</ div >
2024-05-16 18:02:50 +02:00
< div class = " tip " data - widget = " tooltip " title = " '.tr('Tenta il completamento automatico dei riferimenti per le righe delle fattura elettronica sulla base di Ordini e DDT registrati nel gestionale per il Fornitore').'. " >
2020-09-16 15:57:49 +02:00
< button type = " button " class = " btn btn-primary " '.(!empty($anagrafica) ? ' ' : ' disabled ').' onclick = " compilaRiferimenti(this) " >
< i class = " fa fa-list " ></ i > '.tr(' Cerca riferimenti ').'
</ button >
</ div >
2020-02-24 12:21:47 +01:00
< 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 ) {
2020-09-16 15:57:49 +02:00
let restore = buttonLoading ( btn );
2020-02-24 12:21:47 +01:00
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
cache : false ,
type : " GET " ,
2020-09-16 15:57:49 +02:00
dataType : " json " ,
2020-02-24 12:21:47 +01:00
data : {
id_module : " '. $id_module .' " ,
id_plugin : " '. $id_plugin .' " ,
id_record : " '. $id_record .' " ,
op : " compile " ,
},
success : function ( response ) {
2020-09-16 15:57:49 +02:00
buttonRestore ( btn , restore );
if ( response . length === 0 ){
2020-03-13 10:27:20 +01:00
return ;
}
2020-02-24 12:21:47 +01:00
2021-10-29 10:39:34 +02:00
if ( ! $ ( " #id_tipo " ) . val ()) {
$ ( " #id_tipo " ) . selectSet ( response . id_tipo );
}
2020-02-24 12:21:47 +01:00
$ ( " select[name^=iva] " ) . each ( function (){
var aliquota = $ ( this ) . closest ( " tr " ) . find ( " [id^=aliquota] " ) . text ();
2022-01-14 15:44:44 +01:00
if ( response . iva [ aliquota ] !== undefined && ! $ ( this ) . val ()){
2020-09-16 15:57:49 +02:00
$ ( this ) . selectSet ( response . iva [ aliquota ] . id );
2020-02-28 17:45:49 +01:00
}
2020-02-24 12:21:47 +01:00
});
$ ( " select[name^=conto] " ) . each ( function (){
2022-01-14 15:44:44 +01:00
if ( ! $ ( this ) . val ()){
$ ( this ) . selectSetNew ( response . conto . id , response . conto . descrizione );
}
2020-02-24 12:21:47 +01:00
});
2020-09-16 15:57:49 +02:00
},
error : function ( data ) {
swal ( " '.tr('Errore').' " , " '.tr('La compilazione automatica dei campi non è andata a buon fine').'. " , " error " );
2020-02-24 12:21:47 +01:00
buttonRestore ( btn , restore );
2020-09-16 15:57:49 +02:00
}
});
}
function compilaRiferimenti ( btn ) {
let restore = buttonLoading ( btn );
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
cache : false ,
type : " GET " ,
dataType : " json " ,
data : {
id_module : " '. $id_module .' " ,
id_plugin : " '. $id_plugin .' " ,
id_record : " '. $id_record .' " ,
op : " riferimenti-automatici " ,
},
success : function ( response ) {
buttonRestore ( btn , restore );
if ( response . length === 0 ){
return ;
}
2022-03-04 11:50:57 +01:00
for ( id_riga in response ) {
data = response [ id_riga ];
2020-09-16 15:57:49 +02:00
// Selezione dinamica
2022-03-04 11:50:57 +01:00
$ ( " #selezione_riferimento " + id_riga ) . addClass ( " already-loaded " ) . selectSetNew ( data . documento . id , data . documento . opzione ) . removeClass ( " already-loaded " );
2020-09-16 15:57:49 +02:00
2022-03-04 11:50:57 +01:00
// Impostazione del riferimento
2020-09-16 15:57:49 +02:00
impostaRiferimento ( id_riga , data . documento , data . riga );
}
2020-02-24 12:21:47 +01:00
},
error : function ( data ) {
2020-09-16 15:57:49 +02:00
swal ( " '.tr('Errore').' " , " '.tr('La ricerca automatica dei riferimenti per le righe non è andata a buon fine').'. " , " error " );
2020-02-24 12:21:47 +01:00
buttonRestore ( btn , restore );
}
});
}
</ script > ' ;