|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione |
| 5 | + * Copyright (C) DevCode s.r.l. |
| 6 | + * |
| 7 | + * This program is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +namespace API\App\v1; |
| 22 | + |
| 23 | +use API\App\AppResource; |
| 24 | + |
| 25 | +class ArticoliAutomezzo extends AppResource |
| 26 | +{ |
| 27 | + public function getCleanupData($last_sync_at) |
| 28 | + { |
| 29 | + return $this->getMissingIDs('mg_movimenti', 'id', $last_sync_at); |
| 30 | + } |
| 31 | + |
| 32 | + public function getModifiedRecords($last_sync_at) |
| 33 | + { |
| 34 | + // Recupera l'ID utente loggato |
| 35 | + $user = auth_osm()->getUser(); |
| 36 | + $id_utente = $user->id; |
| 37 | + |
| 38 | + // Query per recuperare i movimenti degli articoli sugli automezzi del tecnico |
| 39 | + $query = 'SELECT |
| 40 | + `mg_movimenti`.`id`, |
| 41 | + `mg_movimenti`.`updated_at` |
| 42 | + FROM |
| 43 | + `mg_movimenti` |
| 44 | + INNER JOIN `an_sedi` ON `an_sedi`.`id` = `mg_movimenti`.`idsede` |
| 45 | + INNER JOIN `zz_user_sedi` ON `zz_user_sedi`.`idsede` = `an_sedi`.`id` |
| 46 | + WHERE |
| 47 | + `an_sedi`.`is_automezzo` = 1 |
| 48 | + AND `an_sedi`.`deleted_at` IS NULL |
| 49 | + AND `zz_user_sedi`.`id_user` = '.prepare($id_utente); |
| 50 | + |
| 51 | + // Filtro per data |
| 52 | + if ($last_sync_at) { |
| 53 | + $query .= ' AND `mg_movimenti`.`updated_at` > '.prepare($last_sync_at); |
| 54 | + } |
| 55 | + |
| 56 | + $records = database()->fetchArray($query); |
| 57 | + |
| 58 | + return $this->mapModifiedRecords($records); |
| 59 | + } |
| 60 | + |
| 61 | + public function retrieveRecord($id) |
| 62 | + { |
| 63 | + // Gestione della visualizzazione dei dettagli del record |
| 64 | + $query = 'SELECT |
| 65 | + `mg_movimenti`.`id`, |
| 66 | + `mg_movimenti`.`idarticolo` AS id_articolo, |
| 67 | + `mg_movimenti`.`idsede` AS id_automezzo, |
| 68 | + `mg_movimenti`.`qta`, |
| 69 | + `mg_movimenti`.`movimento` AS descrizione, |
| 70 | + `mg_movimenti`.`data`, |
| 71 | + `mg_articoli`.`codice` AS codice_articolo, |
| 72 | + `mg_articoli_lang`.`title` AS descrizione_articolo, |
| 73 | + `mg_articoli`.`prezzo_vendita`, |
| 74 | + `mg_articoli`.`um` |
| 75 | + FROM |
| 76 | + `mg_movimenti` |
| 77 | + INNER JOIN `mg_articoli` ON `mg_movimenti`.`idarticolo` = `mg_articoli`.`id` |
| 78 | + LEFT JOIN `mg_articoli_lang` ON (`mg_articoli`.`id` = `mg_articoli_lang`.`id_record` AND `mg_articoli_lang`.`id_lang` = '.prepare(\Models\Locale::getDefault()->id).') |
| 79 | + WHERE |
| 80 | + `mg_movimenti`.`id` = '.prepare($id); |
| 81 | + |
| 82 | + $record = database()->fetchOne($query); |
| 83 | + |
| 84 | + return $record; |
| 85 | + } |
| 86 | +} |
0 commit comments