1 #====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (C) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
15 # Contributors: Thomas Bayen <bayen@gmx.de>
16 # Antti Kaihola <akaihola@siba.fi>
17 # Moritz Bunkus (tex code)
19 # This program is free software; you can redistribute it and/or modify
20 # it under the terms of the GNU General Public License as published by
21 # the Free Software Foundation; either version 2 of the License, or
22 # (at your option) any later version.
24 # This program is distributed in the hope that it will be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 # GNU General Public License for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write to the Free Software
30 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #======================================================================
32 # Utilities for parsing forms
33 # and supporting routines for linking account numbers
34 # used in AR, AP and IS, IR modules
36 #======================================================================
58 use List::Util qw(first max min sum);
59 use List::MoreUtils qw(any);
67 $standard_dbh->disconnect();
73 $main::lxdebug->enter_sub(2);
79 my @tokens = split /((?:\[\+?\])?(?:\.|$))/, $key;
84 $curr = \ $self->{ shift @tokens };
88 my $sep = shift @tokens;
89 my $key = shift @tokens;
91 $curr = \ $$curr->[++$#$$curr], next if $sep eq '[]';
92 $curr = \ $$curr->[max 0, $#$$curr] if $sep eq '[].';
93 $curr = \ $$curr->[++$#$$curr] if $sep eq '[+].';
94 $curr = \ $$curr->{$key}
99 $main::lxdebug->leave_sub(2);
105 $main::lxdebug->enter_sub(2);
110 my @pairs = split(/&/, $input);
113 my ($key, $value) = split(/=/, $_, 2);
114 $self->_store_value($self->unescape($key), $self->unescape($value)) if ($key);
117 $main::lxdebug->leave_sub(2);
120 sub _request_to_hash {
121 $main::lxdebug->enter_sub(2);
126 if (!$ENV{'CONTENT_TYPE'}
127 || ($ENV{'CONTENT_TYPE'} !~ /multipart\/form-data\s*;\s*boundary\s*=\s*(.+)$/)) {
129 $self->_input_to_hash($input);
131 $main::lxdebug->leave_sub(2);
135 my ($name, $filename, $headers_done, $content_type, $boundary_found, $need_cr, $previous);
137 my $boundary = '--' . $1;
139 foreach my $line (split m/\n/, $input) {
140 last if (($line eq "${boundary}--") || ($line eq "${boundary}--\r"));
142 if (($line eq $boundary) || ($line eq "$boundary\r")) {
143 ${ $previous } =~ s|\r?\n$|| if $previous;
149 $content_type = "text/plain";
156 next unless $boundary_found;
158 if (!$headers_done) {
159 $line =~ s/[\r\n]*$//;
166 if ($line =~ m|^content-disposition\s*:.*?form-data\s*;|i) {
167 if ($line =~ m|filename\s*=\s*"(.*?)"|i) {
169 substr $line, $-[0], $+[0] - $-[0], "";
172 if ($line =~ m|name\s*=\s*"(.*?)"|i) {
174 substr $line, $-[0], $+[0] - $-[0], "";
177 $previous = $self->_store_value($name, '') if ($name);
178 $self->{FILENAME} = $filename if ($filename);
183 if ($line =~ m|^content-type\s*:\s*(.*?)$|i) {
190 next unless $previous;
192 ${ $previous } .= "${line}\n";
195 ${ $previous } =~ s|\r?\n$|| if $previous;
197 $main::lxdebug->leave_sub(2);
200 sub _recode_recursively {
201 $main::lxdebug->enter_sub();
202 my ($iconv, $param) = @_;
204 if (any { ref $param eq $_ } qw(Form HASH)) {
205 foreach my $key (keys %{ $param }) {
206 if (!ref $param->{$key}) {
207 # Workaround for a bug: converting $param->{$key} directly
208 # leads to 'undef'. I don't know why. Converting a copy works,
210 $param->{$key} = $iconv->convert("" . $param->{$key});
212 _recode_recursively($iconv, $param->{$key});
216 } elsif (ref $param eq 'ARRAY') {
217 foreach my $idx (0 .. scalar(@{ $param }) - 1) {
218 if (!ref $param->[$idx]) {
219 # Workaround for a bug: converting $param->[$idx] directly
220 # leads to 'undef'. I don't know why. Converting a copy works,
222 $param->[$idx] = $iconv->convert("" . $param->[$idx]);
224 _recode_recursively($iconv, $param->[$idx]);
228 $main::lxdebug->leave_sub();
232 $main::lxdebug->enter_sub();
238 if ($LXDebug::watch_form) {
239 require SL::Watchdog;
240 tie %{ $self }, 'SL::Watchdog';
243 read(STDIN, $_, $ENV{CONTENT_LENGTH});
245 if ($ENV{QUERY_STRING}) {
246 $_ = $ENV{QUERY_STRING};
255 $self->_request_to_hash($_);
257 my $db_charset = $main::dbcharset;
258 $db_charset ||= Common::DEFAULT_CHARSET;
260 if ($self->{INPUT_ENCODING}) {
261 if (lc $self->{INPUT_ENCODING} ne lc $db_charset) {
263 my $iconv = Text::Iconv->new($self->{INPUT_ENCODING}, $db_charset);
265 _recode_recursively($iconv, $self);
268 delete $self->{INPUT_ENCODING};
271 $self->{action} = lc $self->{action};
272 $self->{action} =~ s/( |-|,|\#)/_/g;
274 $self->{version} = "2.6.1";
276 $main::lxdebug->leave_sub();
281 sub _flatten_variables_rec {
282 $main::lxdebug->enter_sub(2);
291 if ('' eq ref $curr->{$key}) {
292 @result = ({ 'key' => $prefix . $key, 'value' => $curr->{$key} });
294 } elsif ('HASH' eq ref $curr->{$key}) {
295 foreach my $hash_key (sort keys %{ $curr->{$key} }) {
296 push @result, $self->_flatten_variables_rec($curr->{$key}, $prefix . $key . '.', $hash_key);
300 foreach my $idx (0 .. scalar @{ $curr->{$key} } - 1) {
301 my $first_array_entry = 1;
303 foreach my $hash_key (sort keys %{ $curr->{$key}->[$idx] }) {
304 push @result, $self->_flatten_variables_rec($curr->{$key}->[$idx], $prefix . $key . ($first_array_entry ? '[+].' : '[].'), $hash_key);
305 $first_array_entry = 0;
310 $main::lxdebug->leave_sub(2);
315 sub flatten_variables {
316 $main::lxdebug->enter_sub(2);
324 push @variables, $self->_flatten_variables_rec($self, '', $_);
327 $main::lxdebug->leave_sub(2);
332 sub flatten_standard_variables {
333 $main::lxdebug->enter_sub(2);
336 my %skip_keys = map { $_ => 1 } (qw(login password header stylesheet titlebar version), @_);
340 foreach (grep { ! $skip_keys{$_} } keys %{ $self }) {
341 push @variables, $self->_flatten_variables_rec($self, '', $_);
344 $main::lxdebug->leave_sub(2);
350 $main::lxdebug->enter_sub();
356 map { print "$_ = $self->{$_}\n" } (sort keys %{$self});
358 $main::lxdebug->leave_sub();
362 $main::lxdebug->enter_sub(2);
365 my $password = $self->{password};
367 $self->{password} = 'X' x 8;
369 local $Data::Dumper::Sortkeys = 1;
370 my $output = Dumper($self);
372 $self->{password} = $password;
374 $main::lxdebug->leave_sub(2);
380 $main::lxdebug->enter_sub(2);
382 my ($self, $str) = @_;
384 $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
386 $main::lxdebug->leave_sub(2);
392 $main::lxdebug->enter_sub(2);
394 my ($self, $str) = @_;
399 $str =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
401 $main::lxdebug->leave_sub(2);
407 $main::lxdebug->enter_sub();
408 my ($self, $str) = @_;
410 if ($str && !ref($str)) {
411 $str =~ s/\"/"/g;
414 $main::lxdebug->leave_sub();
420 $main::lxdebug->enter_sub();
421 my ($self, $str) = @_;
423 if ($str && !ref($str)) {
424 $str =~ s/"/\"/g;
427 $main::lxdebug->leave_sub();
433 $main::lxdebug->enter_sub();
437 map({ print($main::cgi->hidden("-name" => $_, "-default" => $self->{$_}) . "\n"); } @_);
439 for (sort keys %$self) {
440 next if (($_ eq "header") || (ref($self->{$_}) ne ""));
441 print($main::cgi->hidden("-name" => $_, "-default" => $self->{$_}) . "\n");
444 $main::lxdebug->leave_sub();
448 $main::lxdebug->enter_sub();
450 $main::lxdebug->show_backtrace();
452 my ($self, $msg) = @_;
453 if ($ENV{HTTP_USER_AGENT}) {
455 $self->show_generic_error($msg);
462 $main::lxdebug->leave_sub();
466 $main::lxdebug->enter_sub();
468 my ($self, $msg) = @_;
470 if ($ENV{HTTP_USER_AGENT}) {
473 if (!$self->{header}) {
486 if ($self->{info_function}) {
487 &{ $self->{info_function} }($msg);
493 $main::lxdebug->leave_sub();
496 # calculates the number of rows in a textarea based on the content and column number
497 # can be capped with maxrows
499 $main::lxdebug->enter_sub();
500 my ($self, $str, $cols, $maxrows, $minrows) = @_;
504 my $rows = sum map { int((length() - 2) / $cols) + 1 } split /\r/, $str;
507 $main::lxdebug->leave_sub();
509 return max(min($rows, $maxrows), $minrows);
513 $main::lxdebug->enter_sub();
515 my ($self, $msg) = @_;
517 $self->error("$msg\n" . $DBI::errstr);
519 $main::lxdebug->leave_sub();
523 $main::lxdebug->enter_sub();
525 my ($self, $name, $msg) = @_;
528 foreach my $part (split m/\./, $name) {
529 if (!$curr->{$part} || ($curr->{$part} =~ /^\s*$/)) {
532 $curr = $curr->{$part};
535 $main::lxdebug->leave_sub();
538 sub _get_request_uri {
541 return URI->new($ENV{HTTP_REFERER})->canonical() if $ENV{HTTP_X_FORWARDED_FOR};
543 my $scheme = $ENV{HTTPS} && (lc $ENV{HTTPS} eq 'on') ? 'https' : 'http';
544 my $port = $ENV{SERVER_PORT} || '';
545 $port = undef if (($scheme eq 'http' ) && ($port == 80))
546 || (($scheme eq 'https') && ($port == 443));
548 my $uri = URI->new("${scheme}://");
549 $uri->scheme($scheme);
551 $uri->host($ENV{HTTP_HOST} || $ENV{SERVER_ADDR});
552 $uri->path_query($ENV{REQUEST_URI});
558 sub create_http_response {
559 $main::lxdebug->enter_sub();
564 my $cgi = $main::cgi;
565 $cgi ||= CGI->new('');
568 if (defined $main::auth) {
569 my $uri = $self->_get_request_uri;
570 my @segments = $uri->path_segments;
572 $uri->path_segments(@segments);
574 my $session_cookie_value = $main::auth->get_session_id();
575 $session_cookie_value ||= 'NO_SESSION';
577 $session_cookie = $cgi->cookie('-name' => $main::auth->get_session_cookie_name(),
578 '-value' => $session_cookie_value,
579 '-path' => $uri->path,
580 '-secure' => $ENV{HTTPS});
583 my %cgi_params = ('-type' => $params{content_type});
584 $cgi_params{'-charset'} = $params{charset} if ($params{charset});
586 my $output = $cgi->header('-cookie' => $session_cookie,
589 $main::lxdebug->leave_sub();
596 $main::lxdebug->enter_sub();
598 # extra code ist currently only used by menuv3 and menuv4 to set their css.
599 # it is strongly deprecated, and will be changed in a future version.
600 my ($self, $extra_code) = @_;
602 if ($self->{header}) {
603 $main::lxdebug->leave_sub();
607 my ($stylesheet, $favicon, $pagelayout);
609 if ($ENV{HTTP_USER_AGENT}) {
612 if ($ENV{'HTTP_USER_AGENT'} =~ m/MSIE\s+\d/) {
613 # Only set the DOCTYPE for Internet Explorer. Other browsers have problems displaying the menu otherwise.
614 $doctype = qq|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n|;
617 my $stylesheets = "$self->{stylesheet} $self->{stylesheets}";
619 $stylesheets =~ s|^\s*||;
620 $stylesheets =~ s|\s*$||;
621 foreach my $file (split m/\s+/, $stylesheets) {
623 next if (! -f "css/$file");
625 $stylesheet .= qq|<link rel="stylesheet" href="css/$file" TYPE="text/css" TITLE="Lx-Office stylesheet">\n|;
628 $self->{favicon} = "favicon.ico" unless $self->{favicon};
630 if ($self->{favicon} && (-f "$self->{favicon}")) {
632 qq|<LINK REL="shortcut icon" HREF="$self->{favicon}" TYPE="image/x-icon">
636 my $db_charset = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
638 if ($self->{landscape}) {
639 $pagelayout = qq|<style type="text/css">
640 \@page { size:landscape; }
645 <script type="text/javascript">
648 document.$self->{fokus}.focus();
652 | if $self->{"fokus"};
656 if ($self->{jsscript} == 1) {
659 <script type="text/javascript" src="js/jquery.js"></script>
660 <script type="text/javascript" src="js/common.js"></script>
661 <style type="text/css">\@import url(js/jscalendar/calendar-win2k-1.css);</style>
662 <script type="text/javascript" src="js/jscalendar/calendar.js"></script>
663 <script type="text/javascript" src="js/jscalendar/lang/calendar-de.js"></script>
664 <script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script>
671 ? "$self->{title} - $self->{titlebar}"
674 for my $item (@ { $self->{AJAX} || [] }) {
675 $ajax .= $item->show_javascript();
678 print $self->create_http_response('content_type' => 'text/html',
679 'charset' => $db_charset,);
680 print qq|${doctype}<html>
682 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=${db_charset}">
683 <title>$self->{titlebar}</title>
692 <link rel="stylesheet" href="css/jquery.autocomplete.css" type="text/css" />
694 <meta name="robots" content="noindex,nofollow" />
695 <script type="text/javascript" src="js/highlight_input.js"></script>
697 <link rel="stylesheet" type="text/css" href="css/tabcontent.css" />
698 <script type="text/javascript" src="js/tabcontent.js">
700 /***********************************************
701 * Tab Content script v2.2- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
702 * This notice MUST stay intact for legal use
703 * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
704 ***********************************************/
715 $main::lxdebug->leave_sub();
718 sub ajax_response_header {
719 $main::lxdebug->enter_sub();
723 my $db_charset = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
724 my $cgi = $main::cgi || CGI->new('');
725 my $output = $cgi->header('-charset' => $db_charset);
727 $main::lxdebug->leave_sub();
732 sub redirect_header {
736 my $base_uri = $self->_get_request_uri;
737 my $new_uri = URI->new_abs($new_url, $base_uri);
739 die "Headers already sent" if $::self->{header};
742 my $cgi = $main::cgi || CGI->new('');
743 return $cgi->redirect($new_uri);
746 sub set_standard_title {
747 $::lxdebug->enter_sub;
750 $self->{titlebar} = "Lx-Office " . $::locale->text('Version') . " $self->{version}";
751 $self->{titlebar} .= "- $::myconfig{name}" if $::myconfig{name};
752 $self->{titlebar} .= "- $::myconfig{dbname}" if $::myconfig{name};
754 $::lxdebug->leave_sub;
757 sub _prepare_html_template {
758 $main::lxdebug->enter_sub();
760 my ($self, $file, $additional_params) = @_;
763 if (!%::myconfig || !$::myconfig{"countrycode"}) {
764 $language = $main::language;
766 $language = $main::myconfig{"countrycode"};
768 $language = "de" unless ($language);
770 if (-f "templates/webpages/${file}.html") {
771 if ((-f ".developer") && ((stat("templates/webpages/${file}.html"))[9] > (stat("locale/${language}/all"))[9])) {
772 my $info = "Developer information: templates/webpages/${file}.html is newer than the translation file locale/${language}/all.\n" .
773 "Please re-run 'locales.pl' in 'locale/${language}'.";
774 print(qq|<pre>$info</pre>|);
778 $file = "templates/webpages/${file}.html";
781 my $info = "Web page template '${file}' not found.\n" .
782 "Please re-run 'locales.pl' in 'locale/${language}'.";
783 print(qq|<pre>$info</pre>|);
787 if ($self->{"DEBUG"}) {
788 $additional_params->{"DEBUG"} = $self->{"DEBUG"};
791 if ($additional_params->{"DEBUG"}) {
792 $additional_params->{"DEBUG"} =
793 "<br><em>DEBUG INFORMATION:</em><pre>" . $additional_params->{"DEBUG"} . "</pre>";
796 if (%main::myconfig) {
797 map({ $additional_params->{"myconfig_${_}"} = $main::myconfig{$_}; } keys(%main::myconfig));
798 my $jsc_dateformat = $main::myconfig{"dateformat"};
799 $jsc_dateformat =~ s/d+/\%d/gi;
800 $jsc_dateformat =~ s/m+/\%m/gi;
801 $jsc_dateformat =~ s/y+/\%Y/gi;
802 $additional_params->{"myconfig_jsc_dateformat"} = $jsc_dateformat;
803 $additional_params->{"myconfig"} ||= \%::myconfig;
806 $additional_params->{"conf_dbcharset"} = $main::dbcharset;
807 $additional_params->{"conf_webdav"} = $main::webdav;
808 $additional_params->{"conf_lizenzen"} = $main::lizenzen;
809 $additional_params->{"conf_latex_templates"} = $main::latex;
810 $additional_params->{"conf_opendocument_templates"} = $main::opendocument_templates;
811 $additional_params->{"conf_vertreter"} = $main::vertreter;
812 $additional_params->{"conf_show_best_before"} = $main::show_best_before;
814 if (%main::debug_options) {
815 map { $additional_params->{'DEBUG_' . uc($_)} = $main::debug_options{$_} } keys %main::debug_options;
818 if ($main::auth && $main::auth->{RIGHTS} && $main::auth->{RIGHTS}->{$self->{login}}) {
819 while (my ($key, $value) = each %{ $main::auth->{RIGHTS}->{$self->{login}} }) {
820 $additional_params->{"AUTH_RIGHTS_" . uc($key)} = $value;
824 $main::lxdebug->leave_sub();
829 sub parse_html_template {
830 $main::lxdebug->enter_sub();
832 my ($self, $file, $additional_params) = @_;
834 $additional_params ||= { };
836 $file = $self->_prepare_html_template($file, $additional_params);
838 my $template = Template->new({ 'INTERPOLATE' => 0,
842 'PLUGIN_BASE' => 'SL::Template::Plugin',
843 'INCLUDE_PATH' => '.:templates/webpages',
846 map { $additional_params->{$_} ||= $self->{$_} } keys %{ $self };
848 my $in = IO::File->new($file, 'r');
851 print STDERR "Error opening template file: $!";
852 $main::lxdebug->leave_sub();
856 my $input = join('', <$in>);
860 if (!$template->process(\$input, $additional_params, \$output)) {
861 print STDERR $template->error();
864 $main::lxdebug->leave_sub();
869 sub show_generic_error {
870 $main::lxdebug->enter_sub();
872 my ($self, $error, %params) = @_;
875 'title_error' => $params{title},
876 'label_error' => $error,
879 if ($params{action}) {
882 map { delete($self->{$_}); } qw(action);
883 map { push @vars, { "name" => $_, "value" => $self->{$_} } if (!ref($self->{$_})); } keys %{ $self };
885 $add_params->{SHOW_BUTTON} = 1;
886 $add_params->{BUTTON_LABEL} = $params{label} || $params{action};
887 $add_params->{VARIABLES} = \@vars;
889 } elsif ($params{back_button}) {
890 $add_params->{SHOW_BACK_BUTTON} = 1;
893 $self->{title} = $params{title} if $params{title};
896 print $self->parse_html_template("generic/error", $add_params);
898 $main::lxdebug->leave_sub();
900 die("Error: $error\n");
903 sub show_generic_information {
904 $main::lxdebug->enter_sub();
906 my ($self, $text, $title) = @_;
909 'title_information' => $title,
910 'label_information' => $text,
913 $self->{title} = $title if ($title);
916 print $self->parse_html_template("generic/information", $add_params);
918 $main::lxdebug->leave_sub();
920 die("Information: $text\n");
923 # write Trigger JavaScript-Code ($qty = quantity of Triggers)
924 # changed it to accept an arbitrary number of triggers - sschoeling
926 $main::lxdebug->enter_sub();
929 my $myconfig = shift;
932 # set dateform for jsscript
935 "dd.mm.yy" => "%d.%m.%Y",
936 "dd-mm-yy" => "%d-%m-%Y",
937 "dd/mm/yy" => "%d/%m/%Y",
938 "mm/dd/yy" => "%m/%d/%Y",
939 "mm-dd-yy" => "%m-%d-%Y",
940 "yyyy-mm-dd" => "%Y-%m-%d",
943 my $ifFormat = defined($dateformats{$myconfig->{"dateformat"}}) ?
944 $dateformats{$myconfig->{"dateformat"}} : "%d.%m.%Y";
951 inputField : "| . (shift) . qq|",
952 ifFormat :"$ifFormat",
953 align : "| . (shift) . qq|",
954 button : "| . (shift) . qq|"
960 <script type="text/javascript">
961 <!--| . join("", @triggers) . qq|//-->
965 $main::lxdebug->leave_sub();
968 } #end sub write_trigger
971 $main::lxdebug->enter_sub();
973 my ($self, $msg) = @_;
975 if (!$self->{callback}) {
981 # my ($script, $argv) = split(/\?/, $self->{callback}, 2);
982 # $script =~ s|.*/||;
983 # $script =~ s|[^a-zA-Z0-9_\.]||g;
984 # exec("perl", "$script", $argv);
986 print $::form->redirect_header($self->{callback});
988 $main::lxdebug->leave_sub();
991 # sort of columns removed - empty sub
993 $main::lxdebug->enter_sub();
995 my ($self, @columns) = @_;
997 $main::lxdebug->leave_sub();
1003 $main::lxdebug->enter_sub(2);
1005 my ($self, $myconfig, $amount, $places, $dash) = @_;
1007 if ($amount eq "") {
1011 # Hey watch out! The amount can be an exponential term like 1.13686837721616e-13
1013 my $neg = ($amount =~ s/^-//);
1014 my $exp = ($amount =~ m/[e]/) ? 1 : 0;
1016 if (defined($places) && ($places ne '')) {
1022 my ($actual_places) = ($amount =~ /\.(\d+)/);
1023 $actual_places = length($actual_places);
1024 $places = $actual_places > $places ? $actual_places : $places;
1027 $amount = $self->round_amount($amount, $places);
1030 my @d = map { s/\d//g; reverse split // } my $tmp = $myconfig->{numberformat}; # get delim chars
1031 my @p = split(/\./, $amount); # split amount at decimal point
1033 $p[0] =~ s/\B(?=(...)*$)/$d[1]/g if $d[1]; # add 1,000 delimiters
1036 $amount .= $d[0].$p[1].(0 x ($places - length $p[1])) if ($places || $p[1] ne '');
1039 ($dash =~ /-/) ? ($neg ? "($amount)" : "$amount" ) :
1040 ($dash =~ /DRCR/) ? ($neg ? "$amount " . $main::locale->text('DR') : "$amount " . $main::locale->text('CR') ) :
1041 ($neg ? "-$amount" : "$amount" ) ;
1045 $main::lxdebug->leave_sub(2);
1049 sub format_amount_units {
1050 $main::lxdebug->enter_sub();
1055 my $myconfig = \%main::myconfig;
1056 my $amount = $params{amount} * 1;
1057 my $places = $params{places};
1058 my $part_unit_name = $params{part_unit};
1059 my $amount_unit_name = $params{amount_unit};
1060 my $conv_units = $params{conv_units};
1061 my $max_places = $params{max_places};
1063 if (!$part_unit_name) {
1064 $main::lxdebug->leave_sub();
1068 AM->retrieve_all_units();
1069 my $all_units = $main::all_units;
1071 if (('' eq ref $conv_units) && ($conv_units =~ /convertible/)) {
1072 $conv_units = AM->convertible_units($all_units, $part_unit_name, $conv_units eq 'convertible_not_smaller');
1075 if (!scalar @{ $conv_units }) {
1076 my $result = $self->format_amount($myconfig, $amount, $places, undef, $max_places) . " " . $part_unit_name;
1077 $main::lxdebug->leave_sub();
1081 my $part_unit = $all_units->{$part_unit_name};
1082 my $conv_unit = ($amount_unit_name && ($amount_unit_name ne $part_unit_name)) ? $all_units->{$amount_unit_name} : $part_unit;
1084 $amount *= $conv_unit->{factor};
1089 foreach my $unit (@$conv_units) {
1090 my $last = $unit->{name} eq $part_unit->{name};
1092 $num = int($amount / $unit->{factor});
1093 $amount -= $num * $unit->{factor};
1096 if ($last ? $amount : $num) {
1097 push @values, { "unit" => $unit->{name},
1098 "amount" => $last ? $amount / $unit->{factor} : $num,
1099 "places" => $last ? $places : 0 };
1106 push @values, { "unit" => $part_unit_name,
1111 my $result = join " ", map { $self->format_amount($myconfig, $_->{amount}, $_->{places}, undef, $max_places), $_->{unit} } @values;
1113 $main::lxdebug->leave_sub();
1119 $main::lxdebug->enter_sub(2);
1124 $input =~ s/(^|[^\#]) \# (\d+) /$1$_[$2 - 1]/gx;
1125 $input =~ s/(^|[^\#]) \#\{(\d+)\}/$1$_[$2 - 1]/gx;
1126 $input =~ s/\#\#/\#/g;
1128 $main::lxdebug->leave_sub(2);
1136 $main::lxdebug->enter_sub(2);
1138 my ($self, $myconfig, $amount) = @_;
1140 if ( ($myconfig->{numberformat} eq '1.000,00')
1141 || ($myconfig->{numberformat} eq '1000,00')) {
1146 if ($myconfig->{numberformat} eq "1'000.00") {
1152 $main::lxdebug->leave_sub(2);
1154 return ($amount * 1);
1158 $main::lxdebug->enter_sub(2);
1160 my ($self, $amount, $places) = @_;
1163 # Rounding like "Kaufmannsrunden" (see http://de.wikipedia.org/wiki/Rundung )
1165 # Round amounts to eight places before rounding to the requested
1166 # number of places. This gets rid of errors due to internal floating
1167 # point representation.
1168 $amount = $self->round_amount($amount, 8) if $places < 8;
1169 $amount = $amount * (10**($places));
1170 $round_amount = int($amount + .5 * ($amount <=> 0)) / (10**($places));
1172 $main::lxdebug->leave_sub(2);
1174 return $round_amount;
1178 sub parse_template {
1179 $main::lxdebug->enter_sub();
1181 my ($self, $myconfig, $userspath) = @_;
1182 my ($template, $out);
1186 $self->{"cwd"} = getcwd();
1187 $self->{"tmpdir"} = $self->{cwd} . "/${userspath}";
1191 if ($self->{"format"} =~ /(opendocument|oasis)/i) {
1192 $template = OpenDocumentTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1193 $ext_for_format = $self->{"format"} =~ m/pdf/ ? 'pdf' : 'odt';
1195 } elsif ($self->{"format"} =~ /(postscript|pdf)/i) {
1196 $ENV{"TEXINPUTS"} = ".:" . getcwd() . "/" . $myconfig->{"templates"} . ":" . $ENV{"TEXINPUTS"};
1197 $template = LaTeXTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1198 $ext_for_format = 'pdf';
1200 } elsif (($self->{"format"} =~ /html/i) || (!$self->{"format"} && ($self->{"IN"} =~ /html$/i))) {
1201 $template = HTMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1202 $ext_for_format = 'html';
1204 } elsif (($self->{"format"} =~ /xml/i) || (!$self->{"format"} && ($self->{"IN"} =~ /xml$/i))) {
1205 $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1206 $ext_for_format = 'xml';
1208 } elsif ( $self->{"format"} =~ /elsterwinston/i ) {
1209 $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1211 } elsif ( $self->{"format"} =~ /elstertaxbird/i ) {
1212 $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1214 } elsif ( $self->{"format"} =~ /excel/i ) {
1215 $template = ExcelTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1216 $ext_for_format = 'xls';
1218 } elsif ( defined $self->{'format'}) {
1219 $self->error("Outputformat not defined. This may be a future feature: $self->{'format'}");
1221 } elsif ( $self->{'format'} eq '' ) {
1222 $self->error("No Outputformat given: $self->{'format'}");
1224 } else { #Catch the rest
1225 $self->error("Outputformat not defined: $self->{'format'}");
1228 # Copy the notes from the invoice/sales order etc. back to the variable "notes" because that is where most templates expect it to be.
1229 $self->{"notes"} = $self->{ $self->{"formname"} . "notes" };
1231 if (!$self->{employee_id}) {
1232 map { $self->{"employee_${_}"} = $myconfig->{$_}; } qw(email tel fax name signature company address businessnumber co_ustid taxnumber duns);
1235 map { $self->{"${_}"} = $myconfig->{$_}; } qw(co_ustid);
1237 $self->{copies} = 1 if (($self->{copies} *= 1) <= 0);
1239 # OUT is used for the media, screen, printer, email
1240 # for postscript we store a copy in a temporary file
1242 my $prepend_userspath;
1244 if (!$self->{tmpfile}) {
1245 $self->{tmpfile} = "${fileid}.$self->{IN}";
1246 $prepend_userspath = 1;
1249 $prepend_userspath = 1 if substr($self->{tmpfile}, 0, length $userspath) eq $userspath;
1251 $self->{tmpfile} =~ s|.*/||;
1252 $self->{tmpfile} =~ s/[^a-zA-Z0-9\._\ \-]//g;
1253 $self->{tmpfile} = "$userspath/$self->{tmpfile}" if $prepend_userspath;
1255 if ($template->uses_temp_file() || $self->{media} eq 'email') {
1256 $out = $self->{OUT};
1257 $self->{OUT} = ">$self->{tmpfile}";
1261 open(OUT, "$self->{OUT}") or $self->error("$self->{OUT} : $!");
1263 open(OUT, ">-") or $self->error("STDOUT : $!");
1267 if (!$template->parse(*OUT)) {
1269 $self->error("$self->{IN} : " . $template->get_error());
1274 if ($template->uses_temp_file() || $self->{media} eq 'email') {
1276 if ($self->{media} eq 'email') {
1278 my $mail = new Mailer;
1280 map { $mail->{$_} = $self->{$_} }
1281 qw(cc bcc subject message version format);
1282 $mail->{charset} = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
1283 $mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email};
1284 $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
1285 $mail->{fileid} = "$fileid.";
1286 $myconfig->{signature} =~ s/\r//g;
1288 # if we send html or plain text inline
1289 if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
1290 $mail->{contenttype} = "text/html";
1292 $mail->{message} =~ s/\r//g;
1293 $mail->{message} =~ s/\n/<br>\n/g;
1294 $myconfig->{signature} =~ s/\n/<br>\n/g;
1295 $mail->{message} .= "<br>\n-- <br>\n$myconfig->{signature}\n<br>";
1297 open(IN, $self->{tmpfile})
1298 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
1300 $mail->{message} .= $_;
1307 if (!$self->{"do_not_attach"}) {
1308 my $attachment_name = $self->{attachment_filename} || $self->{tmpfile};
1309 $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format);
1310 $mail->{attachments} = [{ "filename" => $self->{tmpfile},
1311 "name" => $attachment_name }];
1314 $mail->{message} =~ s/\r//g;
1315 $mail->{message} .= "\n-- \n$myconfig->{signature}";
1319 my $err = $mail->send();
1320 $self->error($self->cleanup . "$err") if ($err);
1324 $self->{OUT} = $out;
1326 my $numbytes = (-s $self->{tmpfile});
1327 open(IN, $self->{tmpfile})
1328 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
1330 $self->{copies} = 1 unless $self->{media} eq 'printer';
1332 chdir("$self->{cwd}");
1333 #print(STDERR "Kopien $self->{copies}\n");
1334 #print(STDERR "OUT $self->{OUT}\n");
1335 for my $i (1 .. $self->{copies}) {
1337 open(OUT, $self->{OUT})
1338 or $self->error($self->cleanup . "$self->{OUT} : $!");
1340 $self->{attachment_filename} = ($self->{attachment_filename})
1341 ? $self->{attachment_filename}
1342 : $self->generate_attachment_filename();
1344 # launch application
1345 print qq|Content-Type: | . $template->get_mime_type() . qq|
1346 Content-Disposition: attachment; filename="$self->{attachment_filename}"
1347 Content-Length: $numbytes
1351 open(OUT, ">-") or $self->error($self->cleanup . "$!: STDOUT");
1372 chdir("$self->{cwd}");
1373 $main::lxdebug->leave_sub();
1376 sub get_formname_translation {
1377 $main::lxdebug->enter_sub();
1378 my ($self, $formname) = @_;
1380 $formname ||= $self->{formname};
1382 my %formname_translations = (
1383 bin_list => $main::locale->text('Bin List'),
1384 credit_note => $main::locale->text('Credit Note'),
1385 invoice => $main::locale->text('Invoice'),
1386 packing_list => $main::locale->text('Packing List'),
1387 pick_list => $main::locale->text('Pick List'),
1388 proforma => $main::locale->text('Proforma Invoice'),
1389 purchase_order => $main::locale->text('Purchase Order'),
1390 request_quotation => $main::locale->text('RFQ'),
1391 sales_order => $main::locale->text('Confirmation'),
1392 sales_quotation => $main::locale->text('Quotation'),
1393 storno_invoice => $main::locale->text('Storno Invoice'),
1394 storno_packing_list => $main::locale->text('Storno Packing List'),
1395 sales_delivery_order => $main::locale->text('Delivery Order'),
1396 purchase_delivery_order => $main::locale->text('Delivery Order'),
1397 dunning => $main::locale->text('Dunning'),
1400 $main::lxdebug->leave_sub();
1401 return $formname_translations{$formname}
1404 sub get_number_prefix_for_type {
1405 $main::lxdebug->enter_sub();
1409 (first { $self->{type} eq $_ } qw(invoice credit_note)) ? 'inv'
1410 : ($self->{type} =~ /_quotation$/) ? 'quo'
1411 : ($self->{type} =~ /_delivery_order$/) ? 'do'
1414 $main::lxdebug->leave_sub();
1418 sub get_extension_for_format {
1419 $main::lxdebug->enter_sub();
1422 my $extension = $self->{format} =~ /pdf/i ? ".pdf"
1423 : $self->{format} =~ /postscript/i ? ".ps"
1424 : $self->{format} =~ /opendocument/i ? ".odt"
1425 : $self->{format} =~ /excel/i ? ".xls"
1426 : $self->{format} =~ /html/i ? ".html"
1429 $main::lxdebug->leave_sub();
1433 sub generate_attachment_filename {
1434 $main::lxdebug->enter_sub();
1437 my $attachment_filename = $main::locale->unquote_special_chars('HTML', $self->get_formname_translation());
1438 my $prefix = $self->get_number_prefix_for_type();
1440 if ($self->{preview} && (first { $self->{type} eq $_ } qw(invoice credit_note))) {
1441 $attachment_filename .= ' (' . $main::locale->text('Preview') . ')' . $self->get_extension_for_format();
1443 } elsif ($attachment_filename && $self->{"${prefix}number"}) {
1444 $attachment_filename .= "_" . $self->{"${prefix}number"} . $self->get_extension_for_format();
1447 $attachment_filename = "";
1450 $attachment_filename = $main::locale->quote_special_chars('filenames', $attachment_filename);
1451 $attachment_filename =~ s|[\s/\\]+|_|g;
1453 $main::lxdebug->leave_sub();
1454 return $attachment_filename;
1457 sub generate_email_subject {
1458 $main::lxdebug->enter_sub();
1461 my $subject = $main::locale->unquote_special_chars('HTML', $self->get_formname_translation());
1462 my $prefix = $self->get_number_prefix_for_type();
1464 if ($subject && $self->{"${prefix}number"}) {
1465 $subject .= " " . $self->{"${prefix}number"}
1468 $main::lxdebug->leave_sub();
1473 $main::lxdebug->enter_sub();
1477 chdir("$self->{tmpdir}");
1480 if (-f "$self->{tmpfile}.err") {
1481 open(FH, "$self->{tmpfile}.err");
1486 if ($self->{tmpfile} && ! $::keep_temp_files) {
1487 $self->{tmpfile} =~ s|.*/||g;
1489 $self->{tmpfile} =~ s/\.\w+$//g;
1490 my $tmpfile = $self->{tmpfile};
1491 unlink(<$tmpfile.*>);
1494 chdir("$self->{cwd}");
1496 $main::lxdebug->leave_sub();
1502 $main::lxdebug->enter_sub();
1504 my ($self, $date, $myconfig) = @_;
1507 if ($date && $date =~ /\D/) {
1509 if ($myconfig->{dateformat} =~ /^yy/) {
1510 ($yy, $mm, $dd) = split /\D/, $date;
1512 if ($myconfig->{dateformat} =~ /^mm/) {
1513 ($mm, $dd, $yy) = split /\D/, $date;
1515 if ($myconfig->{dateformat} =~ /^dd/) {
1516 ($dd, $mm, $yy) = split /\D/, $date;
1521 $yy = ($yy < 70) ? $yy + 2000 : $yy;
1522 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
1524 $dd = "0$dd" if ($dd < 10);
1525 $mm = "0$mm" if ($mm < 10);
1527 $date = "$yy$mm$dd";
1530 $main::lxdebug->leave_sub();
1535 # Database routines used throughout
1538 $main::lxdebug->enter_sub(2);
1540 my ($self, $myconfig) = @_;
1542 # connect to database
1544 DBI->connect($myconfig->{dbconnect},
1545 $myconfig->{dbuser}, $myconfig->{dbpasswd})
1549 if ($myconfig->{dboptions}) {
1550 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1553 $main::lxdebug->leave_sub(2);
1558 sub dbconnect_noauto {
1559 $main::lxdebug->enter_sub();
1561 my ($self, $myconfig) = @_;
1563 # connect to database
1565 DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser},
1566 $myconfig->{dbpasswd}, { AutoCommit => 0 })
1570 if ($myconfig->{dboptions}) {
1571 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1574 $main::lxdebug->leave_sub();
1579 sub get_standard_dbh {
1580 $main::lxdebug->enter_sub(2);
1582 my ($self, $myconfig) = @_;
1584 if ($standard_dbh && !$standard_dbh->{Active}) {
1585 $main::lxdebug->message(LXDebug->INFO(), "get_standard_dbh: \$standard_dbh is defined but not Active anymore");
1586 undef $standard_dbh;
1589 $standard_dbh ||= $self->dbconnect_noauto($myconfig);
1591 $main::lxdebug->leave_sub(2);
1593 return $standard_dbh;
1597 $main::lxdebug->enter_sub();
1599 my ($self, $date, $myconfig) = @_;
1600 my $dbh = $self->dbconnect($myconfig);
1602 my $query = "SELECT 1 FROM defaults WHERE ? < closedto";
1603 my $sth = prepare_execute_query($self, $dbh, $query, $date);
1604 my ($closed) = $sth->fetchrow_array;
1606 $main::lxdebug->leave_sub();
1611 sub update_balance {
1612 $main::lxdebug->enter_sub();
1614 my ($self, $dbh, $table, $field, $where, $value, @values) = @_;
1616 # if we have a value, go do it
1619 # retrieve balance from table
1620 my $query = "SELECT $field FROM $table WHERE $where FOR UPDATE";
1621 my $sth = prepare_execute_query($self, $dbh, $query, @values);
1622 my ($balance) = $sth->fetchrow_array;
1628 $query = "UPDATE $table SET $field = $balance WHERE $where";
1629 do_query($self, $dbh, $query, @values);
1631 $main::lxdebug->leave_sub();
1634 sub update_exchangerate {
1635 $main::lxdebug->enter_sub();
1637 my ($self, $dbh, $curr, $transdate, $buy, $sell) = @_;
1639 # some sanity check for currency
1641 $main::lxdebug->leave_sub();
1644 $query = qq|SELECT curr FROM defaults|;
1646 my ($currency) = selectrow_query($self, $dbh, $query);
1647 my ($defaultcurrency) = split m/:/, $currency;
1650 if ($curr eq $defaultcurrency) {
1651 $main::lxdebug->leave_sub();
1655 $query = qq|SELECT e.curr FROM exchangerate e
1656 WHERE e.curr = ? AND e.transdate = ?
1658 my $sth = prepare_execute_query($self, $dbh, $query, $curr, $transdate);
1667 $buy = conv_i($buy, "NULL");
1668 $sell = conv_i($sell, "NULL");
1671 if ($buy != 0 && $sell != 0) {
1672 $set = "buy = $buy, sell = $sell";
1673 } elsif ($buy != 0) {
1674 $set = "buy = $buy";
1675 } elsif ($sell != 0) {
1676 $set = "sell = $sell";
1679 if ($sth->fetchrow_array) {
1680 $query = qq|UPDATE exchangerate
1686 $query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
1687 VALUES (?, $buy, $sell, ?)|;
1690 do_query($self, $dbh, $query, $curr, $transdate);
1692 $main::lxdebug->leave_sub();
1695 sub save_exchangerate {
1696 $main::lxdebug->enter_sub();
1698 my ($self, $myconfig, $currency, $transdate, $rate, $fld) = @_;
1700 my $dbh = $self->dbconnect($myconfig);
1704 $buy = $rate if $fld eq 'buy';
1705 $sell = $rate if $fld eq 'sell';
1708 $self->update_exchangerate($dbh, $currency, $transdate, $buy, $sell);
1713 $main::lxdebug->leave_sub();
1716 sub get_exchangerate {
1717 $main::lxdebug->enter_sub();
1719 my ($self, $dbh, $curr, $transdate, $fld) = @_;
1722 unless ($transdate) {
1723 $main::lxdebug->leave_sub();
1727 $query = qq|SELECT curr FROM defaults|;
1729 my ($currency) = selectrow_query($self, $dbh, $query);
1730 my ($defaultcurrency) = split m/:/, $currency;
1732 if ($currency eq $defaultcurrency) {
1733 $main::lxdebug->leave_sub();
1737 $query = qq|SELECT e.$fld FROM exchangerate e
1738 WHERE e.curr = ? AND e.transdate = ?|;
1739 my ($exchangerate) = selectrow_query($self, $dbh, $query, $curr, $transdate);
1743 $main::lxdebug->leave_sub();
1745 return $exchangerate;
1748 sub check_exchangerate {
1749 $main::lxdebug->enter_sub();
1751 my ($self, $myconfig, $currency, $transdate, $fld) = @_;
1753 if ($fld !~/^buy|sell$/) {
1754 $self->error('Fatal: check_exchangerate called with invalid buy/sell argument');
1757 unless ($transdate) {
1758 $main::lxdebug->leave_sub();
1762 my ($defaultcurrency) = $self->get_default_currency($myconfig);
1764 if ($currency eq $defaultcurrency) {
1765 $main::lxdebug->leave_sub();
1769 my $dbh = $self->get_standard_dbh($myconfig);
1770 my $query = qq|SELECT e.$fld FROM exchangerate e
1771 WHERE e.curr = ? AND e.transdate = ?|;
1773 my ($exchangerate) = selectrow_query($self, $dbh, $query, $currency, $transdate);
1775 $main::lxdebug->leave_sub();
1777 return $exchangerate;
1780 sub get_all_currencies {
1781 $main::lxdebug->enter_sub();
1783 my ($self, $myconfig) = @_;
1784 my $dbh = $self->get_standard_dbh($myconfig);
1786 my $query = qq|SELECT curr FROM defaults|;
1788 my ($curr) = selectrow_query($self, $dbh, $query);
1789 my @currencies = grep { $_ } map { s/\s//g; $_ } split m/:/, $curr;
1791 $main::lxdebug->leave_sub();
1796 sub get_default_currency {
1797 $main::lxdebug->enter_sub();
1799 my ($self, $myconfig) = @_;
1800 my @currencies = $self->get_all_currencies($myconfig);
1802 $main::lxdebug->leave_sub();
1804 return $currencies[0];
1807 sub set_payment_options {
1808 $main::lxdebug->enter_sub();
1810 my ($self, $myconfig, $transdate) = @_;
1812 return $main::lxdebug->leave_sub() unless ($self->{payment_id});
1814 my $dbh = $self->get_standard_dbh($myconfig);
1817 qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, p.description_long | .
1818 qq|FROM payment_terms p | .
1821 ($self->{terms_netto}, $self->{terms_skonto}, $self->{percent_skonto},
1822 $self->{payment_terms}) =
1823 selectrow_query($self, $dbh, $query, $self->{payment_id});
1825 if ($transdate eq "") {
1826 if ($self->{invdate}) {
1827 $transdate = $self->{invdate};
1829 $transdate = $self->{transdate};
1834 qq|SELECT ?::date + ?::integer AS netto_date, ?::date + ?::integer AS skonto_date | .
1835 qq|FROM payment_terms|;
1836 ($self->{netto_date}, $self->{skonto_date}) =
1837 selectrow_query($self, $dbh, $query, $transdate, $self->{terms_netto}, $transdate, $self->{terms_skonto});
1839 my ($invtotal, $total);
1840 my (%amounts, %formatted_amounts);
1842 if ($self->{type} =~ /_order$/) {
1843 $amounts{invtotal} = $self->{ordtotal};
1844 $amounts{total} = $self->{ordtotal};
1846 } elsif ($self->{type} =~ /_quotation$/) {
1847 $amounts{invtotal} = $self->{quototal};
1848 $amounts{total} = $self->{quototal};
1851 $amounts{invtotal} = $self->{invtotal};
1852 $amounts{total} = $self->{total};
1854 $amounts{skonto_in_percent} = 100.0 * $self->{percent_skonto};
1856 map { $amounts{$_} = $self->parse_amount($myconfig, $amounts{$_}) } keys %amounts;
1858 $amounts{skonto_amount} = $amounts{invtotal} * $self->{percent_skonto};
1859 $amounts{invtotal_wo_skonto} = $amounts{invtotal} * (1 - $self->{percent_skonto});
1860 $amounts{total_wo_skonto} = $amounts{total} * (1 - $self->{percent_skonto});
1862 foreach (keys %amounts) {
1863 $amounts{$_} = $self->round_amount($amounts{$_}, 2);
1864 $formatted_amounts{$_} = $self->format_amount($myconfig, $amounts{$_}, 2);
1867 if ($self->{"language_id"}) {
1869 qq|SELECT t.description_long, l.output_numberformat, l.output_dateformat, l.output_longdates | .
1870 qq|FROM translation_payment_terms t | .
1871 qq|LEFT JOIN language l ON t.language_id = l.id | .
1872 qq|WHERE (t.language_id = ?) AND (t.payment_terms_id = ?)|;
1873 my ($description_long, $output_numberformat, $output_dateformat,
1874 $output_longdates) =
1875 selectrow_query($self, $dbh, $query,
1876 $self->{"language_id"}, $self->{"payment_id"});
1878 $self->{payment_terms} = $description_long if ($description_long);
1880 if ($output_dateformat) {
1881 foreach my $key (qw(netto_date skonto_date)) {
1883 $main::locale->reformat_date($myconfig, $self->{$key},
1889 if ($output_numberformat &&
1890 ($output_numberformat ne $myconfig->{"numberformat"})) {
1891 my $saved_numberformat = $myconfig->{"numberformat"};
1892 $myconfig->{"numberformat"} = $output_numberformat;
1893 map { $formatted_amounts{$_} = $self->format_amount($myconfig, $amounts{$_}) } keys %amounts;
1894 $myconfig->{"numberformat"} = $saved_numberformat;
1898 $self->{payment_terms} =~ s/<%netto_date%>/$self->{netto_date}/g;
1899 $self->{payment_terms} =~ s/<%skonto_date%>/$self->{skonto_date}/g;
1900 $self->{payment_terms} =~ s/<%currency%>/$self->{currency}/g;
1901 $self->{payment_terms} =~ s/<%terms_netto%>/$self->{terms_netto}/g;
1902 $self->{payment_terms} =~ s/<%account_number%>/$self->{account_number}/g;
1903 $self->{payment_terms} =~ s/<%bank%>/$self->{bank}/g;
1904 $self->{payment_terms} =~ s/<%bank_code%>/$self->{bank_code}/g;
1906 map { $self->{payment_terms} =~ s/<%${_}%>/$formatted_amounts{$_}/g; } keys %formatted_amounts;
1908 $self->{skonto_in_percent} = $formatted_amounts{skonto_in_percent};
1910 $main::lxdebug->leave_sub();
1914 sub get_template_language {
1915 $main::lxdebug->enter_sub();
1917 my ($self, $myconfig) = @_;
1919 my $template_code = "";
1921 if ($self->{language_id}) {
1922 my $dbh = $self->get_standard_dbh($myconfig);
1923 my $query = qq|SELECT template_code FROM language WHERE id = ?|;
1924 ($template_code) = selectrow_query($self, $dbh, $query, $self->{language_id});
1927 $main::lxdebug->leave_sub();
1929 return $template_code;
1932 sub get_printer_code {
1933 $main::lxdebug->enter_sub();
1935 my ($self, $myconfig) = @_;
1937 my $template_code = "";
1939 if ($self->{printer_id}) {
1940 my $dbh = $self->get_standard_dbh($myconfig);
1941 my $query = qq|SELECT template_code, printer_command FROM printers WHERE id = ?|;
1942 ($template_code, $self->{printer_command}) = selectrow_query($self, $dbh, $query, $self->{printer_id});
1945 $main::lxdebug->leave_sub();
1947 return $template_code;
1951 $main::lxdebug->enter_sub();
1953 my ($self, $myconfig) = @_;
1955 my $template_code = "";
1957 if ($self->{shipto_id}) {
1958 my $dbh = $self->get_standard_dbh($myconfig);
1959 my $query = qq|SELECT * FROM shipto WHERE shipto_id = ?|;
1960 my $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{shipto_id});
1961 map({ $self->{$_} = $ref->{$_} } keys(%$ref));
1964 $main::lxdebug->leave_sub();
1968 $main::lxdebug->enter_sub();
1970 my ($self, $dbh, $id, $module) = @_;
1975 foreach my $item (qw(name department_1 department_2 street zipcode city country
1976 contact phone fax email)) {
1977 if ($self->{"shipto$item"}) {
1978 $shipto = 1 if ($self->{$item} ne $self->{"shipto$item"});
1980 push(@values, $self->{"shipto${item}"});
1984 if ($self->{shipto_id}) {
1985 my $query = qq|UPDATE shipto set
1987 shiptodepartment_1 = ?,
1988 shiptodepartment_2 = ?,
1997 WHERE shipto_id = ?|;
1998 do_query($self, $dbh, $query, @values, $self->{shipto_id});
2000 my $query = qq|SELECT * FROM shipto
2001 WHERE shiptoname = ? AND
2002 shiptodepartment_1 = ? AND
2003 shiptodepartment_2 = ? AND
2004 shiptostreet = ? AND
2005 shiptozipcode = ? AND
2007 shiptocountry = ? AND
2008 shiptocontact = ? AND
2014 my $insert_check = selectfirst_hashref_query($self, $dbh, $query, @values, $module, $id);
2017 qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2,
2018 shiptostreet, shiptozipcode, shiptocity, shiptocountry,
2019 shiptocontact, shiptophone, shiptofax, shiptoemail, module)
2020 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
2021 do_query($self, $dbh, $query, $id, @values, $module);
2026 $main::lxdebug->leave_sub();
2030 $main::lxdebug->enter_sub();
2032 my ($self, $dbh) = @_;
2034 $dbh ||= $self->get_standard_dbh(\%main::myconfig);
2036 my $query = qq|SELECT id, name FROM employee WHERE login = ?|;
2037 ($self->{"employee_id"}, $self->{"employee"}) = selectrow_query($self, $dbh, $query, $self->{login});
2038 $self->{"employee_id"} *= 1;
2040 $main::lxdebug->leave_sub();
2043 sub get_employee_data {
2044 $main::lxdebug->enter_sub();
2049 Common::check_params(\%params, qw(prefix));
2050 Common::check_params_x(\%params, qw(id));
2053 $main::lxdebug->leave_sub();
2057 my $myconfig = \%main::myconfig;
2058 my $dbh = $params{dbh} || $self->get_standard_dbh($myconfig);
2060 my ($login) = selectrow_query($self, $dbh, qq|SELECT login FROM employee WHERE id = ?|, conv_i($params{id}));
2063 my $user = User->new($login);
2064 map { $self->{$params{prefix} . "_${_}"} = $user->{$_}; } qw(address businessnumber co_ustid company duns email fax name signature taxnumber tel);
2066 $self->{$params{prefix} . '_login'} = $login;
2067 $self->{$params{prefix} . '_name'} ||= $login;
2070 $main::lxdebug->leave_sub();
2074 $main::lxdebug->enter_sub();
2076 my ($self, $myconfig, $reference_date) = @_;
2078 $reference_date = $reference_date ? conv_dateq($reference_date) . '::DATE' : 'current_date';
2080 my $dbh = $self->get_standard_dbh($myconfig);
2081 my $query = qq|SELECT ${reference_date} + terms_netto FROM payment_terms WHERE id = ?|;
2082 my ($duedate) = selectrow_query($self, $dbh, $query, $self->{payment_id});
2084 $main::lxdebug->leave_sub();
2090 $main::lxdebug->enter_sub();
2092 my ($self, $dbh, $id, $key) = @_;
2094 $key = "all_contacts" unless ($key);
2098 $main::lxdebug->leave_sub();
2103 qq|SELECT cp_id, cp_cv_id, cp_name, cp_givenname, cp_abteilung | .
2104 qq|FROM contacts | .
2105 qq|WHERE cp_cv_id = ? | .
2106 qq|ORDER BY lower(cp_name)|;
2108 $self->{$key} = selectall_hashref_query($self, $dbh, $query, $id);
2110 $main::lxdebug->leave_sub();
2114 $main::lxdebug->enter_sub();
2116 my ($self, $dbh, $key) = @_;
2118 my ($all, $old_id, $where, @values);
2120 if (ref($key) eq "HASH") {
2123 $key = "ALL_PROJECTS";
2125 foreach my $p (keys(%{$params})) {
2127 $all = $params->{$p};
2128 } elsif ($p eq "old_id") {
2129 $old_id = $params->{$p};
2130 } elsif ($p eq "key") {
2131 $key = $params->{$p};
2137 $where = "WHERE active ";
2139 if (ref($old_id) eq "ARRAY") {
2140 my @ids = grep({ $_ } @{$old_id});
2142 $where .= " OR id IN (" . join(",", map({ "?" } @ids)) . ") ";
2143 push(@values, @ids);
2146 $where .= " OR (id = ?) ";
2147 push(@values, $old_id);
2153 qq|SELECT id, projectnumber, description, active | .
2156 qq|ORDER BY lower(projectnumber)|;
2158 $self->{$key} = selectall_hashref_query($self, $dbh, $query, @values);
2160 $main::lxdebug->leave_sub();
2164 $main::lxdebug->enter_sub();
2166 my ($self, $dbh, $vc_id, $key) = @_;
2168 $key = "all_shipto" unless ($key);
2171 # get shipping addresses
2172 my $query = qq|SELECT * FROM shipto WHERE trans_id = ?|;
2174 $self->{$key} = selectall_hashref_query($self, $dbh, $query, $vc_id);
2180 $main::lxdebug->leave_sub();
2184 $main::lxdebug->enter_sub();
2186 my ($self, $dbh, $key) = @_;
2188 $key = "all_printers" unless ($key);
2190 my $query = qq|SELECT id, printer_description, printer_command, template_code FROM printers|;
2192 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2194 $main::lxdebug->leave_sub();
2198 $main::lxdebug->enter_sub();
2200 my ($self, $dbh, $params) = @_;
2203 $key = $params->{key};
2204 $key = "all_charts" unless ($key);
2206 my $transdate = quote_db_date($params->{transdate});
2209 qq|SELECT c.id, c.accno, c.description, c.link, c.charttype, tk.taxkey_id, tk.tax_id | .
2211 qq|LEFT JOIN taxkeys tk ON | .
2212 qq|(tk.id = (SELECT id FROM taxkeys | .
2213 qq| WHERE taxkeys.chart_id = c.id AND startdate <= $transdate | .
2214 qq| ORDER BY startdate DESC LIMIT 1)) | .
2215 qq|ORDER BY c.accno|;
2217 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2219 $main::lxdebug->leave_sub();
2222 sub _get_taxcharts {
2223 $main::lxdebug->enter_sub();
2225 my ($self, $dbh, $params) = @_;
2227 my $key = "all_taxcharts";
2230 if (ref $params eq 'HASH') {
2231 $key = $params->{key} if ($params->{key});
2232 if ($params->{module} eq 'AR') {
2233 push @where, 'taxkey NOT IN (8, 9, 18, 19)';
2235 } elsif ($params->{module} eq 'AP') {
2236 push @where, 'taxkey NOT IN (1, 2, 3, 12, 13)';
2243 my $where = ' WHERE ' . join(' AND ', map { "($_)" } @where) if (@where);
2245 my $query = qq|SELECT * FROM tax $where ORDER BY taxkey|;
2247 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2249 $main::lxdebug->leave_sub();
2253 $main::lxdebug->enter_sub();
2255 my ($self, $dbh, $key) = @_;
2257 $key = "all_taxzones" unless ($key);
2259 my $query = qq|SELECT * FROM tax_zones ORDER BY id|;
2261 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2263 $main::lxdebug->leave_sub();
2266 sub _get_employees {
2267 $main::lxdebug->enter_sub();
2269 my ($self, $dbh, $default_key, $key) = @_;
2271 $key = $default_key unless ($key);
2272 $self->{$key} = selectall_hashref_query($self, $dbh, qq|SELECT * FROM employee ORDER BY lower(name)|);
2274 $main::lxdebug->leave_sub();
2277 sub _get_business_types {
2278 $main::lxdebug->enter_sub();
2280 my ($self, $dbh, $key) = @_;
2282 my $options = ref $key eq 'HASH' ? $key : { key => $key };
2283 $options->{key} ||= "all_business_types";
2286 if (exists $options->{salesman}) {
2287 $where = 'WHERE ' . ($options->{salesman} ? '' : 'NOT ') . 'COALESCE(salesman)';
2290 $self->{ $options->{key} } = selectall_hashref_query($self, $dbh, qq|SELECT * FROM business $where ORDER BY lower(description)|);
2292 $main::lxdebug->leave_sub();
2295 sub _get_languages {
2296 $main::lxdebug->enter_sub();
2298 my ($self, $dbh, $key) = @_;
2300 $key = "all_languages" unless ($key);
2302 my $query = qq|SELECT * FROM language ORDER BY id|;
2304 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2306 $main::lxdebug->leave_sub();
2309 sub _get_dunning_configs {
2310 $main::lxdebug->enter_sub();
2312 my ($self, $dbh, $key) = @_;
2314 $key = "all_dunning_configs" unless ($key);
2316 my $query = qq|SELECT * FROM dunning_config ORDER BY dunning_level|;
2318 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2320 $main::lxdebug->leave_sub();
2323 sub _get_currencies {
2324 $main::lxdebug->enter_sub();
2326 my ($self, $dbh, $key) = @_;
2328 $key = "all_currencies" unless ($key);
2330 my $query = qq|SELECT curr AS currency FROM defaults|;
2332 $self->{$key} = [split(/\:/ , selectfirst_hashref_query($self, $dbh, $query)->{currency})];
2334 $main::lxdebug->leave_sub();
2338 $main::lxdebug->enter_sub();
2340 my ($self, $dbh, $key) = @_;
2342 $key = "all_payments" unless ($key);
2344 my $query = qq|SELECT * FROM payment_terms ORDER BY id|;
2346 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2348 $main::lxdebug->leave_sub();
2351 sub _get_customers {
2352 $main::lxdebug->enter_sub();
2354 my ($self, $dbh, $key) = @_;
2356 my $options = ref $key eq 'HASH' ? $key : { key => $key };
2357 $options->{key} ||= "all_customers";
2358 my $limit_clause = "LIMIT $options->{limit}" if $options->{limit};
2359 my $where = $options->{business_is_salesman} ? qq| AND business_id IN (SELECT id FROM business WHERE salesman)| : '';
2361 my $query = qq|SELECT * FROM customer WHERE NOT obsolete $where ORDER BY name $limit_clause|;
2362 $self->{ $options->{key} } = selectall_hashref_query($self, $dbh, $query);
2364 $main::lxdebug->leave_sub();
2368 $main::lxdebug->enter_sub();
2370 my ($self, $dbh, $key) = @_;
2372 $key = "all_vendors" unless ($key);
2374 my $query = qq|SELECT * FROM vendor WHERE NOT obsolete ORDER BY name|;
2376 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2378 $main::lxdebug->leave_sub();
2381 sub _get_departments {
2382 $main::lxdebug->enter_sub();
2384 my ($self, $dbh, $key) = @_;
2386 $key = "all_departments" unless ($key);
2388 my $query = qq|SELECT * FROM department ORDER BY description|;
2390 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2392 $main::lxdebug->leave_sub();
2395 sub _get_warehouses {
2396 $main::lxdebug->enter_sub();
2398 my ($self, $dbh, $param) = @_;
2400 my ($key, $bins_key);
2402 if ('' eq ref $param) {
2406 $key = $param->{key};
2407 $bins_key = $param->{bins};
2410 my $query = qq|SELECT w.* FROM warehouse w
2411 WHERE (NOT w.invalid) AND
2412 ((SELECT COUNT(b.*) FROM bin b WHERE b.warehouse_id = w.id) > 0)
2413 ORDER BY w.sortkey|;
2415 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2418 $query = qq|SELECT id, description FROM bin WHERE warehouse_id = ?|;
2419 my $sth = prepare_query($self, $dbh, $query);
2421 foreach my $warehouse (@{ $self->{$key} }) {
2422 do_statement($self, $sth, $query, $warehouse->{id});
2423 $warehouse->{$bins_key} = [];
2425 while (my $ref = $sth->fetchrow_hashref()) {
2426 push @{ $warehouse->{$bins_key} }, $ref;
2432 $main::lxdebug->leave_sub();
2436 $main::lxdebug->enter_sub();
2438 my ($self, $dbh, $table, $key, $sortkey) = @_;
2440 my $query = qq|SELECT * FROM $table|;
2441 $query .= qq| ORDER BY $sortkey| if ($sortkey);
2443 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2445 $main::lxdebug->leave_sub();
2449 # $main::lxdebug->enter_sub();
2451 # my ($self, $dbh, $key) = @_;
2453 # $key ||= "all_groups";
2455 # my $groups = $main::auth->read_groups();
2457 # $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2459 # $main::lxdebug->leave_sub();
2463 $main::lxdebug->enter_sub();
2468 my $dbh = $self->get_standard_dbh(\%main::myconfig);
2469 my ($sth, $query, $ref);
2471 my $vc = $self->{"vc"} eq "customer" ? "customer" : "vendor";
2472 my $vc_id = $self->{"${vc}_id"};
2474 if ($params{"contacts"}) {
2475 $self->_get_contacts($dbh, $vc_id, $params{"contacts"});
2478 if ($params{"shipto"}) {
2479 $self->_get_shipto($dbh, $vc_id, $params{"shipto"});
2482 if ($params{"projects"} || $params{"all_projects"}) {
2483 $self->_get_projects($dbh, $params{"all_projects"} ?
2484 $params{"all_projects"} : $params{"projects"},
2485 $params{"all_projects"} ? 1 : 0);
2488 if ($params{"printers"}) {
2489 $self->_get_printers($dbh, $params{"printers"});
2492 if ($params{"languages"}) {
2493 $self->_get_languages($dbh, $params{"languages"});
2496 if ($params{"charts"}) {
2497 $self->_get_charts($dbh, $params{"charts"});
2500 if ($params{"taxcharts"}) {
2501 $self->_get_taxcharts($dbh, $params{"taxcharts"});
2504 if ($params{"taxzones"}) {
2505 $self->_get_taxzones($dbh, $params{"taxzones"});
2508 if ($params{"employees"}) {
2509 $self->_get_employees($dbh, "all_employees", $params{"employees"});
2512 if ($params{"salesmen"}) {
2513 $self->_get_employees($dbh, "all_salesmen", $params{"salesmen"});
2516 if ($params{"business_types"}) {
2517 $self->_get_business_types($dbh, $params{"business_types"});
2520 if ($params{"dunning_configs"}) {
2521 $self->_get_dunning_configs($dbh, $params{"dunning_configs"});
2524 if($params{"currencies"}) {
2525 $self->_get_currencies($dbh, $params{"currencies"});
2528 if($params{"customers"}) {
2529 $self->_get_customers($dbh, $params{"customers"});
2532 if($params{"vendors"}) {
2533 if (ref $params{"vendors"} eq 'HASH') {
2534 $self->_get_vendors($dbh, $params{"vendors"}{key}, $params{"vendors"}{limit});
2536 $self->_get_vendors($dbh, $params{"vendors"});
2540 if($params{"payments"}) {
2541 $self->_get_payments($dbh, $params{"payments"});
2544 if($params{"departments"}) {
2545 $self->_get_departments($dbh, $params{"departments"});
2548 if ($params{price_factors}) {
2549 $self->_get_simple($dbh, 'price_factors', $params{price_factors}, 'sortkey');
2552 if ($params{warehouses}) {
2553 $self->_get_warehouses($dbh, $params{warehouses});
2556 # if ($params{groups}) {
2557 # $self->_get_groups($dbh, $params{groups});
2560 if ($params{partsgroup}) {
2561 $self->get_partsgroup(\%main::myconfig, { all => 1, target => $params{partsgroup} });
2564 $main::lxdebug->leave_sub();
2567 # this sub gets the id and name from $table
2569 $main::lxdebug->enter_sub();
2571 my ($self, $myconfig, $table) = @_;
2573 # connect to database
2574 my $dbh = $self->get_standard_dbh($myconfig);
2576 $table = $table eq "customer" ? "customer" : "vendor";
2577 my $arap = $self->{arap} eq "ar" ? "ar" : "ap";
2579 my ($query, @values);
2581 if (!$self->{openinvoices}) {
2583 if ($self->{customernumber} ne "") {
2584 $where = qq|(vc.customernumber ILIKE ?)|;
2585 push(@values, '%' . $self->{customernumber} . '%');
2587 $where = qq|(vc.name ILIKE ?)|;
2588 push(@values, '%' . $self->{$table} . '%');
2592 qq~SELECT vc.id, vc.name,
2593 vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
2595 WHERE $where AND (NOT vc.obsolete)
2599 qq~SELECT DISTINCT vc.id, vc.name,
2600 vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
2602 JOIN $table vc ON (a.${table}_id = vc.id)
2603 WHERE NOT (a.amount = a.paid) AND (vc.name ILIKE ?)
2605 push(@values, '%' . $self->{$table} . '%');
2608 $self->{name_list} = selectall_hashref_query($self, $dbh, $query, @values);
2610 $main::lxdebug->leave_sub();
2612 return scalar(@{ $self->{name_list} });
2615 # the selection sub is used in the AR, AP, IS, IR and OE module
2618 $main::lxdebug->enter_sub();
2620 my ($self, $myconfig, $table, $module) = @_;
2623 my $dbh = $self->get_standard_dbh($myconfig);
2625 $table = $table eq "customer" ? "customer" : "vendor";
2627 my $query = qq|SELECT count(*) FROM $table|;
2628 my ($count) = selectrow_query($self, $dbh, $query);
2630 # build selection list
2631 if ($count <= $myconfig->{vclimit}) {
2632 $query = qq|SELECT id, name, salesman_id
2633 FROM $table WHERE NOT obsolete
2635 $self->{"all_$table"} = selectall_hashref_query($self, $dbh, $query);
2639 $self->get_employee($dbh);
2641 # setup sales contacts
2642 $query = qq|SELECT e.id, e.name
2644 WHERE (e.sales = '1') AND (NOT e.id = ?)|;
2645 $self->{all_employees} = selectall_hashref_query($self, $dbh, $query, $self->{employee_id});
2648 push(@{ $self->{all_employees} },
2649 { id => $self->{employee_id},
2650 name => $self->{employee} });
2652 # sort the whole thing
2653 @{ $self->{all_employees} } =
2654 sort { $a->{name} cmp $b->{name} } @{ $self->{all_employees} };
2656 if ($module eq 'AR') {
2658 # prepare query for departments
2659 $query = qq|SELECT id, description
2662 ORDER BY description|;
2665 $query = qq|SELECT id, description
2667 ORDER BY description|;
2670 $self->{all_departments} = selectall_hashref_query($self, $dbh, $query);
2673 $query = qq|SELECT id, description
2677 $self->{languages} = selectall_hashref_query($self, $dbh, $query);
2680 $query = qq|SELECT printer_description, id
2682 ORDER BY printer_description|;
2684 $self->{printers} = selectall_hashref_query($self, $dbh, $query);
2687 $query = qq|SELECT id, description
2691 $self->{payment_terms} = selectall_hashref_query($self, $dbh, $query);
2693 $main::lxdebug->leave_sub();
2696 sub language_payment {
2697 $main::lxdebug->enter_sub();
2699 my ($self, $myconfig) = @_;
2701 my $dbh = $self->get_standard_dbh($myconfig);
2703 my $query = qq|SELECT id, description
2707 $self->{languages} = selectall_hashref_query($self, $dbh, $query);
2710 $query = qq|SELECT printer_description, id
2712 ORDER BY printer_description|;
2714 $self->{printers} = selectall_hashref_query($self, $dbh, $query);
2717 $query = qq|SELECT id, description
2721 $self->{payment_terms} = selectall_hashref_query($self, $dbh, $query);
2723 # get buchungsgruppen
2724 $query = qq|SELECT id, description
2725 FROM buchungsgruppen|;
2727 $self->{BUCHUNGSGRUPPEN} = selectall_hashref_query($self, $dbh, $query);
2729 $main::lxdebug->leave_sub();
2732 # this is only used for reports
2733 sub all_departments {
2734 $main::lxdebug->enter_sub();
2736 my ($self, $myconfig, $table) = @_;
2738 my $dbh = $self->get_standard_dbh($myconfig);
2741 if ($table eq 'customer') {
2742 $where = "WHERE role = 'P' ";
2745 my $query = qq|SELECT id, description
2748 ORDER BY description|;
2749 $self->{all_departments} = selectall_hashref_query($self, $dbh, $query);
2751 delete($self->{all_departments}) unless (@{ $self->{all_departments} || [] });
2753 $main::lxdebug->leave_sub();
2757 $main::lxdebug->enter_sub();
2759 my ($self, $module, $myconfig, $table, $provided_dbh) = @_;
2762 if ($table eq "customer") {
2771 $self->all_vc($myconfig, $table, $module);
2773 # get last customers or vendors
2774 my ($query, $sth, $ref);
2776 my $dbh = $provided_dbh ? $provided_dbh : $self->get_standard_dbh($myconfig);
2781 my $transdate = "current_date";
2782 if ($self->{transdate}) {
2783 $transdate = $dbh->quote($self->{transdate});
2786 # now get the account numbers
2787 $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
2788 FROM chart c, taxkeys tk
2789 WHERE (c.link LIKE ?) AND (c.id = tk.chart_id) AND tk.id =
2790 (SELECT id FROM taxkeys WHERE (taxkeys.chart_id = c.id) AND (startdate <= $transdate) ORDER BY startdate DESC LIMIT 1)
2793 $sth = $dbh->prepare($query);
2795 do_statement($self, $sth, $query, '%' . $module . '%');
2797 $self->{accounts} = "";
2798 while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
2800 foreach my $key (split(/:/, $ref->{link})) {
2801 if ($key =~ /\Q$module\E/) {
2803 # cross reference for keys
2804 $xkeyref{ $ref->{accno} } = $key;
2806 push @{ $self->{"${module}_links"}{$key} },
2807 { accno => $ref->{accno},
2808 description => $ref->{description},
2809 taxkey => $ref->{taxkey_id},
2810 tax_id => $ref->{tax_id} };
2812 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2818 # get taxkeys and description
2819 $query = qq|SELECT id, taxkey, taxdescription FROM tax|;
2820 $self->{TAXKEY} = selectall_hashref_query($self, $dbh, $query);
2822 if (($module eq "AP") || ($module eq "AR")) {
2823 # get tax rates and description
2824 $query = qq|SELECT * FROM tax|;
2825 $self->{TAX} = selectall_hashref_query($self, $dbh, $query);
2831 a.cp_id, a.invnumber, a.transdate, a.${table}_id, a.datepaid,
2832 a.duedate, a.ordnumber, a.taxincluded, a.curr AS currency, a.notes,
2833 a.intnotes, a.department_id, a.amount AS oldinvtotal,
2834 a.paid AS oldtotalpaid, a.employee_id, a.gldate, a.type,
2836 d.description AS department,
2839 JOIN $table c ON (a.${table}_id = c.id)
2840 LEFT JOIN employee e ON (e.id = a.employee_id)
2841 LEFT JOIN department d ON (d.id = a.department_id)
2843 $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{id});
2845 foreach my $key (keys %$ref) {
2846 $self->{$key} = $ref->{$key};
2849 my $transdate = "current_date";
2850 if ($self->{transdate}) {
2851 $transdate = $dbh->quote($self->{transdate});
2854 # now get the account numbers
2855 $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
2857 LEFT JOIN taxkeys tk ON (tk.chart_id = c.id)
2859 AND (tk.id = (SELECT id FROM taxkeys WHERE taxkeys.chart_id = c.id AND startdate <= $transdate ORDER BY startdate DESC LIMIT 1)
2860 OR c.link LIKE '%_tax%' OR c.taxkey_id IS NULL)
2863 $sth = $dbh->prepare($query);
2864 do_statement($self, $sth, $query, "%$module%");
2866 $self->{accounts} = "";
2867 while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
2869 foreach my $key (split(/:/, $ref->{link})) {
2870 if ($key =~ /\Q$module\E/) {
2872 # cross reference for keys
2873 $xkeyref{ $ref->{accno} } = $key;
2875 push @{ $self->{"${module}_links"}{$key} },
2876 { accno => $ref->{accno},
2877 description => $ref->{description},
2878 taxkey => $ref->{taxkey_id},
2879 tax_id => $ref->{tax_id} };
2881 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2887 # get amounts from individual entries
2890 c.accno, c.description,
2891 a.source, a.amount, a.memo, a.transdate, a.cleared, a.project_id, a.taxkey,
2895 LEFT JOIN chart c ON (c.id = a.chart_id)
2896 LEFT JOIN project p ON (p.id = a.project_id)
2897 LEFT JOIN tax t ON (t.id= (SELECT tk.tax_id FROM taxkeys tk
2898 WHERE (tk.taxkey_id=a.taxkey) AND
2899 ((CASE WHEN a.chart_id IN (SELECT chart_id FROM taxkeys WHERE taxkey_id = a.taxkey)
2900 THEN tk.chart_id = a.chart_id
2903 OR (c.link='%tax%')) AND
2904 (startdate <= a.transdate) ORDER BY startdate DESC LIMIT 1))
2905 WHERE a.trans_id = ?
2906 AND a.fx_transaction = '0'
2907 ORDER BY a.acc_trans_id, a.transdate|;
2908 $sth = $dbh->prepare($query);
2909 do_statement($self, $sth, $query, $self->{id});
2911 # get exchangerate for currency
2912 $self->{exchangerate} =
2913 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate}, $fld);
2916 # store amounts in {acc_trans}{$key} for multiple accounts
2917 while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
2918 $ref->{exchangerate} =
2919 $self->get_exchangerate($dbh, $self->{currency}, $ref->{transdate}, $fld);
2920 if (!($xkeyref{ $ref->{accno} } =~ /tax/)) {
2923 if (($xkeyref{ $ref->{accno} } =~ /paid/) && ($self->{type} eq "credit_note")) {
2924 $ref->{amount} *= -1;
2926 $ref->{index} = $index;
2928 push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref;
2934 d.curr AS currencies, d.closedto, d.revtrans,
2935 (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2936 (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2938 $ref = selectfirst_hashref_query($self, $dbh, $query);
2939 map { $self->{$_} = $ref->{$_} } keys %$ref;
2946 current_date AS transdate, d.curr AS currencies, d.closedto, d.revtrans,
2947 (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2948 (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2950 $ref = selectfirst_hashref_query($self, $dbh, $query);
2951 map { $self->{$_} = $ref->{$_} } keys %$ref;
2953 if ($self->{"$self->{vc}_id"}) {
2955 # only setup currency
2956 ($self->{currency}) = split(/:/, $self->{currencies});
2960 $self->lastname_used($dbh, $myconfig, $table, $module);
2962 # get exchangerate for currency
2963 $self->{exchangerate} =
2964 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate}, $fld);
2970 $main::lxdebug->leave_sub();
2974 $main::lxdebug->enter_sub();
2976 my ($self, $dbh, $myconfig, $table, $module) = @_;
2980 $table = $table eq "customer" ? "customer" : "vendor";
2981 my %column_map = ("a.curr" => "currency",
2982 "a.${table}_id" => "${table}_id",
2983 "a.department_id" => "department_id",
2984 "d.description" => "department",
2985 "ct.name" => $table,
2986 "current_date + ct.terms" => "duedate",
2989 if ($self->{type} =~ /delivery_order/) {
2990 $arap = 'delivery_orders';
2991 delete $column_map{"a.curr"};
2993 } elsif ($self->{type} =~ /_order/) {
2995 $where = "quotation = '0'";
2997 } elsif ($self->{type} =~ /_quotation/) {
2999 $where = "quotation = '1'";
3001 } elsif ($table eq 'customer') {
3009 $where = "($where) AND" if ($where);
3010 my $query = qq|SELECT MAX(id) FROM $arap
3011 WHERE $where ${table}_id > 0|;
3012 my ($trans_id) = selectrow_query($self, $dbh, $query);
3015 my $column_spec = join(', ', map { "${_} AS $column_map{$_}" } keys %column_map);
3016 $query = qq|SELECT $column_spec
3018 LEFT JOIN $table ct ON (a.${table}_id = ct.id)
3019 LEFT JOIN department d ON (a.department_id = d.id)
3021 my $ref = selectfirst_hashref_query($self, $dbh, $query, $trans_id);
3023 map { $self->{$_} = $ref->{$_} } values %column_map;
3025 $main::lxdebug->leave_sub();
3029 $main::lxdebug->enter_sub();
3032 my $myconfig = shift || \%::myconfig;
3033 my ($thisdate, $days) = @_;
3035 my $dbh = $self->get_standard_dbh($myconfig);
3040 my $dateformat = $myconfig->{dateformat};
3041 $dateformat .= "yy" if $myconfig->{dateformat} !~ /^y/;
3042 $thisdate = $dbh->quote($thisdate);
3043 $query = qq|SELECT to_date($thisdate, '$dateformat') + $days AS thisdate|;
3045 $query = qq|SELECT current_date AS thisdate|;
3048 ($thisdate) = selectrow_query($self, $dbh, $query);
3050 $main::lxdebug->leave_sub();
3056 $main::lxdebug->enter_sub();
3058 my ($self, $string) = @_;
3060 if ($string !~ /%/) {
3061 $string = "%$string%";
3064 $string =~ s/\'/\'\'/g;
3066 $main::lxdebug->leave_sub();
3072 $main::lxdebug->enter_sub();
3074 my ($self, $flds, $new, $count, $numrows) = @_;
3078 map { push @ndx, { num => $new->[$_ - 1]->{runningnumber}, ndx => $_ } } 1 .. $count;
3083 foreach my $item (sort { $a->{num} <=> $b->{num} } @ndx) {
3085 my $j = $item->{ndx} - 1;
3086 map { $self->{"${_}_$i"} = $new->[$j]->{$_} } @{$flds};
3090 for $i ($count + 1 .. $numrows) {
3091 map { delete $self->{"${_}_$i"} } @{$flds};
3094 $main::lxdebug->leave_sub();
3098 $main::lxdebug->enter_sub();
3100 my ($self, $myconfig) = @_;
3104 my $dbh = $self->dbconnect_noauto($myconfig);
3106 my $query = qq|DELETE FROM status
3107 WHERE (formname = ?) AND (trans_id = ?)|;
3108 my $sth = prepare_query($self, $dbh, $query);
3110 if ($self->{formname} =~ /(check|receipt)/) {
3111 for $i (1 .. $self->{rowcount}) {
3112 do_statement($self, $sth, $query, $self->{formname}, $self->{"id_$i"} * 1);
3115 do_statement($self, $sth, $query, $self->{formname}, $self->{id});
3119 my $printed = ($self->{printed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3120 my $emailed = ($self->{emailed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3122 my %queued = split / /, $self->{queued};
3125 if ($self->{formname} =~ /(check|receipt)/) {
3127 # this is a check or receipt, add one entry for each lineitem
3128 my ($accno) = split /--/, $self->{account};
3129 $query = qq|INSERT INTO status (trans_id, printed, spoolfile, formname, chart_id)
3130 VALUES (?, ?, ?, ?, (SELECT c.id FROM chart c WHERE c.accno = ?))|;
3131 @values = ($printed, $queued{$self->{formname}}, $self->{prinform}, $accno);
3132 $sth = prepare_query($self, $dbh, $query);
3134 for $i (1 .. $self->{rowcount}) {
3135 if ($self->{"checked_$i"}) {
3136 do_statement($self, $sth, $query, $self->{"id_$i"}, @values);
3142 $query = qq|INSERT INTO status (trans_id, printed, emailed, spoolfile, formname)
3143 VALUES (?, ?, ?, ?, ?)|;
3144 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed,
3145 $queued{$self->{formname}}, $self->{formname});
3151 $main::lxdebug->leave_sub();
3155 $main::lxdebug->enter_sub();
3157 my ($self, $dbh) = @_;
3159 my ($query, $printed, $emailed);
3161 my $formnames = $self->{printed};
3162 my $emailforms = $self->{emailed};
3164 $query = qq|DELETE FROM status
3165 WHERE (formname = ?) AND (trans_id = ?)|;
3166 do_query($self, $dbh, $query, $self->{formname}, $self->{id});
3168 # this only applies to the forms
3169 # checks and receipts are posted when printed or queued
3171 if ($self->{queued}) {
3172 my %queued = split / /, $self->{queued};
3174 foreach my $formname (keys %queued) {
3175 $printed = ($self->{printed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3176 $emailed = ($self->{emailed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3178 $query = qq|INSERT INTO status (trans_id, printed, emailed, spoolfile, formname)
3179 VALUES (?, ?, ?, ?, ?)|;
3180 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed, $queued{$formname}, $formname);
3182 $formnames =~ s/\Q$self->{formname}\E//;
3183 $emailforms =~ s/\Q$self->{formname}\E//;
3188 # save printed, emailed info
3189 $formnames =~ s/^ +//g;
3190 $emailforms =~ s/^ +//g;
3193 map { $status{$_}{printed} = 1 } split / +/, $formnames;
3194 map { $status{$_}{emailed} = 1 } split / +/, $emailforms;
3196 foreach my $formname (keys %status) {
3197 $printed = ($formnames =~ /\Q$self->{formname}\E/) ? "1" : "0";
3198 $emailed = ($emailforms =~ /\Q$self->{formname}\E/) ? "1" : "0";
3200 $query = qq|INSERT INTO status (trans_id, printed, emailed, formname)
3201 VALUES (?, ?, ?, ?)|;
3202 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed, $formname);
3205 $main::lxdebug->leave_sub();
3209 # $main::locale->text('SAVED')
3210 # $main::locale->text('DELETED')
3211 # $main::locale->text('ADDED')
3212 # $main::locale->text('PAYMENT POSTED')
3213 # $main::locale->text('POSTED')
3214 # $main::locale->text('POSTED AS NEW')
3215 # $main::locale->text('ELSE')
3216 # $main::locale->text('SAVED FOR DUNNING')
3217 # $main::locale->text('DUNNING STARTED')
3218 # $main::locale->text('PRINTED')
3219 # $main::locale->text('MAILED')
3220 # $main::locale->text('SCREENED')
3221 # $main::locale->text('CANCELED')
3222 # $main::locale->text('invoice')
3223 # $main::locale->text('proforma')
3224 # $main::locale->text('sales_order')
3225 # $main::locale->text('packing_list')
3226 # $main::locale->text('pick_list')
3227 # $main::locale->text('purchase_order')
3228 # $main::locale->text('bin_list')
3229 # $main::locale->text('sales_quotation')
3230 # $main::locale->text('request_quotation')
3233 $main::lxdebug->enter_sub();
3238 if(!exists $self->{employee_id}) {
3239 &get_employee($self, $dbh);
3243 qq|INSERT INTO history_erp (trans_id, employee_id, addition, what_done, snumbers) | .
3244 qq|VALUES (?, (SELECT id FROM employee WHERE login = ?), ?, ?, ?)|;
3245 my @values = (conv_i($self->{id}), $self->{login},
3246 $self->{addition}, $self->{what_done}, "$self->{snumbers}");
3247 do_query($self, $dbh, $query, @values);
3249 $main::lxdebug->leave_sub();
3253 $main::lxdebug->enter_sub();
3255 my ($self, $dbh, $trans_id, $restriction, $order) = @_;
3256 my ($orderBy, $desc) = split(/\-\-/, $order);
3257 $order = " ORDER BY " . ($order eq "" ? " h.itime " : ($desc == 1 ? $orderBy . " DESC " : $orderBy . " "));
3260 if ($trans_id ne "") {
3262 qq|SELECT h.employee_id, h.itime::timestamp(0) AS itime, h.addition, h.what_done, emp.name, h.snumbers, h.trans_id AS id | .
3263 qq|FROM history_erp h | .
3264 qq|LEFT JOIN employee emp ON (emp.id = h.employee_id) | .
3265 qq|WHERE (trans_id = | . $trans_id . qq|) $restriction | .
3268 my $sth = $dbh->prepare($query) || $self->dberror($query);
3270 $sth->execute() || $self->dberror("$query");
3272 while(my $hash_ref = $sth->fetchrow_hashref()) {
3273 $hash_ref->{addition} = $main::locale->text($hash_ref->{addition});
3274 $hash_ref->{what_done} = $main::locale->text($hash_ref->{what_done});
3275 $hash_ref->{snumbers} =~ s/^.+_(.*)$/$1/g;
3276 $tempArray[$i++] = $hash_ref;
3278 $main::lxdebug->leave_sub() and return \@tempArray
3279 if ($i > 0 && $tempArray[0] ne "");
3281 $main::lxdebug->leave_sub();
3285 sub update_defaults {
3286 $main::lxdebug->enter_sub();
3288 my ($self, $myconfig, $fld, $provided_dbh) = @_;
3291 if ($provided_dbh) {
3292 $dbh = $provided_dbh;
3294 $dbh = $self->dbconnect_noauto($myconfig);
3296 my $query = qq|SELECT $fld FROM defaults FOR UPDATE|;
3297 my $sth = $dbh->prepare($query);
3299 $sth->execute || $self->dberror($query);
3300 my ($var) = $sth->fetchrow_array;
3303 if ($var =~ m/\d+$/) {
3304 my $new_var = (substr $var, $-[0]) * 1 + 1;
3305 my $len_diff = length($var) - $-[0] - length($new_var);
3306 $var = substr($var, 0, $-[0]) . ($len_diff > 0 ? '0' x $len_diff : '') . $new_var;
3312 $query = qq|UPDATE defaults SET $fld = ?|;
3313 do_query($self, $dbh, $query, $var);
3315 if (!$provided_dbh) {
3320 $main::lxdebug->leave_sub();
3325 sub update_business {
3326 $main::lxdebug->enter_sub();
3328 my ($self, $myconfig, $business_id, $provided_dbh) = @_;
3331 if ($provided_dbh) {
3332 $dbh = $provided_dbh;
3334 $dbh = $self->dbconnect_noauto($myconfig);
3337 qq|SELECT customernumberinit FROM business
3338 WHERE id = ? FOR UPDATE|;
3339 my ($var) = selectrow_query($self, $dbh, $query, $business_id);
3341 return undef unless $var;
3343 if ($var =~ m/\d+$/) {
3344 my $new_var = (substr $var, $-[0]) * 1 + 1;
3345 my $len_diff = length($var) - $-[0] - length($new_var);
3346 $var = substr($var, 0, $-[0]) . ($len_diff > 0 ? '0' x $len_diff : '') . $new_var;
3352 $query = qq|UPDATE business
3353 SET customernumberinit = ?
3355 do_query($self, $dbh, $query, $var, $business_id);
3357 if (!$provided_dbh) {
3362 $main::lxdebug->leave_sub();
3367 sub get_partsgroup {
3368 $main::lxdebug->enter_sub();
3370 my ($self, $myconfig, $p) = @_;
3371 my $target = $p->{target} || 'all_partsgroup';
3373 my $dbh = $self->get_standard_dbh($myconfig);
3375 my $query = qq|SELECT DISTINCT pg.id, pg.partsgroup
3377 JOIN parts p ON (p.partsgroup_id = pg.id) |;
3380 if ($p->{searchitems} eq 'part') {
3381 $query .= qq|WHERE p.inventory_accno_id > 0|;
3383 if ($p->{searchitems} eq 'service') {
3384 $query .= qq|WHERE p.inventory_accno_id IS NULL|;
3386 if ($p->{searchitems} eq 'assembly') {
3387 $query .= qq|WHERE p.assembly = '1'|;
3389 if ($p->{searchitems} eq 'labor') {
3390 $query .= qq|WHERE (p.inventory_accno_id > 0) AND (p.income_accno_id IS NULL)|;
3393 $query .= qq|ORDER BY partsgroup|;
3396 $query = qq|SELECT id, partsgroup FROM partsgroup
3397 ORDER BY partsgroup|;
3400 if ($p->{language_code}) {
3401 $query = qq|SELECT DISTINCT pg.id, pg.partsgroup,
3402 t.description AS translation
3404 JOIN parts p ON (p.partsgroup_id = pg.id)
3405 LEFT JOIN translation t ON ((t.trans_id = pg.id) AND (t.language_code = ?))
3406 ORDER BY translation|;
3407 @values = ($p->{language_code});
3410 $self->{$target} = selectall_hashref_query($self, $dbh, $query, @values);
3412 $main::lxdebug->leave_sub();
3415 sub get_pricegroup {
3416 $main::lxdebug->enter_sub();
3418 my ($self, $myconfig, $p) = @_;
3420 my $dbh = $self->get_standard_dbh($myconfig);
3422 my $query = qq|SELECT p.id, p.pricegroup
3425 $query .= qq| ORDER BY pricegroup|;
3428 $query = qq|SELECT id, pricegroup FROM pricegroup
3429 ORDER BY pricegroup|;
3432 $self->{all_pricegroup} = selectall_hashref_query($self, $dbh, $query);
3434 $main::lxdebug->leave_sub();
3438 # usage $form->all_years($myconfig, [$dbh])
3439 # return list of all years where bookings found
3442 $main::lxdebug->enter_sub();
3444 my ($self, $myconfig, $dbh) = @_;
3446 $dbh ||= $self->get_standard_dbh($myconfig);
3449 my $query = qq|SELECT (SELECT MIN(transdate) FROM acc_trans),
3450 (SELECT MAX(transdate) FROM acc_trans)|;
3451 my ($startdate, $enddate) = selectrow_query($self, $dbh, $query);
3453 if ($myconfig->{dateformat} =~ /^yy/) {
3454 ($startdate) = split /\W/, $startdate;
3455 ($enddate) = split /\W/, $enddate;
3457 (@_) = split /\W/, $startdate;
3459 (@_) = split /\W/, $enddate;
3464 $startdate = substr($startdate,0,4);
3465 $enddate = substr($enddate,0,4);
3467 while ($enddate >= $startdate) {
3468 push @all_years, $enddate--;
3473 $main::lxdebug->leave_sub();
3477 $main::lxdebug->enter_sub();
3481 map { $self->{_VAR_BACKUP}->{$_} = $self->{$_} if exists $self->{$_} } @vars;
3483 $main::lxdebug->leave_sub();
3487 $main::lxdebug->enter_sub();
3492 map { $self->{$_} = $self->{_VAR_BACKUP}->{$_} if exists $self->{_VAR_BACKUP}->{$_} } @vars;
3494 $main::lxdebug->leave_sub();
3503 SL::Form.pm - main data object.
3507 This is the main data object of Lx-Office.
3508 Unfortunately it also acts as a god object for certain data retrieval procedures used in the entry points.
3509 Points of interest for a beginner are:
3511 - $form->error - renders a generic error in html. accepts an error message
3512 - $form->get_standard_dbh - returns a database connection for the
3514 =head1 SPECIAL FUNCTIONS
3518 =item _store_value()
3520 parses a complex var name, and stores it in the form.
3523 $form->_store_value($key, $value);
3525 keys must start with a string, and can contain various tokens.
3526 supported key structures are:
3529 simple key strings work as expected
3534 separating two keys by a dot (.) will result in a hash lookup for the inner value
3535 this is similar to the behaviour of java and templating mechanisms.
3537 filter.description => $form->{filter}->{description}
3539 3. array+hashref access
3541 adding brackets ([]) before the dot will cause the next hash to be put into an array.
3542 using [+] instead of [] will force a new array index. this is useful for recurring
3543 data structures like part lists. put a [+] into the first varname, and use [] on the
3546 repeating these names in your template:
3549 invoice.items[].parts_id
3553 $form->{invoice}->{items}->[
3567 using brackets at the end of a name will result in a pure array to be created.
3568 note that you mustn't use [+], which is reserved for array+hash access and will
3569 result in undefined behaviour in array context.
3571 filter.status[] => $form->{status}->[ val1, val2, ... ]
3573 =item update_business PARAMS
3576 \%config, - config hashref
3577 $business_id, - business id
3578 $dbh - optional database handle
3580 handles business (thats customer/vendor types) sequences.
3582 special behaviour for empty strings in customerinitnumber field:
3583 will in this case not increase the value, and return undef.
3585 =item redirect_header $url
3587 Generates a HTTP redirection header for the new C<$url>. Constructs an
3588 absolute URL including scheme, host name and port. If C<$url> is a
3589 relative URL then it is considered relative to Lx-Office base URL.
3591 This function C<die>s if headers have already been created with
3592 C<$::form-E<gt>header>.
3596 print $::form->redirect_header('oe.pl?action=edit&id=1234');
3597 print $::form->redirect_header('http://www.lx-office.org/');