Revision 0631432e
Von Moritz Bunkus vor mehr als 8 Jahren hinzugefügt
SL/Controller/BankTransaction.pm | ||
---|---|---|
25 | 25 |
use SL::DB::BankAccount; |
26 | 26 |
use SL::DBUtils qw(like); |
27 | 27 |
use SL::Presenter; |
28 |
|
|
29 |
use List::MoreUtils qw(any); |
|
28 | 30 |
use List::Util qw(max); |
29 | 31 |
|
30 | 32 |
use Rose::Object::MakeMethods::Generic |
... | ... | |
435 | 437 |
my $bank_transaction = $data{bank_transaction}; |
436 | 438 |
my $sign = $bank_transaction->amount < 0 ? -1 : 1; |
437 | 439 |
my $amount_of_transaction = $sign * $bank_transaction->amount; |
440 |
my $payment_received = $bank_transaction->amount > 0; |
|
441 |
my $payment_sent = $bank_transaction->amount < 0; |
|
438 | 442 |
|
439 |
my @invoices; |
|
440 | 443 |
foreach my $invoice_id (@{ $params{invoice_ids} }) { |
441 | 444 |
my $invoice = SL::DB::Manager::Invoice->find_by(id => $invoice_id) || SL::DB::Manager::PurchaseInvoice->find_by(id => $invoice_id); |
442 | 445 |
if (!$invoice) { |
... | ... | |
447 | 450 |
}; |
448 | 451 |
} |
449 | 452 |
|
450 |
push @invoices, $invoice;
|
|
453 |
push @{ $data{invoices} }, $invoice;
|
|
451 | 454 |
} |
452 | 455 |
|
453 |
$data{invoices} = \@invoices; |
|
456 |
if ( $payment_received |
|
457 |
&& any { ( $_->is_sales && ($_->amount < 0)) |
|
458 |
|| (!$_->is_sales && ($_->amount > 0)) |
|
459 |
} @{ $data{invoices} }) { |
|
460 |
return { |
|
461 |
%data, |
|
462 |
result => 'error', |
|
463 |
message => $::locale->text("Received payments can only be posted for sales invoices and purchase credit notes."), |
|
464 |
}; |
|
465 |
} |
|
454 | 466 |
|
455 |
@invoices = sort { return 1 if ( $a->is_sales and $a->amount > 0); |
|
456 |
return 1 if (!$a->is_sales and $a->amount < 0); |
|
457 |
return -1; |
|
458 |
} @invoices if $bank_transaction->amount > 0; |
|
459 |
@invoices = sort { return -1 if ( $a->is_sales and $a->amount > 0); |
|
460 |
return -1 if (!$a->is_sales and $a->amount < 0); |
|
461 |
return 1; |
|
462 |
} @invoices if $bank_transaction->amount < 0; |
|
467 |
if ( $payment_sent |
|
468 |
&& any { ( $_->is_sales && ($_->amount > 0)) |
|
469 |
|| (!$_->is_sales && ($_->amount < 0)) |
|
470 |
} @{ $data{invoices} }) { |
|
471 |
return { |
|
472 |
%data, |
|
473 |
result => 'error', |
|
474 |
message => $::locale->text("Sent payments can only be posted for purchase invoices and sales credit notes."), |
|
475 |
}; |
|
476 |
} |
|
463 | 477 |
|
464 |
my $max_invoices = scalar(@invoices);
|
|
478 |
my $max_invoices = scalar(@{ $data{invoices} });
|
|
465 | 479 |
my $n_invoices = 0; |
466 | 480 |
|
467 |
foreach my $invoice (@invoices) {
|
|
481 |
foreach my $invoice (@{ $data{invoices} }) {
|
|
468 | 482 |
|
469 | 483 |
$n_invoices++ ; |
470 | 484 |
# Check if bank_transaction already has a link to the invoice, may only be linked once per invoice |
Auch abrufbar als: Unified diff
Bankauszug: Transaktionsrichtung mit Belegrichtung abgleichen
Erhält man eine Zahlung, so darf man diese nur mit Belegen verbuchen
können, die Zahlungen in Empfangsrichtung bedingen: Verkaufsrechnungen
und Gutschriften im Einkauf.
Analog gilt das auch für ausgehende Zahlungen. Hier passen nur
Einkaufsrechnungen sowie Gutschriften von Verkaufsrechnungen.
Alle anderen Zuordnungen werden mit einem Fehler zurückgewiesen.