Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ac315ac0

Von Moritz Bunkus vor mehr als 6 Jahren hinzugefügt

  • ID ac315ac059800cab7bc7f21288a8581922acb231
  • Vorgänger 1de19311
  • Nachfolger 2d4626f9

Einkaufsrechnungen: 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/IR.pm
60 60
use constant PCLASS_NOTFORPURCHASE =>   2;
61 61

  
62 62
sub post_invoice {
63
  my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_;
63
  my ($self, $myconfig, $form, $provided_dbh, %params) = @_;
64 64
  $main::lxdebug->enter_sub();
65 65

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

  
68 68
  $::lxdebug->leave_sub;
69 69
  return $rc;
70 70
}
71 71

  
72 72
sub _post_invoice {
73
  my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_;
73
  my ($self, $myconfig, $form, $provided_dbh, %params) = @_;
74 74

  
75
  my $payments_only = $params{payments_only};
75 76
  my $dbh = $provided_dbh || SL::DB->client->dbh;
76 77
  my $restricter = SL::HTML::Restrict->create;
77 78

  
......
591 592

  
592 593
  $form->{amount}{ $form->{id} }{ $form->{AP} } = $form->{paid} if $form->{amount}{$form->{id}}{$form->{AP}} == 0;
593 594

  
595
  my %already_cleared = %{ $params{already_cleared} // {} };
596

  
594 597
  # record payments and offsetting AP
595 598
  for my $i (1 .. $form->{paidaccounts}) {
596 599
    if ($form->{"acc_trans_id_$i"}
......
607 610

  
608 611
    $amount = $form->round_amount($form->{"paid_$i"} * $form->{exchangerate} + $paiddiff, 2) * -1;
609 612

  
613
    my $new_cleared = !$form->{"acc_trans_id_$i"}                                                  ? 'f'
614
                    : !$already_cleared{$form->{"acc_trans_id_$i"}}                                ? 'f'
615
                    : $already_cleared{$form->{"acc_trans_id_$i"}}->{amount} != $form->{"paid_$i"} ? 'f'
616
                    : $already_cleared{$form->{"acc_trans_id_$i"}}->{accno}  != $accno             ? 'f'
617
                    : $already_cleared{$form->{"acc_trans_id_$i"}}->{cleared}                      ? 't'
618
                    :                                                                                'f';
619

  
610 620
    # record AP
611 621
    if ($form->{amount}{ $form->{id} }{ $form->{AP} } != 0) {
612
      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id, chart_link)
622
      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, cleared, tax_id, chart_link)
613 623
                  VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
614 624
                          (SELECT taxkey_id
615 625
                           FROM taxkeys
......
618 628
                                            WHERE accno = ?)
619 629
                           AND startdate <= ?
620 630
                           ORDER BY startdate DESC LIMIT 1),
621
                          ?,
631
                          ?, ?,
622 632
                          (SELECT tax_id
623 633
                           FROM taxkeys
624 634
                           WHERE chart_id= (SELECT id
......
628 638
                           ORDER BY startdate DESC LIMIT 1),
629 639
                          (SELECT link FROM chart WHERE accno = ?))|;
630 640
      @values = (conv_i($form->{id}), $form->{AP}, $amount,
631
                 $form->{"datepaid_$i"}, $form->{AP}, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AP}, conv_date($form->{"datepaid_$i"}), $form->{AP});
641
                 $form->{"datepaid_$i"}, $form->{AP}, conv_date($form->{"datepaid_$i"}), $project_id, $new_cleared, $form->{AP}, conv_date($form->{"datepaid_$i"}), $form->{AP});
632 642
      do_query($form, $dbh, $query, @values);
633 643
    }
634 644

  
......
636 646
    my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig));
637 647

  
638 648
    $query =
639
      qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id, tax_id, chart_link)
649
      qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id, cleared, tax_id, chart_link)
640 650
                VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?,
641 651
                (SELECT taxkey_id
642 652
                 FROM taxkeys
......
644 654
                                  FROM chart WHERE accno = ?)
645 655
                 AND startdate <= ?
646 656
                 ORDER BY startdate DESC LIMIT 1),
647
                ?,
657
                ?, ?,
648 658
                (SELECT tax_id
649 659
                 FROM taxkeys
650 660
                 WHERE chart_id= (SELECT id
......
653 663
                 ORDER BY startdate DESC LIMIT 1),
654 664
                (SELECT link FROM chart WHERE accno = ?))|;
655 665
    @values = (conv_i($form->{id}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"},
656
               $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($form->{"datepaid_$i"}), $project_id, $accno, conv_date($form->{"datepaid_$i"}), $accno);
666
               $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($form->{"datepaid_$i"}), $project_id, $new_cleared, $accno, conv_date($form->{"datepaid_$i"}), $accno);
657 667
    do_query($form, $dbh, $query, @values);
658 668

  
659 669
    $exchangerate = 0;
......
1548 1558

  
1549 1559
  $old_form = save_form();
1550 1560

  
1561
  $query = <<SQL;
1562
    SELECT at.acc_trans_id, at.amount, at.cleared, c.accno
1563
    FROM acc_trans at
1564
    LEFT JOIN chart c ON (at.chart_id = c.id)
1565
    WHERE (at.trans_id = ?)
1566
SQL
1567

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

  
1551 1570
  # Delete all entries in acc_trans from prior payments.
1552 1571
  if (SL::DB::Default->get->payments_changeable != 0) {
1553 1572
    $self->_delete_payments($form, $dbh);
......
1594 1613
  ($form->{AP}) = selectfirst_array_query($form, $dbh, $query, conv_i($form->{id}));
1595 1614

  
1596 1615
  # Post the new payments.
1597
  $self->post_invoice($myconfig, $form, $dbh, 1);
1616
  $self->post_invoice($myconfig, $form, $dbh, payments_only => 1, already_cleared => \%already_cleared);
1598 1617

  
1599 1618
  restore_form($old_form);
1600 1619

  

Auch abrufbar als: Unified diff