From f06b1cc34c8aab704c999af0e43b819287d89fdc Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Mon, 6 Jul 2020 17:01:43 +0200 Subject: [PATCH] Fix sulla gestione dei seriali --- modules/interventi/actions.php | 11 ++--------- src/Database.php | 6 ++++-- update/2_4_16.sql | 6 ++++++ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/interventi/actions.php b/modules/interventi/actions.php index 521bb7f90..3bd0bdcf3 100755 --- a/modules/interventi/actions.php +++ b/modules/interventi/actions.php @@ -294,17 +294,10 @@ $riga = $intervento->getRiga($type, $id_riga); break; case 'add_serial': - $idriga = post('idriga'); - $idarticolo = post('idarticolo'); + $articolo = Articolo::find(post('idriga')); - $serials = (array) post('serial'); - foreach ($serials as $key => $value) { - if (empty($value)) { - unset($serials[$key]); - } - } + $articolo->serials = post('serial'); - $dbo->sync('mg_prodotti', ['id_riga_intervento' => $idriga, 'dir' => 'entrata', 'id_articolo' => $idarticolo], ['serial' => $serials]); aggiorna_sedi_movimenti('interventi', $id_record); break; diff --git a/src/Database.php b/src/Database.php index a1feb7304..862108884 100755 --- a/src/Database.php +++ b/src/Database.php @@ -619,9 +619,11 @@ class Database extends Util\Singleton $sync = array_unique((array) current($list)); if (!empty($field) && !empty($sync)) { - $conditions[$field] = $sync; + foreach ($sync as $element) { + $conditions[$field] = $element; - $this->delete($table, $conditions); + $this->delete($table, $conditions); + } } } diff --git a/update/2_4_16.sql b/update/2_4_16.sql index 3b6f30e9b..3b36d22d7 100644 --- a/update/2_4_16.sql +++ b/update/2_4_16.sql @@ -101,3 +101,9 @@ ALTER TABLE `co_righe_promemoria` ADD `id_dettaglio_fornitore` int(11) NULL, -- Aggiunta campo prezzo_vendita_ivato per gli Articoli ALTER TABLE `mg_articoli` ADD `prezzo_vendita_ivato` decimal(15,6) NOT NULL AFTER `prezzo_vendita`; UPDATE `mg_articoli` SET `prezzo_vendita_ivato` = `prezzo_vendita`; + +-- Aggiornamento ID per gli articoli degli Interventi +ALTER TABLE `mg_prodotti` DROP FOREIGN KEY `mg_prodotti_ibfk_4`; +UPDATE mg_prodotti SET mg_prodotti.id_riga_intervento = NULL WHERE mg_prodotti.id_riga_intervento NOT IN (SELECT old_id FROM in_righe_interventi); +UPDATE mg_prodotti SET mg_prodotti.id_riga_intervento = (SELECT id FROM in_righe_interventi WHERE mg_prodotti.id_riga_intervento = in_righe_interventi.old_id); +ALTER TABLE `mg_prodotti` ADD FOREIGN KEY (`id_riga_intervento`) REFERENCES `in_righe_interventi`(`id`) ON DELETE CASCADE;