mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 00:34:35 -04:00
Handle negative payments
This commit is contained in:
parent
60d9b4f649
commit
24c733827b
@ -185,7 +185,7 @@ class PaymentRepository extends BaseRepository {
|
|||||||
* @param $payment
|
* @param $payment
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private function processExchangeRates($data, $payment)
|
public function processExchangeRates($data, $payment)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(array_key_exists('exchange_rate', $data) && isset($data['exchange_rate']))
|
if(array_key_exists('exchange_rate', $data) && isset($data['exchange_rate']))
|
||||||
|
@ -16,6 +16,7 @@ use App\Jobs\Util\UnlinkFile;
|
|||||||
use App\Models\Credit;
|
use App\Models\Credit;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\PaymentType;
|
use App\Models\PaymentType;
|
||||||
|
use App\Repositories\CreditRepository;
|
||||||
use App\Repositories\PaymentRepository;
|
use App\Repositories\PaymentRepository;
|
||||||
use App\Services\Credit\CreateInvitations;
|
use App\Services\Credit\CreateInvitations;
|
||||||
use App\Services\Credit\TriggeredActions;
|
use App\Services\Credit\TriggeredActions;
|
||||||
@ -97,7 +98,7 @@ class CreditService
|
|||||||
if($this->credit->balance > 0)
|
if($this->credit->balance > 0)
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
$payment_repo = new PaymentRepository();
|
$payment_repo = new PaymentRepository(new CreditRepository());
|
||||||
|
|
||||||
//set credit balance to zero
|
//set credit balance to zero
|
||||||
$adjustment = $this->credit->balance;
|
$adjustment = $this->credit->balance;
|
||||||
@ -129,6 +130,7 @@ class CreditService
|
|||||||
//reduce client paid_to_date by $this->credit->balance amount
|
//reduce client paid_to_date by $this->credit->balance amount
|
||||||
$this->credit
|
$this->credit
|
||||||
->client
|
->client
|
||||||
|
->service()
|
||||||
->updatePaidToDate($adjustment)
|
->updatePaidToDate($adjustment)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ class AutoBillInvoice extends AbstractService
|
|||||||
info("Auto Bill payment captured for ".$this->invoice->number);
|
info("Auto Bill payment captured for ".$this->invoice->number);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->invoice;
|
return $this->invoice->fresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,8 +139,13 @@ class DeletePayment
|
|||||||
if ($this->payment->credits()->exists()) {
|
if ($this->payment->credits()->exists()) {
|
||||||
$this->payment->credits()->each(function ($paymentable_credit) {
|
$this->payment->credits()->each(function ($paymentable_credit) {
|
||||||
|
|
||||||
|
$multiplier = 1;
|
||||||
|
|
||||||
|
if($paymentable_credit->pivot->amount < 0)
|
||||||
|
$multiplier = -1;
|
||||||
|
|
||||||
$paymentable_credit->service()
|
$paymentable_credit->service()
|
||||||
->updateBalance($paymentable_credit->pivot->amount)
|
->updateBalance($paymentable_credit->pivot->amount*$multiplier)
|
||||||
->updatePaidToDate($paymentable_credit->pivot->amount*-1)
|
->updatePaidToDate($paymentable_credit->pivot->amount*-1)
|
||||||
->setStatus(Credit::STATUS_SENT)
|
->setStatus(Credit::STATUS_SENT)
|
||||||
->save();
|
->save();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user