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 #======================================================================
51 $main::lxdebug->enter_sub(2);
55 my @pairs = split(/&/, $input);
58 my ($name, $value) = split(/=/, $_, 2);
59 $in{$name} = unescape(undef, $value);
62 $main::lxdebug->leave_sub(2);
67 sub _request_to_hash {
68 $main::lxdebug->enter_sub(2);
71 my ($i, $loc, $key, $val);
72 my (%ATTACH, $f, $header, $header_body, $len, $buf);
73 my ($boundary, @list, $size, $body, $x, $blah, $name);
75 if ($ENV{'CONTENT_TYPE'}
76 && ($ENV{'CONTENT_TYPE'} =~ /multipart\/form-data; boundary=(.+)$/)) {
77 $boundary = quotemeta('--' . $1);
78 @list = split(/$boundary/, $input);
80 # For some reason there are always 2 extra, that are empty
83 for ($x = 1; $x <= $size; $x++) {
84 $header_body = $list[$x];
85 $header_body =~ /\r\n\r\n|\n\n/;
87 # Here we split the header and body
92 # Now we try to get the file name
94 $name =~ /name=\"(.+)\"/;
95 ($name, $blah) = split(/\"/, $1);
97 # If the form name is not attach, then we need to parse this like
99 if ($name ne "attach") {
100 $body =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
101 $ATTACH{$name} = $body;
103 # Otherwise it is an attachment and we need to finish it up
104 } elsif ($name eq "attach") {
105 $header =~ /filename=\"(.+)\"/;
106 $ATTACH{'FILE_NAME'} = $1;
107 $ATTACH{'FILE_NAME'} =~ s/\"//g;
108 $ATTACH{'FILE_NAME'} =~ s/\s//g;
109 $ATTACH{'FILE_CONTENT'} = $body;
111 for ($i = $x; $list[$i]; $i++) {
112 $list[$i] =~ s/^.+name=$//;
113 $list[$i] =~ /\"(\w+)\"/;
119 $main::lxdebug->leave_sub(2);
123 $main::lxdebug->leave_sub(2);
124 return _input_to_hash($input);
129 $main::lxdebug->enter_sub();
135 read(STDIN, $_, $ENV{CONTENT_LENGTH});
137 if ($ENV{QUERY_STRING}) {
138 $_ = $ENV{QUERY_STRING};
145 my %parameters = _request_to_hash($_);
146 map({ $self->{$_} = $parameters{$_}; } keys(%parameters));
148 $self->{action} = lc $self->{action};
149 $self->{action} =~ s/( |-|,|\#)/_/g;
151 $self->{version} = "2.4.2";
153 $main::lxdebug->leave_sub();
159 $main::lxdebug->enter_sub();
165 map { print "$_ = $self->{$_}\n" } (sort keys %{$self});
167 $main::lxdebug->leave_sub();
171 $main::lxdebug->enter_sub(2);
173 my ($self, $str, $beenthere) = @_;
175 # for Apache 2 we escape strings twice
176 #if (($ENV{SERVER_SOFTWARE} =~ /Apache\/2/) && !$beenthere) {
177 # $str = $self->escape($str, 1);
180 $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
182 $main::lxdebug->leave_sub(2);
188 $main::lxdebug->enter_sub(2);
190 my ($self, $str) = @_;
195 $str =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
197 $main::lxdebug->leave_sub(2);
203 my ($self, $str) = @_;
205 if ($str && !ref($str)) {
206 $str =~ s/\"/"/g;
214 my ($self, $str) = @_;
216 if ($str && !ref($str)) {
217 $str =~ s/"/\"/g;
225 $main::lxdebug->enter_sub(2);
227 my ($self, $str) = @_;
230 ('order' => ['"', '<', '>'],
236 map({ $str =~ s/$_/$replace{$_}/g; } @{ $replace{"order"} });
238 $main::lxdebug->leave_sub(2);
248 print qq|<input type=hidden name="$_" value="|
249 . $self->quote($self->{$_})
253 delete $self->{header};
254 for (sort keys %$self) {
255 print qq|<input type=hidden name="$_" value="|
256 . $self->quote($self->{$_})
264 $main::lxdebug->enter_sub();
266 my ($self, $msg) = @_;
267 if ($ENV{HTTP_USER_AGENT}) {
269 $self->show_generic_error($msg);
273 if ($self->{error_function}) {
274 &{ $self->{error_function} }($msg);
280 $main::lxdebug->leave_sub();
284 $main::lxdebug->enter_sub();
286 my ($self, $msg) = @_;
288 if ($ENV{HTTP_USER_AGENT}) {
291 if (!$self->{header}) {
304 if ($self->{info_function}) {
305 &{ $self->{info_function} }($msg);
311 $main::lxdebug->leave_sub();
315 $main::lxdebug->enter_sub();
317 my ($self, $str, $cols, $maxrows) = @_;
321 map { $rows += int(((length) - 2) / $cols) + 1 } split /\r/, $str;
323 $maxrows = $rows unless defined $maxrows;
325 $main::lxdebug->leave_sub();
327 return ($rows > $maxrows) ? $maxrows : $rows;
331 $main::lxdebug->enter_sub();
333 my ($self, $msg) = @_;
335 $self->error("$msg\n" . $DBI::errstr);
337 $main::lxdebug->leave_sub();
341 $main::lxdebug->enter_sub();
343 my ($self, $name, $msg) = @_;
345 if ($self->{$name} =~ /^\s*$/) {
348 $main::lxdebug->leave_sub();
352 $main::lxdebug->enter_sub();
354 my ($self, $extra_code) = @_;
356 if ($self->{header}) {
357 $main::lxdebug->leave_sub();
361 my ($stylesheet, $favicon, $charset);
363 if ($ENV{HTTP_USER_AGENT}) {
365 if ($self->{stylesheet} && (-f "css/$self->{stylesheet}")) {
367 qq|<LINK REL="stylesheet" HREF="css/$self->{stylesheet}" TYPE="text/css" TITLE="Lx-Office stylesheet">
371 $self->{favicon} = "favicon.ico" unless $self->{favicon};
373 if ($self->{favicon} && (-f "$self->{favicon}")) {
375 qq|<LINK REL="shortcut icon" HREF="$self->{favicon}" TYPE="image/x-icon">
379 if ($self->{charset}) {
381 qq|<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=$self->{charset}">
384 if ($self->{landscape}) {
385 $pagelayout = qq|<style type="text/css">
386 \@page { size:landscape; }
389 if ($self->{fokus}) {
390 $fokus = qq|<script type="text/javascript">
392 function fokus(){document.$self->{fokus}.focus();}
399 if ($self->{jsscript} == 1) {
402 <style type="text/css">\@import url(js/jscalendar/calendar-win2k-1.css);</style>
403 <script type="text/javascript" src="js/jscalendar/calendar.js"></script>
404 <script type="text/javascript" src="js/jscalendar/lang/calendar-de.js"></script>
405 <script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script>
412 ? "$self->{title} - $self->{titlebar}"
415 foreach $item (@ { $self->{AJAX} }) {
416 $ajax .= $item->show_javascript();
418 print qq|Content-Type: text/html
422 <title>$self->{titlebar}</title>
430 <meta name="robots" content="noindex,nofollow" />
431 <script type="text/javascript" src="js/highlight_input.js"></script>
432 <link rel="stylesheet" type="text/css" href="css/tabcontent.css" />
434 <script type="text/javascript" src="js/tabcontent.js">
436 /***********************************************
437 * Tab Content script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
438 * This notice MUST stay intact for legal use
439 * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
440 ***********************************************/
451 $main::lxdebug->leave_sub();
454 sub parse_html_template {
455 $main::lxdebug->enter_sub();
457 my ($self, $file, $additional_params) = @_;
460 if (!defined($main::myconfig) || !defined($main::myconfig{"countrycode"})) {
461 $language = $main::language;
463 $language = $main::myconfig{"countrycode"};
466 if (-f "templates/webpages/${file}_${language}.html") {
467 if ((-f ".developer") &&
468 (-f "templates/webpages/${file}_master.html") &&
469 ((stat("templates/webpages/${file}_master.html"))[9] >
470 (stat("templates/webpages/${file}_${language}.html"))[9])) {
471 my $info = "Developper information: templates/webpages/${file}_master.html is newer than the localized version.\n" .
472 "Please re-run 'locales.pl' in 'locale/${language}'.";
473 print(qq|<pre>$info</pre>|);
477 $file = "templates/webpages/${file}_${language}.html";
478 } elsif (-f "templates/webpages/${file}.html") {
479 $file = "templates/webpages/${file}.html";
481 my $info = "Web page template '${file}' not found.\n" .
482 "Please re-run 'locales.pl' in 'locale/${language}'.";
483 print(qq|<pre>$info</pre>|);
487 my $template = HTML::Template->new("filename" => $file,
488 "die_on_bad_params" => 0,
490 "case_sensitive" => 1,
491 "loop_context_vars" => 1,
494 $additional_params = {} unless ($additional_params);
495 if ($self->{"DEBUG"}) {
496 $additional_params->{"DEBUG"} = $self->{"DEBUG"};
499 if ($additional_params->{"DEBUG"}) {
500 $additional_params->{"DEBUG"} =
501 "<br><em>DEBUG INFORMATION:</em><pre>" . $additional_params->{"DEBUG"} . "</pre>";
504 if (%main::myconfig) {
505 map({ $additional_params->{"myconfig_${_}"} = $main::myconfig{$_}; } keys(%main::myconfig));
506 my $jsc_dateformat = $main::myconfig{"dateformat"};
507 $jsc_dateformat =~ s/d+/\%d/gi;
508 $jsc_dateformat =~ s/m+/\%m/gi;
509 $jsc_dateformat =~ s/y+/\%Y/gi;
510 $additional_params->{"myconfig_jsc_dateformat"} = $jsc_dateformat;
513 $additional_params->{"conf_jscalendar"} = $main::jscalendar;
514 $additional_params->{"conf_lizenzen"} = $main::lizenzen;
515 $additional_params->{"conf_latex_templates"} = $main::latex;
516 $additional_params->{"conf_opendocument_templates"} = $main::opendocument_templates;
518 my @additional_param_names = keys(%{$additional_params});
519 foreach my $key ($template->param()) {
520 my $param = $self->{$key};
521 $param = $additional_params->{$key} if (grep(/^${key}$/, @additional_param_names));
522 $param = [] if (($template->query("name" => $key) eq "LOOP") && (ref($param) ne "ARRAY"));
523 $template->param($key => $param);
526 my $output = $template->output();
528 $main::lxdebug->leave_sub();
533 sub show_generic_error {
534 my ($self, $error, $title, $action) = @_;
537 $add_params->{"title"} = $title if ($title);
538 $self->{"label_error"} = $error;
542 map({ delete($self->{$_}); } qw(action));
543 map({ push(@vars, { "name" => $_, "value" => $self->{$_} })
544 if (!ref($self->{$_})); }
546 $add_params->{"SHOW_BUTTON"} = 1;
547 $add_params->{"BUTTON_LABEL"} = $action;
549 $add_params->{"VARIABLES"} = \@vars;
552 print($self->parse_html_template("generic/error", $add_params));
554 die("Error: $error\n");
557 sub show_generic_information {
558 my ($self, $error, $title) = @_;
561 $add_params->{"title"} = $title if ($title);
562 $self->{"label_information"} = $error;
565 print($self->parse_html_template("generic/information", $add_params));
567 die("Information: $error\n");
570 # write Trigger JavaScript-Code ($qty = quantity of Triggers)
571 # changed it to accept an arbitrary number of triggers - sschoeling
573 $main::lxdebug->enter_sub();
576 my $myconfig = shift;
579 # set dateform for jsscript
582 "dd.mm.yy" => "%d.%m.%Y",
583 "dd-mm-yy" => "%d-%m-%Y",
584 "dd/mm/yy" => "%d/%m/%Y",
585 "mm/dd/yy" => "%m/%d/%Y",
586 "mm-dd-yy" => "%m-%d-%Y",
587 "yyyy-mm-dd" => "%Y-%m-%d",
590 my $ifFormat = defined($dateformats{$myconfig{"dateformat"}}) ?
591 $dateformats{$myconfig{"dateformat"}} : "%d.%m.%Y";
598 inputField : "| . (shift) . qq|",
599 ifFormat :"$ifFormat",
600 align : "| . (shift) . qq|",
601 button : "| . (shift) . qq|"
607 <script type="text/javascript">
608 <!--| . join("", @triggers) . qq|//-->
612 $main::lxdebug->leave_sub();
615 } #end sub write_trigger
618 $main::lxdebug->enter_sub();
620 my ($self, $msg) = @_;
622 if ($self->{callback}) {
624 ($script, $argv) = split(/\?/, $self->{callback});
625 exec("perl", "$script", $argv);
633 $main::lxdebug->leave_sub();
636 # sort of columns removed - empty sub
638 $main::lxdebug->enter_sub();
640 my ($self, @columns) = @_;
642 $main::lxdebug->leave_sub();
648 $main::lxdebug->enter_sub(2);
650 my ($self, $myconfig, $amount, $places, $dash) = @_;
655 my $neg = ($amount =~ s/-//);
657 if (defined($places) && ($places ne '')) {
662 my ($actual_places) = ($amount =~ /\.(\d+)/);
663 $actual_places = length($actual_places);
664 $places = $actual_places > $places ? $actual_places : $places;
667 $amount = $self->round_amount($amount, $places);
670 my @d = map { s/\d//g; reverse split // } my $tmp = $myconfig->{numberformat}; # get delim chars
671 my @p = split(/\./, $amount); # split amount at decimal point
673 $p[0] =~ s/\B(?=(...)*$)/$d[1]/g if $d[1]; # add 1,000 delimiters
676 $amount .= $d[0].$p[1].(0 x ($places - length $p[1])) if ($places || $p[1] ne '');
679 ($dash =~ /-/) ? ($neg ? "($amount)" : "$amount" ) :
680 ($dash =~ /DRCR/) ? ($neg ? "$amount DR" : "$amount CR" ) :
681 ($neg ? "-$amount" : "$amount" ) ;
685 $main::lxdebug->leave_sub(2);
690 $main::lxdebug->enter_sub(2);
692 my ($self, $myconfig, $amount) = @_;
694 if ( ($myconfig->{numberformat} eq '1.000,00')
695 || ($myconfig->{numberformat} eq '1000,00')) {
700 if ($myconfig->{numberformat} eq "1'000.00") {
706 $main::lxdebug->leave_sub(2);
708 return ($amount * 1);
712 $main::lxdebug->enter_sub(2);
714 my ($self, $amount, $places) = @_;
717 # Rounding like "Kaufmannsrunden"
718 # Descr. http://de.wikipedia.org/wiki/Rundung
720 # http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q4.13.html
723 $amount = $amount * (10**($places));
724 $round_amount = int($amount + .5 * ($amount <=> 0)) / (10**($places));
726 $main::lxdebug->leave_sub(2);
728 return $round_amount;
733 $main::lxdebug->enter_sub();
735 my ($self, $myconfig, $userspath) = @_;
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 $self->{tmpfile} = "$userspath/${fileid}.$self->{IN}" if ( $self->{tmpfile} eq '' );
780 if ($template->uses_temp_file() || $self->{media} eq 'email') {
782 $self->{OUT} = ">$self->{tmpfile}";
786 open(OUT, "$self->{OUT}") or $self->error("$self->{OUT} : $!");
788 open(OUT, ">-") or $self->error("STDOUT : $!");
792 if (!$template->parse(*OUT)) {
794 $self->error("$self->{IN} : " . $template->get_error());
799 if ($template->uses_temp_file() || $self->{media} eq 'email') {
801 if ($self->{media} eq 'email') {
805 my $mail = new Mailer;
807 map { $mail->{$_} = $self->{$_} }
808 qw(cc bcc subject message version format charset);
809 $mail->{to} = qq|$self->{email}|;
810 $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
811 $mail->{fileid} = "$fileid.";
812 $myconfig->{signature} =~ s/\\r\\n/\\n/g;
814 # if we send html or plain text inline
815 if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
816 $mail->{contenttype} = "text/html";
818 $mail->{message} =~ s/\r\n/<br>\n/g;
819 $myconfig->{signature} =~ s/\\n/<br>\n/g;
820 $mail->{message} .= "<br>\n-- <br>\n$myconfig->{signature}\n<br>";
822 open(IN, $self->{tmpfile})
823 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
825 $mail->{message} .= $_;
832 if (!$self->{"do_not_attach"}) {
833 @{ $mail->{attachments} } =
834 ({ "filename" => $self->{"tmpfile"},
835 "name" => $self->{"attachment_filename"} ?
836 $self->{"attachment_filename"} : $self->{"tmpfile"} });
839 $mail->{message} =~ s/\r\n/\n/g;
840 $myconfig->{signature} =~ s/\\n/\n/g;
841 $mail->{message} .= "\n-- \n$myconfig->{signature}";
845 my $err = $mail->send($out);
846 $self->error($self->cleanup . "$err") if ($err);
852 my $numbytes = (-s $self->{tmpfile});
853 open(IN, $self->{tmpfile})
854 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
856 $self->{copies} = 1 unless $self->{media} eq 'printer';
858 chdir("$self->{cwd}");
859 #print(STDERR "Kopien $self->{copies}\n");
860 #print(STDERR "OUT $self->{OUT}\n");
861 for my $i (1 .. $self->{copies}) {
863 open(OUT, $self->{OUT})
864 or $self->error($self->cleanup . "$self->{OUT} : $!");
866 $self->{attachment_filename} = $self->{tmpfile} if ($self->{attachment_filename} eq '');
868 print qq|Content-Type: | . $template->get_mime_type() . qq|
869 Content-Disposition: attachment; filename="$self->{attachment_filename}"
870 Content-Length: $numbytes
874 open(OUT, ">-") or $self->error($self->cleanup . "$!: STDOUT");
894 chdir("$self->{cwd}");
895 $main::lxdebug->leave_sub();
899 $main::lxdebug->enter_sub();
903 chdir("$self->{tmpdir}");
906 if (-f "$self->{tmpfile}.err") {
907 open(FH, "$self->{tmpfile}.err");
912 if ($self->{tmpfile}) {
913 $self->{tmpfile} =~ s|.*/||g;
915 $self->{tmpfile} =~ s/\.\w+$//g;
916 my $tmpfile = $self->{tmpfile};
917 unlink(<$tmpfile.*>);
920 chdir("$self->{cwd}");
922 $main::lxdebug->leave_sub();
928 $main::lxdebug->enter_sub();
930 my ($self, $date, $myconfig) = @_;
932 if ($date && $date =~ /\D/) {
934 if ($myconfig->{dateformat} =~ /^yy/) {
935 ($yy, $mm, $dd) = split /\D/, $date;
937 if ($myconfig->{dateformat} =~ /^mm/) {
938 ($mm, $dd, $yy) = split /\D/, $date;
940 if ($myconfig->{dateformat} =~ /^dd/) {
941 ($dd, $mm, $yy) = split /\D/, $date;
946 $yy = ($yy < 70) ? $yy + 2000 : $yy;
947 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
949 $dd = "0$dd" if ($dd < 10);
950 $mm = "0$mm" if ($mm < 10);
955 $main::lxdebug->leave_sub();
960 # Database routines used throughout
963 $main::lxdebug->enter_sub(2);
965 my ($self, $myconfig) = @_;
967 # connect to database
969 DBI->connect($myconfig->{dbconnect},
970 $myconfig->{dbuser}, $myconfig->{dbpasswd})
974 if ($myconfig->{dboptions}) {
975 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
978 $main::lxdebug->leave_sub(2);
983 sub dbconnect_noauto {
984 $main::lxdebug->enter_sub();
986 my ($self, $myconfig) = @_;
988 # connect to database
990 DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser},
991 $myconfig->{dbpasswd}, { AutoCommit => 0 })
995 if ($myconfig->{dboptions}) {
996 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
999 $main::lxdebug->leave_sub();
1004 sub update_balance {
1005 $main::lxdebug->enter_sub();
1007 my ($self, $dbh, $table, $field, $where, $value) = @_;
1009 # if we have a value, go do it
1012 # retrieve balance from table
1013 my $query = "SELECT $field FROM $table WHERE $where FOR UPDATE";
1014 my $sth = $dbh->prepare($query);
1016 $sth->execute || $self->dberror($query);
1017 my ($balance) = $sth->fetchrow_array;
1023 $query = "UPDATE $table SET $field = $balance WHERE $where";
1024 $dbh->do($query) || $self->dberror($query);
1026 $main::lxdebug->leave_sub();
1029 sub update_exchangerate {
1030 $main::lxdebug->enter_sub();
1032 my ($self, $dbh, $curr, $transdate, $buy, $sell) = @_;
1034 # some sanity check for currency
1036 $main::lxdebug->leave_sub();
1040 my $query = qq|SELECT e.curr FROM exchangerate e
1041 WHERE e.curr = '$curr'
1042 AND e.transdate = '$transdate'
1044 my $sth = $dbh->prepare($query);
1045 $sth->execute || $self->dberror($query);
1048 if ($buy != 0 && $sell != 0) {
1049 $set = "buy = $buy, sell = $sell";
1050 } elsif ($buy != 0) {
1051 $set = "buy = $buy";
1052 } elsif ($sell != 0) {
1053 $set = "sell = $sell";
1056 if ($sth->fetchrow_array) {
1057 $query = qq|UPDATE exchangerate
1059 WHERE curr = '$curr'
1060 AND transdate = '$transdate'|;
1062 $query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
1063 VALUES ('$curr', $buy, $sell, '$transdate')|;
1066 $dbh->do($query) || $self->dberror($query);
1068 $main::lxdebug->leave_sub();
1071 sub save_exchangerate {
1072 $main::lxdebug->enter_sub();
1074 my ($self, $myconfig, $currency, $transdate, $rate, $fld) = @_;
1076 my $dbh = $self->dbconnect($myconfig);
1078 my ($buy, $sell) = (0, 0);
1079 $buy = $rate if $fld eq 'buy';
1080 $sell = $rate if $fld eq 'sell';
1082 $self->update_exchangerate($dbh, $currency, $transdate, $buy, $sell);
1086 $main::lxdebug->leave_sub();
1089 sub get_exchangerate {
1090 $main::lxdebug->enter_sub();
1092 my ($self, $dbh, $curr, $transdate, $fld) = @_;
1094 unless ($transdate) {
1095 $main::lxdebug->leave_sub();
1099 my $query = qq|SELECT e.$fld FROM exchangerate e
1100 WHERE e.curr = '$curr'
1101 AND e.transdate = '$transdate'|;
1102 my $sth = $dbh->prepare($query);
1103 $sth->execute || $self->dberror($query);
1105 my ($exchangerate) = $sth->fetchrow_array;
1108 if (!$exchangerate) {
1112 $main::lxdebug->leave_sub();
1114 return $exchangerate;
1117 sub set_payment_options {
1118 $main::lxdebug->enter_sub();
1120 my ($self, $myconfig, $transdate) = @_;
1122 if ($self->{payment_id}) {
1124 my $dbh = $self->dbconnect($myconfig);
1127 qq|SELECT p.terms_netto, p.terms_skonto, p.percent_skonto, | .
1128 qq|p.description_long | .
1129 qq|FROM payment_terms p | .
1132 ($self->{terms_netto}, $self->{terms_skonto}, $self->{percent_skonto},
1133 $self->{payment_terms}) =
1134 selectrow_query($self, $dbh, $query, $self->{payment_id});
1136 if ($transdate eq "") {
1137 if ($self->{invdate}) {
1138 $transdate = $self->{invdate};
1140 $transdate = $self->{transdate};
1145 qq|SELECT date '$transdate' + $self->{terms_netto} AS netto_date, | .
1146 qq|date '$transdate' + $self->{terms_skonto} AS skonto_date | .
1147 qq|FROM payment_terms LIMIT 1|;
1148 ($self->{netto_date}, $self->{skonto_date}) =
1149 selectrow_query($self, $dbh, $query);
1151 my $total = ($self->{invtotal}) ? $self->{invtotal} : $self->{ordtotal};
1152 my $skonto_amount = $self->parse_amount($myconfig, $total) *
1153 $self->{percent_skonto};
1155 $self->{skonto_amount} =
1156 $self->format_amount($myconfig, $skonto_amount, 2);
1158 if ($self->{"language_id"}) {
1160 qq|SELECT t.description_long, | .
1161 qq|l.output_numberformat, l.output_dateformat, l.output_longdates | .
1162 qq|FROM translation_payment_terms t | .
1163 qq|LEFT JOIN language l ON t.language_id = l.id | .
1164 qq|WHERE (t.language_id = ?) AND (t.payment_terms_id = ?)|;
1165 my ($description_long, $output_numberformat, $output_dateformat,
1166 $output_longdates) =
1167 selectrow_query($self, $dbh, $query,
1168 $self->{"language_id"}, $self->{"payment_id"});
1170 $self->{payment_terms} = $description_long if ($description_long);
1172 if ($output_dateformat) {
1173 foreach my $key (qw(netto_date skonto_date)) {
1175 $main::locale->reformat_date($myconfig, $self->{$key},
1181 if ($output_numberformat &&
1182 ($output_numberformat ne $myconfig->{"numberformat"})) {
1183 my $saved_numberformat = $myconfig->{"numberformat"};
1184 $myconfig->{"numberformat"} = $output_numberformat;
1185 $self->{skonto_amount} =
1186 $self->format_amount($myconfig, $skonto_amount, 2);
1187 $myconfig->{"numberformat"} = $saved_numberformat;
1191 $self->{payment_terms} =~ s/<%netto_date%>/$self->{netto_date}/g;
1192 $self->{payment_terms} =~ s/<%skonto_date%>/$self->{skonto_date}/g;
1193 $self->{payment_terms} =~ s/<%skonto_amount%>/$self->{skonto_amount}/g;
1194 $self->{payment_terms} =~ s/<%total%>/$self->{total}/g;
1195 $self->{payment_terms} =~ s/<%invtotal%>/$self->{invtotal}/g;
1196 $self->{payment_terms} =~ s/<%currency%>/$self->{currency}/g;
1197 $self->{payment_terms} =~ s/<%terms_netto%>/$self->{terms_netto}/g;
1198 $self->{payment_terms} =~ s/<%account_number%>/$self->{account_number}/g;
1199 $self->{payment_terms} =~ s/<%bank%>/$self->{bank}/g;
1200 $self->{payment_terms} =~ s/<%bank_code%>/$self->{bank_code}/g;
1205 $main::lxdebug->leave_sub();
1209 sub check_exchangerate {
1210 $main::lxdebug->enter_sub();
1212 my ($self, $myconfig, $currency, $transdate, $fld) = @_;
1214 unless ($transdate) {
1215 $main::lxdebug->leave_sub();
1219 my $dbh = $self->dbconnect($myconfig);
1221 my $query = qq|SELECT e.$fld FROM exchangerate e
1222 WHERE e.curr = '$currency'
1223 AND e.transdate = '$transdate'|;
1224 my $sth = $dbh->prepare($query);
1225 $sth->execute || $self->dberror($query);
1227 my ($exchangerate) = $sth->fetchrow_array;
1231 $main::lxdebug->leave_sub();
1233 return $exchangerate;
1236 sub get_template_language {
1237 $main::lxdebug->enter_sub();
1239 my ($self, $myconfig) = @_;
1241 my $template_code = "";
1243 if ($self->{language_id}) {
1245 my $dbh = $self->dbconnect($myconfig);
1248 my $query = qq|SELECT l.template_code FROM language l
1249 WHERE l.id = $self->{language_id}|;
1250 my $sth = $dbh->prepare($query);
1251 $sth->execute || $self->dberror($query);
1253 ($template_code) = $sth->fetchrow_array;
1258 $main::lxdebug->leave_sub();
1260 return $template_code;
1263 sub get_printer_code {
1264 $main::lxdebug->enter_sub();
1266 my ($self, $myconfig) = @_;
1268 my $template_code = "";
1270 if ($self->{printer_id}) {
1272 my $dbh = $self->dbconnect($myconfig);
1275 my $query = qq|SELECT p.template_code,p.printer_command FROM printers p
1276 WHERE p.id = $self->{printer_id}|;
1277 my $sth = $dbh->prepare($query);
1278 $sth->execute || $self->dberror($query);
1280 ($template_code, $self->{printer_command}) = $sth->fetchrow_array;
1285 $main::lxdebug->leave_sub();
1287 return $template_code;
1291 $main::lxdebug->enter_sub();
1293 my ($self, $myconfig) = @_;
1295 my $template_code = "";
1297 if ($self->{shipto_id}) {
1299 my $dbh = $self->dbconnect($myconfig);
1302 my $query = qq|SELECT s.* FROM shipto s
1303 WHERE s.shipto_id = $self->{shipto_id}|;
1304 my $sth = $dbh->prepare($query);
1305 $sth->execute || $self->dberror($query);
1306 $ref = $sth->fetchrow_hashref(NAME_lc);
1307 map { $self->{$_} = $ref->{$_} } keys %$ref;
1312 $main::lxdebug->leave_sub();
1317 $main::lxdebug->enter_sub();
1319 my ($self, $dbh, $id, $module) = @_;
1323 qw(name department_1 department_2 street zipcode city country contact phone fax email)
1325 if ($self->{"shipto$item"}) {
1326 $shipto = 1 if ($self->{$item} ne $self->{"shipto$item"});
1328 $self->{"shipto$item"} =~ s/\'/\'\'/g;
1331 if ($self->{shipto_id}) {
1332 my $query = qq| UPDATE shipto set
1333 shiptoname = '$self->{shiptoname}',
1334 shiptodepartment_1 = '$self->{shiptodepartment_1}',
1335 shiptodepartment_2 = '$self->{shiptodepartment_2}',
1336 shiptostreet = '$self->{shiptostreet}',
1337 shiptozipcode = '$self->{shiptozipcode}',
1338 shiptocity = '$self->{shiptocity}',
1339 shiptocountry = '$self->{shiptocountry}',
1340 shiptocontact = '$self->{shiptocontact}',
1341 shiptophone = '$self->{shiptophone}',
1342 shiptofax = '$self->{shiptofax}',
1343 shiptoemail = '$self->{shiptoemail}'
1344 WHERE shipto_id = $self->{shipto_id}|;
1345 $dbh->do($query) || $self->dberror($query);
1348 qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2, shiptostreet,
1349 shiptozipcode, shiptocity, shiptocountry, shiptocontact,
1350 shiptophone, shiptofax, shiptoemail, module) VALUES ($id,
1351 '$self->{shiptoname}', '$self->{shiptodepartment_1}', '$self->{shiptodepartment_2}', '$self->{shiptostreet}',
1352 '$self->{shiptozipcode}', '$self->{shiptocity}',
1353 '$self->{shiptocountry}', '$self->{shiptocontact}',
1354 '$self->{shiptophone}', '$self->{shiptofax}',
1355 '$self->{shiptoemail}', '$module')|;
1356 $dbh->do($query) || $self->dberror($query);
1360 $main::lxdebug->leave_sub();
1364 $main::lxdebug->enter_sub();
1366 my ($self, $dbh) = @_;
1368 my $query = qq|SELECT e.id, e.name FROM employee e
1369 WHERE e.login = '$self->{login}'|;
1370 my $sth = $dbh->prepare($query);
1371 $sth->execute || $self->dberror($query);
1373 ($self->{employee_id}, $self->{employee}) = $sth->fetchrow_array;
1374 $self->{employee_id} *= 1;
1378 $main::lxdebug->leave_sub();
1382 $main::lxdebug->enter_sub();
1384 my ($self, $myconfig, $salesman_id) = @_;
1386 $main::lxdebug->leave_sub() and return unless $salesman_id;
1388 my $dbh = $self->dbconnect($myconfig);
1391 selectrow_query($self, $dbh, qq|SELECT login FROM employee WHERE id = ?|,
1395 my $user = new User($main::memberfile, $login);
1396 map({ $self->{"salesman_$_"} = $user->{$_}; }
1397 qw(address businessnumber co_ustid company duns email fax name
1399 $self->{salesman_login} = $login;
1401 $self->{salesman_name} = $login
1402 if ($self->{salesman_name} eq "");
1404 map({ $self->{"salesman_$_"} =~ s/\\n/\n/g; } qw(address company));
1409 $main::lxdebug->leave_sub();
1413 $main::lxdebug->enter_sub();
1415 my ($self, $myconfig) = @_;
1417 my $dbh = $self->dbconnect($myconfig);
1418 my $query = qq|SELECT current_date+terms_netto FROM payment_terms
1419 WHERE id = '$self->{payment_id}'|;
1420 my $sth = $dbh->prepare($query);
1421 $sth->execute || $self->dberror($query);
1423 ($self->{duedate}) = $sth->fetchrow_array;
1427 $main::lxdebug->leave_sub();
1430 # get contacts for id, if no contact return {"","","","",""}
1432 $main::lxdebug->enter_sub();
1434 my ($self, $dbh, $id, $key) = @_;
1436 $key = "all_contacts" unless ($key);
1440 qq|SELECT c.cp_id, c.cp_cv_id, c.cp_name, c.cp_givenname, c.cp_abteilung | .
1441 qq|FROM contacts c | .
1442 qq|WHERE cp_cv_id = ? | .
1443 qq|ORDER BY lower(c.cp_name)|;
1444 my $sth = $dbh->prepare($query);
1445 $sth->execute($id) || $self->dberror($query . " ($id)");
1448 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1449 push @{ $self->{$key} }, $ref;
1454 push @{ $self->{$key} }, { { "", "", "", "", "", "" } };
1457 $main::lxdebug->leave_sub();
1461 $main::lxdebug->enter_sub();
1463 my ($self, $dbh, $key) = @_;
1465 my ($all, $old_id, $where, @values);
1467 if (ref($key) eq "HASH") {
1470 $key = "ALL_PROJECTS";
1472 foreach my $p (keys(%{$params})) {
1474 $all = $params->{$p};
1475 } elsif ($p eq "old_id") {
1476 $old_id = $params->{$p};
1477 } elsif ($p eq "key") {
1478 $key = $params->{$p};
1484 $where = "WHERE active ";
1486 if (ref($old_id) eq "ARRAY") {
1487 my @ids = grep({ $_ } @{$old_id});
1489 $where .= " OR id IN (" . join(",", map({ "?" } @ids)) . ") ";
1490 push(@values, @ids);
1493 $where .= " OR (id = ?) ";
1494 push(@values, $old_id);
1500 qq|SELECT id, projectnumber, description, active | .
1503 qq|ORDER BY lower(projectnumber)|;
1504 my $sth = $dbh->prepare($query);
1505 $sth->execute(@values) ||
1506 $self->dberror($query . " (" . join(", ", @values) . ")");
1509 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1510 push(@{ $self->{$key} }, $ref);
1514 $main::lxdebug->leave_sub();
1518 $main::lxdebug->enter_sub();
1520 my ($self, $dbh, $vc_id, $key) = @_;
1522 $key = "all_shipto" unless ($key);
1525 # get shipping addresses
1527 qq|SELECT s.shipto_id,s.shiptoname,s.shiptodepartment_1 | .
1528 qq|FROM shipto s | .
1529 qq|WHERE s.trans_id = ?|;
1530 my $sth = $dbh->prepare($query);
1531 $sth->execute($vc_id) || $self->dberror($query . " ($vc_id)");
1533 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1534 push(@{ $self->{$key} }, $ref);
1538 $main::lxdebug->leave_sub();
1542 $main::lxdebug->enter_sub();
1544 my ($self, $dbh, $key) = @_;
1546 $key = "all_printers" unless ($key);
1549 my $query = qq|SELECT id, printer_description, printer_command FROM printers|;
1550 my $sth = $dbh->prepare($query);
1551 $sth->execute() || $self->dberror($query);
1553 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1554 push(@{ $self->{$key} }, $ref);
1558 $main::lxdebug->leave_sub();
1562 $main::lxdebug->enter_sub();
1564 my ($self, $dbh, $params) = @_;
1566 $key = $params->{key};
1567 $key = "all_charts" unless ($key);
1570 my $transdate = quote_db_date($params->{transdate});
1573 qq|SELECT c.accno, c.description, c.link, tk.taxkey_id, tk.tax_id | .
1575 qq|LEFT JOIN taxkeys tk ON | .
1576 qq|(tk.id = (SELECT id FROM taxkeys | .
1577 qq| WHERE taxkeys.chart_id = c.id AND startdate <= $transdate | .
1578 qq| ORDER BY startdate DESC LIMIT 1)) | .
1579 qq|ORDER BY c.accno|;
1581 my $sth = $dbh->prepare($query);
1582 $sth->execute() || $self->dberror($query);
1584 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1585 push(@{ $self->{$key} }, $ref);
1589 $main::lxdebug->leave_sub();
1592 sub _get_taxcharts {
1593 $main::lxdebug->enter_sub();
1595 my ($self, $dbh, $key) = @_;
1597 $key = "all_taxcharts" unless ($key);
1600 my $query = qq|SELECT * FROM tax ORDER BY taxkey|;
1602 my $sth = $dbh->prepare($query);
1603 $sth->execute() || $self->dberror($query);
1605 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1606 push(@{ $self->{$key} }, $ref);
1610 $main::lxdebug->leave_sub();
1613 sub _get_employees {
1614 $main::lxdebug->enter_sub();
1616 my ($self, $dbh, $key) = @_;
1618 $key = "all_employees" unless ($key);
1620 selectall_hashref_query($self, $dbh, qq|SELECT * FROM employee|);
1622 $main::lxdebug->leave_sub();
1625 sub _get_business_types {
1626 $main::lxdebug->enter_sub();
1628 my ($self, $dbh, $key) = @_;
1630 $key = "all_business_types" unless ($key);
1632 selectall_hashref_query($self, $dbh, qq|SELECT * FROM business|);
1634 $main::lxdebug->leave_sub();
1638 $main::lxdebug->enter_sub();
1643 my $dbh = $self->dbconnect(\%main::myconfig);
1644 my ($sth, $query, $ref);
1646 my $vc = $self->{"vc"} eq "customer" ? "customer" : "vendor";
1647 my $vc_id = $self->{"${vc}_id"};
1649 if ($params{"contacts"}) {
1650 $self->_get_contacts($dbh, $vc_id, $params{"contacts"});
1653 if ($params{"shipto"}) {
1654 $self->_get_shipto($dbh, $vc_id, $params{"shipto"});
1657 if ($params{"projects"} || $params{"all_projects"}) {
1658 $self->_get_projects($dbh, $params{"all_projects"} ?
1659 $params{"all_projects"} : $params{"projects"},
1660 $params{"all_projects"} ? 1 : 0);
1663 if ($params{"printers"}) {
1664 $self->_get_printers($dbh, $params{"printers"});
1667 if ($params{"charts"}) {
1668 $self->_get_charts($dbh, $params{"charts"});
1671 if ($params{"taxcharts"}) {
1672 $self->_get_taxcharts($dbh, $params{"taxcharts"});
1675 if ($params{"employees"}) {
1676 $self->_get_employees($dbh, $params{"employees"});
1679 if ($params{"business_types"}) {
1680 $self->_get_business_types($dbh, $params{"business_types"});
1685 $main::lxdebug->leave_sub();
1688 # this sub gets the id and name from $table
1690 $main::lxdebug->enter_sub();
1692 my ($self, $myconfig, $table) = @_;
1694 # connect to database
1695 my $dbh = $self->dbconnect($myconfig);
1697 my $name = $self->like(lc $self->{$table});
1698 my $customernumber = $self->like(lc $self->{customernumber});
1700 if ($self->{customernumber} ne "") {
1701 $query = qq~SELECT c.id, c.name,
1702 c.street || ' ' || c.zipcode || ' ' || c.city || ' ' || c.country AS address
1704 WHERE (lower(c.customernumber) LIKE '$customernumber') AND (not c.obsolete)
1707 $query = qq~SELECT c.id, c.name,
1708 c.street || ' ' || c.zipcode || ' ' || c.city || ' ' || c.country AS address
1710 WHERE (lower(c.name) LIKE '$name') AND (not c.obsolete)
1714 if ($self->{openinvoices}) {
1715 $query = qq~SELECT DISTINCT c.id, c.name,
1716 c.street || ' ' || c.zipcode || ' ' || c.city || ' ' || c.country AS address
1717 FROM $self->{arap} a
1718 JOIN $table c ON (a.${table}_id = c.id)
1719 WHERE NOT a.amount = a.paid
1720 AND lower(c.name) LIKE '$name'
1723 my $sth = $dbh->prepare($query);
1725 $sth->execute || $self->dberror($query);
1728 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1729 push(@{ $self->{name_list} }, $ref);
1735 $main::lxdebug->leave_sub();
1740 # the selection sub is used in the AR, AP, IS, IR and OE module
1743 $main::lxdebug->enter_sub();
1745 my ($self, $myconfig, $table, $module) = @_;
1748 my $dbh = $self->dbconnect($myconfig);
1750 my $query = qq|SELECT count(*) FROM $table|;
1751 my $sth = $dbh->prepare($query);
1752 $sth->execute || $self->dberror($query);
1753 my ($count) = $sth->fetchrow_array;
1756 # build selection list
1757 if ($count < $myconfig->{vclimit}) {
1758 $query = qq|SELECT id, name, salesman_id
1759 FROM $table WHERE not obsolete
1761 $sth = $dbh->prepare($query);
1762 $sth->execute || $self->dberror($query);
1764 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1765 push @{ $self->{"all_$table"} }, $ref;
1773 $self->get_employee($dbh);
1775 # setup sales contacts
1776 $query = qq|SELECT e.id, e.name
1779 AND NOT e.id = $self->{employee_id}|;
1780 $sth = $dbh->prepare($query);
1781 $sth->execute || $self->dberror($query);
1783 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1784 push @{ $self->{all_employees} }, $ref;
1789 push @{ $self->{all_employees} },
1790 { id => $self->{employee_id},
1791 name => $self->{employee} };
1793 # sort the whole thing
1794 @{ $self->{all_employees} } =
1795 sort { $a->{name} cmp $b->{name} } @{ $self->{all_employees} };
1797 if ($module eq 'AR') {
1799 # prepare query for departments
1800 $query = qq|SELECT d.id, d.description
1806 $query = qq|SELECT d.id, d.description
1811 $sth = $dbh->prepare($query);
1812 $sth->execute || $self->dberror($query);
1814 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1815 push @{ $self->{all_departments} }, $ref;
1820 $query = qq|SELECT id, description
1823 $sth = $dbh->prepare($query);
1824 $sth->execute || $self->dberror($query);
1826 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1827 push @{ $self->{languages} }, $ref;
1832 $query = qq|SELECT printer_description, id
1835 $sth = $dbh->prepare($query);
1836 $sth->execute || $self->dberror($query);
1838 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1839 push @{ $self->{printers} }, $ref;
1845 $query = qq|SELECT id, description
1848 $sth = $dbh->prepare($query);
1849 $sth->execute || $self->dberror($query);
1851 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1852 push @{ $self->{payment_terms} }, $ref;
1856 $main::lxdebug->leave_sub();
1859 sub language_payment {
1860 $main::lxdebug->enter_sub();
1862 my ($self, $myconfig) = @_;
1863 undef $self->{languages};
1864 undef $self->{payment_terms};
1865 undef $self->{printers};
1868 my $dbh = $self->dbconnect($myconfig);
1870 my $query = qq|SELECT id, description
1873 my $sth = $dbh->prepare($query);
1874 $sth->execute || $self->dberror($query);
1876 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1877 push @{ $self->{languages} }, $ref;
1882 $query = qq|SELECT printer_description, id
1885 $sth = $dbh->prepare($query);
1886 $sth->execute || $self->dberror($query);
1888 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1889 push @{ $self->{printers} }, $ref;
1894 $query = qq|SELECT id, description
1897 $sth = $dbh->prepare($query);
1898 $sth->execute || $self->dberror($query);
1900 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1901 push @{ $self->{payment_terms} }, $ref;
1905 # get buchungsgruppen
1906 $query = qq|SELECT id, description
1907 FROM buchungsgruppen|;
1908 $sth = $dbh->prepare($query);
1909 $sth->execute || $self->dberror($query);
1911 $self->{BUCHUNGSGRUPPEN} = [];
1912 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1913 push @{ $self->{BUCHUNGSGRUPPEN} }, $ref;
1918 $main::lxdebug->leave_sub();
1921 # this is only used for reports
1922 sub all_departments {
1923 $main::lxdebug->enter_sub();
1925 my ($self, $myconfig, $table) = @_;
1927 my $dbh = $self->dbconnect($myconfig);
1928 my $where = "1 = 1";
1930 if (defined $table) {
1931 if ($table eq 'customer') {
1932 $where = " d.role = 'P'";
1936 my $query = qq|SELECT d.id, d.description
1940 my $sth = $dbh->prepare($query);
1941 $sth->execute || $self->dberror($query);
1943 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1944 push @{ $self->{all_departments} }, $ref;
1950 $main::lxdebug->leave_sub();
1954 $main::lxdebug->enter_sub();
1956 my ($self, $module, $myconfig, $table) = @_;
1958 $self->all_vc($myconfig, $table, $module);
1960 # get last customers or vendors
1963 my $dbh = $self->dbconnect($myconfig);
1968 my $transdate = "current_date";
1969 if ($self->{transdate}) {
1970 $transdate = qq|'$self->{transdate}'|;
1973 # now get the account numbers
1974 $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id
1975 FROM chart c, taxkeys tk
1976 WHERE c.link LIKE '%$module%' AND c.id=tk.chart_id AND tk.id =
1977 (SELECT id FROM taxkeys where taxkeys.chart_id = c.id AND startdate <= $transdate ORDER BY startdate desc LIMIT 1)
1980 $sth = $dbh->prepare($query);
1982 do_statement($form, $sth, $query);
1984 $self->{accounts} = "";
1985 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1987 foreach my $key (split(/:/, $ref->{link})) {
1988 if ($key =~ /$module/) {
1990 # cross reference for keys
1991 $xkeyref{ $ref->{accno} } = $key;
1993 push @{ $self->{"${module}_links"}{$key} },
1994 { accno => $ref->{accno},
1995 description => $ref->{description},
1996 taxkey => $ref->{taxkey_id},
1997 tax_id => $ref->{tax_id} };
1999 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2005 # get taxkeys and description
2006 $query = qq|SELECT id, taxkey, taxdescription FROM tax|;
2007 $self->{TAXKEY} = selectall_hashref_query($form, $dbh, $query);
2010 $query = qq|SELECT id, description FROM tax_zones|;
2011 $self->{TAXZONE} = selectall_hashref_query($form, $dbh, $query);
2013 if (($module eq "AP") || ($module eq "AR")) {
2014 # get tax rates and description
2015 $query = qq| SELECT * FROM tax t|;
2016 $self->{TAX} = selectall_hashref_query($form, $dbh, $query);
2020 my $arap = ($table eq 'customer') ? 'ar' : 'ap';
2022 $query = qq|SELECT a.cp_id, a.invnumber, a.transdate,
2023 a.${table}_id, a.datepaid, a.duedate, a.ordnumber,
2024 a.taxincluded, a.curr AS currency, a.notes, a.intnotes,
2025 c.name AS $table, a.department_id, d.description AS department,
2026 a.amount AS oldinvtotal, a.paid AS oldtotalpaid,
2027 a.employee_id, e.name AS employee, a.gldate, a.type
2029 JOIN $table c ON (a.${table}_id = c.id)
2030 LEFT JOIN employee e ON (e.id = a.employee_id)
2031 LEFT JOIN department d ON (d.id = a.department_id)
2032 WHERE a.id = $self->{id}|;
2033 $sth = $dbh->prepare($query);
2034 do_statement($form, $sth, $query);
2036 $ref = $sth->fetchrow_hashref(NAME_lc);
2037 foreach $key (keys %$ref) {
2038 $self->{$key} = $ref->{$key};
2043 my $transdate = "current_date";
2044 if ($self->{transdate}) {
2045 $transdate = qq|'$self->{transdate}'|;
2048 # now get the account numbers
2057 LEFT JOIN taxkeys tk ON (tk.chart_id = c.id)
2061 (tk.chart_id = c.id AND NOT c.link like '%_tax%')
2062 OR (NOT tk.chart_id = c.id AND c.link like '%_tax%')
2064 tk.id = ( SELECT id from taxkeys
2065 WHERE taxkeys.chart_id = c.id
2067 ORDER BY startdate desc LIMIT 1
2071 $sth = $dbh->prepare($query);
2072 do_statement($form, $sth, $query, "%$module%", $transdate);
2074 $self->{accounts} = "";
2075 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
2077 foreach my $key (split(/:/, $ref->{link})) {
2078 if ($key =~ /$module/) {
2080 # cross reference for keys
2081 $xkeyref{ $ref->{accno} } = $key;
2083 push @{ $self->{"${module}_links"}{$key} },
2084 { accno => $ref->{accno},
2085 description => $ref->{description},
2086 taxkey => $ref->{taxkey_id},
2087 tax_id => $ref->{tax_id} };
2089 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
2095 # get amounts from individual entries
2096 $query = qq|SELECT c.accno, c.description, a.source, a.amount, a.memo,
2097 a.transdate, a.cleared, a.project_id, p.projectnumber, a.taxkey, t.rate, t.id
2099 JOIN chart c ON (c.id = a.chart_id)
2100 LEFT JOIN project p ON (p.id = a.project_id)
2101 LEFT JOIN tax t ON (t.id=(SELECT tk.tax_id from taxkeys tk WHERE (tk.taxkey_id=a.taxkey) AND ((CASE WHEN a.chart_id IN (SELECT chart_id FROM taxkeys WHERE taxkey_id=a.taxkey) THEN tk.chart_id=a.chart_id ELSE 1=1 END) OR (c.link='%tax%')) AND startdate <=a.transdate ORDER BY startdate DESC LIMIT 1))
2102 WHERE a.trans_id = $self->{id}
2103 AND a.fx_transaction = '0'
2104 ORDER BY a.oid,a.transdate|;
2105 $sth = $dbh->prepare($query);
2106 do_statement($form, $sth, $query);
2108 my $fld = ($table eq 'customer') ? 'buy' : 'sell';
2110 # get exchangerate for currency
2111 $self->{exchangerate} =
2112 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate},
2116 # store amounts in {acc_trans}{$key} for multiple accounts
2117 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
2118 $ref->{exchangerate} =
2119 $self->get_exchangerate($dbh, $self->{currency}, $ref->{transdate},
2121 if (!($xkeyref{ $ref->{accno} } =~ /tax/)) {
2124 if (($xkeyref{ $ref->{accno} } =~ /paid/) && ($self->{type} eq "credit_note")) {
2125 $ref->{amount} *= -1;
2127 $ref->{index} = $index;
2129 push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref;
2133 $query = qq|SELECT d.curr AS currencies, d.closedto, d.revtrans,
2134 (SELECT c.accno FROM chart c
2135 WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2136 (SELECT c.accno FROM chart c
2137 WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2139 $sth = $dbh->prepare($query);
2140 do_statement($form, $sth, $query);
2142 $ref = $sth->fetchrow_hashref(NAME_lc);
2143 map { $self->{$_} = $ref->{$_} } keys %$ref;
2149 $query = qq|SELECT current_date AS transdate,
2150 d.curr AS currencies, d.closedto, d.revtrans,
2151 (SELECT c.accno FROM chart c
2152 WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
2153 (SELECT c.accno FROM chart c
2154 WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
2156 $sth = $dbh->prepare($query);
2157 do_statement($form, $sth, $query);
2159 $ref = $sth->fetchrow_hashref(NAME_lc);
2160 map { $self->{$_} = $ref->{$_} } keys %$ref;
2163 if ($self->{"$self->{vc}_id"}) {
2165 # only setup currency
2166 ($self->{currency}) = split(/:/, $self->{currencies});
2170 $self->lastname_used($dbh, $myconfig, $table, $module);
2172 my $fld = ($table eq 'customer') ? 'buy' : 'sell';
2174 # get exchangerate for currency
2175 $self->{exchangerate} =
2176 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate},
2187 $main::lxdebug->leave_sub();
2191 $main::lxdebug->enter_sub();
2193 my ($self, $dbh, $myconfig, $table, $module) = @_;
2195 my $arap = ($table eq 'customer') ? "ar" : "ap";
2196 my $where = "1 = 1";
2198 if ($self->{type} =~ /_order/) {
2200 $where = "quotation = '0'";
2202 if ($self->{type} =~ /_quotation/) {
2204 $where = "quotation = '1'";
2207 my $query = qq|SELECT MAX(id) FROM $arap
2209 AND ${table}_id > 0|;
2210 my $sth = $dbh->prepare($query);
2211 $sth->execute || $self->dberror($query);
2213 my ($trans_id) = $sth->fetchrow_array;
2217 $query = qq|SELECT ct.name, a.curr, a.${table}_id,
2218 current_date + ct.terms AS duedate, a.department_id,
2219 d.description AS department
2221 JOIN $table ct ON (a.${table}_id = ct.id)
2222 LEFT JOIN department d ON (a.department_id = d.id)
2223 WHERE a.id = $trans_id|;
2224 $sth = $dbh->prepare($query);
2225 $sth->execute || $self->dberror($query);
2227 ($self->{$table}, $self->{currency}, $self->{"${table}_id"},
2228 $self->{duedate}, $self->{department_id}, $self->{department})
2229 = $sth->fetchrow_array;
2232 $main::lxdebug->leave_sub();
2236 $main::lxdebug->enter_sub();
2238 my ($self, $myconfig, $thisdate, $days) = @_;
2240 my $dbh = $self->dbconnect($myconfig);
2245 my $dateformat = $myconfig->{dateformat};
2246 $dateformat .= "yy" if $myconfig->{dateformat} !~ /^y/;
2248 $query = qq|SELECT to_date('$thisdate', '$dateformat') + $days AS thisdate
2250 $sth = $dbh->prepare($query);
2251 $sth->execute || $self->dberror($query);
2253 $query = qq|SELECT current_date AS thisdate
2255 $sth = $dbh->prepare($query);
2256 $sth->execute || $self->dberror($query);
2259 ($thisdate) = $sth->fetchrow_array;
2264 $main::lxdebug->leave_sub();
2270 $main::lxdebug->enter_sub();
2272 my ($self, $string) = @_;
2274 if ($string !~ /%/) {
2275 $string = "%$string%";
2278 $string =~ s/\'/\'\'/g;
2280 $main::lxdebug->leave_sub();
2286 $main::lxdebug->enter_sub();
2288 my ($self, $flds, $new, $count, $numrows) = @_;
2292 map { push @ndx, { num => $new->[$_ - 1]->{runningnumber}, ndx => $_ } }
2298 foreach my $item (sort { $a->{num} <=> $b->{num} } @ndx) {
2300 $j = $item->{ndx} - 1;
2301 map { $self->{"${_}_$i"} = $new->[$j]->{$_} } @{$flds};
2305 for $i ($count + 1 .. $numrows) {
2306 map { delete $self->{"${_}_$i"} } @{$flds};
2309 $main::lxdebug->leave_sub();
2313 $main::lxdebug->enter_sub();
2315 my ($self, $myconfig) = @_;
2319 my $dbh = $self->dbconnect_noauto($myconfig);
2321 my $query = qq|DELETE FROM status
2322 WHERE formname = '$self->{formname}'
2324 my $sth = $dbh->prepare($query) || $self->dberror($query);
2326 if ($self->{formname} =~ /(check|receipt)/) {
2327 for $i (1 .. $self->{rowcount}) {
2328 $sth->execute($self->{"id_$i"} * 1) || $self->dberror($query);
2332 $sth->execute($self->{id}) || $self->dberror($query);
2336 my $printed = ($self->{printed} =~ /$self->{formname}/) ? "1" : "0";
2337 my $emailed = ($self->{emailed} =~ /$self->{formname}/) ? "1" : "0";
2339 my %queued = split / /, $self->{queued};
2341 if ($self->{formname} =~ /(check|receipt)/) {
2343 # this is a check or receipt, add one entry for each lineitem
2344 my ($accno) = split /--/, $self->{account};
2345 $query = qq|INSERT INTO status (trans_id, printed, spoolfile, formname,
2346 chart_id) VALUES (?, '$printed',
2347 '$queued{$self->{formname}}', '$self->{prinform}',
2348 (SELECT c.id FROM chart c WHERE c.accno = '$accno'))|;
2349 $sth = $dbh->prepare($query) || $self->dberror($query);
2351 for $i (1 .. $self->{rowcount}) {
2352 if ($self->{"checked_$i"}) {
2353 $sth->execute($self->{"id_$i"}) || $self->dberror($query);
2358 $query = qq|INSERT INTO status (trans_id, printed, emailed,
2359 spoolfile, formname)
2360 VALUES ($self->{id}, '$printed', '$emailed',
2361 '$queued{$self->{formname}}', '$self->{formname}')|;
2362 $dbh->do($query) || $self->dberror($query);
2368 $main::lxdebug->leave_sub();
2372 # $main::locale->text('SAVED')
2373 # $main::locale->text('DELETED')
2374 # $main::locale->text('ADDED')
2375 # $main::locale->text('PAYMENT POSTED')
2376 # $main::locale->text('POSTED')
2377 # $main::locale->text('POSTED AS NEW')
2378 # $main::locale->text('ELSE')
2379 # $main::locale->text('SAVED FOR DUNNING')
2380 # $main::locale->text('DUNNING STARTED')
2381 # $main::locale->text('PRINTED')
2382 # $main::locale->text('MAILED')
2383 # $main::locale->text('SCREENED')
2384 # $main::locale->text('invoice')
2385 # $main::locale->text('proforma')
2386 # $main::locale->text('sales_order')
2387 # $main::locale->text('packing_list')
2388 # $main::locale->text('pick_list')
2389 # $main::locale->text('purchase_order')
2390 # $main::locale->text('bin_list')
2391 # $main::locale->text('sales_quotation')
2392 # $main::locale->text('request_quotation')
2395 $main::lxdebug->enter_sub();
2400 if(!exists $self->{employee_id}) {
2401 &get_employee($self, $dbh);
2405 qq|INSERT INTO history_erp (trans_id, employee_id, addition, what_done) | .
2406 qq|VALUES (?, ?, ?, ?)|;
2407 my @values = (conv_i($self->{id}), conv_i($self->{employee_id}),
2408 $self->{addition}, $self->{what_done});
2409 do_query($self, $dbh, $query, @values);
2411 $main::lxdebug->leave_sub();
2415 $main::lxdebug->enter_sub();
2419 my $trans_id = shift();
2420 my $restriction = shift();
2423 if ($trans_id ne "") {
2425 qq|SELECT h.employee_id, h.itime::timestamp(0) AS itime, h.addition, h.what_done, emp.name | .
2426 qq|FROM history_erp h | .
2427 qq|LEFT JOIN employee emp | .
2428 qq|ON emp.id = h.employee_id | .
2429 qq|WHERE trans_id = ? |
2432 my $sth = $dbh->prepare($query) || $self->dberror($query);
2434 $sth->execute($trans_id) || $self->dberror("$query ($trans_id)");
2436 while(my $hash_ref = $sth->fetchrow_hashref()) {
2437 $hash_ref->{addition} = $main::locale->text($hash_ref->{addition});
2438 $hash_ref->{what_done} = $main::locale->text($hash_ref->{what_done});
2439 $tempArray[$i++] = $hash_ref;
2441 $main::lxdebug->leave_sub() and return \@tempArray
2442 if ($i > 0 && $tempArray[0] ne "");
2444 $main::lxdebug->leave_sub();
2449 $main::lxdebug->enter_sub();
2451 my ($self, $dbh) = @_;
2453 my ($query, $printed, $emailed);
2455 my $formnames = $self->{printed};
2456 my $emailforms = $self->{emailed};
2458 $query = qq|DELETE FROM status
2459 WHERE formname = '$self->{formname}'
2460 AND trans_id = $self->{id}|;
2461 $dbh->do($query) || $self->dberror($query);
2463 # this only applies to the forms
2464 # checks and receipts are posted when printed or queued
2466 if ($self->{queued}) {
2467 my %queued = split / /, $self->{queued};
2469 foreach my $formname (keys %queued) {
2470 $printed = ($self->{printed} =~ /$self->{formname}/) ? "1" : "0";
2471 $emailed = ($self->{emailed} =~ /$self->{formname}/) ? "1" : "0";
2473 $query = qq|INSERT INTO status (trans_id, printed, emailed,
2474 spoolfile, formname)
2475 VALUES ($self->{id}, '$printed', '$emailed',
2476 '$queued{$formname}', '$formname')|;
2477 $dbh->do($query) || $self->dberror($query);
2479 $formnames =~ s/$self->{formname}//;
2480 $emailforms =~ s/$self->{formname}//;
2485 # save printed, emailed info
2486 $formnames =~ s/^ +//g;
2487 $emailforms =~ s/^ +//g;
2490 map { $status{$_}{printed} = 1 } split / +/, $formnames;
2491 map { $status{$_}{emailed} = 1 } split / +/, $emailforms;
2493 foreach my $formname (keys %status) {
2494 $printed = ($formnames =~ /$self->{formname}/) ? "1" : "0";
2495 $emailed = ($emailforms =~ /$self->{formname}/) ? "1" : "0";
2497 $query = qq|INSERT INTO status (trans_id, printed, emailed, formname)
2498 VALUES ($self->{id}, '$printed', '$emailed', '$formname')|;
2499 $dbh->do($query) || $self->dberror($query);
2502 $main::lxdebug->leave_sub();
2505 sub update_defaults {
2506 $main::lxdebug->enter_sub();
2508 my ($self, $myconfig, $fld, $provided_dbh) = @_;
2511 if ($provided_dbh) {
2512 $dbh = $provided_dbh;
2514 $dbh = $self->dbconnect_noauto($myconfig);
2516 my $query = qq|SELECT $fld FROM defaults FOR UPDATE|;
2517 my $sth = $dbh->prepare($query);
2519 $sth->execute || $self->dberror($query);
2520 my ($var) = $sth->fetchrow_array;
2525 $query = qq|UPDATE defaults
2527 $dbh->do($query) || $self->dberror($query);
2529 if (!$provided_dbh) {
2534 $main::lxdebug->leave_sub();
2539 sub update_business {
2540 $main::lxdebug->enter_sub();
2542 my ($self, $myconfig, $business_id, $provided_dbh) = @_;
2545 if ($provided_dbh) {
2546 $dbh = $provided_dbh;
2548 $dbh = $self->dbconnect_noauto($myconfig);
2551 qq|SELECT customernumberinit FROM business WHERE id=$business_id FOR UPDATE|;
2552 my $sth = $dbh->prepare($query);
2554 $sth->execute || $self->dberror($query);
2555 my ($var) = $sth->fetchrow_array;
2560 $query = qq|UPDATE business
2561 SET customernumberinit = '$var' WHERE id=$business_id|;
2562 $dbh->do($query) || $self->dberror($query);
2564 if (!$provided_dbh) {
2569 $main::lxdebug->leave_sub();
2574 sub get_partsgroup {
2575 $main::lxdebug->enter_sub();
2577 my ($self, $myconfig, $p) = @_;
2579 my $dbh = $self->dbconnect($myconfig);
2581 my $query = qq|SELECT DISTINCT pg.id, pg.partsgroup
2583 JOIN parts p ON (p.partsgroup_id = pg.id)|;
2585 if ($p->{searchitems} eq 'part') {
2587 WHERE p.inventory_accno_id > 0|;
2589 if ($p->{searchitems} eq 'service') {
2591 WHERE p.inventory_accno_id IS NULL|;
2593 if ($p->{searchitems} eq 'assembly') {
2595 WHERE p.assembly = '1'|;
2597 if ($p->{searchitems} eq 'labor') {
2599 WHERE p.inventory_accno_id > 0 AND p.income_accno_id IS NULL|;
2603 ORDER BY partsgroup|;
2606 $query = qq|SELECT id, partsgroup FROM partsgroup
2607 ORDER BY partsgroup|;
2610 if ($p->{language_code}) {
2611 $query = qq|SELECT DISTINCT pg.id, pg.partsgroup,
2612 t.description AS translation
2614 JOIN parts p ON (p.partsgroup_id = pg.id)
2615 LEFT JOIN translation t ON (t.trans_id = pg.id AND t.language_code = '$p->{language_code}')
2616 ORDER BY translation|;
2619 my $sth = $dbh->prepare($query);
2620 $sth->execute || $self->dberror($query);
2622 $self->{all_partsgroup} = ();
2623 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
2624 push @{ $self->{all_partsgroup} }, $ref;
2628 $main::lxdebug->leave_sub();
2631 sub get_pricegroup {
2632 $main::lxdebug->enter_sub();
2634 my ($self, $myconfig, $p) = @_;
2636 my $dbh = $self->dbconnect($myconfig);
2638 my $query = qq|SELECT p.id, p.pricegroup
2642 ORDER BY pricegroup|;
2645 $query = qq|SELECT id, pricegroup FROM pricegroup
2646 ORDER BY pricegroup|;
2649 my $sth = $dbh->prepare($query);
2650 $sth->execute || $self->dberror($query);
2652 $self->{all_pricegroup} = ();
2653 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
2654 push @{ $self->{all_pricegroup} }, $ref;
2659 $main::lxdebug->leave_sub();
2663 my ($self, $dbh, $myconfig, $audittrail) = @_;
2665 # table, $reference, $formname, $action, $id, $transdate) = @_;
2672 $dbh = $self->dbconnect($myconfig);
2676 # if we have an id add audittrail, otherwise get a new timestamp
2678 if ($audittrail->{id}) {
2680 $query = qq|SELECT audittrail FROM defaults|;
2682 if ($dbh->selectrow_array($query)) {
2683 my ($null, $employee_id) = $self->get_employee($dbh);
2685 if ($self->{audittrail} && !$myconfig) {
2686 chop $self->{audittrail};
2688 my @a = split /\|/, $self->{audittrail};
2692 my @flds = qw(tablename reference formname action transdate);
2694 # put into hash and remove dups
2696 $key = "$a[2]$a[3]";
2698 $newtrail{$key} = { map { $_ => $a[$i++] } @flds };
2702 $query = qq|INSERT INTO audittrail (trans_id, tablename, reference,
2703 formname, action, employee_id, transdate)
2704 VALUES ($audittrail->{id}, ?, ?,
2705 ?, ?, $employee_id, ?)|;
2706 my $sth = $dbh->prepare($query) || $self->dberror($query);
2710 $newtrail{$a}{transdate} cmp $newtrail{$b}{transdate}
2714 for (@flds) { $sth->bind_param($i++, $newtrail{$key}{$_}) }
2716 $sth->execute || $self->dberror;
2721 if ($audittrail->{transdate}) {
2722 $query = qq|INSERT INTO audittrail (trans_id, tablename, reference,
2723 formname, action, employee_id, transdate) VALUES (
2724 $audittrail->{id}, '$audittrail->{tablename}', |
2725 . $dbh->quote($audittrail->{reference}) . qq|,
2726 '$audittrail->{formname}', '$audittrail->{action}',
2727 $employee_id, '$audittrail->{transdate}')|;
2729 $query = qq|INSERT INTO audittrail (trans_id, tablename, reference,
2730 formname, action, employee_id) VALUES ($audittrail->{id},
2731 '$audittrail->{tablename}', |
2732 . $dbh->quote($audittrail->{reference}) . qq|,
2733 '$audittrail->{formname}', '$audittrail->{action}',
2740 $query = qq|SELECT current_timestamp FROM defaults|;
2741 my ($timestamp) = $dbh->selectrow_array($query);
2744 "$audittrail->{tablename}|$audittrail->{reference}|$audittrail->{formname}|$audittrail->{action}|$timestamp|";
2747 $dbh->disconnect if $disconnect;
2755 # usage $form->all_years($myconfig, [$dbh])
2756 # return list of all years where bookings found
2759 $main::lxdebug->enter_sub();
2761 my ($self, $myconfig, $dbh) = @_;
2765 $dbh = $self->dbconnect($myconfig);
2770 my $query = qq|SELECT (SELECT MIN(transdate) FROM acc_trans),
2771 (SELECT MAX(transdate) FROM acc_trans)
2773 my ($startdate, $enddate) = $dbh->selectrow_array($query);
2775 if ($myconfig->{dateformat} =~ /^yy/) {
2776 ($startdate) = split /\W/, $startdate;
2777 ($enddate) = split /\W/, $enddate;
2779 (@_) = split /\W/, $startdate;
2781 (@_) = split /\W/, $enddate;
2786 $startdate = substr($startdate,0,4);
2787 $enddate = substr($enddate,0,4);
2789 while ($enddate >= $startdate) {
2790 push @all_years, $enddate--;
2793 $dbh->disconnect if $disconnect;
2797 $main::lxdebug->leave_sub();