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 #======================================================================
41 $main::lxdebug->enter_sub();
45 my @pairs = split(/&/, $input);
48 my ($name, $value) = split(/=/, $_, 2);
49 $in{$name} = unescape(undef, $value);
52 $main::lxdebug->leave_sub();
57 sub _request_to_hash {
58 $main::lxdebug->enter_sub();
61 my ($i, $loc, $key, $val);
62 my (%ATTACH, $f, $header, $header_body, $len, $buf);
63 my ($boundary, @list, $size, $body, $x, $blah, $name);
65 if ($ENV{'CONTENT_TYPE'}
66 && ($ENV{'CONTENT_TYPE'} =~ /multipart\/form-data; boundary=(.+)$/)) {
67 $boundary = quotemeta('--' . $1);
68 @list = split(/$boundary/, $input);
70 # For some reason there are always 2 extra, that are empty
73 for ($x = 1; $x <= $size; $x++) {
74 $header_body = $list[$x];
75 $header_body =~ /\r\n\r\n|\n\n/;
77 # Here we split the header and body
82 # Now we try to get the file name
84 $name =~ /name=\"(.+)\"/;
85 ($name, $blah) = split(/\"/, $1);
87 # If the form name is not attach, then we need to parse this like
89 if ($name ne "attach") {
90 $body =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
91 $ATTACH{$name} = $body;
93 # Otherwise it is an attachment and we need to finish it up
94 } elsif ($name eq "attach") {
95 $header =~ /filename=\"(.+)\"/;
96 $ATTACH{'FILE_NAME'} = $1;
97 $ATTACH{'FILE_NAME'} =~ s/\"//g;
98 $ATTACH{'FILE_NAME'} =~ s/\s//g;
99 $ATTACH{'FILE_CONTENT'} = $body;
101 for ($i = $x; $list[$i]; $i++) {
102 $list[$i] =~ s/^.+name=$//;
103 $list[$i] =~ /\"(\w+)\"/;
109 $main::lxdebug->leave_sub();
113 $main::lxdebug->leave_sub();
114 return _input_to_hash($input);
119 $main::lxdebug->enter_sub();
125 read(STDIN, $_, $ENV{CONTENT_LENGTH});
127 if ($ENV{QUERY_STRING}) {
128 $_ = $ENV{QUERY_STRING};
135 my %parameters = _request_to_hash($_);
136 map({ $self->{$_} = $parameters{$_}; } keys(%parameters));
138 $self->{menubar} = 1 if $self->{path} =~ /lynx/i;
140 $self->{action} = lc $self->{action};
141 $self->{action} =~ s/( |-|,|#)/_/g;
143 $self->{version} = "2.1.2";
144 $self->{dbversion} = "2.1.2";
146 $main::lxdebug->leave_sub();
152 $main::lxdebug->enter_sub();
158 map { print "$_ = $self->{$_}\n" } (sort keys %{$self});
160 $main::lxdebug->leave_sub();
164 $main::lxdebug->enter_sub();
166 my ($self, $str, $beenthere) = @_;
168 # for Apache 2 we escape strings twice
169 #if (($ENV{SERVER_SOFTWARE} =~ /Apache\/2/) && !$beenthere) {
170 # $str = $self->escape($str, 1);
173 $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
175 $main::lxdebug->leave_sub();
181 $main::lxdebug->enter_sub();
183 my ($self, $str) = @_;
188 $str =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
190 $main::lxdebug->leave_sub();
196 $main::lxdebug->enter_sub();
198 my ($self, $msg) = @_;
200 if ($ENV{HTTP_USER_AGENT}) {
208 <h2 class=error>Error!</h2>
220 if ($self->{error_function}) {
221 &{ $self->{error_function} }($msg);
227 $main::lxdebug->leave_sub();
231 $main::lxdebug->enter_sub();
233 my ($self, $msg) = @_;
235 if ($ENV{HTTP_USER_AGENT}) {
238 if (!$self->{header}) {
251 if ($self->{info_function}) {
252 &{ $self->{info_function} }($msg);
258 $main::lxdebug->leave_sub();
262 $main::lxdebug->enter_sub();
264 my ($self, $str, $cols, $maxrows) = @_;
268 map { $rows += int(((length) - 2) / $cols) + 1 } split /\r/, $str;
270 $maxrows = $rows unless defined $maxrows;
272 $main::lxdebug->leave_sub();
274 return ($rows > $maxrows) ? $maxrows : $rows;
278 $main::lxdebug->enter_sub();
280 my ($self, $msg) = @_;
282 $self->error("$msg\n" . $DBI::errstr);
284 $main::lxdebug->leave_sub();
288 $main::lxdebug->enter_sub();
290 my ($self, $name, $msg) = @_;
292 if ($self->{$name} =~ /^\s*$/) {
295 $main::lxdebug->leave_sub();
299 $main::lxdebug->enter_sub();
303 if ($self->{header}) {
304 $main::lxdebug->leave_sub();
308 my ($stylesheet, $favicon, $charset);
310 if ($ENV{HTTP_USER_AGENT}) {
312 if ($self->{stylesheet} && (-f "css/$self->{stylesheet}")) {
314 qq|<LINK REL="stylesheet" HREF="css/$self->{stylesheet}" TYPE="text/css" TITLE="Lx-Office stylesheet">
318 if ($self->{favicon} && (-f "$self->{favicon}")) {
320 qq|<LINK REL="shortcut icon" HREF="$self->{favicon}" TYPE="image/x-icon">
324 if ($self->{charset}) {
326 qq|<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=$self->{charset}">
329 if ($self->{landscape}) {
330 $pagelayout = qq|<style type="text/css">
331 \@page { size:landscape; }
334 if ($self->{fokus}) {
335 $fokus = qq|<script type="text/javascript">
337 function fokus(){document.$self->{fokus}.focus();}
344 if ($self->{jsscript} == 1) {
347 <style type="text/css">\@import url(js/jscalendar/calendar-win2k-1.css);</style>
348 <script type="text/javascript" src="js/jscalendar/calendar.js"></script>
349 Â <script type="text/javascript" src="js/jscalendar/lang/calendar-de.js"></script>
350 Â <script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script>
356 ? "$self->{title} - $self->{titlebar}"
359 print qq|Content-Type: text/html
362 <title>$self->{titlebar}</title>
375 $main::lxdebug->leave_sub();
378 # write Trigger JavaScript-Code ($qty = 1 - only one Trigger)
380 $main::lxdebug->enter_sub();
382 my ($self, $myconfig, $qty,
383 $inputField_1, $align_1, $button_1,
384 $inputField_2, $align_2, $button_2)
387 # set dateform for jsscript
389 $ifFormat = "%d.%m.%Y";
390 if ($myconfig->{dateformat} eq "dd.mm.yy") {
391 $ifFormat = "%d.%m.%Y";
393 if ($myconfig->{dateformat} eq "dd-mm-yy") {
394 $ifFormat = "%d-%m-%Y";
396 if ($myconfig->{dateformat} eq "dd/mm/yy") {
397 $ifFormat = "%d/%m/%Y";
399 if ($myconfig->{dateformat} eq "mm/dd/yy") {
400 $ifFormat = "%m/%d/%Y";
402 if ($myconfig->{dateformat} eq "mm-dd-yy") {
403 $ifFormat = "%m-%d-%Y";
405 if ($myconfig->{dateformat} eq "yyyy-mm-dd") {
406 $ifFormat = "%Y-%m-%d";
417    inputField  : "$inputField_1",
418    ifFormat    :"$ifFormat",
419    align    : "$align_1",    Â
420    button      : "$button_1"
429    inputField  : "$inputField_2",
430    ifFormat    :"$ifFormat",
431    align    : "$align_2",    Â
432    button      : "$button_2"
438 <script type="text/javascript">
446 $main::lxdebug->leave_sub();
449 } #end sub write_trigger
452 $main::lxdebug->enter_sub();
454 my ($self, $msg) = @_;
456 if ($self->{callback}) {
458 ($script, $argv) = split(/\?/, $self->{callback});
459 exec("perl", "$script", $argv);
467 $main::lxdebug->leave_sub();
470 # sort of columns removed - empty sub
472 $main::lxdebug->enter_sub();
474 my ($self, @columns) = @_;
476 $main::lxdebug->leave_sub();
482 $main::lxdebug->enter_sub();
484 my ($self, $myconfig, $amount, $places, $dash) = @_;
486 if ($places =~ /\d/) {
487 $amount = $self->round_amount($amount, $places);
490 # is the amount negative
491 my $negative = ($amount < 0);
494 if ($myconfig->{numberformat} && ($myconfig->{numberformat} ne '1000.00'))
496 my ($whole, $dec) = split /\./, "$amount";
498 $amount = join '', reverse split //, $whole;
500 if ($myconfig->{numberformat} eq '1,000.00') {
501 $amount =~ s/\d{3,}?/$&,/g;
503 $amount = join '', reverse split //, $amount;
504 $amount .= "\.$dec" if ($dec ne "");
507 if ($myconfig->{numberformat} eq '1.000,00') {
508 $amount =~ s/\d{3,}?/$&./g;
510 $amount = join '', reverse split //, $amount;
511 $amount .= ",$dec" if ($dec ne "");
514 if ($myconfig->{numberformat} eq '1000,00') {
516 $amount .= ",$dec" if ($dec ne "");
520 $amount = ($negative) ? "($amount)" : "$amount";
521 } elsif ($dash =~ /DRCR/) {
522 $amount = ($negative) ? "$amount DR" : "$amount CR";
524 $amount = ($negative) ? "-$amount" : "$amount";
528 if ($dash eq "0" && $places) {
529 if ($myconfig->{numberformat} eq '1.000,00') {
530 $amount = "0" . "," . "0" x $places;
532 $amount = "0" . "." . "0" x $places;
535 $amount = ($dash ne "") ? "$dash" : "0";
539 $main::lxdebug->leave_sub();
545 $main::lxdebug->enter_sub();
547 my ($self, $myconfig, $amount) = @_;
549 if (!(substr($amount, -3, 1) eq ".")) {
550 if ( ($myconfig->{numberformat} eq '1.000,00')
551 || ($myconfig->{numberformat} eq '1000,00')) {
559 $main::lxdebug->leave_sub();
561 return ($amount * 1);
565 $main::lxdebug->enter_sub();
567 my ($self, $amount, $places) = @_;
570 # $places = 3 if $places == 2;
572 if (($places * 1) >= 0) {
576 sprintf("%.${places}f",
577 $amount + (1 / (10**($places + 3))) * (($amount > 0) ? 1 : -1));
581 sprintf("%.f", $amount / (10**$places) + (($amount > 0) ? 0.1 : -0.1)) *
585 $main::lxdebug->leave_sub();
591 $main::lxdebug->enter_sub();
593 my ($self, $myconfig, $userspath) = @_;
596 # Some variables used for page breaks
597 my ($chars_per_line, $lines_on_first_page, $lines_on_second_page) =
599 my ($current_page, $current_line) = (1, 1);
605 # Make sure that all *notes* (intnotes, partnotes_*, notes etc) are converted to markup correctly.
606 $self->format_string(grep(/notes/, keys(%{$self})));
608 # Copy the notes from the invoice/sales order etc. back to the variable "notes" because that is where most templates expect it to be.
609 $self->{"notes"} = $self->{ $self->{"formname"} . "notes" };
611 map({ $self->{"employee_${_}"} = $myconfig->{$_}; }
612 qw(email tel fax name signature));
614 open(IN, "$self->{templates}/$self->{IN}")
615 or $self->error("$self->{IN} : $!");
620 $self->{copies} = 1 if (($self->{copies} *= 1) <= 0);
622 # OUT is used for the media, screen, printer, email
623 # for postscript we store a copy in a temporary file
625 $self->{tmpfile} = "$userspath/${fileid}.$self->{IN}";
626 if ($self->{format} =~ /(postscript|pdf)/ || $self->{media} eq 'email') {
628 $self->{OUT} = ">$self->{tmpfile}";
632 open(OUT, "$self->{OUT}") or $self->error("$self->{OUT} : $!");
634 open(OUT, ">-") or $self->error("STDOUT : $!");
638 # Do we have to run LaTeX two times? This is needed if
639 # the template contains page references.
642 # first we generate a tmpfile
643 # read file and replace <%variable%>
649 $two_passes = 1 if (/\\pageref/);
652 # detect pagebreak block and its parameters
653 if (/\s*<%pagebreak ([0-9]+) ([0-9]+) ([0-9]+)%>/) {
654 $chars_per_line = $1;
655 $lines_on_first_page = $2;
656 $lines_on_second_page = $3;
659 last if (/\s*<%end pagebreak%>/);
666 if (/\s*<%foreach /) {
668 # this one we need for the count
670 $var =~ s/\s*<%foreach (.+?)%>/$1/;
672 last if (/\s*<%end /);
678 # display contents of $self->{number}[] array
679 for $i (0 .. $#{ $self->{$var} }) {
682 # Try to detect whether a manual page break is necessary
683 # but only if there was a <%pagebreak ...%> block before
685 if ($chars_per_line) {
687 int(length($self->{"description"}[$i]) / $chars_per_line + 0.95);
690 my $_description = $self->{"description"}[$i];
691 while ($_description =~ /\\newline/) {
693 $_description =~ s/\\newline//;
695 $self->{"description"}[$i] =~ s/(\\newline\s?)*$//;
697 if ($current_page == 1) {
698 $lpp = $lines_on_first_page;
700 $lpp = $lines_on_second_page;
703 # Yes we need a manual page break
704 if (($current_line + $lines) > $lpp) {
707 # replace the special variables <%sumcarriedforward%>
710 my $psum = $self->format_amount($myconfig, $sum, 2);
711 $pb =~ s/<%sumcarriedforward%>/$psum/g;
712 $pb =~ s/<%lastpage%>/$current_page/g;
714 # only "normal" variables are supported here
715 # (no <%if, no <%foreach, no <%include)
717 $pb =~ s/<%(.+?)%>/$self->{$1}/g;
719 # page break block is ready to rock
724 $current_line += $lines;
726 $sum += $self->parse_amount($myconfig, $self->{"linetotal"}[$i]);
730 # don't parse par, we need it for each line
732 s/<%(.+?)%>/$self->{$1}[$i]/mg;
738 # if not comes before if!
739 if (/\s*<%if not /) {
741 # check if it is not set and display
743 s/\s*<%if not (.+?)%>/$1/;
745 unless ($self->{$_}) {
747 last if (/\s*<%end /);
757 last if (/\s*<%end /);
765 # check if it is set and display
767 s/\s*<%if (.+?)%>/$1/;
771 last if (/\s*<%end /);
781 last if (/\s*<%end /);
787 # check for <%include filename%>
788 if (/\s*<%include /) {
792 $var =~ s/\s*<%include (.+?)%>/$1/;
795 $var =~ s/(\/|\.\.)//g;
797 # prevent the infinite loop!
798 next if ($self->{"$var"});
800 open(INC, "$self->{templates}/$var")
801 or $self->error($self->cleanup . "$self->{templates}/$var : $!");
810 s/<%(.+?)%>/$self->{$1}/g;
817 # Convert the tex file to postscript
818 if ($self->{format} =~ /(postscript|pdf)/) {
821 $self->{cwd} = cwd();
822 $self->{tmpdir} = "$self->{cwd}/$userspath";
824 chdir("$userspath") or $self->error($self->cleanup . "chdir : $!");
826 $self->{tmpfile} =~ s/$userspath\///g;
828 if ($self->{format} eq 'postscript') {
830 "latex --interaction=nonstopmode $self->{tmpfile} > $self->{tmpfile}.err"
832 $self->error($self->cleanup) if ($?);
835 "latex --interaction=nonstopmode $self->{tmpfile} > $self->{tmpfile}.err"
837 $self->error($self->cleanup) if ($?);
840 $self->{tmpfile} =~ s/tex$/dvi/;
842 system("dvips $self->{tmpfile} -o -q > /dev/null");
843 $self->error($self->cleanup . "dvips : $!") if ($?);
844 $self->{tmpfile} =~ s/dvi$/ps/;
846 if ($self->{format} eq 'pdf') {
848 "pdflatex --interaction=nonstopmode $self->{tmpfile} > $self->{tmpfile}.err"
850 $self->error($self->cleanup) if ($?);
853 "pdflatex --interaction=nonstopmode $self->{tmpfile} > $self->{tmpfile}.err"
855 $self->error($self->cleanup) if ($?);
857 $self->{tmpfile} =~ s/tex$/pdf/;
862 if ($self->{format} =~ /(postscript|pdf)/ || $self->{media} eq 'email') {
864 if ($self->{media} eq 'email') {
868 my $mail = new Mailer;
870 map { $mail->{$_} = $self->{$_} }
871 qw(cc bcc subject message version format charset);
872 $mail->{to} = qq|$self->{email}|;
873 $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
874 $mail->{fileid} = "$fileid.";
876 # if we send html or plain text inline
877 if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
878 $mail->{contenttype} = "text/html";
880 $mail->{message} =~ s/\r\n/<br>\n/g;
881 $myconfig->{signature} =~ s/\\n/<br>\n/g;
882 $mail->{message} .= "<br>\n--<br>\n$myconfig->{signature}\n<br>";
884 open(IN, $self->{tmpfile})
885 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
887 $mail->{message} .= $_;
894 @{ $mail->{attachments} } = ($self->{tmpfile});
896 $myconfig->{signature} =~ s/\\n/\r\n/g;
897 $mail->{message} .= "\r\n--\r\n$myconfig->{signature}";
901 my $err = $mail->send($out);
902 $self->error($self->cleanup . "$err") if ($err);
908 my $numbytes = (-s $self->{tmpfile});
909 open(IN, $self->{tmpfile})
910 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
912 $self->{copies} = 1 unless $self->{media} eq 'printer';
914 chdir("$self->{cwd}");
916 for my $i (1 .. $self->{copies}) {
918 open(OUT, $self->{OUT})
919 or $self->error($self->cleanup . "$self->{OUT} : $!");
923 print qq|Content-Type: application/$self->{format}
924 Content-Disposition: attachment; filename="$self->{tmpfile}"
925 Content-Length: $numbytes
929 open(OUT, ">-") or $self->error($self->cleanup . "$!: STDOUT");
949 chdir("$self->{cwd}");
950 $main::lxdebug->leave_sub();
954 $main::lxdebug->enter_sub();
958 chdir("$self->{tmpdir}");
961 if (-f "$self->{tmpfile}.err") {
962 open(FH, "$self->{tmpfile}.err");
967 if ($self->{tmpfile}) {
970 $self->{tmpfile} =~ s/\.\w+$//g;
971 my $tmpfile = $self->{tmpfile};
972 unlink(<$tmpfile.*>);
975 chdir("$self->{cwd}");
977 $main::lxdebug->leave_sub();
983 $main::lxdebug->enter_sub();
985 my ($self, @fields) = @_;
988 %unique_fields = map({ $_ => 1 } @fields);
989 @fields = keys(%unique_fields);
990 my $format = $self->{format};
991 if ($self->{format} =~ /(postscript|pdf)/) {
998 '<', '>', quotemeta('\n'), '
1002 '&', quotemeta('\n'), '
1004 '"', '\$', '%', '_', '#', quotemeta('^'),
1005 '{', '}', '<', '>', '£', "\r"
1011 quotemeta('\n') => '<br>',
1022 quotemeta('^') => '\^\\',
1027 quotemeta('\n') => '\newline ',
1034 foreach my $key (@{ $replace{order}{$format} }) {
1035 map { $self->{$_} =~ s/$key/$replace{$format}{$key}/g; } @fields;
1038 $main::lxdebug->leave_sub();
1042 $main::lxdebug->enter_sub();
1044 my ($self, $date, $myconfig) = @_;
1046 if ($date && $date =~ /\D/) {
1048 if ($myconfig->{dateformat} =~ /^yy/) {
1049 ($yy, $mm, $dd) = split /\D/, $date;
1051 if ($myconfig->{dateformat} =~ /^mm/) {
1052 ($mm, $dd, $yy) = split /\D/, $date;
1054 if ($myconfig->{dateformat} =~ /^dd/) {
1055 ($dd, $mm, $yy) = split /\D/, $date;
1060 $yy = ($yy < 70) ? $yy + 2000 : $yy;
1061 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
1063 $dd = "0$dd" if ($dd < 10);
1064 $mm = "0$mm" if ($mm < 10);
1066 $date = "$yy$mm$dd";
1069 $main::lxdebug->leave_sub();
1074 # Database routines used throughout
1077 $main::lxdebug->enter_sub();
1079 my ($self, $myconfig) = @_;
1081 # connect to database
1083 DBI->connect($myconfig->{dbconnect},
1084 $myconfig->{dbuser}, $myconfig->{dbpasswd})
1088 if ($myconfig->{dboptions}) {
1089 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1092 $main::lxdebug->leave_sub();
1097 sub dbconnect_noauto {
1098 $main::lxdebug->enter_sub();
1100 my ($self, $myconfig) = @_;
1102 # connect to database
1104 DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser},
1105 $myconfig->{dbpasswd}, { AutoCommit => 0 })
1109 if ($myconfig->{dboptions}) {
1110 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1113 $main::lxdebug->leave_sub();
1118 sub update_balance {
1119 $main::lxdebug->enter_sub();
1121 my ($self, $dbh, $table, $field, $where, $value) = @_;
1123 # if we have a value, go do it
1126 # retrieve balance from table
1127 my $query = "SELECT $field FROM $table WHERE $where FOR UPDATE";
1128 my $sth = $dbh->prepare($query);
1130 $sth->execute || $self->dberror($query);
1131 my ($balance) = $sth->fetchrow_array;
1137 $query = "UPDATE $table SET $field = $balance WHERE $where";
1138 $dbh->do($query) || $self->dberror($query);
1140 $main::lxdebug->leave_sub();
1143 sub update_exchangerate {
1144 $main::lxdebug->enter_sub();
1146 my ($self, $dbh, $curr, $transdate, $buy, $sell) = @_;
1148 # some sanity check for currency
1150 $main::lxdebug->leave_sub();
1154 my $query = qq|SELECT e.curr FROM exchangerate e
1155 WHERE e.curr = '$curr'
1156 AND e.transdate = '$transdate'
1158 my $sth = $dbh->prepare($query);
1159 $sth->execute || $self->dberror($query);
1162 if ($buy != 0 && $sell != 0) {
1163 $set = "buy = $buy, sell = $sell";
1164 } elsif ($buy != 0) {
1165 $set = "buy = $buy";
1166 } elsif ($sell != 0) {
1167 $set = "sell = $sell";
1170 if ($sth->fetchrow_array) {
1171 $query = qq|UPDATE exchangerate
1173 WHERE curr = '$curr'
1174 AND transdate = '$transdate'|;
1176 $query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
1177 VALUES ('$curr', $buy, $sell, '$transdate')|;
1180 $dbh->do($query) || $self->dberror($query);
1182 $main::lxdebug->leave_sub();
1185 sub save_exchangerate {
1186 $main::lxdebug->enter_sub();
1188 my ($self, $myconfig, $currency, $transdate, $rate, $fld) = @_;
1190 my $dbh = $self->dbconnect($myconfig);
1192 my ($buy, $sell) = (0, 0);
1193 $buy = $rate if $fld eq 'buy';
1194 $sell = $rate if $fld eq 'sell';
1196 $self->update_exchangerate($dbh, $currency, $transdate, $buy, $sell);
1200 $main::lxdebug->leave_sub();
1203 sub get_exchangerate {
1204 $main::lxdebug->enter_sub();
1206 my ($self, $dbh, $curr, $transdate, $fld) = @_;
1208 my $query = qq|SELECT e.$fld FROM exchangerate e
1209 WHERE e.curr = '$curr'
1210 AND e.transdate = '$transdate'|;
1211 my $sth = $dbh->prepare($query);
1212 $sth->execute || $self->dberror($query);
1214 my ($exchangerate) = $sth->fetchrow_array;
1217 $main::lxdebug->leave_sub();
1219 return $exchangerate;
1222 sub check_exchangerate {
1223 $main::lxdebug->enter_sub();
1225 my ($self, $myconfig, $currency, $transdate, $fld) = @_;
1227 unless ($transdate) {
1228 $main::lxdebug->leave_sub();
1232 my $dbh = $self->dbconnect($myconfig);
1234 my $query = qq|SELECT e.$fld FROM exchangerate e
1235 WHERE e.curr = '$currency'
1236 AND e.transdate = '$transdate'|;
1237 my $sth = $dbh->prepare($query);
1238 $sth->execute || $self->dberror($query);
1240 my ($exchangerate) = $sth->fetchrow_array;
1244 $main::lxdebug->leave_sub();
1246 return $exchangerate;
1250 $main::lxdebug->enter_sub();
1252 my ($self, $dbh, $id) = @_;
1256 my $item (qw(name department_1 department_2 street zipcode city country contact phone fax email)) {
1257 if ($self->{"shipto$item"}) {
1258 $shipto = 1 if ($self->{$item} ne $self->{"shipto$item"});
1260 $self->{"shipto$item"} =~ s/\'/\'\'/g;
1264 my $query = qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2, shiptostreet,
1265 shiptozipcode, shiptocity, shiptocountry, shiptocontact,
1266 shiptophone, shiptofax, shiptoemail) VALUES ($id,
1267 '$self->{shiptoname}', '$self->{shiptodepartment_1}', '$self->{shiptodepartment_2}', '$self->{shiptostreet}',
1268 '$self->{shiptozipcode}', '$self->{shiptocity}',
1269 '$self->{shiptocountry}', '$self->{shiptocontact}',
1270 '$self->{shiptophone}', '$self->{shiptofax}',
1271 '$self->{shiptoemail}')|;
1272 $dbh->do($query) || $self->dberror($query);
1275 $main::lxdebug->leave_sub();
1279 $main::lxdebug->enter_sub();
1281 my ($self, $dbh) = @_;
1283 my $query = qq|SELECT e.id, e.name FROM employee e
1284 WHERE e.login = '$self->{login}'|;
1285 my $sth = $dbh->prepare($query);
1286 $sth->execute || $self->dberror($query);
1288 ($self->{employee_id}, $self->{employee}) = $sth->fetchrow_array;
1289 $self->{employee_id} *= 1;
1293 $main::lxdebug->leave_sub();
1296 # get other contact for transaction and form - html/tex
1298 $main::lxdebug->enter_sub();
1300 my ($self, $dbh, $id) = @_;
1302 my $query = qq|SELECT c.*
1305 $sth = $dbh->prepare($query);
1306 $sth->execute || $self->dberror($query);
1308 $ref = $sth->fetchrow_hashref(NAME_lc);
1310 push @{ $self->{$_} }, $ref;
1313 $main::lxdebug->leave_sub();
1316 # get contacts for id, if no contact return {"","","","",""}
1318 $main::lxdebug->enter_sub();
1320 my ($self, $dbh, $id) = @_;
1322 my $query = qq|SELECT c.cp_id, c.cp_cv_id, c.cp_name, c.cp_givenname
1324 WHERE cp_cv_id=$id|;
1325 my $sth = $dbh->prepare($query);
1326 $sth->execute || $self->dberror($query);
1329 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1330 push @{ $self->{all_contacts} }, $ref;
1335 push @{ $self->{all_contacts} }, { { "", "", "", "", "" } };
1338 $main::lxdebug->leave_sub();
1341 # this sub gets the id and name from $table
1343 $main::lxdebug->enter_sub();
1345 my ($self, $myconfig, $table) = @_;
1347 # connect to database
1348 my $dbh = $self->dbconnect($myconfig);
1350 my $name = $self->like(lc $self->{$table});
1351 my $customernumber = $self->like(lc $self->{customernumber});
1353 if ($self->{customernumber} ne "") {
1354 $query = qq~SELECT c.id, c.name,
1355 c.street || ' ' || c.zipcode || ' ' || c.city || ' ' || c.country AS address
1357 WHERE (lower(c.customernumber) LIKE '$customernumber') AND (not c.obsolete)
1360 $query = qq~SELECT c.id, c.name,
1361 c.street || ' ' || c.zipcode || ' ' || c.city || ' ' || c.country AS address
1363 WHERE (lower(c.name) LIKE '$name') AND (not c.obsolete)
1367 if ($self->{openinvoices}) {
1368 $query = qq~SELECT DISTINCT c.id, c.name,
1369 c.street || ' ' || c.zipcode || ' ' || c.city || ' ' || c.country AS address
1370 FROM $self->{arap} a
1371 JOIN $table c ON (a.${table}_id = c.id)
1372 WHERE NOT a.amount = a.paid
1373 AND lower(c.name) LIKE '$name'
1376 my $sth = $dbh->prepare($query);
1378 $sth->execute || $self->dberror($query);
1381 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1382 push(@{ $self->{name_list} }, $ref);
1388 $main::lxdebug->leave_sub();
1393 # the selection sub is used in the AR, AP, IS, IR and OE module
1396 $main::lxdebug->enter_sub();
1398 my ($self, $myconfig, $table, $module) = @_;
1401 my $dbh = $self->dbconnect($myconfig);
1403 my $query = qq|SELECT count(*) FROM $table|;
1404 my $sth = $dbh->prepare($query);
1405 $sth->execute || $self->dberror($query);
1406 my ($count) = $sth->fetchrow_array;
1409 # build selection list
1410 if ($count < $myconfig->{vclimit}) {
1411 $query = qq|SELECT id, name
1412 FROM $table WHERE not obsolete
1414 $sth = $dbh->prepare($query);
1415 $sth->execute || $self->dberror($query);
1417 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1418 push @{ $self->{"all_$table"} }, $ref;
1426 $self->get_employee($dbh);
1428 # setup sales contacts
1429 $query = qq|SELECT e.id, e.name
1432 AND NOT e.id = $self->{employee_id}|;
1433 $sth = $dbh->prepare($query);
1434 $sth->execute || $self->dberror($query);
1436 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1437 push @{ $self->{all_employees} }, $ref;
1442 push @{ $self->{all_employees} },
1443 { id => $self->{employee_id},
1444 name => $self->{employee} };
1446 # sort the whole thing
1447 @{ $self->{all_employees} } =
1448 sort { $a->{name} cmp $b->{name} } @{ $self->{all_employees} };
1450 if ($module eq 'AR') {
1452 # prepare query for departments
1453 $query = qq|SELECT d.id, d.description
1459 $query = qq|SELECT d.id, d.description
1464 $sth = $dbh->prepare($query);
1465 $sth->execute || $self->dberror($query);
1467 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1468 push @{ $self->{all_departments} }, $ref;
1473 $main::lxdebug->leave_sub();
1476 # this is only used for reports
1477 sub all_departments {
1478 $main::lxdebug->enter_sub();
1480 my ($self, $myconfig, $table) = @_;
1482 my $dbh = $self->dbconnect($myconfig);
1483 my $where = "1 = 1";
1485 if (defined $table) {
1486 if ($table eq 'customer') {
1487 $where = " d.role = 'P'";
1491 my $query = qq|SELECT d.id, d.description
1495 my $sth = $dbh->prepare($query);
1496 $sth->execute || $self->dberror($query);
1498 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1499 push @{ $self->{all_departments} }, $ref;
1505 $main::lxdebug->leave_sub();
1509 $main::lxdebug->enter_sub();
1511 my ($self, $module, $myconfig, $table) = @_;
1513 $self->all_vc($myconfig, $table, $module);
1515 # get last customers or vendors
1518 my $dbh = $self->dbconnect($myconfig);
1522 # now get the account numbers
1524 qq|SELECT c.accno, SUBSTRING(c.description,1,50) as description, c.link, c.taxkey_id
1526 WHERE c.link LIKE '%$module%'
1529 $sth = $dbh->prepare($query);
1530 $sth->execute || $self->dberror($query);
1532 $self->{accounts} = "";
1533 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1535 foreach my $key (split /:/, $ref->{link}) {
1536 if ($key =~ /$module/) {
1538 # cross reference for keys
1539 $xkeyref{ $ref->{accno} } = $key;
1541 push @{ $self->{"${module}_links"}{$key} },
1542 { accno => $ref->{accno},
1543 description => $ref->{description},
1544 taxkey => $ref->{taxkey_id} };
1546 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
1552 if (($module eq "AP") || ($module eq "AR")) {
1554 # get tax rates and description
1555 $query = qq| SELECT * FROM tax t|;
1556 $sth = $dbh->prepare($query);
1557 $sth->execute || $self->dberror($query);
1559 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1560 push @{ $self->{TAX} }, $ref;
1566 my $arap = ($table eq 'customer') ? 'ar' : 'ap';
1568 $query = qq|SELECT a.cp_id, a.invnumber, a.transdate,
1569 a.${table}_id, a.datepaid, a.duedate, a.ordnumber,
1570 a.taxincluded, a.curr AS currency, a.notes, a.intnotes,
1571 c.name AS $table, a.department_id, d.description AS department,
1572 a.amount AS oldinvtotal, a.paid AS oldtotalpaid,
1573 a.employee_id, e.name AS employee, a.gldate
1575 JOIN $table c ON (a.${table}_id = c.id)
1576 LEFT JOIN employee e ON (e.id = a.employee_id)
1577 LEFT JOIN department d ON (d.id = a.department_id)
1578 WHERE a.id = $self->{id}|;
1579 $sth = $dbh->prepare($query);
1580 $sth->execute || $self->dberror($query);
1582 $ref = $sth->fetchrow_hashref(NAME_lc);
1583 foreach $key (keys %$ref) {
1584 $self->{$key} = $ref->{$key};
1588 # get amounts from individual entries
1589 $query = qq|SELECT c.accno, c.description, a.source, a.amount, a.memo,
1590 a.transdate, a.cleared, a.project_id, p.projectnumber, a.taxkey, t.rate
1592 JOIN chart c ON (c.id = a.chart_id)
1593 LEFT JOIN project p ON (p.id = a.project_id)
1594 LEFT Join tax t ON (a.taxkey = t.taxkey)
1595 WHERE a.trans_id = $self->{id}
1596 AND a.fx_transaction = '0'
1597 ORDER BY a.transdate|;
1598 $sth = $dbh->prepare($query);
1599 $sth->execute || $self->dberror($query);
1601 my $fld = ($table eq 'customer') ? 'buy' : 'sell';
1603 # get exchangerate for currency
1604 $self->{exchangerate} =
1605 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate},
1608 # store amounts in {acc_trans}{$key} for multiple accounts
1609 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1610 $ref->{exchangerate} =
1611 $self->get_exchangerate($dbh, $self->{currency}, $ref->{transdate},
1614 push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref;
1618 $query = qq|SELECT d.curr AS currencies, d.closedto, d.revtrans,
1619 (SELECT c.accno FROM chart c
1620 WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
1621 (SELECT c.accno FROM chart c
1622 WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
1624 $sth = $dbh->prepare($query);
1625 $sth->execute || $self->dberror($query);
1627 $ref = $sth->fetchrow_hashref(NAME_lc);
1628 map { $self->{$_} = $ref->{$_} } keys %$ref;
1634 $query = qq|SELECT current_date AS transdate,
1635 d.curr AS currencies, d.closedto, d.revtrans,
1636 (SELECT c.accno FROM chart c
1637 WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
1638 (SELECT c.accno FROM chart c
1639 WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
1641 $sth = $dbh->prepare($query);
1642 $sth->execute || $self->dberror($query);
1644 $ref = $sth->fetchrow_hashref(NAME_lc);
1645 map { $self->{$_} = $ref->{$_} } keys %$ref;
1648 if ($self->{"$self->{vc}_id"}) {
1650 # only setup currency
1651 ($self->{currency}) = split /:/, $self->{currencies};
1655 $self->lastname_used($dbh, $myconfig, $table, $module);
1657 my $fld = ($table eq 'customer') ? 'buy' : 'sell';
1659 # get exchangerate for currency
1660 $self->{exchangerate} =
1661 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate},
1670 $main::lxdebug->leave_sub();
1674 $main::lxdebug->enter_sub();
1676 my ($self, $dbh, $myconfig, $table, $module) = @_;
1678 my $arap = ($table eq 'customer') ? "ar" : "ap";
1679 my $where = "1 = 1";
1681 if ($self->{type} =~ /_order/) {
1683 $where = "quotation = '0'";
1685 if ($self->{type} =~ /_quotation/) {
1687 $where = "quotation = '1'";
1690 my $query = qq|SELECT id FROM $arap
1691 WHERE id IN (SELECT MAX(id) FROM $arap
1693 AND ${table}_id > 0)|;
1694 my $sth = $dbh->prepare($query);
1695 $sth->execute || $self->dberror($query);
1697 my ($trans_id) = $sth->fetchrow_array;
1701 $query = qq|SELECT ct.name, a.curr, a.${table}_id,
1702 current_date + ct.terms AS duedate, a.department_id,
1703 d.description AS department
1705 JOIN $table ct ON (a.${table}_id = ct.id)
1706 LEFT JOIN department d ON (a.department_id = d.id)
1707 WHERE a.id = $trans_id|;
1708 $sth = $dbh->prepare($query);
1709 $sth->execute || $self->dberror($query);
1711 ($self->{$table}, $self->{currency}, $self->{"${table}_id"},
1712 $self->{duedate}, $self->{department_id}, $self->{department})
1713 = $sth->fetchrow_array;
1716 $main::lxdebug->leave_sub();
1720 $main::lxdebug->enter_sub();
1722 my ($self, $myconfig, $thisdate, $days) = @_;
1724 my $dbh = $self->dbconnect($myconfig);
1729 my $dateformat = $myconfig->{dateformat};
1730 $dateformat .= "yy" if $myconfig->{dateformat} !~ /^y/;
1732 $query = qq|SELECT to_date('$thisdate', '$dateformat') + $days AS thisdate
1734 $sth = $dbh->prepare($query);
1735 $sth->execute || $self->dberror($query);
1737 $query = qq|SELECT current_date AS thisdate
1739 $sth = $dbh->prepare($query);
1740 $sth->execute || $self->dberror($query);
1743 ($thisdate) = $sth->fetchrow_array;
1748 $main::lxdebug->leave_sub();
1754 $main::lxdebug->enter_sub();
1756 my ($self, $string) = @_;
1758 if ($string !~ /%/) {
1759 $string = "%$string%";
1762 $string =~ s/\'/\'\'/g;
1764 $main::lxdebug->leave_sub();
1770 $main::lxdebug->enter_sub();
1772 my ($self, $flds, $new, $count, $numrows) = @_;
1776 map { push @ndx, { num => $new->[$_ - 1]->{runningnumber}, ndx => $_ } }
1782 foreach my $item (sort { $a->{num} <=> $b->{num} } @ndx) {
1784 $j = $item->{ndx} - 1;
1785 map { $self->{"${_}_$i"} = $new->[$j]->{$_} } @{$flds};
1789 for $i ($count + 1 .. $numrows) {
1790 map { delete $self->{"${_}_$i"} } @{$flds};
1793 $main::lxdebug->leave_sub();
1797 $main::lxdebug->enter_sub();
1799 my ($self, $myconfig) = @_;
1803 my $dbh = $self->dbconnect_noauto($myconfig);
1805 my $query = qq|DELETE FROM status
1806 WHERE formname = '$self->{formname}'
1808 my $sth = $dbh->prepare($query) || $self->dberror($query);
1810 if ($self->{formname} =~ /(check|receipt)/) {
1811 for $i (1 .. $self->{rowcount}) {
1812 $sth->execute($self->{"id_$i"} * 1) || $self->dberror($query);
1816 $sth->execute($self->{id}) || $self->dberror($query);
1820 my $printed = ($self->{printed} =~ /$self->{formname}/) ? "1" : "0";
1821 my $emailed = ($self->{emailed} =~ /$self->{formname}/) ? "1" : "0";
1823 my %queued = split / /, $self->{queued};
1825 if ($self->{formname} =~ /(check|receipt)/) {
1827 # this is a check or receipt, add one entry for each lineitem
1828 my ($accno) = split /--/, $self->{account};
1829 $query = qq|INSERT INTO status (trans_id, printed, spoolfile, formname,
1830 chart_id) VALUES (?, '$printed',
1831 '$queued{$self->{formname}}', '$self->{prinform}',
1832 (SELECT c.id FROM chart c WHERE c.accno = '$accno'))|;
1833 $sth = $dbh->prepare($query) || $self->dberror($query);
1835 for $i (1 .. $self->{rowcount}) {
1836 if ($self->{"checked_$i"}) {
1837 $sth->execute($self->{"id_$i"}) || $self->dberror($query);
1842 $query = qq|INSERT INTO status (trans_id, printed, emailed,
1843 spoolfile, formname)
1844 VALUES ($self->{id}, '$printed', '$emailed',
1845 '$queued{$self->{formname}}', '$self->{formname}')|;
1846 $dbh->do($query) || $self->dberror($query);
1852 $main::lxdebug->leave_sub();
1856 $main::lxdebug->enter_sub();
1858 my ($self, $dbh) = @_;
1860 my ($query, $printed, $emailed);
1862 my $formnames = $self->{printed};
1863 my $emailforms = $self->{emailed};
1865 my $query = qq|DELETE FROM status
1866 WHERE formname = '$self->{formname}'
1867 AND trans_id = $self->{id}|;
1868 $dbh->do($query) || $self->dberror($query);
1870 # this only applies to the forms
1871 # checks and receipts are posted when printed or queued
1873 if ($self->{queued}) {
1874 my %queued = split / /, $self->{queued};
1876 foreach my $formname (keys %queued) {
1877 $printed = ($self->{printed} =~ /$self->{formname}/) ? "1" : "0";
1878 $emailed = ($self->{emailed} =~ /$self->{formname}/) ? "1" : "0";
1880 $query = qq|INSERT INTO status (trans_id, printed, emailed,
1881 spoolfile, formname)
1882 VALUES ($self->{id}, '$printed', '$emailed',
1883 '$queued{$formname}', '$formname')|;
1884 $dbh->do($query) || $self->dberror($query);
1886 $formnames =~ s/$self->{formname}//;
1887 $emailforms =~ s/$self->{formname}//;
1892 # save printed, emailed info
1893 $formnames =~ s/^ +//g;
1894 $emailforms =~ s/^ +//g;
1897 map { $status{$_}{printed} = 1 } split / +/, $formnames;
1898 map { $status{$_}{emailed} = 1 } split / +/, $emailforms;
1900 foreach my $formname (keys %status) {
1901 $printed = ($formnames =~ /$self->{formname}/) ? "1" : "0";
1902 $emailed = ($emailforms =~ /$self->{formname}/) ? "1" : "0";
1904 $query = qq|INSERT INTO status (trans_id, printed, emailed, formname)
1905 VALUES ($self->{id}, '$printed', '$emailed', '$formname')|;
1906 $dbh->do($query) || $self->dberror($query);
1909 $main::lxdebug->leave_sub();
1912 sub update_defaults {
1913 $main::lxdebug->enter_sub();
1915 my ($self, $myconfig, $fld) = @_;
1917 my $dbh = $self->dbconnect_noauto($myconfig);
1918 my $query = qq|SELECT $fld FROM defaults FOR UPDATE|;
1919 my $sth = $dbh->prepare($query);
1921 $sth->execute || $self->dberror($query);
1922 my ($var) = $sth->fetchrow_array;
1927 $query = qq|UPDATE defaults
1929 $dbh->do($query) || $form->dberror($query);
1934 $main::lxdebug->leave_sub();
1939 sub update_business {
1940 $main::lxdebug->enter_sub();
1942 my ($self, $myconfig, $business_id) = @_;
1944 my $dbh = $self->dbconnect_noauto($myconfig);
1946 qq|SELECT customernumberinit FROM business WHERE id=$business_id FOR UPDATE|;
1947 my $sth = $dbh->prepare($query);
1949 $sth->execute || $self->dberror($query);
1950 my ($var) = $sth->fetchrow_array;
1955 $query = qq|UPDATE business
1956 SET customernumberinit = '$var' WHERE id=$business_id|;
1957 $dbh->do($query) || $form->dberror($query);
1962 $main::lxdebug->leave_sub();
1968 $main::lxdebug->enter_sub();
1970 my ($self, $myconfig, $salesman) = @_;
1972 my $dbh = $self->dbconnect($myconfig);
1974 qq|SELECT id, name FROM customer WHERE (customernumber ilike '%$salesman%' OR name ilike '%$salesman%') AND business_id in (SELECT id from business WHERE salesman)|;
1975 my $sth = $dbh->prepare($query);
1976 $sth->execute || $self->dberror($query);
1979 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1980 push(@{ $self->{salesman_list} }, $ref);
1984 $main::lxdebug->leave_sub();
1989 sub get_partsgroup {
1990 $main::lxdebug->enter_sub();
1992 my ($self, $myconfig, $p) = @_;
1994 my $dbh = $self->dbconnect($myconfig);
1996 my $query = qq|SELECT DISTINCT pg.id, pg.partsgroup
1998 JOIN parts p ON (p.partsgroup_id = pg.id)|;
2000 if ($p->{searchitems} eq 'part') {
2002 WHERE p.inventory_accno_id > 0|;
2004 if ($p->{searchitems} eq 'service') {
2006 WHERE p.inventory_accno_id IS NULL|;
2008 if ($p->{searchitems} eq 'assembly') {
2010 WHERE p.assembly = '1'|;
2012 if ($p->{searchitems} eq 'labor') {
2014 WHERE p.inventory_accno_id > 0 AND p.income_accno_id IS NULL|;
2018 ORDER BY partsgroup|;
2021 $query = qq|SELECT id, partsgroup FROM partsgroup
2022 ORDER BY partsgroup|;
2025 if ($p->{language_code}) {
2026 $query = qq|SELECT DISTINCT pg.id, pg.partsgroup,
2027 t.description AS translation
2029 JOIN parts p ON (p.partsgroup_id = pg.id)
2030 LEFT JOIN translation t ON (t.trans_id = pg.id AND t.language_code = '$p->{language_code}')
2031 ORDER BY translation|;
2034 my $sth = $dbh->prepare($query);
2035 $sth->execute || $self->dberror($query);
2037 $self->{all_partsgroup} = ();
2038 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
2039 push @{ $self->{all_partsgroup} }, $ref;
2043 $main::lxdebug->leave_sub();
2049 $main::lxdebug->enter_sub();
2051 my ($type, $country, $NLS_file) = @_;
2055 if ($country && -d "locale/$country") {
2056 $self->{countrycode} = $country;
2057 eval { require "locale/$country/$NLS_file"; };
2060 $self->{NLS_file} = $NLS_file;
2062 push @{ $self->{LONG_MONTH} },
2063 ("January", "February", "March", "April",
2064 "May ", "June", "July", "August",
2065 "September", "October", "November", "December");
2066 push @{ $self->{SHORT_MONTH} },
2067 (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
2069 $main::lxdebug->leave_sub();
2075 my ($self, $text) = @_;
2077 return (exists $self{texts}{$text}) ? $self{texts}{$text} : $text;
2081 $main::lxdebug->enter_sub();
2083 my ($self, $text) = @_;
2085 if (exists $self{subs}{$text}) {
2086 $text = $self{subs}{$text};
2088 if ($self->{countrycode} && $self->{NLS_file}) {
2090 "$text not defined in locale/$self->{countrycode}/$self->{NLS_file}");
2094 $main::lxdebug->leave_sub();
2100 $main::lxdebug->enter_sub();
2102 my ($self, $myconfig, $date, $longformat) = @_;
2105 my $longmonth = ($longformat) ? 'LONG_MONTH' : 'SHORT_MONTH';
2110 $spc = $myconfig->{dateformat};
2112 $spc = substr($spc, 1, 1);
2114 if ($date =~ /\D/) {
2115 if ($myconfig->{dateformat} =~ /^yy/) {
2116 ($yy, $mm, $dd) = split /\D/, $date;
2118 if ($myconfig->{dateformat} =~ /^mm/) {
2119 ($mm, $dd, $yy) = split /\D/, $date;
2121 if ($myconfig->{dateformat} =~ /^dd/) {
2122 ($dd, $mm, $yy) = split /\D/, $date;
2125 $date = substr($date, 2);
2126 ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
2131 $yy = ($yy < 70) ? $yy + 2000 : $yy;
2132 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
2134 if ($myconfig->{dateformat} =~ /^dd/) {
2135 if (defined $longformat && $longformat == 0) {
2137 $dd = "0$dd" if ($dd < 10);
2138 $mm = "0$mm" if ($mm < 10);
2139 $longdate = "$dd$spc$mm$spc$yy";
2142 $longdate .= ($spc eq '.') ? ". " : " ";
2143 $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
2145 } elsif ($myconfig->{dateformat} eq "yyyy-mm-dd") {
2147 # Use German syntax with the ISO date style "yyyy-mm-dd" because
2148 # Lx-Office is mainly used in Germany or German speaking countries.
2149 if (defined $longformat && $longformat == 0) {
2151 $dd = "0$dd" if ($dd < 10);
2152 $mm = "0$mm" if ($mm < 10);
2153 $longdate = "$yy-$mm-$dd";
2155 $longdate = "$dd. ";
2156 $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
2159 if (defined $longformat && $longformat == 0) {
2161 $dd = "0$dd" if ($dd < 10);
2162 $mm = "0$mm" if ($mm < 10);
2163 $longdate = "$mm$spc$dd$spc$yy";
2165 $longdate = &text($self, $self->{$longmonth}[$mm]) . " $dd, $yy";
2171 $main::lxdebug->leave_sub();
2177 $main::lxdebug->enter_sub();
2179 my ($self, $myconfig, $date, $longformat) = @_;
2182 $main::lxdebug->leave_sub();
2187 $spc = $myconfig->{dateformat};
2189 $spc = substr($spc, 1, 1);
2191 if ($date =~ /\D/) {
2192 if ($myconfig->{dateformat} =~ /^yy/) {
2193 ($yy, $mm, $dd) = split /\D/, $date;
2194 } elsif ($myconfig->{dateformat} =~ /^mm/) {
2195 ($mm, $dd, $yy) = split /\D/, $date;
2196 } elsif ($myconfig->{dateformat} =~ /^dd/) {
2197 ($dd, $mm, $yy) = split /\D/, $date;
2200 $date = substr($date, 2);
2201 ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
2206 $yy = ($yy < 70) ? $yy + 2000 : $yy;
2207 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
2209 $main::lxdebug->leave_sub();
2210 return ($yy, $mm, $dd);