Ein "," anstelle eines "." sorgte dafür, dass die Steuerkontenbeschreibungen bei...
[kivitendo-erp.git] / SL / Form.pm
index c62c8ad..196d828 100644 (file)
@@ -294,11 +294,7 @@ sub error {
 
   } else {
 
-    if ($self->{error_function}) {
-      &{ $self->{error_function} }($msg);
-    } else {
-      die "Error: $msg\n";
-    }
+    die "Error: $msg\n";
   }
 
   $main::lxdebug->leave_sub();
@@ -386,10 +382,15 @@ sub header {
 
   if ($ENV{HTTP_USER_AGENT}) {
 
-    if ($self->{stylesheet} && (-f "css/$self->{stylesheet}")) {
-      $stylesheet =
-        qq|<LINK REL="stylesheet" HREF="css/$self->{stylesheet}" TYPE="text/css" TITLE="Lx-Office stylesheet">
- |;
+    my $stylesheets = "$self->{stylesheet} $self->{stylesheets}";
+
+    $stylesheets =~ s|^\s*||;
+    $stylesheets =~ s|\s*$||;
+    foreach my $file (split m/\s+/, $stylesheets) {
+      $file =~ s|.*/||;
+      next if (! -f "css/$file");
+
+      $stylesheet .= qq|<link rel="stylesheet" href="css/$file" TYPE="text/css" TITLE="Lx-Office stylesheet">\n|;
     }
 
     $self->{favicon}    = "favicon.ico" unless $self->{favicon};
@@ -590,7 +591,9 @@ sub parse_html_template2 {
   map { $additional_params->{$_} ||= $self->{$_} } keys %{ $self };
 
   my $output;
-  $template->process($file, $additional_params, \$output);
+  if (!$template->process($file, $additional_params, \$output)) {
+    print STDERR $template->error();
+  }
 
   $output = $main::locale->{iconv}->convert($output) if ($main::locale);
 
@@ -757,6 +760,22 @@ sub format_amount {
   return $amount;
 }
 #
+
+sub format_string {
+  $main::lxdebug->enter_sub(2);
+
+  my $self  = shift;
+  my $input = shift;
+
+  $input =~ s/(^|[^\#]) \#  (\d+)  /$1$_[$2 - 1]/gx;
+  $input =~ s/(^|[^\#]) \#\{(\d+)\}/$1$_[$2 - 1]/gx;
+  $input =~ s/\#\#/\#/g;
+
+  $main::lxdebug->leave_sub(2);
+
+  return $input;
+}
+
 sub parse_amount {
   $main::lxdebug->enter_sub(2);
 
@@ -1365,12 +1384,32 @@ sub set_payment_options {
   ($self->{netto_date}, $self->{skonto_date}) =
     selectrow_query($self, $dbh, $query, $transdate, $self->{terms_netto}, $transdate, $self->{terms_skonto});
 
-  my $total = ($self->{invtotal}) ? $self->{invtotal} : $self->{ordtotal};
-  my $skonto_amount = $self->parse_amount($myconfig, $total) *
-    $self->{percent_skonto};
+  my ($invtotal, $total);
+  my (%amounts, %formatted_amounts);
+
+  if ($self->{type} =~ /_order$/) {
+    $amounts{invtotal} = $self->{ordtotal};
+    $amounts{total}    = $self->{ordtotal};
+
+  } elsif ($self->{type} =~ /_quotation$/) {
+    $amounts{invtotal} = $self->{quototal};
+    $amounts{total}    = $self->{quototal};
+
+  } else {
+    $amounts{invtotal} = $self->{invtotal};
+    $amounts{total}    = $self->{total};
+  }
+
+  map { $amounts{$_} = $self->parse_amount($myconfig, $amounts{$_}) } keys %amounts;
 
-  $self->{skonto_amount} =
-    $self->format_amount($myconfig, $skonto_amount, 2);
+  $amounts{skonto_amount}      = $amounts{invtotal} * $self->{percent_skonto};
+  $amounts{invtotal_wo_skonto} = $amounts{invtotal} * (1 - $self->{percent_skonto});
+  $amounts{total_wo_skonto}    = $amounts{total}    * (1 - $self->{percent_skonto});
+
+  foreach (keys %amounts) {
+    $amounts{$_}           = $self->round_amount($amounts{$_}, 2);
+    $formatted_amounts{$_} = $self->format_amount($myconfig, $amounts{$_}, 2);
+  }
 
   if ($self->{"language_id"}) {
     $query =
@@ -1398,23 +1437,21 @@ sub set_payment_options {
         ($output_numberformat ne $myconfig->{"numberformat"})) {
       my $saved_numberformat = $myconfig->{"numberformat"};
       $myconfig->{"numberformat"} = $output_numberformat;
-      $self->{skonto_amount} =
-        $self->format_amount($myconfig, $skonto_amount, 2);
+      map { $formatted_amounts{$_} = $self->format_amount($myconfig, $amounts{$_}) } keys %amounts;
       $myconfig->{"numberformat"} = $saved_numberformat;
     }
   }
 
   $self->{payment_terms} =~ s/<%netto_date%>/$self->{netto_date}/g;
   $self->{payment_terms} =~ s/<%skonto_date%>/$self->{skonto_date}/g;
-  $self->{payment_terms} =~ s/<%skonto_amount%>/$self->{skonto_amount}/g;
-  $self->{payment_terms} =~ s/<%total%>/$self->{total}/g;
-  $self->{payment_terms} =~ s/<%invtotal%>/$self->{invtotal}/g;
   $self->{payment_terms} =~ s/<%currency%>/$self->{currency}/g;
   $self->{payment_terms} =~ s/<%terms_netto%>/$self->{terms_netto}/g;
   $self->{payment_terms} =~ s/<%account_number%>/$self->{account_number}/g;
   $self->{payment_terms} =~ s/<%bank%>/$self->{bank}/g;
   $self->{payment_terms} =~ s/<%bank_code%>/$self->{bank_code}/g;
 
+  map { $self->{payment_terms} =~ s/<%${_}%>/$formatted_amounts{$_}/g; } keys %formatted_amounts;
+
   $main::lxdebug->leave_sub();
 
 }
@@ -1857,6 +1894,20 @@ sub _get_departments {
   $main::lxdebug->leave_sub();
 }
 
+sub _get_price_factors {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $dbh, $key) = @_;
+
+  $key ||= "all_price_factors";
+
+  my $query = qq|SELECT * FROM price_factors ORDER BY sortkey|;
+
+  $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+
+  $main::lxdebug->leave_sub();
+}
+
 sub get_lists {
   $main::lxdebug->enter_sub();
 
@@ -1939,6 +1990,10 @@ sub get_lists {
     $self->_get_departments($dbh, $params{"departments"});
   }
 
+  if ($params{price_factors}) {
+    $self->_get_price_factors($dbh, $params{price_factors});
+  }
+
   $main::lxdebug->leave_sub();
 }