2018-09-24 18:10:16 +02: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-09-24 18:10:16 +02:00
2020-09-16 15:57:49 +02:00
use Carbon\Carbon ;
2018-09-24 18:10:16 +02:00
include_once __DIR__ . '/../../core.php' ;
2019-07-24 17:17:54 +02:00
echo '
< script >
$ ( document ) . ready ( function () {
$ ( " #save " ) . hide ();
});
</ script > ' ;
2020-09-23 17:53:19 +02:00
$skip_link = $has_next ? base_path () . '/editor.php?id_module=' . $id_module . '&id_plugin=' . $id_plugin . '&id_record=' . ( $id_record + 1 ) . '&sequence=' . get ( 'sequence' ) : base_path () . '/editor.php?id_module=' . $id_module ;
2019-07-24 17:17:54 +02:00
if ( empty ( $fattura_pa )) {
if ( ! empty ( $error )) {
echo '
< p > '.tr("Errore durante l' apertura della fattura elettronica _NAME_ " , [
'_NAME_' => $record [ 'name' ],
]) . '.</p>' ;
} elseif ( ! empty ( $imported )) {
echo '
< p > '.tr(' La fattura elettrnica _NAME_ è già stata importata in passato ' , [
'_NAME_' => $record [ 'name' ],
]) . '.</p>' ;
}
echo '
< div class = " row " >
< div class = " col-md-12 text-right " > ' ;
if ( ! empty ( $imported )) {
echo '
< button type = " button " class = " btn btn-danger " onclick = " cleanup() " >
< i class = " fa fa-trash-o " ></ i > '.tr(' Processa e rimuovi ').'
</ button > ' ;
}
echo '
< button type = " button " class = " btn btn-warning " onclick = " skip() " >
< i class = " fa fa-ban " ></ i > '.tr(' Salta fattura ').'
</ button >
</ div >
</ div >
2019-11-29 18:26:02 +01:00
2019-07-24 17:17:54 +02:00
< script >
function skip () {
redirect ( " '. $skip_link .' " );
}
function cleanup (){
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " get " ,
data : {
id_module : " '. $id_module .' " ,
id_plugin : " '. $id_plugin .' " ,
op : " delete " ,
name : " '. $record['name'] .' " ,
}
2019-11-29 18:26:02 +01:00
});
2019-07-24 17:17:54 +02:00
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " get " ,
data : {
id_module : " '. $id_module .' " ,
id_plugin : " '. $id_plugin .' " ,
op : " process " ,
name : " '. $record['name'] .' " ,
}
});
2019-11-29 18:26:02 +01:00
2019-07-24 17:17:54 +02:00
skip ();
}
</ script > ' ;
return ;
}
2018-10-13 10:15:54 +02:00
// Fornitore
2019-04-19 03:18:05 +02:00
$fornitore = $fattura_pa -> getAnagrafe ();
2019-07-22 18:35:13 +02:00
2019-04-19 03:18:05 +02:00
$ragione_sociale = $fornitore [ 'ragione_sociale' ] ? : $fornitore [ 'cognome' ] . ' ' . $fornitore [ 'nome' ];
$codice_fiscale = $fornitore [ 'codice_fiscale' ];
$partita_iva = $fornitore [ 'partita_iva' ];
2018-10-13 10:15:54 +02:00
2019-04-19 03:18:05 +02:00
$sede = $fornitore [ 'sede' ];
2019-01-05 10:08:45 +01:00
2019-04-19 03:18:05 +02:00
$cap = $sede [ 'cap' ];
$citta = $sede [ 'comune' ];
$provincia = $sede [ 'provincia' ];
2019-01-05 10:08:45 +01:00
2019-01-10 19:31:26 +01:00
// Dati generali
$dati_generali = $fattura_pa -> getBody ()[ 'DatiGenerali' ][ 'DatiGeneraliDocumento' ];
2019-07-22 18:35:13 +02:00
$tipo_documento = $database -> fetchOne ( 'SELECT CONCAT("(", codice, ") ", descrizione) AS descrizione FROM fe_tipi_documento WHERE codice = ' . prepare ( $dati_generali [ 'TipoDocumento' ]))[ 'descrizione' ];
$pagamenti = $fattura_pa -> getBody ()[ 'DatiPagamento' ];
$metodi = $pagamenti [ 'DettaglioPagamento' ];
$metodi = isset ( $metodi [ 0 ]) ? $metodi : [ $metodi ];
$codice_modalita_pagamento = $metodi [ 0 ][ 'ModalitaPagamento' ];
2019-01-10 19:31:26 +01:00
2018-10-13 10:15:54 +02:00
echo '
2019-07-24 17:17:54 +02:00
< form action = " " method = " post " >
< input type = " hidden " name = " filename " value = " '. $record['name'] .' " >
2019-07-22 18:35:13 +02:00
< input type = " hidden " name = " op " value = " generate " >
2019-11-29 18:26:02 +01:00
2019-07-22 18:35:13 +02:00
< div class = " row " >
< div class = " col-md-3 " >
< h4 >
'.$ragione_sociale.'
2019-11-29 18:26:02 +01:00
2019-07-24 15:41:04 +02:00
'.(empty($anagrafica) ? ' < span class = " badge badge-success " > '.tr(' Nuova anagrafica ').' </ span > ' : ' < small > '.Modules::link(' Anagrafiche ', $anagrafica->id, ' ', null, ' ')).' </ small >< br >
2019-11-29 18:26:02 +01:00
2019-01-10 19:31:26 +01:00
< small >
'.(!empty($codice_fiscale) ? (tr(' Codice Fiscale ').' : '.$codice_fiscale.' < br > ') : ' ').'
'.(!empty($partita_iva) ? (tr(' Partita IVA ').' : '.$partita_iva.' < br > ') : ' ').'
'.$cap.' '.$citta.' ( '.$provincia.' ) < br >
</ small >
</ h4 >
</ div >
2019-11-29 18:26:02 +01:00
2019-07-22 18:35:13 +02:00
< div class = " col-md-3 " >
< h4 >
'.$dati_generali[' Numero '].'
2019-11-29 18:26:02 +01:00
2019-07-24 17:17:54 +02:00
< a href = " '. $structure->fileurl ('view.php').'?filename='. $record['name'] .' " class = " btn btn-info btn-xs " target = " _blank " >
2019-02-02 13:11:20 +01:00
< i class = " fa fa-eye " ></ i > '.tr(' Visualizza ').'
2019-07-22 18:35:13 +02:00
</ a >
2019-11-29 18:26:02 +01:00
2019-02-13 10:55:46 +01:00
< br >< small >
2019-07-22 18:35:13 +02:00
'.$tipo_documento.'
2019-01-10 19:31:26 +01:00
< br > '.Translator::dateToLocale($dati_generali[' Data ']).'
< br > '.$dati_generali[' Divisa '].'
2019-01-09 19:12:49 +01:00
</ small >
</ h4 >
2019-07-22 18:35:13 +02:00
</ div > ' ;
// Blocco DatiPagamento è valorizzato (opzionale)
if ( ! empty ( $pagamenti )) {
echo '
< div class = " col-md-6 " >
< h4 > '.tr(' Pagamento ').' </ h4 >
2019-11-29 18:26:02 +01:00
2019-07-22 18:35:13 +02:00
< p > '.tr(' La fattura importata presenta _NUM_ rat_E_ di pagamento con le seguenti scadenze ' , [
'_NUM_' => count ( $metodi ),
'_E_' => (( count ( $metodi ) > 1 ) ? 'e' : 'a' ),
]) . ' :</ p >
< ol > ' ;
// Scadenze di pagamento
foreach ( $metodi as $metodo ) {
$descrizione = ! empty ( $metodo [ 'ModalitaPagamento' ]) ? $database -> fetchOne ( 'SELECT descrizione FROM fe_modalita_pagamento WHERE codice = ' . prepare ( $metodo [ 'ModalitaPagamento' ]))[ 'descrizione' ] : '' ;
$data = ! empty ( $metodo [ 'DataScadenzaPagamento' ]) ? Translator :: dateToLocale ( $metodo [ 'DataScadenzaPagamento' ]) . ' ' : '' ;
echo '
< li >
'.$data.'
'.moneyFormat($metodo[' ImportoPagamento ']).'
( '.$descrizione.' )
</ li > ' ;
}
echo '
</ ol >
</ div > ' ;
}
echo '
2019-01-09 19:12:49 +01:00
</ div > ' ;
2018-10-13 10:15:54 +02:00
2019-01-10 19:31:26 +01:00
// Tipo del documento
2019-07-22 18:35:13 +02:00
$query = " SELECT id, CONCAT (descrizione, IF((codice_tipo_documento_fe IS NULL), '', CONCAT(' (', codice_tipo_documento_fe, ')' ) )) AS descrizione FROM co_tipidocumento WHERE dir = 'uscita' " ;
$query_tipo = $query . ' AND codice_tipo_documento_fe = ' . prepare ( $dati_generali [ 'TipoDocumento' ]);
if ( $database -> fetchNum ( $query_tipo )) {
$query = $query_tipo ;
2019-01-10 19:31:26 +01:00
}
2019-07-22 18:35:13 +02:00
2019-01-10 19:31:26 +01:00
echo '
2019-07-22 11:35:44 +02:00
< div class = " row " >
2019-07-22 18:35:13 +02:00
< div class = " col-md-3 " >
2019-01-10 19:31:26 +01:00
{[ " type " : " select " , " label " : " '.tr('Tipo fattura').' " , " name " : " id_tipo " , " required " : 1 , " values " : " query='. $query .' " ]}
</ div > ' ;
2019-01-10 18:41:25 +01:00
2019-01-10 19:31:26 +01:00
// Sezionale
echo '
2019-07-22 18:35:13 +02:00
< div class = " col-md-3 " >
2019-07-24 17:17:54 +02:00
{[ " type " : " select " , " label " : " '.tr('Sezionale').' " , " name " : " id_segment " , " required " : 1 , " values " : " query=SELECT id, name AS descrizione FROM zz_segments WHERE is_fiscale = 1 AND id_module='. $id_module .' ORDER BY name " , " value " : " '. $_SESSION['module_'.$id_module] ['id_segment'].' " ]}
2019-07-22 18:35:13 +02:00
</ div > ' ;
2019-01-10 19:31:26 +01:00
2019-07-22 18:35:13 +02:00
// Data di registrazione
2019-09-20 17:59:27 +02:00
$data_registrazione = get ( 'data_registrazione' );
2020-09-16 15:57:49 +02:00
$data_registrazione = new Carbon ( $data_registrazione );
2019-05-13 19:21:46 +02:00
echo '
2019-07-22 18:35:13 +02:00
< div class = " col-md-3 " >
2019-10-16 11:11:09 +02:00
{[ " type " : " date " , " label " : " '.tr('Data di registrazione').' " , " name " : " data_registrazione " , " required " : 1 , " value " : " '.( $data_registrazione ?: $dati_generali['Data'] ).' " , " max-date " : " -now- " , " min-date " : " '. $dati_generali['Data'] .' " ]}
2019-07-22 11:35:44 +02:00
</ div > ' ;
2019-07-22 18:35:13 +02:00
if ( ! empty ( $anagrafica )) {
2019-07-22 11:35:44 +02:00
$query = " SELECT
2019-07-22 18:35:13 +02:00
co_documenti . id ,
CONCAT ( 'Fattura num. ' , co_documenti . numero_esterno , ' del ' , DATE_FORMAT ( co_documenti . data , '%d/%m/%Y' )) AS descrizione
FROM co_documenti
INNER JOIN co_tipidocumento ON co_tipidocumento . id = co_documenti . idtipodocumento
WHERE
co_tipidocumento . dir = 'uscita' AND
( co_documenti . data BETWEEN NOW () - INTERVAL 1 YEAR AND NOW ()) AND
co_documenti . idstatodocumento IN ( SELECT id FROM co_statidocumento WHERE descrizione != 'Bozza' ) AND
co_documenti . idanagrafica = " .prepare( $anagrafica->id );
// Riferimenti ad altre fatture
if ( in_array ( $dati_generali [ 'TipoDocumento' ], [ 'TD04' , 'TD05' ])) {
echo '
< div class = " col-md-3 " >
2019-07-22 11:35:44 +02:00
{[ " type " : " select " , " label " : " '.tr('Fattura collegata').' " , " name " : " ref_fattura " , " required " : 1 , " values " : " query='. $query .' " ]}
</ div > ' ;
2019-07-22 18:35:13 +02:00
} elseif ( $dati_generali [ 'TipoDocumento' ] == 'TD06' ) {
$query .= " AND co_documenti.id_segment = (SELECT id FROM zz_segments WHERE name = 'Fatture pro-forma' AND id_module = " . prepare ( $id_module ) . ')' ;
2019-07-22 11:35:44 +02:00
2019-07-22 18:35:13 +02:00
echo '
< div class = " col-md-3 " >
2019-07-22 12:52:48 +02:00
{[ " type " : " select " , " label " : " '.tr('Fattura pro-forma').' " , " name " : " ref_fattura " , " values " : " query='. $query .' " ]}
2019-07-22 11:35:44 +02:00
</ div > ' ;
2019-07-22 18:35:13 +02:00
}
2019-07-22 11:35:44 +02:00
}
echo '
2019-05-13 19:21:46 +02:00
</ div > ' ;
2019-02-21 17:14:37 +01:00
// Pagamento
2018-10-13 10:15:54 +02:00
echo '
2019-02-21 17:14:37 +01:00
< div class = " row " >
< div class = " col-md-6 " >
2020-08-17 10:57:51 +02:00
< button type = " button " class = " btn btn-info btn-xs pull-right " onclick = " updateSelectOption( \ 'codice_modalita_pagamento_fe \ ', \ ' \ ') " >
2019-10-03 11:24:58 +02:00
< i class = " fa fa-refresh " ></ i > '.tr(' Visualizza tutte le modalità ').'
2019-07-22 12:52:48 +02:00
</ button >
2019-11-29 18:26:02 +01:00
2020-08-26 10:44:36 +02:00
{[ " type " : " select " , " label " : " '.tr('Pagamento').' " , " name " : " pagamento " , " required " : 1 , " ajax-source " : " pagamenti " , " select-options " : '.json_encode([' codice_modalita_pagamento_fe ' => $codice_modalita_pagamento]).' ]}
2019-02-21 17:14:37 +01:00
</ div > ' ;
// Movimentazioni
echo '
2019-10-18 16:40:15 +02:00
< div class = " col-md-3 " >
2019-02-21 17:14:37 +01:00
{[ " type " : " checkbox " , " label " : " '.tr('Movimenta gli articoli').' " , " name " : " movimentazione " , " value " : 1 ]}
</ div >
2019-11-29 18:26:02 +01:00
2019-10-18 16:40:15 +02:00
< div class = " col-md-3 " >
{[ " type " : " checkbox " , " label " : " '.tr('Creazione automatica articoli').' " , " name " : " crea_articoli " , " value " : 0 , " help " : " '.tr( " Nel caso di righe con tag CodiceArticolo , il gestionale procede alla creazione dell 'articolo se la riga non risulta assegnata manualmente").' " ]}
</ div >
2019-02-21 17:14:37 +01:00
</ div > ' ;
2018-09-24 18:10:16 +02:00
2018-10-13 10:15:54 +02:00
// Righe
$righe = $fattura_pa -> getRighe ();
2018-09-24 18:10:16 +02:00
if ( ! empty ( $righe )) {
echo '
2018-12-07 10:56:49 +01:00
< h4 >
'.tr(' Righe ').'
2019-04-18 13:08:03 +02:00
< button type = " button " class = " btn btn-info btn-sm pull-right " onclick = " copy() " >< i class = " fa fa-copy " ></ i > '.tr(' Copia dati contabili dalla prima riga valorizzata ').' </ button >
2018-12-19 23:26:28 +01:00
< div class = " clearfix " ></ div >
2018-12-07 10:56:49 +01:00
</ h4 >
2018-10-13 10:15:54 +02:00
2018-10-29 22:23:29 +01:00
< div class = " table-responsive " >
2020-09-03 11:55:15 +02:00
< table class = " table table-striped table-hover table-condensed table-bordered " >
< thead >
< tr >
< th > '.tr(' Descrizione ').' </ th >
< th class = " text-center " width = " 10% " > '.tr(' Quantità ').' </ th >
< th class = " text-center " width = " 10% " > '.tr(' Prezzo unitario ').' </ th >
< th class = " text-center " width = " 10% " > '.tr(' Aliquota ').' </ th >
</ tr >
</ thead >
< tbody > ' ;
2018-09-24 18:10:16 +02:00
foreach ( $righe as $key => $riga ) {
2020-09-16 15:57:49 +02:00
$query = " SELECT id, IF(codice IS NULL, descrizione, CONCAT(codice, ' - ', descrizione)) AS descrizione FROM co_iva WHERE percentuale = " . prepare ( $riga [ 'AliquotaIVA' ]);
2018-09-25 11:55:52 +02:00
if ( ! empty ( $riga [ 'Natura' ])) {
$query .= ' AND codice_natura_fe = ' . prepare ( $riga [ 'Natura' ]);
}
$query .= ' ORDER BY descrizione ASC' ;
2019-05-10 17:14:34 +02:00
2019-10-18 15:28:44 +02:00
// Visualizzazione codici articoli
$codici = $riga [ 'CodiceArticolo' ] ? : [];
$codici = ! empty ( $codici ) && ! isset ( $codici [ 0 ]) ? [ $codici ] : $codici ;
2019-05-10 17:14:34 +02:00
2019-10-18 15:28:44 +02:00
$codici_articoli = [];
foreach ( $codici as $codice ) {
$codici_articoli [] = $codice [ 'CodiceValore' ] . ' (' . $codice [ 'CodiceTipo' ] . ')' ;
2019-05-10 17:14:34 +02:00
}
2019-10-18 15:28:44 +02:00
// Individuazione articolo con codice relativo
2020-04-27 10:24:03 +02:00
$id_articolo = null ;
2019-10-18 16:40:15 +02:00
$codice_principale = $codici [ 0 ][ 'CodiceValore' ];
2020-04-27 10:24:03 +02:00
if ( ! empty ( $codice_principale )) {
2020-09-16 15:57:49 +02:00
if ( ! empty ( $anagrafica ) && empty ( $id_articolo )) {
$id_articolo = $database -> fetchOne ( 'SELECT id_articolo AS id FROM mg_fornitore_articolo WHERE codice_fornitore = ' . prepare ( $codice_principale ) . ' AND id_fornitore = ' . prepare ( $anagrafica -> id ))[ 'id' ];
}
if ( empty ( $id_articolo )) {
$id_articolo = $database -> fetchOne ( 'SELECT id FROM mg_articoli WHERE codice = ' . prepare ( $codice_principale ))[ 'id' ];
}
2020-04-27 10:24:03 +02:00
}
2019-10-18 15:28:44 +02:00
2020-09-03 11:55:15 +02:00
$qta = $riga [ 'Quantita' ];
$um = $riga [ 'UnitaMisura' ];
$prezzo_unitario = $riga [ 'PrezzoUnitario' ];
2018-09-24 18:10:16 +02:00
echo '
2020-09-03 14:29:17 +02:00
< tr data - id = " '. $key .' " data - qta = " '. $qta .' " data - prezzo_unitario = " '. $prezzo_unitario .' " data - iva_percentuale = " '. $riga['AliquotaIVA'] .' " >
2019-03-01 13:11:08 +01:00
< td >
2020-09-16 09:14:00 +02:00
< small class = " pull-right text-muted " id = " riferimento_'. $key .' " ></ small >
2019-03-01 13:11:08 +01:00
'.$riga[' Descrizione '].' < br >
2019-11-29 18:26:02 +01:00
2019-10-18 15:28:44 +02:00
'.(!empty($codici_articoli) ? ' < small > '.implode(' , ', $codici_articoli).' </ small >< br > ' : ' ').'
2020-09-16 09:14:00 +02:00
< b id = " riferimento_'. $key .'_descrizione " ></ b >
2020-09-03 11:55:15 +02:00
</ td >
2019-11-29 18:26:02 +01:00
2020-09-03 11:55:15 +02:00
< td class = " text-center " >
'.numberFormat($qta, ' qta ').' '.$um.'
< span id = " riferimento_'. $key .'_qta " ></ span >
</ td >
2019-11-29 18:26:02 +01:00
2020-09-03 11:55:15 +02:00
< td class = " text-right " >
'.moneyFormat($prezzo_unitario).'
< span id = " riferimento_'. $key .'_prezzo " ></ span >
</ td >
2019-11-29 18:26:02 +01:00
2020-09-03 11:55:15 +02:00
< td class = " text-right " >
'.replace(' _VALUE_ _DESC_ ' , [
2020-09-07 15:50:33 +02:00
'_VALUE_' => empty ( $riga [ 'Natura' ]) ? numberFormat ( $riga [ 'AliquotaIVA' ], 0 ) . '%' : $riga [ 'Natura' ],
2019-03-01 13:11:08 +01:00
'_DESC_' => $riga [ 'RiferimentoNormativo' ] ? ' - ' . $riga [ 'RiferimentoNormativo' ] : '' ,
2020-09-03 11:55:15 +02:00
]) . '
2020-09-03 14:29:17 +02:00
< span id = " riferimento_'. $key .'_iva " ></ span >
2018-10-29 22:23:29 +01:00
</ td >
2020-09-03 11:55:15 +02:00
</ tr >
2020-02-24 18:30:05 +01:00
2020-09-03 11:55:15 +02:00
< tr id = " dati_'. $key .' " >
< td colspan = " 4 " class = " row " >
< span class = " hide " id = " aliquota['. $key .'] " > '.$riga[' AliquotaIVA '].' </ span >
2020-02-24 18:30:05 +01:00
< input type = " hidden " name = " qta_riferimento['. $key .'] " id = " qta_riferimento_'. $key .' " value = " '. $riga['Quantita'] .' " >
< input type = " hidden " name = " tipo_riferimento['. $key .'] " id = " tipo_riferimento_'. $key .' " value = " " >
< input type = " hidden " name = " id_riferimento['. $key .'] " id = " id_riferimento_'. $key .' " value = " " >
< input type = " hidden " name = " id_riga_riferimento['. $key .'] " id = " id_riga_riferimento_'. $key .' " value = " " >
< input type = " hidden " name = " tipo_riga_riferimento['. $key .'] " id = " tipo_riga_riferimento_'. $key .' " value = " " >
2020-09-03 11:55:15 +02:00
< div class = " col-md-3 " >
{[ " type " : " select " , " name " : " articoli['. $key .'] " , " ajax-source " : " articoli " , " select-options " : '.json_encode([' permetti_movimento_a_zero ' => 1, ' dir ' => ' entrata ', ' idanagrafica ' => $anagrafica ? $anagrafica->id : ' ']).' , " icon-after " : " add|'.Modules::get('Articoli')['id'].'|codice='.htmlentities( $codice_principale ).'&descrizione='.htmlentities( $riga['Descrizione'] ).' " , " value " : " '. $id_articolo .' " , " label " : " '.tr('Articolo').' " ]}
</ div >
< div class = " col-md-3 " >
{[ " type " : " select " , " name " : " conto['. $key .'] " , " ajax-source " : " conti-acquisti " , " required " : 1 , " label " : " '.tr('Conto acquisti').' " ]}
</ div >
< div class = " col-md-3 " >
{[ " type " : " select " , " name " : " iva['. $key .'] " , " values " : '.json_encode(' query = '.$query).' , " required " : 1 , " label " : " '.tr('Aliquota IVA').' " ]}
</ div >
< div class = " col-md-3 " >
2020-09-10 09:53:00 +02:00
{[ " type " : " select " , " name " : " selezione_riferimento['. $key .'] " , " ajax-source " : " riferimenti-fe " , " select-options " : '.json_encode([' id_anagrafica ' => $anagrafica ? $anagrafica->id : ' ']).' , " required " : 0 , " label " : " '.tr('Riferimento').' " , " icon-after " : '.json_encode(' < button type = " button " onclick = " rimuoviRiferimento(this) " class = " btn btn-primary disabled " id = " rimuovi_riferimento_'. $key .' " >< i class = " fa fa-close " ></ i ></ button > ').' ]}
2020-09-03 11:55:15 +02:00
</ div >
2018-09-24 18:10:16 +02:00
</ td >
</ tr > ' ;
}
echo '
2020-09-03 11:55:15 +02:00
</ tbody >
2018-10-29 22:23:29 +01:00
</ table >
</ div > ' ;
2018-12-07 10:56:49 +01:00
echo '
< script >
2020-09-03 11:55:15 +02:00
function copy () {
2020-09-03 14:29:17 +02:00
let aliquote = $ ( " select[name^=iva " );
let conti = $ ( " select[name^=conto " );
// Individuazione della prima IVA selezionata
let iva_selezionata = null ;
for ( const aliquota of aliquote ) {
const data = $ ( aliquota ) . selectData ();
2020-09-07 15:50:33 +02:00
if ( data && data . id ) {
2020-09-03 14:29:17 +02:00
iva_selezionata = data ;
break ;
2019-04-18 13:08:03 +02:00
}
2020-09-03 14:29:17 +02:00
}
2019-04-18 13:08:03 +02:00
2020-09-03 14:29:17 +02:00
// Individuazione del primo conto selezionato
let conto_selezionato = null ;
for ( const conto of conti ) {
const data = $ ( conto ) . selectData ();
2020-09-07 15:50:33 +02:00
if ( data && data . id ) {
2020-09-03 14:29:17 +02:00
conto_selezionato = data ;
break ;
2019-04-18 13:08:03 +02:00
}
2020-09-03 14:29:17 +02:00
}
2018-12-07 10:56:49 +01:00
2020-09-03 14:29:17 +02:00
// Selezione generale per l\'IVA
if ( iva_selezionata ) {
aliquote . each ( function () {
$ ( this ) . selectSet ( iva_selezionata . id );
2018-12-07 10:56:49 +01:00
});
}
2020-09-03 14:29:17 +02:00
// Selezione generale per il conto
if ( conto_selezionato ) {
conti . each ( function () {
$ ( this ) . selectSetNew ( conto_selezionato . id , conto_selezionato . text , conto_selezionato );
2018-12-07 10:56:49 +01:00
});
}
}
</ script > ' ;
2018-09-24 18:10:16 +02:00
} else {
echo '
2018-12-07 10:56:49 +01:00
< p > '.tr(' Non ci sono righe nella fattura ').' .</ p > ' ;
2018-09-24 18:10:16 +02:00
}
echo '
< div class = " row " >
< div class = " col-md-12 text-right " >
2019-07-24 17:17:54 +02:00
< a href = " '. $skip_link .' " class = " btn btn-warning " >
< i class = " fa fa-ban " ></ i > '.tr(' Salta fattura ').'
</ a >
2019-11-29 18:26:02 +01:00
2018-09-24 18:10:16 +02:00
< button type = " submit " class = " btn btn-primary " >
< i class = " fa fa-arrow-right " ></ i > '.tr(' Continua ').' ...
</ button >
</ div >
</ div >
2020-02-24 18:30:05 +01:00
</ form >
< script >
2020-09-03 11:55:15 +02:00
$ ( " select[name^=selezione_riferimento " ) . change ( function () {
let $this = $ ( this );
let data = $this . selectData ();
2020-02-24 18:30:05 +01:00
2020-09-03 11:55:15 +02:00
if ( data ) {
let riga = $this . closest ( " tr " ) . prev ();
selezionaRiferimento ( riga , data . tipo , data . id );
}
});
2020-02-24 18:30:05 +01:00
2020-09-03 13:54:43 +02:00
function rimuoviRiferimento ( button ) {
let riga = $ ( button ) . closest ( " tr " ) . prev ();
let id_riga = riga . data ( " id " );
impostaRiferimento ( id_riga , {}, {});
2020-02-24 18:30:05 +01:00
2020-09-03 13:54:43 +02:00
input ( " selezione_riferimento[ " + id_riga + " ] " ) . enable ()
. getElement () . selectReset ();
$ ( button ) . addClass ( " disabled " );
2020-09-16 09:14:00 +02:00
riga . removeClass ( " success " ) . removeClass ( " warning " );
2020-02-24 18:30:05 +01:00
}
2020-09-03 11:55:15 +02:00
function selezionaRiferimento ( riga , tipo_documento , id_documento ) {
let id_riga = riga . data ( " id " );
let qta = riga . data ( " qta " );
let riferimenti = getRiferimenti ();
let query = {
id_module : " '. $id_module .' " ,
id_record : " '. $id_record .' " ,
qta : qta ,
id_riga : id_riga ,
id_documento : id_documento ,
tipo_documento : tipo_documento ,
righe_ddt : riferimenti . ddt ,
righe_ordini : riferimenti . ordini ,
};
2020-09-03 14:29:17 +02:00
let url = " '. $structure->fileurl ('riferimento.php').'? " + $ . param ( query );
2020-09-03 11:55:15 +02:00
openModal ( " '.tr('Selezione riferimento').' " , url );
2020-02-24 18:30:05 +01:00
}
2020-09-03 11:55:15 +02:00
function getRiferimenti () {
let righe_ordini = {};
let righe_ddt = {};
$ ( " [id^=tipo_riferimento_] " ) . each ( function ( index , item ) {
let tipo = $ ( item ) . val ();
let riga = $ ( item ) . closest ( " tr " );
let qta = parseFloat ( riga . find ( " [id^=qta_riferimento_] " ) . val ());
let id_riga = riga . find ( " [id^=id_riga_riferimento_] " ) . val ();
if ( tipo === " ordine " ) {
righe_ordini [ id_riga ] = righe_ordini [ id_riga ] ? righe_ordini [ id_riga ] : 0 ;
righe_ordini [ id_riga ] += qta ;
} else if ( tipo === " ddt " ) {
righe_ddt [ id_riga ] = righe_ddt [ id_riga ] ? righe_ddt [ id_riga ] : 0 ;
righe_ddt [ id_riga ] += qta ;
}
});
2020-02-24 18:30:05 +01:00
2020-09-03 11:55:15 +02:00
return {
ordini : righe_ordini ,
ddt : righe_ddt ,
};
}
2020-02-24 18:30:05 +01:00
2020-09-03 11:55:15 +02:00
/**
*
* @ param id_riga
* @ param documento = { tipo , id , descrizione }
* @ param riga = { tipo , id , descrizione , qta , prezzo_unitario }
*/
function impostaRiferimento ( id_riga , documento , riga ) {
2020-09-03 14:29:17 +02:00
// Informazioni interne per il riferimento
2020-09-03 11:55:15 +02:00
$ ( " #tipo_riferimento_ " + id_riga ) . val ( documento . tipo );
$ ( " #id_riferimento_ " + id_riga ) . val ( documento . id );
$ ( " #tipo_riga_riferimento_ " + id_riga ) . val ( riga . tipo );
$ ( " #id_riga_riferimento_ " + id_riga ) . val ( riga . id );
2020-09-03 14:29:17 +02:00
// Gestione della selezione
2020-09-03 13:54:43 +02:00
input ( " selezione_riferimento[ " + id_riga + " ] " ) . disable ();
$ ( " #rimuovi_riferimento_ " + id_riga ) . removeClass ( " disabled " );
2020-02-24 18:30:05 +01:00
2020-09-03 14:29:17 +02:00
let riga_fe = $ ( " #id_riga_riferimento_ " + id_riga ) . closest ( " tr " ) . prev ();
2020-09-07 15:17:58 +02:00
// Informazioni visibili sulla quantità
2020-09-11 08:55:39 +02:00
impostaContenuto ( riga_fe . data ( " qta " ), riga . qta , ( riga . um ? " " + riga . um : " " ), " #riferimento_ " + id_riga + " _qta " );
2020-09-03 14:29:17 +02:00
2020-09-07 15:17:58 +02:00
// Informazioni visibili sul prezzo unitario
2020-09-11 08:55:39 +02:00
impostaContenuto ( riga_fe . data ( " prezzo_unitario " ), riga . prezzo_unitario , " " + globals . currency , " #riferimento_ " + id_riga + " _prezzo " );
2020-09-07 15:17:58 +02:00
// Informazioni visibili sull\'aliquota IVA
2020-09-11 08:55:39 +02:00
impostaContenuto ( riga_fe . data ( " iva_percentuale " ), riga . iva_percentuale , " % " , " #riferimento_ " + id_riga + " _iva " );
2020-09-07 15:17:58 +02:00
$ ( " #riferimento_ " + id_riga ) . html ( documento . descrizione ? documento . descrizione : " " );
2020-09-16 09:14:00 +02:00
$ ( " #riferimento_ " + id_riga + " _descrizione " ) . html ( riga . descrizione ? riga . descrizione : " " );
// Colorazione dell\'intera riga
let warnings = riga_fe . find ( " .text-warning " );
if ( warnings . length === 0 ) {
riga_fe . addClass ( " success " ) . removeClass ( " warning " );
} else {
riga_fe . removeClass ( " success " ) . addClass ( " warning " );
}
2020-09-07 15:17:58 +02:00
}
// Informazioni visibili sull\'aliquota IVA
2020-09-11 08:55:39 +02:00
function impostaContenuto ( valore_riga , valore_riferimento , contenuto_successivo , id_elemento ) {
2020-09-07 15:17:58 +02:00
let elemento = $ ( id_elemento );
2020-09-11 08:55:39 +02:00
if ( valore_riferimento === undefined ) {
2020-09-07 15:17:58 +02:00
elemento . html ( " " );
return ;
2020-09-03 14:29:17 +02:00
}
2020-09-07 15:17:58 +02:00
valore_riga = parseFloat ( valore_riga );
valore_riferimento = parseFloat ( valore_riferimento );
2020-09-11 08:55:39 +02:00
let contenuto = valore_riferimento . toLocale () + contenuto_successivo ;
2020-09-07 15:17:58 +02:00
if ( valore_riferimento === valore_riga ) {
2020-09-11 08:55:39 +02:00
contenuto = `<i class="fa fa-check"></i> ` + contenuto ;
2020-09-07 15:17:58 +02:00
elemento . addClass ( " text-success " ) . removeClass ( " text-warning " );
2020-09-03 14:29:17 +02:00
} else {
2020-09-11 08:55:39 +02:00
contenuto = `<i class="fa fa-warning"></i> ` + contenuto ;
2020-09-07 15:17:58 +02:00
elemento . removeClass ( " text-success " ) . addClass ( " text-warning " );
2020-09-03 14:29:17 +02:00
}
2020-02-24 18:30:05 +01:00
2020-09-07 15:17:58 +02:00
elemento . html ( " <br> " + contenuto );
2020-02-24 18:30:05 +01:00
}
</ script > ' ;