X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FOrder.pm;h=97dc5c94dc42d2f9b7e40860b13901272f889a28;hb=1268bf670c06f5a66ad78a75e41ad6c15061d9bc;hp=e13339b2e278ffe450f00123260e5d6931c4c9bf;hpb=c4a13349f53975eb5e1e0d8ae6f4e09f5a334797;p=kivitendo-erp.git diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index e13339b2e..97dc5c94d 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -24,6 +24,7 @@ use SL::DB::Part; use SL::DB::PartClassification; use SL::DB::PartsGroup; use SL::DB::Printer; +use SL::DB::Note; use SL::DB::Language; use SL::DB::RecordLink; use SL::DB::RequirementSpec; @@ -33,6 +34,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 +199,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 +260,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)); @@ -316,7 +330,7 @@ sub action_print { if ($media eq 'screen') { # screen/download - $self->js->flash('info', t8('The document has been created.')); + flash_later('info', t8('The document has been created.')); $self->send_file( \$doc, type => SL::MIME->mime_type_from_ext($doc_filename), @@ -332,20 +346,24 @@ sub action_print { content => $doc, ); - $self->js->flash('info', t8('The document has been printed.')); + flash_later('info', t8('The document has been printed.')); } my @warnings = $self->store_doc_to_webdav_and_filemanagement($doc, $doc_filename, $formname); if (scalar @warnings) { - $self->js->flash('warning', $_) for @warnings; + flash_later('warning', $_) for @warnings; } $self->save_history('PRINTED'); - $self->js - ->run('kivi.ActionBar.setEnabled', '#save_and_email_action') - ->render; + my @redirect_params = ( + action => 'edit', + type => $self->type, + id => $self->order->id, + ); + $self->js->redirect_to($self->url_for(@redirect_params))->render; } + sub action_preview_pdf { my ($self) = @_; @@ -381,14 +399,21 @@ sub action_preview_pdf { return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render; } $self->save_history('PREVIEWED'); - $self->js->flash('info', t8('The PDF has been previewed')); + flash_later('info', t8('The PDF has been previewed')); # screen/download $self->send_file( \$pdf, type => SL::MIME->mime_type_from_ext($pdf_filename), name => $pdf_filename, - js_no_render => 0, + js_no_render => 1, ); + + my @redirect_params = ( + action => 'edit', + type => $self->type, + id => $self->order->id, + ); + $self->js->redirect_to($self->url_for(@redirect_params))->render; } # open the email dialog @@ -402,6 +427,8 @@ sub action_save_and_show_email_dialog { return $self->js->render(); } + $self->js_reset_order_and_item_ids_after_save; + my $cv_method = $self->cv; if (!$self->order->$cv_method) { @@ -438,12 +465,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 +500,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 }; @@ -519,18 +556,20 @@ sub action_send_email { $::form->{id} = $self->order->id; # this is used in SL::Mailer to create a linked record to the mail $::form->send_email(\%::myconfig, $::form->{print_options}->{format}); - # internal notes - my $intnotes = $self->order->intnotes; - $intnotes .= "\n\n" if $self->order->intnotes; - $intnotes .= t8('[email]') . "\n"; - $intnotes .= t8('Date') . ": " . $::locale->format_date_object(DateTime->now_local, precision => 'seconds') . "\n"; - $intnotes .= t8('To (email)') . ": " . $::form->{email} . "\n"; - $intnotes .= t8('Cc') . ": " . $::form->{cc} . "\n" if $::form->{cc}; - $intnotes .= t8('Bcc') . ": " . $::form->{bcc} . "\n" if $::form->{bcc}; - $intnotes .= t8('Subject') . ": " . $::form->{subject} . "\n\n"; - $intnotes .= t8('Message') . ": " . SL::HTML::Util->strip($::form->{message}); + # internal notes unless no email journal + unless ($::instance_conf->get_email_journal) { + my $intnotes = $self->order->intnotes; + $intnotes .= "\n\n" if $self->order->intnotes; + $intnotes .= t8('[email]') . "\n"; + $intnotes .= t8('Date') . ": " . $::locale->format_date_object(DateTime->now_local, precision => 'seconds') . "\n"; + $intnotes .= t8('To (email)') . ": " . $::form->{email} . "\n"; + $intnotes .= t8('Cc') . ": " . $::form->{cc} . "\n" if $::form->{cc}; + $intnotes .= t8('Bcc') . ": " . $::form->{bcc} . "\n" if $::form->{bcc}; + $intnotes .= t8('Subject') . ": " . $::form->{subject} . "\n\n"; + $intnotes .= t8('Message') . ": " . SL::HTML::Util->strip($::form->{message}); - $self->order->update_attributes(intnotes => $intnotes); + $self->order->update_attributes(intnotes => $intnotes); + } $self->save_history('MAILED'); @@ -862,6 +901,34 @@ 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); + $item->unit($item->part->unit); + + my ($price_src, $discount_src) = get_best_price_and_discount_source($record, $item, 0); + + $self->js + ->val ('#add_item_unit', $item->unit) + ->val ('#add_item_description', $item->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) = @_; @@ -929,6 +996,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'); @@ -1082,11 +1151,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); @@ -1155,27 +1224,18 @@ sub action_update_row_from_master_data { $item->description($texts->{description}); $item->longdescription($texts->{longdescription}); - 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($::form->round_amount($price_src->price / $self->order->exchangerate, 5)) if $self->order->exchangerate; - $price_src->price(0) if !$price_source->best_price; - } - + my ($price_src, $discount_src) = get_best_price_and_discount_source($self->order, $item, 1); $item->sellprice($price_src->price); $item->active_price_source($price_src); + $item->discount($discount_src->discount); + $item->active_discount_source($discount_src); + + my $price_editable = $self->order->is_sales ? $::auth->assert('sales_edit_prices', 1) : $::auth->assert('purchase_edit_prices', 1); $self->js - ->run('kivi.Order.update_sellprice', $item_id, $item->sellprice_as_number) + ->run('kivi.Order.set_price_and_source_text', $item_id, $price_src ->source, $price_src ->source_description, $item->sellprice_as_number, $price_editable) + ->run('kivi.Order.set_discount_and_source_text', $item_id, $discount_src->source, $discount_src->source_description, $item->discount_as_percent, $price_editable) ->html('.row_entry:has(#item_' . $item_id . ') [name = "partnumber"] a', $item->part->partnumber) ->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); @@ -1193,6 +1253,58 @@ sub action_update_row_from_master_data { $self->js->render(); } +sub action_save_phone_note { + my ($self) = @_; + + if (!$::form->{phone_note}->{subject} || !$::form->{phone_note}->{body}) { + return $self->js->flash('error', t8('Phone note needs a subject and a body.'))->render; + } + + my $phone_note; + if ($::form->{phone_note}->{id}) { + $phone_note = first { $_->id == $::form->{phone_note}->{id} } @{$self->order->phone_notes}; + return $self->js->flash('error', t8('Phone note not found for this order.'))->render if !$phone_note; + } + + $phone_note = SL::DB::Note->new() if !$phone_note; + my $is_new = !$phone_note->id; + + $phone_note->assign_attributes(%{ $::form->{phone_note} }, + trans_id => $self->order->id, + trans_module => 'oe', + employee => SL::DB::Manager::Employee->current); + + $phone_note->save; + $self->order(SL::DB::Order->new(id => $self->order->id)->load); + + my $tab_as_html = $self->p->render('order/tabs/phone_notes', SELF => $self); + + return $self->js + ->replaceWith('#phone-notes', $tab_as_html) + ->html('#num_phone_notes', (scalar @{$self->order->phone_notes}) ? ' (' . scalar @{$self->order->phone_notes} . ')' : '') + ->flash('info', $is_new ? t8('Phone note has been created.') : t8('Phone note has been updated.')) + ->render; +} + +sub action_delete_phone_note { + my ($self) = @_; + + my $phone_note = first { $_->id == $::form->{phone_note}->{id} } @{$self->order->phone_notes}; + + return $self->js->flash('error', t8('Phone note not found for this order.'))->render if !$phone_note; + + $phone_note->delete; + $self->order(SL::DB::Order->new(id => $self->order->id)->load); + + my $tab_as_html = $self->p->render('order/tabs/phone_notes', SELF => $self); + + return $self->js + ->replaceWith('#phone-notes', $tab_as_html) + ->html('#num_phone_notes', (scalar @{$self->order->phone_notes}) ? ' (' . scalar @{$self->order->phone_notes} . ')' : '') + ->flash('info', t8('Phone note has been deleted.')) + ->render; +} + sub js_load_second_row { my ($self, $item, $item_id, $do_parse) = @_; @@ -1617,58 +1729,29 @@ sub new_item { } $item->assign_attributes(%$attr); + $item->qty(1.0) if !$item->qty; + $item->unit($item->part->unit) if !$item->unit; - my $part = SL::DB::Part->new(id => $attr->{parts_id})->load; - my $price_source = SL::PriceSource->new(record_item => $item, record => $record); - - $item->unit($part->unit) if !$item->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; - } + my ($price_src, $discount_src) = get_best_price_and_discount_source($record, $item, 0); my %new_attr; - $new_attr{part} = $part; - $new_attr{description} = $part->description if ! $item->description; - $new_attr{qty} = 1.0 if ! $item->qty; - $new_attr{price_factor_id} = $part->price_factor_id if ! $item->price_factor_id; + $new_attr{description} = $item->part->description if ! $item->description; + $new_attr{qty} = 1.0 if ! $item->qty; + $new_attr{price_factor_id} = $item->part->price_factor_id if ! $item->price_factor_id; $new_attr{sellprice} = $price_src->price; $new_attr{discount} = $discount_src->discount; $new_attr{active_price_source} = $price_src; $new_attr{active_discount_source} = $discount_src; - $new_attr{longdescription} = $part->notes if ! defined $attr->{longdescription}; + $new_attr{longdescription} = $item->part->notes if ! defined $attr->{longdescription}; $new_attr{project_id} = $record->globalproject_id; - $new_attr{lastcost} = $record->is_sales ? $part->lastcost : 0; + $new_attr{lastcost} = $record->is_sales ? $item->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 # saved. Adding empty custom_variables to new orderitem here solves this problem. $new_attr{custom_variables} = []; - my $texts = get_part_texts($part, $record->language_id, description => $new_attr{description}, longdescription => $new_attr{longdescription}); + my $texts = get_part_texts($item->part, $record->language_id, description => $new_attr{description}, longdescription => $new_attr{longdescription}); $item->assign_attributes(%new_attr, %{ $texts }); @@ -1678,7 +1761,7 @@ sub new_item { sub setup_order_from_cv { my ($order) = @_; - $order->$_($order->customervendor->$_) for (qw(taxzone_id payment_id delivery_term_id currency_id)); + $order->$_($order->customervendor->$_) for (qw(taxzone_id payment_id delivery_term_id currency_id language_id)); $order->intnotes($order->customervendor->notes); @@ -1785,6 +1868,29 @@ sub save { my $errors = []; my $db = $self->order->db; + # check for new or updated phone note + if ($::form->{phone_note}->{subject} || $::form->{phone_note}->{body}) { + if (!$::form->{phone_note}->{subject} || !$::form->{phone_note}->{body}) { + return [t8('Phone note needs a subject and a body.')]; + } + + my $phone_note; + if ($::form->{phone_note}->{id}) { + $phone_note = first { $_->id == $::form->{phone_note}->{id} } @{$self->order->phone_notes}; + return [t8('Phone note not found for this order.')] if !$phone_note; + } + + $phone_note = SL::DB::Note->new() if !$phone_note; + my $is_new = !$phone_note->id; + + $phone_note->assign_attributes(%{ $::form->{phone_note} }, + trans_id => $self->order->id, + trans_module => 'oe', + employee => SL::DB::Manager::Employee->current); + + $self->order->add_phone_notes($phone_note) if $is_new; + } + $db->with_transaction(sub { # delete custom shipto if it is to be deleted or if it is empty if ($self->order->custom_shipto && ($self->is_custom_shipto_to_delete || $self->order->custom_shipto->is_empty)) { @@ -1845,7 +1951,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}) { @@ -1945,7 +2054,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'); @@ -2002,9 +2111,12 @@ 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}; + $self->{template_args}->{num_phone_notes} = scalar @{ $self->order->phone_notes || [] }; + $::request->{layout}->use_javascript("${_}.js") for qw(kivi.Validator kivi.SalesPurchase kivi.Order kivi.File ckeditor/ckeditor ckeditor/adapters/jquery edit_periodic_invoices_config calculate_qty follow_up show_history); $self->setup_edit_action_bar; @@ -2032,11 +2144,11 @@ sub setup_edit_action_bar { $has_final_invoice = any {'SL::DB::Invoice' eq ref $_ && "final_invoice" eq $_->type} @$lr; } - my $right_for = { map { $_ => $_.'_edit' } @{$self->valid_types} }; - my $right = $right_for->{ $self->type }; - $right ||= 'DOES_NOT_EXIST'; + my $right_for = { map { $_ => $_.'_edit' } @{$self->valid_types} }; + my $right = $right_for->{ $self->type }; + $right ||= 'DOES_NOT_EXIST'; + my $may_edit_create = $::auth->assert($right, 'may fail'); - if ($::auth->assert($right, 1)) { for my $bar ($::request->layout->get('actionbar')) { $bar->add( combobox => [ @@ -2048,6 +2160,18 @@ sub setup_edit_action_bar { 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 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'), @@ -2055,7 +2179,9 @@ sub setup_edit_action_bar { checks => [ 'kivi.Order.check_save_active_periodic_invoices', @req_trans_cost_art, @req_cusordnumber, ], - disabled => !$self->order->id ? t8('This object has not been saved yet.') : undef, + disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') + : !$self->order->id ? t8('This object has not been saved yet.') + : undef, ], ], # end of combobox "Save" @@ -2068,23 +2194,27 @@ sub setup_edit_action_bar { submit => [ '#order_form', { action => "Order/sales_quotation" } ], 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'), submit => [ '#order_form', { action => "Order/request_for_quotation" } ], 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'), submit => [ '#order_form', { action => "Order/sales_order" } ], 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' ], 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, ], action => [ t8('Save and Delivery Order'), @@ -2094,7 +2224,8 @@ sub setup_edit_action_bar { checks => [ 'kivi.Order.check_save_active_periodic_invoices', @req_trans_cost_art, @req_cusordnumber, ], - only_if => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type())) + only_if => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type())), + disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, ], action => [ t8('Save and Supplier Delivery Order'), @@ -2104,7 +2235,8 @@ sub setup_edit_action_bar { checks => [ 'kivi.Order.check_save_active_periodic_invoices', @req_trans_cost_art, @req_cusordnumber, ], - only_if => (any { $self->type eq $_ } (purchase_order_type())) + 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 Invoice'), @@ -2112,6 +2244,7 @@ sub setup_edit_action_bar { checks => [ 'kivi.Order.check_save_active_periodic_invoices', @req_trans_cost_art, @req_cusordnumber, ], + disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef, ], action => [ ($has_invoice_for_advance_payment ? t8('Save and Further Invoice for Advance Payment') : t8('Save and Invoice for Advance Payment')), @@ -2119,8 +2252,9 @@ sub setup_edit_action_bar { checks => [ 'kivi.Order.check_save_active_periodic_invoices', @req_trans_cost_art, @req_cusordnumber, ], - disabled => $has_final_invoice ? t8('This order has already a final invoice.') - : undef, + disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') + : $has_final_invoice ? t8('This order has already a final invoice.') + : undef, only_if => (any { $self->type eq $_ } (sales_order_type())), ], action => [ @@ -2129,14 +2263,16 @@ sub setup_edit_action_bar { checks => [ 'kivi.Order.check_save_active_periodic_invoices', @req_trans_cost_art, @req_cusordnumber, ], - disabled => $has_final_invoice ? t8('This order has already a final invoice.') - : undef, + disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') + : $has_final_invoice ? t8('This order has already a final invoice.') + : undef, only_if => (any { $self->type eq $_ } (sales_order_type())) && $has_invoice_for_advance_payment, ], 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())) + 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, ], ], # end of combobox "Workflow" @@ -2147,25 +2283,29 @@ sub setup_edit_action_bar { ], action => [ t8('Save and preview PDF'), - call => [ 'kivi.Order.save', 'preview_pdf', $::instance_conf->get_order_warn_duplicate_parts, - $::instance_conf->get_order_warn_no_deliverydate, - ], - checks => [ @req_trans_cost_art, @req_cusordnumber ], + call => [ 'kivi.Order.save', 'preview_pdf', $::instance_conf->get_order_warn_duplicate_parts, + $::instance_conf->get_order_warn_no_deliverydate, + ], + checks => [ @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 and print'), - call => [ 'kivi.Order.show_print_options', $::instance_conf->get_order_warn_duplicate_parts, - $::instance_conf->get_order_warn_no_deliverydate, - ], - checks => [ @req_trans_cost_art, @req_cusordnumber ], + call => [ 'kivi.Order.show_print_options', $::instance_conf->get_order_warn_duplicate_parts, + $::instance_conf->get_order_warn_no_deliverydate, + ], + checks => [ @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 and E-mail'), - id => 'save_and_email_action', - call => [ 'kivi.Order.save', 'save_and_show_email_dialog', $::instance_conf->get_order_warn_duplicate_parts, - $::instance_conf->get_order_warn_no_deliverydate, - ], - disabled => !$self->order->id ? t8('This object has not been saved yet.') : undef, + id => 'save_and_email_action', + call => [ 'kivi.Order.save', 'save_and_show_email_dialog', $::instance_conf->get_order_warn_duplicate_parts, + $::instance_conf->get_order_warn_no_deliverydate, + ], + disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') + : !$self->order->id ? t8('This object has not been saved yet.') + : undef, ], action => [ t8('Download attachments of all parts'), @@ -2179,16 +2319,12 @@ sub setup_edit_action_bar { t8('Delete'), call => [ 'kivi.Order.delete_order' ], confirm => $::locale->text('Do you really want to delete this object?'), - disabled => !$self->order->id ? t8('This object has not been saved yet.') : undef, + disabled => !$may_edit_create ? t8('You do not have the permissions to access this function.') + : !$self->order->id ? t8('This object has not been saved yet.') + : undef, only_if => $deletion_allowed, ], - ); - } - } - - for my $bar ($::request->layout->get('actionbar')) { - $bar->add( combobox => [ action => [ t8('more') @@ -2207,7 +2343,6 @@ sub setup_edit_action_bar { ], # end of combobox "more" ); } - } sub generate_doc { @@ -2394,6 +2529,41 @@ sub get_part_texts { return $texts; } +sub get_best_price_and_discount_source { + my ($record, $item, $ignore_given) = @_; + + my $price_source = SL::PriceSource->new(record_item => $item, record => $record); + + 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); + } elsif (!$ignore_given && 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 (!$ignore_given && 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; + } + + return ($price_src, $discount_src); +} + sub sales_order_type { 'sales_order'; } @@ -2659,21 +2829,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 * @@ -2696,10 +2855,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.