Skip to content

Commit 7dba938

Browse files
committed
feat: sincronizzazzione su app di automezzi e giacenza automezzi
1 parent d4185c1 commit 7dba938

4 files changed

Lines changed: 182 additions & 1 deletion

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
}

src/API/App/v1/Automezzi.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 Automezzi extends AppResource
26+
{
27+
public function getCleanupData($last_sync_at)
28+
{
29+
return $this->getMissingIDs('an_sedi', '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 gli automezzi collegati al tecnico tramite zz_user_sedi
39+
$query = 'SELECT
40+
DISTINCT(`an_sedi`.`id`) AS id,
41+
`an_sedi`.`updated_at`
42+
FROM
43+
`an_sedi`
44+
INNER JOIN `zz_user_sedi` ON `zz_user_sedi`.`idsede` = `an_sedi`.`id`
45+
WHERE
46+
`an_sedi`.`is_automezzo` = 1
47+
AND `an_sedi`.`deleted_at` IS NULL
48+
AND `zz_user_sedi`.`id_user` = '.prepare($id_utente);
49+
50+
// Filtro per data
51+
if ($last_sync_at) {
52+
$query .= ' AND `an_sedi`.`updated_at` > '.prepare($last_sync_at);
53+
}
54+
55+
$records = database()->fetchArray($query);
56+
57+
return $this->mapModifiedRecords($records);
58+
}
59+
60+
public function retrieveRecord($id)
61+
{
62+
// Gestione della visualizzazione dei dettagli del record
63+
$query = 'SELECT
64+
`an_sedi`.`id`,
65+
`an_sedi`.`nome`,
66+
`an_sedi`.`targa`,
67+
`an_sedi`.`descrizione`,
68+
`an_sedi`.`indirizzo`,
69+
`an_sedi`.`citta`,
70+
`an_sedi`.`cap`,
71+
`an_sedi`.`provincia`,
72+
IFNULL(`an_sedi`.`lat`, 0.00) AS latitudine,
73+
IFNULL(`an_sedi`.`lng`, 0.00) AS longitudine
74+
FROM
75+
`an_sedi`
76+
WHERE
77+
`an_sedi`.`id` = '.prepare($id).'
78+
AND `an_sedi`.`is_automezzo` = 1';
79+
80+
$record = database()->fetchOne($query);
81+
82+
return $record;
83+
}
84+
}

src/API/App/v1/VerificaAggiornamenti.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class VerificaAggiornamenti extends Resource implements RetrieveInterface
5858
'checklists' => Checklists::class,
5959
'pagamenti' => Pagamenti::class,
6060
'allegati-interventi' => AllegatiInterventi::class,
61+
'automezzi' => Automezzi::class,
62+
'articoli-automezzo' => ArticoliAutomezzo::class,
6163
];
6264

6365
/**

update/2_11.sql

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,13 @@ INSERT INTO `zz_settings` (`nome`, `valore`, `tipo`, `editable`, `sezione`) VALU
4949

5050
INSERT INTO `zz_settings_lang` (`id_lang`, `id_record`, `title`, `help`) VALUES
5151
(1, (SELECT MAX(`id`) FROM `zz_settings`), 'Ritardo apertura tooltip dashboard (ms)', 'Definisce il ritardo in millisecondi prima che il tooltip venga mostrato al passaggio del mouse sugli eventi del calendario nella Dashboard.'),
52-
(2, (SELECT MAX(`id`) FROM `zz_settings`), 'Dashboard tooltip opening delay (ms)', 'Defines the delay in milliseconds before the tooltip is shown when hovering over calendar events in the Dashboard.');
52+
(2, (SELECT MAX(`id`) FROM `zz_settings`), 'Dashboard tooltip opening delay (ms)', 'Defines the delay in milliseconds before the tooltip is shown when hovering over calendar events in the Dashboard.');
53+
54+
-- Registrazione risorse API per automezzi e articoli automezzo
55+
INSERT INTO `zz_api_resources` (`version`, `type`, `resource`, `class`, `enabled`) VALUES
56+
('app-v1', 'retrieve', 'automezzi', 'API\\App\\v1\\Automezzi', 1),
57+
('app-v1', 'retrieve', 'automezzi-cleanup', 'API\\App\\v1\\Automezzi', 1),
58+
('app-v1', 'retrieve', 'automezzo', 'API\\App\\v1\\Automezzi', 1),
59+
('app-v1', 'retrieve', 'articoli-automezzo', 'API\\App\\v1\\ArticoliAutomezzo', 1),
60+
('app-v1', 'retrieve', 'articoli-automezzo-cleanup', 'API\\App\\v1\\ArticoliAutomezzo', 1),
61+
('app-v1', 'retrieve', 'articolo-automezzo', 'API\\App\\v1\\ArticoliAutomezzo', 1);

0 commit comments

Comments
 (0)