2018-09-24 18:10:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
2019-07-24 17:17:54 +02:00
echo '
< script >
$ ( document ) . ready ( function () {
$ ( " #save " ) . hide ();
});
</ script > ' ;
$skip_link = $has_next ? ROOTDIR . '/editor.php?id_module=' . $id_module . '&id_plugin=' . $id_plugin . '&id_record=' . ( $id_record + 1 ) . '&sequence=' . get ( 'sequence' ) : ROOTDIR . '/editor.php?id_module=' . $id_module ;
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' );
2019-11-29 18:26:02 +01:00
$data_registrazione = new \Carbon\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-01-10 18:41:25 +01:00
if ( ! empty ( $codice_modalita_pagamento )) {
2019-07-22 12:52:48 +02:00
$_SESSION [ 'superselect' ][ 'codice_modalita_pagamento_fe' ] = $codice_modalita_pagamento ;
2018-10-13 10:15:54 +02:00
}
2019-01-10 18:06:15 +01:00
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 " >
2019-07-22 12:52:48 +02:00
< button type = " button " class = " btn btn-info btn-xs pull-right " onclick = " session_set( \ 'superselect,codice_modalita_pagamento_fe \ ', \ ' \ ', 0) " >
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
2019-07-22 12:52:48 +02:00
{[ " type " : " select " , " label " : " '.tr('Pagamento').' " , " name " : " pagamento " , " required " : 1 , " ajax-source " : " pagamenti " ]}
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 " >
< table class = " table table-hover table-striped table-condensed " >
< tr >
< th > '.tr(' Descrizione ').' </ th >
2019-03-01 13:11:08 +01:00
< th width = " 25% " > '.tr(' Dati contabili ').' *</ th >
2018-12-19 23:53:02 +01:00
< th width = " 25% " > '.tr(' Articolo ').' </ th >
2018-10-29 22:23:29 +01:00
</ tr > ' ;
2018-09-24 18:10:16 +02:00
foreach ( $righe as $key => $riga ) {
2018-09-25 11:55:52 +02:00
$query = 'SELECT id, IF(codice IS NULL, descrizione, CONCAT(codice, " - ", descrizione)) AS descrizione FROM co_iva WHERE percentuale = ' . prepare ( $riga [ 'AliquotaIVA' ]);
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
2019-10-18 16:40:15 +02:00
$codice_principale = $codici [ 0 ][ 'CodiceValore' ];
2019-10-18 15:28:44 +02:00
$id_articolo = $database -> fetchOne ( 'SELECT id FROM mg_articoli WHERE codice = ' . prepare ( $codice_principale ))[ 'id' ];
2018-09-24 18:10:16 +02:00
echo '
< tr >
2019-03-01 13:11:08 +01:00
< td >
'.$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 > ' : ' ').'
2019-11-29 18:26:02 +01:00
2019-03-01 13:11:08 +01:00
< small > '.tr(' Q . tà : _QTA_ _UM_ ' , [
'_QTA_' => Translator :: numberToLocale ( $riga [ 'Quantita' ]),
'_UM_' => $riga [ 'UnitaMisura' ],
]) . ' </ small >< br >
2019-11-29 18:26:02 +01:00
2019-05-09 19:59:59 +02:00
< small > '.tr(' Aliquota IVA : _VALUE_ _DESC_ ' , [
2019-05-04 00:32:28 +02:00
'_VALUE_' => empty ( $riga [ 'Natura' ]) ? numberFormat ( $riga [ 'AliquotaIVA' ]) . '%' : $riga [ 'Natura' ],
2019-03-01 13:11:08 +01:00
'_DESC_' => $riga [ 'RiferimentoNormativo' ] ? ' - ' . $riga [ 'RiferimentoNormativo' ] : '' ,
]) . ' </ small >
</ td >
2018-09-25 11:55:52 +02:00
< td >
2019-01-25 10:44:03 +01:00
{[ " type " : " select " , " name " : " iva['. $key .'] " , " values " : " query='.str_replace(' " ', ' \ " ', $query ).' " , " required " : 1 , " placeholder " : " Aliquota iva " ]}
< br >
{[ " type " : " select " , " name " : " conto['. $key .'] " , " ajax-source " : " conti-acquisti " , " required " : 1 , " placeholder " : " Conto acquisti " ]}
2018-10-29 22:23:29 +01:00
</ td >
2018-09-24 18:10:16 +02:00
< td >
2019-10-18 15:28:44 +02:00
{[ " type " : " select " , " name " : " articoli['. $key .'] " , " ajax-source " : " articoli " , " icon-after " : " add|'.Modules::get('Articoli')['id'].'|codice='.htmlentities( $codice_principale ).'&descrizione='.htmlentities( $riga['Descrizione'] ).' " , " value " : " '. $id_articolo .' " ]}
2018-09-24 18:10:16 +02:00
</ td >
</ tr > ' ;
}
echo '
2018-10-29 22:23:29 +01:00
</ table >
</ div > ' ;
2018-12-07 10:56:49 +01:00
echo '
< script >
function copy (){
2019-04-18 13:08:03 +02:00
var first_iva = null ;
var first_conto = null ;
$ ( " select[name^=iva " ) . each ( function (){
if ( $ ( this ) . val () != " " && first_iva == null ){
first_iva = $ ( this );
}
});
$ ( " select[name^=conto " ) . each ( function (){
if ( $ ( this ) . val () != " " && first_conto == null ){
first_conto = $ ( this );
}
});
if ( first_iva ) {
$iva = first_iva . selectData ();
2018-12-07 10:56:49 +01:00
$ ( " select[name^=iva " ) . each ( function (){
$ ( this ) . selectSet ( $iva . id );
});
}
2019-04-18 13:08:03 +02:00
if ( first_conto ) {
$conto = first_conto . selectData ();
2018-12-07 10:56:49 +01:00
$ ( " select[name^=conto " ) . each ( function (){
$ ( this ) . selectSetNew ( $conto . id , $conto . text );
});
}
}
</ 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 >
</ form > ' ;