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::PriceRuleItem;
8 use SL::DB::MetaSetup::PriceRuleItem;
9 use SL::DB::Manager::PriceRuleItem;
10 use Rose::DB::Object::Helpers qw(clone_and_reset);
11 use SL::Locale::String qw(t8);
13 __PACKAGE__->meta->initialize;
15 use Rose::Object::MakeMethods::Generic (
16 'scalar --get_set_init' => [ qw(object operator) ],
20 my ($self, %params) = @_;
22 die 'need record' unless $params{record};
23 die 'need record_item' unless $params{record_item};
25 $self->${\ "match_" . $self->type }(%params);
29 $_[0]->value_int == $_[1]{record}->customer_id;
32 $_[0]->value_int == $_[1]{record}->vendor_id;
35 $_[0]->value_int == $_[1]{record}->customervendor->business_id;
37 sub match_partsgroup {
38 $_[0]->value_int == $_[1]{record_item}->parts->partsgroup_id;
41 $_[0]->value_int == $_[1]{record_item}->parts_id;
44 if ($_[0]->op eq 'eq') {
45 return $_[0]->value_num == $_[1]{record_item}->qty
46 } elsif ($_[0]->op eq 'le') {
47 return $_[0]->value_num < $_[1]{record_item}->qty;
48 } elsif ($_[0]->op eq 'ge') {
49 return $_[0]->value_num > $_[1]{record_item}->qty;
53 if ($_[0]->op eq 'eq') {
54 return $_[0]->value_date == $_[1]{record}->reqdate;
55 } elsif ($_[0]->op eq 'lt') {
56 return $_[0]->value_date < $_[1]{record}->reqdate;
57 } elsif ($_[0]->op eq 'gt') {
58 return $_[0]->value_date > $_[1]{record}->reqdate;
62 if ($_[0]->op eq 'eq') {
63 return $_[0]->value_date == $_[1]{record}->transdate;
64 } elsif ($_[0]->op eq 'lt') {
65 return $_[0]->value_date < $_[1]{record}->transdate;
66 } elsif ($_[0]->op eq 'gt') {
67 return $_[0]->value_date > $_[1]{record}->transdate;
70 sub match_pricegroup {
71 $_[0]->value_int == $_[1]{record_item}->customervendor->pricegroup_id;
76 SL::DB::Part->load_cached($_[0]->value_int);
79 require SL::DB::Customer;
80 SL::DB::Customer->load_cached($_[0]->value_int);
84 require SL::DB::Vendor;
85 SL::DB::Vendor->load_cached($_[0]->value_int);
89 require SL::DB::Business;
90 SL::DB::Business->load_cached($_[0]->value_int);
94 require SL::DB::PartsGroup;
95 SL::DB::PartsGroup->load_cached($_[0]->value_int);
99 require SL::DB::Pricegroup;
100 SL::DB::Pricegroup->load_cached($_[0]->value_int);
103 sub full_description {
106 my $type = $self->type;
109 $type eq 'customer' ? t8('Customer') . ' ' . $self->customer->displayable_name
110 : $type eq 'vendor' ? t8('Vendor') . ' ' . $self->vendor->displayable_name
111 : $type eq 'business' ? t8('Type of Business') . ' ' . $self->business->displayable_name
112 : $type eq 'partsgroup' ? t8('Group') . ' ' . $self->partsgroup->displayable_name
113 : $type eq 'pricegroup' ? t8('Pricegroup') . ' ' . $self->pricegroup->displayable_name
114 : $type eq 'part' ? t8('Part') . ' ' . $self->part->displayable_name
116 $op eq 'eq' ? t8('Qty equals #1', $self->value_num_as_number)
117 : $op eq 'lt' ? t8('Qty less than #1', $self->value_num_as_number)
118 : $op eq 'gt' ? t8('Qty more than #1', $self->value_num_as_number)
119 : $op eq 'le' ? t8('Qty equal or less than #1', $self->value_num_as_number)
120 : $op eq 'ge' ? t8('Qty equal or more than #1', $self->value_num_as_number)
121 : do { die "unknown op $op for type $type" } )
122 : $type eq 'reqdate' ? (
123 $op eq 'eq' ? t8('Reqdate is #1', $self->value_date_as_date)
124 : $op eq 'lt' ? t8('Reqdate is before #1', $self->value_date_as_date)
125 : $op eq 'gt' ? t8('Reqdate is after #1', $self->value_date_as_date)
126 : do { die "unknown op $op for type $type" } )
127 : $type eq 'transdate' ? (
128 $op eq 'eq' ? t8('Transdate is #1', $self->value_date_as_date)
129 : $op eq 'lt' ? t8('Transdate is before #1', $self->value_date_as_date)
130 : $op eq 'gt' ? t8('Transdate is after #1', $self->value_date_as_date)
131 : do { die "unknown op $op for type $type" } )
132 : do { die "unknown type $type" }
139 push @errors, t8('Rule for part must not be empty') if $self->type eq 'part' && !$self->value_int;
140 push @errors, t8('Rule for customer must not be empty') if $self->type eq 'customer' && !$self->value_int;
141 push @errors, t8('Rule for vendor must not be empty') if $self->type eq 'vendor' && !$self->value_int;