mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for autobill
This commit is contained in:
parent
3139539f46
commit
2d0e1a53f2
@ -112,6 +112,7 @@ class CreateSingleAccount extends Command
|
||||
$company = Company::factory()->create([
|
||||
'account_id' => $account->id,
|
||||
'slack_webhook_url' => config('ninja.notification.slack'),
|
||||
'use_credits_payment' => 'always',
|
||||
]);
|
||||
|
||||
$account->default_company_id = $company->id;
|
||||
|
@ -82,7 +82,7 @@ class BaseMailerJob implements ShouldQueue
|
||||
public function failed($exception = null)
|
||||
{
|
||||
|
||||
info('the job failed');
|
||||
// info('the job failed');
|
||||
|
||||
$job_failure = new EmailFailure();
|
||||
$job_failure->string_metric5 = get_parent_class($this);
|
||||
|
@ -55,6 +55,19 @@ class CreditService
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCalculatedStatus()
|
||||
{
|
||||
|
||||
if((int)$this->credit->balance == 0)
|
||||
$this->credit->status_id = Credit::STATUS_APPLIED;
|
||||
elseif((string)$this->credit->amount == (string)$this->credit->balance)
|
||||
$this->credit->status_id = Credit::STATUS_SENT;
|
||||
elseif($this->credit->balance > 0)
|
||||
$this->credit->status_id = Credit::STATUS_PARTIAL;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function markSent()
|
||||
{
|
||||
$this->credit = (new MarkSent($this->credit->client, $this->credit))->run();
|
||||
@ -69,6 +82,13 @@ class CreditService
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function adjustBalance($adjustment)
|
||||
{
|
||||
$this->credit->balance += $adjustment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the credit.
|
||||
* @return Credit object
|
||||
|
@ -68,7 +68,7 @@ class AutoBillInvoice extends AbstractService
|
||||
elseif($this->invoice->balance > 0)
|
||||
$amount = $this->invoice->balance;
|
||||
else
|
||||
return $this->finalizePaymentUsingCredits();
|
||||
return $this->invoice;
|
||||
|
||||
info("balance remains to be paid!!");
|
||||
|
||||
@ -127,8 +127,11 @@ class AutoBillInvoice extends AbstractService
|
||||
$current_credit = Credit::find($credit['credit_id']);
|
||||
$payment->credits()->attach($current_credit->id, ['amount' => $credit['amount']]);
|
||||
|
||||
info("adjusting credit balance {$current_credit->balance} by this amount ". $credit['amount']);
|
||||
|
||||
$current_credit->balance -= $credit['amount'];
|
||||
$current_credit->save();
|
||||
|
||||
$current_credit->service()->setCalculatedStatus()->save();
|
||||
// $this->applyPaymentToCredit($current_credit, $credit['amount']);
|
||||
}
|
||||
|
||||
@ -147,9 +150,9 @@ class AutoBillInvoice extends AbstractService
|
||||
->updateCreditBalance($amount * -1, 'Credits used to pay down Invoice ' . $this->invoice->number)
|
||||
->save();
|
||||
|
||||
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
|
||||
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
|
||||
|
||||
return $this->invoice->service()->setStatus(Invoice::STATUS_PAID)->save();
|
||||
return $this->invoice->service()->setCalculatedStatus()->save();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,6 +172,8 @@ class AutoBillInvoice extends AbstractService
|
||||
|
||||
$available_credit_balance = $available_credits->sum('balance');
|
||||
|
||||
info("available credit balance = {$available_credit_balance}");
|
||||
|
||||
if((int)$available_credit_balance == 0)
|
||||
return;
|
||||
|
||||
@ -217,7 +222,7 @@ class AutoBillInvoice extends AbstractService
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->finalizePaymentUsingCredits();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -210,6 +210,16 @@ class InvoiceService
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCalculatedStatus()
|
||||
{
|
||||
if((int)$this->invoice->balance == 0)
|
||||
$this->setStatus(Invoice::STATUS_PAID);
|
||||
elseif($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount)
|
||||
$this->setStatus(Invoice::STATUS_PARTIAL);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function updateStatus()
|
||||
{
|
||||
info("invoice balance = {$this->invoice->balance}");
|
||||
|
Loading…
x
Reference in New Issue
Block a user