Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1de19311

Von Moritz Bunkus vor mehr als 6 Jahren hinzugefügt

  • ID 1de193119512c28ad62e604711024a4a54667bb9
  • Vorgänger b4cc349b
  • Nachfolger ac315ac0

Verkaufsrechnungen: 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/IS.pm
682 682
}
683 683

  
684 684
sub post_invoice {
685
  my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_;
685
  my ($self, $myconfig, $form, $provided_dbh, %params) = @_;
686 686
  $main::lxdebug->enter_sub();
687 687

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

  
690 690
  $::lxdebug->leave_sub;
691 691
  return $rc;
692 692
}
693 693

  
694 694
sub _post_invoice {
695
  my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_;
695
  my ($self, $myconfig, $form, $provided_dbh, %params) = @_;
696 696

  
697
  my $payments_only = $params{payments_only};
697 698
  my $dbh = $provided_dbh || SL::DB->client->dbh;
698 699
  my $restricter = SL::HTML::Restrict->create;
699 700

  
......
1144 1145
    }
1145 1146
  }
1146 1147

  
1148
  my %already_cleared = %{ $params{already_cleared} // {} };
1149

  
1147 1150
  # record payments and offsetting AR
1148 1151
  if (!$form->{storno}) {
1149 1152
    for my $i (1 .. $form->{paidaccounts}) {
......
1173 1176
      # record AR
1174 1177
      $amount = $form->round_amount($form->{"paid_$i"} * $form->{exchangerate} + $diff, 2);
1175 1178

  
1179
      my $new_cleared = !$form->{"acc_trans_id_$i"}                                                       ? 'f'
1180
                      : !$already_cleared{$form->{"acc_trans_id_$i"}}                                     ? 'f'
1181
                      : $already_cleared{$form->{"acc_trans_id_$i"}}->{amount} != $form->{"paid_$i"} * -1 ? 'f'
1182
                      : $already_cleared{$form->{"acc_trans_id_$i"}}->{accno}  != $accno                  ? 'f'
1183
                      : $already_cleared{$form->{"acc_trans_id_$i"}}->{cleared}                           ? 't'
1184
                      :                                                                                     'f';
1185

  
1176 1186
      if ($form->{amount}{ $form->{id} }{ $form->{AR} } != 0) {
1177 1187
        $query =
1178
        qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id, chart_link)
1188
        qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id, cleared, chart_link)
1179 1189
           VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
1180 1190
                   (SELECT tax_id
1181 1191
                    FROM taxkeys
......
1191 1201
                                     WHERE accno = ?)
1192 1202
                    AND startdate <= ?
1193 1203
                    ORDER BY startdate DESC LIMIT 1),
1194
                   ?,
1204
                   ?, ?,
1195 1205
                   (SELECT link FROM chart WHERE accno = ?))|;
1196
        @values = (conv_i($form->{"id"}), $form->{AR}, $amount, $form->{"datepaid_$i"}, $form->{AR}, conv_date($taxdate), $form->{AR}, conv_date($taxdate), $project_id, $form->{AR});
1206
        @values = (conv_i($form->{"id"}), $form->{AR}, $amount, $form->{"datepaid_$i"}, $form->{AR}, conv_date($taxdate), $form->{AR}, conv_date($taxdate), $project_id, $new_cleared, $form->{AR});
1197 1207
        do_query($form, $dbh, $query, @values);
1198 1208
      }
1199 1209

  
......
1202 1212
      my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig));
1203 1213

  
1204 1214
      $query =
1205
      qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, tax_id, taxkey, project_id, chart_link)
1215
      qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, tax_id, taxkey, project_id, cleared, chart_link)
1206 1216
         VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?,
1207 1217
                 (SELECT tax_id
1208 1218
                  FROM taxkeys
......
1218 1228
                                   WHERE accno = ?)
1219 1229
                  AND startdate <= ?
1220 1230
                  ORDER BY startdate DESC LIMIT 1),
1221
                 ?,
1231
                 ?, ?,
1222 1232
                 (SELECT link FROM chart WHERE accno = ?))|;
1223 1233
      @values = (conv_i($form->{"id"}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"},
1224
                 $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($taxdate), $accno, conv_date($taxdate), $project_id, $accno);
1234
                 $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($taxdate), $accno, conv_date($taxdate), $project_id, $new_cleared, $accno);
1225 1235
      do_query($form, $dbh, $query, @values);
1226 1236

  
1227 1237
      # exchangerate difference
......
1620 1630

  
1621 1631
  $old_form = save_form();
1622 1632

  
1633
  $query = <<SQL;
1634
    SELECT at.acc_trans_id, at.amount, at.cleared, c.accno
1635
    FROM acc_trans at
1636
    LEFT JOIN chart c ON (at.chart_id = c.id)
1637
    WHERE (at.trans_id = ?)
1638
SQL
1639

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

  
1623 1642
  # Delete all entries in acc_trans from prior payments.
1624 1643
  if (SL::DB::Default->get->payments_changeable != 0) {
1625 1644
    $self->_delete_payments($form, $dbh);
......
1666 1685
  ($form->{AR}) = selectfirst_array_query($form, $dbh, $query, conv_i($form->{id}));
1667 1686

  
1668 1687
  # Post the new payments.
1669
  $self->post_invoice($myconfig, $form, $dbh, 1);
1688
  $self->post_invoice($myconfig, $form, $dbh, payments_only => 1, already_cleared => \%already_cleared);
1670 1689

  
1671 1690
  restore_form($old_form);
1672 1691

  

Auch abrufbar als: Unified diff