Das nächste Release ist 2.4.3.
[kivitendo-erp.git] / SL / IS.pm
index 261c7c1..55f92b1 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -38,6 +38,7 @@ use SL::AM;
 use SL::Common;
 use SL::DBUtils;
 use SL::MoreCommon;
+use Data::Dumper;
 
 sub invoice_details {
   $main::lxdebug->enter_sub();
@@ -902,6 +903,9 @@ sub post_invoice {
                                    $form->{"exchangerate_$i"}, 0);
       }
     }
+
+  } else {                      # if (!$form->{storno})
+    $form->{marge_total} *= -1;
   }
 
   if ($payments_only) {
@@ -991,6 +995,7 @@ Message: $form->{message}\r| if $form->{message};
                 employee_id = ?,
                 salesman_id = ?,
                 storno = ?,
+                storno_id = ?,
                 globalproject_id = ?,
                 cp_id = ?,
                 transaction_description = ?,
@@ -1008,9 +1013,9 @@ Message: $form->{message}\r| if $form->{message};
              conv_i($form->{"shipto_id"}),
              conv_i($form->{"delivery_customer_id"}), conv_i($form->{"delivery_vendor_id"}),
              conv_i($form->{"employee_id"}), conv_i($form->{"salesman_id"}),
-             $form->{"storno"} ? 't' : 'f', conv_i($form->{"globalproject_id"}),
+             $form->{"storno"} ? 't' : 'f', conv_i($form->{storno_id}), conv_i($form->{"globalproject_id"}),
              conv_i($form->{"cp_id"}), $form->{transaction_description},
-             $form->{marge_total}, $form->{marge_percent},
+             $form->{marge_total} * 1, $form->{marge_percent} * 1,
              conv_i($form->{"id"}));
   do_query($form, $dbh, $query, @values);
   
@@ -1219,19 +1224,9 @@ sub cogs {
   my $taxzone_id = $form->{"taxzone_id"} * 1;
   my $query =
     qq|SELECT i.id, i.trans_id, i.base_qty, i.allocated, i.sellprice,
-
-         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,
-
-         c3.accno AS expense_accno,
-         c3.new_chart_id AS expense_new_chart,
-         date($transdate) - c3.valid_from AS expense_valid
-
+         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,
+         c3.accno AS   expense_accno, c3.new_chart_id AS   expense_new_chart, date($transdate) - c3.valid_from AS   expense_valid
        FROM invoice i, parts p
        LEFT JOIN chart c1 ON ((SELECT inventory_accno_id FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c1.id)
        LEFT JOIN chart c2 ON ((SELECT income_accno_id_${taxzone_id} FROM buchungsgruppen WHERE id = p.buchungsgruppen_id) = c2.id)
@@ -1422,6 +1417,7 @@ sub retrieve_invoice {
            a.employee_id, a.salesman_id, a.payment_id,
            a.language_id, a.delivery_customer_id, a.delivery_vendor_id, a.type,
            a.transaction_description,
+           a.marge_total, a.marge_percent,
            e.name AS employee
          FROM ar a
          LEFT JOIN employee e ON (e.id = a.employee_id)
@@ -2171,9 +2167,9 @@ sub has_storno {
 sub is_storno {
   $main::lxdebug->enter_sub();
 
-  my ($self, $myconfig, $form, $table) = @_;
+  my ($self, $myconfig, $form, $table, $id) = @_;
 
-  $main::lxdebug->leave_sub() and return 0 unless ($form->{id});
+  $main::lxdebug->leave_sub() and return 0 unless ($id);
 
   # make sure there's no funny stuff in $table
   # ToDO: die when this happens and throw an error
@@ -2182,7 +2178,7 @@ sub is_storno {
   my $dbh = $form->dbconnect($myconfig);
 
   my $query = qq|SELECT storno FROM $table WHERE id = ?|;
-  my ($result) = selectrow_query($form, $dbh, $query, $form->{id});
+  my ($result) = selectrow_query($form, $dbh, $query, $id);
 
   $dbh->disconnect();