Projektauswahl in Debitoren- und Kreditorenbuchungen per Drop-Down-Box. Bei der Buchu...
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 20 Feb 2007 09:11:11 +0000 (09:11 +0000)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 20 Feb 2007 09:11:11 +0000 (09:11 +0000)
SL/AP.pm
SL/AR.pm
bin/mozilla/ap.pl
bin/mozilla/ar.pl

index f20d61a..3522e62 100644 (file)
--- a/SL/AP.pm
+++ b/SL/AP.pm
@@ -222,14 +222,8 @@ sub post_transaction {
   for $i (1 .. $form->{rowcount}) {
     if ($form->{"amount_$i"} != 0) {
       my $project_id;
-      if ("amount_$i" =~ /amount_/) {
-        if ($form->{"project_id_$i"} && $form->{"projectnumber_$i"}) {
-          $project_id = $form->{"project_id_$i"};
-        }
-      }
-      if ("amount_$i" =~ /amount/) {
-        $taxkey = $form->{AP_amounts}{"amount_$i"}{taxkey};
-      }
+      $project_id = conv_i($form->{"project_id_$i"});
+      $taxkey = $form->{AP_amounts}{"amount_$i"}{taxkey};
 
       # insert detail records in acc_trans
       $query =
@@ -239,7 +233,7 @@ sub post_transaction {
         qq|  ?, ?, ?, ?)|;
       @values = ($form->{id}, $form->{AP_amounts}{"amount_$i"},
                  $form->{"amount_$i"}, conv_date($form->{transdate}),
-                 conv_i($project_id), $taxkey);
+                 $project_id, $taxkey);
       do_query($form, $dbh, $query, @values);
 
       if ($form->{"tax_$i"} != 0) {
@@ -251,7 +245,7 @@ sub post_transaction {
           qq|  ?, ?, ?, ?)|;
         @values = ($form->{id}, $form->{AP_amounts}{"tax_$i"},
                    $form->{"tax_$i"}, conv_date($form->{transdate}),
-                   conv_date($project_id), $taxkey);
+                   $project_id, $taxkey);
         do_query($form, $dbh, $query, @values);
       }
 
@@ -260,11 +254,10 @@ sub post_transaction {
 
   # add payables
   $query =
-    qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id) | .
-    qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | .
-    qq|  ?, ?, ?)|;
+    qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate) | .
+    qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?)|;
   @values = ($form->{id}, $form->{AP_amounts}{payables}, $form->{payables},
-             conv_date($form->{transdate}), conv_i($project_id));
+             conv_date($form->{transdate}));
   do_query($form, $dbh, $query, @values);
 
   # if there is no amount but a payment record a payable
index a38259a..22ed409 100644 (file)
--- a/SL/AR.pm
+++ b/SL/AR.pm
@@ -35,6 +35,7 @@
 package AR;
 
 use Data::Dumper;
+use SL::DBUtils;
 
 sub post_transaction {
   $main::lxdebug->enter_sub();
@@ -45,6 +46,8 @@ sub post_transaction {
   my $exchangerate = 0;
   my $i;
 
+  my @values;
+
   my $dbh = $form->dbconnect_noauto($myconfig);
 
   if ($form->{currency} eq $form->{defaultcurrency}) {
@@ -226,43 +229,38 @@ sub post_transaction {
   # add individual transactions for AR, amount and taxes
   for $i (1 .. $form->{rowcount}) {
     if ($form->{"amount_$i"} != 0) {
-      $project_id = 'NULL';
-      if ("amount_$i" =~ /amount_/) {
-        if ($form->{"project_id_$i"} && $form->{"projectnumber_$i"}) {
-          $project_id = $form->{"project_id_$i"};
-        }
-      }
-      if ("amount_$i" =~ /amount/) {
-        $taxkey = $form->{AR_amounts}{"amount_$i"}{taxkey};
-      }
+      my $project_id = undef;
+      $project_id = conv_i($form->{"project_id_$i"});
+      $taxkey = $form->{AR_amounts}{"amount_$i"}{taxkey};
 
+      @values = ($project_id);
       # insert detail records in acc_trans
       $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
                                          project_id, taxkey)
                  VALUES ($form->{id}, (SELECT c.id FROM chart c
                                        WHERE c.accno = '$form->{AR_amounts}{"amount_$i"}'),
-                 $form->{"amount_$i"}, '$form->{transdate}', $project_id, '$taxkey')|;
-      $dbh->do($query) || $form->dberror($query);
+                 $form->{"amount_$i"}, '$form->{transdate}', ?, '$taxkey')|;
+      do_query($form, $dbh, $query, @values);
       if ($form->{"tax_$i"} != 0) {
 
+        @values = ($project_id);
         # insert detail records in acc_trans
         $query =
           qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
                                           project_id, taxkey)
                     VALUES ($form->{id}, (SELECT c.id FROM chart c
                                           WHERE c.accno = '$form->{AR_amounts}{"tax_$i"}'),
-                    $form->{"tax_$i"}, '$form->{transdate}', $project_id, '$taxkey')|;
-        $dbh->do($query) || $form->dberror($query);
+                    $form->{"tax_$i"}, '$form->{transdate}', ?, '$taxkey')|;
+        do_query($form, $dbh, $query, @values);
       }
     }
   }
 
   # add recievables
