Add locations to mini/first load

This commit is contained in:
David Bomba 2025-02-21 13:28:47 +11:00
parent 7b7a630fdc
commit c7bad23909
12 changed files with 110 additions and 4 deletions

View File

@ -154,6 +154,7 @@ class BaseController extends Controller
'company.bank_transactions', 'company.bank_transactions',
'company.bank_transaction_rules', 'company.bank_transaction_rules',
'company.task_schedulers', 'company.task_schedulers',
'company.locations',
]; ];
/** /**
@ -178,6 +179,7 @@ class BaseController extends Controller
'company.bank_integrations', 'company.bank_integrations',
'company.bank_transaction_rules', 'company.bank_transaction_rules',
'company.task_schedulers', 'company.task_schedulers',
'company.locations',
]; ];
/** /**
@ -525,6 +527,9 @@ class BaseController extends Controller
'company.task_schedulers' => function ($query) { 'company.task_schedulers' => function ($query) {
$query->whereNotNull('updated_at'); $query->whereNotNull('updated_at');
}, },
'company.locations' => function ($query) {
$query->whereNotNull('updated_at');
},
] ]
); );
@ -630,6 +635,9 @@ class BaseController extends Controller
$query->where('schedulers.user_id', $user->id); $query->where('schedulers.user_id', $user->id);
} }
}, },
'company.locations' => function ($query) use ($created_at) {
$query->where('created_at', '>=', $created_at);
},
] ]
); );

View File

@ -252,6 +252,11 @@ class Credit extends BaseModel
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed(); return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
} }
public function location(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Location::class)->withTrashed();
}
public function vendor(): \Illuminate\Database\Eloquent\Relations\BelongsTo public function vendor(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{ {
return $this->belongsTo(Vendor::class); return $this->belongsTo(Vendor::class);

View File

@ -319,6 +319,11 @@ class Invoice extends BaseModel
return $this->belongsTo(User::class)->withTrashed(); return $this->belongsTo(User::class)->withTrashed();
} }
public function location(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Location::class)->withTrashed();
}
public function recurring_invoice(): \Illuminate\Database\Eloquent\Relations\BelongsTo public function recurring_invoice(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{ {
return $this->belongsTo(RecurringInvoice::class, 'recurring_id', 'id')->withTrashed(); return $this->belongsTo(RecurringInvoice::class, 'recurring_id', 'id')->withTrashed();

View File

@ -307,6 +307,11 @@ class PurchaseOrder extends BaseModel
return $this->belongsTo(User::class)->withTrashed(); return $this->belongsTo(User::class)->withTrashed();
} }
public function location(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Location::class)->withTrashed();
}
public function client(): \Illuminate\Database\Eloquent\Relations\BelongsTo public function client(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{ {
return $this->belongsTo(Client::class)->withTrashed(); return $this->belongsTo(Client::class)->withTrashed();

View File

@ -268,6 +268,11 @@ class Quote extends BaseModel
return $this->belongsTo(User::class)->withTrashed(); return $this->belongsTo(User::class)->withTrashed();
} }
public function location(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Location::class)->withTrashed();
}
public function client(): \Illuminate\Database\Eloquent\Relations\BelongsTo public function client(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{ {
return $this->belongsTo(Client::class)->withTrashed(); return $this->belongsTo(Client::class)->withTrashed();

View File

@ -362,6 +362,11 @@ class RecurringInvoice extends BaseModel
return $this->belongsTo(User::class)->withTrashed(); return $this->belongsTo(User::class)->withTrashed();
} }
public function location(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Location::class)->withTrashed();
}
public function assigned_user(): \Illuminate\Database\Eloquent\Relations\BelongsTo public function assigned_user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{ {
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed(); return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();

View File

@ -32,8 +32,20 @@ class CreditTransformer extends EntityTransformer
protected array $availableIncludes = [ protected array $availableIncludes = [
'activities', 'activities',
'client', 'client',
'location',
]; ];
public function includeLocation(Credit $credit)
{
$transformer = new LocationTransformer($this->serializer);
if (!$credit->location) {
return null;
}
return $this->includeItem($credit->location, $transformer, \App\Models\Location::class);
}
public function includeActivities(Credit $credit) public function includeActivities(Credit $credit)
{ {
$transformer = new ActivityTransformer($this->serializer); $transformer = new ActivityTransformer($this->serializer);
@ -134,6 +146,7 @@ class CreditTransformer extends EntityTransformer
'invoice_id' => $credit->invoice_id ? $this->encodePrimaryKey($credit->invoice_id) : '', 'invoice_id' => $credit->invoice_id ? $this->encodePrimaryKey($credit->invoice_id) : '',
'tax_info' => $credit->tax_data ?: new \stdClass(), 'tax_info' => $credit->tax_data ?: new \stdClass(),
'e_invoice' => $credit->e_invoice ?: new \stdClass(), 'e_invoice' => $credit->e_invoice ?: new \stdClass(),
'location_id' => $this->encodePrimaryKey($credit->location_id),
]; ];
} }

View File

@ -34,8 +34,20 @@ class InvoiceTransformer extends EntityTransformer
'payments', 'payments',
'client', 'client',
'activities', 'activities',
'location',
]; ];
public function includeLocation(Invoice $invoice)
{
$transformer = new LocationTransformer($this->serializer);
if (!$invoice->location) {
return null;
}
return $this->includeItem($invoice->location, $transformer, \App\Models\Location::class);
}
public function includeInvitations(Invoice $invoice) public function includeInvitations(Invoice $invoice)
{ {
$transformer = new InvoiceInvitationTransformer($this->serializer); $transformer = new InvoiceInvitationTransformer($this->serializer);
@ -160,6 +172,7 @@ class InvoiceTransformer extends EntityTransformer
'tax_info' => $invoice->tax_data ?: new \stdClass(), 'tax_info' => $invoice->tax_data ?: new \stdClass(),
'e_invoice' => $invoice->e_invoice ?: new \stdClass(), 'e_invoice' => $invoice->e_invoice ?: new \stdClass(),
'backup' => $invoice->backup ?: new \stdClass(), 'backup' => $invoice->backup ?: new \stdClass(),
'location_id' => $this->encodePrimaryKey($invoice->location_id),
]; ];
if (request()->has('reminder_schedule') && request()->query('reminder_schedule') == 'true') { if (request()->has('reminder_schedule') && request()->query('reminder_schedule') == 'true') {

View File

@ -151,6 +151,7 @@ class PurchaseOrderTransformer extends EntityTransformer
'currency_id' => $purchase_order->currency_id ? (string) $purchase_order->currency_id : '', 'currency_id' => $purchase_order->currency_id ? (string) $purchase_order->currency_id : '',
'tax_info' => $purchase_order->tax_data ?: new \stdClass(), 'tax_info' => $purchase_order->tax_data ?: new \stdClass(),
'e_invoice' => $purchase_order->e_invoice ?: new \stdClass(), 'e_invoice' => $purchase_order->e_invoice ?: new \stdClass(),
'location_id' => $this->encodePrimaryKey($purchase_order->location_id),
]; ];
} }

View File

@ -32,8 +32,21 @@ class QuoteTransformer extends EntityTransformer
protected array $availableIncludes = [ protected array $availableIncludes = [
'activities', 'activities',
'client', 'client',
'location',
]; ];
public function includeLocation(Quote $quote)
{
$transformer = new LocationTransformer($this->serializer);
if (!$quote->location) {
return null;
}
return $this->includeItem($quote->location, $transformer, \App\Models\Location::class);
}
public function includeActivities(Quote $quote) public function includeActivities(Quote $quote)
{ {
$transformer = new ActivityTransformer($this->serializer); $transformer = new ActivityTransformer($this->serializer);
@ -150,6 +163,7 @@ class QuoteTransformer extends EntityTransformer
'subscription_id' => $this->encodePrimaryKey($quote->subscription_id), 'subscription_id' => $this->encodePrimaryKey($quote->subscription_id),
'tax_info' => $quote->tax_data ?: new \stdClass(), 'tax_info' => $quote->tax_data ?: new \stdClass(),
'e_invoice' => $quote->e_invoice ?: new \stdClass(), 'e_invoice' => $quote->e_invoice ?: new \stdClass(),
'location_id' => $this->encodePrimaryKey($quote->location_id),
]; ];
} }

View File

@ -31,8 +31,20 @@ class RecurringInvoiceTransformer extends EntityTransformer
protected array $availableIncludes = [ protected array $availableIncludes = [
'activities', 'activities',
'client', 'client',
'location',
]; ];
public function includeLocation(RecurringInvoice $invoice)
{
$transformer = new LocationTransformer($this->serializer);
if (!$invoice->location) {
return null;
}
return $this->includeItem($invoice->location, $transformer, \App\Models\Location::class);
}
public function includeHistory(RecurringInvoice $invoice) public function includeHistory(RecurringInvoice $invoice)
{ {
$transformer = new InvoiceHistoryTransformer($this->serializer); $transformer = new InvoiceHistoryTransformer($this->serializer);
@ -134,6 +146,7 @@ class RecurringInvoiceTransformer extends EntityTransformer
'paid_to_date' => (float) $invoice->paid_to_date, 'paid_to_date' => (float) $invoice->paid_to_date,
'subscription_id' => (string) $this->encodePrimaryKey($invoice->subscription_id), 'subscription_id' => (string) $this->encodePrimaryKey($invoice->subscription_id),
'e_invoice' => $invoice->e_invoice ?: new \stdClass(), 'e_invoice' => $invoice->e_invoice ?: new \stdClass(),
'location_id' => $this->encodePrimaryKey($invoice->location_id),
]; ];
if (request()->has('show_dates') && request()->query('show_dates') == 'true') { if (request()->has('show_dates') && request()->query('show_dates') == 'true') {

View File

@ -40,11 +40,30 @@ return new class extends Migration
$table->foreign('vendor_id')->references('id')->on('vendors')->onDelete('cascade')->onUpdate('cascade'); $table->foreign('vendor_id')->references('id')->on('vendors')->onDelete('cascade')->onUpdate('cascade');
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
}); });
Schema::table('invoices', function (Blueprint $table){
$table->foreignId('location_id')->nullable()->constrained()->cascadeOnDelete();
});
Schema::table('recurring_invoices', function (Blueprint $table) {
$table->foreignId('location_id')->nullable()->constrained()->cascadeOnDelete();
});
Schema::table('credits', function (Blueprint $table) {
$table->foreignId('location_id')->nullable()->constrained()->cascadeOnDelete();
});
Schema::table('quotes', function (Blueprint $table) {
$table->foreignId('location_id')->nullable()->constrained()->cascadeOnDelete();
});
Schema::table('purchase_orders', function (Blueprint $table) {
$table->foreignId('location_id')->nullable()->constrained()->cascadeOnDelete();
});
} }
/**
* Reverse the migrations.
*/
public function down(): void public function down(): void
{ {
// //