Fehler bei Lieferadressen die Anfuehrungszeichen im Namen enthalten
[kivitendo-erp.git] / SL / Form.pm
index 2a04e15..4bea5f0 100644 (file)
@@ -146,7 +146,7 @@ sub new {
   $self->{action} = lc $self->{action};
   $self->{action} =~ s/( |-|,|\#)/_/g;
 
-  $self->{version}   = "2.3.9";
+  $self->{version}   = "2.4.0";
 
   $main::lxdebug->leave_sub();
 
@@ -349,7 +349,7 @@ sub isblank {
 sub header {
   $main::lxdebug->enter_sub();
 
-  my ($self) = @_;
+  my ($self, $extra_code) = @_;
 
   if ($self->{header}) {
     $main::lxdebug->leave_sub();
@@ -366,6 +366,8 @@ sub header {
  |;
     }
 
+    $self->{favicon}    = "favicon.ico" unless $self->{favicon};
+
     if ($self->{favicon} && (-f "$self->{favicon}")) {
       $favicon =
         qq|<LINK REL="shortcut icon" HREF="$self->{favicon}" TYPE="image/x-icon">
@@ -437,6 +439,7 @@ function fokus(){document.$self->{fokus}.focus();}
   
   </script>
 
+  $extra_code
 </head>
 
 |;
@@ -664,7 +667,7 @@ sub format_amount {
   $amount = $self->round_amount($amount, $places) if ($places =~ /\d/);
 
   my @d = map { s/\d//g; reverse split // } my $tmp = $myconfig->{numberformat}; # get delim chars
-  my @p = split /\./, $amount ; # split amount at decimal point
+  my @p = split(/\./, $amount); # split amount at decimal point
 
   $p[0] =~ s/\B(?=(...)*$)/$d[1]/g if $d[1]; # add 1,000 delimiters
 
@@ -754,20 +757,36 @@ sub parse_template {
   } elsif (($self->{"format"} =~ /html/i) ||
            (!$self->{"format"} && ($self->{"IN"} =~ /html$/i))) {
     $template = HTMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
+  } elsif (($self->{"format"} =~ /xml/i) ||
+             (!$self->{"format"} && ($self->{"IN"} =~ /xml$/i))) {
+    $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
+  } elsif ( $self->{"format"} =~ /elsterwinston/i ) {
+    $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);  
+  } elsif ( $self->{"format"} =~ /elstertaxbird/i ) {
+    $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
+  } elsif ( defined $self->{'format'}) {
+    $self->error("Outputformat not defined. This may be a future feature: $self->{'format'}");
+  } elsif ( $self->{'format'} eq '' ) {
+    $self->error("No Outputformat given: $self->{'format'}");
+  } else { #Catch the rest
+    $self->error("Outputformat not defined: $self->{'format'}");  
   }
 
   # Copy the notes from the invoice/sales order etc. back to the variable "notes" because that is where most templates expect it to be.
   $self->{"notes"} = $self->{ $self->{"formname"} . "notes" };
 
   map({ $self->{"employee_${_}"} = $myconfig->{$_}; }
-      qw(email tel fax name signature company address businessnumber));
+      qw(email tel fax name signature company address businessnumber
+         co_ustid taxnumber duns));
+  map({ $self->{"employee_${_}"} =~ s/\\n/\n/g; }
+      qw(company address signature));
 
   $self->{copies} = 1 if (($self->{copies} *= 1) <= 0);
 
   # OUT is used for the media, screen, printer, email
   # for postscript we store a copy in a temporary file
   my $fileid = time;
-  $self->{tmpfile} = "$userspath/${fileid}.$self->{IN}";
+  $self->{tmpfile} = "$userspath/${fileid}.$self->{IN}" if ( $self->{tmpfile} eq '' );
   if ($template->uses_temp_file() || $self->{media} eq 'email') {
     $out = $self->{OUT};
     $self->{OUT} = ">$self->{tmpfile}";
@@ -786,9 +805,6 @@ sub parse_template {
   }
 
   close(OUT);
-  
-  use Data::Dumper;
-  #print(STDERR Dumper($self));
 
   if ($template->uses_temp_file() || $self->{media} eq 'email') {
 
@@ -823,7 +839,7 @@ sub parse_template {
 
       } else {
 
-        @{ $mail->{attachments} } = ($self->{tmpfile}) unless ($form->{do_not_attach});
+        @{ $mail->{attachments} } = ($self->{tmpfile}) unless ($self->{do_not_attach});
 
         $mail->{message}       =~ s/\r\n/\n/g;
         $myconfig->{signature} =~ s/\\n/\n/g;
@@ -1133,6 +1149,13 @@ sub set_payment_options {
     $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;
 
     $dbh->disconnect;
   }
@@ -1239,7 +1262,7 @@ sub get_shipto {
     my $sth = $dbh->prepare($query);
     $sth->execute || $self->dberror($query);
     $ref = $sth->fetchrow_hashref(NAME_lc);
-    map { $form->{$_} = $ref->{$_} } keys %$ref;
+    map { $self->{$_} = $ref->{$_} } keys %$ref;
     $sth->finish;  
     $dbh->disconnect;
   }
@@ -1313,6 +1336,24 @@ sub get_employee {
   $main::lxdebug->leave_sub();
 }
 
+sub get_duedate {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig) = @_;
+
+  my $dbh = $self->dbconnect($myconfig);
+  my $query = qq|SELECT current_date+terms_netto FROM payment_terms
+                 WHERE id = '$self->{payment_id}'|;
+  my $sth = $dbh->prepare($query);
+  $sth->execute || $self->dberror($query);
+
+  ($self->{duedate}) = $sth->fetchrow_array;
+
+  $sth->finish;
+
+  $main::lxdebug->leave_sub();
+}
+
 # get other contact for transaction and form - html/tex
 sub get_contact {
   $main::lxdebug->enter_sub();
@@ -1494,7 +1535,7 @@ sub all_vc {
               FROM language
              ORDER BY 1|;
   $sth = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
+  $sth->execute || $self->dberror($query);
 
   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
     push @{ $self->{languages} }, $ref;
@@ -1506,7 +1547,7 @@ sub all_vc {
               FROM printers
              ORDER BY 1|;
   $sth = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
+  $sth->execute || $self->dberror($query);
 
   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
     push @{ $self->{printers} }, $ref;
@@ -1519,7 +1560,7 @@ sub all_vc {
               FROM payment_terms
              ORDER BY 1|;
   $sth = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
+  $sth->execute || $self->dberror($query);
 
   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
     push @{ $self->{payment_terms} }, $ref;
@@ -1545,7 +1586,7 @@ sub language_payment {
               FROM language
              ORDER BY 1|;
   my $sth = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
+  $sth->execute || $self->dberror($query);
 
   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
     push @{ $self->{languages} }, $ref;
@@ -1557,7 +1598,7 @@ sub language_payment {
               FROM printers
              ORDER BY 1|;
   $sth = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
+  $sth->execute || $self->dberror($query);
 
   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
     push @{ $self->{printers} }, $ref;
@@ -1569,7 +1610,7 @@ sub language_payment {
               FROM payment_terms
              ORDER BY 1|;
   $sth = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
+  $sth->execute || $self->dberror($query);
 
   while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
     push @{ $self->{payment_terms} }, $ref;
@@ -1580,7 +1621,7 @@ sub language_payment {
   $query = qq|SELECT id, description
               FROM buchungsgruppen|;
   $sth = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
+  $sth->execute || $self->dberror($query);
 
   $self->{BUCHUNGSGRUPPEN} = [];
   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
@@ -1656,7 +1697,7 @@ sub create_links {
     $self->{accounts} = "";
     while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
   
-      foreach my $key (split /:/, $ref->{link}) {
+      foreach my $key (split(/:/, $ref->{link})) {
         if ($key =~ /$module/) {
   
           # cross reference for keys
@@ -1693,7 +1734,7 @@ sub create_links {
   $query = qq|SELECT id, description
               FROM tax_zones|;
   $sth = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
+  $sth->execute || $self->dberror($query);
 
 
   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
@@ -1755,7 +1796,7 @@ sub create_links {
     $self->{accounts} = "";
     while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
   
-      foreach my $key (split /:/, $ref->{link}) {
+      foreach my $key (split(/:/, $ref->{link})) {
         if ($key =~ /$module/) {
   
           # cross reference for keys
@@ -1844,7 +1885,7 @@ sub create_links {
     if ($self->{"$self->{vc}_id"}) {
 
       # only setup currency
-      ($self->{currency}) = split /:/, $self->{currencies};
+      ($self->{currency}) = split(/:/, $self->{currencies});
 
     } else {
 
@@ -2533,4 +2574,33 @@ sub parse_date {
   return ($yy, $mm, $dd);
 }
 
+sub reformat_date {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $date, $output_format, $longformat) = @_;
+
+  $main::lxdebug->leave_sub() and return "" unless ($date);
+
+  my ($yy, $mm, $dd) = $self->parse_date($myconfig, $date);
+
+  $output_format =~ /d+/;
+  substr($output_format, $-[0], $+[0] - $-[0]) =
+    sprintf("%0" . (length($&)) . "d", $dd);
+
+  $output_format =~ /m+/;
+  substr($output_format, $-[0], $+[0] - $-[0]) =
+    sprintf("%0" . (length($&)) . "d", $mm);
+
+  $output_format =~ /y+/;
+  if (length($&) == 2) {
+    $yy -= $yy >= 2000 ? 2000 : 1900;
+  }
+  substr($output_format, $-[0], $+[0] - $-[0]) =
+    sprintf("%0" . (length($&)) . "d", $yy);
+
+  $main::lxdebug->leave_sub();
+
+  return $output_format;
+}
+
 1;