+ push @bind_vars, $value;
+ }
+ }
+
+ # special case smart search
+ if ($form->{all}) {
+ $form->{"l_$_"} = 1 for qw(partnumber description unit sellprice lastcost cvar_packaging linetotal);
+ push @where_tokens, "p.partnumber ILIKE ? OR p.description ILIKE ?";
+ push @bind_vars, (like($form->{all})) x 2;
+ }
+
+ # special case insertdate
+ if (grep { trim($form->{$_}) } qw(insertdatefrom insertdateto)) {
+ $form->{"l_insertdate"} = 1;
+ push @select_tokens, 'insertdate';
+
+ my $token_builder = $make_token_builder->();
+ my $token = $token_builder->('insertdate');
+
+ for (qw(insertdatefrom insertdateto)) {
+ my $value = trim($form->{$_});
+ next unless $value;
+ push @where_tokens, sprintf "$token %s ?", /from$/ ? '>=' : '<=';
+ push @bind_vars, $value;
+ }
+ }
+
+ if ($form->{"partsgroup_id"}) {
+ $form->{"l_partsgroup"} = '1'; # show the column
+ push @where_tokens, "pg.id = ?";
+ push @bind_vars, $form->{"partsgroup_id"};
+ }
+
+ if ($form->{shop} ne '') {
+ $form->{l_shop} = '1'; # show the column
+ if ($form->{shop} eq '0' || $form->{shop} eq 'f') {
+ push @where_tokens, 'NOT p.shop';
+ $form->{shop} = 'f';
+ } else {
+ push @where_tokens, 'p.shop';