use SL::DBUtils;
+use strict;
+
sub get_vc {
$main::lxdebug->enter_sub();
my $vc = $form->{vc} eq "customer" ? "customer" : "vendor";
my $arap_type = defined($arap{$form->{type}}) ? $arap{$form->{type}} : 'ar';
- $query =
+ my $query =
qq|SELECT count(*) | .
qq|FROM (SELECT DISTINCT ON (vc.id) vc.id FROM $vc vc, $arap_type a, status s | .
qq| WHERE a.${vc}_id = vc.id AND s.trans_id = a.id AND s.formname = ? | .
qq|WHERE a.${vc}_id = vc.id AND s.trans_id = a.id AND s.formname = ? | .
qq| AND s.spoolfile IS NOT NULL|;
- $sth = $dbh->prepare($query);
+ my $sth = $dbh->prepare($query);
$sth->execute($form->{type}) || $form->dberror($query . " ($form->{type})");
$form->{"all_${vc}"} = [];
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
push @{ $form->{"all_${vc}"} }, $ref;
}
$sth->finish;
$sth->execute($form->{type}) || $form->dberror($query . " ($form->{type})");
$form->{accounts} = [];
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
push @{ $form->{accounts} }, $ref;
}
}
}
- my @a = (transdate, $invnumber, name);
+ my @a = ("transdate", $invnumber, "name");
my $sortorder = join ', ', $form->sort_columns(@a);
if (grep({ $_ eq $form->{sort} }
$form->dberror($query . " (" . join(", ", @values) . ")");
$form->{SPOOL} = [];
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
push @{ $form->{SPOOL} }, $ref;
}
sub print_spool {
$main::lxdebug->enter_sub();
- my ($self, $myconfig, $form, $spool) = @_;
+ my ($self, $myconfig, $form, $spool, $output) = @_;
# connect to database
my $dbh = $form->dbconnect($myconfig);
foreach my $i (1 .. $form->{rowcount}) {
if ($form->{"checked_$i"}) {
- open(OUT, $form->{OUT}) or $form->error("$form->{OUT} : $!");
+ # $output is safe ( = does not come directly from the browser).
+ open(OUT, $output) or $form->error("$output : $!");
- $spoolfile = qq|$spool/$form->{"spoolfile_$i"}|;
+ $form->{"spoolfile_$i"} =~ s|.*/||;
+ my $spoolfile = qq|$spool/$form->{"spoolfile_$i"}|;
# send file to printer
open(IN, $spoolfile) or $form->error("$spoolfile : $!");