X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FManager%2FPart.pm;h=b46f851cf2166cc142d6d17e082a88bbda47d740;hb=332e327b6613bf762b34d841442378de255d946b;hp=50219cb61d596470259fc7e779fad1d0c09c1fd0;hpb=60009b978dd3d0a84e5fbd8d56330618f7016b39;p=kivitendo-erp.git diff --git a/SL/DB/Manager/Part.pm b/SL/DB/Manager/Part.pm index 50219cb61..b46f851cf 100644 --- a/SL/DB/Manager/Part.pm +++ b/SL/DB/Manager/Part.pm @@ -3,6 +3,9 @@ package SL::DB::Manager::Part; use strict; use SL::DB::Helper::Manager; +use SL::DB::Helper::Sorted; +use SL::DB::Helper::Paginated; +use SL::DB::Helper::Filtered; use base qw(SL::DB::Helper::Manager); use Carp; @@ -12,31 +15,55 @@ use SL::MoreCommon qw(listify); sub object_class { 'SL::DB::Part' } __PACKAGE__->make_manager_methods; +__PACKAGE__->add_filter_specs( + part_type => sub { + my ($key, $value, $prefix) = @_; + return __PACKAGE__->type_filter($value, $prefix); + }, + all => sub { + my ($key, $value, $prefix) = @_; + return or => [ map { $prefix . $_ => $value } qw(partnumber description ean) ] + }, + all_with_makemodel => sub { + my ($key, $value, $prefix) = @_; + return or => [ map { $prefix . $_ => $value } qw(partnumber description ean makemodels.model) ], + $prefix . 'makemodels'; + }, + all_with_customer_partnumber => sub { + my ($key, $value, $prefix) = @_; + return or => [ map { $prefix . $_ => $value } qw(partnumber description ean customerprices.customer_partnumber) ], + $prefix . 'customerprices'; + }, +); sub type_filter { - my ($class, $type) = @_; + my ($class, $type, $prefix) = @_; return () unless $type; - my @types = listify($type); + $prefix //= ''; + + # this is to make selections like part_type => { part => 1, service => 1 } work + if ('HASH' eq ref $type) { + $type = [ grep { $type->{$_} } keys %$type ]; + } + + my @types = grep { $_ } listify($type); my @filter; for my $type (@types) { if ($type =~ m/^part/) { - push @filter, (and => [ or => [ assembly => 0, assembly => undef ], - '!inventory_accno_id' => 0, - '!inventory_accno_id' => undef, - ]); + push @filter, ($prefix . part_type => 'part'); } elsif ($type =~ m/^service/) { - push @filter, (and => [ or => [ assembly => 0, assembly => undef ], - or => [ inventory_accno_id => 0, inventory_accno_id => undef ], - ]); - } elsif ($type =~ m/^assembl/) { - push @filter, (assembly => 1); + push @filter, ($prefix . part_type => 'service'); + } elsif ($type =~ m/^assembly/) { + push @filter, ($prefix . part_type => 'assembly'); + } elsif ($type =~ m/^assortment/) { + push @filter, ($prefix . part_type => 'assortment'); } } - return @filter ? (or => \@filter) : (); + return @filter > 2 ? (or => \@filter) : @filter; } sub get_ordered_qty { @@ -64,4 +91,58 @@ SQL return %qty_by_id; } +sub _sort_spec { + ( + default => [ 'partnumber', 1 ], + columns => { + SIMPLE => 'ALL', + }, + nulls => {}, + ); +} + 1; +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::DB::Manager::Part - RDBO manager for the C table + +=head1 FUNCTIONS + +=over 4 + +=item C + +For each of the given part IDs the ordered quantity is +calculated. This is done by summing over all open purchase orders. + +Returns a hash with the part IDs being the keys and the ordered +quantities being the values. + +=item C + +Constructs a partial filter for matching any of the article types +given with C<@types>. The returned partial filter is suitable for a +Rose manager query. + +Each type can be either 'C', 'C' or 'C' +(their plurals are recognized as well). If multiple types are given +then they're combined with C. + +=back + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Sven Schöling Es.schoeling@linet-services.deE, +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut