X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FOrder.pm;h=70f75aa8dc738fe67be89b71cfdf55cc399928e7;hb=fc58ee00364ec05d5a5277d8e64fe07374c9db08;hp=fa5c4c364bce79f110ddd06b3101953b553028a0;hpb=eeaebcf9bc5b9bb25e8ddacd1a8b1c0acc421f4c;p=kivitendo-erp.git diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index fa5c4c364..70f75aa8d 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -423,11 +423,13 @@ sub action_save_and_show_email_dialog { $email_form->{js_send_function} = 'kivi.Order.send_email()'; my %files = $self->get_files_for_email_dialog(); + $self->{all_employees} = SL::DB::Manager::Employee->get_all(query => [ deleted => 0 ]); 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 => $self->{all_employees}, ); $self->js @@ -550,7 +552,10 @@ sub action_show_periodic_invoices_config_dialog { if ($::form->{customer_id}) { $::form->{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all_sorted(where => [ cp_cv_id => $::form->{customer_id} ]); - $::form->{email_recipient_invoice_address} = SL::DB::Manager::Customer->find_by(id => $::form->{customer_id})->invoice_mail; + my $customer_object = SL::DB::Manager::Customer->find_by(id => $::form->{customer_id}); + $::form->{postal_invoice} = $customer_object->postal_invoice; + $::form->{email_recipient_invoice_address} = $::form->{postal_invoice} ? '' : $customer_object->invoice_mail; + $config->send_email(0) if $::form->{postal_invoice}; } $self->render('oe/edit_periodic_invoices_config', { layout => 0 }, @@ -772,6 +777,8 @@ sub action_unit_changed { sub action_add_item { my ($self) = @_; + delete $::form->{add_item}->{create_part_type}; + my $form_attr = $::form->{add_item}; return unless $form_attr->{parts_id}; @@ -971,6 +978,62 @@ sub action_price_popup { $self->render_price_dialog($item); } +# save the order in a session variable and redirect to the part controller +sub action_create_part { + my ($self) = @_; + + $::lxdebug->dump(0, "bb: form", $::form); + my $previousform = $::auth->save_form_in_session(non_scalars => 1); + + my $callback = $self->url_for( + action => 'return_from_create_part', + type => $self->type, # type is needed for check_auth on return + previousform => $previousform, + ); + + 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, + ); + + $self->redirect_to(@redirect_params); +} + +sub action_return_from_create_part { + my ($self) = @_; + + $self->{created_part} = SL::DB::Part->new(id => delete $::form->{new_parts_id})->load if $::form->{new_parts_id}; + + $::auth->restore_form_from_session(delete $::form->{previousform}); + + # set item ids to new fake id, to identify them as new items + foreach my $item (@{$self->order->items_sorted}) { + $item->{new_fake_id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000); + } + + $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}} + ); + +} + # load the second row for one or more items # # This action gets the html code for all items second rows by rendering a template for @@ -1793,8 +1856,10 @@ sub pre_render { } if (any { $self->type eq $_ } (sales_order_type(), purchase_order_type())) { - # calculate shipped qtys here to prevent calling calculate for every item via the items method - SL::Helper::ShippedQty->new->calculate($self->order)->write_to_objects; + # Calculate shipped qtys here to prevent calling calculate for every item via the items method. + # Do not use write_to_objects to prevent order->delivered to be set, because this should be + # the value from db, which can be set manually or is set when linked delivery orders are saved. + SL::Helper::ShippedQty->new->calculate($self->order)->write_to(\@{$self->order->items}); } if ($self->order->number && $::instance_conf->get_webdav) { @@ -1898,12 +1963,16 @@ sub setup_edit_action_bar { ], action => [ t8('Save and print'), - call => [ 'kivi.Order.show_print_options', $::instance_conf->get_order_warn_duplicate_parts ], + call => [ 'kivi.Order.show_print_options', $::instance_conf->get_order_warn_duplicate_parts, + $::instance_conf->get_order_warn_no_deliverydate, + ], ], 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 ], + 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, ], action => [