push(@values, $form->{vendor_id});
} elsif ($form->{vendor}) {
$where .= " AND v.name ILIKE ?";
- push(@values, $form->like($form->{vendor}));
+ push(@values, like($form->{vendor}));
}
if ($form->{"cp_name"}) {
$where .= " AND (cp.cp_name ILIKE ? OR cp.cp_givenname ILIKE ?)";
}
if ($form->{invnumber}) {
$where .= " AND a.invnumber ILIKE ?";
- push(@values, $form->like($form->{invnumber}));
+ push(@values, like($form->{invnumber}));
}
if ($form->{ordnumber}) {
$where .= " AND a.ordnumber ILIKE ?";
- push(@values, $form->like($form->{ordnumber}));
+ push(@values, like($form->{ordnumber}));
}
if ($form->{notes}) {
$where .= " AND lower(a.notes) LIKE ?";
- push(@values, $form->like($form->{notes}));
+ push(@values, like($form->{notes}));
}
if ($form->{project_id}) {
$where .=
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 ?)";
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"}) {
push(@values, conv_i($form->{"${vc}_id"}));
} elsif ($form->{ $vc }) {
$query .= " AND vc.name ILIKE ?";
- push(@values, $form->like($form->{ $vc }));
+ push(@values, like($form->{ $vc }));
}
foreach my $column (qw(invnumber ordnumber quonumber donumber)) {
if ($form->{$column}) {
$query .= " AND a.$column ILIKE ?";
- push(@values, $form->like($form->{$column}));
+ push(@values, like($form->{$column}));
}
}
our @ISA = qw(Exporter);
our @EXPORT = qw(conv_i conv_date conv_dateq do_query selectrow_query do_statement
- dump_query quote_db_date
+ dump_query quote_db_date like
selectfirst_hashref_query selectfirst_array_query
selectall_hashref_query selectall_array_query
selectall_as_map
return ($token, @vals);
}
+sub like {
+ my ($string) = @_;
+
+ return "%" . SL::Util::trim($string // '') . "%";
+}
+
1;
Treats STR as a database date, quoting it. If STR equals current_date returns an escaped version which is treated as the current date by Postgres.
Returns 'NULL' if STR is empty.
+=item like STR
+
+Turns C<STR> into an argument suitable for SQL's C<LIKE> and C<ILIKE>
+operators by Trimming the string C<STR> (removes leading and trailing
+whitespaces) and prepending and appending C<%>.
+
=back
=head2 QUERY FUNCTIONS
return $thisdate;
}
-sub like {
- my ($self, $string) = @_;
-
- return "%" . SL::Util::trim($string // '') . "%";
-}
-
sub redo_rows {
$main::lxdebug->enter_sub();
$glwhere .= qq| AND g.reference ILIKE ?|;
$arwhere .= qq| AND a.invnumber ILIKE ?|;
$apwhere .= qq| AND a.invnumber ILIKE ?|;
- push(@glvalues, $::form->like($form->{reference}));
- push(@arvalues, $::form->like($form->{reference}));
- push(@apvalues, $::form->like($form->{reference}));
+ push(@glvalues, like($form->{reference}));
+ push(@arvalues, like($form->{reference}));
+ push(@apvalues, like($form->{reference}));
}
if ($form->{department}) {
$glwhere .= " AND ac.trans_id IN (SELECT trans_id from acc_trans WHERE source ILIKE ?)";
$arwhere .= " AND ac.trans_id IN (SELECT trans_id from acc_trans WHERE source ILIKE ?)";
$apwhere .= " AND ac.trans_id IN (SELECT trans_id from acc_trans WHERE source ILIKE ?)";
- push(@glvalues, $::form->like($form->{source}));
- push(@arvalues, $::form->like($form->{source}));
- push(@apvalues, $::form->like($form->{source}));
+ push(@glvalues, like($form->{source}));
+ push(@arvalues, like($form->{source}));
+ push(@apvalues, like($form->{source}));
}
# default Datumseinschränkung falls nicht oder falsch übergeben (sollte nie passieren)
$glwhere .= " AND g.description ILIKE ?";
$arwhere .= " AND ct.name ILIKE ?";
$apwhere .= " AND ct.name ILIKE ?";
- push(@glvalues, $::form->like($form->{description}));
- push(@arvalues, $::form->like($form->{description}));
- push(@apvalues, $::form->like($form->{description}));
+ push(@glvalues, like($form->{description}));
+ push(@arvalues, like($form->{description}));
+ push(@apvalues, like($form->{description}));
}
if ($form->{employee_id}) {
$glwhere .= " AND g.notes ILIKE ?";
$arwhere .= " AND a.notes ILIKE ?";
$apwhere .= " AND a.notes ILIKE ?";
- push(@glvalues, $::form->like($form->{notes}));
- push(@arvalues, $::form->like($form->{notes}));
- push(@apvalues, $::form->like($form->{notes}));
+ push(@glvalues, like($form->{notes}));
+ push(@arvalues, like($form->{notes}));
+ push(@apvalues, like($form->{notes}));
}
if ($form->{accno}) {
if ($form->{partnumber}) {
$where .= qq| AND (p.partnumber ILIKE ?)|;
- push(@values, $::form->like($form->{partnumber}));
+ push(@values, like($form->{partnumber}));
}
if ($form->{description}) {
$where .= qq| AND (p.description ILIKE ?)|;
- push(@values, $::form->like($form->{description}));
+ push(@values, like($form->{description}));
}
# retrieve assembly items
while (my ($column, $table) = each(%columns)) {
next unless ($form->{"${column}_$i"});
$where .= qq| AND ${table}.${column} ILIKE ?|;
- push(@values, $::form->like($form->{"${column}_$i"}));
+ push(@values, like($form->{"${column}_$i"}));
}
if ($form->{id}) {
next unless $form->{$_};
$form->{"l_$_"} = '1'; # show the column
push @where_tokens, "$table_prefix{$_}$_ ILIKE ?";
- push @bind_vars, $::form->like($form->{$_});
+ push @bind_vars, like($form->{$_});
}
foreach (@simple_l_switches) {
# fortunately makemodel doesn't need to be displayed later, so adding a special clause to where_token is sufficient.
if ($form->{make}) {
push @where_tokens, 'mv.name ILIKE ?';
- push @bind_vars, $::form->like($form->{make});
+ push @bind_vars, like($form->{make});
}
if ($form->{model}) {
push @where_tokens, 'mm.model ILIKE ?';
- push @bind_vars, $::form->like($form->{model});
+ push @bind_vars, like($form->{model});
}
# special case: sorting by partnumber
next unless ($form->{$column});
$where .= qq| AND $item ILIKE ?|;
- push(@where_values, $::form->like($form->{$column}));
+ push(@where_values, like($form->{$column}));
}
foreach my $item (qw(description serialnumber)) {
next unless ($form->{$item});
$where .= qq| AND (${item} ILIKE ?)|;
- push(@where_values, $::form->like($form->{$item}));
+ push(@where_values, like($form->{$item}));
}
foreach my $column (qw(make model)) {
next unless ($form->{$column});
$where .= qq| AND p.id IN (SELECT DISTINCT parts_id FROM makemodel WHERE $column ILIKE ?|;
- push(@where_values, $::form->like($form->{$column}));
+ push(@where_values, like($form->{$column}));
}
$main::lxdebug->leave_sub();
if ($sortorder eq "all") {
$where .= qq| AND (partnumber ILIKE ?) AND (description ILIKE ?)|;
- push(@values, $::form->like($form->{partnumber}), $::form->like($form->{description}));
+ push(@values, like($form->{partnumber}), like($form->{description}));
} elsif ($sortorder eq "partnumber") {
$where .= qq| AND (partnumber ILIKE ?)|;
- push(@values, $::form->like($form->{partnumber}));
+ push(@values, like($form->{partnumber}));
} elsif ($sortorder eq "description") {
$where .= qq| AND (description ILIKE ?)|;
- push(@values, $::form->like($form->{description}));
+ push(@values, like($form->{description}));
$order = "description";
}
if ($form->{$ct_id}) {
$where .= qq| AND (ct.id = | . conv_i($form->{$ct_id}) . qq|)|;
} elsif ($form->{ $form->{ct} }) {
- $where .= qq| AND (ct.name ILIKE | . $dbh->quote($::form->like($form->{$ct})) . qq|)|;
+ $where .= qq| AND (ct.name ILIKE | . $dbh->quote(like($form->{$ct})) . qq|)|;
}
my $dpt_join;
push(@values, $form->{customer_id});
} elsif ($form->{customer}) {
$where .= " AND ct.name ILIKE ?";
- push(@values, $form->like($form->{customer}));
+ push(@values, like($form->{customer}));
}
if ($form->{customernumber}) {
$where .= qq| AND ct.customernumber = ? |;
if ($filter{partnumber}) {
push @filter_ary, "p.partnumber ILIKE ?";
- push @filter_vars, $::form->like($filter{partnumber});
+ push @filter_vars, like($filter{partnumber});
}
if ($filter{description}) {
push @filter_ary, "(p.description ILIKE ?)";
- push @filter_vars, $::form->like($filter{description});
+ push @filter_vars, like($filter{description});
}
if ($filter{chargenumber}) {
push @filter_ary, "i1.chargenumber ILIKE ?";
- push @filter_vars, $::form->like($filter{chargenumber});
+ push @filter_vars, like($filter{chargenumber});
}
if (trim($form->{bestbefore})) {
if ($filter{partnumber}) {
push @filter_ary, "p.partnumber ILIKE ?";
- push @filter_vars, $::form->like($filter{partnumber});
+ push @filter_vars, like($filter{partnumber});
}
if ($filter{description}) {
push @filter_ary, "p.description ILIKE ?";
- push @filter_vars, $::form->like($filter{description});
+ push @filter_vars, like($filter{description});
}
if ($filter{partsid}) {
if ($filter{chargenumber}) {
push @filter_ary, "i.chargenumber ILIKE ?";
- push @filter_vars, $::form->like($filter{chargenumber});
+ push @filter_vars, like($filter{chargenumber});
}
if (trim($form->{bestbefore})) {
if ($filter{ean}) {
push @filter_ary, "p.ean ILIKE ?";
- push @filter_vars, $::form->like($filter{ean});
+ push @filter_vars, like($filter{ean});
}
if (trim($filter{date})) {
if ( $::form->{filter_partnumber} ) {
$where .= ' AND partnumber ILIKE ?';
- push(@values, $::form->like( $::form->{filter_partnumber} ));
+ push(@values, like( $::form->{filter_partnumber} ));
}
if ($::form->{filter_description}) {
$where .= ' AND description ILIKE ?';
- push(@values, $::form->like($::form->{filter_description}));
+ push(@values, like($::form->{filter_description}));
}
if ($::form->{filter_notes}) {
$where .= ' AND notes ILIKE ?';
- push(@values, $::form->like($::form->{filter_notes}));
+ push(@values, like($::form->{filter_notes}));
}
if ($::form->{filter_ean}) {
$where .= ' AND ean ILIKE ?';
- push(@values, $::form->like($::form->{filter_ean}));
+ push(@values, like($::form->{filter_ean}));
}
if ($::form->{filter_type} eq 'assembly') {