2018-09-24 18:10:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
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-22 18:35:13 +02:00
< 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 = " '. $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 " >
< div class = " row " >
< div class = " col-md-3 " >
< h4 >
'.$ragione_sociale.'
'.(empty($anagrafica) ? ' < span class = " badge badge-success " > '.tr(' Nuova anagrafica ').' </ span > ' : ' < small > '.Modules::link(' Anagrafiche ', $idanagrafica)).' </ small >< br >
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-07-22 18:35:13 +02:00
< div class = " col-md-3 " >
< h4 >
'.$dati_generali[' Numero '].'
2019-05-04 00:40:51 +02:00
< a href = " '. $structure->fileurl ('view.php').'?filename='. $filename .' " 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-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 >
< 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-01-10 19:31:26 +01:00
{[ " 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'].' " ]}
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-05-13 19:21:46 +02:00
echo '
2019-07-22 18:35:13 +02:00
< div class = " col-md-3 " >
2019-07-22 15:45:36 +02:00
{[ " type " : " date " , " label " : " '.tr('Data di registrazione').' " , " name " : " data_registrazione " , " required " : 1 , " value " : " '.get('data_registrazione').' " , " max-date " : " -now- " , " min-date " : " '. $dati_generali['Data'] .' " , " readonly " : " '.(intval(get('data_registrazione') != null)).' " ]}
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) " >
< i class = " fa fa-refresh " ></ i > '.tr(' Reset modalità ').'
</ button >
{[ " type " : " select " , " label " : " '.tr('Pagamento').' " , " name " : " pagamento " , " required " : 1 , " ajax-source " : " pagamenti " ]}
2019-02-21 17:14:37 +01:00
</ div > ' ;
// Movimentazioni
echo '
< div class = " col-md-6 " >
{[ " type " : " checkbox " , " label " : " '.tr('Movimenta gli articoli').' " , " name " : " movimentazione " , " value " : 1 ]}
</ div >
</ 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
/*Visualizzo codici articoli*/
$codici_articoli = '' ;
//caso di un solo codice articolo
if ( isset ( $riga [ 'CodiceArticolo' ]) and empty ( $riga [ 'CodiceArticolo' ][ 0 ][ 'CodiceValore' ])) {
$riga [ 'CodiceArticolo' ][ 0 ][ 'CodiceValore' ] = $riga [ 'CodiceArticolo' ][ 'CodiceValore' ];
$riga [ 'CodiceArticolo' ][ 0 ][ 'CodiceTipo' ] = $riga [ 'CodiceArticolo' ][ 'CodiceTipo' ];
}
2019-05-16 14:56:18 +02:00
foreach ( $riga [ 'CodiceArticolo' ] as $key2 => $item ) {
foreach ( $item as $key2 => $name ) {
if ( $key2 == 'CodiceValore' ) {
2019-05-10 17:14:34 +02:00
if ( ! empty ( $item [ 'CodiceValore' ])) {
$codici_articoli .= '<small>' . $item [ 'CodiceValore' ] . ' (' . $item [ 'CodiceTipo' ] . ')</small>' ;
if (( $item [ 'CodiceValore' ] != end ( $riga [ 'CodiceArticolo' ][( count ( $riga [ 'CodiceArticolo' ]) - 1 )])) and ( is_array ( $riga [ 'CodiceArticolo' ][ 1 ]))) {
$codici_articoli .= ', ' ;
}
}
}
}
}
2018-09-24 18:10:16 +02:00
echo '
< tr >
2019-03-01 13:11:08 +01:00
< td >
'.$riga[' Descrizione '].' < br >
2019-05-09 19:59:59 +02:00
2019-05-10 17:14:34 +02:00
'.(($codici_articoli != ' ') ? $codici_articoli.' < br > ' : ' ').'
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-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-05-16 17:24:21 +02:00
{[ " type " : " select " , " name " : " articoli['. $key .'] " , " ajax-source " : " articoli " , " class " : " " , " icon-after " : " add|'.Modules::get('Articoli')['id'].'|codice='.htmlentities( $riga['CodiceArticolo'] [0]['CodiceValore']).'&descrizione='.htmlentities( $riga['Descrizione'] ).' " ]}
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 " >
< button type = " submit " class = " btn btn-primary " >
< i class = " fa fa-arrow-right " ></ i > '.tr(' Continua ').' ...
</ button >
</ div >
</ div >
</ form > ' ;
echo '
2019-07-22 18:35:13 +02:00
< script >
$ ( document ) . ready ( function () {
$ ( " #save " ) . hide ();
});
</ script >
2018-09-24 18:10:16 +02:00
< script src = " '. $rootdir .'/lib/init.js " ></ script > ' ;