Initial commit
This commit is contained in:
176
database/seeders/FinancialWorkflowPermissionsSeeder.php
Normal file
176
database/seeders/FinancialWorkflowPermissionsSeeder.php
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class FinancialWorkflowPermissionsSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// Create permissions for financial workflow
|
||||
$permissions = [
|
||||
// Approval Stage Permissions
|
||||
'approve_finance_cashier' => '出納審核財務申請單(第一階段)',
|
||||
'approve_finance_accountant' => '會計審核財務申請單(第二階段)',
|
||||
'approve_finance_chair' => '理事長審核財務申請單(第三階段)',
|
||||
'approve_finance_board' => '理事會審核大額財務申請(大於50,000)',
|
||||
|
||||
// Payment Stage Permissions
|
||||
'create_payment_order' => '會計製作付款單',
|
||||
'verify_payment_order' => '出納覆核付款單',
|
||||
'execute_payment' => '出納執行付款',
|
||||
'upload_payment_receipt' => '上傳付款憑證',
|
||||
|
||||
// Recording Stage Permissions
|
||||
'record_cashier_ledger' => '出納記錄現金簿',
|
||||
'record_accounting_transaction' => '會計記錄會計分錄',
|
||||
'view_cashier_ledger' => '查看出納現金簿',
|
||||
'view_accounting_transactions' => '查看會計分錄',
|
||||
|
||||
// Reconciliation Permissions
|
||||
'prepare_bank_reconciliation' => '出納製作銀行調節表',
|
||||
'review_bank_reconciliation' => '會計覆核銀行調節表',
|
||||
'approve_bank_reconciliation' => '主管核准銀行調節表',
|
||||
|
||||
// General Finance Document Permissions
|
||||
'view_finance_documents' => '查看財務申請單',
|
||||
'create_finance_documents' => '建立財務申請單',
|
||||
'edit_finance_documents' => '編輯財務申請單',
|
||||
'delete_finance_documents' => '刪除財務申請單',
|
||||
|
||||
// Chart of Accounts & Budget Permissions
|
||||
'assign_chart_of_account' => '指定會計科目',
|
||||
'assign_budget_item' => '指定預算項目',
|
||||
|
||||
// Dashboard & Reports Permissions
|
||||
'view_finance_dashboard' => '查看財務儀表板',
|
||||
'view_finance_reports' => '查看財務報表',
|
||||
'export_finance_reports' => '匯出財務報表',
|
||||
];
|
||||
|
||||
foreach ($permissions as $name => $description) {
|
||||
Permission::firstOrCreate(
|
||||
['name' => $name],
|
||||
['guard_name' => 'web']
|
||||
);
|
||||
$this->command->info("Permission created: {$name}");
|
||||
}
|
||||
|
||||
// Create roles for financial workflow
|
||||
$roles = [
|
||||
'finance_cashier' => [
|
||||
'permissions' => [
|
||||
// Approval stage
|
||||
'approve_finance_cashier',
|
||||
// Payment stage
|
||||
'verify_payment_order',
|
||||
'execute_payment',
|
||||
'upload_payment_receipt',
|
||||
// Recording stage
|
||||
'record_cashier_ledger',
|
||||
'view_cashier_ledger',
|
||||
// Reconciliation
|
||||
'prepare_bank_reconciliation',
|
||||
// General
|
||||
'view_finance_documents',
|
||||
'view_finance_dashboard',
|
||||
],
|
||||
'description' => '出納 - 管錢(覆核付款單、執行付款、記錄現金簿、製作銀行調節表)',
|
||||
],
|
||||
'finance_accountant' => [
|
||||
'permissions' => [
|
||||
// Approval stage
|
||||
'approve_finance_accountant',
|
||||
// Payment stage
|
||||
'create_payment_order',
|
||||
// Recording stage
|
||||
'record_accounting_transaction',
|
||||
'view_accounting_transactions',
|
||||
// Reconciliation
|
||||
'review_bank_reconciliation',
|
||||
// Chart of accounts & budget
|
||||
'assign_chart_of_account',
|
||||
'assign_budget_item',
|
||||
// General
|
||||
'view_finance_documents',
|
||||
'view_finance_dashboard',
|
||||
'view_finance_reports',
|
||||
'export_finance_reports',
|
||||
],
|
||||
'description' => '會計 - 管帳(製作付款單、記錄會計分錄、覆核銀行調節表、指定會計科目)',
|
||||
],
|
||||
'finance_chair' => [
|
||||
'permissions' => [
|
||||
// Approval stage
|
||||
'approve_finance_chair',
|
||||
// Reconciliation
|
||||
'approve_bank_reconciliation',
|
||||
// General
|
||||
'view_finance_documents',
|
||||
'view_finance_dashboard',
|
||||
'view_finance_reports',
|
||||
'export_finance_reports',
|
||||
],
|
||||
'description' => '理事長 - 審核中大額財務申請、核准銀行調節表',
|
||||
],
|
||||
'finance_board_member' => [
|
||||
'permissions' => [
|
||||
// Approval stage (for large amounts)
|
||||
'approve_finance_board',
|
||||
// General
|
||||
'view_finance_documents',
|
||||
'view_finance_dashboard',
|
||||
'view_finance_reports',
|
||||
],
|
||||
'description' => '理事 - 審核大額財務申請(大於50,000)',
|
||||
],
|
||||
'finance_requester' => [
|
||||
'permissions' => [
|
||||
'view_finance_documents',
|
||||
'create_finance_documents',
|
||||
'edit_finance_documents',
|
||||
],
|
||||
'description' => '財務申請人 - 可建立和編輯自己的財務申請單',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($roles as $roleName => $roleData) {
|
||||
$role = Role::firstOrCreate(
|
||||
['name' => $roleName],
|
||||
['guard_name' => 'web']
|
||||
);
|
||||
|
||||
// Assign permissions to role
|
||||
$role->syncPermissions($roleData['permissions']);
|
||||
|
||||
$this->command->info("Role created: {$roleName} with permissions: " . implode(', ', $roleData['permissions']));
|
||||
}
|
||||
|
||||
// Assign all financial workflow permissions to admin role (if exists)
|
||||
$adminRole = Role::where('name', 'admin')->first();
|
||||
if ($adminRole) {
|
||||
$adminRole->givePermissionTo(array_keys($permissions));
|
||||
$this->command->info("Admin role updated with all financial workflow permissions");
|
||||
}
|
||||
|
||||
$this->command->info("\n=== Financial Workflow Roles & Permissions Created ===");
|
||||
$this->command->info("Roles created:");
|
||||
$this->command->info("1. finance_cashier - 出納(管錢)");
|
||||
$this->command->info("2. finance_accountant - 會計(管帳)");
|
||||
$this->command->info("3. finance_chair - 理事長");
|
||||
$this->command->info("4. finance_board_member - 理事");
|
||||
$this->command->info("5. finance_requester - 財務申請人");
|
||||
$this->command->info("\nWorkflow stages:");
|
||||
$this->command->info("1. Approval Stage: Cashier → Accountant → Chair (→ Board for large amounts)");
|
||||
$this->command->info("2. Payment Stage: Accountant creates order → Cashier verifies → Cashier executes");
|
||||
$this->command->info("3. Recording Stage: Cashier records ledger + Accountant records transactions");
|
||||
$this->command->info("4. Reconciliation: Cashier prepares → Accountant reviews → Chair approves");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user