Erstes Update zur USTVA Anpassung an 16%/19%.
[kivitendo-erp.git] / SL / OE.pm
index 8af63e6..916d41b 100644 (file)
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -65,7 +65,7 @@ sub transactions {
   my $query = qq|SELECT o.id, o.ordnumber, o.transdate, o.reqdate,
                  o.amount, ct.name, o.netamount, o.$form->{vc}_id,
                 ex.$rate AS exchangerate,
-                o.closed, o.quonumber, o.shippingpoint, o.shipvia,
+                o.closed, o.delivered, o.quonumber, o.shippingpoint, o.shipvia,
                 e.name AS employee
                 FROM oe o
                 JOIN $form->{vc} ct ON (o.$form->{vc}_id = ct.id)
@@ -126,6 +126,12 @@ sub transactions {
     $query .= ($form->{open}) ? " AND o.closed = '0'" : " AND o.closed = '1'";
   }
 
+  if (($form->{"notdelivered"} || $form->{"delivered"}) &&
+      ($form->{"notdelivered"} ne $form->{"delivered"})) {
+    $query .= $form->{"delivered"} ?
+      " AND o.delivered " : " AND NOT o.delivered";
+  }
+
   my $sortorder = join ', ',
     ("o.id", $form->sort_columns(transdate, $ordnumber, name));
   $sortorder = $form->{sort} if $form->{sort};
@@ -240,7 +246,7 @@ sub save {
         $form->parse_amount($myconfig, $form->{"${_}_$i"})
     } qw(qty ship);
 
-    if ($form->{"qty_$i"}) {
+    if ($form->{"id_$i"}) {
 
       # get item baseunit
       $query = qq|SELECT p.unit
@@ -460,6 +466,7 @@ Message: $form->{message}\r| if $form->{message};
              intnotes = '$form->{intnotes}',
              curr = '$form->{currency}',
              closed = '$form->{closed}',
+             delivered = '| . ($form->{delivered} ? "t" : "f") . qq|',
              proforma = '$form->{proforma}',
              quotation = '$quotation',
              department_id = $form->{department_id},
@@ -525,27 +532,6 @@ sub close_orders {
 
   my ($self, $myconfig, $form) = @_;
 
-  for my $i (1 .. $form->{rowcount}) {
-
-    map {
-      $form->{"${_}_$i"} =
-        $form->parse_amount($myconfig, $form->{"${_}_$i"})
-    } qw(qty ship);
-    if ($delete_oe_id) {
-      $form->{"orderitems_id_$i"} = "";
-    }
-
-    if ($form->{"qty_$i"}) {
-
-      # set values to 0 if nothing entered
-      $form->{"discount_$i"} =
-        $form->parse_amount($myconfig, $form->{"discount_$i"});
-
-      $form->{"sellprice_$i"} =
-        $form->parse_amount($myconfig, $form->{"sellprice_$i"});
-    }
-  }
-
   # get ids from $form
   map { push @ids, $form->{"ordnumber_$_"} if $form->{"ordnumber_$_"} }
     (1 .. $form->{rowcount});
@@ -569,7 +555,7 @@ sub close_order {
   $main::lxdebug->leave_sub() unless ($form->{"id"});
 
   my $dbh = $form->dbconnect($myconfig);
-  do_query($form, $dbh, qq|UPDATE oe SET closed = TRUE where ordnumber = ?|,
+  do_query($form, $dbh, qq|UPDATE oe SET closed = TRUE where id = ?|,
            $form->{"id"});
   $dbh->disconnect;
 
@@ -724,7 +710,9 @@ sub retrieve {
                o.curr AS currency, e.name AS employee, o.employee_id,
                o.$form->{vc}_id, cv.name AS $form->{vc}, o.amount AS invtotal,
                o.closed, o.reqdate, o.quonumber, o.department_id, o.cusordnumber,
-               d.description AS department, o.payment_id, o.language_id, o.taxzone_id, o.delivery_customer_id, o.delivery_vendor_id, o.proforma, o.shipto_id
+               d.description AS department, o.payment_id, o.language_id, o.taxzone_id,
+                o.delivery_customer_id, o.delivery_vendor_id, o.proforma, o.shipto_id,
+                o.delivered
                FROM oe o
                JOIN $form->{vc} cv ON (o.$form->{vc}_id = cv.id)
                LEFT JOIN employee e ON (o.employee_id = e.id)
@@ -1028,7 +1016,7 @@ sub order_details {
 
     $form->{"qty_$i"} = $form->parse_amount($myconfig, $form->{"qty_$i"});
 
-    if ($form->{"qty_$i"} != 0) {
+    if ($form->{"id_$i"} != 0) {
 
       # add number, description and qty to $form->{number}, ....
 
@@ -1183,7 +1171,9 @@ sub order_details {
         while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
           if ($form->{groupitems} && $ref->{partsgroup} ne $sameitem) {
             map { push(@{ $form->{$_} }, "") }
-              qw(runningnumber ship bin serialnumber number unit bin qty reqdate sellprice listprice netprice discount linetotal nodiscount_linetotal);
+              qw(runningnumber ship bin serialnumber number unit bin qty 
+                 reqdate sellprice listprice netprice discount p_discount
+                 linetotal nodiscount_linetotal);
             $sameitem = ($ref->{partsgroup}) ? $ref->{partsgroup} : "--";
             push(@{ $form->{description} }, $sameitem);
           }
@@ -1194,7 +1184,9 @@ sub order_details {
                  . qq|, $ref->{partnumber}, $ref->{description}|);
 
           map { push(@{ $form->{$_} }, "") }
-            qw(number unit qty runningnumber ship bin serialnumber reqdate sellprice listprice netprice discount linetotal nodiscount_linetotal);
+            qw(number unit qty runningnumber ship bin serialnumber reqdate 
+               sellprice listprice netprice discount p_discount linetotal 
+               nodiscount_linetotal);
 
         }
         $sth->finish;