- };
-
-
- $main::lxdebug->leave_sub();
-
- return @{ $form->{parts} };
-}
-
-sub _create_filter_for_priceupdate {
- $main::lxdebug->enter_sub();
-
- my $self = shift;
- my $myconfig = \%main::myconfig;
- my $form = $main::form;
-
- my @where_values;
- my $where = '1 = 1';
-
- foreach my $item (qw(partnumber drawing microfiche make model pg.partsgroup)) {
- my $column = $item;
- $column =~ s/.*\.//;
- next unless ($form->{$column});
-
- $where .= qq| AND $item ILIKE ?|;
- push(@where_values, like($form->{$column}));
- }
-
- foreach my $item (qw(description serialnumber)) {
- next unless ($form->{$item});
-
- $where .= qq| AND (${item} ILIKE ?)|;
- push(@where_values, like($form->{$item}));
- }
-
-
- # items which were never bought, sold or on an order
- if ($form->{itemstatus} eq 'orphaned') {
- $where .=
- qq| AND (p.onhand = 0)
- AND p.id NOT IN
- (
- SELECT DISTINCT parts_id FROM invoice
- UNION
- SELECT DISTINCT parts_id FROM assembly
- UNION
- SELECT DISTINCT parts_id FROM orderitems
- )|;
-
- } elsif ($form->{itemstatus} eq 'active') {
- $where .= qq| AND p.obsolete = '0'|;
-
- } elsif ($form->{itemstatus} eq 'obsolete') {
- $where .= qq| AND p.obsolete = '1'|;
-
- } elsif ($form->{itemstatus} eq 'onhand') {
- $where .= qq| AND p.onhand > 0|;
-
- } elsif ($form->{itemstatus} eq 'short') {
- $where .= qq| AND p.onhand < p.rop|;
-
- }
-
- 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, like($form->{$column}));
- }
-
- $main::lxdebug->leave_sub();
-
- return ($where, @where_values);
-}
-
-sub get_num_matches_for_priceupdate {
- $main::lxdebug->enter_sub();
-
- my $self = shift;
-
- my $myconfig = \%main::myconfig;
- my $form = $main::form;
-
- my $dbh = $form->get_standard_dbh($myconfig);
-
- my ($where, @where_values) = $self->_create_filter_for_priceupdate();
-
- my $num_updated = 0;
- my $query;
-
- for my $column (qw(sellprice listprice)) {
- next if ($form->{$column} eq "");
-
- $query =
- qq|SELECT COUNT(*)
- FROM parts
- WHERE id IN
- (SELECT p.id
- FROM parts p
- LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
- WHERE $where)|;
- my ($result) = selectfirst_array_query($form, $dbh, $query, @where_values);
- $num_updated += $result if (0 <= $result);