posaune
[kivitendo-erp.git] / SL / GL.pm
index ada29ac..01417aa 100644 (file)
--- a/SL/GL.pm
+++ b/SL/GL.pm
@@ -104,7 +104,7 @@ sub post_transaction {
     $query =
       qq|INSERT INTO gl (id, employee_id) | .
       qq|VALUES (?, (SELECT id FROM employee WHERE login = ?))|;
-    @values = ($form->{id}, $form->{login});
+    @values = ($form->{id}, $::myconfig{login});
     do_query($form, $dbh, $query, @values);
   }
 
@@ -196,8 +196,6 @@ sub post_transaction {
       exporttype => DATEV_ET_BUCHUNGEN,
       format     => DATEV_FORMAT_KNE,
       dbh        => $dbh,
-      from       => $transdate,
-      to         => $transdate,
       trans_id   => $form->{id},
     );
 
@@ -354,8 +352,6 @@ sub all_transactions {
     }
   }
 
-  my $false = ($myconfig->{dbdriver} eq 'Pg') ? "FALSE" : q|'0'|;
-
   my %sort_columns =  (
     'id'           => [ qw(id)                   ],
     'transdate'    => [ qw(transdate id)         ],
@@ -385,7 +381,7 @@ sub all_transactions {
 
   $query =
     qq|SELECT
-        ac.acc_trans_id, g.id, 'gl' AS type, $false AS invoice, g.reference, ac.taxkey, c.link,
+        ac.acc_trans_id, g.id, 'gl' AS type, FALSE AS invoice, g.reference, ac.taxkey, c.link,
         g.description, ac.transdate, ac.gldate, ac.source, ac.trans_id,
         ac.amount, c.accno, g.notes, t.chart_id,
         CASE WHEN (COALESCE(e.name, '') = '') THEN e.login ELSE e.name END AS employee
@@ -672,19 +668,7 @@ sub transaction {
          FROM acc_trans a
          JOIN chart c ON (c.id = a.chart_id)
          LEFT JOIN project p ON (p.id = a.project_id)
-         LEFT JOIN tax t ON
-           (t.id =
-             (SELECT tk.tax_id
-              FROM taxkeys tk
-              WHERE (tk.taxkey_id = a.taxkey) AND
-                ((CASE WHEN a.chart_id IN
-                    (SELECT chart_id FROM taxkeys WHERE taxkey_id = a.taxkey)
-                  THEN tk.chart_id = a.chart_id
-                  ELSE 1 = 1
-                  END)
-                 OR (c.link LIKE '%tax%'))
-                AND (startdate <= a.transdate)
-              ORDER BY startdate DESC LIMIT 1))
+         LEFT JOIN tax t ON (t.id = a.tax_id)
          WHERE (a.trans_id = ?)
            AND (a.fx_transaction = '0')
          ORDER BY a.acc_trans_id, a.transdate|;
@@ -738,10 +722,14 @@ sub storno {
   $query = qq|SELECT * FROM gl WHERE id = ?|;
   $storno_row = selectfirst_hashref_query($form, $dbh, $query, $id);
 
-  $storno_row->{id}        = $new_id;
-  $storno_row->{storno_id} = $id;
-  $storno_row->{storno}    = 't';
-  $storno_row->{reference} = 'Storno-' . $storno_row->{reference};
+  $storno_row->{id}          = $new_id;
+  $storno_row->{storno_id}   = $id;
+  $storno_row->{storno}      = 't';
+  $storno_row->{reference}   = 'Storno-' . $storno_row->{reference};
+
+  $query = qq|SELECT id FROM employee WHERE login = ?|;
+  my ($employee_id) = selectrow_query($form, $dbh, $query, $::myconfig{login});
+  $storno_row->{employee_id} = $employee_id;
 
   delete @$storno_row{qw(itime mtime gldate)};
 
@@ -803,23 +791,26 @@ sub get_chart_balances {
 }
 
 sub get_tax_dropdown {
+  my ($self, $accno) = @_;
+
   my $myconfig = \%main::myconfig;
   my $form = $main::form;
 
   my $dbh = $form->get_standard_dbh($myconfig);
 
   my $query = qq|SELECT category FROM chart WHERE accno = ?|;
-  my ($category) = selectrow_query($form, $dbh, $query, $form->{accno});
+  my ($category) = selectrow_query($form, $dbh, $query, $accno);
 
   $query = qq|SELECT * FROM tax WHERE chart_categories like '%$category%' order by taxkey, rate|;
 
   my $sth = prepare_execute_query($form, $dbh, $query);
 
-  $form->{TAX_ACCOUNTS} = [];
+  my @tax_accounts = ();
   while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
-    push(@{ $form->{TAX_ACCOUNTS} }, $ref);
+    push(@tax_accounts, $ref);
   }
 
+  return @tax_accounts;
 }
 
 1;