Revision bc4dfd19
Von Sven Schöling vor etwa 1 Jahr hinzugefügt
SL/DB/Order/TypeData.pm | ||
---|---|---|
1 |
package SL::DB::Order::TypeData; |
|
2 |
|
|
3 |
use strict; |
|
4 |
use Carp; |
|
5 |
use Exporter qw(import); |
|
6 |
use SL::Locale::String qw(t8); |
|
7 |
|
|
8 |
use constant { |
|
9 |
SALES_ORDER_TYPE => 'sales_order', |
|
10 |
PURCHASE_ORDER_TYPE => 'purchase_order', |
|
11 |
SALES_QUOTATION_TYPE => 'sales_quotation', |
|
12 |
REQUEST_QUOTATION_TYPE => 'request_quotation', |
|
13 |
}; |
|
14 |
|
|
15 |
my @export_types = qw(SALES_ORDER_TYPE PURCHASE_ORDER_TYPE REQUEST_QUOTATION_TYPE SALES_QUOTATION_TYPE); |
|
16 |
my @export_subs = qw(valid_types validate_type is_valid_type get get3); |
|
17 |
|
|
18 |
our @EXPORT_OK = (@export_types, @export_subs); |
|
19 |
our %EXPORT_TAGS = (types => \@export_types, subs => \@export_subs); |
|
20 |
|
|
21 |
my %type_data = ( |
|
22 |
SALES_ORDER_TYPE() => { |
|
23 |
text => { |
|
24 |
delete => t8('The order has been deleted'), |
|
25 |
saved => t8('The order has been saved'), |
|
26 |
add => t8("Add Sales Order"), |
|
27 |
edit => t8("Edit Sales Order"), |
|
28 |
list => t8("Sales Orders"), |
|
29 |
attachment => t8("sales_order_list"), |
|
30 |
}, |
|
31 |
show_menu => { |
|
32 |
save_and_quotation => 1, |
|
33 |
save_and_rfq => 1, |
|
34 |
save_and_sales_order => 0, |
|
35 |
save_and_purchase_order => 1, |
|
36 |
save_and_delivery_order => 1, |
|
37 |
save_and_supplier_delivery_order => 0, |
|
38 |
save_and_reclamation => 1, |
|
39 |
save_and_invoice_for_advance_payment => 1, |
|
40 |
save_and_final_invoice => 1, |
|
41 |
save_and_ap_transaction => 0, |
|
42 |
save_and_invoice => 1, |
|
43 |
delete => sub { $::instance_conf->get_sales_order_show_delete }, |
|
44 |
}, |
|
45 |
properties => { |
|
46 |
customervendor => "customer", |
|
47 |
is_customer => 1, |
|
48 |
nr_key => "ordnumber", |
|
49 |
}, |
|
50 |
part_classification_query => [ "used_for_sale" => 1 ], |
|
51 |
rights => { |
|
52 |
edit => "sales_order_edit", |
|
53 |
view => "sales_order_edit | sales_order_view", |
|
54 |
}, |
|
55 |
}, |
|
56 |
PURCHASE_ORDER_TYPE() => { |
|
57 |
text => { |
|
58 |
delete => t8('The order has been deleted'), |
|
59 |
saved => t8('The order has been saved'), |
|
60 |
add => t8("Add Purchase Order"), |
|
61 |
edit => t8("Edit Purchase Order"), |
|
62 |
list => t8("Purchase Orders"), |
|
63 |
attachment => t8("purchase_order_list"), |
|
64 |
}, |
|
65 |
show_menu => { |
|
66 |
save_and_quotation => 0, |
|
67 |
save_and_rfq => 1, |
|
68 |
save_and_sales_order => 1, |
|
69 |
save_and_purchase_order => 0, |
|
70 |
save_and_delivery_order => 1, |
|
71 |
save_and_supplier_delivery_order => 1, |
|
72 |
save_and_reclamation => 1, |
|
73 |
save_and_invoice_for_advance_payment => 0, |
|
74 |
save_and_final_invoice => 0, |
|
75 |
save_and_ap_transaction => 1, |
|
76 |
save_and_invoice => 1, |
|
77 |
delete => sub { $::instance_conf->get_purchase_order_show_delete }, |
|
78 |
}, |
|
79 |
properties => { |
|
80 |
customervendor => "vendor", |
|
81 |
is_customer => 0, |
|
82 |
nr_key => "ordnumber", |
|
83 |
}, |
|
84 |
part_classification_query => [ "used_for_purchase" => 1 ], |
|
85 |
rights => { |
|
86 |
edit => "purchase_order_edit", |
|
87 |
view => "purchase_order_edit | purchase_order_view", |
|
88 |
}, |
|
89 |
}, |
|
90 |
SALES_QUOTATION_TYPE() => { |
|
91 |
text => { |
|
92 |
delete => t8('The quotation has been deleted'), |
|
93 |
saved => t8('The quotation has been saved'), |
|
94 |
add => t8("Add Quotation"), |
|
95 |
edit => t8("Edit Quotation"), |
|
96 |
list => t8("Quotations"), |
|
97 |
attachment => t8("quotation_list"), |
|
98 |
}, |
|
99 |
show_menu => { |
|
100 |
save_and_quotation => 0, |
|
101 |
save_and_rfq => 1, |
|
102 |
save_and_sales_order => 1, |
|
103 |
save_and_purchase_order => 0, |
|
104 |
save_and_delivery_order => 0, |
|
105 |
save_and_supplier_delivery_order => 0, |
|
106 |
save_and_reclamation => 0, |
|
107 |
save_and_invoice_for_advance_payment => 0, |
|
108 |
save_and_final_invoice => 0, |
|
109 |
save_and_ap_transaction => 0, |
|
110 |
save_and_invoice => 1, |
|
111 |
delete => 1, |
|
112 |
}, |
|
113 |
properties => { |
|
114 |
customervendor => "customer", |
|
115 |
is_customer => 1, |
|
116 |
nr_key => "quonumber", |
|
117 |
}, |
|
118 |
part_classification_query => [ "used_for_sale" => 1 ], |
|
119 |
rights => { |
|
120 |
edit => "sales_quotation_edit", |
|
121 |
view => "sales_quotation_edit | sales_quotation_view", |
|
122 |
}, |
|
123 |
}, |
|
124 |
REQUEST_QUOTATION_TYPE() => { |
|
125 |
text => { |
|
126 |
delete => t8('The rfq has been deleted'), |
|
127 |
saved => t8('The rfq has been saved'), |
|
128 |
add => t8("Add Request for Quotation"), |
|
129 |
edit => t8("Edit Request for Quotation"), |
|
130 |
list => t8("Request for Quotations"), |
|
131 |
attachment => t8("rfq_list"), |
|
132 |
}, |
|
133 |
show_menu => { |
|
134 |
save_and_quotation => 1, |
|
135 |
save_and_rfq => 0, |
|
136 |
save_and_sales_order => 1, |
|
137 |
save_and_purchase_order => 1, |
|
138 |
save_and_delivery_order => 0, |
|
139 |
save_and_supplier_delivery_order => 0, |
|
140 |
save_and_reclamation => 0, |
|
141 |
save_and_invoice_for_advance_payment => 0, |
|
142 |
save_and_final_invoice => 0, |
|
143 |
save_and_ap_transaction => 0, |
|
144 |
save_and_invoice => 1, |
|
145 |
delete => 1, |
|
146 |
}, |
|
147 |
properties => { |
|
148 |
customervendor => "vendor", |
|
149 |
is_customer => 0, |
|
150 |
nr_key => "quonumber", |
|
151 |
}, |
|
152 |
part_classification_query => [ "used_for_purchase" => 1 ], |
|
153 |
rights => { |
|
154 |
edit => "purchase_quotation_edit", |
|
155 |
view => "purchase_quotation_edit | purchase_quotation_view", |
|
156 |
}, |
|
157 |
}, |
|
158 |
); |
|
159 |
|
|
160 |
my @valid_types = ( |
|
161 |
SALES_ORDER_TYPE, |
|
162 |
PURCHASE_ORDER_TYPE, |
|
163 |
SALES_QUOTATION_TYPE, |
|
164 |
REQUEST_QUOTATION_TYPE, |
|
165 |
); |
|
166 |
|
|
167 |
my %valid_types = map { $_ => $_ } @valid_types; |
|
168 |
|
|
169 |
sub valid_types { |
|
170 |
\@valid_types; |
|
171 |
} |
|
172 |
|
|
173 |
sub is_valid_type { |
|
174 |
!!exists $type_data{$_[0]}; |
|
175 |
} |
|
176 |
|
|
177 |
sub validate_type { |
|
178 |
my ($type) = @_; |
|
179 |
|
|
180 |
return $valid_types{$type} // croak "invalid type '$type'"; |
|
181 |
} |
|
182 |
|
|
183 |
sub get { |
|
184 |
my ($type, $key) = @_; |
|
185 |
|
|
186 |
croak "invalid type '$type'" unless exists $type_data{$type}; |
|
187 |
|
|
188 |
my $ret = $type_data{$type}->{$key} // die "unknown property '$key'"; |
|
189 |
|
|
190 |
ref $ret eq 'CODE' |
|
191 |
? $ret->() |
|
192 |
: $ret; |
|
193 |
} |
|
194 |
|
|
195 |
sub get3 { |
|
196 |
my ($type, $topic, $key) = @_; |
|
197 |
|
|
198 |
croak "invalid type '$type'" unless exists $type_data{$type}; |
|
199 |
|
|
200 |
my $ret = $type_data{$type}{$topic}{$key} // croak "unknown property '$key' in topic '$topic' for type '$type'"; |
|
201 |
|
|
202 |
ref $ret eq 'CODE' |
|
203 |
? $ret->() |
|
204 |
: $ret; |
|
205 |
} |
|
206 |
|
|
207 |
1; |
|
208 |
|
|
209 |
__END__ |
|
210 |
|
|
211 |
todo: |
|
212 |
|
|
213 |
features: |
|
214 |
- price_tax_calculation |
|
215 |
- subversioning for sales_orders |
|
216 |
- final invoices for sales_orders |
|
217 |
- payment_terms |
|
218 |
- periodic invoices for some types |
|
219 |
- auto close quotations for some types |
|
220 |
- |
Auch abrufbar als: Unified diff
TypeData: Order