X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FOrder.pm;h=9454a1e132368c098cf44df35a79e81cf2565f73;hb=15aab04c1710b3c8a2bf8785aef31f13a958a43e;hp=f0920f739d58eee038f5eb2fa0c52992493c51a6;hpb=fa91a37b164d2e8d1657948111a8da14154bc266;p=kivitendo-erp.git diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index f0920f739..9454a1e13 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -33,6 +33,7 @@ use SL::DB::Translation; use SL::Helper::CreatePDF qw(:all); use SL::Helper::PrintOptions; use SL::Helper::ShippedQty; +use SL::Helper::UserPreferences::DisplayPreferences; use SL::Helper::UserPreferences::PositionsScrollbar; use SL::Helper::UserPreferences::UpdatePositions; @@ -197,11 +198,19 @@ sub action_save { : ''; flash_later('info', $text); - my @redirect_params = ( - action => 'edit', - type => $self->type, - id => $self->order->id, - ); + my @redirect_params; + if ($::form->{back_to_caller}) { + @redirect_params = $::form->{callback} ? ($::form->{callback}) + : (controller => 'LoginScreen', action => 'user_login'); + + } else { + @redirect_params = ( + action => 'edit', + type => $self->type, + id => $self->order->id, + callback => $::form->{callback}, + ); + } $self->redirect_to(@redirect_params); } @@ -250,6 +259,10 @@ sub action_save_as_new { # Update employee $new_attrs{employee} = SL::DB::Manager::Employee->current; + # Warn on obsolete items + my @obsolete_positions = map { $_->position } grep { $_->part->obsolete } @{ $order->items_sorted }; + flash_later('warning', t8('This record containts obsolete items at position #1', join ', ', @obsolete_positions)) if @obsolete_positions; + # Create new record from current one $self->order(SL::DB::Order->new_from($order, destination_type => $order->type, attributes => \%new_attrs)); @@ -438,12 +451,16 @@ sub action_save_and_show_email_dialog { $user && !!trim($user->get_config_value('email')); } @{ SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]) }; + + my $all_partner_email_addresses = $self->order->customervendor->get_all_email_addresses(); + my $dialog_html = $self->render('common/_send_email_dialog', { output => 0 }, email_form => $email_form, show_bcc => $::auth->assert('email_bcc', 'may fail'), FILES => \%files, is_customer => $self->cv eq 'customer', ALL_EMPLOYEES => \@employees_with_email, + ALL_PARTNER_EMAIL_ADDRESSES => $all_partner_email_addresses, ); $self->js @@ -469,6 +486,12 @@ sub action_send_email { $self->js_reset_order_and_item_ids_after_save; my $email_form = delete $::form->{email_form}; + + if ($email_form->{additional_to}) { + $email_form->{to} = join ', ', grep { $_ } $email_form->{to}, @{$email_form->{additional_to}}; + delete $email_form->{additional_to}; + } + my %field_names = (to => 'email'); $::form->{ $field_names{$_} // $_ } = $email_form->{$_} for keys %{ $email_form }; @@ -864,6 +887,62 @@ sub action_unit_changed { $self->js->render(); } +# update item input row when a part ist picked +sub action_update_item_input_row { + my ($self) = @_; + + delete $::form->{add_item}->{$_} for qw(create_part_type sellprice_as_number discount_as_percent); + + my $form_attr = $::form->{add_item}; + + return unless $form_attr->{parts_id}; + + my $record = $self->order; + my $item = SL::DB::OrderItem->new(%$form_attr); + my $part = SL::DB::Part->new(id => $::form->{add_item}->{parts_id})->load; + my $price_source = SL::PriceSource->new(record_item => $item, record => $record); + + $item->unit($part->unit); + + my $price_src; + if ( $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); + } elsif (defined $item->sellprice) { + $price_src = $price_source->price_from_source(""); + $price_src->price($item->sellprice); + } else { + $price_src = $price_source->best_price + ? $price_source->best_price + : $price_source->price_from_source(""); + $price_src->price($::form->round_amount($price_src->price / $record->exchangerate, 5)) if $record->exchangerate; + $price_src->price(0) if !$price_source->best_price; + } + + my $discount_src; + if (defined $item->discount) { + $discount_src = $price_source->discount_from_source(""); + $discount_src->discount($item->discount); + } else { + $discount_src = $price_source->best_discount + ? $price_source->best_discount + : $price_source->discount_from_source(""); + $discount_src->discount(0) if !$price_source->best_discount; + } + + $self->js + ->val ('#add_item_unit', $item->unit) + ->val ('#add_item_description', $part->description) + ->val ('#add_item_sellprice_as_number', '') + ->attr ('#add_item_sellprice_as_number', 'placeholder', $price_src->price_as_number) + ->attr ('#add_item_sellprice_as_number', 'title', $price_src->source_description) + ->val ('#add_item_discount_as_percent', '') + ->attr ('#add_item_discount_as_percent', 'placeholder', $discount_src->discount_as_percent) + ->attr ('#add_item_discount_as_percent', 'title', $discount_src->source_description) + ->render; +} + # add an item row for a new item entered in the input row sub action_add_item { my ($self) = @_; @@ -931,6 +1010,8 @@ sub action_add_item { $self->js ->val('.add_item_input', '') + ->attr('.add_item_input', 'placeholder', '') + ->attr('.add_item_input', 'title', '') ->run('kivi.Order.init_row_handlers') ->run('kivi.Order.renumber_positions') ->focus('#add_item_parts_id_name'); @@ -1084,11 +1165,11 @@ sub action_create_part { flash_later('info', t8('You are adding a new part while you are editing another document. You will be redirected to your document when saving the new part or aborting this form.')); my @redirect_params = ( - controller => 'Part', - action => 'add', - part_type => $::form->{add_item}->{create_part_type}, - callback => $callback, - show_abort => 1, + controller => 'Part', + action => 'add', + part_type => $::form->{add_item}->{create_part_type}, + callback => $callback, + inline_create => 1, ); $self->redirect_to(@redirect_params); @@ -1847,7 +1928,10 @@ sub workflow_sales_or_request_for_quotation { 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)); - $self->{converted_from_oe_id} = delete $::form->{id}; + 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}) { @@ -1947,7 +2031,7 @@ sub pre_render { $self->{all_taxzones} = SL::DB::Manager::TaxZone->get_all_sorted(); $self->{all_currencies} = SL::DB::Manager::Currency->get_all_sorted(); $self->{all_departments} = SL::DB::Manager::Department->get_all_sorted(); - $self->{all_languages} = SL::DB::Manager::Language->get_all_sorted(); + $self->{all_languages} = SL::DB::Manager::Language->get_all_sorted( query => [ or => [ obsolete => 0, id => $self->order->language_id ] ] ); $self->{all_employees} = SL::DB::Manager::Employee->get_all(where => [ or => [ id => $self->order->employee_id, deleted => 0 ] ], sort_by => 'name'); @@ -2004,6 +2088,7 @@ sub pre_render { && $::instance_conf->get_transport_cost_reminder_article_number_id ) { $self->{template_args}->{transport_cost_reminder_article} = SL::DB::Part->new(id => $::instance_conf->get_transport_cost_reminder_article_number_id)->load; } + $self->{template_args}->{longdescription_dialog_size_percentage} = SL::Helper::UserPreferences::DisplayPreferences->new()->get_longdescription_dialog_size_percentage(); $self->get_item_cvpartnumber($_) for @{$self->order->items_sorted}; @@ -2052,6 +2137,17 @@ sub setup_edit_action_bar { ], disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, ], + action => [ + t8('Save and Close'), + call => [ 'kivi.Order.save', 'save', $::instance_conf->get_order_warn_duplicate_parts, + $::instance_conf->get_order_warn_no_deliverydate, + 1 + ], + checks => [ 'kivi.Order.check_save_active_periodic_invoices', ['kivi.validate_form','#order_form'], + @req_trans_cost_art, @req_cusordnumber, + ], + disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, + ], action => [ t8('Save as new'), call => [ 'kivi.Order.save', 'save_as_new', $::instance_conf->get_order_warn_duplicate_parts ], @@ -2204,6 +2300,22 @@ sub setup_edit_action_bar { only_if => $deletion_allowed, ], + combobox => [ + action => [ + t8('more') + ], + action => [ + t8('History'), + call => [ 'set_history_window', $self->order->id, 'id' ], + disabled => !$self->order->id ? t8('This record has not been saved yet.') : undef, + ], + action => [ + t8('Follow-Up'), + call => [ 'kivi.Order.follow_up_window' ], + disabled => !$self->order->id ? t8('This object has not been saved yet.') : undef, + only_if => $::auth->assert('productivity', 1), + ], + ], # end of combobox "more" ); } } @@ -2657,21 +2769,10 @@ java script functions =item * -Customer discount is not displayed as a valid discount in price source popup -(this might be a bug in price sources) - -(I cannot reproduce this (Bernd)) - -=item * - No indication that -up/down expands/collapses second row. =item * -Inline creation of parts is not currently supported - -=item * - Table header is not sticky in the scrolling area. =item * @@ -2694,10 +2795,6 @@ How to expand/collapse second row. Now it can be done clicking the icon or =item * -Possibility to select PriceSources in input row? - -=item * - This controller uses a (changed) copy of the template for the PriceSource dialog. Maybe there could be used one code source.