Revision 5e3518da
Von Tamino Steinert vor fast 2 Jahren hinzugefügt
SL/Controller/Reclamation.pm | ||
---|---|---|
111 | 111 |
|
112 | 112 |
$self->render( |
113 | 113 |
'reclamation/form', |
114 |
title => $self->get_title_for('add'),
|
|
114 |
title => $self->type_data->text('add'),
|
|
115 | 115 |
%{$self->{template_args}}, |
116 | 116 |
); |
117 | 117 |
} |
... | ... | |
125 | 125 |
} |
126 | 126 |
|
127 | 127 |
my $order = SL::DB::Order->new(id => $::form->{from_id})->load; |
128 |
my $target_type = $order->is_sales ? SALES_RECLAMATION_TYPE() |
|
129 |
: PURCHASE_RECLAMATION_TYPE(); |
|
130 |
my $reclamation = SL::Model::Record->new_from_workflow($order, $target_type); |
|
128 |
my $reclamation = SL::Model::Record->new_from_workflow($order, $self->type); |
|
131 | 129 |
|
132 | 130 |
$self->reclamation($reclamation); |
133 | 131 |
|
... | ... | |
139 | 137 |
|
140 | 138 |
$self->render( |
141 | 139 |
'reclamation/form', |
142 |
title => $self->get_title_for('add'),
|
|
140 |
title => $self->type_data->text('add'),
|
|
143 | 141 |
%{$self->{template_args}}, |
144 | 142 |
); |
145 | 143 |
} |
... | ... | |
153 | 151 |
} |
154 | 152 |
|
155 | 153 |
my $delivery_order = SL::DB::DeliveryOrder->new(id => $::form->{from_id})->load; |
156 |
my $target_type = $delivery_order->is_sales ? SALES_RECLAMATION_TYPE() |
|
157 |
: PURCHASE_RECLAMATION_TYPE(); |
|
158 |
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $target_type); |
|
154 |
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $self->type); |
|
159 | 155 |
|
160 | 156 |
$self->reclamation($reclamation); |
161 | 157 |
|
... | ... | |
167 | 163 |
|
168 | 164 |
$self->render( |
169 | 165 |
'reclamation/form', |
170 |
title => $self->get_title_for('add'),
|
|
166 |
title => $self->type_data->text('add'),
|
|
171 | 167 |
%{$self->{template_args}}, |
172 | 168 |
); |
173 | 169 |
} |
... | ... | |
181 | 177 |
} |
182 | 178 |
|
183 | 179 |
my $invoice = SL::DB::Invoice->new(id => $::form->{from_id})->load; |
184 |
my $target_type = SALES_RECLAMATION_TYPE(); |
|
185 |
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $target_type); |
|
180 |
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $self->type); |
|
186 | 181 |
|
187 | 182 |
$self->reclamation($reclamation); |
188 | 183 |
|
... | ... | |
194 | 189 |
|
195 | 190 |
$self->render( |
196 | 191 |
'reclamation/form', |
197 |
title => $self->get_title_for('add'),
|
|
192 |
title => $self->type_data->text('add'),
|
|
198 | 193 |
%{$self->{template_args}}, |
199 | 194 |
); |
200 | 195 |
} |
... | ... | |
210 | 205 |
require SL::DB::PurchaseInvoice; |
211 | 206 |
my $invoice = SL::DB::PurchaseInvoice->new(id => $::form->{from_id})->load; |
212 | 207 |
$invoice->{type} = $invoice->invoice_type; #can't add type → invoice_type in SL/DB/PurchaseInvoice |
213 |
my $target_type = PURCHASE_RECLAMATION_TYPE(); |
|
214 |
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $target_type); |
|
208 |
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $self->type); |
|
215 | 209 |
|
216 | 210 |
$self->reclamation($reclamation); |
217 | 211 |
|
... | ... | |
223 | 217 |
|
224 | 218 |
$self->render( |
225 | 219 |
'reclamation/form', |
226 |
title => $self->get_title_for('add'),
|
|
220 |
title => $self->type_data->text('add'),
|
|
227 | 221 |
%{$self->{template_args}}, |
228 | 222 |
); |
229 | 223 |
} |
... | ... | |
244 | 238 |
|
245 | 239 |
$self->render( |
246 | 240 |
'reclamation/form', |
247 |
title => $self->get_title_for('edit'),
|
|
241 |
title => $self->type_data->text('edit'),
|
|
248 | 242 |
%{$self->{template_args}}, |
249 | 243 |
); |
250 | 244 |
} |
... | ... | |
255 | 249 |
|
256 | 250 |
|
257 | 251 |
SL::Model::Record->delete($self->reclamation); |
258 |
flash_later('info', t8('The reclamation has been deleted'));
|
|
252 |
flash_later('info', $self->type_data->text('delete'));
|
|
259 | 253 |
|
260 | 254 |
my @redirect_params = ( |
261 | 255 |
action => 'add', |
... | ... | |
450 | 444 |
|
451 | 445 |
unless ($self->reclamation->customervendor) { |
452 | 446 |
return $self->js->flash('error', |
453 |
$self->cv eq 'customer' ?
|
|
454 |
t8('Cannot send E-mail without customer given')
|
|
455 |
: t8('Cannot send E-mail without vendor given'))
|
|
456 |
->render($self);
|
|
447 |
$self->type_data->properties('is_customer') ?
|
|
448 |
t8('Cannot send E-mail without customer given') |
|
449 |
: t8('Cannot send E-mail without vendor given')) |
|
450 |
->render($self); |
|
457 | 451 |
} |
458 | 452 |
|
459 | 453 |
my $form = Form->new; |
... | ... | |
483 | 477 |
email_form => $email_form, |
484 | 478 |
show_bcc => $::auth->assert('email_bcc', 'may fail'), |
485 | 479 |
FILES => \%files, |
486 |
is_customer => $self->cv eq 'customer',
|
|
480 |
is_customer => $self->type_data->properties('is_customer'),
|
|
487 | 481 |
ALL_EMPLOYEES => $self->{all_employees}, |
488 | 482 |
); |
489 | 483 |
|
... | ... | |
674 | 668 |
|
675 | 669 |
$self->recalc(); |
676 | 670 |
|
677 |
my $cv_method = $self->cv; |
|
678 |
|
|
679 | 671 |
if ( $self->reclamation->customervendor->contacts |
680 | 672 |
&& scalar @{ $self->reclamation->customervendor->contacts } > 0) { |
681 | 673 |
$self->js->show('#cp_row'); |
... | ... | |
716 | 708 |
sub action_show_customer_vendor_details_dialog { |
717 | 709 |
my ($self) = @_; |
718 | 710 |
|
719 |
my $is_sales = ($self->cv eq 'customer');
|
|
711 |
my $is_customer = ($self->type_data->properties('is_customer'));
|
|
720 | 712 |
my $cv; |
721 |
if ($is_sales) {
|
|
713 |
if ($is_customer) {
|
|
722 | 714 |
$cv = SL::DB::Customer->new(id => $::form->{cv_id})->load; |
723 | 715 |
} else { |
724 | 716 |
$cv = SL::DB::Vendor->new(id => $::form->{cv_id})->load; |
... | ... | |
731 | 723 |
$details{language} = $cv->language_obj->description if $cv->language_obj; |
732 | 724 |
$details{delivery_terms} = $cv->delivery_term->description if $cv->delivery_term; |
733 | 725 |
$details{payment_terms} = $cv->payment->description if $cv->payment; |
734 |
$details{pricegroup} = $cv->pricegroup->pricegroup if !$is_sales && $cv->pricegroup;
|
|
726 |
$details{pricegroup} = $cv->pricegroup->pricegroup if !$is_customer && $cv->pricegroup;
|
|
735 | 727 |
|
736 | 728 |
foreach my $entry (@{ $cv->shipto }) { |
737 | 729 |
push @{ $details{SHIPTO} }, { map { $_ => $entry->$_ } @{$entry->meta->columns} }; |
... | ... | |
741 | 733 |
} |
742 | 734 |
|
743 | 735 |
$_[0]->render('common/show_vc_details', { layout => 0 }, |
744 |
is_customer => !$is_sales,
|
|
736 |
is_customer => $is_customer,
|
|
745 | 737 |
%details); |
746 | 738 |
} |
747 | 739 |
|
... | ... | |
1032 | 1024 |
|
1033 | 1025 |
$self->render( |
1034 | 1026 |
'reclamation/form', |
1035 |
title => $self->get_title_for('edit'),
|
|
1027 |
title => $self->type_data->text('edit'),
|
|
1036 | 1028 |
%{$self->{template_args}} |
1037 | 1029 |
); |
1038 | 1030 |
} |
... | ... | |
1231 | 1223 |
sub init_cv { |
1232 | 1224 |
my ($self) = @_; |
1233 | 1225 |
|
1234 |
my $cv = (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())) ? 'customer' |
|
1235 |
: (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())) ? 'vendor' |
|
1236 |
: die "Not a valid type for reclamation"; |
|
1237 |
|
|
1238 |
return $cv; |
|
1226 |
$self->type_data->properties('customervendor'); |
|
1239 | 1227 |
} |
1240 | 1228 |
|
1241 | 1229 |
sub init_search_cvpartnumber { |
... | ... | |
1243 | 1231 |
|
1244 | 1232 |
my $user_prefs = SL::Helper::UserPreferences::PartPickerSearch->new(); |
1245 | 1233 |
my $search_cvpartnumber; |
1246 |
$search_cvpartnumber = !!$user_prefs->get_sales_search_customer_partnumber() if $self->cv eq 'customer'; |
|
1247 |
$search_cvpartnumber = !!$user_prefs->get_purchase_search_makemodel() if $self->cv eq 'vendor'; |
|
1234 |
if ($self->type_data->properties('is_customer')) { |
|
1235 |
$search_cvpartnumber = !!$user_prefs->get_sales_search_customer_partnumber() |
|
1236 |
} else { |
|
1237 |
$search_cvpartnumber = !!$user_prefs->get_purchase_search_makemodel(); |
|
1238 |
} |
|
1248 | 1239 |
|
1249 | 1240 |
return $search_cvpartnumber; |
1250 | 1241 |
} |
... | ... | |
1275 | 1266 |
language_id => t8('Language'), |
1276 | 1267 |
department_id => t8('Department'), |
1277 | 1268 |
globalproject_id => t8('Project Number'), |
1278 |
cv_record_number => ($self->type eq SALES_RECLAMATION_TYPE() ? t8('Customer Record Number') : t8('Vendor Record Number')),
|
|
1269 |
cv_record_number => ($self->type_data->properties('is_customer') ? t8('Customer Record Number') : t8('Vendor Record Number')),
|
|
1279 | 1270 |
transaction_description => t8('Description'), |
1280 | 1271 |
notes => t8('Notes'), |
1281 | 1272 |
intnotes => t8('Internal Notes'), |
... | ... | |
1321 | 1312 |
|
1322 | 1313 |
sub init_part_picker_classification_ids { |
1323 | 1314 |
my ($self) = @_; |
1324 |
my $attribute = 'used_for_' . ($self->type eq SALES_RECLAMATION_TYPE() ? 'sale' : 'purchase'); |
|
1325 | 1315 |
|
1326 |
return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => [ $attribute => 1 ]) } ];
|
|
1316 |
return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => $self->type_data->part_classification_query()) } ];
|
|
1327 | 1317 |
} |
1328 | 1318 |
|
1329 | 1319 |
sub check_auth { |
1330 | 1320 |
my ($self) = @_; |
1331 |
|
|
1332 |
my $right_for = { map { $_ => $_.'_edit' } @{$self->valid_types} }; |
|
1333 |
|
|
1334 |
my $right = $right_for->{ $self->type }; |
|
1335 |
$right ||= 'DOES_NOT_EXIST'; |
|
1336 |
|
|
1337 |
$::auth->assert($right); |
|
1321 |
$::auth->assert($self->type_data->rights('edit')); |
|
1338 | 1322 |
} |
1339 | 1323 |
|
1340 | 1324 |
# build the selection box for contacts |
... | ... | |
1478 | 1462 |
reclamation_items => [], |
1479 | 1463 |
currency_id => $::instance_conf->get_currency_id(), |
1480 | 1464 |
); |
1481 |
my $cv_id_method = $self->cv . '_id'; |
|
1482 |
if ($::form->{$cv_id_method}) { |
|
1483 |
$reclamation->$cv_id_method($::form->{$cv_id_method}); |
|
1484 |
} |
|
1485 | 1465 |
} |
1486 | 1466 |
|
1487 | 1467 |
my $form_reclamation_items = delete $::form->{reclamation}->{reclamation_items}; |
... | ... | |
1709 | 1689 |
? SL::DB::Manager::ReclamationItem->get_all(where => [id => $self->item_ids_to_delete]) |
1710 | 1690 |
: undef; |
1711 | 1691 |
|
1712 |
SL::Model::Record->save($self->order,
|
|
1692 |
SL::Model::Record->save($self->reclamation,
|
|
1713 | 1693 |
with_validity_token => { scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE(), token => $::form->{form_validity_token} }, |
1714 | 1694 |
delete_custom_shipto => $self->is_custom_shipto_to_delete || $self->reclamation->custom_shipto->is_empty, |
1715 | 1695 |
items_to_delete => $items_to_delete, |
... | ... | |
1734 | 1714 |
|
1735 | 1715 |
# check for direct delivery |
1736 | 1716 |
# copy shipto in custom shipto (custom shipto will be copied by new_from() in case) |
1737 |
if ($::form->{type} eq PURCHASE_RECLAMATION_TYPE()) {
|
|
1717 |
if (!$self->type_data->properties('is_customer')) {
|
|
1738 | 1718 |
if ($::form->{use_shipto}) { |
1739 | 1719 |
my $custom_shipto = $source_reclamation->shipto->clone('SL::DB::Reclamation'); |
1740 | 1720 |
$self->reclamation->custom_shipto($custom_shipto) if $custom_shipto; |
... | ... | |
1752 | 1732 |
|
1753 | 1733 |
$self->render( |
1754 | 1734 |
'reclamation/form', |
1755 |
title => $self->get_title_for('add'),
|
|
1735 |
title => $self->type_data->text('add'),
|
|
1756 | 1736 |
%{$self->{template_args}} |
1757 | 1737 |
); |
1758 | 1738 |
} |
... | ... | |
2026 | 2006 |
sub => sub { $_[0]->closed ? t8('Yes') : t8('No') }, |
2027 | 2007 |
}, |
2028 | 2008 |
); |
2029 |
if ($self->type eq SALES_RECLAMATION_TYPE()) {
|
|
2009 |
if ($self->type_data->properties('is_customer')) {
|
|
2030 | 2010 |
$column_defs{customer_id} = ({ |
2031 | 2011 |
raw_data => sub { $_[0]->customervendor->presenter->customer(display => 'table-cell', callback => $callback) }, |
2032 | 2012 |
sub => sub { $_[0]->customervendor->name }, |
... | ... | |
2041 | 2021 |
}, |
2042 | 2022 |
sub => sub { $_[0]->contact ? $_[0]->contact->cp_name : '' }, |
2043 | 2023 |
}); |
2044 |
} elsif ($self->type eq PURCHASE_RECLAMATION_TYPE()) {
|
|
2024 |
} else {
|
|
2045 | 2025 |
$column_defs{vendor_id} = ({ |
2046 | 2026 |
raw_data => sub { $_[0]->customervendor->presenter->vendor(display => 'table-cell', callback => $callback) }, |
2047 | 2027 |
sub => sub { $_[0]->customervendor->name }, |
... | ... | |
2102 | 2082 |
{ output => 0 }, |
2103 | 2083 |
models => $self->models |
2104 | 2084 |
), |
2105 |
title => $self->type eq SALES_RECLAMATION_TYPE() ? t8('Sales Reclamations') : t8('Purchase Reclamations'),
|
|
2085 |
title => $self->type_data->text('list'),
|
|
2106 | 2086 |
allow_pdf_export => 1, |
2107 | 2087 |
allow_csv_export => 1, |
2108 | 2088 |
); |
... | ... | |
2117 | 2097 |
sub _setup_edit_action_bar { |
2118 | 2098 |
my ($self, %params) = @_; |
2119 | 2099 |
|
2120 |
my $deletion_allowed = ($self->type eq SALES_RECLAMATION_TYPE() |
|
2121 |
&& $::instance_conf->get_sales_reclamation_show_delete) |
|
2122 |
|| ($self->type eq PURCHASE_RECLAMATION_TYPE() |
|
2123 |
&& $::instance_conf->get_purchase_reclamation_show_delete); |
|
2124 |
|
|
2125 | 2100 |
for my $bar ($::request->layout->get('actionbar')) { |
2126 | 2101 |
$bar->add( |
2127 | 2102 |
combobox => [ |
... | ... | |
2157 | 2132 |
$::instance_conf->get_reclamation_warn_duplicate_parts, |
2158 | 2133 |
$::instance_conf->get_reclamation_warn_no_reqdate, |
2159 | 2134 |
], |
2160 |
only_if => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
|
|
2135 |
only_if => $self->type_data->show_menu('save_and_sales_reclamation'),
|
|
2161 | 2136 |
], |
2162 | 2137 |
action => [ |
2163 | 2138 |
t8('Save and Purchase Reclamation'), |
2164 | 2139 |
call => [ 'kivi.Reclamation.purchase_reclamation_check_for_direct_delivery' ], |
2165 |
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
|
|
2140 |
only_if => $self->type_data->show_menu('save_and_purchase_reclamation'),
|
|
2166 | 2141 |
], |
2167 | 2142 |
action => [ |
2168 | 2143 |
t8('Save and Order'), |
... | ... | |
2179 | 2154 |
$::instance_conf->get_reclamation_warn_duplicate_parts, |
2180 | 2155 |
$::instance_conf->get_reclamation_warn_no_reqdate, |
2181 | 2156 |
], |
2182 |
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
|
|
2157 |
only_if => $self->type_data->show_menu('save_and_rma_delivery_order'),
|
|
2183 | 2158 |
], |
2184 | 2159 |
action => [ |
2185 | 2160 |
t8('Save and Supplier Delivery Order'), |
... | ... | |
2188 | 2163 |
$::instance_conf->get_reclamation_warn_duplicate_parts, |
2189 | 2164 |
$::instance_conf->get_reclamation_warn_no_reqdate, |
2190 | 2165 |
], |
2191 |
only_if => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
|
|
2166 |
only_if => $self->type_data->show_menu('save_and_supplier_delivery_order'),
|
|
2192 | 2167 |
], |
2193 | 2168 |
action => [ |
2194 | 2169 |
t8('Save and Credit Note'), |
... | ... | |
2197 | 2172 |
$::instance_conf->get_reclamation_warn_duplicate_parts, |
2198 | 2173 |
$::instance_conf->get_reclamation_warn_no_reqdate, |
2199 | 2174 |
], |
2200 |
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
|
|
2175 |
only_if => $self->type_data->show_menu('save_and_credit_note'),
|
|
2201 | 2176 |
], |
2202 | 2177 |
], # end of combobox "Workflow" |
2203 | 2178 |
|
... | ... | |
2244 | 2219 |
call => [ 'kivi.Reclamation.delete_reclamation' ], |
2245 | 2220 |
confirm => t8('Do you really want to delete this object?'), |
2246 | 2221 |
disabled => !$self->reclamation->id ? t8('This object has not been saved yet.') : undef, |
2247 |
only_if => $deletion_allowed,
|
|
2222 |
only_if => $self->type_data->show_menu('delete'),
|
|
2248 | 2223 |
], |
2249 | 2224 |
|
2250 | 2225 |
combobox => [ |
... | ... | |
2400 | 2375 |
return %files; |
2401 | 2376 |
} |
2402 | 2377 |
|
2403 |
sub get_title_for { |
|
2404 |
my ($self, $action) = @_; |
|
2405 |
|
|
2406 |
return '' if none { lc($action)} qw(add edit); |
|
2407 |
|
|
2408 |
# for locales: |
|
2409 |
# t8("Add Sales Reclamation"); |
|
2410 |
# t8("Add Purchase Reclamation"); |
|
2411 |
# t8("Edit Sales Reclamation"); |
|
2412 |
# t8("Edit Purchase Reclamation"); |
|
2413 |
|
|
2414 |
$action = ucfirst(lc($action)); |
|
2415 |
return $self->type eq SALES_RECLAMATION_TYPE() ? t8("$action Sales Reclamation") |
|
2416 |
: $self->type eq PURCHASE_RECLAMATION_TYPE() ? t8("$action Purchase Reclamation") |
|
2417 |
: ''; |
|
2418 |
} |
|
2419 |
|
|
2420 | 2378 |
sub get_item_cvpartnumber { |
2421 | 2379 |
my ($self, $item) = @_; |
2422 | 2380 |
|
2423 | 2381 |
return if !$self->search_cvpartnumber; |
2424 | 2382 |
return if !$self->reclamation->customervendor; |
2425 | 2383 |
|
2426 |
if ($self->cv eq 'vendor') {
|
|
2384 |
if (!$self->reclamation->is_sales) {
|
|
2427 | 2385 |
my @mms = grep { $_->make eq $self->reclamation->customervendor->id } @{$item->part->makemodels}; |
2428 | 2386 |
$item->{cvpartnumber} = $mms[0]->model if scalar @mms; |
2429 |
} elsif ($self->cv eq 'customer') {
|
|
2387 |
} elsif ($self->reclamation->is_sales) {
|
|
2430 | 2388 |
my @cps = grep { $_->customer_id eq $self->reclamation->customervendor->id } @{$item->part->customerprices}; |
2431 | 2389 |
$item->{cvpartnumber} = $cps[0]->customer_partnumber if scalar @cps; |
2432 | 2390 |
} |
Auch abrufbar als: Unified diff
Controller::Reclamation: nutze TypeData