From: Jan Büren Date: Mon, 5 Jan 2015 20:45:28 +0000 (+0100) Subject: delivery_order_items_stock persistent machen Teil 2 X-Git-Tag: release-3.2.0beta~102 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=2b32359da2778b424667ab9e2c27438bf1ccd980;p=kivitendo-erp.git delivery_order_items_stock persistent machen Teil 2 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) --- 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();