Dialogbuchen: Anzeigen und Speichern von Projektnummern für jede Zeile.
[kivitendo-erp.git] / bin / mozilla / gl.pl
index 2668083..89febc2 100644 (file)
@@ -35,6 +35,7 @@ use SL::GL;
 use SL::PE;
 
 require "$form->{path}/arap.pl";
+require "bin/mozilla/common.pl";
 
 1;
 
@@ -154,8 +155,6 @@ sub edit {
   my $tax      = 0;
   my $taxaccno = "";
   foreach $ref (@{ $form->{GL} }) {
-    $form->{"projectnumber_$i"} = "$ref->{projectnumber}--$ref->{project_id}";
-
     $j = $i - 1;
     if ($tax && ($ref->{accno} eq $taxaccno)) {
       $form->{"tax_$j"}      = abs($ref->{amount});
@@ -750,16 +749,23 @@ sub generate_report {
       }
     }
 
+    $transdate = "";
+    foreach $key (sort keys(%{ $ref->{transdate} })) {
+      if ($key == 0) {
+        $transdate = "$ref->{transdate}{$key}";
+      } else {
+        $transdate .= "<br>$ref->{transdate}{$key}";
+      }
+    }
+
     #    $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
     #    $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
 
     $column_data{id}        = "<td align=right>&nbsp;$ref->{id}&nbsp;</td>";
-    $column_data{transdate} =
-      "<td align=center>&nbsp;$ref->{transdate}&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>";
-    $column_data{description} =
-      "<td align=center>$ref->{description}&nbsp;</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>";
     $column_data{debit}        = "<td align=right>$debit</td>";
@@ -849,14 +855,7 @@ sub generate_report {
 <input class=submit type=submit name=action value="|
     . $locale->text('Sales Invoice') . qq|">
 <input class=submit type=submit name=action value="|
-    . $locale->text('Vendor Invoice') . qq|">|;
-
-  if ($form->{menubar}) {
-    require "$form->{path}/menu.pl";
-    &menubar;
-  }
-
-  print qq|
+    . $locale->text('Vendor Invoice') . qq|">
 
 </form>
 
@@ -895,21 +894,7 @@ sub gl_subtotal {
 sub update {
   $lxdebug->enter_sub();
 
-  if ($form->{transdate} ne $form->{oldtransdate}) {
-    if ($form->{selectprojectnumber}) {
-      $form->all_projects(\%myconfig, undef, $form->{transdate});
-      if (@{ $form->{all_project} }) {
-        $form->{selectprojectnumber} = "<option>\n";
-        for (@{ $form->{all_project} }) {
-          $form->{selectprojectnumber} .=
-            qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
-        }
-        $form->{selectprojectnumber} =
-          $form->escape($form->{selectprojectnumber}, 1);
-      }
-    }
-    $form->{oldtransdate} = $form->{transdate};
-  }
+  $form->{oldtransdate} = $form->{transdate};
 
   my @a           = ();
   my $count       = 0;
@@ -1033,15 +1018,28 @@ sub display_rows {
   my ($init) = @_;
   $lxdebug->enter_sub();
 
-  $form->{selectprojectnumber} = $form->unescape($form->{selectprojectnumber})
-    if $form->{selectprojectnumber};
-
   $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_$_"})
+          if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
+
+  $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
+                                   "all" => 0,
+                                   "old_id" => \@old_project_ids });
+
+  my %project_labels = ();
+  my @project_values = ("");
+  foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
+    push(@project_values, $item->{"id"});
+    $project_labels{$item->{"id"}} = $item->{"projectnumber"};
+  }
+
   for $i (1 .. $form->{rowcount}) {
 
     $source = qq|
@@ -1060,10 +1058,6 @@ sub display_rows {
         . ($i + 10 + (($i - 1) * 8))
         . qq|>$form->{taxchart}</select></td>|;
 
-      #       if ($form->{selectprojectnumber}) {
-      #         $project = qq|
-      #     <td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
-      #       }
       $korrektur =
         qq|<td><input type="checkbox" name="korrektur_$i" value="1" tabindex=|
         . ($i + 9 + (($i - 1) * 8))
@@ -1106,22 +1100,12 @@ sub display_rows {
           . qq|>$accno</select></td>|;
         $tax          = $taxchart;
         $tax_selected = $form->{"taxchart_$i"};
-        print(STDERR "TAX_SELCTED $tax_selected\n");
         $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->{selectprojectnumber}) {
-        #           $form->{"projectnumber_$i"} = ""
-        #             if $form->{selectprojectnumber} !~ /$form->{"projectnumber_$i"}/;
-        #
-        #           $project = $form->{"projectnumber_$i"};
-        #           $project =~ s/--.*//;
-        #           $project = qq|<td>$project</td>|;
-        #         }
-
         if ($form->{transfer}) {
           $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
           $x = ($checked) ? "x" : "";
@@ -1145,10 +1129,6 @@ sub display_rows {
       <td><select id="taxchart_$i" name="taxchart_$i" tabindex=|
           . ($i + 10 + (($i - 1) * 8)) . qq|>$taxchart</select></td>|;
 
-        #         if ($form->{selectprojectnumber}) {
-        #           $project = qq|
-        #       <td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>|;
-        #         }
         $korrektur =
           qq|<td><input type="checkbox" name="korrektur_$i" value="1" tabindex=|
           . ($i + 9 + (($i - 1) * 8))
@@ -1170,6 +1150,12 @@ sub display_rows {
       }
     }
 
+    my $projectnumber =
+      NTI($cgi->popup_menu('-name' => "project_id_$i",
+                           '-values' => \@project_values,
+                           '-labels' => \%project_labels,
+                           '-default' => $form->{"project_id_$i"} ));
+
     print qq|<tr valign=top>
     $accno
     $fx_transaction
@@ -1183,6 +1169,7 @@ sub display_rows {
     $tax
     $source
     $memo
+    <td>$projectnumber</td>
   </tr>
 
   |;
@@ -1190,9 +1177,6 @@ sub display_rows {
 
   $form->hide_form(qw(rowcount selectaccno));
 
-  #   print qq|
-  # <input type=hidden name=selectprojectnumber value="|
-  #     . $form->escape($form->{selectprojectnumber}, 1) . qq|">|;
   $lxdebug->leave_sub();
 
 }
@@ -1392,7 +1376,8 @@ sub form_header {
          <th class=listheading style="width:20%">|
     . $locale->text('Source') . qq|</th>
          <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
-         $project
+         <th class=listheading style="width:20%">|
+    . $locale->text('Project Number') . qq|</th>
        </tr>
 
 $jsscript
@@ -1418,7 +1403,7 @@ sub form_footer {
     <td></td>
     <th align=right class=listtotal> $form->{totaldebit}</th>
     <th align=right class=listtotal> $form->{totalcredit}</th> 
-    <td colspan=5></td>
+    <td colspan=6></td>
     </tr>
   </table>
   </td>
@@ -1465,11 +1450,6 @@ sub form_footer {
     }
   }
 
-  if ($form->{menubar}) {
-    require "$form->{path}/menu.pl";
-    &menubar;
-  }
-
   print "
   </form>
 
@@ -1535,9 +1515,6 @@ sub post {
   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
   $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
-  # check project
-  &check_project;
-
   my @a           = ();
   my $count       = 0;
   my $debittax    = 0;
@@ -1693,6 +1670,11 @@ sub post {
   if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
     $form->error($locale->text('Out of balance transaction!'));
   }
+  
+  if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
+    $form->error($locale->text('Empty transaction!'));
+  }
+  
   if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
     $errno *= -1;
     $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');