E-Mail-Protokollierung in interne Bemerkung abschalten, falls Journal an
[kivitendo-erp.git] / SL / Controller / DeliveryOrder.pm
index ab43497..a4b3462 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use parent qw(SL::Controller::Base);
 
 use SL::Helper::Flash qw(flash_later);
-use SL::Helper::Number qw(_format_number_units _parse_number);
+use SL::Helper::Number qw(_format_number _parse_number);
 use SL::Presenter::Tag qw(select_tag hidden_tag div_tag);
 use SL::Presenter::DeliveryOrder qw(delivery_order_status_line);
 use SL::Locale::String qw(t8);
@@ -480,18 +480,21 @@ 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, 'pdf');
 
-  # 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')    . ": " . $::form->{message};
+  # internal notes unless no email journal
+  unless ($::instance_conf->get_email_journal) {
 
-  $self->order->update_attributes(intnotes => $intnotes);
+    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')    . ": " . $::form->{message};
+
+    $self->order->update_attributes(intnotes => $intnotes);
+  }
 
   $self->save_history('MAILED');
 
@@ -897,8 +900,8 @@ sub action_stock_in_out_dialog {
   my ($self) = @_;
 
   my $part    = SL::DB::Part->load_cached($::form->{parts_id}) or die "need parts_id";
+  my $unit    = SL::DB::Unit->load_cached($::form->{unit}) or die "need unit";
   my $stock   = $::form->{stock};
-  my $unit    = $::form->{unit};
   my $row     = $::form->{row};
   my $item_id = $::form->{item_id};
   my $qty     = _parse_number($::form->{qty_as_number});
@@ -908,13 +911,13 @@ sub action_stock_in_out_dialog {
   my @contents   = DO->get_item_availability(parts_id => $part->id);
   my $stock_info = DO->unpack_stock_information(packed => $stock);
 
-  $self->merge_stock_data($stock_info, \@contents, $part);
+  $self->merge_stock_data($stock_info, \@contents, $part, $unit);
 
   $self->render("delivery_order/stock_dialog", { layout => 0 },
     WHCONTENTS => $self->order->delivered ? $stock_info : \@contents,
     part       => $part,
     do_qty     => $qty,
-    do_unit    => $unit,
+    do_unit    => $unit->unit,
     delivered  => $self->order->delivered,
     row        => $row,
     item_id    => $item_id,
@@ -933,17 +936,17 @@ sub action_update_stock_information {
     stock_info => $yaml,
     stock_qty => $stock_qty,
   };
-
   $self->render(\ SL::JSON::to_json($response), { layout => 0, type => 'json', process => 0 });
 }
 
 sub merge_stock_data {
-  my ($self, $stock_info, $contents, $part) = @_;
+  my ($self, $stock_info, $contents, $part, $unit) = @_;
   # TODO rewrite to mapping
 
   if (!$self->order->delivered) {
     for my $row (@$contents) {
-      $row->{available_qty} = _format_number_units($row->{qty}, $row->{unit}, $part->unit);
+      # row here is in parts units. stock is in item units
+      $row->{available_qty} = _format_number($part->unit_obj->convert_to($row->{qty}, $unit));
 
       for my $sinfo (@{ $stock_info }) {
         next if $row->{bin_id}       != $sinfo->{bin_id} ||
@@ -1795,7 +1798,9 @@ sub setup_edit_action_bar {
         action => [
           t8('Save as new'),
           call      => [ 'kivi.DeliveryOrder.save', 'save_as_new', $::instance_conf->get_order_warn_duplicate_parts ],
-          disabled  => !$self->order->id ? t8('This object has not been saved yet.') : undef,
+          disabled  =>   $self->type eq 'supplier_delivery_order' ? t8('Need a workflow for Supplier Delivery Order')
+                       : !$self->order->id                        ? t8('This object has not been saved yet.')
+                       : undef,
         ],
       ], # end of combobox "Save"
 
@@ -2151,7 +2156,7 @@ sub calculate_stock_in_out_from_stock_info {
     $units_by_name{$_->{unit}}->convert_to($_->{qty}, $units_by_name{$unit})
   } @$stock_info;
 
-  my $content  = _format_number_units($sum, 2, $units_by_name{$unit}, $units_by_name{$unit});
+  my $content  = _format_number($sum, 2) . ' ' . $unit;
 
   return $content;
 }
@@ -2165,7 +2170,7 @@ sub calculate_stock_in_out {
     $_->unit_obj->convert_to($_->qty, $item->unit_obj)
   } $item->delivery_order_stock_entries;
 
-  my $content  = _format_number_units($sum, 2, $item->unit_obj, $item->part->unit_obj);
+  my $content  = _format_number($sum, 2);
 
   return $content;
 }