X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FManager%2FPriceRule.pm;h=974011a55d4fd023415e58fdde92ab4b260d70a1;hb=0d12df6dc721dcdbc81ca8db667cd644393bc5fc;hp=09e588b8802b93d3315812c046b7bff7dfc70389;hpb=9589ecd776677cdeb2fbaf8de211963d24cf5aa1;p=kivitendo-erp.git diff --git a/SL/DB/Manager/PriceRule.pm b/SL/DB/Manager/PriceRule.pm index 09e588b88..974011a55 100644 --- a/SL/DB/Manager/PriceRule.pm +++ b/SL/DB/Manager/PriceRule.pm @@ -7,6 +7,10 @@ use strict; use parent qw(SL::DB::Helper::Manager); +use constant PRICE_NEW => 0; +use constant PRICE_REDUCED_MASTER_DATA => 1; +use constant PRICE_DISCOUNT => 2; + use SL::DB::Helper::Filtered; use SL::DB::Helper::Paginated; use SL::DB::Helper::Sorted; @@ -17,6 +21,28 @@ use SL::Locale::String qw(t8); sub object_class { 'SL::DB::PriceRule' } __PACKAGE__->make_manager_methods; +__PACKAGE__->add_filter_specs( + has_item_type => sub { + my ($key, $values, $prefix) = @_; + return unless @$values; + + my $each_type = "SELECT DISTINCT price_rules_id FROM price_rule_items WHERE type = %s"; + my $sub_query = join ' INTERSECT ', map { sprintf $each_type, $::form->get_standard_dbh->quote($_) } @$values; + return or => [ ${prefix} . 'id' => [ \$sub_query ] ]; + }, + item_type_matches => sub { + my ($key, $values, $prefix) = @_; + return unless @$values; + return unless 'HASH' eq ref $values->[0]; + return unless grep $_, values %{ $values->[0] }; + + my $each_type = "SELECT DISTINCT price_rules_id FROM price_rule_items WHERE type = %s AND (%s)"; + my $sub_query = join ' INTERSECT ', map { + sprintf $each_type, $::form->get_standard_dbh->quote($_), SL::DB::Manager::PriceRuleItem->filter_match($_, $values->[0]{$_}) + } grep { $values->[0]{$_} } keys %{ $values->[0] }; + return or => [ ${prefix} . 'id' => [ \$sub_query ] ]; + }, +); sub get_matching_filter { my ($class, %params) = @_; @@ -27,8 +53,7 @@ sub get_matching_filter { my $type = $params{record}->is_sales ? 'customer' : 'vendor'; # plan: 1. search all rule_items that do NOT match this record/record item combo - my ($sub_where, @value_subs) = SL::DB::Manager::PriceRuleItem->not_matching_sql_and_values(type => $type); - my @values = map { $_->($params{record}, $params{record_item}) } @value_subs; + my ($sub_where, @values) = SL::DB::Manager::PriceRuleItem->not_matching_sql_and_values(type => $type, %params); # now union all NOT matching, invert ids, load these my $matching_rule_ids = <get_matching_filter(%params); - my @ids = selectall_ids($::form, $::form->get_standard_dbh, $query, 0, @values); + my @ids = selectcol_array_query($::form, SL::DB->client->dbh, $query, @values); + return [] unless @ids; $self->get_all(query => [ id => \@ids ]); } +sub all_price_types { + [ PRICE_NEW, t8('Price') ], + [ PRICE_REDUCED_MASTER_DATA, t8('Reduced Master Data') ], + [ PRICE_DISCOUNT, t8('Discount') ], +} + sub _sort_spec { return ( columns => { SIMPLE => 'ALL', }, default => [ 'name', 1 ],