mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on restoring deleted invoices
This commit is contained in:
parent
fa105210bb
commit
ea6cd9e012
@ -7,16 +7,19 @@ use Illuminate\Queue\SerializesModels;
|
|||||||
class InvoiceWasRestored extends Event {
|
class InvoiceWasRestored extends Event {
|
||||||
|
|
||||||
use SerializesModels;
|
use SerializesModels;
|
||||||
|
|
||||||
public $invoice;
|
public $invoice;
|
||||||
|
public $fromDeleted;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new event instance.
|
* Create a new event instance.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($invoice)
|
public function __construct($invoice, $fromDeleted)
|
||||||
{
|
{
|
||||||
$this->invoice = $invoice;
|
$this->invoice = $invoice;
|
||||||
|
$this->fromDeleted = $fromDeleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,16 +7,19 @@ use Illuminate\Queue\SerializesModels;
|
|||||||
class PaymentWasRestored extends Event {
|
class PaymentWasRestored extends Event {
|
||||||
|
|
||||||
use SerializesModels;
|
use SerializesModels;
|
||||||
|
|
||||||
public $payment;
|
public $payment;
|
||||||
|
public $fromDeleted;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new event instance.
|
* Create a new event instance.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($payment)
|
public function __construct($payment, $fromDeleted)
|
||||||
{
|
{
|
||||||
$this->payment = $payment;
|
$this->payment = $payment;
|
||||||
|
$this->fromDeleted = $fromDeleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
<?php namespace app\Listeners;
|
<?php namespace app\Listeners;
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use Utils;
|
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
|
|
||||||
use App\Events\ClientWasCreated;
|
use App\Events\ClientWasCreated;
|
||||||
use App\Events\ClientWasDeleted;
|
use App\Events\ClientWasDeleted;
|
||||||
use App\Events\ClientWasArchived;
|
use App\Events\ClientWasArchived;
|
||||||
use App\Events\ClientWasRestored;
|
use App\Events\ClientWasRestored;
|
||||||
|
|
||||||
use App\Events\InvoiceWasCreated;
|
use App\Events\InvoiceWasCreated;
|
||||||
use App\Events\InvoiceWasUpdated;
|
use App\Events\InvoiceWasUpdated;
|
||||||
use App\Events\InvoiceWasDeleted;
|
use App\Events\InvoiceWasDeleted;
|
||||||
@ -16,7 +12,6 @@ use App\Events\InvoiceWasArchived;
|
|||||||
use App\Events\InvoiceWasRestored;
|
use App\Events\InvoiceWasRestored;
|
||||||
use App\Events\InvoiceInvitationWasEmailed;
|
use App\Events\InvoiceInvitationWasEmailed;
|
||||||
use App\Events\InvoiceInvitationWasViewed;
|
use App\Events\InvoiceInvitationWasViewed;
|
||||||
|
|
||||||
use App\Events\QuoteWasCreated;
|
use App\Events\QuoteWasCreated;
|
||||||
use App\Events\QuoteWasUpdated;
|
use App\Events\QuoteWasUpdated;
|
||||||
use App\Events\QuoteWasDeleted;
|
use App\Events\QuoteWasDeleted;
|
||||||
@ -25,17 +20,14 @@ use App\Events\QuoteWasRestored;
|
|||||||
use App\Events\QuoteInvitationWasEmailed;
|
use App\Events\QuoteInvitationWasEmailed;
|
||||||
use App\Events\QuoteInvitationWasViewed;
|
use App\Events\QuoteInvitationWasViewed;
|
||||||
use App\Events\QuoteInvitationWasApproved;
|
use App\Events\QuoteInvitationWasApproved;
|
||||||
|
|
||||||
use App\Events\PaymentWasCreated;
|
use App\Events\PaymentWasCreated;
|
||||||
use App\Events\PaymentWasDeleted;
|
use App\Events\PaymentWasDeleted;
|
||||||
use App\Events\PaymentWasArchived;
|
use App\Events\PaymentWasArchived;
|
||||||
use App\Events\PaymentWasRestored;
|
use App\Events\PaymentWasRestored;
|
||||||
|
|
||||||
use App\Events\CreditWasCreated;
|
use App\Events\CreditWasCreated;
|
||||||
use App\Events\CreditWasDeleted;
|
use App\Events\CreditWasDeleted;
|
||||||
use App\Events\CreditWasArchived;
|
use App\Events\CreditWasArchived;
|
||||||
use App\Events\CreditWasRestored;
|
use App\Events\CreditWasRestored;
|
||||||
|
|
||||||
use App\Ninja\Repositories\ActivityRepository;
|
use App\Ninja\Repositories\ActivityRepository;
|
||||||
|
|
||||||
class ActivityListener
|
class ActivityListener
|
||||||
@ -84,7 +76,6 @@ class ActivityListener
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Invoices
|
// Invoices
|
||||||
public function createdInvoice(InvoiceWasCreated $event)
|
public function createdInvoice(InvoiceWasCreated $event)
|
||||||
{
|
{
|
||||||
@ -97,7 +88,7 @@ class ActivityListener
|
|||||||
|
|
||||||
public function updatedInvoice(InvoiceWasUpdated $event)
|
public function updatedInvoice(InvoiceWasUpdated $event)
|
||||||
{
|
{
|
||||||
if ( ! $event->invoice->isChanged()) {
|
if (! $event->invoice->isChanged()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +130,9 @@ class ActivityListener
|
|||||||
{
|
{
|
||||||
$this->activityRepo->create(
|
$this->activityRepo->create(
|
||||||
$event->invoice,
|
$event->invoice,
|
||||||
ACTIVITY_TYPE_RESTORE_INVOICE
|
ACTIVITY_TYPE_RESTORE_INVOICE,
|
||||||
|
$event->fromDeleted ? $event->invoice->balance : 0,
|
||||||
|
$event->fromDeleted ? $event->invoice->getAmountPaid() : 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +158,6 @@ class ActivityListener
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Quotes
|
// Quotes
|
||||||
public function createdQuote(QuoteWasCreated $event)
|
public function createdQuote(QuoteWasCreated $event)
|
||||||
{
|
{
|
||||||
@ -177,7 +169,7 @@ class ActivityListener
|
|||||||
|
|
||||||
public function updatedQuote(QuoteWasUpdated $event)
|
public function updatedQuote(QuoteWasUpdated $event)
|
||||||
{
|
{
|
||||||
if ( ! $event->quote->isChanged()) {
|
if (! $event->quote->isChanged()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,8 +177,7 @@ class ActivityListener
|
|||||||
|
|
||||||
$activity = $this->activityRepo->create(
|
$activity = $this->activityRepo->create(
|
||||||
$event->quote,
|
$event->quote,
|
||||||
ACTIVITY_TYPE_UPDATE_QUOTE,
|
ACTIVITY_TYPE_UPDATE_QUOTE
|
||||||
$event->quote->getAdjustment()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$activity->json_backup = $backupQuote->hidePrivateFields()->toJSON();
|
$activity->json_backup = $backupQuote->hidePrivateFields()->toJSON();
|
||||||
@ -254,7 +245,6 @@ class ActivityListener
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Credits
|
// Credits
|
||||||
public function createdCredit(CreditWasCreated $event)
|
public function createdCredit(CreditWasCreated $event)
|
||||||
{
|
{
|
||||||
@ -292,7 +282,6 @@ class ActivityListener
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Payments
|
// Payments
|
||||||
public function createdPayment(PaymentWasCreated $event)
|
public function createdPayment(PaymentWasCreated $event)
|
||||||
{
|
{
|
||||||
@ -333,5 +322,4 @@ class ActivityListener
|
|||||||
ACTIVITY_TYPE_RESTORE_PAYMENT
|
ACTIVITY_TYPE_RESTORE_PAYMENT
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,27 +13,32 @@ class BaseRepository
|
|||||||
return new $className();
|
return new $className();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function dispatchEvent($entity, $type)
|
private function getEventClass($entity, $type)
|
||||||
{
|
{
|
||||||
$className = 'App\Events\\' . ucfirst($entity->getEntityType()) . 'Was' . $type;
|
return 'App\Events\\' . ucfirst($entity->getEntityType()) . 'Was' . $type;
|
||||||
event(new $className($entity));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function archive($entity)
|
public function archive($entity)
|
||||||
{
|
{
|
||||||
$entity->delete();
|
$entity->delete();
|
||||||
|
|
||||||
$this->dispatchEvent($entity, 'Archived');
|
$className = $this->getEventClass($entity, 'Archived');
|
||||||
|
event(new $className($entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function restore($entity)
|
public function restore($entity)
|
||||||
{
|
{
|
||||||
|
$fromDeleted = false;
|
||||||
$entity->restore();
|
$entity->restore();
|
||||||
|
|
||||||
$entity->is_deleted = false;
|
if ($entity->is_deleted) {
|
||||||
$entity->save();
|
$fromDeleted = true;
|
||||||
|
$entity->is_deleted = false;
|
||||||
|
$entity->save();
|
||||||
|
}
|
||||||
|
|
||||||
$this->dispatchEvent($entity, 'Restored');
|
$className = $this->getEventClass($entity, 'Restored');
|
||||||
|
event(new $className($entity, $fromDeleted));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete($entity)
|
public function delete($entity)
|
||||||
@ -43,7 +48,8 @@ class BaseRepository
|
|||||||
|
|
||||||
$entity->delete();
|
$entity->delete();
|
||||||
|
|
||||||
$this->dispatchEvent($entity, 'Deleted');
|
$className = $this->getEventClass($entity, 'Deleted');
|
||||||
|
event(new $className($entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findByPublicIds($ids)
|
public function findByPublicIds($ids)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user