Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 0d34b381

Von Kivitendo Admin vor fast 9 Jahren hinzugefügt

  • ID 0d34b38184fdd6a6f1dd1bc7ce509c560e326b4e
  • Vorgänger 44703001
  • Nachfolger c4e13bb2

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.

Unterschiede anzeigen:

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
SL/DB/Invoice.pm
5 5
use Carp;
6 6
use List::Util qw(first sum);
7 7

  
8
use Rose::DB::Object::Helpers qw(has_loaded_related);
8
use Rose::DB::Object::Helpers qw(has_loaded_related forget_related);
9 9
use SL::DB::MetaSetup::Invoice;
10 10
use SL::DB::Manager::Invoice;
11 11
use SL::DB::Helper::Payment qw(:ALL);
SL/DB/PurchaseInvoice.pm
11 11
use SL::DB::Helper::LinkedRecords;
12 12
use SL::DB::Helper::Payment qw(:ALL);
13 13
use SL::Locale::String qw(t8);
14
use Rose::DB::Object::Helpers qw(has_loaded_related forget_related);
14 15

  
15 16
# The calculator hasn't been adjusted for purchase invoices yet.
16 17
# use SL::DB::Helper::PriceTaxCalculator;
t/db_helper/payment.t
257 257
}
258 258

  
259 259
sub number_of_payments {
260
  my $transactions = shift;
260
  my $invoice = shift;
261 261

  
262 262
  my $number_of_payments;
263 263
  my $paid_amount;
264
  foreach my $transaction ( @$transactions ) {
264
  foreach my $transaction ( @{ $invoice->transactions } ) {
265 265
    if ( $transaction->chart_link =~ /(AR_paid|AP_paid)/ ) {
266 266
      $paid_amount += $transaction->amount ;
267 267
      $number_of_payments++;
......
271 271
};
272 272

  
273 273
sub total_amount {
274
  my $transactions = shift;
274
  my $invoice = shift;
275 275

  
276
  my $total = sum map { $_->amount } @$transactions;
276
  my $total = sum map { $_->amount } @{ $invoice->transactions };
277 277

  
278 278
  return $::form->round_amount($total, 5);
279 279

  
......
305 305

  
306 306
  $invoice->pay_invoice( %params );
307 307

  
308
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
309
  my $total = total_amount($invoice->transactions);
308
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
309
  my $total = total_amount($invoice);
310 310

  
311 311
  my $title = 'default invoice, one item, 19% tax, without_skonto';
312 312

  
......
345 345
  $params{amount} = '-10.00';
346 346
  $invoice->pay_invoice( %params );
347 347

  
348
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
349
  my $total = total_amount($invoice->transactions);
348
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
349
  my $total = total_amount($invoice);
350 350

  
351 351
  my $title = 'default invoice, one item, 19% tax, without_skonto';
352 352

  
......
383 383

  
384 384
  $invoice->pay_invoice( %params );
385 385

  
386
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
387
  my $total = total_amount($invoice->transactions);
386
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
387
  my $total = total_amount($invoice);
388 388

  
389 389
  my $title = 'default invoice, two items, 19/7% tax with_skonto_pt';
390 390

  
......
418 418

  
419 419
  $invoice->pay_invoice( %params );
420 420

  
421
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
422
  my $total = total_amount($invoice->transactions);
421
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
422
  my $total = total_amount($invoice);
423 423

  
424 424
  my $title = 'default invoice, two items, 19/7% tax with_skonto_pt';
425 425

  
......
456 456

  
457 457
  $invoice->pay_invoice( %params );
458 458

  
459
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
460
  my $total = total_amount($invoice->transactions);
459
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
460
  my $total = total_amount($invoice);
461 461

  
462 462
  my $title = 'default invoice, two items, 19/7% tax without skonto';
463 463

  
......
488 488
                         transdate    => DateTime->today_local->to_kivitendo,
489 489
                       );
490 490

  
491
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
492
  my $total = total_amount($invoice->transactions);
491
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
492
  my $total = total_amount($invoice);
493 493

  
494 494
  my $title = 'default invoice, two items, 19/7% tax without skonto incomplete payment';
495 495

  
......
524 524
                         transdate    => DateTime->today_local->to_kivitendo
525 525
                       );
526 526

  
527
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
528
  my $total = total_amount($invoice->transactions);
527
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
528
  my $total = total_amount($invoice);
529 529

  
530 530
  my $title = 'default invoice, two items, 19/7% tax not included';
531 531

  
......
567 567
                         transdate    => DateTime->today_local->to_kivitendo
568 568
                       );
569 569

  
570
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
571
  my $total = total_amount($invoice->transactions);
570
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
571
  my $total = total_amount($invoice);
572 572

  
573 573
  my $title = 'default invoice, two items, 19/7% tax not included';
574 574

  
......
609 609
                         transdate    => DateTime->today_local->to_kivitendo
610 610
                       );
611 611

  
612
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
613
  my $total = total_amount($invoice->transactions);
