Doc-Build-Script fixen
[kivitendo-erp.git] / SL / DO.pm
index d91f473..8d61b0f 100644 (file)
--- a/SL/DO.pm
+++ b/SL/DO.pm
@@ -76,10 +76,9 @@ sub transactions {
 
   push @where, ($form->{type} eq 'sales_delivery_order' ? '' : 'NOT ') . qq|COALESCE(dord.is_sales, FALSE)|;
 
-  my $department_id = (split /--/, $form->{department})[1];
-  if ($department_id) {
+  if ($form->{department_id}) {
     push @where,  qq|dord.department_id = ?|;
-    push @values, conv_i($department_id);
+    push @values, conv_i($form->{department_id});
   }
 
   if ($form->{project_id}) {
@@ -252,9 +251,9 @@ sub save {
          id, delivery_order_id, parts_id, description, longdescription, qty, base_qty,
          sellprice, discount, unit, reqdate, project_id, serialnumber,
          ordnumber, transdate, cusordnumber,
-         lastcost, price_factor_id, price_factor, marge_price_factor)
+         lastcost, price_factor_id, price_factor, marge_price_factor, pricegroup_id)
        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
-         (SELECT factor FROM price_factors WHERE id = ?), ?)|;
+         (SELECT factor FROM price_factors WHERE id = ?), ?, ?)|;
   my $h_item = prepare_query($form, $dbh, $q_item);
 
   my $q_item_stock =
@@ -301,7 +300,8 @@ sub save {
                $form->{"cusordnumber_$i"},
                $form->{"lastcost_$i"},
                conv_i($form->{"price_factor_id_$i"}), conv_i($form->{"price_factor_id_$i"}),
-               conv_i($form->{"marge_price_factor_$i"}));
+               conv_i($form->{"marge_price_factor_$i"}),
+               conv_i($form->{"pricegroup_id_$i"}));
     do_statement($form, $h_item, $q_item, @values);
 
     my $stock_info = DO->unpack_stock_information('packed' => $form->{"stock_${in_out}_$i"});
