]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/Order.pm
t/datev/datev_format_2018.t nutzt Dev create_gl_transaction
[mfinanz.git] / SL / Controller / Order.pm
index 47ab4e7de4f0f45de9fa9e22fa82a8f3fcb9f953..771b1606d8b31609ca0f2ac12d92c25eb22f913d 100644 (file)
@@ -26,6 +26,7 @@ use SL::Helper::CreatePDF qw(:all);
 use SL::Helper::PrintOptions;
 use SL::Helper::ShippedQty;
 use SL::Helper::UserPreferences::PositionsScrollbar;
+use SL::Helper::UserPreferences::UpdatePositions;
 
 use SL::Controller::Helper::GetModels;
 
@@ -40,7 +41,7 @@ use Sort::Naturally;
 use Rose::Object::MakeMethods::Generic
 (
  scalar => [ qw(item_ids_to_delete) ],
- 'scalar --get_set_init' => [ qw(order valid_types type cv p multi_items_models all_price_factors search_cvpartnumber) ],
+ 'scalar --get_set_init' => [ qw(order valid_types type cv p multi_items_models all_price_factors search_cvpartnumber show_update_button) ],
 );
 
 
@@ -790,11 +791,9 @@ sub action_add_item {
 
   my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
   my $row_as_html = $self->p->render('order/tabs/_row',
-                                     ITEM                => $item,
-                                     ID                  => $item_id,
-                                     TYPE                => $self->type,
-                                     ALL_PRICE_FACTORS   => $self->all_price_factors,
-                                     SEARCH_CVPARTNUMBER => $self->search_cvpartnumber,
+                                     ITEM => $item,
+                                     ID   => $item_id,
+                                     SELF => $self,
   );
 
   $self->js
@@ -818,11 +817,9 @@ sub action_add_item {
       $self->get_item_cvpartnumber($item);
       my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
       my $row_as_html = $self->p->render('order/tabs/_row',
-                                         ITEM                => $item,
-                                         ID                  => $item_id,
-                                         TYPE                => $self->type,
-                                         ALL_PRICE_FACTORS   => $self->all_price_factors,
-                                         SEARCH_CVPARTNUMBER => $self->search_cvpartnumber,
+                                         ITEM => $item,
+                                         ID   => $item_id,
+                                         SELF => $self,
       );
       $self->js
         ->append('#row_table_id', $row_as_html);
@@ -901,11 +898,9 @@ sub action_add_multi_items {
     $self->get_item_cvpartnumber($item);
     my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
     my $row_as_html = $self->p->render('order/tabs/_row',
-                                       ITEM                => $item,
-                                       ID                  => $item_id,
-                                       TYPE                => $self->type,
-                                       ALL_PRICE_FACTORS   => $self->all_price_factors,
-                                       SEARCH_CVPARTNUMBER => $self->search_cvpartnumber,
+                                       ITEM => $item,
+                                       ID   => $item_id,
+                                       SELF => $self,
     );
 
     $self->js->append('#row_table_id', $row_as_html);
@@ -1015,6 +1010,47 @@ sub action_load_second_rows {
   $self->js->render();
 }
 
+# update description, notes and sellprice from master data
+sub action_update_row_from_master_data {
+  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];
+
+    $item->description($item->part->description);
+    $item->longdescription($item->part->notes);
+
+    my $price_source = SL::PriceSource->new(record_item => $item, record => $self->order);
+
+    my $price_src;
+    if ($item->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);
+    } else {
+      $price_src = $price_source->best_price
+                 ? $price_source->best_price
+                 : $price_source->price_from_source("");
+      $price_src->price(0) if !$price_source->best_price;
+    }
+
+    $item->sellprice($price_src->price);
+    $item->active_price_source($price_src);
+
+    $self->js
+      ->run('kivi.Order.update_sellprice', $item_id, $item->sellprice_as_number)
+      ->val('.row_entry:has(#item_' . $item_id . ') [name = "order.orderitems[].description"]', $item->description)
+      ->val('.row_entry:has(#item_' . $item_id . ') [name = "order.orderitems[].longdescription"]', $item->longdescription);
+  }
+
+  $self->recalc();
+  $self->js_redisplay_line_values;
+  $self->js_redisplay_amounts_and_taxes;
+
+  $self->js->render();
+}
+
 sub js_load_second_row {
   my ($self, $item, $item_id, $do_parse) = @_;
 
@@ -1167,6 +1203,12 @@ sub init_search_cvpartnumber {
   return $search_cvpartnumber;
 }
 
+sub init_show_update_button {
+  my ($self) = @_;
+
+  !!SL::Helper::UserPreferences::UpdatePositions->new()->get_show_update_button();
+}
+
 sub init_p {
   SL::Presenter->get;
 }