chore: initial commit of existing codebase

This commit is contained in:
ghassan committed 2026-05-19 12:40:08 +03:00
commit 11e94889b2
292 files changed
+38586

No files matched your search

+1
View File
@@ -0,0 +1 @@
*.sqlite*
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* @extends Factory<User>
*/
class UserFactory extends Factory
{
/**
* The current password being used by the factory.
*/
protected static ?string $password;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}
@@ -0,0 +1,49 @@
<?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('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
Schema::dropIfExists('password_reset_tokens');
Schema::dropIfExists('sessions');
}
};
@@ -0,0 +1,35 @@
<?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('cache', function (Blueprint $table) {
$table->string('key')->primary();
$table->mediumText('value');
$table->integer('expiration')->index();
});
Schema::create('cache_locks', function (Blueprint $table) {
$table->string('key')->primary();
$table->string('owner');
$table->integer('expiration')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('cache');
Schema::dropIfExists('cache_locks');
}
};
@@ -0,0 +1,57 @@
<?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('jobs', function (Blueprint $table) {
$table->id();
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->longText('failed_job_ids');
$table->mediumText('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('jobs');
Schema::dropIfExists('job_batches');
Schema::dropIfExists('failed_jobs');
}
};
@@ -0,0 +1,134 @@
<?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
{
$teams = config('permission.teams');
$tableNames = config('permission.table_names');
$columnNames = config('permission.column_names');
$pivotRole = $columnNames['role_pivot_key'] ?? 'role_id';
$pivotPermission = $columnNames['permission_pivot_key'] ?? 'permission_id';
throw_if(empty($tableNames), Exception::class, 'Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
throw_if($teams && empty($columnNames['team_foreign_key'] ?? null), Exception::class, 'Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
Schema::create($tableNames['permissions'], static function (Blueprint $table) {
// $table->engine('InnoDB');
$table->bigIncrements('id'); // permission id
$table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
$table->string('guard_name'); // For MyISAM use string('guard_name', 25);
$table->timestamps();
$table->unique(['name', 'guard_name']);
});
Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) {
// $table->engine('InnoDB');
$table->bigIncrements('id'); // role id
if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing
$table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable();
$table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index');
}
$table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
$table->string('guard_name'); // For MyISAM use string('guard_name', 25);
$table->timestamps();
if ($teams || config('permission.testing')) {
$table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']);
} else {
$table->unique(['name', 'guard_name']);
}
});
Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) {
$table->unsignedBigInteger($pivotPermission);
$table->string('model_type');
$table->unsignedBigInteger($columnNames['model_morph_key']);
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index');
$table->foreign($pivotPermission)
->references('id') // permission id
->on($tableNames['permissions'])
->onDelete('cascade');
if ($teams) {
$table->unsignedBigInteger($columnNames['team_foreign_key']);
$table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index');
$table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'],
'model_has_permissions_permission_model_type_primary');
} else {
$table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
'model_has_permissions_permission_model_type_primary');
}
});
Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) {
$table->unsignedBigInteger($pivotRole);
$table->string('model_type');
$table->unsignedBigInteger($columnNames['model_morph_key']);
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index');
$table->foreign($pivotRole)
->references('id') // role id
->on($tableNames['roles'])
->onDelete('cascade');
if ($teams) {
$table->unsignedBigInteger($columnNames['team_foreign_key']);
$table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index');
$table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'],
'model_has_roles_role_model_type_primary');
} else {
$table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'],
'model_has_roles_role_model_type_primary');
}
});
Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) {
$table->unsignedBigInteger($pivotPermission);
$table->unsignedBigInteger($pivotRole);
$table->foreign($pivotPermission)
->references('id') // permission id
->on($tableNames['permissions'])
->onDelete('cascade');
$table->foreign($pivotRole)
->references('id') // role id
->on($tableNames['roles'])
->onDelete('cascade');
$table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary');
});
app('cache')
->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
->forget(config('permission.cache.key'));
}
/**
* Reverse the migrations.
*/
public function down(): void
{
$tableNames = config('permission.table_names');
throw_if(empty($tableNames), Exception::class, 'Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
Schema::drop($tableNames['role_has_permissions']);
Schema::drop($tableNames['model_has_roles']);
Schema::drop($tableNames['model_has_permissions']);
Schema::drop($tableNames['roles']);
Schema::drop($tableNames['permissions']);
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('items', function (Blueprint $table) {
$table->id();
$table->string('item_code')->unique();
$table->string('item_name');
$table->enum('category', ['raw_material', 'wip', 'finished_good']);
$table->string('unit_of_measure');
$table->decimal('minimum_stock_level', 12, 2)->default(0);
$table->decimal('cost_price', 12, 2)->default(0);
$table->text('description')->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('items');
}
};
@@ -0,0 +1,25 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('stock_levels', function (Blueprint $table) {
$table->id();
$table->foreignId('item_id')->constrained()->onDelete('cascade');
$table->foreignId('warehouse_id')->constrained()->onDelete('cascade');
$table->decimal('quantity', 12, 2)->default(0);
$table->timestamps();
$table->unique(['item_id', 'warehouse_id']);
});
}
public function down(): void
{
Schema::dropIfExists('stock_levels');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('suppliers', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('contact_person')->nullable();
$table->string('email')->nullable();
$table->string('phone')->nullable();
$table->text('address')->nullable();
$table->string('tax_number')->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('suppliers');
}
};
@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('warehouses', function (Blueprint $table) {
$table->id();
$table->string('code')->unique();
$table->string('name');
$table->text('location')->nullable();
$table->text('description')->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('warehouses');
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('stock_movements', function (Blueprint $table) {
$table->id();
$table->foreignId('item_id')->constrained()->onDelete('cascade');
$table->foreignId('warehouse_id')->constrained()->onDelete('cascade');
$table->enum('type', ['in', 'out', 'transfer']);
$table->decimal('quantity', 12, 2);
$table->string('reference_type')->nullable();
$table->unsignedBigInteger('reference_id')->nullable();
$table->text('notes')->nullable();
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('stock_movements');
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('goods_receipt_notes', function (Blueprint $table) {
$table->id();
$table->string('grn_number')->unique();
$table->foreignId('purchase_order_id')->constrained()->onDelete('restrict');
$table->foreignId('supplier_id')->constrained()->onDelete('restrict');
$table->foreignId('warehouse_id')->constrained()->onDelete('restrict');
$table->date('received_date');
$table->enum('status', ['draft', 'confirmed'])->default('draft');
$table->text('notes')->nullable();
$table->foreignId('received_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('goods_receipt_notes');
}
};
@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('purchase_order_items', function (Blueprint $table) {
$table->id();
$table->foreignId('purchase_order_id')->constrained()->onDelete('cascade');
$table->foreignId('item_id')->constrained()->onDelete('restrict');
$table->decimal('quantity', 12, 2);
$table->decimal('rate', 12, 2);
$table->decimal('total_amount', 14, 2);
$table->decimal('quantity_received', 12, 2)->default(0);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('purchase_order_items');
}
};
@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('purchase_orders', function (Blueprint $table) {
$table->id();
$table->string('po_number')->unique();
$table->foreignId('supplier_id')->constrained()->onDelete('restrict');
$table->foreignId('purchase_request_id')->nullable()->constrained()->nullOnDelete();
$table->date('po_date');
$table->date('expected_delivery_date')->nullable();
$table->decimal('total_amount', 14, 2)->default(0);
$table->enum('status', ['draft', 'sent', 'partial', 'received', 'cancelled'])->default('draft');
$table->text('notes')->nullable();
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('purchase_orders');
}
};
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('purchase_requests', function (Blueprint $table) {
$table->id();
$table->string('request_number')->unique();
$table->date('date');
$table->string('project_name')->nullable();
$table->string('department')->nullable();
$table->string('requested_by_name')->nullable();
$table->string('required_date_text')->nullable();
$table->string('location')->nullable();
$table->text('remarks')->nullable();
$table->enum('status', ['pending', 'approved', 'rejected', 'ordered'])->default('pending');
$table->string('verified_by_name')->nullable();
$table->foreignId('requested_by')->constrained('users')->onDelete('restrict');
$table->foreignId('approved_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamp('approved_at')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('purchase_requests');
}
};
@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('grn_items', function (Blueprint $table) {
$table->id();
$table->foreignId('goods_receipt_note_id')->constrained()->onDelete('cascade');
$table->foreignId('purchase_order_item_id')->constrained()->onDelete('restrict');
$table->foreignId('item_id')->constrained()->onDelete('restrict');
$table->decimal('quantity_received', 12, 2);
$table->decimal('unit_cost', 12, 2)->default(0);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('grn_items');
}
};
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('supplier_invoices', function (Blueprint $table) {
$table->id();
$table->string('invoice_number');
$table->foreignId('supplier_id')->constrained()->onDelete('restrict');
$table->foreignId('purchase_order_id')->nullable()->constrained()->nullOnDelete();
$table->foreignId('goods_receipt_note_id')->nullable()->constrained()->nullOnDelete();
$table->date('invoice_date');
$table->date('due_date')->nullable();
$table->decimal('subtotal', 14, 2)->default(0);
$table->decimal('vat_amount', 14, 2)->default(0);
$table->decimal('total_amount', 14, 2)->default(0);
$table->decimal('paid_amount', 14, 2)->default(0);
$table->enum('status', ['unpaid', 'partial', 'paid'])->default('unpaid');
$table->text('notes')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('supplier_invoices');
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('supplier_payments', function (Blueprint $table) {
$table->id();
$table->foreignId('supplier_invoice_id')->constrained()->onDelete('restrict');
$table->foreignId('supplier_id')->constrained()->onDelete('restrict');
$table->date('payment_date');
$table->decimal('amount', 14, 2);
$table->enum('payment_method', ['cash', 'bank_transfer', 'cheque', 'other']);
$table->string('reference_number')->nullable();
$table->text('notes')->nullable();
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('supplier_payments');
}
};
@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('bill_of_materials', function (Blueprint $table) {
$table->id();
$table->foreignId('product_id')->constrained('items')->onDelete('cascade');
$table->foreignId('raw_material_id')->constrained('items')->onDelete('restrict');
$table->decimal('quantity_required', 12, 2);
$table->string('unit_of_measure')->nullable();
$table->text('notes')->nullable();
$table->timestamps();
$table->unique(['product_id', 'raw_material_id']);
});
}
public function down(): void
{
Schema::dropIfExists('bill_of_materials');
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('material_issues', function (Blueprint $table) {
$table->id();
$table->string('issue_number')->unique();
$table->foreignId('production_order_id')->constrained()->onDelete('restrict');
$table->foreignId('item_id')->constrained()->onDelete('restrict');
$table->foreignId('warehouse_id')->constrained()->onDelete('restrict');
$table->decimal('quantity', 12, 2);
$table->date('issue_date');
$table->text('notes')->nullable();
$table->foreignId('issued_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('material_issues');
}
};
@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('production_orders', function (Blueprint $table) {
$table->id();
$table->string('order_number')->unique();
$table->foreignId('product_id')->constrained('items')->onDelete('restrict');
$table->decimal('quantity_to_produce', 12, 2);
$table->decimal('quantity_produced', 12, 2)->default(0);
$table->date('production_date');
$table->date('completion_date')->nullable();
$table->enum('status', ['planned', 'in_progress', 'completed', 'cancelled'])->default('planned');
$table->text('notes')->nullable();
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('production_orders');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('production_costs', function (Blueprint $table) {
$table->id();
$table->foreignId('production_order_id')->constrained()->onDelete('cascade');
$table->decimal('raw_material_cost', 14, 2)->default(0);
$table->decimal('labor_cost', 14, 2)->default(0);
$table->decimal('machine_cost', 14, 2)->default(0);
$table->decimal('overhead_cost', 14, 2)->default(0);
$table->decimal('total_cost', 14, 2)->default(0);
$table->text('notes')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('production_costs');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('production_outputs', function (Blueprint $table) {
$table->id();
$table->foreignId('production_order_id')->constrained()->onDelete('restrict');
$table->foreignId('item_id')->constrained('items')->onDelete('restrict');
$table->foreignId('warehouse_id')->constrained()->onDelete('restrict');
$table->decimal('quantity', 12, 2);
$table->date('output_date');
$table->text('notes')->nullable();
$table->foreignId('recorded_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('production_outputs');
}
};
@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('customers', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('contact_person')->nullable();
$table->string('email')->nullable();
$table->string('phone')->nullable();
$table->text('address')->nullable();
$table->string('tax_number')->nullable();
$table->decimal('credit_limit', 14, 2)->default(0);
$table->decimal('outstanding_balance', 14, 2)->default(0);
$table->boolean('is_active')->default(true);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('customers');
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('delivery_notes', function (Blueprint $table) {
$table->id();
$table->string('delivery_number')->unique();
$table->foreignId('sales_order_id')->constrained()->onDelete('restrict');
$table->foreignId('customer_id')->constrained()->onDelete('restrict');
$table->foreignId('warehouse_id')->constrained()->onDelete('restrict');
$table->date('delivery_date');
$table->enum('status', ['draft', 'dispatched'])->default('draft');
$table->text('notes')->nullable();
$table->foreignId('dispatched_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('delivery_notes');
}
};
@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('sales_order_items', function (Blueprint $table) {
$table->id();
$table->foreignId('sales_order_id')->constrained()->onDelete('cascade');
$table->foreignId('item_id')->constrained()->onDelete('restrict');
$table->decimal('quantity', 12, 2);
$table->decimal('price', 12, 2);
$table->decimal('total_amount', 14, 2);
$table->decimal('quantity_delivered', 12, 2)->default(0);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('sales_order_items');
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('sales_orders', function (Blueprint $table) {
$table->id();
$table->string('order_number')->unique();
$table->foreignId('customer_id')->constrained()->onDelete('restrict');
$table->date('order_date');
$table->date('delivery_date')->nullable();
$table->decimal('total_amount', 14, 2)->default(0);
$table->enum('status', ['draft', 'confirmed', 'dispatched', 'invoiced', 'cancelled'])->default('draft');
$table->text('notes')->nullable();
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('sales_orders');
}
};
@@ -0,0 +1,25 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('delivery_note_items', function (Blueprint $table) {
$table->id();
$table->foreignId('delivery_note_id')->constrained()->onDelete('cascade');
$table->foreignId('sales_order_item_id')->constrained()->onDelete('restrict');
$table->foreignId('item_id')->constrained()->onDelete('restrict');
$table->decimal('quantity_delivered', 12, 2);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('delivery_note_items');
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('payment_receipts', function (Blueprint $table) {
$table->id();
$table->foreignId('sales_invoice_id')->constrained()->onDelete('restrict');
$table->foreignId('customer_id')->constrained()->onDelete('restrict');
$table->date('receipt_date');
$table->decimal('amount', 14, 2);
$table->enum('payment_method', ['cash', 'bank_transfer', 'cheque', 'other']);
$table->string('reference_number')->nullable();
$table->text('notes')->nullable();
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('payment_receipts');
}
};
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('sales_invoices', function (Blueprint $table) {
$table->id();
$table->string('invoice_number')->unique();
$table->foreignId('sales_order_id')->constrained()->onDelete('restrict');
$table->foreignId('customer_id')->constrained()->onDelete('restrict');
$table->date('invoice_date');
$table->date('due_date')->nullable();
$table->decimal('subtotal', 14, 2)->default(0);
$table->decimal('vat_rate', 5, 2)->default(0);
$table->decimal('vat_amount', 14, 2)->default(0);
$table->decimal('total_amount', 14, 2)->default(0);
$table->decimal('paid_amount', 14, 2)->default(0);
$table->enum('status', ['unpaid', 'partial', 'paid', 'cancelled'])->default('unpaid');
$table->text('notes')->nullable();
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('sales_invoices');
}
};
@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('purchase_request_items', function (Blueprint $table) {
$table->id();
$table->foreignId('purchase_request_id')->constrained()->onDelete('cascade');
$table->text('description');
$table->string('unit', 50)->nullable();
$table->decimal('quantity_required', 12, 2);
$table->string('purpose_use')->nullable();
$table->date('required_date')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('purchase_request_items');
}
};
@@ -0,0 +1,37 @@
<?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::table('suppliers', function (Blueprint $table) {
$table->string('supplier_code')->nullable()->after('id');
$table->string('category')->nullable()->after('name');
$table->string('secondary_email')->nullable()->after('email');
$table->string('phone2')->nullable()->after('phone');
$table->string('whatsapp')->nullable()->after('phone2');
$table->string('website')->nullable()->after('address');
$table->string('credit_terms', 10)->nullable()->after('tax_number');
$table->integer('credit_days')->nullable()->after('credit_terms');
$table->text('remarks')->nullable()->after('is_active');
});
}
public function down(): void
{
Schema::table('suppliers', function (Blueprint $table) {
$table->dropColumn([
'supplier_code', 'category', 'secondary_email',
'phone2', 'whatsapp', 'website',
'credit_terms', 'credit_days', 'remarks',
]);
});
}
};
@@ -0,0 +1,24 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::table('purchase_requests', function (Blueprint $table) {
$table->enum('stage', [
'draft', 'gm_approval', 'rfq', 'quoting',
'comparison', 'lpo', 'receiving', 'payment', 'complete',
])->default('draft')->after('status');
});
}
public function down(): void
{
Schema::table('purchase_requests', function (Blueprint $table) {
$table->dropColumn('stage');
});
}
};
@@ -0,0 +1,21 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::table('grn_items', function (Blueprint $table) {
$table->enum('type', ['inventory', 'consumable'])->default('inventory')->after('unit_cost');
});
}
public function down(): void
{
Schema::table('grn_items', function (Blueprint $table) {
$table->dropColumn('type');
});
}
};
@@ -0,0 +1,25 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::create('purchase_signatures', function (Blueprint $table) {
$table->id();
$table->foreignId('purchase_request_id')->constrained()->onDelete('cascade');
$table->foreignId('signed_by')->constrained('users')->onDelete('restrict');
$table->text('signature_image');
$table->timestamp('signed_at');
$table->string('ip_address')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('purchase_signatures');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::create('rfq_invitations', function (Blueprint $table) {
$table->id();
$table->foreignId('purchase_request_id')->constrained()->onDelete('cascade');
$table->foreignId('supplier_id')->constrained()->onDelete('restrict');
$table->string('token', 64)->unique();
$table->enum('channel', ['email', 'whatsapp', 'both'])->default('both');
$table->timestamp('sent_at')->nullable();
$table->timestamp('opened_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->enum('status', ['pending', 'sent', 'opened', 'submitted', 'declined'])->default('pending');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('rfq_invitations');
}
};
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::create('supplier_quotes', function (Blueprint $table) {
$table->id();
$table->foreignId('rfq_invitation_id')->constrained()->onDelete('cascade');
$table->foreignId('purchase_request_id')->constrained()->onDelete('cascade');
$table->foreignId('supplier_id')->constrained()->onDelete('restrict');
$table->timestamp('submitted_at');
$table->integer('lead_time_days')->nullable();
$table->string('payment_terms')->nullable();
$table->text('notes')->nullable();
$table->decimal('total_amount', 12, 3)->default(0);
$table->boolean('is_awarded')->default(false);
$table->text('award_reason')->nullable();
$table->timestamp('awarded_at')->nullable();
$table->foreignId('awarded_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('supplier_quotes');
}
};
@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::create('supplier_quote_items', function (Blueprint $table) {
$table->id();
$table->foreignId('supplier_quote_id')->constrained()->onDelete('cascade');
$table->text('description');
$table->string('unit', 50)->nullable();
$table->decimal('quantity', 10, 3);
$table->decimal('unit_price', 12, 3);
$table->decimal('total_price', 12, 3);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('supplier_quote_items');
}
};
@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::table('purchase_requests', function (Blueprint $table) {
if (!Schema::hasColumn('purchase_requests', 'project_name')) {
$table->string('project_name')->nullable()->after('date');
}
if (!Schema::hasColumn('purchase_requests', 'requested_by_name')) {
$table->string('requested_by_name')->nullable()->after('department');
}
if (!Schema::hasColumn('purchase_requests', 'required_date_text')) {
$table->string('required_date_text')->nullable()->after('requested_by_name');
}
if (!Schema::hasColumn('purchase_requests', 'location')) {
$table->string('location')->nullable()->after('required_date_text');
}
if (!Schema::hasColumn('purchase_requests', 'verified_by_name')) {
$table->string('verified_by_name')->nullable()->after('status');
}
});
}
public function down(): void
{
Schema::table('purchase_requests', function (Blueprint $table) {
$table->dropColumn(array_filter([
Schema::hasColumn('purchase_requests', 'project_name') ? 'project_name' : null,
Schema::hasColumn('purchase_requests', 'requested_by_name') ? 'requested_by_name' : null,
Schema::hasColumn('purchase_requests', 'required_date_text')? 'required_date_text': null,
Schema::hasColumn('purchase_requests', 'location') ? 'location' : null,
Schema::hasColumn('purchase_requests', 'verified_by_name') ? 'verified_by_name' : null,
]));
});
}
};
@@ -0,0 +1,21 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::table('purchase_requests', function (Blueprint $table) {
$table->integer('item_id')->nullable()->change();
$table->decimal('quantity', 12, 3)->nullable()->change();
$table->string('unit_of_measure')->nullable()->change();
});
}
public function down(): void
{
// Intentionally left blank — reverting NOT NULL on legacy columns risks data loss
}
};
@@ -0,0 +1,20 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::table('purchase_requests', function (Blueprint $table) {
$table->string('department')->nullable()->change();
$table->text('remarks')->nullable()->change();
});
}
public function down(): void
{
// Intentionally left blank — reverting NOT NULL on legacy columns risks data loss
}
};
@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::table('rfq_invitations', function (Blueprint $table) {
// null = whole order; JSON array of item IDs = per-item assignment
$table->text('item_ids')->nullable()->after('status');
});
}
public function down(): void
{
Schema::table('rfq_invitations', function (Blueprint $table) {
$table->dropColumn('item_ids');
});
}
};
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace Database\Seeders;
use App\Models\User;
use App\Models\Warehouse;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Models\Role;
class DatabaseSeeder extends Seeder
{
public function run(): void
{
$roles = ['Admin', 'Accounts', 'Store Manager', 'Production Manager', 'Sales Manager'];
foreach ($roles as $role) {
Role::firstOrCreate(['name' => $role]);
}
$admin = User::firstOrCreate(
['email' => '[email protected]'],
['name' => 'Admin User', 'password' => Hash::make('password')]
);
$admin->assignRole('Admin');
$warehouses = [
['code' => 'WH-MAIN', 'name' => 'Main Warehouse', 'location' => 'Main Building'],
['code' => 'WH-PROD', 'name' => 'Production Warehouse', 'location' => 'Factory Floor'],
['code' => 'WH-FG', 'name' => 'Finished Goods Warehouse', 'location' => 'Dispatch Area'],
];
foreach ($warehouses as $wh) {
Warehouse::firstOrCreate(['code' => $wh['code']], $wh);
}
}
}
@@ -0,0 +1,18 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class PurchaseRequestStagePatchSeeder extends Seeder
{
public function run(): void
{
DB::table('purchase_requests')->where('status', 'approved')->whereNull('stage')->update(['stage' => 'rfq']);
DB::table('purchase_requests')->where('status', 'rejected')->whereNull('stage')->update(['stage' => 'draft']);
DB::table('purchase_requests')->where('status', 'ordered')->whereNull('stage')->update(['stage' => 'lpo']);
DB::table('purchase_requests')->where('status', 'pending')->whereNull('stage')->update(['stage' => 'gm_approval']);
DB::table('purchase_requests')->whereNull('stage')->update(['stage' => 'draft']);
}
}