Fixed issue with recurring invoices

This commit is contained in:
Hillel Coren 2015-11-02 08:51:57 +02:00
parent 3b6a4a6100
commit e08c80f23c
2 changed files with 16 additions and 7 deletions

View File

@ -106,11 +106,13 @@ class ActivityListener
public function deletedInvoice(InvoiceWasDeleted $event) public function deletedInvoice(InvoiceWasDeleted $event)
{ {
$invoice = $event->invoice;
$this->activityRepo->create( $this->activityRepo->create(
$event->invoice, $invoice,
ACTIVITY_TYPE_DELETE_INVOICE, ACTIVITY_TYPE_DELETE_INVOICE,
$event->invoice->balance * -1, $invoice->affectsBalance() ? $invoice->balance * -1 : 0,
$event->invoice->getAmountPaid() * -1 $invoice->affectsBalance() ? $invoice->getAmountPaid() * -1 : 0
); );
} }
@ -128,11 +130,13 @@ class ActivityListener
public function restoredInvoice(InvoiceWasRestored $event) public function restoredInvoice(InvoiceWasRestored $event)
{ {
$invoice = $event->invoice;
$this->activityRepo->create( $this->activityRepo->create(
$event->invoice, $invoice,
ACTIVITY_TYPE_RESTORE_INVOICE, ACTIVITY_TYPE_RESTORE_INVOICE,
$event->fromDeleted ? $event->invoice->balance : 0, $invoice->affectsBalance() && $event->fromDeleted ? $invoice->balance : 0,
$event->fromDeleted ? $event->invoice->getAmountPaid() : 0 $invoice->affectsBalance() && $event->fromDeleted ? $invoice->getAmountPaid() : 0
); );
} }

View File

@ -46,9 +46,14 @@ class Invoice extends EntityModel implements BalanceAffecting
return $this->is_recurring ? trans('texts.recurring') : $this->invoice_number; return $this->is_recurring ? trans('texts.recurring') : $this->invoice_number;
} }
public function affectsBalance()
{
return !$this->is_quote && !$this->is_recurring;
}
public function getAdjustment() public function getAdjustment()
{ {
if ($this->is_quote || $this->is_recurring) { if (!$this->affectsBalance()) {
return 0; return 0;
} }