Features: - Implement two fee types: entrance fee and annual fee (both NT$1,000) - Add 50% discount for disability certificate holders - Add disability certificate upload in member profile - Integrate disability verification into cashier approval workflow - Add membership fee settings in system admin Document permissions: - Fix hard-coded role logic in Document model - Use permission-based authorization instead of role checks Additional features: - Add announcements, general ledger, and trial balance modules - Add income management and accounting entries - Add comprehensive test suite with factories - Update UI translations to Traditional Chinese 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
316 lines
14 KiB
PHP
316 lines
14 KiB
PHP
<?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.
|
||
*
|
||
* 此 Seeder 建立統一的角色與權限系統,整合:
|
||
* - 財務工作流程權限
|
||
* - 會員繳費審核權限(原 PaymentVerificationRolesSeeder)
|
||
* - 基礎角色(原 RoleSeeder)
|
||
*/
|
||
public function run(): void
|
||
{
|
||
// Create permissions for financial workflow
|
||
$permissions = [
|
||
// ===== 會員繳費審核權限(原 PaymentVerificationRolesSeeder) =====
|
||
'verify_payments_cashier' => '出納審核會員繳費(第一階段)',
|
||
'verify_payments_accountant' => '會計審核會員繳費(第二階段)',
|
||
'verify_payments_chair' => '理事長審核會員繳費(第三階段)',
|
||
'activate_memberships' => '啟用會員帳號',
|
||
'view_payment_verifications' => '查看繳費審核儀表板',
|
||
|
||
// ===== 財務申請單審核權限(新工作流程) =====
|
||
'approve_finance_secretary' => '秘書長審核財務申請單(第一階段)',
|
||
'approve_finance_chair' => '理事長審核財務申請單(第二階段:中額以上)',
|
||
'approve_finance_board' => '董理事會審核財務申請單(第三階段:大額)',
|
||
// Legacy permissions
|
||
'approve_finance_cashier' => '出納審核財務申請單(舊流程)',
|
||
'approve_finance_accountant' => '會計審核財務申請單(舊流程)',
|
||
|
||
// ===== 出帳確認權限 =====
|
||
'confirm_disbursement_requester' => '申請人確認領款',
|
||
'confirm_disbursement_cashier' => '出納確認出帳',
|
||
|
||
// ===== 入帳確認權限 =====
|
||
'confirm_recording_accountant' => '會計確認入帳',
|
||
|
||
// ===== 收入管理權限 =====
|
||
'view_incomes' => '查看收入記錄',
|
||
'record_income' => '記錄收入(出納)',
|
||
'confirm_income' => '確認收入(會計)',
|
||
'cancel_income' => '取消收入',
|
||
'export_incomes' => '匯出收入報表',
|
||
'view_income_statistics' => '查看收入統計',
|
||
|
||
// ===== 付款階段權限 =====
|
||
'create_payment_order' => '會計製作付款單',
|
||
'verify_payment_order' => '出納覆核付款單',
|
||
'execute_payment' => '出納執行付款',
|
||
'upload_payment_receipt' => '上傳付款憑證',
|
||
|
||
// ===== 記錄階段權限 =====
|
||
'record_cashier_ledger' => '出納記錄現金簿',
|
||
'record_accounting_transaction' => '會計記錄會計分錄',
|
||
'view_cashier_ledger' => '查看出納現金簿',
|
||
'view_accounting_transactions' => '查看會計分錄',
|
||
|
||
// ===== 銀行調節權限 =====
|
||
'prepare_bank_reconciliation' => '出納製作銀行調節表',
|
||
'review_bank_reconciliation' => '會計覆核銀行調節表',
|
||
'approve_bank_reconciliation' => '主管核准銀行調節表',
|
||
|
||
// ===== 財務文件權限 =====
|
||
'view_finance_documents' => '查看財務申請單',
|
||
'create_finance_documents' => '建立財務申請單',
|
||
'edit_finance_documents' => '編輯財務申請單',
|
||
'delete_finance_documents' => '刪除財務申請單',
|
||
|
||
// ===== 會計科目與預算權限 =====
|
||
'assign_chart_of_account' => '指定會計科目',
|
||
'assign_budget_item' => '指定預算項目',
|
||
|
||
// ===== 儀表板與報表權限 =====
|
||
'view_finance_dashboard' => '查看財務儀表板',
|
||
'view_finance_reports' => '查看財務報表',
|
||
'export_finance_reports' => '匯出財務報表',
|
||
|
||
// ===== 公告系統權限 =====
|
||
'view_announcements' => '查看公告',
|
||
'create_announcements' => '建立公告',
|
||
'edit_announcements' => '編輯公告',
|
||
'delete_announcements' => '刪除公告',
|
||
'publish_announcements' => '發布公告',
|
||
'manage_all_announcements' => '管理所有公告',
|
||
];
|
||
|
||
foreach ($permissions as $name => $description) {
|
||
Permission::firstOrCreate(
|
||
['name' => $name],
|
||
['guard_name' => 'web']
|
||
);
|
||
$this->command->info("Permission created: {$name}");
|
||
}
|
||
|
||
// ===== 建立基礎角色(原 RoleSeeder) =====
|
||
$baseRoles = [
|
||
'admin' => '系統管理員 - 擁有系統所有權限,負責使用者管理、系統設定與維護',
|
||
'staff' => '工作人員 - 一般協會工作人員,可檢視文件與協助行政事務',
|
||
];
|
||
|
||
foreach ($baseRoles as $roleName => $description) {
|
||
Role::updateOrCreate(
|
||
['name' => $roleName, 'guard_name' => 'web'],
|
||
['description' => $description]
|
||
);
|
||
$this->command->info("Base role created: {$roleName}");
|
||
}
|
||
|
||
// ===== 建立財務與會員管理角色 =====
|
||
$roles = [
|
||
'secretary_general' => [
|
||
'permissions' => [
|
||
// 財務申請單審核(新工作流程第一階段)
|
||
'approve_finance_secretary',
|
||
// 一般
|
||
'view_finance_documents',
|
||
'view_finance_dashboard',
|
||
'view_finance_reports',
|
||
// 公告系統
|
||
'view_announcements',
|
||
'create_announcements',
|
||
'edit_announcements',
|
||
'delete_announcements',
|
||
'publish_announcements',
|
||
'manage_all_announcements',
|
||
],
|
||
'description' => '秘書長 - 協會行政負責人,負責初審所有財務申請',
|
||
],
|
||
'finance_cashier' => [
|
||
'permissions' => [
|
||
// 會員繳費審核(原 payment_cashier)
|
||
'verify_payments_cashier',
|
||
'view_payment_verifications',
|
||
// 財務申請單審核(舊流程,保留)
|
||
'approve_finance_cashier',
|
||
// 出帳確認(新工作流程)
|
||
'confirm_disbursement_cashier',
|
||
// 收入管理
|
||
'view_incomes',
|
||
'record_income',
|
||
// 付款階段
|
||
'verify_payment_order',
|
||
'execute_payment',
|
||
'upload_payment_receipt',
|
||
// 記錄階段
|
||
'record_cashier_ledger',
|
||
'view_cashier_ledger',
|
||
// 銀行調節
|
||
'prepare_bank_reconciliation',
|
||
// 一般
|
||
'view_finance_documents',
|
||
'view_finance_dashboard',
|
||
// 公告系統
|
||
'view_announcements',
|
||
'create_announcements',
|
||
'edit_announcements',
|
||
'delete_announcements',
|
||
'publish_announcements',
|
||
],
|
||
'description' => '出納 - 負責現金收付、銀行調節表製作、出帳確認、記錄收入',
|
||
],
|
||
'finance_accountant' => [
|
||
'permissions' => [
|
||
// 會員繳費審核(原 payment_accountant)
|
||
'verify_payments_accountant',
|
||
'view_payment_verifications',
|
||
// 財務申請單審核(舊流程,保留)
|
||
'approve_finance_accountant',
|
||
// 入帳確認(新工作流程)
|
||
'confirm_recording_accountant',
|
||
// 收入管理
|
||
'view_incomes',
|
||
'confirm_income',
|
||
'cancel_income',
|
||
'export_incomes',
|
||
'view_income_statistics',
|
||
// 付款階段
|
||
'create_payment_order',
|
||
// 記錄階段
|
||
'record_accounting_transaction',
|
||
'view_accounting_transactions',
|
||
// 銀行調節
|
||
'review_bank_reconciliation',
|
||
// 會計科目與預算
|
||
'assign_chart_of_account',
|
||
'assign_budget_item',
|
||
// 一般
|
||
'view_finance_documents',
|
||
'view_finance_dashboard',
|
||
'view_finance_reports',
|
||
'export_finance_reports',
|
||
// 公告系統
|
||
'view_announcements',
|
||
'create_announcements',
|
||
'edit_announcements',
|
||
'delete_announcements',
|
||
'publish_announcements',
|
||
],
|
||
'description' => '會計 - 負責會計傳票製作、財務報表編製、入帳確認、確認收入',
|
||
],
|
||
'finance_chair' => [
|
||
'permissions' => [
|
||
// 會員繳費審核(原 payment_chair)
|
||
'verify_payments_chair',
|
||
'view_payment_verifications',
|
||
// 財務申請單審核
|
||
'approve_finance_chair',
|
||
// 銀行調節
|
||
'approve_bank_reconciliation',
|
||
// 一般
|
||
'view_finance_documents',
|
||
'view_finance_dashboard',
|
||
'view_finance_reports',
|
||
'export_finance_reports',
|
||
// 公告系統
|
||
'view_announcements',
|
||
'create_announcements',
|
||
'edit_announcements',
|
||
'delete_announcements',
|
||
'publish_announcements',
|
||
'manage_all_announcements',
|
||
],
|
||
'description' => '理事長 - 協會負責人,負責核決重大財務支出與會員繳費最終審核',
|
||
],
|
||
'finance_board_member' => [
|
||
'permissions' => [
|
||
// 大額審核
|
||
'approve_finance_board',
|
||
// 一般
|
||
'view_finance_documents',
|
||
'view_finance_dashboard',
|
||
'view_finance_reports',
|
||
// 公告系統
|
||
'view_announcements',
|
||
'create_announcements',
|
||
'edit_announcements',
|
||
'delete_announcements',
|
||
'publish_announcements',
|
||
],
|
||
'description' => '理事 - 理事會成員,協助監督協會運作與審核特定議案',
|
||
],
|
||
'finance_requester' => [
|
||
'permissions' => [
|
||
'view_finance_documents',
|
||
'create_finance_documents',
|
||
'edit_finance_documents',
|
||
// 出帳確認(新工作流程)
|
||
'confirm_disbursement_requester',
|
||
],
|
||
'description' => '財務申請人 - 一般有權申請款項之人員(如活動負責人),可確認領款',
|
||
],
|
||
'membership_manager' => [
|
||
'permissions' => [
|
||
'activate_memberships',
|
||
'view_payment_verifications',
|
||
// 公告系統
|
||
'view_announcements',
|
||
'create_announcements',
|
||
'edit_announcements',
|
||
'delete_announcements',
|
||
'publish_announcements',
|
||
],
|
||
'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 permissions to admin role
|
||
$adminRole = Role::where('name', 'admin')->first();
|
||
if ($adminRole) {
|
||
$adminRole->givePermissionTo(array_keys($permissions));
|
||
$this->command->info("Admin role updated with all permissions");
|
||
}
|
||
|
||
$this->command->info("\n=== 統一角色系統建立完成 ===");
|
||
$this->command->info("基礎角色:");
|
||
$this->command->info(" - admin - 系統管理員");
|
||
$this->command->info(" - staff - 工作人員");
|
||
$this->command->info("\n財務角色:");
|
||
$this->command->info(" - secretary_general - 秘書長(新增:財務申請初審)");
|
||
$this->command->info(" - finance_cashier - 出納(出帳確認)");
|
||
$this->command->info(" - finance_accountant - 會計(入帳確認)");
|
||
$this->command->info(" - finance_chair - 理事長(中額以上審核)");
|
||
$this->command->info(" - finance_board_member - 理事(大額審核)");
|
||
$this->command->info(" - finance_requester - 財務申請人(可確認領款)");
|
||
$this->command->info("\n會員管理角色:");
|
||
$this->command->info(" - membership_manager - 會員管理員");
|
||
$this->command->info("\n新財務申請審核工作流程:");
|
||
$this->command->info(" 審核階段:");
|
||
$this->command->info(" 小額 (< 5,000): secretary_general");
|
||
$this->command->info(" 中額 (5,000-50,000): secretary_general → finance_chair");
|
||
$this->command->info(" 大額 (> 50,000): secretary_general → finance_chair → finance_board_member");
|
||
$this->command->info(" 出帳階段: finance_requester(申請人確認) + finance_cashier(出納確認)");
|
||
$this->command->info(" 入帳階段: finance_accountant(會計入帳)");
|
||
}
|
||
}
|