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
2019-11-08 15:09:05 +01:00
include_once __DIR__ . '/../../core.php' ;
2022-07-02 20:46:18 +02:00
use Models\User ;
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
2022-07-02 20:46:18 +02:00
2018-11-01 12:39:54 +01:00
// Sessioni dell'intervento
2022-07-22 16:23:05 +02:00
$query = ' SELECT
in_interventi_tecnici .* ,
( in_interventi_tecnici . prezzo_ore_unitario * in_interventi_tecnici . ore - in_interventi_tecnici . sconto ) AS prezzo_ore_consuntivo ,
( in_interventi_tecnici . prezzo_km_unitario * in_interventi_tecnici . km - in_interventi_tecnici . scontokm ) AS prezzo_km_consuntivo ,
( in_interventi_tecnici . prezzo_ore_unitario_tecnico * in_interventi_tecnici . ore ) AS prezzo_ore_consuntivo ,
( in_interventi_tecnici . prezzo_km_unitario_tecnico * in_interventi_tecnici . km ) AS prezzo_km_consuntivo ,
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 ,
user . id AS id_user
FROM
in_interventi_tecnici INNER JOIN an_anagrafiche
ON in_interventi_tecnici . idtecnico = an_anagrafiche . idanagrafica
LEFT JOIN ( SELECT zz_users . idanagrafica , zz_users . id FROM zz_users GROUP BY zz_users . idanagrafica ) AS user
ON user . idanagrafica = an_anagrafiche . idanagrafica
INNER JOIN in_tipiintervento
ON in_interventi_tecnici . idtipointervento = in_tipiintervento . idtipointervento
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 " >
2022-07-02 20:46:18 +02:00
< tr >< th > ' ;
if ( $sessione [ 'id_user' ]) {
2022-07-02 22:08:09 +02:00
$user = User :: where ( 'idanagrafica' , $sessione [ 'idtecnico' ]) -> orderByRaw ( " CASE WHEN idgruppo = 2 THEN -1 ELSE idgruppo END " ) -> first ();
2022-07-02 20:46:18 +02:00
echo '
< img class = " attachment-img tip " src = " '. $user->photo .' " title = " '. $user->nome_completo .' " > ' ;
} else {
echo '
< i class = " fa fa-user-circle-o attachment-img tip " title = " '. $sessione['ragione_sociale'] .' " ></ i > ' ;
}
echo '
'.$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 '
2022-01-29 23:49:19 +01:00
< th width = " 100 " class = " text-center " >& nbsp ; </ 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 '
2022-07-03 14:59:10 +02:00
< td style = " border-right:1px solid #aaa; " > '.($ore<=0 ? ' < i class = " fa fa-warning tip " style = " position:relative;margin-left:-16px; " title = " '.tr( " Questa sessione è vuota " ).' " ></ i > ': ' ' ).' '.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 " >
2021-06-28 15:06:30 +02:00
< button type = " button " class = " btn btn-xs btn-primary tip " title = " '.tr('Salva e duplica sessione').' " onclick = " copySessione(this) " >
2021-04-07 17:47:48 +02:00
< i class = " fa fa-files-o " ></ i >
</ button >
2021-06-28 15:06:30 +02:00
< button type = " button " class = " btn btn-xs btn-warning tip " title = " '.tr('Salva e modifica sessione').' " onclick = " modificaSessione(this) " >
2020-08-03 12:43:30 +02:00
< i class = " fa fa-edit " ></ i >
</ button >
2018-11-01 12:39:54 +01:00
2021-06-28 15:06:30 +02:00
< button type = " button " class = " btn btn-xs btn-danger tip " id = " delbtn_'. $sessione['id'] .' " onclick = " elimina_sessione( \ ''. $sessione['id'] .' \ '); " title = " '.tr('Elimina sessione').' " class = " only_rw " >< i class = " fa fa-trash " ></ i ></ button >
2018-11-01 12:39:54 +01:00
</ 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 " >
2021-04-02 13:52:48 +02:00
{[ " type " : " select " , " label " : " '.tr('Tecnico').' " , " name " : " nuovo_tecnico " , " placeholder " : " '.tr('Seleziona un tecnico').' " , " ajax-source " : " tecnici " , " icon-after " : " add|'.Modules::get('Anagrafiche')['id'].'|tipoanagrafica=Tecnico&readonly_tipo=1 " ]}
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 >
2020-09-14 10:49:23 +02:00
< button type = " button " class = " btn btn-primary btn-block " onclick = " if( $ ( \ '#nuovo_tecnico \ ').val()) { add_tecnici( $ ( \ '#nuovo_tecnico \ ').val()); }else { swal( \ ''.tr('Attenzione').' \ ', \ ''.tr('Seleziona il tecnico da aggiungere').'. \ ', \ 'warning \ '); $ ( \ '#nuovo_tecnico \ ').focus(); } " >
2018-11-20 21:53:43 +01:00
< 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 '
2022-08-04 22:05:28 +02:00
< script src = " '.base_path().'/assets/dist/js/functions.min.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
2021-03-29 18:31:23 +02:00
await salvaForm ( " #edit-form " , {}, button );
2020-08-03 12:43:30 +02:00
2021-03-29 18:31:23 +02:00
// Chiusura tooltip
if ( $ ( button ) . hasClass ( " tooltipstered " ))
$ ( button ) . tooltipster ( " close " );
2020-08-03 12:43:30 +02:00
2021-03-29 18:31:23 +02:00
// Apertura modal
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 calcolaConflittiTecnici () {
2020-09-14 10:49:23 +02:00
let tecnici = [ input ( " nuovo_tecnico " ) . get ()];
2020-08-17 09:47:18 +02:00
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 " ),
});
}
2020-09-14 10:49:23 +02:00
input ( " nuovo_tecnico " ) . change ( function () {
2020-08-17 09:47:18 +02:00
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 ();
2020-09-14 10:49:23 +02:00
caricaCosti ();
2020-08-17 09:47:18 +02:00
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 ) {
2021-06-28 15:06:30 +02:00
swal ({
title : " '.tr('Eliminare la sessione di lavoro?').' " ,
type : " warning " ,
showCancelButton : true ,
confirmButtonText : " '.tr('Elimina').' "
}) . then ( function ( result ) {
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 ();
2020-09-14 10:49:23 +02:00
caricaCosti ();
2020-08-17 09:47:18 +02:00
calcolaConflittiTecnici ();
2017-09-01 18:13:25 +02:00
}
});
2021-06-28 15:06:30 +02:00
}) . catch ( swal . noop );
2020-08-17 09:47:18 +02:00
}
2021-04-07 17:47:48 +02:00
async function copySessione ( button ) {
var riga = $ ( button ) . closest ( " tr " );
var id = riga . data ( " id " );
// Salvataggio via AJAX
await salvaForm ( " #edit-form " , {}, button );
// Chiusura tooltip
if ( $ ( button ) . hasClass ( " tooltipstered " ))
$ ( button ) . tooltipster ( " close " );
// Apertura modal
openModal ( " '.tr('Copia sessione').' " , " '. $module->fileurl ('modals/copy_sessione.php').'?id_module= " + globals . id_module + " &id_record= " + globals . id_record + " &id_sessione= " + id );
}
2018-11-01 12:39:54 +01:00
</ script > ' ;