mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Fixes for observers
This commit is contained in:
parent
0cfe5bc39a
commit
dc116013d9
@ -203,7 +203,7 @@ class InvoiceSum
|
||||
{
|
||||
//Build invoice values here and return Invoice
|
||||
$this->setCalculatedAttributes();
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
@ -211,7 +211,7 @@ class InvoiceSum
|
||||
public function getQuote()
|
||||
{
|
||||
$this->setCalculatedAttributes();
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
@ -219,7 +219,7 @@ class InvoiceSum
|
||||
public function getCredit()
|
||||
{
|
||||
$this->setCalculatedAttributes();
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
@ -230,7 +230,7 @@ class InvoiceSum
|
||||
$this->invoice->total_taxes = $this->getTotalTaxes();
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ class InvoiceSumInclusive
|
||||
$this->invoice->total_taxes = $this->getTotalTaxes();
|
||||
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision);
|
||||
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
@ -206,7 +206,7 @@ class InvoiceSumInclusive
|
||||
{
|
||||
//Build invoice values here and return Invoice
|
||||
$this->setCalculatedAttributes();
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
@ -215,7 +215,7 @@ class InvoiceSumInclusive
|
||||
{
|
||||
//Build invoice values here and return Invoice
|
||||
$this->setCalculatedAttributes();
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
@ -224,7 +224,7 @@ class InvoiceSumInclusive
|
||||
{
|
||||
//Build invoice values here and return Invoice
|
||||
$this->setCalculatedAttributes();
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ class RecurringInvoiceController extends BaseController
|
||||
|
||||
$offset = $recurring_invoice->client->timezone_offset();
|
||||
$recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->startOfDay()->addSeconds($offset);
|
||||
$recurring_invoice->save();
|
||||
$recurring_invoice->saveQuietly();
|
||||
|
||||
$recurring_invoice->service()
|
||||
->triggeredActions($request)
|
||||
|
@ -23,7 +23,7 @@ class UpdateAutoBilling extends Component
|
||||
{
|
||||
if ($this->invoice->auto_bill == 'optin' || $this->invoice->auto_bill == 'optout') {
|
||||
$this->invoice->auto_bill_enabled = !$this->invoice->auto_bill_enabled;
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ class CreateEntityPdf implements ShouldQueue
|
||||
public function handle()
|
||||
{
|
||||
$start = microtime(true);
|
||||
nlog("Start ". $start);
|
||||
// nlog("Start ". $start);
|
||||
|
||||
/* Forget the singleton*/
|
||||
App::forgetInstance('translator');
|
||||
@ -154,7 +154,7 @@ class CreateEntityPdf implements ShouldQueue
|
||||
$html = new HtmlEngine($this->invitation);
|
||||
|
||||
$design_time = microtime(true);
|
||||
nlog("Design ". $design_time - $translate);
|
||||
// nlog("Design ". $design_time - $translate);
|
||||
|
||||
if ($design->is_custom) {
|
||||
$options = [
|
||||
@ -168,7 +168,7 @@ class CreateEntityPdf implements ShouldQueue
|
||||
$variables = $html->generateLabelsAndValues();
|
||||
|
||||
$labels_time = microtime(true);
|
||||
nlog("Labels ". $labels_time - $design_time);
|
||||
// nlog("Labels ". $labels_time - $design_time);
|
||||
|
||||
$state = [
|
||||
'template' => $template->elements([
|
||||
@ -194,7 +194,7 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
|
||||
$template_time = microtime(true);
|
||||
nlog("Template Build ". $template_time - $labels_time);
|
||||
// nlog("Template Build ". $template_time - $labels_time);
|
||||
|
||||
$pdf = null;
|
||||
|
||||
@ -217,7 +217,7 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
|
||||
$pdf_time = microtime(true);
|
||||
nlog("PDF time " . $pdf_time - $template_time);
|
||||
// nlog("PDF time " . $pdf_time - $template_time);
|
||||
|
||||
if ($pdf) {
|
||||
|
||||
|
@ -43,18 +43,19 @@ class WebhookHandler implements ShouldQueue
|
||||
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
|
||||
private string $includes;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $event_id
|
||||
* @param $entity
|
||||
*/
|
||||
public function __construct($event_id, $entity, $company)
|
||||
public function __construct($event_id, $entity, $company, $includes = '')
|
||||
{
|
||||
$this->event_id = $event_id;
|
||||
$this->entity = $entity;
|
||||
$this->company = $company;
|
||||
$this->includes = $includes;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,6 +91,7 @@ class WebhookHandler implements ShouldQueue
|
||||
// generate JSON data
|
||||
$manager = new Manager();
|
||||
$manager->setSerializer(new ArraySerializer());
|
||||
$manager->parseIncludes($this->includes);
|
||||
|
||||
$class = sprintf('App\\Transformers\\%sTransformer', class_basename($this->entity));
|
||||
|
||||
|
@ -36,9 +36,7 @@ class InvoiceObserver
|
||||
|
||||
if ($subscriptions) {
|
||||
|
||||
$invoice->load('client');
|
||||
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company);
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company, 'client');
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,17 +48,14 @@ class InvoiceObserver
|
||||
*/
|
||||
public function updated(Invoice $invoice)
|
||||
{
|
||||
|
||||
$subscriptions = Webhook::where('company_id', $invoice->company_id)
|
||||
->where('event_id', Webhook::EVENT_UPDATE_INVOICE)
|
||||
->exists();
|
||||
|
||||
|
||||
|
||||
if ($subscriptions) {
|
||||
|
||||
$invoice->load('client');
|
||||
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company);
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company, 'client');
|
||||
|
||||
}
|
||||
|
||||
@ -80,9 +75,7 @@ class InvoiceObserver
|
||||
|
||||
if ($subscriptions) {
|
||||
|
||||
$invoice->load('client');
|
||||
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company);
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company, 'client');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,11 +29,8 @@ class PaymentObserver
|
||||
->where('event_id', Webhook::EVENT_CREATE_PAYMENT)
|
||||
->exists();
|
||||
|
||||
if($payment->invoices()->exists())
|
||||
$payment->load('invoices');
|
||||
|
||||
if ($subscriptions) {
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company);
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company, 'invoices');
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +57,7 @@ class PaymentObserver
|
||||
->exists();
|
||||
|
||||
if ($subscriptions) {
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment, $payment->company);
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment, $payment->company, 'invoices');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,36 +12,8 @@
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Http\Middleware\SetDomainNameDb;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Expense;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Product;
|
||||
use App\Models\Proposal;
|
||||
use App\Models\Quote;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
use App\Observers\AccountObserver;
|
||||
use App\Observers\ClientObserver;
|
||||
use App\Observers\CompanyGatewayObserver;
|
||||
use App\Observers\CompanyObserver;
|
||||
use App\Observers\CompanyTokenObserver;
|
||||
use App\Observers\CreditObserver;
|
||||
use App\Observers\ExpenseObserver;
|
||||
use App\Observers\InvoiceObserver;
|
||||
use App\Observers\PaymentObserver;
|
||||
use App\Observers\ProductObserver;
|
||||
use App\Observers\ProposalObserver;
|
||||
use App\Observers\QuoteObserver;
|
||||
use App\Observers\SubscriptionObserver;
|
||||
use App\Observers\TaskObserver;
|
||||
use App\Observers\UserObserver;
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
@ -80,23 +52,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
Schema::defaultStringLength(191);
|
||||
|
||||
Account::observe(AccountObserver::class);
|
||||
Subscription::observe(SubscriptionObserver::class);
|
||||
Client::observe(ClientObserver::class);
|
||||
Company::observe(CompanyObserver::class);
|
||||
CompanyGateway::observe(CompanyGatewayObserver::class);
|
||||
CompanyToken::observe(CompanyTokenObserver::class);
|
||||
Credit::observe(CreditObserver::class);
|
||||
Expense::observe(ExpenseObserver::class);
|
||||
Invoice::observe(InvoiceObserver::class);
|
||||
Payment::observe(PaymentObserver::class);
|
||||
Product::observe(ProductObserver::class);
|
||||
Proposal::observe(ProposalObserver::class);
|
||||
Quote::observe(QuoteObserver::class);
|
||||
Task::observe(TaskObserver::class);
|
||||
User::observe(UserObserver::class);
|
||||
|
||||
|
||||
/* Handles setting the correct database with livewire classes */
|
||||
if(Ninja::isHosted())
|
||||
{
|
||||
|
@ -202,6 +202,36 @@ use App\Listeners\User\DeletedUserActivity;
|
||||
use App\Listeners\User\RestoredUserActivity;
|
||||
use App\Listeners\User\UpdateUserLastLogin;
|
||||
use App\Listeners\User\UpdatedUserActivity;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Expense;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Product;
|
||||
use App\Models\Proposal;
|
||||
use App\Models\Quote;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
use App\Observers\AccountObserver;
|
||||
use App\Observers\ClientObserver;
|
||||
use App\Observers\CompanyGatewayObserver;
|
||||
use App\Observers\CompanyObserver;
|
||||
use App\Observers\CompanyTokenObserver;
|
||||
use App\Observers\CreditObserver;
|
||||
use App\Observers\ExpenseObserver;
|
||||
use App\Observers\InvoiceObserver;
|
||||
use App\Observers\PaymentObserver;
|
||||
use App\Observers\ProductObserver;
|
||||
use App\Observers\ProposalObserver;
|
||||
use App\Observers\QuoteObserver;
|
||||
use App\Observers\SubscriptionObserver;
|
||||
use App\Observers\TaskObserver;
|
||||
use App\Observers\UserObserver;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Mail\Events\MessageSending;
|
||||
use Illuminate\Mail\Events\MessageSent;
|
||||
@ -542,5 +572,21 @@ class EventServiceProvider extends ServiceProvider
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
Account::observe(AccountObserver::class);
|
||||
Subscription::observe(SubscriptionObserver::class);
|
||||
Client::observe(ClientObserver::class);
|
||||
Company::observe(CompanyObserver::class);
|
||||
CompanyGateway::observe(CompanyGatewayObserver::class);
|
||||
CompanyToken::observe(CompanyTokenObserver::class);
|
||||
Credit::observe(CreditObserver::class);
|
||||
Expense::observe(ExpenseObserver::class);
|
||||
Invoice::observe(InvoiceObserver::class);
|
||||
Payment::observe(PaymentObserver::class);
|
||||
Product::observe(ProductObserver::class);
|
||||
Proposal::observe(ProposalObserver::class);
|
||||
Quote::observe(QuoteObserver::class);
|
||||
Task::observe(TaskObserver::class);
|
||||
User::observe(UserObserver::class);
|
||||
}
|
||||
}
|
||||
|
@ -326,6 +326,8 @@ class BaseRepository
|
||||
|
||||
if($this->new_model)
|
||||
event('eloquent.created: App\Models\Invoice', $model);
|
||||
else
|
||||
event('eloquent.updated: App\Models\Invoice', $model);
|
||||
|
||||
}
|
||||
|
||||
@ -339,6 +341,9 @@ class BaseRepository
|
||||
|
||||
if($this->new_model)
|
||||
event('eloquent.created: App\Models\Credit', $model);
|
||||
else
|
||||
event('eloquent.updated: App\Models\Credit', $model);
|
||||
|
||||
}
|
||||
|
||||
if ($model instanceof Quote) {
|
||||
@ -351,7 +356,8 @@ class BaseRepository
|
||||
|
||||
if($this->new_model)
|
||||
event('eloquent.created: App\Models\Quote', $model);
|
||||
|
||||
else
|
||||
event('eloquent.updated: App\Models\Quote', $model);
|
||||
}
|
||||
|
||||
if ($model instanceof RecurringInvoice) {
|
||||
@ -364,6 +370,8 @@ class BaseRepository
|
||||
|
||||
if($this->new_model)
|
||||
event('eloquent.created: App\Models\RecurringInvoice', $model);
|
||||
else
|
||||
event('eloquent.updated: App\Models\RecurringInvoice', $model);
|
||||
}
|
||||
|
||||
$model->save();
|
||||
|
@ -356,9 +356,9 @@ class AutoBillInvoice extends AbstractService
|
||||
$items[] = $item;
|
||||
|
||||
$this->invoice->line_items = $items;
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
|
||||
$this->invoice = $this->invoice->calc()->getInvoice()->save();
|
||||
$this->invoice = $this->invoice->calc()->getInvoice()->saveQuietly();
|
||||
|
||||
if ($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT) {
|
||||
$this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save();
|
||||
|
@ -75,7 +75,7 @@ class HandleCancellation extends AbstractService
|
||||
$backup = $this->invoice->backup;
|
||||
unset($backup->cancellation);
|
||||
$this->invoice->backup = $backup;
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
|
||||
return $this->invoice;
|
||||
}
|
||||
@ -101,6 +101,6 @@ class HandleCancellation extends AbstractService
|
||||
$invoice_backup->cancellation = $cancellation;
|
||||
|
||||
$this->invoice->backup = $invoice_backup;
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ nlog("second payment_amount = {$payment_amount}");
|
||||
else
|
||||
$this->invoice->number = $new_invoice_number;
|
||||
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
} catch (\Exception $e) {
|
||||
nlog("I could not wind back the invoice number");
|
||||
|
||||
|
@ -37,7 +37,7 @@ class UpdateReminder extends AbstractService
|
||||
|
||||
if (! $this->invoice->isPayable()) {
|
||||
$this->invoice->next_send_date = null;
|
||||
$this->invoice->save();
|
||||
$this->invoice->saveQuietly();
|
||||
|
||||
return $this->invoice; //exit early
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ class RefundPayment
|
||||
$invoice->service()->setStatus(Invoice::STATUS_PARTIAL);
|
||||
}
|
||||
|
||||
$invoice->save();
|
||||
$invoice->saveQuietly();
|
||||
|
||||
$client = $invoice->client;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user