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
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 />.
*/
2018-09-24 18:10:16 +02:00
2020-09-16 15:57:49 +02:00
use Carbon\Carbon ;
2020-10-09 16:43:07 +02:00
use Plugins\ImportFE\FatturaElettronica ;
2020-09-16 15:57:49 +02:00
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 () {
2021-03-15 11:10:46 +01:00
$ ( " #save-buttons " ) . hide ();
2019-07-24 17:17:54 +02:00
});
</ 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
2021-01-28 20:24:32 +01:00
$fattura_body = $fattura_pa -> getBody ();
$dati_generali = $fattura_body [ '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' ];
2021-01-28 20:24:32 +01:00
// Gestione per fattura elettroniche senza pagamento definito
$pagamenti = [];
if ( isset ( $fattura_body [ 'DatiPagamento' ])) {
2021-02-18 18:48:44 +01:00
$pagamenti = $fattura_body [ 'DatiPagamento' ];
2021-01-28 20:24:32 +01:00
$pagamenti = isset ( $pagamenti [ 0 ]) ? $pagamenti : [ $pagamenti ];
}
// Individuazione metodo di pagamento di base
$metodi = isset ( $pagamenti [ 0 ][ 'DettaglioPagamento' ]) ? $pagamenti [ 0 ][ 'DettaglioPagamento' ] : [];
2019-07-22 18:35:13 +02:00
$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 ' , [
2021-01-28 20:24:32 +01:00
'_NUM_' => count ( $metodi ),
'_E_' => (( count ( $metodi ) > 1 ) ? 'e' : 'a' ),
]) . ' :</ p >
2019-07-22 18:35:13 +02:00
< ol > ' ;
2020-12-04 17:40:25 +01:00
foreach ( $pagamenti as $pagamento ) {
$rate = $pagamento [ 'DettaglioPagamento' ];
$rate = isset ( $rate [ 0 ]) ? $rate : [ $rate ];
2019-07-22 18:35:13 +02:00
2020-12-04 17:40:25 +01:00
// Scadenze di pagamento
foreach ( $rate as $rata ) {
$descrizione = ! empty ( $rata [ 'ModalitaPagamento' ]) ? $database -> fetchOne ( 'SELECT descrizione FROM fe_modalita_pagamento WHERE codice = ' . prepare ( $rata [ 'ModalitaPagamento' ]))[ 'descrizione' ] : '' ;
$data = ! empty ( $rata [ 'DataScadenzaPagamento' ]) ? FatturaElettronica :: parseDate ( $rata [ 'DataScadenzaPagamento' ]) : '' ;
echo '
2019-07-22 18:35:13 +02:00
< li >
2020-10-09 16:43:07 +02:00
'.dateFormat($data).'
2020-12-04 17:40:25 +01:00
'.moneyFormat($rata[' ImportoPagamento ']).'
2019-07-22 18:35:13 +02:00
( '.$descrizione.' )
</ li > ' ;
2020-12-04 17:40:25 +01:00
}
2019-07-22 18:35:13 +02:00
}
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' ]);
2021-03-08 11:24:54 +01:00
$numero_tipo = $database -> fetchNum ( $query_tipo );
if ( ! empty ( $numero_tipo )) {
2019-07-22 18:35:13 +02:00
$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 " >
2021-03-08 11:24:54 +01:00
{[ " type " : " select " , " label " : " '.tr('Tipo fattura').' " , " name " : " id_tipo " , " required " : 1 , " values " : " query='. $query .' " , " value " : " '.( $numero_tipo == 1 ? $database->fetchOne ( $query_tipo )['id'] : '').' " ]}
2019-01-10 19:31:26 +01:00
</ 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 " >
2021-02-05 15:38:35 +01:00
{[ " type " : " select " , " label " : " '.tr('Fattura collegata').' " , " name " : " ref_fattura " , " required " : 0 , " values " : " query='. $query .' " ]}
2019-07-22 11:35:44 +02:00
</ 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 " >
2021-02-04 13:19:14 +01:00
{[ " type " : " select " , " label " : " '.tr('Collega a 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 " >
2021-02-04 13:19:14 +01:00
< div class = " col-md-3 " >
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").' " ]}
2021-02-04 13:19:14 +01:00
</ div > ' ;
$ritenuta = $dati_generali [ 'DatiRitenuta' ];
2021-02-18 18:48:44 +01:00
if ( ! empty ( $ritenuta )) {
2021-02-04 13:19:14 +01:00
echo '
< div class = " col-md-3 " >
2021-02-18 18:48:44 +01:00
{[ " type " : " checkbox " , " label " : " '.tr('Ritenuta pagata dal fornitore').' " , " name " : " is_ritenuta_pagata " , " value " : 0 , " help " : " '.tr('Attivare se la ritenuta è stata pagata dal fornitore').' " ]}
2021-02-04 13:19:14 +01:00
</ div > ' ;
}
echo '
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 ) {
2021-01-04 16:31:35 +01:00
$query = " SELECT id, IF(codice IS NULL, descrizione, CONCAT(codice, ' - ', descrizione)) AS descrizione FROM co_iva WHERE deleted_at IS NULL AND percentuale = " . prepare ( $riga [ 'AliquotaIVA' ]);
2021-01-04 19:22:11 +01:00
$start_query = $query ;
2018-09-25 11:55:52 +02:00
if ( ! empty ( $riga [ 'Natura' ])) {
2021-01-04 16:31:35 +01:00
$query .= ' AND codice_natura_fe = ' . prepare ( $riga [ 'Natura' ]);
2021-01-04 19:22:11 +01:00
// Fallback per natura iva mancante
2021-02-18 18:48:44 +01:00
if ( empty ( $dbo -> fetchArray ( $query ))) {
2021-01-04 19:22:11 +01:00
$query = $start_query ;
}
2018-09-25 11:55:52 +02:00
}
$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' ];
2021-09-27 17:02:33 +02:00
if ( empty ( $id_articolo )) {
$id_articolo = $database -> fetchOne ( 'SELECT id_articolo AS id FROM mg_fornitore_articolo WHERE REPLACE(codice_fornitore, " ", "") = ' . prepare ( $codice_principale ) . ' AND id_fornitore = ' . prepare ( $anagrafica -> id ))[ 'id' ];
}
2020-09-16 15:57:49 +02:00
}
2021-09-27 17:02:33 +02:00
2020-09-16 15:57:49 +02:00
if ( empty ( $id_articolo )) {
$id_articolo = $database -> fetchOne ( 'SELECT id FROM mg_articoli WHERE codice = ' . prepare ( $codice_principale ))[ 'id' ];
2021-09-27 17:02:33 +02:00
if ( empty ( $id_articolo )) {
$id_articolo = $database -> fetchOne ( 'SELECT id FROM mg_articoli WHERE REPLACE(codice, " ", "") = ' . prepare ( $codice_principale ))[ 'id' ];
}
2020-09-16 15:57:49 +02:00
}
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' ];
2020-11-13 15:49:26 +01:00
$prezzo_unitario = $riga [ 'PrezzoUnitario' ] ? : $riga [ 'Importo' ];
2020-09-03 11:55:15 +02:00
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 >
2021-03-02 11:57:53 +01:00
'.(empty($codice_principale) ? ' < span class = " label label-warning pull-right text-muted articolo-warning hidden " > '.tr(' Creazione automatica articolo non disponibile ').' </ span > ' : ' ').'
2020-09-16 09:14:00 +02:00
< small class = " pull-right text-muted " id = " riferimento_'. $key .' " ></ small >
2021-02-26 18:45:52 +01:00
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
2021-02-18 17:46:38 +01:00
< input type = " hidden " name = " tipo_riferimento_vendita['. $key .'] " id = " tipo_riferimento_vendita_'. $key .' " value = " " >
< input type = " hidden " name = " id_riferimento_vendita['. $key .'] " id = " id_riferimento_vendita_'. $key .' " value = " " >
< input type = " hidden " name = " id_riga_riferimento_vendita['. $key .'] " id = " id_riga_riferimento_vendita_'. $key .' " value = " " >
< input type = " hidden " name = " tipo_riga_riferimento_vendita['. $key .'] " id = " tipo_riga_riferimento_vendita_'. $key .' " value = " " >
< div class = " col-md-12 " >
< div class = " row " >
< div class = " col-md-6 " >
2021-09-09 11:18:13 +02:00
{[ " 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='.str_replace(' \\ ', '/', htmlentities( $codice_principale )).'&descrizione='.str_replace(' \\ ', '/', str_replace(' \ '', '‘', htmlentities( $riga['Descrizione'] ))).' " , " value " : " '. $id_articolo .' " , " label " : " '.tr('Articolo').' " ]}
2021-02-18 17:46:38 +01:00
</ 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 >
< div class = " row " >
< div class = " col-md-3 " >
2021-02-23 11:34:37 +01:00
{[ " type " : " select " , " name " : " selezione_riferimento['. $key .'] " , " ajax-source " : " riferimenti-fe " , " select-options " : '.json_encode([' id_anagrafica ' => $anagrafica ? $anagrafica->id : ' ']).' , " label " : " '.tr('Riferimento acquisto').' " , " 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 > ').' , " help " : " '.tr('Articoli contenuti in Ordini o DDT del Fornitore').' " ]}
2021-02-18 17:46:38 +01:00
</ div >
2021-02-23 11:34:37 +01:00
2021-02-18 17:46:38 +01:00
< div class = " col-md-3 " >
2021-02-23 11:34:37 +01:00
{[ " type " : " select " , " name " : " selezione_riferimento_vendita['. $key .'] " , " ajax-source " : " riferimenti-vendita-fe " , " select-options " : '.json_encode([' id_articolo ' => $id_articolo]).' , " label " : " '.tr('Riferimento vendita').' " , " icon-after " : '.json_encode(' < button type = " button " onclick = " rimuoviRiferimentoVendita(this) " class = " btn btn-primary disabled " id = " rimuovi_riferimento_vendita_'. $key .' " >< i class = " fa fa-close " ></ i ></ button > ').' , " help " : " '.tr('Articoli contenuti in Ordini Cliente').' " ]}
2021-02-18 17:46:38 +01:00
</ div >
</ div >
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 >
2021-02-26 18:45:52 +01:00
input ( " crea_articoli " ) . on ( " change " , function (){
if ( input ( " crea_articoli " ) . get ()) {
$ ( " .articolo-warning " ) . removeClass ( " hidden " );
} else {
$ ( " .articolo-warning " ) . addClass ( " hidden " );
}
});
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 ();
2021-02-18 17:46:38 +01:00
selezionaRiferimento ( riga , data . tipo , data . id , data . dir );
2020-09-03 11:55:15 +02:00
}
});
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
}
2021-02-18 17:46:38 +01:00
function selezionaRiferimento ( riga , tipo_documento , id_documento , dir ) {
2020-09-03 11:55:15 +02:00
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 ,
2021-02-18 17:46:38 +01:00
dir : dir ,
2020-09-03 11:55:15 +02:00
};
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 : " " );
2021-02-23 11:34:37 +01:00
2021-02-18 17:46:38 +01:00
var descrizione = riga . descrizione ;
console . log ( descrizione );
if ( typeof descrizione !== " undefined " ){
descrizione = descrizione . replace ( / _ / g , " " );
}
$ ( " #riferimento_ " + id_riga + " _descrizione " ) . html ( descrizione ? descrizione : " " );
2020-09-16 09:14:00 +02:00
// 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
}
2021-02-18 17:46:38 +01:00
function impostaRiferimentoVendita ( id_riga , documento , riga ) {
// Informazioni interne per il riferimento
$ ( " #tipo_riferimento_vendita_ " + id_riga ) . val ( documento . tipo );
$ ( " #id_riferimento_vendita_ " + id_riga ) . val ( documento . id );
$ ( " #tipo_riga_riferimento_vendita_ " + id_riga ) . val ( riga . tipo );
$ ( " #id_riga_riferimento_vendita_ " + id_riga ) . val ( riga . id );
// Gestione della selezione
input ( " selezione_riferimento_vendita[ " + id_riga + " ] " ) . disable ();
$ ( " #rimuovi_riferimento_vendita_ " + id_riga ) . removeClass ( " disabled " );
}
function rimuoviRiferimentoVendita ( button ) {
let riga = $ ( button ) . closest ( " tr " ) . prev ();
let id_riga = riga . data ( " id " );
impostaRiferimentoVendita ( id_riga , {}, {});
input ( " selezione_riferimento_vendita[ " + id_riga + " ] " ) . enable ()
. getElement () . selectReset ();
$ ( button ) . addClass ( " disabled " );
riga . removeClass ( " success " ) . removeClass ( " warning " );
}
$ ( " [id^= \ 'articoli \ '] " ) . change ( function () {
updateSelectOption ( " id_articolo " , $ ( this ) . val ());
});
2020-02-24 18:30:05 +01:00
</ script > ' ;