From 72d2e885af9abfdf91aea1d893dd0fbdff1bb4ae Mon Sep 17 00:00:00 2001 From: MatteoPistorello Date: Mon, 26 Jun 2023 15:12:43 +0200 Subject: [PATCH] Gestione flag is_rientrabile per i ddt --- modules/causali/actions.php | 1 + modules/causali/edit.php | 9 ++++++--- modules/fatture/actions.php | 9 ++++++++- modules/fatture/add_serial.php | 33 +++++++++++++++++++++++++++++---- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/modules/causali/actions.php b/modules/causali/actions.php index 1d057be0c..9ae2b2261 100755 --- a/modules/causali/actions.php +++ b/modules/causali/actions.php @@ -35,6 +35,7 @@ switch (filter('op')) { 'is_importabile' => filter('is_importabile'), 'reversed' => filter('reversed'), 'predefined' => $predefined, + 'is_rientrabile' => filter('is_rientrabile'), ], ['id' => $id_record]); flash()->info(tr('Salvataggio completato!')); diff --git a/modules/causali/edit.php b/modules/causali/edit.php index 222334659..86eec6185 100755 --- a/modules/causali/edit.php +++ b/modules/causali/edit.php @@ -40,15 +40,18 @@ include_once __DIR__.'/../../core.php';

-
+
{[ "type": "checkbox", "label": "", "name": "predefined", "value": "$predefined$", "help":"." ]}
-
+
{[ "type": "checkbox", "label": "", "name": "is_importabile", "value": "$is_importabile$", "help": "", "placeholder": "" ]}
-
+
{[ "type": "checkbox", "label": "", "name": "reversed", "value": "$reversed$", "help": "", "placeholder": "" ]}
+
+ {[ "type": "checkbox", "label": "", "name": "is_rientrabile", "value": "$is_rientrabile$", "help": "", "placeholder": "" ]} +
diff --git a/modules/fatture/actions.php b/modules/fatture/actions.php index 662974e7f..0a0aaa6c5 100755 --- a/modules/fatture/actions.php +++ b/modules/fatture/actions.php @@ -930,7 +930,14 @@ switch (post('op')) { break; case 'controlla_serial': - $has_serial = $dbo->fetchOne('SELECT id FROM mg_prodotti WHERE serial='.prepare(post('serial')).' AND dir="uscita" AND id_articolo='.prepare(post('id_articolo')).' AND (id_riga_documento IS NOT NULL OR id_riga_ordine IS NOT NULL OR id_riga_ddt IS NOT NULL)')['id']; + if (post('is_rientrabile')) { + // Controllo che i serial entrati e usciti siano uguali in modo da poterli registrare nuovamente. + $serial_uscita = $dbo->fetchOne('SELECT COUNT(id) AS `tot` FROM mg_prodotti WHERE serial='.prepare(post('serial')).' AND dir="uscita" AND id_articolo='.prepare(post('id_articolo')))['tot']; + $serial_entrata = $dbo->fetchOne('SELECT COUNT(id) AS `tot` FROM mg_prodotti WHERE serial='.prepare(post('serial')).' AND dir="entrata" AND id_articolo='.prepare(post('id_articolo')))['tot']; + $has_serial = $serial_entrata != $serial_uscita; + } else { + $has_serial = $dbo->fetchOne('SELECT id FROM mg_prodotti WHERE serial='.prepare(post('serial')).' AND dir="uscita" AND id_articolo='.prepare(post('id_articolo')).' AND (id_riga_documento IS NOT NULL OR id_riga_ordine IS NOT NULL OR id_riga_ddt IS NOT NULL)')['id']; + } echo json_encode($has_serial); diff --git a/modules/fatture/add_serial.php b/modules/fatture/add_serial.php index 121f494c3..02816d98a 100755 --- a/modules/fatture/add_serial.php +++ b/modules/fatture/add_serial.php @@ -19,6 +19,8 @@ include_once __DIR__.'/../../core.php'; +use Modules\DDT\DDT; + $module = Modules::get($id_module); // Controllo sulla direzione monetaria @@ -58,6 +60,8 @@ if (in_array($module['name'], ['Fatture di vendita', 'Fatture di acquisto'])) { $modulo = 'fat'; } elseif (in_array($module['name'], ['Ddt di vendita', 'Ddt di acquisto'])) { $modulo = 'ddt'; + $ddt = DDT::find($id_record); + $is_rientrabile = $database->fetchOne('SELECT * FROM `dt_causalet` WHERE `id` = '.prepare($ddt->idcausalet))['is_rientrabile']; } elseif (in_array($module['name'], ['Ordini cliente', 'Ordini fornitore'])) { $modulo = 'ord'; } else { @@ -107,8 +111,8 @@ if ($dir == 'entrata') { } echo ' -
- {[ "type": "text", "name": "serial[]", "class": "serial", "value": "'.$serials[$i].'"'.(!empty($res) ? ', "readonly": 1' : '').' ]}'; +
+ {[ "type": "text", "name": "serial[]", "class": "serial", "id": "serial_'.$i.'", "value": "'.$serials[$i].'"'.(!empty($res) ? ', "readonly": 1' : '').' ]}'; if (!empty($res)) { if (!empty($res[0]['id_riga_intervento'])) { @@ -133,6 +137,13 @@ if ($dir == 'entrata') { echo '
'; + if ($is_rientrabile) { + echo ' +
+ {[ "type": "select", "name": "select_serial_'.$i.'", "value": "'.implode(',', $serials).'", "values": "query=SELECT serial AS id, serial AS descrizione FROM mg_prodotti WHERE id_articolo = '.prepare($rs[0]['idarticolo']).' AND mg_prodotti.dir=\'entrata\' AND id=(SELECT MAX(id) FROM mg_prodotti AS prodotti WHERE prodotti.id_articolo=mg_prodotti.id_articolo AND prodotti.serial=mg_prodotti.serial)", "onchange": "aggiornaSerial('.$i.');"'.(!empty($res) ? ', "readonly": 1' : '').' ]} +
'; + } + if (($i + 1) % 3 == 0) { echo '
@@ -154,13 +165,18 @@ if ($dir == 'entrata') { '; }