1 package SL::DB::Manager::Part;
 
   5 use SL::DB::Helpers::Manager;
 
   6 use base qw(SL::DB::Helpers::Manager);
 
  11 sub object_class { 'SL::DB::Part' }
 
  13 __PACKAGE__->make_manager_methods;
 
  17   my $type  = lc(shift || '');
 
  19   if ($type =~ m/^part/) {
 
  20     return (and => [ or                    => [ assembly => 0, assembly => undef ],
 
  21                      '!inventory_accno_id' => 0,
 
  22                      '!inventory_accno_id' => undef,
 
  25   } elsif ($type =~ m/^service/) {
 
  26     return (and => [ or => [ assembly           => 0, assembly           => undef ],
 
  27                      or => [ inventory_accno_id => 0, inventory_accno_id => undef ],
 
  30   } elsif ($type =~ m/^assembl/) {
 
  31     return (assembly => 1);
 
  42   return () unless @part_ids;
 
  44   my $placeholders = join ',', ('?') x @part_ids;
 
  46     SELECT oi.parts_id, SUM(oi.base_qty) AS qty
 
  48     LEFT JOIN oe ON (oi.trans_id = oe.id)
 
  49     WHERE (oi.parts_id IN ($placeholders))
 
  50       AND (NOT COALESCE(oe.quotation, FALSE))
 
  51       AND (NOT COALESCE(oe.closed,    FALSE))
 
  52       AND (NOT COALESCE(oe.delivered, FALSE))
 
  53       AND (COALESCE(oe.vendor_id, 0) <> 0)
 
  57   my %qty_by_id = map { $_->{parts_id} => $_->{qty} * 1 } @{ selectall_hashref_query($::form, $class->object_class->init_db->dbh, $query, @part_ids) };
 
  58   map { $qty_by_id{$_} ||= 0 } @part_ids;