Revision 461ffe0b
Von Bernd Bleßmann vor etwa 1 Jahr 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', |
... | ... | |
1711 | 1711 |
sub save { |
1712 | 1712 |
my ($self) = @_; |
1713 | 1713 |
|
1714 |
my $errors = []; |
|
1715 |
my $db = $self->reclamation->db; |
|
1716 |
|
|
1717 | 1714 |
if (scalar @{$self->reclamation->items} == 0 && !grep { $self->type eq $_ } @{$::instance_conf->get_allowed_documents_with_no_positions() || []}) { |
1718 | 1715 |
return [t8('The action you\'ve chosen has not been executed because the document does not contain any item yet.')]; |
1719 | 1716 |
} |
1720 | 1717 |
|
1721 |
$db->with_transaction(sub { |
|
1722 |
my $validity_token; |
|
1723 |
if (!$self->reclamation->id) { |
|
1724 |
$validity_token = SL::DB::Manager::ValidityToken->fetch_valid_token( |
|
1725 |
scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE(), |
|
1726 |
token => $::form->{form_validity_token}, |
|
1727 |
); |
|
1718 |
my $items_to_delete = scalar @{ $self->item_ids_to_delete || [] } |
|
1719 |
? SL::DB::Manager::ReclamationItem->get_all(where => [id => $self->item_ids_to_delete]) |
|
1720 |
: undef; |
|
1728 | 1721 |
|
1729 |
die $::locale->text('The form is not valid anymore.') if !$validity_token; |
|
1730 |
} |
|
1731 |
|
|
1732 |
# delete custom shipto if it is to be deleted or if it is empty |
|
1733 |
if ($self->reclamation->custom_shipto |
|
1734 |
&& ($self->is_custom_shipto_to_delete |
|
1735 |
|| $self->reclamation->custom_shipto->is_empty) |
|
1736 |
) { |
|
1737 |
$self->reclamation->custom_shipto->delete if $self->reclamation->custom_shipto->shipto_id; |
|
1738 |
$self->reclamation->custom_shipto(undef); |
|
1739 |
} |
|
1740 |
|
|
1741 |
SL::DB::ReclamationItem->new(id => $_)->delete for @{$self->item_ids_to_delete || []}; |
|
1742 |
$self->reclamation->save(cascade => 1); |
|
1743 |
|
|
1744 |
$self->save_history('SAVED'); |
|
1745 |
|
|
1746 |
$validity_token->delete if $validity_token; |
|
1747 |
delete $::form->{form_validity_token}; |
|
1748 |
|
|
1749 |
1; |
|
1750 |
}) || push(@{$errors}, $db->error); |
|
1751 |
|
|
1752 |
return $errors; |
|
1753 |
} |
|
1754 |
|
|
1755 |
sub save_with_render_error { |
|
1756 |
my ($self) = @_; |
|
1757 |
|
|
1758 |
my $errors = $self->save(); |
|
1722 |
SL::Model::Record->save($self->order, |
|
1723 |
with_validity_token => { scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE(), token => $::form->{form_validity_token} }, |
|
1724 |
delete_custom_shipto => $self->is_custom_shipto_to_delete || $self->reclamation->custom_shipto->is_empty, |
|
1725 |
items_to_delete => $items_to_delete, |
|
1726 |
); |
|
1759 | 1727 |
|
1760 |
if (scalar @{ $errors }) { |
|
1761 |
$self->js->flash('error', $_) foreach @{ $errors }; |
|
1762 |
$self->js->render(); |
|
1763 |
$::dispatcher->end_request; |
|
1764 |
} |
|
1728 |
delete $::form->{form_validity_token}; |
|
1765 | 1729 |
} |
1766 | 1730 |
|
1767 | 1731 |
# sales → purchase or purchase → sales |
Auch abrufbar als: Unified diff
Reclamation-Controller: Model::Record->save verwenden