2017-08-04 16:28:16 +02:00
< ? php
2019-11-08 15:09:05 +01:00
include_once __DIR__ . '/../../core.php' ;
2018-06-23 15:41:32 +02:00
2017-08-04 16:28:16 +02:00
$show_costi = true ;
// Limitazione delle azioni dei tecnici
if ( $user [ 'gruppo' ] == 'Tecnici' ) {
2018-07-08 18:11:17 +02:00
$show_costi = ! empty ( $user [ 'idanagrafica' ]) && setting ( 'Mostra i prezzi al tecnico' );
2017-08-04 16:28:16 +02:00
}
2018-11-01 12:39:54 +01:00
// Stato dell'intervento
$rss = $dbo -> fetchArray ( 'SELECT completato AS flag_completato FROM in_statiintervento WHERE idstatointervento = (SELECT idstatointervento FROM in_interventi WHERE id=' . prepare ( $id_record ) . ')' );
$is_completato = $rss [ 0 ][ 'flag_completato' ];
2018-02-16 15:45:15 +01:00
2018-11-01 12:39:54 +01:00
// Sessioni dell'intervento
2018-12-05 11:38:36 +01:00
$query = ' SELECT in_interventi_tecnici .* , an_anagrafiche . ragione_sociale , an_anagrafiche . deleted_at AS anagrafica_deleted_at , in_tipiintervento . descrizione AS descrizione_tipo , in_interventi_tecnici . tipo_scontokm AS tipo_sconto_km FROM in_interventi_tecnici
2018-11-01 12:39:54 +01:00
INNER JOIN an_anagrafiche ON in_interventi_tecnici . idtecnico = an_anagrafiche . idanagrafica
INNER JOIN in_tipiintervento ON in_interventi_tecnici . idtipointervento = in_tipiintervento . idtipointervento
2018-11-30 16:10:15 +01:00
WHERE in_interventi_tecnici . idintervento = '.prepare($id_record).' ORDER BY ragione_sociale ASC , in_interventi_tecnici . orario_inizio ASC , in_interventi_tecnici . id ASC ' ;
2018-11-01 12:39:54 +01:00
$sessioni = $dbo -> fetchArray ( $query );
2017-08-04 16:28:16 +02:00
$prev_tecnico = '' ;
2018-11-01 12:39:54 +01:00
if ( ! empty ( $sessioni )) {
foreach ( $sessioni as $key => $sessione ) {
2017-08-04 16:28:16 +02:00
// Intestazione tecnico
2018-11-01 12:39:54 +01:00
if ( $prev_tecnico != $sessione [ 'ragione_sociale' ]) {
$prev_tecnico = $sessione [ 'ragione_sociale' ];
2017-09-14 16:20:11 +02:00
2017-08-04 16:28:16 +02:00
echo '
< div class = " table-responsive " >
2017-09-14 16:20:11 +02:00
< table class = " table table-striped table-hover table-condensed " >
2017-08-04 16:28:16 +02:00
< tr >
2018-11-01 12:39:54 +01:00
< th >< i class = " fa fa-user " ></ i > '.$sessione[' ragione_sociale '].' '.(($sessione[' anagrafica_deleted_at ']) ? ' < small class = " text-danger " >< em > ( '.tr(' Eliminato ').' ) </ em ></ small > ' : ' ').' </ th >
< th width = " 20% " > '.tr(' Orario inizio ').' </ th >
< th width = " 20% " > '.tr(' Orario fine ').' </ th >
< th width = " 5% " > '.tr(' Ore ').' </ th >
< th width = " 5% " > '.tr(' Km ').' </ th > ' ;
if ( $show_costi ) {
echo '
< th width = " 10% " > '.tr(' Sconto ore ').' </ th >
< th width = " 10% " > '.tr(' Sconto km ').' </ th > ' ;
}
if ( ! $is_completato ) {
echo '
< th width = " 120 " class = " text-center " > #</th>';
}
echo '
2017-08-04 16:28:16 +02:00
</ tr > ' ;
}
// Lettura costi unitari salvati al momento dell'intervento
2018-11-01 12:39:54 +01:00
$sconto = $sessione [ 'sconto' ];
$scontokm = $sessione [ 'scontokm' ];
2017-08-04 16:28:16 +02:00
2018-11-01 12:39:54 +01:00
$costo_ore_unitario = $sessione [ 'prezzo_ore_unitario' ];
$costo_km_unitario = $sessione [ 'prezzo_km_unitario' ];
$costo_dirittochiamata = $sessione [ 'prezzo_dirittochiamata' ];
2017-08-04 16:28:16 +02:00
2018-11-01 12:39:54 +01:00
$costo_ore_unitario_tecnico = $sessione [ 'prezzo_ore_unitario_tecnico' ];
$costo_km_unitario_tecnico = $sessione [ 'prezzo_km_unitario_tecnico' ];
$costo_dirittochiamata_tecnico = $sessione [ 'prezzo_dirittochiamata_tecnico' ];
2017-08-04 16:28:16 +02:00
2018-11-01 12:39:54 +01:00
$costo_km_consuntivo_tecnico = $sessione [ 'prezzo_km_consuntivo_tecnico' ];
$costo_ore_consuntivo_tecnico = $sessione [ 'prezzo_ore_consuntivo_tecnico' ];
$costo_km_consuntivo = $sessione [ 'prezzo_km_consuntivo' ];
$costo_ore_consuntivo = $sessione [ 'prezzo_ore_consuntivo' ];
2017-08-04 16:28:16 +02:00
2018-11-02 12:44:07 +01:00
$ore = $sessione [ 'ore' ];
$km = $sessione [ 'km' ];
2018-11-01 12:39:54 +01:00
// Tipologia
2017-08-04 16:28:16 +02:00
echo '
2018-11-01 12:39:54 +01:00
< tr >
< td >
'.$sessione[' descrizione_tipo '].'
2017-08-04 16:28:16 +02:00
</ td > ' ;
2017-09-01 18:13:25 +02:00
// Orario di inizio
2017-08-04 16:28:16 +02:00
echo '
2018-06-23 15:41:32 +02:00
< td >
2018-11-01 12:39:54 +01:00
'.Translator::timestampToLocale($sessione[' orario_inizio ']).'
2017-08-04 16:28:16 +02:00
</ td > ' ;
2017-09-01 18:13:25 +02:00
// Orario di fine
echo '
2018-11-01 12:39:54 +01:00
< td >
'.Translator::timestampToLocale($sessione[' orario_fine ']).'
</ td > ' ;
2017-09-01 18:13:25 +02:00
2017-08-04 16:28:16 +02:00
// ORE
echo '
< td style = " border-right:1px solid #aaa; " >
2018-11-02 12:44:07 +01:00
'.Translator::numberToLocale($ore).'
2017-08-04 16:28:16 +02:00
< div class = " extra hide " >
< table class = " table table-condensed table-bordered " >
2018-11-01 12:39:54 +01:00
< tr >
< th class = " text-danger " > '.tr(' Costo ').' :</ th >
< td align = " right " >
' . Translator :: numberToLocale ( $costo_ore_consuntivo_tecnico ) . "
< small class = 'help-block' > " .Translator::numberToLocale( $costo_ore_unitario_tecnico ).'x'.Translator::numberToLocale( $ore ).'<br>+'.Translator::numberToLocale( $costo_dirittochiamata_tecnico ).'</small>
</ td >
</ tr >
< tr >
< th > '.tr(' Addebito ').' :</ th >
< td align = " right " >
'.Translator::numberToLocale($costo_ore_consuntivo).'
< small class = " help-block " > '.Translator::numberToLocale($costo_ore_unitario).' x '.Translator::numberToLocale($ore).' < br >+ '.Translator::numberToLocale($costo_dirittochiamata).' </ small >
</ td >
</ tr >
< tr >
< th > '.tr(' Scontato ').' :</ th >
< td align = " right " > '.Translator::numberToLocale($costo_ore_consuntivo - $sconto).' </ td >
</ tr >
2017-08-04 16:28:16 +02:00
</ table >
</ div >
</ td > ' ;
// KM
echo '
< td style = " border-right:1px solid #aaa; " >
2018-11-02 12:44:07 +01:00
'.Translator::numberToLocale($km).'
2017-08-04 16:28:16 +02:00
< div class = " extra hide " >
< table class = " table table-condensed table-bordered " >
< tr >
2017-09-04 12:02:29 +02:00
< th class = " text-danger " > '.tr(' Costo ').' :</ th >
2017-08-04 16:28:16 +02:00
< td align = " right " >
'.Translator::numberToLocale($costo_km_consuntivo_tecnico).'
< small class = " help-block " >
'.Translator::numberToLocale($costo_km_unitario_tecnico).' x '.Translator::numberToLocale($km).'
</ small >< br >
</ td >
</ tr >
< tr >
2017-09-04 12:02:29 +02:00
< th > '.tr(' Addebito ').' :</ th >
2017-08-04 16:28:16 +02:00
< td align = " right " >
'.Translator::numberToLocale($costo_km_consuntivo).'
< small class = " help-block " >
'.Translator::numberToLocale($costo_km_unitario).' x '.Translator::numberToLocale($km).'
</ small >< br >
</ td >
</ tr >
< tr >
2017-09-04 12:02:29 +02:00
< th > '.tr(' Scontato ').' :</ th >
2017-08-04 16:28:16 +02:00
< td align = " right " > '.Translator::numberToLocale($costo_km_consuntivo - $scontokm).' </ td >
</ tr >
</ table >
</ div >
</ td > ' ;
// Sconto ore
2018-10-12 10:33:08 +02:00
if ( $show_costi ) {
2017-08-04 16:28:16 +02:00
echo '
2018-11-01 12:39:54 +01:00
< td style = " border-right:1px solid #aaa; " >
'.tr(' _TOT_ _TYPE_ ' , [
'_TOT_' => Translator :: numberToLocale ( $sessione [ 'sconto_unitario' ]),
2019-04-13 00:09:48 +02:00
'_TYPE_' => ( $sessione [ 'tipo_sconto' ] == 'PRC' ? '%' : currency ()),
2018-11-01 12:39:54 +01:00
]) . '
2017-08-04 16:28:16 +02:00
</ td > ' ;
2018-11-01 12:39:54 +01:00
}
2017-08-04 16:28:16 +02:00
// Sconto km
2018-10-12 10:33:08 +02:00
if ( $show_costi ) {
2017-08-04 16:28:16 +02:00
echo '
2018-11-01 12:39:54 +01:00
< td style = " border-right:1px solid #aaa; " >
'.tr(' _TOT_ _TYPE_ ' , [
'_TOT_' => Translator :: numberToLocale ( $sessione [ 'scontokm_unitario' ]),
2019-04-13 00:09:48 +02:00
'_TYPE_' => ( $sessione [ 'tipo_sconto_km' ] == 'PRC' ? '%' : currency ()),
2018-11-01 12:39:54 +01:00
]) . '
2017-08-04 16:28:16 +02:00
</ td > ' ;
2018-11-01 12:39:54 +01:00
}
2017-08-04 16:28:16 +02:00
2018-11-01 12:39:54 +01:00
// Pulsante per la sessione
if ( ! $is_completato ) {
2018-02-16 15:45:15 +01:00
echo '
2018-11-01 12:39:54 +01:00
< td class = " text-center " >
2019-07-29 13:16:55 +02:00
< button type = " button " class = " btn btn-sm btn-warning " onclick = " launch_modal( \ ''.tr('Modifica sessione').' \ ', \ ''. $module->fileurl ('manage_sessione.php').'?id_module='. $id_module .'&id_record='. $id_record .'&id_sessione='. $sessione['id'] .' \ '); " title = " '.tr('Modifica sessione').' " >< i class = " fa fa-edit " ></ i ></ button >
2018-11-01 12:39:54 +01:00
< button type = " button " class = " btn btn-sm btn-danger " id = " delbtn_'. $sessione['id'] .' " onclick = " elimina_sessione( \ ''. $sessione['id'] .' \ '); " title = " Elimina riga " class = " only_rw " >< i class = " fa fa-trash " ></ i ></ button >
</ td > ' ;
2018-02-16 15:45:15 +01:00
}
2018-02-18 19:53:23 +01:00
2017-08-04 16:28:16 +02:00
echo '
</ tr > ' ;
// Intestazione tecnico
2018-11-01 12:39:54 +01:00
if ( ! isset ( $sessioni [ $key + 1 ][ 'ragione_sociale' ]) || $sessione [ 'ragione_sociale' ] != $sessioni [ $key + 1 ][ 'ragione_sociale' ]) {
2017-08-04 16:28:16 +02:00
echo '
</ table >
</ div > ' ;
}
}
} else {
2018-11-01 12:39:54 +01:00
echo '
< div class = \ 'alert alert-info\' ><i class=\'fa fa-info-circle\'></i> ' . tr ( 'Nessun tecnico assegnato' ) . '.</div>' ;
2017-08-04 16:28:16 +02:00
}
2018-11-01 12:39:54 +01:00
if ( ! $is_completato ) {
2018-02-16 15:45:15 +01:00
echo '
2018-11-01 12:39:54 +01:00
<!-- AGGIUNTA TECNICO -->
< div class = " row " >
2018-11-20 21:53:43 +01:00
< div class = " col-md-offset-6 col-md-4 " >
2019-07-08 18:10:52 +02:00
{[ " type " : " select " , " label " : " '.tr('Tecnico').' " , " name " : " nuovotecnico " , " placeholder " : " '.tr('Seleziona un tecnico').' " , " ajax-source " : " tecnici " , " icon-after " : " add|'.Modules::get('Anagrafiche')['id'].'|tipoanagrafica=Tecnico " ]}
2018-11-01 12:39:54 +01:00
</ div >
2018-11-20 21:53:43 +01:00
< div class = " col-md-2 " >
< label >& nbsp ; </ label >
< button type = " button " class = " btn btn-primary btn-block " onclick = " if( $ ( \ '#nuovotecnico \ ').val()) { add_tecnici( $ ( \ '#nuovotecnico \ ').val()); }else { swal( \ ''.tr('Attenzione').' \ ', \ ''.tr('Seleziona il tecnico da aggiungere').'. \ ', \ 'warning \ '); $ ( \ '#nuovotecnico \ ').focus(); } " >
< i class = " fa fa-plus " ></ i > '.tr(' Aggiungi ').'
2018-11-01 12:39:54 +01:00
</ button >
</ div >
</ div > ' ;
2018-02-16 15:45:15 +01:00
}
2017-08-04 16:28:16 +02:00
2018-11-01 12:39:54 +01:00
echo '
2019-07-26 18:05:19 +02:00
< script > $ ( document ) . ready ( init ) </ script >
2017-08-04 16:28:16 +02:00
2017-09-01 18:13:25 +02:00
< script type = " text/javascript " >
2018-11-01 12:39:54 +01:00
$ ( document ) . ready ( function (){ ' ;
2017-08-04 16:28:16 +02:00
2018-11-01 12:39:54 +01:00
if ( empty ( $sessioni )) {
echo '
$ ( " .btn-details " ) . attr ( " disabled " , true );
$ ( " .btn-details " ) . addClass ( " disabled " );
$ ( " #showall_dettagli " ) . removeClass ( " hide " );
$ ( " #dontshowall_dettagli " ) . addClass ( " hide " ); ' ;
} else {
echo '
$ ( " .btn-details " ) . attr ( " disabled " , false );
$ ( " .btn-details " ) . removeClass ( " disabled " ); ' ;
}
2017-09-01 18:13:25 +02:00
2018-11-01 12:39:54 +01:00
echo '
});
2017-09-01 18:13:25 +02:00
2018-11-01 12:39:54 +01:00
/*
* Aggiunge una nuova riga per la sessione di lavoro in base al tecnico selezionato .
*/
function add_tecnici ( id_tecnico ) {
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
beforeSubmit : function ( arr , $form , options ) {
return $form . parsley () . validate ();
},
data : {
id_module : globals . id_module ,
id_record : globals . id_record ,
op : " add_sessione " ,
id_tecnico : id_tecnico ,
},
type : " post " ,
success : function (){
$ ( " #tecnici " ) . load ( " '. $module->fileurl ('ajax_tecnici.php').'?id_module= " + globals . id_module + " &id_record= " + globals . id_record );
$ ( " #costi " ) . load ( " '. $module->fileurl ('ajax_costi.php').'?id_module= " + globals . id_module + " &id_record= " + globals . id_record );
2017-09-01 18:13:25 +02:00
}
});
2018-11-01 12:39:54 +01:00
}
/*
* Rimuove la sessione di lavoro dall\ ' intervento .
*/
function elimina_sessione ( id_sessione ) {
if ( confirm ( " Eliminare sessione di lavoro? " )) {
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
data : {
id_module : globals . id_module ,
id_record : globals . id_record ,
op : " delete_sessione " ,
id_sessione : id_sessione ,
},
type : " post " ,
success : function (){
$ ( " #tecnici " ) . load ( " '. $module->fileurl ('ajax_tecnici.php').'?id_module= " + globals . id_module + " &id_record= " + globals . id_record );
$ ( " #costi " ) . load ( " '. $module->fileurl ('ajax_costi.php').'?id_module= " + globals . id_module + " &id_record= " + globals . id_record );
}
});
}
}
</ script > ' ;