From 472c88889c3a076cc51519187491636d72b391d7 Mon Sep 17 00:00:00 2001 From: MatteoPistorello Date: Fri, 12 Feb 2021 17:30:34 +0100 Subject: [PATCH] Gestione serial in caso di nota di credito --- modules/fatture/actions.php | 1 - modules/fatture/add_serial.php | 8 +------- modules/fatture/crea_documento.php | 1 + src/Common/Components/Article.php | 13 ++++++++++++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/modules/fatture/actions.php b/modules/fatture/actions.php index d5f79f054..add1481da 100755 --- a/modules/fatture/actions.php +++ b/modules/fatture/actions.php @@ -804,7 +804,6 @@ switch (post('op')) { $serials = is_array(post('serial')[$riga->id]) ? post('serial')[$riga->id] : []; $copia->serials = $serials; - $riga->removeSerials($serials); } $copia->save(); diff --git a/modules/fatture/add_serial.php b/modules/fatture/add_serial.php index 8b5c1912b..9f59e8378 100755 --- a/modules/fatture/add_serial.php +++ b/modules/fatture/add_serial.php @@ -86,16 +86,10 @@ $info = $dbo->fetchArray('SELECT * FROM mg_prodotti WHERE serial IS NOT NULL AND $serials = array_column($info, 'serial'); if ($dir == 'entrata') { - $in = []; - foreach ($serials as $value) { - $in[] = prepare($value); - } - $in = implode(',', $in); - echo '
- {[ "type": "select", "label": "'.tr('Serial').'", "name": "serial[]", "multiple": 1, "value": "'.implode(',', $serials).'", "values": "query=SELECT DISTINCT serial AS id, serial AS descrizione FROM mg_prodotti WHERE dir=\'uscita\' AND mg_prodotti.id_articolo = '.prepare($rs[0]['idarticolo']).' AND serial NOT IN (SELECT serial FROM mg_prodotti WHERE dir=\'entrata\' AND serial NOT IN (SELECT serial FROM mg_prodotti WHERE '.$riga.' = \''.$idriga.'\'))'.(!empty($in) ? ' OR serial IN ('.$in.')' : '').'", "extra": "data-maximum=\"'.intval($rs[0]['qta']).'\"" ]} + {[ "type": "select", "label": "'.tr('Serial').'", "name": "serial[]", "multiple": 1, "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=\'uscita\' AND id=(SELECT MAX(id) FROM mg_prodotti AS prodotti WHERE prodotti.id_articolo=mg_prodotti.id_articolo AND prodotti.serial=mg_prodotti.serial)" ]}
'; } else { diff --git a/modules/fatture/crea_documento.php b/modules/fatture/crea_documento.php index 8e1cdf59b..e1d0cb10b 100755 --- a/modules/fatture/crea_documento.php +++ b/modules/fatture/crea_documento.php @@ -27,6 +27,7 @@ $tipo_documento_finale = Fattura::class; $options = [ 'type' => 'nota_credito', 'op' => 'nota_credito', + 'serials' => true, 'module' => 'Fatture di vendita', 'documento' => $documento, 'tipo_documento_finale' => $tipo_documento_finale, diff --git a/src/Common/Components/Article.php b/src/Common/Components/Article.php index 30c0be7e9..eaa88a5c8 100755 --- a/src/Common/Components/Article.php +++ b/src/Common/Components/Article.php @@ -120,11 +120,22 @@ abstract class Article extends Accounting return; } + // Inversione di movimento nei seriali in caso di nota di credito + if($this->getDocument()->isNota()){ + if($this->getDirection()=='uscita'){ + $dir = 'entrata'; + } else{ + $dir = 'uscita'; + } + } else { + $dir = $this->getDirection(); + } + $serials = array_clean($serials); database()->sync('mg_prodotti', [ 'id_riga_'.$this->serialRowID => $this->id, - 'dir' => $this->getDirection(), + 'dir' => $dir, 'id_articolo' => $this->idarticolo, ], [ 'serial' => $serials,