Merge branch 'master' of github.com:kivitendo/kivitendo-erp
[kivitendo-erp.git] / bin / mozilla / io.pl
index 54e4803..6ae6cd0 100644 (file)
@@ -65,8 +65,8 @@ use strict;
 if (-f "bin/mozilla/custom_io.pl") {
   eval { require "bin/mozilla/custom_io.pl"; };
 }
-if (-f "bin/mozilla/$::form->{login}_io.pl") {
-  eval { require "bin/mozilla/$::form->{login}_io.pl"; };
+if (-f "bin/mozilla/$::myconfig{login}_io.pl") {
+  eval { require "bin/mozilla/$::myconfig{login}_io.pl"; };
 }
 
 1;
@@ -139,6 +139,7 @@ sub display_row {
   my $is_quotation       = $form->{type} =~ /_quotation$/;
   my $is_invoice         = $form->{type} =~ /invoice/;
   my $is_s_p_order       = (first { $_ eq $form->{type} } qw(sales_order purchase_order));
+  my $show_ship_missing  = $is_s_p_order && $::instance_conf->get_sales_purchase_order_ship_missing_column;
 
   if ($is_delivery_order) {
     if ($form->{type} eq 'sales_delivery_order') {
@@ -159,6 +160,7 @@ sub display_row {
     {  id => 'partnumber',    width => 8,     value => $locale->text('Number'),               display => 1, },
     {  id => 'description',   width => 30,    value => $locale->text('Part Description'),     display => 1, },
     {  id => 'ship',          width => 5,     value => $locale->text('Delivered'),            display => $is_s_p_order, },
+    {  id => 'ship_missing',  width => 5,     value => $locale->text('Not delivered'),        display => $show_ship_missing, },
     {  id => 'qty',           width => 5,     value => $locale->text('Qty'),                  display => 1, },
     {  id => 'price_factor',  width => 5,     value => $locale->text('Price Factor'),         display => !$is_delivery_order, },
     {  id => 'unit',          width => 5,     value => $locale->text('Unit'),                 display => 1, },
@@ -200,7 +202,7 @@ sub display_row {
   my $deliverydate  = $locale->text('Required by');
 
   # special alignings
-  my %align  = map { $_ => 'right' } qw(qty ship right discount linetotal stock_in_out weight);
+  my %align  = map { $_ => 'right' } qw(qty ship right discount linetotal stock_in_out weight ship_missing);
   my %nowrap = map { $_ => 1 }       qw(description unit);
 
   $form->{marge_total}           = 0;
@@ -309,6 +311,11 @@ sub display_row {
       $ship_qty          /= ( $all_units->{$form->{"unit_$i"}}->{factor} || 1 );
 
       $column_data{ship}  = $form->format_amount(\%myconfig, $form->round_amount($ship_qty, 2) * 1) . ' ' . $form->{"unit_$i"};
+
+      my $ship_missing_qty    = $form->{"qty_$i"} - $ship_qty;
+      my $ship_missing_amount = $form->round_amount($ship_missing_qty * $form->{"sellprice_$i"} * (100 - $form->{"discount_$i"}) / 100 / $price_factor, 2);
+
+      $column_data{ship_missing} = $form->format_amount(\%myconfig, $ship_missing_qty) . ' ' . $form->{"unit_$i"} . '; ' . $form->format_amount(\%myconfig, $ship_missing_amount, $decimalplaces);
     }
 
     my $sellprice_value = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
@@ -442,7 +449,7 @@ sub display_row {
       push @hidden_vars, qw(orderitems_id converted_from_orderitems_id converted_from_invoice_id);
     }
     if ($is_invoice) {
-      push @hidden_vars, qw(invoice_id converted_from_orderitems_id converted_from_delivery_order_items_id);
+      push @hidden_vars, qw(invoice_id converted_from_orderitems_id converted_from_delivery_order_items_id converted_from_invoice_id);
     }
     if ($::form->{type} =~ /credit_note/) {
       push @hidden_vars, qw(invoice_id converted_from_invoice_id);
@@ -451,7 +458,7 @@ sub display_row {
       map { $form->{"${_}_${i}"} = $form->format_amount(\%myconfig, $form->{"${_}_${i}"}) } qw(sellprice discount lastcost);
       push @hidden_vars, grep { defined $form->{"${_}_${i}"} } qw(sellprice discount not_discountable price_factor_id lastcost);
       push @hidden_vars, "stock_${stock_in_out}_sum_qty", "stock_${stock_in_out}";
-      push @hidden_vars, qw(delivery_order_items_id converted_from_orderitems_id);
+      push @hidden_vars, qw(delivery_order_items_id converted_from_orderitems_id converted_from_delivery_order_items_id);
     }
 
     my @HIDDENS = map { value => $_}, (
@@ -509,12 +516,17 @@ sub select_item {
   print $::form->parse_html_template('io/select_item', { PREVIOUS_FORM => $previous_form,
                                                          MODE          => $mode,
                                                          ITEM_LIST     => \@item_list,
+                                                         IS_ASSEMBLY   => $mode eq 'IC', 
                                                          IS_PURCHASE   => $mode eq 'IS' });
 
   $main::lxdebug->leave_sub();
 }
 
 sub item_selected {
+
+  # this function is used for adding parts to records (mode = IR/IS)
+  # and to assemblies (mode = IC)
+
   $main::lxdebug->enter_sub();
 
   my $form     = $main::form;
@@ -528,6 +540,13 @@ sub item_selected {
   my $id   = delete($form->{select_item_id})   || croak 'Missing item selection ID';
   my $i    = $form->{ $mode eq 'IC' ? 'assembly_rows' : 'rowcount' };
 
+  if ( $mode eq 'IC' ) {
+    # assembly mode:
+    # the qty variables of the existing assembly items are all still formatted, so we parse them here (1 .. $i-1)
+    # including the qty of the just added part ($i)
+    $form->{"qty_$_"} = $form->parse_amount(\%myconfig, $form->{"qty_$_"}) for (1 .. $i);
+  };
+
   $form->{"id_${i}"} = $id;
 
   if ($mode eq 'IS') {
@@ -543,7 +562,10 @@ sub item_selected {
   my $new_item = $form->{item_list}->[0] || croak "No item found for mode '${mode}' and ID '${id}'";
 
   # if there was a price entered, override it
-  my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
+  my $sellprice;
+  unless ( $mode eq 'IC' ) {
+    $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
+  };
 
   my @new_fields =
     qw(id partnumber description sellprice listprice inventory_accno
@@ -598,6 +620,7 @@ sub item_selected {
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
     qw(sellprice listprice weight);
 
+  # at this stage qty of newly added part needs to be have been parsed
   $form->{weight}    += ($form->{"weight_$i"} * $form->{"qty_$i"});
 
   if ($form->{"not_discountable_$i"}) {
@@ -1335,6 +1358,7 @@ sub print_form {
     $form->{TEMPLATE_DRIVER_OPTIONS}->{variable_content_types} = {
       longdescription => 'html',
       partnotes       => 'html',
+      notes           => 'html',
     };
   }
 
@@ -2048,4 +2072,3 @@ sub _make_record {
 
   return $obj;
 }
-