X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/859394a5b4389f497ce493d11d29882ef66f2e47..9589ecd776677cdeb2fbaf8de211963d24cf5aa1:/SL/DB/Manager/PriceRule.pm diff --git a/SL/DB/Manager/PriceRule.pm b/SL/DB/Manager/PriceRule.pm new file mode 100644 index 000000000..09e588b88 --- /dev/null +++ b/SL/DB/Manager/PriceRule.pm @@ -0,0 +1,63 @@ +# This file as been auto-generated only because it didn't exist. +# Feel free to modify it at will; it will not be overwritten automatically. + +package SL::DB::Manager::PriceRule; + +use strict; + +use parent qw(SL::DB::Helper::Manager); + +use SL::DB::Helper::Filtered; +use SL::DB::Helper::Paginated; +use SL::DB::Helper::Sorted; +use SL::DBUtils; + +use SL::Locale::String qw(t8); + +sub object_class { 'SL::DB::PriceRule' } + +__PACKAGE__->make_manager_methods; + +sub get_matching_filter { + my ($class, %params) = @_; + + die 'need record' unless $params{record}; + die 'need record_item' unless $params{record_item}; + + 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; + + # 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); + + $self->get_all(query => [ id => \@ids ]); +} + +sub _sort_spec { + return ( columns => { SIMPLE => 'ALL', }, + default => [ 'name', 1 ], + nulls => { price => 'LAST', discount => 'LAST' } + ); +} + +1;