X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FForm.pm;h=4bea5f094d4dc51386abb29df1940b52289e6e98;hb=ddc3bbb167d3010b0058efa8f90936d15be76c2e;hp=381d8152d18496580f439e61ecc081158fd46f60;hpb=53beea8bb782b8ddf13d291bb274cff31456dc21;p=kivitendo-erp.git diff --git a/SL/Form.pm b/SL/Form.pm index 381d8152d..4bea5f094 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -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| @@ -423,6 +425,7 @@ function fokus(){document.$self->{fokus}.focus();} $jsscript $ajax $fokus + @@ -436,6 +439,7 @@ function fokus(){document.$self->{fokus}.focus();} + $extra_code |; @@ -663,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 @@ -753,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}"; @@ -785,9 +805,6 @@ sub parse_template { } close(OUT); - - use Data::Dumper; - #print(STDERR Dumper($self)); if ($template->uses_temp_file() || $self->{media} eq 'email') { @@ -822,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; @@ -1132,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; } @@ -1238,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; } @@ -1312,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(); @@ -1493,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; @@ -1505,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; @@ -1518,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; @@ -1544,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; @@ -1556,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; @@ -1568,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; @@ -1579,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)) { @@ -1655,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 @@ -1692,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)) { @@ -1754,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 @@ -1843,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 { @@ -2532,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;