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 # Rounding like "Kaufmannsrunden"
571 # Descr. http://de.wikipedia.org/wiki/Rundung
573 # http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q4.13.html
576 $amount = $amount * (10 ** ($places));
577 $round_amount = int($amount + .5 * ($amount <=> 0))/(10**($places));
579 $main::lxdebug->leave_sub();
581 return $round_amount;
585 $main::lxdebug->enter_sub();
587 my ($self, $myconfig, $userspath) = @_;
590 # Some variables used for page breaks
591 my ($chars_per_line, $lines_on_first_page, $lines_on_second_page) =
593 my ($current_page, $current_line) = (1, 1);
599 # Make sure that all *notes* (intnotes, partnotes_*, notes etc) are converted to markup correctly.
600 $self->format_string(grep(/notes/, keys(%{$self})));
602 # Copy the notes from the invoice/sales order etc. back to the variable "notes" because that is where most templates expect it to be.
603 $self->{"notes"} = $self->{ $self->{"formname"} . "notes" };
605 map({ $self->{"employee_${_}"} = $myconfig->{$_}; }
606 qw(email tel fax name signature));
608 open(IN, "$self->{templates}/$self->{IN}")
609 or $self->error("$self->{IN} : $!");
614 $self->{copies} = 1 if (($self->{copies} *= 1) <= 0);
616 # OUT is used for the media, screen, printer, email
617 # for postscript we store a copy in a temporary file
619 $self->{tmpfile} = "$userspath/${fileid}.$self->{IN}";
620 if ($self->{format} =~ /(postscript|pdf)/ || $self->{media} eq 'email') {
622 $self->{OUT} = ">$self->{tmpfile}";
626 open(OUT, "$self->{OUT}") or $self->error("$self->{OUT} : $!");
628 open(OUT, ">-") or $self->error("STDOUT : $!");
632 # Do we have to run LaTeX two times? This is needed if
633 # the template contains page references.
636 # first we generate a tmpfile
637 # read file and replace <%variable%>
643 $two_passes = 1 if (/\\pageref/);
646 # detect pagebreak block and its parameters
647 if (/\s*<%pagebreak ([0-9]+) ([0-9]+) ([0-9]+)%>/) {
648 $chars_per_line = $1;
649 $lines_on_first_page = $2;
650 $lines_on_second_page = $3;
653 last if (/\s*<%end pagebreak%>/);
660 if (/\s*<%foreach /) {
662 # this one we need for the count
664 $var =~ s/\s*<%foreach (.+?)%>/$1/;
666 last if (/\s*<%end /);
672 # display contents of $self->{number}[] array
673 for $i (0 .. $#{ $self->{$var} }) {
676 # Try to detect whether a manual page break is necessary
677 # but only if there was a <%pagebreak ...%> block before
679 if ($chars_per_line) {
681 int(length($self->{"description"}[$i]) / $chars_per_line + 0.95);
684 my $_description = $self->{"description"}[$i];
685 while ($_description =~ /\\newline/) {
687 $_description =~ s/\\newline//;
689 $self->{"description"}[$i] =~ s/(\\newline\s?)*$//;
691 if ($current_page == 1) {
692 $lpp = $lines_on_first_page;
694 $lpp = $lines_on_second_page;
697 # Yes we need a manual page break
698 if (($current_line + $lines) > $lpp) {
701 # replace the special variables <%sumcarriedforward%>
704 my $psum = $self->format_amount($myconfig, $sum, 2);
705 $pb =~ s/<%sumcarriedforward%>/$psum/g;
706 $pb =~ s/<%lastpage%>/$current_page/g;
708 # only "normal" variables are supported here
709 # (no <%if, no <%foreach, no <%include)
711 $pb =~ s/<%(.+?)%>/$self->{$1}/g;
713 # page break block is ready to rock
718 $current_line += $lines;
720 $sum += $self->parse_amount($myconfig, $self->{"linetotal"}[$i]);
724 # don't parse par, we need it for each line
726 s/<%(.+?)%>/$self->{$1}[$i]/mg;
732 # if not comes before if!
733 if (/\s*<%if not /) {
735 # check if it is not set and display
737 s/\s*<%if not (.+?)%>/$1/;
739 unless ($self->{$_}) {
741 last if (/\s*<%end /);
751 last if (/\s*<%end /);
759 # check if it is set and display
761 s/\s*<%if (.+?)%>/$1/;
765 last if (/\s*<%end /);
775 last if (/\s*<%end /);
781 # check for <%include filename%>
782 if (/\s*<%include /) {
786 $var =~ s/\s*<%include (.+?)%>/$1/;
789 $var =~ s/(\/|\.\.)//g;
791 # prevent the infinite loop!
792 next if ($self->{"$var"});
794 open(INC, "$self->{templates}/$var")
795 or $self->error($self->cleanup . "$self->{templates}/$var : $!");
804 s/<%(.+?)%>/$self->{$1}/g;
811 # Convert the tex file to postscript
812 if ($self->{format} =~ /(postscript|pdf)/) {
815 $self->{cwd} = cwd();
816 $self->{tmpdir} = "$self->{cwd}/$userspath";
818 chdir("$userspath") or $self->error($self->cleanup . "chdir : $!");
820 $self->{tmpfile} =~ s/$userspath\///g;
822 if ($self->{format} eq 'postscript') {
824 "latex --interaction=nonstopmode $self->{tmpfile} > $self->{tmpfile}.err"
826 $self->error($self->cleanup) if ($?);
829 "latex --interaction=nonstopmode $self->{tmpfile} > $self->{tmpfile}.err"
831 $self->error($self->cleanup) if ($?);
834 $self->{tmpfile} =~ s/tex$/dvi/;
836 system("dvips $self->{tmpfile} -o -q > /dev/null");
837 $self->error($self->cleanup . "dvips : $!") if ($?);
838 $self->{tmpfile} =~ s/dvi$/ps/;
840 if ($self->{format} eq 'pdf') {
842 "pdflatex --interaction=nonstopmode $self->{tmpfile} > $self->{tmpfile}.err"
844 $self->error($self->cleanup) if ($?);
847 "pdflatex --interaction=nonstopmode $self->{tmpfile} > $self->{tmpfile}.err"
849 $self->error($self->cleanup) if ($?);
851 $self->{tmpfile} =~ s/tex$/pdf/;
856 if ($self->{format} =~ /(postscript|pdf)/ || $self->{media} eq 'email') {
858 if ($self->{media} eq 'email') {
862 my $mail = new Mailer;
864 map { $mail->{$_} = $self->{$_} }
865 qw(cc bcc subject message version format charset);
866 $mail->{to} = qq|$self->{email}|;
867 $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|;
868 $mail->{fileid} = "$fileid.";
870 # if we send html or plain text inline
871 if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
872 $mail->{contenttype} = "text/html";
874 $mail->{message} =~ s/\r\n/<br>\n/g;
875 $myconfig->{signature} =~ s/\\n/<br>\n/g;
876 $mail->{message} .= "<br>\n--<br>\n$myconfig->{signature}\n<br>";
878 open(IN, $self->{tmpfile})
879 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
881 $mail->{message} .= $_;
888 @{ $mail->{attachments} } = ($self->{tmpfile});
890 $myconfig->{signature} =~ s/\\n/\r\n/g;
891 $mail->{message} .= "\r\n--\r\n$myconfig->{signature}";
895 my $err = $mail->send($out);
896 $self->error($self->cleanup . "$err") if ($err);
902 my $numbytes = (-s $self->{tmpfile});
903 open(IN, $self->{tmpfile})
904 or $self->error($self->cleanup . "$self->{tmpfile} : $!");
906 $self->{copies} = 1 unless $self->{media} eq 'printer';
908 chdir("$self->{cwd}");
910 for my $i (1 .. $self->{copies}) {
912 open(OUT, $self->{OUT})
913 or $self->error($self->cleanup . "$self->{OUT} : $!");
917 print qq|Content-Type: application/$self->{format}
918 Content-Disposition: attachment; filename="$self->{tmpfile}"
919 Content-Length: $numbytes
923 open(OUT, ">-") or $self->error($self->cleanup . "$!: STDOUT");
943 chdir("$self->{cwd}");
944 $main::lxdebug->leave_sub();
948 $main::lxdebug->enter_sub();
952 chdir("$self->{tmpdir}");
955 if (-f "$self->{tmpfile}.err") {
956 open(FH, "$self->{tmpfile}.err");
961 if ($self->{tmpfile}) {
964 $self->{tmpfile} =~ s/\.\w+$//g;
965 my $tmpfile = $self->{tmpfile};
966 unlink(<$tmpfile.*>);
969 chdir("$self->{cwd}");
971 $main::lxdebug->leave_sub();
977 $main::lxdebug->enter_sub();
979 my ($self, @fields) = @_;
982 %unique_fields = map({ $_ => 1 } @fields);
983 @fields = keys(%unique_fields);
984 my $format = $self->{format};
985 if ($self->{format} =~ /(postscript|pdf)/) {
992 '<', '>', quotemeta('\n'), '
996 '&', quotemeta('\n'), '
998 '"', '\$', '%', '_', '#', quotemeta('^'),
999 '{', '}', '<', '>', '£', "\r"
1005 quotemeta('\n') => '<br>',
1016 quotemeta('^') => '\^\\',
1021 quotemeta('\n') => '\newline ',
1028 foreach my $key (@{ $replace{order}{$format} }) {
1029 map { $self->{$_} =~ s/$key/$replace{$format}{$key}/g; } @fields;
1032 $main::lxdebug->leave_sub();
1036 $main::lxdebug->enter_sub();
1038 my ($self, $date, $myconfig) = @_;
1040 if ($date && $date =~ /\D/) {
1042 if ($myconfig->{dateformat} =~ /^yy/) {
1043 ($yy, $mm, $dd) = split /\D/, $date;
1045 if ($myconfig->{dateformat} =~ /^mm/) {
1046 ($mm, $dd, $yy) = split /\D/, $date;
1048 if ($myconfig->{dateformat} =~ /^dd/) {
1049 ($dd, $mm, $yy) = split /\D/, $date;
1054 $yy = ($yy < 70) ? $yy + 2000 : $yy;
1055 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
1057 $dd = "0$dd" if ($dd < 10);
1058 $mm = "0$mm" if ($mm < 10);
1060 $date = "$yy$mm$dd";
1063 $main::lxdebug->leave_sub();
1068 # Database routines used throughout
1071 $main::lxdebug->enter_sub();
1073 my ($self, $myconfig) = @_;
1075 # connect to database
1077 DBI->connect($myconfig->{dbconnect},
1078 $myconfig->{dbuser}, $myconfig->{dbpasswd})
1082 if ($myconfig->{dboptions}) {
1083 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1086 $main::lxdebug->leave_sub();
1091 sub dbconnect_noauto {
1092 $main::lxdebug->enter_sub();
1094 my ($self, $myconfig) = @_;
1096 # connect to database
1098 DBI->connect($myconfig->{dbconnect}, $myconfig->{dbuser},
1099 $myconfig->{dbpasswd}, { AutoCommit => 0 })
1103 if ($myconfig->{dboptions}) {
1104 $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions});
1107 $main::lxdebug->leave_sub();
1112 sub update_balance {
1113 $main::lxdebug->enter_sub();
1115 my ($self, $dbh, $table, $field, $where, $value) = @_;
1117 # if we have a value, go do it
1120 # retrieve balance from table
1121 my $query = "SELECT $field FROM $table WHERE $where FOR UPDATE";
1122 my $sth = $dbh->prepare($query);
1124 $sth->execute || $self->dberror($query);
1125 my ($balance) = $sth->fetchrow_array;
1131 $query = "UPDATE $table SET $field = $balance WHERE $where";
1132 $dbh->do($query) || $self->dberror($query);
1134 $main::lxdebug->leave_sub();
1137 sub update_exchangerate {
1138 $main::lxdebug->enter_sub();
1140 my ($self, $dbh, $curr, $transdate, $buy, $sell) = @_;
1142 # some sanity check for currency
1144 $main::lxdebug->leave_sub();
1148 my $query = qq|SELECT e.curr FROM exchangerate e
1149 WHERE e.curr = '$curr'
1150 AND e.transdate = '$transdate'
1152 my $sth = $dbh->prepare($query);
1153 $sth->execute || $self->dberror($query);
1156 if ($buy != 0 && $sell != 0) {
1157 $set = "buy = $buy, sell = $sell";
1158 } elsif ($buy != 0) {
1159 $set = "buy = $buy";
1160 } elsif ($sell != 0) {
1161 $set = "sell = $sell";
1164 if ($sth->fetchrow_array) {
1165 $query = qq|UPDATE exchangerate
1167 WHERE curr = '$curr'
1168 AND transdate = '$transdate'|;
1170 $query = qq|INSERT INTO exchangerate (curr, buy, sell, transdate)
1171 VALUES ('$curr', $buy, $sell, '$transdate')|;
1174 $dbh->do($query) || $self->dberror($query);
1176 $main::lxdebug->leave_sub();
1179 sub save_exchangerate {
1180 $main::lxdebug->enter_sub();
1182 my ($self, $myconfig, $currency, $transdate, $rate, $fld) = @_;
1184 my $dbh = $self->dbconnect($myconfig);
1186 my ($buy, $sell) = (0, 0);
1187 $buy = $rate if $fld eq 'buy';
1188 $sell = $rate if $fld eq 'sell';
1190 $self->update_exchangerate($dbh, $currency, $transdate, $buy, $sell);
1194 $main::lxdebug->leave_sub();
1197 sub get_exchangerate {
1198 $main::lxdebug->enter_sub();
1200 my ($self, $dbh, $curr, $transdate, $fld) = @_;
1202 my $query = qq|SELECT e.$fld FROM exchangerate e
1203 WHERE e.curr = '$curr'
1204 AND e.transdate = '$transdate'|;
1205 my $sth = $dbh->prepare($query);
1206 $sth->execute || $self->dberror($query);
1208 my ($exchangerate) = $sth->fetchrow_array;
1211 $main::lxdebug->leave_sub();
1213 return $exchangerate;
1216 sub check_exchangerate {
1217 $main::lxdebug->enter_sub();
1219 my ($self, $myconfig, $currency, $transdate, $fld) = @_;
1221 unless ($transdate) {
1222 $main::lxdebug->leave_sub();
1226 my $dbh = $self->dbconnect($myconfig);
1228 my $query = qq|SELECT e.$fld FROM exchangerate e
1229 WHERE e.curr = '$currency'
1230 AND e.transdate = '$transdate'|;
1231 my $sth = $dbh->prepare($query);
1232 $sth->execute || $self->dberror($query);
1234 my ($exchangerate) = $sth->fetchrow_array;
1238 $main::lxdebug->leave_sub();
1240 return $exchangerate;
1244 $main::lxdebug->enter_sub();
1246 my ($self, $dbh, $id) = @_;
1250 my $item (qw(name department_1 department_2 street zipcode city country contact phone fax email)) {
1251 if ($self->{"shipto$item"}) {
1252 $shipto = 1 if ($self->{$item} ne $self->{"shipto$item"});
1254 $self->{"shipto$item"} =~ s/\'/\'\'/g;
1258 my $query = qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2, shiptostreet,
1259 shiptozipcode, shiptocity, shiptocountry, shiptocontact,
1260 shiptophone, shiptofax, shiptoemail) VALUES ($id,
1261 '$self->{shiptoname}', '$self->{shiptodepartment_1}', '$self->{shiptodepartment_2}', '$self->{shiptostreet}',
1262 '$self->{shiptozipcode}', '$self->{shiptocity}',
1263 '$self->{shiptocountry}', '$self->{shiptocontact}',
1264 '$self->{shiptophone}', '$self->{shiptofax}',
1265 '$self->{shiptoemail}')|;
1266 $dbh->do($query) || $self->dberror($query);
1269 $main::lxdebug->leave_sub();
1273 $main::lxdebug->enter_sub();
1275 my ($self, $dbh) = @_;
1277 my $query = qq|SELECT e.id, e.name FROM employee e
1278 WHERE e.login = '$self->{login}'|;
1279 my $sth = $dbh->prepare($query);
1280 $sth->execute || $self->dberror($query);
1282 ($self->{employee_id}, $self->{employee}) = $sth->fetchrow_array;
1283 $self->{employee_id} *= 1;
1287 $main::lxdebug->leave_sub();
1290 # get other contact for transaction and form - html/tex
1292 $main::lxdebug->enter_sub();
1294 my ($self, $dbh, $id) = @_;
1296 my $query = qq|SELECT c.*
1299 $sth = $dbh->prepare($query);
1300 $sth->execute || $self->dberror($query);
1302 $ref = $sth->fetchrow_hashref(NAME_lc);
1304 push @{ $self->{$_} }, $ref;
1307 $main::lxdebug->leave_sub();
1310 # get contacts for id, if no contact return {"","","","",""}
1312 $main::lxdebug->enter_sub();
1314 my ($self, $dbh, $id) = @_;
1316 my $query = qq|SELECT c.cp_id, c.cp_cv_id, c.cp_name, c.cp_givenname
1318 WHERE cp_cv_id=$id|;
1319 my $sth = $dbh->prepare($query);
1320 $sth->execute || $self->dberror($query);
1323 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1324 push @{ $self->{all_contacts} }, $ref;
1329 push @{ $self->{all_contacts} }, { { "", "", "", "", "" } };
1332 $main::lxdebug->leave_sub();
1335 # this sub gets the id and name from $table
1337 $main::lxdebug->enter_sub();
1339 my ($self, $myconfig, $table) = @_;
1341 # connect to database
1342 my $dbh = $self->dbconnect($myconfig);
1344 my $name = $self->like(lc $self->{$table});
1345 my $customernumber = $self->like(lc $self->{customernumber});
1347 if ($self->{customernumber} ne "") {
1348 $query = qq~SELECT c.id, c.name,
1349 c.street || ' ' || c.zipcode || ' ' || c.city || ' ' || c.country AS address
1351 WHERE (lower(c.customernumber) LIKE '$customernumber') AND (not c.obsolete)
1354 $query = qq~SELECT c.id, c.name,
1355 c.street || ' ' || c.zipcode || ' ' || c.city || ' ' || c.country AS address
1357 WHERE (lower(c.name) LIKE '$name') AND (not c.obsolete)
1361 if ($self->{openinvoices}) {
1362 $query = qq~SELECT DISTINCT c.id, c.name,
1363 c.street || ' ' || c.zipcode || ' ' || c.city || ' ' || c.country AS address
1364 FROM $self->{arap} a
1365 JOIN $table c ON (a.${table}_id = c.id)
1366 WHERE NOT a.amount = a.paid
1367 AND lower(c.name) LIKE '$name'
1370 my $sth = $dbh->prepare($query);
1372 $sth->execute || $self->dberror($query);
1375 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1376 push(@{ $self->{name_list} }, $ref);
1382 $main::lxdebug->leave_sub();
1387 # the selection sub is used in the AR, AP, IS, IR and OE module
1390 $main::lxdebug->enter_sub();
1392 my ($self, $myconfig, $table, $module) = @_;
1395 my $dbh = $self->dbconnect($myconfig);
1397 my $query = qq|SELECT count(*) FROM $table|;
1398 my $sth = $dbh->prepare($query);
1399 $sth->execute || $self->dberror($query);
1400 my ($count) = $sth->fetchrow_array;
1403 # build selection list
1404 if ($count < $myconfig->{vclimit}) {
1405 $query = qq|SELECT id, name
1406 FROM $table WHERE not obsolete
1408 $sth = $dbh->prepare($query);
1409 $sth->execute || $self->dberror($query);
1411 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1412 push @{ $self->{"all_$table"} }, $ref;
1420 $self->get_employee($dbh);
1422 # setup sales contacts
1423 $query = qq|SELECT e.id, e.name
1426 AND NOT e.id = $self->{employee_id}|;
1427 $sth = $dbh->prepare($query);
1428 $sth->execute || $self->dberror($query);
1430 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1431 push @{ $self->{all_employees} }, $ref;
1436 push @{ $self->{all_employees} },
1437 { id => $self->{employee_id},
1438 name => $self->{employee} };
1440 # sort the whole thing
1441 @{ $self->{all_employees} } =
1442 sort { $a->{name} cmp $b->{name} } @{ $self->{all_employees} };
1444 if ($module eq 'AR') {
1446 # prepare query for departments
1447 $query = qq|SELECT d.id, d.description
1453 $query = qq|SELECT d.id, d.description
1458 $sth = $dbh->prepare($query);
1459 $sth->execute || $self->dberror($query);
1461 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1462 push @{ $self->{all_departments} }, $ref;
1467 $main::lxdebug->leave_sub();
1470 # this is only used for reports
1471 sub all_departments {
1472 $main::lxdebug->enter_sub();
1474 my ($self, $myconfig, $table) = @_;
1476 my $dbh = $self->dbconnect($myconfig);
1477 my $where = "1 = 1";
1479 if (defined $table) {
1480 if ($table eq 'customer') {
1481 $where = " d.role = 'P'";
1485 my $query = qq|SELECT d.id, d.description
1489 my $sth = $dbh->prepare($query);
1490 $sth->execute || $self->dberror($query);
1492 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1493 push @{ $self->{all_departments} }, $ref;
1499 $main::lxdebug->leave_sub();
1503 $main::lxdebug->enter_sub();
1505 my ($self, $module, $myconfig, $table) = @_;
1507 $self->all_vc($myconfig, $table, $module);
1509 # get last customers or vendors
1512 my $dbh = $self->dbconnect($myconfig);
1516 # now get the account numbers
1518 qq|SELECT c.accno, SUBSTRING(c.description,1,50) as description, c.link, c.taxkey_id
1520 WHERE c.link LIKE '%$module%'
1523 $sth = $dbh->prepare($query);
1524 $sth->execute || $self->dberror($query);
1526 $self->{accounts} = "";
1527 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1529 foreach my $key (split /:/, $ref->{link}) {
1530 if ($key =~ /$module/) {
1532 # cross reference for keys
1533 $xkeyref{ $ref->{accno} } = $key;
1535 push @{ $self->{"${module}_links"}{$key} },
1536 { accno => $ref->{accno},
1537 description => $ref->{description},
1538 taxkey => $ref->{taxkey_id} };
1540 $self->{accounts} .= "$ref->{accno} " unless $key =~ /tax/;
1546 if (($module eq "AP") || ($module eq "AR")) {
1548 # get tax rates and description
1549 $query = qq| SELECT * FROM tax t|;
1550 $sth = $dbh->prepare($query);
1551 $sth->execute || $self->dberror($query);
1553 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1554 push @{ $self->{TAX} }, $ref;
1560 my $arap = ($table eq 'customer') ? 'ar' : 'ap';
1562 $query = qq|SELECT a.cp_id, a.invnumber, a.transdate,
1563 a.${table}_id, a.datepaid, a.duedate, a.ordnumber,
1564 a.taxincluded, a.curr AS currency, a.notes, a.intnotes,
1565 c.name AS $table, a.department_id, d.description AS department,
1566 a.amount AS oldinvtotal, a.paid AS oldtotalpaid,
1567 a.employee_id, e.name AS employee, a.gldate
1569 JOIN $table c ON (a.${table}_id = c.id)
1570 LEFT JOIN employee e ON (e.id = a.employee_id)
1571 LEFT JOIN department d ON (d.id = a.department_id)
1572 WHERE a.id = $self->{id}|;
1573 $sth = $dbh->prepare($query);
1574 $sth->execute || $self->dberror($query);
1576 $ref = $sth->fetchrow_hashref(NAME_lc);
1577 foreach $key (keys %$ref) {
1578 $self->{$key} = $ref->{$key};
1582 # get amounts from individual entries
1583 $query = qq|SELECT c.accno, c.description, a.source, a.amount, a.memo,
1584 a.transdate, a.cleared, a.project_id, p.projectnumber, a.taxkey, t.rate
1586 JOIN chart c ON (c.id = a.chart_id)
1587 LEFT JOIN project p ON (p.id = a.project_id)
1588 LEFT Join tax t ON (a.taxkey = t.taxkey)
1589 WHERE a.trans_id = $self->{id}
1590 AND a.fx_transaction = '0'
1591 ORDER BY a.transdate|;
1592 $sth = $dbh->prepare($query);
1593 $sth->execute || $self->dberror($query);
1595 my $fld = ($table eq 'customer') ? 'buy' : 'sell';
1597 # get exchangerate for currency
1598 $self->{exchangerate} =
1599 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate},
1602 # store amounts in {acc_trans}{$key} for multiple accounts
1603 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1604 $ref->{exchangerate} =
1605 $self->get_exchangerate($dbh, $self->{currency}, $ref->{transdate},
1608 push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref;
1612 $query = qq|SELECT d.curr AS currencies, d.closedto, d.revtrans,
1613 (SELECT c.accno FROM chart c
1614 WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
1615 (SELECT c.accno FROM chart c
1616 WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
1618 $sth = $dbh->prepare($query);
1619 $sth->execute || $self->dberror($query);
1621 $ref = $sth->fetchrow_hashref(NAME_lc);
1622 map { $self->{$_} = $ref->{$_} } keys %$ref;
1628 $query = qq|SELECT current_date AS transdate,
1629 d.curr AS currencies, d.closedto, d.revtrans,
1630 (SELECT c.accno FROM chart c
1631 WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
1632 (SELECT c.accno FROM chart c
1633 WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
1635 $sth = $dbh->prepare($query);
1636 $sth->execute || $self->dberror($query);
1638 $ref = $sth->fetchrow_hashref(NAME_lc);
1639 map { $self->{$_} = $ref->{$_} } keys %$ref;
1642 if ($self->{"$self->{vc}_id"}) {
1644 # only setup currency
1645 ($self->{currency}) = split /:/, $self->{currencies};
1649 $self->lastname_used($dbh, $myconfig, $table, $module);
1651 my $fld = ($table eq 'customer') ? 'buy' : 'sell';
1653 # get exchangerate for currency
1654 $self->{exchangerate} =
1655 $self->get_exchangerate($dbh, $self->{currency}, $self->{transdate},
1664 $main::lxdebug->leave_sub();
1668 $main::lxdebug->enter_sub();
1670 my ($self, $dbh, $myconfig, $table, $module) = @_;
1672 my $arap = ($table eq 'customer') ? "ar" : "ap";
1673 my $where = "1 = 1";
1675 if ($self->{type} =~ /_order/) {
1677 $where = "quotation = '0'";
1679 if ($self->{type} =~ /_quotation/) {
1681 $where = "quotation = '1'";
1684 my $query = qq|SELECT id FROM $arap
1685 WHERE id IN (SELECT MAX(id) FROM $arap
1687 AND ${table}_id > 0)|;
1688 my $sth = $dbh->prepare($query);
1689 $sth->execute || $self->dberror($query);
1691 my ($trans_id) = $sth->fetchrow_array;
1695 $query = qq|SELECT ct.name, a.curr, a.${table}_id,
1696 current_date + ct.terms AS duedate, a.department_id,
1697 d.description AS department
1699 JOIN $table ct ON (a.${table}_id = ct.id)
1700 LEFT JOIN department d ON (a.department_id = d.id)
1701 WHERE a.id = $trans_id|;
1702 $sth = $dbh->prepare($query);
1703 $sth->execute || $self->dberror($query);
1705 ($self->{$table}, $self->{currency}, $self->{"${table}_id"},
1706 $self->{duedate}, $self->{department_id}, $self->{department})
1707 = $sth->fetchrow_array;
1710 $main::lxdebug->leave_sub();
1714 $main::lxdebug->enter_sub();
1716 my ($self, $myconfig, $thisdate, $days) = @_;
1718 my $dbh = $self->dbconnect($myconfig);
1723 my $dateformat = $myconfig->{dateformat};
1724 $dateformat .= "yy" if $myconfig->{dateformat} !~ /^y/;
1726 $query = qq|SELECT to_date('$thisdate', '$dateformat') + $days AS thisdate
1728 $sth = $dbh->prepare($query);
1729 $sth->execute || $self->dberror($query);
1731 $query = qq|SELECT current_date AS thisdate
1733 $sth = $dbh->prepare($query);
1734 $sth->execute || $self->dberror($query);
1737 ($thisdate) = $sth->fetchrow_array;
1742 $main::lxdebug->leave_sub();
1748 $main::lxdebug->enter_sub();
1750 my ($self, $string) = @_;
1752 if ($string !~ /%/) {
1753 $string = "%$string%";
1756 $string =~ s/\'/\'\'/g;
1758 $main::lxdebug->leave_sub();
1764 $main::lxdebug->enter_sub();
1766 my ($self, $flds, $new, $count, $numrows) = @_;
1770 map { push @ndx, { num => $new->[$_ - 1]->{runningnumber}, ndx => $_ } }
1776 foreach my $item (sort { $a->{num} <=> $b->{num} } @ndx) {
1778 $j = $item->{ndx} - 1;
1779 map { $self->{"${_}_$i"} = $new->[$j]->{$_} } @{$flds};
1783 for $i ($count + 1 .. $numrows) {
1784 map { delete $self->{"${_}_$i"} } @{$flds};
1787 $main::lxdebug->leave_sub();
1791 $main::lxdebug->enter_sub();
1793 my ($self, $myconfig) = @_;
1797 my $dbh = $self->dbconnect_noauto($myconfig);
1799 my $query = qq|DELETE FROM status
1800 WHERE formname = '$self->{formname}'
1802 my $sth = $dbh->prepare($query) || $self->dberror($query);
1804 if ($self->{formname} =~ /(check|receipt)/) {
1805 for $i (1 .. $self->{rowcount}) {
1806 $sth->execute($self->{"id_$i"} * 1) || $self->dberror($query);
1810 $sth->execute($self->{id}) || $self->dberror($query);
1814 my $printed = ($self->{printed} =~ /$self->{formname}/) ? "1" : "0";
1815 my $emailed = ($self->{emailed} =~ /$self->{formname}/) ? "1" : "0";
1817 my %queued = split / /, $self->{queued};
1819 if ($self->{formname} =~ /(check|receipt)/) {
1821 # this is a check or receipt, add one entry for each lineitem
1822 my ($accno) = split /--/, $self->{account};
1823 $query = qq|INSERT INTO status (trans_id, printed, spoolfile, formname,
1824 chart_id) VALUES (?, '$printed',
1825 '$queued{$self->{formname}}', '$self->{prinform}',
1826 (SELECT c.id FROM chart c WHERE c.accno = '$accno'))|;
1827 $sth = $dbh->prepare($query) || $self->dberror($query);
1829 for $i (1 .. $self->{rowcount}) {
1830 if ($self->{"checked_$i"}) {
1831 $sth->execute($self->{"id_$i"}) || $self->dberror($query);
1836 $query = qq|INSERT INTO status (trans_id, printed, emailed,
1837 spoolfile, formname)
1838 VALUES ($self->{id}, '$printed', '$emailed',
1839 '$queued{$self->{formname}}', '$self->{formname}')|;
1840 $dbh->do($query) || $self->dberror($query);
1846 $main::lxdebug->leave_sub();
1850 $main::lxdebug->enter_sub();
1852 my ($self, $dbh) = @_;
1854 my ($query, $printed, $emailed);
1856 my $formnames = $self->{printed};
1857 my $emailforms = $self->{emailed};
1859 my $query = qq|DELETE FROM status
1860 WHERE formname = '$self->{formname}'
1861 AND trans_id = $self->{id}|;
1862 $dbh->do($query) || $self->dberror($query);
1864 # this only applies to the forms
1865 # checks and receipts are posted when printed or queued
1867 if ($self->{queued}) {
1868 my %queued = split / /, $self->{queued};
1870 foreach my $formname (keys %queued) {
1871 $printed = ($self->{printed} =~ /$self->{formname}/) ? "1" : "0";
1872 $emailed = ($self->{emailed} =~ /$self->{formname}/) ? "1" : "0";
1874 $query = qq|INSERT INTO status (trans_id, printed, emailed,
1875 spoolfile, formname)
1876 VALUES ($self->{id}, '$printed', '$emailed',
1877 '$queued{$formname}', '$formname')|;
1878 $dbh->do($query) || $self->dberror($query);
1880 $formnames =~ s/$self->{formname}//;
1881 $emailforms =~ s/$self->{formname}//;
1886 # save printed, emailed info
1887 $formnames =~ s/^ +//g;
1888 $emailforms =~ s/^ +//g;
1891 map { $status{$_}{printed} = 1 } split / +/, $formnames;
1892 map { $status{$_}{emailed} = 1 } split / +/, $emailforms;
1894 foreach my $formname (keys %status) {
1895 $printed = ($formnames =~ /$self->{formname}/) ? "1" : "0";
1896 $emailed = ($emailforms =~ /$self->{formname}/) ? "1" : "0";
1898 $query = qq|INSERT INTO status (trans_id, printed, emailed, formname)
1899 VALUES ($self->{id}, '$printed', '$emailed', '$formname')|;
1900 $dbh->do($query) || $self->dberror($query);
1903 $main::lxdebug->leave_sub();
1906 sub update_defaults {
1907 $main::lxdebug->enter_sub();
1909 my ($self, $myconfig, $fld) = @_;
1911 my $dbh = $self->dbconnect_noauto($myconfig);
1912 my $query = qq|SELECT $fld FROM defaults FOR UPDATE|;
1913 my $sth = $dbh->prepare($query);
1915 $sth->execute || $self->dberror($query);
1916 my ($var) = $sth->fetchrow_array;
1921 $query = qq|UPDATE defaults
1923 $dbh->do($query) || $form->dberror($query);
1928 $main::lxdebug->leave_sub();
1933 sub update_business {
1934 $main::lxdebug->enter_sub();
1936 my ($self, $myconfig, $business_id) = @_;
1938 my $dbh = $self->dbconnect_noauto($myconfig);
1940 qq|SELECT customernumberinit FROM business WHERE id=$business_id FOR UPDATE|;
1941 my $sth = $dbh->prepare($query);
1943 $sth->execute || $self->dberror($query);
1944 my ($var) = $sth->fetchrow_array;
1949 $query = qq|UPDATE business
1950 SET customernumberinit = '$var' WHERE id=$business_id|;
1951 $dbh->do($query) || $form->dberror($query);
1956 $main::lxdebug->leave_sub();
1962 $main::lxdebug->enter_sub();
1964 my ($self, $myconfig, $salesman) = @_;
1966 my $dbh = $self->dbconnect($myconfig);
1968 qq|SELECT id, name FROM customer WHERE (customernumber ilike '%$salesman%' OR name ilike '%$salesman%') AND business_id in (SELECT id from business WHERE salesman)|;
1969 my $sth = $dbh->prepare($query);
1970 $sth->execute || $self->dberror($query);
1973 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1974 push(@{ $self->{salesman_list} }, $ref);
1978 $main::lxdebug->leave_sub();
1983 sub get_partsgroup {
1984 $main::lxdebug->enter_sub();
1986 my ($self, $myconfig, $p) = @_;
1988 my $dbh = $self->dbconnect($myconfig);
1990 my $query = qq|SELECT DISTINCT pg.id, pg.partsgroup
1992 JOIN parts p ON (p.partsgroup_id = pg.id)|;
1994 if ($p->{searchitems} eq 'part') {
1996 WHERE p.inventory_accno_id > 0|;
1998 if ($p->{searchitems} eq 'service') {
2000 WHERE p.inventory_accno_id IS NULL|;
2002 if ($p->{searchitems} eq 'assembly') {
2004 WHERE p.assembly = '1'|;
2006 if ($p->{searchitems} eq 'labor') {
2008 WHERE p.inventory_accno_id > 0 AND p.income_accno_id IS NULL|;
2012 ORDER BY partsgroup|;
2015 $query = qq|SELECT id, partsgroup FROM partsgroup
2016 ORDER BY partsgroup|;
2019 if ($p->{language_code}) {
2020 $query = qq|SELECT DISTINCT pg.id, pg.partsgroup,
2021 t.description AS translation
2023 JOIN parts p ON (p.partsgroup_id = pg.id)
2024 LEFT JOIN translation t ON (t.trans_id = pg.id AND t.language_code = '$p->{language_code}')
2025 ORDER BY translation|;
2028 my $sth = $dbh->prepare($query);
2029 $sth->execute || $self->dberror($query);
2031 $self->{all_partsgroup} = ();
2032 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
2033 push @{ $self->{all_partsgroup} }, $ref;
2037 $main::lxdebug->leave_sub();
2043 $main::lxdebug->enter_sub();
2045 my ($type, $country, $NLS_file) = @_;
2049 if ($country && -d "locale/$country") {
2050 $self->{countrycode} = $country;
2051 eval { require "locale/$country/$NLS_file"; };
2054 $self->{NLS_file} = $NLS_file;
2056 push @{ $self->{LONG_MONTH} },
2057 ("January", "February", "March", "April",
2058 "May ", "June", "July", "August",
2059 "September", "October", "November", "December");
2060 push @{ $self->{SHORT_MONTH} },
2061 (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
2063 $main::lxdebug->leave_sub();
2069 my ($self, $text) = @_;
2071 return (exists $self{texts}{$text}) ? $self{texts}{$text} : $text;
2075 $main::lxdebug->enter_sub();
2077 my ($self, $text) = @_;
2079 if (exists $self{subs}{$text}) {
2080 $text = $self{subs}{$text};
2082 if ($self->{countrycode} && $self->{NLS_file}) {
2084 "$text not defined in locale/$self->{countrycode}/$self->{NLS_file}");
2088 $main::lxdebug->leave_sub();
2094 $main::lxdebug->enter_sub();
2096 my ($self, $myconfig, $date, $longformat) = @_;
2099 my $longmonth = ($longformat) ? 'LONG_MONTH' : 'SHORT_MONTH';
2104 $spc = $myconfig->{dateformat};
2106 $spc = substr($spc, 1, 1);
2108 if ($date =~ /\D/) {
2109 if ($myconfig->{dateformat} =~ /^yy/) {
2110 ($yy, $mm, $dd) = split /\D/, $date;
2112 if ($myconfig->{dateformat} =~ /^mm/) {
2113 ($mm, $dd, $yy) = split /\D/, $date;
2115 if ($myconfig->{dateformat} =~ /^dd/) {
2116 ($dd, $mm, $yy) = split /\D/, $date;
2119 $date = substr($date, 2);
2120 ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
2125 $yy = ($yy < 70) ? $yy + 2000 : $yy;
2126 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
2128 if ($myconfig->{dateformat} =~ /^dd/) {
2129 if (defined $longformat && $longformat == 0) {
2131 $dd = "0$dd" if ($dd < 10);
2132 $mm = "0$mm" if ($mm < 10);
2133 $longdate = "$dd$spc$mm$spc$yy";
2136 $longdate .= ($spc eq '.') ? ". " : " ";
2137 $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
2139 } elsif ($myconfig->{dateformat} eq "yyyy-mm-dd") {
2141 # Use German syntax with the ISO date style "yyyy-mm-dd" because
2142 # Lx-Office is mainly used in Germany or German speaking countries.
2143 if (defined $longformat && $longformat == 0) {
2145 $dd = "0$dd" if ($dd < 10);
2146 $mm = "0$mm" if ($mm < 10);
2147 $longdate = "$yy-$mm-$dd";
2149 $longdate = "$dd. ";
2150 $longdate .= &text($self, $self->{$longmonth}[$mm]) . " $yy";
2153 if (defined $longformat && $longformat == 0) {
2155 $dd = "0$dd" if ($dd < 10);
2156 $mm = "0$mm" if ($mm < 10);
2157 $longdate = "$mm$spc$dd$spc$yy";
2159 $longdate = &text($self, $self->{$longmonth}[$mm]) . " $dd, $yy";
2165 $main::lxdebug->leave_sub();
2171 $main::lxdebug->enter_sub();
2173 my ($self, $myconfig, $date, $longformat) = @_;
2176 $main::lxdebug->leave_sub();
2181 $spc = $myconfig->{dateformat};
2183 $spc = substr($spc, 1, 1);
2185 if ($date =~ /\D/) {
2186 if ($myconfig->{dateformat} =~ /^yy/) {
2187 ($yy, $mm, $dd) = split /\D/, $date;
2188 } elsif ($myconfig->{dateformat} =~ /^mm/) {
2189 ($mm, $dd, $yy) = split /\D/, $date;
2190 } elsif ($myconfig->{dateformat} =~ /^dd/) {
2191 ($dd, $mm, $yy) = split /\D/, $date;
2194 $date = substr($date, 2);
2195 ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
2200 $yy = ($yy < 70) ? $yy + 2000 : $yy;
2201 $yy = ($yy >= 70 && $yy <= 99) ? $yy + 1900 : $yy;
2203 $main::lxdebug->leave_sub();
2204 return ($yy, $mm, $dd);