Move invoice archive to Base Repository

This commit is contained in:
Lars Kusch 2023-01-30 08:02:02 +01:00
parent 949722ff57
commit 0f05065279
2 changed files with 34 additions and 39 deletions

View File

@ -93,18 +93,4 @@ class InvoiceObserver
{
//
}
/**
* @param Invoice $invoice
* @return void
*/
public function archived(Invoice $invoice){
$subscriptions = Webhook::where('company_id', $invoice->company_id)
->where('event_id', Webhook::EVENT_ARCHIVE_INVOICE)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(2));
}
}
}

View File

@ -12,6 +12,7 @@
namespace App\Repositories;
use App\Jobs\Product\UpdateOrCreateProduct;
use App\Jobs\Util\WebhookHandler;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Company;
@ -19,6 +20,7 @@ use App\Models\Credit;
use App\Models\Invoice;
use App\Models\Quote;
use App\Models\RecurringInvoice;
use App\Models\Webhook;
use App\Utils\Helpers;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
@ -60,6 +62,13 @@ class BaseRepository
if (class_exists($className)) {
event(new $className($entity, $entity->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
$subscriptions = Webhook::where('company_id', $entity->company_id)
->where('event_id', Webhook::EVENT_ARCHIVE_INVOICE)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_ARCHIVE_INVOICE, $entity, $entity->company, 'client')->delay(now()->addSeconds(2));
}
}
}