create stock and stock logs

This commit is contained in:
2025-06-10 18:38:06 +07:00
parent 1a2ddb59d4
commit 51079aa567
36 changed files with 1621 additions and 311 deletions

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateStocksTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('stocks', function (Blueprint $table) {
$table->id();
$table->foreignId('product_id')->constrained('products')->onDelete('cascade');
$table->foreignId('dealer_id')->constrained('dealers')->onDelete('cascade');
$table->decimal('quantity', 10, 2)->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('stocks');
}
}

View File

@@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
class CreateStockLogsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('stock_logs', function (Blueprint $table) {
$table->id();
$table->foreignId('stock_id')->constrained('stocks')->onDelete('cascade');
$table->string('source_type'); // 'opname' atau 'mutation'
$table->unsignedBigInteger('source_id'); // ID dari opname atau mutation
$table->decimal('previous_quantity', 10, 2);
$table->decimal('new_quantity', 10, 2);
$table->decimal('quantity_change', 10, 2); // bisa positif atau negatif
$table->enum('change_type', ['increase', 'decrease', 'adjustment', 'no_change'])->default('no_change');
$table->string('description')->nullable();
$table->foreignId('user_id')->constrained('users');
$table->timestamps();
// Index untuk pencarian berdasarkan source
$table->index(['source_type', 'source_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('stock_logs');
}
}

View File

@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddApprovalColumnsToOpnamesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('opnames', function (Blueprint $table) {
$table->enum('status', ['draft', 'pending', 'approved', 'rejected'])->default('draft');
$table->foreignId('approved_by')->nullable()->constrained('users');
$table->timestamp('approved_at')->nullable();
$table->text('rejection_note')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('opnames', function (Blueprint $table) {
$table->dropForeign(['approved_by']);
$table->dropColumn(['status', 'approved_by', 'approved_at', 'rejection_note']);
});
}
}

View File

@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ChangeStockColumnsToDecimalInOpnameDetails extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('opname_details', function (Blueprint $table) {
// Mengubah kolom system_stock dari integer ke decimal(10,2)
$table->decimal('system_stock', 10, 2)->change();
// Mengubah kolom physical_stock dari integer ke decimal(10,2)
$table->decimal('physical_stock', 10, 2)->change();
// Mengubah kolom difference dari integer ke decimal(10,2)
$table->decimal('difference', 10, 2)->default(0)->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('opname_details', function (Blueprint $table) {
$table->integer('system_stock')->change();
$table->integer('physical_stock')->change();
$table->integer('difference')->default(0)->change();
});
}
}