-#=====================================================================
+#====================================================================
# LX-Office ERP
# Copyright (C) 2004
# Based on SQL-Ledger Version 2.1.9
package Form;
+use HTML::Template;
+use SL::Menu;
+
sub _input_to_hash {
- $main::lxdebug->enter_sub();
+ $main::lxdebug->enter_sub(2);
my $input = $_[0];
my %in = ();
$in{$name} = unescape(undef, $value);
}
- $main::lxdebug->leave_sub();
+ $main::lxdebug->leave_sub(2);
return %in;
}
sub _request_to_hash {
- $main::lxdebug->enter_sub();
+ $main::lxdebug->enter_sub(2);
my ($input) = @_;
my ($i, $loc, $key, $val);
}
}
- $main::lxdebug->leave_sub();
+ $main::lxdebug->leave_sub(2);
return %ATTACH;
} else {
- $main::lxdebug->leave_sub();
+ $main::lxdebug->leave_sub(2);
return _input_to_hash($input);
}
}
$self->{action} = lc $self->{action};
$self->{action} =~ s/( |-|,|#)/_/g;
- $self->{version} = "2.1.2";
- $self->{dbversion} = "2.1.2";
+ $self->{version} = "2.3.0";
$main::lxdebug->leave_sub();
}
sub escape {
- $main::lxdebug->enter_sub();
+ $main::lxdebug->enter_sub(2);
my ($self, $str, $beenthere) = @_;
$str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
- $main::lxdebug->leave_sub();
+ $main::lxdebug->leave_sub(2);
return $str;
}
sub unescape {
- $main::lxdebug->enter_sub();
+ $main::lxdebug->enter_sub(2);
my ($self, $str) = @_;
$str =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
- $main::lxdebug->leave_sub();
+ $main::lxdebug->leave_sub(2);
return $str;
}
-sub error {
- $main::lxdebug->enter_sub();
+sub quote {
+ my ($self, $str) = @_;
- my ($self, $msg) = @_;
+ if ($str && !ref($str)) {
+ $str =~ s/\"/"/g;
+ }
- if ($ENV{HTTP_USER_AGENT}) {
- $msg =~ s/\n/<br>/g;
+ $str;
- $self->header;
+}
- print qq|
- <body>
+sub unquote {
+ my ($self, $str) = @_;
- <h2 class=error>Error!</h2>
+ if ($str && !ref($str)) {
+ $str =~ s/"/\"/g;
+ }
- <p><b>$msg</b>
+ $str;
- </body>
- </html>
- |;
+}
+
+sub hide_form {
+ my $self = shift;
+
+ if (@_) {
+ for (@_) {
+ print qq|<input type=hidden name="$_" value="|
+ . $self->quote($self->{$_})
+ . qq|">\n|;
+ }
+ } else {
+ delete $self->{header};
+ for (sort keys %$self) {
+ print qq|<input type=hidden name="$_" value="|
+ . $self->quote($self->{$_})
+ . qq|">\n|;
+ }
+ }
+
+}
+
+sub error {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $msg) = @_;
- die "Error: $msg\n";
+ if ($ENV{HTTP_USER_AGENT}) {
+ $msg =~ s/\n/<br>/g;
+ $self->show_generic_error($msg);
} else {
}
#Set Calendar
- $jsscript = "";
+ my $jsscript = "";
if ($self->{jsscript} == 1) {
$jsscript = qq|
<style type="text/css">\@import url(js/jscalendar/calendar-win2k-1.css);</style>
<script type="text/javascript" src="js/jscalendar/calendar.js"></script>
- <script type="text/javascript" src="js/jscalendar/lang/calendar-de.js"></script>
- <script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script>
+ <script type="text/javascript" src="js/jscalendar/lang/calendar-de.js"></script>
+ <script type="text/javascript" src="js/jscalendar/calendar-setup.js"></script>
+ $self->{javascript}
|;
}
print qq|Content-Type: text/html
+<html>
<head>
<title>$self->{titlebar}</title>
$stylesheet
$main::lxdebug->leave_sub();
}
-# write Trigger JavaScript-Code ($qty = 1 - only one Trigger)
+sub parse_html_template {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $file, $additional_params) = @_;
+ my $language;
+
+ if (!defined($main::myconfig) || !defined($main::myconfig{"countrycode"})) {
+ $language = $main::language;
+ } else {
+ $language = $main::myconfig{"countrycode"};
+ }
+
+ if (-f "templates/webpages/${file}_${language}.html") {
+ if ((-f ".developer") &&
+ (-f "templates/webpages/${file}_master.html") &&
+ ((stat("templates/webpages/${file}_master.html"))[9] >
+ (stat("templates/webpages/${file}_${language}.html"))[9])) {
+ my $info = "Developper information: templates/webpages/${file}_master.html is newer than the localized version.\n" .
+ "Please re-run 'locales.pl' in 'locale/${language}'.";
+ print(qq|<pre>$info</pre>|);
+ die($info);
+ }
+
+ $file = "templates/webpages/${file}_${language}.html";
+ } elsif (-f "templates/webpages/${file}.html") {
+ $file = "templates/webpages/${file}.html";
+ } else {
+ my $info = "Web page template '${file}' not found.\n" .
+ "Please re-run 'locales.pl' in 'locale/${language}'.";
+ print(qq|<pre>$info</pre>|);
+ die($info);
+ }
+
+ my $template = HTML::Template->new("filename" => $file,
+ "die_on_bad_params" => 0,
+ "strict" => 0,
+ "case_sensitive" => 1,
+ "loop_context_vars" => 1,
+ "global_vars" => 1);
+
+ $additional_params = {} unless ($additional_params);
+ if ($self->{"DEBUG"}) {
+ $additional_params->{"DEBUG"} = $self->{"DEBUG"};
+ }
+
+ if ($additional_params->{"DEBUG"}) {
+ $additional_params->{"DEBUG"} =
+ "<br><em>DEBUG INFORMATION:</em><pre>" . $additional_params->{"DEBUG"} . "</pre>";
+ }
+
+ if (%main::myconfig) {
+ map({ $additional_params->{"myconfig_${_}"} = $main::myconfig{$_}; } keys(%main::myconfig));
+ my $jsc_dateformat = $main::myconfig{"dateformat"};
+ $jsc_dateformat =~ s/d+/\%d/gi;
+ $jsc_dateformat =~ s/m+/\%m/gi;
+ $jsc_dateformat =~ s/y+/\%Y/gi;
+ $additional_params->{"myconfig_jsc_dateformat"} = $jsc_dateformat;
+ }
+
+ $additional_params->{"conf_jscalendar"} = $main::jscalendar;
+ $additional_params->{"conf_lizenzen"} = $main::lizenzen;
+ $additional_params->{"conf_latex_templates"} = $main::latex;
+ $additional_params->{"conf_opendocument_templates"} = $main::opendocument_templates;
+
+ my $menu;
+ if (-f $self->{"login"} . "_menu.ini") {
+ $menu = Menu->new($self->{"login"} . "_menu.ini");
+ } else {
+ $menu = Menu->new("menu.ini");
+ }
+ $menu->generate_acl("", $additional_params);
+
+ my @additional_param_names = keys(%{$additional_params});
+
+ foreach my $key ($template->param()) {
+ if (grep(/^${key}$/, @additional_param_names)) {
+ $template->param($key => $additional_params->{$key});
+ } else {
+ $template->param($key => $self->{$key});
+ }
+ }
+
+ my $output = $template->output();
+
+ $main::lxdebug->leave_sub();
+
+ return $output;
+}
+
+sub show_generic_error {
+ my ($self, $error, $title) = @_;
+
+ my $add_params = {};
+ $add_params->{"title"} = $title if ($title);
+ $self->{"label_error"} = $error;
+
+ $self->header();
+ print($self->parse_html_template("generic/error", $add_params));
+
+ die("Error: $error\n");
+}
+
+sub show_generic_information {
+ my ($self, $error, $title) = @_;
+
+ my $add_params = {};
+ $add_params->{"title"} = $title if ($title);
+ $self->{"label_information"} = $error;
+
+ $self->header();
+ print($self->parse_html_template("generic/information", $add_params));
+
+ die("Information: $error\n");
+}
+
+# write Trigger JavaScript-Code ($qty = quantity of Triggers)
+# changed it to accept an arbitrary number of triggers - sschoeling
sub write_trigger {
$main::lxdebug->enter_sub();
- my ($self, $myconfig, $qty,
- $inputField_1, $align_1, $button_1,
- $inputField_2, $align_2, $button_2)
- = @_;
+ my $self = shift;
+ my $myconfig = shift;
+ my $qty = shift;
# set dateform for jsscript
# default
}
}
- $trigger_1 = qq|
+ while ($#_ >= 2) {
+ push @triggers, qq|
Calendar.setup(
- {
- inputField : "$inputField_1",
- ifFormat :"$ifFormat",
- align : "$align_1",
- button : "$button_1"
- }
- );
+ {
+ inputField : "| . (shift) . qq|",
+ ifFormat :"$ifFormat",
+ align : "| . (shift) . qq|",
+ button : "| . (shift) . qq|"
+ }
+ );
|;
-
- if ($qty == 2) {
- $trigger_2 = qq|
- Calendar.setup(
- {
- inputField : "$inputField_2",
- ifFormat :"$ifFormat",
- align : "$align_2",
- button : "$button_2"
- }
- );
- |;
}
- $jsscript = qq|
+ my $jsscript = qq|
<script type="text/javascript">
- <!--
- $trigger_1
- $trigger_2
- //-->
+ <!--| . join("", @triggers) . qq|//-->
</script>
|;
return @columns;
}
-
+#
sub format_amount {
- $main::lxdebug->enter_sub();
+ $main::lxdebug->enter_sub(2);
my ($self, $myconfig, $amount, $places, $dash) = @_;
+ my $neg = ($amount =~ s/-//);
- if ($places =~ /\d/) {
- $amount = $self->round_amount($amount, $places);
- }
-
- # is the amount negative
- my $negative = ($amount < 0);
-
- if ($amount != 0) {
- if ($myconfig->{numberformat} && ($myconfig->{numberformat} ne '1000.00'))
- {
- my ($whole, $dec) = split /\./, "$amount";
- $whole =~ s/-//;
- $amount = join '', reverse split //, $whole;
+ $amount = $self->round_amount($amount, $places) if ($places =~ /\d/);
- if ($myconfig->{numberformat} eq '1,000.00') {
- $amount =~ s/\d{3,}?/$&,/g;
- $amount =~ s/,$//;
- $amount = join '', reverse split //, $amount;
- $amount .= "\.$dec" if ($dec ne "");
- }
+ my @d = map { s/\d//g; reverse split // } my $tmp = $myconfig->{numberformat}; # get delim chars
+ my @p = split /\./, $amount ; # split amount at decimal point
- if ($myconfig->{numberformat} eq '1.000,00') {
- $amount =~ s/\d{3,}?/$&./g;
- $amount =~ s/\.$//;
- $amount = join '', reverse split //, $amount;
- $amount .= ",$dec" if ($dec ne "");
- }
-
- if ($myconfig->{numberformat} eq '1000,00') {
- $amount = "$whole";
- $amount .= ",$dec" if ($dec ne "");
- }
-
- if ($dash =~ /-/) {
- $amount = ($negative) ? "($amount)" : "$amount";
- } elsif ($dash =~ /DRCR/) {
- $amount = ($negative) ? "$amount DR" : "$amount CR";
- } else {
- $amount = ($negative) ? "-$amount" : "$amount";
- }
- }
- } else {
- if ($dash eq "0" && $places) {
- if ($myconfig->{numberformat} eq '1.000,00') {
- $amount = "0" . "," . "0" x $places;
- } else {
- $amount = "0" . "." . "0" x $places;
- }
- } else {
- $amount = ($dash ne "") ? "$dash" : "0";
- }
- }
-
- $main::lxdebug->leave_sub();
+ $p[0] =~ s/\B(?=(...)*$)/$d[1]/g if $d[1]; # add 1,000 delimiters
+ $amount = $p[0];
+ $amount .= $d[0].$p[1].(0 x ($places - length $p[1])) if ($places || $p[1] ne '');
+
+ $amount = do {
+ ($dash =~ /-/) ? ($neg ? "($amount)" : "$amount" ) :
+ ($dash =~ /DRCR/) ? ($neg ? "$amount DR" : "$amount CR" ) :
+ ($neg ? "-$amount" : "$amount" ) ;
+ };
+
+ $main::lxdebug->leave_sub(2);
return $amount;
}
-
+#
sub parse_amount {
- $main::lxdebug->enter_sub();
+ $main::lxdebug->enter_sub(2);
my ($self, $myconfig, $amount) = @_;
- if (!(substr($amount, -3, 1) eq ".")) {
- if ( ($myconfig->{numberformat} eq '1.000,00')
- || ($myconfig->{numberformat} eq '1000,00')) {
- $amount =~ s/\.//g;
- $amount =~ s/,/\./;
- }
+ if ($myconfig->{in_numberformat} == 1) {
+ # Extra input number format 1000.00 or 1000,00
+ $amount =~ s/,/\./g;
+ $amount = scalar reverse $amount;
+ $amount =~ s/\./DOT/;
+ $amount =~ s/\.//g;
+ $amount =~ s/DOT/\./;
+ $amount = scalar reverse $amount;
+ $main::lxdebug->leave_sub(2);
+ return ($amount * 1);
+ }
- $amount =~ s/,//g;
+ if ( ($myconfig->{numberformat} eq '1.000,00')
+ || ($myconfig->{numberformat} eq '1000,00')) {
+ $amount =~ s/\.//g;
+ $amount =~ s/,/\./;
}
- $main::lxdebug->leave_sub();
+ if ($myconfig->{numberformat} eq "1'000.00") {
+ $amount =~ s/\'//g;
+ }
+
+ $amount =~ s/,//g;
+
+ $main::lxdebug->leave_sub(2);
return ($amount * 1);
}
sub round_amount {
- $main::lxdebug->enter_sub();
+ $main::lxdebug->enter_sub(2);
my ($self, $amount, $places) = @_;
- my $rc;
-
- # $places = 3 if $places == 2;
+ my $round_amount;
- if (($places * 1) >= 0) {
+ # Rounding like "Kaufmannsrunden"
+ # Descr. http://de.wikipedia.org/wiki/Rundung
+ # Inspired by
+ # http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q4.13.html
+ # Solves Bug: 189
+ # Udo Spallek
+ $amount = $amount * (10**($places));
+ $round_amount = int($amount + .5 * ($amount <=> 0)) / (10**($places));
- # add 1/10^$places+3
- $rc =
- sprintf("%.${places}f",
- $amount + (1 / (10**($places + 3))) * (($amount > 0) ? 1 : -1));
- } else {
- $places *= -1;
- $rc =
- sprintf("%.f", $amount / (10**$places) + (($amount > 0) ? 0.1 : -0.1)) *
- (10**$places);
- }
+ $main::lxdebug->leave_sub(2);
- $main::lxdebug->leave_sub();
+ return $round_amount;
- return $rc;
}
sub parse_template {
my ($current_page, $current_line, $current_row) = (1, 1, 0);
my $pagebreak = "";
my $sum = 0;
-
# } Moritz Bunkus
+ # The old fixed notation of <%variable%> is changed to a new dynamic one.
+ my ${pre} = '<%'; # Variable Prefix, must be regex save!
+ my ${suf} = '%>'; # Variable Suffix, must be regex save!
+
+
# Make sure that all *notes* (intnotes, partnotes_*, notes etc) are converted to markup correctly.
$self->format_string(grep(/notes/, keys(%{$self})));
$self->{"notes"} = $self->{ $self->{"formname"} . "notes" };
map({ $self->{"employee_${_}"} = $myconfig->{$_}; }
- qw(email tel fax name signature));
+ qw(email tel fax name signature company address businessnumber));
open(IN, "$self->{templates}/$self->{IN}")
or $self->error("$self->{IN} : $!");
$two_passes = 0;
# first we generate a tmpfile
- # read file and replace <%variable%>
+ # read file and replace ${pre}variable${suf}
while ($_ = shift) {
$par = "";
$var = $_;
-
+
+ # Switch ${pre}analyse${suf} for template checking
+ # If ${pre}analyse${suf} is set in the template, you'll find the
+ # parsed output in the user Directory for analysing
+ # Latex errors
+ # ${pre}analyse${suf} is a switch (allways off, on if set), not a Variable
+ # Set $form->{analysing}="" for system state: never analyse.
+ # Set $form->{analysing}="1" for system state: ever analyse.
+ $self->{analysing} = "1" if (/${pre}analyse${suf}/ && !defined $self->{analysing});
+
$two_passes = 1 if (/\\pageref/);
# { Moritz Bunkus
# detect pagebreak block and its parameters
- if (/\s*<%pagebreak ([0-9]+) ([0-9]+) ([0-9]+)%>/) {
+ if (/\s*${pre}pagebreak ([0-9]+) ([0-9]+) ([0-9]+)${suf}/) {
$chars_per_line = $1;
$lines_on_first_page = $2;
$lines_on_second_page = $3;
while ($_ = shift) {
- last if (/\s*<%end pagebreak%>/);
+ last if (/\s*${pre}end pagebreak${suf}/);
$pagebreak .= $_;
}
}
# } Moritz Bunkus
-
- if (/\s*<%foreach /) {
+
+ if (/\s*${pre}foreach /) {
# this one we need for the count
chomp $var;
- $var =~ s/\s*<%foreach (.+?)%>/$1/;
+ $var =~ s/\s*${pre}foreach (.+?)${suf}/$1/;
while ($_ = shift) {
- last if (/\s*<%end /);
+ last if (/\s*${pre}end /);
# store line in $par
$par .= $_;
# { Moritz Bunkus
# Try to detect whether a manual page break is necessary
- # but only if there was a <%pagebreak ...%> block before
+ # but only if there was a ${pre}pagebreak ...${suf} block before
if ($chars_per_line) {
my $lines =
}
# Yes we need a manual page break -- or the user has forced one
- if ((($current_line + $lines) > $lpp) ||
- ($self->{"_forced_pagebreaks"} && grep(/^${current_row}$/, @{$self->{"_forced_pagebreaks"}}))) {
+ if (
+ (($current_line + $lines) > $lpp)
+ || ($self->{"_forced_pagebreaks"}
+ && grep(/^${current_row}$/, @{ $self->{"_forced_pagebreaks"} }))
+ ) {
my $pb = $pagebreak;
- # replace the special variables <%sumcarriedforward%>
- # and <%lastpage%>
+ # replace the special variables ${pre}sumcarriedforward${suf}
+ # and ${pre}lastpage${suf}
my $psum = $self->format_amount($myconfig, $sum, 2);
- $pb =~ s/<%sumcarriedforward%>/$psum/g;
- $pb =~ s/<%lastpage%>/$current_page/g;
+ $pb =~ s/${pre}sumcarriedforward${suf}/$psum/g;
+ $pb =~ s/${pre}lastpage${suf}/$current_page/g;
# only "normal" variables are supported here
- # (no <%if, no <%foreach, no <%include)
+ # (no ${pre}if, no ${pre}foreach, no ${pre}include)
- $pb =~ s/<%(.+?)%>/$self->{$1}/g;
+ $pb =~ s/${pre}(.+?)${suf}/$self->{$1}/g;
# page break block is ready to rock
print(OUT $pb);
# don't parse par, we need it for each line
$_ = $par;
- s/<%(.+?)%>/$self->{$1}[$i]/mg;
+ s/${pre}(.+?)${suf}/$self->{$1}[$i]/mg;
print OUT;
}
next;
}
# if not comes before if!
- if (/\s*<%if not /) {
+ if (/\s*${pre}if not /) {
# check if it is not set and display
chop;
- s/\s*<%if not (.+?)%>/$1/;
+ s/\s*${pre}if not (.+?)${suf}/$1/;
unless ($self->{$_}) {
while ($_ = shift) {
- last if (/\s*<%end /);
+ last if (/\s*${pre}end /);
# store line in $par
$par .= $_;
} else {
while ($_ = shift) {
- last if (/\s*<%end /);
+ last if (/\s*${pre}end /);
}
next;
}
}
- if (/\s*<%if /) {
+ if (/\s*${pre}if /) {
# check if it is set and display
chop;
- s/\s*<%if (.+?)%>/$1/;
+ s/\s*${pre}if (.+?)${suf}/$1/;
if ($self->{$_}) {
while ($_ = shift) {
- last if (/\s*<%end /);
+ last if (/\s*${pre}end /);
# store line in $par
$par .= $_;
} else {
while ($_ = shift) {
- last if (/\s*<%end /);
+ last if (/\s*${pre}end /);
}
next;
}
}
- # check for <%include filename%>
- if (/\s*<%include /) {
+ # check for ${pre}include filename${suf}
+ if (/\s*${pre}include /) {
- # get the filename
+ # get the directory/filename
chomp $var;
- $var =~ s/\s*<%include (.+?)%>/$1/;
+ $var =~ s/\s*${pre}include (.+?)${suf}/$1/;
- # mangle filename
- $var =~ s/(\/|\.\.)//g;
+ # mangle filename on basedir
+ $var =~ s/^(\/|\.\.)//g;
# prevent the infinite loop!
next if ($self->{"$var"});
next;
}
- s/<%(.+?)%>/$self->{$1}/g;
+ s/${pre}(.+?)${suf}/$self->{$1}/g;
+ s/<nobr><\/nobr>/ /g;
print OUT;
}
close(IN);
}
- $self->cleanup;
-
}
+ $self->cleanup;
+
chdir("$self->{cwd}");
$main::lxdebug->leave_sub();
}
close(FH);
}
- if ($self->{tmpfile}) {
+ if ($self->{analysing} eq "") {
+ if ($self->{tmpfile}) {
- # strip extension
- $self->{tmpfile} =~ s/\.\w+$//g;
- my $tmpfile = $self->{tmpfile};
- unlink(<$tmpfile.*>);
+ # strip extension
+ $self->{tmpfile} =~ s/\.\w+$//g;
+ my $tmpfile = $self->{tmpfile};
+ unlink(<$tmpfile.*>);
+ }
}
chdir("$self->{cwd}");
my %unique_fields;
%unique_fields = map({ $_ => 1 } @fields);
- @fields = keys(%unique_fields);
+ @fields = keys(%unique_fields);
foreach my $field (@fields) {
next unless ($self->{$field} =~ /\<pagebreak\>/);
$self->{$field} =~ s/\<pagebreak\>//g;
if ($field =~ /.*_(\d+)$/) {
- if ($self->{"_forced_pagebreaks"}) {
+ if (!$self->{"_forced_pagebreaks"}) {
$self->{"_forced_pagebreaks"} = [];
}
push(@{ $self->{"_forced_pagebreaks"} }, "$1");
'&', quotemeta('\n'), '
',
'"', '\$', '%', '_', '#', quotemeta('^'),
- '{', '}', '<', '>', '£', "\r"
+ '{', '}', '<', '>', '£', "\r", '²'
]
},
'html' => {
'
' => '\newline ',
'£' => '\pounds ',
+ '²' => '$^2$',
"\r" => ""
});
'u' => 'underline');
foreach my $field (@fields) {
- if ($field =~ /descrip/) {
- print(STDERR "QFT: ${field}: " . $self->{$field} . "\n");
- }
foreach my $key (keys(%markup_replace)) {
my $new = $markup_replace{$key};
$self->{$field} =~
my ($self, $dbh, $curr, $transdate, $fld) = @_;
+ unless ($transdate) {
+ $main::lxdebug->leave_sub();
+ return "";
+ }
+
my $query = qq|SELECT e.$fld FROM exchangerate e
WHERE e.curr = '$curr'
AND e.transdate = '$transdate'|;
my ($self, $dbh, $id) = @_;
##LINET
my $shipto;
- foreach
- my $item (qw(name department_1 department_2 street zipcode city country contact phone fax email)) {
+ foreach my $item (
+ qw(name department_1 department_2 street zipcode city country contact phone fax email)
+ ) {
if ($self->{"shipto$item"}) {
$shipto = 1 if ($self->{$item} ne $self->{"shipto$item"});
}
}
if ($shipto) {
- my $query = qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2, shiptostreet,
+ my $query =
+ qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2, shiptostreet,
shiptozipcode, shiptocity, shiptocountry, shiptocontact,
shiptophone, shiptofax, shiptoemail) VALUES ($id,
'$self->{shiptoname}', '$self->{shiptodepartment_1}', '$self->{shiptodepartment_2}', '$self->{shiptostreet}',
my %xkeyref = ();
# now get the account numbers
- $query =
- qq|SELECT c.accno, SUBSTRING(c.description,1,50) as description, c.link, c.taxkey_id
+ $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id
FROM chart c
WHERE c.link LIKE '%$module%'
ORDER BY c.accno|;
$query = qq| SELECT * FROM tax t|;
$sth = $dbh->prepare($query);
$sth->execute || $self->dberror($query);
- $form->{TAX} = ();
+ $self->{TAX} = ();
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
push @{ $self->{TAX} }, $ref;
}
LEFT Join tax t ON (a.taxkey = t.taxkey)
WHERE a.trans_id = $self->{id}
AND a.fx_transaction = '0'
- ORDER BY a.transdate|;
+ ORDER BY a.oid,a.transdate|;
$sth = $dbh->prepare($query);
$sth->execute || $self->dberror($query);
$self->{exchangerate} =
$self->get_exchangerate($dbh, $self->{currency}, $self->{transdate},
$fld);
+ my $index = 0;
# store amounts in {acc_trans}{$key} for multiple accounts
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
$ref->{exchangerate} =
$self->get_exchangerate($dbh, $self->{currency}, $ref->{transdate},
$fld);
+ if (!($xkeyref{ $ref->{accno} } =~ /tax/)) {
+ $index++;
+ }
+ $ref->{index} = $index;
push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref;
}
$where = "quotation = '1'";
}
- my $query = qq|SELECT id FROM $arap
- WHERE id IN (SELECT MAX(id) FROM $arap
+ my $query = qq|SELECT MAX(id) FROM $arap
WHERE $where
- AND ${table}_id > 0)|;
+ AND ${table}_id > 0|;
my $sth = $dbh->prepare($query);
$sth->execute || $self->dberror($query);
$query = qq|UPDATE defaults
SET $fld = '$var'|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $self->dberror($query);
$dbh->commit;
$dbh->disconnect;
}
$query = qq|UPDATE business
SET customernumberinit = '$var' WHERE id=$business_id|;
- $dbh->do($query) || $form->dberror($query);
+ $dbh->do($query) || $self->dberror($query);
$dbh->commit;
$dbh->disconnect;
$main::lxdebug->leave_sub();
}
+sub get_pricegroup {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $p) = @_;
+
+ my $dbh = $self->dbconnect($myconfig);
+
+ my $query = qq|SELECT p.id, p.pricegroup
+ FROM pricegroup p|;
+
+ $query .= qq|
+ ORDER BY pricegroup|;
+
+ if ($p->{all}) {
+ $query = qq|SELECT id, pricegroup FROM pricegroup
+ ORDER BY pricegroup|;
+ }
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $self->dberror($query);
+
+ $self->{all_pricegroup} = ();
+ while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push @{ $self->{all_pricegroup} }, $ref;
+ }
+ $sth->finish;
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub audittrail {
+ my ($self, $dbh, $myconfig, $audittrail) = @_;
+
+ # table, $reference, $formname, $action, $id, $transdate) = @_;
+
+ my $query;
+ my $rv;
+ my $disconnect;
+
+ if (!$dbh) {
+ $dbh = $self->dbconnect($myconfig);
+ $disconnect = 1;
+ }
+
+ # if we have an id add audittrail, otherwise get a new timestamp
+
+ if ($audittrail->{id}) {
+
+ $query = qq|SELECT audittrail FROM defaults|;
+
+ if ($dbh->selectrow_array($query)) {
+ my ($null, $employee_id) = $self->get_employee($dbh);
+
+ if ($self->{audittrail} && !$myconfig) {
+ chop $self->{audittrail};
+
+ my @a = split /\|/, $self->{audittrail};
+ my %newtrail = ();
+ my $key;
+ my $i;
+ my @flds = qw(tablename reference formname action transdate);
+
+ # put into hash and remove dups
+ while (@a) {
+ $key = "$a[2]$a[3]";
+ $i = 0;
+ $newtrail{$key} = { map { $_ => $a[$i++] } @flds };
+ splice @a, 0, 5;
+ }
+
+ $query = qq|INSERT INTO audittrail (trans_id, tablename, reference,
+ formname, action, employee_id, transdate)
+ VALUES ($audittrail->{id}, ?, ?,
+ ?, ?, $employee_id, ?)|;
+ my $sth = $dbh->prepare($query) || $self->dberror($query);
+
+ foreach $key (
+ sort {
+ $newtrail{$a}{transdate} cmp $newtrail{$b}{transdate}
+ } keys %newtrail
+ ) {
+ $i = 1;
+ for (@flds) { $sth->bind_param($i++, $newtrail{$key}{$_}) }
+
+ $sth->execute || $self->dberror;
+ $sth->finish;
+ }
+ }
+
+ if ($audittrail->{transdate}) {
+ $query = qq|INSERT INTO audittrail (trans_id, tablename, reference,
+ formname, action, employee_id, transdate) VALUES (
+ $audittrail->{id}, '$audittrail->{tablename}', |
+ . $dbh->quote($audittrail->{reference}) . qq|,
+ '$audittrail->{formname}', '$audittrail->{action}',
+ $employee_id, '$audittrail->{transdate}')|;
+ } else {
+ $query = qq|INSERT INTO audittrail (trans_id, tablename, reference,
+ formname, action, employee_id) VALUES ($audittrail->{id},
+ '$audittrail->{tablename}', |
+ . $dbh->quote($audittrail->{reference}) . qq|,
+ '$audittrail->{formname}', '$audittrail->{action}',
+ $employee_id)|;
+ }
+ $dbh->do($query);
+ }
+ } else {
+
+ $query = qq|SELECT current_timestamp FROM defaults|;
+ my ($timestamp) = $dbh->selectrow_array($query);
+
+ $rv =
+ "$audittrail->{tablename}|$audittrail->{reference}|$audittrail->{formname}|$audittrail->{action}|$timestamp|";
+ }
+
+ $dbh->disconnect if $disconnect;
+
+ $rv;
+
+}
+
package Locale;
sub new {