Neues Feature: Wenn die Anzahl Dezimalstellen bei format_amount() negativ ist, dann...
[kivitendo-erp.git] / SL / IR.pm
index c847781..8fb9b77 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -35,6 +35,7 @@
 package IR;
 
 use SL::AM;
+use SL::DBUtils;
 
 sub post_invoice {
   $main::lxdebug->enter_sub();
@@ -107,8 +108,12 @@ sub post_invoice {
     if ($form->{storno}) {
       $form->{"qty_$i"} *= -1;
     }
+
+    if ($main::eur) {
+      $form->{"inventory_accno_$i"} = $form->{"expense_accno_$i"};
+    }
     
-    if ($form->{"qty_$i"} != 0) {
+    if ($form->{"id_$i"}) {
 
       # get item baseunit
       $query = qq|SELECT p.unit
@@ -620,6 +625,8 @@ sub post_invoice {
              ordnumber = '$form->{ordnumber}',
              quonumber = '$form->{quonumber}',
               transdate = '$form->{invdate}',
+              orddate = | . conv_dateq($form->{"orddate"}) . qq|,
+              quodate = | . conv_dateq($form->{"quodate"}) . qq|,
               vendor_id = $form->{vendor_id},
               amount = $amount,
               netamount = $netamount,
@@ -841,7 +848,8 @@ sub retrieve_invoice {
 
     # retrieve invoice
     $query = qq|SELECT a.cp_id, a.invnumber, a.transdate AS invdate, a.duedate,
-                a.ordnumber, a.quonumber, a.paid, a.taxincluded, a.notes, a.taxzone_id, a.storno,
+                a.orddate, a.quodate,
+                a.ordnumber, a.quonumber, a.paid, a.taxincluded, a.notes, a.taxzone_id, a.storno, a.gldate,
                a.intnotes, a.curr AS currency
                FROM ap a
                WHERE a.id = $form->{id}|;
@@ -994,8 +1002,10 @@ sub get_vendor {
   my $query = qq|SELECT v.name AS vendor, v.creditlimit, v.terms,
                  v.email, v.cc, v.bcc, v.language_id, v.payment_id,
                 v.street, v.zipcode, v.city, v.country, v.taxzone_id,
-                 $duedate + v.terms AS duedate
+                 $duedate + v.terms AS duedate,
+                 b.description AS business
                  FROM vendor v
+                 LEFT JOIN business b ON b.id = v.business_id
                 WHERE v.id = $form->{vendor_id}|;
   my $sth = $dbh->prepare($query);
   $sth->execute || $form->dberror($query);
@@ -1147,7 +1157,7 @@ sub retrieve_item {
       $form->{transdate} ? $dbh->quote($form->{transdate}) : "current_date";
   }
 
-  my $query = qq|SELECT p.id, p.partnumber, p.description, p.sellprice,
+  my $query = qq|SELECT p.id, p.partnumber, p.description, p.lastcost AS sellprice,
                         p.listprice, p.inventory_accno_id,
                         c1.accno AS inventory_accno, c1.new_chart_id AS inventory_new_chart, date($transdate) - c1.valid_from as inventory_valid,
                        c2.accno AS income_accno, c2.new_chart_id AS income_new_chart, date($transdate)  - c2.valid_from as income_valid,
@@ -1218,7 +1228,7 @@ sub retrieve_item {
 sub vendor_details {
   $main::lxdebug->enter_sub();
 
-  my ($self, $myconfig, $form) = @_;
+  my ($self, $myconfig, $form, @wanted_vars) = @_;
 
   # connect to database
   my $dbh = $form->dbconnect($myconfig);
@@ -1245,6 +1255,14 @@ sub vendor_details {
 
   # remove id and taxincluded before copy back
   delete @$ref{qw(id taxincluded)};
+
+  @wanted_vars = grep({ $_ } @wanted_vars);
+  if (scalar(@wanted_vars) > 0) {
+    my %h_wanted_vars;
+    map({ $h_wanted_vars{$_} = 1; } @wanted_vars);
+    map({ delete($ref->{$_}) unless ($h_wanted_vars{$_}); } keys(%{$ref}));
+  }
+
   map { $form->{$_} = $ref->{$_} } keys %$ref;
 
   $sth->finish;