$form->{taxaccount} = "";
while ($ptr = $stw->fetchrow_hashref(NAME_lc)) {
$form->{taxaccount} .= "$ptr->{accno} ";
- if (!($form->{taxaccount2} =~ /$ptr->{accno}/)) {
+ if (!($form->{taxaccount2} =~ /\Q$ptr->{accno}\E/)) {
$form->{"$ptr->{accno}_rate"} = $ptr->{rate};
$form->{"$ptr->{accno}_description"} = $ptr->{description};
$form->{"$ptr->{accno}_taxnumber"} = $ptr->{taxnumber};
$form->{parts} = +{ };
- my @simple_filters = qw(partnumber ean description partsgroup microfiche drawing);
+ my @simple_filters = qw(partnumber ean description partsgroup microfiche drawing onhand);
my @makemodel_filters = qw(make model);
my @invoice_oi_filters = qw(serialnumber soldtotal);
my @apoe_filters = qw(transdate);
}
}
+ my %simple_filter_table_prefix = (
+ description => 'p.',
+ );
+
foreach (@simple_filters, @makemodel_filters, @invoice_oi_filters) {
next unless $form->{$_};
$form->{"l_$_"} = '1'; # show the column
- push @where_tokens, "$_ ILIKE ?";
+ push @where_tokens, "$simple_filter_table_prefix{$_}$_ ILIKE ?";
push @bind_vars, "%$form->{$_}%";
}
my @sort_cols = (@simple_filters, qw(id bin priceupdate onhand invnumber ordnumber quonumber name serialnumber soldtotal deliverydate));
$form->{sort} = 'id' unless grep { $form->{"l_$_"} } grep { $form->{sort} eq $_ } @sort_cols;
- my $order_clause = " ORDER BY $form->{sort} " . ($form->{revers} ? 'DESC' : 'ASC');
+
+ my $sort_order = ($form->{revers} ? ' DESC' : ' ASC');
+
+ # special case: sorting by partnumber
+ # since partnumbers are expected to be prefixed integers, a special sorting is implemented sorting first lexically by prefix and then by suffix.
+ # and yes, that expression is designed to hold that array of regexes only once, so the map is kinda messy, sorry about that.
+ # ToDO: implement proper functional sorting
+ $form->{sort} = join ', ', map { push @select_tokens, $_; ($table_prefix{$_} = "substring(partnumber,'[") . $_ } qw|^[:digit:]]+') [:digit:]]+')::INTEGER|
+ if $form->{sort} eq 'partnumber';
+
+ my $order_clause = " ORDER BY $form->{sort} $sort_order";
my $limit_clause = " LIMIT 100" if $form->{top100};
#============= build query ================#
- my %table_prefix = (
+ %table_prefix = (
+ %table_prefix,
deliverydate => 'apoe.', serialnumber => 'ioi.',
transdate => 'apoe.', trans_id => 'ioi.',
module => 'apoe.', name => 'cv.',
my $group;
my $limit;
- my @where_values;
-
if ($item ne 'make') {
foreach my $item (qw(partnumber drawing microfiche make model pg.partsgroup)) {
my $column = $item;
my $sth = prepare_execute_query($form, $dbh, $query, @values);
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
foreach my $key (split(/:/, $ref->{link})) {
- if ($key =~ /$module/) {
+ if ($key =~ /\Q$module\E/) {
if ( ($ref->{id} eq $ref->{inventory_accno_id})
|| ($ref->{id} eq $ref->{income_accno_id})
|| ($ref->{id} eq $ref->{expense_accno_id})) {
$query =
qq|SELECT l.id, l.description, tr.translation, tr.longdescription
FROM language l
- LEFT OUTER JOIN translation tr ON (tr.language_id = l.id) AND (tr.parts_id = ?)|;
+ LEFT OUTER JOIN translation tr ON (tr.language_id = l.id) AND (tr.parts_id = ?)
+ ORDER BY lower(l.description)|;
@values = (conv_i($form->{id}));
} else {
- $query = qq|SELECT id, description FROM language|;
+ $query = qq|SELECT id, description
+ FROM language
+ ORDER BY lower(description)|;
}
my $languages = selectall_hashref_query($form, $dbh, $query, @values);