This commit is contained in:
Abhishek Mali
2025-11-14 13:55:01 +05:30
parent 6608caf61d
commit b495a58d64
7 changed files with 725 additions and 7 deletions

View File

@@ -0,0 +1,63 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateShipmentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('shipments', function (Blueprint $table) {
$table->bigIncrements('id');
// Human-friendly auto-generated shipment id (e.g. SHIP-25-00000001)
$table->string('shipment_id')->unique();
// Basic details
$table->string('origin')->nullable();
$table->string('destination')->nullable();
// Totals (calculated when creating shipment)
$table->integer('total_ctn')->default(0)->comment('sum of CTN of selected orders');
$table->integer('total_qty')->default(0)->comment('sum of qty of selected orders');
$table->integer('total_ttl_qty')->default(0)->comment('sum of ttl_qty of selected orders');
$table->decimal('total_amount', 16, 2)->default(0.00)->comment('sum of ttl_amount of selected orders');
$table->decimal('total_cbm', 14, 3)->default(0.000)->comment('sum cbm');
$table->decimal('total_ttl_cbm', 14, 3)->default(0.000)->comment('sum ttl cbm');
$table->decimal('total_kg', 14, 3)->default(0.000)->comment('sum kg');
$table->decimal('total_ttl_kg', 14, 3)->default(0.000)->comment('sum ttl kg');
// status: pending (default), in_transit, dispatched, delivered, cancelled, etc.
$table->string('status')->default('pending');
// shipment date (admin can change)
$table->date('shipment_date')->nullable();
// optional meta (vehicle, driver etc)
$table->json('meta')->nullable();
$table->timestamps();
// Indexes for fast filtering
$table->index('shipment_id');
$table->index('status');
$table->index('shipment_date');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('shipments');
}
}

View File

@@ -0,0 +1,51 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateShipmentItemsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('shipment_items', function (Blueprint $table) {
$table->bigIncrements('id');
// Link to shipments
$table->foreignId('shipment_id')->constrained('shipments')->onDelete('cascade');
// Link to orders. assuming orders.id is bigIncrements
$table->foreignId('order_id')->constrained('orders')->onDelete('restrict');
// Snapshots (optional) — store basic order totals at time of assignment
$table->integer('order_ctn')->nullable()->default(0);
$table->integer('order_qty')->nullable()->default(0);
$table->integer('order_ttl_qty')->nullable()->default(0);
$table->decimal('order_ttl_amount', 16, 2)->nullable()->default(0.00);
$table->decimal('order_ttl_kg', 14, 3)->nullable()->default(0.000);
$table->timestamps();
// Prevent duplicate assignment of same order to the same shipment
$table->unique(['shipment_id', 'order_id']);
// We will check order_id uniqueness across shipments in app logic (see below)
$table->index('order_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('shipment_items');
}
}