@@ -326,7 +326,6 @@ sub save {
   $h_item->finish();
   $h_item_stock->finish();
 
-  ($null, $form->{department_id}) = split(/--/, $form->{department});
 
   # save DO record
   $query =
@@ -350,7 +349,7 @@ sub save {
              conv_i($form->{salesman_id}), conv_i($form->{cp_id}),
              $form->{transaction_description},
              $form->{type} =~ /^sales/ ? 't' : 'f',
-             conv_i($form->{taxzone_id}), $form->{taxincluded} ? 't' : 'f', conv_i($form->{terms}), $form->{curr},
+             conv_i($form->{taxzone_id}), $form->{taxincluded} ? 't' : 'f', conv_i($form->{terms}), substr($form->{currency}, 0, 3),
              conv_i($form->{id}));
   do_query($form, $dbh, $query, @values);
 
@@ -383,7 +382,7 @@ sub save {
 
   $form->{saved_donumber} = $form->{donumber};
 
-  Common::webdav_folder($form) if ($main::webdav);
+  Common::webdav_folder($form);
 
   $main::lxdebug->leave_sub();
 
@@ -408,7 +407,7 @@ sub mark_orders_if_delivered {
                                         'to_table'   => 'delivery_orders',
                                         'to_id'      => $params{do_id});
 
-  my ($oe_id)  = $links[0]->{from_id} if (scalar @links);
+  my $oe_id  = @links ? $links[0]->{from_id} : undef;
 
   return $main::lxdebug->leave_sub() if (!$oe_id);
 
@@ -491,7 +490,7 @@ sub delete {
 
   my $myconfig = \%main::myconfig;
   my $form     = $main::form;
-  my $spool    = $main::spool;
+  my $spool    = $::lx_office_conf{paths}->{spool};
 
   # connect to database
   my $dbh = $form->get_standard_dbh($myconfig);
@@ -601,7 +600,7 @@ sub retrieve {
          d.description AS department, dord.language_id,
          dord.shipto_id,
          dord.globalproject_id, dord.delivered, dord.transaction_description,
-         dord.taxzone_id, dord.taxincluded, dord.terms, dord.curr
+         dord.taxzone_id, dord.taxincluded, dord.terms, dord.curr AS currency
        FROM delivery_orders dord
        JOIN ${vc} cv ON (dord.${vc}_id = cv.id)
        LEFT JOIN employee e ON (dord.employee_id = e.id)
@@ -623,6 +622,9 @@ sub retrieve {
   }
   $sth->finish();
 
+  # remove any trailing whitespace
+  $form->{currency} =~ s/\s*$//;
+
   $form->{donumber_array} =~ s/\s*$//g;
 
   $form->{saved_donumber} = $form->{donumber};
@@ -663,11 +665,11 @@ sub retrieve {
   # stuff different from the whole will not be overwritten, but saved with a suffix.
   $query =
     qq|SELECT doi.id AS delivery_order_items_id,
-         p.partnumber, p.assembly, doi.description, doi.qty,
+         p.partnumber, p.assembly, p.listprice, doi.description, doi.qty,
          doi.sellprice, doi.parts_id AS id, doi.unit, doi.discount, p.bin, p.notes AS partnotes,
          doi.reqdate, doi.project_id, doi.serialnumber, doi.lastcost,
          doi.ordnumber, doi.transdate, doi.cusordnumber, doi.longdescription,
-         doi.price_factor_id, doi.price_factor, doi.marge_price_factor,
+         doi.price_factor_id, doi.price_factor, doi.marge_price_factor, doi.pricegroup_id,
          pr.projectnumber, dord.transdate AS dord_transdate,
          pg.partsgroup
        FROM delivery_order_items doi
@@ -712,7 +714,7 @@ sub retrieve {
     $sth->finish();
   }
 
-  Common::webdav_folder($form) if ($main::webdav);
+  Common::webdav_folder($form);
 
   $main::lxdebug->leave_sub();
 
@@ -831,6 +833,7 @@ sub order_details {
     push @{ $form->{TEMPLATE_ARRAYS}{description} },     $form->{"description_$i"};
     push @{ $form->{TEMPLATE_ARRAYS}{longdescription} }, $form->{"longdescription_$i"};
     push @{ $form->{TEMPLATE_ARRAYS}{qty} },             $form->format_amount($myconfig, $form->{"qty_$i"});
+    push @{ $form->{TEMPLATE_ARRAYS}{qty_nofmt} },       $form->{"qty_$i"};
     push @{ $form->{TEMPLATE_ARRAYS}{unit} },            $form->{"unit_$i"};
     push @{ $form->{TEMPLATE_ARRAYS}{partnotes} },       $form->{"partnotes_$i"};
     push @{ $form->{TEMPLATE_ARRAYS}{serialnumber} },    $form->{"serialnumber_$i"};
@@ -859,7 +862,6 @@ sub order_details {
           $sameitem = ($ref->{partsgroup}) ? $ref->{partsgroup} : "--";
           push(@{ $form->{description} }, $sameitem);
         }
-
         push(@{ $form->{description} }, $form->format_amount($myconfig, $ref->{qty} * $form->{"qty_$i"}) . qq|, $ref->{partnumber}, $ref->{description}|);
 
         map({ push(@{ $form->{$_} }, "") } grep({ $_ ne "description" } @arrays));
@@ -883,11 +885,14 @@ sub order_details {
         push @{ $form->{TEMPLATE_ARRAYS}{si_chargenumber}[$position-1] },  $si->{chargenumber};
         push @{ $form->{TEMPLATE_ARRAYS}{si_bestbefore}[$position-1] },    $si->{bestbefore};
         push @{ $form->{TEMPLATE_ARRAYS}{si_qty}[$position-1] },           $form->format_amount($myconfig, $si->{qty} * 1);
+        push @{ $form->{TEMPLATE_ARRAYS}{si_qty_nofmt}[$position-1] },     $si->{qty} * 1;
         push @{ $form->{TEMPLATE_ARRAYS}{si_unit}[$position-1] },          $si->{unit};
       }
     }
 
-    map { push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} }, $form->{"ic_cvar_$_->{name}_$i"} } @{ $ic_cvar_configs };
+    push @{ $form->{TEMPLATE_ARRAYS}->{"ic_cvar_$_->{name}"} },
+      CVar->format_to_template(CVar->parse($form->{"ic_cvar_$_->{name}_$i"}, $_), $_)
+        for @{ $ic_cvar_configs };
   }
 
   $h_pg->finish();
@@ -1096,7 +1101,7 @@ sub get_shipped_qty {
   my $all_units = AM->retrieve_all_units();
 
   foreach my $entry (@{ $entries }) {
-    $entry->{qty} *= $all_units->{$entry->{unit}}->{factor} / $all_units->{$entry->{partunit}}->{factor};
+    $entry->{qty} *= AM->convert_unit($entry->{unit}, $entry->{partunit}, $all_units);
 
     if (!$ship{$entry->{parts_id}}) {
       $ship{$entry->{parts_id}} = $entry;