]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/DeliveryOrder.pm
locales typo
[mfinanz.git] / SL / Controller / DeliveryOrder.pm
index 547e3e2a082349f5d859798fa93e0c9f401de3b2..80a215566a9f15f77fd7211d84b4b3106ff1366f 100644 (file)
@@ -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;
@@ -407,7 +407,7 @@ sub action_save_and_show_email_dialog {
                                   email_form  => $email_form,
                                   show_bcc    => $::auth->assert('email_bcc', 'may fail'),
                                   FILES       => \%files,
-                                  is_customer => $self->cv eq 'customer',
+                                  is_customer => $self->type_data->is_customer,
                                   ALL_EMPLOYEES => $self->{all_employees},
   );
 
@@ -665,6 +665,7 @@ sub action_add_item {
                                      ITEM => $item,
                                      ID   => $item_id,
                                      SELF => $self,
+                                     in_out => $self->type_data->transfer,
   );
 
   if ($::form->{insert_before_item_id}) {
@@ -752,6 +753,7 @@ sub action_add_multi_items {
                                        ITEM => $item,
                                        ID   => $item_id,
                                        SELF => $self,
+                                       in_out => $self->type_data->transfer,
     );
 
     if ($::form->{insert_before_item_id}) {
@@ -884,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
@@ -1637,7 +1692,7 @@ sub pre_render {
                                                 } } @all_objects;
   }
 
-  $self->{template_args}{inout} = $self->type_data->properties('transfer');
+  $self->{template_args}{in_out} = $self->type_data->transfer;
 
   $self->get_item_cvpartnumber($_) for @{$self->order->items_sorted};
 
@@ -2007,7 +2062,7 @@ sub calculate_stock_in_out {
 
   return "" if !$item->part || !$item->part->unit || !$item->unit;
 
-  my $in_out   = $self->type_data->properties("transfer");
+  my $in_out   = $self->type_data->transfer;
 
   my $do_qty   = $item->qty;
   my $sum      = sum0 map {