Beim Durchlesen der BankTransaction.pm ist mir aufgefallen, dass es
a)
viel sinnvoller ist, den offenen Betrag einer Rechnung/Gutschrift/Einkaufsrechnung/Kreditorenbeleg über
das Objekt zu ermitteln, um einige Fallunterschiede und Verrenkungen ggf. erst gar nicht im Controller zu haben.
Ich hab im POD wie folgt ergänzt:
Get the current open signed amount of this invoice. A positive number
indicates a missing incoming transaction. A negative number indicates
a missing outgoing transaction, i.e. open credit note.
Ich hab einen Fallunterschied für unterschiedliche Typen dort gemacht, aber wenn
ich die Funktion so schreibe, ist ar.amount - ar.paid immer korrekt.
Ein negatives Vorzeichen bedeutet einfach nur Gutschrift.
Damit hab ich mit der kleinstmöglichen Änderung im Controller den Fall abgedeckt.
# pay invoice or go to the next bank transaction if the amount is not sufficiently high
if ($invoice->amount_open <= $amount_of_transaction) {
$invoice->pay_invoice(chart_id => $bank_transaction->local_bank_account->chart_id,
trans_id => $invoice->id,
amount => $invoice->amount_open,
payment_type => $payment_type,
transdate => $bank_transaction->transdate->to_kivitendo);
if ($invoice->is_sales) {
$amount_of_transaction -= $sign * $invoice->amount_open;
$bank_transaction->invoice_amount($bank_transaction->invoice_amount + $invoice->amount_open);
} else {
$amount_of_transaction += $sign * $invoice->amount_open if (!$invoice->is_sales);
$bank_transaction->invoice_amount($bank_transaction->invoice_amount - $invoice->amount_open);
}
} else {
$invoice->pay_invoice(chart_id => $bank_transaction->local_bank_account->chart_id,
trans_id => $invoice->id,
amount => $amount_of_transaction,
payment_type => $payment_type,
transdate => $bank_transaction->transdate->to_kivitendo);
$bank_transaction->invoice_amount($bank_transaction->amount) if $invoice->is_sales;
$bank_transaction->invoice_amount($bank_transaction->amount) if !$invoice->is_sales;
$amount_of_transaction = 0;
}
Bzw. visuell
Ein paar Stellen sehen im Controller im Detail nicht so ganz sinnvoll aus, dass würde
ich gerne nochmal mit jmd. besprechen, bevor ich hier was ändere.
Das hier macht bspw. keinen Sinn:
$bank_transaction->invoice_amount($bank_transaction->amount) if $invoice->is_sales;
$bank_transaction->invoice_amount($bank_transaction->amount) if !$invoice->is_sales;
Ansonsten sollte der Weg nicht ganz verkehrt sein.
Mit der Bitte um kurzes Feedback!
Testfälle gibt es auch nicht.