USTVA: Winston export ueberarbeitet. Kz vor die pos_ustva gesetzt, 'Kennzahl Nr'...
[kivitendo-erp.git] / bin / mozilla / gl.pl
index ccfee8b..43f5447 100644 (file)
 #======================================================================
 
 use SL::GL;
+use SL::IS;
 use SL::PE;
 
-require "$form->{path}/arap.pl";
+require "bin/mozilla/arap.pl";
 require "bin/mozilla/common.pl";
 
 1;
@@ -75,7 +76,7 @@ sub add {
   $form->{title} = "Add";
 
   $form->{callback} =
-    "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}"
+    "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
     unless $form->{callback};
 
   # we use this only to set a default date
@@ -109,7 +110,7 @@ sub add {
 
 }
 
-sub edit {
+sub prepare_transaction {
   $lxdebug->enter_sub();
 
   GL->transaction(\%myconfig, \%$form);
@@ -178,15 +179,24 @@ sub edit {
     ($form->datetonum($form->{transdate}, \%myconfig) <=
      $form->datetonum($form->{closedto}, \%myconfig));
 
+  $lxdebug->leave_sub();
+}
+
+sub edit {
+  $lxdebug->enter_sub();
+
+  prepare_transaction();
+
   $form->{title} = "Edit";
 
-  &form_header;
-  &display_rows;
-  &form_footer;
-  $lxdebug->leave_sub();
+  form_header();
+  display_rows();
+  form_footer();
 
+  $lxdebug->leave_sub();
 }
 
+
 sub search {
   $lxdebug->enter_sub();
 
@@ -364,7 +374,6 @@ $jsscript
 
 <input type=hidden name=nextsub value=generate_report>
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -387,7 +396,7 @@ sub generate_report {
   GL->all_transactions(\%myconfig, \%$form);
 
   $callback =
-    "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&password=$form->{password}";
+    "$form->{script}?action=generate_report&login=$form->{login}&password=$form->{password}";
 
   $href = $callback;
 
@@ -768,7 +777,7 @@ sub generate_report {
     $column_data{id}        = "<td align=right>&nbsp;$ref->{id}&nbsp;</td>";
     $column_data{transdate}    = "<td align=center>$transdate</td>";
     $column_data{reference} =
-      "<td align=center><a href=$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{reference}</td>";
+      "<td align=center><a href=$ref->{module}.pl?action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{reference}</td>";
     $column_data{description}  = "<td align=center>$ref->{description}&nbsp;</td>";
     $column_data{source}       = "<td align=center>$ref->{source}&nbsp;</td>";
     $column_data{notes}        = "<td align=center>$ref->{notes}&nbsp;</td>";
@@ -871,7 +880,6 @@ sub generate_report {
 
 <input name=callback type=hidden value="$form->{callback}">
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -1319,11 +1327,11 @@ sub form_header {
 <body onLoad="fokus()">
 
 <form method=post name="gl" action=$form->{script}>
+|;
 
-<input name=id type=hidden value=$form->{id}>
+  $form->hide_form(qw(id closedto locked storno storno_id));
 
-<input type=hidden name=closedto value=$form->{closedto}>
-<input type=hidden name=locked value=$form->{locked}>
+  print qq|
 <input type=hidden name=title value="$title">
 
 
@@ -1455,7 +1463,6 @@ sub form_footer {
   </tr>
 </table>
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -1469,8 +1476,10 @@ sub form_footer {
 
   if ($form->{id}) {
 
-    print qq|<input class=submit type=submit name=action value="|
-      . $locale->text('Storno') . qq|">|;
+    if (!$form->{storno}) {
+      print qq|<input class=submit type=submit name=action value="|
+        . $locale->text('Storno') . qq|">|;
+    }
 
     # Löschen und Ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
 
@@ -1544,7 +1553,7 @@ sub yes {
   if (GL->delete_transaction(\%myconfig, \%$form)){
     # saving the history
       if(!exists $form->{addition} && $form->{id} ne "") {
-        $form->{snumber} = qq|ordnumber_| . $form->{ordnumber};
+        $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
            $form->{addition} = "DELETED";
            $form->save_history($form->dbconnect(\%myconfig));
       }
@@ -1578,19 +1587,6 @@ sub post {
 
   my @flds =
     qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
-  if ($form->{storno}) {
-    for my $i (1 .. $form->{rowcount}) {
-      unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
-        if ($form->{"debit_$i"} ne "") {
-          $form->{"credit_$i"} = $form->{"debit_$i"};
-          $form->{"debit_$i"}  = "";
-        } elsif ($form->{"credit_$i"} ne "") {
-          $form->{"debit_$i"}  = $form->{"credit_$i"};
-          $form->{"credit_$i"} = "";
-        }
-      }
-    }
-  }
 
   for my $i (1 .. $form->{rowcount}) {
 
@@ -1738,7 +1734,7 @@ sub post {
   undef($form->{callback});
   # saving the history
   if(!exists $form->{addition} && $form->{id} ne "") {
-    $form->{snumber} = qq|ordnumber_| . $form->{ordnumber};
+    $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
        $form->{addition} = "SAVED";
        $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id}; 
        $form->save_history($form->dbconnect(\%myconfig));
@@ -1761,16 +1757,55 @@ sub post_as_new {
 sub storno {
   $lxdebug->enter_sub();
 
-  $form->{id}     = 0;
-  $form->{storno} = 1;
+  if (IS->has_storno(\%myconfig, $form, 'gl')) {
+    $form->{title} = $locale->text("Cancel General Ledger Transaction");
+    $form->error($locale->text("Transaction has already been cancelled!"));
+  }
+
+  my %keep_keys = map { $_, 1 } qw(login password id stylesheet);
+  map { delete $form->{$_} unless $keep_keys{$_} } keys %{ $form };
+
+  prepare_transaction();
+
+  for my $i (1 .. $form->{rowcount}) {
+    for (qw(debit credit tax)) {
+      $form->{"${_}_$i"} =
+        ($form->{"${_}_$i"})
+        ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
+        : "";
+    }
+  }
+
+  $form->{storno}      = 1;
+  $form->{storno_id}   = $form->{id};
+  $form->{id}          = 0;
+
+  $form->{reference}   = "Storno-" . $form->{reference};
+  $form->{description} = "Storno-" . $form->{description};
+
+  for my $i (1 .. $form->{rowcount}) {
+    next if (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq ""));
+
+    if ($form->{"debit_$i"} ne "") {
+      $form->{"credit_$i"} = $form->{"debit_$i"};
+      $form->{"debit_$i"}  = "";
+
+    } else {
+      $form->{"debit_$i"}  = $form->{"credit_$i"};
+      $form->{"credit_$i"} = "";
+    }
+  }
+
+  post();
+
   # saving the history
   if(!exists $form->{addition} && $form->{id} ne "") {
-    $form->{snumber} = qq|ordnumber_| . $form->{ordnumber};
+    $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
        $form->{addition} = "STORNO";
        $form->save_history($form->dbconnect(\%myconfig));
   }
   # /saving the history 
-  &post;
+
   $lxdebug->leave_sub();
 
 }