mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Handle negative payments
This commit is contained in:
parent
60d9b4f649
commit
24c733827b
@ -185,7 +185,7 @@ class PaymentRepository extends BaseRepository {
|
||||
* @param $payment
|
||||
* @return
|
||||
*/
|
||||
private function processExchangeRates($data, $payment)
|
||||
public function processExchangeRates($data, $payment)
|
||||
{
|
||||
|
||||
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\Payment;
|
||||
use App\Models\PaymentType;
|
||||
use App\Repositories\CreditRepository;
|
||||
use App\Repositories\PaymentRepository;
|
||||
use App\Services\Credit\CreateInvitations;
|
||||
use App\Services\Credit\TriggeredActions;
|
||||
@ -97,7 +98,7 @@ class CreditService
|
||||
if($this->credit->balance > 0)
|
||||
return $this;
|
||||
|
||||
$payment_repo = new PaymentRepository();
|
||||
$payment_repo = new PaymentRepository(new CreditRepository());
|
||||
|
||||
//set credit balance to zero
|
||||
$adjustment = $this->credit->balance;
|
||||
@ -129,6 +130,7 @@ class CreditService
|
||||
//reduce client paid_to_date by $this->credit->balance amount
|
||||
$this->credit
|
||||
->client
|
||||
->service()
|
||||
->updatePaidToDate($adjustment)
|
||||
->save();
|
||||
|
||||
|
@ -130,7 +130,7 @@ class AutoBillInvoice extends AbstractService
|
||||
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()) {
|
||||
$this->payment->credits()->each(function ($paymentable_credit) {
|
||||
|
||||
$multiplier = 1;
|
||||
|
||||
if($paymentable_credit->pivot->amount < 0)
|
||||
$multiplier = -1;
|
||||
|
||||
$paymentable_credit->service()
|
||||
->updateBalance($paymentable_credit->pivot->amount)
|
||||
->updateBalance($paymentable_credit->pivot->amount*$multiplier)
|
||||
->updatePaidToDate($paymentable_credit->pivot->amount*-1)
|
||||
->setStatus(Credit::STATUS_SENT)
|
||||
->save();
|
||||
|
Loading…
x
Reference in New Issue
Block a user