Changelog-Eintrag zu Gewicht in Verkaufsbericht
[kivitendo-erp.git] / bin / mozilla / io.pl
index b42ddde..e25f963 100644 (file)
@@ -38,6 +38,7 @@
 
 use Carp;
 use CGI;
+use List::MoreUtils qw(uniq);
 use List::Util qw(min max first);
 
 use SL::CVar;
@@ -341,7 +342,19 @@ sub display_row {
     $form->{"marge_percent_$i"} = 0;
 
     my $marge_color;
-    my $real_sellprice           = $linetotal;
+    my $real_sellprice;
+    if ( $form->{taxincluded} and $form->{"qty_$i"} * 1  and $form->{$form->{"taxaccounts_$i"} . "_rate"} * 1) {
+      # if we use taxincluded we need to calculate the marge from the net_value
+      # all the marge calculations are based on linetotal which we need to
+      # convert to net first
+
+      # there is no direct form value for the tax_rate of the item, but
+      # form->{taxaccounts_$i} gives the tax account (e.g. 3806) and 3806_rate
+      # gives the tax percentage (e.g. 0.19)
+      $real_sellprice = $linetotal / (1 + $form->{$form->{"taxaccounts_$i"} . "_rate"});
+    } else {
+      $real_sellprice            = $linetotal;
+    };
     my $real_lastcost            = $form->{"lastcost_$i"} * $form->{"qty_$i"} / ( $form->{"marge_price_factor_$i"} || 1 );
     my $marge_percent_warn       = $myconfig{marge_percent_warn} * 1 || 15;
     my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
@@ -388,7 +401,7 @@ sub display_row {
 
     if ($is_delivery_order) {
       map { $form->{"${_}_${i}"} = $form->format_amount(\%myconfig, $form->{"${_}_${i}"}) } qw(sellprice discount lastcost);
-      push @hidden_vars, qw(sellprice discount not_discountable price_factor_id lastcost);
+      push @hidden_vars, qw(sellprice discount not_discountable price_factor_id lastcost pricegroup_id);
       push @hidden_vars, "stock_${stock_in_out}_sum_qty", "stock_${stock_in_out}";
     }
 
@@ -543,6 +556,11 @@ sub item_selected {
       $form->{"sellprice_$i"} =
         $form->round_amount($form->{"sellprice_$i"}, $decimalplaces);
     }
+
+    # tradediscount
+    if ($::form->{tradediscount}) {
+      $::form->{"sellprice_$i"} *= 1 - $::form->{tradediscount};
+    }
   }
 
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
@@ -945,6 +963,9 @@ sub edit_e_mail {
     $form->{"email"} = $form->{"cp_email"} if $form->{"cp_email"};
   }
 
+  $form->{language} = $form->get_template_language(\%myconfig);
+  $form->{language} = "_" . $form->{language} if $form->{language};
+
   my $title = $locale->text('E-mail') . " " . $form->get_formname_translation();
 
   $form->{oldmedia} = $form->{media};
@@ -1380,7 +1401,7 @@ sub print_form {
     $form->get_shipto(\%myconfig);
   }
 
-  my @a = qw(name street zipcode city country contact);
+  my @a = qw(name department_1 department_2 street zipcode city country contact phone fax email);
 
   my $shipto = 1;
 
@@ -1429,7 +1450,7 @@ sub print_form {
   format_dates($output_dateformat, $output_longdates,
                qw(invdate orddate quodate pldate duedate reqdate transdate
                   shippingdate deliverydate validitydate paymentdate
-                  datepaid transdate_oe deliverydate_oe
+                  datepaid transdate_oe deliverydate_oe dodate
                   employee_startdate employee_enddate
                   ),
                grep({ /^datepaid_\d+$/ ||
@@ -1484,14 +1505,8 @@ sub print_form {
   push @template_files, "$form->{formname}$form->{language}$printer_code.$extension";
   push @template_files, "$form->{formname}.$extension";
   push @template_files, "default.$extension";
-
-  $form->{IN} = undef;
-  for my $filename (@template_files) {
-    if (-f "$myconfig{templates}/$filename") {
-      $form->{IN} = $filename;
-      last;
-    }
-  }
+  @template_files = uniq @template_files;
+  $form->{IN}     = first { -f "$myconfig{templates}/$_" } @template_files;
 
   if (!defined $form->{IN}) {
     $::form->error($::locale->text('Cannot find matching template for this print request. Please contact your template maintainer. I tried these: #1.', join ', ', map { "'$_'"} @template_files));
@@ -1500,7 +1515,6 @@ sub print_form {
   delete $form->{OUT};
 
   if ($form->{media} eq 'printer') {
-    #$form->{OUT} = "| $form->{printer_command} &>/dev/null";
     $form->{OUT}      = $form->{printer_command};
     $form->{OUT_MODE} = '|-';
     $form->{printed} .= " $form->{formname}";
@@ -1521,22 +1535,31 @@ sub print_form {
     my %queued = map { s|.*/|| } split / /, $form->{queued};
 
     my $filename;
+    my $suffix = ($form->{postscript}) ? '.ps' : '.pdf';
     if ($filename = $queued{ $form->{formname} }) {
       $form->{queued} =~ s/\Q$form->{formname} $filename\E//;
       unlink $::lx_office_conf{paths}->{spool} . "/$filename";
       $filename =~ s/\..*$//g;
+      $filename .= $suffix;
+      $form->{OUT} = $::lx_office_conf{paths}->{spool} . "/$filename";
+      $form->{OUT_MODE} = '>';
     } else {
-      $filename = time;
-      $filename .= $$;
+      my $temp_fh;
+      ($temp_fh, $filename) = File::Temp::tempfile(
+        'kivitendo-spoolXXXXXX',
+        SUFFIX => "$suffix",
+        DIR => $::lx_office_conf{paths}->{spool},
+      );
+      close $temp_fh;
+      $form->{OUT} = "$filename";
+      # use >> for OUT_MODE because file is already created by File::Temp
+      $form->{OUT_MODE} = '>>';
+      # strip directory so that only filename is stored in table status
+      ($filename) = $filename =~ /^$::lx_office_conf{paths}->{spool}\/(.*)/;
     }
 
-    $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
-    $form->{OUT} = $::lx_office_conf{paths}->{spool} . "/$filename";
-    $form->{OUT_MODE} = '>';
-
     # add type
     $form->{queued} .= " $form->{formname} $filename";
-
     $form->{queued} =~ s/^ //;
   }
   my $queued = $form->{queued};
@@ -1568,6 +1591,7 @@ sub print_form {
     media     => $form->{media},
     extension => $extension,
     printer   => SL::DB::Manager::Printer->find_by_or_create(id => $form->{printer_id}),
+    today     => DateTime->today,
   };
 
   $form->parse_template(\%myconfig);