Kunden- und Liferantenstammdatenliste auf die Verwendung von ReportGenerator umgestellt.
[kivitendo-erp.git] / SL / OE.pm
index 0c14f17..5da1478 100644 (file)
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -66,6 +66,8 @@ sub transactions {
     qq|SELECT o.id, o.ordnumber, o.transdate, o.reqdate, | .
     qq|  o.amount, ct.name, o.netamount, o.${vc}_id, o.globalproject_id, | .
     qq|  o.closed, o.delivered, o.quonumber, o.shippingpoint, o.shipvia, | .
+    qq|  o.transaction_description, | .
+    qq|  o.marge_total, o.marge_percent, | .
     qq|  ex.$rate AS exchangerate, | .
     qq|  pr.projectnumber AS globalprojectnumber, | .
     qq|  e.name AS employee | .
@@ -101,6 +103,11 @@ sub transactions {
     push(@values, '%' . $form->{$vc} . '%');
   }
 
+  if ($form->{employee_id}) {
+    $query .= " AND o.employee_id = ?";
+    push @values, conv_i($form->{employee_id});
+  }
+
   if (!$form->{open} && !$form->{closed}) {
     $query .= " AND o.id = 0";
   } elsif (!($form->{open} && $form->{closed})) {
@@ -114,7 +121,7 @@ sub transactions {
   }
 
   if ($form->{$ordnumber}) {
-    $query .= qq| AND $ordnumber ILIKE ?|;
+    $query .= qq| AND o.$ordnumber ILIKE ?|;
     push(@values, '%' . $form->{$ordnumber} . '%');
   }
 
@@ -128,6 +135,11 @@ sub transactions {
     push(@values, conv_date($form->{transdateto}));
   }
 
+  if ($form->{transaction_description}) {
+    $query .= qq| AND o.transaction_description ILIKE ?|;
+    push(@values, '%' . $form->{transaction_description} . '%');
+  }
+
   my $sortorder = join(', ', ("o.id", $form->sort_columns("transdate", $ordnumber, "name")));
   my %allowed_sort_columns =
     ("transdate" => "o.transdate",
@@ -137,7 +149,8 @@ sub transactions {
      "quonumber" => "o.quonumber",
      "name" => "ct.name",
      "employee" => "e.name",
-     "shipvia" => "o.shipvia");
+     "shipvia" => "o.shipvia",
+     "transaction_description" => "o.transaction_description");
   if ($form->{sort} && grep($form->{sort}, keys(%allowed_sort_columns))) {
     $sortorder = $allowed_sort_columns{$form->{sort}};
   }
@@ -175,7 +188,7 @@ sub save {
   my $all_units = AM->retrieve_units($myconfig, $form);
   $form->{all_units} = $all_units;
 
-  ($null, $form->{employee_id}) = split /--/, $form->{employee};
+  $form->{employee_id} = (split /--/, $form->{employee})[1] if !$form->{employee_id};
   unless ($form->{employee_id}) {
     $form->get_employee($dbh);
   }
@@ -234,6 +247,10 @@ sub save {
       }
       my $baseqty = $form->{"qty_$i"} * $basefactor;
 
+      $form->{"marge_percent_$i"} = $form->parse_amount($myconfig, $form->{"marge_percent_$i"}) * 1;
+      $form->{"marge_absolut_$i"} = $form->parse_amount($myconfig, $form->{"marge_absolut_$i"}) * 1;
+      $form->{"lastcost_$i"} = $form->{"lastcost_$i"} * 1;
+
       # set values to 0 if nothing entered
       $form->{"discount_$i"} =
         $form->parse_amount($myconfig, $form->{"discount_$i"}) / 100;
@@ -323,13 +340,14 @@ sub save {
       }
       $query .= qq|trans_id, parts_id, description, longdescription, qty, base_qty, | .
                 qq|sellprice, discount, unit, reqdate, project_id, serialnumber, ship, | .
-                qq|pricegroup_id, ordnumber, transdate, cusordnumber, subtotal) | .
+                qq|pricegroup_id, ordnumber, transdate, cusordnumber, subtotal, | .
+                qq|marge_percent, marge_total, lastcost) | .
                 qq|VALUES (|;
       if($form->{"orderitems_id_$i"}) {
         $query .= qq|?,|;
         push(@values, $form->{"orderitems_id_$i"});
       }
-      $query .= qq|?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
+      $query .= qq|?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
                  push(@values,
            conv_i($form->{id}), conv_i($form->{"id_$i"}),
            $form->{"description_$i"}, $form->{"longdescription_$i"},
@@ -338,7 +356,9 @@ sub save {
            $form->{"unit_$i"}, conv_date($reqdate), conv_i($form->{"project_id_$i"}),
            $form->{"serialnumber_$i"}, $form->{"ship_$i"}, conv_i($pricegroup_id),
            $form->{"ordnumber_$i"}, conv_date($form->{"transdate_$i"}),
-           $form->{"cusordnumber_$i"}, $subtotal);
+           $form->{"cusordnumber_$i"}, $subtotal,
+           $form->{"marge_percent_$i"}, $form->{"marge_absolut_$i"},
+           $form->{"lastcost_$i"});
       do_query($form, $dbh, $query, @values);
 
       $form->{"sellprice_$i"} = $fxsellprice;
@@ -407,7 +427,7 @@ Message: $form->{message}\r| if $form->{message};
     qq|shippingpoint = ?, shipvia = ?, notes = ?, intnotes = ?, curr = ?, closed = ?, | .
     qq|delivered = ?, proforma = ?, quotation = ?, department_id = ?, language_id = ?, | .
     qq|taxzone_id = ?, shipto_id = ?, payment_id = ?, delivery_vendor_id = ?, delivery_customer_id = ?, | .
-    qq|globalproject_id = ?, employee_id = ?, salesman_id = ?, cp_id = ? | .
+    qq|globalproject_id = ?, employee_id = ?, salesman_id = ?, cp_id = ?, transaction_description = ?, marge_total = ?, marge_percent = ?| .
     qq|WHERE id = ?|;
 
   @values = ($form->{ordnumber}, $form->{quonumber},
@@ -425,6 +445,8 @@ Message: $form->{message}\r| if $form->{message};
              conv_i($form->{delivery_customer_id}),
              conv_i($form->{globalproject_id}), conv_i($form->{employee_id}),
              conv_i($form->{salesman_id}), conv_i($form->{cp_id}),
+             $form->{transaction_description},
+             $form->{marge_total}, $form->{marge_percent},
              conv_i($form->{id}));
   do_query($form, $dbh, $query, @values);
 
@@ -669,7 +691,7 @@ sub retrieve {
       qq|  o.closed, o.reqdate, o.quonumber, o.department_id, o.cusordnumber, | .
       qq|  d.description AS department, o.payment_id, o.language_id, o.taxzone_id, | .
       qq|  o.delivery_customer_id, o.delivery_vendor_id, o.proforma, o.shipto_id, | .
-      qq|  o.globalproject_id, o.delivered | .
+      qq|  o.globalproject_id, o.delivered, o.transaction_description | .
       qq|FROM oe o | .
       qq|JOIN ${vc} cv ON (o.${vc}_id = cv.id) | .
       qq|LEFT JOIN employee e ON (o.employee_id = e.id) | .
@@ -754,7 +776,7 @@ sub retrieve {
       qq|  oe.ordnumber AS ordnumber_oe, oe.transdate AS transdate_oe, oe.cusordnumber AS cusordnumber_oe,  | .
       qq|  p.partnumber, p.assembly, o.description, o.qty, | .
       qq|  o.sellprice, o.parts_id AS id, o.unit, o.discount, p.bin, p.notes AS partnotes, p.inventory_accno_id AS part_inventory_accno_id, | .
-      qq|  o.reqdate, o.project_id, o.serialnumber, o.ship, | .
+      qq|  o.reqdate, o.project_id, o.serialnumber, o.ship, o.lastcost, | .
       qq|  o.ordnumber, o.transdate, o.cusordnumber, o.subtotal, o.longdescription, | .
       qq|  pr.projectnumber, p.formel, | .
       qq|  pg.partsgroup, o.pricegroup_id, (SELECT pricegroup FROM pricegroup WHERE id=o.pricegroup_id) as pricegroup | .
@@ -870,10 +892,6 @@ sub retrieve {
 
   Common::webdav_folder($form) if ($main::webdav);
 
-  # get tax zones
-  $query = qq|SELECT id, description FROM tax_zones|;
-  $form->{TAXZONE} = selectall_hashref_query($form, $dbh, $query);
-
   my $rc = $dbh->commit;
   $dbh->disconnect;