612
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
613
  my $total = total_amount($invoice);
614 614

  
615 615
  my $title = 'default invoice, two items, 19/7% tax not included';
616 616

  
......
647 647
                         transdate    => DateTime->today_local->to_kivitendo
648 648
                       );
649 649

  
650
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
651
  my $total = total_amount($invoice->transactions);
650
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
651
  my $total = total_amount($invoice);
652 652

  
653 653
  my $title = 'default invoice, two items, 19/7% tax not included';
654 654

  
......
689 689
  $params{payment_type} = 'difference_as_skonto';
690 690
  $invoice->pay_invoice( %params );
691 691

  
692
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
693
  my $total = total_amount($invoice->transactions);
692
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
693
  my $total = total_amount($invoice);
694 694

  
695 695
  my $title = 'default invoice, one item, 19% tax, without_skonto';
696 696

  
......
727 727
  $params{payment_type} = 'difference_as_skonto';
728 728
  $invoice->pay_invoice( %params );
729 729

  
730
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
731
  my $total = total_amount($invoice->transactions);
730
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
731
  my $total = total_amount($invoice);
732 732

  
733 733
  my $title = 'default invoice, one item, 19% tax, without_skonto';
734 734

  
......
756 756

  
757 757
  $purchase_invoice->pay_invoice( %params );
758 758

  
759
  my ($number_of_payments, $paid_amount) = number_of_payments($purchase_invoice->transactions);
760
  my $total = total_amount($purchase_invoice->transactions);
759
  my ($number_of_payments, $paid_amount) = number_of_payments($purchase_invoice);
760
  my $total = total_amount($purchase_invoice);
761 761

  
762 762
  my $title = 'default invoice, two items, 19/7% tax without skonto';
763 763

  
......
781 781

  
782 782
  $purchase_invoice->pay_invoice( %params );
783 783

  
784
  my ($number_of_payments, $paid_amount) = number_of_payments($purchase_invoice->transactions);
785
  my $total = total_amount($purchase_invoice->transactions);
784
  my ($number_of_payments, $paid_amount) = number_of_payments($purchase_invoice);
785
  my $total = total_amount($purchase_invoice);
786 786

  
787 787
  my $title = 'default invoice, two items, 19/7% tax without skonto';
788 788

  
......
802 802
                          chart_id     => $bank_account->chart_id,
803 803
                          transdate    => DateTime->today_local->to_kivitendo
804 804
                         );
805
  my ($number_of_payments, $paid_amount) = number_of_payments($purchase_invoice->transactions);
806
  my $total = total_amount($purchase_invoice->transactions);
805
  my ($number_of_payments, $paid_amount) = number_of_payments($purchase_invoice);
806
  my $total = total_amount($purchase_invoice);
807 807

  
808 808
  my $title = 'default purchase_invoice, two charts, 19/7% tax multiple payments with final difference as skonto';
809 809

  
......
837 837
                          transdate    => DateTime->today_local->to_kivitendo
838 838
                         );
839 839

  
840
  my ($number_of_payments, $paid_amount) = number_of_payments($purchase_invoice->transactions);
841
  my $total = total_amount($purchase_invoice->transactions);
840
  my ($number_of_payments, $paid_amount) = number_of_payments($purchase_invoice);
841
  my $total = total_amount($purchase_invoice);
842 842

  
843 843
  my $title = 'default purchase_invoice, two charts, 19/7% tax multiple payments with final difference as skonto';
844 844

  
......
871 871

  
872 872
  $invoice->pay_invoice( %params );
873 873

  
874
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
875
  my $total = total_amount($invoice->transactions);
874
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
875
  my $total = total_amount($invoice);
876 876

  
877 877
  my $title = 'default invoice, two items, 19/7% tax with_skonto_pt 50/50';
878 878

  
......
909 909

  
910 910
  $invoice->pay_invoice( %params );
911 911

  
912
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
913
  my $total = total_amount($invoice->transactions);
912
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
913
  my $total = total_amount($invoice);
914 914

  
915 915
  my $title = 'default invoice, four items, 19/7% tax with_skonto_pt 4x25';
916 916

  
......
946 946

  
947 947
  $invoice->pay_invoice( %params );
948 948

  
949
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
950
  my $total = total_amount($invoice->transactions);
949
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
950
  my $total = total_amount($invoice);
951 951

  
952 952
  my $title = 'default invoice, four items, 19/7% tax with_skonto_pt 4x25';
953 953

  
......
985 985
                         transdate    => DateTime->today_local->to_kivitendo
986 986
                       );
987 987

  
988
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice->transactions);
989
  my $total = total_amount($invoice->transactions);
988
  my ($number_of_payments, $paid_amount) = number_of_payments($invoice);
989
  my $total = total_amount($invoice);
990 990

  
991 991
  my $title = 'default invoice, four items, 19/7% tax with_skonto_pt 4x25';
992 992

  

Auch abrufbar als: Unified diff