diff --git a/app/Events/Invoice/InvoiceWasPaid.php b/app/Events/Invoice/InvoiceWasPaid.php index 61904c95538e..dfdd115e69a3 100644 --- a/app/Events/Invoice/InvoiceWasPaid.php +++ b/app/Events/Invoice/InvoiceWasPaid.php @@ -11,6 +11,7 @@ namespace App\Events\Invoice; +use App\Models\Company; use App\Models\Invoice; use Illuminate\Queue\SerializesModels; @@ -26,13 +27,16 @@ class InvoiceWasPaid */ public $invoice; + public $company; + /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice) + public function __construct(Invoice $invoice, Company $company) { $this->invoice = $invoice; + $this->company = $company; } } diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 1476757396c9..da0f59a9021a 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -72,26 +72,10 @@ class BaseController extends Controller if(request()->has('first_load') && request()->input('first_load') == 'true') { + /* For very large accounts, we reduce the includes automatically */ if(auth()->user()->getCompany()->clients->count() > 1000) { - $include = [ - 'account', - 'user.company_user', - 'token', - 'company.activities', - 'company.users.company_user', - 'company.tax_rates', - 'company.groups', - 'company.company_gateways.gateway', - // 'company.clients', - // 'company.products', - // 'company.invoices', - // 'company.payments', - // 'company.quotes', - ]; - } - else - { + $include = [ 'account', 'user.company_user', @@ -107,6 +91,27 @@ class BaseController extends Controller 'company.payments', 'company.quotes', ]; + + } + else + { + + $include = [ + 'account', + 'user.company_user', + 'token', + 'company.activities', + 'company.users.company_user', + 'company.tax_rates', + 'company.groups', + // 'company.company_gateways.gateway', + // 'company.clients', + // 'company.products', + // 'company.invoices', + // 'company.payments', + // 'company.quotes', + ]; + } $include = array_merge($this->forced_includes, $include); @@ -147,6 +152,7 @@ class BaseController extends Controller $this->manager->setSerializer(new ArraySerializer()); } + } /** @@ -157,8 +163,8 @@ class BaseController extends Controller { return response()->json(['message' => '404 | Nothing to see here!'], 404) - ->header('X-Api-Version', config('ninja.api_version')) - ->header('X-App-Version', config('ninja.app_version')); + ->header('X-API-VERSION', config('ninja.api_version')) + ->header('X-APP-VERSION', config('ninja.app_version')); } @@ -188,6 +194,7 @@ class BaseController extends Controller $transformer = new $this->entity_transformer(Input::get('serializer')); $includes = $transformer->getDefaultIncludes(); + $includes = $this->getRequestIncludes($includes); $query->with($includes); diff --git a/app/Jobs/Invoice/ApplyPaymentToInvoice.php b/app/Jobs/Invoice/ApplyPaymentToInvoice.php index 03a77dc1ce22..8c00d8602edb 100644 --- a/app/Jobs/Invoice/ApplyPaymentToInvoice.php +++ b/app/Jobs/Invoice/ApplyPaymentToInvoice.php @@ -106,7 +106,7 @@ class ApplyPaymentToInvoice implements ShouldQueue if($this->invoice->balance == 0){ $this->invoice->status_id = Invoice::STATUS_PAID; $this->invoice->save(); - event(new InvoiceWasPaid($this->invoice)); + event(new InvoiceWasPaid($this->invoice, $this->invoice->company)); } elseif($this->payment->amount > 0 && $this->invoice->balance > 0) $this->invoice->status_id = Invoice::STATUS_PARTIAL; diff --git a/app/Jobs/Invoice/CreateInvoicePdf.php b/app/Jobs/Invoice/CreateInvoicePdf.php index 1c0ef31519c0..f61a2ec44a89 100644 --- a/app/Jobs/Invoice/CreateInvoicePdf.php +++ b/app/Jobs/Invoice/CreateInvoicePdf.php @@ -36,7 +36,7 @@ class CreateInvoicePdf implements ShouldQueue public $invoice; - + public $company; /** * Create a new job instance. * diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 2ed3d2b11092..0fd0ae9d639c 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -414,7 +414,7 @@ class Invoice extends BaseModel if($this->balance == 0) { $this->status_id = self::STATUS_PAID; $this->save(); - event(new InvoiceWasPaid($this)); + event(new InvoiceWasPaid($this, $this->company)); return; } diff --git a/app/Models/User.php b/app/Models/User.php index 25a8219e3a3a..63664e6da357 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -47,7 +47,7 @@ class User extends Authenticatable implements MustVerifyEmail protected $presenter = 'App\Models\Presenters\UserPresenter'; - protected $with = ['companies']; + protected $with = []; // ? companies also protected $dateFormat = 'Y-m-d H:i:s.u'; @@ -105,7 +105,6 @@ class User extends Authenticatable implements MustVerifyEmail return $this->encodePrimaryKey($this->id); } - /** * Returns a account. * diff --git a/app/Transformers/ActivityTransformer.php b/app/Transformers/ActivityTransformer.php index 4f363dd4e211..a63189ee9d78 100644 --- a/app/Transformers/ActivityTransformer.php +++ b/app/Transformers/ActivityTransformer.php @@ -27,17 +27,17 @@ class ActivityTransformer extends EntityTransformer return [ 'id' => (string) $this->encodePrimaryKey($activity->id), 'activity_type_id' => (string) $activity->activity_type_id, - 'client_id' => $activity->client ? (string) $this->encodePrimaryKey($activity->client->id) : '', - 'company_id' => $activity->company ? (string) $this->encodePrimaryKey($activity->company->id) : '', + 'client_id' => $activity->client_id ? (string) $this->encodePrimaryKey($activity->client_id) : '', + 'company_id' => $activity->company_id ? (string) $this->encodePrimaryKey($activity->company_id) : '', 'user_id' => (string) $this->encodePrimaryKey($activity->user_id), - 'invoice_id' => $activity->invoice ? (string) $this->encodePrimaryKey($activity->invoice->id) : '', - 'payment_id' => $activity->payment ? (string) $this->encodePrimaryKey($activity->payment->id) : '', - 'credit_id' => $activity->credit ? (string) $this->encodePrimaryKey($activity->credit->id) : '', + 'invoice_id' => $activity->invoice_id ? (string) $this->encodePrimaryKey($activity->invoice_id) : '', + 'payment_id' => $activity->payment_id ? (string) $this->encodePrimaryKey($activity->payment_id) : '', + 'credit_id' => $activity->credit_id ? (string) $this->encodePrimaryKey($activity->credit_id) : '', 'updated_at' => $activity->updated_at, - 'expense_id' => $activity->expense_id ? (string) $this->encodePrimaryKey($activity->expense->id) : '', + 'expense_id' => $activity->expense_id ? (string) $this->encodePrimaryKey($activity->expense_id) : '', 'is_system' => (bool) $activity->is_system, - 'contact_id' => $activity->contact_id ? (string) $this->encodePrimaryKey($activity->contact->id) : '', - 'task_id' => $activity->task_id ? (string) $this->encodePrimaryKey($activity->task->id) : '', + 'contact_id' => $activity->contact_id ? (string) $this->encodePrimaryKey($activity->contact_id) : '', + 'task_id' => $activity->task_id ? (string) $this->encodePrimaryKey($activity->task_id) : '', 'notes' => $activity->notes ? (string) $activity->notes : '', 'ip' => (string) $activity->ip,