2018-02-04 09:41:46 +01:00
< ? php
2024-12-02 11:17:31 +01:00
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 />.
*/
2018-02-04 09:41:46 +01:00
include_once __DIR__ . '/../../../core.php' ;
2024-11-25 12:30:10 +01:00
use Modules\Contratti\Contratto ;
2018-02-04 09:41:46 +01:00
switch ( $resource ) {
2020-08-14 09:55:05 +02:00
/*
2020-08-17 10:57:51 +02:00
* Opzioni utilizzate :
2020-08-17 16:25:01 +02:00
* - idanagrafica
2020-08-14 09:55:05 +02:00
* - stato
2020-08-17 16:25:01 +02:00
*/
2018-02-04 09:41:46 +01:00
case 'contratti' :
2024-12-18 10:33:32 +01:00
$query = ' SELECT
`co_contratti` . `id` AS id ,
CONCAT ( " Contratto " , `numero` , " del " , DATE_FORMAT ( `data_bozza` , " %d/%m/%Y " ), " - " , `co_contratti` . `nome` , " [ " , ( SELECT `title` FROM `co_staticontratti` LEFT JOIN `co_staticontratti_lang` ON ( `co_staticontratti` . `id` = `co_staticontratti_lang` . `id_record` AND `co_staticontratti_lang` . `id_lang` = '.prepare(Models\Locale::getDefault()->id).' ) WHERE `co_staticontratti` . `id` = `idstato` ) , " ] " ) AS descrizione ,
( SELECT SUM ( `subtotale` ) FROM `co_righe_contratti` WHERE `idcontratto` = `co_contratti` . `id` ) AS totale ,
( SELECT SUM ( `sconto` ) FROM `co_righe_contratti` WHERE `idcontratto` = `co_contratti` . `id` ) AS sconto ,
( SELECT COUNT ( `id` ) FROM `co_righe_contratti` WHERE `idcontratto` = `co_contratti` . `id` ) AS n_righe ,
`co_contratti` . `idtipointervento` ,
`in_tipiintervento_lang` . `title` AS idtipointervento_descrizione ,
`in_tipiintervento` . `tempo_standard` AS tempo_standard
FROM
`co_contratti`
INNER JOIN `an_anagrafiche` ON `co_contratti` . `idanagrafica` = `an_anagrafiche` . `idanagrafica`
LEFT JOIN `in_tipiintervento` ON ( `co_contratti` . `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(Models\Locale::getDefault()->id).' )
| where |
ORDER BY
`co_contratti` . `id` ' ;
2018-02-04 09:41:46 +01:00
foreach ( $elements as $element ) {
2024-02-09 12:08:55 +01:00
$filter [] = '`co_contratti`.`id`=' . prepare ( $element );
2018-02-04 09:41:46 +01:00
}
2019-02-14 17:49:58 +01:00
if ( empty ( $elements )) {
2024-02-09 12:08:55 +01:00
$where [] = '`an_anagrafiche`.`idanagrafica`=' . prepare ( $superselect [ 'idanagrafica' ]);
2018-07-02 18:01:39 +02:00
2019-03-22 11:35:26 +01:00
$stato = ! empty ( $superselect [ 'stato' ]) ? $superselect [ 'stato' ] : 'is_pianificabile' ;
2024-02-09 12:08:55 +01:00
$where [] = '`idstato` IN (SELECT `id` FROM `co_staticontratti` WHERE ' . $stato . ' = 1)' ;
2018-07-02 18:01:39 +02:00
}
2018-02-04 09:41:46 +01:00
if ( ! empty ( $search )) {
2024-02-09 12:08:55 +01:00
$search_fields [] = '`co_contratti`.`nome` LIKE ' . prepare ( '%' . $search . '%' );
2018-02-04 09:41:46 +01:00
}
2024-11-25 12:30:10 +01:00
$query = str_replace ( '|where|' , ! empty ( $where ) ? 'WHERE ' . implode ( ' AND ' , $where ) : '' , $query );
$rs = $dbo -> fetchArray ( $query );
foreach ( $rs as $r ) {
$contratto = Contratto :: find ( $r [ 'id' ]);
$ore_erogate = $contratto -> interventi -> sum ( 'ore_totali' );
$ore_previste = $contratto -> getRighe () -> where ( 'um' , 'ore' ) -> sum ( 'qta' );
$perc_ore = $ore_previste != 0 ? ( $ore_erogate * 100 ) / ( $ore_previste ? : 1 ) : 0 ;
2024-12-02 11:17:31 +01:00
if ( $ore_previste ) {
2024-11-25 12:30:10 +01:00
if ( $perc_ore < 75 ) {
$color = '#81f794' ;
} elseif ( $perc_ore <= 100 ) {
$color = '#f5cb78' ;
}
}
2024-12-02 11:17:31 +01:00
$descrizione = ( $ore_previste > 0 ? $r [ 'descrizione' ] . ' - ' . tr ( '_EROGATE_/_PREVISTE_ ore' , [
'_EROGATE_' => Translator :: numberToLocale ( $ore_erogate , 2 ),
'_PREVISTE_' => Translator :: numberToLocale ( $ore_previste , 2 ),
2024-11-25 12:30:10 +01:00
]) : $r [ 'descrizione' ]);
$results [] = [
'id' => $r [ 'id' ],
'text' => $descrizione ,
'descrizione' => $descrizione ,
'_bgcolor_' => $color ,
2024-12-18 10:33:32 +01:00
'idtipointervento' => $r [ 'idtipointervento' ],
'idtipointervento_descrizione' => $r [ 'idtipointervento_descrizione' ]
2024-11-25 12:30:10 +01:00
];
}
2018-02-04 09:41:46 +01:00
break ;
2024-11-25 15:59:41 +01:00
case 'categorie_contratti' :
$query = 'SELECT `co_categorie_contratti`.`id`, `title` AS descrizione FROM `co_categorie_contratti` LEFT JOIN `co_categorie_contratti_lang` ON (`co_categorie_contratti`.`id` = `co_categorie_contratti_lang`.`id_record` AND `co_categorie_contratti_lang`.`id_lang` = ' . prepare ( Models\Locale :: getDefault () -> id ) . ') |where| ORDER BY `title`' ;
foreach ( $elements as $element ) {
$filter [] = '`co_categorie_contratti`.`id`=' . prepare ( $element );
}
$where [] = '`parent` IS NULL' ;
if ( ! empty ( $search )) {
$search_fields [] = '`title` LIKE ' . prepare ( '%' . $search . '%' );
}
break ;
/*
* Opzioni utilizzate :
* - id_categoria
*/
case 'sottocategorie_contratti' :
if ( isset ( $superselect [ 'id_categoria' ])) {
$query = 'SELECT `co_categorie_contratti`.`id`, `title` AS descrizione FROM `co_categorie_contratti` LEFT JOIN `co_categorie_contratti_lang` ON (`co_categorie_contratti`.`id` = `co_categorie_contratti_lang`.`id_record` AND `co_categorie_contratti_lang`.`id_lang` = ' . prepare ( Models\Locale :: getDefault () -> id ) . ') |where| ORDER BY `title`' ;
foreach ( $elements as $element ) {
$filter [] = '`co_categorie_contratti`.`id`=' . prepare ( $element );
}
$where [] = '`parent`=' . prepare ( $superselect [ 'id_categoria' ]);
if ( ! empty ( $search )) {
$search_fields [] = '`title` LIKE ' . prepare ( '%' . $search . '%' );
}
}
break ;
2018-02-04 09:41:46 +01:00
}