X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FForm.pm;h=25d437fd1a2517af3266e15895994eae44a75d3f;hb=6216f7b53a81a73641a2d98ea43f363b6a615b07;hp=5a9272465e7fc3d41e1b36f3f953ba2476aa8a41;hpb=7e6d7935ef67bfb97d4aa8b6fb44b26e9a3d3e04;p=kivitendo-erp.git diff --git a/SL/Form.pm b/SL/Form.pm index 5a9272465..25d437fd1 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -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(); @@ -595,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); @@ -728,18 +726,23 @@ sub format_amount { if ($amount eq "") { $amount = 0; } - my $neg = ($amount =~ s/-//); - + + # Hey watch out! The amount can be an exponential term like 1.13686837721616e-13 + + my $neg = ($amount =~ s/^-//); + my $exp = ($amount =~ m/[e]/) ? 1 : 0; + if (defined($places) && ($places ne '')) { - if ($places < 0) { - $amount *= 1; - $places *= -1; - - my ($actual_places) = ($amount =~ /\.(\d+)/); - $actual_places = length($actual_places); - $places = $actual_places > $places ? $actual_places : $places; + if (not $exp) { + if ($places < 0) { + $amount *= 1; + $places *= -1; + + my ($actual_places) = ($amount =~ /\.(\d+)/); + $actual_places = length($actual_places); + $places = $actual_places > $places ? $actual_places : $places; + } } - $amount = $self->round_amount($amount, $places); } @@ -762,6 +765,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); @@ -849,6 +868,10 @@ sub parse_template { qw(company address signature)); map({ $self->{$_} =~ s/\\n/\n/g; } qw(company address signature)); + map({ $self->{"${_}"} = $myconfig->{$_}; } + qw(co_ustid)); + + $self->{copies} = 1 if (($self->{copies} *= 1) <= 0); # OUT is used for the media, screen, printer, email @@ -1880,6 +1903,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(); @@ -1962,6 +1999,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(); } @@ -2199,7 +2240,7 @@ sub create_links { while ($ref = $sth->fetchrow_hashref(NAME_lc)) { foreach my $key (split(/:/, $ref->{link})) { - if ($key =~ /$module/) { + if ($key =~ /\Q$module\E/) { # cross reference for keys $xkeyref{ $ref->{accno} } = $key; @@ -2258,7 +2299,7 @@ sub create_links { LEFT JOIN taxkeys tk ON (tk.chart_id = c.id) WHERE c.link LIKE ? AND (tk.id = (SELECT id FROM taxkeys WHERE taxkeys.chart_id = c.id AND startdate <= $transdate ORDER BY startdate DESC LIMIT 1) - OR c.link LIKE '%_tax%') + OR c.link LIKE '%_tax%' OR c.taxkey_id IS NULL) ORDER BY c.accno|; $sth = $dbh->prepare($query); @@ -2268,7 +2309,7 @@ sub create_links { while ($ref = $sth->fetchrow_hashref(NAME_lc)) { foreach my $key (split(/:/, $ref->{link})) { - if ($key =~ /$module/) { + if ($key =~ /\Q$module\E/) { # cross reference for keys $xkeyref{ $ref->{accno} } = $key; @@ -2500,8 +2541,8 @@ sub update_status { } $sth->finish(); - my $printed = ($self->{printed} =~ /$self->{formname}/) ? "1" : "0"; - my $emailed = ($self->{emailed} =~ /$self->{formname}/) ? "1" : "0"; + my $printed = ($self->{printed} =~ /\Q$self->{formname}\E/) ? "1" : "0"; + my $emailed = ($self->{emailed} =~ /\Q$self->{formname}\E/) ? "1" : "0"; my %queued = split / /, $self->{queued}; my @values; @@ -2556,15 +2597,15 @@ sub save_status { my %queued = split / /, $self->{queued}; foreach my $formname (keys %queued) { - $printed = ($self->{printed} =~ /$self->{formname}/) ? "1" : "0"; - $emailed = ($self->{emailed} =~ /$self->{formname}/) ? "1" : "0"; + $printed = ($self->{printed} =~ /\Q$self->{formname}\E/) ? "1" : "0"; + $emailed = ($self->{emailed} =~ /\Q$self->{formname}\E/) ? "1" : "0"; $query = qq|INSERT INTO status (trans_id, printed, emailed, spoolfile, formname) VALUES (?, ?, ?, ?, ?)|; do_query($self, $dbh, $query, $self->{id}, $printed, $emailed, $queued{$formname}, $formname); - $formnames =~ s/$self->{formname}//; - $emailforms =~ s/$self->{formname}//; + $formnames =~ s/\Q$self->{formname}\E//; + $emailforms =~ s/\Q$self->{formname}\E//; } } @@ -2578,8 +2619,8 @@ sub save_status { map { $status{$_}{emailed} = 1 } split / +/, $emailforms; foreach my $formname (keys %status) { - $printed = ($formnames =~ /$self->{formname}/) ? "1" : "0"; - $emailed = ($emailforms =~ /$self->{formname}/) ? "1" : "0"; + $printed = ($formnames =~ /\Q$self->{formname}\E/) ? "1" : "0"; + $emailed = ($emailforms =~ /\Q$self->{formname}\E/) ? "1" : "0"; $query = qq|INSERT INTO status (trans_id, printed, emailed, formname) VALUES (?, ?, ?, ?)|;