From: Sven Schöling Date: Tue, 7 Oct 2014 12:29:43 +0000 (+0200) Subject: PriceRule: Mehr Filteroptionen X-Git-Tag: release-3.2.0beta~129 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=986282c191d6ad3c02608b2fd33d66a12779e401;p=kivitendo-erp.git PriceRule: Mehr Filteroptionen --- diff --git a/SL/Controller/PriceRule.pm b/SL/Controller/PriceRule.pm index 3d7a75e27..60870e2ad 100644 --- a/SL/Controller/PriceRule.pm +++ b/SL/Controller/PriceRule.pm @@ -197,11 +197,17 @@ sub make_filter_summary { push @filter_strings, "$_->[1]: $_->[0]" if $_->[0]; } + if ($filter->{has_item_type}) { + push @filter_strings, sprintf "%s: %s", t8('Has item type'), join ', ', map { + SL::DB::Manager::PriceRuleItem->get_type($_)->{description} + } @{ $filter->{has_item_type} || [] }; + } + $self->{filter_summary} = join ', ', @filter_strings; } sub all_price_rule_item_types { - SL::DB::Manager::PriceRuleItem->get_all_types($_[0]->price_rule->type); + SL::DB::Manager::PriceRuleItem->get_all_types($_[0]->vc || $_[0]->price_rule->type); } sub add_javascripts { diff --git a/SL/DB/Manager/PriceRule.pm b/SL/DB/Manager/PriceRule.pm index e94fd1546..99065dbb5 100644 --- a/SL/DB/Manager/PriceRule.pm +++ b/SL/DB/Manager/PriceRule.pm @@ -17,6 +17,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) = @_; diff --git a/SL/DB/Manager/PriceRuleItem.pm b/SL/DB/Manager/PriceRuleItem.pm index 2d3e9cfe9..f45db3d4e 100644 --- a/SL/DB/Manager/PriceRuleItem.pm +++ b/SL/DB/Manager/PriceRuleItem.pm @@ -78,4 +78,34 @@ sub get_all_types { [ map { [ $_, $types{$_}{description} ] } grep { $types{$_}{$vc} } map { $_ } @types ]; } +sub get_type { + $types{$_[1]} +} + +sub filter_match { + my ($self, $type, $value) = @_; + + my $type_def = $types{$type}; + + if (!$type_def->{ops}) { + my $evalue = $::form->get_standard_dbh->quote($value); + return "value_$type_def->{data_type} = $evalue"; + } elsif ($type_def->{ops} eq 'date') { + my $date_value = $::form->get_standard_dbh->quote(DateTime->from_kivitendo($value)); + return " + (value_$type_def->{data_type} > $date_value AND op = 'lt') OR + (value_$type_def->{data_type} < $date_value AND op = 'gt') OR + (value_$type_def->{data_type} = $date_value AND op = 'eq') + "; + } elsif ($type_def->{ops} eq 'num') { + my $num_value = $::form->get_standard_dbh->quote($::form->parse_amount(\%::myconfig, $value)); + return " + (value_$type_def->{data_type} >= $num_value AND op = 'le') OR + (value_$type_def->{data_type} <= $num_value AND op = 'ge') OR + (value_$type_def->{data_type} = $num_value AND op = 'eq') + "; + } +} + + 1; diff --git a/locale/de/all b/locale/de/all index c000ae6db..2a55bf466 100755 --- a/locale/de/all +++ b/locale/de/all @@ -1210,6 +1210,7 @@ $self->{texts} = { 'HTML Templates' => 'HTML-Vorlagen', 'Handling of WebDAV' => 'Behandlung von WebDAV', 'Hardcopy' => 'Seite drucken', + 'Has item type' => 'Hat Regeltypen', 'Has serial number' => 'Hat eine Serienummer', 'Heading' => 'Überschrift', 'Help Template Variables' => 'Hilfe zu Dokumenten-Variablen', diff --git a/templates/webpages/price_rule/_filter.html b/templates/webpages/price_rule/_filter.html index 1f499d35d..3dfc3b3e8 100644 --- a/templates/webpages/price_rule/_filter.html +++ b/templates/webpages/price_rule/_filter.html @@ -10,18 +10,58 @@