Factor in gateway fees to client / invoice balances

This commit is contained in:
David Bomba 2022-03-24 13:11:09 +11:00
parent 3cf13a3b57
commit 35f97d1b91
3 changed files with 63 additions and 2 deletions

View File

@ -322,8 +322,8 @@ class BaseDriver extends AbstractPaymentDriver
if (collect($invoice->line_items)->contains('type_id', '3')) {
$invoice->service()->toggleFeesPaid()->save();
$invoice->client->service()->updateBalance($fee_total)->save();
$invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for invoice {$invoice->number}");
// $invoice->client->service()->updateBalance($fee_total)->save();
// $invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for invoice {$invoice->number}");
}
$transaction = [

View File

@ -74,6 +74,8 @@ class AddGatewayFee extends AbstractService
private function processGatewayFee($gateway_fee)
{
$balance = $this->invoice->balance;
App::forgetInstance('translator');
$t = app('translator');
$t->replace(Ninja::transformTranslations($this->invoice->company->settings));
@ -100,11 +102,30 @@ class AddGatewayFee extends AbstractService
/**Refresh Invoice values*/
$this->invoice = $this->invoice->calc()->getInvoice();
$new_balance = $this->invoice->balance;
if(floatval($new_balance) - floatval($balance) != 0)
{
$adjustment = $new_balance - $balance;
$this->invoice
->client
->service()
->updateBalance($adjustment)
->save();
$this->invoice
->ledger()
->updateInvoiceBalance($adjustment, 'Adjustment for removing gateway fee');
}
return $this->invoice;
}
private function processGatewayDiscount($gateway_fee)
{
$balance = $this->invoice->balance;
App::forgetInstance('translator');
$t = app('translator');
$t->replace(Ninja::transformTranslations($this->invoice->company->settings));
@ -129,6 +150,25 @@ class AddGatewayFee extends AbstractService
$this->invoice = $this->invoice->calc()->getInvoice();
$new_balance = $this->invoice->balance;
if(floatval($new_balance) - floatval($balance) != 0)
{
$adjustment = $new_balance - $balance;
$this->invoice
->client
->service()
->updateBalance($adjustment * -1)
->save();
$this->invoice
->ledger()
->updateInvoiceBalance($adjustment * -1, 'Adjustment for removing gateway fee');
}
return $this->invoice;
}
}

View File

@ -361,6 +361,8 @@ class InvoiceService
public function removeUnpaidGatewayFees()
{
$balance = $this->invoice->balance;
//return early if type three does not exist.
if(!collect($this->invoice->line_items)->contains('type_id', 3))
return $this;
@ -372,6 +374,25 @@ class InvoiceService
$this->invoice = $this->invoice->calc()->getInvoice();
/* 24-03-2022 */
$new_balance = $this->invoice->balance;
if(floatval($balance) - floatval($new_balance) != 0)
{
$adjustment = $balance - $new_balance;
$this->invoice
->client
->service()
->updateBalance($adjustment * -1)
->save();
$this->invoice
->ledger()
->updateInvoiceBalance($adjustment * -1, 'Adjustment for removing gateway fee');
}
return $this;
}