From: Jan Büren Date: Tue, 6 Jan 2015 08:54:36 +0000 (+0100) Subject: delivery_order_items_stock persistent machen Teil 3 X-Git-Tag: release-3.2.0beta~101 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=5f7cab519820f9d5d7bbad3ba32271ef9995d78e;p=kivitendo-erp.git delivery_order_items_stock persistent machen Teil 3 Testfall (Einkauf-Lieferschein): Update drücken (alles wird erneuert) => i.O. (alle ids werden gelöscht) Position löschen mit schon ausgewählten stock_items => i.O. (keine verwaisten dois) Stichproben: Verkaufs-LS als neu speichern i.O. Einkaufs-LS mittlere Position löschen (mit und ohne dois) i.O. Einkaufs-LS E-Mail-Knopf statt Speichern i.O. Einkaufs-LS Rechnung (keine hiddens doi!) i.O. Einkaufs-LS mit dois Löschen i.O. (keine verwaisten doi oder dois) --- diff --git a/SL/DO.pm b/SL/DO.pm index 2e05f1d29..469d36592 100644 --- a/SL/DO.pm +++ b/SL/DO.pm @@ -386,18 +386,10 @@ SQL dbh => $dbh); } - # search for orphaned doi - $query = sprintf 'SELECT id FROM delivery_order_items WHERE delivery_order_id = ? AND NOT id IN (%s)', join ', ', ("?") x scalar @processed_doi; - @values = (conv_i($form->{id}), map { conv_i($_) } @processed_doi); - my @orphaned_ids = map { $_->{id} } selectall_hashref_query($form, $dbh, $query, @values); - if (scalar @orphaned_ids) { - # clean up delivery_order_items - $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 + # 1. search for orphaned dois; processed_dois may be empty (no transfer) TODO: be supersafe and alter same statement for doi and oi $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; + (select id from delivery_order_items where delivery_order_id = ?)'; + $query .= sprintf ' AND NOT id IN (%s)', join ', ', ("?") x scalar @processed_dois if (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) { @@ -405,6 +397,15 @@ SQL $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); } + # 2. search for orphaned doi + $query = sprintf 'SELECT id FROM delivery_order_items WHERE delivery_order_id = ? AND NOT id IN (%s)', join ', ', ("?") x scalar @processed_doi; + @values = (conv_i($form->{id}), map { conv_i($_) } @processed_doi); + my @orphaned_ids = map { $_->{id} } selectall_hashref_query($form, $dbh, $query, @values); + if (scalar @orphaned_ids) { + # clean up delivery_order_items + $query = sprintf 'DELETE FROM delivery_order_items WHERE id IN (%s)', join ', ', ("?") x scalar @orphaned_ids; + do_query($form, $dbh, $query, @orphaned_ids); + } $h_item->finish(); $h_item_stock->finish(); diff --git a/bin/mozilla/do.pl b/bin/mozilla/do.pl index 69854e2b7..9bca5a785 100644 --- a/bin/mozilla/do.pl +++ b/bin/mozilla/do.pl @@ -1089,7 +1089,8 @@ sub update_stock_in { foreach my $i (1..$form->{rowcount}) { $form->{"qty_$i"} = $form->parse_amount(\%myconfig, $form->{"qty_$i"}); - push @{ $stock_info }, { map { $_ => $form->{"${_}_${i}"} } qw(warehouse_id bin_id chargenumber bestbefore qty unit) }; + push @{ $stock_info }, { map { $_ => $form->{"${_}_${i}"} } qw(warehouse_id bin_id chargenumber + bestbefore qty unit delivery_order_items_stock_id) }; } display_stock_in_form($stock_info);