]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/Order.pm
Auftrags-Controller: zweite Zeile laden mit Icons und alle zweiten Zeilen laden.
[mfinanz.git] / SL / Controller / Order.pm
index 741476603c49c3cfdd064537049b82c40fec424d..b11e364b9313e48fb6fc3b1f35f3bd1865bdd2ac 100644 (file)
@@ -425,6 +425,10 @@ sub action_add_item {
                    description => $assortment_item->part->description,
                  };
       my $item = _new_item($self->order, $attr);
                    description => $assortment_item->part->description,
                  };
       my $item = _new_item($self->order, $attr);
+
+      # set discount to 100% if item isn't supposed to be charged, overwriting any customer discount
+      $item->discount(1) unless $assortment_item->charge;
+
       $self->order->add_items( $item );
       $self->_recalc();
       my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
       $self->order->add_items( $item );
       $self->_recalc();
       my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
@@ -486,7 +490,22 @@ sub action_add_multi_items {
 
   my @items;
   foreach my $attr (@form_attr) {
 
   my @items;
   foreach my $attr (@form_attr) {
-    push @items, _new_item($self->order, $attr);
+    my $item = _new_item($self->order, $attr);
+    push @items, $item;
+    if ( $item->part->is_assortment ) {
+      foreach my $assortment_item ( @{$item->part->assortment_items} ) {
+        my $attr = { parts_id => $assortment_item->parts_id,
+                     qty      => $assortment_item->qty * $item->qty, # TODO $form_attr->{unit}
+                     unit     => $assortment_item->unit,
+                     description => $assortment_item->part->description,
+                   };
+        my $item = _new_item($self->order, $attr);
+
+        # set discount to 100% if item isn't supposed to be charged, overwriting any customer discount
+        $item->discount(1) unless $assortment_item->charge;
+        push @items, $assortment_item;
+      }
+    }
   }
   $self->order->add_items(@items);
 
   }
   $self->order->add_items(@items);
 
@@ -575,6 +594,43 @@ sub action_get_item_longdescription {
   $_[0]->render(\ $longdescription, { type => 'text' });
 }
 
   $_[0]->render(\ $longdescription, { type => 'text' });
 }
 
+# load the second row for one or more items (cvars only for now)
+#
+# This action gets the html code for all items second rows by rendering a template for
+# the second row and sets the html code via client js.
+sub action_load_second_rows {
+  my ($self) = @_;
+
+  foreach my $item_id (@{ $::form->{item_ids} }) {
+    my $idx  = first_index { $_ eq $item_id } @{ $::form->{orderitem_ids} };
+    my $item = $self->order->items_sorted->[$idx];
+
+    $self->_js_load_second_row($item, $item_id, 0);
+  }
+
+  $self->js->render();
+}
+
+sub _js_load_second_row {
+  my ($self, $item, $item_id, $do_parse) = @_;
+
+  if ($do_parse) {
+    # Parse values from form (they are formated while rendering (template)).
+    # Workaround to pre-parse number-cvars (parse_custom_variable_values does not parse number values).
+    # This parsing is not necessary at all, if we assure that the second row/cvars are only loaded once.
+    foreach my $var (@{ $item->cvars_by_config }) {
+      $var->unparsed_value($::form->parse_amount(\%::myconfig, $var->{__unparsed_value})) if ($var->config->type eq 'number' && exists($var->{__unparsed_value}));
+    }
+    $item->parse_custom_variable_values;
+  }
+
+  my $row_as_html = $self->p->render('order/tabs/_second_row', ITEM => $item);
+
+  $self->js
+    ->html('.row_entry:has(#item_' . $item_id . ') [name = "second_row"]', $row_as_html)
+    ->data('.row_entry:has(#item_' . $item_id . ') [name = "second_row"]', 'loaded', 1);
+}
+
 sub _js_redisplay_linetotals {
   my ($self) = @_;
 
 sub _js_redisplay_linetotals {
   my ($self) = @_;
 
@@ -829,7 +885,11 @@ sub _new_item {
   $item->unit($part->unit) if !$item->unit;
 
   my $price_src;
   $item->unit($part->unit) if !$item->unit;
 
   my $price_src;
-  if ($item->sellprice) {
+  if ( $part->is_assortment ) {
+    # add assortment items with price 0, as the components carry the price
+    $price_src = $price_source->price_from_source("");
+    $price_src->price(0);
+  } elsif ($item->sellprice) {
     $price_src = $price_source->price_from_source("");
     $price_src->price($item->sellprice);
   } else {
     $price_src = $price_source->price_from_source("");
     $price_src->price($item->sellprice);
   } else {
@@ -1266,15 +1326,6 @@ should be implemented.
 C<show_multi_items_dialog> does not use the currently inserted string for
 filtering.
 
 C<show_multi_items_dialog> does not use the currently inserted string for
 filtering.
 
-=item * Performance
-
-Rendering a 50 items order takes twice as long as the old code.
-
-90% of that is rendering the (hidden) second rows, and 50% of those again are
-checks for is_valid and C<INCLUDE> on the cvar input template.
-
-Suggestion: fetch second rows when asked for.
-
 =back
 
 =head1 AUTHOR
 =back
 
 =head1 AUTHOR