XML-Templates um Mimetypen fuer Winston und Taxbird erweitert
[kivitendo-erp.git] / SL / OE.pm
index 2e5c8d6..e8127a2 100644 (file)
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -35,6 +35,7 @@
 package OE;
 
 use SL::AM;
+use SL::DBUtils;
 
 sub transactions {
   $main::lxdebug->enter_sub();
@@ -351,7 +352,7 @@ sub save {
         ($form->{"reqdate_$i"}) ? qq|'$form->{"reqdate_$i"}'| : "NULL";
 
       # get pricegroup_id and save ist
-      ($null, my $pricegroup_id) = split /--/, $form->{"sellprice_drag_$i"};
+      ($null, my $pricegroup_id) = split /--/, $form->{"sellprice_pg_$i"};
       $pricegroup_id *= 1;
       $subtotal = $form->{"subtotal_$i"} * 1;
 
@@ -560,6 +561,21 @@ sub close_orders {
   $main::lxdebug->leave_sub();
 }
 
+sub close_order {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form) = @_;
+
+  $main::lxdebug->leave_sub() unless ($form->{"id"});
+
+  my $dbh = $form->dbconnect($myconfig);
+  do_query($form, $dbh, qq|UPDATE oe SET closed = TRUE where ordnumber = ?|,
+           $form->{"id"});
+  $dbh->disconnect;
+
+  $main::lxdebug->leave_sub();
+}
+
 sub delete {
   $main::lxdebug->enter_sub();
 
@@ -787,10 +803,9 @@ sub retrieve {
     my %oid = ('Pg'     => 'oid',
                'Oracle' => 'rowid');
 
-    my $transdate = "'$form->{transdate}'";
-    if (!$transdate) {
-      $transdate = "current_date";
-    }
+    my $transdate =
+      $form->{transdate} ? $dbh->quote($form->{transdate}) : "current_date";
+
     if(!$form->{taxzone_id}) {
       $form->{taxzone_id} = 0;
     }
@@ -806,7 +821,7 @@ sub retrieve {
                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,
                 o.reqdate, o.project_id, o.serialnumber, o.ship,
                o.ordnumber, o.transdate, o.cusordnumber, o.subtotal, o.longdescription,
-               pr.projectnumber, p.alu, p.formel,
+               pr.projectnumber, p.formel,
                pg.partsgroup, o.pricegroup_id, (SELECT pricegroup FROM pricegroup WHERE id=o.pricegroup_id) as pricegroup
                FROM orderitems o
                JOIN parts p ON (o.parts_id = p.id)
@@ -869,19 +884,13 @@ sub retrieve {
       # delete orderitems_id in collective orders, so that they get cloned no matter what
       delete $ref->{orderitems_id} if (@ids);
 
-      #set expense_accno=inventory_accno if they are different => bilanz
-      $vendor_accno =
-        ($ref->{expense_accno} != $ref->{inventory_accno})
-        ? $ref->{inventory_accno}
-        : $ref->{expense_accno};
-
       # get tax rates and description
       $accno_id =
-        ($form->{vc} eq "customer") ? $ref->{income_accno} : $vendor_accno;
+        ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
       $query = qq|SELECT c.accno, t.taxdescription, t.rate, t.taxnumber
-                FROM tax t LEFT JOIN chart c ON (c.id=t.chart_id)
-                WHERE t.taxkey in (SELECT taxkey_id from chart where accno = '$accno_id')
-                ORDER BY accno|;
+             FROM tax t LEFT JOIN chart c on (c.id=t.chart_id)
+             WHERE t.id in (SELECT tk.tax_id from taxkeys tk where tk.chart_id = (SELECT id from chart WHERE accno='$accno_id') AND startdate<=$transdate ORDER BY startdate desc LIMIT 1)
+             ORDER BY c.accno|;
       $stw = $dbh->prepare($query);
       $stw->execute || $form->dberror($query);
       $ref->{taxaccounts} = "";
@@ -1012,7 +1021,9 @@ sub order_details {
       $sameitem = $item->[1];
 
       map { push(@{ $form->{$_} }, "") }
-        qw(runningnumber number qty ship unit bin partnotes serialnumber reqdate sellprice listprice netprice discount linetotal);
+        qw(runningnumber number qty ship unit bin partnotes
+           serialnumber reqdate sellprice listprice netprice
+           discount p_discount linetotal);
     }
 
     $form->{"qty_$i"} = $form->parse_amount($myconfig, $form->{"qty_$i"});
@@ -1172,7 +1183,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);
           }
@@ -1183,7 +1196,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;