create new menu histori stock audit

This commit is contained in:
2025-06-16 17:27:59 +07:00
parent 567e4aa5fc
commit aa233eb793
13 changed files with 1264 additions and 1 deletions

View File

@@ -0,0 +1,83 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Menu;
use App\Models\Role;
use App\Models\Privilege;
class SetupStockAuditMenu extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'setup:stock-audit-menu';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Setup Stock Audit menu and privileges';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$this->info('Setting up Stock Audit menu...');
// Check if menu already exists
$existingMenu = Menu::where('link', 'stock-audit.index')->first();
if ($existingMenu) {
$this->warn('Stock Audit menu already exists!');
return 0;
}
// Create Stock Audit menu
$menu = Menu::create([
'name' => 'Audit Histori Stock',
'link' => 'stock-audit.index',
'created_at' => now(),
'updated_at' => now()
]);
$this->info('Stock Audit menu created with ID: ' . $menu->id);
// Give all roles access to this menu
$roles = Role::all();
$privilegeCount = 0;
foreach($roles as $role) {
// Check if privilege already exists
$existingPrivilege = Privilege::where('role_id', $role->id)
->where('menu_id', $menu->id)
->first();
if (!$existingPrivilege) {
Privilege::create([
'role_id' => $role->id,
'menu_id' => $menu->id,
'create' => 0, // Stock audit is view-only
'update' => 0, // Stock audit is view-only
'delete' => 0, // Stock audit is view-only
'view' => 1, // Allow viewing
'created_at' => now(),
'updated_at' => now()
]);
$privilegeCount++;
}
}
$this->info("Created {$privilegeCount} privileges for Stock Audit menu.");
$this->info('Stock Audit menu setup completed successfully!');
return 0;
}
}