From 18a627a60525c399009c39b4e6ce7cf5ade46a87 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Sat, 20 Nov 2021 00:53:12 +0100 Subject: [PATCH] DeliveryOrder: serialize stock to yaml --- SL/Controller/DeliveryOrder.pm | 15 ++++++- js/kivi.DeliveryOrder.js | 32 +++++++++++++- .../webpages/delivery_order/stock_dialog.html | 43 ++++++++----------- 3 files changed, 64 insertions(+), 26 deletions(-) diff --git a/SL/Controller/DeliveryOrder.pm b/SL/Controller/DeliveryOrder.pm index 80a215566..42ee5d5ad 100644 --- a/SL/Controller/DeliveryOrder.pm +++ b/SL/Controller/DeliveryOrder.pm @@ -53,7 +53,8 @@ use Rose::Object::MakeMethods::Generic # safety -__PACKAGE__->run_before('check_auth'); +__PACKAGE__->run_before('check_auth', + except => [ qw(pack_stock_information) ]); __PACKAGE__->run_before('get_unalterable_data', only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_ap_transaction @@ -906,8 +907,20 @@ sub action_stock_in_out_dialog { part => $part, do_qty => $qty, do_unit => $unit, + delivered => $self->order->delivered, ); +} + +# we're using the old YAML based stock packing, but don't want to do this in +# the frontend so we're doing a tiny roundtrip to the backend, back the info in +# perl, serve it back to the frontend and store it in the DOM there +sub action_pack_stock_information { + my ($self) = @_; + + my $stock_info = $::form->{stock_info}; + my $yaml = SL::YAML::Dump($stock_info); + $self->render(\$yaml, { layout => 0, process => 0 }); } sub merge_stock_data { diff --git a/js/kivi.DeliveryOrder.js b/js/kivi.DeliveryOrder.js index f708413e9..d937a51ce 100644 --- a/js/kivi.DeliveryOrder.js +++ b/js/kivi.DeliveryOrder.js @@ -84,7 +84,7 @@ namespace('kivi.DeliveryOrder', function(ns) { $row.uniqueId(); kivi.popup_dialog({ - id: "stock_in_out", + id: "stock_in_out_dialog", url: "controller.pl?action=DeliveryOrder/stock_in_out_dialog", data: { id: $("#id").val(), @@ -100,6 +100,36 @@ namespace('kivi.DeliveryOrder', function(ns) { }); }; + ns.save_updated_stock = function() { + // stock information is saved in DOM as a yaml dump. + // we don't want to do this in javascript so we do a tiny roundtrip to the backend + + let data = []; + $("#stock-in-out-table tr.listrow").each((i,row) => { + data.push({ + qty: kivi.parse_amount($(row).find(".data-qty").val()), + warehouse_id: $(row).find(".data-warehouse-id").val(), + bin_id: $(row).find(".data-bin-id").val(), + chargenumber: $(row).find(".data-chargenumber").val(), + bestbefore: $(row).find(".data-bestbefore").val(), + unit: $(row).find(".data-unit").val(), + delivery_order_items_stock_id: $(row).find(".data-stock-id").val(), + }); + }); + + let row = $(".data-row").val(); + + $.post("controller.pl", kivi.serialize({ + action: "DeliveryOrder/pack_stock_information", + stock_info: data + }), + (data) => { + $("[name=stock_info_" + row + "]").val(data); + $("#stock_in_out_dialog").dialog("close"); + } + ); + }; + ns.print = function() { $('#print_options').dialog('close'); diff --git a/templates/webpages/delivery_order/stock_dialog.html b/templates/webpages/delivery_order/stock_dialog.html index 9fbeb6e72..40fa8556c 100644 --- a/templates/webpages/delivery_order/stock_dialog.html +++ b/templates/webpages/delivery_order/stock_dialog.html @@ -1,6 +1,7 @@ [%- USE T8 %] [%- USE HTML %] [%- USE LxERP %] +[%- USE L %] [%- IF delivered %] [%- SET RO = ' readonly' %] [%- END %] @@ -28,10 +29,10 @@ [% L.hidden_tag("parts_id", parts_id) %] [% L.hidden_tag("do_qty", do_qty) %] [% L.hidden_tag("do_unit", do_unit) %] - [% L.hidden_tag("row", row) %] + [% L.hidden_tag("row", row, class="data-row") %]

- +
@@ -60,43 +61,37 @@ [%- IF delivered %] - + [%- ELSE %] - + [% L.input_tag("qty", row.stock_qty ? LxERP.format_amount(row.stock_qty) + : (WHCONTENTS.size == 1) && (!row.stock_qty) ? LxERP.format_amount(do_qty) + : "", class="numeric data-qty", size="12") %] + [%- END %] + - - - - - [% IF INSTANCE_CONF.get_show_bestbefore %] - - [% END %] [%- END %]
  [% 'Warehouse' | $T8 %][% LxERP.format_amount(row.stock_qty) | html %][% row.stock_unit | html %] + [% row.stock_unit | html %] + [% L.hidden_tag("unit", row.stock_unit, class="data-unit") %] + [% row.available_qty | html %] - [% L.select_tag("unit_" _ loop.count, part.unit_obj.convertible_units, value_key="name", default=row.stock_unit) %] - [% L.select_tag("unit_" _ loop.count, part.unit_obj.convertible_units, value_key="name", default=row.stock_unit, class="data-unit") %] + [% L.hidden_tag("warehouse_id", row.warehouse_id, class="data-warehouse-id") %] + [% L.hidden_tag("bin_id", row.bin_id, class="data-bin-id") %] + [% L.hidden_tag("chargenumber", row.chargenumber, class="data-chargenumber") %] + [% L.hidden_tag("delivery_order_items_stock_id", row.delivery_order_items_stock_id, class="data-stock-id") %] + [% L.hidden_tag("bestbefore", row.bestbefore, class="data-bestbefore") IF INSTANCE_CONF.get_show_bestbefore %] +


-

- [%- IF !delivered %] - [% L.button_tag('kivi.DeliveryOrder.save_updated_stock()', 'Save') | $T8 %] - [%- END %] -

+

[% L.button_tag('kivi.DeliveryOrder.save_updated_stock()', LxERP.t8('Save')) IF !delivered %]

[%- END %] -- 2.20.1