mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 15:34:35 -04:00
Fixes for handling partial payments with credits
This commit is contained in:
parent
84e634c28c
commit
a0d1635a58
@ -901,9 +901,10 @@ class BaseController extends Controller
|
|||||||
return redirect('/')->with(['signup' => 'true']);
|
return redirect('/')->with(['signup' => 'true']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 06-09-2022 - parse the path if loaded in a subdirectory for canvaskit resolution
|
||||||
$canvas_path_array = parse_url(config('ninja.app_url'));
|
$canvas_path_array = parse_url(config('ninja.app_url'));
|
||||||
|
|
||||||
$canvas_path = (array_key_exists('path', $canvas_path_array)) ? $canvas_path_array['path'] : '';
|
$canvas_path = (array_key_exists('path', $canvas_path_array)) ? $canvas_path_array['path'] : '';
|
||||||
|
$canvas_path = rtrim(str_replace("index.php", "", $canvas_path),'/');
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
|
@ -35,6 +35,9 @@ class AutoBillInvoice extends AbstractService
|
|||||||
|
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
|
/*Specific variable for partial payments */
|
||||||
|
private bool $is_partial_amount = false;
|
||||||
|
|
||||||
public function __construct(Invoice $invoice, $db)
|
public function __construct(Invoice $invoice, $db)
|
||||||
{
|
{
|
||||||
$this->invoice = $invoice;
|
$this->invoice = $invoice;
|
||||||
@ -46,7 +49,8 @@ class AutoBillInvoice extends AbstractService
|
|||||||
{
|
{
|
||||||
MultiDB::setDb($this->db);
|
MultiDB::setDb($this->db);
|
||||||
|
|
||||||
$this->client = $this->invoice->client->fresh();
|
/* Harvest Client*/
|
||||||
|
$this->client = $this->invoice->client;
|
||||||
|
|
||||||
$is_partial = false;
|
$is_partial = false;
|
||||||
|
|
||||||
@ -68,6 +72,10 @@ class AutoBillInvoice extends AbstractService
|
|||||||
$this->applyCreditPayment();
|
$this->applyCreditPayment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//If this returns true, it means a partial invoice amount was paid as a credit and there is no further balance payable
|
||||||
|
if($this->is_partial_amount && $this->invoice->partial == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
$amount = 0;
|
$amount = 0;
|
||||||
|
|
||||||
/* Determine $amount */
|
/* Determine $amount */
|
||||||
@ -170,7 +178,7 @@ class AutoBillInvoice extends AbstractService
|
|||||||
|
|
||||||
$this->invoice
|
$this->invoice
|
||||||
->service()
|
->service()
|
||||||
->setStatus(Invoice::STATUS_PAID)
|
->setCalculatedStatus()
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
foreach ($this->used_credit as $credit) {
|
foreach ($this->used_credit as $credit) {
|
||||||
@ -191,16 +199,16 @@ class AutoBillInvoice extends AbstractService
|
|||||||
->updatePaymentBalance($amount * -1)
|
->updatePaymentBalance($amount * -1)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
$client = $this->invoice->client->fresh();
|
$this->invoice
|
||||||
|
->client
|
||||||
$client->service()
|
->service()
|
||||||
->updateBalance($amount * -1)
|
->updateBalanceAndPaidToDate($amount * -1, $amount)
|
||||||
->updatePaidToDate($amount)
|
// ->updateBalance($amount * -1)
|
||||||
|
// ->updatePaidToDate($amount)
|
||||||
->adjustCreditBalance($amount * -1)
|
->adjustCreditBalance($amount * -1)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
$this->invoice->ledger() //09-03-2022
|
$this->invoice->ledger() //09-03-2022
|
||||||
// ->updateInvoiceBalance($amount * -1, "Invoice {$this->invoice->number} payment using Credit {$current_credit->number}")
|
|
||||||
->updateCreditBalance($amount * -1, "Credit {$current_credit->number} used to pay down Invoice {$this->invoice->number}")
|
->updateCreditBalance($amount * -1, "Credit {$current_credit->number} used to pay down Invoice {$this->invoice->number}")
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
@ -235,16 +243,14 @@ class AutoBillInvoice extends AbstractService
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_partial_amount = false;
|
|
||||||
|
|
||||||
if ($this->invoice->partial > 0) {
|
if ($this->invoice->partial > 0) {
|
||||||
$is_partial_amount = true;
|
$this->is_partial_amount = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->used_credit = [];
|
$this->used_credit = [];
|
||||||
|
|
||||||
foreach ($available_credits as $key => $credit) {
|
foreach ($available_credits as $key => $credit) {
|
||||||
if ($is_partial_amount) {
|
if ($this->is_partial_amount) {
|
||||||
|
|
||||||
//more credit than needed
|
//more credit than needed
|
||||||
if ($credit->balance > $this->invoice->partial) {
|
if ($credit->balance > $this->invoice->partial) {
|
||||||
|
@ -62,15 +62,17 @@ class UpdateInvoicePayment
|
|||||||
$paid_amount = $paid_invoice->amount;
|
$paid_amount = $paid_invoice->amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
\DB::connection(config('database.default'))->transaction(function () use($client, $paid_amount){
|
$client->service()->updateBalanceAndPaidToDate($paid_amount*-1, $paid_amount);
|
||||||
|
|
||||||
$update_client = Client::withTrashed()->where('id', $client->id)->lockForUpdate()->first();
|
// \DB::connection(config('database.default'))->transaction(function () use($client, $paid_amount){
|
||||||
|
|
||||||
$update_client->paid_to_date += $paid_amount;
|
// $update_client = Client::withTrashed()->where('id', $client->id)->lockForUpdate()->first();
|
||||||
$update_client->balance -= $paid_amount;
|
|
||||||
$update_client->save();
|
|
||||||
|
|
||||||
}, 1);
|
// $update_client->paid_to_date += $paid_amount;
|
||||||
|
// $update_client->balance -= $paid_amount;
|
||||||
|
// $update_client->save();
|
||||||
|
|
||||||
|
// }, 1);
|
||||||
|
|
||||||
/* Need to determine here is we have an OVER payment - if YES only apply the max invoice amount */
|
/* Need to determine here is we have an OVER payment - if YES only apply the max invoice amount */
|
||||||
if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance)
|
if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user