]> wagnertech.de Git - mfinanz.git/blob - SL/DB/PriceRuleItem.pm
restart apache2 in postinst
[mfinanz.git] / SL / DB / PriceRuleItem.pm
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.
3
4 package SL::DB::PriceRuleItem;
5
6 use strict;
7
8 use SL::DB::MetaSetup::PriceRuleItem;
9 use SL::DB::Manager::PriceRuleItem;
10 use SL::Locale::String qw(t8);
11
12 __PACKAGE__->meta->initialize;
13
14 use Rose::Object::MakeMethods::Generic (
15   'scalar --get_set_init' => [ qw(object operator) ],
16 );
17
18 sub match {
19   my ($self, %params) = @_;
20
21   die 'need record'      unless $params{record};
22   die 'need record_item' unless $params{record_item};
23
24   $self->${\ "match_" . $self->type }(%params);
25 }
26
27 sub match_customer {
28   $_[0]->value_int == $_[1]{record}->customer_id;
29 }
30 sub match_vendor {
31   $_[0]->value_int == $_[1]{record}->vendor_id;
32 }
33 sub match_business {
34   $_[0]->value_int == $_[1]{record}->customervendor->business_id;
35 }
36 sub match_partsgroup {
37   $_[0]->value_int == $_[1]{record_item}->parts->partsgroup_id;
38 }
39 sub match_part {
40   $_[0]->value_int == $_[1]{record_item}->parts_id;
41 }
42 sub match_qty {
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;
49   }
50 }
51 sub match_reqdate {
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;
58   }
59 }
60 sub match_transdate {
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;
67   }
68 }
69 sub match_pricegroup {
70   $_[0]->value_int == $_[1]{record_item}->customervendor->pricegroup_id;
71 }
72
73 sub part {
74   require SL::DB::Part;
75   SL::DB::Part->load_cached($_[0]->value_int);
76 }
77 sub customer {
78   require SL::DB::Customer;
79   SL::DB::Customer->load_cached($_[0]->value_int);
80 }
81
82 sub vendor {
83   require SL::DB::Vendor;
84   SL::DB::Vendor->load_cached($_[0]->value_int);
85 }
86
87 sub business {
88   require SL::DB::Business;
89   SL::DB::Business->load_cached($_[0]->value_int);
90 }
91
92 sub partsgroup {
93   require SL::DB::PartsGroup;
94   SL::DB::PartsGroup->load_cached($_[0]->value_int);
95 }
96
97 sub pricegroup {
98   require SL::DB::Pricegroup;
99   SL::DB::Pricegroup->load_cached($_[0]->value_int);
100 }
101
102 sub cvar_config {
103   die "not a cvar price rule item" unless $_[0]->type eq 'cvar';
104   &custom_variable_configs
105 }
106
107 sub full_description {
108   my ($self) = @_;
109
110   my $type = $self->type;
111   my $op   = $self->op;
112
113     $type eq 'customer'   ? t8('Customer')         . ' ' . $self->customer->displayable_name
114   : $type eq 'vendor'     ? t8('Vendor')           . ' ' . $self->vendor->displayable_name
115   : $type eq 'business'   ? t8('Type of Business') . ' ' . $self->business->displayable_name
116   : $type eq 'partsgroup' ? t8('Partsgroup')       . ' ' . $self->partsgroup->displayable_name
117   : $type eq 'pricegroup' ? t8('Pricegroup')       . ' ' . $self->pricegroup->displayable_name
118   : $type eq 'part'       ? t8('Part')             . ' ' . $self->part->displayable_name
119   : $type eq 'qty' ? (
120        $op eq 'eq' ? t8('Qty equals #1',             $self->value_num_as_number)
121      : $op eq 'lt' ? t8('Qty less than #1',          $self->value_num_as_number)
122      : $op eq 'gt' ? t8('Qty more than #1',          $self->value_num_as_number)
123      : $op eq 'le' ? t8('Qty equal or less than #1', $self->value_num_as_number)
124      : $op eq 'ge' ? t8('Qty equal or more than #1', $self->value_num_as_number)
125      : do { die "unknown op $op for type $type" } )
126   : $type eq 'reqdate' ? (
127        $op eq 'eq' ? t8('Reqdate is #1',        $self->value_date_as_date)
128      : $op eq 'lt' ? t8('Reqdate is before #1', $self->value_date_as_date)
129      : $op eq 'gt' ? t8('Reqdate is after #1',  $self->value_date_as_date)
130      : do { die "unknown op $op for type $type" } )
131   : $type eq 'transdate' ? (
132        $op eq 'eq' ? t8('Transdate is #1',        $self->value_date_as_date)
133      : $op eq 'lt' ? t8('Transdate is before #1', $self->value_date_as_date)
134      : $op eq 'gt' ? t8('Transdate is after #1',  $self->value_date_as_date)
135      : do { die "unknown op $op for type $type" } )
136   : $type eq 'cvar' ? $self->cvar_rule_description($type, $op)
137   : do { die "unknown type $type" }
138 }
139
140 sub cvar_rule_description {
141   my ($self, $type, $op) = @_;
142   my $config      = $self->cvar_config;
143   my $description = $config->description;
144
145   t8('Custom Variables (Abbreviation)') . ' ' . (
146       $config->type eq 'select'   ? t8("#1 is #2", $description, $self->value_text)
147     : $config->type eq 'customer' ? t8("#1 is #2", $description, $self->customer->displayable_name)
148     : $config->type eq 'vendor'   ? t8("#1 is #2", $description, $self->vendor->displayable_name)
149     : $config->type eq 'part'     ? t8("#1 is #2", $description, $self->part->displayable_name)
150     : $config->type eq 'number'   ? (
151           $op eq 'eq' ? t8('#1 equals #2',             $description, $self->value_num_as_number)
152         : $op eq 'lt' ? t8('#1 less than #2',          $description, $self->value_num_as_number)
153         : $op eq 'gt' ? t8('#1 more than #2',          $description, $self->value_num_as_number)
154         : $op eq 'le' ? t8('#1 equal or less than #2', $description, $self->value_num_as_number)
155         : $op eq 'ge' ? t8('#1 equal or more than #2', $description, $self->value_num_as_number)
156         : do { die "unknown op $op for type ", $config->type }
157       )
158      : $config->type eq 'date'     ? (
159            $op eq 'eq' ? t8('#1 is #2',        $description, $self->value_date_as_date)
160          : $op eq 'lt' ? t8('#1 is before #2', $description, $self->value_date_as_date)
161          : $op eq 'gt' ? t8('#1 is after #2',  $description, $self->value_date_as_date)
162          : do { die "unknown op $op for type ", $config->type }
163        )
164     : do { die "unknown type " . $config->type }
165   );
166 }
167
168 sub validate {
169   my ($self) = @_;
170
171   my @errors;
172   push @errors, t8('Rule for part must not be empty')     if $self->type eq 'part'     && !$self->value_int;
173   push @errors, t8('Rule for customer must not be empty') if $self->type eq 'customer' && !$self->value_int;
174   push @errors, t8('Rule for vendor must not be empty')   if $self->type eq 'vendor'   && !$self->value_int;
175
176   return @errors;
177 }
178
179 1;