Revision c1ed1e91
Von Tamino Steinert vor mehr als 2 Jahren hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
61 | 61 |
except => [ qw(edit show_customer_vendor_details_dialog price_popup load_second_rows) ]); |
62 | 62 |
|
63 | 63 |
__PACKAGE__->run_before('recalc', |
64 |
only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment save_and_final_invoice save_and_ap_transaction |
|
64 |
only => [ qw(save save_as_new |
|
65 |
save_and_delivery_order |
|
66 |
save_and_reclamation |
|
67 |
save_and_invoice save_and_invoice_for_advance_payment save_and_final_invoice save_and_ap_transaction |
|
65 | 68 |
print send_email) ]); |
66 | 69 |
|
67 | 70 |
__PACKAGE__->run_before('get_unalterable_data', |
68 |
only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment save_and_final_invoice save_and_ap_transaction |
|
71 |
only => [ qw(save save_as_new |
|
72 |
save_and_delivery_order |
|
73 |
save_and_reclamation |
|
74 |
save_and_invoice save_and_invoice_for_advance_payment save_and_final_invoice save_and_ap_transaction |
|
69 | 75 |
print send_email) ]); |
70 | 76 |
|
71 | 77 |
# |
... | ... | |
95 | 101 |
); |
96 | 102 |
} |
97 | 103 |
|
104 |
sub action_add_from_reclamation { |
|
105 |
my ($self) = @_; |
|
106 |
|
|
107 |
require SL::DB::Reclamation; |
|
108 |
my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load; |
|
109 |
my $order = $reclamation->convert_to_order(); |
|
110 |
|
|
111 |
$self->order($order); |
|
112 |
|
|
113 |
$self->recalc(); |
|
114 |
$self->pre_render(); |
|
115 |
$self->render( |
|
116 |
'order/form', |
|
117 |
title => $self->get_title_for('edit'), |
|
118 |
%{$self->{template_args}} |
|
119 |
); |
|
120 |
} |
|
121 |
|
|
98 | 122 |
# edit an existing order |
99 | 123 |
sub action_edit { |
100 | 124 |
my ($self) = @_; |
... | ... | |
717 | 741 |
); |
718 | 742 |
} |
719 | 743 |
|
744 |
# save the order and redirect to the frontend subroutine for a new reclamation |
|
745 |
sub action_save_and_reclamation { |
|
746 |
my ($self) = @_; |
|
747 |
|
|
748 |
# cann't use save_and_redirect_to, because id is set! |
|
749 |
my $errors = $self->save(); |
|
750 |
if (scalar @{ $errors }) { |
|
751 |
$self->js->flash('error', $_) foreach @{ $errors }; |
|
752 |
return $self->js->render(); |
|
753 |
} |
|
754 |
|
|
755 |
my $to_type = $self->order->is_sales ? 'sales_reclamation' |
|
756 |
: 'purchase_reclamation'; |
|
757 |
$self->redirect_to( |
|
758 |
controller => 'Reclamation', |
|
759 |
action => 'add_from_order', |
|
760 |
type => $to_type, |
|
761 |
from_id => $self->order->id, |
|
762 |
); |
|
763 |
} |
|
764 |
|
|
720 | 765 |
# save the order and redirect to the frontend subroutine for a new |
721 | 766 |
# invoice |
722 | 767 |
sub action_save_and_invoice { |
... | ... | |
2147 | 2192 |
only_if => (any { $self->type eq $_ } (purchase_order_type())), |
2148 | 2193 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2149 | 2194 |
], |
2195 |
action => [ |
|
2196 |
t8('Save and Reclamation'), |
|
2197 |
call => [ 'kivi.Order.save', 'save_and_reclamation', $::instance_conf->get_order_warn_duplicate_parts ], |
|
2198 |
only_if => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type())) |
|
2199 |
], |
|
2150 | 2200 |
action => [ |
2151 | 2201 |
t8('Save and Invoice'), |
2152 | 2202 |
call => [ 'kivi.Order.save', 'save_and_invoice', $::instance_conf->get_order_warn_duplicate_parts ], |
SL/Controller/Reclamation.pm | ||
---|---|---|
68 | 68 |
save save_as_new print preview_pdf send_email |
69 | 69 |
save_and_show_email_dialog |
70 | 70 |
workflow_save_and_sales_or_purchase_reclamation |
71 |
save_and_order |
|
71 | 72 |
)]); |
72 | 73 |
|
73 | 74 |
__PACKAGE__->run_before('get_unalterable_data', |
... | ... | |
75 | 76 |
save save_as_new print preview_pdf send_email |
76 | 77 |
save_and_show_email_dialog |
77 | 78 |
workflow_save_and_sales_or_purchase_reclamation |
79 |
save_and_order |
|
78 | 80 |
)]); |
79 | 81 |
|
80 | 82 |
# |
... | ... | |
96 | 98 |
); |
97 | 99 |
} |
98 | 100 |
|
101 |
sub action_add_from_order { |
|
102 |
my ($self) = @_; |
|
103 |
|
|
104 |
unless ($::form->{from_id}) { |
|
105 |
$self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given.")); |
|
106 |
return $self->js->render(); |
|
107 |
} |
|
108 |
|
|
109 |
require SL::DB::Order; |
|
110 |
my $order = SL::DB::Order->new(id => $::form->{from_id})->load; |
|
111 |
my $reclamation = $order->convert_to_reclamation(); |
|
112 |
|
|
113 |
$self->reclamation($reclamation); |
|
114 |
|
|
115 |
$self->reinit_after_new_reclamation(); |
|
116 |
|
|
117 |
$self->render( |
|
118 |
'reclamation/form', |
|
119 |
title => $self->get_title_for('add'), |
|
120 |
%{$self->{template_args}}, |
|
121 |
); |
|
122 |
} |
|
123 |
|
|
99 | 124 |
# edit an existing reclamation |
100 | 125 |
sub action_edit { |
101 | 126 |
my ($self) = @_; |
... | ... | |
467 | 492 |
$self->redirect_to(@redirect_params); |
468 | 493 |
} |
469 | 494 |
|
495 |
sub action_save_and_order { |
|
496 |
my ($self) = @_; |
|
497 |
|
|
498 |
my $to_type = $self->reclamation->is_sales ? 'sales_order' |
|
499 |
: 'purchase_order'; |
|
500 |
$self->save_and_redirect_to( |
|
501 |
controller => 'Order', |
|
502 |
action => 'add_from_reclamation', |
|
503 |
type => $to_type, |
|
504 |
from_id => $self->reclamation->id, |
|
505 |
); |
|
506 |
} |
|
507 |
|
|
470 | 508 |
# workflow from purchase to sales reclamation |
471 | 509 |
sub action_save_and_sales_reclamation { |
472 | 510 |
$_[0]->workflow_save_and_sales_or_purchase_reclamation(); |
... | ... | |
1578 | 1616 |
my ($self) = @_; |
1579 | 1617 |
my %allowed_linked_records = map {$_ => 1} qw( |
1580 | 1618 |
SL::DB::Reclamation |
1619 |
SL::DB::Order |
|
1581 | 1620 |
); |
1582 | 1621 |
my %allowed_linked_record_items = map {$_ => 1} qw( |
1583 | 1622 |
SL::DB::ReclamationItem |
1623 |
SL::DB::OrderItem |
|
1584 | 1624 |
); |
1585 | 1625 |
|
1586 | 1626 |
my $from_record_id = delete $::form->{converted_from_record_id}; |
... | ... | |
2085 | 2125 |
call => [ 'kivi.Reclamation.purchase_reclamation_check_for_direct_delivery' ], |
2086 | 2126 |
only_if => (any { $self->type eq $_ } (sales_reclamation_type())), |
2087 | 2127 |
], |
2128 |
action => [ |
|
2129 |
t8('Save and Order'), |
|
2130 |
call => [ |
|
2131 |
'kivi.Reclamation.save', 'save_and_order', |
|
2132 |
$::instance_conf->get_reclamation_warn_duplicate_parts, |
|
2133 |
$::instance_conf->get_reclamation_warn_no_reqdate, |
|
2134 |
], |
|
2135 |
], |
|
2088 | 2136 |
], # end of combobox "Workflow" |
2089 | 2137 |
|
2090 | 2138 |
combobox => [ |
SL/DB/Order.pm | ||
---|---|---|
299 | 299 |
return $delivery_order; |
300 | 300 |
} |
301 | 301 |
|
302 |
sub convert_to_reclamation { |
|
303 |
my ($self, %params) = @_; |
|
304 |
$params{destination_type} = $self->is_sales ? 'sales_reclamation' |
|
305 |
: 'purchase_reclamation'; |
|
306 |
|
|
307 |
require SL::DB::Reclamation; |
|
308 |
my $reclamation = SL::DB::Reclamation->new_from($self, %params); |
|
309 |
|
|
310 |
return $reclamation; |
|
311 |
} |
|
312 |
|
|
302 | 313 |
sub _clone_orderitem_cvar { |
303 | 314 |
my ($cvar) = @_; |
304 | 315 |
|
... | ... | |
311 | 322 |
sub new_from { |
312 | 323 |
my ($class, $source, %params) = @_; |
313 | 324 |
|
314 |
croak("Unsupported source object type '" . ref($source) . "'") unless ref($source) eq 'SL::DB::Order'; |
|
325 |
unless (any {ref($source) eq $_} qw( |
|
326 |
SL::DB::Order |
|
327 |
SL::DB::Reclamation |
|
328 |
)) { |
|
329 |
croak("Unsupported source object type '" . ref($source) . "'"); |
|
330 |
} |
|
315 | 331 |
croak("A destination type must be given as parameter") unless $params{destination_type}; |
316 | 332 |
|
317 | 333 |
my $destination_type = delete $params{destination_type}; |
... | ... | |
327 | 343 |
{ from => 'purchase_order', to => 'sales_order', abbr => 'poso' }, |
328 | 344 |
{ from => 'sales_order', to => 'sales_quotation', abbr => 'sosq' }, |
329 | 345 |
{ from => 'purchase_order', to => 'request_quotation', abbr => 'porq' }, |
346 |
{ from => 'sales_reclamation', to => 'sales_order', abbr => 'srso' }, |
|
347 |
{ from => 'purchase_reclamation', to => 'purchase_order', abbr => 'prpo' }, |
|
330 | 348 |
); |
331 | 349 |
my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0]; |
332 | 350 |
croak("Cannot convert from '" . $source->type . "' to '" . $destination_type . "'") if !$from_to; |
... | ... | |
340 | 358 |
if (ref($source) eq 'SL::DB::Order') { |
341 | 359 |
$item_parent_id_column = 'trans_id'; |
342 | 360 |
$item_parent_column = 'order'; |
361 |
} elsif ( ref($source) eq 'SL::DB::Reclamation') { |
|
362 |
$item_parent_id_column = 'reclamation_id'; |
|
363 |
$item_parent_column = 'reclamation'; |
|
343 | 364 |
} |
344 | 365 |
|
345 |
my %args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id |
|
346 |
department_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes |
|
347 |
ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded tax_point taxzone_id |
|
348 |
transaction_description vendor_id billing_address_id |
|
349 |
)), |
|
350 |
quotation => !!($destination_type =~ m{quotation$}), |
|
351 |
closed => 0, |
|
352 |
delivered => 0, |
|
353 |
transdate => DateTime->today_local, |
|
354 |
employee => SL::DB::Manager::Employee->current, |
|
355 |
); |
|
366 |
my %args; |
|
367 |
if (ref($source) eq 'SL::DB::Order') { |
|
368 |
%args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id |
|
369 |
department_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes |
|
370 |
ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded tax_point taxzone_id |
|
371 |
transaction_description vendor_id billing_address_id |
|
372 |
)), |
|
373 |
quotation => !!($destination_type =~ m{quotation$}), |
|
374 |
closed => 0, |
|
375 |
delivered => 0, |
|
376 |
transdate => DateTime->today_local, |
|
377 |
employee => SL::DB::Manager::Employee->current, |
|
378 |
); |
|
379 |
} elsif ( ref($source) eq 'SL::DB::Reclamation') { |
|
380 |
#TODO(Tamino): add billing_address_id to reclamation |
|
381 |
%args = ( map({ ( $_ => $source->$_ ) } qw( |
|
382 |
amount currency_id customer_id delivery_term_id department_id |
|
383 |
exchangerate globalproject_id intnotes language_id netamount |
|
384 |
notes payment_id reqdate salesman_id shippingpoint shipvia taxincluded |
|
385 |
tax_point taxzone_id transaction_description vendor_id |
|
386 |
)), |
|
387 |
cp_id => $source->{contact_id}, |
|
388 |
closed => 0, |
|
389 |
delivered => 0, |
|
390 |
transdate => DateTime->today_local, |
|
391 |
employee => SL::DB::Manager::Employee->current, |
|
392 |
); |
|
393 |
} |
|
356 | 394 |
|
357 | 395 |
if ( $is_abbr_any->(qw(sopo poso)) ) { |
358 | 396 |
$args{ordnumber} = undef; |
... | ... | |
402 | 440 |
$item_parents{$source_item_id} ||= $source_item->$item_parent_column; |
403 | 441 |
my $item_parent = $item_parents{$source_item_id}; |
404 | 442 |
|
405 |
my $current_oe_item = SL::DB::OrderItem->new(map({ ( $_ => $source_item->$_ ) } |
|
406 |
qw(active_discount_source active_price_source base_qty cusordnumber |
|
407 |
description discount lastcost longdescription |
|
408 |
marge_percent marge_price_factor marge_total |
|
409 |
ordnumber parts_id price_factor price_factor_id pricegroup_id |
|
410 |
project_id qty reqdate sellprice serialnumber ship subtotal transdate unit |
|
411 |
optional |
|
412 |
)), |
|
413 |
custom_variables => \@custom_variables, |
|
414 |
); |
|
443 |
my $current_oe_item; |
|
444 |
if (ref($source) eq 'SL::DB::Order') { |
|
445 |
$current_oe_item = SL::DB::OrderItem->new(map({ ( $_ => $source_item->$_ ) } |
|
446 |
qw(active_discount_source active_price_source base_qty cusordnumber |
|
447 |
description discount lastcost longdescription |
|
448 |
marge_percent marge_price_factor marge_total |
|
449 |
ordnumber parts_id price_factor price_factor_id pricegroup_id |
|
450 |
project_id qty reqdate sellprice serialnumber ship subtotal transdate unit |
|
451 |
optional |
|
452 |
)), |
|
453 |
custom_variables => \@custom_variables, |
|
454 |
); |
|
455 |
} elsif (ref($source) eq 'SL::DB::Reclamation') { |
|
456 |
$current_oe_item = SL::DB::OrderItem->new( |
|
457 |
map({ ( $_ => $source_item->$_ ) } qw( |
|
458 |
active_discount_source active_price_source base_qty description |
|
459 |
discount lastcost longdescription parts_id price_factor |
|
460 |
price_factor_id pricegroup_id project_id qty reqdate sellprice |
|
461 |
serialnumber unit |
|
462 |
)), |
|
463 |
custom_variables => \@custom_variables, |
|
464 |
); |
|
465 |
} |
|
415 | 466 |
if ( $is_abbr_any->(qw(sopo)) ) { |
416 | 467 |
$current_oe_item->sellprice($source_item->lastcost); |
417 | 468 |
$current_oe_item->discount(0); |
... | ... | |
420 | 471 |
$current_oe_item->lastcost($source_item->sellprice); |
421 | 472 |
} |
422 | 473 |
$current_oe_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order'; |
474 |
$current_oe_item->{"converted_from_reclamation_item_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Reclamation'; |
|
423 | 475 |
$current_oe_item; |
424 | 476 |
} @{ $items }; |
425 | 477 |
|
SL/DB/Reclamation.pm | ||
---|---|---|
181 | 181 |
where => [ $valid_for_type => 1 ]); |
182 | 182 |
} |
183 | 183 |
|
184 |
sub convert_to_order { |
|
185 |
my ($self, %params) = @_; |
|
186 |
|
|
187 |
my $order; |
|
188 |
$params{destination_type} = $self->is_sales ? 'sales_order' |
|
189 |
: 'purchase_order'; |
|
190 |
if (!$self->db->with_transaction(sub { |
|
191 |
require SL::DB::Order; |
|
192 |
$order = SL::DB::Order->new_from($self, %params); |
|
193 |
$order->save; |
|
194 |
$self->link_to_record($order); |
|
195 |
foreach my $item (@{ $order->items }) { |
|
196 |
foreach (qw(reclamation_item)) { |
|
197 |
if ($item->{"converted_from_${_}_id"}) { |
|
198 |
die unless $item->{id}; |
|
199 |
RecordLinks->create_links('dbh' => $self->db->dbh, |
|
200 |
'mode' => 'ids', |
|
201 |
'from_table' => 'reclamation_items', |
|
202 |
'from_ids' => $item->{"converted_from_${_}_id"}, |
|
203 |
'to_table' => 'orderitems', |
|
204 |
'to_id' => $item->{id}, |
|
205 |
) || die; |
|
206 |
delete $item->{"converted_from_${_}_id"}; |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
1; |
|
212 |
})) { |
|
213 |
return undef; |
|
214 |
} |
|
215 |
|
|
216 |
return $order; |
|
217 |
} |
|
218 |
|
|
184 | 219 |
#TODO(Werner): überprüfen ob alle Felder richtig gestetzt werden |
185 | 220 |
sub new_from { |
186 | 221 |
my ($class, $source, %params) = @_; |
187 | 222 |
my %allowed_sources = map { $_ => 1 } qw( |
188 | 223 |
SL::DB::Reclamation |
224 |
SL::DB::Order |
|
189 | 225 |
); |
190 | 226 |
unless( $allowed_sources{ref $source} ) { |
191 | 227 |
croak("Unsupported source object type '" . ref($source) . "'"); |
... | ... | |
200 | 236 |
{ from => 'purchase_reclamation', to => 'purchase_reclamation', abbr => 'prpr', }, |
201 | 237 |
{ from => 'sales_reclamation', to => 'purchase_reclamation', abbr => 'srpr', }, |
202 | 238 |
{ from => 'purchase_reclamation', to => 'sales_reclamation', abbr => 'prsr', }, |
239 |
#Order |
|
240 |
{ from => 'sales_order', to => 'sales_reclamation', abbr => 'sosr', }, |
|
241 |
{ from => 'purchase_order', to => 'purchase_reclamation', abbr => 'popr', }, |
|
203 | 242 |
); |
204 | 243 |
my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0]; |
205 | 244 |
if (!$from_to) { |
... | ... | |
244 | 283 |
transaction_description |
245 | 284 |
vendor_id |
246 | 285 |
); # }}} for vim folds |
286 |
} elsif ( $is_abbr_any->(qw(sosr popr)) ) { #Order |
|
287 |
map { $record_args{$_} = $source->$_ } # {{{ for vim folds |
|
288 |
qw( |
|
289 |
amount |
|
290 |
currency_id |
|
291 |
customer_id |
|
292 |
delivery_term_id |
|
293 |
department_id |
|
294 |
exchangerate |
|
295 |
globalproject_id |
|
296 |
intnotes |
|
297 |
language_id |
|
298 |
netamount |
|
299 |
notes |
|
300 |
payment_id |
|
301 |
salesman_id |
|
302 |
shippingpoint |
|
303 |
shipvia |
|
304 |
tax_point |
|
305 |
taxincluded |
|
306 |
taxzone_id |
|
307 |
transaction_description |
|
308 |
vendor_id |
|
309 |
); |
|
310 |
$record_args{contact_id} = $source->cp_id; |
|
311 |
$record_args{cv_record_number} = $source->cusordnumber; |
|
312 |
# }}} for vim folds |
|
247 | 313 |
} |
248 | 314 |
|
249 | 315 |
if ( ($from_to->{from} =~ m{sales}) && ($from_to->{to} =~ m{purchase}) ) { |
SL/DB/ReclamationItem.pm | ||
---|---|---|
53 | 53 |
unless (any {ref($source) eq $_} |
54 | 54 |
qw( |
55 | 55 |
SL::DB::ReclamationItem |
56 |
SL::DB::OrderItem |
|
56 | 57 |
) |
57 | 58 |
) { |
58 | 59 |
croak("Unsupported source object type '" . ref($source) . "'"); |
... | ... | |
70 | 71 |
unit |
71 | 72 |
); |
72 | 73 |
$item_args{custom_variables} = \@custom_variables; |
74 |
} elsif (ref($source) eq 'SL::DB::OrderItem') { |
|
75 |
map { $item_args{$_} = $source->$_ } qw( |
|
76 |
active_discount_source active_price_source base_qty description discount |
|
77 |
lastcost longdescription parts_id position price_factor price_factor_id |
|
78 |
pricegroup_id project_id qty reqdate sellprice serialnumber unit |
|
79 |
); |
|
80 |
$item_args{custom_variables} = \@custom_variables; |
|
73 | 81 |
} |
74 | 82 |
|
75 | 83 |
my $item = $class->new(%item_args); |
Auch abrufbar als: Unified diff
Workflow: order ↔ reclamation