]> wagnertech.de Git - mfinanz.git/blobdiff - SL/AP.pm
is.pl: unnötige parse_amounts
[mfinanz.git] / SL / AP.pm
index 6bc1095b44302a72cec8f49c21d36b2e304004fb..ad8749f56882cd4d2fafe78b8383acbc258ce5f6 100644 (file)
--- a/SL/AP.pm
+++ b/SL/AP.pm
 package AP;
 
 use SL::DBUtils;
+use SL::IO;
 use SL::MoreCommon;
 
+use strict;
+
 sub post_transaction {
   $main::lxdebug->enter_sub();
 
@@ -60,7 +63,7 @@ sub post_transaction {
     $form->{exchangerate} = $exchangerate || $form->parse_amount($myconfig, $form->{exchangerate});
   }
 
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     $form->{AP_amounts}{"amount_$i"} =
       (split(/--/, $form->{"AP_amount_$i"}))[0];
   }
@@ -86,19 +89,21 @@ sub post_transaction {
   # taxincluded doesn't make sense if there is no amount
   $form->{taxincluded} = 0 if ($form->{amount} == 0);
 
-  for $i (1 .. $form->{rowcount}) {
-    ($form->{"tax_id_$i"}, $NULL) = split /--/, $form->{"taxchart_$i"};
+  for my $i (1 .. $form->{rowcount}) {
+    ($form->{"tax_id_$i"}, undef) = split /--/, $form->{"taxchart_$i"};
 
-    $query =
+    my $query =
       qq|SELECT c.accno, t.taxkey, t.rate | .
       qq|FROM tax t LEFT JOIN chart c on (c.id=t.chart_id) | .
       qq|WHERE t.id = ? | .
       qq|ORDER BY c.accno|;
-    $sth = $dbh->prepare($query);
+    my $sth = $dbh->prepare($query);
     $sth->execute($form->{"tax_id_$i"}) || $form->dberror($query . " (" . $form->{"tax_id_$i"} . ")");
     ($form->{AP_amounts}{"tax_$i"}, $form->{"taxkey_$i"}, $form->{"taxrate_$i"}) = $sth->fetchrow_array();
 
     $sth->finish;
+
+    my ($tax, $diff);
     if ($form->{taxincluded} *= 1) {
       if (!$form->{"korrektur_$i"}) {
         $tax =
@@ -151,16 +156,13 @@ sub post_transaction {
   # amount for total AP
   $form->{payables} = $form->{invtotal};
 
-  $form->{datepaid} = $form->{transdate} unless ($form->{datepaid});
-  my $datepaid = ($form->{invpaid} != 0) ? $form->{datepaid} : undef;
-
   # update exchangerate
   if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) {
     $form->update_exchangerate($dbh, $form->{currency}, $form->{transdate}, 0,
                                $form->{exchangerate});
   }
 
-  my ($query, $sth);
+  my ($query, $sth, @values);
 
   if (!$payments_only) {
     # if we have an id delete old records
@@ -191,21 +193,21 @@ sub post_transaction {
 
     $query = qq|UPDATE ap SET
                 invnumber = ?, transdate = ?, ordnumber = ?, vendor_id = ?, taxincluded = ?,
-                amount = ?, duedate = ?, paid = ?, datepaid = ?, netamount = ?,
+                amount = ?, duedate = ?, paid = ?, netamount = ?,
                 curr = ?, notes = ?, department_id = ?, storno = ?, storno_id = ?
                WHERE id = ?|;
-    my @values = ($form->{invnumber}, conv_date($form->{transdate}),
+    @values = ($form->{invnumber}, conv_date($form->{transdate}),
                   $form->{ordnumber}, conv_i($form->{vendor_id}),
                   $form->{taxincluded} ? 't' : 'f', $form->{invtotal},
                   conv_date($form->{duedate}), $form->{invpaid},
-                  conv_date($datepaid), $form->{netamount},
+                  $form->{netamount},
                   $form->{currency}, $form->{notes},
                   conv_i($form->{department_id}), $form->{storno},
                   $form->{storno_id}, $form->{id});
     do_query($form, $dbh, $query, @values);
 
     # add individual transactions
-    for $i (1 .. $form->{rowcount}) {
+    for my $i (1 .. $form->{rowcount}) {
       if ($form->{"amount_$i"} != 0) {
         my $project_id;
         $project_id = conv_i($form->{"project_id_$i"});
@@ -350,6 +352,8 @@ sub post_transaction {
     do_query($form, $dbh, $query,  $form->{invpaid}, $form->{invpaid} ? conv_date($form->{datepaid}) : undef, conv_i($form->{id}));
   }
 
+  IO->set_datepaid(table => 'ap', id => $form->{id}, dbh => $dbh);
+
   my $rc = 1;
   if (!$provided_dbh) {
     $dbh->commit();
@@ -470,8 +474,8 @@ sub ap_transactions {
     $query .= $where;
   }
 
-  my @a = (transdate, invnumber, name);
-  push @a, "employee" if $self->{l_employee};
+  my @a = qw(transdate invnumber name);
+  push @a, "employee" if $form->{l_employee};
   my $sortdir   = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC';
   my $sortorder = join(', ', map { "$_ $sortdir" } @a);
 
@@ -616,7 +620,8 @@ sub setup_form {
 
   my ($self, $form) = @_;
 
-  my ($exchangerate, $i, $j, $k, $key, $akey, $ref, $index, $taxamount, $totalamount);
+  my ($exchangerate, $i, $j, $k, $key, $akey, $ref, $index, $taxamount, $totalamount, $totaltax, $totalwithholding, $withholdingrate,
+      $taxincluded, $tax, $diff);
 
   # forex
   $form->{forex} = $form->{exchangerate};
@@ -637,6 +642,7 @@ sub setup_form {
     $j = 0;
     $k = 0;
 
+    next unless $form->{acc_trans}{$key};
     for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
 
       if ($key eq "AP_paid") {
@@ -780,6 +786,8 @@ sub storno {
     do_query($form, $dbh, $query, (values %$row));
   }
 
+  map { IO->set_datepaid(table => 'ap', id => $_, dbh => $dbh) } ($id, $new_id);
+
   $dbh->commit;
 
   $main::lxdebug->leave_sub();