Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
"spatie/laravel-schedule-monitor": "^3.7",
"spatie/laravel-sluggable": "^3.5",
"sqids/sqids": "^0.4.1",
"xantios/mimey": "^2.2.0"
"xantios/mimey": "^2.2.0",
"spatie/laravel-pdf": "^2.0",
"mossadal/math-parser": "^2.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.34.1",
Expand Down Expand Up @@ -105,4 +107,4 @@
"@test:unit"
]
}
}
}
72 changes: 72 additions & 0 deletions migrations/2026_03_03_000001_create_templates_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('templates', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('uuid', 191)->unique()->nullable();
$table->string('public_id', 191)->unique()->nullable();
$table->string('company_uuid', 191)->nullable()->index();
$table->string('created_by_uuid', 191)->nullable()->index();
$table->string('updated_by_uuid', 191)->nullable()->index();

// Identity
$table->string('name');
$table->text('description')->nullable();

// Context type — defines which Fleetbase model this template is designed for.
// e.g. 'order', 'invoice', 'transaction', 'shipping_label', 'receipt', 'report'
$table->string('context_type')->default('generic')->index();

// Canvas dimensions (in mm by default, configurable via unit)
$table->string('unit')->default('mm'); // mm, px, in
$table->decimal('width', 10, 4)->default(210); // A4 width
$table->decimal('height', 10, 4)->default(297); // A4 height
$table->string('orientation')->default('portrait'); // portrait | landscape

// Page settings
$table->json('margins')->nullable(); // { top, right, bottom, left }
$table->string('background_color')->nullable();
$table->string('background_image_uuid')->nullable();

// The full template content — array of element objects
$table->longText('content')->nullable(); // JSON array of TemplateElement objects

// Element type definitions / schema overrides (optional per-template customisation)
$table->json('element_schemas')->nullable();

// Status
$table->boolean('is_default')->default(false);
$table->boolean('is_system')->default(false);
$table->boolean('is_public')->default(false);

$table->timestamps();
$table->softDeletes();

// Foreign keys
$table->foreign('company_uuid')->references('uuid')->on('companies')->onDelete('cascade');
$table->foreign('created_by_uuid')->references('uuid')->on('users')->onDelete('set null');
$table->foreign('updated_by_uuid')->references('uuid')->on('users')->onDelete('set null');

// Composite indexes
$table->index(['company_uuid', 'context_type']);
$table->index(['company_uuid', 'is_default']);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('templates');
}
};
61 changes: 61 additions & 0 deletions migrations/2026_03_03_000002_create_template_queries_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('template_queries', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('uuid', 191)->unique()->nullable();
$table->string('public_id', 191)->unique()->nullable();
$table->string('company_uuid', 191)->nullable()->index();
$table->string('template_uuid', 191)->nullable()->index();
$table->string('created_by_uuid', 191)->nullable()->index();

// The fully-qualified model class this query targets
// e.g. 'Fleetbase\Models\Order', 'Fleetbase\FleetOps\Models\Order'
$table->string('model_type');

// The variable name used in the template to access this collection
// e.g. 'orders', 'transactions', 'invoices'
$table->string('variable_name');

// Human-readable label shown in the variable picker
$table->string('label')->nullable();

// JSON array of filter condition groups
// Each condition: { field, operator, value, type }
$table->json('conditions')->nullable();

// JSON array of sort directives: [{ field, direction }]
$table->json('sort')->nullable();

// Maximum number of records to return (null = no limit)
$table->unsignedInteger('limit')->nullable();

// Which relationships to eager-load on the result set
$table->json('with')->nullable();

$table->timestamps();
$table->softDeletes();

$table->foreign('company_uuid')->references('uuid')->on('companies')->onDelete('cascade');
$table->foreign('template_uuid')->references('uuid')->on('templates')->onDelete('cascade');
$table->foreign('created_by_uuid')->references('uuid')->on('users')->onDelete('set null');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('template_queries');
}
};
Loading
Loading