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);
66 disconnect_standard_dbh();
69 sub disconnect_standard_dbh {
70 return unless $standard_dbh;
71 $standard_dbh->disconnect();
76 $main::lxdebug->enter_sub(2);
82 my @tokens = split /((?:\[\+?\])?(?:\.|$))/, $key;
87 $curr = \ $self->{ shift @tokens };
91 my $sep = shift @tokens;
92 my $key = shift @tokens;
94 $curr = \ $$curr->[++$#$$curr], next if $sep eq '[]';
95 $curr = \ $$curr->[max 0, $#$$curr] if $sep eq '[].';
96 $curr = \ $$curr->[++$#$$curr] if $sep eq '[+].';
97 $curr = \ $$curr->{$key}
102 $main::lxdebug->leave_sub(2);
108 $main::lxdebug->enter_sub(2);
113 my @pairs = split(/&/, $input);
116 my ($key, $value) = split(/=/, $_, 2);
117 $self->_store_value($self->unescape($key), $self->unescape($value)) if ($key);
120 $main::lxdebug->leave_sub(2);
123 sub _request_to_hash {
124 $main::lxdebug->enter_sub(2);
129 if (!$ENV{'CONTENT_TYPE'}
130 || ($ENV{'CONTENT_TYPE'} !~ /multipart\/form-data\s*;\s*boundary\s*=\s*(.+)$/)) {
132 $self->_input_to_hash($input);
134 $main::lxdebug->leave_sub(2);
138 my ($name, $filename, $headers_done, $content_type, $boundary_found, $need_cr, $previous);
140 my $boundary = '--' . $1;
142 foreach my $line (split m/\n/, $input) {
143 last if (($line eq "${boundary}--") || ($line eq "${boundary}--\r"));
145 if (($line eq $boundary) || ($line eq "$boundary\r")) {
146 ${ $previous } =~ s|\r?\n$|| if $previous;
152 $content_type = "text/plain";
159 next unless $boundary_found;
161 if (!$headers_done) {
162 $line =~ s/[\r\n]*$//;
169 if ($line =~ m|^content-disposition\s*:.*?form-data\s*;|i) {
170 if ($line =~ m|filename\s*=\s*"(.*?)"|i) {
172 substr $line, $-[0], $+[0] - $-[0], "";
175 if ($line =~ m|name\s*=\s*"(.*?)"|i) {
177 substr $line, $-[0], $+[0] - $-[0], "";
180 $previous = $self->_store_value($name, '') if ($name);
181 $self->{FILENAME} = $filename if ($filename);
186 if ($line =~ m|^content-type\s*:\s*(.*?)$|i) {
193 next unless $previous;
195 ${ $previous } .= "${line}\n";
198 ${ $previous } =~ s|\r?\n$|| if $previous;
200 $main::lxdebug->leave_sub(2);
203 sub _recode_recursively {
204 $main::lxdebug->enter_sub();
205 my ($iconv, $param) = @_;
207 if (any { ref $param eq $_ } qw(Form HASH)) {
208 foreach my $key (keys %{ $param }) {
209 if (!ref $param->{$key}) {
210 # Workaround for a bug: converting $param->{$key} directly
211 # leads to 'undef'. I don't know why. Converting a copy works,
213 $param->{$key} = $iconv->convert("" . $param->{$key});
215 _recode_recursively($iconv, $param->{$key});
219 } elsif (ref $param eq 'ARRAY') {
220 foreach my $idx (0 .. scalar(@{ $param }) - 1) {
221 if (!ref $param->[$idx]) {
222 # Workaround for a bug: converting $param->[$idx] directly
223 # leads to 'undef'. I don't know why. Converting a copy works,
225 $param->[$idx] = $iconv->convert("" . $param->[$idx]);
227 _recode_recursively($iconv, $param->[$idx]);
231 $main::lxdebug->leave_sub();
235 $main::lxdebug->enter_sub();
241 if ($LXDebug::watch_form) {
242 require SL::Watchdog;
243 tie %{ $self }, 'SL::Watchdog';
248 $self->_input_to_hash($ENV{QUERY_STRING}) if $ENV{QUERY_STRING};
249 $self->_input_to_hash($ARGV[0]) if @ARGV && $ARGV[0];
251 if ($ENV{CONTENT_LENGTH}) {
253 read STDIN, $content, $ENV{CONTENT_LENGTH};
254 $self->_request_to_hash($content);
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);
458 print STDERR "Error: $msg\n";
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 print STDERR "Error: $error\n";
900 $main::lxdebug->leave_sub();
905 sub show_generic_information {
906 $main::lxdebug->enter_sub();
908 my ($self, $text, $title) = @_;
911 'title_information' => $title,
912 'label_information' => $text,
915 $self->{title} = $title if ($title);
918 print $self->parse_html_template("generic/information", $add_params);
920 $main::lxdebug->leave_sub();
925 # write Trigger JavaScript-Code ($qty = quantity of Triggers)
926 # changed it to accept an arbitrary number of triggers - sschoeling
928 $main::lxdebug->enter_sub();
931 my $myconfig = shift;
934 # set dateform for jsscript
937 "dd.mm.yy" => "%d.%m.%Y",
938 "dd-mm-yy" => "%d-%m-%Y",
939 "dd/mm/yy" => "%d/%m/%Y",
940 "mm/dd/yy" => "%m/%d/%Y",
941 "mm-dd-yy" => "%m-%d-%Y",
942 "yyyy-mm-dd" => "%Y-%m-%d",
945 my $ifFormat = defined($dateformats{$myconfig->{"dateformat"}}) ?
946 $dateformats{$myconfig->{"dateformat"}} : "%d.%m.%Y";
953 inputField : "| . (shift) . qq|",
954 ifFormat :"$ifFormat",
955 align : "| . (shift) . qq|",
956 button : "| . (shift) . qq|"
962 <script type="text/javascript">
963 <!--| . join("", @triggers) . qq|//-->
967 $main::lxdebug->leave_sub();
970 } #end sub write_trigger
973 $main::lxdebug->enter_sub();
975 my ($self, $msg) = @_;
977 if (!$self->{callback}) {
983 # my ($script, $argv) = split(/\?/, $self->{callback}, 2);
984 # $script =~ s|.*/||;
985 # $script =~ s|[^a-zA-Z0-9_\.]||g;
986 # exec("perl", "$script", $argv);
988 print $::form->redirect_header($self->{callback});
990 $main::lxdebug->leave_sub();
993 # sort of columns removed - empty sub
995 $main::lxdebug->enter_sub();
997 my ($self, @columns) = @_;
999 $main::lxdebug->leave_sub();
1005 $main::lxdebug->enter_sub(2);
1007 my ($self, $myconfig, $amount, $places, $dash) = @_;
1009 if ($amount eq "") {
1013 # Hey watch out! The amount can be an exponential term like 1.13686837721616e-13
1015 my $neg = ($amount =~ s/^-//);
1016 my $exp = ($amount =~ m/[e]/) ? 1 : 0;
1018 if (defined($places) && ($places ne '')) {
1024 my ($actual_places) = ($amount =~ /\.(\d+)/);
1025 $actual_places = length($actual_places);
1026 $places = $actual_places > $places ? $actual_places : $places;
1029 $amount = $self->round_amount($amount, $places);
1032 my @d = map { s/\d//g; reverse split // } my $tmp = $myconfig->{numberformat}; # get delim chars
1033 my @p = split(/\./, $amount); # split amount at decimal point
1035 $p[0] =~ s/\B(?=(...)*$)/$d[1]/g if $d[1]; # add 1,000 delimiters
1038 $amount .= $d[0].$p[1].(0 x ($places - length $p[1])) if ($places || $p[1] ne '');
1041 ($dash =~ /-/) ? ($neg ? "($amount)" : "$amount" ) :
1042 ($dash =~ /DRCR/) ? ($neg ? "$amount " . $main::locale->text('DR') : "$amount " . $main::locale->text('CR') ) :
1043 ($neg ? "-$amount" : "$amount" ) ;
1047 $main::lxdebug->leave_sub(2);
1051 sub format_amount_units {
1052 $main::lxdebug->enter_sub();
1057 my $myconfig = \%main::myconfig;
1058 my $amount = $params{amount} * 1;
1059 my $places = $params{places};
1060 my $part_unit_name = $params{part_unit};
1061 my $amount_unit_name = $params{amount_unit};
1062 my $conv_units = $params{conv_units};
1063 my $max_places = $params{max_places};
1065 if (!$part_unit_name) {
1066 $main::lxdebug->leave_sub();
1070 AM->retrieve_all_units();
1071 my $all_units = $main::all_units;
1073 if (('' eq ref $conv_units) && ($conv_units =~ /convertible/)) {
1074 $conv_units = AM->convertible_units($all_units, $part_unit_name, $conv_units eq 'convertible_not_smaller');
1077 if (!scalar @{ $conv_units }) {
1078 my $result = $self->format_amount($myconfig, $amount, $places, undef, $max_places) . " " . $part_unit_name;
1079 $main::lxdebug->leave_sub();
1083 my $part_unit = $all_units->{$part_unit_name};
1084 my $conv_unit = ($amount_unit_name && ($amount_unit_name ne $part_unit_name)) ? $all_units->{$amount_unit_name} : $part_unit;
1086 $amount *= $conv_unit->{factor};
1091 foreach my $unit (@$conv_units) {
1092 my $last = $unit->{name} eq $part_unit->{name};
1094 $num = int($amount / $unit->{factor});
1095 $amount -= $num * $unit->{factor};
1098 if ($last ? $amount : $num) {
1099 push @values, { "unit" => $unit->{name},
1100 "amount" => $last ? $amount / $unit->{factor} : $num,
1101 "places" => $last ? $places : 0 };
1108 push @values, { "unit" => $part_unit_name,
1113 my $result = join " ", map { $self->format_amount($myconfig, $_->{amount}, $_->{places}, undef, $max_places), $_->{unit} } @values;
1115 $main::lxdebug->leave_sub();
1121 $main::lxdebug->enter_sub(2);
1126 $input =~ s/(^|[^\#]) \# (\d+) /$1$_[$2 - 1]/gx;
1127 $input =~ s/(^|[^\#]) \#\{(\d+)\}/$1$_[$2 - 1]/gx;
1128 $input =~ s/\#\#/\#/g;
1130 $main::lxdebug->leave_sub(2);
1138 $main::lxdebug->enter_sub(2);
1140 my ($self, $myconfig, $amount) = @_;
1142 if ( ($myconfig->{numberformat} eq '1.000,00')
1143 || ($myconfig->{numberformat} eq '1000,00')) {
1148 if ($myconfig->{numberformat} eq "1'000.00") {
1154 $main::lxdebug->leave_sub(2);
1156 return ($amount * 1);
1160 $main::lxdebug->enter_sub(2);
1162 my ($self, $amount, $places) = @_;
1165 # Rounding like "Kaufmannsrunden" (see http://de.wikipedia.org/wiki/Rundung )
1167 # Round amounts to eight places before rounding to the requested
1168 # number of places. This gets rid of errors due to internal floating
1169 # point representation.
1170 $amount = $self->round_amount($amount, 8) if $places < 8;
1171 $amount = $amount * (10**($places));
1172 $round_amount = int($amount + .5 * ($amount <=> 0)) / (10**($places));
1174 $main::lxdebug->leave_sub(2);
1176 return $round_amount;
1180 sub parse_template {
1181 $main::lxdebug->enter_sub();
1183 my ($self, $myconfig, $userspath) = @_;
1184 my ($template, $out);
1188 $self->{"cwd"} = getcwd();
1189 $self->{"tmpdir"} = $self->{cwd} . "/${userspath}";
1193 if ($self->{"format"} =~ /(opendocument|oasis)/i) {
1194 $template = OpenDocumentTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1195 $ext_for_format = $self->{"format"} =~ m/pdf/ ? 'pdf' : 'odt';
1197 } elsif ($self->{"format"} =~ /(postscript|pdf)/i) {
1198 $ENV{"TEXINPUTS"} = ".:" . getcwd() . "/" . $myconfig->{"templates"} . ":" . $ENV{"TEXINPUTS"};
1199 $template = LaTeXTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1200 $ext_for_format = 'pdf';
1202 } elsif (($self->{"format"} =~ /html/i) || (!$self->{"format"} && ($self->{"IN"} =~ /html$/i))) {
1203 $template = HTMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1204 $ext_for_format = 'html';
1206 } elsif (($self->{"format"} =~ /xml/i) || (!$self->{"format"} && ($self->{"IN"} =~ /xml$/i))) {
1207 $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1208 $ext_for_format = 'xml';
1210 } elsif ( $self->{"format"} =~ /elsterwinston/i ) {
1211 $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1213 } elsif ( $self->{"format"} =~ /elstertaxbird/i ) {
1214 $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1216 } elsif ( $self->{"format"} =~ /excel/i ) {
1217 $template = ExcelTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
1218 $ext_for_format = 'xls';
1220 } elsif ( defined $self->{'format'}) {
1221 $self->error("Outputformat not defined. This may be a future feature: $self->{'format'}");
1223 } elsif ( $self->{'format'} eq '' ) {
1224 $self->error("No Outputformat given: $self->{'format'}");
1226 } else { #Catch the rest
1227 $self->error("Outputformat not defined: $self->{'format'}");
1230 # Copy the notes from the invoice/sales order etc. back to the variable "notes" because that is where most templates expect it to be.
1231 $self->{"notes"} = $self->{ $self->{"formname"} . "notes" };
1233 if (!$self->{employee_id}) {
1234 map { $self->{"employee_${_}"} = $myconfig->{$_}; } qw(email tel fax name signature company address businessnumber co_ustid taxnumber duns);
1237 map { $self->{"${_}"} = $myconfig->{$_}; } qw(co_ustid);
1239 $self->{copies} = 1 if (($self->{copies} *= 1) <= 0);
1241 # OUT is used for the media, screen, printer, email
1242 # for postscript we store a copy in a temporary file
1244 my $prepend_userspath;
1246 if (!$self->{tmpfile}) {
1247 $self->{tmpfile} = "${fileid}.$self->{IN}";
1248 $prepend_userspath = 1;
1251 $prepend_userspath = 1 if substr($self->{tmpfile}, 0, length $userspath) eq $userspath;
1253 $self->{tmpfile} =~ s|.*/||;
1254 $self->{tmpfile} =~ s/[^a-zA-Z0-9\._\ \-]//g;
1255 $self->{tmpfile} = "$userspath/$self->{tmpfile}" if $prepend_userspath;
1257 if ($template->uses_temp_file() || $self->{media} eq 'email') {
1258 $out = $self->{OUT};
1259 $self->{OUT} = ">$self->{tmpfile}";
1263 open(OUT, "$self->{OUT}") or $self->error("$self->{OUT} : $!");
1265 open(OUT, ">-") or $self->error("STDOUT : $!");
1269 if (!$template->parse(*OUT)) {
1271 $self->error("$self->{IN} : " . $template->get_error());
1276 if ($template->uses_temp_file() || $self->{media} eq 'email') {
1278 if ($self->{media} eq 'email') {
1280 my $mail = new Mailer;
1282 map { $mail->{$_} = $self->{$_} }
1283 qw(cc bcc subject message version format);
1284 $mail->{charset} = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
1285 $mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email};
1286 $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
1287 $mail->{fileid} = "$fileid.";
1288 $myconfig->{signature} =~ s/\r//g;
1290 # if we send html or plain text inline
1291 if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
1292 $mail->{contenttype} = "text/html";
1294 $mail->{message} =~ s/\r//g;
1295 $mail->{message} =~ s/\n/<br>\n/g;
1296 $myconfig->{signature} =~ s/\n/<br>\n/g;
1297 $mail->{message} .= "<br>\n-- <br>\n$myconfig->{signature}\n<br>";
1299 open(IN, $self->{tmpfile})
1300 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
1302 $mail->{message} .= $_;
1309 if (!$self->{"do_not_attach"}) {
1310 my $attachment_name = $self->{attachment_filename} || $self->{tmpfile};
1311 $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format);
1312 $mail->{attachments} = [{ "filename" => $self->{tmpfile},
1313 "name" => $attachment_name }];
1316 $mail->{message} =~ s/\r//g;
1317 $mail->{message} .= "\n-- \n$myconfig->{signature}";
1321 my $err = $mail->send();
1322 $self->error($self->cleanup . "$err") if ($err);
1326 $self->{OUT} = $out;
1328 my $numbytes = (-s $self->{tmpfile});
1329 open(IN, $self->{tmpfile})
1330 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
1332 $self->{copies} = 1 unless $self->{media} eq 'printer';
1334 chdir("$self->{cwd}");
1335 #print(STDERR "Kopien $self->{copies}\n");
1336 #print(STDERR "OUT $self->{OUT}\n");
1337 for my $i (1 .. $self->{copies}) {
1339 open OUT, $self->{OUT} or $self->error($self->cleanup . "$self->{OUT} : $!");
1340 print OUT while <IN>;
1345 $self->{attachment_filename} = ($self->{attachment_filename})
1346 ? $self->{attachment_filename}
1347 : $self->generate_attachment_filename();
1349 # launch application
1350 print qq|Content-Type: | . $template->get_mime_type() . qq|
1351 Content-Disposition: attachment; filename="$self->{attachment_filename}"
1352 Content-Length: $numbytes
1356 $::locale->with_raw_io(\*STDOUT, sub { print while <IN> });
1367 chdir("$self->{cwd}");
1368 $main::lxdebug->leave_sub();
1371 sub get_formname_translation {
1372 $main::lxdebug->enter_sub();
1373 my ($self, $formname) = @_;
1375 $formname ||= $self->{formname};
1377 my %formname_translations = (
1378 bin_list => $main::locale->text('Bin List'),
1379 credit_note => $main::locale->text('Credit Note'),
1380 invoice => $main::locale->text('Invoice'),
1381 packing_list => $main::locale->text('Packing List'),
1382 pick_list => $main::locale->text('Pick List'),
1383 proforma => $main::locale->text('Proforma Invoice'),
1384 purchase_order => $main::locale->text('Purchase Order'),
1385 request_quotation => $main::locale->text('RFQ'),
1386 sales_order => $main::locale->text('Confirmation'),
1387 sales_quotation => $main::locale->text('Quotation'),
1388 storno_invoice => $main::locale->text('Storno Invoice'),
1389 storno_packing_list => $main::locale->text('Storno Packing List'),
1390 sales_delivery_order => $main::locale->text('Delivery Order'),
1391 purchase_delivery_order => $main::locale->text('Delivery Order'),
1392 dunning => $main::locale->text('Dunning'),
1395 $main::lxdebug->leave_sub();
1396 return $formname_translations{$formname}
1399 sub get_number_prefix_for_type {
1400 $main::lxdebug->enter_sub();
1404 (first { $self->{type} eq $_ } qw(invoice credit_note)) ? 'inv'
1405 : ($self->{type} =~ /_quotation$/) ? 'quo'
1406 : ($self->{type} =~ /_delivery_order$/) ? 'do'
1409 $main::lxdebug->leave_sub();
1413 sub get_extension_for_format {
1414 $main::lxdebug->enter_sub();
1417 my $extension = $self->{format} =~ /pdf/i ? ".pdf"
1418 : $self->{format} =~ /postscript/i ? ".ps"
1419 : $self->{format} =~ /opendocument/i ? ".odt"
1420 : $self->{format} =~ /excel/i ? ".xls"
1421 : $self->{format} =~ /html/i ? ".html"
1424 $main::lxdebug->leave_sub();
1428 sub generate_attachment_filename {
1429 $main::lxdebug->enter_sub();
1432 my $attachment_filename = $main::locale->unquote_special_chars('HTML', $self->get_formname_translation());
1433 my $prefix = $self->get_number_prefix_for_type();
1435 if ($self->{preview} && (first { $self->{type} eq $_ } qw(invoice credit_note))) {
1436 $attachment_filename .= ' (' . $main::locale->text('Preview') . ')' . $self->get_extension_for_format();
1438 } elsif ($attachment_filename && $self->{"${prefix}number"}) {
1439 $attachment_filename .= "_" . $self->{"${prefix}number"} . $self->get_extension_for_format();
1442 $attachment_filename = "";
1445 $attachment_filename = $main::locale->quote_special_chars('filenames', $attachment_filename);
1446 $attachment_filename =~ s|[\s/\\]+|_|g;
1448 $main::lxdebug->leave_sub();
1449 return $attachment_filename;
1452 sub generate_email_subject {
1453 $main::lxdebug->enter_sub();
1456 my $subject = $main::locale->unquote_special_chars('HTML', $self->get_formname_translation());
1457 my $prefix = $self->get_number_prefix_for_type();
1459 if ($subject && $self->{"${prefix}number"}) {
1460 $subject .= " " . $self->{"${prefix}number"}
1463 $main::lxdebug->leave_sub();
1468 $main::lxdebug->enter_sub();
1472 chdir("$self->{tmpdir}");
1475 if (-f "$self->{tmpfile}.err") {
1476 open(FH, "$self->{tmpfile}.err");
1481 if ($self->{tmpfile} && ! $::keep_temp_files) {
1482 $self->{tmpfile} =~ s|.*/||g;
1484 $self->{tmpfile} =~ s/\.\w+$//g;
1485 my $tmpfile = $self->{tmpfile};
1486 unlink(<$tmpfile.*>);
1489 chdir("$self->{cwd}");
1491 $main::lxdebug->leave_sub();
1497 $main::lxdebug->enter_sub();
1499 my ($self, $date, $myconfig) = @_;
1502 if ($date && $date =~ /\D/) {
1504 if ($myconfig->{dateformat} =~ /^yy/) {
1505 ($yy, $mm, $dd) = split /\D/, $date;
1507 if ($myconfig->{dateformat} =~ /^mm/) {
1508 ($mm, $dd, $yy) = split /\D/, $date;
1510 if ($myconfig->{dateformat} =~ /^dd/) {
1511 ($dd, $mm, $yy) = split /\D/, $date;
1516 $yy = ($yy < 70) ? $yy + 2000 : $yy;
1517 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
1519 $dd = "0$dd" if ($dd < 10);
1520 $mm = "0$mm" if ($mm < 10);
1522 $date = "$yy$mm$dd";
1525 $main::lxdebug->leave_sub();
1530 # Database routines used throughout
1533 $main::lxdebug->enter_sub(2);
1535 my ($self, $myconfig) = @_;
1537 # connect to database
1539 DBI->connect($myconfig->{dbconnect},
1540 $myconfig->{dbuser}, $myconfig->{dbpasswd})
1544 if ($myconfig->{dboptions}) {
1545 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1548 $main::lxdebug->leave_sub(2);
1553 sub dbconnect_noauto {
1554 $main::lxdebug->enter_sub();
1556 my ($self, $myconfig) = @_;
1558 # connect to database
1560 DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser},
1561 $myconfig->{dbpasswd}, { AutoCommit => 0 })
1565 if ($myconfig->{dboptions}) {
1566 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1569 $main::lxdebug->leave_sub();
1574 sub get_standard_dbh {
1575 $main::lxdebug->enter_sub(2);
1577 my ($self, $myconfig) = @_;
1579 if ($standard_dbh && !$standard_dbh->{Active}) {
1580 $main::lxdebug->message(LXDebug->INFO(), "get_standard_dbh: \$standard_dbh is defined but not Active anymore");
1581 undef $standard_dbh;
1584 $standard_dbh ||= $self->dbconnect_noauto($myconfig);
1586 $main::lxdebug->leave_sub(2);
1588 return $standard_dbh;
1592 $main::lxdebug->enter_sub();
1594 my ($self, $date, $myconfig) = @_;
1595 my $dbh = $self->dbconnect($myconfig);
1597 my $query = "SELECT 1 FROM defaults WHERE ? < closedto";
1598 my $sth = prepare_execute_query($self, $dbh, $query, $date);
1599 my ($closed) = $sth->fetchrow_array;
1601 $main::lxdebug->leave_sub();
1606 sub update_balance {
1607 $main::lxdebug->enter_sub();
1609 my ($self, $dbh, $table, $field, $where, $value, @values) = @_;
1611 # if we have a value, go do it
1614 # retrieve balance from table
1615 my $query = "SELECT $field FROM $table WHERE $where FOR UPDATE";
1616 my $sth = prepare_execute_query($self, $dbh, $query, @values);
1617 my ($balance) = $sth->fetchrow_array;
1623 $query = "UPDATE $table SET $field = $balance WHERE $where";
1624 do_query($self, $dbh, $query, @values);
1626 $main::lxdebug->leave_sub();
1629 sub update_exchangerate {
1630 $main::lxdebug->enter_sub();
1632 my ($self, $dbh, $curr, $transdate, $buy, $sell) = @_;
1634 # some sanity check for currency
1636 $main::lxdebug->leave_sub();
1639 $query = qq|SELECT curr FROM defaults|;
1641 my ($currency) = selectrow_query($self, $dbh, $query);
1642 my ($defaultcurrency) = split m/:/, $currency;
1645 if ($curr eq $defaultcurrency) {
1646 $main::lxdebug->leave_sub();
1650 $query = qq|SELECT e.curr FROM exchangerate e
1651 WHERE e.curr = ? AND e.transdate = ?
1653 my $sth = prepare_execute_query($self, $dbh, $query, $curr, $transdate);
1662 $buy = conv_i($buy, "NULL");
1663 $sell = conv_i($sell, "NULL");
1666 if ($buy != 0 && $sell != 0) {
1667 $set = "buy = $buy, sell = $sell";
1668 } elsif ($buy != 0) {
1669 $set = "buy = $buy";
1670 } elsif ($sell != 0) {
1671 $set = "sell = $sell";
1674 if ($sth->fetchrow_array) {
1675 $query = qq|UPDATE exchangerate
1681 $query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
1682 VALUES (?, $buy, $sell, ?)|;
1685 do_query($self, $dbh, $query, $curr, $transdate);
1687 $main::lxdebug->leave_sub();
1690 sub save_exchangerate {
1691 $main::lxdebug->enter_sub();
1693 my ($self, $myconfig, $currency, $transdate, $rate, $fld) = @_;
1695 my $dbh = $self->dbconnect($myconfig);
1699 $buy = $rate if $fld eq 'buy';
1700 $sell = $rate if $fld eq 'sell';
1703 $self->update_exchangerate($dbh, $currency, $transdate, $buy, $sell);
1708 $main::lxdebug->leave_sub();
1711 sub get_exchangerate {
1712 $main::lxdebug->enter_sub();
1714 my ($self, $dbh, $curr, $transdate, $fld) = @_;
1717 unless ($transdate) {
1718 $main::lxdebug->leave_sub();
1722 $query = qq|SELECT curr FROM defaults|;
1724 my ($currency) = selectrow_query($self, $dbh, $query);
1725 my ($defaultcurrency) = split m/:/, $currency;
1727 if ($currency eq $defaultcurrency) {
1728 $main::lxdebug->leave_sub();
1732 $query = qq|SELECT e.$fld FROM exchangerate e
1733 WHERE e.curr = ? AND e.transdate = ?|;
1734 my ($exchangerate) = selectrow_query($self, $dbh, $query, $curr, $transdate);
1738 $main::lxdebug->leave_sub();
1740 return $exchangerate;
1743 sub check_exchangerate {
1744 $main::lxdebug->enter_sub();
1746 my ($self, $myconfig, $currency, $transdate, $fld) = @_;
1748 if ($fld !~/^buy|sell$/) {
1749 $self->error('Fatal: check_exchangerate called with invalid buy/sell argument');
1752 unless ($transdate) {
1753 $main::lxdebug->leave_sub();
1757 my ($defaultcurrency) = $self->get_default_currency($myconfig);
1759 if ($currency eq $defaultcurrency) {
1760 $main::lxdebug->leave_sub();
1764 my $dbh = $self->get_standard_dbh($myconfig);
1765 my $query = qq|SELECT e.$fld FROM exchangerate e
1766 WHERE e.curr = ? AND e.transdate = ?|;
1768 my ($exchangerate) = selectrow_query($self, $dbh, $query, $currency, $transdate);
1770 $main::lxdebug->leave_sub();
1772 return $exchangerate;
1775 sub get_all_currencies {
1776 $main::lxdebug->enter_sub();
1778 my ($self, $myconfig) = @_;
1779 my $dbh = $self->get_standard_dbh($myconfig);
1781 my $query = qq|SELECT curr FROM defaults|;
1783 my ($curr) = selectrow_query($self, $dbh, $query);
1784 my @currencies = grep { $_ } map { s/\s//g; $_ } split m/:/, $curr;
1786 $main::lxdebug->leave_sub();
1791 sub get_default_currency {
1792 $main::lxdebug->enter_sub();
1794 my ($self, $myconfig) = @_;
1795 my @currencies = $self->get_all_currencies($myconfig);
1797 $main::lxdebug->leave_sub();
1799 return $currencies[0];
1802 sub set_payment_options {
1803 $main::lxdebug->enter_sub();
1805 my ($self, $myconfig, $transdate) = @_;
1807 return $main::lxdebug->leave_sub() unless ($self->{payment_id});
1809 my $dbh = $self->get_standard_dbh($myconfig);
1812 qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, p.description_long | .
1813 qq|FROM payment_terms p | .
1816 ($self->{terms_netto}, $self->{terms_skonto}, $self->{percent_skonto},
1817 $self->{payment_terms}) =
1818 selectrow_query($self, $dbh, $query, $self->{payment_id});
1820 if ($transdate eq "") {
1821 if ($self->{invdate}) {
1822 $transdate = $self->{invdate};
1824 $transdate = $self->{transdate};
1829 qq|SELECT ?::date + ?::integer AS netto_date, ?::date + ?::integer AS skonto_date | .
1830 qq|FROM payment_terms|;
1831 ($self->{netto_date}, $self->{skonto_date}) =
1832 selectrow_query($self, $dbh, $query, $transdate, $self->{terms_netto}, $transdate, $self->{terms_skonto});
1834 my ($invtotal, $total);
1835 my (%amounts, %formatted_amounts);
1837 if ($self->{type} =~ /_order$/) {
1838 $amounts{invtotal} = $self->{ordtotal};
1839 $amounts{total} = $self->{ordtotal};
1841 } elsif ($self->{type} =~ /_quotation$/) {
1842 $amounts{invtotal} = $self->{quototal};
1843 $amounts{total} = $self->{quototal};
1846 $amounts{invtotal} = $self->{invtotal};
1847 $amounts{total} = $self->{total};
1849 $amounts{skonto_in_percent} = 100.0 * $self->{percent_skonto};
1851 map { $amounts{$_} = $self->parse_amount($myconfig, $amounts{$_}) } keys %amounts;
1853 $amounts{skonto_amount} = $amounts{invtotal} * $self->{percent_skonto};
1854 $amounts{invtotal_wo_skonto} = $amounts{invtotal} * (1 - $self->{percent_skonto});
1855 $amounts{total_wo_skonto} = $amounts{total} * (1 - $self->{percent_skonto});
1857 foreach (keys %amounts) {
1858 $amounts{$_} = $self->round_amount($amounts{$_}, 2);
1859 $formatted_amounts{$_} = $self->format_amount($myconfig, $amounts{$_}, 2);
1862 if ($self->{"language_id"}) {
1864 qq|SELECT t.description_long, l.output_numberformat, l.output_dateformat, l.output_longdates | .
1865 qq|FROM translation_payment_terms t | .
1866 qq|LEFT JOIN language l ON t.language_id = l.id | .
1867 qq|WHERE (t.language_id = ?) AND (t.payment_terms_id = ?)|;
1868 my ($description_long, $output_numberformat, $output_dateformat,
1869 $output_longdates) =
1870 selectrow_query($self, $dbh, $query,
1871 $self->{"language_id"}, $self->{"payment_id"});
1873 $self->{payment_terms} = $description_long if ($description_long);
1875 if ($output_dateformat) {
1876 foreach my $key (qw(netto_date skonto_date)) {
1878 $main::locale->reformat_date($myconfig, $self->{$key},
1884 if ($output_numberformat &&
1885 ($output_numberformat ne $myconfig->{"numberformat"})) {
1886 my $saved_numberformat = $myconfig->{"numberformat"};
1887 $myconfig->{"numberformat"} = $output_numberformat;
1888 map { $formatted_amounts{$_} = $self->format_amount($myconfig, $amounts{$_}) } keys %amounts;
1889 $myconfig->{"numberformat"} = $saved_numberformat;
1893 $self->{payment_terms} =~ s/<%netto_date%>/$self->{netto_date}/g;
1894 $self->{payment_terms} =~ s/<%skonto_date%>/$self->{skonto_date}/g;
1895 $self->{payment_terms} =~ s/<%currency%>/$self->{currency}/g;
1896 $self->{payment_terms} =~ s/<%terms_netto%>/$self->{terms_netto}/g;
1897 $self->{payment_terms} =~ s/<%account_number%>/$self->{account_number}/g;
1898 $self->{payment_terms} =~ s/<%bank%>/$self->{bank}/g;
1899 $self->{payment_terms} =~ s/<%bank_code%>/$self->{bank_code}/g;
1901 map { $self->{payment_terms} =~ s/<%${_}%>/$formatted_amounts{$_}/g; } keys %formatted_amounts;
1903 $self->{skonto_in_percent} = $formatted_amounts{skonto_in_percent};
1905 $main::lxdebug->leave_sub();
1909 sub get_template_language {
1910 $main::lxdebug->enter_sub();
1912 my ($self, $myconfig) = @_;
1914 my $template_code = "";
1916 if ($self->{language_id}) {
1917 my $dbh = $self->get_standard_dbh($myconfig);
1918 my $query = qq|SELECT template_code FROM language WHERE id = ?|;
1919 ($template_code) = selectrow_query($self, $dbh, $query, $self->{language_id});
1922 $main::lxdebug->leave_sub();
1924 return $template_code;
1927 sub get_printer_code {
1928 $main::lxdebug->enter_sub();
1930 my ($self, $myconfig) = @_;
1932 my $template_code = "";
1934 if ($self->{printer_id}) {
1935 my $dbh = $self->get_standard_dbh($myconfig);
1936 my $query = qq|SELECT template_code, printer_command FROM printers WHERE id = ?|;
1937 ($template_code, $self->{printer_command}) = selectrow_query($self, $dbh, $query, $self->{printer_id});
1940 $main::lxdebug->leave_sub();
1942 return $template_code;
1946 $main::lxdebug->enter_sub();
1948 my ($self, $myconfig) = @_;
1950 my $template_code = "";
1952 if ($self->{shipto_id}) {
1953 my $dbh = $self->get_standard_dbh($myconfig);
1954 my $query = qq|SELECT * FROM shipto WHERE shipto_id = ?|;
1955 my $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{shipto_id});
1956 map({ $self->{$_} = $ref->{$_} } keys(%$ref));
1959 $main::lxdebug->leave_sub();
1963 $main::lxdebug->enter_sub();
1965 my ($self, $dbh, $id, $module) = @_;
1970 foreach my $item (qw(name department_1 department_2 street zipcode city country
1971 contact phone fax email)) {
1972 if ($self->{"shipto$item"}) {
1973 $shipto = 1 if ($self->{$item} ne $self->{"shipto$item"});
1975 push(@values, $self->{"shipto${item}"});
1979 if ($self->{shipto_id}) {
1980 my $query = qq|UPDATE shipto set
1982 shiptodepartment_1 = ?,
1983 shiptodepartment_2 = ?,
1992 WHERE shipto_id = ?|;
1993 do_query($self, $dbh, $query, @values, $self->{shipto_id});
1995 my $query = qq|SELECT * FROM shipto
1996 WHERE shiptoname = ? AND
1997 shiptodepartment_1 = ? AND
1998 shiptodepartment_2 = ? AND
1999 shiptostreet = ? AND
2000 shiptozipcode = ? AND
2002 shiptocountry = ? AND
2003 shiptocontact = ? AND
2009 my $insert_check = selectfirst_hashref_query($self, $dbh, $query, @values, $module, $id);
2012 qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2,
2013 shiptostreet, shiptozipcode, shiptocity, shiptocountry,
2014 shiptocontact, shiptophone, shiptofax, shiptoemail, module)
2015 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
2016 do_query($self, $dbh, $query, $id, @values, $module);
2021 $main::lxdebug->leave_sub();
2025 $main::lxdebug->enter_sub();
2027 my ($self, $dbh) = @_;
2029 $dbh ||= $self->get_standard_dbh(\%main::myconfig);
2031 my $query = qq|SELECT id, name FROM employee WHERE login = ?|;
2032 ($self->{"employee_id"}, $self->{"employee"}) = selectrow_query($self, $dbh, $query, $self->{login});
2033 $self->{"employee_id"} *= 1;
2035 $main::lxdebug->leave_sub();
2038 sub get_employee_data {
2039 $main::lxdebug->enter_sub();
2044 Common::check_params(\%params, qw(prefix));
2045 Common::check_params_x(\%params, qw(id));
2048 $main::lxdebug->leave_sub();
2052 my $myconfig = \%main::myconfig;
2053 my $dbh = $params{dbh} || $self->get_standard_dbh($myconfig);
2055 my ($login) = selectrow_query($self, $dbh, qq|SELECT login FROM employee WHERE id = ?|, conv_i($params{id}));
2058 my $user = User->new($login);
2059 map { $self->{$params{prefix} . "_${_}"} = $user->{$_}; } qw(address businessnumber co_ustid company duns email fax name signature taxnumber tel);
2061 $self->{$params{prefix} . '_login'} = $login;
2062 $self->{$params{prefix} . '_name'} ||= $login;
2065 $main::lxdebug->leave_sub();
2069 $main::lxdebug->enter_sub();
2071 my ($self, $myconfig, $reference_date) = @_;
2073 $reference_date = $reference_date ? conv_dateq($reference_date) . '::DATE' : 'current_date';
2075 my $dbh = $self->get_standard_dbh($myconfig);
2076 my $query = qq|SELECT ${reference_date} + terms_netto FROM payment_terms WHERE id = ?|;
2077 my ($duedate) = selectrow_query($self, $dbh, $query, $self->{payment_id});
2079 $main::lxdebug->leave_sub();
2085 $main::lxdebug->enter_sub();
2087 my ($self, $dbh, $id, $key) = @_;
2089 $key = "all_contacts" unless ($key);
2093 $main::lxdebug->leave_sub();
2098 qq|SELECT cp_id, cp_cv_id, cp_name, cp_givenname, cp_abteilung | .
2099 qq|FROM contacts | .
2100 qq|WHERE cp_cv_id = ? | .
2101 qq|ORDER BY lower(cp_name)|;
2103 $self->{$key} = selectall_hashref_query($self, $dbh, $query, $id);
2105 $main::lxdebug->leave_sub();
2109 $main::lxdebug->enter_sub();
2111 my ($self, $dbh, $key) = @_;
2113 my ($all, $old_id, $where, @values);
2115 if (ref($key) eq "HASH") {
2118 $key = "ALL_PROJECTS";
2120 foreach my $p (keys(%{$params})) {
2122 $all = $params->{$p};
2123 } elsif ($p eq "old_id") {
2124 $old_id = $params->{$p};
2125 } elsif ($p eq "key") {
2126 $key = $params->{$p};
2132 $where = "WHERE active ";
2134 if (ref($old_id) eq "ARRAY") {
2135 my @ids = grep({ $_ } @{$old_id});
2137 $where .= " OR id IN (" . join(",", map({ "?" } @ids)) . ") ";
2138 push(@values, @ids);
2141 $where .= " OR (id = ?) ";
2142 push(@values, $old_id);
2148 qq|SELECT id, projectnumber, description, active | .
2151 qq|ORDER BY lower(projectnumber)|;
2153 $self->{$key} = selectall_hashref_query($self, $dbh, $query, @values);
2155 $main::lxdebug->leave_sub();
2159 $main::lxdebug->enter_sub();
2161 my ($self, $dbh, $vc_id, $key) = @_;
2163 $key = "all_shipto" unless ($key);
2166 # get shipping addresses
2167 my $query = qq|SELECT * FROM shipto WHERE trans_id = ?|;
2169 $self->{$key} = selectall_hashref_query($self, $dbh, $query, $vc_id);
2175 $main::lxdebug->leave_sub();
2179 $main::lxdebug->enter_sub();
2181 my ($self, $dbh, $key) = @_;
2183 $key = "all_printers" unless ($key);
2185 my $query = qq|SELECT id, printer_description, printer_command, template_code FROM printers|;
2187 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2189 $main::lxdebug->leave_sub();
2193 $main::lxdebug->enter_sub();
2195 my ($self, $dbh, $params) = @_;
2198 $key = $params->{key};
2199 $key = "all_charts" unless ($key);
2201 my $transdate = quote_db_date($params->{transdate});
2204 qq|SELECT c.id, c.accno, c.description, c.link, c.charttype, tk.taxkey_id, tk.tax_id | .
2206 qq|LEFT JOIN taxkeys tk ON | .
2207 qq|(tk.id = (SELECT id FROM taxkeys | .
2208 qq| WHERE taxkeys.chart_id = c.id AND startdate <= $transdate | .
2209 qq| ORDER BY startdate DESC LIMIT 1)) | .
2210 qq|ORDER BY c.accno|;
2212 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2214 $main::lxdebug->leave_sub();
2217 sub _get_taxcharts {
2218 $main::lxdebug->enter_sub();
2220 my ($self, $dbh, $params) = @_;
2222 my $key = "all_taxcharts";
2225 if (ref $params eq 'HASH') {
2226 $key = $params->{key} if ($params->{key});
2227 if ($params->{module} eq 'AR') {
2228 push @where, 'taxkey NOT IN (8, 9, 18, 19)';
2230 } elsif ($params->{module} eq 'AP') {
2231 push @where, 'taxkey NOT IN (1, 2, 3, 12, 13)';
2238 my $where = ' WHERE ' . join(' AND ', map { "($_)" } @where) if (@where);
2240 my $query = qq|SELECT * FROM tax $where ORDER BY taxkey|;
2242 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2244 $main::lxdebug->leave_sub();
2248 $main::lxdebug->enter_sub();
2250 my ($self, $dbh, $key) = @_;
2252 $key = "all_taxzones" unless ($key);
2254 my $query = qq|SELECT * FROM tax_zones ORDER BY id|;
2256 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2258 $main::lxdebug->leave_sub();
2261 sub _get_employees {
2262 $main::lxdebug->enter_sub();
2264 my ($self, $dbh, $default_key, $key) = @_;
2266 $key = $default_key unless ($key);
2267 $self->{$key} = selectall_hashref_query($self, $dbh, qq|SELECT * FROM employee ORDER BY lower(name)|);
2269 $main::lxdebug->leave_sub();
2272 sub _get_business_types {
2273 $main::lxdebug->enter_sub();
2275 my ($self, $dbh, $key) = @_;
2277 my $options = ref $key eq 'HASH' ? $key : { key => $key };
2278 $options->{key} ||= "all_business_types";
2281 if (exists $options->{salesman}) {
2282 $where = 'WHERE ' . ($options->{salesman} ? '' : 'NOT ') . 'COALESCE(salesman)';
2285 $self->{ $options->{key} } = selectall_hashref_query($self, $dbh, qq|SELECT * FROM business $where ORDER BY lower(description)|);
2287 $main::lxdebug->leave_sub();
2290 sub _get_languages {
2291 $main::lxdebug->enter_sub();
2293 my ($self, $dbh, $key) = @_;
2295 $key = "all_languages" unless ($key);
2297 my $query = qq|SELECT * FROM language ORDER BY id|;
2299 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2301 $main::lxdebug->leave_sub();
2304 sub _get_dunning_configs {
2305 $main::lxdebug->enter_sub();
2307 my ($self, $dbh, $key) = @_;
2309 $key = "all_dunning_configs" unless ($key);
2311 my $query = qq|SELECT * FROM dunning_config ORDER BY dunning_level|;
2313 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2315 $main::lxdebug->leave_sub();
2318 sub _get_currencies {
2319 $main::lxdebug->enter_sub();
2321 my ($self, $dbh, $key) = @_;
2323 $key = "all_currencies" unless ($key);
2325 my $query = qq|SELECT curr AS currency FROM defaults|;
2327 $self->{$key} = [split(/\:/ , selectfirst_hashref_query($self, $dbh, $query)->{currency})];
2329 $main::lxdebug->leave_sub();
2333 $main::lxdebug->enter_sub();
2335 my ($self, $dbh, $key) = @_;
2337 $key = "all_payments" unless ($key);
2339 my $query = qq|SELECT * FROM payment_terms ORDER BY id|;
2341 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2343 $main::lxdebug->leave_sub();
2346 sub _get_customers {
2347 $main::lxdebug->enter_sub();
2349 my ($self, $dbh, $key) = @_;
2351 my $options = ref $key eq 'HASH' ? $key : { key => $key };
2352 $options->{key} ||= "all_customers";
2353 my $limit_clause = "LIMIT $options->{limit}" if $options->{limit};
2354 my $where = $options->{business_is_salesman} ? qq| AND business_id IN (SELECT id FROM business WHERE salesman)| : '';
2356 my $query = qq|SELECT * FROM customer WHERE NOT obsolete $where ORDER BY name $limit_clause|;
2357 $self->{ $options->{key} } = selectall_hashref_query($self, $dbh, $query);
2359 $main::lxdebug->leave_sub();
2363 $main::lxdebug->enter_sub();
2365 my ($self, $dbh, $key) = @_;
2367 $key = "all_vendors" unless ($key);
2369 my $query = qq|SELECT * FROM vendor WHERE NOT obsolete ORDER BY name|;
2371 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2373 $main::lxdebug->leave_sub();
2376 sub _get_departments {
2377 $main::lxdebug->enter_sub();
2379 my ($self, $dbh, $key) = @_;
2381 $key = "all_departments" unless ($key);
2383 my $query = qq|SELECT * FROM department ORDER BY description|;
2385 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2387 $main::lxdebug->leave_sub();
2390 sub _get_warehouses {
2391 $main::lxdebug->enter_sub();
2393 my ($self, $dbh, $param) = @_;
2395 my ($key, $bins_key);
2397 if ('' eq ref $param) {
2401 $key = $param->{key};
2402 $bins_key = $param->{bins};
2405 my $query = qq|SELECT w.* FROM warehouse w
2406 WHERE (NOT w.invalid) AND
2407 ((SELECT COUNT(b.*) FROM bin b WHERE b.warehouse_id = w.id) > 0)
2408 ORDER BY w.sortkey|;
2410 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2413 $query = qq|SELECT id, description FROM bin WHERE warehouse_id = ?|;
2414 my $sth = prepare_query($self, $dbh, $query);
2416 foreach my $warehouse (@{ $self->{$key} }) {
2417 do_statement($self, $sth, $query, $warehouse->{id});
2418 $warehouse->{$bins_key} = [];
2420 while (my $ref = $sth->fetchrow_hashref()) {
2421 push @{ $warehouse->{$bins_key} }, $ref;
2427 $main::lxdebug->leave_sub();
2431 $main::lxdebug->enter_sub();
2433 my ($self, $dbh, $table, $key, $sortkey) = @_;
2435 my $query = qq|SELECT * FROM $table|;
2436 $query .= qq| ORDER BY $sortkey| if ($sortkey);
2438 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2440 $main::lxdebug->leave_sub();
2444 # $main::lxdebug->enter_sub();
2446 # my ($self, $dbh, $key) = @_;
2448 # $key ||= "all_groups";
2450 # my $groups = $main::auth->read_groups();
2452 # $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2454 # $main::lxdebug->leave_sub();
2458 $main::lxdebug->enter_sub();
2463 my $dbh = $self->get_standard_dbh(\%main::myconfig);
2464 my ($sth, $query, $ref);
2466 my $vc = $self->{"vc"} eq "customer" ? "customer" : "vendor";
2467 my $vc_id = $self->{"${vc}_id"};
2469 if ($params{"contacts"}) {
2470 $self->_get_contacts($dbh, $vc_id, $params{"contacts"});
2473 if ($params{"shipto"}) {
2474 $self->_get_shipto($dbh, $vc_id, $params{"shipto"});
2477 if ($params{"projects"} || $params{"all_projects"}) {
2478 $self->_get_projects($dbh, $params{"all_projects"} ?
2479 $params{"all_projects"} : $params{"projects"},
2480 $params{"all_projects"} ? 1 : 0);
2483 if ($params{"printers"}) {
2484 $self->_get_printers($dbh, $params{"printers"});
2487 if ($params{"languages"}) {
2488 $self->_get_languages($dbh, $params{"languages"});
2491 if ($params{"charts"}) {
2492 $self->_get_charts($dbh, $params{"charts"});
2495 if ($params{"taxcharts"}) {
2496 $self->_get_taxcharts($dbh, $params{"taxcharts"});
2499 if ($params{"taxzones"}) {
2500 $self->_get_taxzones($dbh, $params{"taxzones"});
2503 if ($params{"employees"}) {
2504 $self->_get_employees($dbh, "all_employees", $params{"employees"});
2507 if ($params{"salesmen"}) {
2508 $self->_get_employees($dbh, "all_salesmen", $params{"salesmen"});
2511 if ($params{"business_types"}) {
2512 $self->_get_business_types($dbh, $params{"business_types"});
2515 if ($params{"dunning_configs"}) {
2516 $self->_get_dunning_configs($dbh, $params{"dunning_configs"});
2519 if($params{"currencies"}) {
2520 $self->_get_currencies($dbh, $params{"currencies"});
2523 if($params{"customers"}) {
2524 $self->_get_customers($dbh, $params{"customers"});
2527 if($params{"vendors"}) {
2528 if (ref $params{"vendors"} eq 'HASH') {
2529 $self->_get_vendors($dbh, $params{"vendors"}{key}, $params{"vendors"}{limit});
2531 $self->_get_vendors($dbh, $params{"vendors"});
2535 if($params{"payments"}) {
2536 $self->_get_payments($dbh, $params{"payments"});
2539 if($params{"departments"}) {
2540 $self->_get_departments($dbh, $params{"departments"});
2543 if ($params{price_factors}) {
2544 $self->_get_simple($dbh, 'price_factors', $params{price_factors}, 'sortkey');
2547 if ($params{warehouses}) {
2548 $self->_get_warehouses($dbh, $params{warehouses});
2551 # if ($params{groups}) {
2552 # $self->_get_groups($dbh, $params{groups});
2555 if ($params{partsgroup}) {
2556 $self->get_partsgroup(\%main::myconfig, { all => 1, target => $params{partsgroup} });
2559 $main::lxdebug->leave_sub();
2562 # this sub gets the id and name from $table
2564 $main::lxdebug->enter_sub();
2566 my ($self, $myconfig, $table) = @_;
2568 # connect to database
2569 my $dbh = $self->get_standard_dbh($myconfig);
2571 $table = $table eq "customer" ? "customer" : "vendor";
2572 my $arap = $self->{arap} eq "ar" ? "ar" : "ap";
2574 my ($query, @values);
2576 if (!$self->{openinvoices}) {
2578 if ($self->{customernumber} ne "") {
2579 $where = qq|(vc.customernumber ILIKE ?)|;
2580 push(@values, '%' . $self->{customernumber} . '%');
2582 $where = qq|(vc.name ILIKE ?)|;
2583 push(@values, '%' . $self->{$table} . '%');
2587 qq~SELECT vc.id, vc.name,
2588 vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
2590 WHERE $where AND (NOT vc.obsolete)
2594 qq~SELECT DISTINCT vc.id, vc.name,
2595 vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
2597 JOIN $table vc ON (a.${table}_id = vc.id)
2598 WHERE NOT (a.amount = a.paid) AND (vc.name ILIKE ?)
2600 push(@values, '%' . $self->{$table} . '%');
2603 $self->{name_list} = selectall_hashref_query($self, $dbh, $query, @values);
2605 $main::lxdebug->leave_sub();
2607 return scalar(@{ $self->{name_list} });
2610 # the selection sub is used in the AR, AP, IS, IR and OE module
2613 $main::lxdebug->enter_sub();
2615 my ($self, $myconfig, $table, $module) = @_;
2618 my $dbh = $self->get_standard_dbh($myconfig);
2620 $table = $table eq "customer" ? "customer" : "vendor";
2622 my $query = qq|SELECT count(*) FROM $table|;
2623 my ($count) = selectrow_query($self, $dbh, $query);
2625 # build selection list
2626 if ($count <= $myconfig->{vclimit}) {
2627 $query = qq|SELECT id, name, salesman_id
2628 FROM $table WHERE NOT obsolete
2630 $self->{"all_$table"} = selectall_hashref_query($self, $dbh, $query);
2634 $self->get_employee($dbh);
2636 # setup sales contacts
2637 $query = qq|SELECT e.id, e.name
2639 WHERE (e.sales = '1') AND (NOT e.id = ?)|;
2640 $self->{all_employees} = selectall_hashref_query($self, $dbh, $query, $self->{employee_id});
2643 push(@{ $self->{all_employees} },
2644 { id => $self->{employee_id},
2645 name => $self->{employee} });
2647 # sort the whole thing
2648 @{ $self->{all_employees} } =
2649 sort { $a->{name} cmp $b->{name} } @{ $self->{all_employees} };
2651 if ($module eq 'AR') {
2653 # prepare query for departments
2654 $query = qq|SELECT id, description
2657 ORDER BY description|;
2660 $query = qq|SELECT id, description
2662 ORDER BY description|;
2665 $self->{all_departments} = selectall_hashref_query($self, $dbh, $query);
2668 $query = qq|SELECT id, description
2672 $self->{languages} = selectall_hashref_query($self, $dbh, $query);
2675 $query = qq|SELECT printer_description, id
2677 ORDER BY printer_description|;
2679 $self->{printers} = selectall_hashref_query($self, $dbh, $query);
2682 $query = qq|SELECT id, description
2686 $self->{payment_terms} = selectall_hashref_query($self, $dbh, $query);
2688 $main::lxdebug->leave_sub();
2691 sub language_payment {
2692 $main::lxdebug->enter_sub();
2694 my ($self, $myconfig) = @_;
2696 my $dbh = $self->get_standard_dbh($myconfig);
2698 my $query = qq|SELECT id, description
2702 $self->{languages} = selectall_hashref_query($self, $dbh, $query);
2705 $query = qq|SELECT printer_description, id
2707 ORDER BY printer_description|;
2709 $self->{printers} = selectall_hashref_query($self, $dbh, $query);
2712 $query = qq|SELECT id, description
2716 $self->{payment_terms} = selectall_hashref_query($self, $dbh, $query);
2718 # get buchungsgruppen
2719 $query = qq|SELECT id, description
2720 FROM buchungsgruppen|;
2722 $self->{BUCHUNGSGRUPPEN} = selectall_hashref_query($self, $dbh, $query);
2724 $main::lxdebug->leave_sub();
2727 # this is only used for reports
2728 sub all_departments {
2729 $main::lxdebug->enter_sub();
2731 my ($self, $myconfig, $table) = @_;
2733 my $dbh = $self->get_standard_dbh($myconfig);
2736 if ($table eq 'customer') {
2737 $where = "WHERE role = 'P' ";
2740 my $query = qq|SELECT id, description
2743 ORDER BY description|;
2744 $self->{all_departments} = selectall_hashref_query($self, $dbh, $query);
2746 delete($self->{all_departments}) unless (@{ $self->{all_departments} || [] });
2748 $main::lxdebug->leave_sub();
2752 $main::lxdebug->enter_sub();
2754 my ($self, $module, $myconfig, $table, $provided_dbh) = @_;
2757 if ($table eq "customer") {
2766 $self->all_vc($myconfig, $table, $module);
2768 # get last customers or vendors
2769 my ($query, $sth, $ref);
2771 my $dbh = $provided_dbh ? $provided_dbh : $self->get_standard_dbh($myconfig);
2776 my $transdate = "current_date";
2777 if ($self->{transdate}) {
2778 $transdate = $dbh->quote($self->{transdate});
2781 # now get the account numbers
2782 $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
2783 FROM chart c, taxkeys tk
2784 WHERE (c.link LIKE ?) AND (c.id = tk.chart_id) AND tk.id =
2785 (SELECT id FROM taxkeys WHERE (taxkeys.chart_id = c.id) AND (startdate <= $transdate) ORDER BY startdate DESC LIMIT 1)
2788 $sth = $dbh->prepare($query);
2790 do_statement($self, $sth, $query, '%' . $module . '%');
2792 $self->{accounts} = "";
2793 while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
2795 foreach my $key (split(/:/, $ref->{link})) {
2796 if ($key =~ /\Q$module\E/) {
2798 # cross reference for keys
2799 $xkeyref{ $ref->{accno} } = $key;
2801 push @{ $self->{"${module}_links"}{$key} },
2802 { accno => $ref->{accno},
2803 description => $ref->{description},
2804 taxkey => $ref->{taxkey_id},
2805 tax_id => $ref->{tax_id} };
2807 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2813 # get taxkeys and description
2814 $query = qq|SELECT id, taxkey, taxdescription FROM tax|;
2815 $self->{TAXKEY} = selectall_hashref_query($self, $dbh, $query);
2817 if (($module eq "AP") || ($module eq "AR")) {
2818 # get tax rates and description
2819 $query = qq|SELECT * FROM tax|;
2820 $self->{TAX} = selectall_hashref_query($self, $dbh, $query);
2826 a.cp_id, a.invnumber, a.transdate, a.${table}_id, a.datepaid,
2827 a.duedate, a.ordnumber, a.taxincluded, a.curr AS currency, a.notes,
2828 a.intnotes, a.department_id, a.amount AS oldinvtotal,
2829 a.paid AS oldtotalpaid, a.employee_id, a.gldate, a.type,
2831 d.description AS department,
2834 JOIN $table c ON (a.${table}_id = c.id)
2835 LEFT JOIN employee e ON (e.id = a.employee_id)
2836 LEFT JOIN department d ON (d.id = a.department_id)
2838 $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{id});
2840 foreach my $key (keys %$ref) {
2841 $self->{$key} = $ref->{$key};
2844 my $transdate = "current_date";
2845 if ($self->{transdate}) {
2846 $transdate = $dbh->quote($self->{transdate});
2849 # now get the account numbers
2850 $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
2852 LEFT JOIN taxkeys tk ON (tk.chart_id = c.id)
2854 AND (tk.id = (SELECT id FROM taxkeys WHERE taxkeys.chart_id = c.id AND startdate <= $transdate ORDER BY startdate DESC LIMIT 1)
2855 OR c.link LIKE '%_tax%' OR c.taxkey_id IS NULL)
2858 $sth = $dbh->prepare($query);
2859 do_statement($self, $sth, $query, "%$module%");
2861 $self->{accounts} = "";
2862 while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
2864 foreach my $key (split(/:/, $ref->{link})) {
2865 if ($key =~ /\Q$module\E/) {
2867 # cross reference for keys
2868 $xkeyref{ $ref->{accno} } = $key;
2870 push @{ $self->{"${module}_links"}{$key} },
2871 { accno => $ref->{accno},
2872 description => $ref->{description},
2873 taxkey => $ref->{taxkey_id},
2874 tax_id => $ref->{tax_id} };
2876 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2882 # get amounts from individual entries
2885 c.accno, c.description,
2886 a.source, a.amount, a.memo, a.transdate, a.cleared, a.project_id, a.taxkey,
2890 LEFT JOIN chart c ON (c.id = a.chart_id)
2891 LEFT JOIN project p ON (p.id = a.project_id)
2892 LEFT JOIN tax t ON (t.id= (SELECT tk.tax_id FROM taxkeys tk
2893 WHERE (tk.taxkey_id=a.taxkey) AND
2894 ((CASE WHEN a.chart_id IN (SELECT chart_id FROM taxkeys WHERE taxkey_id = a.taxkey)
2895 THEN tk.chart_id = a.chart_id
2898 OR (c.link='%tax%')) AND
2899 (startdate <= a.transdate) ORDER BY startdate DESC LIMIT 1))
2900 WHERE a.trans_id = ?
2901 AND a.fx_transaction = '0'
2902 ORDER BY a.acc_trans_id, a.transdate|;
2903 $sth = $dbh->prepare($query);
2904 do_statement($self, $sth, $query, $self->{id});
2906 # get exchangerate for currency
2907 $self->{exchangerate} =
2908 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate}, $fld);
2911 # store amounts in {acc_trans}{$key} for multiple accounts
2912 while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
2913 $ref->{exchangerate} =
2914 $self->get_exchangerate($dbh, $self->{currency}, $ref->{transdate}, $fld);
2915 if (!($xkeyref{ $ref->{accno} } =~ /tax/)) {
2918 if (($xkeyref{ $ref->{accno} } =~ /paid/) && ($self->{type} eq "credit_note")) {
2919 $ref->{amount} *= -1;
2921 $ref->{index} = $index;
2923 push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref;
2929 d.curr AS currencies, d.closedto, d.revtrans,
2930 (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2931 (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2933 $ref = selectfirst_hashref_query($self, $dbh, $query);
2934 map { $self->{$_} = $ref->{$_} } keys %$ref;
2941 current_date AS transdate, d.curr AS currencies, d.closedto, d.revtrans,
2942 (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2943 (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2945 $ref = selectfirst_hashref_query($self, $dbh, $query);
2946 map { $self->{$_} = $ref->{$_} } keys %$ref;
2948 if ($self->{"$self->{vc}_id"}) {
2950 # only setup currency
2951 ($self->{currency}) = split(/:/, $self->{currencies});
2955 $self->lastname_used($dbh, $myconfig, $table, $module);
2957 # get exchangerate for currency
2958 $self->{exchangerate} =
2959 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate}, $fld);
2965 $main::lxdebug->leave_sub();
2969 $main::lxdebug->enter_sub();
2971 my ($self, $dbh, $myconfig, $table, $module) = @_;
2975 $table = $table eq "customer" ? "customer" : "vendor";
2976 my %column_map = ("a.curr" => "currency",
2977 "a.${table}_id" => "${table}_id",
2978 "a.department_id" => "department_id",
2979 "d.description" => "department",
2980 "ct.name" => $table,
2981 "current_date + ct.terms" => "duedate",
2984 if ($self->{type} =~ /delivery_order/) {
2985 $arap = 'delivery_orders';
2986 delete $column_map{"a.curr"};
2988 } elsif ($self->{type} =~ /_order/) {
2990 $where = "quotation = '0'";
2992 } elsif ($self->{type} =~ /_quotation/) {
2994 $where = "quotation = '1'";
2996 } elsif ($table eq 'customer') {
3004 $where = "($where) AND" if ($where);
3005 my $query = qq|SELECT MAX(id) FROM $arap
3006 WHERE $where ${table}_id > 0|;
3007 my ($trans_id) = selectrow_query($self, $dbh, $query);
3010 my $column_spec = join(', ', map { "${_} AS $column_map{$_}" } keys %column_map);
3011 $query = qq|SELECT $column_spec
3013 LEFT JOIN $table ct ON (a.${table}_id = ct.id)
3014 LEFT JOIN department d ON (a.department_id = d.id)
3016 my $ref = selectfirst_hashref_query($self, $dbh, $query, $trans_id);
3018 map { $self->{$_} = $ref->{$_} } values %column_map;
3020 $main::lxdebug->leave_sub();
3024 $main::lxdebug->enter_sub();
3027 my $myconfig = shift || \%::myconfig;
3028 my ($thisdate, $days) = @_;
3030 my $dbh = $self->get_standard_dbh($myconfig);
3035 my $dateformat = $myconfig->{dateformat};
3036 $dateformat .= "yy" if $myconfig->{dateformat} !~ /^y/;
3037 $thisdate = $dbh->quote($thisdate);
3038 $query = qq|SELECT to_date($thisdate, '$dateformat') + $days AS thisdate|;
3040 $query = qq|SELECT current_date AS thisdate|;
3043 ($thisdate) = selectrow_query($self, $dbh, $query);
3045 $main::lxdebug->leave_sub();
3051 $main::lxdebug->enter_sub();
3053 my ($self, $string) = @_;
3055 if ($string !~ /%/) {
3056 $string = "%$string%";
3059 $string =~ s/\'/\'\'/g;
3061 $main::lxdebug->leave_sub();
3067 $main::lxdebug->enter_sub();
3069 my ($self, $flds, $new, $count, $numrows) = @_;
3073 map { push @ndx, { num => $new->[$_ - 1]->{runningnumber}, ndx => $_ } } 1 .. $count;
3078 foreach my $item (sort { $a->{num} <=> $b->{num} } @ndx) {
3080 my $j = $item->{ndx} - 1;
3081 map { $self->{"${_}_$i"} = $new->[$j]->{$_} } @{$flds};
3085 for $i ($count + 1 .. $numrows) {
3086 map { delete $self->{"${_}_$i"} } @{$flds};
3089 $main::lxdebug->leave_sub();
3093 $main::lxdebug->enter_sub();
3095 my ($self, $myconfig) = @_;
3099 my $dbh = $self->dbconnect_noauto($myconfig);
3101 my $query = qq|DELETE FROM status
3102 WHERE (formname = ?) AND (trans_id = ?)|;
3103 my $sth = prepare_query($self, $dbh, $query);
3105 if ($self->{formname} =~ /(check|receipt)/) {
3106 for $i (1 .. $self->{rowcount}) {
3107 do_statement($self, $sth, $query, $self->{formname}, $self->{"id_$i"} * 1);
3110 do_statement($self, $sth, $query, $self->{formname}, $self->{id});
3114 my $printed = ($self->{printed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3115 my $emailed = ($self->{emailed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3117 my %queued = split / /, $self->{queued};
3120 if ($self->{formname} =~ /(check|receipt)/) {
3122 # this is a check or receipt, add one entry for each lineitem
3123 my ($accno) = split /--/, $self->{account};
3124 $query = qq|INSERT INTO status (trans_id, printed, spoolfile, formname, chart_id)
3125 VALUES (?, ?, ?, ?, (SELECT c.id FROM chart c WHERE c.accno = ?))|;
3126 @values = ($printed, $queued{$self->{formname}}, $self->{prinform}, $accno);
3127 $sth = prepare_query($self, $dbh, $query);
3129 for $i (1 .. $self->{rowcount}) {
3130 if ($self->{"checked_$i"}) {
3131 do_statement($self, $sth, $query, $self->{"id_$i"}, @values);
3137 $query = qq|INSERT INTO status (trans_id, printed, emailed, spoolfile, formname)
3138 VALUES (?, ?, ?, ?, ?)|;
3139 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed,
3140 $queued{$self->{formname}}, $self->{formname});
3146 $main::lxdebug->leave_sub();
3150 $main::lxdebug->enter_sub();
3152 my ($self, $dbh) = @_;
3154 my ($query, $printed, $emailed);
3156 my $formnames = $self->{printed};
3157 my $emailforms = $self->{emailed};
3159 $query = qq|DELETE FROM status
3160 WHERE (formname = ?) AND (trans_id = ?)|;
3161 do_query($self, $dbh, $query, $self->{formname}, $self->{id});
3163 # this only applies to the forms
3164 # checks and receipts are posted when printed or queued
3166 if ($self->{queued}) {
3167 my %queued = split / /, $self->{queued};
3169 foreach my $formname (keys %queued) {
3170 $printed = ($self->{printed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3171 $emailed = ($self->{emailed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3173 $query = qq|INSERT INTO status (trans_id, printed, emailed, spoolfile, formname)
3174 VALUES (?, ?, ?, ?, ?)|;
3175 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed, $queued{$formname}, $formname);
3177 $formnames =~ s/\Q$self->{formname}\E//;
3178 $emailforms =~ s/\Q$self->{formname}\E//;
3183 # save printed, emailed info
3184 $formnames =~ s/^ +//g;
3185 $emailforms =~ s/^ +//g;
3188 map { $status{$_}{printed} = 1 } split / +/, $formnames;
3189 map { $status{$_}{emailed} = 1 } split / +/, $emailforms;
3191 foreach my $formname (keys %status) {
3192 $printed = ($formnames =~ /\Q$self->{formname}\E/) ? "1" : "0";
3193 $emailed = ($emailforms =~ /\Q$self->{formname}\E/) ? "1" : "0";
3195 $query = qq|INSERT INTO status (trans_id, printed, emailed, formname)
3196 VALUES (?, ?, ?, ?)|;
3197 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed, $formname);
3200 $main::lxdebug->leave_sub();
3204 # $main::locale->text('SAVED')
3205 # $main::locale->text('DELETED')
3206 # $main::locale->text('ADDED')
3207 # $main::locale->text('PAYMENT POSTED')
3208 # $main::locale->text('POSTED')
3209 # $main::locale->text('POSTED AS NEW')
3210 # $main::locale->text('ELSE')
3211 # $main::locale->text('SAVED FOR DUNNING')
3212 # $main::locale->text('DUNNING STARTED')
3213 # $main::locale->text('PRINTED')
3214 # $main::locale->text('MAILED')
3215 # $main::locale->text('SCREENED')
3216 # $main::locale->text('CANCELED')
3217 # $main::locale->text('invoice')
3218 # $main::locale->text('proforma')
3219 # $main::locale->text('sales_order')
3220 # $main::locale->text('packing_list')
3221 # $main::locale->text('pick_list')
3222 # $main::locale->text('purchase_order')
3223 # $main::locale->text('bin_list')
3224 # $main::locale->text('sales_quotation')
3225 # $main::locale->text('request_quotation')
3228 $main::lxdebug->enter_sub();
3233 if(!exists $self->{employee_id}) {
3234 &get_employee($self, $dbh);
3238 qq|INSERT INTO history_erp (trans_id, employee_id, addition, what_done, snumbers) | .
3239 qq|VALUES (?, (SELECT id FROM employee WHERE login = ?), ?, ?, ?)|;
3240 my @values = (conv_i($self->{id}), $self->{login},
3241 $self->{addition}, $self->{what_done}, "$self->{snumbers}");
3242 do_query($self, $dbh, $query, @values);
3244 $main::lxdebug->leave_sub();
3248 $main::lxdebug->enter_sub();
3250 my ($self, $dbh, $trans_id, $restriction, $order) = @_;
3251 my ($orderBy, $desc) = split(/\-\-/, $order);
3252 $order = " ORDER BY " . ($order eq "" ? " h.itime " : ($desc == 1 ? $orderBy . " DESC " : $orderBy . " "));
3255 if ($trans_id ne "") {
3257 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 | .
3258 qq|FROM history_erp h | .
3259 qq|LEFT JOIN employee emp ON (emp.id = h.employee_id) | .
3260 qq|WHERE (trans_id = | . $trans_id . qq|) $restriction | .
3263 my $sth = $dbh->prepare($query) || $self->dberror($query);
3265 $sth->execute() || $self->dberror("$query");
3267 while(my $hash_ref = $sth->fetchrow_hashref()) {
3268 $hash_ref->{addition} = $main::locale->text($hash_ref->{addition});
3269 $hash_ref->{what_done} = $main::locale->text($hash_ref->{what_done});
3270 $hash_ref->{snumbers} =~ s/^.+_(.*)$/$1/g;
3271 $tempArray[$i++] = $hash_ref;
3273 $main::lxdebug->leave_sub() and return \@tempArray
3274 if ($i > 0 && $tempArray[0] ne "");
3276 $main::lxdebug->leave_sub();
3280 sub update_defaults {
3281 $main::lxdebug->enter_sub();
3283 my ($self, $myconfig, $fld, $provided_dbh) = @_;
3286 if ($provided_dbh) {
3287 $dbh = $provided_dbh;
3289 $dbh = $self->dbconnect_noauto($myconfig);
3291 my $query = qq|SELECT $fld FROM defaults FOR UPDATE|;
3292 my $sth = $dbh->prepare($query);
3294 $sth->execute || $self->dberror($query);
3295 my ($var) = $sth->fetchrow_array;
3298 if ($var =~ m/\d+$/) {
3299 my $new_var = (substr $var, $-[0]) * 1 + 1;
3300 my $len_diff = length($var) - $-[0] - length($new_var);
3301 $var = substr($var, 0, $-[0]) . ($len_diff > 0 ? '0' x $len_diff : '') . $new_var;
3307 $query = qq|UPDATE defaults SET $fld = ?|;
3308 do_query($self, $dbh, $query, $var);
3310 if (!$provided_dbh) {
3315 $main::lxdebug->leave_sub();
3320 sub update_business {
3321 $main::lxdebug->enter_sub();
3323 my ($self, $myconfig, $business_id, $provided_dbh) = @_;
3326 if ($provided_dbh) {
3327 $dbh = $provided_dbh;
3329 $dbh = $self->dbconnect_noauto($myconfig);
3332 qq|SELECT customernumberinit FROM business
3333 WHERE id = ? FOR UPDATE|;
3334 my ($var) = selectrow_query($self, $dbh, $query, $business_id);
3336 return undef unless $var;
3338 if ($var =~ m/\d+$/) {
3339 my $new_var = (substr $var, $-[0]) * 1 + 1;
3340 my $len_diff = length($var) - $-[0] - length($new_var);
3341 $var = substr($var, 0, $-[0]) . ($len_diff > 0 ? '0' x $len_diff : '') . $new_var;
3347 $query = qq|UPDATE business
3348 SET customernumberinit = ?
3350 do_query($self, $dbh, $query, $var, $business_id);
3352 if (!$provided_dbh) {
3357 $main::lxdebug->leave_sub();
3362 sub get_partsgroup {
3363 $main::lxdebug->enter_sub();
3365 my ($self, $myconfig, $p) = @_;
3366 my $target = $p->{target} || 'all_partsgroup';
3368 my $dbh = $self->get_standard_dbh($myconfig);
3370 my $query = qq|SELECT DISTINCT pg.id, pg.partsgroup
3372 JOIN parts p ON (p.partsgroup_id = pg.id) |;
3375 if ($p->{searchitems} eq 'part') {
3376 $query .= qq|WHERE p.inventory_accno_id > 0|;
3378 if ($p->{searchitems} eq 'service') {
3379 $query .= qq|WHERE p.inventory_accno_id IS NULL|;
3381 if ($p->{searchitems} eq 'assembly') {
3382 $query .= qq|WHERE p.assembly = '1'|;
3384 if ($p->{searchitems} eq 'labor') {
3385 $query .= qq|WHERE (p.inventory_accno_id > 0) AND (p.income_accno_id IS NULL)|;
3388 $query .= qq|ORDER BY partsgroup|;
3391 $query = qq|SELECT id, partsgroup FROM partsgroup
3392 ORDER BY partsgroup|;
3395 if ($p->{language_code}) {
3396 $query = qq|SELECT DISTINCT pg.id, pg.partsgroup,
3397 t.description AS translation
3399 JOIN parts p ON (p.partsgroup_id = pg.id)
3400 LEFT JOIN translation t ON ((t.trans_id = pg.id) AND (t.language_code = ?))
3401 ORDER BY translation|;
3402 @values = ($p->{language_code});
3405 $self->{$target} = selectall_hashref_query($self, $dbh, $query, @values);
3407 $main::lxdebug->leave_sub();
3410 sub get_pricegroup {
3411 $main::lxdebug->enter_sub();
3413 my ($self, $myconfig, $p) = @_;
3415 my $dbh = $self->get_standard_dbh($myconfig);
3417 my $query = qq|SELECT p.id, p.pricegroup
3420 $query .= qq| ORDER BY pricegroup|;
3423 $query = qq|SELECT id, pricegroup FROM pricegroup
3424 ORDER BY pricegroup|;
3427 $self->{all_pricegroup} = selectall_hashref_query($self, $dbh, $query);
3429 $main::lxdebug->leave_sub();
3433 # usage $form->all_years($myconfig, [$dbh])
3434 # return list of all years where bookings found
3437 $main::lxdebug->enter_sub();
3439 my ($self, $myconfig, $dbh) = @_;
3441 $dbh ||= $self->get_standard_dbh($myconfig);
3444 my $query = qq|SELECT (SELECT MIN(transdate) FROM acc_trans),
3445 (SELECT MAX(transdate) FROM acc_trans)|;
3446 my ($startdate, $enddate) = selectrow_query($self, $dbh, $query);
3448 if ($myconfig->{dateformat} =~ /^yy/) {
3449 ($startdate) = split /\W/, $startdate;
3450 ($enddate) = split /\W/, $enddate;
3452 (@_) = split /\W/, $startdate;
3454 (@_) = split /\W/, $enddate;
3459 $startdate = substr($startdate,0,4);
3460 $enddate = substr($enddate,0,4);
3462 while ($enddate >= $startdate) {
3463 push @all_years, $enddate--;
3468 $main::lxdebug->leave_sub();
3472 $main::lxdebug->enter_sub();
3476 map { $self->{_VAR_BACKUP}->{$_} = $self->{$_} if exists $self->{$_} } @vars;
3478 $main::lxdebug->leave_sub();
3482 $main::lxdebug->enter_sub();
3487 map { $self->{$_} = $self->{_VAR_BACKUP}->{$_} if exists $self->{_VAR_BACKUP}->{$_} } @vars;
3489 $main::lxdebug->leave_sub();
3498 SL::Form.pm - main data object.
3502 This is the main data object of Lx-Office.
3503 Unfortunately it also acts as a god object for certain data retrieval procedures used in the entry points.
3504 Points of interest for a beginner are:
3506 - $form->error - renders a generic error in html. accepts an error message
3507 - $form->get_standard_dbh - returns a database connection for the
3509 =head1 SPECIAL FUNCTIONS
3513 =item _store_value()
3515 parses a complex var name, and stores it in the form.
3518 $form->_store_value($key, $value);
3520 keys must start with a string, and can contain various tokens.
3521 supported key structures are:
3524 simple key strings work as expected
3529 separating two keys by a dot (.) will result in a hash lookup for the inner value
3530 this is similar to the behaviour of java and templating mechanisms.
3532 filter.description => $form->{filter}->{description}
3534 3. array+hashref access
3536 adding brackets ([]) before the dot will cause the next hash to be put into an array.
3537 using [+] instead of [] will force a new array index. this is useful for recurring
3538 data structures like part lists. put a [+] into the first varname, and use [] on the
3541 repeating these names in your template:
3544 invoice.items[].parts_id
3548 $form->{invoice}->{items}->[
3562 using brackets at the end of a name will result in a pure array to be created.
3563 note that you mustn't use [+], which is reserved for array+hash access and will
3564 result in undefined behaviour in array context.
3566 filter.status[] => $form->{status}->[ val1, val2, ... ]
3568 =item update_business PARAMS
3571 \%config, - config hashref
3572 $business_id, - business id
3573 $dbh - optional database handle
3575 handles business (thats customer/vendor types) sequences.
3577 special behaviour for empty strings in customerinitnumber field:
3578 will in this case not increase the value, and return undef.
3580 =item redirect_header $url
3582 Generates a HTTP redirection header for the new C<$url>. Constructs an
3583 absolute URL including scheme, host name and port. If C<$url> is a
3584 relative URL then it is considered relative to Lx-Office base URL.
3586 This function C<die>s if headers have already been created with
3587 C<$::form-E<gt>header>.
3591 print $::form->redirect_header('oe.pl?action=edit&id=1234');
3592 print $::form->redirect_header('http://www.lx-office.org/');