use SL::MoreCommon;
use SL::DB::Default;
use SL::TransNumber;
+use SL::Util qw(trim);
use strict;
qq| dc.dunning_description, | .
qq| tz.description AS taxzone, | .
qq| pt.description AS payment_terms, | .
+ qq| d.description AS department, | .
qq{ ( SELECT ch.accno || ' -- ' || ch.description
FROM acc_trans at
LEFT JOIN chart ch ON ch.id = at.chart_id
if ($form->{customernumber}) {
$where .= " AND c.customernumber = ?";
- push(@values, $form->{customernumber});
+ push(@values, trim($form->{customernumber}));
}
if ($form->{customer_id}) {
$where .= " AND a.customer_id = ?";
push(@values, $form->{customer_id});
} elsif ($form->{customer}) {
$where .= " AND c.name ILIKE ?";
- push(@values, $form->like($form->{customer}));
+ push(@values, like($form->{customer}));
}
if ($form->{"cp_name"}) {
$where .= " AND (cp.cp_name ILIKE ? OR cp.cp_givenname ILIKE ?)";
- push(@values, ('%' . $form->{"cp_name"} . '%')x2);
+ push(@values, (like($form->{"cp_name"}))x2);
}
if ($form->{business_id}) {
my $business_id = $form->{business_id};
push(@values, $department_id);
}
if ($form->{department}) {
- my $department = "%" . $form->{department} . "%";
+ my $department = like($form->{department});
$where .= " AND d.description ILIKE ?";
push(@values, $department);
}
foreach my $column (qw(invnumber ordnumber cusordnumber notes transaction_description)) {
if ($form->{$column}) {
$where .= " AND a.$column ILIKE ?";
- push(@values, $form->like($form->{$column}));
+ push(@values, like($form->{$column}));
}
}
if ($form->{"project_id"}) {
if ($form->{transdatefrom}) {
$where .= " AND a.transdate >= ?";
- push(@values, $form->{transdatefrom});
+ push(@values, trim($form->{transdatefrom}));
}
if ($form->{transdateto}) {
$where .= " AND a.transdate <= ?";
- push(@values, $form->{transdateto});
+ push(@values, trim($form->{transdateto}));
}
if ($form->{duedatefrom}) {
$where .= " AND a.duedate >= ?";
- push(@values, $form->{duedatefrom});
+ push(@values, trim($form->{duedatefrom}));
}
if ($form->{duedateto}) {
$where .= " AND a.duedate <= ?";
- push(@values, $form->{duedateto});
+ push(@values, trim($form->{duedateto}));
}
if ($form->{open} || $form->{closed}) {
unless ($form->{open} && $form->{closed}) {
}
};
+ if ($form->{parts_partnumber}) {
+ $where .= <<SQL;
+ AND EXISTS (
+ SELECT invoice.trans_id
+ FROM invoice
+ LEFT JOIN parts ON (invoice.parts_id = parts.id)
+ WHERE (invoice.trans_id = a.id)
+ AND (parts.partnumber ILIKE ?)
+ LIMIT 1
+ )
+SQL
+ push @values, like($form->{parts_partnumber});
+ }
+
+ if ($form->{parts_description}) {
+ $where .= <<SQL;
+ AND EXISTS (
+ SELECT invoice.trans_id
+ FROM invoice
+ WHERE (invoice.trans_id = a.id)
+ AND (invoice.description ILIKE ?)
+ LIMIT 1
+ )
+SQL
+ push @values, like($form->{parts_description});
+ }
+
my ($cvar_where, @cvar_values) = CVar->build_filter_query('module' => 'CT',
'trans_id_field' => 'c.id',
'filter' => $form,
$query = qq|UPDATE ar SET paid = amount + paid, storno = 't' WHERE id = ?|;
do_query($form, $dbh, $query, $id);
+ $form->new_lastmtime('ar') if $id == $form->{id};
+
# now copy acc_trans entries
$query = qq|SELECT a.*, c.link FROM acc_trans a LEFT JOIN chart c ON a.chart_id = c.id WHERE a.trans_id = ? ORDER BY a.acc_trans_id|;
my $rowref = selectall_hashref_query($form, $dbh, $query, $id);