Revision ac05693f
Von Tamino Steinert vor mehr als 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_id => t8('Language'), |
1274 | 1276 |
department_id => t8('Department'), |
1275 | 1277 |
globalproject_id => 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'), |
... | ... | |
1319 | 1321 |
|
1320 | 1322 |
sub init_part_picker_classification_ids { |
1321 | 1323 |
my ($self) = @_; |
1322 |
my $attribute = 'used_for_' . ($self->type eq sales_reclamation_type() ? 'sale' : 'purchase');
|
|
1324 |
my $attribute = 'used_for_' . ($self->type eq SALES_RECLAMATION_TYPE() ? 'sale' : 'purchase');
|
|
1323 | 1325 |
|
1324 | 1326 |
return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => [ $attribute => 1 ]) } ]; |
1325 | 1327 |
} |
... | ... | |
1767 | 1769 |
|
1768 | 1770 |
# check for direct delivery |
1769 | 1771 |
# copy shipto in custom shipto (custom shipto will be copied by new_from() in case) |
1770 |
if ($::form->{type} eq purchase_reclamation_type()) {
|
|
1772 |
if ($::form->{type} eq PURCHASE_RECLAMATION_TYPE()) {
|
|
1771 | 1773 |
if ($::form->{use_shipto}) { |
1772 | 1774 |
my $custom_shipto = $source_reclamation->shipto->clone('SL::DB::Reclamation'); |
1773 | 1775 |
$self->reclamation->custom_shipto($custom_shipto) if $custom_shipto; |
... | ... | |
2059 | 2061 |
sub => sub { $_[0]->closed ? t8('Yes') : t8('No') }, |
2060 | 2062 |
}, |
2061 | 2063 |
); |
2062 |
if ($self->type eq sales_reclamation_type()) {
|
|
2064 |
if ($self->type eq SALES_RECLAMATION_TYPE()) {
|
|
2063 | 2065 |
$column_defs{customer_id} = ({ |
2064 | 2066 |
raw_data => sub { $_[0]->customervendor->presenter->customer(display => 'table-cell', callback => $callback) }, |
2065 | 2067 |
sub => sub { $_[0]->customervendor->name }, |
... | ... | |
2074 | 2076 |
}, |
2075 | 2077 |
sub => sub { $_[0]->contact ? $_[0]->contact->cp_name : '' }, |
2076 | 2078 |
}); |
2077 |
} elsif ($self->type eq purchase_reclamation_type()) {
|
|
2079 |
} elsif ($self->type eq PURCHASE_RECLAMATION_TYPE()) {
|
|
2078 | 2080 |
$column_defs{vendor_id} = ({ |
2079 | 2081 |
raw_data => sub { $_[0]->customervendor->presenter->vendor(display => 'table-cell', callback => $callback) }, |
2080 | 2082 |
sub => sub { $_[0]->customervendor->name }, |
... | ... | |
2135 | 2137 |
{ output => 0 }, |
2136 | 2138 |
models => $self->models |
2137 | 2139 |
), |
2138 |
title => $self->type eq sales_reclamation_type() ? t8('Sales Reclamations') : t8('Purchase Reclamations'),
|
|
2140 |
title => $self->type eq SALES_RECLAMATION_TYPE() ? t8('Sales Reclamations') : t8('Purchase Reclamations'),
|
|
2139 | 2141 |
allow_pdf_export => 1, |
2140 | 2142 |
allow_csv_export => 1, |
2141 | 2143 |
); |
... | ... | |
2150 | 2152 |
sub _setup_edit_action_bar { |
2151 | 2153 |
my ($self, %params) = @_; |
2152 | 2154 |
|
2153 |
my $deletion_allowed = ($self->type eq sales_reclamation_type()
|
|
2155 |
my $deletion_allowed = ($self->type eq SALES_RECLAMATION_TYPE()
|
|
2154 | 2156 |
&& $::instance_conf->get_sales_reclamation_show_delete) |
2155 |
|| ($self->type eq purchase_reclamation_type()
|
|
2157 |
|| ($self->type eq PURCHASE_RECLAMATION_TYPE()
|
|
2156 | 2158 |
&& $::instance_conf->get_purchase_reclamation_show_delete); |
2157 | 2159 |
|
2158 | 2160 |
for my $bar ($::request->layout->get('actionbar')) { |
... | ... | |
2190 | 2192 |
$::instance_conf->get_reclamation_warn_duplicate_parts, |
2191 | 2193 |
$::instance_conf->get_reclamation_warn_no_reqdate, |
2192 | 2194 |
], |
2193 |
only_if => (any { $self->type eq $_ } (purchase_reclamation_type())),
|
|
2195 |
only_if => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
|
|
2194 | 2196 |
], |
2195 | 2197 |
action => [ |
2196 | 2198 |
t8('Save and Purchase Reclamation'), |
2197 | 2199 |
call => [ 'kivi.Reclamation.purchase_reclamation_check_for_direct_delivery' ], |
2198 |
only_if => (any { $self->type eq $_ } (sales_reclamation_type())),
|
|
2200 |
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
|
|
2199 | 2201 |
], |
2200 | 2202 |
action => [ |
2201 | 2203 |
t8('Save and Order'), |
... | ... | |
2212 | 2214 |
$::instance_conf->get_reclamation_warn_duplicate_parts, |
2213 | 2215 |
$::instance_conf->get_reclamation_warn_no_reqdate, |
2214 | 2216 |
], |
2215 |
only_if => (any { $self->type eq $_ } (sales_reclamation_type())),
|
|
2217 |
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
|
|
2216 | 2218 |
], |
2217 | 2219 |
action => [ |
2218 | 2220 |
t8('Save and Supplier Delivery Order'), |
... | ... | |
2221 | 2223 |
$::instance_conf->get_reclamation_warn_duplicate_parts, |
2222 | 2224 |
$::instance_conf->get_reclamation_warn_no_reqdate, |
2223 | 2225 |
], |
2224 |
only_if => (any { $self->type eq $_ } (purchase_reclamation_type())),
|
|
2226 |
only_if => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
|
|
2225 | 2227 |
], |
2226 | 2228 |
action => [ |
2227 | 2229 |
t8('Save and Credit Note'), |
... | ... | |
2230 | 2232 |
$::instance_conf->get_reclamation_warn_duplicate_parts, |
2231 | 2233 |
$::instance_conf->get_reclamation_warn_no_reqdate, |
2232 | 2234 |
], |
2233 |
only_if => (any { $self->type eq $_ } (sales_reclamation_type())),
|
|
2235 |
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
|
|
2234 | 2236 |
], |
2235 | 2237 |
], # end of combobox "Workflow" |
2236 | 2238 |
|
... | ... | |
2445 | 2447 |
# t8("Edit Purchase Reclamation"); |
2446 | 2448 |
|
2447 | 2449 |
$action = ucfirst(lc($action)); |
2448 |
return $self->type eq sales_reclamation_type() ? t8("$action Sales Reclamation")
|
|
2449 |
: $self->type eq purchase_reclamation_type() ? t8("$action Purchase Reclamation")
|
|
2450 |
return $self->type eq SALES_RECLAMATION_TYPE() ? t8("$action Sales Reclamation")
|
|
2451 |
: $self->type eq PURCHASE_RECLAMATION_TYPE() ? t8("$action Purchase Reclamation")
|
|
2450 | 2452 |
: ''; |
2451 | 2453 |
} |
2452 | 2454 |
|
... | ... | |
2489 | 2491 |
return $texts; |
2490 | 2492 |
} |
2491 | 2493 |
|
2492 |
sub sales_reclamation_type { |
|
2493 |
'sales_reclamation'; |
|
2494 |
} |
|
2495 |
|
|
2496 |
sub purchase_reclamation_type { |
|
2497 |
'purchase_reclamation'; |
|
2498 |
} |
|
2499 |
|
|
2500 | 2494 |
sub save_history { |
2501 | 2495 |
my ($self, $addition) = @_; |
2502 | 2496 |
|
... | ... | |
2550 | 2544 |
} |
2551 | 2545 |
|
2552 | 2546 |
sub init_type_data { |
2553 |
SL::DB::Helper::TypeDataProxy->new('SL::DB::Reclamation', $_[0]->type);
|
|
2547 |
SL::DB::Helper::TypeDataProxy->new('SL::DB::Reclamation', $::form->{type});
|
|
2554 | 2548 |
} |
2555 | 2549 |
|
2556 | 2550 |
1; |
Auch abrufbar als: Unified diff
TypeData: nutzte Konstanten anstatt String für Typen