2018-09-24 18:10:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
2018-11-30 15:33:25 +01:00
$fattura_pa = new Plugins\ImportFE\FatturaElettronica ( get ( 'filename' ));
2018-09-24 18:10:16 +02:00
2018-10-13 10:15:54 +02:00
echo '
< form action = " '. $rootdir .'/actions.php " method = " post " >
< input type = " hidden " name = " id_module " value = " '. $id_module .' " >
< input type = " hidden " name = " id_plugin " value = " '. $id_plugin .' " >
< input type = " hidden " name = " filename " value = " '.get('filename').' " >
< input type = " hidden " name = " id_segment " value = " '.get('id_segment').' " >
< input type = " hidden " name = " id " value = " '.get('id').' " >
< input type = " hidden " name = " backto " value = " record-edit " >
< input type = " hidden " name = " op " value = " generate " > ' ;
// Fornitore
$fornitore = $fattura_pa -> getHeader ()[ 'CedentePrestatore' ][ 'DatiAnagrafici' ];
$ragione_sociale = $fornitore [ 'Anagrafica' ][ 'Denominazione' ] ? : $fornitore [ 'Anagrafica' ][ 'Nome' ] . ' ' . $fornitore [ 'Anagrafica' ][ 'Cognome' ];
$codice_fiscale = $fornitore [ 'CodiceFiscale' ];
$partita_iva = $fornitore [ 'IdFiscaleIVA' ][ 'IdCodice' ];
2019-01-05 10:08:45 +01:00
$sede = $fattura_pa -> getHeader ()[ 'CedentePrestatore' ][ 'Sede' ];
$cap = $sede [ 'CAP' ];
$citta = $sede [ 'Comune' ];
$provincia = $sede [ 'Provincia' ];
2019-01-10 19:31:26 +01:00
// Dati generali
$dati_generali = $fattura_pa -> getBody ()[ 'DatiGenerali' ][ 'DatiGeneraliDocumento' ];
$descrizione_documento = database () -> fetchOne ( 'SELECT CONCAT("(", codice, ") ", descrizione) AS descrizione FROM fe_tipi_documento WHERE codice = ' . prepare ( $dati_generali [ 'TipoDocumento' ]));
2018-10-13 10:15:54 +02:00
echo '
2019-01-10 19:31:26 +01:00
< div class = " row " >
< div class = " col-md-6 " >
< h4 > ' .
$ragione_sociale . ' < br >
< 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-01-09 19:12:49 +01:00
< div class = " col-md-6 " >
2019-02-02 13:11:20 +01:00
< h4 > '.$dati_generali[' Numero ' ];
echo '
< a href = " '.ROOTDIR.'/view.php?file_id='.get('id').' " class = " btn btn-info btn-xs " target = " _blank " >
< i class = " fa fa-eye " ></ i > '.tr(' Visualizza ').'
</ a >< br >
2019-01-09 19:12:49 +01:00
< small >
2019-01-10 19:31:26 +01:00
'.database()->fetchOne(' SELECT CONCAT ( " ( " , codice , " ) " , descrizione ) AS descrizione FROM fe_tipi_documento WHERE codice = '.prepare($dati_generali[' TipoDocumento ']))[' descrizione '].'
< br > '.Translator::dateToLocale($dati_generali[' Data ']).'
< br > '.$dati_generali[' Divisa '].'
2019-01-09 19:12:49 +01:00
</ small >
</ h4 >
</ div >
</ div > ' ;
2018-10-13 10:15:54 +02:00
2019-01-10 19:31:26 +01:00
// Tipo del documento
$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\'' ;
if ( database () -> fetchNum ( 'SELECT id FROM co_tipidocumento WHERE codice_tipo_documento_fe = ' . prepare ( $dati_generali [ 'TipoDocumento' ]))) {
$query .= ' AND codice_tipo_documento_fe = ' . prepare ( $dati_generali [ 'TipoDocumento' ]);
}
echo '
< div class = " row " >
< div class = " col-md-6 " >
{[ " 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 '
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Sezionale').' " , " name " : " id_segment " , " required " : 1 , " values " : " query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='. $id_module .' ORDER BY name " , " value " : " '. $_SESSION['module_'.$id_module] ['id_segment'].' " ]}
</ div >
</ div > ' ;
// Blocco DatiPagamento è valorizzato (opzionale)
$pagamenti = $fattura_pa -> getBody ()[ 'DatiPagamento' ];
if ( ! empty ( $pagamenti )) {
2019-01-10 18:11:09 +01:00
$metodi = $pagamenti [ 'DettaglioPagamento' ];
$metodi = isset ( $metodi [ 0 ]) ? $metodi : [ $metodi ];
2019-01-09 17:12:00 +01:00
2019-01-10 18:11:09 +01:00
echo '
2019-01-09 17:12:00 +01:00
< h4 > '.tr(' Pagamento ').' </ h4 >
2019-01-10 19:31:26 +01:00
< p > '.tr(' La fattura importata presenta _NUM_ rat_E_ di pagamento con le seguenti scadenze ' , [
2019-01-10 18:11:09 +01:00
'_NUM_' => count ( $metodi ),
2019-01-10 18:41:25 +01:00
'_E_' => (( count ( $metodi ) > 1 ) ? 'e' : 'a' ),
2019-01-10 18:11:09 +01:00
]) . ' :</ p >
2019-01-09 19:12:49 +01:00
< ol > ' ;
2019-01-09 17:12:00 +01:00
2019-01-10 18:11:09 +01:00
// Scadenze di pagamento
foreach ( $metodi as $metodo ) {
echo '
2019-01-09 17:12:00 +01:00
< li > ' ;
2019-01-10 18:11:09 +01:00
//DataScadenzaPagamento è un nodo opzionale per il blocco DatiPagamento
if ( ! empty ( $metodo [ 'DataScadenzaPagamento' ])) {
echo Translator :: dateToLocale ( $metodo [ 'DataScadenzaPagamento' ]) . ' ' ;
}
2019-01-10 19:31:26 +01:00
$descrizione = ! empty ( $metodo [ 'ModalitaPagamento' ]) ? database () -> fetchOne ( 'SELECT descrizione FROM fe_modalita_pagamento WHERE codice = ' . prepare ( $metodo [ 'ModalitaPagamento' ]))[ 'descrizione' ] : '' ;
2019-01-10 18:11:09 +01:00
2019-01-10 19:31:26 +01:00
echo Translator :: numberToLocale ( $metodo [ 'ImportoPagamento' ]) . ' & euro ;
( '.$descrizione.' )
</ li > ' ;
2019-01-10 18:11:09 +01:00
}
2019-01-09 17:12:00 +01:00
2019-01-10 18:11:09 +01:00
echo '
2019-01-09 19:12:49 +01:00
</ ol > ' ;
2019-01-09 17:12:00 +01:00
}
2018-09-25 16:47:44 +02:00
2019-01-10 18:41:25 +01:00
// prc '.($pagamenti['CondizioniPagamento'] == 'TP01' ? '!' : '').'= 100 AND
$query = 'SELECT id, CONCAT (descrizione, IF((codice_modalita_pagamento_fe IS NULL), \"\", CONCAT( \" (\", codice_modalita_pagamento_fe, \")\" ) )) as descrizione FROM co_pagamenti' ;
if ( ! empty ( $codice_modalita_pagamento )) {
$query .= ' WHERE codice_modalita_pagamento_fe = ' . prepare ( $codice_modalita_pagamento );
2018-10-13 10:15:54 +02:00
}
2019-01-10 18:41:25 +01:00
$query .= ' GROUP BY descrizione ORDER BY descrizione ASC' ;
2019-01-10 18:06:15 +01:00
2018-10-13 10:15:54 +02:00
echo '
2018-09-25 16:47:44 +02:00
{[ " type " : " select " , " label " : " '.tr('Pagamento').' " , " name " : " pagamento " , " required " : 1 , " values " : " query='. $query .' " ]} ' ;
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-01-25 10:44:03 +01: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 ').' </ 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 >
2018-12-19 23:53:02 +01:00
< th width = " 10% " > '.tr(' Q . tà ').' </ th >
2018-12-19 23:26:28 +01:00
< th width = " 10% " > '.tr(' Prezzo unitario ').' </ th >
2019-01-25 10:44:03 +01:00
< th width = " 15% " > '.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' ;
2018-09-24 18:10:16 +02:00
echo '
< tr >
< td > '.$riga[' Descrizione '].' </ td >
2018-11-30 15:33:25 +01:00
< td > '.Translator::numberToLocale($riga[' Quantita ']).' '.$riga[' UnitaMisura '].' </ td >
2019-01-22 13:13:31 +01:00
< td > '.Translator::numberToLocale($riga[' PrezzoUnitario ']).' & nbsp ; & euro ; < small class = " help-block " > Aliquota iva : '.$riga[' AliquotaIVA '].' %</ 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 >
2018-12-23 14:01:59 +01:00
{[ " type " : " select " , " name " : " articoli['. $key .'] " , " ajax-source " : " articoli " , " class " : " " , " icon-after " : " add|'.Modules::get('Articoli')['id'].' " ]}
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 (){
$iva = $ ( " select[name^=iva " ) . first () . selectData ();
$conto = $ ( " select[name^=conto " ) . first () . selectData ();
if ( $iva ) {
$ ( " select[name^=iva " ) . each ( function (){
$ ( this ) . selectSet ( $iva . id );
});
}
if ( $conto ) {
$ ( " 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 " >
< button type = " submit " class = " btn btn-primary " >
< i class = " fa fa-arrow-right " ></ i > '.tr(' Continua ').' ...
</ button >
</ div >
</ div >
</ form > ' ;
echo '
< script src = " '. $rootdir .'/lib/init.js " ></ script > ' ;