Revision a3844d90
Von Tamino Steinert vor etwa 1 Jahr hinzugefügt
SL/Controller/Reclamation.pm | ||
---|---|---|
27 | 27 |
use SL::DB::ValidityToken; |
28 | 28 |
use SL::DB::Helper::RecordLink qw(RECORD_ID RECORD_TYPE_REF RECORD_ITEM_ID RECORD_ITEM_TYPE_REF); |
29 | 29 |
use SL::DB::Helper::TypeDataProxy; |
30 |
use SL::DB::Helper::Record qw(get_object_name_from_type get_class_from_type); |
|
30 | 31 |
|
31 | 32 |
use SL::Helper::CreatePDF qw(:all); |
32 | 33 |
use SL::Helper::PrintOptions; |
... | ... | |
67 | 68 |
only => [qw( |
68 | 69 |
save save_as_new print preview_pdf send_email |
69 | 70 |
save_and_show_email_dialog |
70 |
workflow_save_and_sales_or_purchase_reclamation |
|
71 |
save_and_order |
|
72 |
save_and_delivery_order |
|
71 |
save_and_new_record |
|
73 | 72 |
save_and_credit_note |
74 | 73 |
)]); |
75 | 74 |
|
... | ... | |
77 | 76 |
only => [qw( |
78 | 77 |
save save_as_new print preview_pdf send_email |
79 | 78 |
save_and_show_email_dialog |
80 |
workflow_save_and_sales_or_purchase_reclamation |
|
81 |
save_and_order |
|
82 |
save_and_delivery_order |
|
79 |
save_and_new_record |
|
83 | 80 |
save_and_credit_note |
84 | 81 |
)]); |
85 | 82 |
|
... | ... | |
87 | 84 |
only => [qw( |
88 | 85 |
save save_as_new print preview_pdf send_email |
89 | 86 |
save_and_show_email_dialog |
90 |
workflow_save_and_sales_or_purchase_reclamation |
|
91 |
save_and_order |
|
92 |
save_and_delivery_order |
|
87 |
save_and_new_record |
|
93 | 88 |
save_and_credit_note |
94 | 89 |
)]); |
95 | 90 |
|
... | ... | |
116 | 111 |
); |
117 | 112 |
} |
118 | 113 |
|
119 |
sub action_add_from_order {
|
|
114 |
sub action_add_from_record {
|
|
120 | 115 |
my ($self) = @_; |
116 |
my $from_type = $::form->{from_type}; |
|
117 |
my $from_id = $::form->{from_id}; |
|
121 | 118 |
|
122 |
unless ($::form->{from_id}) { |
|
123 |
$self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given.")); |
|
119 |
unless ($from_type && $from_id) { |
|
120 |
$self->js->flash('error', t8("Can't create new record.")); |
|
121 |
$self->js->flash('error', t8("No 'from_type' was given.")) unless ($from_type); |
|
122 |
$self->js->flash('error', t8("No 'from_id' was given.")) unless ($from_id); |
|
124 | 123 |
return $self->js->render(); |
125 | 124 |
} |
126 | 125 |
|
127 |
my $order = SL::DB::Order->new(id => $::form->{from_id})->load; |
|
128 |
my $reclamation = SL::Model::Record->new_from_workflow($order, $self->type); |
|
129 |
|
|
130 |
$self->reclamation($reclamation); |
|
131 |
|
|
132 |
$self->reinit_after_new_reclamation(); |
|
133 |
|
|
134 |
if (!$::form->{form_validity_token}) { |
|
135 |
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token; |
|
136 |
} |
|
137 |
|
|
138 |
$self->render( |
|
139 |
'reclamation/form', |
|
140 |
title => $self->type_data->text('add'), |
|
141 |
%{$self->{template_args}}, |
|
142 |
); |
|
143 |
} |
|
144 |
|
|
145 |
sub action_add_from_delivery_order { |
|
146 |
my ($self) = @_; |
|
147 |
|
|
148 |
unless ($::form->{from_id}) { |
|
149 |
$self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given.")); |
|
150 |
return $self->js->render(); |
|
151 |
} |
|
152 |
|
|
153 |
my $delivery_order = SL::DB::DeliveryOrder->new(id => $::form->{from_id})->load; |
|
154 |
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $self->type); |
|
155 |
|
|
126 |
my $record = SL::Model::Record->get_record($from_type, $from_id); |
|
127 |
my $reclamation = SL::Model::Record->new_from_workflow($record, $self->type); |
|
156 | 128 |
$self->reclamation($reclamation); |
157 | 129 |
|
158 |
$self->reinit_after_new_reclamation(); |
|
159 |
|
|
160 |
if (!$::form->{form_validity_token}) { |
|
161 |
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token; |
|
162 |
} |
|
163 |
|
|
164 |
$self->render( |
|
165 |
'reclamation/form', |
|
166 |
title => $self->type_data->text('add'), |
|
167 |
%{$self->{template_args}}, |
|
168 |
); |
|
169 |
} |
|
170 |
|
|
171 |
sub action_add_from_sales_invoice { |
|
172 |
my ($self) = @_; |
|
173 |
|
|
174 |
unless ($::form->{from_id}) { |
|
175 |
$self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given.")); |
|
176 |
return $self->js->render(); |
|
177 |
} |
|
178 |
|
|
179 |
my $invoice = SL::DB::Invoice->new(id => $::form->{from_id})->load; |
|
180 |
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $self->type); |
|
181 |
|
|
182 |
$self->reclamation($reclamation); |
|
183 |
|
|
184 |
$self->reinit_after_new_reclamation(); |
|
185 |
|
|
186 |
if (!$::form->{form_validity_token}) { |
|
187 |
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token; |
|
188 |
} |
|
189 |
|
|
190 |
$self->render( |
|
191 |
'reclamation/form', |
|
192 |
title => $self->type_data->text('add'), |
|
193 |
%{$self->{template_args}}, |
|
194 |
); |
|
195 |
} |
|
196 |
|
|
197 |
sub action_add_from_purchase_invoice { |
|
198 |
my ($self) = @_; |
|
199 |
|
|
200 |
unless ($::form->{from_id}) { |
|
201 |
$self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given.")); |
|
202 |
return $self->js->render(); |
|
130 |
if ($record->type eq SALES_RECLAMATION_TYPE()) { # check for direct delivery |
|
131 |
# copy shipto in custom shipto (custom shipto will be copied by new_from() in case) |
|
132 |
if ($::form->{use_shipto}) { |
|
133 |
my $custom_shipto = $record->shipto->clone('SL::DB::Reclamation'); |
|
134 |
$self->reclamation->custom_shipto($custom_shipto) if $custom_shipto; |
|
135 |
} else { |
|
136 |
# remove any custom shipto if not wanted |
|
137 |
$self->reclamation->custom_shipto(SL::DB::Shipto->new(module => 'RC', custom_variables => [])); |
|
138 |
} |
|
203 | 139 |
} |
204 | 140 |
|
205 |
require SL::DB::PurchaseInvoice; |
|
206 |
my $invoice = SL::DB::PurchaseInvoice->new(id => $::form->{from_id})->load; |
|
207 |
$invoice->{type} = $invoice->invoice_type; #can't add type → invoice_type in SL/DB/PurchaseInvoice |
|
208 |
my $reclamation = SL::Model::Record->new_from_workflow($invoice, ref($self->reclamaiton), $self->type); |
|
209 |
|
|
210 |
$self->reclamation($reclamation); |
|
211 |
|
|
212 | 141 |
$self->reinit_after_new_reclamation(); |
213 | 142 |
|
214 | 143 |
if (!$::form->{form_validity_token}) { |
... | ... | |
573 | 502 |
$self->redirect_to(@redirect_params); |
574 | 503 |
} |
575 | 504 |
|
576 |
sub action_save_and_order { |
|
577 |
my ($self) = @_; |
|
578 |
|
|
579 |
my $to_type = $self->reclamation->is_sales ? SALES_ORDER_TYPE() |
|
580 |
: PURCHASE_ORDER_TYPE(); |
|
581 |
|
|
582 |
$self->save(); |
|
583 |
|
|
584 |
flash_later('info', t8('The reclamation has been saved')); |
|
585 |
$self->redirect_to( |
|
586 |
controller => 'Order', |
|
587 |
action => 'add_from_reclamation', |
|
588 |
type => $to_type, |
|
589 |
from_id => $self->reclamation->id, |
|
590 |
); |
|
591 |
} |
|
592 |
|
|
593 |
# workflow from purchase to sales reclamation |
|
594 |
sub action_save_and_sales_reclamation { |
|
505 |
sub action_save_and_new_record { |
|
595 | 506 |
my ($self) = @_; |
507 |
my $to_type = $::form->{to_type}; |
|
508 |
my $to_controller = get_object_name_from_type($to_type); |
|
596 | 509 |
|
597 | 510 |
$self->save(); |
598 |
|
|
599 | 511 |
flash_later('info', t8('The reclamation has been saved')); |
600 |
$self->redirect_to( |
|
601 |
controller => 'Reclamation', |
|
602 |
action => 'add_from_reclamation', |
|
603 |
from_id => $self->reclamation->id, |
|
604 |
type => SALES_RECLAMATION_TYPE(), |
|
605 |
); |
|
606 |
} |
|
607 |
|
|
608 |
# workflow from sales to purchase reclamation |
|
609 |
sub action_save_and_purchase_reclamation { |
|
610 |
my ($self) = @_; |
|
611 |
|
|
612 |
$self->save(); |
|
613 | 512 |
|
614 |
flash_later('info', t8('The reclamation has been saved')); |
|
615 | 513 |
$self->redirect_to( |
616 |
controller => 'Reclamation', |
|
617 |
action => 'add_from_reclamation', |
|
618 |
from_id => $self->reclamation->id, |
|
619 |
type => PURCHASE_RECLAMATION_TYPE(), |
|
620 |
); |
|
621 |
} |
|
622 |
|
|
623 |
# save the reclamation and redirect to the frontend subroutine for a new |
|
624 |
# delivery order |
|
625 |
|
|
626 |
sub action_save_and_delivery_order { |
|
627 |
my ($self) = @_; |
|
628 |
|
|
629 |
my $to_type = $self->reclamation->is_sales ? 'rma_delivery_order' |
|
630 |
: 'supplier_delivery_order'; |
|
631 |
$self->save(); |
|
632 |
|
|
633 |
flash_later('info', t8('The reclamation has been saved')); |
|
634 |
$self->redirect_to( |
|
635 |
controller => 'controller.pl', |
|
636 |
action => 'DeliveryOrder/add_from_reclamation', |
|
514 |
controller => $to_controller, |
|
515 |
action => 'add_from_record', |
|
637 | 516 |
type => $to_type, |
638 | 517 |
from_id => $self->reclamation->id, |
518 |
from_type => $self->reclamation->type, |
|
639 | 519 |
); |
640 | 520 |
} |
641 | 521 |
|
... | ... | |
1718 | 1598 |
delete $::form->{form_validity_token}; |
1719 | 1599 |
} |
1720 | 1600 |
|
1721 |
# sales → purchase or purchase → sales |
|
1722 |
sub action_add_from_reclamation { |
|
1723 |
my ($self) = @_; |
|
1724 |
|
|
1725 |
my $destination_type = $::form->{destination_type}; |
|
1726 |
|
|
1727 |
my $source_reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load; |
|
1728 |
|
|
1729 |
$self->reclamation( |
|
1730 |
SL::DB::Reclamation->new_from( |
|
1731 |
$source_reclamation, |
|
1732 |
destination_type => $::form->{type}, |
|
1733 |
)); |
|
1734 |
|
|
1735 |
# check for direct delivery |
|
1736 |
# copy shipto in custom shipto (custom shipto will be copied by new_from() in case) |
|
1737 |
if (!$self->type_data->properties('is_customer')) { |
|
1738 |
if ($::form->{use_shipto}) { |
|
1739 |
my $custom_shipto = $source_reclamation->shipto->clone('SL::DB::Reclamation'); |
|
1740 |
$self->reclamation->custom_shipto($custom_shipto) if $custom_shipto; |
|
1741 |
} else { |
|
1742 |
# remove any custom shipto if not wanted |
|
1743 |
$self->reclamation->custom_shipto(SL::DB::Shipto->new(module => 'RC', custom_variables => [])); |
|
1744 |
} |
|
1745 |
} |
|
1746 |
|
|
1747 |
$self->reinit_after_new_reclamation(); |
|
1748 |
|
|
1749 |
if (!$::form->{form_validity_token}) { |
|
1750 |
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token; |
|
1751 |
} |
|
1752 |
|
|
1753 |
$self->render( |
|
1754 |
'reclamation/form', |
|
1755 |
title => $self->type_data->text('add'), |
|
1756 |
%{$self->{template_args}} |
|
1757 |
); |
|
1758 |
} |
|
1759 |
|
|
1760 | 1601 |
sub reinit_after_new_reclamation { |
1761 | 1602 |
my ($self) = @_; |
1762 | 1603 |
|
Auch abrufbar als: Unified diff
Records: Workflow-Methoden angepasst und vereinheitlicht