Schreibfehler in Variable.
[kivitendo-erp.git] / bin / mozilla / gl.pl
index faaad58..b14fb6f 100644 (file)
@@ -32,6 +32,7 @@
 #======================================================================
 
 use SL::GL;
+use SL::IS;
 use SL::PE;
 
 require "bin/mozilla/arap.pl";
@@ -104,12 +105,14 @@ sub add {
     } (@{ $form->{all_departments} });
   }
 
+  $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
+
   &display_form(1);
   $lxdebug->leave_sub();
 
 }
 
-sub edit {
+sub prepare_transaction {
   $lxdebug->enter_sub();
 
   GL->transaction(\%myconfig, \%$form);
@@ -178,15 +181,26 @@ 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->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
 
+  form_header();
+  display_rows();
+  form_footer();
+
+  $lxdebug->leave_sub();
 }
 
+
 sub search {
   $lxdebug->enter_sub();
 
@@ -227,7 +241,7 @@ sub search {
                          '-labels' => \%project_labels));
 
   # use JavaScript Calendar or not
-  $form->{jsscript} = $jscalendar;
+  $form->{jsscript} = 1;
   $jsscript = "";
   if ($form->{jsscript}) {
 
@@ -1045,6 +1059,7 @@ sub display_rows {
   my ($init) = @_;
   $lxdebug->enter_sub();
 
+  $form->{debit_1}     = 0 if !$form->{"debit_1"};
   $form->{totaldebit}  = 0;
   $form->{totalcredit} = 0;
 
@@ -1138,7 +1153,7 @@ sub display_rows {
 
     if ($init) {
       $korrektur =
-        qq|<td><input type="checkbox" name="korrektur_$i" value="1"</td>|;
+        qq|<td><input type="checkbox" name="korrektur_$i" value="1"></td>|;
       if ($form->{transfer}) {
         $fx_transaction = qq|
         <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
@@ -1204,20 +1219,27 @@ sub display_rows {
                            '-labels' => \%project_labels,
                            '-default' => $form->{"project_id_$i"} ));
 
+    my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
+
     print qq|<tr valign=top>
     $accno
     $fx_transaction
-    <td><input name="debit_$i" size=8 value="$form->{"debit_$i"}" accesskey=$i $debitreadonly></td>
+    <td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td>
     <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
     <td><input name="tax_$i" size=6 value="$form->{"tax_$i"}"></td>
     $korrektur
-    $tax
+    $tax|;
+
+    if ($form->{show_details}) {
+      print qq|
     $source
     $memo
     <td>$projectnumber</td>
+|;
+    }
+    print qq|
   </tr>
-
-  |;
+|;
   }
 
   $form->hide_form(qw(rowcount selectaccno));
@@ -1233,11 +1255,14 @@ sub form_header {
   $form->{title} = $locale->text("$title General Ledger Transaction");
   $readonly      = ($form->{id}) ? "readonly" : "";
 
+  $show_details_checked = "checked" if $form->{show_details};
+
   # $locale->text('Add General Ledger Transaction')
   # $locale->text('Edit General Ledger Transaction')
 
   map { $form->{$_} =~ s/\"/&quot;/g }
     qw(reference description chart taxchart);
+
   $form->{javascript} = qq|<script type="text/javascript">
   <!--
   function setTaxkey(accno, row) {
@@ -1255,8 +1280,15 @@ sub form_header {
       }
     }
   };
+
+  function copy_debit_to_credit() {
+    var txt = document.getElementsByName('debit_1')[0].value;
+    document.getElementsByName('credit_2')[0].value = txt;
+  };
+
   //-->
   </script>|;
+  $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
 
   $form->{selectdepartment} =~ s/ selected//;
   $form->{selectdepartment} =~
@@ -1290,7 +1322,7 @@ sub form_header {
   }
 
   # use JavaScript Calendar or not
-  $form->{jsscript} = $jscalendar;
+  $form->{jsscript} = 1;
   $jsscript = "";
   if ($form->{jsscript}) {
 
@@ -1311,17 +1343,20 @@ sub form_header {
       qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\"></td>|;
   }
 
+  $form->{previous_id}     ||= "--";
+  $form->{previous_gldate} ||= "--";
+
   $form->header;
 
   print qq|
 <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 previous_id previous_gldate));
 
-<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">
 
 
@@ -1333,6 +1368,14 @@ sub form_header {
   <tr>
     <td>
       <table width=100%>
+        <tr>
+          <td colspan="6" align="left">|
+    . $locale->text("Previous transnumber text")
+    . " $form->{previous_id} "
+    . $locale->text("Previous transdate text")
+    . " $form->{previous_gldate}"
+    . qq|</td>
+        </tr>
        <tr>
          <th align=right>| . $locale->text('Reference') . qq|</th>
          <td><input name=reference size=20 value="$form->{reference}" $readonly></td>
@@ -1399,6 +1442,12 @@ sub form_header {
         </td>
        </tr>|;
   }
+
+  print qq|<tr>
+       <td width="1%" align="right" nowrap>| . $locale->text('Show details') . qq|</td>
+       <td width="1%"><input type="checkbox" onclick="show_form_details();" name="show_details" value="1" $show_details_checked></td>
+      </tr>|;
+
   print qq|
       <tr>
       <td colspan=4>
@@ -1415,12 +1464,17 @@ sub form_header {
           <th class=listheading style="width:5%">|
     . $locale->text('Korrektur') . qq|</th>
           <th class=listheading style="width:10%">|
-    . $locale->text('Taxkey') . qq|</th>
-         <th class=listheading style="width:20%">|
-    . $locale->text('Source') . qq|</th>
+    . $locale->text('Taxkey') . qq|</th>|;
+
+  if ($form->{show_details}) {
+    print qq|
+         <th class=listheading style="width:20%">| . $locale->text('Source') . qq|</th>
          <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
-         <th class=listheading style="width:20%">|
-    . $locale->text('Project Number') . qq|</th>
+         <th class=listheading style="width:20%">| . $locale->text('Project Number') . qq|</th>
+|;
+  }
+
+  print qq|
        </tr>
 
 $jsscript
@@ -1466,8 +1520,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
 
@@ -1485,7 +1541,7 @@ sub form_footer {
     #  }
   } else {
     if ($transdate > $closedto) {
-      print qq|<input class=submit type=submit name=action value="|
+      print qq|<input class=submit type=submit name=action id=update_button value="|
         . $locale->text('Update') . qq|">
                 <input class=submit type=submit name=action value="|
         . $locale->text('Post') . qq|">|;
@@ -1556,6 +1612,8 @@ sub yes {
 sub post {
   $lxdebug->enter_sub();
 
+  $form->{title} = $locale->text("$form->{title} General Ledger Transaction");
+
   # check if there is something in reference and date
   $form->isblank("reference",   $locale->text('Reference missing!'));
   $form->isblank("transdate",   $locale->text('Transaction Date missing!'));
@@ -1575,19 +1633,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}) {
 
@@ -1741,7 +1786,10 @@ sub post {
        $form->save_history($form->dbconnect(\%myconfig));
   }
   # /saving the history 
-  $form->redirect("Buchung gespeichert. Buchungsnummer = " . $form->{id});
+
+  $form->{callback} = build_std_url("action=add", "show_details");
+  $form->redirect($form->{callback});
+
   $lxdebug->leave_sub();
 
 }
@@ -1758,8 +1806,47 @@ 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->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
@@ -1767,7 +1854,7 @@ sub storno {
        $form->save_history($form->dbconnect(\%myconfig));
   }
   # /saving the history 
-  &post;
+
   $lxdebug->leave_sub();
 
 }