Listenpreis in Belegen u. Ausdruck richtig formatieren und nicht mehr parsen.
[kivitendo-erp.git] / bin / mozilla / io.pl
index 4a3805d..c511893 100644 (file)
@@ -420,8 +420,6 @@ sub display_row {
                    $locale->text('EK'), $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces) }
       if $form->{"id_$i"} && ($form->{type} =~ /^sales_/ ||  $form->{type} =~ /invoice/ || $form->{type} =~ /^credit_note$/ ) && !$is_delivery_order;
 
-    $form->{"listprice_$i"} = $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2)
-      if $form->{"id_$i"} && ($form->{type} =~ /^sales_/ ||  $form->{type} =~ /invoice/) ;
 # / marge calculations ending
 
 # Calculate total weight
@@ -557,7 +555,7 @@ sub item_selected {
   }
 
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-    qw(sellprice listprice weight);
+    qw(sellprice weight);
 
   if ( $mode eq 'IC' ) {
     # assembly mode:
@@ -579,101 +577,98 @@ sub item_selected {
 
     delete $form->{item_list};
 
-  if ($mode eq 'IS') {
-    IS->retrieve_item(\%myconfig, \%$form);
-  } elsif ($mode eq 'IR') {
-    IR->retrieve_item(\%myconfig, \%$form);
-  } elsif ($mode eq 'IC') {
-    IC->assembly_item(\%myconfig, \%$form);
-  } else {
-    croak "Invalid item selection mode '${mode}'";
-  }
+    if ($mode eq 'IS') {
+      IS->retrieve_item(\%myconfig, \%$form);
+    } elsif ($mode eq 'IR') {
+      IR->retrieve_item(\%myconfig, \%$form);
+    } elsif ($mode eq 'IC') {
+      IC->assembly_item(\%myconfig, \%$form);
+    } else {
+      croak "Invalid item selection mode '${mode}'";
+    }
 
-  my $new_item = $form->{item_list}->[0] || croak "No item found for mode '${mode}' and ID '${id}'";
+    my $new_item = $form->{item_list}->[0] || croak "No item found for mode '${mode}' and ID '${id}'";
 
-  # if there was a price entered, override it
-  my $sellprice;
-  unless ( $mode eq 'IC' ) {
-    $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
-  };
+    # if there was a price entered, override it
+    my $sellprice;
+    unless ( $mode eq 'IC' ) {
+      $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
+    };
 
-  my @new_fields =
-    qw(id partnumber description sellprice listprice inventory_accno
-       income_accno expense_accno bin unit weight assembly taxaccounts
-       partsgroup formel longdescription not_discountable partnotes lastcost
-       price_factor_id price_factor);
+    my @new_fields =
+        qw(id partnumber description sellprice listprice inventory_accno
+           income_accno expense_accno bin unit weight assembly taxaccounts
+           partsgroup formel longdescription not_discountable partnotes lastcost
+           price_factor_id price_factor);
 
-  my $ic_cvar_configs = CVar->get_configs(module => 'IC');
-  push @new_fields, map { "ic_cvar_$_->{name}" } @{ $ic_cvar_configs };
+    my $ic_cvar_configs = CVar->get_configs(module => 'IC');
+    push @new_fields, map { "ic_cvar_$_->{name}" } @{ $ic_cvar_configs };
 
-  map { $form->{"${_}_$i"} = $new_item->{$_} } @new_fields;
+    map { $form->{"${_}_$i"} = $new_item->{$_} } @new_fields;
 
-  if (my $record = _make_record()) {
-    my $price_source = SL::PriceSource->new(record_item => $record->items->[$i-1], record => $record);
-    my $best_price   = $price_source->best_price;
+    if (my $record = _make_record()) {
+      my $price_source = SL::PriceSource->new(record_item => $record->items->[$i-1], record => $record);
+      my $best_price   = $price_source->best_price;
 
-    if ($best_price) {
-      $::form->{"sellprice_$i"}           = $best_price->price;
-      $::form->{"active_price_source_$i"} = $best_price->source;
-    }
+      if ($best_price) {
+        $::form->{"sellprice_$i"}           = $best_price->price;
+        $::form->{"active_price_source_$i"} = $best_price->source;
+      }
 
-    my $best_discount = $price_source->best_discount;
+      my $best_discount = $price_source->best_discount;
 
-    if ($best_discount) {
-      $::form->{"discount_$i"}               = $best_discount->discount;
-      $::form->{"active_discount_source_$i"} = $best_discount->source;
+      if ($best_discount) {
+        $::form->{"discount_$i"}               = $best_discount->discount;
+        $::form->{"active_discount_source_$i"} = $best_discount->source;
+      }
     }
-  }
 
-  $form->{"marge_price_factor_$i"} = $new_item->{price_factor};
+    $form->{"marge_price_factor_$i"} = $new_item->{price_factor};
 
-  if ($form->{"part_payment_id_$i"} ne "") {
-    $form->{payment_id} = $form->{"part_payment_id_$i"};
-  }
+    if ($form->{"part_payment_id_$i"} ne "") {
+      $form->{payment_id} = $form->{"part_payment_id_$i"};
+    }
 
-  my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
-  $dec           = length $dec;
-  my $decimalplaces = ($dec > 2) ? $dec : 2;
+    my ($dec)         = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
+    $dec              = length $dec;
+    my $decimalplaces = ($dec > 2) ? $dec : 2;
 
-  if ($sellprice) {
-    $form->{"sellprice_$i"} = $sellprice;
-  } else {
+    if ($sellprice) {
+      $form->{"sellprice_$i"} = $sellprice;
+    } else {
 
-    # if there is an exchange rate adjust sellprice
-    if (($form->{exchangerate} * 1) != 0) {
-      $form->{"sellprice_$i"} /= $form->{exchangerate};
-      $form->{"sellprice_$i"} =
-        $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
+      # if there is an exchange rate adjust sellprice
+      if (($form->{exchangerate} * 1) != 0) {
+        $form->{"sellprice_$i"} /= $form->{exchangerate};
+        $form->{"sellprice_$i"} =
+            $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
+      }
     }
-  }
 
-  # at this stage qty of newly added part needs to be have been parsed
-  $form->{weight}    += ($form->{"weight_$i"} * $form->{"qty_$i"});
+    # at this stage qty of newly added part needs to be have been parsed
+    $form->{weight}    += ($form->{"weight_$i"} * $form->{"qty_$i"});
 
-  if ($form->{"not_discountable_$i"}) {
-    $form->{"discount_$i"} = 0;
-  }
+    if ($form->{"not_discountable_$i"}) {
+      $form->{"discount_$i"} = 0;
+    }
 
-  my $amount =
-    $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
-    $form->{"qty_$i"};
-  map { $form->{"${_}_base"} += $amount }
-    (split / /, $form->{"taxaccounts_$i"});
-  map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /,
-    $form->{"taxaccounts_$i"}
-    if !$form->{taxincluded};
+    my $amount =
+        $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"}) * $form->{"qty_$i"};
+    map { $form->{"${_}_base"} += $amount }                         (split / /, $form->{"taxaccounts_$i"});
+    map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
 
-  $form->{creditremaining} -= $amount;
+    $form->{creditremaining} -= $amount;
 
-  $form->{"runningnumber_$i"} = $i;
+    $form->{"runningnumber_$i"} = $i;
 
-  # format amounts
-  map {
-    $form->{"${_}_$i"} =
-      $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
-  } qw(sellprice listprice lastcost qty) if $form->{item} ne 'assembly';
+    # format amounts
+    map {
+      $form->{"${_}_$i"} =
+          $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
+    } qw(sellprice lastcost qty) if $form->{item} ne 'assembly';
+    $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100.0) if $form->{item} ne 'assembly';
 
-  delete $form->{nextsub};
+    delete $form->{nextsub};
 
   }
 
@@ -731,7 +726,7 @@ sub check_form {
     #$form->{sellprice} = 0;
     $form->{weight}    = 0;
     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
-      qw(listprice sellprice rop stock);
+      qw(sellprice rop stock);
 
     my @flds = qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup lastcost);
 
@@ -937,7 +932,7 @@ sub order {
   for my $i (1 .. $form->{rowcount}) {
     map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"})
             if ($form->{"${_}_${i}"}) }
-        qw(ship qty sellprice listprice basefactor discount));
+        qw(ship qty sellprice basefactor discount));
     $form->{"converted_from_invoice_id_$i"} = delete $form->{"invoice_id_$i"};
   }
 
