Revision 5bae603d
Von Tamino Steinert vor etwa 1 Jahr hinzugefügt
SL/Controller/Reclamation.pm | ||
---|---|---|
39 | 39 |
use SL::DB::DeliveryOrder; |
40 | 40 |
use SL::DB::Invoice; |
41 | 41 |
use SL::Model::Record; |
42 |
use SL::DB::Order::TypeData qw(:types); |
|
43 |
use SL::DB::Reclamation::TypeData qw(:types); |
|
42 | 44 |
|
43 | 45 |
use List::Util qw(first sum0); |
44 | 46 |
use List::UtilsBy qw(sort_by uniq_by); |
... | ... | |
123 | 125 |
} |
124 | 126 |
|
125 | 127 |
my $order = SL::DB::Order->new(id => $::form->{from_id})->load; |
126 |
my $target_type = $order->is_sales ? 'sales_reclamation'
|
|
127 |
: 'purchase_reclamation';
|
|
128 |
my $target_type = $order->is_sales ? SALES_RECLAMATION_TYPE()
|
|
129 |
: PURCHASE_RECLAMATION_TYPE();
|
|
128 | 130 |
my $reclamation = SL::Model::Record->new_from_workflow($order, $target_type); |
129 | 131 |
|
130 | 132 |
$self->reclamation($reclamation); |
... | ... | |
151 | 153 |
} |
152 | 154 |
|
153 | 155 |
my $delivery_order = SL::DB::DeliveryOrder->new(id => $::form->{from_id})->load; |
154 |
my $target_type = $delivery_order->is_sales ? 'sales_reclamation'
|
|
155 |
: 'purchase_reclamation';
|
|
156 |
my $target_type = $delivery_order->is_sales ? SALES_RECLAMATION_TYPE()
|
|
157 |
: PURCHASE_RECLAMATION_TYPE();
|
|
156 | 158 |
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $target_type); |
157 | 159 |
|
158 | 160 |
$self->reclamation($reclamation); |
... | ... | |
179 | 181 |
} |
180 | 182 |
|
181 | 183 |
my $invoice = SL::DB::Invoice->new(id => $::form->{from_id})->load; |
182 |
my $target_type = 'sales_reclamation';
|
|
184 |
my $target_type = SALES_RECLAMATION_TYPE();
|
|
183 | 185 |
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $target_type); |
184 | 186 |
|
185 | 187 |
$self->reclamation($reclamation); |
... | ... | |
208 | 210 |
require SL::DB::PurchaseInvoice; |
209 | 211 |
my $invoice = SL::DB::PurchaseInvoice->new(id => $::form->{from_id})->load; |
210 | 212 |
$invoice->{type} = $invoice->invoice_type; #can't add type → invoice_type in SL/DB/PurchaseInvoice |
211 |
my $target_type = 'purchase_reclamation';
|
|
213 |
my $target_type = PURCHASE_RECLAMATION_TYPE();
|
|
212 | 214 |
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $target_type); |
213 | 215 |
|
214 | 216 |
$self->reclamation($reclamation); |
... | ... | |
583 | 585 |
sub action_save_and_order { |
584 | 586 |
my ($self) = @_; |
585 | 587 |
|
586 |
my $to_type = $self->reclamation->is_sales ? 'sales_order'
|
|
587 |
: 'purchase_order';
|
|
588 |
my $to_type = $self->reclamation->is_sales ? SALES_ORDER_TYPE()
|
|
589 |
: PURCHASE_ORDER_TYPE();
|
|
588 | 590 |
|
589 | 591 |
$self->save_with_render_error(); |
590 | 592 |
flash_later('info', t8('The reclamation has been saved')); |
... | ... | |
606 | 608 |
controller => 'Reclamation', |
607 | 609 |
action => 'add_from_reclamation', |
608 | 610 |
from_id => $self->reclamation->id, |
609 |
type => sales_reclamation_type(),
|
|
611 |
type => SALES_RECLAMATION_TYPE(),
|
|
610 | 612 |
); |
611 | 613 |
} |
612 | 614 |
|
... | ... | |
620 | 622 |
controller => 'Reclamation', |
621 | 623 |
action => 'add_from_reclamation', |
622 | 624 |
from_id => $self->reclamation->id, |
623 |
type => purchase_reclamation_type(),
|
|
625 |
type => PURCHASE_RECLAMATION_TYPE(),
|
|
624 | 626 |
); |
625 | 627 |
} |
626 | 628 |
|
... | ... | |
1213 | 1215 |
# |
1214 | 1216 |
|
1215 | 1217 |
sub init_valid_types { |
1216 |
[ sales_reclamation_type(), purchase_reclamation_type() ];
|
|
1218 |
$_[0]->type_data->valid_types;
|
|
1217 | 1219 |
} |
1218 | 1220 |
|
1219 | 1221 |
sub init_type { |
... | ... | |
1229 | 1231 |
sub init_cv { |
1230 | 1232 |
my ($self) = @_; |
1231 | 1233 |
|
1232 |
my $cv = (any { $self->type eq $_ } (sales_reclamation_type())) ? 'customer'
|
|
1233 |
: (any { $self->type eq $_ } (purchase_reclamation_type())) ? 'vendor'
|
|
1234 |
my $cv = (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())) ? 'customer'
|
|
1235 |
: (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())) ? 'vendor'
|
|
1234 | 1236 |
: die "Not a valid type for reclamation"; |
1235 | 1237 |
|
1236 | 1238 |
return $cv; |
... | ... | |
1273 | 1275 |
language => t8('Language'), |
1274 | 1276 |
department => t8('Department'), |
1275 | 1277 |
globalproject => t8('Project Number'), |
1276 |
cv_record_number => ($self->type eq 'sales_reclamation' ? t8('Customer Record Number') : t8('Vendor Record Number')),
|
|
1278 |
cv_record_number => ($self->type eq SALES_RECLAMATION_TYPE() ? t8('Customer Record Number') : t8('Vendor Record Number')),
|
|
1277 | 1279 |
transaction_description => t8('Description'), |
1278 | 1280 |
notes => t8('Notes'), |
1279 | 1281 |
intnotes => t8('Internal Notes'), |
... | ... | |
1325 | 1327 |
|
1326 | 1328 |
sub init_part_picker_classification_ids { |
1327 | 1329 |
my ($self) = @_; |
1328 |
my $attribute = 'used_for_' . ($self->type eq sales_reclamation_type() ? 'sale' : 'purchase');
|
|
1330 |
my $attribute = 'used_for_' . ($self->type eq SALES_RECLAMATION_TYPE() ? 'sale' : 'purchase');
|
|
1329 | 1331 |
|
1330 | 1332 |
return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => [ $attribute => 1 ]) } ]; |
1331 | 1333 |
} |
... | ... | |
1778 | 1780 |
|
1779 | 1781 |
# check for direct delivery |
1780 | 1782 |
# copy shipto in custom shipto (custom shipto will be copied by new_from() in case) |
1781 |
if ($::form->{type} eq purchase_reclamation_type()) {
|
|
1783 |
if ($::form->{type} eq PURCHASE_RECLAMATION_TYPE()) {
|
|
1782 | 1784 |
if ($::form->{use_shipto}) { |
1783 | 1785 |
my $custom_shipto = $source_reclamation->shipto->clone('SL::DB::Reclamation'); |
1784 | 1786 |
$self->reclamation->custom_shipto($custom_shipto) if $custom_shipto; |
... | ... | |
2070 | 2072 |
sub => sub { $_[0]->closed ? t8('Yes') : t8('No') }, |
2071 | 2073 |
}, |
2072 | 2074 |
); |
2073 |
if ($self->type eq sales_reclamation_type()) {
|
|
2075 |
if ($self->type eq SALES_RECLAMATION_TYPE()) {
|
|
2074 | 2076 |
$column_defs{customer} = ({ |
2075 | 2077 |
raw_data => sub { $_[0]->customervendor->presenter->customer(display => 'table-cell', callback => $callback) }, |
2076 | 2078 |
sub => sub { $_[0]->customervendor->name }, |
... | ... | |
2085 | 2087 |
}, |
2086 | 2088 |
sub => sub { $_[0]->contact ? $_[0]->contact->cp_name : '' }, |
2087 | 2089 |
}); |
2088 |
} elsif ($self->type eq purchase_reclamation_type()) {
|
|
2090 |
} elsif ($self->type eq PURCHASE_RECLAMATION_TYPE()) {
|
|
2089 | 2091 |
$column_defs{vendor} = ({ |
2090 | 2092 |
raw_data => sub { $_[0]->customervendor->presenter->vendor(display => 'table-cell', callback => $callback) }, |
2091 | 2093 |
sub => sub { $_[0]->customervendor->name }, |
... | ... | |
2147 | 2149 |
{ output => 0 }, |
2148 | 2150 |
models => $self->models |
2149 | 2151 |
), |
2150 |
title => $self->type eq sales_reclamation_type() ? t8('Sales Reclamations') : t8('Purchase Reclamations'),
|
|
2152 |
title => $self->type eq SALES_RECLAMATION_TYPE() ? t8('Sales Reclamations') : t8('Purchase Reclamations'),
|
|
2151 | 2153 |
allow_pdf_export => 1, |
2152 | 2154 |
allow_csv_export => 1, |
2153 | 2155 |
); |
... | ... | |
2162 | 2164 |
sub _setup_edit_action_bar { |
2163 | 2165 |
my ($self, %params) = @_; |
2164 | 2166 |
|
2165 |
my $deletion_allowed = ($self->type eq sales_reclamation_type()
|
|
2167 |
my $deletion_allowed = ($self->type eq SALES_RECLAMATION_TYPE()
|
|
2166 | 2168 |
&& $::instance_conf->get_sales_reclamation_show_delete) |
2167 |
|| ($self->type eq purchase_reclamation_type()
|
|
2169 |
|| ($self->type eq PURCHASE_RECLAMATION_TYPE()
|
|
2168 | 2170 |
&& $::instance_conf->get_purchase_reclamation_show_delete); |
2169 | 2171 |
|
2170 | 2172 |
for my $bar ($::request->layout->get('actionbar')) { |
... | ... | |
2202 | 2204 |
$::instance_conf->get_reclamation_warn_duplicate_parts, |
2203 | 2205 |
$::instance_conf->get_reclamation_warn_no_reqdate, |
2204 | 2206 |
], |
2205 |
only_if => (any { $self->type eq $_ } (purchase_reclamation_type())),
|
|
2207 |
only_if => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
|
|
2206 | 2208 |
], |
2207 | 2209 |
action => [ |
2208 | 2210 |
t8('Save and Purchase Reclamation'), |
2209 | 2211 |
call => [ 'kivi.Reclamation.purchase_reclamation_check_for_direct_delivery' ], |
2210 |
only_if => (any { $self->type eq $_ } (sales_reclamation_type())),
|
|
2212 |
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
|
|
2211 | 2213 |
], |
2212 | 2214 |
action => [ |
2213 | 2215 |
t8('Save and Order'), |
... | ... | |
2224 | 2226 |
$::instance_conf->get_reclamation_warn_duplicate_parts, |
2225 | 2227 |
$::instance_conf->get_reclamation_warn_no_reqdate, |
2226 | 2228 |
], |
2227 |
only_if => (any { $self->type eq $_ } (sales_reclamation_type())),
|
|
2229 |
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
|
|
2228 | 2230 |
], |
2229 | 2231 |
action => [ |
2230 | 2232 |
t8('Save and Supplier Delivery Order'), |
... | ... | |
2233 | 2235 |
$::instance_conf->get_reclamation_warn_duplicate_parts, |
2234 | 2236 |
$::instance_conf->get_reclamation_warn_no_reqdate, |
2235 | 2237 |
], |
2236 |
only_if => (any { $self->type eq $_ } (purchase_reclamation_type())),
|
|
2238 |
only_if => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
|
|
2237 | 2239 |
], |
2238 | 2240 |
action => [ |
2239 | 2241 |
t8('Save and Credit Note'), |
... | ... | |
2242 | 2244 |
$::instance_conf->get_reclamation_warn_duplicate_parts, |
2243 | 2245 |
$::instance_conf->get_reclamation_warn_no_reqdate, |
2244 | 2246 |
], |
2245 |
only_if => (any { $self->type eq $_ } (sales_reclamation_type())),
|
|
2247 |
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
|
|
2246 | 2248 |
], |
2247 | 2249 |
], # end of combobox "Workflow" |
2248 | 2250 |
|
... | ... | |
2458 | 2460 |
# t8("Edit Purchase Reclamation"); |
2459 | 2461 |
|
2460 | 2462 |
$action = ucfirst(lc($action)); |
2461 |
return $self->type eq sales_reclamation_type() ? t8("$action Sales Reclamation")
|
|
2462 |
: $self->type eq purchase_reclamation_type() ? t8("$action Purchase Reclamation")
|
|
2463 |
return $self->type eq SALES_RECLAMATION_TYPE() ? t8("$action Sales Reclamation")
|
|
2464 |
: $self->type eq PURCHASE_RECLAMATION_TYPE() ? t8("$action Purchase Reclamation")
|
|
2463 | 2465 |
: ''; |
2464 | 2466 |
} |
2465 | 2467 |
|
... | ... | |
2502 | 2504 |
return $texts; |
2503 | 2505 |
} |
2504 | 2506 |
|
2505 |
sub sales_reclamation_type { |
|
2506 |
'sales_reclamation'; |
|
2507 |
} |
|
2508 |
|
|
2509 |
sub purchase_reclamation_type { |
|
2510 |
'purchase_reclamation'; |
|
2511 |
} |
|
2512 |
|
|
2513 | 2507 |
sub save_history { |
2514 | 2508 |
my ($self, $addition) = @_; |
2515 | 2509 |
|
... | ... | |
2563 | 2557 |
} |
2564 | 2558 |
|
2565 | 2559 |
sub init_type_data { |
2566 |
SL::DB::Helper::TypeDataProxy->new('SL::DB::Reclamation', $_[0]->type);
|
|
2560 |
SL::DB::Helper::TypeDataProxy->new('SL::DB::Reclamation', $::form->{type});
|
|
2567 | 2561 |
} |
2568 | 2562 |
|
2569 | 2563 |
1; |
Auch abrufbar als: Unified diff
TypeData: nutzte Konstanten anstatt String für Typen