2017-08-04 16:28:16 +02:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright ( C ) DevCode s . r . l .
2020-09-07 15:04:06 +02:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*/
2017-08-04 16:28:16 +02:00
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
2022-02-04 16:55:54 +01:00
$tipologie = [];
$tecnici = [];
$stati_intervento = [];
$materiali_art = [];
$materiali_righe = [];
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 >
2021-12-20 12:15:00 +01:00
< th width = " 125 " > '.tr(' Ore ').' </ th >
< th width = " 125 " > '.tr(' Km ').' </ th >
< th width = " 145 " > '.tr(' Costo ').' </ th >
< th width = " 145 " > '.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_ ' , [
2024-03-22 15:52:24 +01:00
'_NUM_' => $intervento -> codice ,
'_DATE_' => Translator :: dateToLocale ( $intervento -> inizio ),
])) . '
2017-08-04 16:28:16 +02:00
</ td >
< td class = " text-right " >
2023-08-04 14:54:28 +02:00
'.($intervento->ore_totali <= 0 ? ' < i class = " fa fa-warning tip " style = " position:relative;margin-left:-16px; " title = " '.tr('Questa sessione è vuota').' " ></ i > ' : ' ').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->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 .' " >
2021-12-20 12:15:00 +01:00
< td colspan = " 5 " > ' ;
2017-08-04 16:28:16 +02:00
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 >
2021-12-20 12:15:00 +01:00
< th width = " 210 " > '.tr(' Tipo attività ').' </ th >
< th width = " 110 " > '.tr(' Ore ').' </ th >
< th width = " 110 " > '.tr(' Km ').' </ th >
< th width = " 110 " > '.tr(' Costo ore ').' </ th >
< th width = " 110 " > '.tr(' Costo km ').' </ th >
< th width = " 110 " > '.tr(' Diritto ch . ').' </ th >
< th width = " 110 " > '.tr(' Prezzo ore ').' </ th >
< th width = " 110 " > '.tr(' Prezzo km ').' </ th >
< th width = " 110 " > '.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 >
2024-04-18 17:44:05 +02:00
< td > '.$sessione->tipo->getTranslation(' title ').' </ td >
2020-02-14 17:02:16 +01:00
< 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 > ' ;
2021-12-20 12:15:00 +01:00
// Raggruppamento per tipologia descrizione
2024-04-18 17:44:05 +02:00
$tipologie [ $sessione -> tipo -> getTranslation ( 'title' )][ 'ore' ] += $sessione -> ore ;
$tipologie [ $sessione -> tipo -> getTranslation ( 'title' )][ 'costo' ] += $sessione -> costo_manodopera + $sessione -> costo_viaggio + $sessione -> costo_diritto_chiamata ;
$tipologie [ $sessione -> tipo -> getTranslation ( 'title' )][ 'ricavo' ] += $sessione -> prezzo_manodopera - $sessione -> sconto_totale_manodopera + $sessione -> prezzo_viaggio - $sessione -> sconto_totale_viaggio + $sessione -> prezzo_diritto_chiamata ;
2023-08-04 14:54:28 +02:00
2021-12-20 12:15:00 +01:00
// Raggruppamento per tecnico
$tecnici [ $sessione -> anagrafica -> ragione_sociale ][ 'ore' ] += $sessione -> ore ;
$tecnici [ $sessione -> anagrafica -> ragione_sociale ][ 'km' ] += $sessione -> km ;
$tecnici [ $sessione -> anagrafica -> ragione_sociale ][ 'costo' ] += $sessione -> costo_manodopera + $sessione -> costo_viaggio + $sessione -> costo_diritto_chiamata ;
2023-11-23 09:50:38 +01:00
$tecnici [ $sessione -> anagrafica -> ragione_sociale ][ 'ricavo' ] += $sessione -> prezzo_manodopera - $sessione -> sconto_totale_manodopera + $sessione -> prezzo_viaggio - $sessione -> sconto_totale_viaggio + $sessione -> prezzo_diritto_chiamata ;
2021-12-20 12:15:00 +01:00
// Raggruppamento per stato intervento
2024-04-18 17:44:05 +02:00
$stati_intervento [ $intervento -> stato -> getTranslation ( 'title' )][ 'colore' ] = $intervento -> stato -> colore ;
$stati_intervento [ $intervento -> stato -> getTranslation ( 'title' )][ 'ore' ] += $sessione -> ore ;
$stati_intervento [ $intervento -> stato -> getTranslation ( 'title' )][ 'costo' ] += $sessione -> costo_manodopera + $sessione -> costo_viaggio + $sessione -> costo_diritto_chiamata ;
$stati_intervento [ $intervento -> stato -> getTranslation ( 'title' )][ 'ricavo' ] += $sessione -> prezzo_manodopera - $sessione -> sconto_totale_manodopera + $sessione -> prezzo_viaggio - $sessione -> sconto_totale_viaggio + $sessione -> prezzo_diritto_chiamata ;
2017-08-04 16:28:16 +02:00
}
echo '
</ table > ' ;
}
2020-02-14 17:02:16 +01:00
// Lettura articoli utilizzati
2024-03-25 17:20:23 +01:00
$righe_articoli = $intervento -> articoli ;
if ( ! $righe_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 > ' ;
2024-03-25 17:20:23 +01:00
foreach ( $righe_articoli as $riga_articolo ) {
$sconto = ! empty ( $riga_articolo -> sconto ) ? '<br><span class="label label-danger">' . moneyFormat ( - $riga_articolo -> sconto ) . '</span>' : '' ;
2017-08-04 16:28:16 +02:00
echo '
< tr >
< td >
2024-03-25 17:20:23 +01:00
'.Modules::link(' Articoli ', $riga_articolo->idarticolo, $riga_articolo->descrizione).'
2017-08-04 16:28:16 +02:00
</ td >
2024-03-25 17:20:23 +01:00
< td class = " text-right " > '.numberFormat($riga_articolo->qta, ' qta ').' </ td >
< td class = " text-right danger " > '.moneyFormat($riga_articolo->spesa).' </ td >
< td class = " text-right success " > '.moneyFormat($riga_articolo->imponibile).$sconto.' </ td >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
2021-12-20 12:15:00 +01:00
2021-12-27 15:05:20 +01:00
// Raggruppamento per articolo con lo stesso prezzo
2024-03-25 17:20:23 +01:00
if ( $riga_articolo -> qta ) {
$ricavo = ( $riga_articolo -> imponibile - $riga_articolo -> sconto ) / $riga_articolo -> qta ;
$costo = $riga_articolo -> spesa / $riga_articolo -> qta ;
2024-02-05 17:07:33 +01:00
}
2024-04-18 17:44:05 +02:00
$descrizione = $riga_articolo -> articolo -> codice . ' - ' . $riga_articolo -> articolo -> getTranslation ( 'title' );
2021-12-27 15:05:20 +01:00
2024-03-25 17:20:23 +01:00
$materiali_art [ $descrizione ][ $ricavo ][ $costo ][ 'id' ] = $riga_articolo -> articolo -> id ;
$materiali_art [ $descrizione ][ $ricavo ][ $costo ][ 'qta' ] += $riga_articolo -> qta ;
$materiali_art [ $descrizione ][ $ricavo ][ $costo ][ 'costo' ] += $riga_articolo -> spesa ;
$materiali_art [ $descrizione ][ $ricavo ][ $costo ][ 'ricavo' ] += $riga_articolo -> imponibile - $riga_articolo -> sconto ;
2017-08-04 16:28:16 +02:00
}
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 > ' ;
2021-12-27 15:05:20 +01:00
// Raggruppamento per riga
$materiali_righe [ $riga -> descrizione ][ 'qta' ] += $riga -> qta ;
$materiali_righe [ $riga -> descrizione ][ 'costo' ] += $riga -> spesa ;
$materiali_righe [ $riga -> descrizione ][ 'ricavo' ] += $riga -> imponibile - $riga -> sconto ;
2017-08-04 16:28:16 +02:00
}
echo '
</ table > ' ;
}
echo '
</ td >
</ tr > ' ;
}
2020-02-14 17:02:16 +01:00
$array_interventi = $interventi -> toArray ();
$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' ));
2021-12-20 12:15:00 +01:00
$totale_ore = sum ( array_column ( $array_interventi , 'ore_totali' ));
2020-02-14 17:02:16 +01:00
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).' </ b ></ big >
2017-08-04 16:28:16 +02:00
</ td >
2021-12-20 12:15:00 +01:00
</ tr >
2017-08-04 16:28:16 +02:00
</ table > ' ;
}
2020-02-14 17:02:16 +01:00
// Bilancio del preventivo
$budget = $preventivo -> totale_imponibile ;
2023-06-13 16:37:43 +02:00
$diff = sum ( $budget , - $totale ) - $preventivo -> provvigione ;
2017-08-04 16:28:16 +02:00
echo '
< div class = " well text-center " >
< br >< span >< big >
2022-09-30 12:18:45 +02:00
< b > '.tr(' Budget rimanente ').' :< 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
}
2024-01-15 15:30:45 +01:00
echo '
2017-08-04 16:28:16 +02:00
</ b ></ big ></ span >
< br >< br >
2021-12-20 12:15:00 +01:00
< div class = " row " >
< div class = " col-md-6 " >
< table class = " table text-left table-striped table-bordered " >
< tr >
< th > '.tr(' Tipologia ').' </ th >
2022-09-30 12:18:45 +02:00
< th width = " 11% " > '.tr(' Ore ').' </ th >
< th width = " 15% " > '.tr(' Costo ').' </ th >
< th width = " 15% " > '.tr(' Ricavo ').' </ th >
< th width = " 15% " > '.tr(' Margine ').' </ th >
< th width = " 15% " > '.tr(' Ricarico ').' </ th >
2021-12-20 12:15:00 +01:00
</ tr > ' ;
2024-01-15 15:30:45 +01:00
ksort ( $tipologie );
foreach ( $tipologie as $key => $tipologia ) {
$margine = $tipologia [ 'ricavo' ] - $tipologia [ 'costo' ];
$margine_prc = ( $tipologia [ 'ricavo' ] && $tipologia [ 'costo' ]) ? ( int ) ( 1 - ( $tipologia [ 'costo' ] / $tipologia [ 'ricavo' ])) * 100 : 100 ;
$ricarico_prc = ( $tipologia [ 'ricavo' ] && $tipologia [ 'costo' ]) ? ( int ) ((( $tipologia [ 'ricavo' ] / $tipologia [ 'costo' ]) - 1 ) * 100 ) : 100 ;
echo '
2021-12-20 12:15:00 +01:00
< tr >
< td > '.$key.' </ td >
< td class = " text-right " > '.Translator::numberToLocale($tipologia[' ore ']).' </ td >
< td class = " text-right " > '.Translator::numberToLocale($tipologia[' costo ']).' € </ td >
< td class = " text-right " > '.Translator::numberToLocale($tipologia[' ricavo ']).' € </ td >
2023-08-04 14:54:28 +02:00
< td class = " text-right '.( $margine > 0 ? 'bg-success' : 'bg-danger').' " > '.Translator::numberToLocale($margine).' € ( '.$margine_prc.' % ) </ td >
< td class = " text-right '.( $margine > 0 ? 'bg-success' : 'bg-danger').' " > '.Translator::numberToLocale($margine).' € ( '.$ricarico_prc.' % ) </ td >
2021-12-20 12:15:00 +01:00
</ tr > ' ;
2024-01-15 15:30:45 +01:00
}
echo '
2021-12-20 12:15:00 +01:00
</ table >
</ div >
< div class = " col-md-6 " >
< table class = " table text-left table-striped table-bordered " >
< tr >
< th > '.tr(' Tecnici ').' </ th >
2022-09-30 12:18:45 +02:00
< th width = " 11% " > '.tr(' Km ').' </ th >
< th width = " 11% " > '.tr(' Ore ').' </ th >
< th width = " 15% " > '.tr(' Costo ').' </ th >
< th width = " 15% " > '.tr(' Ricavo ').' </ th >
< th width = " 15% " > '.tr(' Margine ').' </ th >
< th width = " 15% " > '.tr(' Ricarico ').' </ th >
2021-12-20 12:15:00 +01:00
</ tr > ' ;
2024-01-15 15:30:45 +01:00
ksort ( $tecnici );
foreach ( $tecnici as $key => $tecnico ) {
$margine = $tecnico [ 'ricavo' ] - $tecnico [ 'costo' ];
$margine_prc = ( $tecnico [ 'ricavo' ] && $tecnico [ 'costo' ]) ? ( int ) ( 1 - ( $tecnico [ 'costo' ] / $tecnico [ 'ricavo' ])) * 100 : 100 ;
$ricarico_prc = ( $tecnico [ 'ricavo' ] && $tecnico [ 'costo' ]) ? ( int ) ((( $tecnico [ 'ricavo' ] / $tecnico [ 'costo' ]) - 1 ) * 100 ) : 100 ;
echo '
2021-12-20 12:15:00 +01:00
< tr >
< td > '.$key.' </ td >
2022-09-30 12:18:45 +02:00
< td class = " text-right " > '.Translator::numberToLocale($tecnico[' km ']).' </ td >
2021-12-20 12:15:00 +01:00
< td class = " text-right " > '.Translator::numberToLocale($tecnico[' ore ']).' </ td >
< td class = " text-right " > '.Translator::numberToLocale($tecnico[' costo ']).' € </ td >
< td class = " text-right " > '.Translator::numberToLocale($tecnico[' ricavo ']).' € </ td >
2023-08-04 14:54:28 +02:00
< td class = " text-right '.( $margine > 0 ? 'bg-success' : 'bg-danger').' " > '.Translator::numberToLocale($margine).' € ( '.$margine_prc.' % ) </ td >
< td class = " text-right '.( $margine > 0 ? 'bg-success' : 'bg-danger').' " > '.Translator::numberToLocale($margine).' € ( '.$ricarico_prc.' % ) </ td >
2021-12-20 12:15:00 +01:00
</ tr > ' ;
2024-01-15 15:30:45 +01:00
}
echo '
2021-12-20 12:15:00 +01:00
</ table >
</ div >
</ div >
< div class = " row " >
< div class = " col-md-6 " >
< table class = " table text-left table-striped table-bordered " >
< tr >
< th > '.tr(' Stato ').' </ th >
2022-09-30 12:18:45 +02:00
< th width = " 11% " > '.tr(' Ore ').' </ th >
< th width = " 15% " > '.tr(' Costo ').' </ th >
< th width = " 15% " > '.tr(' Ricavo ').' </ th >
< th width = " 15% " > '.tr(' Margine ').' </ th >
< th width = " 15% " > '.tr(' Ricarico ').' </ th >
2021-12-20 12:15:00 +01:00
</ tr > ' ;
2024-01-15 15:30:45 +01:00
ksort ( $stati_intervento );
foreach ( $stati_intervento as $key => $stato ) {
$margine = $stato [ 'ricavo' ] - $stato [ 'costo' ];
$margine_prc = ( $stato [ 'ricavo' ] && $stato [ 'costo' ]) ? ( int ) ( 1 - ( $stato [ 'costo' ] / $stato [ 'ricavo' ])) * 100 : 100 ;
$ricarico_prc = ( $stato [ 'ricavo' ] && $stato [ 'costo' ]) ? ( int ) ((( $stato [ 'ricavo' ] / $stato [ 'costo' ]) - 1 ) * 100 ) : 100 ;
echo '
2021-12-20 12:15:00 +01:00
< tr >
< td >< div class = " img-circle " style = " width:18px; height:18px; position:relative; bottom:-2px; background:'. $stato['colore'] .'; float:left; " ></ div > '.$key.' </ td >
< td class = " text-right " > '.Translator::numberToLocale($stato[' ore ']).' </ td >
< td class = " text-right " > '.Translator::numberToLocale($stato[' costo ']).' € </ td >
< td class = " text-right " > '.Translator::numberToLocale($stato[' ricavo ']).' € </ td >
2023-08-04 14:54:28 +02:00
< td class = " text-right '.( $margine > 0 ? 'bg-success' : 'bg-danger').' " > '.Translator::numberToLocale($margine).' € ( '.$margine_prc.' % ) </ td >
< td class = " text-right '.( $margine > 0 ? 'bg-success' : 'bg-danger').' " > '.Translator::numberToLocale($margine).' € ( '.$ricarico_prc.' % ) </ td >
2021-12-20 12:15:00 +01:00
</ tr > ' ;
2024-01-15 15:30:45 +01:00
}
echo '
2021-12-20 12:15:00 +01:00
</ table >
</ div >
< div class = " col-md-6 " >
< table class = " table text-left table-striped table-bordered " >
< tr >
< th > '.tr(' Materiale ').' </ th >
2022-09-30 12:18:45 +02:00
< th width = " 11% " > '.tr(' Qtà ').' </ th >
< th width = " 15% " > '.tr(' Costo ').' </ th >
< th width = " 15% " > '.tr(' Ricavo ').' </ th >
< th width = " 15% " > '.tr(' Margine ').' </ th >
< th width = " 15% " > '.tr(' Ricarico ').' </ th >
2021-12-20 12:15:00 +01:00
</ tr > ' ;
2024-01-15 15:30:45 +01:00
ksort ( $materiali_art );
foreach ( $materiali_art as $key => $materiali_array1 ) {
foreach ( $materiali_array1 as $materiali_array2 ) {
foreach ( $materiali_array2 as $materiale ) {
$margine = $materiale [ 'ricavo' ] - $materiale [ 'costo' ];
$margine_prc = ( $materiale [ 'ricavo' ] && $materiale [ 'costo' ]) ? ( int ) ( 1 - ( $materiale [ 'costo' ] / $materiale [ 'ricavo' ])) * 100 : 100 ;
$ricarico_prc = ( $materiale [ 'ricavo' ] && $materiale [ 'costo' ]) ? ( int ) ((( $materiale [ 'ricavo' ] / $materiale [ 'costo' ]) - 1 ) * 100 ) : 100 ;
echo '
2021-12-27 15:05:20 +01:00
< tr >
< td > '.Modules::link(' Articoli ', $materiale[' id '], $key).' </ td >
< td class = " text-center " > '.$materiale[' qta '].' </ td >
< td class = " text-right " > '.Translator::numberToLocale($materiale[' costo ']).' € </ td >
< td class = " text-right " > '.Translator::numberToLocale($materiale[' ricavo ']).' € </ td >
2023-08-04 14:54:28 +02:00
< td class = " text-right '.( $margine > 0 ? 'bg-success' : 'bg-danger').' " > '.Translator::numberToLocale($margine).' € ( '.$margine_prc.' % ) </ td >
< td class = " text-right '.( $margine > 0 ? 'bg-success' : 'bg-danger').' " > '.Translator::numberToLocale($margine).' € ( '.$ricarico_prc.' % ) </ td >
2021-12-27 15:05:20 +01:00
</ tr > ' ;
2024-01-15 15:30:45 +01:00
}
}
}
2021-12-27 15:05:20 +01:00
2024-01-15 15:30:45 +01:00
ksort ( $materiali_righe );
foreach ( $materiali_righe as $key => $materiale ) {
$margine = $materiale [ 'ricavo' ] - $materiale [ 'costo' ];
$margine_prc = ( $materiale [ 'ricavo' ]) ? ( int ) ( 1 - ( $materiale [ 'costo' ] / $materiale [ 'ricavo' ])) * 100 : 0 ;
$ricarico_prc = ( $materiale [ 'ricavo' ] && $materiale [ 'costo' ]) ? ( int ) ((( $materiale [ 'ricavo' ] / $materiale [ 'costo' ]) - 1 ) * 100 ) : 100 ;
echo '
2021-12-20 12:15:00 +01:00
< tr >
< td > '.$key.' </ td >
2021-12-27 15:05:20 +01:00
< td class = " text-center " > '.$materiale[' qta '].' </ td >
2021-12-20 12:15:00 +01:00
< td class = " text-right " > '.Translator::numberToLocale($materiale[' costo ']).' € </ td >
< td class = " text-right " > '.Translator::numberToLocale($materiale[' ricavo ']).' € </ td >
2023-08-04 14:54:28 +02:00
< td class = " text-right '.( $margine > 0 ? 'bg-success' : 'bg-danger').' " > '.Translator::numberToLocale($margine).' € ( '.$margine_prc.' % ) </ td >
< td class = " text-right '.( $margine > 0 ? 'bg-success' : 'bg-danger').' " > '.Translator::numberToLocale($margine).' € ( '.$ricarico_prc.' % ) </ td >
2021-12-20 12:15:00 +01:00
</ tr > ' ;
2024-01-15 15:30:45 +01:00
}
echo '
2021-12-20 12:15:00 +01:00
</ table >
</ div >
</ div >
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 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)
2022-05-26 16:44:51 +02:00
$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_contratto IS NULL AND id_ordine 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' ]);
$count = $dbo -> fetchNum ( $query );
2024-01-15 15:30:45 +01:00
echo ' < hr >
2022-05-26 16:44:51 +02:00
< form action = " " method = " post " id = " aggiungi-intervento " >
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " op " value = " addintervento " >
< input type = " hidden " name = " backto " value = " record-edit " >
< div class = " row " >
2022-05-26 16:44:51 +02:00
< div class = " col-md-8 " >
{[ " type " : " select " , " label " : " '.tr('Aggiungi un intervento a questo preventivo').' ('. $count .') " , " name " : " idintervento " , " values " : " query='. $query .' " , " required " : " 1 " ]}
2017-08-04 16:28:16 +02:00
</ div >
<!-- PULSANTI -->
2022-05-26 16:44:51 +02:00
< div class = " col-md-4 " >
< p style = " margin-top:-5px; " >& nbsp ; </ p >
2024-01-15 15:30:45 +01:00
< button type = " button " class = " btn btn-primary " onclick = " if( $ ( \ '#aggiungi-intervento \ ').parsley().validate() && confirm( \ ''.tr('Aggiungere questo intervento al preventivo?').' \ ') ) { $ ( \ '#aggiungi-intervento \ ').submit(); } " '.(($record[' is_pianificabile '] && !$block_edit) ? ' ' : ' disabled ').' >
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 > ' ;