Revision b6185e74
Von Bernd Bleßmann vor etwa 7 Jahren hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
use SL::DB::Part;
|
||
use SL::DB::Printer;
|
||
use SL::DB::Language;
|
||
use SL::DB::RecordLink;
|
||
|
||
use SL::Helper::CreatePDF qw(:all);
|
||
use SL::Helper::PrintOptions;
|
||
... | ... | |
$self->_pre_render();
|
||
$self->render(
|
||
'order/form',
|
||
title => $self->type eq _sales_order_type() ? $::locale->text('Add Sales Order')
|
||
: $self->type eq _purchase_order_type() ? $::locale->text('Add Purchase Order')
|
||
: $self->type eq _sales_quotation_type() ? $::locale->text('Add Quotation')
|
||
: $self->type eq _request_quotation_type() ? $::locale->text('Add Request for Quotation')
|
||
: '',
|
||
title => $self->_get_title_for('add'),
|
||
%{$self->{template_args}}
|
||
);
|
||
}
|
||
... | ... | |
$self->_pre_render();
|
||
$self->render(
|
||
'order/form',
|
||
title => $self->type eq _sales_order_type() ? $::locale->text('Edit Sales Order')
|
||
: $self->type eq _purchase_order_type() ? $::locale->text('Edit Purchase Order')
|
||
: $self->type eq _sales_quotation_type() ? $::locale->text('Edit Quotation')
|
||
: $self->type eq _request_quotation_type() ? $::locale->text('Edit Request for Quotation')
|
||
: '',
|
||
title => $self->_get_title_for('edit'),
|
||
%{$self->{template_args}}
|
||
);
|
||
}
|
||
... | ... | |
$self->redirect_to(@redirect_params);
|
||
}
|
||
|
||
# workflow from sales quotation to sales order
|
||
sub action_sales_order {
|
||
$_[0]->_workflow_sales_or_purchase_order();
|
||
}
|
||
|
||
# workflow from rfq to purchase order
|
||
sub action_purchase_order {
|
||
$_[0]->_workflow_sales_or_purchase_order();
|
||
}
|
||
|
||
# set form elements in respect to a changed customer or vendor
|
||
#
|
||
# This action is called on an change of the customer/vendor picker.
|
||
... | ... | |
$item ||= SL::DB::OrderItem->new(custom_variables => []);
|
||
|
||
$item->assign_attributes(%$attr);
|
||
$item->longdescription($item->part->notes) if $is_new && !defined $attr->{longdescription};
|
||
$item->project_id($record->globalproject_id) if $is_new && !defined $attr->{project_id};
|
||
$item->lastcost($item->part->lastcost) if $is_new && !defined $attr->{lastcost_as_number};
|
||
$item->longdescription($item->part->notes) if $is_new && !defined $attr->{longdescription};
|
||
$item->project_id($record->globalproject_id) if $is_new && !defined $attr->{project_id};
|
||
$item->lastcost($record->is_sales ? $item->part->lastcost : 0) if $is_new && !defined $attr->{lastcost_as_number};
|
||
|
||
return $item;
|
||
}
|
||
... | ... | |
$new_attr{active_discount_source} = $discount_src;
|
||
$new_attr{longdescription} = $part->notes if ! defined $attr->{longdescription};
|
||
$new_attr{project_id} = $record->globalproject_id;
|
||
$new_attr{lastcost} = $part->lastcost;
|
||
$new_attr{lastcost} = $record->is_sales ? $part->lastcost : 0;
|
||
|
||
# add_custom_variables adds cvars to an orderitem with no cvars for saving, but
|
||
# they cannot be retrieved via custom_variables until the order/orderitem is
|
||
... | ... | |
$db->with_transaction(sub {
|
||
SL::DB::OrderItem->new(id => $_)->delete for @{$self->item_ids_to_delete};
|
||
$self->order->save(cascade => 1);
|
||
|
||
# link records
|
||
if ($::form->{converted_from_oe_id}) {
|
||
SL::DB::Order->new(id => $::form->{converted_from_oe_id})->load->link_to_record($self->order);
|
||
|
||
if (scalar @{ $::form->{converted_from_orderitems_ids} || [] }) {
|
||
my $idx = 0;
|
||
foreach (@{ $self->order->items_sorted }) {
|
||
my $from_id = $::form->{converted_from_orderitems_ids}->[$idx];
|
||
next if !$from_id;
|
||
SL::DB::RecordLink->new(from_table => 'orderitems',
|
||
from_id => $from_id,
|
||
to_table => 'orderitems',
|
||
to_id => $_->id
|
||
)->save;
|
||
$idx++;
|
||
}
|
||
}
|
||
}
|
||
1;
|
||
}) || push(@{$errors}, $db->error);
|
||
|
||
return $errors;
|
||
}
|
||
|
||
sub _workflow_sales_or_purchase_order {
|
||
my ($self) = @_;
|
||
|
||
my $destination_type = $::form->{type} eq _sales_quotation_type() ? _sales_order_type()
|
||
: $::form->{type} eq _request_quotation_type() ? _purchase_order_type()
|
||
: '';
|
||
|
||
$self->order(SL::DB::Order->new_from($self->order, destination_type => $destination_type));
|
||
$self->{converted_from_oe_id} = delete $::form->{id};
|
||
|
||
# change form type
|
||
$::form->{type} = $destination_type;
|
||
$self->init_type;
|
||
$self->_check_auth;
|
||
|
||
$self->_recalc();
|
||
$self->_get_unalterable_data();
|
||
$self->_pre_render();
|
||
|
||
# trigger rendering values for second row/longdescription 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 };
|
||
$_->{render_longdescription} = 1 for @{ $self->order->items_sorted };
|
||
|
||
$self->render(
|
||
'order/form',
|
||
title => $self->_get_title_for('edit'),
|
||
%{$self->{template_args}}
|
||
);
|
||
}
|
||
|
||
|
||
sub _pre_render {
|
||
my ($self) = @_;
|
||
... | ... | |
call => [ 'kivi.Order.save_and_invoice', $::instance_conf->get_order_warn_duplicate_parts ],
|
||
checks => [ 'kivi.Order.check_save_active_periodic_invoices' ],
|
||
],
|
||
|
||
], # end of combobox "Save"
|
||
|
||
combobox => [
|
||
action => [
|
||
t8('Workflow'),
|
||
],
|
||
action => [
|
||
t8('Sales Order'),
|
||
submit => [ '#order_form', { action => "Order/sales_order" } ],
|
||
only_if => (any { $self->type eq $_ } (_sales_quotation_type())),
|
||
],
|
||
action => [
|
||
t8('Purchase Order'),
|
||
submit => [ '#order_form', { action => "Order/purchase_order" } ],
|
||
only_if => (any { $self->type eq $_ } (_request_quotation_type())),
|
||
],
|
||
], # end of combobox "Workflow"
|
||
|
||
combobox => [
|
||
action => [
|
||
t8('Export'),
|
||
... | ... | |
return $active ? t8('active') : t8('inactive');
|
||
}
|
||
|
||
sub _get_title_for {
|
||
my ($self, $action) = @_;
|
||
|
||
return '' if none { lc($action)} qw(add edit);
|
||
|
||
# for locales:
|
||
# $::locale->text("Add Sales Order");
|
||
# $::locale->text("Add Purchase Order");
|
||
# $::locale->text("Add Quotation");
|
||
# $::locale->text("Add Request for Quotation");
|
||
# $::locale->text("Edit Sales Order");
|
||
# $::locale->text("Edit Purchase Order");
|
||
# $::locale->text("Edit Quotation");
|
||
# $::locale->text("Edit Request for Quotation");
|
||
|
||
$action = ucfirst(lc($action));
|
||
return $self->type eq _sales_order_type() ? $::locale->text("$action Sales Order")
|
||
: $self->type eq _purchase_order_type() ? $::locale->text("$action Purchase Order")
|
||
: $self->type eq _sales_quotation_type() ? $::locale->text("$action Quotation")
|
||
: $self->type eq _request_quotation_type() ? $::locale->text("$action Request for Quotation")
|
||
: '';
|
||
}
|
||
|
||
sub _sales_order_type {
|
||
'sales_order';
|
||
}
|
templates/webpages/order/form.html | ||
---|---|---|
</div>
|
||
|
||
<form method="post" action="controller.pl" id="order_form">
|
||
[% L.hidden_tag('callback', FORM.callback) %]
|
||
[% L.hidden_tag('type', FORM.type) %]
|
||
[% L.hidden_tag('id', SELF.order.id) %]
|
||
[% L.hidden_tag('callback', FORM.callback) %]
|
||
[% L.hidden_tag('type', FORM.type) %]
|
||
[% L.hidden_tag('id', SELF.order.id) %]
|
||
[% L.hidden_tag('converted_from_oe_id', SELF.converted_from_oe_id) %]
|
||
|
||
[%- INCLUDE 'common/flash.html' %]
|
||
|
templates/webpages/order/tabs/_row.html | ||
---|---|---|
alt=LxERP.t8('Show details'), title=LxERP.t8('Show details'), class="expand") %]
|
||
[%- END %]
|
||
[% L.hidden_tag("orderitem_ids[+]", ID) %]
|
||
[% L.hidden_tag("converted_from_orderitems_ids[+]", ITEM.converted_from_orderitems_id) %]
|
||
[% L.hidden_tag("order.orderitems[+].id", ITEM.id, id='item_' _ ID) %]
|
||
[% L.hidden_tag("order.orderitems[].parts_id", ITEM.parts_id) %]
|
||
</td>
|
||
... | ... | |
ITEM.description,
|
||
size='40',
|
||
style='width: 300px') %]
|
||
[%- IF ITEM.render_longdescription -%]
|
||
[%- L.hidden_tag("order.orderitems[].longdescription", ITEM.longdescription) %]
|
||
[%- END -%]
|
||
[%- L.button_tag("kivi.Order.show_longdescription_dialog(this)", LxERP.t8("L")) %]
|
||
</td>
|
||
<td>
|
||
... | ... | |
|
||
<tr [%- IF !MYCONFIG.show_form_details -%]style="display:none"[%- END -%]>
|
||
<td colspan="100%">
|
||
[%- IF MYCONFIG.show_form_details %]
|
||
[%- IF MYCONFIG.show_form_details || ITEM.render_second_row %]
|
||
<div name="second_row" data-loaded="1">
|
||
[%- PROCESS order/tabs/_second_row.html ITEM=ITEM TYPE=TYPE %]
|
||
</div>
|
Auch abrufbar als: Unified diff
Auftrags-Controller: Workflow von Angebot nach Auftrag (Ein- und Verkauf).