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 #======================================================================
52 $main::lxdebug->enter_sub(2);
56 my @pairs = split(/&/, $input);
59 my ($name, $value) = split(/=/, $_, 2);
60 $in{$name} = unescape(undef, $value);
63 $main::lxdebug->leave_sub(2);
68 sub _request_to_hash {
69 $main::lxdebug->enter_sub(2);
72 my ($i, $loc, $key, $val);
73 my (%ATTACH, $f, $header, $header_body, $len, $buf);
74 my ($boundary, @list, $size, $body, $x, $blah, $name);
76 if ($ENV{'CONTENT_TYPE'}
77 && ($ENV{'CONTENT_TYPE'} =~ /multipart\/form-data; boundary=(.+)$/)) {
78 $boundary = quotemeta('--' . $1);
79 @list = split(/$boundary/, $input);
81 # For some reason there are always 2 extra, that are empty
84 for ($x = 1; $x <= $size; $x++) {
85 $header_body = $list[$x];
86 $header_body =~ /\r\n\r\n|\n\n/;
88 # Here we split the header and body
93 # Now we try to get the file name
95 $name =~ /name=\"(.+)\"/;
96 ($name, $blah) = split(/\"/, $1);
98 # If the form name is not attach, then we need to parse this like
100 if ($name ne "attach") {
101 $body =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
102 $ATTACH{$name} = $body;
104 # Otherwise it is an attachment and we need to finish it up
105 } elsif ($name eq "attach") {
106 $header =~ /filename=\"(.+)\"/;
107 $ATTACH{'FILE_NAME'} = $1;
108 $ATTACH{'FILE_NAME'} =~ s/\"//g;
109 $ATTACH{'FILE_NAME'} =~ s/\s//g;
110 $ATTACH{'FILE_CONTENT'} = $body;
112 for ($i = $x; $list[$i]; $i++) {
113 $list[$i] =~ s/^.+name=$//;
114 $list[$i] =~ /\"(\w+)\"/;
120 $main::lxdebug->leave_sub(2);
124 $main::lxdebug->leave_sub(2);
125 return _input_to_hash($input);
130 $main::lxdebug->enter_sub();
136 if ($LXDebug::watch_form) {
137 require SL::Watchdog;
138 tie %{ $self }, 'SL::Watchdog';
141 read(STDIN, $_, $ENV{CONTENT_LENGTH});
143 if ($ENV{QUERY_STRING}) {
144 $_ = $ENV{QUERY_STRING};
151 my %parameters = _request_to_hash($_);
152 map({ $self->{$_} = $parameters{$_}; } keys(%parameters));
154 $self->{action} = lc $self->{action};
155 $self->{action} =~ s/( |-|,|\#)/_/g;
157 $self->{version} = "2.4.2";
159 $main::lxdebug->leave_sub();
165 $main::lxdebug->enter_sub();
171 map { print "$_ = $self->{$_}\n" } (sort keys %{$self});
173 $main::lxdebug->leave_sub();
177 $main::lxdebug->enter_sub(2);
179 my ($self, $str) = @_;
181 $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
183 $main::lxdebug->leave_sub(2);
189 $main::lxdebug->enter_sub(2);
191 my ($self, $str) = @_;
196 $str =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
198 $main::lxdebug->leave_sub(2);
204 my ($self, $str) = @_;
206 if ($str && !ref($str)) {
207 $str =~ s/\"/"/g;
215 my ($self, $str) = @_;
217 if ($str && !ref($str)) {
218 $str =~ s/"/\"/g;
226 $main::lxdebug->enter_sub(2);
228 my ($self, $str) = @_;
231 ('order' => ['"', '<', '>'],
237 map({ $str =~ s/$_/$replace{$_}/g; } @{ $replace{"order"} });
239 $main::lxdebug->leave_sub(2);
248 map({ print($main::cgi->hidden("-name" => $_, "-default" => $self->{$_}) . "\n"); } @_);
250 for (sort keys %$self) {
251 next if (($_ eq "header") || (ref($self->{$_}) ne ""));
252 print($main::cgi->hidden("-name" => $_, "-default" => $self->{$_}) . "\n");
259 $main::lxdebug->enter_sub();
261 $main::lxdebug->show_backtrace();
263 my ($self, $msg) = @_;
264 if ($ENV{HTTP_USER_AGENT}) {
266 $self->show_generic_error($msg);
270 if ($self->{error_function}) {
271 &{ $self->{error_function} }($msg);
277 $main::lxdebug->leave_sub();
281 $main::lxdebug->enter_sub();
283 my ($self, $msg) = @_;
285 if ($ENV{HTTP_USER_AGENT}) {
288 if (!$self->{header}) {
301 if ($self->{info_function}) {
302 &{ $self->{info_function} }($msg);
308 $main::lxdebug->leave_sub();
312 $main::lxdebug->enter_sub();
314 my ($self, $str, $cols, $maxrows) = @_;
318 map { $rows += int(((length) - 2) / $cols) + 1 } split /\r/, $str;
320 $maxrows = $rows unless defined $maxrows;
322 $main::lxdebug->leave_sub();
324 return ($rows > $maxrows) ? $maxrows : $rows;
328 $main::lxdebug->enter_sub();
330 my ($self, $msg) = @_;
332 $self->error("$msg\n" . $DBI::errstr);
334 $main::lxdebug->leave_sub();
338 $main::lxdebug->enter_sub();
340 my ($self, $name, $msg) = @_;
342 if ($self->{$name} =~ /^\s*$/) {
345 $main::lxdebug->leave_sub();
349 $main::lxdebug->enter_sub();
351 my ($self, $extra_code) = @_;
353 if ($self->{header}) {
354 $main::lxdebug->leave_sub();
358 my ($stylesheet, $favicon);
360 if ($ENV{HTTP_USER_AGENT}) {
362 if ($self->{stylesheet} && (-f "css/$self->{stylesheet}")) {
364 qq|<LINK REL="stylesheet" HREF="css/$self->{stylesheet}" TYPE="text/css" TITLE="Lx-Office stylesheet">
368 $self->{favicon} = "favicon.ico" unless $self->{favicon};
370 if ($self->{favicon} && (-f "$self->{favicon}")) {
372 qq|<LINK REL="shortcut icon" HREF="$self->{favicon}" TYPE="image/x-icon">
376 my $db_charset = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
378 if ($self->{landscape}) {
379 $pagelayout = qq|<style type="text/css">
380 \@page { size:landscape; }
384 my $fokus = qq| document.$self->{fokus}.focus();| if ($self->{"fokus"});
388 if ($self->{jsscript} == 1) {
391 <style type="text/css">\@import url(js/jscalendar/calendar-win2k-1.css);</style>
392 <script type="text/javascript" src="js/jscalendar/calendar.js"></script>
393 <script type="text/javascript" src="js/jscalendar/lang/calendar-de.js"></script>
394 <script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script>
401 ? "$self->{title} - $self->{titlebar}"
404 foreach $item (@ { $self->{AJAX} }) {
405 $ajax .= $item->show_javascript();
407 print qq|Content-Type: text/html; charset=${db_charset};
411 <title>$self->{titlebar}</title>
415 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=${db_charset}">
419 <script type="text/javascript">
427 <meta name="robots" content="noindex,nofollow" />
428 <script type="text/javascript" src="js/highlight_input.js"></script>
429 <link rel="stylesheet" type="text/css" href="css/tabcontent.css" />
431 <script type="text/javascript" src="js/tabcontent.js">
433 /***********************************************
434 * Tab Content script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
435 * This notice MUST stay intact for legal use
436 * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
437 ***********************************************/
448 $main::lxdebug->leave_sub();
451 sub parse_html_template {
452 $main::lxdebug->enter_sub();
454 my ($self, $file, $additional_params) = @_;
457 if (!defined(%main::myconfig) || !defined($main::myconfig{"countrycode"})) {
458 $language = $main::language;
460 $language = $main::myconfig{"countrycode"};
462 $language = "de" unless ($language);
464 if (-f "templates/webpages/${file}_${language}.html") {
465 if ((-f ".developer") &&
466 (-f "templates/webpages/${file}_master.html") &&
467 ((stat("templates/webpages/${file}_master.html"))[9] >
468 (stat("templates/webpages/${file}_${language}.html"))[9])) {
469 my $info = "Developer information: templates/webpages/${file}_master.html is newer than the localized version.\n" .
470 "Please re-run 'locales.pl' in 'locale/${language}'.";
471 print(qq|<pre>$info</pre>|);
475 $file = "templates/webpages/${file}_${language}.html";
476 } elsif (-f "templates/webpages/${file}.html") {
477 $file = "templates/webpages/${file}.html";
479 my $info = "Web page template '${file}' not found.\n" .
480 "Please re-run 'locales.pl' in 'locale/${language}'.";
481 print(qq|<pre>$info</pre>|);
485 my $template = HTML::Template->new("filename" => $file,
486 "die_on_bad_params" => 0,
488 "case_sensitive" => 1,
489 "loop_context_vars" => 1,
492 $additional_params = {} unless ($additional_params);
493 if ($self->{"DEBUG"}) {
494 $additional_params->{"DEBUG"} = $self->{"DEBUG"};
497 if ($additional_params->{"DEBUG"}) {
498 $additional_params->{"DEBUG"} =
499 "<br><em>DEBUG INFORMATION:</em><pre>" . $additional_params->{"DEBUG"} . "</pre>";
502 if (%main::myconfig) {
503 map({ $additional_params->{"myconfig_${_}"} = $main::myconfig{$_}; } keys(%main::myconfig));
504 my $jsc_dateformat = $main::myconfig{"dateformat"};
505 $jsc_dateformat =~ s/d+/\%d/gi;
506 $jsc_dateformat =~ s/m+/\%m/gi;
507 $jsc_dateformat =~ s/y+/\%Y/gi;
508 $additional_params->{"myconfig_jsc_dateformat"} = $jsc_dateformat;
511 $additional_params->{"conf_lizenzen"} = $main::lizenzen;
512 $additional_params->{"conf_latex_templates"} = $main::latex;
513 $additional_params->{"conf_opendocument_templates"} = $main::opendocument_templates;
515 my @additional_param_names = keys(%{$additional_params});
516 foreach my $key ($template->param()) {
517 my $param = $self->{$key};
518 $param = $additional_params->{$key} if (grep(/^${key}$/, @additional_param_names));
519 $param = [] if (($template->query("name" => $key) eq "LOOP") && (ref($param) ne "ARRAY"));
520 $template->param($key => $param);
523 my $output = $template->output();
525 $main::lxdebug->leave_sub();
530 sub show_generic_error {
531 my ($self, $error, $title, $action) = @_;
534 $add_params->{"title"} = $title if ($title);
535 $self->{"label_error"} = $error;
539 map({ delete($self->{$_}); } qw(action));
540 map({ push(@vars, { "name" => $_, "value" => $self->{$_} })
541 if (!ref($self->{$_})); }
543 $add_params->{"SHOW_BUTTON"} = 1;
544 $add_params->{"BUTTON_LABEL"} = $action;
546 $add_params->{"VARIABLES"} = \@vars;
549 print($self->parse_html_template("generic/error", $add_params));
551 die("Error: $error\n");
554 sub show_generic_information {
555 my ($self, $error, $title) = @_;
558 $add_params->{"title"} = $title if ($title);
559 $self->{"label_information"} = $error;
562 print($self->parse_html_template("generic/information", $add_params));
564 die("Information: $error\n");
567 # write Trigger JavaScript-Code ($qty = quantity of Triggers)
568 # changed it to accept an arbitrary number of triggers - sschoeling
570 $main::lxdebug->enter_sub();
573 my $myconfig = shift;
576 # set dateform for jsscript
579 "dd.mm.yy" => "%d.%m.%Y",
580 "dd-mm-yy" => "%d-%m-%Y",
581 "dd/mm/yy" => "%d/%m/%Y",
582 "mm/dd/yy" => "%m/%d/%Y",
583 "mm-dd-yy" => "%m-%d-%Y",
584 "yyyy-mm-dd" => "%Y-%m-%d",
587 my $ifFormat = defined($dateformats{$myconfig{"dateformat"}}) ?
588 $dateformats{$myconfig{"dateformat"}} : "%d.%m.%Y";
595 inputField : "| . (shift) . qq|",
596 ifFormat :"$ifFormat",
597 align : "| . (shift) . qq|",
598 button : "| . (shift) . qq|"
604 <script type="text/javascript">
605 <!--| . join("", @triggers) . qq|//-->
609 $main::lxdebug->leave_sub();
612 } #end sub write_trigger
615 $main::lxdebug->enter_sub();
617 my ($self, $msg) = @_;
619 if ($self->{callback}) {
621 ($script, $argv) = split(/\?/, $self->{callback});
622 exec("perl", "$script", $argv);
630 $main::lxdebug->leave_sub();
633 # sort of columns removed - empty sub
635 $main::lxdebug->enter_sub();
637 my ($self, @columns) = @_;
639 $main::lxdebug->leave_sub();
645 $main::lxdebug->enter_sub(2);
647 my ($self, $myconfig, $amount, $places, $dash) = @_;
652 my $neg = ($amount =~ s/-//);
654 if (defined($places) && ($places ne '')) {
659 my ($actual_places) = ($amount =~ /\.(\d+)/);
660 $actual_places = length($actual_places);
661 $places = $actual_places > $places ? $actual_places : $places;
664 $amount = $self->round_amount($amount, $places);
667 my @d = map { s/\d//g; reverse split // } my $tmp = $myconfig->{numberformat}; # get delim chars
668 my @p = split(/\./, $amount); # split amount at decimal point
670 $p[0] =~ s/\B(?=(...)*$)/$d[1]/g if $d[1]; # add 1,000 delimiters
673 $amount .= $d[0].$p[1].(0 x ($places - length $p[1])) if ($places || $p[1] ne '');
676 ($dash =~ /-/) ? ($neg ? "($amount)" : "$amount" ) :
677 ($dash =~ /DRCR/) ? ($neg ? "$amount DR" : "$amount CR" ) :
678 ($neg ? "-$amount" : "$amount" ) ;
682 $main::lxdebug->leave_sub(2);
687 $main::lxdebug->enter_sub(2);
689 my ($self, $myconfig, $amount) = @_;
691 if ( ($myconfig->{numberformat} eq '1.000,00')
692 || ($myconfig->{numberformat} eq '1000,00')) {
697 if ($myconfig->{numberformat} eq "1'000.00") {
703 $main::lxdebug->leave_sub(2);
705 return ($amount * 1);
709 $main::lxdebug->enter_sub(2);
711 my ($self, $amount, $places) = @_;
714 # Rounding like "Kaufmannsrunden"
715 # Descr. http://de.wikipedia.org/wiki/Rundung
717 # http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q4.13.html
720 $amount = $amount * (10**($places));
721 $round_amount = int($amount + .5 * ($amount <=> 0)) / (10**($places));
723 $main::lxdebug->leave_sub(2);
725 return $round_amount;
730 $main::lxdebug->enter_sub();
732 my ($self, $myconfig, $userspath) = @_;
733 my ($template, $out);
737 $self->{"cwd"} = getcwd();
738 $self->{"tmpdir"} = $self->{cwd} . "/${userspath}";
740 if ($self->{"format"} =~ /(opendocument|oasis)/i) {
741 $template = OpenDocumentTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
742 } elsif ($self->{"format"} =~ /(postscript|pdf)/i) {
743 $ENV{"TEXINPUTS"} = ".:" . getcwd() . "/" . $myconfig->{"templates"} . ":" . $ENV{"TEXINPUTS"};
744 $template = LaTeXTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
745 } elsif (($self->{"format"} =~ /html/i) ||
746 (!$self->{"format"} && ($self->{"IN"} =~ /html$/i))) {
747 $template = HTMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
748 } elsif (($self->{"format"} =~ /xml/i) ||
749 (!$self->{"format"} && ($self->{"IN"} =~ /xml$/i))) {
750 $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
751 } elsif ( $self->{"format"} =~ /elsterwinston/i ) {
752 $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
753 } elsif ( $self->{"format"} =~ /elstertaxbird/i ) {
754 $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
755 } elsif ( defined $self->{'format'}) {
756 $self->error("Outputformat not defined. This may be a future feature: $self->{'format'}");
757 } elsif ( $self->{'format'} eq '' ) {
758 $self->error("No Outputformat given: $self->{'format'}");
759 } else { #Catch the rest
760 $self->error("Outputformat not defined: $self->{'format'}");
763 # Copy the notes from the invoice/sales order etc. back to the variable "notes" because that is where most templates expect it to be.
764 $self->{"notes"} = $self->{ $self->{"formname"} . "notes" };
766 map({ $self->{"employee_${_}"} = $myconfig->{$_}; }
767 qw(email tel fax name signature company address businessnumber
768 co_ustid taxnumber duns));
769 map({ $self->{"employee_${_}"} =~ s/\\n/\n/g; }
770 qw(company address signature));
771 map({ $self->{$_} =~ s/\\n/\n/g; } qw(company address signature));
773 $self->{copies} = 1 if (($self->{copies} *= 1) <= 0);
775 # OUT is used for the media, screen, printer, email
776 # for postscript we store a copy in a temporary file
778 my $prepend_userspath;
780 if (!$self->{tmpfile}) {
781 $self->{tmpfile} = "${fileid}.$self->{IN}";
782 $prepend_userspath = 1;
785 $prepend_userspath = 1 if substr($self->{tmpfile}, 0, length $userspath) eq $userspath;
787 $self->{tmpfile} =~ s|.*/||;
788 $self->{tmpfile} =~ s/[^a-zA-Z0-9\._\ \-]//g;
789 $self->{tmpfile} = "$userspath/$self->{tmpfile}" if $prepend_userspath;
791 if ($template->uses_temp_file() || $self->{media} eq 'email') {
793 $self->{OUT} = ">$self->{tmpfile}";
797 open(OUT, "$self->{OUT}") or $self->error("$self->{OUT} : $!");
799 open(OUT, ">-") or $self->error("STDOUT : $!");
803 if (!$template->parse(*OUT)) {
805 $self->error("$self->{IN} : " . $template->get_error());
810 if ($template->uses_temp_file() || $self->{media} eq 'email') {
812 if ($self->{media} eq 'email') {
816 my $mail = new Mailer;
818 map { $mail->{$_} = $self->{$_} }
819 qw(cc bcc subject message version format);
820 $mail->{charset} = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
821 $mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email};
822 $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
823 $mail->{fileid} = "$fileid.";
824 $myconfig->{signature} =~ s/\\r\\n/\\n/g;
826 # if we send html or plain text inline
827 if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
828 $mail->{contenttype} = "text/html";
830 $mail->{message} =~ s/\r\n/<br>\n/g;
831 $myconfig->{signature} =~ s/\\n/<br>\n/g;
832 $mail->{message} .= "<br>\n-- <br>\n$myconfig->{signature}\n<br>";
834 open(IN, $self->{tmpfile})
835 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
837 $mail->{message} .= $_;
844 if (!$self->{"do_not_attach"}) {
845 @{ $mail->{attachments} } =
846 ({ "filename" => $self->{"tmpfile"},
847 "name" => $self->{"attachment_filename"} ?
848 $self->{"attachment_filename"} : $self->{"tmpfile"} });
851 $mail->{message} =~ s/\r\n/\n/g;
852 $myconfig->{signature} =~ s/\\n/\n/g;
853 $mail->{message} .= "\n-- \n$myconfig->{signature}";
857 my $err = $mail->send();
858 $self->error($self->cleanup . "$err") if ($err);
864 my $numbytes = (-s $self->{tmpfile});
865 open(IN, $self->{tmpfile})
866 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
868 $self->{copies} = 1 unless $self->{media} eq 'printer';
870 chdir("$self->{cwd}");
871 #print(STDERR "Kopien $self->{copies}\n");
872 #print(STDERR "OUT $self->{OUT}\n");
873 for my $i (1 .. $self->{copies}) {
875 open(OUT, $self->{OUT})
876 or $self->error($self->cleanup . "$self->{OUT} : $!");
878 $self->{attachment_filename} = ($self->{attachment_filename})
879 ? $self->{attachment_filename}
880 : $self->generate_attachment_filename();
883 print qq|Content-Type: | . $template->get_mime_type() . qq|
884 Content-Disposition: attachment; filename="$self->{attachment_filename}"
885 Content-Length: $numbytes
889 open(OUT, ">-") or $self->error($self->cleanup . "$!: STDOUT");
909 chdir("$self->{cwd}");
910 $main::lxdebug->leave_sub();
913 sub generate_attachment_filename {
916 my %formname_translations = (
917 bin_list => $main::locale->text('Bin List'),
918 credit_note => $main::locale->text('Credit Note'),
919 invoice => $main::locale->text('Invoice'),
920 packing_list => $main::locale->text('Packing List'),
921 pick_list => $main::locale->text('Pick List'),
922 proforma => $main::locale->text('Proforma Invoice'),
923 purchase_order => $main::locale->text('Purchase Order'),
924 request_quotation => $main::locale->text('RFQ'),
925 sales_order => $main::locale->text('Confirmation'),
926 sales_quotation => $main::locale->text('Quotation'),
927 storno_invoice => $main::locale->text('Storno Invoice'),
928 storno_packing_list => $main::locale->text('Storno Packing List'),
931 my $attachment_filename = $formname_translations{$self->{"formname"}};
933 (grep { $self->{"type"} eq $_ } qw(invoice credit_note)) ? "inv"
934 : ($self->{"type"} =~ /_quotation$/) ? "quo"
937 if ($attachment_filename && $self->{"${prefix}number"}) {
938 $attachment_filename .= "_" . $self->{"${prefix}number"}
939 . ( $self->{format} =~ /pdf/i ? ".pdf"
940 : $self->{format} =~ /postscript/i ? ".ps"
941 : $self->{format} =~ /opendocument/i ? ".odt"
942 : $self->{format} =~ /html/i ? ".html"
944 $attachment_filename =~ s/ /_/g;
945 my %umlaute = ( "ä" => "ae", "ö" => "oe", "ü" => "ue",
946 "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue", "ß" => "ss");
947 map { $attachment_filename =~ s/$_/$umlaute{$_}/g } keys %umlaute;
949 $attachment_filename = "";
952 return $attachment_filename;
956 $main::lxdebug->enter_sub();
960 chdir("$self->{tmpdir}");
963 if (-f "$self->{tmpfile}.err") {
964 open(FH, "$self->{tmpfile}.err");
969 if ($self->{tmpfile}) {
970 $self->{tmpfile} =~ s|.*/||g;
972 $self->{tmpfile} =~ s/\.\w+$//g;
973 my $tmpfile = $self->{tmpfile};
974 unlink(<$tmpfile.*>);
977 chdir("$self->{cwd}");
979 $main::lxdebug->leave_sub();
985 $main::lxdebug->enter_sub();
987 my ($self, $date, $myconfig) = @_;
989 if ($date && $date =~ /\D/) {
991 if ($myconfig->{dateformat} =~ /^yy/) {
992 ($yy, $mm, $dd) = split /\D/, $date;
994 if ($myconfig->{dateformat} =~ /^mm/) {
995 ($mm, $dd, $yy) = split /\D/, $date;
997 if ($myconfig->{dateformat} =~ /^dd/) {
998 ($dd, $mm, $yy) = split /\D/, $date;
1003 $yy = ($yy < 70) ? $yy + 2000 : $yy;
1004 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
1006 $dd = "0$dd" if ($dd < 10);
1007 $mm = "0$mm" if ($mm < 10);
1009 $date = "$yy$mm$dd";
1012 $main::lxdebug->leave_sub();
1017 # Database routines used throughout
1020 $main::lxdebug->enter_sub(2);
1022 my ($self, $myconfig) = @_;
1024 # connect to database
1026 DBI->connect($myconfig->{dbconnect},
1027 $myconfig->{dbuser}, $myconfig->{dbpasswd})
1031 if ($myconfig->{dboptions}) {
1032 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1035 $main::lxdebug->leave_sub(2);
1040 sub dbconnect_noauto {
1041 $main::lxdebug->enter_sub();
1043 my ($self, $myconfig) = @_;
1045 # connect to database
1047 DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser},
1048 $myconfig->{dbpasswd}, { AutoCommit => 0 })
1052 if ($myconfig->{dboptions}) {
1053 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1056 $main::lxdebug->leave_sub();
1061 sub update_balance {
1062 $main::lxdebug->enter_sub();
1064 my ($self, $dbh, $table, $field, $where, $value, @values) = @_;
1066 # if we have a value, go do it
1069 # retrieve balance from table
1070 my $query = "SELECT $field FROM $table WHERE $where FOR UPDATE";
1071 my $sth = prepare_execute_query($self, $dbh, $query, @values);
1072 my ($balance) = $sth->fetchrow_array;
1078 $query = "UPDATE $table SET $field = $balance WHERE $where";
1079 do_query($self, $dbh, $query, @values);
1081 $main::lxdebug->leave_sub();
1084 sub update_exchangerate {
1085 $main::lxdebug->enter_sub();
1087 my ($self, $dbh, $curr, $transdate, $buy, $sell) = @_;
1089 # some sanity check for currency
1091 $main::lxdebug->leave_sub();
1095 my $query = qq|SELECT e.curr FROM exchangerate e
1096 WHERE e.curr = ? AND e.transdate = ?
1098 my $sth = prepare_execute_query($self, $dbh, $query, $curr, $transdate);
1101 if ($buy != 0 && $sell != 0) {
1102 $set = "buy = $buy, sell = $sell";
1103 } elsif ($buy != 0) {
1104 $set = "buy = $buy";
1105 } elsif ($sell != 0) {
1106 $set = "sell = $sell";
1109 if ($sth->fetchrow_array) {
1110 $query = qq|UPDATE exchangerate
1115 $query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
1116 VALUES (?, $buy, $sell, ?)|;
1119 do_query($self, $dbh, $query, $curr, $transdate);
1121 $main::lxdebug->leave_sub();
1124 sub save_exchangerate {
1125 $main::lxdebug->enter_sub();
1127 my ($self, $myconfig, $currency, $transdate, $rate, $fld) = @_;
1129 my $dbh = $self->dbconnect($myconfig);
1131 my ($buy, $sell) = (0, 0);
1132 $buy = $rate if $fld eq 'buy';
1133 $sell = $rate if $fld eq 'sell';
1135 $self->update_exchangerate($dbh, $currency, $transdate, $buy, $sell);
1139 $main::lxdebug->leave_sub();
1142 sub get_exchangerate {
1143 $main::lxdebug->enter_sub();
1145 my ($self, $dbh, $curr, $transdate, $fld) = @_;
1147 unless ($transdate) {
1148 $main::lxdebug->leave_sub();
1152 my $query = qq|SELECT e.$fld FROM exchangerate e
1153 WHERE e.curr = ? AND e.transdate = ?|;
1154 my ($exchangerate) = selectrow_query($self, $dbh, $query, $curr, $transdate);
1156 if (!$exchangerate) {
1160 $main::lxdebug->leave_sub();
1162 return $exchangerate;
1165 sub check_exchangerate {
1166 $main::lxdebug->enter_sub();
1168 my ($self, $myconfig, $currency, $transdate, $fld) = @_;
1170 unless ($transdate) {
1171 $main::lxdebug->leave_sub();
1175 my $dbh = $self->dbconnect($myconfig);
1177 my $query = qq|SELECT e.$fld FROM exchangerate e
1178 WHERE e.curr = ? AND e.transdate = ?|;
1179 my ($exchangerate) = selectrow_query($self, $dbh, $query, $currency, $transdate);
1182 $main::lxdebug->leave_sub();
1184 return $exchangerate;
1187 sub set_payment_options {
1188 $main::lxdebug->enter_sub();
1190 my ($self, $myconfig, $transdate) = @_;
1192 if ($self->{payment_id}) {
1194 my $dbh = $self->dbconnect($myconfig);
1197 qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, p.description_long | .
1198 qq|FROM payment_terms p | .
1201 ($self->{terms_netto}, $self->{terms_skonto}, $self->{percent_skonto},
1202 $self->{payment_terms}) =
1203 selectrow_query($self, $dbh, $query, $self->{payment_id});
1205 if ($transdate eq "") {
1206 if ($self->{invdate}) {
1207 $transdate = $self->{invdate};
1209 $transdate = $self->{transdate};
1214 qq|SELECT ?::date + ?::integer AS netto_date, ?::date + ?::integer AS skonto_date | .
1215 qq|FROM payment_terms|;
1216 ($self->{netto_date}, $self->{skonto_date}) =
1217 selectrow_query($self, $dbh, $query, $transdate, $self->{terms_netto}, $transdate, $self->{terms_skonto});
1219 my $total = ($self->{invtotal}) ? $self->{invtotal} : $self->{ordtotal};
1220 my $skonto_amount = $self->parse_amount($myconfig, $total) *
1221 $self->{percent_skonto};
1223 $self->{skonto_amount} =
1224 $self->format_amount($myconfig, $skonto_amount, 2);
1226 if ($self->{"language_id"}) {
1228 qq|SELECT t.description_long, l.output_numberformat, l.output_dateformat, l.output_longdates | .
1229 qq|FROM translation_payment_terms t | .
1230 qq|LEFT JOIN language l ON t.language_id = l.id | .
1231 qq|WHERE (t.language_id = ?) AND (t.payment_terms_id = ?)|;
1232 my ($description_long, $output_numberformat, $output_dateformat,
1233 $output_longdates) =
1234 selectrow_query($self, $dbh, $query,
1235 $self->{"language_id"}, $self->{"payment_id"});
1237 $self->{payment_terms} = $description_long if ($description_long);
1239 if ($output_dateformat) {
1240 foreach my $key (qw(netto_date skonto_date)) {
1242 $main::locale->reformat_date($myconfig, $self->{$key},
1248 if ($output_numberformat &&
1249 ($output_numberformat ne $myconfig->{"numberformat"})) {
1250 my $saved_numberformat = $myconfig->{"numberformat"};
1251 $myconfig->{"numberformat"} = $output_numberformat;
1252 $self->{skonto_amount} =
1253 $self->format_amount($myconfig, $skonto_amount, 2);
1254 $myconfig->{"numberformat"} = $saved_numberformat;
1258 $self->{payment_terms} =~ s/<%netto_date%>/$self->{netto_date}/g;
1259 $self->{payment_terms} =~ s/<%skonto_date%>/$self->{skonto_date}/g;
1260 $self->{payment_terms} =~ s/<%skonto_amount%>/$self->{skonto_amount}/g;
1261 $self->{payment_terms} =~ s/<%total%>/$self->{total}/g;
1262 $self->{payment_terms} =~ s/<%invtotal%>/$self->{invtotal}/g;
1263 $self->{payment_terms} =~ s/<%currency%>/$self->{currency}/g;
1264 $self->{payment_terms} =~ s/<%terms_netto%>/$self->{terms_netto}/g;
1265 $self->{payment_terms} =~ s/<%account_number%>/$self->{account_number}/g;
1266 $self->{payment_terms} =~ s/<%bank%>/$self->{bank}/g;
1267 $self->{payment_terms} =~ s/<%bank_code%>/$self->{bank_code}/g;
1272 $main::lxdebug->leave_sub();
1276 sub get_template_language {
1277 $main::lxdebug->enter_sub();
1279 my ($self, $myconfig) = @_;
1281 my $template_code = "";
1283 if ($self->{language_id}) {
1284 my $dbh = $self->dbconnect($myconfig);
1285 my $query = qq|SELECT template_code FROM language WHERE id = ?|;
1286 ($template_code) = selectrow_query($self, $dbh, $query, $self->{language_id});
1290 $main::lxdebug->leave_sub();
1292 return $template_code;
1295 sub get_printer_code {
1296 $main::lxdebug->enter_sub();
1298 my ($self, $myconfig) = @_;
1300 my $template_code = "";
1302 if ($self->{printer_id}) {
1303 my $dbh = $self->dbconnect($myconfig);
1304 my $query = qq|SELECT template_code, printer_command FROM printers WHERE id = ?|;
1305 ($template_code, $self->{printer_command}) = selectrow_query($self, $dbh, $query, $self->{printer_id});
1309 $main::lxdebug->leave_sub();
1311 return $template_code;
1315 $main::lxdebug->enter_sub();
1317 my ($self, $myconfig) = @_;
1319 my $template_code = "";
1321 if ($self->{shipto_id}) {
1322 my $dbh = $self->dbconnect($myconfig);
1323 my $query = qq|SELECT * FROM shipto WHERE shipto_id = ?|;
1324 my $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{shipto_id});
1325 map({ $self->{$_} = $ref->{$_} } keys(%$ref));
1329 $main::lxdebug->leave_sub();
1333 $main::lxdebug->enter_sub();
1335 my ($self, $dbh, $id, $module) = @_;
1339 foreach my $item (qw(name department_1 department_2 street zipcode city country
1340 contact phone fax email)) {
1341 if ($self->{"shipto$item"}) {
1342 $shipto = 1 if ($self->{$item} ne $self->{"shipto$item"});
1344 push(@values, $self->{"shipto${item}"});
1347 if ($self->{shipto_id}) {
1348 my $query = qq|UPDATE shipto set
1350 shiptodepartment_1 = ?,
1351 shiptodepartment_2 = ?,
1360 WHERE shipto_id = ?|;
1361 do_query($self, $dbh, $query, @values, $self->{shipto_id});
1363 my $query = qq|SELECT * FROM shipto
1364 WHERE shiptoname = ? AND
1365 shiptodepartment_1 = ? AND
1366 shiptodepartment_2 = ? AND
1367 shiptostreet = ? AND
1368 shiptozipcode = ? AND
1370 shiptocountry = ? AND
1371 shiptocontact = ? AND
1375 my $insert_check = selectfirst_hashref_query($self, $dbh, $query, @values);
1378 qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2,
1379 shiptostreet, shiptozipcode, shiptocity, shiptocountry,
1380 shiptocontact, shiptophone, shiptofax, shiptoemail, module)
1381 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
1382 do_query($self, $dbh, $query, $id, @values, $module);
1387 $main::lxdebug->leave_sub();
1391 $main::lxdebug->enter_sub();
1393 my ($self, $dbh) = @_;
1395 my $query = qq|SELECT id, name FROM employee WHERE login = ?|;
1396 ($self->{employee_id}, $self->{employee}) = selectrow_query($self, $dbh, $query, $self->{login});
1397 $self->{employee_id} *= 1;
1399 $main::lxdebug->leave_sub();
1403 $main::lxdebug->enter_sub();
1405 my ($self, $myconfig, $salesman_id) = @_;
1407 $main::lxdebug->leave_sub() and return unless $salesman_id;
1409 my $dbh = $self->dbconnect($myconfig);
1412 selectrow_query($self, $dbh, qq|SELECT login FROM employee WHERE id = ?|,
1416 my $user = new User($main::memberfile, $login);
1417 map({ $self->{"salesman_$_"} = $user->{$_}; }
1418 qw(address businessnumber co_ustid company duns email fax name
1420 $self->{salesman_login} = $login;
1422 $self->{salesman_name} = $login
1423 if ($self->{salesman_name} eq "");
1425 map({ $self->{"salesman_$_"} =~ s/\\n/\n/g; } qw(address company));
1430 $main::lxdebug->leave_sub();
1434 $main::lxdebug->enter_sub();
1436 my ($self, $myconfig) = @_;
1438 my $dbh = $self->dbconnect($myconfig);
1439 my $query = qq|SELECT current_date + terms_netto FROM payment_terms WHERE id = ?|;
1440 ($self->{duedate}) = selectrow_query($self, $dbh, $query, $self->{payment_id});
1443 $main::lxdebug->leave_sub();
1447 $main::lxdebug->enter_sub();
1449 my ($self, $dbh, $id, $key) = @_;
1451 $key = "all_contacts" unless ($key);
1454 qq|SELECT cp_id, cp_cv_id, cp_name, cp_givenname, cp_abteilung | .
1455 qq|FROM contacts | .
1456 qq|WHERE cp_cv_id = ? | .
1457 qq|ORDER BY lower(cp_name)|;
1459 $self->{$key} = selectall_hashref_query($self, $dbh, $query, $id);
1461 $main::lxdebug->leave_sub();
1465 $main::lxdebug->enter_sub();
1467 my ($self, $dbh, $key) = @_;
1469 my ($all, $old_id, $where, @values);
1471 if (ref($key) eq "HASH") {
1474 $key = "ALL_PROJECTS";
1476 foreach my $p (keys(%{$params})) {
1478 $all = $params->{$p};
1479 } elsif ($p eq "old_id") {
1480 $old_id = $params->{$p};
1481 } elsif ($p eq "key") {
1482 $key = $params->{$p};
1488 $where = "WHERE active ";
1490 if (ref($old_id) eq "ARRAY") {
1491 my @ids = grep({ $_ } @{$old_id});
1493 $where .= " OR id IN (" . join(",", map({ "?" } @ids)) . ") ";
1494 push(@values, @ids);
1497 $where .= " OR (id = ?) ";
1498 push(@values, $old_id);
1504 qq|SELECT id, projectnumber, description, active | .
1507 qq|ORDER BY lower(projectnumber)|;
1509 $self->{$key} = selectall_hashref_query($self, $dbh, $query, @values);
1511 $main::lxdebug->leave_sub();
1515 $main::lxdebug->enter_sub();
1517 my ($self, $dbh, $vc_id, $key) = @_;
1519 $key = "all_shipto" unless ($key);
1521 # get shipping addresses
1523 qq|SELECT shipto_id, shiptoname, shiptodepartment_1 | .
1525 qq|WHERE trans_id = ?|;
1527 $self->{$key} = selectall_hashref_query($self, $dbh, $query, $vc_id);
1529 $main::lxdebug->leave_sub();
1533 $main::lxdebug->enter_sub();
1535 my ($self, $dbh, $key) = @_;
1537 $key = "all_printers" unless ($key);
1539 my $query = qq|SELECT id, printer_description, printer_command, template_code FROM printers|;
1541 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1543 $main::lxdebug->leave_sub();
1547 $main::lxdebug->enter_sub();
1549 my ($self, $dbh, $params) = @_;
1551 $key = $params->{key};
1552 $key = "all_charts" unless ($key);
1554 my $transdate = quote_db_date($params->{transdate});
1557 qq|SELECT c.accno, c.description, c.link, tk.taxkey_id, tk.tax_id | .
1559 qq|LEFT JOIN taxkeys tk ON | .
1560 qq|(tk.id = (SELECT id FROM taxkeys | .
1561 qq| WHERE taxkeys.chart_id = c.id AND startdate <= $transdate | .
1562 qq| ORDER BY startdate DESC LIMIT 1)) | .
1563 qq|ORDER BY c.accno|;
1565 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1567 $main::lxdebug->leave_sub();
1570 sub _get_taxcharts {
1571 $main::lxdebug->enter_sub();
1573 my ($self, $dbh, $key) = @_;
1575 $key = "all_taxcharts" unless ($key);
1577 my $query = qq|SELECT * FROM tax ORDER BY taxkey|;
1579 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1581 $main::lxdebug->leave_sub();
1585 $main::lxdebug->enter_sub();
1587 my ($self, $dbh, $key) = @_;
1589 $key = "all_taxzones" unless ($key);
1591 my $query = qq|SELECT * FROM tax_zones ORDER BY id|;
1593 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1595 $main::lxdebug->leave_sub();
1598 sub _get_employees {
1599 $main::lxdebug->enter_sub();
1601 my ($self, $dbh, $key) = @_;
1603 $key = "all_employees" unless ($key);
1605 selectall_hashref_query($self, $dbh, qq|SELECT * FROM employee|);
1607 $main::lxdebug->leave_sub();
1610 sub _get_business_types {
1611 $main::lxdebug->enter_sub();
1613 my ($self, $dbh, $key) = @_;
1615 $key = "all_business_types" unless ($key);
1617 selectall_hashref_query($self, $dbh, qq|SELECT * FROM business|);
1619 $main::lxdebug->leave_sub();
1622 sub _get_languages {
1623 $main::lxdebug->enter_sub();
1625 my ($self, $dbh, $key) = @_;
1627 $key = "all_languages" unless ($key);
1629 my $query = qq|SELECT * FROM language ORDER BY id|;
1631 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1633 $main::lxdebug->leave_sub();
1636 sub _get_dunning_configs {
1637 $main::lxdebug->enter_sub();
1639 my ($self, $dbh, $key) = @_;
1641 $key = "all_dunning_configs" unless ($key);
1643 my $query = qq|SELECT * FROM dunning_config ORDER BY dunning_level|;
1645 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1647 $main::lxdebug->leave_sub();
1650 sub _get_currencies {
1651 $main::lxdebug->enter_sub();
1653 my ($self, $dbh, $key) = @_;
1655 $key = "all_currencies" unless ($key);
1657 my $query = qq|SELECT curr AS currency FROM defaults|;
1659 $self->{$key} = [split(/\:/ , selectfirst_hashref_query($self, $dbh, $query)->{currency})];
1661 $main::lxdebug->leave_sub();
1665 $main::lxdebug->enter_sub();
1667 my ($self, $dbh, $key) = @_;
1669 $key = "all_payments" unless ($key);
1671 my $query = qq|SELECT * FROM payment_terms ORDER BY id|;
1673 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1675 $main::lxdebug->leave_sub();
1678 sub _get_customers {
1679 $main::lxdebug->enter_sub();
1681 my ($self, $dbh, $key) = @_;
1683 $key = "all_customers" unless ($key);
1685 my $query = qq|SELECT * FROM customer|;
1687 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1689 $main::lxdebug->leave_sub();
1693 $main::lxdebug->enter_sub();
1695 my ($self, $dbh, $key) = @_;
1697 $key = "all_vendors" unless ($key);
1699 my $query = qq|SELECT * FROM vendor|;
1701 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1703 $main::lxdebug->leave_sub();
1707 $main::lxdebug->enter_sub();
1712 my $dbh = $self->dbconnect(\%main::myconfig);
1713 my ($sth, $query, $ref);
1715 my $vc = $self->{"vc"} eq "customer" ? "customer" : "vendor";
1716 my $vc_id = $self->{"${vc}_id"};
1718 if ($params{"contacts"}) {
1719 $self->_get_contacts($dbh, $vc_id, $params{"contacts"});
1722 if ($params{"shipto"}) {
1723 $self->_get_shipto($dbh, $vc_id, $params{"shipto"});
1726 if ($params{"projects"} || $params{"all_projects"}) {
1727 $self->_get_projects($dbh, $params{"all_projects"} ?
1728 $params{"all_projects"} : $params{"projects"},
1729 $params{"all_projects"} ? 1 : 0);
1732 if ($params{"printers"}) {
1733 $self->_get_printers($dbh, $params{"printers"});
1736 if ($params{"languages"}) {
1737 $self->_get_languages($dbh, $params{"languages"});
1740 if ($params{"charts"}) {
1741 $self->_get_charts($dbh, $params{"charts"});
1744 if ($params{"taxcharts"}) {
1745 $self->_get_taxcharts($dbh, $params{"taxcharts"});
1748 if ($params{"taxzones"}) {
1749 $self->_get_taxzones($dbh, $params{"taxzones"});
1752 if ($params{"employees"}) {
1753 $self->_get_employees($dbh, $params{"employees"});
1756 if ($params{"business_types"}) {
1757 $self->_get_business_types($dbh, $params{"business_types"});
1760 if ($params{"dunning_configs"}) {
1761 $self->_get_dunning_configs($dbh, $params{"dunning_configs"});
1764 if($params{"currencies"}) {
1765 $self->_get_currencies($dbh, $params{"currencies"});
1768 if($params{"customers"}) {
1769 $self->_get_customers($dbh, $params{"customers"});
1772 if($params{"vendors"}) {
1773 $self->_get_vendors($dbh, $params{"vendors"});
1776 if($params{"payments"}) {
1777 $self->_get_payments($dbh, $params{"payments"});
1782 $main::lxdebug->leave_sub();
1785 # this sub gets the id and name from $table
1787 $main::lxdebug->enter_sub();
1789 my ($self, $myconfig, $table) = @_;
1791 # connect to database
1792 my $dbh = $self->dbconnect($myconfig);
1794 $table = $table eq "customer" ? "customer" : "vendor";
1795 my $arap = $self->{arap} eq "ar" ? "ar" : "ap";
1797 my ($query, @values);
1799 if (!$self->{openinvoices}) {
1801 if ($self->{customernumber} ne "") {
1802 $where = qq|(vc.customernumber ILIKE ?)|;
1803 push(@values, '%' . $self->{customernumber} . '%');
1805 $where = qq|(vc.name ILIKE ?)|;
1806 push(@values, '%' . $self->{$table} . '%');
1810 qq~SELECT vc.id, vc.name,
1811 vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
1813 WHERE $where AND (NOT vc.obsolete)
1817 qq~SELECT DISTINCT vc.id, vc.name,
1818 vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
1820 JOIN $table vc ON (a.${table}_id = vc.id)
1821 WHERE NOT (a.amount = a.paid) AND (vc.name ILIKE ?)
1823 push(@values, '%' . $self->{$table} . '%');
1826 $self->{name_list} = selectall_hashref_query($self, $dbh, $query, @values);
1828 $main::lxdebug->leave_sub();
1830 return scalar(@{ $self->{name_list} });
1833 # the selection sub is used in the AR, AP, IS, IR and OE module
1836 $main::lxdebug->enter_sub();
1838 my ($self, $myconfig, $table, $module) = @_;
1841 my $dbh = $self->dbconnect($myconfig);
1843 $table = $table eq "customer" ? "customer" : "vendor";
1845 my $query = qq|SELECT count(*) FROM $table|;
1846 my ($count) = selectrow_query($self, $dbh, $query);
1848 # build selection list
1849 if ($count < $myconfig->{vclimit}) {
1850 $query = qq|SELECT id, name, salesman_id
1851 FROM $table WHERE NOT obsolete
1853 $self->{"all_$table"} = selectall_hashref_query($self, $dbh, $query);
1857 $self->get_employee($dbh);
1859 # setup sales contacts
1860 $query = qq|SELECT e.id, e.name
1862 WHERE (e.sales = '1') AND (NOT e.id = ?)|;
1863 $self->{all_employees} = selectall_hashref_query($self, $dbh, $query, $self->{employee_id});
1866 push(@{ $self->{all_employees} },
1867 { id => $self->{employee_id},
1868 name => $self->{employee} });
1870 # sort the whole thing
1871 @{ $self->{all_employees} } =
1872 sort { $a->{name} cmp $b->{name} } @{ $self->{all_employees} };
1874 if ($module eq 'AR') {
1876 # prepare query for departments
1877 $query = qq|SELECT id, description
1880 ORDER BY description|;
1883 $query = qq|SELECT id, description
1885 ORDER BY description|;
1888 $self->{all_departments} = selectall_hashref_query($self, $dbh, $query);
1891 $query = qq|SELECT id, description
1895 $self->{languages} = selectall_hashref_query($self, $dbh, $query);
1898 $query = qq|SELECT printer_description, id
1900 ORDER BY printer_description|;
1902 $self->{printers} = selectall_hashref_query($self, $dbh, $query);
1905 $query = qq|SELECT id, description
1909 $self->{payment_terms} = selectall_hashref_query($self, $dbh, $query);
1913 $main::lxdebug->leave_sub();
1916 sub language_payment {
1917 $main::lxdebug->enter_sub();
1919 my ($self, $myconfig) = @_;
1921 my $dbh = $self->dbconnect($myconfig);
1923 my $query = qq|SELECT id, description
1927 $self->{languages} = selectall_hashref_query($self, $dbh, $query);
1930 $query = qq|SELECT printer_description, id
1932 ORDER BY printer_description|;
1934 $self->{printers} = selectall_hashref_query($self, $dbh, $query);
1937 $query = qq|SELECT id, description
1941 $self->{payment_terms} = selectall_hashref_query($self, $dbh, $query);
1943 # get buchungsgruppen
1944 $query = qq|SELECT id, description
1945 FROM buchungsgruppen|;
1947 $self->{BUCHUNGSGRUPPEN} = selectall_hashref_query($self, $dbh, $query);
1950 $main::lxdebug->leave_sub();
1953 # this is only used for reports
1954 sub all_departments {
1955 $main::lxdebug->enter_sub();
1957 my ($self, $myconfig, $table) = @_;
1959 my $dbh = $self->dbconnect($myconfig);
1962 if ($table eq 'customer') {
1963 $where = "WHERE role = 'P' ";
1966 my $query = qq|SELECT id, description
1969 ORDER BY description|;
1970 $self->{all_departments} = selectall_hashref_query($self, $dbh, $query);
1972 delete($self->{all_departments}) unless (@{ $self->{all_departments} });
1976 $main::lxdebug->leave_sub();
1980 $main::lxdebug->enter_sub();
1982 my ($self, $module, $myconfig, $table) = @_;
1985 if ($table eq "customer") {
1994 $self->all_vc($myconfig, $table, $module);
1996 # get last customers or vendors
1997 my ($query, $sth, $ref);
1999 my $dbh = $self->dbconnect($myconfig);
2004 my $transdate = "current_date";
2005 if ($self->{transdate}) {
2006 $transdate = $dbh->quote($self->{transdate});
2009 # now get the account numbers
2010 $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
2011 FROM chart c, taxkeys tk
2012 WHERE (c.link LIKE ?) AND (c.id = tk.chart_id) AND tk.id =
2013 (SELECT id FROM taxkeys WHERE (taxkeys.chart_id = c.id) AND (startdate <= $transdate) ORDER BY startdate DESC LIMIT 1)
2016 $sth = $dbh->prepare($query);
2018 do_statement($self, $sth, $query, '%' . $module . '%');
2020 $self->{accounts} = "";
2021 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
2023 foreach my $key (split(/:/, $ref->{link})) {
2024 if ($key =~ /$module/) {
2026 # cross reference for keys
2027 $xkeyref{ $ref->{accno} } = $key;
2029 push @{ $self->{"${module}_links"}{$key} },
2030 { accno => $ref->{accno},
2031 description => $ref->{description},
2032 taxkey => $ref->{taxkey_id},
2033 tax_id => $ref->{tax_id} };
2035 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2041 # get taxkeys and description
2042 $query = qq|SELECT id, taxkey, taxdescription FROM tax|;
2043 $self->{TAXKEY} = selectall_hashref_query($self, $dbh, $query);
2045 if (($module eq "AP") || ($module eq "AR")) {
2046 # get tax rates and description
2047 $query = qq|SELECT * FROM tax|;
2048 $self->{TAX} = selectall_hashref_query($self, $dbh, $query);
2054 a.cp_id, a.invnumber, a.transdate, a.${table}_id, a.datepaid,
2055 a.duedate, a.ordnumber, a.taxincluded, a.curr AS currency, a.notes,
2056 a.intnotes, a.department_id, a.amount AS oldinvtotal,
2057 a.paid AS oldtotalpaid, a.employee_id, a.gldate, a.type,
2059 d.description AS department,
2062 JOIN $table c ON (a.${table}_id = c.id)
2063 LEFT JOIN employee e ON (e.id = a.employee_id)
2064 LEFT JOIN department d ON (d.id = a.department_id)
2066 $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{id});
2068 foreach $key (keys %$ref) {
2069 $self->{$key} = $ref->{$key};
2072 my $transdate = "current_date";
2073 if ($self->{transdate}) {
2074 $transdate = $dbh->quote($self->{transdate});
2077 # now get the account numbers
2078 $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
2080 LEFT JOIN taxkeys tk ON (tk.chart_id = c.id)
2082 AND (tk.id = (SELECT id FROM taxkeys WHERE taxkeys.chart_id = c.id AND startdate <= $transdate ORDER BY startdate DESC LIMIT 1)
2083 OR c.link LIKE '%_tax%')
2086 $sth = $dbh->prepare($query);
2087 do_statement($self, $sth, $query, "%$module%");
2089 $self->{accounts} = "";
2090 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
2092 foreach my $key (split(/:/, $ref->{link})) {
2093 if ($key =~ /$module/) {
2095 # cross reference for keys
2096 $xkeyref{ $ref->{accno} } = $key;
2098 push @{ $self->{"${module}_links"}{$key} },
2099 { accno => $ref->{accno},
2100 description => $ref->{description},
2101 taxkey => $ref->{taxkey_id},
2102 tax_id => $ref->{tax_id} };
2104 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2110 # get amounts from individual entries
2113 c.accno, c.description,
2114 a.source, a.amount, a.memo, a.transdate, a.cleared, a.project_id, a.taxkey,
2118 LEFT JOIN chart c ON (c.id = a.chart_id)
2119 LEFT JOIN project p ON (p.id = a.project_id)
2120 LEFT JOIN tax t ON (t.id= (SELECT tk.tax_id FROM taxkeys tk
2121 WHERE (tk.taxkey_id=a.taxkey) AND
2122 ((CASE WHEN a.chart_id IN (SELECT chart_id FROM taxkeys WHERE taxkey_id = a.taxkey)
2123 THEN tk.chart_id = a.chart_id
2126 OR (c.link='%tax%')) AND
2127 (startdate <= a.transdate) ORDER BY startdate DESC LIMIT 1))
2128 WHERE a.trans_id = ?
2129 AND a.fx_transaction = '0'
2130 ORDER BY a.oid, a.transdate|;
2131 $sth = $dbh->prepare($query);
2132 do_statement($self, $sth, $query, $self->{id});
2134 # get exchangerate for currency
2135 $self->{exchangerate} =
2136 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate}, $fld);
2139 # store amounts in {acc_trans}{$key} for multiple accounts
2140 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
2141 $ref->{exchangerate} =
2142 $self->get_exchangerate($dbh, $self->{currency}, $ref->{transdate}, $fld);
2143 if (!($xkeyref{ $ref->{accno} } =~ /tax/)) {
2146 if (($xkeyref{ $ref->{accno} } =~ /paid/) && ($self->{type} eq "credit_note")) {
2147 $ref->{amount} *= -1;
2149 $ref->{index} = $index;
2151 push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref;
2157 d.curr AS currencies, d.closedto, d.revtrans,
2158 (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2159 (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2161 $ref = selectfirst_hashref_query($self, $dbh, $query);
2162 map { $self->{$_} = $ref->{$_} } keys %$ref;
2169 current_date AS transdate, d.curr AS currencies, d.closedto, d.revtrans,
2170 (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2171 (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2173 $ref = selectfirst_hashref_query($self, $dbh, $query);
2174 map { $self->{$_} = $ref->{$_} } keys %$ref;
2176 if ($self->{"$self->{vc}_id"}) {
2178 # only setup currency
2179 ($self->{currency}) = split(/:/, $self->{currencies});
2183 $self->lastname_used($dbh, $myconfig, $table, $module);
2185 # get exchangerate for currency
2186 $self->{exchangerate} =
2187 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate}, $fld);
2195 $main::lxdebug->leave_sub();
2199 $main::lxdebug->enter_sub();
2201 my ($self, $dbh, $myconfig, $table, $module) = @_;
2203 my $arap = ($table eq 'customer') ? "ar" : "ap";
2204 $table = $table eq "customer" ? "customer" : "vendor";
2205 my $where = "1 = 1";
2207 if ($self->{type} =~ /_order/) {
2209 $where = "quotation = '0'";
2211 if ($self->{type} =~ /_quotation/) {
2213 $where = "quotation = '1'";
2216 my $query = qq|SELECT MAX(id) FROM $arap
2217 WHERE $where AND ${table}_id > 0|;
2218 my ($trans_id) = selectrow_query($self, $dbh, $query);
2223 a.curr, a.${table}_id, a.department_id,
2224 d.description AS department,
2225 ct.name, current_date + ct.terms AS duedate
2227 LEFT JOIN $table ct ON (a.${table}_id = ct.id)
2228 LEFT JOIN department d ON (a.department_id = d.id)
2230 ($self->{currency}, $self->{"${table}_id"}, $self->{department_id},
2231 $self->{department}, $self->{$table}, $self->{duedate})
2232 = selectrow_query($self, $dbh, $query, $trans_id);
2234 $main::lxdebug->leave_sub();
2238 $main::lxdebug->enter_sub();
2240 my ($self, $myconfig, $thisdate, $days) = @_;
2242 my $dbh = $self->dbconnect($myconfig);
2247 my $dateformat = $myconfig->{dateformat};
2248 $dateformat .= "yy" if $myconfig->{dateformat} !~ /^y/;
2249 $thisdate = $dbh->quote($thisdate);
2250 $query = qq|SELECT to_date($thisdate, '$dateformat') + $days AS thisdate|;
2252 $query = qq|SELECT current_date AS thisdate|;
2255 ($thisdate) = selectrow_query($self, $dbh, $query);
2259 $main::lxdebug->leave_sub();
2265 $main::lxdebug->enter_sub();
2267 my ($self, $string) = @_;
2269 if ($string !~ /%/) {
2270 $string = "%$string%";
2273 $string =~ s/\'/\'\'/g;
2275 $main::lxdebug->leave_sub();
2281 $main::lxdebug->enter_sub();
2283 my ($self, $flds, $new, $count, $numrows) = @_;
2287 map { push @ndx, { num => $new->[$_ - 1]->{runningnumber}, ndx => $_ } }
2293 foreach my $item (sort { $a->{num} <=> $b->{num} } @ndx) {
2295 $j = $item->{ndx} - 1;
2296 map { $self->{"${_}_$i"} = $new->[$j]->{$_} } @{$flds};
2300 for $i ($count + 1 .. $numrows) {
2301 map { delete $self->{"${_}_$i"} } @{$flds};
2304 $main::lxdebug->leave_sub();
2308 $main::lxdebug->enter_sub();
2310 my ($self, $myconfig) = @_;
2314 my $dbh = $self->dbconnect_noauto($myconfig);
2316 my $query = qq|DELETE FROM status
2317 WHERE (formname = ?) AND (trans_id = ?)|;
2318 my $sth = prepare_query($self, $dbh, $query);
2320 if ($self->{formname} =~ /(check|receipt)/) {
2321 for $i (1 .. $self->{rowcount}) {
2322 do_statement($self, $sth, $query, $self->{formname}, $self->{"id_$i"} * 1);
2325 do_statement($self, $sth, $query, $self->{formname}, $self->{id});
2329 my $printed = ($self->{printed} =~ /$self->{formname}/) ? "1" : "0";
2330 my $emailed = ($self->{emailed} =~ /$self->{formname}/) ? "1" : "0";
2332 my %queued = split / /, $self->{queued};
2335 if ($self->{formname} =~ /(check|receipt)/) {
2337 # this is a check or receipt, add one entry for each lineitem
2338 my ($accno) = split /--/, $self->{account};
2339 $query = qq|INSERT INTO status (trans_id, printed, spoolfile, formname, chart_id)
2340 VALUES (?, ?, ?, ?, (SELECT c.id FROM chart c WHERE c.accno = ?))|;
2341 @values = ($printed, $queued{$self->{formname}}, $self->{prinform}, $accno);
2342 $sth = prepare_query($self, $dbh, $query);
2344 for $i (1 .. $self->{rowcount}) {
2345 if ($self->{"checked_$i"}) {
2346 do_statement($self, $sth, $query, $self->{"id_$i"}, @values);
2352 $query = qq|INSERT INTO status (trans_id, printed, emailed, spoolfile, formname)
2353 VALUES (?, ?, ?, ?, ?)|;
2354 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed,
2355 $queued{$self->{formname}}, $self->{formname});
2361 $main::lxdebug->leave_sub();
2365 $main::lxdebug->enter_sub();
2367 my ($self, $dbh) = @_;
2369 my ($query, $printed, $emailed);
2371 my $formnames = $self->{printed};
2372 my $emailforms = $self->{emailed};
2374 my $query = qq|DELETE FROM status
2375 WHERE (formname = ?) AND (trans_id = ?)|;
2376 do_query($self, $dbh, $query, $self->{formname}, $self->{id});
2378 # this only applies to the forms
2379 # checks and receipts are posted when printed or queued
2381 if ($self->{queued}) {
2382 my %queued = split / /, $self->{queued};
2384 foreach my $formname (keys %queued) {
2385 $printed = ($self->{printed} =~ /$self->{formname}/) ? "1" : "0";
2386 $emailed = ($self->{emailed} =~ /$self->{formname}/) ? "1" : "0";
2388 $query = qq|INSERT INTO status (trans_id, printed, emailed, spoolfile, formname)
2389 VALUES (?, ?, ?, ?, ?)|;
2390 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed, $queued{$formname}, $formname);
2392 $formnames =~ s/$self->{formname}//;
2393 $emailforms =~ s/$self->{formname}//;
2398 # save printed, emailed info
2399 $formnames =~ s/^ +//g;
2400 $emailforms =~ s/^ +//g;
2403 map { $status{$_}{printed} = 1 } split / +/, $formnames;
2404 map { $status{$_}{emailed} = 1 } split / +/, $emailforms;
2406 foreach my $formname (keys %status) {
2407 $printed = ($formnames =~ /$self->{formname}/) ? "1" : "0";
2408 $emailed = ($emailforms =~ /$self->{formname}/) ? "1" : "0";
2410 $query = qq|INSERT INTO status (trans_id, printed, emailed, formname)
2411 VALUES (?, ?, ?, ?)|;
2412 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed, $formname);
2415 $main::lxdebug->leave_sub();
2419 # $main::locale->text('SAVED')
2420 # $main::locale->text('DELETED')
2421 # $main::locale->text('ADDED')
2422 # $main::locale->text('PAYMENT POSTED')
2423 # $main::locale->text('POSTED')
2424 # $main::locale->text('POSTED AS NEW')
2425 # $main::locale->text('ELSE')
2426 # $main::locale->text('SAVED FOR DUNNING')
2427 # $main::locale->text('DUNNING STARTED')
2428 # $main::locale->text('PRINTED')
2429 # $main::locale->text('MAILED')
2430 # $main::locale->text('SCREENED')
2431 # $main::locale->text('CANCELED')
2432 # $main::locale->text('invoice')
2433 # $main::locale->text('proforma')
2434 # $main::locale->text('sales_order')
2435 # $main::locale->text('packing_list')
2436 # $main::locale->text('pick_list')
2437 # $main::locale->text('purchase_order')
2438 # $main::locale->text('bin_list')
2439 # $main::locale->text('sales_quotation')
2440 # $main::locale->text('request_quotation')
2443 $main::lxdebug->enter_sub();
2448 if(!exists $self->{employee_id}) {
2449 &get_employee($self, $dbh);
2453 qq|INSERT INTO history_erp (trans_id, employee_id, addition, what_done, snumbers) | .
2454 qq|VALUES (?, ?, ?, ?, ?)|;
2455 my @values = (conv_i($self->{id}), conv_i($self->{employee_id}),
2456 $self->{addition}, $self->{what_done}, "$self->{snumbers}");
2457 do_query($self, $dbh, $query, @values);
2459 $main::lxdebug->leave_sub();
2463 $main::lxdebug->enter_sub();
2467 my $trans_id = shift();
2468 my $restriction = shift();
2471 if ($trans_id ne "") {
2473 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 | .
2474 qq|FROM history_erp h | .
2475 qq|LEFT JOIN employee emp ON (emp.id = h.employee_id) | .
2476 qq|WHERE trans_id = ? |
2479 my $sth = $dbh->prepare($query) || $self->dberror($query);
2481 $sth->execute($trans_id) || $self->dberror("$query ($trans_id)");
2483 while(my $hash_ref = $sth->fetchrow_hashref()) {
2484 $hash_ref->{addition} = $main::locale->text($hash_ref->{addition});
2485 $hash_ref->{what_done} = $main::locale->text($hash_ref->{what_done});
2486 $hash_ref->{snumbers} =~ s/^.+_(.*)$/$1/g;
2487 $tempArray[$i++] = $hash_ref;
2489 $main::lxdebug->leave_sub() and return \@tempArray
2490 if ($i > 0 && $tempArray[0] ne "");
2492 $main::lxdebug->leave_sub();
2496 sub update_defaults {
2497 $main::lxdebug->enter_sub();
2499 my ($self, $myconfig, $fld, $provided_dbh) = @_;
2502 if ($provided_dbh) {
2503 $dbh = $provided_dbh;
2505 $dbh = $self->dbconnect_noauto($myconfig);
2507 my $query = qq|SELECT $fld FROM defaults FOR UPDATE|;
2508 my $sth = $dbh->prepare($query);
2510 $sth->execute || $self->dberror($query);
2511 my ($var) = $sth->fetchrow_array;
2514 $var =~ s/\d+$/ sprintf '%0*d', length($&), $&+1 /e;
2517 $query = qq|UPDATE defaults SET $fld = ?|;
2518 do_query($self, $dbh, $query, $var);
2520 if (!$provided_dbh) {
2525 $main::lxdebug->leave_sub();
2530 sub update_business {
2531 $main::lxdebug->enter_sub();
2533 my ($self, $myconfig, $business_id, $provided_dbh) = @_;
2536 if ($provided_dbh) {
2537 $dbh = $provided_dbh;
2539 $dbh = $self->dbconnect_noauto($myconfig);
2542 qq|SELECT customernumberinit FROM business
2543 WHERE id = ? FOR UPDATE|;
2544 my ($var) = selectrow_query($self, $dbh, $query, $business_id);
2546 $var =~ s/\d+$/ sprintf '%0*d', length($&), $&+1 /e;
2548 $query = qq|UPDATE business
2549 SET customernumberinit = ?
2551 do_query($self, $dbh, $query, $var, $business_id);
2553 if (!$provided_dbh) {
2558 $main::lxdebug->leave_sub();
2563 sub get_partsgroup {
2564 $main::lxdebug->enter_sub();
2566 my ($self, $myconfig, $p) = @_;
2568 my $dbh = $self->dbconnect($myconfig);
2570 my $query = qq|SELECT DISTINCT pg.id, pg.partsgroup
2572 JOIN parts p ON (p.partsgroup_id = pg.id) |;
2575 if ($p->{searchitems} eq 'part') {
2576 $query .= qq|WHERE p.inventory_accno_id > 0|;
2578 if ($p->{searchitems} eq 'service') {
2579 $query .= qq|WHERE p.inventory_accno_id IS NULL|;
2581 if ($p->{searchitems} eq 'assembly') {
2582 $query .= qq|WHERE p.assembly = '1'|;
2584 if ($p->{searchitems} eq 'labor') {
2585 $query .= qq|WHERE (p.inventory_accno_id > 0) AND (p.income_accno_id IS NULL)|;
2588 $query .= qq|ORDER BY partsgroup|;
2591 $query = qq|SELECT id, partsgroup FROM partsgroup
2592 ORDER BY partsgroup|;
2595 if ($p->{language_code}) {
2596 $query = qq|SELECT DISTINCT pg.id, pg.partsgroup,
2597 t.description AS translation
2599 JOIN parts p ON (p.partsgroup_id = pg.id)
2600 LEFT JOIN translation t ON ((t.trans_id = pg.id) AND (t.language_code = ?))
2601 ORDER BY translation|;
2602 @values = ($p->{language_code});
2605 $self->{all_partsgroup} = selectall_hashref_query($self, $dbh, $query, @values);
2608 $main::lxdebug->leave_sub();
2611 sub get_pricegroup {
2612 $main::lxdebug->enter_sub();
2614 my ($self, $myconfig, $p) = @_;
2616 my $dbh = $self->dbconnect($myconfig);
2618 my $query = qq|SELECT p.id, p.pricegroup
2621 $query .= qq| ORDER BY pricegroup|;
2624 $query = qq|SELECT id, pricegroup FROM pricegroup
2625 ORDER BY pricegroup|;
2628 $self->{all_pricegroup} = selectall_hashref_query($self, $dbh, $query);
2632 $main::lxdebug->leave_sub();
2636 # usage $form->all_years($myconfig, [$dbh])
2637 # return list of all years where bookings found
2640 $main::lxdebug->enter_sub();
2642 my ($self, $myconfig, $dbh) = @_;
2646 $dbh = $self->dbconnect($myconfig);
2651 my $query = qq|SELECT (SELECT MIN(transdate) FROM acc_trans),
2652 (SELECT MAX(transdate) FROM acc_trans)|;
2653 my ($startdate, $enddate) = selectrow_query($self, $dbh, $query);
2655 if ($myconfig->{dateformat} =~ /^yy/) {
2656 ($startdate) = split /\W/, $startdate;
2657 ($enddate) = split /\W/, $enddate;
2659 (@_) = split /\W/, $startdate;
2661 (@_) = split /\W/, $enddate;
2666 $startdate = substr($startdate,0,4);
2667 $enddate = substr($enddate,0,4);
2669 while ($enddate >= $startdate) {
2670 push @all_years, $enddate--;
2673 $dbh->disconnect if $disconnect;
2677 $main::lxdebug->leave_sub();