]> wagnertech.de Git - kivitendo-erp.git/blobdiff - SL/IS.pm
subtotal ist eine Boolean-Spalte; ältere DBI-Versionen mögen's nicht, wenn man ihnen...
[kivitendo-erp.git] / SL / IS.pm
index 261c7c1e458c4b2e5e8a2e580a0416ff17e22d94..ec744df2eba91e049438f2961a1db36c03ffaa0f 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();
@@ -685,7 +686,6 @@ sub post_invoice {
       # get pricegroup_id and save it
       ($null, my $pricegroup_id) = split(/--/, $form->{"sellprice_pg_$i"});
       $pricegroup_id *= 1;
-      my $subtotal = $form->{"subtotal_$i"} * 1;
 
       # save detail record in invoice table
       $query =
@@ -703,7 +703,7 @@ sub post_invoice {
                  $form->{"unit_$i"}, conv_date($form->{"deliverydate_$i"}), conv_i($form->{"project_id_$i"}),
                  $form->{"serialnumber_$i"}, conv_i($pricegroup_id),
                  $form->{"ordnumber_$i"}, conv_date($form->{"transdate_$i"}),
-                 $form->{"cusordnumber_$i"}, $baseqty, $subtotal,
+                 $form->{"cusordnumber_$i"}, $baseqty, $form->{"subtotal_$i"} ? 't' : 'f',
                  $form->{"marge_percent_$i"}, $form->{"marge_absolut_$i"},
                  $form->{"lastcost_$i"});
       do_query($form, $dbh, $query, @values);
@@ -902,6 +902,9 @@ sub post_invoice {
                                    $form->{"exchangerate_$i"}, 0);
       }
     }
+
+  } else {                      # if (!$form->{storno})
+    $form->{marge_total} *= -1;
   }
 
   if ($payments_only) {
@@ -938,24 +941,6 @@ sub post_invoice {
 
   $amount = $netamount + $tax;
 
-  # fill in subject if there is none
-  $form->{subject} = qq|$form->{label} $form->{invnumber}|
-    unless $form->{subject};
-
-  # if there is a message stuff it into the intnotes
-  my $cc  = "Cc: $form->{cc}\\r\n"   if $form->{cc};
-  my $bcc = "Bcc: $form->{bcc}\\r\n" if $form->{bcc};
-  my $now = scalar localtime;
-  $form->{intnotes} .= qq|\r
-\r| if $form->{intnotes};
-
-  $form->{intnotes} .= qq|[email]\r
-Date: $now
-To: $form->{email}\r
-$cc${bcc}Subject: $form->{subject}\r
-\r
-Message: $form->{message}\r| if $form->{message};
-
   # save AR record
   $query = qq|UPDATE ar set
                 invnumber = ?,
@@ -991,6 +976,7 @@ Message: $form->{message}\r| if $form->{message};
                 employee_id = ?,
                 salesman_id = ?,
                 storno = ?,
+                storno_id = ?,
                 globalproject_id = ?,
                 cp_id = ?,
                 transaction_description = ?,
@@ -1008,9 +994,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 +1205,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 +1398,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 +2148,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 +2159,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();