-  $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
-                                      project_id)
+  $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate)
               VALUES ($form->{id}, (SELECT c.id FROM chart c
                                     WHERE c.accno = '$form->{AR_amounts}{receivables}'),
-              $form->{receivables}, '$form->{transdate}', $project_id)|;
+              $form->{receivables}, '$form->{transdate}')|;
   $dbh->do($query) || $form->dberror($query);
 
   # add paid transactions
index 34b285d..0d531cf 100644 (file)
@@ -397,6 +397,21 @@ sub form_header {
     ? qq|<select name=vendor>$form->{selectvendor}</select>|
     : qq|<input name=vendor value="$form->{vendor}" size=35>|;
 
+  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"};
+  }
+
   # use JavaScript Calendar or not
   $form->{jsscript} = $jscalendar;
   $jsscript = "";
@@ -558,6 +573,12 @@ $jsscript
 
     my $korrektur = $form->{"korrektur_$i"} ? 'checked' : '';
 
+    my $projectnumber =
+      NTI($cgi->popup_menu('-name' => "project_id_$i",
+                           '-values' => \@project_values,
+                           '-labels' => \%project_labels,
+                           '-default' => $form->{"project_id_$i"} ));
+
     print qq|
        <tr>
           <td width=50%><select name="AP_amount_$i" onChange="setTaxkey(this, $i)" style="width:100%">$selectAP_amount</select></td>
@@ -565,9 +586,7 @@ $jsscript
           <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
           <td><input type="checkbox" name="korrektur_$i" value="1" "$korrektur"></td>
           $tax
-         <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}">
-             <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
-             <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
+          <td>$projectnumber</td>
        </tr>
 |;
     $amount  = "";
@@ -843,7 +862,6 @@ sub update {
   &check_name(vendor);
   $form->{AP} = $save_AP;
 
-  &check_project;
   $form->{rowcount} = $count + 1;
 
   $form->{invtotal} =
index 291ad06..9ca39fd 100644 (file)
@@ -421,6 +421,21 @@ sub form_header {
 |;
   }
 
+  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"};
+  }
+
   $form->{fokus} = "arledger.customer";
 
   # use JavaScript Calendar or not
@@ -582,6 +597,12 @@ $jsscript
       qq|<td><select id="taxchart_$i" name="taxchart_$i" style="width:200px">$tax</select></td>|;
     $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : '');
 
+    my $projectnumber =
+      NTI($cgi->popup_menu('-name' => "project_id_$i",
+                           '-values' => \@project_values,
+                           '-labels' => \%project_labels,
+                           '-default' => $form->{"project_id_$i"} ));
+
     print qq|
        <tr>
           <td width=50%><select name="AR_amount_$i" onChange="setTaxkey(this, $i)" style="width:100%">$selectAR_amount</select></td>
@@ -589,9 +610,7 @@ $jsscript
           <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
           <td><input type="checkbox" name="korrektur_$i" value="1" $korrektur_checked></td>
           $tax
-         <td><input name="projectnumber_$i" size=20 value="$form->{"projectnumber_$i"}">
-             <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
-             <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
+          <td>$projectnumber</td>
        </tr>
 |;
     $amount  = "";
@@ -870,8 +889,6 @@ sub update {
   &check_name(customer);
   $form->{AR} = $save_AR;
 
-  &check_project;
-
   $form->{invtotal} =
     ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;