fix inventory

This commit is contained in:
root
2026-06-11 11:06:32 -04:00
parent 9483750161
commit c91fa2ce4d
53 changed files with 2936 additions and 12666 deletions
@@ -0,0 +1,46 @@
<?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('inventory_movements', function (Blueprint $table) {
// Audit/correction fields for append-only ledger
$table->timestamp('voided_at')->nullable()->after('updated_at');
$table->unsignedBigInteger('voided_by')->nullable()->after('voided_at');
$table->string('void_reason', 255)->nullable()->after('voided_by');
$table->unsignedBigInteger('corrects_movement_id')->nullable()->after('void_reason');
$table->string('source_type', 50)->nullable()->after('corrects_movement_id');
$table->unsignedBigInteger('source_id')->nullable()->after('source_type');
// Index for efficient queries
$table->index('voided_at');
$table->index('corrects_movement_id');
$table->index('source_type');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('inventory_movements', function (Blueprint $table) {
$table->dropColumn([
'voided_at',
'voided_by',
'void_reason',
'corrects_movement_id',
'source_type',
'source_id',
]);
});
}
};
@@ -0,0 +1,52 @@
<?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('inventory_items', function (Blueprint $table) {
// Supplier and reorder fields
$table->unsignedBigInteger('preferred_supplier_id')->nullable()->after('updated_by');
$table->decimal('last_purchase_price', 10, 2)->nullable()->after('preferred_supplier_id');
$table->decimal('average_unit_cost', 10, 2)->nullable()->after('last_purchase_price');
$table->integer('reorder_point')->nullable()->after('average_unit_cost');
$table->integer('reorder_quantity')->nullable()->after('reorder_point');
$table->integer('lead_time_days')->nullable()->after('reorder_quantity');
// Barcode/QR support
$table->string('barcode', 100)->nullable()->after('lead_time_days');
$table->string('qr_code', 255)->nullable()->after('barcode');
$table->string('asset_tag', 100)->nullable()->after('qr_code');
$table->index('preferred_supplier_id');
$table->index('reorder_point');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('inventory_items', function (Blueprint $table) {
$table->dropColumn([
'preferred_supplier_id',
'last_purchase_price',
'average_unit_cost',
'reorder_point',
'reorder_quantity',
'lead_time_days',
'barcode',
'qr_code',
'asset_tag',
]);
});
}
};
@@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('purchase_order_items', function (Blueprint $table) {
if (!Schema::hasColumn('purchase_order_items', 'inventory_item_id')) {
$table->unsignedInteger('inventory_item_id')->nullable()->after('supply_id');
}
});
// Add index if it doesn't exist
$indexExists = DB::select("SHOW INDEX FROM purchase_order_items WHERE Key_name = 'po_items_inventory_item_idx'");
if (empty($indexExists)) {
Schema::table('purchase_order_items', function (Blueprint $table) {
$table->index('inventory_item_id', 'po_items_inventory_item_idx');
});
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('purchase_order_items', function (Blueprint $table) {
$table->dropIndex('po_items_inventory_item_idx');
$table->dropColumn('inventory_item_id');
});
}
};