Filtro per far visualizzare al tecnico loggato nell'APP solo le sue attività

This commit is contained in:
Luca 2020-06-12 13:00:28 +02:00
parent 33f7fd1d7b
commit 2da06652d9
1 changed files with 18 additions and 1 deletions

View File

@ -11,6 +11,7 @@ use Modules\Anagrafiche\Anagrafica;
use Modules\Interventi\Intervento; use Modules\Interventi\Intervento;
use Modules\Interventi\Stato; use Modules\Interventi\Stato;
use Modules\TipiIntervento\Tipo as TipoSessione; use Modules\TipiIntervento\Tipo as TipoSessione;
use Auth;
class Interventi extends Resource implements RetrieveInterface, CreateInterface, UpdateInterface class Interventi extends Resource implements RetrieveInterface, CreateInterface, UpdateInterface
{ {
@ -20,6 +21,7 @@ class Interventi extends Resource implements RetrieveInterface, CreateInterface,
$today = date('Y-m-d'); $today = date('Y-m-d');
$period_end = date('Y-m-d', strtotime($today.' +7 days')); $period_end = date('Y-m-d', strtotime($today.' +7 days'));
$period_start = date('Y-m-d', strtotime($today.' -2 months')); $period_start = date('Y-m-d', strtotime($today.' -2 months'));
$user = Auth::user();
// AND `in_statiintervento`.`is_completato`=0 // AND `in_statiintervento`.`is_completato`=0
$query = "SELECT `in_interventi`.`id`, $query = "SELECT `in_interventi`.`id`,
@ -46,24 +48,39 @@ class Interventi extends Resource implements RetrieveInterface, CreateInterface,
INNER JOIN `in_statiintervento` ON `in_interventi`.`idstatointervento` = `in_statiintervento`.`idstatointervento` INNER JOIN `in_statiintervento` ON `in_interventi`.`idstatointervento` = `in_statiintervento`.`idstatointervento`
INNER JOIN `an_anagrafiche` ON `in_interventi`.`idanagrafica` = `an_anagrafiche`.`idanagrafica` INNER JOIN `an_anagrafiche` ON `in_interventi`.`idanagrafica` = `an_anagrafiche`.`idanagrafica`
LEFT JOIN `an_sedi` ON `in_interventi`.`idsede_destinazione` = `an_sedi`.`id` LEFT JOIN `an_sedi` ON `in_interventi`.`idsede_destinazione` = `an_sedi`.`id`
LEFT JOIN `in_interventi_tecnici` ON `in_interventi_tecnici`.`idintervento` = `in_interventi`.`id`
WHERE EXISTS(SELECT `orario_fine` FROM `in_interventi_tecnici` WHERE `in_interventi_tecnici`.`idintervento` = `in_interventi`.`id` AND `orario_fine` BETWEEN :period_start AND :period_end)"; WHERE EXISTS(SELECT `orario_fine` FROM `in_interventi_tecnici` WHERE `in_interventi_tecnici`.`idintervento` = `in_interventi`.`id` AND `orario_fine` BETWEEN :period_start AND :period_end)";
//Filtro per far visualizzare al tecnico loggato solo le sue attività
$filters = [];
$filters[] = 'in_interventi_tecnici.idtecnico ='.$user->idanagrafica;
$query .= !empty($filters) ? ' AND ('.implode('OR ', $filters).')' : '';
$query .= ' $query .= '
HAVING 2=2 HAVING 2=2
ORDER BY `in_interventi`.`data_richiesta` DESC'; ORDER BY `in_interventi`.`data_richiesta` DESC';
$parameters = [ $parameters = [
':period_end' => $period_end, ':period_end' => $period_end,
':period_start' => $period_start, ':period_start' => $period_start,
]; ];
$module = Modules::get('Interventi'); $module = Modules::get('Interventi');
$query = Modules::replaceAdditionals($module->id, $query); $query = Modules::replaceAdditionals($module->id, $query);
return [ return [
'query' => $query, 'query' => $query,
'parameters' => $parameters, 'parameters' => $parameters,
]; ];
} }
public function create($request) public function create($request)