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 _add_to_request_uri {
561 my $relative_new_path = shift;
562 my $request_uri = shift || $self->_get_request_uri;
563 my $relative_new_uri = URI->new($relative_new_path);
564 my @request_segments = $request_uri->path_segments;
566 my $new_uri = $request_uri->clone;
567 $new_uri->path_segments(@request_segments[0..scalar(@request_segments) - 2], $relative_new_uri->path_segments);
572 sub create_http_response {
573 $main::lxdebug->enter_sub();
578 my $cgi = $main::cgi;
579 $cgi ||= CGI->new('');
582 if (defined $main::auth) {
583 my $uri = $self->_get_request_uri;
584 my @segments = $uri->path_segments;
586 $uri->path_segments(@segments);
588 my $session_cookie_value = $main::auth->get_session_id();
589 $session_cookie_value ||= 'NO_SESSION';
591 $session_cookie = $cgi->cookie('-name' => $main::auth->get_session_cookie_name(),
592 '-value' => $session_cookie_value,
593 '-path' => $uri->path,
594 '-secure' => $ENV{HTTPS});
597 my %cgi_params = ('-type' => $params{content_type});
598 $cgi_params{'-charset'} = $params{charset} if ($params{charset});
600 my $output = $cgi->header('-cookie' => $session_cookie,
603 $main::lxdebug->leave_sub();
610 $main::lxdebug->enter_sub();
612 # extra code ist currently only used by menuv3 and menuv4 to set their css.
613 # it is strongly deprecated, and will be changed in a future version.
614 my ($self, $extra_code) = @_;
616 if ($self->{header}) {
617 $main::lxdebug->leave_sub();
621 my ($stylesheet, $favicon, $pagelayout);
623 if ($ENV{HTTP_USER_AGENT}) {
626 if ($ENV{'HTTP_USER_AGENT'} =~ m/MSIE\s+\d/) {
627 # Only set the DOCTYPE for Internet Explorer. Other browsers have problems displaying the menu otherwise.
628 $doctype = qq|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n|;
631 my $stylesheets = "$self->{stylesheet} $self->{stylesheets}";
633 $stylesheets =~ s|^\s*||;
634 $stylesheets =~ s|\s*$||;
635 foreach my $file (split m/\s+/, $stylesheets) {
637 next if (! -f "css/$file");
639 $stylesheet .= qq|<link rel="stylesheet" href="css/$file" TYPE="text/css" TITLE="Lx-Office stylesheet">\n|;
642 $self->{favicon} = "favicon.ico" unless $self->{favicon};
644 if ($self->{favicon} && (-f "$self->{favicon}")) {
646 qq|<LINK REL="shortcut icon" HREF="$self->{favicon}" TYPE="image/x-icon">
650 my $db_charset = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
652 if ($self->{landscape}) {
653 $pagelayout = qq|<style type="text/css">
654 \@page { size:landscape; }
659 <script type="text/javascript">
662 document.$self->{fokus}.focus();
666 | if $self->{"fokus"};
670 if ($self->{jsscript} == 1) {
673 <script type="text/javascript" src="js/jquery.js"></script>
674 <script type="text/javascript" src="js/common.js"></script>
675 <style type="text/css">\@import url(js/jscalendar/calendar-win2k-1.css);</style>
676 <script type="text/javascript" src="js/jscalendar/calendar.js"></script>
677 <script type="text/javascript" src="js/jscalendar/lang/calendar-de.js"></script>
678 <script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script>
685 ? "$self->{title} - $self->{titlebar}"
688 for my $item (@ { $self->{AJAX} || [] }) {
689 $ajax .= $item->show_javascript();
692 print $self->create_http_response('content_type' => 'text/html',
693 'charset' => $db_charset,);
694 print qq|${doctype}<html>
696 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=${db_charset}">
697 <title>$self->{titlebar}</title>
706 <link rel="stylesheet" href="css/jquery.autocomplete.css" type="text/css" />
708 <meta name="robots" content="noindex,nofollow" />
709 <script type="text/javascript" src="js/highlight_input.js"></script>
711 <link rel="stylesheet" type="text/css" href="css/tabcontent.css" />
712 <script type="text/javascript" src="js/tabcontent.js">
714 /***********************************************
715 * Tab Content script v2.2- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
716 * This notice MUST stay intact for legal use
717 * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
718 ***********************************************/
729 $main::lxdebug->leave_sub();
732 sub ajax_response_header {
733 $main::lxdebug->enter_sub();
737 my $db_charset = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
738 my $cgi = $main::cgi || CGI->new('');
739 my $output = $cgi->header('-charset' => $db_charset);
741 $main::lxdebug->leave_sub();
746 sub redirect_header {
750 my $base_uri = $self->_get_request_uri;
751 my $new_uri = URI->new_abs($new_url, $base_uri);
753 die "Headers already sent" if $::self->{header};
756 my $cgi = $main::cgi || CGI->new('');
757 return $cgi->redirect($new_uri);
760 sub set_standard_title {
761 $::lxdebug->enter_sub;
764 $self->{titlebar} = "Lx-Office " . $::locale->text('Version') . " $self->{version}";
765 $self->{titlebar} .= "- $::myconfig{name}" if $::myconfig{name};
766 $self->{titlebar} .= "- $::myconfig{dbname}" if $::myconfig{name};
768 $::lxdebug->leave_sub;
771 sub _prepare_html_template {
772 $main::lxdebug->enter_sub();
774 my ($self, $file, $additional_params) = @_;
777 if (!%::myconfig || !$::myconfig{"countrycode"}) {
778 $language = $main::language;
780 $language = $main::myconfig{"countrycode"};
782 $language = "de" unless ($language);
784 if (-f "templates/webpages/${file}.html") {
785 if ((-f ".developer") && ((stat("templates/webpages/${file}.html"))[9] > (stat("locale/${language}/all"))[9])) {
786 my $info = "Developer information: templates/webpages/${file}.html is newer than the translation file locale/${language}/all.\n" .
787 "Please re-run 'locales.pl' in 'locale/${language}'.";
788 print(qq|<pre>$info</pre>|);
792 $file = "templates/webpages/${file}.html";
795 my $info = "Web page template '${file}' not found.\n" .
796 "Please re-run 'locales.pl' in 'locale/${language}'.";
797 print(qq|<pre>$info</pre>|);
801 if ($self->{"DEBUG"}) {
802 $additional_params->{"DEBUG"} = $self->{"DEBUG"};
805 if ($additional_params->{"DEBUG"}) {
806 $additional_params->{"DEBUG"} =
807 "<br><em>DEBUG INFORMATION:</em><pre>" . $additional_params->{"DEBUG"} . "</pre>";
810 if (%main::myconfig) {
811 map({ $additional_params->{"myconfig_${_}"} = $main::myconfig{$_}; } keys(%main::myconfig));
812 my $jsc_dateformat = $main::myconfig{"dateformat"};
813 $jsc_dateformat =~ s/d+/\%d/gi;
814 $jsc_dateformat =~ s/m+/\%m/gi;
815 $jsc_dateformat =~ s/y+/\%Y/gi;
816 $additional_params->{"myconfig_jsc_dateformat"} = $jsc_dateformat;
817 $additional_params->{"myconfig"} ||= \%::myconfig;
820 $additional_params->{"conf_dbcharset"} = $main::dbcharset;
821 $additional_params->{"conf_webdav"} = $main::webdav;
822 $additional_params->{"conf_lizenzen"} = $main::lizenzen;
823 $additional_params->{"conf_latex_templates"} = $main::latex;
824 $additional_params->{"conf_opendocument_templates"} = $main::opendocument_templates;
825 $additional_params->{"conf_vertreter"} = $main::vertreter;
826 $additional_params->{"conf_show_best_before"} = $main::show_best_before;
828 if (%main::debug_options) {
829 map { $additional_params->{'DEBUG_' . uc($_)} = $main::debug_options{$_} } keys %main::debug_options;
832 if ($main::auth && $main::auth->{RIGHTS} && $main::auth->{RIGHTS}->{$self->{login}}) {
833 while (my ($key, $value) = each %{ $main::auth->{RIGHTS}->{$self->{login}} }) {
834 $additional_params->{"AUTH_RIGHTS_" . uc($key)} = $value;
838 $main::lxdebug->leave_sub();
843 sub parse_html_template {
844 $main::lxdebug->enter_sub();
846 my ($self, $file, $additional_params) = @_;
848 $additional_params ||= { };
850 my $real_file = $self->_prepare_html_template($file, $additional_params);
851 my $template = $self->template || $self->init_template;
853 map { $additional_params->{$_} ||= $self->{$_} } keys %{ $self };
856 $template->process($real_file, $additional_params, \$output) || die $template->error;
858 $main::lxdebug->leave_sub();
866 return if $self->template;
868 return $self->template(Template->new({
873 'PLUGIN_BASE' => 'SL::Template::Plugin',
874 'INCLUDE_PATH' => '.:templates/webpages',
875 'COMPILE_EXT' => '.tcc',
876 'COMPILE_DIR' => $::userspath . '/templates-cache',
882 $self->{template_object} = shift if @_;
883 return $self->{template_object};
886 sub show_generic_error {
887 $main::lxdebug->enter_sub();
889 my ($self, $error, %params) = @_;
892 'title_error' => $params{title},
893 'label_error' => $error,
896 if ($params{action}) {
899 map { delete($self->{$_}); } qw(action);
900 map { push @vars, { "name" => $_, "value" => $self->{$_} } if (!ref($self->{$_})); } keys %{ $self };
902 $add_params->{SHOW_BUTTON} = 1;
903 $add_params->{BUTTON_LABEL} = $params{label} || $params{action};
904 $add_params->{VARIABLES} = \@vars;
906 } elsif ($params{back_button}) {
907 $add_params->{SHOW_BACK_BUTTON} = 1;
910 $self->{title} = $params{title} if $params{title};
913 print $self->parse_html_template("generic/error", $add_params);
915 print STDERR "Error: $error\n";
917 $main::lxdebug->leave_sub();
922 sub show_generic_information {
923 $main::lxdebug->enter_sub();
925 my ($self, $text, $title) = @_;
928 'title_information' => $title,
929 'label_information' => $text,
932 $self->{title} = $title if ($title);
935 print $self->parse_html_template("generic/information", $add_params);
937 $main::lxdebug->leave_sub();
942 # write Trigger JavaScript-Code ($qty = quantity of Triggers)
943 # changed it to accept an arbitrary number of triggers - sschoeling
945 $main::lxdebug->enter_sub();
948 my $myconfig = shift;
951 # set dateform for jsscript
954 "dd.mm.yy" => "%d.%m.%Y",
955 "dd-mm-yy" => "%d-%m-%Y",
956 "dd/mm/yy" => "%d/%m/%Y",
957 "mm/dd/yy" => "%m/%d/%Y",
958 "mm-dd-yy" => "%m-%d-%Y",
959 "yyyy-mm-dd" => "%Y-%m-%d",
962 my $ifFormat = defined($dateformats{$myconfig->{"dateformat"}}) ?
963 $dateformats{$myconfig->{"dateformat"}} : "%d.%m.%Y";
970 inputField : "| . (shift) . qq|",
971 ifFormat :"$ifFormat",
972 align : "| . (shift) . qq|",
973 button : "| . (shift) . qq|"
979 <script type="text/javascript">
980 <!--| . join("", @triggers) . qq|//-->
984 $main::lxdebug->leave_sub();
987 } #end sub write_trigger
990 $main::lxdebug->enter_sub();
992 my ($self, $msg) = @_;
994 if (!$self->{callback}) {
1000 # my ($script, $argv) = split(/\?/, $self->{callback}, 2);
1001 # $script =~ s|.*/||;
1002 # $script =~ s|[^a-zA-Z0-9_\.]||g;
1003 # exec("perl", "$script", $argv);
1005 print $::form->redirect_header($self->{callback});
1007 $main::lxdebug->leave_sub();
1010 # sort of columns removed - empty sub
1012 $main::lxdebug->enter_sub();
1014 my ($self, @columns) = @_;
1016 $main::lxdebug->leave_sub();
1022 $main::lxdebug->enter_sub(2);
1024 my ($self, $myconfig, $amount, $places, $dash) = @_;
1026 if ($amount eq "") {
1030 # Hey watch out! The amount can be an exponential term like 1.13686837721616e-13
1032 my $neg = ($amount =~ s/^-//);
1033 my $exp = ($amount =~ m/[e]/) ? 1 : 0;
1035 if (defined($places) && ($places ne '')) {
1041 my ($actual_places) = ($amount =~ /\.(\d+)/);
1042 $actual_places = length($actual_places);
1043 $places = $actual_places > $places ? $actual_places : $places;
1046 $amount = $self->round_amount($amount, $places);
1049 my @d = map { s/\d//g; reverse split // } my $tmp = $myconfig->{numberformat}; # get delim chars
1050 my @p = split(/\./, $amount); # split amount at decimal point
1052 $p[0] =~ s/\B(?=(...)*$)/$d[1]/g if $d[1]; # add 1,000 delimiters
1055 $amount .= $d[0].$p[1].(0 x ($places - length $p[1])) if ($places || $p[1] ne '');
1058 ($dash =~ /-/) ? ($neg ? "($amount)" : "$amount" ) :
1059 ($dash =~ /DRCR/) ? ($neg ? "$amount " . $main::locale->text('DR') : "$amount " . $main::locale->text('CR') ) :
1060 ($neg ? "-$amount" : "$amount" ) ;
1064 $main::lxdebug->leave_sub(2);
1068 sub format_amount_units {
1069 $main::lxdebug->enter_sub();
1074 my $myconfig = \%main::myconfig;
1075 my $amount = $params{amount} * 1;
1076 my $places = $params{places};
1077 my $part_unit_name = $params{part_unit};
1078 my $amount_unit_name = $params{amount_unit};
1079 my $conv_units = $params{conv_units};
1080 my $max_places = $params{max_places};
1082 if (!$part_unit_name) {
1083 $main::lxdebug->leave_sub();
1087 AM->retrieve_all_units();
1088 my $all_units = $main::all_units;
1090 if (('' eq ref $conv_units) && ($conv_units =~ /convertible/)) {
1091 $conv_units = AM->convertible_units($all_units, $part_unit_name, $conv_units eq 'convertible_not_smaller');
1094 if (!scalar @{ $conv_units }) {
1095 my $result = $self->format_amount($myconfig, $amount, $places, undef, $max_places) . " " . $part_unit_name;
1096 $main::lxdebug->leave_sub();
1100 my $part_unit = $all_units->{$part_unit_name};
1101 my $conv_unit = ($amount_unit_name && ($amount_unit_name ne $part_unit_name)) ? $all_units->{$amount_unit_name} : $part_unit;
1103 $amount *= $conv_unit->{factor};
1108 foreach my $unit (@$conv_units) {
1109 my $last = $unit->{name} eq $part_unit->{name};
1111 $num = int($amount / $unit->{factor});
1112 $amount -= $num * $unit->{factor};
1115 if ($last ? $amount : $num) {
1116 push @values, { "unit" => $unit->{name},
1117 "amount" => $last ? $amount / $unit->{factor} : $num,
1118 "places" => $last ? $places : 0 };
1125 push @values, { "unit" => $part_unit_name,
1130 my $result = join " ", map { $self->format_amount($myconfig, $_->{amount}, $_->{places}, undef, $max_places), $_->{unit} } @values;
1132 $main::lxdebug->leave_sub();
1138 $main::lxdebug->enter_sub(2);
1143 $input =~ s/(^|[^\#]) \# (\d+) /$1$_[$2 - 1]/gx;
1144 $input =~ s/(^|[^\#]) \#\{(\d+)\}/$1$_[$2 - 1]/gx;
1145 $input =~ s/\#\#/\#/g;
1147 $main::lxdebug->leave_sub(2);
1155 $main::lxdebug->enter_sub(2);
1157 my ($self, $myconfig, $amount) = @_;
1159 if ( ($myconfig->{numberformat} eq '1.000,00')
1160 || ($myconfig->{numberformat} eq '1000,00')) {
1165 if ($myconfig->{numberformat} eq "1'000.00") {
1171 $main::lxdebug->leave_sub(2);
1173 return ($amount * 1);
1177 $main::lxdebug->enter_sub(2);
1179 my ($self, $amount, $places) = @_;
1182 # Rounding like "Kaufmannsrunden" (see http://de.wikipedia.org/wiki/Rundung )
1184 # Round amounts to eight places before rounding to the requested
1185 # number of places. This gets rid of errors due to internal floating
1186 # point representation.
1187 $amount = $self->round_amount($amount, 8) if $places < 8;
1188 $amount = $amount * (10**($places));
1189 $round_amount = int($amount + .5 * ($amount <=> 0)) / (10**($places));
1191 $main::lxdebug->leave_sub(2);
1193 return $round_amount;
1197 sub parse_template {
1198 $main::lxdebug->enter_sub();
1200 my ($self, $myconfig, $userspath) = @_;
1205 $self->{"cwd"} = getcwd();
1206 $self->{"tmpdir"} = $self->{cwd} . "/${userspath}";
1211 if ($self->{"format"} =~ /(opendocument|oasis)/i) {
1212 $template_type = 'OpenDocument';
1213 $ext_for_format = $self->{"format"} =~ m/pdf/ ? 'pdf' : 'odt';
1215 } elsif ($self->{"format"} =~ /(postscript|pdf)/i) {
1216 $ENV{"TEXINPUTS"} = ".:" . getcwd() . "/" . $myconfig->{"templates"} . ":" . $ENV{"TEXINPUTS"};
1217 $template_type = 'LaTeX';
1218 $ext_for_format = 'pdf';
1220 } elsif (($self->{"format"} =~ /html/i) || (!$self->{"format"} && ($self->{"IN"} =~ /html$/i))) {
1221 $template_type = 'HTML';
1222 $ext_for_format = 'html';
1224 } elsif (($self->{"format"} =~ /xml/i) || (!$self->{"format"} && ($self->{"IN"} =~ /xml$/i))) {
1225 $template_type = 'XML';
1226 $ext_for_format = 'xml';
1228 } elsif ( $self->{"format"} =~ /elster(?:winston|taxbird)/i ) {
1229 $template_type = 'xml';
1231 } elsif ( $self->{"format"} =~ /excel/i ) {
1232 $template_type = 'Excel';
1233 $ext_for_format = 'xls';
1235 } elsif ( defined $self->{'format'}) {
1236 $self->error("Outputformat not defined. This may be a future feature: $self->{'format'}");
1238 } elsif ( $self->{'format'} eq '' ) {
1239 $self->error("No Outputformat given: $self->{'format'}");
1241 } else { #Catch the rest
1242 $self->error("Outputformat not defined: $self->{'format'}");
1245 my $template = SL::Template::create(type => $template_type,
1246 file_name => $self->{IN},
1248 myconfig => $myconfig,
1249 userspath => $userspath);
1251 # Copy the notes from the invoice/sales order etc. back to the variable "notes" because that is where most templates expect it to be.
1252 $self->{"notes"} = $self->{ $self->{"formname"} . "notes" };
1254 if (!$self->{employee_id}) {
1255 map { $self->{"employee_${_}"} = $myconfig->{$_}; } qw(email tel fax name signature company address businessnumber co_ustid taxnumber duns);
1258 map { $self->{"${_}"} = $myconfig->{$_}; } qw(co_ustid);
1260 $self->{copies} = 1 if (($self->{copies} *= 1) <= 0);
1262 # OUT is used for the media, screen, printer, email
1263 # for postscript we store a copy in a temporary file
1265 my $prepend_userspath;
1267 if (!$self->{tmpfile}) {
1268 $self->{tmpfile} = "${fileid}.$self->{IN}";
1269 $prepend_userspath = 1;
1272 $prepend_userspath = 1 if substr($self->{tmpfile}, 0, length $userspath) eq $userspath;
1274 $self->{tmpfile} =~ s|.*/||;
1275 $self->{tmpfile} =~ s/[^a-zA-Z0-9\._\ \-]//g;
1276 $self->{tmpfile} = "$userspath/$self->{tmpfile}" if $prepend_userspath;
1278 if ($template->uses_temp_file() || $self->{media} eq 'email') {
1279 $out = $self->{OUT};
1280 $self->{OUT} = ">$self->{tmpfile}";
1286 open OUT, "$self->{OUT}" or $self->error("$self->{OUT} : $!");
1287 $result = $template->parse(*OUT);
1292 $result = $template->parse(*STDOUT);
1297 $self->error("$self->{IN} : " . $template->get_error());
1300 if ($template->uses_temp_file() || $self->{media} eq 'email') {
1302 if ($self->{media} eq 'email') {
1304 my $mail = new Mailer;
1306 map { $mail->{$_} = $self->{$_} }
1307 qw(cc bcc subject message version format);
1308 $mail->{charset} = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
1309 $mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email};
1310 $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
1311 $mail->{fileid} = "$fileid.";
1312 $myconfig->{signature} =~ s/\r//g;
1314 # if we send html or plain text inline
1315 if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
1316 $mail->{contenttype} = "text/html";
1318 $mail->{message} =~ s/\r//g;
1319 $mail->{message} =~ s/\n/<br>\n/g;
1320 $myconfig->{signature} =~ s/\n/<br>\n/g;
1321 $mail->{message} .= "<br>\n-- <br>\n$myconfig->{signature}\n<br>";
1323 open(IN, $self->{tmpfile})
1324 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
1326 $mail->{message} .= $_;
1333 if (!$self->{"do_not_attach"}) {
1334 my $attachment_name = $self->{attachment_filename} || $self->{tmpfile};
1335 $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format);
1336 $mail->{attachments} = [{ "filename" => $self->{tmpfile},
1337 "name" => $attachment_name }];
1340 $mail->{message} =~ s/\r//g;
1341 $mail->{message} .= "\n-- \n$myconfig->{signature}";
1345 my $err = $mail->send();
1346 $self->error($self->cleanup . "$err") if ($err);
1350 $self->{OUT} = $out;
1352 my $numbytes = (-s $self->{tmpfile});
1353 open(IN, $self->{tmpfile})
1354 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
1356 $self->{copies} = 1 unless $self->{media} eq 'printer';
1358 chdir("$self->{cwd}");
1359 #print(STDERR "Kopien $self->{copies}\n");
1360 #print(STDERR "OUT $self->{OUT}\n");
1361 for my $i (1 .. $self->{copies}) {
1363 open OUT, $self->{OUT} or $self->error($self->cleanup . "$self->{OUT} : $!");
1364 print OUT while <IN>;
1369 $self->{attachment_filename} = ($self->{attachment_filename})
1370 ? $self->{attachment_filename}
1371 : $self->generate_attachment_filename();
1373 # launch application
1374 print qq|Content-Type: | . $template->get_mime_type() . qq|
1375 Content-Disposition: attachment; filename="$self->{attachment_filename}"
1376 Content-Length: $numbytes
1380 $::locale->with_raw_io(\*STDOUT, sub { print while <IN> });
1391 chdir("$self->{cwd}");
1392 $main::lxdebug->leave_sub();
1395 sub get_formname_translation {
1396 $main::lxdebug->enter_sub();
1397 my ($self, $formname) = @_;
1399 $formname ||= $self->{formname};
1401 my %formname_translations = (
1402 bin_list => $main::locale->text('Bin List'),
1403 credit_note => $main::locale->text('Credit Note'),
1404 invoice => $main::locale->text('Invoice'),
1405 packing_list => $main::locale->text('Packing List'),
1406 pick_list => $main::locale->text('Pick List'),
1407 proforma => $main::locale->text('Proforma Invoice'),
1408 purchase_order => $main::locale->text('Purchase Order'),
1409 request_quotation => $main::locale->text('RFQ'),
1410 sales_order => $main::locale->text('Confirmation'),
1411 sales_quotation => $main::locale->text('Quotation'),
1412 storno_invoice => $main::locale->text('Storno Invoice'),
1413 storno_packing_list => $main::locale->text('Storno Packing List'),
1414 sales_delivery_order => $main::locale->text('Delivery Order'),
1415 purchase_delivery_order => $main::locale->text('Delivery Order'),
1416 dunning => $main::locale->text('Dunning'),
1419 $main::lxdebug->leave_sub();
1420 return $formname_translations{$formname}
1423 sub get_number_prefix_for_type {
1424 $main::lxdebug->enter_sub();
1428 (first { $self->{type} eq $_ } qw(invoice credit_note)) ? 'inv'
1429 : ($self->{type} =~ /_quotation$/) ? 'quo'
1430 : ($self->{type} =~ /_delivery_order$/) ? 'do'
1433 $main::lxdebug->leave_sub();
1437 sub get_extension_for_format {
1438 $main::lxdebug->enter_sub();
1441 my $extension = $self->{format} =~ /pdf/i ? ".pdf"
1442 : $self->{format} =~ /postscript/i ? ".ps"
1443 : $self->{format} =~ /opendocument/i ? ".odt"
1444 : $self->{format} =~ /excel/i ? ".xls"
1445 : $self->{format} =~ /html/i ? ".html"
1448 $main::lxdebug->leave_sub();
1452 sub generate_attachment_filename {
1453 $main::lxdebug->enter_sub();
1456 my $attachment_filename = $main::locale->unquote_special_chars('HTML', $self->get_formname_translation());
1457 my $prefix = $self->get_number_prefix_for_type();
1459 if ($self->{preview} && (first { $self->{type} eq $_ } qw(invoice credit_note))) {
1460 $attachment_filename .= ' (' . $main::locale->text('Preview') . ')' . $self->get_extension_for_format();
1462 } elsif ($attachment_filename && $self->{"${prefix}number"}) {
1463 $attachment_filename .= "_" . $self->{"${prefix}number"} . $self->get_extension_for_format();
1466 $attachment_filename = "";
1469 $attachment_filename = $main::locale->quote_special_chars('filenames', $attachment_filename);
1470 $attachment_filename =~ s|[\s/\\]+|_|g;
1472 $main::lxdebug->leave_sub();
1473 return $attachment_filename;
1476 sub generate_email_subject {
1477 $main::lxdebug->enter_sub();
1480 my $subject = $main::locale->unquote_special_chars('HTML', $self->get_formname_translation());
1481 my $prefix = $self->get_number_prefix_for_type();
1483 if ($subject && $self->{"${prefix}number"}) {
1484 $subject .= " " . $self->{"${prefix}number"}
1487 $main::lxdebug->leave_sub();
1492 $main::lxdebug->enter_sub();
1496 chdir("$self->{tmpdir}");
1499 if (-f "$self->{tmpfile}.err") {
1500 open(FH, "$self->{tmpfile}.err");
1505 if ($self->{tmpfile} && ! $::keep_temp_files) {
1506 $self->{tmpfile} =~ s|.*/||g;
1508 $self->{tmpfile} =~ s/\.\w+$//g;
1509 my $tmpfile = $self->{tmpfile};
1510 unlink(<$tmpfile.*>);
1513 chdir("$self->{cwd}");
1515 $main::lxdebug->leave_sub();
1521 $main::lxdebug->enter_sub();
1523 my ($self, $date, $myconfig) = @_;
1526 if ($date && $date =~ /\D/) {
1528 if ($myconfig->{dateformat} =~ /^yy/) {
1529 ($yy, $mm, $dd) = split /\D/, $date;
1531 if ($myconfig->{dateformat} =~ /^mm/) {
1532 ($mm, $dd, $yy) = split /\D/, $date;
1534 if ($myconfig->{dateformat} =~ /^dd/) {
1535 ($dd, $mm, $yy) = split /\D/, $date;
1540 $yy = ($yy < 70) ? $yy + 2000 : $yy;
1541 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
1543 $dd = "0$dd" if ($dd < 10);
1544 $mm = "0$mm" if ($mm < 10);
1546 $date = "$yy$mm$dd";
1549 $main::lxdebug->leave_sub();
1554 # Database routines used throughout
1557 $main::lxdebug->enter_sub(2);
1559 my ($self, $myconfig) = @_;
1561 # connect to database
1563 DBI->connect($myconfig->{dbconnect},
1564 $myconfig->{dbuser}, $myconfig->{dbpasswd})
1568 if ($myconfig->{dboptions}) {
1569 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1572 $main::lxdebug->leave_sub(2);
1577 sub dbconnect_noauto {
1578 $main::lxdebug->enter_sub();
1580 my ($self, $myconfig) = @_;
1582 # connect to database
1584 DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser},
1585 $myconfig->{dbpasswd}, { AutoCommit => 0 })
1589 if ($myconfig->{dboptions}) {
1590 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1593 $main::lxdebug->leave_sub();
1598 sub get_standard_dbh {
1599 $main::lxdebug->enter_sub(2);
1602 my $myconfig = shift || \%::myconfig;
1604 if ($standard_dbh && !$standard_dbh->{Active}) {
1605 $main::lxdebug->message(LXDebug->INFO(), "get_standard_dbh: \$standard_dbh is defined but not Active anymore");
1606 undef $standard_dbh;
1609 $standard_dbh ||= $self->dbconnect_noauto($myconfig);
1611 $main::lxdebug->leave_sub(2);
1613 return $standard_dbh;
1617 $main::lxdebug->enter_sub();
1619 my ($self, $date, $myconfig) = @_;
1620 my $dbh = $self->dbconnect($myconfig);
1622 my $query = "SELECT 1 FROM defaults WHERE ? < closedto";
1623 my $sth = prepare_execute_query($self, $dbh, $query, $date);
1624 my ($closed) = $sth->fetchrow_array;
1626 $main::lxdebug->leave_sub();
1631 sub update_balance {
1632 $main::lxdebug->enter_sub();
1634 my ($self, $dbh, $table, $field, $where, $value, @values) = @_;
1636 # if we have a value, go do it
1639 # retrieve balance from table
1640 my $query = "SELECT $field FROM $table WHERE $where FOR UPDATE";
1641 my $sth = prepare_execute_query($self, $dbh, $query, @values);
1642 my ($balance) = $sth->fetchrow_array;
1648 $query = "UPDATE $table SET $field = $balance WHERE $where";
1649 do_query($self, $dbh, $query, @values);
1651 $main::lxdebug->leave_sub();
1654 sub update_exchangerate {
1655 $main::lxdebug->enter_sub();
1657 my ($self, $dbh, $curr, $transdate, $buy, $sell) = @_;
1659 # some sanity check for currency
1661 $main::lxdebug->leave_sub();
1664 $query = qq|SELECT curr FROM defaults|;
1666 my ($currency) = selectrow_query($self, $dbh, $query);
1667 my ($defaultcurrency) = split m/:/, $currency;
1670 if ($curr eq $defaultcurrency) {
1671 $main::lxdebug->leave_sub();
1675 $query = qq|SELECT e.curr FROM exchangerate e
1676 WHERE e.curr = ? AND e.transdate = ?
1678 my $sth = prepare_execute_query($self, $dbh, $query, $curr, $transdate);
1687 $buy = conv_i($buy, "NULL");
1688 $sell = conv_i($sell, "NULL");
1691 if ($buy != 0 && $sell != 0) {
1692 $set = "buy = $buy, sell = $sell";
1693 } elsif ($buy != 0) {
1694 $set = "buy = $buy";
1695 } elsif ($sell != 0) {
1696 $set = "sell = $sell";
1699 if ($sth->fetchrow_array) {
1700 $query = qq|UPDATE exchangerate
1706 $query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
1707 VALUES (?, $buy, $sell, ?)|;
1710 do_query($self, $dbh, $query, $curr, $transdate);
1712 $main::lxdebug->leave_sub();
1715 sub save_exchangerate {
1716 $main::lxdebug->enter_sub();
1718 my ($self, $myconfig, $currency, $transdate, $rate, $fld) = @_;
1720 my $dbh = $self->dbconnect($myconfig);
1724 $buy = $rate if $fld eq 'buy';
1725 $sell = $rate if $fld eq 'sell';
1728 $self->update_exchangerate($dbh, $currency, $transdate, $buy, $sell);
1733 $main::lxdebug->leave_sub();
1736 sub get_exchangerate {
1737 $main::lxdebug->enter_sub();
1739 my ($self, $dbh, $curr, $transdate, $fld) = @_;
1742 unless ($transdate) {
1743 $main::lxdebug->leave_sub();
1747 $query = qq|SELECT curr FROM defaults|;
1749 my ($currency) = selectrow_query($self, $dbh, $query);
1750 my ($defaultcurrency) = split m/:/, $currency;
1752 if ($currency eq $defaultcurrency) {
1753 $main::lxdebug->leave_sub();
1757 $query = qq|SELECT e.$fld FROM exchangerate e
1758 WHERE e.curr = ? AND e.transdate = ?|;
1759 my ($exchangerate) = selectrow_query($self, $dbh, $query, $curr, $transdate);
1763 $main::lxdebug->leave_sub();
1765 return $exchangerate;
1768 sub check_exchangerate {
1769 $main::lxdebug->enter_sub();
1771 my ($self, $myconfig, $currency, $transdate, $fld) = @_;
1773 if ($fld !~/^buy|sell$/) {
1774 $self->error('Fatal: check_exchangerate called with invalid buy/sell argument');
1777 unless ($transdate) {
1778 $main::lxdebug->leave_sub();
1782 my ($defaultcurrency) = $self->get_default_currency($myconfig);
1784 if ($currency eq $defaultcurrency) {
1785 $main::lxdebug->leave_sub();
1789 my $dbh = $self->get_standard_dbh($myconfig);
1790 my $query = qq|SELECT e.$fld FROM exchangerate e
1791 WHERE e.curr = ? AND e.transdate = ?|;
1793 my ($exchangerate) = selectrow_query($self, $dbh, $query, $currency, $transdate);
1795 $main::lxdebug->leave_sub();
1797 return $exchangerate;
1800 sub get_all_currencies {
1801 $main::lxdebug->enter_sub();
1804 my $myconfig = shift || \%::myconfig;
1805 my $dbh = $self->get_standard_dbh($myconfig);
1807 my $query = qq|SELECT curr FROM defaults|;
1809 my ($curr) = selectrow_query($self, $dbh, $query);
1810 my @currencies = grep { $_ } map { s/\s//g; $_ } split m/:/, $curr;
1812 $main::lxdebug->leave_sub();
1817 sub get_default_currency {
1818 $main::lxdebug->enter_sub();
1820 my ($self, $myconfig) = @_;
1821 my @currencies = $self->get_all_currencies($myconfig);
1823 $main::lxdebug->leave_sub();
1825 return $currencies[0];
1828 sub set_payment_options {
1829 $main::lxdebug->enter_sub();
1831 my ($self, $myconfig, $transdate) = @_;
1833 return $main::lxdebug->leave_sub() unless ($self->{payment_id});
1835 my $dbh = $self->get_standard_dbh($myconfig);
1838 qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, p.description_long | .
1839 qq|FROM payment_terms p | .
1842 ($self->{terms_netto}, $self->{terms_skonto}, $self->{percent_skonto},
1843 $self->{payment_terms}) =
1844 selectrow_query($self, $dbh, $query, $self->{payment_id});
1846 if ($transdate eq "") {
1847 if ($self->{invdate}) {
1848 $transdate = $self->{invdate};
1850 $transdate = $self->{transdate};
1855 qq|SELECT ?::date + ?::integer AS netto_date, ?::date + ?::integer AS skonto_date | .
1856 qq|FROM payment_terms|;
1857 ($self->{netto_date}, $self->{skonto_date}) =
1858 selectrow_query($self, $dbh, $query, $transdate, $self->{terms_netto}, $transdate, $self->{terms_skonto});
1860 my ($invtotal, $total);
1861 my (%amounts, %formatted_amounts);
1863 if ($self->{type} =~ /_order$/) {
1864 $amounts{invtotal} = $self->{ordtotal};
1865 $amounts{total} = $self->{ordtotal};
1867 } elsif ($self->{type} =~ /_quotation$/) {
1868 $amounts{invtotal} = $self->{quototal};
1869 $amounts{total} = $self->{quototal};
1872 $amounts{invtotal} = $self->{invtotal};
1873 $amounts{total} = $self->{total};
1875 $amounts{skonto_in_percent} = 100.0 * $self->{percent_skonto};
1877 map { $amounts{$_} = $self->parse_amount($myconfig, $amounts{$_}) } keys %amounts;
1879 $amounts{skonto_amount} = $amounts{invtotal} * $self->{percent_skonto};
1880 $amounts{invtotal_wo_skonto} = $amounts{invtotal} * (1 - $self->{percent_skonto});
1881 $amounts{total_wo_skonto} = $amounts{total} * (1 - $self->{percent_skonto});
1883 foreach (keys %amounts) {
1884 $amounts{$_} = $self->round_amount($amounts{$_}, 2);
1885 $formatted_amounts{$_} = $self->format_amount($myconfig, $amounts{$_}, 2);
1888 if ($self->{"language_id"}) {
1890 qq|SELECT t.description_long, l.output_numberformat, l.output_dateformat, l.output_longdates | .
1891 qq|FROM translation_payment_terms t | .
1892 qq|LEFT JOIN language l ON t.language_id = l.id | .
1893 qq|WHERE (t.language_id = ?) AND (t.payment_terms_id = ?)|;
1894 my ($description_long, $output_numberformat, $output_dateformat,
1895 $output_longdates) =
1896 selectrow_query($self, $dbh, $query,
1897 $self->{"language_id"}, $self->{"payment_id"});
1899 $self->{payment_terms} = $description_long if ($description_long);
1901 if ($output_dateformat) {
1902 foreach my $key (qw(netto_date skonto_date)) {
1904 $main::locale->reformat_date($myconfig, $self->{$key},
1910 if ($output_numberformat &&
1911 ($output_numberformat ne $myconfig->{"numberformat"})) {
1912 my $saved_numberformat = $myconfig->{"numberformat"};
1913 $myconfig->{"numberformat"} = $output_numberformat;
1914 map { $formatted_amounts{$_} = $self->format_amount($myconfig, $amounts{$_}) } keys %amounts;
1915 $myconfig->{"numberformat"} = $saved_numberformat;
1919 $self->{payment_terms} =~ s/<%netto_date%>/$self->{netto_date}/g;
1920 $self->{payment_terms} =~ s/<%skonto_date%>/$self->{skonto_date}/g;
1921 $self->{payment_terms} =~ s/<%currency%>/$self->{currency}/g;
1922 $self->{payment_terms} =~ s/<%terms_netto%>/$self->{terms_netto}/g;
1923 $self->{payment_terms} =~ s/<%account_number%>/$self->{account_number}/g;
1924 $self->{payment_terms} =~ s/<%bank%>/$self->{bank}/g;
1925 $self->{payment_terms} =~ s/<%bank_code%>/$self->{bank_code}/g;
1927 map { $self->{payment_terms} =~ s/<%${_}%>/$formatted_amounts{$_}/g; } keys %formatted_amounts;
1929 $self->{skonto_in_percent} = $formatted_amounts{skonto_in_percent};
1931 $main::lxdebug->leave_sub();
1935 sub get_template_language {
1936 $main::lxdebug->enter_sub();
1938 my ($self, $myconfig) = @_;
1940 my $template_code = "";
1942 if ($self->{language_id}) {
1943 my $dbh = $self->get_standard_dbh($myconfig);
1944 my $query = qq|SELECT template_code FROM language WHERE id = ?|;
1945 ($template_code) = selectrow_query($self, $dbh, $query, $self->{language_id});
1948 $main::lxdebug->leave_sub();
1950 return $template_code;
1953 sub get_printer_code {
1954 $main::lxdebug->enter_sub();
1956 my ($self, $myconfig) = @_;
1958 my $template_code = "";
1960 if ($self->{printer_id}) {
1961 my $dbh = $self->get_standard_dbh($myconfig);
1962 my $query = qq|SELECT template_code, printer_command FROM printers WHERE id = ?|;
1963 ($template_code, $self->{printer_command}) = selectrow_query($self, $dbh, $query, $self->{printer_id});
1966 $main::lxdebug->leave_sub();
1968 return $template_code;
1972 $main::lxdebug->enter_sub();
1974 my ($self, $myconfig) = @_;
1976 my $template_code = "";
1978 if ($self->{shipto_id}) {
1979 my $dbh = $self->get_standard_dbh($myconfig);
1980 my $query = qq|SELECT * FROM shipto WHERE shipto_id = ?|;
1981 my $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{shipto_id});
1982 map({ $self->{$_} = $ref->{$_} } keys(%$ref));
1985 $main::lxdebug->leave_sub();
1989 $main::lxdebug->enter_sub();
1991 my ($self, $dbh, $id, $module) = @_;
1996 foreach my $item (qw(name department_1 department_2 street zipcode city country
1997 contact phone fax email)) {
1998 if ($self->{"shipto$item"}) {
1999 $shipto = 1 if ($self->{$item} ne $self->{"shipto$item"});
2001 push(@values, $self->{"shipto${item}"});
2005 if ($self->{shipto_id}) {
2006 my $query = qq|UPDATE shipto set
2008 shiptodepartment_1 = ?,
2009 shiptodepartment_2 = ?,
2018 WHERE shipto_id = ?|;
2019 do_query($self, $dbh, $query, @values, $self->{shipto_id});
2021 my $query = qq|SELECT * FROM shipto
2022 WHERE shiptoname = ? AND
2023 shiptodepartment_1 = ? AND
2024 shiptodepartment_2 = ? AND
2025 shiptostreet = ? AND
2026 shiptozipcode = ? AND
2028 shiptocountry = ? AND
2029 shiptocontact = ? AND
2035 my $insert_check = selectfirst_hashref_query($self, $dbh, $query, @values, $module, $id);
2038 qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2,
2039 shiptostreet, shiptozipcode, shiptocity, shiptocountry,
2040 shiptocontact, shiptophone, shiptofax, shiptoemail, module)
2041 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
2042 do_query($self, $dbh, $query, $id, @values, $module);
2047 $main::lxdebug->leave_sub();
2051 $main::lxdebug->enter_sub();
2053 my ($self, $dbh) = @_;
2055 $dbh ||= $self->get_standard_dbh(\%main::myconfig);
2057 my $query = qq|SELECT id, name FROM employee WHERE login = ?|;
2058 ($self->{"employee_id"}, $self->{"employee"}) = selectrow_query($self, $dbh, $query, $self->{login});
2059 $self->{"employee_id"} *= 1;
2061 $main::lxdebug->leave_sub();
2064 sub get_employee_data {
2065 $main::lxdebug->enter_sub();
2070 Common::check_params(\%params, qw(prefix));
2071 Common::check_params_x(\%params, qw(id));
2074 $main::lxdebug->leave_sub();
2078 my $myconfig = \%main::myconfig;
2079 my $dbh = $params{dbh} || $self->get_standard_dbh($myconfig);
2081 my ($login) = selectrow_query($self, $dbh, qq|SELECT login FROM employee WHERE id = ?|, conv_i($params{id}));
2084 my $user = User->new($login);
2085 map { $self->{$params{prefix} . "_${_}"} = $user->{$_}; } qw(address businessnumber co_ustid company duns email fax name signature taxnumber tel);
2087 $self->{$params{prefix} . '_login'} = $login;
2088 $self->{$params{prefix} . '_name'} ||= $login;
2091 $main::lxdebug->leave_sub();
2095 $main::lxdebug->enter_sub();
2097 my ($self, $myconfig, $reference_date) = @_;
2099 $reference_date = $reference_date ? conv_dateq($reference_date) . '::DATE' : 'current_date';
2101 my $dbh = $self->get_standard_dbh($myconfig);
2102 my $query = qq|SELECT ${reference_date} + terms_netto FROM payment_terms WHERE id = ?|;
2103 my ($duedate) = selectrow_query($self, $dbh, $query, $self->{payment_id});
2105 $main::lxdebug->leave_sub();
2111 $main::lxdebug->enter_sub();
2113 my ($self, $dbh, $id, $key) = @_;
2115 $key = "all_contacts" unless ($key);
2119 $main::lxdebug->leave_sub();
2124 qq|SELECT cp_id, cp_cv_id, cp_name, cp_givenname, cp_abteilung | .
2125 qq|FROM contacts | .
2126 qq|WHERE cp_cv_id = ? | .
2127 qq|ORDER BY lower(cp_name)|;
2129 $self->{$key} = selectall_hashref_query($self, $dbh, $query, $id);
2131 $main::lxdebug->leave_sub();
2135 $main::lxdebug->enter_sub();
2137 my ($self, $dbh, $key) = @_;
2139 my ($all, $old_id, $where, @values);
2141 if (ref($key) eq "HASH") {
2144 $key = "ALL_PROJECTS";
2146 foreach my $p (keys(%{$params})) {
2148 $all = $params->{$p};
2149 } elsif ($p eq "old_id") {
2150 $old_id = $params->{$p};
2151 } elsif ($p eq "key") {
2152 $key = $params->{$p};
2158 $where = "WHERE active ";
2160 if (ref($old_id) eq "ARRAY") {
2161 my @ids = grep({ $_ } @{$old_id});
2163 $where .= " OR id IN (" . join(",", map({ "?" } @ids)) . ") ";
2164 push(@values, @ids);
2167 $where .= " OR (id = ?) ";
2168 push(@values, $old_id);
2174 qq|SELECT id, projectnumber, description, active | .
2177 qq|ORDER BY lower(projectnumber)|;
2179 $self->{$key} = selectall_hashref_query($self, $dbh, $query, @values);
2181 $main::lxdebug->leave_sub();
2185 $main::lxdebug->enter_sub();
2187 my ($self, $dbh, $vc_id, $key) = @_;
2189 $key = "all_shipto" unless ($key);
2192 # get shipping addresses
2193 my $query = qq|SELECT * FROM shipto WHERE trans_id = ?|;
2195 $self->{$key} = selectall_hashref_query($self, $dbh, $query, $vc_id);
2201 $main::lxdebug->leave_sub();
2205 $main::lxdebug->enter_sub();
2207 my ($self, $dbh, $key) = @_;
2209 $key = "all_printers" unless ($key);
2211 my $query = qq|SELECT id, printer_description, printer_command, template_code FROM printers|;
2213 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2215 $main::lxdebug->leave_sub();
2219 $main::lxdebug->enter_sub();
2221 my ($self, $dbh, $params) = @_;
2224 $key = $params->{key};
2225 $key = "all_charts" unless ($key);
2227 my $transdate = quote_db_date($params->{transdate});
2230 qq|SELECT c.id, c.accno, c.description, c.link, c.charttype, tk.taxkey_id, tk.tax_id | .
2232 qq|LEFT JOIN taxkeys tk ON | .
2233 qq|(tk.id = (SELECT id FROM taxkeys | .
2234 qq| WHERE taxkeys.chart_id = c.id AND startdate <= $transdate | .
2235 qq| ORDER BY startdate DESC LIMIT 1)) | .
2236 qq|ORDER BY c.accno|;
2238 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2240 $main::lxdebug->leave_sub();
2243 sub _get_taxcharts {
2244 $main::lxdebug->enter_sub();
2246 my ($self, $dbh, $params) = @_;
2248 my $key = "all_taxcharts";
2251 if (ref $params eq 'HASH') {
2252 $key = $params->{key} if ($params->{key});
2253 if ($params->{module} eq 'AR') {
2254 push @where, 'taxkey NOT IN (8, 9, 18, 19)';
2256 } elsif ($params->{module} eq 'AP') {
2257 push @where, 'taxkey NOT IN (1, 2, 3, 12, 13)';
2264 my $where = ' WHERE ' . join(' AND ', map { "($_)" } @where) if (@where);
2266 my $query = qq|SELECT * FROM tax $where ORDER BY taxkey|;
2268 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2270 $main::lxdebug->leave_sub();
2274 $main::lxdebug->enter_sub();
2276 my ($self, $dbh, $key) = @_;
2278 $key = "all_taxzones" unless ($key);
2280 my $query = qq|SELECT * FROM tax_zones ORDER BY id|;
2282 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2284 $main::lxdebug->leave_sub();
2287 sub _get_employees {
2288 $main::lxdebug->enter_sub();
2290 my ($self, $dbh, $default_key, $key) = @_;
2292 $key = $default_key unless ($key);
2293 $self->{$key} = selectall_hashref_query($self, $dbh, qq|SELECT * FROM employee ORDER BY lower(name)|);
2295 $main::lxdebug->leave_sub();
2298 sub _get_business_types {
2299 $main::lxdebug->enter_sub();
2301 my ($self, $dbh, $key) = @_;
2303 my $options = ref $key eq 'HASH' ? $key : { key => $key };
2304 $options->{key} ||= "all_business_types";
2307 if (exists $options->{salesman}) {
2308 $where = 'WHERE ' . ($options->{salesman} ? '' : 'NOT ') . 'COALESCE(salesman)';
2311 $self->{ $options->{key} } = selectall_hashref_query($self, $dbh, qq|SELECT * FROM business $where ORDER BY lower(description)|);
2313 $main::lxdebug->leave_sub();
2316 sub _get_languages {
2317 $main::lxdebug->enter_sub();
2319 my ($self, $dbh, $key) = @_;
2321 $key = "all_languages" unless ($key);
2323 my $query = qq|SELECT * FROM language ORDER BY id|;
2325 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2327 $main::lxdebug->leave_sub();
2330 sub _get_dunning_configs {
2331 $main::lxdebug->enter_sub();
2333 my ($self, $dbh, $key) = @_;
2335 $key = "all_dunning_configs" unless ($key);
2337 my $query = qq|SELECT * FROM dunning_config ORDER BY dunning_level|;
2339 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2341 $main::lxdebug->leave_sub();
2344 sub _get_currencies {
2345 $main::lxdebug->enter_sub();
2347 my ($self, $dbh, $key) = @_;
2349 $key = "all_currencies" unless ($key);
2351 my $query = qq|SELECT curr AS currency FROM defaults|;
2353 $self->{$key} = [split(/\:/ , selectfirst_hashref_query($self, $dbh, $query)->{currency})];
2355 $main::lxdebug->leave_sub();
2359 $main::lxdebug->enter_sub();
2361 my ($self, $dbh, $key) = @_;
2363 $key = "all_payments" unless ($key);
2365 my $query = qq|SELECT * FROM payment_terms ORDER BY id|;
2367 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2369 $main::lxdebug->leave_sub();
2372 sub _get_customers {
2373 $main::lxdebug->enter_sub();
2375 my ($self, $dbh, $key) = @_;
2377 my $options = ref $key eq 'HASH' ? $key : { key => $key };
2378 $options->{key} ||= "all_customers";
2379 my $limit_clause = "LIMIT $options->{limit}" if $options->{limit};
2382 push @where, qq|business_id IN (SELECT id FROM business WHERE salesman)| if $options->{business_is_salesman};
2383 push @where, qq|NOT obsolete| if !$options->{with_obsolete};
2384 my $where_str = @where ? "WHERE " . join(" AND ", map { "($_)" } @where) : '';
2386 my $query = qq|SELECT * FROM customer $where_str ORDER BY name $limit_clause|;
2387 $self->{ $options->{key} } = selectall_hashref_query($self, $dbh, $query);
2389 $main::lxdebug->leave_sub();
2393 $main::lxdebug->enter_sub();
2395 my ($self, $dbh, $key) = @_;
2397 $key = "all_vendors" unless ($key);
2399 my $query = qq|SELECT * FROM vendor WHERE NOT obsolete ORDER BY name|;
2401 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2403 $main::lxdebug->leave_sub();
2406 sub _get_departments {
2407 $main::lxdebug->enter_sub();
2409 my ($self, $dbh, $key) = @_;
2411 $key = "all_departments" unless ($key);
2413 my $query = qq|SELECT * FROM department ORDER BY description|;
2415 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2417 $main::lxdebug->leave_sub();
2420 sub _get_warehouses {
2421 $main::lxdebug->enter_sub();
2423 my ($self, $dbh, $param) = @_;
2425 my ($key, $bins_key);
2427 if ('' eq ref $param) {
2431 $key = $param->{key};
2432 $bins_key = $param->{bins};
2435 my $query = qq|SELECT w.* FROM warehouse w
2436 WHERE (NOT w.invalid) AND
2437 ((SELECT COUNT(b.*) FROM bin b WHERE b.warehouse_id = w.id) > 0)
2438 ORDER BY w.sortkey|;
2440 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2443 $query = qq|SELECT id, description FROM bin WHERE warehouse_id = ?|;
2444 my $sth = prepare_query($self, $dbh, $query);
2446 foreach my $warehouse (@{ $self->{$key} }) {
2447 do_statement($self, $sth, $query, $warehouse->{id});
2448 $warehouse->{$bins_key} = [];
2450 while (my $ref = $sth->fetchrow_hashref()) {
2451 push @{ $warehouse->{$bins_key} }, $ref;
2457 $main::lxdebug->leave_sub();
2461 $main::lxdebug->enter_sub();
2463 my ($self, $dbh, $table, $key, $sortkey) = @_;
2465 my $query = qq|SELECT * FROM $table|;
2466 $query .= qq| ORDER BY $sortkey| if ($sortkey);
2468 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2470 $main::lxdebug->leave_sub();
2474 # $main::lxdebug->enter_sub();
2476 # my ($self, $dbh, $key) = @_;
2478 # $key ||= "all_groups";
2480 # my $groups = $main::auth->read_groups();
2482 # $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2484 # $main::lxdebug->leave_sub();
2488 $main::lxdebug->enter_sub();
2493 my $dbh = $self->get_standard_dbh(\%main::myconfig);
2494 my ($sth, $query, $ref);
2496 my $vc = $self->{"vc"} eq "customer" ? "customer" : "vendor";
2497 my $vc_id = $self->{"${vc}_id"};
2499 if ($params{"contacts"}) {
2500 $self->_get_contacts($dbh, $vc_id, $params{"contacts"});
2503 if ($params{"shipto"}) {
2504 $self->_get_shipto($dbh, $vc_id, $params{"shipto"});
2507 if ($params{"projects"} || $params{"all_projects"}) {
2508 $self->_get_projects($dbh, $params{"all_projects"} ?
2509 $params{"all_projects"} : $params{"projects"},
2510 $params{"all_projects"} ? 1 : 0);
2513 if ($params{"printers"}) {
2514 $self->_get_printers($dbh, $params{"printers"});
2517 if ($params{"languages"}) {
2518 $self->_get_languages($dbh, $params{"languages"});
2521 if ($params{"charts"}) {
2522 $self->_get_charts($dbh, $params{"charts"});
2525 if ($params{"taxcharts"}) {
2526 $self->_get_taxcharts($dbh, $params{"taxcharts"});
2529 if ($params{"taxzones"}) {
2530 $self->_get_taxzones($dbh, $params{"taxzones"});
2533 if ($params{"employees"}) {
2534 $self->_get_employees($dbh, "all_employees", $params{"employees"});
2537 if ($params{"salesmen"}) {
2538 $self->_get_employees($dbh, "all_salesmen", $params{"salesmen"});
2541 if ($params{"business_types"}) {
2542 $self->_get_business_types($dbh, $params{"business_types"});
2545 if ($params{"dunning_configs"}) {
2546 $self->_get_dunning_configs($dbh, $params{"dunning_configs"});
2549 if($params{"currencies"}) {
2550 $self->_get_currencies($dbh, $params{"currencies"});
2553 if($params{"customers"}) {
2554 $self->_get_customers($dbh, $params{"customers"});
2557 if($params{"vendors"}) {
2558 if (ref $params{"vendors"} eq 'HASH') {
2559 $self->_get_vendors($dbh, $params{"vendors"}{key}, $params{"vendors"}{limit});
2561 $self->_get_vendors($dbh, $params{"vendors"});
2565 if($params{"payments"}) {
2566 $self->_get_payments($dbh, $params{"payments"});
2569 if($params{"departments"}) {
2570 $self->_get_departments($dbh, $params{"departments"});
2573 if ($params{price_factors}) {
2574 $self->_get_simple($dbh, 'price_factors', $params{price_factors}, 'sortkey');
2577 if ($params{warehouses}) {
2578 $self->_get_warehouses($dbh, $params{warehouses});
2581 # if ($params{groups}) {
2582 # $self->_get_groups($dbh, $params{groups});
2585 if ($params{partsgroup}) {
2586 $self->get_partsgroup(\%main::myconfig, { all => 1, target => $params{partsgroup} });
2589 $main::lxdebug->leave_sub();
2592 # this sub gets the id and name from $table
2594 $main::lxdebug->enter_sub();
2596 my ($self, $myconfig, $table) = @_;
2598 # connect to database
2599 my $dbh = $self->get_standard_dbh($myconfig);
2601 $table = $table eq "customer" ? "customer" : "vendor";
2602 my $arap = $self->{arap} eq "ar" ? "ar" : "ap";
2604 my ($query, @values);
2606 if (!$self->{openinvoices}) {
2608 if ($self->{customernumber} ne "") {
2609 $where = qq|(vc.customernumber ILIKE ?)|;
2610 push(@values, '%' . $self->{customernumber} . '%');
2612 $where = qq|(vc.name ILIKE ?)|;
2613 push(@values, '%' . $self->{$table} . '%');
2617 qq~SELECT vc.id, vc.name,
2618 vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
2620 WHERE $where AND (NOT vc.obsolete)
2624 qq~SELECT DISTINCT vc.id, vc.name,
2625 vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
2627 JOIN $table vc ON (a.${table}_id = vc.id)
2628 WHERE NOT (a.amount = a.paid) AND (vc.name ILIKE ?)
2630 push(@values, '%' . $self->{$table} . '%');
2633 $self->{name_list} = selectall_hashref_query($self, $dbh, $query, @values);
2635 $main::lxdebug->leave_sub();
2637 return scalar(@{ $self->{name_list} });
2640 # the selection sub is used in the AR, AP, IS, IR and OE module
2643 $main::lxdebug->enter_sub();
2645 my ($self, $myconfig, $table, $module) = @_;
2648 my $dbh = $self->get_standard_dbh;
2650 $table = $table eq "customer" ? "customer" : "vendor";
2652 my $query = qq|SELECT count(*) FROM $table|;
2653 my ($count) = selectrow_query($self, $dbh, $query);
2655 # build selection list
2656 if ($count <= $myconfig->{vclimit}) {
2657 $query = qq|SELECT id, name, salesman_id
2658 FROM $table WHERE NOT obsolete
2660 $self->{"all_$table"} = selectall_hashref_query($self, $dbh, $query);
2664 $self->get_employee($dbh);
2666 # setup sales contacts
2667 $query = qq|SELECT e.id, e.name
2669 WHERE (e.sales = '1') AND (NOT e.id = ?)|;
2670 $self->{all_employees} = selectall_hashref_query($self, $dbh, $query, $self->{employee_id});
2673 push(@{ $self->{all_employees} },
2674 { id => $self->{employee_id},
2675 name => $self->{employee} });
2677 # sort the whole thing
2678 @{ $self->{all_employees} } =
2679 sort { $a->{name} cmp $b->{name} } @{ $self->{all_employees} };
2681 if ($module eq 'AR') {
2683 # prepare query for departments
2684 $query = qq|SELECT id, description
2687 ORDER BY description|;
2690 $query = qq|SELECT id, description
2692 ORDER BY description|;
2695 $self->{all_departments} = selectall_hashref_query($self, $dbh, $query);
2698 $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 $main::lxdebug->leave_sub();
2721 sub language_payment {
2722 $main::lxdebug->enter_sub();
2724 my ($self, $myconfig) = @_;
2726 my $dbh = $self->get_standard_dbh($myconfig);
2728 my $query = qq|SELECT id, description
2732 $self->{languages} = selectall_hashref_query($self, $dbh, $query);
2735 $query = qq|SELECT printer_description, id
2737 ORDER BY printer_description|;
2739 $self->{printers} = selectall_hashref_query($self, $dbh, $query);
2742 $query = qq|SELECT id, description
2746 $self->{payment_terms} = selectall_hashref_query($self, $dbh, $query);
2748 # get buchungsgruppen
2749 $query = qq|SELECT id, description
2750 FROM buchungsgruppen|;
2752 $self->{BUCHUNGSGRUPPEN} = selectall_hashref_query($self, $dbh, $query);
2754 $main::lxdebug->leave_sub();
2757 # this is only used for reports
2758 sub all_departments {
2759 $main::lxdebug->enter_sub();
2761 my ($self, $myconfig, $table) = @_;
2763 my $dbh = $self->get_standard_dbh($myconfig);
2766 if ($table eq 'customer') {
2767 $where = "WHERE role = 'P' ";
2770 my $query = qq|SELECT id, description
2773 ORDER BY description|;
2774 $self->{all_departments} = selectall_hashref_query($self, $dbh, $query);
2776 delete($self->{all_departments}) unless (@{ $self->{all_departments} || [] });
2778 $main::lxdebug->leave_sub();
2782 $main::lxdebug->enter_sub();
2784 my ($self, $module, $myconfig, $table, $provided_dbh) = @_;
2787 if ($table eq "customer") {
2796 $self->all_vc($myconfig, $table, $module);
2798 # get last customers or vendors
2799 my ($query, $sth, $ref);
2801 my $dbh = $provided_dbh ? $provided_dbh : $self->get_standard_dbh($myconfig);
2806 my $transdate = "current_date";
2807 if ($self->{transdate}) {
2808 $transdate = $dbh->quote($self->{transdate});
2811 # now get the account numbers
2812 $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
2813 FROM chart c, taxkeys tk
2814 WHERE (c.link LIKE ?) AND (c.id = tk.chart_id) AND tk.id =
2815 (SELECT id FROM taxkeys WHERE (taxkeys.chart_id = c.id) AND (startdate <= $transdate) ORDER BY startdate DESC LIMIT 1)
2818 $sth = $dbh->prepare($query);
2820 do_statement($self, $sth, $query, '%' . $module . '%');
2822 $self->{accounts} = "";
2823 while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
2825 foreach my $key (split(/:/, $ref->{link})) {
2826 if ($key =~ /\Q$module\E/) {
2828 # cross reference for keys
2829 $xkeyref{ $ref->{accno} } = $key;
2831 push @{ $self->{"${module}_links"}{$key} },
2832 { accno => $ref->{accno},
2833 description => $ref->{description},
2834 taxkey => $ref->{taxkey_id},
2835 tax_id => $ref->{tax_id} };
2837 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2843 # get taxkeys and description
2844 $query = qq|SELECT id, taxkey, taxdescription FROM tax|;
2845 $self->{TAXKEY} = selectall_hashref_query($self, $dbh, $query);
2847 if (($module eq "AP") || ($module eq "AR")) {
2848 # get tax rates and description
2849 $query = qq|SELECT * FROM tax|;
2850 $self->{TAX} = selectall_hashref_query($self, $dbh, $query);
2856 a.cp_id, a.invnumber, a.transdate, a.${table}_id, a.datepaid,
2857 a.duedate, a.ordnumber, a.taxincluded, a.curr AS currency, a.notes,
2858 a.intnotes, a.department_id, a.amount AS oldinvtotal,
2859 a.paid AS oldtotalpaid, a.employee_id, a.gldate, a.type,
2861 d.description AS department,
2864 JOIN $table c ON (a.${table}_id = c.id)
2865 LEFT JOIN employee e ON (e.id = a.employee_id)
2866 LEFT JOIN department d ON (d.id = a.department_id)
2868 $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{id});
2870 foreach my $key (keys %$ref) {
2871 $self->{$key} = $ref->{$key};
2874 my $transdate = "current_date";
2875 if ($self->{transdate}) {
2876 $transdate = $dbh->quote($self->{transdate});
2879 # now get the account numbers
2880 $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
2882 LEFT JOIN taxkeys tk ON (tk.chart_id = c.id)
2884 AND (tk.id = (SELECT id FROM taxkeys WHERE taxkeys.chart_id = c.id AND startdate <= $transdate ORDER BY startdate DESC LIMIT 1)
2885 OR c.link LIKE '%_tax%' OR c.taxkey_id IS NULL)
2888 $sth = $dbh->prepare($query);
2889 do_statement($self, $sth, $query, "%$module%");
2891 $self->{accounts} = "";
2892 while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
2894 foreach my $key (split(/:/, $ref->{link})) {
2895 if ($key =~ /\Q$module\E/) {
2897 # cross reference for keys
2898 $xkeyref{ $ref->{accno} } = $key;
2900 push @{ $self->{"${module}_links"}{$key} },
2901 { accno => $ref->{accno},
2902 description => $ref->{description},
2903 taxkey => $ref->{taxkey_id},
2904 tax_id => $ref->{tax_id} };
2906 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2912 # get amounts from individual entries
2915 c.accno, c.description,
2916 a.source, a.amount, a.memo, a.transdate, a.cleared, a.project_id, a.taxkey,
2920 LEFT JOIN chart c ON (c.id = a.chart_id)
2921 LEFT JOIN project p ON (p.id = a.project_id)
2922 LEFT JOIN tax t ON (t.id= (SELECT tk.tax_id FROM taxkeys tk
2923 WHERE (tk.taxkey_id=a.taxkey) AND
2924 ((CASE WHEN a.chart_id IN (SELECT chart_id FROM taxkeys WHERE taxkey_id = a.taxkey)
2925 THEN tk.chart_id = a.chart_id
2928 OR (c.link='%tax%')) AND
2929 (startdate <= a.transdate) ORDER BY startdate DESC LIMIT 1))
2930 WHERE a.trans_id = ?
2931 AND a.fx_transaction = '0'
2932 ORDER BY a.acc_trans_id, a.transdate|;
2933 $sth = $dbh->prepare($query);
2934 do_statement($self, $sth, $query, $self->{id});
2936 # get exchangerate for currency
2937 $self->{exchangerate} =
2938 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate}, $fld);
2941 # store amounts in {acc_trans}{$key} for multiple accounts
2942 while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
2943 $ref->{exchangerate} =
2944 $self->get_exchangerate($dbh, $self->{currency}, $ref->{transdate}, $fld);
2945 if (!($xkeyref{ $ref->{accno} } =~ /tax/)) {
2948 if (($xkeyref{ $ref->{accno} } =~ /paid/) && ($self->{type} eq "credit_note")) {
2949 $ref->{amount} *= -1;
2951 $ref->{index} = $index;
2953 push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref;
2959 d.curr AS currencies, d.closedto, d.revtrans,
2960 (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2961 (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2963 $ref = selectfirst_hashref_query($self, $dbh, $query);
2964 map { $self->{$_} = $ref->{$_} } keys %$ref;
2971 current_date AS transdate, d.curr AS currencies, d.closedto, d.revtrans,
2972 (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2973 (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2975 $ref = selectfirst_hashref_query($self, $dbh, $query);
2976 map { $self->{$_} = $ref->{$_} } keys %$ref;
2978 if ($self->{"$self->{vc}_id"}) {
2980 # only setup currency
2981 ($self->{currency}) = split(/:/, $self->{currencies});
2985 $self->lastname_used($dbh, $myconfig, $table, $module);
2987 # get exchangerate for currency
2988 $self->{exchangerate} =
2989 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate}, $fld);
2995 $main::lxdebug->leave_sub();
2999 $main::lxdebug->enter_sub();
3001 my ($self, $dbh, $myconfig, $table, $module) = @_;
3005 $table = $table eq "customer" ? "customer" : "vendor";
3006 my %column_map = ("a.curr" => "currency",
3007 "a.${table}_id" => "${table}_id",
3008 "a.department_id" => "department_id",
3009 "d.description" => "department",
3010 "ct.name" => $table,
3011 "current_date + ct.terms" => "duedate",
3014 if ($self->{type} =~ /delivery_order/) {
3015 $arap = 'delivery_orders';
3016 delete $column_map{"a.curr"};
3018 } elsif ($self->{type} =~ /_order/) {
3020 $where = "quotation = '0'";
3022 } elsif ($self->{type} =~ /_quotation/) {
3024 $where = "quotation = '1'";
3026 } elsif ($table eq 'customer') {
3034 $where = "($where) AND" if ($where);
3035 my $query = qq|SELECT MAX(id) FROM $arap
3036 WHERE $where ${table}_id > 0|;
3037 my ($trans_id) = selectrow_query($self, $dbh, $query);
3040 my $column_spec = join(', ', map { "${_} AS $column_map{$_}" } keys %column_map);
3041 $query = qq|SELECT $column_spec
3043 LEFT JOIN $table ct ON (a.${table}_id = ct.id)
3044 LEFT JOIN department d ON (a.department_id = d.id)
3046 my $ref = selectfirst_hashref_query($self, $dbh, $query, $trans_id);
3048 map { $self->{$_} = $ref->{$_} } values %column_map;
3050 $main::lxdebug->leave_sub();
3054 $main::lxdebug->enter_sub();
3057 my $myconfig = shift || \%::myconfig;
3058 my ($thisdate, $days) = @_;
3060 my $dbh = $self->get_standard_dbh($myconfig);
3065 my $dateformat = $myconfig->{dateformat};
3066 $dateformat .= "yy" if $myconfig->{dateformat} !~ /^y/;
3067 $thisdate = $dbh->quote($thisdate);
3068 $query = qq|SELECT to_date($thisdate, '$dateformat') + $days AS thisdate|;
3070 $query = qq|SELECT current_date AS thisdate|;
3073 ($thisdate) = selectrow_query($self, $dbh, $query);
3075 $main::lxdebug->leave_sub();
3081 $main::lxdebug->enter_sub();
3083 my ($self, $string) = @_;
3085 if ($string !~ /%/) {
3086 $string = "%$string%";
3089 $string =~ s/\'/\'\'/g;
3091 $main::lxdebug->leave_sub();
3097 $main::lxdebug->enter_sub();
3099 my ($self, $flds, $new, $count, $numrows) = @_;
3103 map { push @ndx, { num => $new->[$_ - 1]->{runningnumber}, ndx => $_ } } 1 .. $count;
3108 foreach my $item (sort { $a->{num} <=> $b->{num} } @ndx) {
3110 my $j = $item->{ndx} - 1;
3111 map { $self->{"${_}_$i"} = $new->[$j]->{$_} } @{$flds};
3115 for $i ($count + 1 .. $numrows) {
3116 map { delete $self->{"${_}_$i"} } @{$flds};
3119 $main::lxdebug->leave_sub();
3123 $main::lxdebug->enter_sub();
3125 my ($self, $myconfig) = @_;
3129 my $dbh = $self->dbconnect_noauto($myconfig);
3131 my $query = qq|DELETE FROM status
3132 WHERE (formname = ?) AND (trans_id = ?)|;
3133 my $sth = prepare_query($self, $dbh, $query);
3135 if ($self->{formname} =~ /(check|receipt)/) {
3136 for $i (1 .. $self->{rowcount}) {
3137 do_statement($self, $sth, $query, $self->{formname}, $self->{"id_$i"} * 1);
3140 do_statement($self, $sth, $query, $self->{formname}, $self->{id});
3144 my $printed = ($self->{printed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3145 my $emailed = ($self->{emailed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3147 my %queued = split / /, $self->{queued};
3150 if ($self->{formname} =~ /(check|receipt)/) {
3152 # this is a check or receipt, add one entry for each lineitem
3153 my ($accno) = split /--/, $self->{account};
3154 $query = qq|INSERT INTO status (trans_id, printed, spoolfile, formname, chart_id)
3155 VALUES (?, ?, ?, ?, (SELECT c.id FROM chart c WHERE c.accno = ?))|;
3156 @values = ($printed, $queued{$self->{formname}}, $self->{prinform}, $accno);
3157 $sth = prepare_query($self, $dbh, $query);
3159 for $i (1 .. $self->{rowcount}) {
3160 if ($self->{"checked_$i"}) {
3161 do_statement($self, $sth, $query, $self->{"id_$i"}, @values);
3167 $query = qq|INSERT INTO status (trans_id, printed, emailed, spoolfile, formname)
3168 VALUES (?, ?, ?, ?, ?)|;
3169 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed,
3170 $queued{$self->{formname}}, $self->{formname});
3176 $main::lxdebug->leave_sub();
3180 $main::lxdebug->enter_sub();
3182 my ($self, $dbh) = @_;
3184 my ($query, $printed, $emailed);
3186 my $formnames = $self->{printed};
3187 my $emailforms = $self->{emailed};
3189 $query = qq|DELETE FROM status
3190 WHERE (formname = ?) AND (trans_id = ?)|;
3191 do_query($self, $dbh, $query, $self->{formname}, $self->{id});
3193 # this only applies to the forms
3194 # checks and receipts are posted when printed or queued
3196 if ($self->{queued}) {
3197 my %queued = split / /, $self->{queued};
3199 foreach my $formname (keys %queued) {
3200 $printed = ($self->{printed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3201 $emailed = ($self->{emailed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3203 $query = qq|INSERT INTO status (trans_id, printed, emailed, spoolfile, formname)
3204 VALUES (?, ?, ?, ?, ?)|;
3205 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed, $queued{$formname}, $formname);
3207 $formnames =~ s/\Q$self->{formname}\E//;
3208 $emailforms =~ s/\Q$self->{formname}\E//;
3213 # save printed, emailed info
3214 $formnames =~ s/^ +//g;
3215 $emailforms =~ s/^ +//g;
3218 map { $status{$_}{printed} = 1 } split / +/, $formnames;
3219 map { $status{$_}{emailed} = 1 } split / +/, $emailforms;
3221 foreach my $formname (keys %status) {
3222 $printed = ($formnames =~ /\Q$self->{formname}\E/) ? "1" : "0";
3223 $emailed = ($emailforms =~ /\Q$self->{formname}\E/) ? "1" : "0";
3225 $query = qq|INSERT INTO status (trans_id, printed, emailed, formname)
3226 VALUES (?, ?, ?, ?)|;
3227 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed, $formname);
3230 $main::lxdebug->leave_sub();
3234 # $main::locale->text('SAVED')
3235 # $main::locale->text('DELETED')
3236 # $main::locale->text('ADDED')
3237 # $main::locale->text('PAYMENT POSTED')
3238 # $main::locale->text('POSTED')
3239 # $main::locale->text('POSTED AS NEW')
3240 # $main::locale->text('ELSE')
3241 # $main::locale->text('SAVED FOR DUNNING')
3242 # $main::locale->text('DUNNING STARTED')
3243 # $main::locale->text('PRINTED')
3244 # $main::locale->text('MAILED')
3245 # $main::locale->text('SCREENED')
3246 # $main::locale->text('CANCELED')
3247 # $main::locale->text('invoice')
3248 # $main::locale->text('proforma')
3249 # $main::locale->text('sales_order')
3250 # $main::locale->text('packing_list')
3251 # $main::locale->text('pick_list')
3252 # $main::locale->text('purchase_order')
3253 # $main::locale->text('bin_list')
3254 # $main::locale->text('sales_quotation')
3255 # $main::locale->text('request_quotation')
3258 $main::lxdebug->enter_sub();
3261 my $dbh = shift || $self->get_standard_dbh;
3263 if(!exists $self->{employee_id}) {
3264 &get_employee($self, $dbh);
3268 qq|INSERT INTO history_erp (trans_id, employee_id, addition, what_done, snumbers) | .
3269 qq|VALUES (?, (SELECT id FROM employee WHERE login = ?), ?, ?, ?)|;
3270 my @values = (conv_i($self->{id}), $self->{login},
3271 $self->{addition}, $self->{what_done}, "$self->{snumbers}");
3272 do_query($self, $dbh, $query, @values);
3276 $main::lxdebug->leave_sub();
3280 $main::lxdebug->enter_sub();
3282 my ($self, $dbh, $trans_id, $restriction, $order) = @_;
3283 my ($orderBy, $desc) = split(/\-\-/, $order);
3284 $order = " ORDER BY " . ($order eq "" ? " h.itime " : ($desc == 1 ? $orderBy . " DESC " : $orderBy . " "));
3287 if ($trans_id ne "") {
3289 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 | .
3290 qq|FROM history_erp h | .
3291 qq|LEFT JOIN employee emp ON (emp.id = h.employee_id) | .
3292 qq|WHERE (trans_id = | . $trans_id . qq|) $restriction | .
3295 my $sth = $dbh->prepare($query) || $self->dberror($query);
3297 $sth->execute() || $self->dberror("$query");
3299 while(my $hash_ref = $sth->fetchrow_hashref()) {
3300 $hash_ref->{addition} = $main::locale->text($hash_ref->{addition});
3301 $hash_ref->{what_done} = $main::locale->text($hash_ref->{what_done});
3302 $hash_ref->{snumbers} =~ s/^.+_(.*)$/$1/g;
3303 $tempArray[$i++] = $hash_ref;
3305 $main::lxdebug->leave_sub() and return \@tempArray
3306 if ($i > 0 && $tempArray[0] ne "");
3308 $main::lxdebug->leave_sub();
3312 sub update_defaults {
3313 $main::lxdebug->enter_sub();
3315 my ($self, $myconfig, $fld, $provided_dbh) = @_;
3318 if ($provided_dbh) {
3319 $dbh = $provided_dbh;
3321 $dbh = $self->dbconnect_noauto($myconfig);
3323 my $query = qq|SELECT $fld FROM defaults FOR UPDATE|;
3324 my $sth = $dbh->prepare($query);
3326 $sth->execute || $self->dberror($query);
3327 my ($var) = $sth->fetchrow_array;
3330 if ($var =~ m/\d+$/) {
3331 my $new_var = (substr $var, $-[0]) * 1 + 1;
3332 my $len_diff = length($var) - $-[0] - length($new_var);
3333 $var = substr($var, 0, $-[0]) . ($len_diff > 0 ? '0' x $len_diff : '') . $new_var;
3339 $query = qq|UPDATE defaults SET $fld = ?|;
3340 do_query($self, $dbh, $query, $var);
3342 if (!$provided_dbh) {
3347 $main::lxdebug->leave_sub();
3352 sub update_business {
3353 $main::lxdebug->enter_sub();
3355 my ($self, $myconfig, $business_id, $provided_dbh) = @_;
3358 if ($provided_dbh) {
3359 $dbh = $provided_dbh;
3361 $dbh = $self->dbconnect_noauto($myconfig);
3364 qq|SELECT customernumberinit FROM business
3365 WHERE id = ? FOR UPDATE|;
3366 my ($var) = selectrow_query($self, $dbh, $query, $business_id);
3368 return undef unless $var;
3370 if ($var =~ m/\d+$/) {
3371 my $new_var = (substr $var, $-[0]) * 1 + 1;
3372 my $len_diff = length($var) - $-[0] - length($new_var);
3373 $var = substr($var, 0, $-[0]) . ($len_diff > 0 ? '0' x $len_diff : '') . $new_var;
3379 $query = qq|UPDATE business
3380 SET customernumberinit = ?
3382 do_query($self, $dbh, $query, $var, $business_id);
3384 if (!$provided_dbh) {
3389 $main::lxdebug->leave_sub();
3394 sub get_partsgroup {
3395 $main::lxdebug->enter_sub();
3397 my ($self, $myconfig, $p) = @_;
3398 my $target = $p->{target} || 'all_partsgroup';
3400 my $dbh = $self->get_standard_dbh($myconfig);
3402 my $query = qq|SELECT DISTINCT pg.id, pg.partsgroup
3404 JOIN parts p ON (p.partsgroup_id = pg.id) |;
3407 if ($p->{searchitems} eq 'part') {
3408 $query .= qq|WHERE p.inventory_accno_id > 0|;
3410 if ($p->{searchitems} eq 'service') {
3411 $query .= qq|WHERE p.inventory_accno_id IS NULL|;
3413 if ($p->{searchitems} eq 'assembly') {
3414 $query .= qq|WHERE p.assembly = '1'|;
3416 if ($p->{searchitems} eq 'labor') {
3417 $query .= qq|WHERE (p.inventory_accno_id > 0) AND (p.income_accno_id IS NULL)|;
3420 $query .= qq|ORDER BY partsgroup|;
3423 $query = qq|SELECT id, partsgroup FROM partsgroup
3424 ORDER BY partsgroup|;
3427 if ($p->{language_code}) {
3428 $query = qq|SELECT DISTINCT pg.id, pg.partsgroup,
3429 t.description AS translation
3431 JOIN parts p ON (p.partsgroup_id = pg.id)
3432 LEFT JOIN translation t ON ((t.trans_id = pg.id) AND (t.language_code = ?))
3433 ORDER BY translation|;
3434 @values = ($p->{language_code});
3437 $self->{$target} = selectall_hashref_query($self, $dbh, $query, @values);
3439 $main::lxdebug->leave_sub();
3442 sub get_pricegroup {
3443 $main::lxdebug->enter_sub();
3445 my ($self, $myconfig, $p) = @_;
3447 my $dbh = $self->get_standard_dbh($myconfig);
3449 my $query = qq|SELECT p.id, p.pricegroup
3452 $query .= qq| ORDER BY pricegroup|;
3455 $query = qq|SELECT id, pricegroup FROM pricegroup
3456 ORDER BY pricegroup|;
3459 $self->{all_pricegroup} = selectall_hashref_query($self, $dbh, $query);
3461 $main::lxdebug->leave_sub();
3465 # usage $form->all_years($myconfig, [$dbh])
3466 # return list of all years where bookings found
3469 $main::lxdebug->enter_sub();
3471 my ($self, $myconfig, $dbh) = @_;
3473 $dbh ||= $self->get_standard_dbh($myconfig);
3476 my $query = qq|SELECT (SELECT MIN(transdate) FROM acc_trans),
3477 (SELECT MAX(transdate) FROM acc_trans)|;
3478 my ($startdate, $enddate) = selectrow_query($self, $dbh, $query);
3480 if ($myconfig->{dateformat} =~ /^yy/) {
3481 ($startdate) = split /\W/, $startdate;
3482 ($enddate) = split /\W/, $enddate;
3484 (@_) = split /\W/, $startdate;
3486 (@_) = split /\W/, $enddate;
3491 $startdate = substr($startdate,0,4);
3492 $enddate = substr($enddate,0,4);
3494 while ($enddate >= $startdate) {
3495 push @all_years, $enddate--;
3500 $main::lxdebug->leave_sub();
3504 $main::lxdebug->enter_sub();
3508 map { $self->{_VAR_BACKUP}->{$_} = $self->{$_} if exists $self->{$_} } @vars;
3510 $main::lxdebug->leave_sub();
3514 $main::lxdebug->enter_sub();
3519 map { $self->{$_} = $self->{_VAR_BACKUP}->{$_} if exists $self->{_VAR_BACKUP}->{$_} } @vars;
3521 $main::lxdebug->leave_sub();
3530 SL::Form.pm - main data object.
3534 This is the main data object of Lx-Office.
3535 Unfortunately it also acts as a god object for certain data retrieval procedures used in the entry points.
3536 Points of interest for a beginner are:
3538 - $form->error - renders a generic error in html. accepts an error message
3539 - $form->get_standard_dbh - returns a database connection for the
3541 =head1 SPECIAL FUNCTIONS
3545 =item _store_value()
3547 parses a complex var name, and stores it in the form.
3550 $form->_store_value($key, $value);
3552 keys must start with a string, and can contain various tokens.
3553 supported key structures are:
3556 simple key strings work as expected
3561 separating two keys by a dot (.) will result in a hash lookup for the inner value
3562 this is similar to the behaviour of java and templating mechanisms.
3564 filter.description => $form->{filter}->{description}
3566 3. array+hashref access
3568 adding brackets ([]) before the dot will cause the next hash to be put into an array.
3569 using [+] instead of [] will force a new array index. this is useful for recurring
3570 data structures like part lists. put a [+] into the first varname, and use [] on the
3573 repeating these names in your template:
3576 invoice.items[].parts_id
3580 $form->{invoice}->{items}->[
3594 using brackets at the end of a name will result in a pure array to be created.
3595 note that you mustn't use [+], which is reserved for array+hash access and will
3596 result in undefined behaviour in array context.
3598 filter.status[] => $form->{status}->[ val1, val2, ... ]
3600 =item update_business PARAMS
3603 \%config, - config hashref
3604 $business_id, - business id
3605 $dbh - optional database handle
3607 handles business (thats customer/vendor types) sequences.
3609 special behaviour for empty strings in customerinitnumber field:
3610 will in this case not increase the value, and return undef.
3612 =item redirect_header $url
3614 Generates a HTTP redirection header for the new C<$url>. Constructs an
3615 absolute URL including scheme, host name and port. If C<$url> is a
3616 relative URL then it is considered relative to Lx-Office base URL.
3618 This function C<die>s if headers have already been created with
3619 C<$::form-E<gt>header>.
3623 print $::form->redirect_header('oe.pl?action=edit&id=1234');
3624 print $::form->redirect_header('http://www.lx-office.org/');