26 |
26 |
my %types = (
|
27 |
27 |
'customer' => { description => t8('Customer'), customer => 1, vendor => 0, data_type => 'int', data => sub { $_[0]->customer->id }, },
|
28 |
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 }, },
|
|
29 |
'business' => { description => t8('Type of Business'), customer => 1, vendor => 1, data_type => 'int', data => sub { $_[0]->customervendor->business_id }, exclude_nulls => 1 },
|
30 |
30 |
'reqdate' => { description => t8('Reqdate'), customer => 1, vendor => 1, data_type => 'date', data => sub { $_[0]->reqdate }, ops => 'date' },
|
31 |
|
'pricegroup' => { description => t8('Pricegroup'), customer => 1, vendor => 1, data_type => 'int', data => sub { $_[1]->pricegroup_id }, },
|
32 |
|
'partsgroup' => { description => t8('Group'), customer => 1, vendor => 1, data_type => 'int', data => sub { $_[1]->part->partsgroup_id }, },
|
|
31 |
'pricegroup' => { description => t8('Pricegroup'), customer => 1, vendor => 1, data_type => 'int', data => sub { $_[1]->pricegroup_id }, exclude_nulls => 1 },
|
|
32 |
'partsgroup' => { description => t8('Group'), customer => 1, vendor => 1, data_type => 'int', data => sub { $_[1]->part->partsgroup_id }, exclude_nulls => 1 },
|
33 |
33 |
'qty' => { description => t8('Qty'), customer => 1, vendor => 1, data_type => 'num', data => sub { $_[1]->qty }, ops => 'num' },
|
34 |
34 |
);
|
35 |
35 |
|
... | ... | |
37 |
37 |
my ($class, %params) = @_;
|
38 |
38 |
|
39 |
39 |
die 'must be called with a customer/vendor type' unless $params{type};
|
|
40 |
my @args = @params{'record', 'record_item'};
|
40 |
41 |
|
41 |
42 |
my (@tokens, @values);
|
42 |
43 |
|
... | ... | |
44 |
45 |
my $def = $types{$type};
|
45 |
46 |
next unless $def->{$params{type}};
|
46 |
47 |
|
47 |
|
if ($def->{ops}) {
|
48 |
|
my $ops = $ops{$def->{ops}};
|
|
48 |
my $value = $def->{data}->(@args);
|
49 |
49 |
|
|
50 |
if ($def->{exclude_nulls} && !defined $value) {
|
|
51 |
push @tokens, "type = '$type'";
|
|
52 |
} else {
|
50 |
53 |
my @sub_tokens;
|
51 |
|
for (keys %$ops) {
|
52 |
|
push @sub_tokens, "op = '$_' AND NOT value_$def->{data_type} $ops->{$_} ?";
|
53 |
|
push @values, $def->{data};
|
|
54 |
if ($def->{ops}) {
|
|
55 |
my $ops = $ops{$def->{ops}};
|
|
56 |
|
|
57 |
for (keys %$ops) {
|
|
58 |
push @sub_tokens, "op = '$_' AND NOT value_$def->{data_type} $ops->{$_} ?";
|
|
59 |
push @values, $value;
|
|
60 |
}
|
|
61 |
} else {
|
|
62 |
push @sub_tokens, "NOT value_$def->{data_type} = ?";
|
|
63 |
push @values, $value;
|
54 |
64 |
}
|
55 |
65 |
|
56 |
66 |
push @tokens, "type = '$type' AND " . join ' OR ', map "($_)", @sub_tokens;
|
57 |
|
} else {
|
58 |
|
push @tokens, "type = '$type' AND NOT value_$def->{data_type} = ?";
|
59 |
|
push @values, $def->{data};
|
60 |
67 |
}
|
61 |
68 |
}
|
62 |
69 |
|
PriceRule: Korrektes Matching von Nulls