Revision f3842deb
Von Tamino Steinert vor etwa 1 Jahr hinzugefügt
SL/DB/Order.pm | ||
---|---|---|
26 | 26 |
use SL::RecordLinks; |
27 | 27 |
use Rose::DB::Object::Helpers qw(as_tree strip); |
28 | 28 |
|
29 |
use SL::DB::Order::TypeData qw(:types); |
|
30 |
use SL::DB::Reclamation::TypeData qw(:types); |
|
31 |
|
|
29 | 32 |
__PACKAGE__->meta->add_relationship( |
30 | 33 |
orderitems => { |
31 | 34 |
type => 'one to many', |
... | ... | |
99 | 102 |
my ($self) = @_; |
100 | 103 |
|
101 | 104 |
# force new project, if not set yet |
102 |
if ($::instance_conf->get_order_always_project && !$self->globalproject_id && ($self->type eq 'sales_order')) {
|
|
105 |
if ($::instance_conf->get_order_always_project && !$self->globalproject_id && ($self->type eq SALES_ORDER_TYPE())) {
|
|
103 | 106 |
|
104 | 107 |
die t8("Error while creating project with project number of new order number, project number #1 already exists!", $self->ordnumber) |
105 | 108 |
if SL::DB::Manager::Project->find_by(projectnumber => $self->ordnumber); |
... | ... | |
161 | 164 |
sub type { |
162 | 165 |
my $self = shift; |
163 | 166 |
|
164 |
return 'sales_order_intake' if $self->customer_id && $self->intake;
|
|
165 |
return 'sales_order' if $self->customer_id && ! $self->quotation;
|
|
166 |
return 'purchase_order' if $self->vendor_id && ! $self->quotation;
|
|
167 |
return 'sales_quotation' if $self->customer_id && $self->quotation;
|
|
168 |
return 'request_quotation' if $self->vendor_id && $self->quotation && ! $self->intake;
|
|
169 |
return 'purchase_quotation_intake' if $self->vendor_id && $self->quotation && $self->intake;
|
|
167 |
return SALES_ORDER_INTAKE_TYPE() if $self->customer_id && $self->intake;
|
|
168 |
return SALES_ORDER_TYPE() if $self->customer_id && ! $self->quotation;
|
|
169 |
return PURCHASE_ORDER_TYPE() if $self->vendor_id && ! $self->quotation;
|
|
170 |
return SALES_QUOTATION_TYPE() if $self->customer_id && $self->quotation;
|
|
171 |
return REQUEST_QUOTATION_TYPE() if $self->vendor_id && $self->quotation && ! $self->intake;
|
|
172 |
return PURCHASE_QUOTATION_INTAKE_TYPE() if $self->vendor_id && $self->quotation && $self->intake;
|
|
170 | 173 |
|
171 | 174 |
return; |
172 | 175 |
} |
... | ... | |
180 | 183 |
# But this has a different meaning for sales quotations. |
181 | 184 |
# deliverydate can be used to determine tax if tax_point isn't set. |
182 | 185 |
|
183 |
return $_[0]->reqdate if $_[0]->type ne 'sales_quotation';
|
|
186 |
return $_[0]->reqdate if $_[0]->type ne SALES_QUOTATION_TYPE();
|
|
184 | 187 |
} |
185 | 188 |
|
186 | 189 |
sub effective_tax_point { |
... | ... | |
192 | 195 |
sub displayable_type { |
193 | 196 |
my $type = shift->type; |
194 | 197 |
|
195 |
return $::locale->text('Sales quotation') if $type eq 'sales_quotation';
|
|
196 |
return $::locale->text('Request quotation') if $type eq 'request_quotation';
|
|
197 |
return $::locale->text('Sales Order') if $type eq 'sales_order';
|
|
198 |
return $::locale->text('Purchase Order') if $type eq 'purchase_order';
|
|
198 |
return $::locale->text('Sales quotation') if $type eq SALES_QUOTATION_TYPE();
|
|
199 |
return $::locale->text('Request quotation') if $type eq REQUEST_QUOTATION_TYPE();
|
|
200 |
return $::locale->text('Sales Order') if $type eq SALES_ORDER_TYPE();
|
|
201 |
return $::locale->text('Purchase Order') if $type eq PURCHASE_ORDER_TYPE();
|
|
199 | 202 |
|
200 | 203 |
die 'invalid type'; |
201 | 204 |
} |
... | ... | |
214 | 217 |
|
215 | 218 |
return 1 if $self->currency_id == $::instance_conf->get_currency_id; |
216 | 219 |
|
217 |
my $rate = (any { $self->is_type($_) } qw(sales_quotation sales_order)) ? 'buy'
|
|
218 |
: (any { $self->is_type($_) } qw(request_quotation purchase_order)) ? 'sell'
|
|
220 |
my $rate = (any { $self->is_type($_) } (SALES_QUOTATION_TYPE(), SALES_ORDER_TYPE())) ? 'buy'
|
|
221 |
: (any { $self->is_type($_) } (REQUEST_QUOTATION_TYPE(), PURCHASE_ORDER_TYPE())) ? 'sell'
|
|
219 | 222 |
: undef; |
220 | 223 |
return if !$rate; |
221 | 224 |
|
... | ... | |
305 | 308 |
|
306 | 309 |
sub convert_to_reclamation { |
307 | 310 |
my ($self, %params) = @_; |
308 |
$params{destination_type} = $self->is_sales ? 'sales_reclamation'
|
|
309 |
: 'purchase_reclamation';
|
|
311 |
$params{destination_type} = $self->is_sales ? SALES_RECLAMATION_TYPE()
|
|
312 |
: PURCHASE_RECLAMATION_TYPE();
|
|
310 | 313 |
|
311 | 314 |
require SL::DB::Reclamation; |
312 | 315 |
my $reclamation = SL::DB::Reclamation->new_from($self, %params); |
... | ... | |
337 | 340 |
my $destination_type = delete $params{destination_type}; |
338 | 341 |
|
339 | 342 |
my @from_tos = ( |
340 |
{ from => 'sales_quotation', to => 'sales_order', abbr => 'sqso' },
|
|
341 |
{ from => 'request_quotation', to => 'purchase_order', abbr => 'rqpo' },
|
|
342 |
{ from => 'sales_quotation', to => 'sales_quotation', abbr => 'sqsq' },
|
|
343 |
{ from => 'sales_order', to => 'sales_order', abbr => 'soso' },
|
|
344 |
{ from => 'request_quotation', to => 'request_quotation', abbr => 'rqrq' },
|
|
345 |
{ from => 'purchase_order', to => 'purchase_order', abbr => 'popo' },
|
|
346 |
{ from => 'sales_order', to => 'purchase_order', abbr => 'sopo' },
|
|
347 |
{ from => 'purchase_order', to => 'sales_order', abbr => 'poso' },
|
|
348 |
{ from => 'sales_order', to => 'sales_quotation', abbr => 'sosq' },
|
|
349 |
{ from => 'purchase_order', to => 'request_quotation', abbr => 'porq' },
|
|
350 |
{ from => 'request_quotation', to => 'sales_quotation', abbr => 'rqsq' },
|
|
351 |
{ from => 'request_quotation', to => 'sales_order', abbr => 'rqso' },
|
|
352 |
{ from => 'sales_quotation', to => 'request_quotation', abbr => 'sqrq' },
|
|
353 |
{ from => 'sales_order', to => 'request_quotation', abbr => 'sorq' },
|
|
354 |
{ from => 'sales_reclamation', to => 'sales_order', abbr => 'srso' },
|
|
355 |
{ from => 'purchase_reclamation', to => 'purchase_order', abbr => 'prpo' },
|
|
356 |
{ from => 'sales_order_intake', to => 'sales_order_intake', abbr => 'soisoi' },
|
|
357 |
{ from => 'sales_order_intake', to => 'sales_quotation', abbr => 'soisq' },
|
|
358 |
{ from => 'sales_order_intake', to => 'request_quotation', abbr => 'soirq' },
|
|
359 |
{ from => 'sales_order_intake', to => 'sales_order', abbr => 'soiso' },
|
|
360 |
{ from => 'sales_order_intake', to => 'purchase_order', abbr => 'soipo' },
|
|
361 |
{ from => 'sales_quotation', to => 'sales_order_intake', abbr => 'sqsoi' },
|
|
362 |
{ from => 'purchase_quotation_intake', to => 'purchase_quotation_intake', abbr => 'pqipqi' },
|
|
363 |
{ from => 'purchase_quotation_intake', to => 'sales_quotation', abbr => 'pqisq' },
|
|
364 |
{ from => 'purchase_quotation_intake', to => 'sales_order', abbr => 'pqiso' },
|
|
365 |
{ from => 'purchase_quotation_intake', to => 'purchase_order', abbr => 'pqipo' },
|
|
366 |
{ from => 'request_quotation', to => 'purchase_quotation_intake', abbr => 'rqpqi' },
|
|
343 |
{ from => SALES_QUOTATION_TYPE(), to => SALES_ORDER_TYPE(), abbr => 'sqso' },
|
|
344 |
{ from => REQUEST_QUOTATION_TYPE(), to => PURCHASE_ORDER_TYPE(), abbr => 'rqpo' },
|
|
345 |
{ from => SALES_QUOTATION_TYPE(), to => SALES_QUOTATION_TYPE(), abbr => 'sqsq' },
|
|
346 |
{ from => SALES_ORDER_TYPE(), to => SALES_ORDER_TYPE(), abbr => 'soso' },
|
|
347 |
{ from => REQUEST_QUOTATION_TYPE(), to => REQUEST_QUOTATION_TYPE(), abbr => 'rqrq' },
|
|
348 |
{ from => PURCHASE_ORDER_TYPE(), to => PURCHASE_ORDER_TYPE(), abbr => 'popo' },
|
|
349 |
{ from => SALES_ORDER_TYPE(), to => PURCHASE_ORDER_TYPE(), abbr => 'sopo' },
|
|
350 |
{ from => PURCHASE_ORDER_TYPE(), to => SALES_ORDER_TYPE(), abbr => 'poso' },
|
|
351 |
{ from => SALES_ORDER_TYPE(), to => SALES_QUOTATION_TYPE(), abbr => 'sosq' },
|
|
352 |
{ from => PURCHASE_ORDER_TYPE(), to => REQUEST_QUOTATION_TYPE(), abbr => 'porq' },
|
|
353 |
{ from => REQUEST_QUOTATION_TYPE(), to => SALES_QUOTATION_TYPE(), abbr => 'rqsq' },
|
|
354 |
{ from => REQUEST_QUOTATION_TYPE(), to => SALES_ORDER_TYPE(), abbr => 'rqso' },
|
|
355 |
{ from => SALES_QUOTATION_TYPE(), to => REQUEST_QUOTATION_TYPE(), abbr => 'sqrq' },
|
|
356 |
{ from => SALES_ORDER_TYPE(), to => REQUEST_QUOTATION_TYPE(), abbr => 'sorq' },
|
|
357 |
{ from => SALES_RECLAMATION_TYPE(), to => SALES_ORDER_TYPE(), abbr => 'srso' },
|
|
358 |
{ from => PURCHASE_RECLAMATION_TYPE(), to => PURCHASE_ORDER_TYPE(), abbr => 'prpo' },
|
|
359 |
{ from => SALES_ORDER_INTAKE_TYPE(), to => SALES_ORDER_INTAKE_TYPE(), abbr => 'soisoi' },
|
|
360 |
{ from => SALES_ORDER_INTAKE_TYPE(), to => SALES_QUOTATION_TYPE(), abbr => 'soisq' },
|
|
361 |
{ from => SALES_ORDER_INTAKE_TYPE(), to => REQUEST_QUOTATION_TYPE(), abbr => 'soirq' },
|
|
362 |
{ from => SALES_ORDER_INTAKE_TYPE(), to => SALES_ORDER_TYPE(), abbr => 'soiso' },
|
|
363 |
{ from => SALES_ORDER_INTAKE_TYPE(), to => PURCHASE_ORDER_TYPE(), abbr => 'soipo' },
|
|
364 |
{ from => SALES_QUOTATION_TYPE(), to => SALES_ORDER_INTAKE_TYPE(), abbr => 'sqsoi' },
|
|
365 |
{ from => PURCHASE_QUOTATION_INTAKE_TYPE(), to => PURCHASE_QUOTATION_INTAKE_TYPE(), abbr => 'pqipqi' },
|
|
366 |
{ from => PURCHASE_QUOTATION_INTAKE_TYPE(), to => SALES_QUOTATION_TYPE(), abbr => 'pqisq' },
|
|
367 |
{ from => PURCHASE_QUOTATION_INTAKE_TYPE(), to => SALES_ORDER_TYPE(), abbr => 'pqiso' },
|
|
368 |
{ from => PURCHASE_QUOTATION_INTAKE_TYPE(), to => PURCHASE_ORDER_TYPE(), abbr => 'pqipo' },
|
|
369 |
{ from => REQUEST_QUOTATION_TYPE(), to => PURCHASE_QUOTATION_INTAKE_TYPE(), abbr => 'rqpqi' },
|
|
367 | 370 |
); |
368 | 371 |
my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0]; |
369 | 372 |
croak("Cannot convert from '" . $source->type . "' to '" . $destination_type . "'") if !$from_to; |
... | ... | |
596 | 599 |
push @items, @{$_->items_sorted} for @$sources; |
597 | 600 |
# make order from first source and all items |
598 | 601 |
my $order = $class->new_from($sources->[0], |
599 |
destination_type => 'sales_order',
|
|
602 |
destination_type => SALES_ORDER_TYPE(),
|
|
600 | 603 |
attributes => \%attributes, |
601 | 604 |
items => \@items, |
602 | 605 |
%params); |
... | ... | |
610 | 613 |
return if !$self->type; |
611 | 614 |
|
612 | 615 |
my %number_method = ( |
613 |
sales_order_intake => 'ordnumber',
|
|
614 |
sales_order => 'ordnumber',
|
|
615 |
sales_quotation => 'quonumber',
|
|
616 |
purchase_order => 'ordnumber',
|
|
617 |
request_quotation => 'quonumber',
|
|
618 |
purchase_quotation_intake => 'quonumber',
|
|
616 |
SALES_ORDER_INTAKE_TYPE() => 'ordnumber',
|
|
617 |
SALES_ORDER_TYPE() => 'ordnumber',
|
|
618 |
SALES_QUOTATION_TYPE() => 'quonumber',
|
|
619 |
PURCHASE_ORDER_TYPE() => 'ordnumber',
|
|
620 |
REQUEST_QUOTATION_TYPE() => 'quonumber',
|
|
621 |
PURCHASE_QUOTATION_INTAKE_TYPE() => 'quonumber',
|
|
619 | 622 |
); |
620 | 623 |
|
621 | 624 |
return $self->${ \ $number_method{$self->type} }(@_); |
Auch abrufbar als: Unified diff
TypeData: nutzte Konstanten anstatt String für Typen