160 lines
6.7 KiB
PHP
Executable File
160 lines
6.7 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
use Illuminate\Database\Seeder;
|
|
use App\Models\Mutation;
|
|
use App\Models\MutationDetail;
|
|
use App\Models\Dealer;
|
|
use App\Models\Product;
|
|
use App\Models\User;
|
|
use App\Enums\MutationStatus;
|
|
|
|
class MutationTestSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
// Pastikan ada dealer dan produk
|
|
$dealers = Dealer::take(3)->get();
|
|
$products = Product::take(5)->get();
|
|
$users = User::take(3)->get();
|
|
|
|
$this->command->info('Dealers found: ' . $dealers->count());
|
|
$this->command->info('Products found: ' . $products->count());
|
|
$this->command->info('Users found: ' . $users->count());
|
|
|
|
if ($dealers->count() < 2 || $products->count() < 2 || $users->count() < 1) {
|
|
$this->command->error('Tidak cukup data dealer, produk, atau user untuk membuat test mutation');
|
|
$this->command->error("Need at least 2 dealers, 2 products, 1 user");
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// 1. Mutation dengan status SENT (baru terkirim, menunggu diterima dealer tujuan)
|
|
$this->command->info('Creating SENT mutation...');
|
|
$mutation1 = Mutation::create([
|
|
'from_dealer_id' => $dealers[0]->id,
|
|
'to_dealer_id' => $dealers[1]->id,
|
|
'status' => MutationStatus::SENT,
|
|
'requested_by' => $users[0]->id,
|
|
'notes' => 'Mutasi test - status SENT (menunggu diterima)'
|
|
]);
|
|
|
|
MutationDetail::create([
|
|
'mutation_id' => $mutation1->id,
|
|
'product_id' => $products[0]->id,
|
|
'quantity_requested' => 10.00,
|
|
'notes' => 'Produk test 1'
|
|
]);
|
|
|
|
MutationDetail::create([
|
|
'mutation_id' => $mutation1->id,
|
|
'product_id' => $products[1]->id,
|
|
'quantity_requested' => 5.00,
|
|
'notes' => 'Produk test 2'
|
|
]);
|
|
|
|
// 2. Mutation dengan status RECEIVED (sudah diterima, menunggu approval pengirim)
|
|
$this->command->info('Creating RECEIVED mutation...');
|
|
$mutation2 = Mutation::create([
|
|
'from_dealer_id' => $dealers[0]->id,
|
|
'to_dealer_id' => $dealers[1]->id,
|
|
'status' => MutationStatus::RECEIVED,
|
|
'requested_by' => $users[0]->id,
|
|
'received_by' => $users[1]->id ?? $users[0]->id,
|
|
'received_at' => now()->subHours(2),
|
|
'notes' => 'Mutasi test - status RECEIVED (menunggu approval)'
|
|
]);
|
|
|
|
MutationDetail::create([
|
|
'mutation_id' => $mutation2->id,
|
|
'product_id' => $products[0]->id,
|
|
'quantity_requested' => 8.00,
|
|
'notes' => 'Produk untuk approval'
|
|
]);
|
|
|
|
// 3. Mutation dengan status APPROVED (sudah diapprove, siap dikompletkan)
|
|
$this->command->info('Creating APPROVED mutation...');
|
|
$mutation3 = Mutation::create([
|
|
'from_dealer_id' => $dealers[0]->id,
|
|
'to_dealer_id' => $dealers[1]->id,
|
|
'status' => MutationStatus::APPROVED,
|
|
'requested_by' => $users[0]->id,
|
|
'received_by' => $users[1]->id ?? $users[0]->id,
|
|
'received_at' => now()->subHours(4),
|
|
'approved_by' => $users[0]->id,
|
|
'approved_at' => now()->subHours(1),
|
|
'notes' => 'Mutasi test - status APPROVED (siap dikompletkan)'
|
|
]);
|
|
|
|
$mutation3Detail = MutationDetail::create([
|
|
'mutation_id' => $mutation3->id,
|
|
'product_id' => $products[0]->id,
|
|
'quantity_requested' => 12.00,
|
|
'quantity_approved' => 10.00, // Approved dengan jumlah berbeda
|
|
'notes' => 'Produk approved parsial'
|
|
]);
|
|
|
|
// 4. Additional APPROVED mutation (completed workflow is now just approved)
|
|
$this->command->info('Creating additional APPROVED mutation...');
|
|
$mutation4 = Mutation::create([
|
|
'from_dealer_id' => $dealers[0]->id,
|
|
'to_dealer_id' => $dealers[1]->id,
|
|
'status' => MutationStatus::APPROVED,
|
|
'requested_by' => $users[0]->id,
|
|
'received_by' => $users[1]->id ?? $users[0]->id,
|
|
'received_at' => now()->subDay(),
|
|
'approved_by' => $users[0]->id,
|
|
'approved_at' => now()->subHours(6),
|
|
'notes' => 'Mutasi test - status APPROVED (stock moved)'
|
|
]);
|
|
|
|
MutationDetail::create([
|
|
'mutation_id' => $mutation4->id,
|
|
'product_id' => $products[1]->id,
|
|
'quantity_requested' => 6.00,
|
|
'quantity_approved' => 6.00,
|
|
'notes' => 'Produk approved & stock moved'
|
|
]);
|
|
|
|
// 5. Mutation dengan status REJECTED
|
|
$this->command->info('Creating REJECTED mutation...');
|
|
$mutation5 = Mutation::create([
|
|
'from_dealer_id' => $dealers[0]->id,
|
|
'to_dealer_id' => $dealers[1]->id,
|
|
'status' => MutationStatus::REJECTED,
|
|
'requested_by' => $users[0]->id,
|
|
'received_by' => $users[1]->id ?? $users[0]->id,
|
|
'received_at' => now()->subHours(8),
|
|
'approved_by' => $users[0]->id,
|
|
'approved_at' => now()->subHours(3),
|
|
'rejection_reason' => 'Stock tidak mencukupi untuk produk yang diminta',
|
|
'notes' => 'Mutasi test - status REJECTED'
|
|
]);
|
|
|
|
MutationDetail::create([
|
|
'mutation_id' => $mutation5->id,
|
|
'product_id' => $products[2]->id,
|
|
'quantity_requested' => 20.00,
|
|
'quantity_approved' => 0,
|
|
'notes' => 'Produk rejected'
|
|
]);
|
|
|
|
$this->command->info('Test mutations created successfully!');
|
|
$this->command->info('- Mutation SENT: ' . $mutation1->mutation_number);
|
|
$this->command->info('- Mutation RECEIVED: ' . $mutation2->mutation_number);
|
|
$this->command->info('- Mutation APPROVED (1): ' . $mutation3->mutation_number);
|
|
$this->command->info('- Mutation APPROVED (2): ' . $mutation4->mutation_number);
|
|
$this->command->info('- Mutation REJECTED: ' . $mutation5->mutation_number);
|
|
|
|
} catch (\Exception $e) {
|
|
$this->command->error('Error creating test mutations: ' . $e->getMessage());
|
|
$this->command->error('Stack trace: ' . $e->getTraceAsString());
|
|
}
|
|
}
|
|
}
|