]> wagnertech.de Git - mfinanz.git/blobdiff - SL/AP.pm
Bugfix in SL/Menu und weitere stricts.
[mfinanz.git] / SL / AP.pm
index 50afccb52f0205a473b51c915e26b67e75fcccb7..d4fe48428f8e7e658319e9fd6e11f77c53ebac50 100644 (file)
--- a/SL/AP.pm
+++ b/SL/AP.pm
@@ -37,6 +37,8 @@ package AP;
 use SL::DBUtils;
 use SL::MoreCommon;
 
+use strict;
+
 sub post_transaction {
   $main::lxdebug->enter_sub();
 
@@ -60,7 +62,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 +88,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 =
@@ -160,7 +164,7 @@ sub post_transaction {
                                $form->{exchangerate});
   }
 
-  my ($query, $sth);
+  my ($query, $sth, @values);
 
   if (!$payments_only) {
     # if we have an id delete old records
@@ -194,7 +198,7 @@ sub post_transaction {
                 amount = ?, duedate = ?, paid = ?, datepaid = ?, 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},
@@ -205,7 +209,7 @@ sub post_transaction {
     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"});
@@ -390,18 +394,30 @@ sub ap_transactions {
   my ($self, $myconfig, $form) = @_;
 
   # connect to database
-  my $dbh = $form->dbconnect($myconfig);
+  my $dbh = $form->get_standard_dbh($myconfig);
 
   my $query =
     qq|SELECT a.id, a.invnumber, a.transdate, a.duedate, a.amount, a.paid, | .
     qq|  a.ordnumber, v.name, a.invoice, a.netamount, a.datepaid, a.notes, | .
     qq|  a.globalproject_id, a.storno, a.storno_id, | .
     qq|  pr.projectnumber AS globalprojectnumber, | .
-    qq|  e.name AS employee | .
+    qq|  e.name AS employee, | .
+    qq|  v.vendornumber, v.country, v.ustid, | .
+    qq|  tz.description AS taxzone, | .
+    qq|  pt.description AS payment_terms, | .
+    qq{  ( SELECT ch.accno || ' -- ' || ch.description
+           FROM acc_trans at
+           LEFT JOIN chart ch ON ch.id = at.chart_id
+           WHERE ch.link ~ 'AP[[:>:]]'
+            AND at.trans_id = a.id
+            LIMIT 1
+          ) AS charts } .
     qq|FROM ap a | .
     qq|JOIN vendor v ON (a.vendor_id = v.id) | .
     qq|LEFT JOIN employee e ON (a.employee_id = e.id) | .
-    qq|LEFT JOIN project pr ON (a.globalproject_id = pr.id) |;
+    qq|LEFT JOIN project pr ON (a.globalproject_id = pr.id) | .
+    qq|LEFT JOIN tax_zones tz ON (tz.id = v.taxzone_id)| .
+    qq|LEFT JOIN payment_terms pt ON (pt.id = v.payment_id)|;
 
   my $where = '';
   my @values;
@@ -458,7 +474,7 @@ sub ap_transactions {
     $query .= $where;
   }
 
-  my @a = (transdate, invnumber, name);
+  my @a = qw(transdate invnumber name);
   push @a, "employee" if $self->{l_employee};
   my $sortdir   = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC';
   my $sortorder = join(', ', map { "$_ $sortdir" } @a);
@@ -469,17 +485,9 @@ sub ap_transactions {
 
   $query .= " ORDER BY $sortorder";
 
-  my $sth = $dbh->prepare($query);
-  $sth->execute(@values) ||
-    $form->dberror($query . " (" . join(", ", @values) . ")");
+  my @result = selectall_hashref_query($form, $dbh, $query, @values);
 
-  $form->{AP} = [];
-  while (my $ap = $sth->fetchrow_hashref(NAME_lc)) {
-    push @{ $form->{AP} }, $ap;
-  }
-
-  $sth->finish;
-  $dbh->disconnect;
+  $form->{AP} = [ @result ];
 
   $main::lxdebug->leave_sub();
 }
@@ -612,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};
@@ -761,7 +770,7 @@ sub storno {
 
   # now copy acc_trans entries
   $query = qq|SELECT a.*, c.link FROM acc_trans a LEFT JOIN chart c ON a.chart_id = c.id WHERE a.trans_id = ? ORDER BY a.acc_trans_id|;
-  my $rowref = selectall_hashref_query($form, $dbh, $query, $id); 
+  my $rowref = selectall_hashref_query($form, $dbh, $query, $id);
 
   # kill all entries containing payments, which are the last 2n rows, of which the last has link =~ /paid/
   while ($rowref->[-1]{link} =~ /paid/) {