mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Webhooks for Projects
This commit is contained in:
parent
f33f1d81e7
commit
e8e8598fd8
@ -48,6 +48,16 @@ class RecurringInvoiceToInvoiceFactory
|
||||
$invoice->custom_value4 = $recurring_invoice->custom_value4;
|
||||
$invoice->amount = $recurring_invoice->amount;
|
||||
$invoice->uses_inclusive_taxes = $recurring_invoice->uses_inclusive_taxes;
|
||||
|
||||
$invoice->custom_surcharge1 = $recurring_invoice->custom_surcharge1;
|
||||
$invoice->custom_surcharge2 = $recurring_invoice->custom_surcharge2;
|
||||
$invoice->custom_surcharge3 = $recurring_invoice->custom_surcharge3;
|
||||
$invoice->custom_surcharge4 = $recurring_invoice->custom_surcharge4;
|
||||
$invoice->custom_surcharge_tax1 = $recurring_invoice->custom_surcharge_tax1;
|
||||
$invoice->custom_surcharge_tax2 = $recurring_invoice->custom_surcharge_tax2;
|
||||
$invoice->custom_surcharge_tax3 = $recurring_invoice->custom_surcharge_tax3;
|
||||
$invoice->custom_surcharge_tax4 = $recurring_invoice->custom_surcharge_tax4;
|
||||
|
||||
// $invoice->balance = $recurring_invoice->balance;
|
||||
$invoice->user_id = $recurring_invoice->user_id;
|
||||
$invoice->assigned_user_id = $recurring_invoice->assigned_user_id;
|
||||
|
@ -42,7 +42,10 @@ class Webhook extends BaseModel
|
||||
const EVENT_LATE_INVOICE = 22;
|
||||
const EVENT_EXPIRED_QUOTE = 23;
|
||||
const EVENT_REMIND_INVOICE = 24;
|
||||
const EVENT_PROJECT_CREATE = 25;
|
||||
const EVENT_PROJECT_UPDATE = 26;
|
||||
|
||||
|
||||
public static $valid_events = [
|
||||
self::EVENT_CREATE_CLIENT,
|
||||
self::EVENT_CREATE_INVOICE,
|
||||
@ -68,6 +71,8 @@ class Webhook extends BaseModel
|
||||
self::EVENT_LATE_INVOICE,
|
||||
self::EVENT_EXPIRED_QUOTE,
|
||||
self::EVENT_REMIND_INVOICE,
|
||||
self::EVENT_PROJECT_CREATE,
|
||||
self::EVENT_PROJECT_UPDATE
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
|
89
app/Observers/ProjectObserver.php
Normal file
89
app/Observers/ProjectObserver.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Jobs\Util\WebhookHandler;
|
||||
use App\Models\Project;
|
||||
use App\Models\Webhook;
|
||||
|
||||
class ProjectObserver
|
||||
{
|
||||
public $afterCommit = true;
|
||||
/**
|
||||
* Handle the product "created" event.
|
||||
*
|
||||
* @param Project $project
|
||||
* @return void
|
||||
*/
|
||||
public function created(Project $project)
|
||||
{
|
||||
$subscriptions = Webhook::where('company_id', $project->company_id)
|
||||
->where('event_id', Webhook::EVENT_PROJECT_CREATE)
|
||||
->exists();
|
||||
|
||||
if ($subscriptions) {
|
||||
|
||||
WebhookHandler::dispatch(Webhook::EVENT_PROJECT_CREATE, $project, $project->company, 'client');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the product "updated" event.
|
||||
*
|
||||
* @param Project $project
|
||||
* @return void
|
||||
*/
|
||||
public function updated(Project $project)
|
||||
{
|
||||
$subscriptions = Webhook::where('company_id', $project->company_id)
|
||||
->where('event_id', Webhook::EVENT_PROJECT_UPDATE)
|
||||
->exists();
|
||||
|
||||
if ($subscriptions) {
|
||||
|
||||
WebhookHandler::dispatch(Webhook::EVENT_PROJECT_UPDATE, $project, $project->company, 'client');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the product "deleted" event.
|
||||
*
|
||||
* @param Project $project
|
||||
* @return void
|
||||
*/
|
||||
public function deleted(Project $project)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the product "restored" event.
|
||||
*
|
||||
* @param Project $project
|
||||
* @return void
|
||||
*/
|
||||
public function restored(Project $project)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the product "force deleted" event.
|
||||
*
|
||||
* @param Project $project
|
||||
* @return void
|
||||
*/
|
||||
public function forceDeleted(Project $project)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -213,6 +213,7 @@ use App\Models\Expense;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Product;
|
||||
use App\Models\Project;
|
||||
use App\Models\Proposal;
|
||||
use App\Models\Quote;
|
||||
use App\Models\Subscription;
|
||||
@ -228,6 +229,7 @@ use App\Observers\ExpenseObserver;
|
||||
use App\Observers\InvoiceObserver;
|
||||
use App\Observers\PaymentObserver;
|
||||
use App\Observers\ProductObserver;
|
||||
use App\Observers\ProjectObserver;
|
||||
use App\Observers\ProposalObserver;
|
||||
use App\Observers\QuoteObserver;
|
||||
use App\Observers\SubscriptionObserver;
|
||||
@ -586,6 +588,7 @@ class EventServiceProvider extends ServiceProvider
|
||||
Invoice::observe(InvoiceObserver::class);
|
||||
Payment::observe(PaymentObserver::class);
|
||||
Product::observe(ProductObserver::class);
|
||||
Project::observe(ProjectObserver::class);
|
||||
Proposal::observe(ProposalObserver::class);
|
||||
Quote::observe(QuoteObserver::class);
|
||||
Task::observe(TaskObserver::class);
|
||||
|
Loading…
x
Reference in New Issue
Block a user