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_jscalendar"} = $main::jscalendar;
512 $additional_params->{"conf_lizenzen"} = $main::lizenzen;
513 $additional_params->{"conf_latex_templates"} = $main::latex;
514 $additional_params->{"conf_opendocument_templates"} = $main::opendocument_templates;
516 my @additional_param_names = keys(%{$additional_params});
517 foreach my $key ($template->param()) {
518 my $param = $self->{$key};
519 $param = $additional_params->{$key} if (grep(/^${key}$/, @additional_param_names));
520 $param = [] if (($template->query("name" => $key) eq "LOOP") && (ref($param) ne "ARRAY"));
521 $template->param($key => $param);
524 my $output = $template->output();
526 $main::lxdebug->leave_sub();
531 sub show_generic_error {
532 my ($self, $error, $title, $action) = @_;
535 $add_params->{"title"} = $title if ($title);
536 $self->{"label_error"} = $error;
540 map({ delete($self->{$_}); } qw(action));
541 map({ push(@vars, { "name" => $_, "value" => $self->{$_} })
542 if (!ref($self->{$_})); }
544 $add_params->{"SHOW_BUTTON"} = 1;
545 $add_params->{"BUTTON_LABEL"} = $action;
547 $add_params->{"VARIABLES"} = \@vars;
550 print($self->parse_html_template("generic/error", $add_params));
552 die("Error: $error\n");
555 sub show_generic_information {
556 my ($self, $error, $title) = @_;
559 $add_params->{"title"} = $title if ($title);
560 $self->{"label_information"} = $error;
563 print($self->parse_html_template("generic/information", $add_params));
565 die("Information: $error\n");
568 # write Trigger JavaScript-Code ($qty = quantity of Triggers)
569 # changed it to accept an arbitrary number of triggers - sschoeling
571 $main::lxdebug->enter_sub();
574 my $myconfig = shift;
577 # set dateform for jsscript
580 "dd.mm.yy" => "%d.%m.%Y",
581 "dd-mm-yy" => "%d-%m-%Y",
582 "dd/mm/yy" => "%d/%m/%Y",
583 "mm/dd/yy" => "%m/%d/%Y",
584 "mm-dd-yy" => "%m-%d-%Y",
585 "yyyy-mm-dd" => "%Y-%m-%d",
588 my $ifFormat = defined($dateformats{$myconfig{"dateformat"}}) ?
589 $dateformats{$myconfig{"dateformat"}} : "%d.%m.%Y";
596 inputField : "| . (shift) . qq|",
597 ifFormat :"$ifFormat",
598 align : "| . (shift) . qq|",
599 button : "| . (shift) . qq|"
605 <script type="text/javascript">
606 <!--| . join("", @triggers) . qq|//-->
610 $main::lxdebug->leave_sub();
613 } #end sub write_trigger
616 $main::lxdebug->enter_sub();
618 my ($self, $msg) = @_;
620 if ($self->{callback}) {
622 ($script, $argv) = split(/\?/, $self->{callback});
623 exec("perl", "$script", $argv);
631 $main::lxdebug->leave_sub();
634 # sort of columns removed - empty sub
636 $main::lxdebug->enter_sub();
638 my ($self, @columns) = @_;
640 $main::lxdebug->leave_sub();
646 $main::lxdebug->enter_sub(2);
648 my ($self, $myconfig, $amount, $places, $dash) = @_;
653 my $neg = ($amount =~ s/-//);
655 if (defined($places) && ($places ne '')) {
660 my ($actual_places) = ($amount =~ /\.(\d+)/);
661 $actual_places = length($actual_places);
662 $places = $actual_places > $places ? $actual_places : $places;
665 $amount = $self->round_amount($amount, $places);
668 my @d = map { s/\d//g; reverse split // } my $tmp = $myconfig->{numberformat}; # get delim chars
669 my @p = split(/\./, $amount); # split amount at decimal point
671 $p[0] =~ s/\B(?=(...)*$)/$d[1]/g if $d[1]; # add 1,000 delimiters
674 $amount .= $d[0].$p[1].(0 x ($places - length $p[1])) if ($places || $p[1] ne '');
677 ($dash =~ /-/) ? ($neg ? "($amount)" : "$amount" ) :
678 ($dash =~ /DRCR/) ? ($neg ? "$amount DR" : "$amount CR" ) :
679 ($neg ? "-$amount" : "$amount" ) ;
683 $main::lxdebug->leave_sub(2);
688 $main::lxdebug->enter_sub(2);
690 my ($self, $myconfig, $amount) = @_;
692 if ( ($myconfig->{numberformat} eq '1.000,00')
693 || ($myconfig->{numberformat} eq '1000,00')) {
698 if ($myconfig->{numberformat} eq "1'000.00") {
704 $main::lxdebug->leave_sub(2);
706 return ($amount * 1);
710 $main::lxdebug->enter_sub(2);
712 my ($self, $amount, $places) = @_;
715 # Rounding like "Kaufmannsrunden"
716 # Descr. http://de.wikipedia.org/wiki/Rundung
718 # http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q4.13.html
721 $amount = $amount * (10**($places));
722 $round_amount = int($amount + .5 * ($amount <=> 0)) / (10**($places));
724 $main::lxdebug->leave_sub(2);
726 return $round_amount;
731 $main::lxdebug->enter_sub();
733 my ($self, $myconfig, $userspath) = @_;
734 my ($template, $out);
738 $self->{"cwd"} = getcwd();
739 $self->{"tmpdir"} = $self->{cwd} . "/${userspath}";
741 if ($self->{"format"} =~ /(opendocument|oasis)/i) {
742 $template = OpenDocumentTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
743 } elsif ($self->{"format"} =~ /(postscript|pdf)/i) {
744 $ENV{"TEXINPUTS"} = ".:" . getcwd() . "/" . $myconfig->{"templates"} . ":" . $ENV{"TEXINPUTS"};
745 $template = LaTeXTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
746 } elsif (($self->{"format"} =~ /html/i) ||
747 (!$self->{"format"} && ($self->{"IN"} =~ /html$/i))) {
748 $template = HTMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
749 } elsif (($self->{"format"} =~ /xml/i) ||
750 (!$self->{"format"} && ($self->{"IN"} =~ /xml$/i))) {
751 $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
752 } elsif ( $self->{"format"} =~ /elsterwinston/i ) {
753 $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
754 } elsif ( $self->{"format"} =~ /elstertaxbird/i ) {
755 $template = XMLTemplate->new($self->{"IN"}, $self, $myconfig, $userspath);
756 } elsif ( defined $self->{'format'}) {
757 $self->error("Outputformat not defined. This may be a future feature: $self->{'format'}");
758 } elsif ( $self->{'format'} eq '' ) {
759 $self->error("No Outputformat given: $self->{'format'}");
760 } else { #Catch the rest
761 $self->error("Outputformat not defined: $self->{'format'}");
764 # Copy the notes from the invoice/sales order etc. back to the variable "notes" because that is where most templates expect it to be.
765 $self->{"notes"} = $self->{ $self->{"formname"} . "notes" };
767 map({ $self->{"employee_${_}"} = $myconfig->{$_}; }
768 qw(email tel fax name signature company address businessnumber
769 co_ustid taxnumber duns));
770 map({ $self->{"employee_${_}"} =~ s/\\n/\n/g; }
771 qw(company address signature));
772 map({ $self->{$_} =~ s/\\n/\n/g; } qw(company address signature));
774 $self->{copies} = 1 if (($self->{copies} *= 1) <= 0);
776 # OUT is used for the media, screen, printer, email
777 # for postscript we store a copy in a temporary file
779 my $prepend_userspath;
781 if (!$self->{tmpfile}) {
782 $self->{tmpfile} = "${fileid}.$self->{IN}";
783 $prepend_userspath = 1;
786 $prepend_userspath = 1 if substr($self->{tmpfile}, 0, length $userspath) eq $userspath;
788 $self->{tmpfile} =~ s|.*/||;
789 $self->{tmpfile} =~ s/[^a-zA-Z0-9\._\ \-]//g;
790 $self->{tmpfile} = "$userspath/$self->{tmpfile}" if $prepend_userspath;
792 if ($template->uses_temp_file() || $self->{media} eq 'email') {
794 $self->{OUT} = ">$self->{tmpfile}";
798 open(OUT, "$self->{OUT}") or $self->error("$self->{OUT} : $!");
800 open(OUT, ">-") or $self->error("STDOUT : $!");
804 if (!$template->parse(*OUT)) {
806 $self->error("$self->{IN} : " . $template->get_error());
811 if ($template->uses_temp_file() || $self->{media} eq 'email') {
813 if ($self->{media} eq 'email') {
817 my $mail = new Mailer;
819 map { $mail->{$_} = $self->{$_} }
820 qw(cc bcc subject message version format);
821 $mail->{charset} = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
822 $mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email};
823 $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
824 $mail->{fileid} = "$fileid.";
825 $myconfig->{signature} =~ s/\\r\\n/\\n/g;
827 # if we send html or plain text inline
828 if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
829 $mail->{contenttype} = "text/html";
831 $mail->{message} =~ s/\r\n/<br>\n/g;
832 $myconfig->{signature} =~ s/\\n/<br>\n/g;
833 $mail->{message} .= "<br>\n-- <br>\n$myconfig->{signature}\n<br>";
835 open(IN, $self->{tmpfile})
836 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
838 $mail->{message} .= $_;
845 if (!$self->{"do_not_attach"}) {
846 @{ $mail->{attachments} } =
847 ({ "filename" => $self->{"tmpfile"},
848 "name" => $self->{"attachment_filename"} ?
849 $self->{"attachment_filename"} : $self->{"tmpfile"} });
852 $mail->{message} =~ s/\r\n/\n/g;
853 $myconfig->{signature} =~ s/\\n/\n/g;
854 $mail->{message} .= "\n-- \n$myconfig->{signature}";
858 my $err = $mail->send();
859 $self->error($self->cleanup . "$err") if ($err);
865 my $numbytes = (-s $self->{tmpfile});
866 open(IN, $self->{tmpfile})
867 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
869 $self->{copies} = 1 unless $self->{media} eq 'printer';
871 chdir("$self->{cwd}");
872 #print(STDERR "Kopien $self->{copies}\n");
873 #print(STDERR "OUT $self->{OUT}\n");
874 for my $i (1 .. $self->{copies}) {
876 open(OUT, $self->{OUT})
877 or $self->error($self->cleanup . "$self->{OUT} : $!");
879 $self->{attachment_filename} = ($self->{attachment_filename})
880 ? $self->{attachment_filename}
881 : $self->generate_attachment_filename();
884 print qq|Content-Type: | . $template->get_mime_type() . qq|
885 Content-Disposition: attachment; filename="$self->{attachment_filename}"
886 Content-Length: $numbytes
890 open(OUT, ">-") or $self->error($self->cleanup . "$!: STDOUT");
910 chdir("$self->{cwd}");
911 $main::lxdebug->leave_sub();
914 sub generate_attachment_filename {
917 my %formname_translations = (
918 bin_list => $main::locale->text('Bin List'),
919 credit_note => $main::locale->text('Credit Note'),
920 invoice => $main::locale->text('Invoice'),
921 packing_list => $main::locale->text('Packing List'),
922 pick_list => $main::locale->text('Pick List'),
923 proforma => $main::locale->text('Proforma Invoice'),
924 purchase_order => $main::locale->text('Purchase Order'),
925 request_quotation => $main::locale->text('RFQ'),
926 sales_order => $main::locale->text('Confirmation'),
927 sales_quotation => $main::locale->text('Quotation'),
928 storno_invoice => $main::locale->text('Storno Invoice'),
929 storno_packing_list => $main::locale->text('Storno Packing List'),
932 my $attachment_filename = $formname_translations{$self->{"formname"}};
934 (grep { $self->{"type"} eq $_ } qw(invoice credit_note)) ? "inv"
935 : ($self->{"type"} =~ /_quotation$/) ? "quo"
938 if ($attachment_filename && $self->{"${prefix}number"}) {
939 $attachment_filename .= "_" . $self->{"${prefix}number"}
940 . ( $self->{format} =~ /pdf/i ? ".pdf"
941 : $self->{format} =~ /postscript/i ? ".ps"
942 : $self->{format} =~ /opendocument/i ? ".odt"
943 : $self->{format} =~ /html/i ? ".html"
945 $attachment_filename =~ s/ /_/g;
946 my %umlaute = ( "ä" => "ae", "ö" => "oe", "ü" => "ue",
947 "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue", "ß" => "ss");
948 map { $attachment_filename =~ s/$_/$umlaute{$_}/g } keys %umlaute;
950 $attachment_filename = "";
953 return $attachment_filename;
957 $main::lxdebug->enter_sub();
961 chdir("$self->{tmpdir}");
964 if (-f "$self->{tmpfile}.err") {
965 open(FH, "$self->{tmpfile}.err");
970 if ($self->{tmpfile}) {
971 $self->{tmpfile} =~ s|.*/||g;
973 $self->{tmpfile} =~ s/\.\w+$//g;
974 my $tmpfile = $self->{tmpfile};
975 unlink(<$tmpfile.*>);
978 chdir("$self->{cwd}");
980 $main::lxdebug->leave_sub();
986 $main::lxdebug->enter_sub();
988 my ($self, $date, $myconfig) = @_;
990 if ($date && $date =~ /\D/) {
992 if ($myconfig->{dateformat} =~ /^yy/) {
993 ($yy, $mm, $dd) = split /\D/, $date;
995 if ($myconfig->{dateformat} =~ /^mm/) {
996 ($mm, $dd, $yy) = split /\D/, $date;
998 if ($myconfig->{dateformat} =~ /^dd/) {
999 ($dd, $mm, $yy) = split /\D/, $date;
1004 $yy = ($yy < 70) ? $yy + 2000 : $yy;
1005 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
1007 $dd = "0$dd" if ($dd < 10);
1008 $mm = "0$mm" if ($mm < 10);
1010 $date = "$yy$mm$dd";
1013 $main::lxdebug->leave_sub();
1018 # Database routines used throughout
1021 $main::lxdebug->enter_sub(2);
1023 my ($self, $myconfig) = @_;
1025 # connect to database
1027 DBI->connect($myconfig->{dbconnect},
1028 $myconfig->{dbuser}, $myconfig->{dbpasswd})
1032 if ($myconfig->{dboptions}) {
1033 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1036 $main::lxdebug->leave_sub(2);
1041 sub dbconnect_noauto {
1042 $main::lxdebug->enter_sub();
1044 my ($self, $myconfig) = @_;
1046 # connect to database
1048 DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser},
1049 $myconfig->{dbpasswd}, { AutoCommit => 0 })
1053 if ($myconfig->{dboptions}) {
1054 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1057 $main::lxdebug->leave_sub();
1062 sub update_balance {
1063 $main::lxdebug->enter_sub();
1065 my ($self, $dbh, $table, $field, $where, $value, @values) = @_;
1067 # if we have a value, go do it
1070 # retrieve balance from table
1071 my $query = "SELECT $field FROM $table WHERE $where FOR UPDATE";
1072 my $sth = prepare_execute_query($self, $dbh, $query, @values);
1073 my ($balance) = $sth->fetchrow_array;
1079 $query = "UPDATE $table SET $field = $balance WHERE $where";
1080 do_query($self, $dbh, $query, @values);
1082 $main::lxdebug->leave_sub();
1085 sub update_exchangerate {
1086 $main::lxdebug->enter_sub();
1088 my ($self, $dbh, $curr, $transdate, $buy, $sell) = @_;
1090 # some sanity check for currency
1092 $main::lxdebug->leave_sub();
1096 my $query = qq|SELECT e.curr FROM exchangerate e
1097 WHERE e.curr = ? AND e.transdate = ?
1099 my $sth = prepare_execute_query($self, $dbh, $query, $curr, $transdate);
1102 if ($buy != 0 && $sell != 0) {
1103 $set = "buy = $buy, sell = $sell";
1104 } elsif ($buy != 0) {
1105 $set = "buy = $buy";
1106 } elsif ($sell != 0) {
1107 $set = "sell = $sell";
1110 if ($sth->fetchrow_array) {
1111 $query = qq|UPDATE exchangerate
1116 $query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
1117 VALUES (?, $buy, $sell, ?)|;
1120 do_query($self, $dbh, $query, $curr, $transdate);
1122 $main::lxdebug->leave_sub();
1125 sub save_exchangerate {
1126 $main::lxdebug->enter_sub();
1128 my ($self, $myconfig, $currency, $transdate, $rate, $fld) = @_;
1130 my $dbh = $self->dbconnect($myconfig);
1132 my ($buy, $sell) = (0, 0);
1133 $buy = $rate if $fld eq 'buy';
1134 $sell = $rate if $fld eq 'sell';
1136 $self->update_exchangerate($dbh, $currency, $transdate, $buy, $sell);
1140 $main::lxdebug->leave_sub();
1143 sub get_exchangerate {
1144 $main::lxdebug->enter_sub();
1146 my ($self, $dbh, $curr, $transdate, $fld) = @_;
1148 unless ($transdate) {
1149 $main::lxdebug->leave_sub();
1153 my $query = qq|SELECT e.$fld FROM exchangerate e
1154 WHERE e.curr = ? AND e.transdate = ?|;
1155 my ($exchangerate) = selectrow_query($self, $dbh, $query, $curr, $transdate);
1157 if (!$exchangerate) {
1161 $main::lxdebug->leave_sub();
1163 return $exchangerate;
1166 sub check_exchangerate {
1167 $main::lxdebug->enter_sub();
1169 my ($self, $myconfig, $currency, $transdate, $fld) = @_;
1171 unless ($transdate) {
1172 $main::lxdebug->leave_sub();
1176 my $dbh = $self->dbconnect($myconfig);
1178 my $query = qq|SELECT e.$fld FROM exchangerate e
1179 WHERE e.curr = ? AND e.transdate = ?|;
1180 my ($exchangerate) = selectrow_query($self, $dbh, $query, $currency, $transdate);
1183 $main::lxdebug->leave_sub();
1185 return $exchangerate;
1188 sub set_payment_options {
1189 $main::lxdebug->enter_sub();
1191 my ($self, $myconfig, $transdate) = @_;
1193 if ($self->{payment_id}) {
1195 my $dbh = $self->dbconnect($myconfig);
1198 qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, p.description_long | .
1199 qq|FROM payment_terms p | .
1202 ($self->{terms_netto}, $self->{terms_skonto}, $self->{percent_skonto},
1203 $self->{payment_terms}) =
1204 selectrow_query($self, $dbh, $query, $self->{payment_id});
1206 if ($transdate eq "") {
1207 if ($self->{invdate}) {
1208 $transdate = $self->{invdate};
1210 $transdate = $self->{transdate};
1215 qq|SELECT ?::date + ?::integer AS netto_date, ?::date + ?::integer AS skonto_date | .
1216 qq|FROM payment_terms|;
1217 ($self->{netto_date}, $self->{skonto_date}) =
1218 selectrow_query($self, $dbh, $query, $transdate, $self->{terms_netto}, $transdate, $self->{terms_skonto});
1220 my $total = ($self->{invtotal}) ? $self->{invtotal} : $self->{ordtotal};
1221 my $skonto_amount = $self->parse_amount($myconfig, $total) *
1222 $self->{percent_skonto};
1224 $self->{skonto_amount} =
1225 $self->format_amount($myconfig, $skonto_amount, 2);
1227 if ($self->{"language_id"}) {
1229 qq|SELECT t.description_long, l.output_numberformat, l.output_dateformat, l.output_longdates | .
1230 qq|FROM translation_payment_terms t | .
1231 qq|LEFT JOIN language l ON t.language_id = l.id | .
1232 qq|WHERE (t.language_id = ?) AND (t.payment_terms_id = ?)|;
1233 my ($description_long, $output_numberformat, $output_dateformat,
1234 $output_longdates) =
1235 selectrow_query($self, $dbh, $query,
1236 $self->{"language_id"}, $self->{"payment_id"});
1238 $self->{payment_terms} = $description_long if ($description_long);
1240 if ($output_dateformat) {
1241 foreach my $key (qw(netto_date skonto_date)) {
1243 $main::locale->reformat_date($myconfig, $self->{$key},
1249 if ($output_numberformat &&
1250 ($output_numberformat ne $myconfig->{"numberformat"})) {
1251 my $saved_numberformat = $myconfig->{"numberformat"};
1252 $myconfig->{"numberformat"} = $output_numberformat;
1253 $self->{skonto_amount} =
1254 $self->format_amount($myconfig, $skonto_amount, 2);
1255 $myconfig->{"numberformat"} = $saved_numberformat;
1259 $self->{payment_terms} =~ s/<%netto_date%>/$self->{netto_date}/g;
1260 $self->{payment_terms} =~ s/<%skonto_date%>/$self->{skonto_date}/g;
1261 $self->{payment_terms} =~ s/<%skonto_amount%>/$self->{skonto_amount}/g;
1262 $self->{payment_terms} =~ s/<%total%>/$self->{total}/g;
1263 $self->{payment_terms} =~ s/<%invtotal%>/$self->{invtotal}/g;
1264 $self->{payment_terms} =~ s/<%currency%>/$self->{currency}/g;
1265 $self->{payment_terms} =~ s/<%terms_netto%>/$self->{terms_netto}/g;
1266 $self->{payment_terms} =~ s/<%account_number%>/$self->{account_number}/g;
1267 $self->{payment_terms} =~ s/<%bank%>/$self->{bank}/g;
1268 $self->{payment_terms} =~ s/<%bank_code%>/$self->{bank_code}/g;
1273 $main::lxdebug->leave_sub();
1277 sub get_template_language {
1278 $main::lxdebug->enter_sub();
1280 my ($self, $myconfig) = @_;
1282 my $template_code = "";
1284 if ($self->{language_id}) {
1285 my $dbh = $self->dbconnect($myconfig);
1286 my $query = qq|SELECT template_code FROM language WHERE id = ?|;
1287 ($template_code) = selectrow_query($self, $dbh, $query, $self->{language_id});
1291 $main::lxdebug->leave_sub();
1293 return $template_code;
1296 sub get_printer_code {
1297 $main::lxdebug->enter_sub();
1299 my ($self, $myconfig) = @_;
1301 my $template_code = "";
1303 if ($self->{printer_id}) {
1304 my $dbh = $self->dbconnect($myconfig);
1305 my $query = qq|SELECT template_code, printer_command FROM printers WHERE id = ?|;
1306 ($template_code, $self->{printer_command}) = selectrow_query($self, $dbh, $query, $self->{printer_id});
1310 $main::lxdebug->leave_sub();
1312 return $template_code;
1316 $main::lxdebug->enter_sub();
1318 my ($self, $myconfig) = @_;
1320 my $template_code = "";
1322 if ($self->{shipto_id}) {
1323 my $dbh = $self->dbconnect($myconfig);
1324 my $query = qq|SELECT * FROM shipto WHERE shipto_id = ?|;
1325 my $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{shipto_id});
1326 map({ $self->{$_} = $ref->{$_} } keys(%$ref));
1330 $main::lxdebug->leave_sub();
1334 $main::lxdebug->enter_sub();
1336 my ($self, $dbh, $id, $module) = @_;
1340 foreach my $item (qw(name department_1 department_2 street zipcode city country
1341 contact phone fax email)) {
1342 if ($self->{"shipto$item"}) {
1343 $shipto = 1 if ($self->{$item} ne $self->{"shipto$item"});
1345 push(@values, $self->{"shipto${item}"});
1348 if ($self->{shipto_id}) {
1349 my $query = qq|UPDATE shipto set
1351 shiptodepartment_1 = ?,
1352 shiptodepartment_2 = ?,
1361 WHERE shipto_id = ?|;
1362 do_query($self, $dbh, $query, @values, $self->{shipto_id});
1364 my $query = qq|SELECT * FROM shipto
1365 WHERE shiptoname = ? AND
1366 shiptodepartment_1 = ? AND
1367 shiptodepartment_2 = ? AND
1368 shiptostreet = ? AND
1369 shiptozipcode = ? AND
1371 shiptocountry = ? AND
1372 shiptocontact = ? AND
1376 my $insert_check = selectfirst_hashref_query($self, $dbh, $query, @values);
1379 qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2,
1380 shiptostreet, shiptozipcode, shiptocity, shiptocountry,
1381 shiptocontact, shiptophone, shiptofax, shiptoemail, module)
1382 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
1383 do_query($self, $dbh, $query, $id, @values, $module);
1388 $main::lxdebug->leave_sub();
1392 $main::lxdebug->enter_sub();
1394 my ($self, $dbh) = @_;
1396 my $query = qq|SELECT id, name FROM employee WHERE login = ?|;
1397 ($self->{employee_id}, $self->{employee}) = selectrow_query($self, $dbh, $query, $self->{login});
1398 $self->{employee_id} *= 1;
1400 $main::lxdebug->leave_sub();
1404 $main::lxdebug->enter_sub();
1406 my ($self, $myconfig, $salesman_id) = @_;
1408 $main::lxdebug->leave_sub() and return unless $salesman_id;
1410 my $dbh = $self->dbconnect($myconfig);
1413 selectrow_query($self, $dbh, qq|SELECT login FROM employee WHERE id = ?|,
1417 my $user = new User($main::memberfile, $login);
1418 map({ $self->{"salesman_$_"} = $user->{$_}; }
1419 qw(address businessnumber co_ustid company duns email fax name
1421 $self->{salesman_login} = $login;
1423 $self->{salesman_name} = $login
1424 if ($self->{salesman_name} eq "");
1426 map({ $self->{"salesman_$_"} =~ s/\\n/\n/g; } qw(address company));
1431 $main::lxdebug->leave_sub();
1435 $main::lxdebug->enter_sub();
1437 my ($self, $myconfig) = @_;
1439 my $dbh = $self->dbconnect($myconfig);
1440 my $query = qq|SELECT current_date + terms_netto FROM payment_terms WHERE id = ?|;
1441 ($self->{duedate}) = selectrow_query($self, $dbh, $query, $self->{payment_id});
1444 $main::lxdebug->leave_sub();
1448 $main::lxdebug->enter_sub();
1450 my ($self, $dbh, $id, $key) = @_;
1452 $key = "all_contacts" unless ($key);
1455 qq|SELECT cp_id, cp_cv_id, cp_name, cp_givenname, cp_abteilung | .
1456 qq|FROM contacts | .
1457 qq|WHERE cp_cv_id = ? | .
1458 qq|ORDER BY lower(cp_name)|;
1460 $self->{$key} = selectall_hashref_query($self, $dbh, $query, $id);
1462 $main::lxdebug->leave_sub();
1466 $main::lxdebug->enter_sub();
1468 my ($self, $dbh, $key) = @_;
1470 my ($all, $old_id, $where, @values);
1472 if (ref($key) eq "HASH") {
1475 $key = "ALL_PROJECTS";
1477 foreach my $p (keys(%{$params})) {
1479 $all = $params->{$p};
1480 } elsif ($p eq "old_id") {
1481 $old_id = $params->{$p};
1482 } elsif ($p eq "key") {
1483 $key = $params->{$p};
1489 $where = "WHERE active ";
1491 if (ref($old_id) eq "ARRAY") {
1492 my @ids = grep({ $_ } @{$old_id});
1494 $where .= " OR id IN (" . join(",", map({ "?" } @ids)) . ") ";
1495 push(@values, @ids);
1498 $where .= " OR (id = ?) ";
1499 push(@values, $old_id);
1505 qq|SELECT id, projectnumber, description, active | .
1508 qq|ORDER BY lower(projectnumber)|;
1510 $self->{$key} = selectall_hashref_query($self, $dbh, $query, @values);
1512 $main::lxdebug->leave_sub();
1516 $main::lxdebug->enter_sub();
1518 my ($self, $dbh, $vc_id, $key) = @_;
1520 $key = "all_shipto" unless ($key);
1522 # get shipping addresses
1524 qq|SELECT shipto_id, shiptoname, shiptodepartment_1 | .
1526 qq|WHERE trans_id = ?|;
1528 $self->{$key} = selectall_hashref_query($self, $dbh, $query, $vc_id);
1530 $main::lxdebug->leave_sub();
1534 $main::lxdebug->enter_sub();
1536 my ($self, $dbh, $key) = @_;
1538 $key = "all_printers" unless ($key);
1540 my $query = qq|SELECT id, printer_description, printer_command, template_code FROM printers|;
1542 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1544 $main::lxdebug->leave_sub();
1548 $main::lxdebug->enter_sub();
1550 my ($self, $dbh, $params) = @_;
1552 $key = $params->{key};
1553 $key = "all_charts" unless ($key);
1555 my $transdate = quote_db_date($params->{transdate});
1558 qq|SELECT c.accno, c.description, c.link, tk.taxkey_id, tk.tax_id | .
1560 qq|LEFT JOIN taxkeys tk ON | .
1561 qq|(tk.id = (SELECT id FROM taxkeys | .
1562 qq| WHERE taxkeys.chart_id = c.id AND startdate <= $transdate | .
1563 qq| ORDER BY startdate DESC LIMIT 1)) | .
1564 qq|ORDER BY c.accno|;
1566 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1568 $main::lxdebug->leave_sub();
1571 sub _get_taxcharts {
1572 $main::lxdebug->enter_sub();
1574 my ($self, $dbh, $key) = @_;
1576 $key = "all_taxcharts" unless ($key);
1578 my $query = qq|SELECT * FROM tax ORDER BY taxkey|;
1580 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1582 $main::lxdebug->leave_sub();
1586 $main::lxdebug->enter_sub();
1588 my ($self, $dbh, $key) = @_;
1590 $key = "all_taxzones" unless ($key);
1592 my $query = qq|SELECT * FROM tax_zones ORDER BY id|;
1594 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1596 $main::lxdebug->leave_sub();
1599 sub _get_employees {
1600 $main::lxdebug->enter_sub();
1602 my ($self, $dbh, $key) = @_;
1604 $key = "all_employees" unless ($key);
1606 selectall_hashref_query($self, $dbh, qq|SELECT * FROM employee|);
1608 $main::lxdebug->leave_sub();
1611 sub _get_business_types {
1612 $main::lxdebug->enter_sub();
1614 my ($self, $dbh, $key) = @_;
1616 $key = "all_business_types" unless ($key);
1618 selectall_hashref_query($self, $dbh, qq|SELECT * FROM business|);
1620 $main::lxdebug->leave_sub();
1623 sub _get_languages {
1624 $main::lxdebug->enter_sub();
1626 my ($self, $dbh, $key) = @_;
1628 $key = "all_languages" unless ($key);
1630 my $query = qq|SELECT * FROM language ORDER BY id|;
1632 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1634 $main::lxdebug->leave_sub();
1637 sub _get_dunning_configs {
1638 $main::lxdebug->enter_sub();
1640 my ($self, $dbh, $key) = @_;
1642 $key = "all_dunning_configs" unless ($key);
1644 my $query = qq|SELECT * FROM dunning_config ORDER BY dunning_level|;
1646 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1648 $main::lxdebug->leave_sub();
1651 sub _get_currencies {
1652 $main::lxdebug->enter_sub();
1654 my ($self, $dbh, $key) = @_;
1656 $key = "all_currencies" unless ($key);
1658 my $query = qq|SELECT curr AS currency FROM defaults|;
1660 $self->{$key} = [split(/\:/ , selectfirst_hashref_query($self, $dbh, $query)->{currency})];
1662 $main::lxdebug->leave_sub();
1666 $main::lxdebug->enter_sub();
1668 my ($self, $dbh, $key) = @_;
1670 $key = "all_payments" unless ($key);
1672 my $query = qq|SELECT * FROM payment_terms ORDER BY id|;
1674 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1676 $main::lxdebug->leave_sub();
1679 sub _get_customers {
1680 $main::lxdebug->enter_sub();
1682 my ($self, $dbh, $key) = @_;
1684 $key = "all_customers" unless ($key);
1686 my $query = qq|SELECT * FROM customer|;
1688 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1690 $main::lxdebug->leave_sub();
1694 $main::lxdebug->enter_sub();
1696 my ($self, $dbh, $key) = @_;
1698 $key = "all_vendors" unless ($key);
1700 my $query = qq|SELECT * FROM vendor|;
1702 $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1704 $main::lxdebug->leave_sub();
1708 $main::lxdebug->enter_sub();
1713 my $dbh = $self->dbconnect(\%main::myconfig);
1714 my ($sth, $query, $ref);
1716 my $vc = $self->{"vc"} eq "customer" ? "customer" : "vendor";
1717 my $vc_id = $self->{"${vc}_id"};
1719 if ($params{"contacts"}) {
1720 $self->_get_contacts($dbh, $vc_id, $params{"contacts"});
1723 if ($params{"shipto"}) {
1724 $self->_get_shipto($dbh, $vc_id, $params{"shipto"});
1727 if ($params{"projects"} || $params{"all_projects"}) {
1728 $self->_get_projects($dbh, $params{"all_projects"} ?
1729 $params{"all_projects"} : $params{"projects"},
1730 $params{"all_projects"} ? 1 : 0);
1733 if ($params{"printers"}) {
1734 $self->_get_printers($dbh, $params{"printers"});
1737 if ($params{"languages"}) {
1738 $self->_get_languages($dbh, $params{"languages"});
1741 if ($params{"charts"}) {
1742 $self->_get_charts($dbh, $params{"charts"});
1745 if ($params{"taxcharts"}) {
1746 $self->_get_taxcharts($dbh, $params{"taxcharts"});
1749 if ($params{"taxzones"}) {
1750 $self->_get_taxzones($dbh, $params{"taxzones"});
1753 if ($params{"employees"}) {
1754 $self->_get_employees($dbh, $params{"employees"});
1757 if ($params{"business_types"}) {
1758 $self->_get_business_types($dbh, $params{"business_types"});
1761 if ($params{"dunning_configs"}) {
1762 $self->_get_dunning_configs($dbh, $params{"dunning_configs"});
1765 if($params{"currencies"}) {
1766 $self->_get_currencies($dbh, $params{"currencies"});
1769 if($params{"customers"}) {
1770 $self->_get_customers($dbh, $params{"customers"});
1773 if($params{"vendors"}) {
1774 $self->_get_vendors($dbh, $params{"vendors"});
1777 if($params{"payments"}) {
1778 $self->_get_payments($dbh, $params{"payments"});
1783 $main::lxdebug->leave_sub();
1786 # this sub gets the id and name from $table
1788 $main::lxdebug->enter_sub();
1790 my ($self, $myconfig, $table) = @_;
1792 # connect to database
1793 my $dbh = $self->dbconnect($myconfig);
1795 $table = $table eq "customer" ? "customer" : "vendor";
1796 my $arap = $self->{arap} eq "ar" ? "ar" : "ap";
1798 my ($query, @values);
1800 if (!$self->{openinvoices}) {
1802 if ($self->{customernumber} ne "") {
1803 $where = qq|(vc.customernumber ILIKE ?)|;
1804 push(@values, '%' . $self->{customernumber} . '%');
1806 $where = qq|(vc.name ILIKE ?)|;
1807 push(@values, '%' . $self->{$table} . '%');
1811 qq~SELECT vc.id, vc.name,
1812 vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
1814 WHERE $where AND (NOT vc.obsolete)
1818 qq~SELECT DISTINCT vc.id, vc.name,
1819 vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
1821 JOIN $table vc ON (a.${table}_id = vc.id)
1822 WHERE NOT (a.amount = a.paid) AND (vc.name ILIKE ?)
1824 push(@values, '%' . $self->{$table} . '%');
1827 $self->{name_list} = selectall_hashref_query($self, $dbh, $query, @values);
1829 $main::lxdebug->leave_sub();
1831 return scalar(@{ $self->{name_list} });
1834 # the selection sub is used in the AR, AP, IS, IR and OE module
1837 $main::lxdebug->enter_sub();
1839 my ($self, $myconfig, $table, $module) = @_;
1842 my $dbh = $self->dbconnect($myconfig);
1844 $table = $table eq "customer" ? "customer" : "vendor";
1846 my $query = qq|SELECT count(*) FROM $table|;
1847 my ($count) = selectrow_query($self, $dbh, $query);
1849 # build selection list
1850 if ($count < $myconfig->{vclimit}) {
1851 $query = qq|SELECT id, name, salesman_id
1852 FROM $table WHERE NOT obsolete
1854 $self->{"all_$table"} = selectall_hashref_query($self, $dbh, $query);
1858 $self->get_employee($dbh);
1860 # setup sales contacts
1861 $query = qq|SELECT e.id, e.name
1863 WHERE (e.sales = '1') AND (NOT e.id = ?)|;
1864 $self->{all_employees} = selectall_hashref_query($self, $dbh, $query, $self->{employee_id});
1867 push(@{ $self->{all_employees} },
1868 { id => $self->{employee_id},
1869 name => $self->{employee} });
1871 # sort the whole thing
1872 @{ $self->{all_employees} } =
1873 sort { $a->{name} cmp $b->{name} } @{ $self->{all_employees} };
1875 if ($module eq 'AR') {
1877 # prepare query for departments
1878 $query = qq|SELECT id, description
1881 ORDER BY description|;
1884 $query = qq|SELECT id, description
1886 ORDER BY description|;
1889 $self->{all_departments} = selectall_hashref_query($self, $dbh, $query);
1892 $query = qq|SELECT id, description
1896 $self->{languages} = selectall_hashref_query($self, $dbh, $query);
1899 $query = qq|SELECT printer_description, id
1901 ORDER BY printer_description|;
1903 $self->{printers} = selectall_hashref_query($self, $dbh, $query);
1906 $query = qq|SELECT id, description
1910 $self->{payment_terms} = selectall_hashref_query($self, $dbh, $query);
1914 $main::lxdebug->leave_sub();
1917 sub language_payment {
1918 $main::lxdebug->enter_sub();
1920 my ($self, $myconfig) = @_;
1922 my $dbh = $self->dbconnect($myconfig);
1924 my $query = qq|SELECT id, description
1928 $self->{languages} = selectall_hashref_query($self, $dbh, $query);
1931 $query = qq|SELECT printer_description, id
1933 ORDER BY printer_description|;
1935 $self->{printers} = selectall_hashref_query($self, $dbh, $query);
1938 $query = qq|SELECT id, description
1942 $self->{payment_terms} = selectall_hashref_query($self, $dbh, $query);
1944 # get buchungsgruppen
1945 $query = qq|SELECT id, description
1946 FROM buchungsgruppen|;
1948 $self->{BUCHUNGSGRUPPEN} = selectall_hashref_query($self, $dbh, $query);
1951 $main::lxdebug->leave_sub();
1954 # this is only used for reports
1955 sub all_departments {
1956 $main::lxdebug->enter_sub();
1958 my ($self, $myconfig, $table) = @_;
1960 my $dbh = $self->dbconnect($myconfig);
1963 if ($table eq 'customer') {
1964 $where = "WHERE role = 'P' ";
1967 my $query = qq|SELECT id, description
1970 ORDER BY description|;
1971 $self->{all_departments} = selectall_hashref_query($self, $dbh, $query);
1973 delete($self->{all_departments}) unless (@{ $self->{all_departments} });
1977 $main::lxdebug->leave_sub();
1981 $main::lxdebug->enter_sub();
1983 my ($self, $module, $myconfig, $table) = @_;
1986 if ($table eq "customer") {
1995 $self->all_vc($myconfig, $table, $module);
1997 # get last customers or vendors
1998 my ($query, $sth, $ref);
2000 my $dbh = $self->dbconnect($myconfig);
2005 my $transdate = "current_date";
2006 if ($self->{transdate}) {
2007 $transdate = $dbh->quote($self->{transdate});
2010 # now get the account numbers
2011 $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
2012 FROM chart c, taxkeys tk
2013 WHERE (c.link LIKE ?) AND (c.id = tk.chart_id) AND tk.id =
2014 (SELECT id FROM taxkeys WHERE (taxkeys.chart_id = c.id) AND (startdate <= $transdate) ORDER BY startdate DESC LIMIT 1)
2017 $sth = $dbh->prepare($query);
2019 do_statement($self, $sth, $query, '%' . $module . '%');
2021 $self->{accounts} = "";
2022 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
2024 foreach my $key (split(/:/, $ref->{link})) {
2025 if ($key =~ /$module/) {
2027 # cross reference for keys
2028 $xkeyref{ $ref->{accno} } = $key;
2030 push @{ $self->{"${module}_links"}{$key} },
2031 { accno => $ref->{accno},
2032 description => $ref->{description},
2033 taxkey => $ref->{taxkey_id},
2034 tax_id => $ref->{tax_id} };
2036 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2042 # get taxkeys and description
2043 $query = qq|SELECT id, taxkey, taxdescription FROM tax|;
2044 $self->{TAXKEY} = selectall_hashref_query($self, $dbh, $query);
2046 if (($module eq "AP") || ($module eq "AR")) {
2047 # get tax rates and description
2048 $query = qq|SELECT * FROM tax|;
2049 $self->{TAX} = selectall_hashref_query($self, $dbh, $query);
2055 a.cp_id, a.invnumber, a.transdate, a.${table}_id, a.datepaid,
2056 a.duedate, a.ordnumber, a.taxincluded, a.curr AS currency, a.notes,
2057 a.intnotes, a.department_id, a.amount AS oldinvtotal,
2058 a.paid AS oldtotalpaid, a.employee_id, a.gldate, a.type,
2060 d.description AS department,
2063 JOIN $table c ON (a.${table}_id = c.id)
2064 LEFT JOIN employee e ON (e.id = a.employee_id)
2065 LEFT JOIN department d ON (d.id = a.department_id)
2067 $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{id});
2069 foreach $key (keys %$ref) {
2070 $self->{$key} = $ref->{$key};
2073 my $transdate = "current_date";
2074 if ($self->{transdate}) {
2075 $transdate = $dbh->quote($self->{transdate});
2078 # now get the account numbers
2079 $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
2081 LEFT JOIN taxkeys tk ON (tk.chart_id = c.id)
2083 AND (tk.id = (SELECT id FROM taxkeys WHERE taxkeys.chart_id = c.id AND startdate <= $transdate ORDER BY startdate DESC LIMIT 1)
2084 OR c.link LIKE '%_tax%')
2087 $sth = $dbh->prepare($query);
2088 do_statement($self, $sth, $query, "%$module%");
2090 $self->{accounts} = "";
2091 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
2093 foreach my $key (split(/:/, $ref->{link})) {
2094 if ($key =~ /$module/) {
2096 # cross reference for keys
2097 $xkeyref{ $ref->{accno} } = $key;
2099 push @{ $self->{"${module}_links"}{$key} },
2100 { accno => $ref->{accno},
2101 description => $ref->{description},
2102 taxkey => $ref->{taxkey_id},
2103 tax_id => $ref->{tax_id} };
2105 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2111 # get amounts from individual entries
2114 c.accno, c.description,
2115 a.source, a.amount, a.memo, a.transdate, a.cleared, a.project_id, a.taxkey,
2119 LEFT JOIN chart c ON (c.id = a.chart_id)
2120 LEFT JOIN project p ON (p.id = a.project_id)
2121 LEFT JOIN tax t ON (t.id= (SELECT tk.tax_id FROM taxkeys tk
2122 WHERE (tk.taxkey_id=a.taxkey) AND
2123 ((CASE WHEN a.chart_id IN (SELECT chart_id FROM taxkeys WHERE taxkey_id = a.taxkey)
2124 THEN tk.chart_id = a.chart_id
2127 OR (c.link='%tax%')) AND
2128 (startdate <= a.transdate) ORDER BY startdate DESC LIMIT 1))
2129 WHERE a.trans_id = ?
2130 AND a.fx_transaction = '0'
2131 ORDER BY a.oid, a.transdate|;
2132 $sth = $dbh->prepare($query);
2133 do_statement($self, $sth, $query, $self->{id});
2135 # get exchangerate for currency
2136 $self->{exchangerate} =
2137 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate}, $fld);
2140 # store amounts in {acc_trans}{$key} for multiple accounts
2141 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
2142 $ref->{exchangerate} =
2143 $self->get_exchangerate($dbh, $self->{currency}, $ref->{transdate}, $fld);
2144 if (!($xkeyref{ $ref->{accno} } =~ /tax/)) {
2147 if (($xkeyref{ $ref->{accno} } =~ /paid/) && ($self->{type} eq "credit_note")) {
2148 $ref->{amount} *= -1;
2150 $ref->{index} = $index;
2152 push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref;
2158 d.curr AS currencies, d.closedto, d.revtrans,
2159 (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2160 (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2162 $ref = selectfirst_hashref_query($self, $dbh, $query);
2163 map { $self->{$_} = $ref->{$_} } keys %$ref;
2170 current_date AS transdate, d.curr AS currencies, d.closedto, d.revtrans,
2171 (SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2172 (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2174 $ref = selectfirst_hashref_query($self, $dbh, $query);
2175 map { $self->{$_} = $ref->{$_} } keys %$ref;
2177 if ($self->{"$self->{vc}_id"}) {
2179 # only setup currency
2180 ($self->{currency}) = split(/:/, $self->{currencies});
2184 $self->lastname_used($dbh, $myconfig, $table, $module);
2186 # get exchangerate for currency
2187 $self->{exchangerate} =
2188 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate}, $fld);
2196 $main::lxdebug->leave_sub();
2200 $main::lxdebug->enter_sub();
2202 my ($self, $dbh, $myconfig, $table, $module) = @_;
2204 my $arap = ($table eq 'customer') ? "ar" : "ap";
2205 $table = $table eq "customer" ? "customer" : "vendor";
2206 my $where = "1 = 1";
2208 if ($self->{type} =~ /_order/) {
2210 $where = "quotation = '0'";
2212 if ($self->{type} =~ /_quotation/) {
2214 $where = "quotation = '1'";
2217 my $query = qq|SELECT MAX(id) FROM $arap
2218 WHERE $where AND ${table}_id > 0|;
2219 my ($trans_id) = selectrow_query($self, $dbh, $query);
2224 a.curr, a.${table}_id, a.department_id,
2225 d.description AS department,
2226 ct.name, current_date + ct.terms AS duedate
2228 LEFT JOIN $table ct ON (a.${table}_id = ct.id)
2229 LEFT JOIN department d ON (a.department_id = d.id)
2231 ($self->{currency}, $self->{"${table}_id"}, $self->{department_id},
2232 $self->{department}, $self->{$table}, $self->{duedate})
2233 = selectrow_query($self, $dbh, $query, $trans_id);
2235 $main::lxdebug->leave_sub();
2239 $main::lxdebug->enter_sub();
2241 my ($self, $myconfig, $thisdate, $days) = @_;
2243 my $dbh = $self->dbconnect($myconfig);
2248 my $dateformat = $myconfig->{dateformat};
2249 $dateformat .= "yy" if $myconfig->{dateformat} !~ /^y/;
2250 $thisdate = $dbh->quote($thisdate);
2251 $query = qq|SELECT to_date($thisdate, '$dateformat') + $days AS thisdate|;
2253 $query = qq|SELECT current_date AS thisdate|;
2256 ($thisdate) = selectrow_query($self, $dbh, $query);
2260 $main::lxdebug->leave_sub();
2266 $main::lxdebug->enter_sub();
2268 my ($self, $string) = @_;
2270 if ($string !~ /%/) {
2271 $string = "%$string%";
2274 $string =~ s/\'/\'\'/g;
2276 $main::lxdebug->leave_sub();
2282 $main::lxdebug->enter_sub();
2284 my ($self, $flds, $new, $count, $numrows) = @_;
2288 map { push @ndx, { num => $new->[$_ - 1]->{runningnumber}, ndx => $_ } }
2294 foreach my $item (sort { $a->{num} <=> $b->{num} } @ndx) {
2296 $j = $item->{ndx} - 1;
2297 map { $self->{"${_}_$i"} = $new->[$j]->{$_} } @{$flds};
2301 for $i ($count + 1 .. $numrows) {
2302 map { delete $self->{"${_}_$i"} } @{$flds};
2305 $main::lxdebug->leave_sub();
2309 $main::lxdebug->enter_sub();
2311 my ($self, $myconfig) = @_;
2315 my $dbh = $self->dbconnect_noauto($myconfig);
2317 my $query = qq|DELETE FROM status
2318 WHERE (formname = ?) AND (trans_id = ?)|;
2319 my $sth = prepare_query($self, $dbh, $query);
2321 if ($self->{formname} =~ /(check|receipt)/) {
2322 for $i (1 .. $self->{rowcount}) {
2323 do_statement($self, $sth, $query, $self->{formname}, $self->{"id_$i"} * 1);
2326 do_statement($self, $sth, $query, $self->{formname}, $self->{id});
2330 my $printed = ($self->{printed} =~ /$self->{formname}/) ? "1" : "0";
2331 my $emailed = ($self->{emailed} =~ /$self->{formname}/) ? "1" : "0";
2333 my %queued = split / /, $self->{queued};
2336 if ($self->{formname} =~ /(check|receipt)/) {
2338 # this is a check or receipt, add one entry for each lineitem
2339 my ($accno) = split /--/, $self->{account};
2340 $query = qq|INSERT INTO status (trans_id, printed, spoolfile, formname, chart_id)
2341 VALUES (?, ?, ?, ?, (SELECT c.id FROM chart c WHERE c.accno = ?))|;
2342 @values = ($printed, $queued{$self->{formname}}, $self->{prinform}, $accno);
2343 $sth = prepare_query($self, $dbh, $query);
2345 for $i (1 .. $self->{rowcount}) {
2346 if ($self->{"checked_$i"}) {
2347 do_statement($self, $sth, $query, $self->{"id_$i"}, @values);
2353 $query = qq|INSERT INTO status (trans_id, printed, emailed, spoolfile, formname)
2354 VALUES (?, ?, ?, ?, ?)|;
2355 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed,
2356 $queued{$self->{formname}}, $self->{formname});
2362 $main::lxdebug->leave_sub();
2366 $main::lxdebug->enter_sub();
2368 my ($self, $dbh) = @_;
2370 my ($query, $printed, $emailed);
2372 my $formnames = $self->{printed};
2373 my $emailforms = $self->{emailed};
2375 my $query = qq|DELETE FROM status
2376 WHERE (formname = ?) AND (trans_id = ?)|;
2377 do_query($self, $dbh, $query, $self->{formname}, $self->{id});
2379 # this only applies to the forms
2380 # checks and receipts are posted when printed or queued
2382 if ($self->{queued}) {
2383 my %queued = split / /, $self->{queued};
2385 foreach my $formname (keys %queued) {
2386 $printed = ($self->{printed} =~ /$self->{formname}/) ? "1" : "0";
2387 $emailed = ($self->{emailed} =~ /$self->{formname}/) ? "1" : "0";
2389 $query = qq|INSERT INTO status (trans_id, printed, emailed, spoolfile, formname)
2390 VALUES (?, ?, ?, ?, ?)|;
2391 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed, $queued{$formname}, $formname);
2393 $formnames =~ s/$self->{formname}//;
2394 $emailforms =~ s/$self->{formname}//;
2399 # save printed, emailed info
2400 $formnames =~ s/^ +//g;
2401 $emailforms =~ s/^ +//g;
2404 map { $status{$_}{printed} = 1 } split / +/, $formnames;
2405 map { $status{$_}{emailed} = 1 } split / +/, $emailforms;
2407 foreach my $formname (keys %status) {
2408 $printed = ($formnames =~ /$self->{formname}/) ? "1" : "0";
2409 $emailed = ($emailforms =~ /$self->{formname}/) ? "1" : "0";
2411 $query = qq|INSERT INTO status (trans_id, printed, emailed, formname)
2412 VALUES (?, ?, ?, ?)|;
2413 do_query($self, $dbh, $query, $self->{id}, $printed, $emailed, $formname);
2416 $main::lxdebug->leave_sub();
2420 # $main::locale->text('SAVED')
2421 # $main::locale->text('DELETED')
2422 # $main::locale->text('ADDED')
2423 # $main::locale->text('PAYMENT POSTED')
2424 # $main::locale->text('POSTED')
2425 # $main::locale->text('POSTED AS NEW')
2426 # $main::locale->text('ELSE')
2427 # $main::locale->text('SAVED FOR DUNNING')
2428 # $main::locale->text('DUNNING STARTED')
2429 # $main::locale->text('PRINTED')
2430 # $main::locale->text('MAILED')
2431 # $main::locale->text('SCREENED')
2432 # $main::locale->text('CANCELED')
2433 # $main::locale->text('invoice')
2434 # $main::locale->text('proforma')
2435 # $main::locale->text('sales_order')
2436 # $main::locale->text('packing_list')
2437 # $main::locale->text('pick_list')
2438 # $main::locale->text('purchase_order')
2439 # $main::locale->text('bin_list')
2440 # $main::locale->text('sales_quotation')
2441 # $main::locale->text('request_quotation')
2444 $main::lxdebug->enter_sub();
2449 if(!exists $self->{employee_id}) {
2450 &get_employee($self, $dbh);
2454 qq|INSERT INTO history_erp (trans_id, employee_id, addition, what_done, snumbers) | .
2455 qq|VALUES (?, ?, ?, ?, ?)|;
2456 my @values = (conv_i($self->{id}), conv_i($self->{employee_id}),
2457 $self->{addition}, $self->{what_done}, "$self->{snumbers}");
2458 do_query($self, $dbh, $query, @values);
2460 $main::lxdebug->leave_sub();
2464 $main::lxdebug->enter_sub();
2468 my $trans_id = shift();
2469 my $restriction = shift();
2472 if ($trans_id ne "") {
2474 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 | .
2475 qq|FROM history_erp h | .
2476 qq|LEFT JOIN employee emp ON (emp.id = h.employee_id) | .
2477 qq|WHERE trans_id = ? |
2480 my $sth = $dbh->prepare($query) || $self->dberror($query);
2482 $sth->execute($trans_id) || $self->dberror("$query ($trans_id)");
2484 while(my $hash_ref = $sth->fetchrow_hashref()) {
2485 $hash_ref->{addition} = $main::locale->text($hash_ref->{addition});
2486 $hash_ref->{what_done} = $main::locale->text($hash_ref->{what_done});
2487 $hash_ref->{snumbers} =~ s/^.+_(.*)$/$1/g;
2488 $tempArray[$i++] = $hash_ref;
2490 $main::lxdebug->leave_sub() and return \@tempArray
2491 if ($i > 0 && $tempArray[0] ne "");
2493 $main::lxdebug->leave_sub();
2497 sub update_defaults {
2498 $main::lxdebug->enter_sub();
2500 my ($self, $myconfig, $fld, $provided_dbh) = @_;
2503 if ($provided_dbh) {
2504 $dbh = $provided_dbh;
2506 $dbh = $self->dbconnect_noauto($myconfig);
2508 my $query = qq|SELECT $fld FROM defaults FOR UPDATE|;
2509 my $sth = $dbh->prepare($query);
2511 $sth->execute || $self->dberror($query);
2512 my ($var) = $sth->fetchrow_array;
2515 $var =~ s/\d+$/ sprintf '%0*d', length($&), $&+1 /e;
2518 $query = qq|UPDATE defaults SET $fld = ?|;
2519 do_query($self, $dbh, $query, $var);
2521 if (!$provided_dbh) {
2526 $main::lxdebug->leave_sub();
2531 sub update_business {
2532 $main::lxdebug->enter_sub();
2534 my ($self, $myconfig, $business_id, $provided_dbh) = @_;
2537 if ($provided_dbh) {
2538 $dbh = $provided_dbh;
2540 $dbh = $self->dbconnect_noauto($myconfig);
2543 qq|SELECT customernumberinit FROM business
2544 WHERE id = ? FOR UPDATE|;
2545 my ($var) = selectrow_query($self, $dbh, $query, $business_id);
2547 $var =~ s/\d+$/ sprintf '%0*d', length($&), $&+1 /e;
2549 $query = qq|UPDATE business
2550 SET customernumberinit = ?
2552 do_query($self, $dbh, $query, $var, $business_id);
2554 if (!$provided_dbh) {
2559 $main::lxdebug->leave_sub();
2564 sub get_partsgroup {
2565 $main::lxdebug->enter_sub();
2567 my ($self, $myconfig, $p) = @_;
2569 my $dbh = $self->dbconnect($myconfig);
2571 my $query = qq|SELECT DISTINCT pg.id, pg.partsgroup
2573 JOIN parts p ON (p.partsgroup_id = pg.id) |;
2576 if ($p->{searchitems} eq 'part') {
2577 $query .= qq|WHERE p.inventory_accno_id > 0|;
2579 if ($p->{searchitems} eq 'service') {
2580 $query .= qq|WHERE p.inventory_accno_id IS NULL|;
2582 if ($p->{searchitems} eq 'assembly') {
2583 $query .= qq|WHERE p.assembly = '1'|;
2585 if ($p->{searchitems} eq 'labor') {
2586 $query .= qq|WHERE (p.inventory_accno_id > 0) AND (p.income_accno_id IS NULL)|;
2589 $query .= qq|ORDER BY partsgroup|;
2592 $query = qq|SELECT id, partsgroup FROM partsgroup
2593 ORDER BY partsgroup|;
2596 if ($p->{language_code}) {
2597 $query = qq|SELECT DISTINCT pg.id, pg.partsgroup,
2598 t.description AS translation
2600 JOIN parts p ON (p.partsgroup_id = pg.id)
2601 LEFT JOIN translation t ON ((t.trans_id = pg.id) AND (t.language_code = ?))
2602 ORDER BY translation|;
2603 @values = ($p->{language_code});
2606 $self->{all_partsgroup} = selectall_hashref_query($self, $dbh, $query, @values);
2609 $main::lxdebug->leave_sub();
2612 sub get_pricegroup {
2613 $main::lxdebug->enter_sub();
2615 my ($self, $myconfig, $p) = @_;
2617 my $dbh = $self->dbconnect($myconfig);
2619 my $query = qq|SELECT p.id, p.pricegroup
2622 $query .= qq| ORDER BY pricegroup|;
2625 $query = qq|SELECT id, pricegroup FROM pricegroup
2626 ORDER BY pricegroup|;
2629 $self->{all_pricegroup} = selectall_hashref_query($self, $dbh, $query);
2633 $main::lxdebug->leave_sub();
2637 # usage $form->all_years($myconfig, [$dbh])
2638 # return list of all years where bookings found
2641 $main::lxdebug->enter_sub();
2643 my ($self, $myconfig, $dbh) = @_;
2647 $dbh = $self->dbconnect($myconfig);
2652 my $query = qq|SELECT (SELECT MIN(transdate) FROM acc_trans),
2653 (SELECT MAX(transdate) FROM acc_trans)|;
2654 my ($startdate, $enddate) = selectrow_query($self, $dbh, $query);
2656 if ($myconfig->{dateformat} =~ /^yy/) {
2657 ($startdate) = split /\W/, $startdate;
2658 ($enddate) = split /\W/, $enddate;
2660 (@_) = split /\W/, $startdate;
2662 (@_) = split /\W/, $enddate;
2667 $startdate = substr($startdate,0,4);
2668 $enddate = substr($enddate,0,4);
2670 while ($enddate >= $startdate) {
2671 push @all_years, $enddate--;
2674 $dbh->disconnect if $disconnect;
2678 $main::lxdebug->leave_sub();