X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FController%2FOrder.pm;h=9b4c1bf4fb5abc7cc8e75c55ea4d3d43cdd8c5ca;hb=ff5279eda2b2e7fb378bfc65ea582b10a06ed604;hp=2f4a68f2bc883ebbee45860f3d78276d53f3fac1;hpb=a66591ccf74ff3d32ac31b6a91849a0476e54eb7;p=kivitendo-erp.git diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 2f4a68f2b..9b4c1bf4f 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -10,6 +10,7 @@ use SL::SessionFile::Random; use SL::PriceSource; use SL::Webdav; use SL::File; +use SL::MIME; use SL::Util qw(trim); use SL::YAML; use SL::DB::Order; @@ -47,10 +48,12 @@ use Rose::Object::MakeMethods::Generic __PACKAGE__->run_before('check_auth'); __PACKAGE__->run_before('recalc', - only => [ qw(save save_as_new save_and_delivery_order save_and_invoice print send_email) ]); + only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_ap_transaction + print send_email) ]); __PACKAGE__->run_before('get_unalterable_data', - only => [ qw(save save_as_new save_and_delivery_order save_and_invoice print send_email) ]); + only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_ap_transaction + print send_email) ]); # # actions @@ -360,7 +363,7 @@ sub action_download_pdf { my $tmp_filename = $::auth->get_session_value("Order::print-${key}"); return $self->send_file( $tmp_filename, - type => 'application/pdf', + type => SL::MIME->mime_type_from_ext($::form->{pdf_filename}), name => $::form->{pdf_filename}, ); } @@ -647,6 +650,33 @@ sub action_purchase_order { $_[0]->workflow_sales_or_purchase_order(); } +# workflow from purchase order to ap transaction +sub action_save_and_ap_transaction { + my ($self) = @_; + + my $errors = $self->save(); + + if (scalar @{ $errors }) { + $self->js->flash('error', $_) foreach @{ $errors }; + return $self->js->render(); + } + + my $text = $self->type eq sales_order_type() ? $::locale->text('The order has been saved') + : $self->type eq purchase_order_type() ? $::locale->text('The order has been saved') + : $self->type eq sales_quotation_type() ? $::locale->text('The quotation has been saved') + : $self->type eq request_quotation_type() ? $::locale->text('The rfq has been saved') + : ''; + flash_later('info', $text); + + my @redirect_params = ( + controller => 'ap.pl', + action => 'add_from_purchase_order', + id => $self->order->id, + ); + + $self->redirect_to(@redirect_params); +} + # set form elements in respect to a changed customer or vendor # # This action is called on an change of the customer/vendor picker. @@ -985,6 +1015,47 @@ sub action_load_second_rows { $self->js->render(); } +# update description, notes and sellprice from master data +sub action_update_row_from_master_data { + my ($self) = @_; + + foreach my $item_id (@{ $::form->{item_ids} }) { + my $idx = first_index { $_ eq $item_id } @{ $::form->{orderitem_ids} }; + my $item = $self->order->items_sorted->[$idx]; + + $item->description($item->part->description); + $item->longdescription($item->part->notes); + + my $price_source = SL::PriceSource->new(record_item => $item, record => $self->order); + + my $price_src; + if ($item->part->is_assortment) { + # add assortment items with price 0, as the components carry the price + $price_src = $price_source->price_from_source(""); + $price_src->price(0); + } else { + $price_src = $price_source->best_price + ? $price_source->best_price + : $price_source->price_from_source(""); + $price_src->price(0) if !$price_source->best_price; + } + + $item->sellprice($price_src->price); + $item->active_price_source($price_src); + + $self->js + ->run('kivi.Order.update_sellprice', $item_id, $item->sellprice_as_number) + ->val('.row_entry:has(#item_' . $item_id . ') [name = "order.orderitems[].description"]', $item->description) + ->val('.row_entry:has(#item_' . $item_id . ') [name = "order.orderitems[].longdescription"]', $item->longdescription); + } + + $self->recalc(); + $self->js_redisplay_line_values; + $self->js_redisplay_amounts_and_taxes; + + $self->js->render(); +} + sub js_load_second_row { my ($self, $item, $item_id, $do_parse) = @_; @@ -1694,6 +1765,12 @@ sub setup_edit_action_bar { call => [ 'kivi.Order.save', 'save_and_invoice', $::instance_conf->get_order_warn_duplicate_parts ], checks => [ 'kivi.Order.check_save_active_periodic_invoices' ], ], + action => [ + t8('Save and AP Transaction'), + call => [ 'kivi.Order.save', 'save_and_ap_transaction', $::instance_conf->get_order_warn_duplicate_parts ], + only_if => (any { $self->type eq $_ } (purchase_order_type())) + ], + ], # end of combobox "Workflow" combobox => [ @@ -1916,9 +1993,8 @@ SL::Controller::Order - controller for orders This is a new form to enter orders, completely rewritten with the use of controller and java script techniques. -The aim is to provide the user a better expirience and a faster flow -of work. Also the code should be more readable, more reliable and -better to maintain. +The aim is to provide the user a better experience and a faster workflow. Also +the code should be more readable, more reliable and better to maintain. =head2 Key Features @@ -1949,7 +2025,7 @@ possible (by partnumber, description, qty, sellprice and discount for now). =item * No C is necessary. All entries and calculations are managed -with ajax-calls and the page does only reload on C. +with ajax-calls and the page only reloads on C. =item *