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' ;
2024-03-05 16:01:45 +01:00
use Models\Module ;
2017-08-04 16:28:16 +02:00
2024-06-11 16:58:27 +02:00
$modulo_interventi = Module :: where ( 'name' , 'Interventi' ) -> first ();
$modulo_preventivi = Module :: where ( 'name' , 'Preventivi' ) -> first ();
2024-06-25 09:40:41 +02:00
$modulo_eventi = Module :: where ( 'name' , 'Eventi' ) -> first ();
2020-08-04 18:33:28 +02:00
2017-08-07 13:07:18 +02:00
if ( ! isset ( $user [ 'idanagrafica' ])) {
$user [ 'idanagrafica' ] = '' ;
2017-08-04 16:28:16 +02:00
}
2020-08-04 18:33:28 +02:00
switch ( filter ( 'op' )) {
2017-08-04 16:28:16 +02:00
// Lettura calendario tecnici
2020-08-04 18:33:28 +02:00
case 'interventi_periodo' :
$start = filter ( 'start' );
$end = filter ( 'end' );
2017-08-04 16:28:16 +02:00
2017-09-01 12:55:48 +02:00
$stati = ( array ) $_SESSION [ 'dashboard' ][ 'idstatiintervento' ];
$stati [] = prepare ( '' );
$tipi = ( array ) $_SESSION [ 'dashboard' ][ 'idtipiintervento' ];
2020-08-04 18:33:28 +02:00
$zone = ( array ) $_SESSION [ 'dashboard' ][ 'idzone' ];
$tecnici = ( array ) $_SESSION [ 'dashboard' ][ 'idtecnici' ];
$query = ' SELECT
2024-02-28 15:28:39 +01:00
`in_interventi_tecnici` . `id` ,
`in_interventi_tecnici` . `idintervento` ,
`in_interventi` . `codice` ,
`in_statiintervento` . `colore` ,
`in_interventi_tecnici` . `idtecnico` ,
`in_interventi_tecnici` . `orario_inizio` ,
`in_interventi_tecnici` . `orario_fine` ,
`tecnico` . `ragione_sociale` AS nome_tecnico ,
`tecnico` . `colore` AS colore_tecnico ,
2024-06-12 09:33:23 +02:00
IF ( `have_attachments` . `cont` , 1 , 0 ) AS have_attachments ,
2024-02-28 15:28:39 +01:00
`an_anagrafiche` . `ragione_sociale` as cliente ,
`an_anagrafiche` . `idzona` as idzona ,
`in_statiintervento` . `is_completato` AS is_completato
FROM `in_interventi_tecnici`
INNER JOIN `in_interventi` ON `in_interventi_tecnici` . `idintervento` = `in_interventi` . `id`
LEFT JOIN `an_anagrafiche` as tecnico ON `in_interventi_tecnici` . `idtecnico` = `tecnico` . `idanagrafica`
INNER JOIN `an_anagrafiche` ON `in_interventi` . `idanagrafica` = `an_anagrafiche` . `idanagrafica`
2024-06-12 09:33:23 +02:00
LEFT JOIN ( SELECT COUNT ( id ) as cont , id_record FROM `zz_files` WHERE `zz_files` . `id_module` = '.prepare($modulo_interventi->id).' ) as `have_attachments` ON `have_attachments` . `id_record` = `in_interventi` . `id`
2024-02-28 15:28:39 +01:00
INNER JOIN `in_statiintervento` ON `in_interventi` . `idstatointervento` = `in_statiintervento` . `id`
2020-08-04 18:33:28 +02:00
WHERE
(
2021-05-12 09:44:37 +02:00
(
2024-02-28 15:28:39 +01:00
`in_interventi_tecnici` . `orario_inizio` >= '.prepare($start).'
2021-05-12 09:44:37 +02:00
AND
2024-02-28 15:28:39 +01:00
`in_interventi_tecnici` . `orario_fine` <= '.prepare($end).'
2021-05-12 09:44:37 +02:00
)
OR
(
2024-02-28 15:28:39 +01:00
`in_interventi_tecnici` . `orario_inizio` >= '.prepare($start).'
2021-05-12 09:44:37 +02:00
AND
2024-02-28 15:28:39 +01:00
`in_interventi_tecnici` . `orario_inizio` <= '.prepare($end).'
2021-05-12 09:44:37 +02:00
)
OR
(
2024-02-28 15:28:39 +01:00
`in_interventi_tecnici` . `orario_inizio` <= '.prepare($start).'
2021-05-12 09:44:37 +02:00
AND
2024-02-28 15:28:39 +01:00
`in_interventi_tecnici` . `orario_fine` >= '.prepare($end).'
2021-05-12 09:44:37 +02:00
)
OR
(
2024-02-28 15:28:39 +01:00
`in_interventi_tecnici` . `orario_fine` >= '.prepare($start).'
2021-05-12 09:44:37 +02:00
AND
2024-02-28 15:28:39 +01:00
`in_interventi_tecnici` . `orario_fine` <= '.prepare($end).'
2021-05-12 09:44:37 +02:00
)
)
2024-02-28 15:28:39 +01:00
AND `idtecnico` IN ( '.implode(' , ', $tecnici).' )
AND `in_interventi` . `idstatointervento` IN ( '.implode(' , ', $stati).' )
AND `in_interventi_tecnici` . `idtipointervento` IN ( '.implode(' , ', $tipi).' )
2021-05-12 09:44:37 +02:00
'.Modules::getAdditionalsQuery(' Interventi ').'
HAVING
2024-02-28 15:28:39 +01:00
`idzona` IN ( '.implode(' , ', $zone).' ) ' ;
2020-08-04 18:33:28 +02:00
$sessioni = $dbo -> fetchArray ( $query );
2017-08-04 16:28:16 +02:00
$results = [];
2020-08-04 18:33:28 +02:00
foreach ( $sessioni as $sessione ) {
2022-02-17 15:51:50 +01:00
if ( setting ( 'Visualizzazione colori sessioni' ) == 'Sfondo colore stato - bordo colore tecnico' ) {
2024-05-23 11:36:25 +02:00
$backgroundcolor = strtoupper (( string ) $sessione [ 'colore' ]);
$bordercolor = strtoupper (( string ) $sessione [ 'colore_tecnico' ]);
2022-02-17 15:51:50 +01:00
} else {
2024-05-23 11:36:25 +02:00
$backgroundcolor = strtoupper (( string ) $sessione [ 'colore_tecnico' ]);
$bordercolor = strtoupper (( string ) $sessione [ 'colore' ]);
2022-02-17 15:51:50 +01:00
}
2017-09-12 18:18:27 +02:00
$results [] = [
2020-08-04 18:33:28 +02:00
'id' => $sessione [ 'id' ],
2022-03-24 11:11:36 +01:00
'title' => (( $sessione [ 'is_completato' ]) ? '<i class="fa fa-lock" aria-hidden="true"></i>' : '' ) . ' ' . (( $sessione [ 'have_attachments' ]) ? '<i class="fa fa-paperclip" aria-hidden="true"></i>' : '' ) . ( $sessione [ 'is_completato' ] || $sessione [ 'have_attachments' ] ? '<br>' : '' ) . '<b>Int. ' . $sessione [ 'codice' ] . '</b> ' . $sessione [ 'cliente' ] . '<br><b>' . tr ( 'Tecnici' ) . ':</b> ' . $sessione [ 'nome_tecnico' ],
2020-08-04 18:33:28 +02:00
'start' => $sessione [ 'orario_inizio' ],
'end' => $sessione [ 'orario_fine' ],
2023-01-23 23:10:52 +01:00
'extendedProps' => [
'link' => base_path () . '/editor.php?id_module=' . $modulo_interventi -> id . '&id_record=' . $sessione [ 'idintervento' ],
'idintervento' => $sessione [ 'idintervento' ],
'idtecnico' => $sessione [ 'idtecnico' ],
],
2022-02-17 15:51:50 +01:00
'backgroundColor' => $backgroundcolor ,
'textColor' => color_inverse ( $backgroundcolor ),
2022-03-24 16:51:39 +01:00
'borderColor' => empty ( $bordercolor ) ? '#FFFFFF' : $bordercolor ,
2017-09-12 18:18:27 +02:00
'allDay' => false ,
];
2017-08-04 16:28:16 +02:00
}
2017-09-12 18:18:27 +02:00
2021-07-07 07:57:10 +02:00
if ( setting ( 'Visualizza informazioni aggiuntive sul calendario' )) {
2024-01-15 15:30:45 +01:00
// # Box allDay preventivi
2021-06-08 10:56:27 +02:00
$query = ' SELECT
2024-02-26 10:50:43 +01:00
`co_preventivi` . `id` ,
`co_preventivi` . `nome` ,
`co_preventivi` . `numero` ,
`co_preventivi` . `data_accettazione` ,
`co_preventivi` . `data_conclusione` ,
`co_statipreventivi` . `is_pianificabile` ,
2024-04-18 17:44:05 +02:00
`co_statipreventivi_lang` . `title` as stato ,
2024-02-26 10:50:43 +01:00
`co_statipreventivi` . `is_completato` ,
`an_anagrafiche` . `ragione_sociale` AS cliente ,
`zz_files` . `id` AS have_attachments
FROM `co_preventivi`
INNER JOIN `an_anagrafiche` ON `co_preventivi` . `idanagrafica` = `an_anagrafiche` . `idanagrafica`
LEFT JOIN `zz_files` ON `zz_files` . `id_record` = `co_preventivi` . `id` AND `zz_files` . `id_module` = '.prepare($modulo_preventivi->id).'
LEFT JOIN `co_statipreventivi` ON `co_preventivi` . `idstato` = `co_statipreventivi` . `id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `co_statipreventivi_lang` ON ( `co_statipreventivi_lang` . `id_record` = `co_statipreventivi` . `id` AND `co_statipreventivi_lang` . `id_lang` = '.prepare(Models\Locale::getDefault()->id).' )
2021-06-08 10:56:27 +02:00
WHERE
2024-06-12 08:59:45 +02:00
(
( `co_preventivi` . `data_accettazione` >= '.prepare($start).' AND `co_preventivi` . `data_accettazione` <= '.prepare($end).' )
OR ( `co_preventivi` . `data_conclusione` >= '.prepare($start).' AND `co_preventivi` . `data_conclusione` <= '.prepare($end).' )
) ' ;
2021-06-08 10:56:27 +02:00
2023-03-29 10:34:46 +02:00
$preventivi = $dbo -> fetchArray ( $query );
2023-10-05 10:26:57 +02:00
2023-03-29 10:34:46 +02:00
foreach ( $preventivi as $preventivo ) {
2023-09-28 12:15:40 +02:00
if ( $preventivo [ 'is_pianificabile' ] == 1 || $preventivo [ 'stato' ] = 'In attesa di conferma' ) {
if ( ! empty ( $preventivo [ 'data_accettazione' ]) && $preventivo [ 'data_accettazione' ] != '0000-00-00' ) {
2024-02-26 10:50:43 +01:00
$query . 'AND `co_statipreventivi`.`is_pianificabile`=1' ;
2023-09-28 12:15:40 +02:00
$results [] = [
'id' => 'A_' . $modulo_preventivi -> id . '_' . $preventivo [ 'id' ],
'idintervento' => $preventivo [ 'id' ],
'idtecnico' => '' ,
2024-01-15 15:30:45 +01:00
'title' => '<div style=\'position:absolute; top:7%; right:3%;\' > ' . (( $preventivo [ 'is_completato' ]) ? '<i class="fa fa-lock" aria-hidden="true"></i>' : '<i class="fa fa-pencil" aria-hidden="true"></i>' ) . ' ' . (( $preventivo [ 'have_attachments' ]) ? '<i class="fa fa-paperclip" aria-hidden="true"></i>' : '' ) . '</div><b>' . tr ( 'Accettazione prev.' ) . ' ' . $preventivo [ 'numero' ] . '</b> ' . $preventivo [ 'nome' ] . '<br><b>' . tr ( 'Cliente' ) . ':</b> ' . $preventivo [ 'cliente' ],
2023-09-28 12:15:40 +02:00
'start' => $preventivo [ 'data_accettazione' ],
2024-01-15 15:30:45 +01:00
// 'end' => $preventivo['data_accettazione'],
2023-09-28 12:15:40 +02:00
'url' => base_path () . '/editor.php?id_module=' . $modulo_preventivi -> id . '&id_record=' . $preventivo [ 'id' ],
'backgroundColor' => '#ff7f50' ,
'textColor' => color_inverse ( '#ff7f50' ),
'borderColor' => '#ff7f50' ,
'allDay' => true ,
'eventStartEditable' => false ,
'editable' => false ,
];
}
if ( $preventivo [ 'data_accettazione' ] != $preventivo [ 'data_conclusione' ] && $preventivo [ 'data_conclusione' ] != '0000-00-00' && ! empty ( $preventivo [ 'data_conclusione' ])) {
$results [] = [
'id' => 'B_' . $modulo_preventivi -> id . '_' . $preventivo [ 'id' ],
'idintervento' => $preventivo [ 'id' ],
'idtecnico' => '' ,
2024-01-15 15:30:45 +01:00
'title' => '<div style=\'position:absolute; top:7%; right:3%;\' > ' . (( $preventivo [ 'is_completato' ]) ? '<i class="fa fa-lock" aria-hidden="true"></i>' : '<i class="fa fa-pencil" aria-hidden="true"></i>' ) . ' ' . (( $preventivo [ 'have_attachments' ]) ? '<i class="fa fa-paperclip" aria-hidden="true"></i>' : '' ) . '</div><b>' . tr ( 'Conclusione prev.' ) . ' ' . $preventivo [ 'numero' ] . '</b> ' . $preventivo [ 'nome' ] . '<br><b>' . tr ( 'Cliente' ) . ':</b> ' . $preventivo [ 'cliente' ],
2023-09-28 12:15:40 +02:00
'start' => $preventivo [ 'data_conclusione' ],
2024-01-15 15:30:45 +01:00
// 'end' => $preventivo['data_conclusione'],
2023-09-28 12:15:40 +02:00
'url' => base_path () . '/editor.php?id_module=' . $modulo_preventivi -> id . '&id_record=' . $preventivo [ 'id' ],
'backgroundColor' => '#ff7f50' ,
'textColor' => color_inverse ( '#ff7f50' ),
'borderColor' => '#ff7f50' ,
'allDay' => true ,
'eventStartEditable' => false ,
'editable' => false ,
];
}
2021-06-08 10:56:27 +02:00
}
2021-06-03 11:06:51 +02:00
}
2022-06-03 16:13:01 +02:00
2024-01-15 15:30:45 +01:00
// # Box allDay eventi (escluse festività)
2022-06-03 16:13:01 +02:00
$query = ' SELECT
*
FROM
2023-03-29 10:34:46 +02:00
`zz_events`
2022-06-03 16:13:01 +02:00
WHERE
2023-03-29 10:34:46 +02:00
`zz_events` . `is_bank_holiday` = 0
AND ( `zz_events` . `is_recurring` = 1 AND
2023-08-04 14:54:28 +02:00
DAYOFYEAR ( `zz_events` . `data` ) BETWEEN DAYOFYEAR ( '.prepare($start).' ) AND IF ( YEAR ( '.prepare($start).' ) = YEAR ( '.prepare($end).' ), DAYOFYEAR ( '.prepare($end).' ), DAYOFYEAR ( '.prepare(date(' Y - m - d ', strtotime($end.' - 1 day '))).' ))
2023-03-29 10:34:46 +02:00
)
OR
2024-06-12 08:59:45 +02:00
( `zz_events` . `is_recurring` = 0 AND `zz_events` . `data` >= '.prepare($start).' AND `zz_events` . `data` <= '.prepare($end).' ) ' ;
2023-08-04 14:54:28 +02:00
2024-01-15 15:30:45 +01:00
// echo $query;
2022-06-03 16:13:01 +02:00
2023-03-29 10:34:46 +02:00
$eventi = $dbo -> fetchArray ( $query );
2022-06-03 16:13:01 +02:00
2023-03-29 10:34:46 +02:00
foreach ( $eventi as $evento ) {
2022-06-03 16:13:01 +02:00
$results [] = [
'id' => $modulo_eventi -> id . '_' . $evento [ 'id' ],
2023-03-29 10:34:46 +02:00
'title' => '<b>' . tr ( 'Evento' ) . ':</b> ' . $evento [ 'nome' ] . '</b>' ,
2024-05-23 11:36:25 +02:00
'start' => ( $evento [ 'is_recurring' ] ? date ( 'Y-' , strtotime ( $start )) . date ( 'm-d' , strtotime (( string ) $evento [ 'data' ])) : $evento [ 'data' ]),
2024-01-15 15:30:45 +01:00
// 'end' => $evento['data'],
2023-01-23 23:10:52 +01:00
'extendedProps' => [
'link' => base_path () . '/editor.php?id_module=' . $modulo_eventi -> id . '&id_record=' . $evento [ 'id' ],
'idintervento' => $evento [ 'id' ],
'idtecnico' => '' ,
],
2022-06-03 16:13:01 +02:00
'backgroundColor' => '#ffebcd' ,
'textColor' => color_inverse ( '#ffebcd' ),
'borderColor' => '#ffebcd' ,
'allDay' => true ,
'eventStartEditable' => false ,
2023-03-29 10:34:46 +02:00
'editable' => false ,
2022-06-03 16:13:01 +02:00
];
}
2021-06-03 11:06:51 +02:00
}
2017-09-12 18:18:27 +02:00
echo json_encode ( $results );
2017-08-04 16:28:16 +02:00
break ;
2020-08-04 18:33:28 +02:00
case 'modifica_intervento' :
$sessione = filter ( 'id' );
$idintervento = filter ( 'idintervento' );
$orario_inizio = filter ( 'timeStart' );
$orario_fine = filter ( 'timeEnd' );
2017-08-04 16:28:16 +02:00
2018-07-17 12:05:21 +02:00
// Aggiornamento prezzo totale
2024-02-28 15:28:39 +01:00
$q = ' SELECT
`in_interventi_tecnici` . `prezzo_ore_unitario` ,
`idtecnico` ,
`in_statiintervento` . `is_completato`
FROM
`in_interventi_tecnici`
INNER JOIN `in_interventi` ON `in_interventi_tecnici` . `idintervento` = `in_interventi` . `id`
LEFT JOIN `in_statiintervento` ON `in_interventi` . `idstatointervento` = `in_statiintervento` . `id`
WHERE
`in_interventi` . `id` = '.prepare($idintervento).' AND
`in_statiintervento` . `is_completato` = 0 '.Modules::getAdditionalsQuery(' Interventi ' );
2017-08-04 16:28:16 +02:00
$rs = $dbo -> fetchArray ( $q );
$prezzo_ore = 0.00 ;
for ( $i = 0 ; $i < count ( $rs ); ++ $i ) {
$prezzo_ore_unitario = $rs [ $i ][ 'prezzo_ore_unitario' ];
2018-07-17 12:05:21 +02:00
$ore = calcola_ore_intervento ( $orario_inizio , $orario_fine );
2017-08-04 16:28:16 +02:00
2018-07-17 12:05:21 +02:00
$prezzo_ore += $ore * $prezzo_ore_unitario ;
2017-08-04 16:28:16 +02:00
}
if ( count ( $rs ) > 0 ) {
// Aggiornamento orario tecnico
2022-07-22 16:23:05 +02:00
// FIXME: usare la classe e relativo metodo
$dbo -> query ( 'UPDATE in_interventi_tecnici SET orario_inizio = ' . prepare ( $orario_inizio ) . ', orario_fine = ' . prepare ( $orario_fine ) . ', ore=' . prepare ( $ore ) . ' WHERE id=' . prepare ( $sessione ));
2017-08-04 16:28:16 +02:00
echo 'ok' ;
} else {
2017-09-04 12:02:29 +02:00
echo tr ( 'Attività completata, non è possibile modificarla!' );
2017-08-04 16:28:16 +02:00
}
break ;
2021-06-04 18:10:00 +02:00
case 'tooltip_info' :
2021-06-08 12:36:54 +02:00
$id = filter ( 'id_record' );
2021-06-04 18:10:00 +02:00
$allDay = filter ( 'allDay' );
2020-08-04 18:33:28 +02:00
$timeStart = filter ( 'timeStart' );
$timeEnd = filter ( 'timeEnd' );
2017-08-04 16:28:16 +02:00
2023-03-08 16:48:25 +01:00
if ( $allDay == 'false' ) {
2021-06-04 18:10:00 +02:00
// Lettura dati intervento di riferimento
2022-10-06 11:52:02 +02:00
$query = 'SELECT in_interventi_tecnici.idintervento, in_interventi.id, idtecnico, orario_inizio, orario_fine, (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=idtecnico) AS nome_tecnico, (SELECT colore FROM an_anagrafiche WHERE idanagrafica=idtecnico) AS colore FROM in_interventi_tecnici INNER JOIN in_interventi ON in_interventi_tecnici.idintervento=in_interventi.id WHERE in_interventi.id=' . prepare ( $id ) . ' ' . Modules :: getAdditionalsQuery ( 'Interventi' , null , false );
2021-06-04 18:10:00 +02:00
$rs = $dbo -> fetchArray ( $query );
2017-08-04 16:28:16 +02:00
2021-06-04 18:10:00 +02:00
if ( ! empty ( $rs )) {
$tecnici = [];
foreach ( $rs as $sessione ) {
$tecnici [] = $sessione [ 'nome_tecnico' ] . ' (' . Translator :: timestampToLocale ( $sessione [ 'orario_inizio' ]) . ' - ' . Translator :: timeToLocale ( $sessione [ 'orario_fine' ]) . ')' ;
}
2017-08-04 16:28:16 +02:00
2021-06-04 18:10:00 +02:00
// Lettura dati intervento
2024-02-28 15:28:39 +01:00
$query = ' SELECT
* ,
`in_interventi` . `codice` ,
`an_anagrafiche` . `note` AS note_anagrafica ,
`in_statiintervento` . `id` AS parent_idstato ,
2024-04-18 17:44:05 +02:00
`in_statiintervento_lang` . `title` AS stato ,
2024-02-28 15:28:39 +01:00
`in_interventi` . `idtipointervento` AS parent_idtipo ,
( SELECT GROUP_CONCAT ( CONCAT ( `matricola` , " - " , `nome` ) SEPARATOR " , " ) FROM `my_impianti` INNER JOIN `my_impianti_interventi` ON `my_impianti` . `id` = `my_impianti_interventi` . `idimpianto` WHERE `my_impianti_interventi` . `idintervento` = '.prepare($id).' GROUP BY `my_impianti_interventi` . `idintervento` ) AS impianti ,
2024-04-18 17:44:05 +02:00
`in_tipiintervento_lang` . `title` AS tipo ,
2024-02-28 15:28:39 +01:00
( SELECT idzona FROM an_anagrafiche WHERE idanagrafica = in_interventi . idanagrafica ) AS idzona
FROM
`in_interventi`
INNER JOIN `in_statiintervento` ON `in_interventi` . `idstatointervento` = `in_statiintervento` . `id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `in_statiintervento_lang` ON ( `in_statiintervento_lang` . `id_record` = `in_statiintervento` . `id` AND `in_statiintervento_lang` . `id_lang` = '.prepare(Models\Locale::getDefault()->id).' )
2024-02-28 16:28:53 +01:00
INNER JOIN `in_tipiintervento` ON `in_interventi` . `idtipointervento` = `in_tipiintervento` . `id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `in_tipiintervento_lang` ON ( `in_tipiintervento_lang` . `id_record` = `in_tipiintervento` . `id` AND `in_tipiintervento_lang` . `id_lang` = '.prepare(Models\Locale::getDefault()->id).' )
2024-02-28 15:28:39 +01:00
LEFT JOIN `in_interventi_tecnici` ON `in_interventi` . `id` = `in_interventi_tecnici` . `idintervento`
LEFT JOIN `an_anagrafiche` ON `in_interventi` . `idanagrafica` = `an_anagrafiche` . `idanagrafica`
WHERE
`in_interventi` . `id` = '.prepare($id).' '.Modules::getAdditionalsQuery(' Interventi ' , null , false );
2021-06-04 18:10:00 +02:00
$rs = $dbo -> fetchArray ( $query );
2017-08-04 16:28:16 +02:00
2024-01-15 15:30:45 +01:00
// correggo info indirizzo citta cap provincia con quelle della sede di destinazione
2021-06-04 18:10:00 +02:00
if ( ! empty ( $rs [ 0 ][ 'idsede_destinazione' ])) {
$sede = $database -> fetchOne ( 'SELECT * FROM an_sedi WHERE id = ' . prepare ( $rs [ 0 ][ 'idsede_destinazione' ]));
$rs [ 0 ][ 'indirizzo' ] = $sede [ 'nomesede' ] . '<br>' . $sede [ 'indirizzo' ];
$rs [ 0 ][ 'cap' ] = $sede [ 'cap' ];
$rs [ 0 ][ 'citta' ] = $sede [ 'citta' ];
$rs [ 0 ][ 'provincia' ] = $sede [ 'provincia' ];
}
2020-10-06 12:29:14 +02:00
2021-06-04 18:10:00 +02:00
$desc_tipointervento = $rs [ 0 ][ 'tipo' ];
2017-08-04 16:28:16 +02:00
2021-06-04 18:10:00 +02:00
$tooltip = '<b>' . tr ( 'Numero intervento' ) . '</b>: ' . $rs [ 0 ][ 'codice' ] . '<br/>' ;
2017-08-04 16:28:16 +02:00
2021-06-04 18:10:00 +02:00
$tooltip .= '<b>' . tr ( 'Data richiesta' ) . '</b>: ' . Translator :: timestampToLocale ( $rs [ 0 ][ 'data_richiesta' ]) . '<br/>' ;
2021-07-07 07:57:10 +02:00
2021-06-08 12:36:54 +02:00
if ( ! empty ( $rs [ 0 ][ 'data_scadenza' ])) {
$tooltip .= '<b>' . tr ( 'Data scadenza' ) . '</b>: ' . Translator :: timestampToLocale ( $rs [ 0 ][ 'data_scadenza' ]) . '<br/>' ;
}
2017-08-04 16:28:16 +02:00
2024-05-23 11:36:25 +02:00
$tooltip .= '<b>' . tr ( 'Tipo intervento' ) . '</b>: ' . nl2br (( string ) $desc_tipointervento ) . '<br/>' ;
2017-08-04 16:28:16 +02:00
2021-06-04 18:10:00 +02:00
$tooltip .= '<b>' . tr ( 'Tecnici' ) . '</b>: ' . implode ( ', ' , $tecnici ) . '<br/>' ;
2017-08-04 16:28:16 +02:00
2021-06-04 18:10:00 +02:00
if ( $rs [ 0 ][ 'impianti' ] != '' ) {
$tooltip .= '<b>' . tr ( 'Impianti' ) . '</b>: ' . $rs [ 0 ][ 'impianti' ] . '<br/>' ;
}
2020-05-19 16:44:20 +02:00
2021-06-04 18:10:00 +02:00
if ( $rs [ 0 ][ 'richiesta' ] != '' ) {
2024-05-23 11:36:25 +02:00
$tooltip .= '<b>' . tr ( 'Richiesta' ) . '</b>:<div class=\'shorten\'> ' . nl2br (( string ) $rs [ 0 ][ 'richiesta' ]) . '</div>' ;
2021-06-04 18:10:00 +02:00
}
if ( $rs [ 0 ][ 'descrizione' ] != '' ) {
2024-05-23 11:36:25 +02:00
$tooltip .= '<b>' . tr ( 'Descrizione' ) . '</b>:<div class=\'shorten\'> ' . nl2br (( string ) $rs [ 0 ][ 'descrizione' ]) . '</div>' ;
2021-06-04 18:10:00 +02:00
}
if ( $rs [ 0 ][ 'informazioniaggiuntive' ] != '' ) {
2024-05-23 11:36:25 +02:00
$tooltip .= '<b>' . tr ( 'Informazioni aggiuntive' ) . '</b>: ' . nl2br (( string ) $rs [ 0 ][ 'informazioniaggiuntive' ]) . '<br/>' ;
2021-06-04 18:10:00 +02:00
}
2021-06-08 12:36:54 +02:00
2024-05-23 11:36:25 +02:00
$tooltip .= '<b>' . tr ( 'Ragione sociale' ) . '</b>: ' . nl2br (( string ) $rs [ 0 ][ 'ragione_sociale' ]) . '<br/>' ;
2021-06-08 12:36:54 +02:00
if ( ! empty ( $rs [ 0 ][ 'telefono' ])) {
2024-05-23 11:36:25 +02:00
$tooltip .= '<b>' . tr ( 'Telefono' ) . '</b>: ' . nl2br (( string ) $rs [ 0 ][ 'telefono' ]) . '<br/>' ;
2021-06-08 12:36:54 +02:00
}
if ( ! empty ( $rs [ 0 ][ 'cellulare' ])) {
2024-05-23 11:36:25 +02:00
$tooltip .= '<b>' . tr ( 'Cellulare' ) . '</b>: ' . nl2br (( string ) $rs [ 0 ][ 'cellulare' ]) . '<br/>' ;
2021-06-08 12:36:54 +02:00
}
if ( ! empty ( $rs [ 0 ][ 'indirizzo' ]) || ! empty ( $rs [ 0 ][ 'citta' ]) || ! empty ( $rs [ 0 ][ 'provincia' ]) || ! empty ( $rs [ 0 ][ 'cap' ])) {
$tooltip .= '<b>' . tr ( 'Indirizzo' ) . '</b>: ' . nl2br ( $rs [ 0 ][ 'indirizzo' ] . ' - ' . $rs [ 0 ][ 'cap' ] . ' ' . $rs [ 0 ][ 'citta' ] . ' (' . $rs [ 0 ][ 'provincia' ] . ')' ) . '<br/>' ;
}
if ( ! empty ( $rs [ 0 ][ 'note_anagrafica' ])) {
2024-05-23 11:36:25 +02:00
$tooltip .= '<b>' . tr ( 'Note anagrafica' ) . '</b>: ' . nl2br (( string ) $rs [ 0 ][ 'note_anagrafica' ]) . '<br/>' ;
2021-06-08 12:36:54 +02:00
}
2023-10-11 17:24:54 +02:00
}
} else {
$query = ' SELECT
2024-02-26 10:50:43 +01:00
`co_preventivi` . `nome` ,
`co_preventivi` . `numero` ,
`co_preventivi` . `data_accettazione` ,
`co_preventivi` . `data_conclusione` ,
`an_anagrafiche` . `ragione_sociale` AS cliente ,
`zz_files` . `id` AS have_attachments
FROM
`co_preventivi`
INNER JOIN `an_anagrafiche` ON `co_preventivi` . `idanagrafica` = `an_anagrafiche` . `idanagrafica`
LEFT JOIN zz_files ON zz_files . id_record = co_preventivi . id AND zz_files . id_module = '.prepare($modulo_preventivi->id).'
LEFT JOIN `co_statipreventivi` ON `co_preventivi` . `idstato` = `co_statipreventivi` . `id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `co_statipreventivi_lang` ON ( `co_statipreventivi_lang` . `id_record` = `co_statipreventivi` . `id` AND `co_statipreventivi_lang` . `id_lang` = '.prepare(Models\Locale::getDefault()->id).' )
2024-02-26 10:50:43 +01:00
WHERE
`co_preventivi` . `id` = ' . prepare ( $id );
2021-06-04 18:10:00 +02:00
2023-10-11 17:24:54 +02:00
$rs = $dbo -> fetchArray ( $query );
2021-06-04 18:10:00 +02:00
2023-10-11 17:24:54 +02:00
if ( ! empty ( $rs [ 0 ][ 'cliente' ])) {
$tooltip = '<b>Prev. ' . $rs [ 0 ][ 'numero' ] . '</b> ' . $rs [ 0 ][ 'nome' ] . '' . (( $rs [ 0 ][ 'have_attachments' ]) ? ' <i class="fa fa-paperclip" aria-hidden="true"></i>' : '' ) . '<br><b>' . tr ( 'Cliente' ) . ':</b> ' . $rs [ 0 ][ 'cliente' ];
} else {
$tooltip = tr ( 'Rilascia per aggiungere l\'attività...' );
2017-09-01 12:55:48 +02:00
}
2023-10-11 17:24:54 +02:00
}
2017-08-04 16:28:16 +02:00
2024-01-15 15:30:45 +01:00
$tooltip .= '
2021-06-08 12:36:54 +02:00
< script type = " text/javascript " >
$ ( " .shorten " ) . shorten ({
moreText : " '.tr('Mostra tutto').' " ,
lessText : " '.tr('Comprimi').' " ,
showChars : 200
});
</ script > ' ;
2023-08-04 14:54:28 +02:00
2024-01-15 15:30:45 +01:00
echo $tooltip ;
2023-10-11 17:24:54 +02:00
2020-08-04 18:33:28 +02:00
break ;
2017-08-04 16:28:16 +02:00
2020-08-04 18:33:28 +02:00
case 'carica_interventi' :
$mese = filter ( 'mese' );
2018-06-26 14:30:26 +02:00
2023-06-12 12:36:55 +02:00
$solo_promemoria_assegnati = setting ( 'Visualizza solo promemoria assegnati' );
2020-08-04 19:04:53 +02:00
$id_tecnico = null ;
if ( $user [ 'gruppo' ] == 'Tecnici' && ! empty ( $user [ 'idanagrafica' ])) {
$id_tecnico = $user [ 'idanagrafica' ];
}
2024-03-19 12:44:01 +01:00
$query = " (SELECT
`co_promemoria` . `id` AS id ,
`idcontratto` AS idcontratto ,
`richiesta` AS richiesta ,
`co_contratti` . `nome` AS nome_contratto ,
`co_contratti` . `numero` AS numero_contratto ,
`co_contratti` . `data_bozza` AS data_contratto ,
DATE_FORMAT ( `data_richiesta` , '%m%Y' ) AS mese ,
`data_richiesta` AS data_richiesta ,
2024-04-10 14:53:26 +02:00
IF ( `co_promemoria` . `data_scadenza` IS NULL , '' , `co_promemoria` . `data_scadenza` ) AS data_scadenza ,
2024-03-19 12:44:01 +01:00
`an_anagrafiche` . `ragione_sociale` AS ragione_sociale ,
'promemoria' AS ref ,
2024-04-18 17:44:05 +02:00
`in_tipiintervento_lang` . `title` AS tipo_intervento ,
2024-03-19 12:44:01 +01:00
'' AS id_tecnico ,
'' AS ragione_sociale_tecnico ,
'' AS colore
FROM
`co_promemoria`
INNER JOIN `co_contratti` ON `co_promemoria` . `idcontratto` = `co_contratti` . `id`
INNER JOIN `co_staticontratti` ON `co_contratti` . `idstato` = `co_staticontratti` . `id`
INNER JOIN `an_anagrafiche` ON `co_contratti` . `idanagrafica` = `an_anagrafiche` . `idanagrafica`
INNER JOIN `in_tipiintervento` ON `co_promemoria` . `idtipointervento` = `in_tipiintervento` . `id`
2024-04-10 14:53:26 +02:00
LEFT JOIN `in_tipiintervento_lang` ON `in_tipiintervento_lang` . `id_record` = `in_tipiintervento` . `id` AND `in_tipiintervento_lang` . `id_lang` = " .prepare(Models \ Locale::getDefault()->id). "
2024-03-19 12:44:01 +01:00
WHERE
`idintervento` IS NULL AND `co_staticontratti` . `is_pianificabile` = 1 )
UNION
( SELECT
`in_interventi` . `id` AS id ,
`in_interventi` . `id_contratto` AS idcontratto ,
`in_interventi` . `richiesta` AS richiesta ,
'' AS nome_contratto ,
'' AS numero_contratto ,
'' AS data_contratto ,
DATE_FORMAT ( IF ( `in_interventi` . `data_scadenza` IS NULL , `in_interventi` . `data_richiesta` , `in_interventi` . `data_scadenza` ), '%m%Y' ) AS mese ,
`in_interventi` . `data_richiesta` AS data_richiesta ,
2024-04-10 14:53:26 +02:00
IF ( `in_interventi` . `data_scadenza` IS NULL , '' , `in_interventi` . `data_scadenza` ) AS data_scadenza ,
2024-03-19 12:44:01 +01:00
`an_anagrafiche` . `ragione_sociale` AS ragione_sociale ,
'intervento' AS ref ,
2024-04-18 17:44:05 +02:00
`in_tipiintervento_lang` . `title` AS tipo_intervento ,
2024-03-19 12:44:01 +01:00
`in_interventi_tecnici_assegnati` . `id_tecnico` AS id_tecnico ,
`tecnico` . `ragione_sociale` AS ragione_sociale_tecnico ,
`tecnico` . `colore`
FROM
`in_interventi`
INNER JOIN `in_tipiintervento` ON `in_interventi` . `idtipointervento` = `in_tipiintervento` . `id`
2024-04-12 09:53:02 +02:00
LEFT JOIN `in_tipiintervento_lang` ON ( `in_tipiintervento_lang` . `id_record` = `in_tipiintervento` . `id` AND `in_tipiintervento_lang` . `id_lang` = " .prepare(Models \ Locale::getDefault()->id).')
INNER JOIN `an_anagrafiche` ON `in_interventi` . `idanagrafica` = `an_anagrafiche` . `idanagrafica` ' ;
2024-03-19 12:44:01 +01:00
2024-03-22 15:52:24 +01:00
// Visualizzo solo promemoria del tecnico loggato
if ( ! empty ( $id_tecnico ) && ! empty ( $solo_promemoria_assegnati )) {
$query .= '
INNER JOIN `in_interventi_tecnici_assegnati` ON `in_interventi` . `id` = `in_interventi_tecnici_assegnati` . `id_intervento` AND `id_tecnico` = ' . prepare ( $id_tecnico );
} else {
$query .= '
LEFT JOIN `in_interventi_tecnici_assegnati` ON `in_interventi` . `id` = `in_interventi_tecnici_assegnati` . `id_intervento` ' ;
}
$query .= ' LEFT JOIN `in_interventi_tecnici` ON `in_interventi_tecnici` . `idintervento` = `in_interventi` . `id`
2024-03-19 12:44:01 +01:00
INNER JOIN `in_statiintervento` ON `in_interventi` . `idstatointervento` = `in_statiintervento` . `id`
LEFT JOIN `an_anagrafiche` AS tecnico ON `in_interventi_tecnici_assegnati` . `id_tecnico` = `tecnico` . `idanagrafica`
WHERE
`in_statiintervento` . `is_completato` = 0
GROUP BY
`in_interventi` . `id` , `in_interventi_tecnici_assegnati` . `id_tecnico`
HAVING
COUNT ( `in_interventi_tecnici` . `id` ) = 0 )
ORDER BY
2024-03-22 15:52:24 +01:00
IF ( `data_scadenza` IS NULL , `data_richiesta` , `data_scadenza` ) ASC ' ;
2024-03-19 12:44:01 +01:00
$promemoria = $dbo -> fetchArray ( $query );
2020-11-06 19:24:11 +01:00
2020-08-04 18:33:28 +02:00
if ( ! empty ( $promemoria )) {
2018-03-22 18:34:33 +01:00
$prev_mese = '' ;
2018-09-20 09:21:34 +02:00
// Elenco interventi da pianificare
2020-08-04 18:33:28 +02:00
foreach ( $promemoria as $sessione ) {
2023-04-13 10:45:50 +02:00
if ( $sessione [ 'mese' ] == $mese || $mese == 'all' ) {
2024-05-23 11:36:25 +02:00
if ( date ( 'Ymd' , strtotime (( string ) $sessione [ 'data_scadenza' ])) < date ( 'Ymd' ) and ! empty ( $sessione [ 'data_scadenza' ])) {
2020-07-17 16:03:21 +02:00
$class = 'danger' ;
2018-06-26 14:30:26 +02:00
} else {
2020-07-17 16:03:21 +02:00
$class = 'primary' ;
2018-03-22 18:34:33 +01:00
}
2018-06-26 14:30:26 +02:00
2020-09-15 12:30:25 +02:00
$link = null ;
2020-09-15 13:22:52 +02:00
if ( $sessione [ 'ref' ] == 'intervento' ) {
2020-09-15 12:30:25 +02:00
$modulo_riferimento = 'Interventi' ;
$id_riferimento = $sessione [ 'id' ];
} else {
$modulo_riferimento = 'Contratti' ;
$id_riferimento = $sessione [ 'idcontratto' ];
}
2018-03-22 18:34:33 +01:00
echo '
2023-01-24 22:43:39 +01:00
< div id = " id-'. $sessione['id'] .' " class = " fc-event fc-event-'. $class .' " data - id = " '. $sessione['id'] .' " data - idcontratto = " '. $sessione['idcontratto'] .' " data - ref = " '. $sessione['ref'] .' " data - id_tecnico = " '. $sessione['id_tecnico'] .' " > '.($sessione[' ref '] == ' intervento ' ? Modules::link($modulo_riferimento, $id_riferimento, ' < i class = " fa fa-wrench " ></ i > ', null, ' title = " '.tr('Visualizza scheda').' " class = " btn btn-'. $class .' btn-xs pull-right " ') : Modules::link($modulo_riferimento, $id_riferimento, ' < i class = " fa fa-file-text-o " ></ i > ', null, ' title = " '.tr('Visualizza scheda').' " class = " btn btn-'. $class .' btn-xs pull-right " ')).'
2020-11-06 19:24:11 +01:00
< b > '.$sessione[' ragione_sociale '].' </ b >
2020-09-15 12:30:25 +02:00
< br > '.dateFormat($sessione[' data_richiesta ']).' ( '.$sessione[' tipo_intervento '].' )
2024-05-23 11:36:25 +02:00
< div class = " request " > '.(!empty($sessione[' richiesta ']) ? ' - '.strip_tags((string) $sessione[' richiesta ']) : ' ').' </ div >
2024-05-16 18:02:50 +02:00
'.(!empty($sessione[' numero_contratto ']) ? ' < span class = " badge badge-'. $class .' " > '.tr(' Contratto numero : ').$sessione[' numero_contratto '].tr(' del ').dateFormat($sessione[' data_contratto ']).' < span > ' : ' ').' '.(!empty($sessione[' data_scadenza '] && $sessione[' data_scadenza '] != ' 0000 - 00 - 00 00 : 00 : 00 ') ? ' < span class = " badge badge-'. $class .' " > '.tr(' Entro il : ').dateFormat($sessione[' data_scadenza ']).' </ span > ' : ' ').' '.(!empty($sessione[' id_tecnico ']) ? ' < span class = " badge " style = " color:'.color_inverse( $sessione['colore'] ).';background-color:'. $sessione['colore'] .'; " > '.tr(' Tecnico ').' : '.$sessione[' ragione_sociale_tecnico '].' </ span > ' : ' ').'
2020-09-15 12:30:25 +02:00
</ div > ' ;
2018-03-22 18:34:33 +01:00
}
2020-08-04 18:33:28 +02:00
}
echo '
2019-07-04 17:36:28 +02:00
< script type = " text/javascript " >
$ ( " .request " ) . shorten ({
2020-08-04 18:33:28 +02:00
moreText : " '.tr('Mostra tutto').' " ,
lessText : " '.tr('Comprimi').' " ,
2019-07-04 17:36:28 +02:00
showChars : 200
});
2020-08-04 18:33:28 +02:00
</ script > ' ;
2018-09-20 09:21:34 +02:00
} else {
2018-06-06 00:15:07 +02:00
echo '<br><small class="help-block">' . tr ( 'Non ci sono interventi da pianificare per questo mese' ) . '</small>' ;
2018-03-22 18:34:33 +01:00
}
2018-06-26 14:30:26 +02:00
2018-03-22 18:34:33 +01:00
break ;
2023-03-28 16:24:33 +02:00
2024-01-15 15:30:45 +01:00
case 'calendario_eventi' :
$start = filter ( 'start' );
$end = filter ( 'end' );
2023-03-28 16:24:33 +02:00
2024-01-15 15:30:45 +01:00
// TODO: Problema con anni bisestili Es. 2024-02-29 e 2023-03-01 sono entrambi il 60 esimo giorno dell'anno.
$query = 'SELECT *, DAYOFYEAR(`zz_events`.`data`) AS d, DAYOFYEAR(' . prepare ( $start ) . ') AS st, DAYOFYEAR(' . prepare ( $end ) . ' ) AS fi FROM `zz_events`
2023-03-29 00:36:46 +02:00
WHERE `zz_events` . `is_bank_holiday` = 1
AND
( `zz_events` . `is_recurring` = 1
2023-08-04 14:54:28 +02:00
AND DAYOFYEAR ( `zz_events` . `data` ) BETWEEN DAYOFYEAR ( '.prepare($start).' ) AND IF ( YEAR ( '.prepare($start).' ) = YEAR ( '.prepare($end).' ), DAYOFYEAR ( '.prepare($end).' ), DAYOFYEAR ( '.prepare(date(' Y - m - d ', strtotime($end.' - 1 day '))).' )) )
2023-03-29 00:36:46 +02:00
OR
( `zz_events` . `is_recurring` = 0 AND `zz_events` . `data` >= '.prepare($start).' AND `zz_events` . `data` <= '.prepare($end).' ) ' ;
2023-03-28 16:24:33 +02:00
2024-01-15 15:30:45 +01:00
$eventi = $dbo -> fetchArray ( $query );
2023-08-04 14:54:28 +02:00
2024-01-15 15:30:45 +01:00
$results = [];
foreach ( $eventi as $evento ) {
$results [] = [
2024-03-22 15:52:24 +01:00
'id' => $evento [ 'id' ],
'title' => $evento [ 'nome' ],
2024-05-23 11:36:25 +02:00
'start' => ( $evento [ 'is_recurring' ] ? date ( 'Y-' , strtotime ( $start )) . date ( 'm-d' , strtotime (( string ) $evento [ 'data' ])) : $evento [ 'data' ]),
2024-03-22 15:52:24 +01:00
// 'end' => date('Y-m-d', strtotime($evento['data']. '+1 day')),
'display' => 'background' ,
'allDay' => true ,
'overlap' => true ,
2024-01-15 15:30:45 +01:00
];
}
2023-03-28 16:24:33 +02:00
2024-01-15 15:30:45 +01:00
echo json_encode ( $results );
2023-03-28 16:24:33 +02:00
break ;
2017-08-04 16:28:16 +02:00
}