"customernumber" => "ct.customernumber",
"vendornumber" => "ct.vendornumber",
"name" => "ct.name",
+ "department_1" => "ct.department_1",
+ "department_2" => "ct.department_2",
"contact" => "ct.contact",
"phone" => "ct.phone",
"fax" => "ct.fax",
"insertdate" => "ct.itime",
"salesman" => "e.name",
"payment" => "pt.description",
+ "taxzone" => "tz.description",
"pricegroup" => "pg.pricegroup",
"ustid" => "ct.ustid",
"creditlimit" => "ct.creditlimit",
"commercial_court" => "ct.commercial_court",
+ "dunning_lock" => "ct.dunning_lock",
);
$form->{sort} ||= "name";
}
my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC';
- if ($sortorder !~ /(business|creditlimit|id|discount|itime)/ && !$join_records) {
+ if ($sortorder !~ /(business|creditlimit|id|discount|itime|dunning_lock)/ && !$join_records) {
$sortorder = "lower($sortorder) ${sortdir}";
} else {
$sortorder .= " ${sortdir}";
push(@values, like($form->{"${cv}number"}));
}
- foreach my $key (qw(name contact email)) {
- if ($form->{$key}) {
+ foreach my $key (qw(name department_1 department_2 contact email)) {
+ if ($form->{$key} ne '') {
$where .= " AND ct.$key ILIKE ?";
push(@values, like($form->{$key}));
}
push(@values, conv_i($form->{salesman_id}));
}
+ if ($form->{payment_id}) {
+ $where .= qq| AND (ct.payment_id = ?)|;
+ push(@values, $form->{payment_id});
+ }
+
+ if ($form->{taxzone_id}) {
+ $where .= qq| AND (ct.taxzone_id = ?)|;
+ push(@values, $form->{taxzone_id});
+ }
+
if($form->{insertdatefrom}) {
$where .= qq| AND (ct.itime::DATE >= ?)|;
push@values, conv_date($form->{insertdatefrom});
push @values, conv_date($form->{insertdateto});
}
+ if($form->{dunning_lock} ne '') {
+ $where .= qq| AND ct.dunning_lock = ?|;
+ push @values, $form->{dunning_lock};
+ }
+
if ($form->{all}) {
my @tokens = parse_line('\s+', 0, $form->{all});
$where .= qq| AND (
}
my $query =
qq|SELECT ct.*, ct.itime::DATE AS insertdate, b.description AS business, e.name as salesman, | .
- qq| pt.description as payment | .
+ qq| pt.description as payment, tz.description as taxzone | .
$pg_select .
$main_cp_select .
(qq|, NULL AS invnumber, NULL AS ordnumber, NULL AS quonumber, NULL AS invid, NULL AS module, NULL AS formtype, NULL AS closed | x!! $join_records) .
qq|LEFT JOIN business b ON (ct.business_id = b.id) | .
qq|LEFT JOIN employee e ON (ct.salesman_id = e.id) | .
qq|LEFT JOIN payment_terms pt ON (ct.payment_id = pt.id) | .
+ qq|LEFT JOIN tax_zones tz ON (ct.taxzone_id = tz.id) | .
$pg_join .
qq|WHERE $where|;
$query .=
qq| UNION | .
qq|SELECT ct.*, ct.itime::DATE AS insertdate, b.description AS business, e.name as salesman, | .
- qq| pt.description as payment | .
+ qq| pt.description as payment, tz.description as taxzone | .
$pg_select .
$main_cp_select .
qq|, a.invnumber, a.ordnumber, a.quonumber, a.id AS invid, | .
qq|LEFT JOIN business b ON (ct.business_id = b.id) | .
qq|LEFT JOIN employee e ON (ct.salesman_id = e.id) | .
qq|LEFT JOIN payment_terms pt ON (ct.payment_id = pt.id) | .
+ qq|LEFT JOIN tax_zones tz ON (ct.taxzone_id = tz.id) | .
$pg_join .
qq|WHERE $where AND (a.invoice = '1')|;
}
$query .=
qq| UNION | .
qq|SELECT ct.*, ct.itime::DATE AS insertdate, b.description AS business, e.name as salesman, | .
- qq| pt.description as payment | .
+ qq| pt.description as payment, tz.description as taxzone | .
$pg_select .
$main_cp_select .
qq|, ' ' AS invnumber, o.ordnumber, o.quonumber, o.id AS invid, | .
qq|LEFT JOIN business b ON (ct.business_id = b.id) | .
qq|LEFT JOIN employee e ON (ct.salesman_id = e.id) | .
qq|LEFT JOIN payment_terms pt ON (ct.payment_id = pt.id) | .
+ qq|LEFT JOIN tax_zones tz ON (ct.taxzone_id = tz.id) | .
$pg_join .
- qq|WHERE $where AND (o.quotation = '0')|;
+ qq|WHERE $where AND ((o.record_type = 'sales_order') OR (o.record_type = 'purchase_order'))|;
}
if ( $form->{l_quonumber} ) {
$query .=
qq| UNION | .
qq|SELECT ct.*, ct.itime::DATE AS insertdate, b.description AS business, e.name as salesman, | .
- qq| pt.description as payment | .
+ qq| pt.description as payment, tz.description as taxzone | .
$pg_select .
$main_cp_select .
qq|, ' ' AS invnumber, o.ordnumber, o.quonumber, o.id AS invid, | .
qq|LEFT JOIN business b ON (ct.business_id = b.id) | .
qq|LEFT JOIN employee e ON (ct.salesman_id = e.id) | .
qq|LEFT JOIN payment_terms pt ON (ct.payment_id = pt.id) | .
+ qq|LEFT JOIN tax_zones tz ON (ct.taxzone_id = tz.id) | .
$pg_join .
- qq|WHERE $where AND (o.quotation = '1')|;
+ qq|WHERE $where AND ((o.record_type = 'sales_quotation') OR (o.record_type = 'request_quotation'))|;
}
}