2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../../core.php' ;
2018-06-26 09:41:43 +02:00
2018-12-28 08:07:56 +01:00
/* CONSUNTIVO */
2017-08-04 16:28:16 +02:00
// Salvo i colori e gli stati degli stati intervento su un array
$colori = [];
$stati = [];
$queryc = 'SELECT * FROM in_statiintervento' ;
$rsc = $dbo -> fetchArray ( $queryc );
for ( $i = 0 ; $i < sizeof ( $rsc ); ++ $i ) {
$colori [ $rsc [ $i ][ 'idstatointervento' ]] = $rsc [ $i ][ 'colore' ];
$stati [ $rsc [ $i ][ 'idstatointervento' ]] = $rsc [ $i ][ 'descrizione' ];
}
2017-09-14 17:37:32 +02:00
$totale_costo = 0 ;
$totale_addebito = 0 ;
2017-08-04 16:28:16 +02:00
$totale = 0 ;
2017-09-14 17:37:32 +02:00
$totale_stato = [];
2017-08-04 16:28:16 +02:00
2017-09-14 17:37:32 +02:00
// Tabella con riepilogo interventi
2019-07-12 12:41:19 +02:00
$rsi = $dbo -> fetchArray ( ' SELECT in_interventi . id , in_interventi . idstatointervento ,
2019-03-08 17:24:48 +01:00
( SELECT completato FROM in_statiintervento WHERE in_statiintervento . idstatointervento = in_interventi . idstatointervento ) AS completato ,
2019-02-14 09:52:42 +01:00
( 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 MIN ( km ) FROM in_interventi_tecnici WHERE idintervento = in_interventi . id ) AS km
FROM co_promemoria
INNER JOIN in_interventi ON co_promemoria . idintervento = in_interventi . id
WHERE co_promemoria . idcontratto = '.prepare($id_record).'
UNION
2019-07-12 12:41:19 +02:00
SELECT in_interventi . id , in_interventi . idstatointervento ,
2019-03-08 17:24:48 +01:00
( SELECT completato FROM in_statiintervento WHERE in_statiintervento . idstatointervento = in_interventi . idstatointervento ) AS completato ,
2019-02-14 09:52:42 +01:00
( 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 MIN ( km ) FROM in_interventi_tecnici WHERE idintervento = in_interventi . id ) AS km
FROM in_interventi
WHERE id_contratto = '.prepare($id_record).'
ORDER BY id DESC ' );
2017-09-14 17:37:32 +02:00
if ( ! empty ( $rsi )) {
2017-08-04 16:28:16 +02:00
echo '
< table class = " table table-bordered table-condensed " >
< tr >
2017-09-14 17:37:32 +02:00
< th > '.tr(' Attività ').' </ th >
< th width = " 100 " > '.tr(' Ore ').' </ th >
< th width = " 100 " > '.tr(' Km ').' </ th >
< th width = " 120 " > '.tr(' Costo ').' </ th >
< th width = " 120 " > '.tr(' Addebito ').' </ th >
< th width = " 120 " > '.tr(' Tot . scontato ').' </ th >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
2017-09-14 17:37:32 +02:00
// Tabella con i dati
foreach ( $rsi as $int ) {
2019-07-12 17:35:14 +02:00
$intervento = \Modules\Interventi\Intervento :: find ( $int [ 'id' ]);
$totale_stato [ $int [ 'idstatointervento' ]] = sum ( $totale_stato [ $int [ 'idstatointervento' ]], $intervento -> totale_imponibile );
2018-11-22 15:34:44 +01:00
2017-09-14 17:37:32 +02:00
// Riga intervento singolo
2017-08-04 16:28:16 +02:00
echo '
2017-09-14 17:37:32 +02:00
< tr style = " background:'. $colori[$int['idstatointervento'] ].'; " >
2017-08-04 16:28:16 +02:00
< td >
2017-09-14 17:37:32 +02:00
< a href = " javascript:; " class = " btn btn-primary btn-xs " onclick = " $ ( \ '#dettagli_'. $int['id'] .' \ ').toggleClass( \ 'hide \ '); $ (this).find( \ 'i \ ').toggleClass( \ 'fa-plus \ ').toggleClass( \ 'fa-minus \ '); " >< i class = " fa fa-plus " ></ i ></ a >
'.Modules::link(' Interventi ', $int[' id '], tr(' Intervento _NUM_ del _DATE_ ' , [
2019-01-23 15:02:51 +01:00
'_NUM_' => $int [ 'codice' ],
2017-09-14 17:37:32 +02:00
'_DATE_' => Translator :: dateToLocale ( $int [ 'inizio' ]),
])) . '
</ td >
2017-08-04 16:28:16 +02:00
2017-09-14 17:37:32 +02:00
< td class = " text-right " >
'.Translator::numberToLocale($int[' ore ']).'
</ td >
2017-08-04 16:28:16 +02:00
2017-09-14 17:37:32 +02:00
< td class = " text-right " >
'.Translator::numberToLocale($int[' km ']).'
</ td >
2017-08-04 16:28:16 +02:00
2017-09-14 17:37:32 +02:00
< td class = " text-right " >
2019-07-12 17:35:14 +02:00
'.Translator::numberToLocale($intervento->spesa).'
2017-09-14 17:37:32 +02:00
</ td >
2017-08-04 16:28:16 +02:00
2017-09-14 17:37:32 +02:00
< td class = " text-right " >
2019-07-12 17:35:14 +02:00
'.Translator::numberToLocale($intervento->imponibile).'
2017-09-14 17:37:32 +02:00
</ td >
2017-08-04 16:28:16 +02:00
2017-09-14 17:37:32 +02:00
< td class = " text-right " >
2019-07-12 17:35:14 +02:00
'.Translator::numberToLocale($intervento->totale_imponibile).'
2017-09-14 17:37:32 +02:00
</ td >
</ tr > ' ;
2017-08-04 16:28:16 +02:00
2017-09-14 17:37:32 +02:00
// Riga con dettagli
echo '
< tr class = " hide " id = " dettagli_'. $int['id'] .' " >
< td colspan = " 6 " > ' ;
/**
* Lettura sessioni di lavoro .
*/
$rst = $dbo -> fetchArray ( 'SELECT in_interventi_tecnici.*, ragione_sociale FROM in_interventi_tecnici LEFT OUTER JOIN an_anagrafiche ON in_interventi_tecnici.idtecnico=an_anagrafiche.idanagrafica WHERE idintervento=' . prepare ( $int [ 'id' ]));
if ( ! empty ( $rst )) {
echo '
< table class = " table table-striped table-condensed table-bordered " >
2017-08-04 16:28:16 +02:00
< tr >
2017-09-14 17:37:32 +02:00
< th > '.tr(' Tecnico ').' </ th >
< th width = " 230 " > '.tr(' Tipo attività ').' </ th >
< th width = " 120 " > '.tr(' Ore ').' </ th >
< th width = " 120 " > '.tr(' Km ').' </ th >
2019-09-06 15:08:31 +02:00
< th width = " 120 " > '.tr(' Costo ore ').' </ th >
2017-09-14 17:37:32 +02:00
< th width = " 120 " > '.tr(' Costo km ').' </ th >
< th width = " 120 " > '.tr(' Diritto ch . ').' </ th >
2019-09-06 15:08:31 +02:00
< th width = " 120 " > '.tr(' Prezzo ore ').' </ th >
2017-09-14 17:37:32 +02:00
< th width = " 120 " > '.tr(' Prezzo km ').' </ th >
< th width = " 120 " > '.tr(' Diritto ch . ').' </ th >
</ tr > ' ;
2017-08-04 16:28:16 +02:00
2017-09-14 17:37:32 +02:00
foreach ( $rst as $r ) {
// Visualizzo lo sconto su ore o km se c'è
2019-04-13 02:56:39 +02:00
$sconto_ore = ( $r [ 'sconto' ] != 0 ) ? '<br><span class="label label-danger">' . moneyFormat ( - $r [ 'sconto' ]) . '</span>' : '' ;
$sconto_km = ( $r [ 'scontokm' ] != 0 ) ? '<br><span class="label label-danger">' . moneyFormat ( - $r [ 'scontokm' ]) . '</span>' : '' ;
2017-08-04 16:28:16 +02:00
2018-01-19 22:48:39 +01:00
// Aggiungo lo sconto globale nel totale ore
2018-02-18 19:53:23 +01:00
if ( $int [ 'sconto_globale' ] > 0 ) {
2019-04-13 02:56:39 +02:00
$sconto_ore .= ' <span class="label label-danger">' . moneyFormat ( - $int [ 'sconto_globale' ]) . '</span>' ;
2018-01-19 22:48:39 +01:00
}
2017-08-04 16:28:16 +02:00
echo '
2017-09-14 17:37:32 +02:00
< tr >
< td > '.$r[' ragione_sociale '].' </ td >
< td > '.$r[' idtipointervento '].' </ td >
< td class = " text-right " > '.Translator::numberToLocale($r[' ore ']).' </ td >
< td class = " text-right " > '.Translator::numberToLocale($r[' km ']).' </ td >
< td class = " text-right danger " > '.Translator::numberToLocale($r[' prezzo_ore_consuntivo_tecnico ']).' </ td >
< td class = " text-right danger " > '.Translator::numberToLocale($r[' prezzo_km_consuntivo_tecnico ']).' </ td >
< td class = " text-right danger " > '.Translator::numberToLocale($r[' prezzo_dirittochiamata_tecnico ']).' </ td >
< td class = " text-right success " > '.Translator::numberToLocale($r[' prezzo_ore_consuntivo ']).$sconto_ore.' </ td >
< td class = " text-right success " > '.Translator::numberToLocale($r[' prezzo_km_consuntivo ']).$sconto_km.' </ td >
< td class = " text-right success " > '.Translator::numberToLocale($r[' prezzo_dirittochiamata ']).' </ td >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
}
2017-09-14 17:37:32 +02:00
2017-08-04 16:28:16 +02:00
echo '
2017-09-14 17:37:32 +02:00
</ table > ' ;
2017-08-04 16:28:16 +02:00
}
2017-09-14 17:37:32 +02:00
/**
* Lettura articoli utilizzati .
*/
$rst = $dbo -> fetchArray ( 'SELECT * FROM mg_articoli_interventi WHERE idintervento=' . prepare ( $int [ 'id' ]));
if ( ! empty ( $rst )) {
2017-08-04 16:28:16 +02:00
echo '
2017-09-14 17:37:32 +02:00
< table class = " table table-striped table-condensed table-bordered " >
2017-08-04 16:28:16 +02:00
< tr >
2017-09-14 17:37:32 +02:00
< th > '.tr(' Materiale ').' </ th >
< th width = " 120 " > '.tr(' Q . tà ').' </ th >
< th width = " 150 " > '.tr(' Prezzo di acquisto ').' </ th >
< th width = " 150 " > '.tr(' Prezzo di vendita ').' </ th >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
2017-09-14 17:37:32 +02:00
foreach ( $rst as $r ) {
// Visualizzo lo sconto su ore o km se c'è
2019-04-13 02:56:39 +02:00
$sconto = ( $r [ 'sconto' ] != 0 ) ? '<br><span class="label label-danger">' . moneyFormat ( - $r [ 'sconto' ]) . '</span>' : '' ;
2017-09-14 17:37:32 +02:00
2017-08-04 16:28:16 +02:00
echo '
< tr >
2017-09-14 17:37:32 +02:00
< td >
'.Modules::link(' Articoli ', $r[' idarticolo '], $r[' descrizione ']).(!empty($extra) ? ' < small class = " help-block " > '.implode(' , ', $extra).' </ small > ' : ' ').'
</ td >
2018-06-29 13:35:39 +02:00
< td class = " text-right " > '.Translator::numberToLocale($r[' qta '], ' qta ').' </ td >
2017-09-14 17:37:32 +02:00
< td class = " text-right danger " > '.Translator::numberToLocale($r[' prezzo_acquisto '] * $r[' qta ']).' </ td >
< td class = " text-right success " > '.Translator::numberToLocale($r[' prezzo_vendita '] * $r[' qta ']).$sconto.' </ td >
</ tr > ' ;
}
2017-08-04 16:28:16 +02:00
2017-09-14 17:37:32 +02:00
echo '
</ table > ' ;
}
2017-08-04 16:28:16 +02:00
2017-09-14 17:37:32 +02:00
/**
* Lettura spese aggiuntive .
*/
$rst = $dbo -> fetchArray ( 'SELECT * FROM in_righe_interventi WHERE idintervento=' . prepare ( $int [ 'id' ]));
if ( ! empty ( $rst )) {
echo '
< table class = " table table-striped table-condensed table-bordered " >
< tr >
< th > '.tr(' Altre spese ').' </ th >
< th width = " 120 " > '.tr(' Q . tà ').' </ th >
< th width = " 150 " > '.tr(' Prezzo di acquisto ').' </ th >
< th width = " 150 " > '.tr(' Prezzo di vendita ').' </ th >
</ tr > ' ;
2017-08-04 16:28:16 +02:00
2017-09-14 17:37:32 +02:00
foreach ( $rst as $r ) {
// Visualizzo lo sconto su ore o km se c'è
2019-04-13 02:56:39 +02:00
$sconto = ( $r [ 'sconto' ] != 0 ) ? '<br><span class="label label-danger">' . moneyFormat ( - $r [ 'sconto' ]) . '</span>' : '' ;
2017-08-04 16:28:16 +02:00
echo '
2017-09-14 17:37:32 +02:00
< tr >
< td >
'.$r[' descrizione '].'
</ td >
2018-06-29 13:35:39 +02:00
< td class = " text-right " > '.Translator::numberToLocale($r[' qta '], ' qta ').' </ td >
2017-09-14 17:37:32 +02:00
< td class = " text-right danger " > '.Translator::numberToLocale($r[' prezzo_acquisto '] * $r[' qta ']).' </ td >
< td class = " text-right success " > '.Translator::numberToLocale($r[' prezzo_vendita '] * $r[' qta ']).$sconto.' </ td >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
}
2017-09-14 17:37:32 +02:00
2017-08-04 16:28:16 +02:00
echo '
2017-09-14 17:37:32 +02:00
</ table > ' ;
}
echo '
2017-08-04 16:28:16 +02:00
</ td >
</ tr > ' ;
2017-09-14 17:37:32 +02:00
2019-03-08 17:24:48 +01:00
$totale_ore_interventi += $int [ 'ore' ];
$totale_ore_completate += ! empty ( $int [ 'completato' ]) ? $int [ 'ore' ] : 0 ;
2017-09-14 17:37:32 +02:00
$totale_km += $int [ 'km' ];
2019-09-06 15:08:31 +02:00
$totale_costo += $intervento -> spesa ;
$totale_addebito += $intervento -> imponibile ;
$totale += $intervento -> totale_imponibile ;
2017-08-04 16:28:16 +02:00
}
// Totali
echo '
< tr >
2017-09-14 17:37:32 +02:00
< td align = " right " >
< b >< big > '.tr(' Totale ').' </ big ></ b >
</ td > ' ;
echo '
< td align = " right " >
2019-03-08 17:24:48 +01:00
< big >< b > '.Translator::numberToLocale($totale_ore_interventi).' </ b ></ big >
2017-09-14 17:37:32 +02:00
</ td > ' ;
echo '
< td align = " right " >
< big >< b > '.Translator::numberToLocale($totale_km).' </ b ></ big >
</ td > ' ;
echo '
< td align = " right " >
< big >< b > '.Translator::numberToLocale($totale_costo).' </ b ></ big >
</ td > ' ;
echo '
< td align = " right " >
< big >< b > '.Translator::numberToLocale($totale_addebito).' </ b ></ big >
</ td > ' ;
echo '
2017-08-04 16:28:16 +02:00
< td align = " right " >
< big >< b > '.Translator::numberToLocale($totale).' </ b ></ big >
</ td >
</ tr > ' ;
// Totali per stato
echo '
< tr >
2017-09-14 17:37:32 +02:00
< td colspan = " 6 " >
< br >< b > '.tr(' Totale interventi per stato ', [], [' upper ' => true]).' </ b >
</ td >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
2017-09-14 17:37:32 +02:00
foreach ( $totale_stato as $stato => $tot ) {
2017-08-04 16:28:16 +02:00
echo '
< tr >
2017-09-14 17:37:32 +02:00
< td colspan = " 3 " ></ td >
< td align = " right " colspan = " 2 " style = " background:'. $colori[$stato] .'; " >
< big >< b > '.$stati[$stato].' :</ b ></ big >
2017-08-04 16:28:16 +02:00
</ td >
< td align = " right " >
< big >< b > '.Translator::numberToLocale($tot).' </ b ></ big >
</ td >
</ tr > ' ;
}
2017-09-14 17:37:32 +02:00
2017-08-04 16:28:16 +02:00
echo '
</ table > ' ;
}
/*
Bilancio del contratto
*/
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-08-04 16:28:16 +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 ));
2019-03-08 17:24:48 +01:00
$totale_ore_contratto = $rs [ 0 ][ 'totale_ore' ];
2017-08-04 16:28:16 +02:00
2018-11-22 15:34:44 +01:00
$diff = sum ( $budget , - $totale );
2018-05-09 15:43:37 +02:00
2017-08-04 16:28:16 +02:00
if ( $diff > 0 ) {
2019-04-13 02:56:39 +02:00
$bilancio = '<span class="text-success"><big>' . moneyFormat ( $diff ) . '</big></span>' ;
2017-08-04 16:28:16 +02:00
} elseif ( $diff < 0 ) {
2019-04-13 02:56:39 +02:00
$bilancio = '<span class="text-danger"><big>' . moneyFormat ( $diff ) . '</big></span>' ;
2017-08-04 16:28:16 +02:00
} else {
2019-04-13 02:56:39 +02:00
$bilancio = '<span><big>' . moneyFormat ( $diff ) . '</big></span>' ;
2017-08-04 16:28:16 +02:00
}
echo '
< div class = " well text-center " >
< big >
2017-09-14 17:37:32 +02:00
< b > '.tr(' Rapporto budget / spesa ').' </ b >:< br >
2017-08-04 16:28:16 +02:00
'.$bilancio.'
</ big >
< br >< br > ' ;
2019-03-08 17:24:48 +01:00
if ( ! empty ( $totale_ore_contratto )) {
2017-09-14 18:25:09 +02:00
echo '
< div class = " row " >
2019-03-08 17:24:48 +01:00
< big class = " col-md-4 col-md-offset-4 text-center " >
2017-09-14 18:25:09 +02:00
< table class = " table text-left " >
< tr >
2019-03-08 17:24:48 +01:00
< td colspan = " 2 " > '.tr(' Ore in contratto ').' :</ td >
< td colspan = " 2 " class = " text-right " > '.Translator::numberToLocale($totale_ore_contratto).' </ td >
2017-09-14 18:25:09 +02:00
</ tr >
2019-03-08 17:24:48 +01:00
2017-09-14 18:25:09 +02:00
< tr >
2019-03-08 17:24:48 +01:00
< td > '.tr(' Ore erogate totali ').' :</ td >
< td class = " text-right " > '.Translator::numberToLocale($totale_ore_interventi).' </ td >
< td > '.tr(' Ore residue totali ').' :</ td >
< td class = " text-right " > '.Translator::numberToLocale(floatval($totale_ore_contratto) - floatval($totale_ore_interventi)).' </ td >
2017-09-14 18:25:09 +02:00
</ tr >
< tr >
2019-03-08 17:24:48 +01:00
< td > '.tr(' Ore erogate concluse ').' :</ td >
< td class = " text-right " > '.Translator::numberToLocale($totale_ore_completate).' </ td >
< td > '.tr(' Ore residue ').' :</ td >
< td class = " text-right " > '.Translator::numberToLocale(floatval($totale_ore_contratto) - floatval($totale_ore_completate)).' </ td >
2017-09-14 18:25:09 +02:00
</ tr >
</ table >
</ big >
</ div > ' ;
} else {
echo '
< div class = " alert alert-info " >
< p > '.tr(' Per monitorare il consumo ore , inserisci almeno una riga con unità di misura " ore " ').' .</ p >
</ div > ' ;
}
echo '
2017-08-04 16:28:16 +02:00
</ div > ' ;
/*
Stampa consuntivo
*/
echo '
< div class = " text-center " >
2017-09-21 17:48:41 +02:00
'.Prints::getLink(' Consuntivo contratto ', $id_record, ' btn - primary ', tr(' Stampa consuntivo ')).'
2017-08-04 16:28:16 +02:00
</ div > ' ;