Gestione serial in caso di nota di credito

This commit is contained in:
MatteoPistorello 2021-02-12 17:30:34 +01:00
parent 382e85cc6c
commit 472c88889c
4 changed files with 14 additions and 9 deletions

View File

@ -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();

View File

@ -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 '
<div class="row">
<div class="col-md-12">
{[ "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)" ]}
</div>
</div>';
} else {

View File

@ -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,

View File

@ -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,