2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../../core.php' ;
2018-06-26 09:41:43 +02:00
include_once Modules :: filepath ( 'Interventi' , 'modutil.php' );
2017-08-04 16:28:16 +02:00
/*
CONSUNTIVO
*/
// 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' ];
}
$budget = get_imponibile_preventivo ( $id_record );
$totale_costo = 0 ;
$totale_addebito = 0 ;
2017-09-14 17:37:32 +02:00
$totale = 0 ;
2017-08-04 16:28:16 +02:00
$totale_stato = [];
// Tabella con riepilogo interventi
2018-09-03 15:29:55 +02:00
$rsi = $dbo -> fetchArray ( 'SELECT *, in_interventi.id, in_interventi.codice, (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 in_interventi.id_preventivo=' . prepare ( $id_record ) . ' ORDER BY in_interventi.id DESC' );
2017-08-04 16:28:16 +02:00
if ( ! empty ( $rsi )) {
echo '
< table class = " table table-bordered table-condensed " >
< tr >
2017-09-04 12:02:29 +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 > ' ;
// Tabella con i dati
foreach ( $rsi as $int ) {
2017-09-06 15:29:51 +02:00
$int = array_merge ( $int , get_costi_intervento ( $int [ 'id' ]));
2017-09-11 13:08:50 +02:00
$totale_stato [ $int [ 'idstatointervento' ]] = sum ( $totale_stato [ $int [ 'idstatointervento' ]], $int [ 'totale' ]);
2017-08-04 16:28:16 +02:00
// Riga intervento singolo
echo '
< tr style = " background:'. $colori[$int['idstatointervento'] ].'; " >
< td >
< 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 >
2017-09-21 10:01:07 +02:00
'.Modules::link(' Interventi ', $int[' id '], tr(' Intervento num . _NUM_ del _DATE_ ' , [
'_NUM_' => $int [ 'codice' ],
2017-09-10 14:35:41 +02:00
'_DATE_' => Translator :: dateToLocale ( $int [ 'inizio' ]),
])) . '
2017-08-04 16:28:16 +02:00
</ td >
< td class = " text-right " >
'.Translator::numberToLocale($int[' ore ']).'
</ td >
< td class = " text-right " >
'.Translator::numberToLocale($int[' km ']).'
</ td >
< td class = " text-right " >
2017-09-14 17:37:32 +02:00
'.Translator::numberToLocale($int[' totale_costo ']).'
2017-08-04 16:28:16 +02:00
</ td >
< td class = " text-right " >
2017-09-14 17:37:32 +02:00
'.Translator::numberToLocale($int[' totale_addebito ']).'
2017-08-04 16:28:16 +02:00
</ td >
< td class = " text-right " >
2018-08-08 19:00:19 +02:00
'.Translator::numberToLocale($int[' totale_scontato ']).'
2017-08-04 16:28:16 +02:00
</ td >
</ tr > ' ;
// 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 " >
< tr >
2017-09-04 12:02:29 +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 >
< th width = " 120 " > '.tr(' Costo orario ').' </ th >
< th width = " 120 " > '.tr(' Costo km ').' </ th >
< th width = " 120 " > '.tr(' Diritto ch . ').' </ th >
< th width = " 120 " > '.tr(' Prezzo orario ').' </ th >
< th width = " 120 " > '.tr(' Prezzo km ').' </ th >
< th width = " 120 " > '.tr(' Diritto ch . ').' </ th >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
foreach ( $rst as $r ) {
// Visualizzo lo sconto su ore o km se c'è
2017-09-14 17:37:32 +02:00
$sconto_ore = ( $r [ 'sconto' ] != 0 ) ? '<br><span class="label label-danger">' . Translator :: numberToLocale ( - $r [ 'sconto' ]) . ' €</span>' : '' ;
$sconto_km = ( $r [ 'scontokm' ] != 0 ) ? '<br><span class="label label-danger">' . Translator :: numberToLocale ( - $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 ) {
2018-01-19 22:48:39 +01:00
$sconto_ore .= ' <span class="label label-danger">' . Translator :: numberToLocale ( - $int [ 'sconto_globale' ]) . ' €</span>' ;
}
2017-08-04 16:28:16 +02:00
echo '
< 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 >
</ tr > ' ;
}
echo '
</ table > ' ;
}
/**
* Lettura articoli utilizzati .
*/
$rst = $dbo -> fetchArray ( 'SELECT * FROM mg_articoli_interventi WHERE idintervento=' . prepare ( $int [ 'id' ]));
if ( ! empty ( $rst )) {
echo '
< table class = " table table-striped table-condensed table-bordered " >
< tr >
2017-09-04 12:02:29 +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 > ' ;
foreach ( $rst as $r ) {
// Visualizzo lo sconto su ore o km se c'è
2017-09-14 17:37:32 +02:00
$sconto = ( $r [ 'sconto' ] != 0 ) ? '<br><span class="label label-danger">' . Translator :: numberToLocale ( - $r [ 'sconto' ]) . ' €</span>' : '' ;
2017-08-04 16:28:16 +02:00
echo '
< tr >
< 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-08-04 16:28:16 +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 > ' ;
}
echo '
</ table > ' ;
}
/**
* 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 >
2017-09-04 12:02:29 +02:00
< 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 >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
foreach ( $rst as $r ) {
// Visualizzo lo sconto su ore o km se c'è
2017-09-14 17:37:32 +02:00
$sconto = ( $r [ 'sconto' ] != 0 ) ? '<br><span class="label label-danger">' . Translator :: numberToLocale ( - $r [ 'sconto' ]) . ' €</span>' : '' ;
2017-08-04 16:28:16 +02:00
echo '
< tr >
< td >
'.$r[' descrizione '].'
</ td >
2018-06-29 13:35:39 +02:00
< td class = " text-right " > '.Translator::numberToLocale($r[' qta '], ' qta ').' </ td >
2017-08-04 16:28:16 +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 > ' ;
}
echo '
</ table > ' ;
}
echo '
</ td >
</ tr > ' ;
$totale_ore += $int [ 'ore' ];
$totale_km += $int [ 'km' ];
2017-09-14 17:37:32 +02:00
$totale_costo += $int [ 'totale_costo' ];
$totale_addebito += $int [ 'totale_addebito' ];
2018-08-08 19:00:19 +02:00
$totale += $int [ 'totale_scontato' ];
2017-08-04 16:28:16 +02:00
}
// Totali
echo '
< tr >
< td align = " right " >
2017-09-04 12:02:29 +02:00
< b >< big > '.tr(' Totale ').' </ big ></ b >
2017-08-04 16:28:16 +02:00
</ td > ' ;
echo '
< td align = " right " >
< big >< b > '.Translator::numberToLocale($totale_ore).' </ b ></ big >
</ 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 '
< td align = " right " >
2017-09-14 17:37:32 +02:00
< big >< b > '.Translator::numberToLocale($totale).' </ b ></ big >
2017-08-04 16:28:16 +02:00
</ td >
</ tr > ' ;
// Totali per stato
echo '
< tr >
< td colspan = " 6 " >
2017-09-10 14:35:41 +02:00
< br >< b > '.tr(' Totale interventi per stato ', [], [' upper ' => true]).' </ b >
2017-08-04 16:28:16 +02:00
</ td >
</ tr > ' ;
foreach ( $totale_stato as $stato => $tot ) {
echo '
< tr >
< td colspan = " 3 " ></ td >
< td align = " right " colspan = " 2 " style = " background:'. $colori[$stato] .'; " >
< big >< b > '.$stati[$stato].' :</ b ></ big >
</ td >
< td align = " right " >
< big >< b > '.Translator::numberToLocale($tot).' </ b ></ big >
</ td >
</ tr > ' ;
}
echo '
</ table > ' ;
}
/*
Bilancio del preventivo
*/
2018-05-09 15:43:37 +02:00
$diff = sum ( $budget , - $totale_addebito );
2017-08-04 16:28:16 +02:00
echo '
< div class = " well text-center " >
< br >< span >< big >
2017-09-04 12:02:29 +02:00
< b > '.tr(' Rapporto budget / spesa ').' :< br > ' ;
2017-09-14 17:37:32 +02:00
if ( $budget > $totale ) {
2017-08-04 16:28:16 +02:00
echo '
< span class = " text-success " >< big >+ '.Translator::numberToLocale($diff).' & euro ; </ big ></ span > ' ;
} elseif ( $diff < 0 ) {
echo '
2017-09-14 17:37:32 +02:00
< span class = " text-danger " >< big > '.Translator::numberToLocale($diff).' & euro ; </ big ></ span > ' ;
2017-08-04 16:28:16 +02:00
} else {
echo '
2017-09-14 17:37:32 +02:00
< span >< big > '.Translator::numberToLocale($diff).' & euro ; </ big ></ span > ' ;
2017-08-04 16:28:16 +02:00
}
echo '
</ b ></ big ></ span >
< br >< br >
</ div > ' ;
/*
Stampa consuntivo
*/
echo '
< div class = " text-center " >
2017-09-21 17:48:41 +02:00
'.Prints::getLink(' Consuntivo preventivo ', $id_record, ' btn - primary ', tr(' Stampa consuntivo ')).'
2017-08-04 16:28:16 +02:00
</ div > ' ;
2018-06-23 18:35:08 +02:00
// Aggiunta interventi se il preventivo é aperto o in attesa o pagato (non si possono inserire interventi collegati ad altri preventivi)
2018-07-18 15:20:10 +02:00
if ( in_array ( $record [ 'stato' ], [ 'Accettato' , 'In lavorazione' , 'Pagato' ])) {
2017-08-04 16:28:16 +02:00
echo '
< form action = " " method = " post " >
< input type = " hidden " name = " op " value = " addintervento " >
< input type = " hidden " name = " backto " value = " record-edit " >
< div class = " row " >
< div class = " col-md-4 " >
2018-09-03 15:29:55 +02:00
{[ " type " : " select " , " label " : " '.tr('Aggiungi un altro intervento a questo preventivo').' " , " name " : " idintervento " , " values " : " query=SELECT id, CONCAT( \ 'Intervento \ ', codice, \ ' del \ ', DATE_FORMAT(IFNULL((SELECT MIN(orario_inizio) FROM in_interventi_tecnici WHERE in_interventi_tecnici.idintervento=in_interventi.id), data_richiesta), \ '%d/%m/%Y \ ')) AS descrizione FROM in_interventi WHERE id_preventivo IS NULL AND id NOT IN( SELECT idintervento FROM co_righe_documenti WHERE idintervento IS NOT NULL) AND id NOT IN( SELECT idintervento FROM co_promemoria WHERE idintervento IS NOT NULL) AND idanagrafica='.prepare( $record['idanagrafica'] ).' " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-12 text-right " >
< button type = " submit " class = " btn btn-primary pull-right " onclick = " if( $ ( \ '#idintervento \ ').val() && confirm( \ 'Aggiungere questo intervento al preventivo? \ ') { $ (this).parent().submit(); } " >
2017-09-04 12:02:29 +02:00
< i class = " fa fa-plus " ></ i > '.tr(' Aggiungi ').'
2017-08-04 16:28:16 +02:00
</ button >
</ div >
</ div >
</ form > ' ;
}