show_history.js in header eingebunden
[kivitendo-erp.git] / bin / mozilla / gl.pl
index 4491206..5154a3f 100644 (file)
@@ -81,24 +81,14 @@ sub add {
   # we use this only to set a default date
   GL->transaction(\%myconfig, \%$form);
 
-  map {
-    $chart .=
-      "<option value=\"$_->{accno}--$_->{tax_id}\">$_->{accno}--$_->{description}</option>"
-  } @{ $form->{chart} };
   map {
     $tax .=
       qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription}  |
       . ($_->{rate} * 100) . qq| %|
   } @{ $form->{TAX} };
 
-  $form->{chart}     = $chart;
-  $form->{chartinit} = $chart;
   $form->{rowcount}  = 2;
 
-  $form->{debitchart}  = $chart;
-  $form->{creditchart} = $chart;
-  $form->{taxchart}    = $tax;
-
   $form->{debit}  = 0;
   $form->{credit} = 0;
   $form->{tax}    = 0;
@@ -123,10 +113,6 @@ sub edit {
   $lxdebug->enter_sub();
 
   GL->transaction(\%myconfig, \%$form);
-  map {
-    $chart .=
-      "<option value=\"$_->{accno}--$_->{tax_id}\">$_->{accno}--$_->{description}</option>"
-  } @{ $form->{chart} };
 
   map {
     $tax .=
@@ -134,10 +120,6 @@ sub edit {
       . ($_->{rate} * 100) . qq| %|
   } @{ $form->{TAX} };
 
-  $form->{chart} = $chart;
-
-  $form->{taxchart} = $tax;
-
   $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
 
   # departments
@@ -166,6 +148,8 @@ sub edit {
           $form->{"credit_$j"} += $form->{"tax_$j"};
         }
       }
+      $form->{"project_id_$j"} = $ref->{project_id};
+
     } else {
       $form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
       for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
@@ -177,6 +161,7 @@ sub edit {
         $form->{"credit_$i"} = $ref->{amount};
       }
       $form->{"taxchart_$i"} = "0--0.00";
+      $form->{"project_id_$i"} = $ref->{project_id};
       $i++;
     }
     if ($ref->{taxaccno} && !$tax) {
@@ -186,7 +171,6 @@ sub edit {
       $taxaccno = "";
       $tax      = 0;
     }
-
   }
 
   $form->{rowcount} = $i;
@@ -494,10 +478,14 @@ sub generate_report {
       . $locale->date(\%myconfig, $form->{dateto}, 1);
   }
 
