1 package SL::DB::Manager::Part;
 
   5 use SL::DB::Helper::Manager;
 
   6 use base qw(SL::DB::Helper::Manager);
 
  10 use SL::MoreCommon qw(listify);
 
  12 sub object_class { 'SL::DB::Part' }
 
  14 __PACKAGE__->make_manager_methods;
 
  17   my ($class, $type) = @_;
 
  19   return () unless $type;
 
  21   my @types = listify($type);
 
  24   for my $type (@types) {
 
  25     if ($type =~ m/^part/) {
 
  26       push @filter, (and => [ or                    => [ assembly => 0, assembly => undef ],
 
  27                        '!inventory_accno_id' => 0,
 
  28                        '!inventory_accno_id' => undef,
 
  30     } elsif ($type =~ m/^service/) {
 
  31       push @filter, (and => [ or => [ assembly           => 0, assembly           => undef ],
 
  32                        or => [ inventory_accno_id => 0, inventory_accno_id => undef ],
 
  34     } elsif ($type =~ m/^assembl/) {
 
  35       push @filter, (assembly => 1);
 
  39   return @filter ? (or => \@filter) : ();
 
  46   return () unless @part_ids;
 
  48   my $placeholders = join ',', ('?') x @part_ids;
 
  50     SELECT oi.parts_id, SUM(oi.base_qty) AS qty
 
  52     LEFT JOIN oe ON (oi.trans_id = oe.id)
 
  53     WHERE (oi.parts_id IN ($placeholders))
 
  54       AND (NOT COALESCE(oe.quotation, FALSE))
 
  55       AND (NOT COALESCE(oe.closed,    FALSE))
 
  56       AND (NOT COALESCE(oe.delivered, FALSE))
 
  57       AND (COALESCE(oe.vendor_id, 0) <> 0)
 
  61   my %qty_by_id = map { $_->{parts_id} => $_->{qty} * 1 } @{ selectall_hashref_query($::form, $class->object_class->init_db->dbh, $query, @part_ids) };
 
  62   map { $qty_by_id{$_} ||= 0 } @part_ids;
 
  76 SL::DB::Manager::Part - RDBO manager for the C<parts> table
 
  82 =item C<get_ordered_qty @part_ids>
 
  84 For each of the given part IDs the ordered quantity is
 
  85 calculated. This is done by summing over all open purchase orders.
 
  87 Returns a hash with the part IDs being the keys and the ordered
 
  88 quantities being the values.
 
  90 =item C<type_filter @types>
 
  92 Constructs a partial filter for matching any of the article types
 
  93 given with C<@types>. The returned partial filter is suitable for a
 
  96 Each type can be either 'C<part>', 'C<service>' or 'C<assembly>'
 
  97 (their plurals are recognized as well). If multiple types are given
 
  98 then they're combined with C<OR>.
 
 108 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>,
 
 109 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>