Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 2d4626f9

Von Moritz Bunkus vor mehr als 6 Jahren hinzugefügt

  • ID 2d4626f98c3ef03c52cadde9e7bcee2330b02cd9
  • Vorgänger ac315ac0
  • Nachfolger 08e42c5d

Debitorenbuchungen: 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/AR.pm
49 49
use strict;
50 50

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

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

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

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

  
64
  my $payments_only = $params{payments_only};
63 65

  
64 66
  my ($query, $sth, $null, $taxrate, $amount, $tax);
65 67
  my $exchangerate = 0;
......
190 192

  
191 193
  $form->new_lastmtime('ar');
192 194

  
195
  my %already_cleared = %{ $params{already_cleared} // {} };
196

  
193 197
  # add paid transactions
194 198
  for my $i (1 .. $form->{paidaccounts}) {
195 199

  
......
213 217
      $form->{exchangerate} = $form->{"exchangerate_$i"}
214 218
        if ($form->{amount} == 0 && $form->{netamount} == 0);
215 219

  
220
      my $new_cleared = !$form->{"acc_trans_id_$i"}                                                       ? 'f'
221
                      : !$already_cleared{$form->{"acc_trans_id_$i"}}                                     ? 'f'
222
                      : $already_cleared{$form->{"acc_trans_id_$i"}}->{amount} != $form->{"paid_$i"} * -1 ? 'f'
223
                      : $already_cleared{$form->{"acc_trans_id_$i"}}->{accno}  != $form->{AR}{"paid_$i"}  ? 'f'
224
                      : $already_cleared{$form->{"acc_trans_id_$i"}}->{cleared}                           ? 't'
225
                      :                                                                                     'f';
226

  
216 227
      # receivables amount
217 228
      $amount = $form->round_amount($form->{"paid_$i"} * $form->{exchangerate}, 2);
218 229

  
219 230
      if ($amount != 0) {
220 231
        # add receivable
221
        $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id, chart_link)
222
                     VALUES (?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?),
232
        $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, cleared, taxkey, tax_id, chart_link)
233
                     VALUES (?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?),
223 234
                     (SELECT tax_id
224 235
                      FROM taxkeys
225 236
                      WHERE chart_id = ?
226 237
                      AND startdate <= ?
227 238
                      ORDER BY startdate DESC LIMIT 1),
228 239
                     (SELECT c.link FROM chart c WHERE c.id = ?))|;
229
        @values = (conv_i($form->{id}), $form->{AR_chart_id}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR_chart_id}, $form->{AR_chart_id}, conv_date($form->{"datepaid_$i"}), $form->{AR_chart_id});
240
        @values = (conv_i($form->{id}), $form->{AR_chart_id}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $new_cleared,
241
                   $form->{AR_chart_id}, $form->{AR_chart_id}, conv_date($form->{"datepaid_$i"}), $form->{AR_chart_id});
230 242

  
231 243
        do_query($form, $dbh, $query, @values);
232 244
      }
......
236 248
        my $project_id = conv_i($form->{"paid_project_id_$i"});
237 249
        my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig));
238 250
        $amount = $form->{"paid_$i"} * -1;
239
        $query  = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id, chart_link)
240
                     VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?),
251
        $query  = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, cleared, taxkey, tax_id, chart_link)
252
                     VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?),
241 253
                     (SELECT tax_id
242 254
                      FROM taxkeys
243 255
                      WHERE chart_id= (SELECT id
......
246 258
                      AND startdate <= ?
247 259
                      ORDER BY startdate DESC LIMIT 1),
248 260
                     (SELECT c.link FROM chart c WHERE c.accno = ?))|;
249
        @values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $form->{AR}{"paid_$i"},
261
        @values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $new_cleared, $form->{AR}{"paid_$i"},
250 262
                    $form->{AR}{"paid_$i"}, conv_date($form->{"datepaid_$i"}), $form->{AR}{"paid_$i"});
251 263
        do_query($form, $dbh, $query, @values);
252 264

  
......
385 397

  
386 398
  $old_form = save_form();
387 399

  
400
  $query = <<SQL;
401
    SELECT at.acc_trans_id, at.amount, at.cleared, c.accno
402
    FROM acc_trans at
403
    LEFT JOIN chart c ON (at.chart_id = c.id)
404
    WHERE (at.trans_id = ?)
405
SQL
406

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

  
388 409
  # Delete all entries in acc_trans from prior payments.
389 410
  if (SL::DB::Default->get->payments_changeable != 0) {
390 411
    $self->_delete_payments($form, $dbh);
......
424 445
  ($form->{AR_chart_id}) = selectfirst_array_query($form, $dbh, $query, conv_i($form->{id}));
425 446

  
426 447
  # Post the new payments.
427
  $self->post_transaction($myconfig, $form, $dbh, 1);
448
  $self->post_transaction($myconfig, $form, $dbh, payments_only => 1, already_cleared => \%already_cleared);
428 449

  
429 450
  restore_form($old_form);
430 451

  

Auch abrufbar als: Unified diff