From 5981dd661e770fe22d4bf2298846097c8096327f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Wed, 12 Aug 2015 01:08:54 +0200 Subject: [PATCH] Auftrags-Controller: Zentrale Eingabe-Zeile oben. --- SL/Controller/Order.pm | 35 ++++++++++++++-- templates/webpages/order/tabs/basic_data.html | 41 ++++++++++++++----- 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index ba56e669e..5c8513264 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -123,17 +123,46 @@ sub action_customer_vendor_changed { ->render($self); } -sub action_add_item_row { +sub action_add_item { my ($self) = @_; - my $random_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000); - my $row_as_html = $self->p->render('order/tabs/_row', ITEM => {id => $random_id}); + my $form_attr = $::form->{add_item}; + my $item = SL::DB::OrderItem->new; + $item->assign_attributes(%$form_attr); + + my $part = SL::DB::Part->new(id => $form_attr->{parts_id})->load; + my $cv_class = "SL::DB::" . ucfirst($self->cv); + my $cv_discount = $::form->{$self->cv . '_id'}? $cv_class->new(id => $::form->{$self->cv . '_id'})->load->discount :0.0; + + my %new_attr; + $new_attr{id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000); + $new_attr{part} = $part; + $new_attr{qty} = 1.0 if ! $item->{qty}; + $new_attr{unit} = $part->unit; + $new_attr{sellprice} = $part->sellprice if ! $item->{sellprice}; + $new_attr{discount} = $cv_discount if ! $item->{discount}; + $item->assign_attributes(%new_attr); + + # add_items seems to fail if no items had been added before + if ($self->order->items) { + $self->order->add_items($item); + } else { + $self->order->items([$item]); + } + + $self->_setup(); + + my $row_as_html = $self->p->render('order/tabs/_row', ITEM => $item); $self->js ->append('#row_table_id tbody', $row_as_html) ->focus('#row_table_id tr:last [id$="parts_id_name"]') ->off('[id^="order_orderitems"][id$="parts_id"]', 'change', 'set_item_values') ->on('[id^="order_orderitems"][id$="parts_id"]', 'change', 'set_item_values') + ->html('#netamount_id', $::form->format_amount(\%::myconfig, $self->order->netamount, -2)) + ->html('#amount_id', $::form->format_amount(\%::myconfig, $self->order->amount, -2)) + ->remove('.tax_row') + ->insertBefore($self->build_tax_rows, '#amount_row_id') ->render($self); } diff --git a/templates/webpages/order/tabs/basic_data.html b/templates/webpages/order/tabs/basic_data.html index fda5f10e8..52bb065d7 100644 --- a/templates/webpages/order/tabs/basic_data.html +++ b/templates/webpages/order/tabs/basic_data.html @@ -102,6 +102,30 @@ +
+ + + + + + + + + + + + + + + + + + + +
[%- 'Part' | $T8 %] [%- 'Qty' | $T8 %] [%- 'Price' | $T8 %] [%- 'Discount' | $T8 %]
[% L.part_picker('add_item.parts_id', '', style='width: 300px') %][% L.input_tag('add_item.qty_as_number', '', size = 5, style='text-align:right') %][% L.input_tag('add_item.sellprice_as_number', '', size = 10, style='text-align:right') %][% L.input_tag('add_item.discount_as_percent', '', size = 5, style='text-align:right') %][% L.button_tag('add_item()', LxERP.t8('Add part')) %]
+ +
+
@@ -125,9 +149,6 @@ [%- FOREACH item = SELF.order.items_sorted %] [%- PROCESS order/tabs/_row.html ITEM=item %] [%- END %] - [%- IF !SELF.order.items.size %] - [%- PROCESS order/tabs/_row.html ITEM='' %] - [%- END %]
@@ -137,10 +158,6 @@ - - [%- L.button_tag('add_order_item_row()', LxERP.t8("Add Row")) -%] - - @@ -183,10 +200,12 @@ function reload_cv_dependend_selections() { }, kivi.eval_json_result); } -function add_order_item_row() { - $.post("controller.pl", { 'action': 'Order/add_item_row', - 'type' : function(){ return $('#type').val() } - }, kivi.eval_json_result); +function add_item() { + var data = $('#order_form').serialize(); + data += '&action=Order/add_item'; + data += '&type=' + $('#type').val(); + + $.post("controller.pl", data, kivi.eval_json_result); } function delete_order_item_row(clicked) { -- 2.20.1