Zahlungen bei Kreditorenbuchungen nur am selben Tag löschbar machen.
authorBernd Blessmann <bibi@online.de>
Thu, 25 Aug 2011 08:17:44 +0000 (10:17 +0200)
committerBernd Blessmann <bibi@online.de>
Thu, 25 Aug 2011 08:17:44 +0000 (10:17 +0200)
Siehe auch Bug 1640. Ändert zwar nichts am Bug, steht da aber als
Anregung drin.

SL/AP.pm
SL/Form.pm
bin/mozilla/ap.pl

index d90a53f..79a93fe 100644 (file)
--- a/SL/AP.pm
+++ b/SL/AP.pm
@@ -288,12 +288,13 @@ sub post_transaction {
       $form->{payables} = $amount;
 
       # add payment
+      my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->{"gldate"});
       $query =
-        qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, source, memo, project_id, taxkey) | .
-        qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, | .
+        qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey) | .
+        qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, | .
         qq|        (SELECT taxkey_id FROM chart WHERE accno = ?))|;
       @values = ($form->{id}, $form->{"AP_paid_account_$i"}, $form->{"paid_$i"},
-                 conv_date($form->{"datepaid_$i"}), $form->{"source_$i"},
+                 conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"},
                  $form->{"memo_$i"}, $project_id, $form->{"AP_paid_account_$i"});
       do_query($form, $dbh, $query, @values);
 
