X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/34540341e99827781065740f9dad625d17d42f07..828c7d4e23cdaf973f83d5dc545e9be8ef73bedc:/SL/Controller/Order.pm diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 8857a85f6..0144529d5 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -210,6 +210,16 @@ sub action_save_as_new { sub action_print { my ($self) = @_; + my $errors = $self->save(); + + if (scalar @{ $errors }) { + $self->js->flash('error', $_) foreach @{ $errors }; + return $self->js->render(); + } + + $self->js->val('#id', $self->order->id) + ->val('#order_' . $self->nr_key(), $self->order->number); + my $format = $::form->{print_options}->{format}; my $media = $::form->{print_options}->{media}; my $formname = $::form->{print_options}->{formname}; @@ -370,6 +380,17 @@ sub action_show_email_dialog { sub action_send_email { my ($self) = @_; + my $errors = $self->save(); + + if (scalar @{ $errors }) { + $self->js->run('kivi.Order.close_email_dialog'); + $self->js->flash('error', $_) foreach @{ $errors }; + return $self->js->render(); + } + + $self->js->val('#id', $self->order->id) + ->val('#order_' . $self->nr_key(), $self->order->number); + my $email_form = delete $::form->{email_form}; my %field_names = (to => 'email'); @@ -387,11 +408,11 @@ sub action_send_email { $language = SL::DB::Language->new(id => $::form->{print_options}->{language_id})->load if $::form->{print_options}->{language_id}; my $pdf; - my @errors = genereate_pdf($self->order, \$pdf, {media => $::form->{media}, - format => $::form->{print_options}->{format}, - formname => $::form->{print_options}->{formname}, - language => $language, - groupitems => $::form->{print_options}->{groupitems}}); + my @errors = generate_pdf($self->order, \$pdf, {media => $::form->{media}, + format => $::form->{print_options}->{format}, + formname => $::form->{print_options}->{formname}, + language => $language, + groupitems => $::form->{print_options}->{groupitems}}); if (scalar @errors) { return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render($self); } @@ -417,6 +438,8 @@ sub action_send_email { $intnotes .= t8('Subject') . ": " . $::form->{subject} . "\n\n"; $intnotes .= t8('Message') . ": " . $::form->{message}; + $self->order->update_attributes(intnotes => $intnotes); + $self->js ->val('#order_intnotes', $intnotes) ->run('kivi.Order.close_email_dialog') @@ -623,6 +646,7 @@ sub action_customer_vendor_changed { ->val( '#order_payment_id', $self->order->payment_id) ->val( '#order_delivery_term_id', $self->order->delivery_term_id) ->val( '#order_intnotes', $self->order->intnotes) + ->val( '#language_id', $self->order->$cv_method->language_id) ->focus( '#order_' . $self->cv . '_id'); $self->js_redisplay_amounts_and_taxes; @@ -967,6 +991,19 @@ sub js_redisplay_amounts_and_taxes { $self->js->show('#subtotal_row_id'); } + if ($self->order->is_sales) { + my $is_neg = $self->order->marge_total < 0; + $self->js + ->html('#marge_total_id', $::form->format_amount(\%::myconfig, $self->order->marge_total, 2)) + ->html('#marge_percent_id', $::form->format_amount(\%::myconfig, $self->order->marge_percent, 2)) + ->action_if( $is_neg, 'addClass', '#marge_total_id', 'plus0') + ->action_if( $is_neg, 'addClass', '#marge_percent_id', 'plus0') + ->action_if( $is_neg, 'addClass', '#marge_percent_sign_id', 'plus0') + ->action_if(!$is_neg, 'removeClass', '#marge_total_id', 'plus0') + ->action_if(!$is_neg, 'removeClass', '#marge_percent_id', 'plus0') + ->action_if(!$is_neg, 'removeClass', '#marge_percent_sign_id', 'plus0'); + } + $self->js ->html('#netamount_id', $::form->format_amount(\%::myconfig, $self->order->netamount, -2)) ->html('#amount_id', $::form->format_amount(\%::myconfig, $self->order->amount, -2)) @@ -1152,8 +1189,10 @@ sub make_order { $order->assign_attributes(%{$::form->{order}}); - my $periodic_invoices_config = make_periodic_invoices_config_from_yaml($form_periodic_invoices_config); - $order->periodic_invoices_config($periodic_invoices_config) if $periodic_invoices_config; + if (my $periodic_invoices_config_attrs = $form_periodic_invoices_config ? YAML::Load($form_periodic_invoices_config) : undef) { + my $periodic_invoices_config = $order->periodic_invoices_config || $order->periodic_invoices_config(SL::DB::PeriodicInvoicesConfig->new); + $periodic_invoices_config->assign_attributes(%$periodic_invoices_config_attrs); + } # remove deleted items $self->item_ids_to_delete([]); @@ -1282,7 +1321,7 @@ sub setup_order_from_cv { $order->intnotes($order->customervendor->notes); if ($order->is_sales) { - $order->salesman_id($order->customer->salesman_id); + $order->salesman_id($order->customer->salesman_id || SL::DB::Manager::Employee->current->id); $order->taxincluded(defined($order->customer->taxincluded_checked) ? $order->customer->taxincluded_checked : $::myconfig{taxincluded_checked}); @@ -1366,7 +1405,11 @@ sub save { # link records if ($::form->{converted_from_oe_id}) { - SL::DB::Order->new(id => $::form->{converted_from_oe_id})->load->link_to_record($self->order); + my $src = SL::DB::Order->new(id => $::form->{converted_from_oe_id})->load; + # implement OE::_close_quotations_rfqs - this a 1 : 1 connection + # close only if workflow: quotation -> order. TODO test case + $src->update_attributes(closed => 1) if $src->type =~ /_quotation$/; + $src->link_to_record($self->order); if (scalar @{ $::form->{converted_from_orderitems_ids} || [] }) { my $idx = 0; @@ -1511,19 +1554,6 @@ sub setup_edit_action_bar { checks => [ 'kivi.Order.check_save_active_periodic_invoices' ], disabled => !$self->order->id ? t8('This object has not been saved yet.') : undef, ], - action => [ - t8('Save and Delivery Order'), - call => [ 'kivi.Order.save', 'save_and_delivery_order', $::instance_conf->get_order_warn_duplicate_parts, - $::instance_conf->get_order_warn_no_deliverydate, - ], - checks => [ 'kivi.Order.check_save_active_periodic_invoices' ], - only_if => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type())) - ], - action => [ - t8('Save and Invoice'), - call => [ 'kivi.Order.save', 'save_and_invoice', $::instance_conf->get_order_warn_duplicate_parts ], - checks => [ 'kivi.Order.check_save_active_periodic_invoices' ], - ], ], # end of combobox "Save" combobox => [ @@ -1542,6 +1572,19 @@ sub setup_edit_action_bar { only_if => (any { $self->type eq $_ } (sales_order_type(), request_quotation_type())), disabled => !$self->order->id ? t8('This object has not been saved yet.') : undef, ], + action => [ + t8('Save and Delivery Order'), + call => [ 'kivi.Order.save', 'save_and_delivery_order', $::instance_conf->get_order_warn_duplicate_parts, + $::instance_conf->get_order_warn_no_deliverydate, + ], + checks => [ 'kivi.Order.check_save_active_periodic_invoices' ], + only_if => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type())) + ], + action => [ + t8('Save and Invoice'), + call => [ 'kivi.Order.save', 'save_and_invoice', $::instance_conf->get_order_warn_duplicate_parts ], + checks => [ 'kivi.Order.check_save_active_periodic_invoices' ], + ], ], # end of combobox "Workflow" combobox => [ @@ -1549,12 +1592,12 @@ sub setup_edit_action_bar { t8('Export'), ], action => [ - t8('Print'), - call => [ 'kivi.Order.show_print_options' ], + t8('Save and print'), + call => [ 'kivi.Order.show_print_options', $::instance_conf->get_order_warn_duplicate_parts ], ], action => [ - t8('E-mail'), - call => [ 'kivi.Order.email' ], + t8('Save and E-mail'), + call => [ 'kivi.Order.email', $::instance_conf->get_order_warn_duplicate_parts ], ], action => [ t8('Download attachments of all parts'), @@ -1774,11 +1817,6 @@ Possibility to enter more than one item at once. =item * -Save order only on "save" (and "save and delivery order"-workflow). No -hidden save on "print" or "email". - -=item * - Item list in a scrollable area, so that the workflow buttons stay at the bottom. @@ -1868,7 +1906,7 @@ java script functions =item * credit limit -=item * more workflows (save as new, quotation, purchase order) +=item * more workflows (quotation, rfq) =item * price sources: little symbols showing better price / better discount @@ -1973,12 +2011,6 @@ editor or on text processing application). A warning when leaving the page without saveing unchanged inputs. -=item * - -Workflows for delivery order and invoice are in the menu "Save", because the -order is saved before opening the new document form. Nevertheless perhaps these -workflow buttons should be put under "Workflows". - =back