Skip to content

Commit d68aa34

Browse files
feat: gestione inventario
1 parent e4724cc commit d68aa34

5 files changed

Lines changed: 435 additions & 0 deletions

File tree

modules/articoli/ajax/select.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
`mg_articoli`.`fattore_um_secondaria`,
9292
`mg_articoli`.`servizio`,
9393
`mg_articoli`.`abilita_serial`,
94+
`mg_articoli`.`ubicazione`,
9495
`mg_articoli`.`idconto_vendita`,
9596
`mg_articoli`.`idconto_acquisto`,
9697
`categoria_lang`.`title` AS categoria,

modules/movimenti/actions.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,48 @@
6060
]);
6161
}
6262

63+
break;
64+
65+
case 'salva_inventario':
66+
$idsede = post('idsede');
67+
$data = post('data') ?: date('Y-m-d');
68+
$righe = post('righe');
69+
70+
if (empty($righe) || !is_array($righe)) {
71+
echo json_encode(['success' => false, 'message' => tr('Nessuna riga da salvare')]);
72+
break;
73+
}
74+
75+
try {
76+
foreach ($righe as $riga) {
77+
$id_articolo = $riga['id_articolo'];
78+
$giacenza_attuale = floatval($riga['giacenza_attuale']);
79+
$nuova_giacenza = floatval($riga['nuova_giacenza']);
80+
$ubicazione = $riga['ubicazione'] ?: '';
81+
82+
// Calcola la differenza
83+
$differenza = $nuova_giacenza - $giacenza_attuale;
84+
85+
if ($differenza != 0) {
86+
$articolo = Articolo::find($id_articolo);
87+
88+
if ($articolo) {
89+
$descrizione = tr('Inventario - Rettifica giacenza');
90+
91+
// Registra il movimento
92+
$articolo->movimenta($differenza, $descrizione, $data, 1, [
93+
'idsede' => $idsede,
94+
]);
95+
96+
$articolo->ubicazione = $ubicazione;
97+
$articolo->save();
98+
}
99+
}
100+
}
101+
echo json_encode(['success' => true, 'message' => tr('Inventario salvato correttamente')]);
102+
} catch (Exception $e) {
103+
echo json_encode(['success' => false, 'message' => tr('Errore durante il salvataggio: ') . $e->getMessage()]);
104+
}
105+
63106
break;
64107
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
include_once __DIR__.'/../../core.php';
22+
23+
// Pulsante centrale per aggiungere inventario
24+
echo '
25+
<div class="row">
26+
<div class="col-md-12 text-center">
27+
<button type="button" class="btn btn-primary btn-lg" onclick="openModal(\''.tr('Inventario').'\', \''.base_path_osm().'/modules/movimenti/modals/inventario.php?id_module='.$id_module.'\');">
28+
'.tr('Aggiorna inventario').'
29+
</button>
30+
</div>
31+
</div>';
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
include_once __DIR__.'/../../../core.php';
22+
23+
$righe = post('righe');
24+
25+
if (empty($righe) || !is_array($righe)) {
26+
exit;
27+
}
28+
29+
echo '<table class="table table-striped table-hover table-bordered" id="tabella-inventario">
30+
<thead>
31+
<tr>
32+
<th width="20%">'.tr('Codice').'</th>
33+
<th width="30%">'.tr('Descrizione').'</th>
34+
<th width="15%">'.tr('Giacenza attuale').'</th>
35+
<th width="15%">'.tr('Nuova giacenza').'</th>
36+
<th width="15%">'.tr('Ubicazione').'</th>
37+
<th width="5%">'.tr('Azioni').'</th>
38+
</tr>
39+
</thead>
40+
<tbody>';
41+
42+
foreach ($righe as $riga) {
43+
$id = $riga['id'];
44+
$codice = $riga['codice'];
45+
$descrizione = $riga['descrizione'];
46+
$giacenza_attuale = floatval($riga['giacenza_attuale']);
47+
$nuova_giacenza = floatval($riga['nuova_giacenza']);
48+
$ubicazione = $riga['ubicazione'];
49+
50+
echo '<tr data-id="'.$id.'">
51+
<td>'.$codice.'</td>
52+
<td>'.$descrizione.'</td>
53+
<td class="text-right">'.Translator::numberToLocale($giacenza_attuale).'</td>
54+
<td>';
55+
56+
// Input giacenza con struttura OpenSTAManager
57+
echo '{[ "type": "number", "name": "giacenza_'.$id.'", "value": "'.$nuova_giacenza.'", "decimals": "qta", "class": "text-right", "onchange": "aggiornaGiacenza('.$id.', this.value)" ]}';
58+
59+
echo '</td>
60+
<td>';
61+
62+
// Input ubicazione con struttura OpenSTAManager
63+
echo '{[ "type": "text", "name": "ubicazione_'.$id.'", "value": "'.$ubicazione.'", "placeholder": "'.tr('Ubicazione').'", "onchange": "aggiornaUbicazione('.$id.', this.value)" ]}';
64+
65+
echo '</td>
66+
<td class="text-center">
67+
<button type="button" class="btn btn-danger"
68+
onclick="rimuoviRigaInventario('.$id.')"
69+
title="'.tr('Rimuovi').'">
70+
<i class="fa fa-trash"></i>
71+
</button>
72+
</td>
73+
</tr>';
74+
}
75+
76+
echo '</tbody></table>';

0 commit comments

Comments
 (0)