@@ -1005,7 +1000,7 @@ sub quotation {
     map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
                                                      $form->{"${_}_${i}"})
             if ($form->{"${_}_${i}"}) }
-        qw(ship qty sellprice listprice basefactor discount lastcost));
+        qw(ship qty sellprice basefactor discount lastcost));
   }
 
   &prepare_order;
@@ -1388,7 +1383,7 @@ sub print_form {
   }
 
   $form->{TEMPLATE_DRIVER_OPTIONS} = { };
-  if (any { $form->{type} eq $_ } qw(sales_quotation sales_order sales_delivery_order invoice request_quotation purchase_order purchase_delivery_order)) {
+  if (any { $form->{type} eq $_ } qw(sales_quotation sales_order sales_delivery_order invoice request_quotation purchase_order purchase_delivery_order credit_note)) {
     $form->{TEMPLATE_DRIVER_OPTIONS}->{variable_content_types} = {
       longdescription => 'html',
       partnotes       => 'html',
@@ -1830,8 +1825,7 @@ sub _update_part_information {
 
   my $form     = $main::form;
 
-  my %part_information = IC->get_basic_part_info('id'        => [ grep { $_ } map { $form->{"id_${_}"} } (1..$form->{rowcount}) ],
-                                                 'vendor_id' => $form->{vendor_id});
+  my %part_information = IC->get_basic_part_info('id' => [ grep { $_ } map { $form->{"id_${_}"} } (1..$form->{rowcount}) ]);
 
   $form->{PART_INFORMATION} = \%part_information;