Bei print_options() die Parameterübergabe umgestellt, sodass der Aufrufer das Verhalt...
[kivitendo-erp.git] / SL / GL.pm
index eda7128..ef04d9a 100644 (file)
--- a/SL/GL.pm
+++ b/SL/GL.pm
@@ -70,13 +70,6 @@ sub post_transaction {
 
   my $i;
 
-  # check if debit and credit balances
-
-  if ($form->{storno}) {
-    $form->{reference}   = "Storno-" . $form->{reference};
-    $form->{description} = "Storno-" . $form->{description};
-  }
-
   # connect to database, turn off AutoCommit
   my $dbh = $form->dbconnect_noauto($myconfig);
 
@@ -119,11 +112,13 @@ sub post_transaction {
   $query =
     qq|UPDATE gl SET
          reference = ?, description = ?, notes = ?,
-         transdate = ?, department_id = ?, taxincluded = ?
+         transdate = ?, department_id = ?, taxincluded = ?,
+         storno = ?, storno_id = ?
        WHERE id = ?|;
 
   @values = ($form->{reference}, $form->{description}, $form->{notes},
              conv_date($form->{transdate}), $department_id, $form->{taxincluded},
+             $form->{storno} ? 't' : 'f', conv_i($form->{storno_id}),
              conv_i($form->{id}));
   do_query($form, $dbh, $query, @values);
 
@@ -180,6 +175,10 @@ sub post_transaction {
     }
   }
 
+  if ($form->{storno} && $form->{storno_id}) {
+    do_query($form, $dbh, qq|UPDATE gl SET storno = 't' WHERE id = ?|, conv_i($form->{storno_id}));
+  }
+
   # commit and redirect
   my $rc = $dbh->commit;
   $dbh->disconnect;
@@ -278,7 +277,7 @@ sub all_transactions {
                           (SELECT id FROM chart c2 WHERE c2.category = ?))|;
     $apwhere .=
       qq| AND ap.id in (SELECT trans_id FROM acc_trans ac2 WHERE ac2.chart_id IN
-                          (SELECT id FROM chart c2 WHERE c2.category = ?))"|;
+                          (SELECT id FROM chart c2 WHERE c2.category = ?))|;
     push(@glvalues, $form->{category});
     push(@arvalues, $form->{category});
     push(@apvalues, $form->{category});
@@ -556,9 +555,14 @@ sub transaction {
   $query = qq|SELECT closedto, revtrans FROM defaults|;
   ($form->{closedto}, $form->{revtrans}) = selectrow_query($form, $dbh, $query);
 
+  $query = qq|SELECT id, gldate
+              FROM gl
+              WHERE id = (SELECT max(id) FROM gl)|;
+  ($form->{previous_id}, $form->{previous_gldate}) = selectrow_query($form, $dbh, $query);
+
   if ($form->{id}) {
     $query =
-      qq|SELECT g.reference, g.description, g.notes, g.transdate,
+      qq|SELECT g.reference, g.description, g.notes, g.transdate, g.storno, g.storno_id,
            d.description AS department, e.name AS employee, g.taxincluded, g.gldate
          FROM gl g
          LEFT JOIN department d ON (d.id = g.department_id)