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 SL::Locale::String qw(t8);
12 __PACKAGE__->meta->initialize;
14 use Rose::Object::MakeMethods::Generic (
15 'scalar --get_set_init' => [ qw(object operator) ],
19 my ($self, %params) = @_;
21 die 'need record' unless $params{record};
22 die 'need record_item' unless $params{record_item};
24 $self->${\ "match_" . $self->type }(%params);
28 $_[0]->value_int == $_[1]{record}->customer_id;
31 $_[0]->value_int == $_[1]{record}->vendor_id;
34 $_[0]->value_int == $_[1]{record}->customervendor->business_id;
36 sub match_partsgroup {
37 $_[0]->value_int == $_[1]{record_item}->parts->partsgroup_id;
40 $_[0]->value_int == $_[1]{record_item}->parts_id;
43 if ($_[0]->op eq 'eq') {
44 return $_[0]->value_num == $_[1]{record_item}->qty
45 } elsif ($_[0]->op eq 'le') {
46 return $_[0]->value_num < $_[1]{record_item}->qty;
47 } elsif ($_[0]->op eq 'ge') {
48 return $_[0]->value_num > $_[1]{record_item}->qty;
52 if ($_[0]->op eq 'eq') {
53 return $_[0]->value_date == $_[1]{record}->reqdate;
54 } elsif ($_[0]->op eq 'lt') {
55 return $_[0]->value_date < $_[1]{record}->reqdate;
56 } elsif ($_[0]->op eq 'gt') {
57 return $_[0]->value_date > $_[1]{record}->reqdate;
61 if ($_[0]->op eq 'eq') {
62 return $_[0]->value_date == $_[1]{record}->transdate;
63 } elsif ($_[0]->op eq 'lt') {
64 return $_[0]->value_date < $_[1]{record}->transdate;
65 } elsif ($_[0]->op eq 'gt') {
66 return $_[0]->value_date > $_[1]{record}->transdate;
69 sub match_pricegroup {
70 $_[0]->value_int == $_[1]{record_item}->customervendor->pricegroup_id;
75 SL::DB::Part->load_cached($_[0]->value_int);
78 require SL::DB::Customer;
79 SL::DB::Customer->load_cached($_[0]->value_int);
83 require SL::DB::Vendor;
84 SL::DB::Vendor->load_cached($_[0]->value_int);
88 require SL::DB::Business;
89 SL::DB::Business->load_cached($_[0]->value_int);
93 require SL::DB::PartsGroup;
94 SL::DB::PartsGroup->load_cached($_[0]->value_int);
98 require SL::DB::Pricegroup;
99 SL::DB::Pricegroup->load_cached($_[0]->value_int);
102 sub full_description {
105 my $type = $self->type;
108 $type eq 'customer' ? t8('Customer') . ' ' . $self->customer->displayable_name
109 : $type eq 'vendor' ? t8('Vendor') . ' ' . $self->vendor->displayable_name
110 : $type eq 'business' ? t8('Type of Business') . ' ' . $self->business->displayable_name
111 : $type eq 'partsgroup' ? t8('Partsgroup') . ' ' . $self->partsgroup->displayable_name
112 : $type eq 'pricegroup' ? t8('Pricegroup') . ' ' . $self->pricegroup->displayable_name
113 : $type eq 'part' ? t8('Part') . ' ' . $self->part->displayable_name
115 $op eq 'eq' ? t8('Qty equals #1', $self->value_num_as_number)
116 : $op eq 'lt' ? t8('Qty less than #1', $self->value_num_as_number)
117 : $op eq 'gt' ? t8('Qty more than #1', $self->value_num_as_number)
118 : $op eq 'le' ? t8('Qty equal or less than #1', $self->value_num_as_number)
119 : $op eq 'ge' ? t8('Qty equal or more than #1', $self->value_num_as_number)
120 : do { die "unknown op $op for type $type" } )
121 : $type eq 'reqdate' ? (
122 $op eq 'eq' ? t8('Reqdate is #1', $self->value_date_as_date)
123 : $op eq 'lt' ? t8('Reqdate is before #1', $self->value_date_as_date)
124 : $op eq 'gt' ? t8('Reqdate is after #1', $self->value_date_as_date)
125 : do { die "unknown op $op for type $type" } )
126 : $type eq 'transdate' ? (
127 $op eq 'eq' ? t8('Transdate is #1', $self->value_date_as_date)
128 : $op eq 'lt' ? t8('Transdate is before #1', $self->value_date_as_date)
129 : $op eq 'gt' ? t8('Transdate is after #1', $self->value_date_as_date)
130 : do { die "unknown op $op for type $type" } )
131 : do { die "unknown type $type" }
138 push @errors, t8('Rule for part must not be empty') if $self->type eq 'part' && !$self->value_int;
139 push @errors, t8('Rule for customer must not be empty') if $self->type eq 'customer' && !$self->value_int;
140 push @errors, t8('Rule for vendor must not be empty') if $self->type eq 'vendor' && !$self->value_int;