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 transdate 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 'transdate' => { description => t8('Transdate'), customer => 1, vendor => 1, data_type => 'date', data => sub { $_[0]->transdate }, ops => 'date' },
32 'part' => { description => t8('Part'), customer => 1, vendor => 1, data_type => 'int', data => sub { $_[1]->part->id }, },
33 'pricegroup' => { description => t8('Pricegroup'), customer => 1, vendor => 1, data_type => 'int', data => sub { $_[1]->pricegroup_id }, exclude_nulls => 1 },
34 'partsgroup' => { description => t8('Partsgroup'), customer => 1, vendor => 1, data_type => 'int', data => sub { $_[1]->part->partsgroup_id }, exclude_nulls => 1 },
35 'qty' => { description => t8('Qty'), customer => 1, vendor => 1, data_type => 'num', data => sub { $_[1]->qty }, ops => 'num' },
38 sub not_matching_sql_and_values {
39 my ($class, %params) = @_;
41 die 'must be called with a customer/vendor type' unless $params{type};
42 my @args = @params{'record', 'record_item'};
44 my (@tokens, @values);
46 for my $type (@types) {
47 my $def = $types{$type};
48 next unless $def->{$params{type}};
50 my $value = $def->{data}->(@args);
52 if ($def->{exclude_nulls} && !defined $value) {
53 push @tokens, "type = '$type'";
57 my $ops = $ops{$def->{ops}};
60 push @sub_tokens, "op = '$_' AND NOT ? $ops->{$_} value_$def->{data_type}";
64 push @sub_tokens, "NOT value_$def->{data_type} = ?";
68 push @tokens, "type = '$type' AND (@{[ join(' OR ', map qq|($_)|, @sub_tokens) ]})";
72 return join(' OR ', map "($_)", @tokens), @values;
76 my ($class, $vc) = @_;
79 ? [ map { [ $_, $types{$_}{description} ] } grep { $types{$_}{$vc} } map { $_ } @types ]
80 : [ map { [ $_, $types{$_}{description} ] } map { $_ } @types ]
88 my ($self, $type, $value) = @_;
90 my $type_def = $types{$type};
92 if (!$type_def->{ops}) {
93 my $evalue = $::form->get_standard_dbh->quote($value);
94 return "value_$type_def->{data_type} = $evalue";
95 } elsif ($type_def->{ops} eq 'date') {
96 my $date_value = $::form->get_standard_dbh->quote(DateTime->from_kivitendo($value));
98 (value_$type_def->{data_type} > $date_value AND op = 'lt') OR
99 (value_$type_def->{data_type} < $date_value AND op = 'gt') OR
100 (value_$type_def->{data_type} = $date_value AND op = 'eq')
102 } elsif ($type_def->{ops} eq 'num') {
103 my $num_value = $::form->get_standard_dbh->quote($::form->parse_amount(\%::myconfig, $value));
105 (value_$type_def->{data_type} >= $num_value AND op = 'le') OR
106 (value_$type_def->{data_type} <= $num_value AND op = 'ge') OR
107 (value_$type_def->{data_type} = $num_value AND op = 'eq')