mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for applying payments
This commit is contained in:
parent
49d848e9c7
commit
9332be7831
@ -35,40 +35,41 @@ class ApplyPayment extends AbstractService
|
|||||||
|
|
||||||
$amount_paid = $this->payment_amount * -1;
|
$amount_paid = $this->payment_amount * -1;
|
||||||
|
|
||||||
$this->invoice->service()->clearPartial()->setDueDate()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($amount_paid)->save();
|
$this->invoice->service()->clearPartial()->setDueDate()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($amount_paid)->updatePaidToDate($amount_paid*-1)->save();
|
||||||
} elseif ($this->invoice->partial > 0 && $this->invoice->partial > $this->payment_amount) {
|
} elseif ($this->invoice->partial > 0 && $this->invoice->partial > $this->payment_amount) {
|
||||||
//partial amount exists, but the amount is less than the partial amount
|
//partial amount exists, but the amount is less than the partial amount
|
||||||
|
|
||||||
$amount_paid = $this->payment_amount * -1;
|
$amount_paid = $this->payment_amount * -1;
|
||||||
|
|
||||||
$this->invoice->service()->updatePartial($amount_paid)->updateBalance($amount_paid)->save();
|
$this->invoice->service()->updatePartial($amount_paid)->updateBalance($amount_paid)->updatePaidToDate($amount_paid*-1)->save();
|
||||||
} elseif ($this->invoice->partial > 0 && $this->invoice->partial < $this->payment_amount) {
|
} elseif ($this->invoice->partial > 0 && $this->invoice->partial < $this->payment_amount) {
|
||||||
//partial exists and the amount paid is GREATER than the partial amount
|
//partial exists and the amount paid is GREATER than the partial amount
|
||||||
|
|
||||||
$amount_paid = $this->payment_amount * -1;
|
$amount_paid = $this->payment_amount * -1;
|
||||||
|
|
||||||
$this->invoice->service()->clearPartial()->setDueDate()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($amount_paid)->save();
|
$this->invoice->service()->clearPartial()->setDueDate()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($amount_paid)->updatePaidToDate($amount_paid*-1)->save();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($this->payment_amount == $this->invoice->balance) {
|
if ($this->payment_amount == $this->invoice->balance) {
|
||||||
$amount_paid = $this->payment_amount * -1;
|
$amount_paid = $this->payment_amount * -1;
|
||||||
|
|
||||||
$this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PAID)->updateBalance($amount_paid)->save();
|
$this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PAID)->updateBalance($amount_paid)->updatePaidToDate($amount_paid*-1)->save();
|
||||||
} elseif ($this->payment_amount < $this->invoice->balance) {
|
} elseif ($this->payment_amount < $this->invoice->balance) {
|
||||||
//partial invoice payment made
|
//partial invoice payment made
|
||||||
|
|
||||||
$amount_paid = $this->payment_amount * -1;
|
$amount_paid = $this->payment_amount * -1;
|
||||||
|
|
||||||
$this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($amount_paid)->save();
|
$this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($amount_paid)->updatePaidToDate($amount_paid*-1)->save();
|
||||||
} elseif ($this->payment_amount > $this->invoice->balance) {
|
} elseif ($this->payment_amount > $this->invoice->balance) {
|
||||||
//partial invoice payment made
|
//partial invoice payment made
|
||||||
|
|
||||||
$amount_paid = $this->invoice->balance * -1;
|
$amount_paid = $this->invoice->balance * -1;
|
||||||
|
|
||||||
$this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PAID)->updateBalance($amount_paid)->save();
|
$this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PAID)->updateBalance($amount_paid)->updatePaidToDate($amount_paid*-1)->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nlog($this->invoice->id. " " . $this->invoice->paid_to_date);
|
||||||
$this->payment
|
$this->payment
|
||||||
->ledger()
|
->ledger()
|
||||||
->updatePaymentBalance($amount_paid);
|
->updatePaymentBalance($amount_paid);
|
||||||
@ -81,22 +82,23 @@ class ApplyPayment extends AbstractService
|
|||||||
->updateBalance($amount_paid)
|
->updateBalance($amount_paid)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
/* Update Pivot Record amount */
|
// /* Update Pivot Record amount */
|
||||||
$this->payment->invoices->each(function ($inv) use ($amount_paid) {
|
// $this->payment->invoices->each(function ($inv) use ($amount_paid) {
|
||||||
if ($inv->id == $this->invoice->id) {
|
// if ($inv->id == $this->invoice->id) {
|
||||||
// $inv->pivot->amount = ($amount_paid * -1);
|
// // $inv->pivot->amount = ($amount_paid * -1);
|
||||||
// $inv->pivot->save();
|
// // $inv->pivot->save();
|
||||||
//25-06-2023
|
// //25-06-2023
|
||||||
$inv->paid_to_date += floatval($amount_paid * -1);
|
// nlog($inv);
|
||||||
$inv->save();
|
// nlog($amount_paid);
|
||||||
}
|
// $inv->paid_to_date += floatval($amount_paid * -1);
|
||||||
});
|
// $inv->save();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
$this->invoice
|
$this->invoice
|
||||||
->service()
|
->service()
|
||||||
->applyNumber()
|
->applyNumber()
|
||||||
->workFlow()
|
->workFlow()
|
||||||
// ->deletePdf()
|
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
return $this->invoice;
|
return $this->invoice;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user