@@ -568,7 +569,7 @@ sub post_payment {
   $self->_delete_payments($form, $dbh);
 
   # Save the new payments the user made before cleaning up $form.
-  my $payments_re = '^datepaid_\d+$|^memo_\d+$|^source_\d+$|^exchangerate_\d+$|^paid_\d+$|^paid_project_id_\d+$|^AP_paid_\d+$|^paidaccounts$';
+  my $payments_re = '^datepaid_\d+$|^gldate_\d+$|^memo_\d+$|^source_\d+$|^exchangerate_\d+$|^paid_\d+$|^paid_project_id_\d+$|^AP_paid_\d+$|^paidaccounts$';
   map { $payments{$_} = $form->{$_} } grep m/$payments_re/, keys %{ $form };
 
   # Clean up $form so that old content won't tamper the results.
@@ -649,6 +650,7 @@ sub setup_form {
         $form->{"AP_paid_$j"}         = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
         $form->{"paid_$j"}            = $form->{acc_trans}{$key}->[$i - 1]->{amount};
         $form->{"datepaid_$j"}        = $form->{acc_trans}{$key}->[$i - 1]->{transdate};
+        $form->{"gldate_$j"}          = $form->{acc_trans}{$key}->[$i - 1]->{gldate};
         $form->{"source_$j"}          = $form->{acc_trans}{$key}->[$i - 1]->{source};
         $form->{"memo_$j"}            = $form->{acc_trans}{$key}->[$i - 1]->{memo};
 
index 418d3cf..14e3ed2 100644 (file)
@@ -2986,7 +2986,7 @@ sub create_links {
     $query =
       qq|SELECT
            c.accno, c.description,
-           a.source, a.amount, a.memo, a.transdate, a.cleared, a.project_id, a.taxkey,
+           a.source, a.amount, a.memo, a.transdate, a.gldate, a.cleared, a.project_id, a.taxkey,
            p.projectnumber,
            t.rate, t.id
          FROM acc_trans a
index f19363d..d90b062 100644 (file)
@@ -692,14 +692,24 @@ $jsscript
       $form->{"exchangerate_$i"} = "";
     }
 
+    print qq|<input type=hidden name="gldate_$i" value=$form->{"gldate_$i"}>\n|;
+    my $changeable = (($form->{"gldate_$i"} eq '') || $form->current_date(\%myconfig) eq $form->{"gldate_$i"});
+    $form->{"payment_readonly_$i"} = ($changeable)? 0 : 1;
+    print qq|<input type=hidden name="payment_readonly_$i" value=$form->{"payment_readonly_$i"}>\n|;
+
     $exchangerate = qq|&nbsp;|;
     if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
       if ($form->{"forex_$i"}) {
         $exchangerate =
           qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
       } else {
-        $exchangerate =
-          qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
+        if ($changeable) {
+          $exchangerate =
+            qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
+        } else {
+          $exchangerate = qq|$form->{"exchangerate_$i"}|.
+            qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
+        }
       }
     }
 
@@ -707,32 +717,78 @@ $jsscript
 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
 |;
 
-    $column_data{"paid_$i"} =
-      qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
-    $column_data{"AP_paid_$i"} =
-      qq|<td align=center>${selectAP_paid}</td>|;
-    $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
-    $column_data{"datepaid_$i"}     =
-      qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="($myconfig{'dateformat'})" value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
+    my $datepaid;
+    if ($changeable) {
+      $datepaid = qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="($myconfig{'dateformat'})" value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
          <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="| . $locale->text('Details (one letter abbreviation)') . qq|"></td>|;
-    $column_data{"source_$i"} =
-      qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
-    $column_data{"memo_$i"} =
-      qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
-    $column_data{"paid_project_id_$i"} =
+    } else {
+      $datepaid = qq|<td align=center>$form->{"datepaid_$i"}</td>|.
+        qq|<input type=hidden name="datepaid_$i" value=$form->{"datepaid_$i"}>|;
+    }
+
+    my $paid;
+    if ($changeable) {
+      $paid = qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
+    } else {
+      $paid = qq|<td align=center>$form->{"paid_$i"}</td>|.
+        qq|<input type=hidden name="paid_$i" value=$form->{"paid_$i"}>|;
+    }
+
+    my $source;
+    if ($changeable) {
+      $source = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
+    } else {
+      $source = qq|<td align=center>$form->{"source_$i"}</td>|.
+        qq|<input type=hidden name="source_$i" value=$form->{"source_$i"}>|;
+    }
+
+    my $memo;
+    if ($changeable) {
+      $memo = qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
+    } else {
+      $memo = qq|<td align=center>$form->{"memo_$i"}</td>|.
+        qq|<input type=hidden name="memo_$i" value=$form->{"memo_$i"}>|;
+    }
+
+    my $AP_paid;
+    if ($changeable) {
+      $AP_paid = qq|<td align=center>${selectAP_paid}</td>|;
+    } else {
+      $AP_paid = qq|<td align=center>$form->{"AP_paid_$i"}</td>|.
+        qq|<input type=hidden name="AP_paid_$i" value=$form->{"AP_paid_$i"}>|;
+    }
+
+    my $paid_project_id;
+    if ($changeable) {
+      $paid_project_id =
       qq|<td>|
       . NTI($cgi->popup_menu('-name' => "paid_project_id_$i",
                              '-values' => \@project_values,
                              '-labels' => \%project_labels,
                              '-default' => $form->{"paid_project_id_$i"} ))
       . qq|</td>|;
+    } else {
+      my $projectnumber = $project_labels{$form->{"paid_project_id_$i"}};
+      $paid_project_id = qq|<td>$projectnumber</td>|.
+        qq|<input type=hidden name="paid_project_id_$i" value=$form->{"paid_project_id_$i"}>|;
+    }
+
+    $column_data{"paid_$i"} = $paid;
+    $column_data{"AP_paid_$i"} = $AP_paid;
+    $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
+    $column_data{"datepaid_$i"}  = $datepaid;
+    $column_data{"source_$i"} = $source;
+    $column_data{"memo_$i"} = $memo;
+    $column_data{"paid_project_id_$i"} = $paid_project_id;
 
     map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
 
     print "
         </tr>
 ";
-    push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
+    if ($changeable) {
+      push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
+    }
   }
 
   my $paid_missing = $form->{invtotal_unformatted} - $form->{totalpaid};
@@ -1126,7 +1182,7 @@ sub use_as_template {
 
   $main::auth->assert('general_ledger');
 
-  map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
+  map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 gldate_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
   $form->{paidaccounts} = 1;
   $form->{rowcount}--;
   $form->{invdate} = $form->current_date(\%myconfig);