2017-09-21 11:02:31 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
include_once $docroot . '/modules/interventi/modutil.php' ;
2018-03-02 20:34:32 +01:00
$report_name = 'contratto_' . $records [ 0 ][ 'numero' ] . '_cons.pdf' ;
2017-09-21 11:02:31 +02:00
echo '
< div class = " row " >
< div class = " col-xs-6 " >
< div class = " text-center " >
< h4 class = " text-bold " > '.tr(' Consuntivo ', [], [' upper ' => true]).' </ h4 >
< b > '.tr(' Contratto num . _NUM_ del _DATE_ ' , [
'_NUM_' => $records [ 0 ][ 'numero' ],
'_DATE_' => Translator :: dateToLocale ( $records [ 0 ][ 'data' ]),
], [ 'upper' => true ]) . ' </ b >
</ div >
</ div >
< div class = " col-xs-5 col-xs-offset-1 " >
< table class = " table " style = " width:100%;margin-top:5mm; " >
< tr >
< td colspan = 2 class = " border-full " style = " height:16mm; " >
< p class = " small-bold " > '.tr(' Spett . le ', [], [' upper ' => true]).' </ p >
< p > $c_ragionesociale $ </ p >
< p > $c_indirizzo $ $c_citta_full $ </ p >
</ td >
</ tr >
< tr >
< td class = " border-bottom border-left " >
< p class = " small-bold " > '.tr(' Partita IVA ', [], [' upper ' => true]).' </ p >
</ td >
< td class = " border-right border-bottom text-right " >
< small > $c_piva $ </ small >
</ td >
</ tr >
< tr >
< td class = " border-bottom border-left " >
< p class = " small-bold " > '.tr(' Codice fiscale ', [], [' upper ' => true]).' </ p >
</ td >
< td class = " border-right border-bottom text-right " >
< small > $c_codicefiscale $ </ small >
</ td >
</ tr >
</ table >
</ div >
</ div > ' ;
// Descrizione
if ( ! empty ( $records [ 0 ][ 'descrizione' ])) {
echo '
< p > '.nl2br($records[0][' descrizione ']).' </ p >
< br > ' ;
}
$totale_ore_impiegate = 0 ;
$sconto = [];
$imponibile = [];
2018-06-29 17:30:41 +02:00
$interventi = $dbo -> fetchArray ( 'SELECT *, in_interventi.id, in_interventi.codice, (SELECT GROUP_CONCAT(DISTINCT ragione_sociale) FROM in_interventi_tecnici JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = in_interventi_tecnici.idtecnico WHERE idintervento=in_interventi.id) AS tecnici, (SELECT MIN(orario_inizio) FROM in_interventi_tecnici WHERE idintervento=in_interventi.id) AS inizio, (SELECT SUM(ore) FROM in_interventi_tecnici WHERE idintervento=in_interventi.id) AS ore, (SELECT SUM(km) FROM in_interventi_tecnici WHERE idintervento=in_interventi.id) AS km FROM co_contratti_promemoria JOIN in_interventi ON co_contratti_promemoria.idintervento=in_interventi.id WHERE co_contratti_promemoria.idcontratto=' . prepare ( $id_record ) . ' ORDER BY inizio DESC' );
2017-09-21 11:02:31 +02:00
if ( ! empty ( $interventi )) {
// Interventi
echo "
< table class = 'table table-striped table-bordered' id = 'contents' >
< thead >
< tr >
< th class = 'text-center' style = 'width:50%' > " .tr('Attività', [], ['upper' => true]). " </ th >
< th class = 'text-center' style = 'width:10%' > " .tr('Ore', [], ['upper' => true]). " </ th >
< th class = 'text-center' style = 'width:15%' > " .tr('Km', [], ['upper' => true]). " </ th >
< th class = 'text-center' style = 'width:15%' > " .tr('Sconto', [], ['upper' => true]). " </ th >
< th class = 'text-center' style = 'width:10%' > " .tr('Imponibile', [], ['upper' => true]).'</th>
</ tr >
</ thead >
< tbody > ' ;
$ore = [];
$km = [];
$sconto_int = [];
$imponibile_int = [];
foreach ( $interventi as $int ) {
$int = array_merge ( $int , get_costi_intervento ( $int [ 'id' ]));
$int [ 'sconto' ] = ( $int [ 'manodopera_addebito' ] - $int [ 'manodopera_scontato' ]) + ( $int [ 'viaggio_addebito' ] - $int [ 'viaggio_scontato' ]);
$int [ 'subtotale' ] = $int [ 'manodopera_scontato' ] + $int [ 'viaggio_scontato' ];
echo '
< tr >
< td >
'.tr(' Intervento num . _NUM_ del _DATE_ ' , [
'_NUM_' => $int [ 'codice' ],
'_DATE_' => Translator :: dateToLocale ( $int [ 'inizio' ]),
]);
if ( ! empty ( $int [ 'tecnici' ])) {
echo '
< br >< small class = " text-muted " > '.tr(' Tecnici ').' : '.str_replace(' , ', ' , ', $int[' tecnici ']).' .</ small > ' ;
}
echo '
</ td > ' ;
echo '
< td class = " text-center " >
'.Translator::numberToLocale($int[' ore ']).'
</ td >
< td class = " text-center " >
'.Translator::numberToLocale($int[' km ']).'
</ td >
< td class = " text-center " >
'.Translator::numberToLocale($int[' sconto ']).' & euro ;
</ td >
< td class = " text-center " >
'.Translator::numberToLocale($int[' subtotale ']).' & euro ;
</ td >
</ tr > ' ;
// Calcolo il totale delle ore lavorate
$tecnici = $dbo -> fetchArray ( 'SELECT orario_inizio, orario_fine FROM in_interventi_tecnici WHERE idintervento=' . prepare ( $int [ 'id' ]));
foreach ( $tecnici as $tecnico ) {
$totale_ore_impiegate += datediff ( 'n' , $tecnico [ 'orario_inizio' ], $tecnico [ 'orario_fine' ]) / 60 ;
}
$ore [] = $int [ 'ore' ];
$km [] = $int [ 'km' ];
$sconto_int [] = $sconto ;
$imponibile_int [] = $int [ 'subtotale' ];
}
$ore = sum ( $ore );
$km = sum ( $km );
$sconto_int = sum ( $sconto_int );
$imponibile_int = sum ( $imponibile_int );
$totale_int = $imponibile_int - $sconto_int ;
$sconto [] = $sconto_int ;
$imponibile [] = $imponibile_int ;
echo '
</ tbody > ' ;
// Totale interventi
echo '
< tr >
< td class = " text-right " >
< b > '.tr(' Totale ', [], [' upper ' => true]).' :</ b >
</ td >
< td class = " text-center " >
< b > '.Translator::numberToLocale($ore).' </ b >
</ td >
< td class = " text-center " >
< b > '.Translator::numberToLocale($km).' </ b >
</ td >
< td class = " text-center " >
< b > '.Translator::numberToLocale($sconto_int).' & euro ; </ b >
</ td >
< th class = " text-center " >
< b > '.Translator::numberToLocale($totale_int).' & euro ; </ b >
</ th >
</ tr > ' ;
echo '
</ table > ' ;
$count = $dbo -> fetchArray ( 'SELECT COUNT(*) FROM `mg_articoli_interventi` WHERE idintervento IN (' . implode ( ',' , array_column ( $interventi , 'id' )) . ')' );
if ( ! empty ( $count )) {
echo '
< table class = " table table-bordered " >
< thead >
< tr >
< th colspan = " 4 " class = " text-center " >
< b > '.tr(' Materiale utilizzato ', [], [' upper ' => true]).' </ b >
</ th >
</ tr >
< tr >
< th style = " font-size:8pt;width:50% " class = " text-center " >
< b > '.tr(' Descrizione ').' </ b >
</ th >
< th style = " font-size:8pt;width:15% " class = " text-center " >
< b > '.tr(' Q . tà ').' </ b >
</ th >
< th style = " font-size:8pt;width:15% " class = " text-center " >
< b > '.tr(' Prezzo ').' </ b >
</ th >
< th style = " font-size:8pt;width:15% " class = " text-center " >
< b > '.tr(' Importo ').' </ b >
</ th >
</ tr >
</ thead >
< tbody > ' ;
$sconto_art = [];
$imponibile_art = [];
// Articoli per intervento
foreach ( $interventi as $int ) {
$righe = $dbo -> fetchArray ( " SELECT *, (SELECT codice FROM mg_articoli WHERE id=idarticolo) AS codice, (SELECT CONCAT_WS(serial, 'SN: ', ', ') FROM mg_prodotti WHERE mg_articoli_interventi.idarticolo = mg_prodotti.id_articolo) AS serials FROM `mg_articoli_interventi` WHERE idintervento = " . prepare ( $int [ 'id' ]) . ' ORDER BY idarticolo ASC' );
foreach ( $righe as $r ) {
echo '
< tr > ' ;
// Descrizione
echo '
< td >
'.$r[' descrizione ' ];
// Codice
if ( ! empty ( $r [ 'codice' ])) {
echo '
< br >< small class = " text-muted " > '.tr(' COD . _COD_ ' , [
'_COD_' => $r [ 'codice' ],
]) . '</small>' ;
}
echo '
< br >< small class = " text-muted " > '.tr(' Intervento num . _NUM_ del _DATE_ ' , [
2018-03-01 12:08:27 +01:00
'_NUM_' => $int [ 'codice' ],
2017-09-21 11:02:31 +02:00
'_DATE_' => Translator :: dateToLocale ( $int [ 'inizio' ]),
]) . '.</small>' ;
echo '
</ td > ' ;
// Quantità
echo '
< td class = " text-center " >
2018-06-29 13:35:39 +02:00
'.Translator::numberToLocale($r[' qta '], ' qta ').' '.$r[' um '].'
2017-09-21 11:02:31 +02:00
</ td > ' ;
// Prezzo unitario
echo "
< td class = 'text-center' >
" .Translator::numberToLocale( $r['prezzo_vendita'] ).' €';
if ( $r [ 'sconto' ] > 0 ) {
echo "
< br >< small class = 'text-muted' >- " .tr('sconto _TOT_ _TYPE_', [
'_TOT_' => Translator :: numberToLocale ( $r [ 'sconto_unitario' ]),
'_TYPE_' => ( $r [ 'tipo_sconto' ] == 'PRC' ? '%' : '€' ),
]) . '</small>' ;
if ( $count <= 1 ) {
$count += 0.4 ;
}
}
echo '
</ td > ' ;
// Netto
$netto = $r [ 'prezzo_vendita' ] * $r [ 'qta' ];
echo '
< td class = " text-center " >
'.Translator::numberToLocale($netto).' & euro ; ' ;
if ( $r [ 'sconto' ] > 0 ) {
echo "
< br >< small class = 'text-muted' >- " .tr('sconto _TOT_ _TYPE_', [
'_TOT_' => Translator :: numberToLocale ( $r [ 'sconto' ]),
'_TYPE_' => '€' ,
]) . '</small>' ;
if ( $count <= 1 ) {
$count += 0.4 ;
}
}
echo '
</ td >
</ tr > ' ;
$sconto_art [] = $r [ 'sconto' ];
$imponibile_art [] = $r [ 'prezzo_vendita' ] * $r [ 'qta' ];
}
}
echo '
</ tbody > ' ;
$sconto_art = sum ( $sconto_art );
$imponibile_art = sum ( $imponibile_art );
$totale_art = $imponibile_art - $sconto_art ;
$sconto [] = $sconto_art ;
$imponibile [] = $imponibile_art ;
// Totale spesa articoli
echo '
< tr >
< td colspan = " 2 " class = " text-right " >
< b > '.tr(' Totale materiale utilizzato ', [], [' upper ' => true]).' :</ b >
</ td >
< th colspan = " 2 " class = " text-center " >
< b > '.Translator::numberToLocale($totale_art).' & euro ; </ b >
</ th >
</ tr > ' ;
echo '
</ table > ' ;
}
// Altre spese per intervento
$count = $dbo -> fetchArray ( 'SELECT COUNT(*) FROM `in_righe_interventi` WHERE idintervento IN (' . implode ( ',' , array_column ( $interventi , 'id' )) . ')' );
if ( ! empty ( $count )) {
echo '
< table class = " table table-bordered " >
< thead >
< tr >
< th colspan = " 4 " class = " text-center " >
< b > '.tr(' Spese aggiuntive ', [], [' upper ' => true]).' </ b >
</ th >
</ tr >
< tr >
< th style = " font-size:8pt;width:50% " class = " text-center " >
< b > '.tr(' Descrizione ').' </ b >
</ th >
< th style = " font-size:8pt;width:15% " class = " text-center " >
< b > '.tr(' Q . tà ').' </ b >
</ th >
< th style = " font-size:8pt;width:15% " class = " text-center " >
< b > '.tr(' Prezzo ').' </ b >
</ th >
< th style = " font-size:8pt;width:15% " class = " text-center " >
< b > '.tr(' Importo ').' </ b >
</ th >
</ tr >
</ thead >
< tbody > ' ;
$sconto_spese = [];
$imponibile_spese = [];
// Articoli per intervento
foreach ( $interventi as $int ) {
$righe = $dbo -> fetchArray ( 'SELECT * FROM `in_righe_interventi` WHERE idintervento =' . prepare ( $int [ 'id' ]) . ' ORDER BY id ASC' );
foreach ( $righe as $r ) {
echo '
< tr > ' ;
// Descrizione
echo '
< td >
'.$r[' descrizione ' ];
echo '
< br >< small class = " text-muted " > '.tr(' Intervento num . _NUM_ del _DATE_ ' , [
2018-02-28 23:44:30 +01:00
'_NUM_' => $int [ 'codice' ],
2017-09-21 11:02:31 +02:00
'_DATE_' => Translator :: dateToLocale ( $int [ 'inizio' ]),
]) . '.</small>' ;
echo '
</ td > ' ;
// Quantità
echo '
< td class = " text-center " >
2018-06-29 13:35:39 +02:00
'.Translator::numberToLocale($r[' qta '], ' qta ').' '.$r[' um '].'
2017-09-21 11:02:31 +02:00
</ td > ' ;
// Prezzo unitario
echo "
< td class = 'text-center' >
" .Translator::numberToLocale( $r['prezzo_vendita'] ).' €';
if ( $r [ 'sconto' ] > 0 ) {
echo "
< br >< small class = 'text-muted' >- " .tr('sconto _TOT_ _TYPE_', [
'_TOT_' => Translator :: numberToLocale ( $r [ 'sconto_unitario' ]),
'_TYPE_' => ( $r [ 'tipo_sconto' ] == 'PRC' ? '%' : '€' ),
]) . '</small>' ;
if ( $count <= 1 ) {
$count += 0.4 ;
}
}
echo '
</ td > ' ;
// Netto
$netto = $r [ 'prezzo_vendita' ] * $r [ 'qta' ];
echo '
< td class = " text-center " >
'.Translator::numberToLocale($netto).' & euro ; ' ;
if ( $r [ 'sconto' ] > 0 ) {
echo "
< br >< small class = 'text-muted' >- " .tr('sconto _TOT_ _TYPE_', [
'_TOT_' => Translator :: numberToLocale ( $r [ 'sconto' ]),
'_TYPE_' => '€' ,
]) . '</small>' ;
if ( $count <= 1 ) {
$count += 0.4 ;
}
}
echo '
</ td >
</ tr > ' ;
$sconto_spese [] = $r [ 'sconto' ];
$imponibile_spese [] = $r [ 'prezzo_vendita' ] * $r [ 'qta' ];
}
}
echo '
</ tbody > ' ;
$sconto_spese = sum ( $sconto_spese );
$imponibile_spese = sum ( $imponibile_spese );
$totale_spese = $imponibile_spese - $sconto_spese ;
$sconto [] = $sconto_spese ;
$imponibile [] = $imponibile_spese ;
// Totale spese aggiuntive
echo '
< tr >
< td colspan = " 2 " class = " text-right " >
< b > '.tr(' Totale spese aggiuntive ', [], [' upper ' => true]).' :</ b >
</ td >
< th colspan = " 2 " class = " text-center " >
< b > '.Translator::numberToLocale($totale_spese).' & euro ; </ b >
</ th >
</ tr > ' ;
echo '
</ table > ' ;
}
}
// TOTALE COSTI FINALI
$sconto = sum ( $sconto );
$imponibile = sum ( $imponibile );
$totale = $imponibile - $sconto ;
2018-06-29 17:30:41 +02:00
$rs = $dbo -> fetchArray ( 'SELECT SUM(subtotale-sconto) as budget FROM `co_righe_contratti` WHERE idcontratto = ' . prepare ( $id_record ));
2017-09-21 11:02:31 +02:00
$budget = $rs [ 0 ][ 'budget' ];
2018-06-29 17:30:41 +02:00
$rs = $dbo -> fetchArray ( " SELECT SUM(qta) AS totale_ore FROM `co_righe_contratti` WHERE um='ore' AND idcontratto = " . prepare ( $id_record ));
2017-09-21 11:02:31 +02:00
$totale_ore = $rs [ 0 ][ 'totale_ore' ];
$rapporto = $budget - $totale ;
2018-05-21 16:49:27 +02:00
//pulisco da informazioni irrilevanti (imponibile,iva)
$show = false ;
2017-09-21 11:02:31 +02:00
// Totale imponibile
echo '
2018-05-21 16:49:27 +02:00
< table class = " table table-bordered " style = " display:none; " > ' ;
if ( $show ) {
2018-06-26 14:30:26 +02:00
echo ' < tr >
2018-05-21 16:49:27 +02:00
< td colspan = " 3 " class = " text-right border-top " >
2017-09-21 11:02:31 +02:00
< b > '.tr(' Imponibile ', [], [' upper ' => true]).' :</ b >
</ td >
< th colspan = " 2 " class = " text-center " >
< b > '.Translator::numberToLocale($imponibile).' & euro ; </ b >
</ th >
</ tr > ' ;
2018-06-26 14:30:26 +02:00
// Eventuale sconto incondizionato
if ( ! empty ( $sconto )) {
echo '
2017-09-21 11:02:31 +02:00
< tr >
< td colspan = " 3 " class = " text-right border-top " >
< b > '.tr(' Sconto ', [], [' upper ' => true]).' :</ b >
</ td >
< th colspan = " 2 " class = " text-center " >
< b >- '.Translator::numberToLocale($sconto).' & euro ; </ b >
</ th >
</ tr > ' ;
2018-06-26 14:30:26 +02:00
// Imponibile scontato
echo '
2017-09-21 11:02:31 +02:00
< tr >
< td colspan = " 3 " class = " text-right border-top " >
< b > '.tr(' Imponibile scontato ', [], [' upper ' => true]).' :</ b >
</ td >
< th colspan = " 2 " class = " text-center " >
< b > '.Translator::numberToLocale($totale).' & euro ; </ b >
</ th >
</ tr > ' ;
2018-06-26 14:30:26 +02:00
}
2017-09-21 11:02:31 +02:00
2018-06-26 14:30:26 +02:00
// IVA
$rs = $dbo -> fetchArray ( 'SELECT * FROM co_iva WHERE co_iva.id = ' . prepare ( get_var ( 'Iva predefinita' )));
$percentuale_iva = $rs [ 0 ][ 'percentuale' ];
$iva = $totale / 100 * $percentuale_iva ;
2018-05-21 16:49:27 +02:00
2018-06-26 14:30:26 +02:00
echo '
2017-09-21 11:02:31 +02:00
< tr >
< td colspan = " 3 " class = " text-right border-top " >
< b > '.tr(' Iva ( _PRC_ % ) ' , [
'_PRC_' => Translator :: numberToLocale ( $percentuale_iva , 0 ),
], [ 'upper' => true ]) . ' :</ b >
</ td >
< th colspan = " 2 " class = " text-center " >
< b > '.Translator::numberToLocale($iva).' & euro ; </ b >
</ th >
</ tr > ' ;
2018-06-26 14:30:26 +02:00
//$totale = sum($totale, $iva);
}
2017-09-21 11:02:31 +02:00
// TOTALE
echo '
< tr >
< td colspan = " 3 " class = " text-right border-top " >
2018-05-21 16:49:27 +02:00
< b > '.tr(' Totale consuntivo ( no IVA ) ', [], [' upper ' => true]).' :</ b >
2017-09-21 11:02:31 +02:00
</ td >
< th colspan = " 2 " class = " text-center " >
< b > '.Translator::numberToLocale($totale).' & euro ; </ b >
</ th >
</ tr > ' ;
// BUDGET
echo '
< tr >
< td colspan = " 3 " class = " text-right border-top " >
< b > '.tr(' Budget ( no IVA ) ', [], [' upper ' => true]).' :</ b >
</ td >
< th colspan = " 2 " class = " text-center " >
< b > '.Translator::numberToLocale($budget).' & euro ; </ b >
</ th >
</ tr > ' ;
// RAPPORTO
echo '
< tr >
< td colspan = " 3 " class = " text-right border-top " >
< b > '.tr(' Rapporto budget / spesa ( no IVA ) ', [], [' upper ' => true]).' :</ b >
</ td >
< th colspan = " 2 " class = " text-center " >
< b > '.Translator::numberToLocale($rapporto).' & euro ; </ b >
</ th >
</ tr > ' ;
// ORE RESIDUE
if ( ! empty ( $totale_ore )) {
echo '
< tr >
< td colspan = " 3 " class = " text-right border-top " >
< b > '.tr(' Ore residue ', [], [' upper ' => true]).' :</ b >
</ td >
< th colspan = " 2 " class = " text-center " >
< b > '.Translator::numberToLocale($totale_ore - $totale_ore_impiegate).' </ b >< br >
< p > '.tr(' Ore erogate ').' : '.Translator::numberToLocale($totale_ore_impiegate).' </ p >
< p > '.tr(' Ore in contratto ').' : '.Translator::numberToLocale($totale_ore).' </ p >
</ th >
</ tr > ' ;
}
echo '
</ table > ' ;