login nicht aus $::form nehmen. Teil 1
[kivitendo-erp.git] / bin / mozilla / vk.pl
index a14a051..a6476d9 100644 (file)
@@ -110,24 +110,10 @@ sub invoice_transactions {
   };
 
   if ( $form->{customer} =~ /--/ ) {
-    # field data comes from dropdown box
-    ($form->{customername}, $form->{customer_id}) = split(/--/, $form->{customer});
-  } elsif ($form->{customer}) {
-
-    # a value was added in the input box, we only want to filter for one
-    # customer, so check that a unique customer can be found
-
-    # check_name is executed with no_select => 1, if the result isn't unique
-    # quit with an error message, the user has to enter a new name
-
-    # Without no_select selecting a customer causes an update which doesn't
-    # return anything, which is the reason for this workaround
-
-    &check_name('customer', no_select => 1);
-
-    # $form->{customer_id} was already set by check_name
-    $form->{customername} = $form->{customer};
-  };
+    # Felddaten kommen aus Dropdownbox
+    my $dummy;
+    ($dummy, $form->{customer_id}) = split(/--/, $form->{customer});
+  }
   # if $form->{customer} is empty nothing further happens here
 
   # test for decimalplaces or set to default of 2
@@ -168,7 +154,7 @@ sub invoice_transactions {
   # pass hidden variables for pdf/csv export
   # first with l_ to determine which columns to show
   # then with the options for headings (such as transdatefrom, partnumber, ...)
-  my @hidden_variables  = (qw(l_headers_mainsort l_headers_subsort l_subtotal_mainsort l_subtotal_subsort l_total l_parts l_customername l_customernumber transdatefrom transdateto decimalplaces customer customername customer_id department partnumber partsgroup country business description project_id customernumber salesman employee salesman_id employee_id business_id partsgroup_id mainsort subsort),
+  my @hidden_variables  = (qw(l_headers_mainsort l_headers_subsort l_subtotal_mainsort l_subtotal_subsort l_total l_parts l_customername l_customernumber transdatefrom transdateto decimalplaces customer customer_id department partnumber partsgroup country business description project_id customernumber salesman employee salesman_id employee_id business_id partsgroup_id mainsort subsort),
       "$form->{db}number",
       map({ "cvar_$_->{name}" } @searchable_custom_variables),
       map { "l_$_" } @columns
@@ -222,7 +208,7 @@ sub invoice_transactions {
   my @options;
 
   push @options, $locale->text('Description')             . " : $form->{description}"                                                       if $form->{description};
-  push @options, $locale->text('Customer')                . " : $form->{customername}"                                                      if $form->{customer};
+  push @options, $locale->text('Customer')                . " : $form->{customer}"                                                          if $form->{customer};
   push @options, $locale->text('Customer Number')         . " : $form->{customernumber}"                                                    if $form->{customernumber};
   # TODO: only customer id is passed
   push @options, $locale->text('Department')              . " : " . (split /--/, $form->{department})[0]                                    if $form->{department};
@@ -314,7 +300,7 @@ sub invoice_transactions {
     # stored seperately).  However, for fxsellprice this method only works when
     # the tax is not included, because otherwise fxsellprice includes the tax
     # and there is no simple way to extract the tax rate of the article from
-    # the big query. 
+    # the big query.
     #
     # Using fxsellprice is potentially more accurate (certainly for tax
     # included), because we can use the same method as is used while the
@@ -329,11 +315,16 @@ sub invoice_transactions {
     # sellprice_total_including_tax = qty * fxsellprice * (1-discount) /  price_factor * exchangerate
     # $ar->{sellprice_total_including_tax} =  $form->round_amount( $ar->{qty} * ( $ar->{fxsellprice} * ( 1 - $ar->{discount} ) ) / $ar->{price_factor}, $form->{"decimalplaces"});
 
-    $ar->{sellprice}       = $ar->{sellprice}  / $ar->{price_factor} / $basefactor; 
-    $ar->{sellprice_total} = $form->round_amount( $ar->{qty} * $ar->{sellprice} / $ar->{price_factor} , $form->{"decimalplaces"});
+    my $sellprice_orig     = $ar->{sellprice};
+    my $qty_orig           = $ar->{qty};
+    # adjust sellprice so it reflects the unit sellprice according to price_factor and basefactor
+    $ar->{sellprice}       = $ar->{sellprice}  / $ar->{price_factor} / $basefactor;
+    # for sellprice_total use the original amounts
+    $ar->{sellprice_total} = $form->round_amount( $qty_orig * $sellprice_orig / $ar->{price_factor}, $form->{"decimalplaces"});
 
+    my $lastcost_orig      = $ar->{lastcost};
     $ar->{lastcost}        = $ar->{lastcost}   / $ar->{price_factor} / $basefactor;
-    $ar->{lastcost_total}  = $form->round_amount( $ar->{qty} * $ar->{lastcost} / $ar->{price_factor}, $form->{"decimalplaces"});
+    $ar->{lastcost_total}  = $form->round_amount( $qty_orig * $lastcost_orig / $ar->{price_factor}, $form->{"decimalplaces"});
 
     # marge_percent is recalculated, because the value in invoice used to be empty
     $ar->{marge_percent} = $ar->{sellprice_total} ? (($ar->{sellprice_total}-$ar->{lastcost_total}) / $ar->{sellprice_total} * 100) : 0;
@@ -341,9 +332,11 @@ sub invoice_transactions {
     $ar->{marge_total} = $ar->{sellprice_total} ? $ar->{sellprice_total}-$ar->{lastcost_total}  : 0;
     $ar->{discount} *= 100;  # format discount value for output, 10% is stored as 0.1 in db
 
-    # adapt qty to the chosen unit
+    # adjust qty to reflect the qty of the base unit
     $ar->{qty} *= $basefactor;
 
+    # now $ar->{sellprice} * $ar->{qty} should be the same as $qty_orig * $ar->{qty}
+
     # weight is the still the weight per part, but here we want the total weight
     $ar->{weight} *= $ar->{qty};