Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 08e42c5d

Von Moritz Bunkus vor mehr als 6 Jahren hinzugefügt

  • ID 08e42c5d48a0c2b27b6f12e75548c8f266e9b0c8
  • Vorgänger 2d4626f9
  • Nachfolger 2d15e56a

Kreditorenbuchungen: Flag »cleared« beim Zahlungsbuchen beibehalten

Existierende Zahlungen werden aus acc_trans komplett gelöscht und neu
eingefügt. Dabei geht der Status des Flags »cleared« verloren, der
anzeigt, dass eine Zahlung mit dem Konto abgeglichen wurde.

Das Flag einer Zahlung wird nun beibehalten, sofern:

• die Zahlung bereits vorher existiert hat (Präsenz der
`acc_trans_id`)
• Wert und Konto gleich geblieben sind

Unterschiede anzeigen:

SL/AP.pm
48 48
use strict;
49 49

  
50 50
sub post_transaction {
51
  my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_;
51
  my ($self, $myconfig, $form, $provided_dbh, %params) = @_;
52 52
  $main::lxdebug->enter_sub();
53 53

  
54
  my $rc = SL::DB->client->with_transaction(\&_post_transaction, $self, $myconfig, $form, $provided_dbh, $payments_only);
54
  my $rc = SL::DB->client->with_transaction(\&_post_transaction, $self, $myconfig, $form, $provided_dbh, %params);
55 55

  
56 56
  $::lxdebug->leave_sub;
57 57
  return $rc;
58 58
}
59 59

  
60 60
sub _post_transaction {
61
  my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_;
61
  my ($self, $myconfig, $form, $provided_dbh, %params) = @_;
62

  
63
  my $payments_only = $params{payments_only};
62 64
  my $dbh = $provided_dbh || SL::DB->client->dbh;
63 65

  
64 66
  my ($null, $taxrate, $amount);
......
210 212
    $form->{payables} = $form->{invpaid};
211 213
  }
212 214

  
215
  my %already_cleared = %{ $params{already_cleared} // {} };
216

  
213 217
  # add paid transactions
214 218
  for my $i (1 .. $form->{paidaccounts}) {
215 219

  
......
243 247
      $amount =
244 248
        $form->round_amount($form->{"paid_$i"} * $form->{exchangerate} * -1,
245 249
                            2);
250

  
251
      my $new_cleared = !$form->{"acc_trans_id_$i"}                                                             ? 'f'
252
                      : !$already_cleared{$form->{"acc_trans_id_$i"}}                                           ? 'f'
253
                      : $already_cleared{$form->{"acc_trans_id_$i"}}->{amount} != $amount * -1                  ? 'f'
254
                      : $already_cleared{$form->{"acc_trans_id_$i"}}->{accno}  != $form->{"AP_paid_account_$i"} ? 'f'
255
                      : $already_cleared{$form->{"acc_trans_id_$i"}}->{cleared}                                 ? 't'
256
                      :                                                                                           'f';
257

  
246 258
      if ($form->{payables}) {
247 259
        $query =
248
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id, chart_link) | .
249
          qq|VALUES (?, ?, ?, ?, ?, | .
260
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, cleared, taxkey, tax_id, chart_link) | .
261
          qq|VALUES (?, ?, ?, ?, ?, ?, | .
250 262
          qq|        (SELECT taxkey_id FROM chart WHERE id = ?),| .
251 263
          qq|        (SELECT tax_id| .
252 264
          qq|         FROM taxkeys| .
......
255 267
          qq|         ORDER BY startdate DESC LIMIT 1),| .
256 268
          qq|        (SELECT c.link FROM chart c WHERE c.id = ?))|;
257 269
        @values = ($form->{id}, $form->{AP_chart_id}, $amount,
258
                   conv_date($form->{"datepaid_$i"}), $project_id,
270
                   conv_date($form->{"datepaid_$i"}), $project_id, $new_cleared,
259 271
                   $form->{AP_chart_id}, $form->{AP_chart_id}, conv_date($form->{"datepaid_$i"}),
260 272
                   $form->{AP_chart_id});
261 273
        do_query($form, $dbh, $query, @values);
......
265 277
      # add payment
266 278
      my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig));
267 279
      $query =
268
        qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id, chart_link) | .
269
        qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, | .
280
        qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, cleared, taxkey, tax_id, chart_link) | .
281
        qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, ?, | .
270 282
        qq|        (SELECT taxkey_id FROM chart WHERE accno = ?), | .
271 283
        qq|        (SELECT tax_id| .
272 284
        qq|         FROM taxkeys| .
......
278 290
        qq|        (SELECT c.link FROM chart c WHERE c.accno = ?))|;
279 291
      @values = ($form->{id}, $form->{"AP_paid_account_$i"}, $form->{"paid_$i"},
280 292
                 conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"},
281
                 $form->{"memo_$i"}, $project_id, $form->{"AP_paid_account_$i"},
293
                 $form->{"memo_$i"}, $project_id, $new_cleared, $form->{"AP_paid_account_$i"},
282 294
                 $form->{"AP_paid_account_$i"}, conv_date($form->{"datepaid_$i"}),
283 295
                 $form->{"AP_paid_account_$i"});
284 296
      do_query($form, $dbh, $query, @values);
......
615 627

  
616 628
  $old_form = save_form();
617 629

  
630
  $query = <<SQL;
631
    SELECT at.acc_trans_id, at.amount, at.cleared, c.accno
632
    FROM acc_trans at
633
    LEFT JOIN chart c ON (at.chart_id = c.id)
634
    WHERE (at.trans_id = ?)
635
SQL
636

  
637
  my %already_cleared = selectall_as_map($form, $dbh, $query, 'acc_trans_id', [ qw(amount cleared accno) ], $form->{id});
638

  
618 639
  # Delete all entries in acc_trans from prior payments.
619 640
  if (SL::DB::Default->get->payments_changeable != 0) {
620 641
    $self->_delete_payments($form, $dbh);
......
654 675
  ($form->{AP_chart_id}) = selectfirst_array_query($form, $dbh, $query, conv_i($form->{id}));
655 676

  
656 677
  # Post the new payments.
657
  $self->post_transaction($myconfig, $form, $dbh, 1);
678
  $self->post_transaction($myconfig, $form, $dbh, payments_only => 1, already_cleared => \%already_cleared);
658 679

  
659 680
  restore_form($old_form);
660 681

  

Auch abrufbar als: Unified diff