1 # This file as been auto-generated only because it didn't exist.
 
   2 # Feel free to modify it at will; it will not be overwritten automatically.
 
   4 package SL::DB::Manager::PriceRule;
 
   8 use parent qw(SL::DB::Helper::Manager);
 
  10 use SL::DB::Helper::Filtered;
 
  11 use SL::DB::Helper::Paginated;
 
  12 use SL::DB::Helper::Sorted;
 
  15 use SL::Locale::String qw(t8);
 
  17 sub object_class { 'SL::DB::PriceRule' }
 
  19 __PACKAGE__->make_manager_methods;
 
  21 sub get_matching_filter {
 
  22   my ($class, %params) = @_;
 
  24   die 'need record'      unless $params{record};
 
  25   die 'need record_item' unless $params{record_item};
 
  27   my $type = $params{record}->is_sales ? 'customer' : 'vendor';
 
  29   # plan: 1. search all rule_items that do NOT match this record/record item combo
 
  30   my ($sub_where, @values) = SL::DB::Manager::PriceRuleItem->not_matching_sql_and_values(type => $type, %params);
 
  32   # now union all NOT matching, invert ids, load these
 
  33   my $matching_rule_ids = <<SQL;
 
  34     SELECT id FROM price_rules
 
  36       SELECT price_rules_id FROM price_rule_items WHERE $sub_where
 
  38     AND type = ? AND NOT obsolete
 
  43   return $matching_rule_ids, @values;
 
  46 sub get_all_matching {
 
  47   my ($self, %params) = @_;
 
  49   my ($query, @values) = $self->get_matching_filter(%params);
 
  50   my @ids = selectall_ids($::form, $::form->get_standard_dbh, $query, 0, @values);
 
  52   return [] unless @ids;
 
  54   $self->get_all(query => [ id => \@ids ]);
 
  58   return ( columns => { SIMPLE => 'ALL', },
 
  59            default => [ 'name', 1 ],
 
  60            nulls   => { price => 'LAST', discount => 'LAST'  }