Revision 0d34b381
Von Kivitendo Admin vor etwa 8 Jahren hinzugefügt
SL/DB/Helper/Payment.pm | ||
---|---|---|
154 | 154 |
source => $params{source}, |
155 | 155 |
taxkey => 0, |
156 | 156 |
tax_id => SL::DB::Manager::Tax->find_by(taxkey => 0)->id); |
157 |
|
|
158 |
# the acc_trans entries are saved individually, not added to $self and then saved all at once |
|
157 | 159 |
$new_acc_trans->save; |
158 | 160 |
|
159 | 161 |
$reference_amount -= abs($amount); |
... | ... | |
193 | 195 |
$self->datepaid($transdate_obj); |
194 | 196 |
$self->save; |
195 | 197 |
|
198 |
# make sure transactions will be reloaded the next time $self->transactions |
|
199 |
# is called, as pay_invoice saves the acc_trans objects individually rather |
|
200 |
# than adding them to the transaction relation array. |
|
201 |
$self->forget_related('transactions'); |
|
202 |
|
|
196 | 203 |
my $datev_check = 0; |
197 | 204 |
if ( $is_sales ) { |
198 | 205 |
if ( ( $self->invoice && $::instance_conf->get_datev_check_on_sales_invoice ) || |
... | ... | |
374 | 381 |
|
375 | 382 |
my $skonto_configured = 1; # default is assume skonto works |
376 | 383 |
|
377 |
my $transactions = $self->transactions; |
|
378 |
foreach my $transaction (@{ $transactions }) { |
|
384 |
# my $transactions = $self->transactions;
|
|
385 |
foreach my $transaction (@{ $self->transactions }) {
|
|
379 | 386 |
# find all transactions with an AR_amount or AP_amount link |
380 | 387 |
my $tax = SL::DB::Manager::Tax->get_first( where => [taxkey => $transaction->{taxkey}]); |
381 | 388 |
croak "no tax for taxkey " . $transaction->{taxkey} unless ref $tax; |
... | ... | |
448 | 455 |
|
449 | 456 |
my $reference_ARAP_amount = 0; |
450 | 457 |
|
451 |
my $transactions = $self->transactions; |
|
452 |
foreach my $transaction (@{ $transactions }) { |
|
458 |
# my $transactions = $self->transactions;
|
|
459 |
foreach my $transaction (@{ $self->transactions }) {
|
|
453 | 460 |
# find all transactions with an AR_amount or AP_amount link |
454 | 461 |
$transaction->{chartlinks} = { map { $_ => 1 } split(m/:/, $transaction->{chart_link}) }; |
455 | 462 |
# second condition is that we can determine an automatic Skonto account for each AR_amount entry |
... | ... | |
659 | 666 |
$ap->pay_invoice(chart_id => $bank->chart_id, |
660 | 667 |
amount => $ap->open_amount, |
661 | 668 |
transdate => DateTime->now->to_kivitendo, |
662 |
memo => 'foobar;
|
|
663 |
source => 'barfoo;
|
|
669 |
memo => 'foobar',
|
|
670 |
source => 'barfoo',
|
|
664 | 671 |
payment_type => 'without_skonto', # default if not specified |
665 | 672 |
); |
666 | 673 |
|
... | ... | |
668 | 675 |
$ap->pay_invoice(chart_id => $bank->chart_id, |
669 | 676 |
amount => $ap->amount, # doesn't need to be specified |
670 | 677 |
transdate => DateTime->now->to_kivitendo, |
671 |
memo => 'foobar;
|
|
672 |
source => 'barfoo;
|
|
678 |
memo => 'foobar',
|
|
679 |
source => 'barfoo',
|
|
673 | 680 |
payment_type => 'with_skonto', |
674 | 681 |
); |
675 | 682 |
|
... | ... | |
933 | 940 |
might always want to pay quickly making use of skonto, while another company |
934 | 941 |
might always want to pay as late as possible. |
935 | 942 |
|
936 |
=item C<transactions> |
|
937 |
|
|
938 |
Returns all acc_trans Objects of an ar/ap object. |
|
939 |
|
|
940 |
Example in console to print account numbers and booked amounts of an invoice: |
|
941 |
my $invoice = invoice(invnumber => '144'); |
|
942 |
foreach my $acc_trans ( @{ $invoice->transactions } ) { |
|
943 |
print $acc_trans->chart->accno . " : " . $acc_trans->amount_as_number . "\n" |
|
944 |
}; |
|
945 |
# 1200 : 226,00000 |
|
946 |
# 1800 : -226,00000 |
|
947 |
# 4300 : 100,00000 |
|
948 |
# 3801 : 7,00000 |
|
949 |
# 3806 : 19,00000 |
|
950 |
# 4400 : 100,00000 |
|
951 |
# 1200 : -226,00000 |
|
952 |
|
|
953 | 943 |
=item C<get_payment_select_options_for_bank_transaction $banktransaction_id %params> |
954 | 944 |
|
955 | 945 |
Make suggestion for a skonto payment type by returning an HTML blob of the options |
Auch abrufbar als: Unified diff
Payment Helper setzt $self->transactions zurück
Als es noch eine Methode transactions in SL::DB::Helper::Payment gab
wurden die acc_trans-Einträge bei Zugriff per $self->transactions jedes
Mal aus der Datenbank ausgelesen:
(SL::DB::Manager::AccTransaction->get_all(query => [ trans_id => $self->id ]);
Seit Commit 01b298ec3 wird stattdessen der aktuelle relationship Array
verwendet, wenn die transactions noch nicht ausgelesen wurden werden sie
wie oben geladen, wenn sie aber schon existieren dann werden die
Transaktionen im Speicher benutzt.
Bei den Tests gab es aber das Problem, daß in pay_invoice die
acc_trans-Einträge der Zahlungen als AccTrans-Objekte unabhängig vom
Rechnungsobjekt gespeichert wurden, und der transaction Array daher
nicht aktualisiert wurde. Am Ende von pay_invoice wird nun per
forget_related der transaction-Array zurückgesetzt, damit bei der
nächsten Verwendung die aktuell gespeicherten Transaktionen nachgeladen
werden.