Revision ac05693f
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)) |
... | ... | |
777 | 779 |
# can't use save_and_redirect_to, because id is set! |
778 | 780 |
$self->save(); |
779 | 781 |
|
780 |
my $to_type = $self->order->is_sales ? 'sales_reclamation'
|
|
781 |
: 'purchase_reclamation';
|
|
782 |
my $to_type = $self->order->is_sales ? SALES_RECLAMATION_TYPE()
|
|
783 |
: PURCHASE_RECLAMATION_TYPE();
|
|
782 | 784 |
$self->redirect_to( |
783 | 785 |
controller => 'Reclamation', |
784 | 786 |
action => 'add_from_order', |
... | ... | |
846 | 848 |
my $destination_type = $::form->{to_type} ? $::form->{to_type} : ''; |
847 | 849 |
|
848 | 850 |
my $from_side = $self->order->is_sales ? 'sales' : 'purchase'; |
849 |
my $to_side = (any { $destination_type eq $_ } (sales_order_type(), sales_quotation_type())) ? 'sales' : 'purchase';
|
|
851 |
my $to_side = (any { $destination_type eq $_ } (SALES_ORDER_TYPE(), SALES_QUOTATION_TYPE())) ? 'sales' : 'purchase';
|
|
850 | 852 |
|
851 | 853 |
# check for direct delivery |
852 | 854 |
# copy shipto in custom shipto (custom shipto will be copied by new_from() in case) |
... | ... | |
859 | 861 |
$self->order(SL::DB::Order->new_from($self->order, destination_type => $destination_type)); |
860 | 862 |
|
861 | 863 |
# no linked records to quotations from the same side (sales -> sales or purchase -> purchase) |
862 |
if ( (any { $destination_type eq $_ } (sales_quotation_type(), request_quotation_type()))
|
|
864 |
if ( (any { $destination_type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE()))
|
|
863 | 865 |
&& $from_side eq $to_side) { |
864 | 866 |
delete $::form->{id}; |
865 | 867 |
delete $::form->{$_} for qw(converted_from_oe_id converted_from_orderitems_ids); |
... | ... | |
1578 | 1580 |
# |
1579 | 1581 |
|
1580 | 1582 |
sub init_valid_types { |
1581 |
[ sales_order_type(), purchase_order_type(), sales_quotation_type(), request_quotation_type() ];
|
|
1583 |
$_[0]->type_data->valid_types;
|
|
1582 | 1584 |
} |
1583 | 1585 |
|
1584 | 1586 |
sub init_type { |
... | ... | |
1594 | 1596 |
sub init_cv { |
1595 | 1597 |
my ($self) = @_; |
1596 | 1598 |
|
1597 |
my $cv = (any { $self->type eq $_ } (sales_order_type(), sales_quotation_type())) ? 'customer'
|
|
1598 |
: (any { $self->type eq $_ } (purchase_order_type(), request_quotation_type())) ? 'vendor'
|
|
1599 |
my $cv = (any { $self->type eq $_ } (SALES_ORDER_TYPE(), SALES_QUOTATION_TYPE())) ? 'customer'
|
|
1600 |
: (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE(), REQUEST_QUOTATION_TYPE())) ? 'vendor'
|
|
1599 | 1601 |
: die "Not a valid type for order"; |
1600 | 1602 |
|
1601 | 1603 |
return $cv; |
... | ... | |
1815 | 1817 |
my $order; |
1816 | 1818 |
$order = SL::DB::Order->new(id => $::form->{id})->load(with => [ 'orderitems', 'orderitems.part' ]) if $::form->{id}; |
1817 | 1819 |
$order ||= SL::DB::Order->new(orderitems => [], |
1818 |
quotation => (any { $self->type eq $_ } (sales_quotation_type(), request_quotation_type())),
|
|
1820 |
quotation => (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE())),
|
|
1819 | 1821 |
currency_id => $::instance_conf->get_currency_id(),); |
1820 | 1822 |
|
1821 | 1823 |
my $cv_id_method = $self->cv . '_id'; |
... | ... | |
2129 | 2131 |
$item->active_discount_source($price_source->discount_from_source($item->active_discount_source)); |
2130 | 2132 |
} |
2131 | 2133 |
|
2132 |
if (any { $self->type eq $_ } (sales_order_type(), purchase_order_type())) {
|
|
2134 |
if (any { $self->type eq $_ } (SALES_ORDER_TYPE(), PURCHASE_ORDER_TYPE())) {
|
|
2133 | 2135 |
# Calculate shipped qtys here to prevent calling calculate for every item via the items method. |
2134 | 2136 |
# Do not use write_to_objects to prevent order->delivered to be set, because this should be |
2135 | 2137 |
# the value from db, which can be set manually or is set when linked delivery orders are saved. |
... | ... | |
2148 | 2150 |
} } @all_objects; |
2149 | 2151 |
} |
2150 | 2152 |
|
2151 |
if ( (any { $self->type eq $_ } (sales_quotation_type(), sales_order_type()))
|
|
2153 |
if ( (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), SALES_ORDER_TYPE()))
|
|
2152 | 2154 |
&& $::instance_conf->get_transport_cost_reminder_article_number_id ) { |
2153 | 2155 |
$self->{template_args}->{transport_cost_reminder_article} = SL::DB::Part->new(id => $::instance_conf->get_transport_cost_reminder_article_number_id)->load; |
2154 | 2156 |
} |
... | ... | |
2166 | 2168 |
sub setup_edit_action_bar { |
2167 | 2169 |
my ($self, %params) = @_; |
2168 | 2170 |
|
2169 |
my $deletion_allowed = (any { $self->type eq $_ } (sales_quotation_type(), request_quotation_type()))
|
|
2170 |
|| (($self->type eq sales_order_type()) && $::instance_conf->get_sales_order_show_delete)
|
|
2171 |
|| (($self->type eq purchase_order_type()) && $::instance_conf->get_purchase_order_show_delete);
|
|
2171 |
my $deletion_allowed = (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE()))
|
|
2172 |
|| (($self->type eq SALES_ORDER_TYPE()) && $::instance_conf->get_sales_order_show_delete)
|
|
2173 |
|| (($self->type eq PURCHASE_ORDER_TYPE()) && $::instance_conf->get_purchase_order_show_delete);
|
|
2172 | 2174 |
|
2173 | 2175 |
my @req_trans_cost_art = qw(kivi.Order.check_transport_cost_article_presence) x!!$::instance_conf->get_transport_cost_reminder_article_number_id; |
2174 |
my @req_cusordnumber = qw(kivi.Order.check_cusordnumber_presence) x($self->type eq sales_order_type() && $::instance_conf->get_order_warn_no_cusordnumber);
|
|
2176 |
my @req_cusordnumber = qw(kivi.Order.check_cusordnumber_presence) x($self->type eq SALES_ORDER_TYPE() && $::instance_conf->get_order_warn_no_cusordnumber);
|
|
2175 | 2177 |
|
2176 | 2178 |
my $has_invoice_for_advance_payment; |
2177 |
if ($self->order->id && $self->type eq sales_order_type()) {
|
|
2179 |
if ($self->order->id && $self->type eq SALES_ORDER_TYPE()) {
|
|
2178 | 2180 |
my $lr = $self->order->linked_records(direction => 'to', to => ['Invoice']); |
2179 | 2181 |
$has_invoice_for_advance_payment = any {'SL::DB::Invoice' eq ref $_ && "invoice_for_advance_payment" eq $_->type} @$lr; |
2180 | 2182 |
} |
2181 | 2183 |
|
2182 | 2184 |
my $has_final_invoice; |
2183 |
if ($self->order->id && $self->type eq sales_order_type()) {
|
|
2185 |
if ($self->order->id && $self->type eq SALES_ORDER_TYPE()) {
|
|
2184 | 2186 |
my $lr = $self->order->linked_records(direction => 'to', to => ['Invoice']); |
2185 | 2187 |
$has_final_invoice = any {'SL::DB::Invoice' eq ref $_ && "final_invoice" eq $_->type} @$lr; |
2186 | 2188 |
} |
... | ... | |
2248 | 2250 |
], |
2249 | 2251 |
action => [ |
2250 | 2252 |
t8('Save and Quotation'), |
2251 |
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => sales_quotation_type()), '#order_form' ],
|
|
2253 |
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => SALES_QUOTATION_TYPE()), '#order_form' ],
|
|
2252 | 2254 |
checks => [ @req_trans_cost_art, @req_cusordnumber ], |
2253 |
only_if => (any { $self->type eq $_ } (sales_order_type(), request_quotation_type())),
|
|
2255 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), REQUEST_QUOTATION_TYPE())),
|
|
2254 | 2256 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2255 | 2257 |
], |
2256 | 2258 |
action => [ |
2257 | 2259 |
t8('Save and RFQ'), |
2258 |
call => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => request_quotation_type() } ],
|
|
2259 |
only_if => (any { $self->type eq $_ } (sales_order_type(), sales_quotation_type(), purchase_order_type())),
|
|
2260 |
call => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => REQUEST_QUOTATION_TYPE() } ],
|
|
2261 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), SALES_QUOTATION_TYPE(), PURCHASE_ORDER_TYPE())),
|
|
2260 | 2262 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2261 | 2263 |
], |
2262 | 2264 |
action => [ |
2263 | 2265 |
t8('Save and Sales Order'), |
2264 |
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => sales_order_type()), '#order_form' ],
|
|
2266 |
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => SALES_ORDER_TYPE()), '#order_form' ],
|
|
2265 | 2267 |
checks => [ @req_trans_cost_art ], |
2266 |
only_if => (any { $self->type eq $_ } (sales_quotation_type(), request_quotation_type(), purchase_order_type())),
|
|
2268 |
only_if => (any { $self->type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE(), PURCHASE_ORDER_TYPE())),
|
|
2267 | 2269 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2268 | 2270 |
], |
2269 | 2271 |
action => [ |
2270 | 2272 |
t8('Save and Purchase Order'), |
2271 |
call => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => purchase_order_type() } ],
|
|
2273 |
call => [ 'kivi.Order.purchase_check_for_direct_delivery', { to_type => PURCHASE_ORDER_TYPE() } ],
|
|
2272 | 2274 |
checks => [ @req_trans_cost_art, @req_cusordnumber ], |
2273 |
only_if => (any { $self->type eq $_ } (sales_order_type(), request_quotation_type())),
|
|
2275 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), REQUEST_QUOTATION_TYPE())),
|
|
2274 | 2276 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2275 | 2277 |
], |
2276 | 2278 |
action => [ |
... | ... | |
2282 | 2284 |
checks => [ 'kivi.Order.check_save_active_periodic_invoices', |
2283 | 2285 |
@req_trans_cost_art, @req_cusordnumber, |
2284 | 2286 |
], |
2285 |
only_if => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type())),
|
|
2287 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), PURCHASE_ORDER_TYPE())),
|
|
2286 | 2288 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2287 | 2289 |
], |
2288 | 2290 |
action => [ |
... | ... | |
2294 | 2296 |
checks => [ 'kivi.Order.check_save_active_periodic_invoices', |
2295 | 2297 |
@req_trans_cost_art, @req_cusordnumber, |
2296 | 2298 |
], |
2297 |
only_if => (any { $self->type eq $_ } (purchase_order_type())),
|
|
2299 |
only_if => (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE())),
|
|
2298 | 2300 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, |
2299 | 2301 |
], |
2300 | 2302 |
action => [ |
... | ... | |
2302 | 2304 |
call => [ 'kivi.Order.save', { action => 'save_and_reclamation', |
2303 | 2305 |
warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts }, |
2304 | 2306 |
], |
2305 |
only_if => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type()))
|
|
2307 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE(), PURCHASE_ORDER_TYPE()))
|
|
2306 | 2308 |
], |
2307 | 2309 |
action => [ |
2308 | 2310 |
t8('Save and Invoice'), |
... | ... | |
2325 | 2327 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') |
2326 | 2328 |
: $has_final_invoice ? t8('This order has already a final invoice.') |
2327 | 2329 |
: undef, |
2328 |
only_if => (any { $self->type eq $_ } (sales_order_type())),
|
|
2330 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE())),
|
|
2329 | 2331 |
], |
2330 | 2332 |
action => [ |
2331 | 2333 |
t8('Save and Final Invoice'), |
... | ... | |
2338 | 2340 |
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') |
2339 | 2341 |
: $has_final_invoice ? t8('This order has already a final invoice.') |
2340 | 2342 |
: undef, |
2341 |
only_if => (any { $self->type eq $_ } (sales_order_type())) && $has_invoice_for_advance_payment,
|
|
2343 |
only_if => (any { $self->type eq $_ } (SALES_ORDER_TYPE())) && $has_invoice_for_advance_payment,
|
|
2342 | 2344 |
], |
2343 | 2345 |
action => [ |
2344 | 2346 |
t8('Save and AP Transaction'), |
2345 | 2347 |
call => [ 'kivi.Order.save', { action => 'save_and_ap_transaction', |
2346 | 2348 |
warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts }, |
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 |
|
... | ... | |
2535 | 2537 |
sub get_periodic_invoices_status { |
2536 | 2538 |
my ($self, $config) = @_; |
2537 | 2539 |
|
2538 |
return if $self->type ne sales_order_type();
|
|
2540 |
return if $self->type ne SALES_ORDER_TYPE();
|
|
2539 | 2541 |
return t8('not configured') if !$config; |
2540 | 2542 |
|
2541 | 2543 |
my $active = ('HASH' eq ref $config) ? $config->{active} |
... | ... | |
2561 | 2563 |
# $::locale->text("Edit Request for Quotation"); |
2562 | 2564 |
|
2563 | 2565 |
$action = ucfirst(lc($action)); |
2564 |
return $self->type eq sales_order_type() ? $::locale->text("$action Sales Order")
|
|
2565 |
: $self->type eq purchase_order_type() ? $::locale->text("$action Purchase Order")
|
|
2566 |
: $self->type eq sales_quotation_type() ? $::locale->text("$action Quotation")
|
|
2567 |
: $self->type eq request_quotation_type() ? $::locale->text("$action Request for Quotation")
|
|
2566 |
return $self->type eq SALES_ORDER_TYPE() ? $::locale->text("$action Sales Order")
|
|
2567 |
: $self->type eq PURCHASE_ORDER_TYPE() ? $::locale->text("$action Purchase Order")
|
|
2568 |
: $self->type eq SALES_QUOTATION_TYPE() ? $::locale->text("$action Quotation")
|
|
2569 |
: $self->type eq REQUEST_QUOTATION_TYPE() ? $::locale->text("$action Request for Quotation")
|
|
2568 | 2570 |
: ''; |
2569 | 2571 |
} |
2570 | 2572 |
|
... | ... | |
2642 | 2644 |
return ($price_src, $discount_src); |
2643 | 2645 |
} |
2644 | 2646 |
|
2645 |
sub sales_order_type { |
|
2646 |
'sales_order'; |
|
2647 |
} |
|
2648 |
|
|
2649 |
sub purchase_order_type { |
|
2650 |
'purchase_order'; |
|
2651 |
} |
|
2652 |
|
|
2653 |
sub sales_quotation_type { |
|
2654 |
'sales_quotation'; |
|
2655 |
} |
|
2656 |
|
|
2657 |
sub request_quotation_type { |
|
2658 |
'request_quotation'; |
|
2659 |
} |
|
2660 |
|
|
2661 | 2647 |
sub nr_key { |
2662 |
return $_[0]->type eq sales_order_type() ? 'ordnumber'
|
|
2663 |
: $_[0]->type eq purchase_order_type() ? 'ordnumber'
|
|
2664 |
: $_[0]->type eq sales_quotation_type() ? 'quonumber'
|
|
2665 |
: $_[0]->type eq request_quotation_type() ? 'quonumber'
|
|
2648 |
return $_[0]->type eq SALES_ORDER_TYPE() ? 'ordnumber'
|
|
2649 |
: $_[0]->type eq PURCHASE_ORDER_TYPE() ? 'ordnumber'
|
|
2650 |
: $_[0]->type eq SALES_QUOTATION_TYPE() ? 'quonumber'
|
|
2651 |
: $_[0]->type eq REQUEST_QUOTATION_TYPE() ? 'quonumber'
|
|
2666 | 2652 |
: ''; |
2667 | 2653 |
} |
2668 | 2654 |
|
... | ... | |
2671 | 2657 |
|
2672 | 2658 |
$self->save(); |
2673 | 2659 |
|
2674 |
my $text = $self->type eq sales_order_type() ? $::locale->text('The order has been saved')
|
|
2675 |
: $self->type eq purchase_order_type() ? $::locale->text('The order has been saved')
|
|
2676 |
: $self->type eq sales_quotation_type() ? $::locale->text('The quotation has been saved')
|
|
2677 |
: $self->type eq request_quotation_type() ? $::locale->text('The rfq has been saved')
|
|
2660 |
my $text = $self->type eq SALES_ORDER_TYPE() ? $::locale->text('The order has been saved')
|
|
2661 |
: $self->type eq PURCHASE_ORDER_TYPE() ? $::locale->text('The order has been saved')
|
|
2662 |
: $self->type eq SALES_QUOTATION_TYPE() ? $::locale->text('The quotation has been saved')
|
|
2663 |
: $self->type eq REQUEST_QUOTATION_TYPE() ? $::locale->text('The rfq has been saved')
|
|
2678 | 2664 |
: ''; |
2679 | 2665 |
flash_later('info', $text); |
2680 | 2666 |
|
Auch abrufbar als: Unified diff
TypeData: nutzte Konstanten anstatt String für Typen