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 my $encoding = $self->{INPUT_ENCODING} || $db_charset;
261 delete $self->{INPUT_ENCODING};
263 _recode_recursively(SL::Iconv->new($encoding, $db_charset), $self);
265 $self->{action} = lc $self->{action};
266 $self->{action} =~ s/( |-|,|\#)/_/g;
268 $self->{version} = "2.6.1";
270 $main::lxdebug->leave_sub();
275 sub _flatten_variables_rec {
276 $main::lxdebug->enter_sub(2);
285 if ('' eq ref $curr->{$key}) {
286 @result = ({ 'key' => $prefix . $key, 'value' => $curr->{$key} });
288 } elsif ('HASH' eq ref $curr->{$key}) {
289 foreach my $hash_key (sort keys %{ $curr->{$key} }) {
290 push @result, $self->_flatten_variables_rec($curr->{$key}, $prefix . $key . '.', $hash_key);
294 foreach my $idx (0 .. scalar @{ $curr->{$key} } - 1) {
295 my $first_array_entry = 1;
297 foreach my $hash_key (sort keys %{ $curr->{$key}->[$idx] }) {
298 push @result, $self->_flatten_variables_rec($curr->{$key}->[$idx], $prefix . $key . ($first_array_entry ? '[+].' : '[].'), $hash_key);
299 $first_array_entry = 0;
304 $main::lxdebug->leave_sub(2);
309 sub flatten_variables {
310 $main::lxdebug->enter_sub(2);
318 push @variables, $self->_flatten_variables_rec($self, '', $_);
321 $main::lxdebug->leave_sub(2);
326 sub flatten_standard_variables {
327 $main::lxdebug->enter_sub(2);
330 my %skip_keys = map { $_ => 1 } (qw(login password header stylesheet titlebar version), @_);
334 foreach (grep { ! $skip_keys{$_} } keys %{ $self }) {
335 push @variables, $self->_flatten_variables_rec($self, '', $_);
338 $main::lxdebug->leave_sub(2);
344 $main::lxdebug->enter_sub();
350 map { print "$_ = $self->{$_}\n" } (sort keys %{$self});
352 $main::lxdebug->leave_sub();
356 $main::lxdebug->enter_sub(2);
359 my $password = $self->{password};
361 $self->{password} = 'X' x 8;
363 local $Data::Dumper::Sortkeys = 1;
364 my $output = Dumper($self);
366 $self->{password} = $password;
368 $main::lxdebug->leave_sub(2);
374 $main::lxdebug->enter_sub(2);
376 my ($self, $str) = @_;
378 $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
380 $main::lxdebug->leave_sub(2);
386 $main::lxdebug->enter_sub(2);
388 my ($self, $str) = @_;
393 $str =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
395 $main::lxdebug->leave_sub(2);
401 $main::lxdebug->enter_sub();
402 my ($self, $str) = @_;
404 if ($str && !ref($str)) {
405 $str =~ s/\"/"/g;
408 $main::lxdebug->leave_sub();
414 $main::lxdebug->enter_sub();
415 my ($self, $str) = @_;
417 if ($str && !ref($str)) {
418 $str =~ s/"/\"/g;
421 $main::lxdebug->leave_sub();
427 $main::lxdebug->enter_sub();
431 map({ print($main::cgi->hidden("-name" => $_, "-default" => $self->{$_}) . "\n"); } @_);
433 for (sort keys %$self) {
434 next if (($_ eq "header") || (ref($self->{$_}) ne ""));
435 print($main::cgi->hidden("-name" => $_, "-default" => $self->{$_}) . "\n");
438 $main::lxdebug->leave_sub();
442 $main::lxdebug->enter_sub();
444 $main::lxdebug->show_backtrace();
446 my ($self, $msg) = @_;
447 if ($ENV{HTTP_USER_AGENT}) {
449 $self->show_generic_error($msg);
452 print STDERR "Error: $msg\n";
456 $main::lxdebug->leave_sub();
460 $main::lxdebug->enter_sub();
462 my ($self, $msg) = @_;
464 if ($ENV{HTTP_USER_AGENT}) {
467 if (!$self->{header}) {
480 if ($self->{info_function}) {
481 &{ $self->{info_function} }($msg);
487 $main::lxdebug->leave_sub();
490 # calculates the number of rows in a textarea based on the content and column number
491 # can be capped with maxrows
493 $main::lxdebug->enter_sub();
494 my ($self, $str, $cols, $maxrows, $minrows) = @_;
498 my $rows = sum map { int((length() - 2) / $cols) + 1 } split /\r/, $str;
501 $main::lxdebug->leave_sub();
503 return max(min($rows, $maxrows), $minrows);
507 $main::lxdebug->enter_sub();
509 my ($self, $msg) = @_;
511 $self->error("$msg\n" . $DBI::errstr);
513 $main::lxdebug->leave_sub();
517 $main::lxdebug->enter_sub();
519 my ($self, $name, $msg) = @_;
522 foreach my $part (split m/\./, $name) {
523 if (!$curr->{$part} || ($curr->{$part} =~ /^\s*$/)) {
526 $curr = $curr->{$part};
529 $main::lxdebug->leave_sub();
532 sub _get_request_uri {
535 return URI->new($ENV{HTTP_REFERER})->canonical() if $ENV{HTTP_X_FORWARDED_FOR};
537 my $scheme = $ENV{HTTPS} && (lc $ENV{HTTPS} eq 'on') ? 'https' : 'http';
538 my $port = $ENV{SERVER_PORT} || '';
539 $port = undef if (($scheme eq 'http' ) && ($port == 80))
540 || (($scheme eq 'https') && ($port == 443));
542 my $uri = URI->new("${scheme}://");
543 $uri->scheme($scheme);
545 $uri->host($ENV{HTTP_HOST} || $ENV{SERVER_ADDR});
546 $uri->path_query($ENV{REQUEST_URI});
552 sub _add_to_request_uri {
555 my $relative_new_path = shift;
556 my $request_uri = shift || $self->_get_request_uri;
557 my $relative_new_uri = URI->new($relative_new_path);
558 my @request_segments = $request_uri->path_segments;
560 my $new_uri = $request_uri->clone;
561 $new_uri->path_segments(@request_segments[0..scalar(@request_segments) - 2], $relative_new_uri->path_segments);
566 sub create_http_response {
567 $main::lxdebug->enter_sub();
572 my $cgi = $main::cgi;
573 $cgi ||= CGI->new('');
576 if (defined $main::auth) {
577 my $uri = $self->_get_request_uri;
578 my @segments = $uri->path_segments;
580 $uri->path_segments(@segments);
582 my $session_cookie_value = $main::auth->get_session_id();
583 $session_cookie_value ||= 'NO_SESSION';
585 $session_cookie = $cgi->cookie('-name' => $main::auth->get_session_cookie_name(),
586 '-value' => $session_cookie_value,
587 '-path' => $uri->path,
588 '-secure' => $ENV{HTTPS});
591 my %cgi_params = ('-type' => $params{content_type});
592 $cgi_params{'-charset'} = $params{charset} if ($params{charset});
594 my $output = $cgi->header('-cookie' => $session_cookie,
597 $main::lxdebug->leave_sub();
604 $main::lxdebug->enter_sub();
606 # extra code ist currently only used by menuv3 and menuv4 to set their css.
607 # it is strongly deprecated, and will be changed in a future version.
608 my ($self, $extra_code) = @_;
610 if ($self->{header}) {
611 $main::lxdebug->leave_sub();
615 my ($stylesheet, $favicon, $pagelayout);
617 if ($ENV{HTTP_USER_AGENT}) {
620 if ($ENV{'HTTP_USER_AGENT'} =~ m/MSIE\s+\d/) {
621 # Only set the DOCTYPE for Internet Explorer. Other browsers have problems displaying the menu otherwise.
622 $doctype = qq|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n|;
625 my $stylesheets = "$self->{stylesheet} $self->{stylesheets}";
627 $stylesheets =~ s|^\s*||;
628 $stylesheets =~ s|\s*$||;
629 foreach my $file (split m/\s+/, $stylesheets) {
631 next if (! -f "css/$file");
633 $stylesheet .= qq|<link rel="stylesheet" href="css/$file" TYPE="text/css" TITLE="Lx-Office stylesheet">\n|;
636 $self->{favicon} = "favicon.ico" unless $self->{favicon};
638 if ($self->{favicon} && (-f "$self->{favicon}")) {
640 qq|<LINK REL="shortcut icon" HREF="$self->{favicon}" TYPE="image/x-icon">
644 my $db_charset = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
646 if ($self->{landscape}) {
647 $pagelayout = qq|<style type="text/css">
648 \@page { size:landscape; }
653 <script type="text/javascript">
656 document.$self->{fokus}.focus();
660 | if $self->{"fokus"};
664 if ($self->{jsscript} == 1) {
667 <script type="text/javascript" src="js/jquery.js"></script>
668 <script type="text/javascript" src="js/common.js"></script>
669 <style type="text/css">\@import url(js/jscalendar/calendar-win2k-1.css);</style>
670 <script type="text/javascript" src="js/jscalendar/calendar.js"></script>
671 <script type="text/javascript" src="js/jscalendar/lang/calendar-de.js"></script>
672 <script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script>
679 ? "$self->{title} - $self->{titlebar}"
682 for my $item (@ { $self->{AJAX} || [] }) {
683 $ajax .= $item->show_javascript();
686 print $self->create_http_response('content_type' => 'text/html',
687 'charset' => $db_charset,);
688 print qq|${doctype}<html>
690 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=${db_charset}">
691 <title>$self->{titlebar}</title>
700 <link rel="stylesheet" href="css/jquery.autocomplete.css" type="text/css" />
702 <meta name="robots" content="noindex,nofollow" />
703 <script type="text/javascript" src="js/highlight_input.js"></script>
705 <link rel="stylesheet" type="text/css" href="css/tabcontent.css" />
706 <script type="text/javascript" src="js/tabcontent.js">
708 /***********************************************
709 * Tab Content script v2.2- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
710 * This notice MUST stay intact for legal use
711 * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
712 ***********************************************/
723 $main::lxdebug->leave_sub();
726 sub ajax_response_header {
727 $main::lxdebug->enter_sub();
731 my $db_charset = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
732 my $cgi = $main::cgi || CGI->new('');
733 my $output = $cgi->header('-charset' => $db_charset);
735 $main::lxdebug->leave_sub();
740 sub redirect_header {
744 my $base_uri = $self->_get_request_uri;
745 my $new_uri = URI->new_abs($new_url, $base_uri);
747 die "Headers already sent" if $::self->{header};
750 my $cgi = $main::cgi || CGI->new('');
751 return $cgi->redirect($new_uri);
754 sub set_standard_title {
755 $::lxdebug->enter_sub;
758 $self->{titlebar} = "Lx-Office " . $::locale->text('Version') . " $self->{version}";
759 $self->{titlebar} .= "- $::myconfig{name}" if $::myconfig{name};
760 $self->{titlebar} .= "- $::myconfig{dbname}" if $::myconfig{name};
762 $::lxdebug->leave_sub;
765 sub _prepare_html_template {
766 $main::lxdebug->enter_sub();
768 my ($self, $file, $additional_params) = @_;
771 if (!%::myconfig || !$::myconfig{"countrycode"}) {
772 $language = $main::language;
774 $language = $main::myconfig{"countrycode"};
776 $language = "de" unless ($language);
778 if (-f "templates/webpages/${file}.html") {
779 if ((-f ".developer") && ((stat("templates/webpages/${file}.html"))[9] > (stat("locale/${language}/all"))[9])) {
780 my $info = "Developer information: templates/webpages/${file}.html is newer than the translation file locale/${language}/all.\n" .
781 "Please re-run 'locales.pl' in 'locale/${language}'.";
782 print(qq|<pre>$info</pre>|);
786 $file = "templates/webpages/${file}.html";
789 my $info = "Web page template '${file}' not found.\n" .
790 "Please re-run 'locales.pl' in 'locale/${language}'.";
791 print(qq|<pre>$info</pre>|);
795 if ($self->{"DEBUG"}) {
796 $additional_params->{"DEBUG"} = $self->{"DEBUG"};
799 if ($additional_params->{"DEBUG"}) {
800 $additional_params->{"DEBUG"} =
801 "<br><em>DEBUG INFORMATION:</em><pre>" . $additional_params->{"DEBUG"} . "</pre>";
804 if (%main::myconfig) {
805 map({ $additional_params->{"myconfig_${_}"} = $main::myconfig{$_}; } keys(%main::myconfig));
806 my $jsc_dateformat = $main::myconfig{"dateformat"};
807 $jsc_dateformat =~ s/d+/\%d/gi;
808 $jsc_dateformat =~ s/m+/\%m/gi;
809 $jsc_dateformat =~ s/y+/\%Y/gi;
810 $additional_params->{"myconfig_jsc_dateformat"} = $jsc_dateformat;
811 $additional_params->{"myconfig"} ||= \%::myconfig;
814 $additional_params->{"conf_dbcharset"} = $main::dbcharset;
815 $additional_params->{"conf_webdav"} = $main::webdav;
816 $additional_params->{"conf_lizenzen"} = $main::lizenzen;
817 $additional_params->{"conf_latex_templates"} = $main::latex;
818 $additional_params->{"conf_opendocument_templates"} = $main::opendocument_templates;
819 $additional_params->{"conf_vertreter"} = $main::vertreter;
820 $additional_params->{"conf_show_best_before"} = $main::show_best_before;
822 if (%main::debug_options) {
823 map { $additional_params->{'DEBUG_' . uc($_)} = $main::debug_options{$_} } keys %main::debug_options;
826 if ($main::auth && $main::auth->{RIGHTS} && $main::auth->{RIGHTS}->{$self->{login}}) {
827 while (my ($key, $value) = each %{ $main::auth->{RIGHTS}->{$self->{login}} }) {
828 $additional_params->{"AUTH_RIGHTS_" . uc($key)} = $value;
832 $main::lxdebug->leave_sub();
837 sub parse_html_template {
838 $main::lxdebug->enter_sub();
840 my ($self, $file, $additional_params) = @_;
842 $additional_params ||= { };
844 my $real_file = $self->_prepare_html_template($file, $additional_params);
845 my $template = $self->template || $self->init_template;
847 map { $additional_params->{$_} ||= $self->{$_} } keys %{ $self };
850 $template->process($real_file, $additional_params, \$output) || die $template->error;
852 $main::lxdebug->leave_sub();
860 return if $self->template;
862 return $self->template(Template->new({
867 'PLUGIN_BASE' => 'SL::Template::Plugin',
868 'INCLUDE_PATH' => '.:templates/webpages',
869 'COMPILE_EXT' => '.tcc',
870 'COMPILE_DIR' => $::userspath . '/templates-cache',
876 $self->{template_object} = shift if @_;
877 return $self->{template_object};
880 sub show_generic_error {
881 $main::lxdebug->enter_sub();
883 my ($self, $error, %params) = @_;
886 'title_error' => $params{title},
887 'label_error' => $error,
890 if ($params{action}) {
893 map { delete($self->{$_}); } qw(action);
894 map { push @vars, { "name" => $_, "value" => $self->{$_} } if (!ref($self->{$_})); } keys %{ $self };
896 $add_params->{SHOW_BUTTON} = 1;
897 $add_params->{BUTTON_LABEL} = $params{label} || $params{action};
898 $add_params->{VARIABLES} = \@vars;
900 } elsif ($params{back_button}) {
901 $add_params->{SHOW_BACK_BUTTON} = 1;
904 $self->{title} = $params{title} if $params{title};
907 print $self->parse_html_template("generic/error", $add_params);
909 print STDERR "Error: $error\n";
911 $main::lxdebug->leave_sub();
916 sub show_generic_information {
917 $main::lxdebug->enter_sub();
919 my ($self, $text, $title) = @_;
922 'title_information' => $title,
923 'label_information' => $text,
926 $self->{title} = $title if ($title);
929 print $self->parse_html_template("generic/information", $add_params);
931 $main::lxdebug->leave_sub();
936 # write Trigger JavaScript-Code ($qty = quantity of Triggers)
937 # changed it to accept an arbitrary number of triggers - sschoeling
939 $main::lxdebug->enter_sub();
942 my $myconfig = shift;
945 # set dateform for jsscript
948 "dd.mm.yy" => "%d.%m.%Y",
949 "dd-mm-yy" => "%d-%m-%Y",
950 "dd/mm/yy" => "%d/%m/%Y",
951 "mm/dd/yy" => "%m/%d/%Y",
952 "mm-dd-yy" => "%m-%d-%Y",
953 "yyyy-mm-dd" => "%Y-%m-%d",
956 my $ifFormat = defined($dateformats{$myconfig->{"dateformat"}}) ?
957 $dateformats{$myconfig->{"dateformat"}} : "%d.%m.%Y";
964 inputField : "| . (shift) . qq|",
965 ifFormat :"$ifFormat",
966 align : "| . (shift) . qq|",
967 button : "| . (shift) . qq|"
973 <script type="text/javascript">
974 <!--| . join("", @triggers) . qq|//-->
978 $main::lxdebug->leave_sub();
981 } #end sub write_trigger
984 $main::lxdebug->enter_sub();
986 my ($self, $msg) = @_;
988 if (!$self->{callback}) {
994 # my ($script, $argv) = split(/\?/, $self->{callback}, 2);
995 # $script =~ s|.*/||;
996 # $script =~ s|[^a-zA-Z0-9_\.]||g;
997 # exec("perl", "$script", $argv);
999 print $::form->redirect_header($self->{callback});
1001 $main::lxdebug->leave_sub();
1004 # sort of columns removed - empty sub
1006 $main::lxdebug->enter_sub();
1008 my ($self, @columns) = @_;
1010 $main::lxdebug->leave_sub();
1016 $main::lxdebug->enter_sub(2);
1018 my ($self, $myconfig, $amount, $places, $dash) = @_;
1020 if ($amount eq "") {
1024 # Hey watch out! The amount can be an exponential term like 1.13686837721616e-13
1026 my $neg = ($amount =~ s/^-//);
1027 my $exp = ($amount =~ m/[e]/) ? 1 : 0;
1029 if (defined($places) && ($places ne '')) {
1035 my ($actual_places) = ($amount =~ /\.(\d+)/);
1036 $actual_places = length($actual_places);
1037 $places = $actual_places > $places ? $actual_places : $places;
1040 $amount = $self->round_amount($amount, $places);
1043 my @d = map { s/\d//g; reverse split // } my $tmp = $myconfig->{numberformat}; # get delim chars
1044 my @p = split(/\./, $amount); # split amount at decimal point
1046 $p[0] =~ s/\B(?=(...)*$)/$d[1]/g if $d[1]; # add 1,000 delimiters
1049 $amount .= $d[0].$p[1].(0 x ($places - length $p[1])) if ($places || $p[1] ne '');
1052 ($dash =~ /-/) ? ($neg ? "($amount)" : "$amount" ) :
1053 ($dash =~ /DRCR/) ? ($neg ? "$amount " . $main::locale->text('DR') : "$amount " . $main::locale->text('CR') ) :
1054 ($neg ? "-$amount" : "$amount" ) ;
1058 $main::lxdebug->leave_sub(2);
1062 sub format_amount_units {
1063 $main::lxdebug->enter_sub();
1068 my $myconfig = \%main::myconfig;
1069 my $amount = $params{amount} * 1;
1070 my $places = $params{places};
1071 my $part_unit_name = $params{part_unit};
1072 my $amount_unit_name = $params{amount_unit};
1073 my $conv_units = $params{conv_units};
1074 my $max_places = $params{max_places};
1076 if (!$part_unit_name) {
1077 $main::lxdebug->leave_sub();
1081 AM->retrieve_all_units();
1082 my $all_units = $main::all_units;
1084 if (('' eq ref $conv_units) && ($conv_units =~ /convertible/)) {
1085 $conv_units = AM->convertible_units($all_units, $part_unit_name, $conv_units eq 'convertible_not_smaller');
1088 if (!scalar @{ $conv_units }) {
1089 my $result = $self->format_amount($myconfig, $amount, $places, undef, $max_places) . " " . $part_unit_name;
1090 $main::lxdebug->leave_sub();
1094 my $part_unit = $all_units->{$part_unit_name};
1095 my $conv_unit = ($amount_unit_name && ($amount_unit_name ne $part_unit_name)) ? $all_units->{$amount_unit_name} : $part_unit;
1097 $amount *= $conv_unit->{factor};
1102 foreach my $unit (@$conv_units) {
1103 my $last = $unit->{name} eq $part_unit->{name};
1105 $num = int($amount / $unit->{factor});
1106 $amount -= $num * $unit->{factor};
1109 if ($last ? $amount : $num) {
1110 push @values, { "unit" => $unit->{name},
1111 "amount" => $last ? $amount / $unit->{factor} : $num,
1112 "places" => $last ? $places : 0 };
1119 push @values, { "unit" => $part_unit_name,
1124 my $result = join " ", map { $self->format_amount($myconfig, $_->{amount}, $_->{places}, undef, $max_places), $_->{unit} } @values;
1126 $main::lxdebug->leave_sub();
1132 $main::lxdebug->enter_sub(2);
1137 $input =~ s/(^|[^\#]) \# (\d+) /$1$_[$2 - 1]/gx;
1138 $input =~ s/(^|[^\#]) \#\{(\d+)\}/$1$_[$2 - 1]/gx;
1139 $input =~ s/\#\#/\#/g;
1141 $main::lxdebug->leave_sub(2);
1149 $main::lxdebug->enter_sub(2);
1151 my ($self, $myconfig, $amount) = @_;
1153 if ( ($myconfig->{numberformat} eq '1.000,00')
1154 || ($myconfig->{numberformat} eq '1000,00')) {
1159 if ($myconfig->{numberformat} eq "1'000.00") {
1165 $main::lxdebug->leave_sub(2);
1167 return ($amount * 1);
1171 $main::lxdebug->enter_sub(2);
1173 my ($self, $amount, $places) = @_;
1176 # Rounding like "Kaufmannsrunden" (see http://de.wikipedia.org/wiki/Rundung )
1178 # Round amounts to eight places before rounding to the requested
1179 # number of places. This gets rid of errors due to internal floating
1180 # point representation.
1181 $amount = $self->round_amount($amount, 8) if $places < 8;
1182 $amount = $amount * (10**($places));
1183 $round_amount = int($amount + .5 * ($amount <=> 0)) / (10**($places));
1185 $main::lxdebug->leave_sub(2);
1187 return $round_amount;
1191 sub parse_template {
1192 $main::lxdebug->enter_sub();
1194 my ($self, $myconfig, $userspath) = @_;
1199 $self->{"cwd"} = getcwd();
1200 $self->{"tmpdir"} = $self->{cwd} . "/${userspath}";
1205 if ($self->{"format"} =~ /(opendocument|oasis)/i) {
1206 $template_type = 'OpenDocument';
1207 $ext_for_format = $self->{"format"} =~ m/pdf/ ? 'pdf' : 'odt';
1209 } elsif ($self->{"format"} =~ /(postscript|pdf)/i) {
1210 $ENV{"TEXINPUTS"} = ".:" . getcwd() . "/" . $myconfig->{"templates"} . ":" . $ENV{"TEXINPUTS"};
1211 $template_type = 'LaTeX';
1212 $ext_for_format = 'pdf';
1214 } elsif (($self->{"format"} =~ /html/i) || (!$self->{"format"} && ($self->{"IN"} =~ /html$/i))) {
1215 $template_type = 'HTML';
1216 $ext_for_format = 'html';
1218 } elsif (($self->{"format"} =~ /xml/i) || (!$self->{"format"} && ($self->{"IN"} =~ /xml$/i))) {
1219 $template_type = 'XML';
1220 $ext_for_format = 'xml';
1222 } elsif ( $self->{"format"} =~ /elster(?:winston|taxbird)/i ) {
1223 $template_type = 'xml';
1225 } elsif ( $self->{"format"} =~ /excel/i ) {
1226 $template_type = 'Excel';
1227 $ext_for_format = 'xls';
1229 } elsif ( defined $self->{'format'}) {
1230 $self->error("Outputformat not defined. This may be a future feature: $self->{'format'}");
1232 } elsif ( $self->{'format'} eq '' ) {
1233 $self->error("No Outputformat given: $self->{'format'}");
1235 } else { #Catch the rest
1236 $self->error("Outputformat not defined: $self->{'format'}");
1239 my $template = SL::Template::create(type => $template_type,
1240 file_name => $self->{IN},
1242 myconfig => $myconfig,
1243 userspath => $userspath);
1245 # Copy the notes from the invoice/sales order etc. back to the variable "notes" because that is where most templates expect it to be.
1246 $self->{"notes"} = $self->{ $self->{"formname"} . "notes" };
1248 if (!$self->{employee_id}) {
1249 map { $self->{"employee_${_}"} = $myconfig->{$_}; } qw(email tel fax name signature company address businessnumber co_ustid taxnumber duns);
1252 map { $self->{"${_}"} = $myconfig->{$_}; } qw(co_ustid);
1254 $self->{copies} = 1 if (($self->{copies} *= 1) <= 0);
1256 # OUT is used for the media, screen, printer, email
1257 # for postscript we store a copy in a temporary file
1259 my $prepend_userspath;
1261 if (!$self->{tmpfile}) {
1262 $self->{tmpfile} = "${fileid}.$self->{IN}";
1263 $prepend_userspath = 1;
1266 $prepend_userspath = 1 if substr($self->{tmpfile}, 0, length $userspath) eq $userspath;
1268 $self->{tmpfile} =~ s|.*/||;
1269 $self->{tmpfile} =~ s/[^a-zA-Z0-9\._\ \-]//g;
1270 $self->{tmpfile} = "$userspath/$self->{tmpfile}" if $prepend_userspath;
1272 if ($template->uses_temp_file() || $self->{media} eq 'email') {
1273 $out = $self->{OUT};
1274 $self->{OUT} = ">$self->{tmpfile}";
1280 open OUT, "$self->{OUT}" or $self->error("$self->{OUT} : $!");
1281 $result = $template->parse(*OUT);
1286 $result = $template->parse(*STDOUT);
1291 $self->error("$self->{IN} : " . $template->get_error());
1294 if ($template->uses_temp_file() || $self->{media} eq 'email') {
1296 if ($self->{media} eq 'email') {
1298 my $mail = new Mailer;
1300 map { $mail->{$_} = $self->{$_} }
1301 qw(cc bcc subject message version format);
1302 $mail->{charset} = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
1303 $mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email};
1304 $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
1305 $mail->{fileid} = "$fileid.";
1306 $myconfig->{signature} =~ s/\r//g;
1308 # if we send html or plain text inline
1309 if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
1310 $mail->{contenttype} = "text/html";
1312 $mail->{message} =~ s/\r//g;
1313 $mail->{message} =~ s/\n/<br>\n/g;
1314 $myconfig->{signature} =~ s/\n/<br>\n/g;
1315 $mail->{message} .= "<br>\n-- <br>\n$myconfig->{signature}\n<br>";
1317 open(IN, $self->{tmpfile})
1318 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
1320 $mail->{message} .= $_;
1327 if (!$self->{"do_not_attach"}) {
1328 my $attachment_name = $self->{attachment_filename} || $self->{tmpfile};
1329 $attachment_name =~ s/\.(.+?)$/.${ext_for_format}/ if ($ext_for_format);
1330 $mail->{attachments} = [{ "filename" => $self->{tmpfile},
1331 "name" => $attachment_name }];
1334 $mail->{message} =~ s/\r//g;
1335 $mail->{message} .= "\n-- \n$myconfig->{signature}";
1339 my $err = $mail->send();
1340 $self->error($self->cleanup . "$err") if ($err);
1344 $self->{OUT} = $out;
1346 my $numbytes = (-s $self->{tmpfile});
1347 open(IN, $self->{tmpfile})
1348 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
1350 $self->{copies} = 1 unless $self->{media} eq 'printer';
1352 chdir("$self->{cwd}");
1353 #print(STDERR "Kopien $self->{copies}\n");
1354 #print(STDERR "OUT $self->{OUT}\n");
1355 for my $i (1 .. $self->{copies}) {
1357 open OUT, $self->{OUT} or $self->error($self->cleanup . "$self->{OUT} : $!");
1358 print OUT while <IN>;
1363 $self->{attachment_filename} = ($self->{attachment_filename})
1364 ? $self->{attachment_filename}
1365 : $self->generate_attachment_filename();
1367 # launch application
1368 print qq|Content-Type: | . $template->get_mime_type() . qq|
1369 Content-Disposition: attachment; filename="$self->{attachment_filename}"
1370 Content-Length: $numbytes
1374 $::locale->with_raw_io(\*STDOUT, sub { print while <IN> });
1385 chdir("$self->{cwd}");
1386 $main::lxdebug->leave_sub();
1389 sub get_formname_translation {
1390 $main::lxdebug->enter_sub();
1391 my ($self, $formname) = @_;
1393 $formname ||= $self->{formname};
1395 my %formname_translations = (
1396 bin_list => $main::locale->text('Bin List'),
1397 credit_note => $main::locale->text('Credit Note'),
1398 invoice => $main::locale->text('Invoice'),
1399 packing_list => $main::locale->text('Packing List'),
1400 pick_list => $main::locale->text('Pick List'),
1401 proforma => $main::locale->text('Proforma Invoice'),
1402 purchase_order => $main::locale->text('Purchase Order'),
1403 request_quotation => $main::locale->text('RFQ'),
1404 sales_order => $main::locale->text('Confirmation'),
1405 sales_quotation => $main::locale->text('Quotation'),
1406 storno_invoice => $main::locale->text('Storno Invoice'),
1407 storno_packing_list => $main::locale->text('Storno Packing List'),
1408 sales_delivery_order => $main::locale->text('Delivery Order'),
1409 purchase_delivery_order => $main::locale->text('Delivery Order'),
1410 dunning => $main::locale->text('Dunning'),
1413 $main::lxdebug->leave_sub();
1414 return $formname_translations{$formname}
1417 sub get_number_prefix_for_type {
1418 $main::lxdebug->enter_sub();
1422 (first { $self->{type} eq $_ } qw(invoice credit_note)) ? 'inv'
1423 : ($self->{type} =~ /_quotation$/) ? 'quo'
1424 : ($self->{type} =~ /_delivery_order$/) ? 'do'
1427 $main::lxdebug->leave_sub();
1431 sub get_extension_for_format {
1432 $main::lxdebug->enter_sub();
1435 my $extension = $self->{format} =~ /pdf/i ? ".pdf"
1436 : $self->{format} =~ /postscript/i ? ".ps"
1437 : $self->{format} =~ /opendocument/i ? ".odt"
1438 : $self->{format} =~ /excel/i ? ".xls"
1439 : $self->{format} =~ /html/i ? ".html"
1442 $main::lxdebug->leave_sub();
1446 sub generate_attachment_filename {
1447 $main::lxdebug->enter_sub();
1450 my $attachment_filename = $main::locale->unquote_special_chars('HTML', $self->get_formname_translation());
1451 my $prefix = $self->get_number_prefix_for_type();
1453 if ($self->{preview} && (first { $self->{type} eq $_ } qw(invoice credit_note))) {
1454 $attachment_filename .= ' (' . $main::locale->text('Preview') . ')' . $self->get_extension_for_format();
1456 } elsif ($attachment_filename && $self->{"${prefix}number"}) {
1457 $attachment_filename .= "_" . $self->{"${prefix}number"} . $self->get_extension_for_format();
1460 $attachment_filename = "";
1463 $attachment_filename = $main::locale->quote_special_chars('filenames', $attachment_filename);
1464 $attachment_filename =~ s|[\s/\\]+|_|g;
1466 $main::lxdebug->leave_sub();
1467 return $attachment_filename;
1470 sub generate_email_subject {
1471 $main::lxdebug->enter_sub();
1474 my $subject = $main::locale->unquote_special_chars('HTML', $self->get_formname_translation());
1475 my $prefix = $self->get_number_prefix_for_type();
1477 if ($subject && $self->{"${prefix}number"}) {
1478 $subject .= " " . $self->{"${prefix}number"}
1481 $main::lxdebug->leave_sub();
1486 $main::lxdebug->enter_sub();
1490 chdir("$self->{tmpdir}");
1493 if (-f "$self->{tmpfile}.err") {
1494 open(FH, "$self->{tmpfile}.err");
1499 if ($self->{tmpfile} && ! $::keep_temp_files) {
1500 $self->{tmpfile} =~ s|.*/||g;
1502 $self->{tmpfile} =~ s/\.\w+$//g;
1503 my $tmpfile = $self->{tmpfile};
1504 unlink(<$tmpfile.*>);
1507 chdir("$self->{cwd}");
1509 $main::lxdebug->leave_sub();
1515 $main::lxdebug->enter_sub();
1517 my ($self, $date, $myconfig) = @_;
1520 if ($date && $date =~ /\D/) {
1522 if ($myconfig->{dateformat} =~ /^yy/) {
1523 ($yy, $mm, $dd) = split /\D/, $date;
1525 if ($myconfig->{dateformat} =~ /^mm/) {
1526 ($mm, $dd, $yy) = split /\D/, $date;
1528 if ($myconfig->{dateformat} =~ /^dd/) {
1529 ($dd, $mm, $yy) = split /\D/, $date;
1534 $yy = ($yy < 70) ? $yy + 2000 : $yy;
1535 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
1537 $dd = "0$dd" if ($dd < 10);
1538 $mm = "0$mm" if ($mm < 10);
1540 $date = "$yy$mm$dd";
1543 $main::lxdebug->leave_sub();
1548 # Database routines used throughout
1551 $main::lxdebug->enter_sub(2);
1553 my ($self, $myconfig) = @_;
1555 # connect to database
1557 DBI->connect($myconfig->{dbconnect},
1558 $myconfig->{dbuser}, $myconfig->{dbpasswd})
1562 if ($myconfig->{dboptions}) {
1563 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1566 $main::lxdebug->leave_sub(2);
1571 sub dbconnect_noauto {
1572 $main::lxdebug->enter_sub();
1574 my ($self, $myconfig) = @_;
1576 # connect to database
1578 DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser},
1579 $myconfig->{dbpasswd}, { AutoCommit => 0 })
1583 if ($myconfig->{dboptions}) {
1584 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1587 $main::lxdebug->leave_sub();
1592 sub get_standard_dbh {
1593 $main::lxdebug->enter_sub(2);
1596 my $myconfig = shift || \%::myconfig;
1598 if ($standard_dbh && !$standard_dbh->{Active}) {
1599 $main::lxdebug->message(LXDebug->INFO(), "get_standard_dbh: \$standard_dbh is defined but not Active anymore");
1600 undef $standard_dbh;
1603 $standard_dbh ||= $self->dbconnect_noauto($myconfig);
1605 $main::lxdebug->leave_sub(2);
1607 return $standard_dbh;
1611 $main::lxdebug->enter_sub();
1613 my ($self, $date, $myconfig) = @_;
1614 my $dbh = $self->dbconnect($myconfig);
1616 my $query = "SELECT 1 FROM defaults WHERE ? < closedto";
1617 my $sth = prepare_execute_query($self, $dbh, $query, $date);
1618 my ($closed) = $sth->fetchrow_array;
1620 $main::lxdebug->leave_sub();
1625 sub update_balance {
1626 $main::lxdebug->enter_sub();
1628 my ($self, $dbh, $table, $field, $where, $value, @values) = @_;
1630 # if we have a value, go do it
1633 # retrieve balance from table
1634 my $query = "SELECT $field FROM $table WHERE $where FOR UPDATE";
1635 my $sth = prepare_execute_query($self, $dbh, $query, @values);
1636 my ($balance) = $sth->fetchrow_array;
1642 $query = "UPDATE $table SET $field = $balance WHERE $where";
1643 do_query($self, $dbh, $query, @values);
1645 $main::lxdebug->leave_sub();
1648 sub update_exchangerate {
1649 $main::lxdebug->enter_sub();
1651 my ($self, $dbh, $curr, $transdate, $buy, $sell) = @_;
1653 # some sanity check for currency
1655 $main::lxdebug->leave_sub();
1658 $query = qq|SELECT curr FROM defaults|;
1660 my ($currency) = selectrow_query($self, $dbh, $query);
1661 my ($defaultcurrency) = split m/:/, $currency;
1664 if ($curr eq $defaultcurrency) {
1665 $main::lxdebug->leave_sub();
1669 $query = qq|SELECT e.curr FROM exchangerate e
1670 WHERE e.curr = ? AND e.transdate = ?
1672 my $sth = prepare_execute_query($self, $dbh, $query, $curr, $transdate);
1681 $buy = conv_i($buy, "NULL");
1682 $sell = conv_i($sell, "NULL");
1685 if ($buy != 0 && $sell != 0) {
1686 $set = "buy = $buy, sell = $sell";
1687 } elsif ($buy != 0) {
1688 $set = "buy = $buy";
1689 } elsif ($sell != 0) {
1690 $set = "sell = $sell";
1693 if ($sth->fetchrow_array) {
1694 $query = qq|UPDATE exchangerate
1700 $query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
1701 VALUES (?, $buy, $sell, ?)|;
1704 do_query($self, $dbh, $query, $curr, $transdate);
1706 $main::lxdebug->leave_sub();
1709 sub save_exchangerate {
1710 $main::lxdebug->enter_sub();
1712 my ($self, $myconfig, $currency, $transdate, $rate, $fld) = @_;
1714 my $dbh = $self->dbconnect($myconfig);
1718 $buy = $rate if $fld eq 'buy';
1719 $sell = $rate if $fld eq 'sell';
1722 $self->update_exchangerate($dbh, $currency, $transdate, $buy, $sell);
1727 $main::lxdebug->leave_sub();
1730 sub get_exchangerate {
1731 $main::lxdebug->enter_sub();
1733 my ($self, $dbh, $curr, $transdate, $fld) = @_;
1736 unless ($transdate) {
1737 $main::lxdebug->leave_sub();
1741 $query = qq|SELECT curr FROM defaults|;
1743 my ($currency) = selectrow_query($self, $dbh, $query);
1744 my ($defaultcurrency) = split m/:/, $currency;
1746 if ($currency eq $defaultcurrency) {
1747 $main::lxdebug->leave_sub();
1751 $query = qq|SELECT e.$fld FROM exchangerate e
1752 WHERE e.curr = ? AND e.transdate = ?|;
1753 my ($exchangerate) = selectrow_query($self, $dbh, $query, $curr, $transdate);
1757 $main::lxdebug->leave_sub();
1759 return $exchangerate;
1762 sub check_exchangerate {
1763 $main::lxdebug->enter_sub();
1765 my ($self, $myconfig, $currency, $transdate, $fld) = @_;
1767 if ($fld !~/^buy|sell$/) {
1768 $self->error('Fatal: check_exchangerate called with invalid buy/sell argument');
1771 unless ($transdate) {
1772 $main::lxdebug->leave_sub();
1776 my ($defaultcurrency) = $self->get_default_currency($myconfig);
1778 if ($currency eq $defaultcurrency) {
1779 $main::lxdebug->leave_sub();
1783 my $dbh = $self->get_standard_dbh($myconfig);
1784 my $query = qq|SELECT e.$fld FROM exchangerate e
1785 WHERE e.curr = ? AND e.transdate = ?|;
1787 my ($exchangerate) = selectrow_query($self, $dbh, $query, $currency, $transdate);
1789 $main::lxdebug->leave_sub();
1791 return $exchangerate;
1794 sub get_all_currencies {
1795 $main::lxdebug->enter_sub();
1798 my $myconfig = shift || \%::myconfig;
1799 my $dbh = $self->get_standard_dbh($myconfig);
1801 my $query = qq|SELECT curr FROM defaults|;
1803 my ($curr) = selectrow_query($self, $dbh, $query);
1804 my @currencies = grep { $_ } map { s/\s//g; $_ } split m/:/, $curr;
1806 $main::lxdebug->leave_sub();
1811 sub get_default_currency {
1812 $main::lxdebug->enter_sub();
1814 my ($self, $myconfig) = @_;
1815 my @currencies = $self->get_all_currencies($myconfig);
1817 $main::lxdebug->leave_sub();
1819 return $currencies[0];
1822 sub set_payment_options {
1823 $main::lxdebug->enter_sub();
1825 my ($self, $myconfig, $transdate) = @_;
1827 return $main::lxdebug->leave_sub() unless ($self->{payment_id});
1829 my $dbh = $self->get_standard_dbh($myconfig);
1832 qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, p.description_long | .
1833 qq|FROM payment_terms p | .
1836 ($self->{terms_netto}, $self->{terms_skonto}, $self->{percent_skonto},
1837 $self->{payment_terms}) =
1838 selectrow_query($self, $dbh, $query, $self->{payment_id});
1840 if ($transdate eq "") {
1841 if ($self->{invdate}) {
1842 $transdate = $self->{invdate};
1844 $transdate = $self->{transdate};
1849 qq|SELECT ?::date + ?::integer AS netto_date, ?::date + ?::integer AS skonto_date | .
1850 qq|FROM payment_terms|;
1851 ($self->{netto_date}, $self->{skonto_date}) =
1852 selectrow_query($self, $dbh, $query, $transdate, $self->{terms_netto}, $transdate, $self->{terms_skonto});
1854 my ($invtotal, $total);
1855 my (%amounts, %formatted_amounts);
1857 if ($self->{type} =~ /_order$/) {
1858 $amounts{invtotal} = $self->{ordtotal};
1859 $amounts{total} = $self->{ordtotal};
1861 } elsif ($self->{type} =~ /_quotation$/) {
1862 $amounts{invtotal} = $self->{quototal};
1863 $amounts{total} = $self->{quototal};
1866 $amounts{invtotal} = $self->{invtotal};
1867 $amounts{total} = $self->{total};
1869 $amounts{skonto_in_percent} = 100.0 * $self->{percent_skonto};
1871 map { $amounts{$_} = $self->parse_amount($myconfig, $amounts{$_}) } keys %amounts;
1873 $amounts{skonto_amount} = $amounts{invtotal} * $self->{percent_skonto};
1874 $amounts{invtotal_wo_skonto} = $amounts{invtotal} * (1 - $self->{percent_skonto});
1875 $amounts{total_wo_skonto} = $amounts{total} * (1 - $self->{percent_skonto});
1877 foreach (keys %amounts) {
1878 $amounts{$_} = $self->round_amount($amounts{$_}, 2);
1879 $formatted_amounts{$_} = $self->format_amount($myconfig, $amounts{$_}, 2);
1882 if ($self->{"language_id"}) {
1884 qq|SELECT t.description_long, l.output_numberformat, l.output_dateformat, l.output_longdates | .
1885 qq|FROM translation_payment_terms t | .
1886 qq|LEFT JOIN language l ON t.language_id = l.id | .
1887 qq|WHERE (t.language_id = ?) AND (t.payment_terms_id = ?)|;
1888 my ($description_long, $output_numberformat, $output_dateformat,
1889 $output_longdates) =
1890 selectrow_query($self, $dbh, $query,
1891 $self->{"language_id"}, $self->{"payment_id"});
1893 $self->{payment_terms} = $description_long if ($description_long);
1895 if ($output_dateformat) {
1896 foreach my $key (qw(netto_date skonto_date)) {
1898 $main::locale->reformat_date($myconfig, $self->{$key},
1904 if ($output_numberformat &&
1905 ($output_numberformat ne $myconfig->{"numberformat"})) {
1906 my $saved_numberformat = $myconfig->{"numberformat"};
1907 $myconfig->{"numberformat"} = $output_numberformat;
1908 map { $formatted_amounts{$_} = $self->format_amount($myconfig, $amounts{$_}) } keys %amounts;
1909 $myconfig->{"numberformat"} = $saved_numberformat;
1913 $self->{payment_terms} =~ s/<%netto_date%>/$self->{netto_date}/g;
1914 $self->{payment_terms} =~ s/<%skonto_date%>/$self->{skonto_date}/g;
1915 $self->{payment_terms} =~ s/<%currency%>/$self->{currency}/g;
1916 $self->{payment_terms} =~ s/<%terms_netto%>/$self->{terms_netto}/g;
1917 $self->{payment_terms} =~ s/<%account_number%>/$self->{account_number}/g;
1918 $self->{payment_terms} =~ s/<%bank%>/$self->{bank}/g;
1919 $self->{payment_terms} =~ s/<%bank_code%>/$self->{bank_code}/g;
1921 map { $self->{payment_terms} =~ s/<%${_}%>/$formatted_amounts{$_}/g; } keys %formatted_amounts;
1923 $self->{skonto_in_percent} = $formatted_amounts{skonto_in_percent};
1925 $main::lxdebug->leave_sub();
1929 sub get_template_language {
1930 $main::lxdebug->enter_sub();
1932 my ($self, $myconfig) = @_;
1934 my $template_code = "";
1936 if ($self->{language_id}) {
1937 my $dbh = $self->get_standard_dbh($myconfig);
1938 my $query = qq|SELECT template_code FROM language WHERE id = ?|;
1939 ($template_code) = selectrow_query($self, $dbh, $query, $self->{language_id});
1942 $main::lxdebug->leave_sub();
1944 return $template_code;
1947 sub get_printer_code {
1948 $main::lxdebug->enter_sub();
1950 my ($self, $myconfig) = @_;
1952 my $template_code = "";
1954 if ($self->{printer_id}) {
1955 my $dbh = $self->get_standard_dbh($myconfig);
1956 my $query = qq|SELECT template_code, printer_command FROM printers WHERE id = ?|;
1957 ($template_code, $self->{printer_command}) = selectrow_query($self, $dbh, $query, $self->{printer_id});
1960 $main::lxdebug->leave_sub();
1962 return $template_code;
1966 $main::lxdebug->enter_sub();
1968 my ($self, $myconfig) = @_;
1970 my $template_code = "";
1972 if ($self->{shipto_id}) {
1973 my $dbh = $self->get_standard_dbh($myconfig);
1974 my $query = qq|SELECT * FROM shipto WHERE shipto_id = ?|;
1975 my $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{shipto_id});
1976 map({ $self->{$_} = $ref->{$_} } keys(%$ref));
1979 $main::lxdebug->leave_sub();
1983 $main::lxdebug->enter_sub();
1985 my ($self, $dbh, $id, $module) = @_;
1990 foreach my $item (qw(name department_1 department_2 street zipcode city country
1991 contact phone fax email)) {
1992 if ($self->{"shipto$item"}) {
1993 $shipto = 1 if ($self->{$item} ne $self->{"shipto$item"});
1995 push(@values, $self->{"shipto${item}"});
1999 if ($self->{shipto_id}) {
2000 my $query = qq|UPDATE shipto set
2002 shiptodepartment_1 = ?,
2003 shiptodepartment_2 = ?,
2012 WHERE shipto_id = ?|;
2013 do_query($self, $dbh, $query, @values, $self->{shipto_id});
2015 my $query = qq|SELECT * FROM shipto
2016 WHERE shiptoname = ? AND
2017 shiptodepartment_1 = ? AND
2018 shiptodepartment_2 = ? AND
2019 shiptostreet = ? AND
2020 shiptozipcode = ? AND
2022 shiptocountry = ? AND
2023 shiptocontact = ? AND
2029 my $insert_check = selectfirst_hashref_query($self, $dbh, $query, @values, $module, $id);
2032 qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2,
2033 shiptostreet, shiptozipcode, shiptocity, shiptocountry,
2034 shiptocontact, shiptophone, shiptofax, shiptoemail, module)
2035 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
2036 do_query($self, $dbh, $query, $id, @values, $module);
2041 $main::lxdebug->leave_sub();
2045 $main::lxdebug->enter_sub();
2047 my ($self, $dbh) = @_;
2049 $dbh ||= $self->get_standard_dbh(\%main::myconfig);
2051 my $query = qq|SELECT id, name FROM employee WHERE login = ?|;
2052 ($self->{"employee_id"}, $self->{"employee"}) = selectrow_query($self, $dbh, $query, $self->{login});
2053 $self->{"employee_id"} *= 1;
2055 $main::lxdebug->leave_sub();
2058 sub get_employee_data {
2059 $main::lxdebug->enter_sub();
2064 Common::check_params(\%params, qw(prefix));
2065 Common::check_params_x(\%params, qw(id));
2068 $main::lxdebug->leave_sub();
2072 my $myconfig = \%main::myconfig;
2073 my $dbh = $params{dbh} || $self->get_standard_dbh($myconfig);
2075 my ($login) = selectrow_query($self, $dbh, qq|SELECT login FROM employee WHERE id = ?|, conv_i($params{id}));
2078 my $user = User->new($login);
2079 map { $self->{$params{prefix} . "_${_}"} = $user->{$_}; } qw(address businessnumber co_ustid company duns email fax name signature taxnumber tel);
2081 $self->{$params{prefix} . '_login'} = $login;
2082 $self->{$params{prefix} . '_name'} ||= $login;
2085 $main::lxdebug->leave_sub();
2089 $main::lxdebug->enter_sub();
2091 my ($self, $myconfig, $reference_date) = @_;
2093 $reference_date = $reference_date ? conv_dateq($reference_date) . '::DATE' : 'current_date';
2095 my $dbh = $self->get_standard_dbh($myconfig);
2096 my $query = qq|SELECT ${reference_date} + terms_netto FROM payment_terms WHERE id = ?|;
2097 my ($duedate) = selectrow_query($self, $dbh, $query, $self->{payment_id});
2099 $main::lxdebug->leave_sub();
2105 $main::lxdebug->enter_sub();
2107 my ($self, $dbh, $id, $key) = @_;
2109 $key = "all_contacts" unless ($key);
2113 $main::lxdebug->leave_sub();
2118 qq|SELECT cp_id, cp_cv_id, cp_name, cp_givenname, cp_abteilung | .
2119 qq|FROM contacts | .
2120 qq|WHERE cp_cv_id = ? | .
2121 qq|ORDER BY lower(cp_name)|;
2123 $self->{$key} = selectall_hashref_query($self, $dbh, $query, $id);
2125 $main::lxdebug->leave_sub();
2129 $main::lxdebug->enter_sub();
2131 my ($self, $dbh, $key) = @_;
2133 my ($all, $old_id, $where, @values);
2135 if (ref($key) eq "HASH") {
2138 $key = "ALL_PROJECTS";
2140 foreach my $p (keys(%{$params})) {
2142 $all = $params->{$p};
2143 } elsif ($p eq "old_id") {
2144 $old_id = $params->{$p};
2145 } elsif ($p eq "key") {
2146 $key = $params->{$p};
2152 $where = "WHERE active ";
2154 if (ref($old_id) eq "ARRAY") {
2155 my @ids = grep({ $_ } @{$old_id});
2157 $where .= " OR id IN (" . join(",", map({ "?" } @ids)) . ") ";
2158 push(@values, @ids);
2161 $where .= " OR (id = ?) ";
2162 push(@values, $old_id);
2168 qq|SELECT id, projectnumber, description, active | .
2171 qq|ORDER BY lower(projectnumber)|;
2173 $self->{$key} = selectall_hashref_query($self, $dbh, $query, @values);
2175 $main::lxdebug->leave_sub();
2179 $main::lxdebug->enter_sub();
2181 my ($self, $dbh, $vc_id, $key) = @_;
2183 $key = "all_shipto" unless ($key);
2186 # get shipping addresses
2187 my $query = qq|SELECT * FROM shipto WHERE trans_id = ?|;
2189 $self->{$key} = selectall_hashref_query($self, $dbh, $query, $vc_id);
2195 $main::lxdebug->leave_sub();
2199 $main::lxdebug->enter_sub();
2201 my ($self, $dbh, $key) = @_;
2203 $key = "all_printers" unless ($key);
2205 my $query = qq|SELECT id, printer_description, printer_command, template_code FROM printers|;
2207 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2209 $main::lxdebug->leave_sub();
2213 $main::lxdebug->enter_sub();
2215 my ($self, $dbh, $params) = @_;
2218 $key = $params->{key};
2219 $key = "all_charts" unless ($key);
2221 my $transdate = quote_db_date($params->{transdate});
2224 qq|SELECT c.id, c.accno, c.description, c.link, c.charttype, tk.taxkey_id, tk.tax_id | .
2226 qq|LEFT JOIN taxkeys tk ON | .
2227 qq|(tk.id = (SELECT id FROM taxkeys | .
2228 qq| WHERE taxkeys.chart_id = c.id AND startdate <= $transdate | .
2229 qq| ORDER BY startdate DESC LIMIT 1)) | .
2230 qq|ORDER BY c.accno|;
2232 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2234 $main::lxdebug->leave_sub();
2237 sub _get_taxcharts {
2238 $main::lxdebug->enter_sub();
2240 my ($self, $dbh, $params) = @_;
2242 my $key = "all_taxcharts";
2245 if (ref $params eq 'HASH') {
2246 $key = $params->{key} if ($params->{key});
2247 if ($params->{module} eq 'AR') {
2248 push @where, 'taxkey NOT IN (8, 9, 18, 19)';
2250 } elsif ($params->{module} eq 'AP') {
2251 push @where, 'taxkey NOT IN (1, 2, 3, 12, 13)';
2258 my $where = ' WHERE ' . join(' AND ', map { "($_)" } @where) if (@where);
2260 my $query = qq|SELECT * FROM tax $where ORDER BY taxkey|;
2262 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2264 $main::lxdebug->leave_sub();
2268 $main::lxdebug->enter_sub();
2270 my ($self, $dbh, $key) = @_;
2272 $key = "all_taxzones" unless ($key);
2274 my $query = qq|SELECT * FROM tax_zones ORDER BY id|;
2276 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2278 $main::lxdebug->leave_sub();
2281 sub _get_employees {
2282 $main::lxdebug->enter_sub();
2284 my ($self, $dbh, $default_key, $key) = @_;
2286 $key = $default_key unless ($key);
2287 $self->{$key} = selectall_hashref_query($self, $dbh, qq|SELECT * FROM employee ORDER BY lower(name)|);
2289 $main::lxdebug->leave_sub();
2292 sub _get_business_types {
2293 $main::lxdebug->enter_sub();
2295 my ($self, $dbh, $key) = @_;
2297 my $options = ref $key eq 'HASH' ? $key : { key => $key };
2298 $options->{key} ||= "all_business_types";
2301 if (exists $options->{salesman}) {
2302 $where = 'WHERE ' . ($options->{salesman} ? '' : 'NOT ') . 'COALESCE(salesman)';
2305 $self->{ $options->{key} } = selectall_hashref_query($self, $dbh, qq|SELECT * FROM business $where ORDER BY lower(description)|);
2307 $main::lxdebug->leave_sub();
2310 sub _get_languages {
2311 $main::lxdebug->enter_sub();
2313 my ($self, $dbh, $key) = @_;
2315 $key = "all_languages" unless ($key);
2317 my $query = qq|SELECT * FROM language ORDER BY id|;
2319 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2321 $main::lxdebug->leave_sub();
2324 sub _get_dunning_configs {
2325 $main::lxdebug->enter_sub();
2327 my ($self, $dbh, $key) = @_;
2329 $key = "all_dunning_configs" unless ($key);
2331 my $query = qq|SELECT * FROM dunning_config ORDER BY dunning_level|;
2333 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2335 $main::lxdebug->leave_sub();
2338 sub _get_currencies {
2339 $main::lxdebug->enter_sub();
2341 my ($self, $dbh, $key) = @_;
2343 $key = "all_currencies" unless ($key);
2345 my $query = qq|SELECT curr AS currency FROM defaults|;
2347 $self->{$key} = [split(/\:/ , selectfirst_hashref_query($self, $dbh, $query)->{currency})];
2349 $main::lxdebug->leave_sub();
2353 $main::lxdebug->enter_sub();
2355 my ($self, $dbh, $key) = @_;
2357 $key = "all_payments" unless ($key);
2359 my $query = qq|SELECT * FROM payment_terms ORDER BY id|;
2361 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2363 $main::lxdebug->leave_sub();
2366 sub _get_customers {
2367 $main::lxdebug->enter_sub();
2369 my ($self, $dbh, $key) = @_;
2371 my $options = ref $key eq 'HASH' ? $key : { key => $key };
2372 $options->{key} ||= "all_customers";
2373 my $limit_clause = "LIMIT $options->{limit}" if $options->{limit};
2376 push @where, qq|business_id IN (SELECT id FROM business WHERE salesman)| if $options->{business_is_salesman};
2377 push @where, qq|NOT obsolete| if !$options->{with_obsolete};
2378 my $where_str = @where ? "WHERE " . join(" AND ", map { "($_)" } @where) : '';
2380 my $query = qq|SELECT * FROM customer $where_str ORDER BY name $limit_clause|;
2381 $self->{ $options->{key} } = selectall_hashref_query($self, $dbh, $query);
2383 $main::lxdebug->leave_sub();
2387 $main::lxdebug->enter_sub();
2389 my ($self, $dbh, $key) = @_;
2391 $key = "all_vendors" unless ($key);
2393 my $query = qq|SELECT * FROM vendor WHERE NOT obsolete ORDER BY name|;
2395 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2397 $main::lxdebug->leave_sub();
2400 sub _get_departments {
2401 $main::lxdebug->enter_sub();
2403 my ($self, $dbh, $key) = @_;
2405 $key = "all_departments" unless ($key);
2407 my $query = qq|SELECT * FROM department ORDER BY description|;
2409 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2411 $main::lxdebug->leave_sub();
2414 sub _get_warehouses {
2415 $main::lxdebug->enter_sub();
2417 my ($self, $dbh, $param) = @_;
2419 my ($key, $bins_key);
2421 if ('' eq ref $param) {
2425 $key = $param->{key};
2426 $bins_key = $param->{bins};
2429 my $query = qq|SELECT w.* FROM warehouse w
2430 WHERE (NOT w.invalid) AND
2431 ((SELECT COUNT(b.*) FROM bin b WHERE b.warehouse_id = w.id) > 0)
2432 ORDER BY w.sortkey|;
2434 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2437 $query = qq|SELECT id, description FROM bin WHERE warehouse_id = ?|;
2438 my $sth = prepare_query($self, $dbh, $query);
2440 foreach my $warehouse (@{ $self->{$key} }) {
2441 do_statement($self, $sth, $query, $warehouse->{id});
2442 $warehouse->{$bins_key} = [];
2444 while (my $ref = $sth->fetchrow_hashref()) {
2445 push @{ $warehouse->{$bins_key} }, $ref;
2451 $main::lxdebug->leave_sub();
2455 $main::lxdebug->enter_sub();
2457 my ($self, $dbh, $table, $key, $sortkey) = @_;
2459 my $query = qq|SELECT * FROM $table|;
2460 $query .= qq| ORDER BY $sortkey| if ($sortkey);
2462 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2464 $main::lxdebug->leave_sub();
2468 # $main::lxdebug->enter_sub();
2470 # my ($self, $dbh, $key) = @_;
2472 # $key ||= "all_groups";
2474 # my $groups = $main::auth->read_groups();
2476 # $self->{$key} = selectall_hashref_query($self, $dbh, $query);
2478 # $main::lxdebug->leave_sub();
2482 $main::lxdebug->enter_sub();
2487 my $dbh = $self->get_standard_dbh(\%main::myconfig);
2488 my ($sth, $query, $ref);
2490 my $vc = $self->{"vc"} eq "customer" ? "customer" : "vendor";
2491 my $vc_id = $self->{"${vc}_id"};
2493 if ($params{"contacts"}) {
2494 $self->_get_contacts($dbh, $vc_id, $params{"contacts"});
2497 if ($params{"shipto"}) {
2498 $self->_get_shipto($dbh, $vc_id, $params{"shipto"});
2501 if ($params{"projects"} || $params{"all_projects"}) {
2502 $self->_get_projects($dbh, $params{"all_projects"} ?
2503 $params{"all_projects"} : $params{"projects"},
2504 $params{"all_projects"} ? 1 : 0);
2507 if ($params{"printers"}) {
2508 $self->_get_printers($dbh, $params{"printers"});
2511 if ($params{"languages"}) {
2512 $self->_get_languages($dbh, $params{"languages"});
2515 if ($params{"charts"}) {
2516 $self->_get_charts($dbh, $params{"charts"});
2519 if ($params{"taxcharts"}) {
2520 $self->_get_taxcharts($dbh, $params{"taxcharts"});
2523 if ($params{"taxzones"}) {
2524 $self->_get_taxzones($dbh, $params{"taxzones"});
2527 if ($params{"employees"}) {
2528 $self->_get_employees($dbh, "all_employees", $params{"employees"});
2531 if ($params{"salesmen"}) {
2532 $self->_get_employees($dbh, "all_salesmen", $params{"salesmen"});
2535 if ($params{"business_types"}) {
2536 $self->_get_business_types($dbh, $params{"business_types"});
2539 if ($params{"dunning_configs"}) {
2540 $self->_get_dunning_configs($dbh, $params{"dunning_configs"});
2543 if($params{"currencies"}) {
2544 $self->_get_currencies($dbh, $params{"currencies"});
2547 if($params{"customers"}) {
2548 $self->_get_customers($dbh, $params{"customers"});
2551 if($params{"vendors"}) {
2552 if (ref $params{"vendors"} eq 'HASH') {
2553 $self->_get_vendors($dbh, $params{"vendors"}{key}, $params{"vendors"}{limit});
2555 $self->_get_vendors($dbh, $params{"vendors"});
2559 if($params{"payments"}) {
2560 $self->_get_payments($dbh, $params{"payments"});
2563 if($params{"departments"}) {
2564 $self->_get_departments($dbh, $params{"departments"});
2567 if ($params{price_factors}) {
2568 $self->_get_simple($dbh, 'price_factors', $params{price_factors}, 'sortkey');
2571 if ($params{warehouses}) {
2572 $self->_get_warehouses($dbh, $params{warehouses});
2575 # if ($params{groups}) {
2576 # $self->_get_groups($dbh, $params{groups});
2579 if ($params{partsgroup}) {
2580 $self->get_partsgroup(\%main::myconfig, { all => 1, target => $params{partsgroup} });
2583 $main::lxdebug->leave_sub();
2586 # this sub gets the id and name from $table
2588 $main::lxdebug->enter_sub();
2590 my ($self, $myconfig, $table) = @_;
2592 # connect to database
2593 my $dbh = $self->get_standard_dbh($myconfig);
2595 $table = $table eq "customer" ? "customer" : "vendor";
2596 my $arap = $self->{arap} eq "ar" ? "ar" : "ap";
2598 my ($query, @values);
2600 if (!$self->{openinvoices}) {
2602 if ($self->{customernumber} ne "") {
2603 $where = qq|(vc.customernumber ILIKE ?)|;
2604 push(@values, '%' . $self->{customernumber} . '%');
2606 $where = qq|(vc.name ILIKE ?)|;
2607 push(@values, '%' . $self->{$table} . '%');
2611 qq~SELECT vc.id, vc.name,
2612 vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
2614 WHERE $where AND (NOT vc.obsolete)
2618 qq~SELECT DISTINCT vc.id, vc.name,
2619 vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
2621 JOIN $table vc ON (a.${table}_id = vc.id)
2622 WHERE NOT (a.amount = a.paid) AND (vc.name ILIKE ?)
2624 push(@values, '%' . $self->{$table} . '%');
2627 $self->{name_list} = selectall_hashref_query($self, $dbh, $query, @values);
2629 $main::lxdebug->leave_sub();
2631 return scalar(@{ $self->{name_list} });
2634 # the selection sub is used in the AR, AP, IS, IR and OE module
2637 $main::lxdebug->enter_sub();
2639 my ($self, $myconfig, $table, $module) = @_;
2642 my $dbh = $self->get_standard_dbh;
2644 $table = $table eq "customer" ? "customer" : "vendor";
2646 my $query = qq|SELECT count(*) FROM $table|;
2647 my ($count) = selectrow_query($self, $dbh, $query);
2649 # build selection list
2650 if ($count <= $myconfig->{vclimit}) {
2651 $query = qq|SELECT id, name, salesman_id
2652 FROM $table WHERE NOT obsolete
2654 $self->{"all_$table"} = selectall_hashref_query($self, $dbh, $query);
2658 $self->get_employee($dbh);
2660 # setup sales contacts
2661 $query = qq|SELECT e.id, e.name
2663 WHERE (e.sales = '1') AND (NOT e.id = ?)|;
2664 $self->{all_employees} = selectall_hashref_query($self, $dbh, $query, $self->{employee_id});
2667 push(@{ $self->{all_employees} },
2668 { id => $self->{employee_id},
2669 name => $self->{employee} });
2671 # sort the whole thing
2672 @{ $self->{all_employees} } =
2673 sort { $a->{name} cmp $b->{name} } @{ $self->{all_employees} };
2675 if ($module eq 'AR') {
2677 # prepare query for departments
2678 $query = qq|SELECT id, description
2681 ORDER BY description|;
2684 $query = qq|SELECT id, description
2686 ORDER BY description|;
2689 $self->{all_departments} = selectall_hashref_query($self, $dbh, $query);
2692 $query = qq|SELECT id, description
2696 $self->{languages} = selectall_hashref_query($self, $dbh, $query);
2699 $query = qq|SELECT printer_description, id
2701 ORDER BY printer_description|;
2703 $self->{printers} = selectall_hashref_query($self, $dbh, $query);
2706 $query = qq|SELECT id, description
2710 $self->{payment_terms} = selectall_hashref_query($self, $dbh, $query);
2712 $main::lxdebug->leave_sub();
2715 sub language_payment {
2716 $main::lxdebug->enter_sub();
2718 my ($self, $myconfig) = @_;
2720 my $dbh = $self->get_standard_dbh($myconfig);
2722 my $query = qq|SELECT id, description
2726 $self->{languages} = selectall_hashref_query($self, $dbh, $query);
2729 $query = qq|SELECT printer_description, id
2731 ORDER BY printer_description|;
2733 $self->{printers} = selectall_hashref_query($self, $dbh, $query);
2736 $query = qq|SELECT id, description
2740 $self->{payment_terms} = selectall_hashref_query($self, $dbh, $query);
2742 # get buchungsgruppen
2743 $query = qq|SELECT id, description
2744 FROM buchungsgruppen|;
2746 $self->{BUCHUNGSGRUPPEN} = selectall_hashref_query($self, $dbh, $query);
2748 $main::lxdebug->leave_sub();
2751 # this is only used for reports
2752 sub all_departments {
2753 $main::lxdebug->enter_sub();
2755 my ($self, $myconfig, $table) = @_;
2757 my $dbh = $self->get_standard_dbh($myconfig);
2760 if ($table eq 'customer') {
2761 $where = "WHERE role = 'P' ";
2764 my $query = qq|SELECT id, description
2767 ORDER BY description|;
2768 $self->{all_departments} = selectall_hashref_query($self, $dbh, $query);
2770 delete($self->{all_departments}) unless (@{ $self->{all_departments} || [] });
2772 $main::lxdebug->leave_sub();
2776 $main::lxdebug->enter_sub();
2778 my ($self, $module, $myconfig, $table, $provided_dbh) = @_;
2781 if ($table eq "customer") {
2790 $self->all_vc($myconfig, $table, $module);
2792 # get last customers or vendors
2793 my ($query, $sth, $ref);
2795 my $dbh = $provided_dbh ? $provided_dbh : $self->get_standard_dbh($myconfig);
2800 my $transdate = "current_date";
2801 if ($self->{transdate}) {
2802 $transdate = $dbh->quote($self->{transdate});
2805 # now get the account numbers
2806 $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
2807 FROM chart c, taxkeys tk
2808 WHERE (c.link LIKE ?) AND (c.id = tk.chart_id) AND tk.id =
2809 (SELECT id FROM taxkeys WHERE (taxkeys.chart_id = c.id) AND (startdate <= $transdate) ORDER BY startdate DESC LIMIT 1)
2812 $sth = $dbh->prepare($query);
2814 do_statement($self, $sth, $query, '%' . $module . '%');
2816 $self->{accounts} = "";
2817 while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
2819 foreach my $key (split(/:/, $ref->{link})) {
2820 if ($key =~ /\Q$module\E/) {
2822 # cross reference for keys
2823 $xkeyref{ $ref->{accno} } = $key;
2825 push @{ $self->{"${module}_links"}{$key} },
2826 { accno => $ref->{accno},
2827 description => $ref->{description},
2828 taxkey => $ref->{taxkey_id},
2829 tax_id => $ref->{tax_id} };
2831 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2837 # get taxkeys and description
2838 $query = qq|SELECT id, taxkey, taxdescription FROM tax|;
2839 $self->{TAXKEY} = selectall_hashref_query($self, $dbh, $query);
2841 if (($module eq "AP") || ($module eq "AR")) {
2842 # get tax rates and description
2843 $query = qq|SELECT * FROM tax|;
2844 $self->{TAX} = selectall_hashref_query($self, $dbh, $query);
2850 a.cp_id, a.invnumber, a.transdate, a.${table}_id, a.datepaid,
2851 a.duedate, a.ordnumber, a.taxincluded, a.curr AS currency, a.notes,
2852 a.intnotes, a.department_id, a.amount AS oldinvtotal,
2853 a.paid AS oldtotalpaid, a.employee_id, a.gldate, a.type,
2855 d.description AS department,
2858 JOIN $table c ON (a.${table}_id = c.id)
2859 LEFT JOIN employee e ON (e.id = a.employee_id)
2860 LEFT JOIN department d ON (d.id = a.department_id)
2862 $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{id});
2864 foreach my $key (keys %$ref) {
2865 $self->{$key} = $ref->{$key};
2868 my $transdate = "current_date";
2869 if ($self->{transdate}) {
2870 $transdate = $dbh->quote($self->{transdate});
2873 # now get the account numbers
2874 $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
2876 LEFT JOIN taxkeys tk ON (tk.chart_id = c.id)
2878 AND (tk.id = (SELECT id FROM taxkeys WHERE taxkeys.chart_id = c.id AND startdate <= $transdate ORDER BY startdate DESC LIMIT 1)
2879 OR c.link LIKE '%_tax%' OR c.taxkey_id IS NULL)
2882 $sth = $dbh->prepare($query);
2883 do_statement($self, $sth, $query, "%$module%");
2885 $self->{accounts} = "";
2886 while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
2888 foreach my $key (split(/:/, $ref->{link})) {
2889 if ($key =~ /\Q$module\E/) {
2891 # cross reference for keys
2892 $xkeyref{ $ref->{accno} } = $key;
2894 push @{ $self->{"${module}_links"}{$key} },
2895 { accno => $ref->{accno},
2896 description => $ref->{description},
2897 taxkey => $ref->{taxkey_id},
2898 tax_id => $ref->{tax_id} };
2900 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2906 # get amounts from individual entries
2909 c.accno, c.description,
2910 a.source, a.amount, a.memo, a.transdate, a.cleared, a.project_id, a.taxkey,
2914 LEFT JOIN chart c ON (c.id = a.chart_id)
2915 LEFT JOIN project p ON (p.id = a.project_id)
2916 LEFT JOIN tax t ON (t.id= (SELECT tk.tax_id FROM taxkeys tk
2917 WHERE (tk.taxkey_id=a.taxkey) AND
2918 ((CASE WHEN a.chart_id IN (SELECT chart_id FROM taxkeys WHERE taxkey_id = a.taxkey)
2919 THEN tk.chart_id = a.chart_id
2922 OR (c.link='%tax%')) AND
2923 (startdate <= a.transdate) ORDER BY startdate DESC LIMIT 1))
2924 WHERE a.trans_id = ?
2925 AND a.fx_transaction = '0'
2926 ORDER BY a.acc_trans_id, a.transdate|;
2927 $sth = $dbh->prepare($query);
2928 do_statement($self, $sth, $query, $self->{id});
2930 # get exchangerate for currency
2931 $self->{exchangerate} =
2932 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate}, $fld);
2935 # store amounts in {acc_trans}{$key} for multiple accounts
2936 while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
2937 $ref->{exchangerate} =
2938 $self->get_exchangerate($dbh, $self->{currency}, $ref->{transdate}, $fld);
2939 if (!($xkeyref{ $ref->{accno} } =~ /tax/)) {
2942 if (($xkeyref{ $ref->{accno} } =~ /paid/) && ($self->{type} eq "credit_note")) {
2943 $ref->{amount} *= -1;
2945 $ref->{index} = $index;
2947 push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref;
2953 d.curr AS currencies, d.closedto, d.revtrans,
2954 (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2955 (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2957 $ref = selectfirst_hashref_query($self, $dbh, $query);
2958 map { $self->{$_} = $ref->{$_} } keys %$ref;
2965 current_date AS transdate, d.curr AS currencies, d.closedto, d.revtrans,
2966 (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2967 (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2969 $ref = selectfirst_hashref_query($self, $dbh, $query);
2970 map { $self->{$_} = $ref->{$_} } keys %$ref;
2972 if ($self->{"$self->{vc}_id"}) {
2974 # only setup currency
2975 ($self->{currency}) = split(/:/, $self->{currencies});
2979 $self->lastname_used($dbh, $myconfig, $table, $module);
2981 # get exchangerate for currency
2982 $self->{exchangerate} =
2983 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate}, $fld);
2989 $main::lxdebug->leave_sub();
2993 $main::lxdebug->enter_sub();
2995 my ($self, $dbh, $myconfig, $table, $module) = @_;
2999 $table = $table eq "customer" ? "customer" : "vendor";
3000 my %column_map = ("a.curr" => "currency",
3001 "a.${table}_id" => "${table}_id",
3002 "a.department_id" => "department_id",
3003 "d.description" => "department",
3004 "ct.name" => $table,
3005 "current_date + ct.terms" => "duedate",
3008 if ($self->{type} =~ /delivery_order/) {
3009 $arap = 'delivery_orders';
3010 delete $column_map{"a.curr"};
3012 } elsif ($self->{type} =~ /_order/) {
3014 $where = "quotation = '0'";
3016 } elsif ($self->{type} =~ /_quotation/) {
3018 $where = "quotation = '1'";
3020 } elsif ($table eq 'customer') {
3028 $where = "($where) AND" if ($where);
3029 my $query = qq|SELECT MAX(id) FROM $arap
3030 WHERE $where ${table}_id > 0|;
3031 my ($trans_id) = selectrow_query($self, $dbh, $query);
3034 my $column_spec = join(', ', map { "${_} AS $column_map{$_}" } keys %column_map);
3035 $query = qq|SELECT $column_spec
3037 LEFT JOIN $table ct ON (a.${table}_id = ct.id)
3038 LEFT JOIN department d ON (a.department_id = d.id)
3040 my $ref = selectfirst_hashref_query($self, $dbh, $query, $trans_id);
3042 map { $self->{$_} = $ref->{$_} } values %column_map;
3044 $main::lxdebug->leave_sub();
3048 $main::lxdebug->enter_sub();
3051 my $myconfig = shift || \%::myconfig;
3052 my ($thisdate, $days) = @_;
3054 my $dbh = $self->get_standard_dbh($myconfig);
3059 my $dateformat = $myconfig->{dateformat};
3060 $dateformat .= "yy" if $myconfig->{dateformat} !~ /^y/;
3061 $thisdate = $dbh->quote($thisdate);
3062 $query = qq|SELECT to_date($thisdate, '$dateformat') + $days AS thisdate|;
3064 $query = qq|SELECT current_date AS thisdate|;
3067 ($thisdate) = selectrow_query($self, $dbh, $query);
3069 $main::lxdebug->leave_sub();
3075 $main::lxdebug->enter_sub();
3077 my ($self, $string) = @_;
3079 if ($string !~ /%/) {
3080 $string = "%$string%";
3083 $string =~ s/\'/\'\'/g;
3085 $main::lxdebug->leave_sub();
3091 $main::lxdebug->enter_sub();
3093 my ($self, $flds, $new, $count, $numrows) = @_;
3097 map { push @ndx, { num => $new->[$_ - 1]->{runningnumber}, ndx => $_ } } 1 .. $count;
3102 foreach my $item (sort { $a->{num} <=> $b->{num} } @ndx) {
3104 my $j = $item->{ndx} - 1;
3105 map { $self->{"${_}_$i"} = $new->[$j]->{$_} } @{$flds};
3109 for $i ($count + 1 .. $numrows) {
3110 map { delete $self->{"${_}_$i"} } @{$flds};
3113 $main::lxdebug->leave_sub();
3117 $main::lxdebug->enter_sub();
3119 my ($self, $myconfig) = @_;
3123 my $dbh = $self->dbconnect_noauto($myconfig);
3125 my $query = qq|DELETE FROM status
3126 WHERE (formname = ?) AND (trans_id = ?)|;
3127 my $sth = prepare_query($self, $dbh, $query);
3129 if ($self->{formname} =~ /(check|receipt)/) {
3130 for $i (1 .. $self->{rowcount}) {
3131 do_statement($self, $sth, $query, $self->{formname}, $self->{"id_$i"} * 1);
3134 do_statement($self, $sth, $query, $self->{formname}, $self->{id});
3138 my $printed = ($self->{printed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3139 my $emailed = ($self->{emailed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3141 my %queued = split / /, $self->{queued};
3144 if ($self->{formname} =~ /(check|receipt)/) {
3146 # this is a check or receipt, add one entry for each lineitem
3147 my ($accno) = split /--/, $self->{account};
3148 $query = qq|INSERT INTO status (trans_id, printed, spoolfile, formname, chart_id)
3149 VALUES (?, ?, ?, ?, (SELECT c.id FROM chart c WHERE c.accno = ?))|;
3150 @values = ($printed, $queued{$self->{formname}}, $self->{prinform}, $accno);
3151 $sth = prepare_query($self, $dbh, $query);
3153 for $i (1 .. $self->{rowcount}) {
3154 if ($self->{"checked_$i"}) {
3155 do_statement($self, $sth, $query, $self->{"id_$i"}, @values);
3161 $query = qq|INSERT INTO status (trans_id, printed, emailed, spoolfile, formname)
3162 VALUES (?, ?, ?, ?, ?)|;
3163 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed,
3164 $queued{$self->{formname}}, $self->{formname});
3170 $main::lxdebug->leave_sub();
3174 $main::lxdebug->enter_sub();
3176 my ($self, $dbh) = @_;
3178 my ($query, $printed, $emailed);
3180 my $formnames = $self->{printed};
3181 my $emailforms = $self->{emailed};
3183 $query = qq|DELETE FROM status
3184 WHERE (formname = ?) AND (trans_id = ?)|;
3185 do_query($self, $dbh, $query, $self->{formname}, $self->{id});
3187 # this only applies to the forms
3188 # checks and receipts are posted when printed or queued
3190 if ($self->{queued}) {
3191 my %queued = split / /, $self->{queued};
3193 foreach my $formname (keys %queued) {
3194 $printed = ($self->{printed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3195 $emailed = ($self->{emailed} =~ /\Q$self->{formname}\E/) ? "1" : "0";
3197 $query = qq|INSERT INTO status (trans_id, printed, emailed, spoolfile, formname)
3198 VALUES (?, ?, ?, ?, ?)|;
3199 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed, $queued{$formname}, $formname);
3201 $formnames =~ s/\Q$self->{formname}\E//;
3202 $emailforms =~ s/\Q$self->{formname}\E//;
3207 # save printed, emailed info
3208 $formnames =~ s/^ +//g;
3209 $emailforms =~ s/^ +//g;
3212 map { $status{$_}{printed} = 1 } split / +/, $formnames;
3213 map { $status{$_}{emailed} = 1 } split / +/, $emailforms;
3215 foreach my $formname (keys %status) {
3216 $printed = ($formnames =~ /\Q$self->{formname}\E/) ? "1" : "0";
3217 $emailed = ($emailforms =~ /\Q$self->{formname}\E/) ? "1" : "0";
3219 $query = qq|INSERT INTO status (trans_id, printed, emailed, formname)
3220 VALUES (?, ?, ?, ?)|;
3221 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed, $formname);
3224 $main::lxdebug->leave_sub();
3228 # $main::locale->text('SAVED')
3229 # $main::locale->text('DELETED')
3230 # $main::locale->text('ADDED')
3231 # $main::locale->text('PAYMENT POSTED')
3232 # $main::locale->text('POSTED')
3233 # $main::locale->text('POSTED AS NEW')
3234 # $main::locale->text('ELSE')
3235 # $main::locale->text('SAVED FOR DUNNING')
3236 # $main::locale->text('DUNNING STARTED')
3237 # $main::locale->text('PRINTED')
3238 # $main::locale->text('MAILED')
3239 # $main::locale->text('SCREENED')
3240 # $main::locale->text('CANCELED')
3241 # $main::locale->text('invoice')
3242 # $main::locale->text('proforma')
3243 # $main::locale->text('sales_order')
3244 # $main::locale->text('packing_list')
3245 # $main::locale->text('pick_list')
3246 # $main::locale->text('purchase_order')
3247 # $main::locale->text('bin_list')
3248 # $main::locale->text('sales_quotation')
3249 # $main::locale->text('request_quotation')
3252 $main::lxdebug->enter_sub();
3255 my $dbh = shift || $self->get_standard_dbh;
3257 if(!exists $self->{employee_id}) {
3258 &get_employee($self, $dbh);
3262 qq|INSERT INTO history_erp (trans_id, employee_id, addition, what_done, snumbers) | .
3263 qq|VALUES (?, (SELECT id FROM employee WHERE login = ?), ?, ?, ?)|;
3264 my @values = (conv_i($self->{id}), $self->{login},
3265 $self->{addition}, $self->{what_done}, "$self->{snumbers}");
3266 do_query($self, $dbh, $query, @values);
3270 $main::lxdebug->leave_sub();
3274 $main::lxdebug->enter_sub();
3276 my ($self, $dbh, $trans_id, $restriction, $order) = @_;
3277 my ($orderBy, $desc) = split(/\-\-/, $order);
3278 $order = " ORDER BY " . ($order eq "" ? " h.itime " : ($desc == 1 ? $orderBy . " DESC " : $orderBy . " "));
3281 if ($trans_id ne "") {
3283 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 | .
3284 qq|FROM history_erp h | .
3285 qq|LEFT JOIN employee emp ON (emp.id = h.employee_id) | .
3286 qq|WHERE (trans_id = | . $trans_id . qq|) $restriction | .
3289 my $sth = $dbh->prepare($query) || $self->dberror($query);
3291 $sth->execute() || $self->dberror("$query");
3293 while(my $hash_ref = $sth->fetchrow_hashref()) {
3294 $hash_ref->{addition} = $main::locale->text($hash_ref->{addition});
3295 $hash_ref->{what_done} = $main::locale->text($hash_ref->{what_done});
3296 $hash_ref->{snumbers} =~ s/^.+_(.*)$/$1/g;
3297 $tempArray[$i++] = $hash_ref;
3299 $main::lxdebug->leave_sub() and return \@tempArray
3300 if ($i > 0 && $tempArray[0] ne "");
3302 $main::lxdebug->leave_sub();
3306 sub update_defaults {
3307 $main::lxdebug->enter_sub();
3309 my ($self, $myconfig, $fld, $provided_dbh) = @_;
3312 if ($provided_dbh) {
3313 $dbh = $provided_dbh;
3315 $dbh = $self->dbconnect_noauto($myconfig);
3317 my $query = qq|SELECT $fld FROM defaults FOR UPDATE|;
3318 my $sth = $dbh->prepare($query);
3320 $sth->execute || $self->dberror($query);
3321 my ($var) = $sth->fetchrow_array;
3324 if ($var =~ m/\d+$/) {
3325 my $new_var = (substr $var, $-[0]) * 1 + 1;
3326 my $len_diff = length($var) - $-[0] - length($new_var);
3327 $var = substr($var, 0, $-[0]) . ($len_diff > 0 ? '0' x $len_diff : '') . $new_var;
3333 $query = qq|UPDATE defaults SET $fld = ?|;
3334 do_query($self, $dbh, $query, $var);
3336 if (!$provided_dbh) {
3341 $main::lxdebug->leave_sub();
3346 sub update_business {
3347 $main::lxdebug->enter_sub();
3349 my ($self, $myconfig, $business_id, $provided_dbh) = @_;
3352 if ($provided_dbh) {
3353 $dbh = $provided_dbh;
3355 $dbh = $self->dbconnect_noauto($myconfig);
3358 qq|SELECT customernumberinit FROM business
3359 WHERE id = ? FOR UPDATE|;
3360 my ($var) = selectrow_query($self, $dbh, $query, $business_id);
3362 return undef unless $var;
3364 if ($var =~ m/\d+$/) {
3365 my $new_var = (substr $var, $-[0]) * 1 + 1;
3366 my $len_diff = length($var) - $-[0] - length($new_var);
3367 $var = substr($var, 0, $-[0]) . ($len_diff > 0 ? '0' x $len_diff : '') . $new_var;
3373 $query = qq|UPDATE business
3374 SET customernumberinit = ?
3376 do_query($self, $dbh, $query, $var, $business_id);
3378 if (!$provided_dbh) {
3383 $main::lxdebug->leave_sub();
3388 sub get_partsgroup {
3389 $main::lxdebug->enter_sub();
3391 my ($self, $myconfig, $p) = @_;
3392 my $target = $p->{target} || 'all_partsgroup';
3394 my $dbh = $self->get_standard_dbh($myconfig);
3396 my $query = qq|SELECT DISTINCT pg.id, pg.partsgroup
3398 JOIN parts p ON (p.partsgroup_id = pg.id) |;
3401 if ($p->{searchitems} eq 'part') {
3402 $query .= qq|WHERE p.inventory_accno_id > 0|;
3404 if ($p->{searchitems} eq 'service') {
3405 $query .= qq|WHERE p.inventory_accno_id IS NULL|;
3407 if ($p->{searchitems} eq 'assembly') {
3408 $query .= qq|WHERE p.assembly = '1'|;
3410 if ($p->{searchitems} eq 'labor') {
3411 $query .= qq|WHERE (p.inventory_accno_id > 0) AND (p.income_accno_id IS NULL)|;
3414 $query .= qq|ORDER BY partsgroup|;
3417 $query = qq|SELECT id, partsgroup FROM partsgroup
3418 ORDER BY partsgroup|;
3421 if ($p->{language_code}) {
3422 $query = qq|SELECT DISTINCT pg.id, pg.partsgroup,
3423 t.description AS translation
3425 JOIN parts p ON (p.partsgroup_id = pg.id)
3426 LEFT JOIN translation t ON ((t.trans_id = pg.id) AND (t.language_code = ?))
3427 ORDER BY translation|;
3428 @values = ($p->{language_code});
3431 $self->{$target} = selectall_hashref_query($self, $dbh, $query, @values);
3433 $main::lxdebug->leave_sub();
3436 sub get_pricegroup {
3437 $main::lxdebug->enter_sub();
3439 my ($self, $myconfig, $p) = @_;
3441 my $dbh = $self->get_standard_dbh($myconfig);
3443 my $query = qq|SELECT p.id, p.pricegroup
3446 $query .= qq| ORDER BY pricegroup|;
3449 $query = qq|SELECT id, pricegroup FROM pricegroup
3450 ORDER BY pricegroup|;
3453 $self->{all_pricegroup} = selectall_hashref_query($self, $dbh, $query);
3455 $main::lxdebug->leave_sub();
3459 # usage $form->all_years($myconfig, [$dbh])
3460 # return list of all years where bookings found
3463 $main::lxdebug->enter_sub();
3465 my ($self, $myconfig, $dbh) = @_;
3467 $dbh ||= $self->get_standard_dbh($myconfig);
3470 my $query = qq|SELECT (SELECT MIN(transdate) FROM acc_trans),
3471 (SELECT MAX(transdate) FROM acc_trans)|;
3472 my ($startdate, $enddate) = selectrow_query($self, $dbh, $query);
3474 if ($myconfig->{dateformat} =~ /^yy/) {
3475 ($startdate) = split /\W/, $startdate;
3476 ($enddate) = split /\W/, $enddate;
3478 (@_) = split /\W/, $startdate;
3480 (@_) = split /\W/, $enddate;
3485 $startdate = substr($startdate,0,4);
3486 $enddate = substr($enddate,0,4);
3488 while ($enddate >= $startdate) {
3489 push @all_years, $enddate--;
3494 $main::lxdebug->leave_sub();
3498 $main::lxdebug->enter_sub();
3502 map { $self->{_VAR_BACKUP}->{$_} = $self->{$_} if exists $self->{$_} } @vars;
3504 $main::lxdebug->leave_sub();
3508 $main::lxdebug->enter_sub();
3513 map { $self->{$_} = $self->{_VAR_BACKUP}->{$_} if exists $self->{_VAR_BACKUP}->{$_} } @vars;
3515 $main::lxdebug->leave_sub();
3524 SL::Form.pm - main data object.
3528 This is the main data object of Lx-Office.
3529 Unfortunately it also acts as a god object for certain data retrieval procedures used in the entry points.
3530 Points of interest for a beginner are:
3532 - $form->error - renders a generic error in html. accepts an error message
3533 - $form->get_standard_dbh - returns a database connection for the
3535 =head1 SPECIAL FUNCTIONS
3539 =item _store_value()
3541 parses a complex var name, and stores it in the form.
3544 $form->_store_value($key, $value);
3546 keys must start with a string, and can contain various tokens.
3547 supported key structures are:
3550 simple key strings work as expected
3555 separating two keys by a dot (.) will result in a hash lookup for the inner value
3556 this is similar to the behaviour of java and templating mechanisms.
3558 filter.description => $form->{filter}->{description}
3560 3. array+hashref access
3562 adding brackets ([]) before the dot will cause the next hash to be put into an array.
3563 using [+] instead of [] will force a new array index. this is useful for recurring
3564 data structures like part lists. put a [+] into the first varname, and use [] on the
3567 repeating these names in your template:
3570 invoice.items[].parts_id
3574 $form->{invoice}->{items}->[
3588 using brackets at the end of a name will result in a pure array to be created.
3589 note that you mustn't use [+], which is reserved for array+hash access and will
3590 result in undefined behaviour in array context.
3592 filter.status[] => $form->{status}->[ val1, val2, ... ]
3594 =item update_business PARAMS
3597 \%config, - config hashref
3598 $business_id, - business id
3599 $dbh - optional database handle
3601 handles business (thats customer/vendor types) sequences.
3603 special behaviour for empty strings in customerinitnumber field:
3604 will in this case not increase the value, and return undef.
3606 =item redirect_header $url
3608 Generates a HTTP redirection header for the new C<$url>. Constructs an
3609 absolute URL including scheme, host name and port. If C<$url> is a
3610 relative URL then it is considered relative to Lx-Office base URL.
3612 This function C<die>s if headers have already been created with
3613 C<$::form-E<gt>header>.
3617 print $::form->redirect_header('oe.pl?action=edit&id=1234');
3618 print $::form->redirect_header('http://www.lx-office.org/');