Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 75063bf3

Von Kivitendo Admin vor etwa 8 Jahren hinzugefügt

  • ID 75063bf3a632f9d54e2f200cd659724432e0ef82
  • Vorgänger 691a1293
  • Nachfolger 68ccd089

Controller BankTransaction - Einrückungen und Kommentare

Unterschiede anzeigen:

SL/Controller/BankTransaction.pm
357 357
  my ($self) = @_;
358 358

  
359 359
  my $invoice_hash = delete $::form->{invoice_ids}; # each key (the bt line with a bt_id) contains an array of invoice_ids
360

  
361
  # e.g. three partial payments with bt_ids 54, 55 and 56 for invoice with id 74:
362
  # $invoice_hash = {
363
  #         '55' => [
364
  #                 '74'
365
  #               ],
366
  #         '54' => [
367
  #                 '74'
368
  #               ],
369
  #         '56' => [
370
  #                 '74'
371
  #               ]
372
  #       };
373
  #
374
  # or if the payment with bt_id 44 is used to pay invoices with ids 50, 51 and 52
375
  # $invoice_hash = {
376
  #           '44' => [ '50', '51', 52' ]
377
  #         };
378

  
360 379
  my $skonto_hash  = delete $::form->{invoice_skontos} || {}; # array containing the payment type, could be empty
361 380

  
362 381
  # a bank_transaction may be assigned to several invoices, i.e. a customer
363 382
  # might pay several open invoices with one transaction
364 383

  
365 384
  while ( my ($bt_id, $invoice_ids) = each(%$invoice_hash) ) {
366
    my $bank_transaction = SL::DB::Manager::BankTransaction->find_by(id => $bt_id);
367
    my $sign = $bank_transaction->amount < 0 ? -1 : 1;
385
    my $bank_transaction      = SL::DB::Manager::BankTransaction->find_by(id => $bt_id);
386
    my $sign                  = $bank_transaction->amount < 0 ? -1 : 1;
368 387
    my $amount_of_transaction = $sign * $bank_transaction->amount;
369 388

  
370 389
    my @invoices;
371 390
    foreach my $invoice_id (@{ $invoice_ids }) {
372 391
      push @invoices, (SL::DB::Manager::Invoice->find_by(id => $invoice_id) || SL::DB::Manager::PurchaseInvoice->find_by(id => $invoice_id));
373 392
    }
374
    @invoices = sort { return 1 if ($a->is_sales and $a->amount > 0);
393
    @invoices = sort { return 1 if ( $a->is_sales and $a->amount > 0);
375 394
                       return 1 if (!$a->is_sales and $a->amount < 0);
376 395
                       return -1;
377 396
                     } @invoices if $bank_transaction->amount > 0;
378
    @invoices = sort { return -1 if ($a->is_sales and $a->amount > 0);
397
    @invoices = sort { return -1 if ( $a->is_sales and $a->amount > 0);
379 398
                       return -1 if (!$a->is_sales and $a->amount < 0);
380 399
                       return 1;
381 400
                     } @invoices if $bank_transaction->amount < 0;
......
420 439
                              amount       => $invoice->open_amount,
421 440
                              payment_type => $payment_type,
422 441
                              transdate    => $bank_transaction->transdate->to_kivitendo);
423
      } else {
442
      } else { # use the whole amount of the bank transaction for the invoice, overpay the invoice if necessary
424 443
        $invoice->pay_invoice(chart_id     => $bank_transaction->local_bank_account->chart_id,
425 444
                              trans_id     => $invoice->id,
426 445
                              amount       => $amount_of_transaction,

Auch abrufbar als: Unified diff