Revision e9eae881
Von Bernd Bleßmann vor fast 2 Jahren hinzugefügt
SL/Controller/Reclamation.pm | ||
---|---|---|
269 | 269 |
sub action_save { |
270 | 270 |
my ($self) = @_; |
271 | 271 |
|
272 |
my $errors = $self->save(); |
|
273 |
if (scalar @{ $errors }) { |
|
274 |
$self->js->flash('error', $_) foreach @{ $errors }; |
|
275 |
return $self->js->render(); |
|
276 |
} |
|
272 |
$self->save(); |
|
273 |
|
|
277 | 274 |
flash_later('info', t8('The reclamation has been saved')); |
278 | 275 |
|
279 | 276 |
my @redirect_params = ( |
... | ... | |
333 | 330 |
sub action_print { |
334 | 331 |
my ($self) = @_; |
335 | 332 |
|
336 |
$self->save_with_render_error();
|
|
333 |
$self->save(); |
|
337 | 334 |
|
338 | 335 |
$self->js_reset_reclamation_and_item_ids_after_save; |
339 | 336 |
|
... | ... | |
407 | 404 |
sub action_preview_pdf { |
408 | 405 |
my ($self) = @_; |
409 | 406 |
|
410 |
$self->save_with_render_error();
|
|
407 |
$self->save(); |
|
411 | 408 |
|
412 | 409 |
$self->js_reset_reclamation_and_item_ids_after_save; |
413 | 410 |
|
... | ... | |
449 | 446 |
sub action_save_and_show_email_dialog { |
450 | 447 |
my ($self) = @_; |
451 | 448 |
|
452 |
$self->save_with_render_error();
|
|
449 |
$self->save(); |
|
453 | 450 |
|
454 | 451 |
unless ($self->reclamation->customervendor) { |
455 | 452 |
return $self->js->flash('error', |
... | ... | |
502 | 499 |
sub action_send_email { |
503 | 500 |
my ($self) = @_; |
504 | 501 |
|
505 |
my $errors = $self->save(); |
|
506 |
|
|
507 |
if (scalar @{ $errors }) { |
|
502 |
eval { |
|
503 |
$self->save(); |
|
504 |
1; |
|
505 |
} or do { |
|
508 | 506 |
$self->js->run('kivi.Reclamation.close_email_dialog'); |
509 |
$self->js->flash('error', $_) foreach @{ $errors }; |
|
510 |
return $self->js->render(); |
|
511 |
} |
|
507 |
die $EVAL_ERROR; |
|
508 |
}; |
|
512 | 509 |
|
513 | 510 |
$self->js_reset_reclamation_and_item_ids_after_save; |
514 | 511 |
|
... | ... | |
588 | 585 |
my $to_type = $self->reclamation->is_sales ? SALES_ORDER_TYPE() |
589 | 586 |
: PURCHASE_ORDER_TYPE(); |
590 | 587 |
|
591 |
$self->save_with_render_error(); |
|
588 |
$self->save(); |
|
589 |
|
|
592 | 590 |
flash_later('info', t8('The reclamation has been saved')); |
593 | 591 |
$self->redirect_to( |
594 | 592 |
controller => 'Order', |
... | ... | |
602 | 600 |
sub action_save_and_sales_reclamation { |
603 | 601 |
my ($self) = @_; |
604 | 602 |
|
605 |
$self->save_with_render_error(); |
|
603 |
$self->save(); |
|
604 |
|
|
606 | 605 |
flash_later('info', t8('The reclamation has been saved')); |
607 | 606 |
$self->redirect_to( |
608 | 607 |
controller => 'Reclamation', |
... | ... | |
616 | 615 |
sub action_save_and_purchase_reclamation { |
617 | 616 |
my ($self) = @_; |
618 | 617 |
|
619 |
$self->save_with_render_error(); |
|
618 |
$self->save(); |
|
619 |
|
|
620 | 620 |
flash_later('info', t8('The reclamation has been saved')); |
621 | 621 |
$self->redirect_to( |
622 | 622 |
controller => 'Reclamation', |
... | ... | |
634 | 634 |
|
635 | 635 |
my $to_type = $self->reclamation->is_sales ? 'rma_delivery_order' |
636 | 636 |
: 'supplier_delivery_order'; |
637 |
$self->save_with_render_error(); |
|
637 |
$self->save(); |
|
638 |
|
|
638 | 639 |
flash_later('info', t8('The reclamation has been saved')); |
639 | 640 |
$self->redirect_to( |
640 | 641 |
controller => 'controller.pl', |
... | ... | |
650 | 651 |
my ($self) = @_; |
651 | 652 |
|
652 | 653 |
# always save |
653 |
$self->save_with_render_error();
|
|
654 |
$self->save(); |
|
654 | 655 |
|
655 | 656 |
if (!$self->reclamation->is_sales) { |
656 | 657 |
$self->js->flash('error', t8("Can't convert Purchase Reclamation to Credit Note")); |
657 | 658 |
return $self->js->render(); |
658 | 659 |
} |
659 | 660 |
|
660 |
$self->save_with_render_error(); |
|
661 | 661 |
flash_later('info', t8('The reclamation has been saved')); |
662 | 662 |
$self->redirect_to( |
663 | 663 |
controller => 'is.pl', |
... | ... | |
1705 | 1705 |
sub save { |
1706 | 1706 |
my ($self) = @_; |
1707 | 1707 |
|
1708 |
my $errors = []; |
|
1709 |
my $db = $self->reclamation->db; |
|
1710 |
|
|
1711 |
$db->with_transaction(sub { |
|
1712 |
my $validity_token; |
|
1713 |
if (!$self->reclamation->id) { |
|
1714 |
$validity_token = SL::DB::Manager::ValidityToken->fetch_valid_token( |
|
1715 |
scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE(), |
|
1716 |
token => $::form->{form_validity_token}, |
|
1717 |
); |
|
1718 |
|
|
1719 |
die $::locale->text('The form is not valid anymore.') if !$validity_token; |
|
1720 |
} |
|
1721 |
|
|
1722 |
# delete custom shipto if it is to be deleted or if it is empty |
|
1723 |
if ($self->reclamation->custom_shipto |
|
1724 |
&& ($self->is_custom_shipto_to_delete |
|
1725 |
|| $self->reclamation->custom_shipto->is_empty) |
|
1726 |
) { |
|
1727 |
$self->reclamation->custom_shipto->delete if $self->reclamation->custom_shipto->shipto_id; |
|
1728 |
$self->reclamation->custom_shipto(undef); |
|
1729 |
} |
|
1730 |
|
|
1731 |
SL::DB::ReclamationItem->new(id => $_)->delete for @{$self->item_ids_to_delete || []}; |
|
1732 |
$self->reclamation->save(cascade => 1); |
|
1733 |
|
|
1734 |
$self->save_history('SAVED'); |
|
1735 |
|
|
1736 |
$validity_token->delete if $validity_token; |
|
1737 |
delete $::form->{form_validity_token}; |
|
1738 |
|
|
1739 |
1; |
|
1740 |
}) || push(@{$errors}, $db->error); |
|
1708 |
my $items_to_delete = scalar @{ $self->item_ids_to_delete || [] } |
|
1709 |
? SL::DB::Manager::ReclamationItem->get_all(where => [id => $self->item_ids_to_delete]) |
|
1710 |
: undef; |
|
1741 | 1711 |
|
1742 |
return $errors; |
|
1743 |
} |
|
1744 |
|
|
1745 |
sub save_with_render_error { |
|
1746 |
my ($self) = @_; |
|
1747 |
|
|
1748 |
my $errors = $self->save(); |
|
1712 |
SL::Model::Record->save($self->order, |
|
1713 |
with_validity_token => { scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE(), token => $::form->{form_validity_token} }, |
|
1714 |
delete_custom_shipto => $self->is_custom_shipto_to_delete || $self->reclamation->custom_shipto->is_empty, |
|
1715 |
items_to_delete => $items_to_delete, |
|
1716 |
); |
|
1749 | 1717 |
|
1750 |
if (scalar @{ $errors }) { |
|
1751 |
$self->js->flash('error', $_) foreach @{ $errors }; |
|
1752 |
return $self->js->render(); |
|
1753 |
} |
|
1718 |
delete $::form->{form_validity_token}; |
|
1754 | 1719 |
} |
1755 | 1720 |
|
1756 | 1721 |
# sales → purchase or purchase → sales |
Auch abrufbar als: Unified diff
Reclamation-Controller: Model::Record->save verwenden