mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Added models and implemented the sent Webhook
This commit is contained in:
parent
052ca31297
commit
d0cfaff6d6
@ -136,6 +136,14 @@ class Webhook extends BaseModel
|
|||||||
|
|
||||||
const EVENT_ARCHIVE_PURCHASE_ORDER = 59; //tested
|
const EVENT_ARCHIVE_PURCHASE_ORDER = 59; //tested
|
||||||
|
|
||||||
|
const EVENT_SENT_INVOICE = 60;
|
||||||
|
|
||||||
|
const EVENT_SENT_QUOTE = 61;
|
||||||
|
|
||||||
|
const EVENT_SENT_CREDIT = 62;
|
||||||
|
|
||||||
|
const EVENT_SENT_PURCHASE_ORDER = 63;
|
||||||
|
|
||||||
public static $valid_events = [
|
public static $valid_events = [
|
||||||
self::EVENT_CREATE_PURCHASE_ORDER,
|
self::EVENT_CREATE_PURCHASE_ORDER,
|
||||||
self::EVENT_UPDATE_PURCHASE_ORDER,
|
self::EVENT_UPDATE_PURCHASE_ORDER,
|
||||||
@ -194,7 +202,11 @@ class Webhook extends BaseModel
|
|||||||
self::EVENT_RESTORE_QUOTE,
|
self::EVENT_RESTORE_QUOTE,
|
||||||
self::EVENT_RESTORE_INVOICE,
|
self::EVENT_RESTORE_INVOICE,
|
||||||
self::EVENT_RESTORE_PAYMENT,
|
self::EVENT_RESTORE_PAYMENT,
|
||||||
self::EVENT_RESTORE_VENDOR
|
self::EVENT_RESTORE_VENDOR,
|
||||||
|
self::EVENT_SENT_INVOICE,
|
||||||
|
self::EVENT_SENT_QUOTE,
|
||||||
|
self::EVENT_SENT_CREDIT,
|
||||||
|
self::EVENT_SENT_PURCHASE_ORDER
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
namespace App\Services\Credit;
|
namespace App\Services\Credit;
|
||||||
|
|
||||||
use App\Events\Credit\CreditWasMarkedSent;
|
use App\Events\Credit\CreditWasMarkedSent;
|
||||||
|
use App\Jobs\Util\WebhookHandler;
|
||||||
use App\Models\Credit;
|
use App\Models\Credit;
|
||||||
|
use App\Models\Webhook;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
|
|
||||||
class MarkSent
|
class MarkSent
|
||||||
@ -49,9 +51,17 @@ class MarkSent
|
|||||||
->service()
|
->service()
|
||||||
->adjustCreditBalance($this->credit->amount)
|
->adjustCreditBalance($this->credit->amount)
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||||
|
|
||||||
|
$subscriptions = Webhook::where('company_id', $this->credit->company_id)
|
||||||
|
->where('event_id', Webhook::EVENT_SENT_CREDIT)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($subscriptions) {
|
||||||
|
WebhookHandler::dispatch(Webhook::EVENT_SENT_CREDIT, $this->credit, $this->credit->company)->delay(0);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->credit;
|
return $this->credit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,10 @@
|
|||||||
namespace App\Services\Invoice;
|
namespace App\Services\Invoice;
|
||||||
|
|
||||||
use App\Events\Invoice\InvoiceWasUpdated;
|
use App\Events\Invoice\InvoiceWasUpdated;
|
||||||
|
use App\Jobs\Util\WebhookHandler;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Webhook;
|
||||||
use App\Services\AbstractService;
|
use App\Services\AbstractService;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
|
|
||||||
@ -70,8 +72,8 @@ class MarkSent extends AbstractService
|
|||||||
|
|
||||||
if($fire_webhook)
|
if($fire_webhook)
|
||||||
event('eloquent.updated: App\Models\Invoice', $this->invoice);
|
event('eloquent.updated: App\Models\Invoice', $this->invoice);
|
||||||
|
|
||||||
$subscriptions = Webhook::where('company_id', $invoice->company_id)
|
$subscriptions = Webhook::where('company_id', $this->invoice->company_id)
|
||||||
->where('event_id', Webhook::EVENT_SENT_INVOICE)
|
->where('event_id', Webhook::EVENT_SENT_INVOICE)
|
||||||
->exists();
|
->exists();
|
||||||
|
|
||||||
|
@ -11,7 +11,9 @@
|
|||||||
|
|
||||||
namespace App\Services\PurchaseOrder;
|
namespace App\Services\PurchaseOrder;
|
||||||
|
|
||||||
|
use App\Jobs\Util\WebhookHandler;
|
||||||
use App\Models\PurchaseOrder;
|
use App\Models\PurchaseOrder;
|
||||||
|
use App\Models\Webhook;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
|
|
||||||
class MarkSent
|
class MarkSent
|
||||||
@ -43,6 +45,13 @@ class MarkSent
|
|||||||
->adjustBalance($this->purchase_order->amount) //why was this commented out previously?
|
->adjustBalance($this->purchase_order->amount) //why was this commented out previously?
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
|
$subscriptions = Webhook::where('company_id', $this->purchase_order->company_id)
|
||||||
|
->where('event_id', Webhook::EVENT_SENT_PURCHASE_ORDER)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($subscriptions)
|
||||||
|
WebhookHandler::dispatch(Webhook::EVENT_SENT_PURCHASE_ORDER, $this->purchase_order, $this->purchase_order->company, 'vendor')->delay(0);
|
||||||
|
|
||||||
return $this->purchase_order;
|
return $this->purchase_order;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
namespace App\Services\Quote;
|
namespace App\Services\Quote;
|
||||||
|
|
||||||
use App\Events\Quote\QuoteWasMarkedSent;
|
use App\Events\Quote\QuoteWasMarkedSent;
|
||||||
|
use App\Jobs\Util\WebhookHandler;
|
||||||
use App\Models\Quote;
|
use App\Models\Quote;
|
||||||
|
use App\Models\Webhook;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
||||||
@ -52,6 +54,13 @@ class MarkSent
|
|||||||
|
|
||||||
event(new QuoteWasMarkedSent($this->quote, $this->quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
event(new QuoteWasMarkedSent($this->quote, $this->quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||||
|
|
||||||
|
$subscriptions = Webhook::where('company_id', $this->quote->company_id)
|
||||||
|
->where('event_id', Webhook::EVENT_SENT_QUOTE)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($subscriptions)
|
||||||
|
WebhookHandler::dispatch(Webhook::EVENT_SENT_QUOTE, $this->quote, $this->quote->company, 'client')->delay(0);
|
||||||
|
|
||||||
return $this->quote;
|
return $this->quote;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user