mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Improve app state by ensuring a invitation is always present for an entity when a contact is deleted
This commit is contained in:
parent
61237f0475
commit
784d28ef0f
@ -12,6 +12,9 @@
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Models\QuoteInvitation;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
|
||||
class ClientContactObserver
|
||||
{
|
||||
@ -45,10 +48,38 @@ class ClientContactObserver
|
||||
*/
|
||||
public function deleted(ClientContact $clientContact)
|
||||
{
|
||||
$client_contact_id = $clientContact->id;
|
||||
|
||||
$clientContact->invoice_invitations()->delete();
|
||||
$clientContact->quote_invitations()->delete();
|
||||
$clientContact->credit_invitations()->delete();
|
||||
$clientContact->recurring_invoice_invitations()->delete();
|
||||
|
||||
//ensure entity state is preserved
|
||||
|
||||
InvoiceInvitation::withTrashed()->where('client_contact_id', 1)->cursor()->each(function ($invite){
|
||||
|
||||
if($invite->invoice()->doesnthave('invitations'))
|
||||
$invite->invoice->service()->createInvitations();
|
||||
|
||||
});
|
||||
|
||||
|
||||
QuoteInvitation::withTrashed()->where('client_contact_id', 1)->cursor()->each(function ($invite){
|
||||
|
||||
if($invite->invoice()->doesnthave('invitations'))
|
||||
$invite->quote->service()->createInvitations();
|
||||
|
||||
});
|
||||
|
||||
RecurringInvoiceInvitation::withTrashed()->where('client_contact_id', 1)->cursor()->each(function ($invite){
|
||||
|
||||
if($invite->recurring_invoice()->doesnthave('invitations'))
|
||||
$invite->quote->service()->createInvitations();
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
85
app/Observers/VendorContactObserver.php
Normal file
85
app/Observers/VendorContactObserver.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\PurchaseOrderInvitation;
|
||||
use App\Models\VendorContact;
|
||||
|
||||
class VendorContactObserver
|
||||
{
|
||||
/**
|
||||
* Handle the vendor contact "created" event.
|
||||
*
|
||||
* @param VendorContact $vendorContact
|
||||
* @return void
|
||||
*/
|
||||
public function created(VendorContact $vendorContact)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the vendor contact "updated" event.
|
||||
*
|
||||
* @param VendorContact $vendorContact
|
||||
* @return void
|
||||
*/
|
||||
public function updated(VendorContact $vendorContact)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the vendor contact "deleted" event.
|
||||
*
|
||||
* @param VendorContact $vendorContact
|
||||
* @return void
|
||||
*/
|
||||
public function deleted(VendorContact $vendorContact)
|
||||
{
|
||||
|
||||
$vendor_contact_id = $vendorContact->id;
|
||||
|
||||
$vendorContact->purchase_order_invitations()->delete();
|
||||
|
||||
PurchaseOrderInvitation::withTrashed()->where('vendor_contact_id', 1)->cursor()->each(function ($invite){
|
||||
|
||||
if($invite->purchase_order()->doesnthave('invitations'))
|
||||
$invite->purchase_order->service()->createInvitations();
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the vendor contact "restored" event.
|
||||
*
|
||||
* @param VendorContact $vendorContact
|
||||
* @return void
|
||||
*/
|
||||
public function restored(VendorContact $vendorContact)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the vendor contact "force deleted" event.
|
||||
*
|
||||
* @param VendorContact $vendorContact
|
||||
* @return void
|
||||
*/
|
||||
public function forceDeleted(VendorContact $vendorContact)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -241,6 +241,7 @@ use App\Models\Quote;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
use App\Models\VendorContact;
|
||||
use App\Observers\AccountObserver;
|
||||
use App\Observers\ClientContactObserver;
|
||||
use App\Observers\ClientObserver;
|
||||
@ -257,6 +258,7 @@ use App\Observers\ProposalObserver;
|
||||
use App\Observers\PurchaseOrderObserver;
|
||||
use App\Observers\QuoteObserver;
|
||||
use App\Observers\SubscriptionObserver;
|
||||
use App\Observers\VendorContactObserver;
|
||||
use App\Observers\TaskObserver;
|
||||
use App\Observers\UserObserver;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
@ -649,6 +651,7 @@ class EventServiceProvider extends ServiceProvider
|
||||
Quote::observe(QuoteObserver::class);
|
||||
Task::observe(TaskObserver::class);
|
||||
User::observe(UserObserver::class);
|
||||
VendorContact::observe(VendorContactObserver::class);
|
||||
PurchaseOrder::observe(PurchaseOrderObserver::class);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user