Revision 9619d8be
Von Bernd Bleßmann vor mehr als 2 Jahren hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
);
|
||
}
|
||
|
||
# workflow from sales order to sales quotation
|
||
sub action_save_and_sales_quotation {
|
||
# workflows to all types of this controller
|
||
sub action_save_and_order_workflow {
|
||
$_[0]->save_and_redirect_to(
|
||
action => 'sales_or_request_for_quotation',
|
||
type => $_[0]->type,
|
||
);
|
||
}
|
||
|
||
# workflow from sales order to sales quotation
|
||
sub action_save_and_request_for_quotation {
|
||
$_[0]->save_and_redirect_to(
|
||
action => 'sales_or_request_for_quotation',
|
||
type => $_[0]->type,
|
||
);
|
||
}
|
||
|
||
# workflow from sales quotation to sales order
|
||
sub action_save_and_sales_order {
|
||
$_[0]->save_and_redirect_to(
|
||
action => 'sales_or_purchase_order',
|
||
type => $_[0]->type,
|
||
use_shipto => $::form->{use_shipto},
|
||
);
|
||
}
|
||
|
||
# workflow from rfq to purchase order
|
||
sub action_save_and_purchase_order {
|
||
$_[0]->save_and_redirect_to(
|
||
action => 'sales_or_purchase_order',
|
||
action => 'order_workflow',
|
||
type => $_[0]->type,
|
||
to_type => $::form->{to_type},
|
||
use_shipto => $::form->{use_shipto},
|
||
);
|
||
}
|
||
... | ... | |
);
|
||
}
|
||
|
||
sub action_sales_or_purchase_order {
|
||
sub action_order_workflow {
|
||
my ($self) = @_;
|
||
|
||
$self->load_order;
|
||
|
||
my $destination_type = $::form->{type} eq sales_quotation_type() ? sales_order_type()
|
||
: $::form->{type} eq request_quotation_type() ? purchase_order_type()
|
||
: $::form->{type} eq purchase_order_type() ? sales_order_type()
|
||
: $::form->{type} eq sales_order_type() ? purchase_order_type()
|
||
: '';
|
||
my $destination_type = $::form->{to_type} ? $::form->{to_type} : '';
|
||
|
||
# check for direct delivery
|
||
# copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
|
||
... | ... | |
}
|
||
|
||
$self->order(SL::DB::Order->new_from($self->order, destination_type => $destination_type));
|
||
$self->{converted_from_oe_id} = delete $::form->{id};
|
||
|
||
# no linked records from order to quotations
|
||
if (any { $destination_type eq $_ } (sales_quotation_type(), request_quotation_type())) {
|
||
delete $::form->{id};
|
||
delete $::form->{$_} for qw(converted_from_oe_id converted_from_orderitems_ids);
|
||
} else {
|
||
$self->{converted_from_oe_id} = delete $::form->{id};
|
||
}
|
||
|
||
# set item ids to new fake id, to identify them as new items
|
||
foreach my $item (@{$self->order->items_sorted}) {
|
||
... | ... | |
);
|
||
}
|
||
|
||
sub action_sales_or_request_for_quotation {
|
||
my ($self) = @_;
|
||
|
||
$self->load_order;
|
||
|
||
my $destination_type = $::form->{type} eq sales_order_type() ? sales_quotation_type() : request_quotation_type();
|
||
|
||
$self->order(SL::DB::Order->new_from($self->order, destination_type => $destination_type));
|
||
delete $::form->{id};
|
||
|
||
# no linked records from order to quotations
|
||
delete $::form->{$_} for qw(converted_from_oe_id converted_from_orderitems_ids);
|
||
|
||
# set item ids to new fake id, to identify them as new items
|
||
foreach my $item (@{$self->order->items_sorted}) {
|
||
$item->{new_fake_id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
|
||
}
|
||
|
||
# change form type
|
||
$::form->{type} = $destination_type;
|
||
$self->type($self->init_type);
|
||
$self->cv ($self->init_cv);
|
||
$self->check_auth;
|
||
|
||
$self->recalc();
|
||
$self->get_unalterable_data();
|
||
$self->pre_render();
|
||
|
||
# trigger rendering values for second row as hidden, because they
|
||
# are loaded only on demand. So we need to keep the values from the
|
||
# source.
|
||
$_->{render_second_row} = 1 for @{ $self->order->items_sorted };
|
||
|
||
$self->render(
|
||
'order/form',
|
||
title => $self->get_title_for('edit'),
|
||
%{$self->{template_args}}
|
||
);
|
||
}
|
||
|
||
# set form elements in respect to a changed customer or vendor
|
||
#
|
||
# This action is called on an change of the customer/vendor picker.
|
||
... | ... | |
],
|
||
action => [
|
||
t8('Save and Quotation'),
|
||
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_sales_quotation"), '#order_form' ],
|
||
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => sales_quotation_type()), '#order_form' ],
|
||
checks => [ @req_trans_cost_art, @req_cusordnumber ],
|
||
only_if => (any { $self->type eq $_ } (sales_order_type())),
|
||
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
|
||
],
|
||
action => [
|
||
t8('Save and RFQ'),
|
||
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_request_for_quotation"), '#order_form' ],
|
||
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => request_quotation_type()), '#order_form' ],
|
||
only_if => (any { $self->type eq $_ } (purchase_order_type())),
|
||
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
|
||
],
|
||
action => [
|
||
t8('Save and Sales Order'),
|
||
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_sales_order"), '#order_form' ],
|
||
call => [ 'kivi.submit_ajax_form', $self->url_for(action => "save_and_order_workflow", to_type => sales_order_type()), '#order_form' ],
|
||
checks => [ @req_trans_cost_art ],
|
||
only_if => (any { $self->type eq $_ } (sales_quotation_type(), purchase_order_type())),
|
||
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
|
||
],
|
||
action => [
|
||
t8('Save and Purchase Order'),
|
||
call => [ 'kivi.Order.purchase_order_check_for_direct_delivery' ],
|
||
call => [ 'kivi.Order.purchase_order_check_for_direct_delivery', { to_type => purchase_order_type() } ],
|
||
checks => [ @req_trans_cost_art, @req_cusordnumber ],
|
||
only_if => (any { $self->type eq $_ } (sales_order_type(), request_quotation_type())),
|
||
disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
|
js/kivi.Order.js | ||
---|---|---|
kivi.SalesPurchase.edit_custom_shipto();
|
||
};
|
||
|
||
ns.purchase_order_check_for_direct_delivery = function() {
|
||
ns.purchase_order_check_for_direct_delivery = function(params) {
|
||
const to_type = params.to_type;
|
||
|
||
if ($('#type').val() != 'sales_order') {
|
||
kivi.submit_ajax_form("controller.pl", '#order_form', {action: 'Order/save_and_purchase_order'});
|
||
kivi.submit_ajax_form("controller.pl", '#order_form', {action: 'Order/save_and_order_workflow', to_type: to_type});
|
||
return;
|
||
}
|
||
|
||
... | ... | |
|
||
var use_it = false;
|
||
if (!empty) {
|
||
ns.direct_delivery_dialog(shipto);
|
||
ns.direct_delivery_dialog(shipto, to_type);
|
||
} else {
|
||
kivi.submit_ajax_form("controller.pl", '#order_form', {action: 'Order/save_and_purchase_order'});
|
||
kivi.submit_ajax_form("controller.pl", '#order_form', {action: 'Order/save_and_order_workflow', to_type: to_type});
|
||
}
|
||
};
|
||
|
||
ns.direct_delivery_callback = function(accepted) {
|
||
ns.direct_delivery_callback = function(accepted, to_type) {
|
||
$('#direct-delivery-dialog').dialog('close');
|
||
|
||
if (accepted) {
|
||
$('<input type="hidden" name="use_shipto">').appendTo('#order_form').val('1');
|
||
}
|
||
|
||
kivi.submit_ajax_form("controller.pl", '#order_form', {action: 'Order/save_and_purchase_order'});
|
||
kivi.submit_ajax_form("controller.pl", '#order_form', {action: 'Order/save_and_order_workflow', to_type: to_type});
|
||
};
|
||
|
||
ns.direct_delivery_dialog = function(shipto) {
|
||
ns.direct_delivery_dialog = function(shipto, to_type) {
|
||
$('#direct-delivery-dialog').remove();
|
||
|
||
var text1 = kivi.t8('You have entered or selected the following shipping address for this customer:');
|
||
var text2 = kivi.t8('Do you want to carry this shipping address over to the new purchase order so that the vendor can deliver the goods directly to your customer?');
|
||
var html = '<div id="direct-delivery-dialog"><p>' + text1 + '</p><p>' + shipto + '</p><p>' + text2 + '</p>';
|
||
html = html + '<hr><p>';
|
||
html = html + '<input type="button" value="' + kivi.t8('Yes') + '" size="30" onclick="kivi.Order.direct_delivery_callback(true)">';
|
||
html = html + '<input type="button" value="' + kivi.t8('Yes') + '" size="30" onclick="kivi.Order.direct_delivery_callback(true, \'' + to_type + '\')">';
|
||
html = html + ' ';
|
||
html = html + '<input type="button" value="' + kivi.t8('No') + '" size="30" onclick="kivi.Order.direct_delivery_callback(false)">';
|
||
html = html + '<input type="button" value="' + kivi.t8('No') + '" size="30" onclick="kivi.Order.direct_delivery_callback(false, \'' + to_type + '\')">';
|
||
html = html + '</p></div>';
|
||
$(html).hide().appendTo('#order_form');
|
||
|
Auch abrufbar als: Unified diff
Auftrags-Controller: Workflows zum Controller selber vereinheitlicht
Es gibt nun eine Methode für die Worklows und das Workflow-Ziel
wird übergeben.