-  @columns =
-    qw(transdate id reference description notes source debit debit_accno credit
-       credit_accno debit_tax debit_tax_accno credit_tax credit_tax_accno accno
-       gifi_accno projectnumbers);
+  @columns = $form->sort_columns( qw(
+       transdate       id                reference         description  
+       notes           source            debit             debit_accno  
+       credit          credit_accno      debit_tax         debit_tax_accno
+       credit_tax      credit_tax_accno  accno             gifi_accno
+       projectnumbers  
+       )
+  );
 
   if ($form->{accno} || $form->{gifi_accno}) {
     @columns = grep !/(accno|gifi_accno)/, @columns;
@@ -833,6 +821,12 @@ sub generate_report {
 
   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
 
+  my $balanced_ledger = $totaldebit 
+                      + $totaldebittax 
+                      - $totalcredit 
+                      - $totalcredittax;
+                    # = 0 for balanced ledger
+                    
   $column_data{debit} =
     "<th align=right class=listtotal>"
     . $form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;") . "</th>";
@@ -857,6 +851,27 @@ sub generate_report {
 
   print qq|
         </tr>
+        <tr>|;
+
+
+  if ( abs($balanced_ledger) >  0.001 ) {
+
+    print qq|<td colspan="4" style="background-color:#FFA0A0" >|
+        . $locale->text('Unbalanced Ledger') 
+        . ": " 
+        . $form->format_amount(\%myconfig, $balanced_ledger, 3, "&nbsp;")
+
+  } elsif ( abs($balanced_ledger) <= 0.001 ) {
+
+    print qq|<td colspan="3">|
+          . $locale->text('Balanced Ledger') 
+
+  }
+
+  
+  print qq|
+         </td>
+        </tr>
         </tbody>
       </table>
     </td>
@@ -1050,10 +1065,6 @@ sub display_rows {
 
   $form->{totaldebit}  = 0;
   $form->{totalcredit} = 0;
-  my $chart = $form->{chart};
-  $chart            = $form->unquote($chart);
-  $form->{taxchart} = $form->unquote($form->{taxchart});
-  $taxchart         = $form->{taxchart};
 
   my @old_project_ids = ();
   map({ push(@old_project_ids, $form->{"project_id_$_"})
@@ -1061,7 +1072,10 @@ sub display_rows {
 
   $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
                                    "all" => 0,
-                                   "old_id" => \@old_project_ids });
+                                   "old_id" => \@old_project_ids },
+                   "charts" => { "key" => "ALL_CHARTS",
+                                 "transdate" => $form->{transdate} },
+                   "taxcharts" => "ALL_TAXCHARTS");
 
   my %project_labels = ();
   my @project_values = ("");
@@ -1070,6 +1084,26 @@ sub display_rows {
     $project_labels{$item->{"id"}} = $item->{"projectnumber"};
   }
 
+  my %chart_labels = ();
+  my @chart_values = ();
+  my $taxchart_init;
+  foreach my $item (@{ $form->{ALL_CHARTS} }) {
+    my $key = Q($item->{accno}) . "--" . Q($item->{tax_id});
+    $taxchart_init = $item->{taxkey_id} unless (@chart_values);
+    push(@chart_values, $key);
+    $chart_labels{$key} = H($item->{accno}) . "--" . H($item->{description});
+  }
+
+  my %taxchart_labels = ();
+  my @taxchart_values = ();
+  foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
+    my $key = Q($item->{id}) . "--" . Q($item->{rate});
+    $taxchart_init = $key if ($taxchart_init eq $item->{taxkey});
+    push(@taxchart_values, $key);
+    $taxchart_labels{$key} = H($item->{taxdescription}) . " " .
+      H($item->{rate} * 100) . ' %';
+  }
+
   for $i (1 .. $form->{rowcount}) {
 
     $source = qq|
@@ -1079,15 +1113,25 @@ sub display_rows {
     <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16" tabindex=|
       . ($i + 12 + (($i - 1) * 8)) . qq|></td>|;
 
-    if ($init) {
-      $accno = qq|
-      <td><select name="accno_$i" onChange="setTaxkey(this, $i)" style="width:200px" tabindex=|
-        . ($i + 5 + (($i - 1) * 8)) . qq|>$form->{chartinit}</select></td>|;
-      $tax =
-        qq|<td><select id="taxchart_$i" name="taxchart_$i" style="width:200px" tabindex=|
-        . ($i + 10 + (($i - 1) * 8))
-        . qq|>$form->{taxchart}</select></td>|;
+    $accno = qq|<td>| .
+      $cgi->popup_menu('-name' => "accno_$i",
+                       '-onChange' => "setTaxkey(this, $i)",
+                       '-style' => 'width:200px',
+                       '-tabindex' => ($i + 5 + (($i - 1) * 8)),
+                       '-values' => \@chart_values,
+                       '-labels' => \%chart_labels,
+                       '-default' => $init ? '' : $form->{"accno_$i"})
+      . qq|</td>|;
+    $tax = qq|<td>| .
+      $cgi->popup_menu('-name' => "taxchart_$i",
+                       '-style' => 'width:200px',
+                       '-tabindex' => ($i + 10 + (($i - 1) * 8)),
+                       '-values' => \@taxchart_values,
+                       '-labels' => \%taxchart_labels,
+                       '-default' => $init ? $taxchart_init : $form->{"taxchart_$i"})
+      . qq|</td>|;
 
+    if ($init) {
       $korrektur =
         qq|<td><input type="checkbox" name="korrektur_$i" value="1" tabindex=|
         . ($i + 9 + (($i - 1) * 8))
@@ -1119,23 +1163,6 @@ sub display_rows {
       }
 
       if ($i < $form->{rowcount}) {
-
-        $accno          = $chart;
-        $chart_selected = $form->{"accno_$i"};
-        $accno =~
-          s/value=\"$chart_selected\"/value=\"$chart_selected\" selected/;
-        $accno =
-          qq|<td><select name="accno_$i" onChange="setTaxkey(this, $i)" style="width:200px" tabindex=|
-          . ($i + 5 + (($i - 1) * 8))
-          . qq|>$accno</select></td>|;
-        $tax          = $taxchart;
-        $tax_selected = $form->{"taxchart_$i"};
-        $tax =~ s/value=\"$tax_selected\"/value=\"$tax_selected\" selected/;
-        $tax =
-            qq|<td><select id="taxchart_$i" name="taxchart_$i" tabindex=|
-          . ($i + 10 + (($i - 1) * 8))
-          . qq|>$tax</select></td>|;
-
         if ($form->{transfer}) {
           $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
           $x = ($checked) ? "x" : "";
@@ -1151,14 +1178,6 @@ sub display_rows {
         $form->hide_form("accno_$i");
 
       } else {
-
-        $accno = qq|
-      <td><select name="accno_$i" onChange="setTaxkey(this, $i)" style="width:300px" tabindex=|
-          . ($i + 5 + (($i - 1) * 8)) . qq|>$chart</select></td>|;
-        $tax = qq|
-      <td><select id="taxchart_$i" name="taxchart_$i" tabindex=|
-          . ($i + 10 + (($i - 1) * 8)) . qq|>$taxchart</select></td>|;
-
         $korrektur =
           qq|<td><input type="checkbox" name="korrektur_$i" value="1" tabindex=|
           . ($i + 9 + (($i - 1) * 8))
@@ -1308,8 +1327,6 @@ sub form_header {
 <input type=hidden name=closedto value=$form->{closedto}>
 <input type=hidden name=locked value=$form->{locked}>
 <input type=hidden name=title value="$title">
-<input type=hidden name=taxchart value="$form->{taxchart}">
-<input type=hidden name=chart value="$form->{chart}">
 
 
 <table width=100%>
@@ -1501,7 +1518,7 @@ sub delete {
 <form method=post action=$form->{script}>
 |;
 
-  map { $form->{$_} =~ s/\"/&quot;/g } qw(reference description chart taxchart);
+  map { $form->{$_} =~ s/\"/&quot;/g } qw(reference description);
 
   delete $form->{header};