From 9ef0dcd3d48a961e72e96f98956ac6938b7bd323 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Mon, 15 Nov 2021 02:20:41 +0100 Subject: [PATCH] DeliveryOrder: erste Version Lager-Dialog --- SL/Controller/DeliveryOrder.pm | 55 ++++++++- js/kivi.DeliveryOrder.js | 22 ++++ .../webpages/delivery_order/stock_dialog.html | 104 ++++++++++++++++++ .../webpages/delivery_order/tabs/_row.html | 3 +- 4 files changed, 181 insertions(+), 3 deletions(-) create mode 100644 templates/webpages/delivery_order/stock_dialog.html diff --git a/SL/Controller/DeliveryOrder.pm b/SL/Controller/DeliveryOrder.pm index 91af197da..80a215566 100644 --- a/SL/Controller/DeliveryOrder.pm +++ b/SL/Controller/DeliveryOrder.pm @@ -4,7 +4,7 @@ use strict; use parent qw(SL::Controller::Base); use SL::Helper::Flash qw(flash_later); -use SL::Helper::Number qw(_format_number_units); +use SL::Helper::Number qw(_format_number_units _parse_number); use SL::Presenter::Tag qw(select_tag hidden_tag div_tag); use SL::Locale::String qw(t8); use SL::SessionFile::Random; @@ -886,6 +886,59 @@ sub action_return_from_create_part { } +sub action_stock_in_out_dialog { + my ($self) = @_; + + my $part = SL::DB::Part->load_cached($::form->{parts_id}) or die "need parts_id"; + my $stock = $::form->{stock}; + my $unit = $::form->{unit}; + my $qty = _parse_number($::form->{qty_as_number}); + + my $inout = $self->type_data->transfer; + + my @contents = DO->get_item_availability(parts_id => $part->id); + my $stock_info = DO->unpack_stock_information(packed => $stock); + + $self->merge_stock_data($stock_info, \@contents, $part); + + $self->render("delivery_order/stock_dialog", { layout => 0 }, + WHCONTENTS => $self->order->delivered ? $stock_info : \@contents, + part => $part, + do_qty => $qty, + do_unit => $unit, + ); + +} + +sub merge_stock_data { + my ($self, $stock_info, $contents, $part) = @_; + # TODO rewrite to mapping + + if (!$self->order->delivered) { + for my $row (@$contents) { + $row->{available_qty} = _format_number_units($row->{qty}, $row->{unit}, $part->unit); + + for my $sinfo (@{ $stock_info }) { + next if $row->{bin_id} != $sinfo->{bin_id} || + $row->{warehouse_id} != $sinfo->{warehouse_id} || + $row->{chargenumber} ne $sinfo->{chargenumber} || + $row->{bestbefore} ne $sinfo->{bestbefore}; + + $row->{"stock_$_"} = $sinfo->{$_} + for qw(qty unit error delivery_order_items_stock_id); + } + } + + } else { + for my $sinfo (@{ $stock_info }) { + my $bin = SL::DB::Bin->load_cached($sinfo->{bin_id}); + $sinfo->{warehouse_description} = $bin->warehouse->description; + $sinfo->{bin_description} = $bin->escription; + map { $sinfo->{"stock_$_"} = $sinfo->{$_} } qw(qty unit); + } + } +} + # load the second row for one or more items # # This action gets the html code for all items second rows by rendering a template for diff --git a/js/kivi.DeliveryOrder.js b/js/kivi.DeliveryOrder.js index 1552616e8..f708413e9 100644 --- a/js/kivi.DeliveryOrder.js +++ b/js/kivi.DeliveryOrder.js @@ -78,6 +78,28 @@ namespace('kivi.DeliveryOrder', function(ns) { }); }; + ns.open_stock_in_out_dialog = function(clicked, in_out) { + var $row = $(clicked).parents("tbody").first(); + var id = $row.find('[name="orderitem_ids[+]"]').val(); + $row.uniqueId(); + + kivi.popup_dialog({ + id: "stock_in_out", + url: "controller.pl?action=DeliveryOrder/stock_in_out_dialog", + data: { + id: $("#id").val(), + type: $("#type").val(), + parts_id: $row.find("[name$=parts_id]").val(), + unit: $row.find("[name$=unit]").val(), + qty_as_number: $("qty_" + id).val(), + stock: $("stock_" + id).val(), + item_id: id, + row: $row.attr("id"), + }, + dialog: { title: kivi.t8('Transfer stock') } + }); + }; + 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 new file mode 100644 index 000000000..9fbeb6e72 --- /dev/null +++ b/templates/webpages/delivery_order/stock_dialog.html @@ -0,0 +1,104 @@ +[%- USE T8 %] +[%- USE HTML %] +[%- USE LxERP %] + [%- IF delivered %] + [%- SET RO = ' readonly' %] + [%- END %] + + + + + + + + + + + + + + +
[% 'Part Number' | $T8 %][% part.partnumber | html %]
[% 'Description' | $T8 %][% part.description | html %]
[% 'Qty according to delivery order' | $T8 %][% LxERP.format_amount(do_qty) %] [% do_unit | html %]
+ + [%- UNLESS WHCONTENTS.size %] +

[% 'There are no items in stock.' | $T8 %]

+ [%- ELSE %] + + [% L.hidden_tag("in_out", in_out) %] + [% 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) %] + +

+ + + + + + + [% IF INSTANCE_CONF.get_show_bestbefore %] + + [% END %] + [%- UNLESS delivered %] + + [%- END %] + + + + + [%- FOREACH row = WHCONTENTS %] + + + + + + [% IF INSTANCE_CONF.get_show_bestbefore %] + + [% END %] + + [%- IF delivered %] + + + + + [%- ELSE %] + + + + + + [%- END %] + + + + + + + [% IF INSTANCE_CONF.get_show_bestbefore %] + + [% END %] + [%- END %] +
 [% 'Warehouse' | $T8 %][% 'Bin' | $T8 %][% 'Charge Number' | $T8 %][% 'Best Before' | $T8 %][% 'Available qty' | $T8 %][% 'Qty' | $T8 %][% 'Unit' | $T8 %]
[% loop.count %][% row.warehousedescription | html %][% row.bindescription | html %][% row.chargenumber | html %][% row.bestbefore | html %][% LxERP.format_amount(row.stock_qty) | html %][% row.stock_unit | html %][% row.available_qty | html %] + [% L.select_tag("unit_" _ loop.count, part.unit_obj.convertible_units, value_key="name", default=row.stock_unit) %] +
+

+ +
+ +

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

+ + [%- END %] + + + diff --git a/templates/webpages/delivery_order/tabs/_row.html b/templates/webpages/delivery_order/tabs/_row.html index 9361f207f..d6aebb949 100644 --- a/templates/webpages/delivery_order/tabs/_row.html +++ b/templates/webpages/delivery_order/tabs/_row.html @@ -88,8 +88,7 @@ [% SELF.calculate_stock_in_out(ITEM) %] - - + [% P.button_tag("kivi.DeliveryOrder.open_stock_in_out_dialog(this, '" _ in_out _"')", "?") %] -- 2.20.1