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
2020-03-12 22:15:02 +01:00
$rss = $dbo -> fetchArray ( 'SELECT is_completato AS flag_completato FROM in_statiintervento WHERE idstatointervento = (SELECT idstatointervento FROM in_interventi WHERE id=' . prepare ( $id_record ) . ')' );
2018-11-01 12:39:54 +01:00
$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 >
2020-07-09 17:58:28 +02:00
< th width = " 15% " > '.tr(' Orario inizio ').' </ th >
< th width = " 15% " > '.tr(' Orario fine ').' </ th >
< th width = " 12% " > '.tr(' Ore ').' </ th >
< th width = " 12% " > '.tr(' Km ').' </ th > ' ;
2018-11-01 12:39:54 +01:00
if ( $show_costi ) {
echo '
< th width = " 10% " > '.tr(' Sconto ore ').' </ th >
< th width = " 10% " > '.tr(' Sconto km ').' </ th > ' ;
}
if ( ! $is_completato ) {
echo '
2020-07-09 17:58:28 +02:00
< th width = " 100 " class = " text-center " > #</th>';
2018-11-01 12:39:54 +01:00
}
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 '
2020-08-03 12:43:30 +02:00
< tr data - id = " '. $sessione['id'] .' " >
2018-11-01 12:39:54 +01:00
< 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 >
2020-07-06 13:19:20 +02:00
< td class = " text-right " >
2018-11-01 12:39:54 +01:00
' . 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 >
2020-07-06 13:19:20 +02:00
< td class = " text-right " >
2018-11-01 12:39:54 +01:00
'.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 >
2020-07-06 13:19:20 +02:00
< td class = " text-right " > '.Translator::numberToLocale($costo_ore_consuntivo - $sconto).' </ td >
2018-11-01 12:39:54 +01:00
</ 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 >
2020-07-06 13:19:20 +02:00
< td class = " text-right " >
2017-08-04 16:28:16 +02:00
'.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 >
2020-07-06 13:19:20 +02:00
< td class = " text-right " >
2017-08-04 16:28:16 +02:00
'.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 >
2020-07-06 13:19:20 +02:00
< td class = " text-right " > '.Translator::numberToLocale($costo_km_consuntivo - $scontokm).' </ td >
2017-08-04 16:28:16 +02:00
</ 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 " >
2020-08-03 12:43:30 +02:00
< button type = " button " class = " btn btn-sm btn-warning tip " title = " '.tr('Modifica sessione').' " onclick = " modificaSessione(this) " >
< 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 '
2020-08-17 09:47:18 +02:00
< 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
}
2020-08-17 09:47:18 +02:00
echo '
< div id = " info-conflitti " ></ div > ' ;
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 '
2020-08-11 15:05:21 +02:00
< script src = " '. $rootdir .'/assets/src/js/functions/functions.js " ></ script >
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 " >
2020-08-03 12:43:30 +02:00
async function modificaSessione ( button ) {
var riga = $ ( button ) . closest ( " tr " );
var id = riga . data ( " id " );
// Salvataggio via AJAX
let valid = await salvaForm ( button , $ ( " #edit-form " ));
if ( valid ) {
// Chiusura tooltip
if ( $ ( button ) . hasClass ( " tooltipstered " ))
$ ( button ) . tooltipster ( " close " );
// Apertura modal
2020-08-17 09:47:18 +02:00
openModal ( " '.tr('Modifica sessione').' " , " '. $module->fileurl ('modals/manage_sessione.php').'?id_module= " + globals . id_module + " &id_record= " + globals . id_record + " &id_sessione= " + id );
2020-08-03 12:43:30 +02:00
}
}
2020-08-17 09:47:18 +02:00
function caricaTecnici () {
return $ ( " #tecnici " ) . load ( " '. $module->fileurl ('ajax_tecnici.php').'?id_module= " + globals . id_module + " &id_record= " + globals . id_record );
}
function calcolaConflittiTecnici () {
let tecnici = [ input ( " nuovotecnico " ) . get ()];
let inizio = moment () . startOf ( " hour " );
return $ ( " #info-conflitti " ) . load ( " '. $module->fileurl ('occupazione_tecnici.php').' " , {
" id_module " : globals . id_module ,
" id_record " : globals . id_record ,
" tecnici[] " : tecnici ,
" inizio " : inizio . format ( " YYYY-MM-DD HH:mm:ss " ),
" fine " : inizio . add ( 1 , " hours " ) . format ( " YYYY-MM-DD HH:mm:ss " ),
});
}
function calcolaCosti () {
return $ ( " #costi " ) . load ( " '. $module->fileurl ('ajax_costi.php').'?id_module= " + globals . id_module + " &id_record= " + globals . id_record );
}
2017-08-04 16:28:16 +02:00
2020-08-17 09:47:18 +02:00
input ( " nuovotecnico " ) . change ( function () {
calcolaConflittiTecnici ();
});
$ ( document ) . ready ( function () {
calcolaConflittiTecnici ();
' ;
2018-11-01 12:39:54 +01:00
if ( empty ( $sessioni )) {
echo '
2020-08-17 09:47:18 +02:00
$ ( " .btn-details " ) . attr ( " disabled " , true );
$ ( " .btn-details " ) . addClass ( " disabled " );
$ ( " #showall_dettagli " ) . removeClass ( " hide " );
$ ( " #dontshowall_dettagli " ) . addClass ( " hide " ); ' ;
2018-11-01 12:39:54 +01:00
} else {
echo '
2020-08-17 09:47:18 +02:00
$ ( " .btn-details " ) . attr ( " disabled " , false );
$ ( " .btn-details " ) . removeClass ( " disabled " ); ' ;
2018-11-01 12:39:54 +01:00
}
2017-09-01 18:13:25 +02:00
2018-11-01 12:39:54 +01:00
echo '
2020-08-17 09:47:18 +02: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 () {
caricaTecnici ();
calcolaCosti ();
calcolaConflittiTecnici ();
}
2018-11-01 12:39:54 +01:00
});
2020-08-17 09:47:18 +02:00
}
2017-09-01 18:13:25 +02:00
2020-08-17 09:47:18 +02:00
/*
* Rimuove la sessione di lavoro dall\ ' intervento .
*/
function elimina_sessione ( id_sessione ) {
if ( confirm ( " Eliminare sessione di lavoro? " )) {
2018-11-01 12:39:54 +01:00
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
data : {
id_module : globals . id_module ,
id_record : globals . id_record ,
2020-08-17 09:47:18 +02:00
op : " delete_sessione " ,
id_sessione : id_sessione ,
2018-11-01 12:39:54 +01:00
},
type : " post " ,
2020-07-31 14:25:50 +02:00
success : function () {
2020-08-17 09:47:18 +02:00
caricaTecnici ();
calcolaCosti ();
calcolaConflittiTecnici ();
2017-09-01 18:13:25 +02:00
}
});
2018-11-01 12:39:54 +01:00
}
2020-08-17 09:47:18 +02:00
}
2018-11-01 12:39:54 +01:00
</ script > ' ;