1 # This file has 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::PriceRuleItem;
8 use SL::DB::Helper::Manager;
9 use base qw(SL::DB::Helper::Manager);
11 sub object_class { 'SL::DB::PriceRuleItem' }
13 __PACKAGE__->make_manager_methods;
15 use SL::Locale::String qw(t8);
18 part customer vendor business partsgroup qty reqdate pricegroup
22 'num' => { eq => '=', le => '<=', ge => '>=' },
23 'date' => { eq => '=', lt => '<', gt => '>' },
27 'customer' => { description => t8('Customer'), customer => 1, vendor => 0, data_type => 'int', data => sub { $_[0]->customer->id }, },
28 'vendor' => { description => t8('Vendor'), customer => 0, vendor => 1, data_type => 'int', data => sub { $_[0]->vendor->id }, },
29 'business' => { description => t8('Type of Business'), customer => 1, vendor => 1, data_type => 'int', data => sub { $_[0]->customervendor->business_id }, exclude_nulls => 1 },
30 'reqdate' => { description => t8('Reqdate'), customer => 1, vendor => 1, data_type => 'date', data => sub { $_[0]->reqdate }, ops => 'date' },
31 'part' => { description => t8('Part'), customer => 1, vendor => 1, data_type => 'int', data => sub { $_[1]->part->id }, },
32 'pricegroup' => { description => t8('Pricegroup'), customer => 1, vendor => 1, data_type => 'int', data => sub { $_[1]->pricegroup_id }, exclude_nulls => 1 },
33 'partsgroup' => { description => t8('Group'), customer => 1, vendor => 1, data_type => 'int', data => sub { $_[1]->part->partsgroup_id }, exclude_nulls => 1 },
34 'qty' => { description => t8('Qty'), customer => 1, vendor => 1, data_type => 'num', data => sub { $_[1]->qty }, ops => 'num' },
37 sub not_matching_sql_and_values {
38 my ($class, %params) = @_;
40 die 'must be called with a customer/vendor type' unless $params{type};
41 my @args = @params{'record', 'record_item'};
43 my (@tokens, @values);
45 for my $type (@types) {
46 my $def = $types{$type};
47 next unless $def->{$params{type}};
49 my $value = $def->{data}->(@args);
51 if ($def->{exclude_nulls} && !defined $value) {
52 push @tokens, "type = '$type'";
56 my $ops = $ops{$def->{ops}};
59 push @sub_tokens, "op = '$_' AND NOT ? $ops->{$_} value_$def->{data_type}";
63 push @sub_tokens, "NOT value_$def->{data_type} = ?";
67 push @tokens, "type = '$type' AND " . join ' OR ', map "($_)", @sub_tokens;
71 return join(' OR ', map "($_)", @tokens), @values;
75 my ($class, $vc) = @_;
77 [ map { [ $_, $types{$_}{description} ] } grep { $types{$_}{$vc} } map { $_ } @types ];