2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../../core.php' ;
2018-06-26 09:41:43 +02:00
2020-02-14 17:02:16 +01:00
use Modules\Interventi\Intervento ;
2017-08-04 16:28:16 +02:00
2020-02-14 17:02:16 +01:00
// CONSUNTIVO
2017-08-04 16:28:16 +02:00
// Tabella con riepilogo interventi
2020-02-14 17:02:16 +01:00
$interventi = Intervento :: where ( 'id_preventivo' , $id_record ) -> get ();
if ( ! empty ( $interventi )) {
2017-08-04 16:28:16 +02:00
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
2020-02-14 17:02:16 +01:00
foreach ( $interventi as $intervento ) {
// Riga per il singolo intervento
2017-08-04 16:28:16 +02:00
echo '
2020-02-14 17:02:16 +01:00
< tr style = " background:'. $intervento->stato ->colore.'; " >
2017-08-04 16:28:16 +02:00
< td >
2020-02-14 17:02:16 +01:00
< a href = " javascript:; " class = " btn btn-primary btn-xs " onclick = " $ ( \ '#dettagli_'. $intervento->id .' \ ').toggleClass( \ 'hide \ '); $ (this).find( \ 'i \ ').toggleClass( \ 'fa-plus \ ').toggleClass( \ 'fa-minus \ '); " >< i class = " fa fa-plus " ></ i ></ a >
'.Modules::link(' Interventi ', $intervento->id, tr(' Intervento num . _NUM_ del _DATE_ ' , [
'_NUM_' => $intervento -> codice ,
'_DATE_' => Translator :: dateToLocale ( $intervento -> inizio ),
2017-09-10 14:35:41 +02:00
])) . '
2017-08-04 16:28:16 +02:00
</ td >
< td class = " text-right " >
2020-02-14 17:02:16 +01:00
'.numberFormat($intervento->ore_totali).'
2017-08-04 16:28:16 +02:00
</ td >
< td class = " text-right " >
2020-02-14 17:02:16 +01:00
'.numberFormat($intervento->km_totali).'
2017-08-04 16:28:16 +02:00
</ td >
< td class = " text-right " >
2020-02-14 17:02:16 +01:00
'.moneyFormat($intervento->spesa).'
2017-08-04 16:28:16 +02:00
</ td >
< td class = " text-right " >
2020-02-14 17:02:16 +01:00
'.moneyFormat($intervento->imponibile).'
2017-08-04 16:28:16 +02:00
</ td >
< td class = " text-right " >
2020-02-14 17:02:16 +01:00
'.moneyFormat($intervento->totale_imponibile).'
2017-08-04 16:28:16 +02:00
</ td >
</ tr > ' ;
// Riga con dettagli
echo '
2020-02-14 17:02:16 +01:00
< tr class = " hide " id = " dettagli_'. $intervento->id .' " >
2017-08-04 16:28:16 +02:00
< td colspan = " 6 " > ' ;
2020-02-14 17:02:16 +01:00
// Lettura sessioni di lavoro
$sessioni = $intervento -> sessioni ;
if ( ! empty ( $sessioni )) {
2017-08-04 16:28:16 +02:00
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 >
2019-09-06 15:08:31 +02:00
< th width = " 120 " > '.tr(' Costo ore ').' </ th >
2017-09-04 12:02:29 +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-04 12:02:29 +02:00
< th width = " 120 " > '.tr(' Prezzo km ').' </ th >
< th width = " 120 " > '.tr(' Diritto ch . ').' </ th >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
2020-02-14 17:02:16 +01:00
foreach ( $sessioni as $sessione ) {
2017-08-04 16:28:16 +02:00
// Visualizzo lo sconto su ore o km se c'è
2020-02-14 17:02:16 +01:00
$sconto_ore = ! empty ( $sessione -> sconto_totale_manodopera ) ? '<br><span class="label label-danger">' . moneyFormat ( - $sessione -> sconto_totale_manodopera ) . '</span>' : '' ;
$sconto_km = ! empty ( $sessione -> sconto_totale_viaggio ) ? '<br><span class="label label-danger">' . moneyFormat ( - $sessione -> sconto_totale_viaggio ) . '</span>' : '' ;
2018-01-19 22:48:39 +01:00
2017-08-04 16:28:16 +02:00
echo '
< tr >
2020-02-14 17:02:16 +01:00
< td > '.$sessione->anagrafica->ragione_sociale.' </ td >
< td > '.$sessione->tipo->descrizione.' </ td >
< td class = " text-right " > '.numberFormat($sessione->ore).' </ td >
< td class = " text-right " > '.numberFormat($sessione->km).' </ td >
< td class = " text-right danger " > '.moneyFormat($sessione->costo_manodopera).' </ td >
< td class = " text-right danger " > '.moneyFormat($sessione->costo_viaggio).' </ td >
< td class = " text-right danger " > '.moneyFormat($sessione->costo_diritto_chiamata).' </ td >
< td class = " text-right success " > '.moneyFormat($sessione->prezzo_manodopera).$sconto_ore.' </ td >
< td class = " text-right success " > '.moneyFormat($sessione->prezzo_viaggio).$sconto_km.' </ td >
< td class = " text-right success " > '.moneyFormat($sessione->prezzo_diritto_chiamata).' </ td >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
}
echo '
</ table > ' ;
}
2020-02-14 17:02:16 +01:00
// Lettura articoli utilizzati
$articoli = $intervento -> articoli ;
if ( ! $articoli -> isEmpty ()) {
2017-08-04 16:28:16 +02:00
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 > ' ;
2020-02-14 17:02:16 +01:00
foreach ( $articoli as $articolo ) {
$sconto = ! empty ( $articolo -> sconto ) ? '<br><span class="label label-danger">' . moneyFormat ( - $articolo -> sconto ) . '</span>' : '' ;
2017-08-04 16:28:16 +02:00
echo '
< tr >
< td >
2020-02-14 17:02:16 +01:00
'.Modules::link(' Articoli ', $articolo->idarticolo, $articolo->descrizione).'
2017-08-04 16:28:16 +02:00
</ td >
2020-02-14 17:02:16 +01:00
< td class = " text-right " > '.numberFormat($articolo->qta, ' qta ').' </ td >
< td class = " text-right danger " > '.moneyFormat($articolo->spesa).' </ td >
< td class = " text-right success " > '.moneyFormat($articolo->imponibile).$sconto.' </ td >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
}
echo '
</ table > ' ;
}
2020-02-14 17:02:16 +01:00
// Lettura spese aggiuntive
$righe = $intervento -> righe ;
if ( ! $righe -> isEmpty ()) {
2017-08-04 16:28:16 +02:00
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 > ' ;
2020-02-14 17:02:16 +01:00
foreach ( $righe as $riga ) {
$sconto = ! empty ( $riga -> sconto ) ? '<br><span class="label label-danger">' . moneyFormat ( - $riga -> sconto ) . '</span>' : '' ;
2017-08-04 16:28:16 +02:00
echo '
< tr >
< td >
2020-02-14 17:02:16 +01:00
'.$riga->descrizione.'
2017-08-04 16:28:16 +02:00
</ td >
2020-02-14 17:02:16 +01:00
< td class = " text-right " > '.numberFormat($riga->qta, ' qta ').' </ td >
< td class = " text-right danger " > '.moneyFormat($riga->spesa).' </ td >
< td class = " text-right success " > '.moneyFormat($riga->imponibile).$sconto.' </ td >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
}
echo '
</ table > ' ;
}
echo '
</ td >
</ tr > ' ;
}
2020-02-14 17:02:16 +01:00
$array_interventi = $interventi -> toArray ();
$totale_ore = sum ( array_column ( $array_interventi , 'ore_totali' ));
$totale_km = sum ( array_column ( $array_interventi , 'km_totali' ));
$totale_costo = sum ( array_column ( $array_interventi , 'spesa' ));
$totale_addebito = sum ( array_column ( $array_interventi , 'imponibile' ));
$totale = sum ( array_column ( $array_interventi , 'totale_imponibile' ));
2017-08-04 16:28:16 +02:00
// Totali
echo '
< tr >
2020-07-06 13:19:20 +02:00
< td class = " text-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 '
2020-07-06 13:19:20 +02:00
< td class = " text-right " >
2020-02-14 17:02:16 +01:00
< big >< b > '.numberFormat($totale_ore).' </ b ></ big >
2017-08-04 16:28:16 +02:00
</ td > ' ;
echo '
2020-07-06 13:19:20 +02:00
< td class = " text-right " >
2020-02-14 17:02:16 +01:00
< big >< b > '.numberFormat($totale_km).' </ b ></ big >
2017-08-04 16:28:16 +02:00
</ td > ' ;
echo '
2020-07-06 13:19:20 +02:00
< td class = " text-right " >
2020-02-14 17:02:16 +01:00
< big >< b > '.moneyFormat($totale_costo).' </ b ></ big >
2017-08-04 16:28:16 +02:00
</ td > ' ;
echo '
2020-07-06 13:19:20 +02:00
< td class = " text-right " >
2020-02-14 17:02:16 +01:00
< big >< b > '.moneyFormat($totale_addebito).' </ b ></ big >
2017-08-04 16:28:16 +02:00
</ td > ' ;
echo '
2020-07-06 13:19:20 +02:00
< td class = " text-right " >
2020-02-14 17:02:16 +01:00
< big >< b > '.moneyFormat($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 > ' ;
2020-02-14 17:02:16 +01:00
$stati = $interventi -> groupBy ( 'idstatointervento' );
foreach ( $stati as $interventi_collegati ) {
$stato = $interventi_collegati -> first () -> stato ;
$totale_stato = sum ( array_column ( $interventi_collegati -> toArray (), 'totale_imponibile' ));
2017-08-04 16:28:16 +02:00
echo '
< tr >
< td colspan = " 3 " ></ td >
2020-07-06 13:19:20 +02:00
< td class = " text-right " colspan = " 2 " style = " background:'. $stato->colore .'; " >
2020-02-14 17:02:16 +01:00
< big >< b > '.$stato->descrizione.' :</ b ></ big >
2017-08-04 16:28:16 +02:00
</ td >
2020-07-06 13:19:20 +02:00
< td class = " text-right " >
2020-02-14 17:02:16 +01:00
< big >< b > '.moneyFormat($totale_stato).' </ b ></ big >
2017-08-04 16:28:16 +02:00
</ td >
</ tr > ' ;
}
echo '
</ table > ' ;
}
2020-02-14 17:02:16 +01:00
// Bilancio del preventivo
$budget = $preventivo -> totale_imponibile ;
2018-11-22 15:34:44 +01:00
$diff = sum ( $budget , - $totale );
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 > ' ;
2018-11-22 15:34:44 +01:00
if ( $diff > 0 ) {
2017-08-04 16:28:16 +02:00
echo '
2019-04-13 02:56:39 +02:00
< span class = " text-success " >< big >+ '.moneyFormat($diff).' </ big ></ span > ' ;
2017-08-04 16:28:16 +02:00
} elseif ( $diff < 0 ) {
echo '
2019-04-13 02:56:39 +02:00
< span class = " text-danger " >< big > '.moneyFormat($diff).' </ big ></ span > ' ;
2017-08-04 16:28:16 +02:00
} else {
echo '
2019-04-13 02:56:39 +02:00
< span >< big > '.moneyFormat($diff).' </ 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 > ' ;
}