mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
commit
768d26c2ed
@ -12,6 +12,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\DataMapper\ClientSettings;
|
||||
use App\Jobs\Util\WebhookHandler;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\UserSessionAttributes;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@ -167,7 +168,7 @@ class BaseModel extends Model
|
||||
*/
|
||||
public function resolveRouteBinding($value, $field = null)
|
||||
{
|
||||
|
||||
|
||||
if (is_numeric($value)) {
|
||||
throw new ModelNotFoundException("Record with value {$value} not found");
|
||||
}
|
||||
@ -189,12 +190,12 @@ class BaseModel extends Model
|
||||
|
||||
public function numberFormatter()
|
||||
{
|
||||
$number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);
|
||||
$number = strlen($this->number) >= 1 ? $this->translate_entity() . "_" . $this->number : class_basename($this) . "_" . Str::random(5);
|
||||
|
||||
$formatted_number = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $number);
|
||||
|
||||
|
||||
$formatted_number = mb_ereg_replace("([\.]{2,})", '', $formatted_number);
|
||||
|
||||
|
||||
$formatted_number = preg_replace('/\s+/', '_', $formatted_number);
|
||||
|
||||
return $formatted_number;
|
||||
@ -205,4 +206,14 @@ class BaseModel extends Model
|
||||
return ctrans('texts.item');
|
||||
}
|
||||
|
||||
public function sendEvent($event_id, $additional_data=""){
|
||||
$subscriptions = Webhook::where('company_id', $this->company_id)
|
||||
->where('event_id', $event_id)
|
||||
->exists();
|
||||
if ($subscriptions) {
|
||||
WebhookHandler::dispatch($event_id, $this, $this->company, $additional_data)->delay(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -136,6 +136,14 @@ class Webhook extends BaseModel
|
||||
|
||||
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 = [
|
||||
self::EVENT_CREATE_PURCHASE_ORDER,
|
||||
self::EVENT_UPDATE_PURCHASE_ORDER,
|
||||
@ -194,7 +202,11 @@ class Webhook extends BaseModel
|
||||
self::EVENT_RESTORE_QUOTE,
|
||||
self::EVENT_RESTORE_INVOICE,
|
||||
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;
|
||||
|
||||
use App\Events\Credit\CreditWasMarkedSent;
|
||||
use App\Jobs\Util\WebhookHandler;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Webhook;
|
||||
use App\Utils\Ninja;
|
||||
|
||||
class MarkSent
|
||||
@ -49,9 +51,11 @@ class MarkSent
|
||||
->service()
|
||||
->adjustCreditBalance($this->credit->amount)
|
||||
->save();
|
||||
|
||||
|
||||
event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
$this->credit->sendEvent(Webhook::EVENT_SENT_CREDIT);
|
||||
|
||||
return $this->credit;
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,10 @@
|
||||
namespace App\Services\Invoice;
|
||||
|
||||
use App\Events\Invoice\InvoiceWasUpdated;
|
||||
use App\Jobs\Util\WebhookHandler;
|
||||
use App\Models\Client;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Webhook;
|
||||
use App\Services\AbstractService;
|
||||
use App\Utils\Ninja;
|
||||
|
||||
@ -71,6 +73,7 @@ class MarkSent extends AbstractService
|
||||
if($fire_webhook)
|
||||
event('eloquent.updated: App\Models\Invoice', $this->invoice);
|
||||
|
||||
$this->invoice->sendEvent(Webhook::EVENT_SENT_INVOICE, "client");
|
||||
|
||||
return $this->invoice->fresh();
|
||||
}
|
||||
|
@ -11,7 +11,9 @@
|
||||
|
||||
namespace App\Services\PurchaseOrder;
|
||||
|
||||
use App\Jobs\Util\WebhookHandler;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\Webhook;
|
||||
use App\Utils\Ninja;
|
||||
|
||||
class MarkSent
|
||||
@ -43,6 +45,8 @@ class MarkSent
|
||||
->adjustBalance($this->purchase_order->amount) //why was this commented out previously?
|
||||
->save();
|
||||
|
||||
$this->purchase_order->sendEvent(Webhook::EVENT_SENT_PURCHASE_ORDER, "vendor");
|
||||
|
||||
return $this->purchase_order;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,9 @@
|
||||
namespace App\Services\Quote;
|
||||
|
||||
use App\Events\Quote\QuoteWasMarkedSent;
|
||||
use App\Jobs\Util\WebhookHandler;
|
||||
use App\Models\Quote;
|
||||
use App\Models\Webhook;
|
||||
use App\Utils\Ninja;
|
||||
use Carbon\Carbon;
|
||||
|
||||
@ -52,6 +54,8 @@ class MarkSent
|
||||
|
||||
event(new QuoteWasMarkedSent($this->quote, $this->quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
$this->quote->sendEvent(Webhook::EVENT_SENT_QUOTE, "client");
|
||||
|
||||
return $this->quote;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user