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 ;
2024-03-05 16:01:45 +01:00
use Models\Module ;
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
2024-02-28 15:28:39 +01:00
$rss = $dbo -> fetchArray ( 'SELECT `is_completato` AS flag_completato FROM `in_statiintervento` INNER JOIN `in_interventi` ON `in_statiintervento`.`id` = `in_interventi`.`idstatointervento` WHERE `in_interventi`.`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
2022-07-22 16:23:05 +02:00
$query = ' SELECT
2024-02-28 16:28:53 +01:00
`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` . `deleted_at` AS tipo_deleted_at ,
`in_tipiintervento_lang` . `name` 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` . `id`
LEFT JOIN `in_tipiintervento_lang` ON ( `in_tipiintervento` . `id` = `in_tipiintervento_lang` . `id_record` AND `in_tipiintervento_lang` . `id_lang` = '.prepare(setting(' Lingua ')).' )
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 > ' ;
2023-08-04 14:54:28 +02:00
if ( $sessione [ 'id_user' ]) {
$user = User :: where ( 'idanagrafica' , $sessione [ 'idtecnico' ]) -> orderByRaw ( 'CASE WHEN idgruppo = 2 THEN -1 ELSE idgruppo END' ) -> first ();
echo '
2022-07-02 20:46:18 +02:00
< img class = " attachment-img tip " src = " '. $user->photo .' " title = " '. $user->nome_completo .' " > ' ;
} else {
2023-08-04 14:54:28 +02:00
echo '
2022-07-02 20:46:18 +02:00
< i class = " fa fa-user-circle-o attachment-img tip " title = " '. $sessione['ragione_sociale'] .' " ></ i > ' ;
}
2023-08-04 14:54:28 +02:00
echo '
2023-12-19 12:11:18 +01:00
'.$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 >
2024-01-10 16:34:51 +01:00
< th width = " 2% " > </ th >
< th width = " 10% " > '.tr(' Ore ').' </ th >
2020-07-09 17:58:28 +02:00
< 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 >
2023-04-18 16:55:37 +02:00
'.$sessione[' descrizione_tipo '].' '.(($sessione[' tipo_deleted_at ']) ? ' < small class = " text-danger " >< em > ( '.tr(' Eliminato ').' ) </ em ></ small > ' : ' ').'
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 >
2023-12-19 12:11:18 +01:00
{[ " type " : " timestamp " , " name " : " data_inizio_'. $sessione['id'] .' " , " required " : 1 , " value " : " '. $sessione['orario_inizio'] .' " , " disabled " : " '. $block_edit .' " ]}
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 >
2023-12-19 12:11:18 +01:00
{[ " type " : " timestamp " , " name " : " data_fine_'. $sessione['id'] .' " , " required " : 1 , " value " : " '. $sessione['orario_fine'] .' " , " disabled " : " '. $block_edit .' " ]}
2018-11-01 12:39:54 +01:00
</ td > ' ;
2017-09-01 18:13:25 +02:00
2017-08-04 16:28:16 +02:00
// ORE
echo '
2024-01-31 14:23:46 +01:00
< td style = " border-right:1px solid #aaa; " > '.((Carbon\Carbon::createFromFormat(' Y - m - d H : i : s ', $sessione[' orario_inizio '])->eq(Carbon\Carbon::createFromFormat(' Y - m - d H : i : s ', $sessione[' orario_fine '])) || Carbon\Carbon::createFromFormat(' Y - m - d H : i : s ', $sessione[' orario_inizio '])->gt(Carbon\Carbon::createFromFormat(' Y - m - d H : i : s ', $sessione[' orario_fine ']))) ? ' < i title = " '.tr('Questa sessione non ha una durata valida.').' " class = " fa fa-warning tip text-warning " ></ i > ' : ' ').'
2024-01-10 16:34:51 +01:00
</ td >
< td style = " border-right:1px solid #aaa; " >
2023-12-19 12:11:18 +01:00
{[ " type " : " number " , " name " : " ore_'. $sessione['id'] .' " , " required " : 1 , " value " : " '.numberFormat( $ore , 'qta').' " , " disabled " : " 1 " ]}
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; " >
2023-12-19 12:11:18 +01:00
{[ " type " : " number " , " name " : " sessione_km_'. $sessione['id'] .' " , " required " : 1 , " value " : " '.numberFormat( $sessione['km'] , 'qta').' " , " onchange " : " aggiornaSessioneInline( $ (this).closest( \ 'tr \ ').data( \ 'id \ ')) " , " disabled " : " '. $block_edit .' " ]}
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 ) {
2023-12-19 12:11:18 +01:00
$tipo_sconto = ( setting ( 'Tipo di sconto predefinito' ) == '%' ? 'PRC' : 'UNT' );
2017-08-04 16:28:16 +02:00
echo '
2018-11-01 12:39:54 +01:00
< td style = " border-right:1px solid #aaa; " >
2023-12-19 12:11:18 +01:00
{[ " type " : " number " , " name " : " sconto_unitario_'. $sessione['id'] .' " , " value " : " '.Translator::numberToLocale( $sessione['sconto_unitario'] ).' " , " onchange " : " aggiornaSessioneInline( $ (this).closest( \ 'tr \ ').data( \ 'id \ ')) " , " icon-after " : " choice|untprc|'.( $sessione['tipo_sconto'] ? $sessione['tipo_sconto'] : $tipo_sconto ).' " , " disabled " : " '. $block_edit .' " ]}
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; " >
2023-12-19 12:11:18 +01:00
{[ " type " : " number " , " name " : " scontokm_unitario_'. $sessione['id'] .' " , " value " : " '.Translator::numberToLocale( $sessione['scontokm_unitario'] ).' " , " onchange " : " aggiornaSessioneInline( $ (this).closest( \ 'tr \ ').data( \ 'id \ ')) " , " icon-after " : " choice|untprc|'.( $sessione['tipo_sconto_km'] ? $sessione['tipo_sconto_km'] : $tipo_sconto ).' " , " disabled " : " '. $block_edit .' " ]}
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 " >
2023-02-03 18:05:51 +01:00
< div class = " col-md-2 " >
< label >& nbsp ; </ label >
< button type = " button " class = " btn btn-default btn-block " onclick = " add_sessioni( $ (this)) " >
< i class = " fa fa-users " ></ i > '.tr(' Inserimento massivo ').'
</ button >
</ div >
< div class = " col-md-offset-4 col-md-4 " >
2024-03-05 16:01:45 +01:00
{[ " type " : " select " , " label " : " '.tr('Tecnico').' " , " name " : " nuovo_tecnico " , " placeholder " : " '.tr('Seleziona un tecnico').' " , " ajax-source " : " tecnici " , " icon-after " : " add|'.(new Module())->getByName('Anagrafiche')->id_record.'|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 '
2024-03-06 11:57:36 +01:00
$ ( " [id^=data_inizio_] " ) . on ( " dp.change " , function ( e ) {
let data_fine = $ ( " #data_fine_ " + $ ( this ) . closest ( " tr " ) . data ( " id " ));
if ( data_fine . data ( " DateTimePicker " ) . date () < e . date ){
data_fine . data ( " DateTimePicker " ) . date ( e . date );
}
});
$ ( " [id^=data_fine_] " ) . on ( " dp.change " , function ( e ) {
let data_inizio = $ ( " #data_inizio_ " + $ ( this ) . closest ( " tr " ) . data ( " id " ));
if ( data_inizio . data ( " DateTimePicker " ) . date () > e . date ){
data_inizio . data ( " DateTimePicker " ) . date ( e . date );
}
});
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
2023-02-03 18:05:51 +01:00
/*
* Aggiunge sessioni massivamente
*/
async function add_sessioni ( button ) {
// Salvataggio via AJAX
await salvaForm ( " #edit-form " , {}, button );
// Chiusura tooltip
if ( $ ( button ) . hasClass ( " tooltipstered " ))
$ ( button ) . tooltipster ( " close " );
// Apertura modal
openModal ( " '.tr('Aggiungi sessioni').' " , " '. $module->fileurl ('modals/add_sessioni.php').'?id_module= " + globals . id_module + " &id_record= " + globals . id_record );
}
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 );
}
2023-12-19 12:11:18 +01:00
$ ( " #tecnici .tipo_icon_after " ) . on ( " change " , function () {
aggiornaSessioneInline ( $ ( this ) . closest ( " tr " ) . data ( " id " ));
});
$ ( " [id^=data_inizio_], [id^=data_fine_] " ) . on ( " dp.hide " , function ( e ) {
aggiornaSessioneInline ( $ ( this ) . closest ( " tr " ) . data ( " id " ));
});
function caricaTecnici () {
let container = $ ( " #tecnici " );
localLoading ( container , true );
$ . get ( " '. $structure->fileurl ('ajax_tecnici.php').'?id_module='. $id_module .'&id_record='. $id_record .' " , function ( data ) {
container . html ( data );
localLoading ( container , false );
});
}
function aggiornaSessioneInline ( id ) {
var id_sessione = id ;
var data_inizio = $ ( " #data_inizio_ " + id_sessione ) . val ();
var data_fine = $ ( " #data_fine_ " + id_sessione ) . val ();
var km = $ ( " #sessione_km_ " + id_sessione ) . val ();
var sconto_unitario = $ ( " #sconto_unitario_ " + id_sessione ) . val ();
var tipo_sconto = $ ( " [id^=tipo_sconto_unitario_ " + id_sessione + " ] " ) . val ()
var scontokm_unitario = $ ( " #scontokm_unitario_ " + id_sessione ) . val ();
var tipo_sconto_km = $ ( " [id^=tipo_scontokm_unitario_ " + id_sessione + " ] " ) . val ()
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " POST " ,
data : {
id_module : globals . id_module ,
id_record : globals . id_record ,
op : " update_inline_sessione " ,
id_sessione : id_sessione ,
data_inizio : data_inizio ,
data_fine : data_fine ,
km : km ,
sconto_unitario : sconto_unitario ,
tipo_sconto : tipo_sconto ,
scontokm_unitario : scontokm_unitario ,
tipo_sconto_km : tipo_sconto_km ,
},
success : function ( response ) {
caricaTecnici ();
caricaCosti ();
renderMessages ();
},
error : function ( xhr , status , error ) {
caricaCosti ();
renderMessages ();
}
});
}
2018-11-01 12:39:54 +01:00
</ script > ' ;