Revision 28142a65
Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
35 | 35 |
use SL::DB::Helper::RecordLink qw(set_record_link_conversions); |
36 | 36 |
use SL::DB::Helper::TypeDataProxy; |
37 | 37 |
use SL::Model::Record; |
38 |
use SL::DB::Order::TypeData qw(:types); |
|
39 |
use SL::DB::Reclamation::TypeData qw(:types); |
|
38 | 40 |
|
39 | 41 |
use SL::Helper::CreatePDF qw(:all); |
40 | 42 |
use SL::Helper::PrintOptions; |
... | ... | |
98 | 100 |
|
99 | 101 |
my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load; |
100 | 102 |
my %params; |
101 |
my $target_type = $reclamation->is_sales ? 'sales_order'
|
|
102 |
: 'purchase_order';
|
|
103 |
my $target_type = $reclamation->is_sales ? SALES_ORDER_TYPE()
|
|
104 |
: PURCHASE_ORDER_TYPE();
|
|
103 | 105 |
my $order = SL::Model::Record->new_from_workflow($reclamation, $target_type); |
104 | 106 |
$self->{converted_from_reclamation_id} = $::form->{from_id}; |
105 | 107 |
|
... | ... | |
189 | 191 |
my ($self) = @_; |
190 | 192 |
|
191 | 193 |
SL::Model::Record->delete($self->order); |
192 |
my $text = $self->type eq sales_order_type() ? $::locale->text('The order has been deleted')
|
|
193 |
: $self->type eq purchase_order_type() ? $::locale->text('The order has been deleted')
|
|
194 |
: $self->type eq sales_quotation_type() ? $::locale->text('The quotation has been deleted')
|
|
195 |
: $self->type eq request_quotation_type() ? $::locale->text('The rfq has been deleted')
|
|
194 |
my $text = $self->type eq SALES_ORDER_TYPE() ? $::locale->text('The order has been deleted')
|
|
195 |
: $self->type eq PURCHASE_ORDER_TYPE() ? $::locale->text('The order has been deleted')
|
|
196 |
: $self->type eq SALES_QUOTATION_TYPE() ? $::locale->text('The quotation has been deleted')
|
|
197 |
: $self->type eq REQUEST_QUOTATION_TYPE() ? $::locale->text('The rfq has been deleted')
|
|
196 | 198 |
: ''; |
197 | 199 |
flash_later('info', $text); |
198 | 200 |
|
... | ... | |
210 | 212 |
|
211 | 213 |
$self->save(); |
212 | 214 |
|
213 |
my $text = $self->type eq sales_order_type() ? $::locale->text('The order has been saved')
|
|
214 |
: $self->type eq purchase_order_type() ? $::locale->text('The order has been saved')
|
|
215 |
: $self->type eq sales_quotation_type() ? $::locale->text('The quotation has been saved')
|
|
216 |
: $self->type eq request_quotation_type() ? $::locale->text('The rfq has been saved')
|
|
215 |
my $text = $self->type eq SALES_ORDER_TYPE() ? $::locale->text('The order has been saved')
|
|
216 |
: $self->type eq PURCHASE_ORDER_TYPE() ? $::locale->text('The order has been saved')
|
|
217 |
: $self->type eq SALES_QUOTATION_TYPE() ? $::locale->text('The quotation has been saved')
|
|
218 |
: $self->type eq REQUEST_QUOTATION_TYPE() ? $::locale->text('The rfq has been saved')
|
|
217 | 219 |
: ''; |
218 | 220 |
flash_later('info', $text); |
219 | 221 |
|
... | ... | |
740 | 742 |
$config ||= SL::DB::Manager::PeriodicInvoicesConfig->find_by(oe_id => $::form->{id}) if $::form->{id}; |
741 | 743 |
|
742 | 744 |
my $has_active_periodic_invoices = |
743 |
$self->type eq sales_order_type()
|
|
745 |
$self->type eq SALES_ORDER_TYPE()
|
|
744 | 746 |
&& $config |
745 | 747 |
&& $config->active |
746 | 748 |
&& (!$config->end_date || ($config->end_date > DateTime->today_local)) |
... | ... | |
784 | 786 |
# can't use save_and_redirect_to, because id is set! |
785 | 787 |
$self->save(); |
786 | 788 |
|
787 |
my $to_type = $self->order->is_sales ? 'sales_reclamation'
|
|
788 |
: 'purchase_reclamation';
|
|
789 |
my $to_type = $self->order->is_sales ? SALES_RECLAMATION_TYPE()
|
|
790 |
: PURCHASE_RECLAMATION_TYPE();
|
|
789 | 791 |
$self->redirect_to( |
790 | 792 |
controller => 'Reclamation', |
791 | 793 |
action => 'add_from_order', |
... | ... | |
853 | 855 |
my $destination_type = $::form->{to_type} ? $::form->{to_type} : ''; |
854 | 856 |
|
855 | 857 |
my $from_side = $self->order->is_sales ? 'sales' : 'purchase'; |
856 |
my $to_side = (any { $destination_type eq $_ } (sales_order_type(), sales_quotation_type())) ? 'sales' : 'purchase';
|
|
858 |
my $to_side = (any { $destination_type eq $_ } (SALES_ORDER_TYPE(), SALES_QUOTATION_TYPE())) ? 'sales' : 'purchase';
|
|
857 | 859 |
|
858 | 860 |
# check for direct delivery |
859 | 861 |
# copy shipto in custom shipto (custom shipto will be copied by new_from() in case) |
... | ... | |
866 | 868 |
$self->order(SL::DB::Order->new_from($self->order, destination_type => $destination_type)); |
867 | 869 |
|
868 | 870 |
# no linked records to quotations from the same side (sales -> sales or purchase -> purchase) |
869 |
if ( (any { $destination_type eq $_ } (sales_quotation_type(), request_quotation_type()))
|
|
871 |
if ( (any { $destination_type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE()))
|
|
870 | 872 |
&& $from_side eq $to_side) { |
871 | 873 |
delete $::form->{id}; |
872 | 874 |
delete $::form->{$_} for qw(converted_from_oe_id converted_from_orderitems_ids); |
... | ... | |
1618 | 1620 |
# |
1619 | 1621 |
|
1620 | 1622 |
sub init_valid_types { |
1621 |
[ sales_order_type(), purchase_order_type(), sales_quotation_type(), request_quotation_type() ];
|
|
1623 |
$_[0]->type_data->valid_types;
|
|
1622 | 1624 |
} |
1623 | 1625 |
|
1624 | 1626 |
sub init_type { |
... | ... | |
1634 | 1636 |
sub init_cv { |
1635 | 1637 |
my ($self) = @_; |
1636 | 1638 |
|
1637 |
my $cv = (any { $self->type eq $_ } (sales_order_type(), sales_quotation_type())) ? 'customer'
|
|
1638 |
: (any { $self->type eq $_ } (purchase_order_type(), request_quotation_type())) ? 'vendor'
|
|
1639 |
my $cv = (any { $self->type eq $_ } (SALES_ORDER_TYPE(), SALES_QUOTATION_TYPE())) ? 'customer'
|
|
1640 |
: (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE(), REQUEST_QUOTATION_TYPE())) ? 'vendor'
|
|
1639 | 1641 |
: die "Not a valid type for order"; |
1640 | 1642 |
|
1641 | 1643 |
return $cv; |
... | ... | |
1855 | 1857 |
my $order; |
1856 | 1858 |
$order = SL::DB::Order->new(id => $::form->{id})->load(with => [ 'orderitems', 'orderitems.part' ]) if $::form->{id}; |
1857 | 1859 |
$order ||= SL::DB::Order->new(orderitems => [], |
1858 |
quotation => (any { $self->type eq $_ } (sales_quotation_type(), request_quotation_type())),
|
|
1860 |
quotation => (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE())),
|
|
1859 | 1861 |
currency_id => $::instance_conf->get_currency_id(),); |
1860 | 1862 |
|
1861 | 1863 |
my $cv_id_method = $self->cv . '_id'; |
... | ... | |
2169 | 2171 |
$item->active_discount_source($price_source->discount_from_source($item->active_discount_source)); |
2170 | 2172 |
} |
2171 | 2173 |
|
2172 |
if (any { $self->type eq $_ } (sales_order_type(), purchase_order_type())) {
|
|
2174 |
if (any { $self->type eq $_ } (SALES_ORDER_TYPE(), PURCHASE_ORDER_TYPE())) {
|
|
2173 | 2175 |
# Calculate shipped qtys here to prevent calling calculate for every item via the items method. |
2174 | 2176 |
# Do not use write_to_objects to prevent order->delivered to be set, because this should be |
2175 | 2177 |
# the value from db, which can be set manually or is set when linked delivery orders are saved. |
... | ... | |
2188 | 2190 |
} } @all_objects; |
2189 | 2191 |
} |
2190 | 2192 |
|
2191 |
if ( (any { $self->type eq $_ } (sales_quotation_type(), sales_order_type()))
|
|
2193 |
if ( (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), SALES_ORDER_TYPE()))
|
|
2192 | 2194 |
&& $::instance_conf->get_transport_cost_reminder_article_number_id ) { |
2193 | 2195 |
$self->{template_args}->{transport_cost_reminder_article} = SL::DB::Part->new(id => $::instance_conf->get_transport_cost_reminder_article_number_id)->load; |
2194 | 2196 |
} |
... | ... | |
2206 | 2208 |
sub setup_edit_action_bar { |
2207 | 2209 |
my ($self, %params) = @_; |
2208 | 2210 |
|
2209 |
my $deletion_allowed = (any { $self->type eq $_ } (sales_quotation_type(), request_quotation_type()))
|
|
2210 |
|| (($self->type eq sales_order_type()) && $::instance_conf->get_sales_order_show_delete)
|
|
2211 |
|| (($self->type eq purchase_order_type()) && $::instance_conf->get_purchase_order_show_delete);
|
|
2211 |
my $deletion_allowed = (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE()))
|
|
2212 |
|| (($self->type eq SALES_ORDER_TYPE()) && $::instance_conf->get_sales_order_show_delete)
|
|
2213 |
|| (($self->type eq PURCHASE_ORDER_TYPE()) && $::instance_conf->get_purchase_order_show_delete);
|
|
2212 | 2214 |
|
2213 | 2215 |
my @req_trans_cost_art = qw(kivi.Order.check_transport_cost_article_presence) x!!$::instance_conf->get_transport_cost_reminder_article_number_id; |
2214 |
my @req_cusordnumber = qw(kivi.Order.check_cusordnumber_presence) x($self->type eq sales_order_type() && $::instance_conf->get_order_warn_no_cusordnumber);
|
|
2216 |
my @req_cusordnumber = qw(kivi.Order.check_cusordnumber_presence) x($self->type eq SALES_ORDER_TYPE() && $::instance_conf->get_order_warn_no_cusordnumber);
|
|
2215 | 2217 |
|
2216 | 2218 |
my $has_invoice_for_advance_payment; |
2217 |
if ($self->order->id && $self->type eq sales_order_type()) {
|
|
2219 |
if ($self->order->id && $self->type eq SALES_ORDER_TYPE()) {
|
|
2218 | 2220 |
my $lr = $self->order->linked_records(direction => 'to', to => ['Invoice']); |
2219 | 2221 |
$has_invoice_for_advance_payment = any {'SL::DB::Invoice' eq ref $_ && "invoice_for_advance_payment" eq $_->type} @$lr; |
2220 | 2222 |
} |
2221 | 2223 |
|
2222 | 2224 |
my $has_final_invoice; |
2223 |
if ($self->order->id && $self->type eq sales_order_type()) {
|
|
2225 |
if ($self->order->id && $self->type eq SALES_ORDER_TYPE()) {
|
|
2224 | 2226 |
my $lr = $self->order->linked_records(direction => 'to', to => ['Invoice']); |
2225 | 2227 |
$has_final_invoice = any {'SL::DB::Invoice' eq ref $_ && "final_invoice" eq $_->type} @$lr; |
2226 | 2228 |
} |
... | ... | |
2288 | 2290 |
], |
2289 | 2291 |
action => [ |
2290 | 2292 |
t8('Save and Quotation'), |
2291 |
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => sales_quotation_type()), '#order_form' ],
|
|
2293 |
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => SALES_QUOTATION_TYPE()), '#order_form' ],
|
|
2292 | 2294 |
checks => [ @req_trans_cost_art, @req_cusordnumber ], |
2293 |
only_if => (any { $self->type eq $_ } (sales_order_type(), request_quotation_type())),
|
|
2295 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), REQUEST_QUOTATION_TYPE())),
|
|
2294 | 2296 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2295 | 2297 |
], |
2296 | 2298 |
action => [ |
2297 | 2299 |
t8('Save and RFQ'), |
2298 |
call => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => request_quotation_type() } ],
|
|
2299 |
only_if => (any { $self->type eq $_ } (sales_order_type(), sales_quotation_type(), purchase_order_type())),
|
|
2300 |
call => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => REQUEST_QUOTATION_TYPE() } ],
|
|
2301 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), SALES_QUOTATION_TYPE(), PURCHASE_ORDER_TYPE())),
|
|
2300 | 2302 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2301 | 2303 |
], |
2302 | 2304 |
action => [ |
2303 | 2305 |
t8('Save and Sales Order'), |
2304 |
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => sales_order_type()), '#order_form' ],
|
|
2306 |
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => SALES_ORDER_TYPE()), '#order_form' ],
|
|
2305 | 2307 |
checks => [ @req_trans_cost_art ], |
2306 |
only_if => (any { $self->type eq $_ } (sales_quotation_type(), request_quotation_type(), purchase_order_type())),
|
|
2308 |
only_if => (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE(), PURCHASE_ORDER_TYPE())),
|
|
2307 | 2309 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2308 | 2310 |
], |
2309 | 2311 |
action => [ |
2310 | 2312 |
t8('Save and Purchase Order'), |
2311 |
call => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => purchase_order_type() } ],
|
|
2313 |
call => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => PURCHASE_ORDER_TYPE() } ],
|
|
2312 | 2314 |
checks => [ @req_trans_cost_art, @req_cusordnumber ], |
2313 |
only_if => (any { $self->type eq $_ } (sales_order_type(), request_quotation_type())),
|
|
2315 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), REQUEST_QUOTATION_TYPE())),
|
|
2314 | 2316 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2315 | 2317 |
], |
2316 | 2318 |
action => [ |
... | ... | |
2322 | 2324 |
checks => [ 'kivi.Order.check_save_active_periodic_invoices', |
2323 | 2325 |
@req_trans_cost_art, @req_cusordnumber, |
2324 | 2326 |
], |
2325 |
only_if => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type())),
|
|
2327 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), PURCHASE_ORDER_TYPE())),
|
|
2326 | 2328 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2327 | 2329 |
], |
2328 | 2330 |
action => [ |
... | ... | |
2345 | 2347 |
checks => [ 'kivi.Order.check_save_active_periodic_invoices', |
2346 | 2348 |
@req_trans_cost_art, @req_cusordnumber, |
2347 | 2349 |
], |
2348 |
only_if => (any { $self->type eq $_ } (purchase_order_type())),
|
|
2350 |
only_if => (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE())),
|
|
2349 | 2351 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2350 | 2352 |
], |
2351 | 2353 |
action => [ |
... | ... | |
2353 | 2355 |
call => [ 'kivi.Order.save', { action => 'save_and_reclamation', |
2354 | 2356 |
warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts }, |
2355 | 2357 |
], |
2356 |
only_if => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type()))
|
|
2358 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), PURCHASE_ORDER_TYPE()))
|
|
2357 | 2359 |
], |
2358 | 2360 |
action => [ |
2359 | 2361 |
t8('Save and Invoice'), |
... | ... | |
2376 | 2378 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') |
2377 | 2379 |
: $has_final_invoice ? t8('This order has already a final invoice.') |
2378 | 2380 |
: undef, |
2379 |
only_if => (any { $self->type eq $_ } (sales_order_type())),
|
|
2381 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE())),
|
|
2380 | 2382 |
], |
2381 | 2383 |
action => [ |
2382 | 2384 |
t8('Save and Final Invoice'), |
... | ... | |
2389 | 2391 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') |
2390 | 2392 |
: $has_final_invoice ? t8('This order has already a final invoice.') |
2391 | 2393 |
: undef, |
2392 |
only_if => (any { $self->type eq $_ } (sales_order_type())) && $has_invoice_for_advance_payment,
|
|
2394 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE())) && $has_invoice_for_advance_payment,
|
|
2393 | 2395 |
], |
2394 | 2396 |
action => [ |
2395 | 2397 |
t8('Save and AP Transaction'), |
2396 | 2398 |
call => [ 'kivi.Order.save', { action => 'save_and_ap_transaction', |
2397 | 2399 |
warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts }, |
2398 | 2400 |
], |
2399 |
only_if => (any { $self->type eq $_ } (purchase_order_type())),
|
|
2401 |
only_if => (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE())),
|
|
2400 | 2402 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2401 | 2403 |
], |
2402 | 2404 |
|
... | ... | |
2586 | 2588 |
sub get_periodic_invoices_status { |
2587 | 2589 |
my ($self, $config) = @_; |
2588 | 2590 |
|
2589 |
return if $self->type ne sales_order_type();
|
|
2591 |
return if $self->type ne SALES_ORDER_TYPE();
|
|
2590 | 2592 |
return t8('not configured') if !$config; |
2591 | 2593 |
|
2592 | 2594 |
my $active = ('HASH' eq ref $config) ? $config->{active} |
... | ... | |
2612 | 2614 |
# $::locale->text("Edit Request for Quotation"); |
2613 | 2615 |
|
2614 | 2616 |
$action = ucfirst(lc($action)); |
2615 |
return $self->type eq sales_order_type() ? $::locale->text("$action Sales Order")
|
|
2616 |
: $self->type eq purchase_order_type() ? $::locale->text("$action Purchase Order")
|
|
2617 |
: $self->type eq sales_quotation_type() ? $::locale->text("$action Quotation")
|
|
2618 |
: $self->type eq request_quotation_type() ? $::locale->text("$action Request for Quotation")
|
|
2617 |
return $self->type eq SALES_ORDER_TYPE() ? $::locale->text("$action Sales Order")
|
|
2618 |
: $self->type eq PURCHASE_ORDER_TYPE() ? $::locale->text("$action Purchase Order")
|
|
2619 |
: $self->type eq SALES_QUOTATION_TYPE() ? $::locale->text("$action Quotation")
|
|
2620 |
: $self->type eq REQUEST_QUOTATION_TYPE() ? $::locale->text("$action Request for Quotation")
|
|
2619 | 2621 |
: ''; |
2620 | 2622 |
} |
2621 | 2623 |
|
... | ... | |
2693 | 2695 |
return ($price_src, $discount_src); |
2694 | 2696 |
} |
2695 | 2697 |
|
2696 |
sub sales_order_type { |
|
2697 |
'sales_order'; |
|
2698 |
} |
|
2699 |
|
|
2700 |
sub purchase_order_type { |
|
2701 |
'purchase_order'; |
|
2702 |
} |
|
2703 |
|
|
2704 |
sub sales_quotation_type { |
|
2705 |
'sales_quotation'; |
|
2706 |
} |
|
2707 |
|
|
2708 |
sub request_quotation_type { |
|
2709 |
'request_quotation'; |
|
2710 |
} |
|
2711 |
|
|
2712 | 2698 |
sub nr_key { |
2713 |
return $_[0]->type eq sales_order_type() ? 'ordnumber'
|
|
2714 |
: $_[0]->type eq purchase_order_type() ? 'ordnumber'
|
|
2715 |
: $_[0]->type eq sales_quotation_type() ? 'quonumber'
|
|
2716 |
: $_[0]->type eq request_quotation_type() ? 'quonumber'
|
|
2699 |
return $_[0]->type eq SALES_ORDER_TYPE() ? 'ordnumber'
|
|
2700 |
: $_[0]->type eq PURCHASE_ORDER_TYPE() ? 'ordnumber'
|
|
2701 |
: $_[0]->type eq SALES_QUOTATION_TYPE() ? 'quonumber'
|
|
2702 |
: $_[0]->type eq REQUEST_QUOTATION_TYPE() ? 'quonumber'
|
|
2717 | 2703 |
: ''; |
2718 | 2704 |
} |
2719 | 2705 |
|
... | ... | |
2722 | 2708 |
|
2723 | 2709 |
$self->save(); |
2724 | 2710 |
|
2725 |
my $text = $self->type eq sales_order_type() ? $::locale->text('The order has been saved')
|
|
2726 |
: $self->type eq purchase_order_type() ? $::locale->text('The order has been saved')
|
|
2727 |
: $self->type eq sales_quotation_type() ? $::locale->text('The quotation has been saved')
|
|
2728 |
: $self->type eq request_quotation_type() ? $::locale->text('The rfq has been saved')
|
|
2711 |
my $text = $self->type eq SALES_ORDER_TYPE() ? $::locale->text('The order has been saved')
|
|
2712 |
: $self->type eq PURCHASE_ORDER_TYPE() ? $::locale->text('The order has been saved')
|
|
2713 |
: $self->type eq SALES_QUOTATION_TYPE() ? $::locale->text('The quotation has been saved')
|
|
2714 |
: $self->type eq REQUEST_QUOTATION_TYPE() ? $::locale->text('The rfq has been saved')
|
|
2729 | 2715 |
: ''; |
2730 | 2716 |
flash_later('info', $text); |
2731 | 2717 |
|
Auch abrufbar als: Unified diff
TypeData: nutzte Konstanten anstatt String für Typen