From 2b32359da2778b424667ab9e2c27438bf1ccd980 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Mon, 5 Jan 2015 21:45:28 +0100 Subject: [PATCH] delivery_order_items_stock persistent machen Teil 2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Testfall: Mittlere Position in stock_in/out_form löschen => i.O. Update drücken (alles wird erneuert) => n.i.O. (alle ids werden gelöscht) --- SL/DO.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/SL/DO.pm b/SL/DO.pm index 57e971ecb..2e05f1d29 100644 --- a/SL/DO.pm +++ b/SL/DO.pm @@ -373,6 +373,7 @@ SQL conv_i($sinfo->{bin_id}), $sinfo->{chargenumber}, conv_date($sinfo->{bestbefore}), conv_i($sinfo->{"delivery_order_items_stock_id"})); do_statement($form, $h_item_stock, $q_item_stock, @values); + push @processed_dois, $sinfo->{"delivery_order_items_stock_id"}; } CVar->save_custom_variables(module => 'IC', @@ -394,6 +395,16 @@ SQL $query = sprintf 'DELETE FROM delivery_order_items WHERE id IN (%s)', join ', ', ("?") x scalar @orphaned_ids; do_query($form, $dbh, $query, @orphaned_ids); } + # search for orphaned dois + $query = sprintf 'SELECT id FROM delivery_order_items_stock WHERE delivery_order_item_id in + (select id from delivery_order_items where delivery_order_id = ?) AND NOT id IN (%s)', join ', ', ("?") x scalar @processed_dois; + @values = (conv_i($form->{id}), map { conv_i($_) } @processed_dois); + my @orphaned_dois_ids = map { $_->{id} } selectall_hashref_query($form, $dbh, $query, @values); + if (scalar @orphaned_dois_ids) { + # clean up delivery_order_items_stock + $query = sprintf 'DELETE FROM delivery_order_items_stock WHERE id IN (%s)', join ', ', ("?") x scalar @orphaned_dois_ids; + do_query($form, $dbh, $query, @orphaned_dois_ids); + } $h_item->finish(); $h_item_stock->finish(); -- 2.20.1