2017-09-07 16:51:14 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
$report_name = 'fattura_' . $numero . '.pdf' ;
2017-09-08 17:03:47 +02:00
$autofill = [
'count' => 0 , // Conteggio delle righe
'words' => 70 , // Numero di parolo dopo cui contare una riga nuova
'rows' => 20 , // Numero di righe massimo presente nella pagina
'additional' => 15 , // Numero di righe massimo da aggiungere
'columns' => 6 , // Numero di colonne della tabella
];
2017-09-07 16:51:14 +02:00
$v_iva = [];
$v_totale = [];
$sconto = 0 ;
$imponibile = 0 ;
$iva = 0 ;
// Intestazione tabella per righe
echo "
2017-09-08 17:03:47 +02:00
< table class = 'table table-striped' id = 'contents' >
2017-09-07 16:51:14 +02:00
< thead >
< tr >
2017-09-10 14:35:41 +02:00
< th class = 'text-center' style = 'width:50%' > " .tr('Descrizione', [], ['upper' => true]). " </ th >
< th class = 'text-center' style = 'width:10%' > " .tr('Q.TÀ', [], ['upper' => true]). " </ th >
< th class = 'text-center' style = 'width:7%' > " .tr('Um', [], ['upper' => true]). " </ th >
< th class = 'text-center' style = 'width:16%' > " .tr('Costo unitario', [], ['upper' => true]). " </ th >
< th class = 'text-center' style = 'width:20%' > " .tr('Importo', [], ['upper' => true]). " </ th >
< th class = 'text-center' style = 'width:7%' > " .tr('IVA', [], ['upper' => true]).' (%)</th>
2017-09-07 16:51:14 +02:00
</ tr >
</ thead >
< tbody > ' ;
// RIGHE FATTURA CON ORDINAMENTO UNICO
$righe = $dbo -> fetchArray ( " SELECT *, IFNULL((SELECT codice FROM mg_articoli WHERE id=idarticolo),'') AS codice_articolo, (SELECT percentuale FROM co_iva WHERE id=idiva) AS perc_iva FROM `co_righe_documenti` WHERE iddocumento= " . prepare ( $iddocumento ) . ' ORDER BY `order`' );
$tot_righe = sizeof ( $righe );
2017-09-08 17:03:47 +02:00
foreach ( $righe as $r ) {
$autofill [ 'count' ] += ceil ( strlen ( $r [ 'descrizione' ]) / $autofill [ 'words' ]);
$autofill [ 'count' ] += substr_count ( $r [ 'descrizione' ], PHP_EOL );
2017-09-07 16:51:14 +02:00
2017-09-08 17:03:47 +02:00
echo '
2017-09-08 13:24:48 +02:00
< tr >
2017-09-08 17:03:47 +02:00
< td >
'.nl2br($r[' descrizione ' ]);
2017-09-07 16:51:14 +02:00
2017-09-08 17:03:47 +02:00
if ( ! empty ( $r [ 'codice_articolo' ])) {
2017-09-07 16:51:14 +02:00
echo '
2017-09-10 14:35:41 +02:00
< br >< small > '.tr(' COD . _COD_ ' , [
'_COD_' => $r [ 'codice_articolo' ],
]) . '</small>' ;
2017-09-08 17:03:47 +02:00
$autofill [ 'count' ] += 0.4 ;
2017-09-07 16:51:14 +02:00
}
// Aggiunta riferimento a ordine
2017-09-08 17:03:47 +02:00
if ( ! empty ( $r [ 'idordine' ])) {
$rso = $dbo -> fetchArray ( 'SELECT numero, numero_esterno, data FROM or_ordini WHERE id=' . prepare ( $r [ 'idordine' ]));
2017-09-07 16:51:14 +02:00
$numero = ! empty ( $rso [ 0 ][ 'numero_esterno' ]) ? $rso [ 0 ][ 'numero_esterno' ] : $rso [ 0 ][ 'numero' ];
echo '
2017-09-10 14:35:41 +02:00
< br >< small > '.tr(' Rif . ordine n < sup > o </ sup > _NUM_ del _DATE_ ' , [
'_NUM_' => $numero ,
'_DATE_' => Translator :: dateToLocale ( $rso [ 0 ][ 'data' ]),
]) . '</small>' ;
2017-09-08 17:03:47 +02:00
$autofill [ 'count' ] += 0.4 ;
2017-09-07 16:51:14 +02:00
}
// Aggiunta riferimento a ddt
2017-09-08 17:03:47 +02:00
elseif ( ! empty ( $r [ 'idddt' ])) {
$rso = $dbo -> fetchArray ( 'SELECT numero, numero_esterno, data FROM dt_ddt WHERE id=' . prepare ( $r [ 'idddt' ]));
2017-09-07 16:51:14 +02:00
$numero = ! empty ( $rso [ 0 ][ 'numero_esterno' ]) ? $rso [ 0 ][ 'numero_esterno' ] : $rso [ 0 ][ 'numero' ];
echo '
2017-09-10 14:35:41 +02:00
< br >< small > '.tr(' Rif . ddt n < sup > o </ sup > _NUM_ del _DATE_ ' , [
'_NUM_' => $numero ,
'_DATE_' => Translator :: dateToLocale ( $rso [ 0 ][ 'data' ]),
]) . '</small>' ;
2017-09-08 17:03:47 +02:00
$autofill [ 'count' ] += 0.4 ;
2017-09-07 16:51:14 +02:00
}
echo '
</ td > ' ;
echo "
2017-09-08 17:03:47 +02:00
< td class = 'text-center' >
" .(empty( $r['qta'] ) ? '' : Translator::numberToLocale( $r['qta'] , 2)).'
2017-09-07 16:51:14 +02:00
</ td > ' ;
// Unità di miusura
echo "
2017-09-08 17:03:47 +02:00
< td class = 'text-center' >
" .nl2br(strtoupper( $r['um'] )).'
2017-09-07 16:51:14 +02:00
</ td > ' ;
// Costo unitario
echo "
2017-09-08 17:03:47 +02:00
< td class = 'text-right' >
" .(empty( $r['qta'] ) || empty( $r['subtotale'] ) ? '' : Translator::numberToLocale( $r['subtotale'] / $r['qta'] , 2)).' €
2017-09-07 16:51:14 +02:00
</ td > ' ;
// Imponibile
echo "
2017-09-08 17:03:47 +02:00
< td class = 'text-right' >
" .(empty( $r['subtotale'] ) ? '' : Translator::numberToLocale( $r['subtotale'] , 2)).' €';
2017-09-07 16:51:14 +02:00
2017-09-08 17:03:47 +02:00
if ( $r [ 'sconto' ] > 0 ) {
$autofill [ 'count' ] += 0.4 ;
2017-09-07 16:51:14 +02:00
echo "
2017-09-08 17:03:47 +02:00
< br >< small class = 'help-block' >- sconto " .Translator::numberToLocale( $r['sconto_unitario'] ).( $r['tipo_sconto'] == 'PRC' ? '%' : ' €').'</small>';
2017-09-07 16:51:14 +02:00
}
echo '
</ td > ' ;
// Iva
echo '
2017-09-12 11:10:16 +02:00
< td class = " text-center " >
'.Translator::numberToLocale($r[' perc_iva '], 2).'
2017-09-07 16:51:14 +02:00
</ td >
</ tr > ' ;
2017-09-08 17:03:47 +02:00
$imponibile += $r [ 'subtotale' ];
$iva += $r [ 'iva' ];
$sconto += $r [ 'sconto' ];
2017-09-07 16:51:14 +02:00
2017-09-08 17:03:47 +02:00
$v_iva [ $r [ 'desc_iva' ]] += $r [ 'iva' ];
$v_totale [ $r [ 'desc_iva' ]] += $r [ 'subtotale' ] - $r [ 'sconto' ];
2017-09-07 16:51:14 +02:00
}
2017-09-12 11:10:16 +02:00
echo '
| autofill |
</ tbody >
</ table > ' ;
2017-09-07 16:51:14 +02:00
2017-09-12 11:10:16 +02:00
// Aggiungo diciture per condizioni iva particolari
foreach ( $v_iva as $key => $value ) {
$dicitura = $dbo -> fetchArray ( 'SELECT dicitura FROM co_iva WHERE descrizione = ' . prepare ( $key ));
2017-09-07 16:51:14 +02:00
2017-09-12 11:10:16 +02:00
if ( ! empty ( $dicitura [ 0 ][ 'dicitura' ])) {
$testo = $dicitura [ 0 ][ 'dicitura' ];
2017-09-07 16:51:14 +02:00
2017-09-12 11:10:16 +02:00
echo "
< p class = 'text-center' >
< b > " .nl2br( $testo ). " </ b >
</ p > " ;
2017-09-07 16:51:14 +02:00
}
}
if ( ! empty ( $rs [ 0 ][ 'note' ])) {
echo '
< br >
2017-09-10 14:35:41 +02:00
< p class = " small-bold " > '.tr(' Note ', [], [' upper ' => true]).' :</ p >
2017-09-07 16:51:14 +02:00
< p > '.$rs[0][' note '].' </ p > ' ;
}
2017-09-08 17:03:47 +02:00
// Info per il footer
$totale_iva = $iva ;
$imponibile_documento = $imponibile - $sconto ;
$totale_documento = $imponibile - $sconto + $totale_iva ;