Adjustments for prepayment with underpayments
This commit is contained in:
parent
abf46e19ab
commit
19804f0574
|
|
@ -116,7 +116,6 @@ class InstantPayment
|
|||
$payable_amount = Number::roundValue(Number::parseFloat($payable_invoice['amount']), $client->currency()->precision);
|
||||
$invoice_balance = Number::roundValue(($invoice->partial > 0 ? $invoice->partial : $invoice->balance), $client->currency()->precision);
|
||||
|
||||
|
||||
/*If we don't allow under/over payments force the payable amount - prevents inspect element adjustments in JS*/
|
||||
|
||||
if ($settings->client_portal_allow_under_payment == false && $settings->client_portal_allow_over_payment == false) {
|
||||
|
|
|
|||
|
|
@ -97,6 +97,26 @@ class UpdateInvoicePayment
|
|||
if ($invoice->is_proforma) {
|
||||
//keep proforma's hidden
|
||||
if (property_exists($this->payment_hash->data, 'pre_payment') && $this->payment_hash->data->pre_payment == "1") {
|
||||
|
||||
if($invoice->balance != 0){
|
||||
$invoice->client->service()->updateBalance($invoice->balance*-1);
|
||||
$invoice->balance = 0;
|
||||
$invoice->status_id = \App\Models\Invoice::STATUS_PAID;
|
||||
$invoice->saveQuietly();
|
||||
|
||||
$invoice
|
||||
->ledger()
|
||||
->updateInvoiceBalance(($invoice->balance + $paid_amount) * -1, "Prepayment Balance Adjustment");
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
$invoice
|
||||
->ledger()
|
||||
->updateInvoiceBalance($paid_amount * -1, "Prepayment Balance Adjustment");
|
||||
|
||||
}
|
||||
|
||||
$invoice->payments()->each(function ($p) {
|
||||
$p->pivot->forceDelete();
|
||||
$p->invoices()->each(function ($i) {
|
||||
|
|
@ -104,11 +124,6 @@ class UpdateInvoicePayment
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
$invoice
|
||||
->ledger()
|
||||
->updateInvoiceBalance($paid_amount * -1, "Prepayment Balance Adjustment");
|
||||
|
||||
$invoice->is_deleted = true;
|
||||
$invoice->deleted_at = now();
|
||||
$invoice->saveQuietly();
|
||||
|
|
|
|||
Loading…
Reference in New Issue