Initial commit

This commit is contained in:
2025-11-20 23:21:05 +08:00
commit 13bc6db529
378 changed files with 54527 additions and 0 deletions

198
setup-financial-workflow.sh Executable file
View File

@@ -0,0 +1,198 @@
#!/bin/bash
###############################################################################
# Financial Workflow Setup Script
#
# This script sets up the complete financial workflow system including:
# - Database migrations for payment orders, cashier ledger, and reconciliations
# - Permissions and roles seeder
# - Test data (optional)
###############################################################################
set -e # Exit on error
echo "======================================================================"
echo "Financial Workflow System Setup"
echo "======================================================================"
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored messages
print_success() {
echo -e "${GREEN}${NC} $1"
}
print_info() {
echo -e "${BLUE}${NC} $1"
}
print_warning() {
echo -e "${YELLOW}${NC} $1"
}
print_error() {
echo -e "${RED}${NC} $1"
}
# Check if we're in the right directory
if [ ! -f "artisan" ]; then
print_error "Error: artisan file not found. Please run this script from the project root."
exit 1
fi
print_info "Starting financial workflow setup..."
echo ""
# Step 1: Run migrations
echo "======================================================================"
echo "Step 1: Running Database Migrations"
echo "======================================================================"
echo ""
print_info "Running all pending migrations..."
php artisan migrate --force
if [ $? -eq 0 ]; then
print_success "Migrations completed successfully"
else
print_error "Migration failed. Please check the error above."
exit 1
fi
echo ""
# Step 2: Run Financial Workflow Permissions Seeder
echo "======================================================================"
echo "Step 2: Setting up Permissions and Roles"
echo "======================================================================"
echo ""
print_info "Running FinancialWorkflowPermissionsSeeder..."
php artisan db:seed --class=FinancialWorkflowPermissionsSeeder
if [ $? -eq 0 ]; then
print_success "Financial permissions and roles created successfully"
echo ""
print_info "The following roles have been created:"
echo " - finance_cashier (出納 - manages money)"
echo " - finance_accountant (會計 - manages books)"
echo " - finance_chair (理事長 - approves medium/large amounts)"
echo " - finance_board_member (理事 - approves large amounts)"
echo " - finance_requester (申請人 - submits requests)"
else
print_warning "Seeder may have already run or encountered an issue"
fi
echo ""
# Step 3: Optional - Create test users
echo "======================================================================"
echo "Step 3: Test Users (Optional)"
echo "======================================================================"
echo ""
read -p "Do you want to create test users for each financial role? (y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
print_info "Creating test users..."
php artisan tinker --execute="
use App\Models\User;
use Spatie\Permission\Models\Role;
// Create test cashier
\$cashier = User::firstOrCreate(
['email' => 'cashier@test.com'],
['name' => 'Test Cashier', 'password' => bcrypt('password')]
);
\$cashier->assignRole('finance_cashier');
echo 'Created: cashier@test.com (password: password)' . PHP_EOL;
// Create test accountant
\$accountant = User::firstOrCreate(
['email' => 'accountant@test.com'],
['name' => 'Test Accountant', 'password' => bcrypt('password')]
);
\$accountant->assignRole('finance_accountant');
echo 'Created: accountant@test.com (password: password)' . PHP_EOL;
// Create test chair
\$chair = User::firstOrCreate(
['email' => 'chair@test.com'],
['name' => 'Test Chair', 'password' => bcrypt('password')]
);
\$chair->assignRole('finance_chair');
echo 'Created: chair@test.com (password: password)' . PHP_EOL;
// Create test requester
\$requester = User::firstOrCreate(
['email' => 'requester@test.com'],
['name' => 'Test Requester', 'password' => bcrypt('password')]
);
\$requester->assignRole('finance_requester');
echo 'Created: requester@test.com (password: password)' . PHP_EOL;
"
print_success "Test users created successfully"
echo ""
print_info "Test users created with password: 'password'"
else
print_info "Skipping test user creation"
fi
echo ""
# Step 4: Clear caches
echo "======================================================================"
echo "Step 4: Clearing Caches"
echo "======================================================================"
echo ""
print_info "Clearing application caches..."
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
print_success "Caches cleared"
echo ""
# Step 5: Summary
echo "======================================================================"
echo "Setup Complete! 🎉"
echo "======================================================================"
echo ""
print_success "Financial workflow system is now ready to use!"
echo ""
echo "Next steps:"
echo "1. Assign financial roles to your users"
echo "2. Create your first finance document"
echo "3. Test the complete workflow:"
echo ""
echo " Workflow stages:"
echo " ├─ Stage 1: Approval (Cashier → Accountant → Chair → Board)"
echo " ├─ Stage 2: Payment (Accountant creates → Cashier verifies → Cashier executes)"
echo " ├─ Stage 3: Recording (Cashier ledger + Accountant transactions)"
echo " └─ Stage 4: Reconciliation (Monthly bank reconciliation)"
echo ""
echo "Key routes:"
echo " - Finance Documents: /admin/finance-documents"
echo " - Payment Orders: /admin/payment-orders"
echo " - Cashier Ledger: /admin/cashier-ledger"
echo " - Bank Reconciliations: /admin/bank-reconciliations"
echo ""
print_info "For detailed testing instructions, see: tests/FINANCIAL_WORKFLOW_TEST_PLAN.md"
echo ""
exit 0