Add phone login support and member import functionality
Features: - Support login via phone number or email (LoginRequest) - Add members:import-roster command for Excel roster import - Merge survey emails with roster data Code Quality (Phase 1-4): - Add database locking for balance calculation - Add self-approval checks for finance workflow - Create service layer (FinanceDocumentApprovalService, PaymentVerificationService) - Add HasAccountingEntries and HasApprovalWorkflow traits - Create FormRequest classes for validation - Add status-badge component - Define authorization gates in AuthServiceProvider - Add accounting config file Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\StoreFinanceDocumentRequest;
|
||||
use App\Mail\FinanceDocumentApprovedByAccountant;
|
||||
use App\Mail\FinanceDocumentApprovedByCashier;
|
||||
use App\Mail\FinanceDocumentFullyApproved;
|
||||
use App\Mail\FinanceDocumentRejected;
|
||||
use App\Mail\FinanceDocumentSubmitted;
|
||||
@@ -12,6 +12,7 @@ use App\Models\Member;
|
||||
use App\Models\User;
|
||||
use App\Support\AuditLogger;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class FinanceDocumentController extends Controller
|
||||
@@ -39,16 +40,16 @@ class FinanceDocumentController extends Controller
|
||||
$query->whereNull('payment_order_created_at');
|
||||
} elseif ($stage === 'payment') {
|
||||
$query->whereNotNull('payment_order_created_at')
|
||||
->whereNull('payment_executed_at');
|
||||
->whereNull('payment_executed_at');
|
||||
} elseif ($stage === 'recording') {
|
||||
$query->whereNotNull('payment_executed_at')
|
||||
->where(function($q) {
|
||||
$q->whereNull('cashier_ledger_entry_id')
|
||||
->where(function ($q) {
|
||||
$q->whereNull('cashier_ledger_entry_id')
|
||||
->orWhereNull('accounting_transaction_id');
|
||||
});
|
||||
});
|
||||
} elseif ($stage === 'completed') {
|
||||
$query->whereNotNull('cashier_ledger_entry_id')
|
||||
->whereNotNull('accounting_transaction_id');
|
||||
->whereNotNull('accounting_transaction_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,15 +69,9 @@ class FinanceDocumentController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
public function store(StoreFinanceDocumentRequest $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'member_id' => ['nullable', 'exists:members,id'],
|
||||
'title' => ['required', 'string', 'max:255'],
|
||||
'amount' => ['required', 'numeric', 'min:0'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'attachment' => ['nullable', 'file', 'max:10240'], // 10MB max
|
||||
]);
|
||||
$validated = $request->validated();
|
||||
|
||||
$attachmentPath = null;
|
||||
if ($request->hasFile('attachment')) {
|
||||
@@ -114,7 +109,7 @@ class FinanceDocumentController extends Controller
|
||||
|
||||
return redirect()
|
||||
->route('admin.finance.index')
|
||||
->with('status', '報銷申請單已提交。金額級別:' . $document->getAmountTierText());
|
||||
->with('status', '報銷申請單已提交。金額級別:'.$document->getAmountTierText());
|
||||
}
|
||||
|
||||
public function show(FinanceDocument $financeDocument)
|
||||
@@ -275,6 +270,7 @@ class FinanceDocumentController extends Controller
|
||||
// 檢查是否雙重確認完成
|
||||
if ($financeDocument->isDisbursementComplete()) {
|
||||
$financeDocument->update(['disbursement_status' => FinanceDocument::DISBURSEMENT_COMPLETED]);
|
||||
|
||||
return redirect()
|
||||
->route('admin.finance.show', $financeDocument)
|
||||
->with('status', '出帳確認完成。等待會計入帳。');
|
||||
@@ -286,7 +282,7 @@ class FinanceDocumentController extends Controller
|
||||
}
|
||||
|
||||
// 出納確認
|
||||
if (($isCashier || $isAdmin) && $financeDocument->canCashierConfirmDisbursement()) {
|
||||
if (($isCashier || $isAdmin) && $financeDocument->canCashierConfirmDisbursement($user)) {
|
||||
$financeDocument->update([
|
||||
'cashier_confirmed_at' => now(),
|
||||
'cashier_confirmed_by_id' => $user->id,
|
||||
@@ -299,6 +295,7 @@ class FinanceDocumentController extends Controller
|
||||
// 檢查是否雙重確認完成
|
||||
if ($financeDocument->isDisbursementComplete()) {
|
||||
$financeDocument->update(['disbursement_status' => FinanceDocument::DISBURSEMENT_COMPLETED]);
|
||||
|
||||
return redirect()
|
||||
->route('admin.finance.show', $financeDocument)
|
||||
->with('status', '出帳確認完成。等待會計入帳。');
|
||||
@@ -322,26 +319,29 @@ class FinanceDocumentController extends Controller
|
||||
$isAccountant = $user->hasRole('finance_accountant');
|
||||
$isAdmin = $user->hasRole('admin');
|
||||
|
||||
if (!$financeDocument->canAccountantConfirmRecording()) {
|
||||
if (! $financeDocument->canAccountantConfirmRecording()) {
|
||||
abort(403, '此文件尚未完成出帳確認,無法入帳。');
|
||||
}
|
||||
|
||||
if (!$isAccountant && !$isAdmin) {
|
||||
if (! $isAccountant && ! $isAdmin) {
|
||||
abort(403, '只有會計可以確認入帳。');
|
||||
}
|
||||
|
||||
$financeDocument->update([
|
||||
'accountant_recorded_at' => now(),
|
||||
'accountant_recorded_by_id' => $user->id,
|
||||
'recording_status' => FinanceDocument::RECORDING_COMPLETED,
|
||||
]);
|
||||
// 使用交易確保資料完整性:如果會計分錄產生失敗,不應標記為已入帳
|
||||
DB::transaction(function () use ($financeDocument, $user) {
|
||||
$financeDocument->update([
|
||||
'accountant_recorded_at' => now(),
|
||||
'accountant_recorded_by_id' => $user->id,
|
||||
'recording_status' => FinanceDocument::RECORDING_COMPLETED,
|
||||
]);
|
||||
|
||||
// 自動產生會計分錄
|
||||
$financeDocument->autoGenerateAccountingEntries();
|
||||
// 自動產生會計分錄
|
||||
$financeDocument->autoGenerateAccountingEntries();
|
||||
|
||||
AuditLogger::log('finance_document.accountant_confirmed_recording', $financeDocument, [
|
||||
'confirmed_by' => $user->name,
|
||||
]);
|
||||
AuditLogger::log('finance_document.accountant_confirmed_recording', $financeDocument, [
|
||||
'confirmed_by' => $user->name,
|
||||
]);
|
||||
});
|
||||
|
||||
return redirect()
|
||||
->route('admin.finance.show', $financeDocument)
|
||||
@@ -369,7 +369,7 @@ class FinanceDocumentController extends Controller
|
||||
$user->hasRole('finance_chair') ||
|
||||
$user->hasRole('finance_board_member');
|
||||
|
||||
if (!$canReject) {
|
||||
if (! $canReject) {
|
||||
abort(403, '您無權駁回此文件。');
|
||||
}
|
||||
|
||||
@@ -396,13 +396,13 @@ class FinanceDocumentController extends Controller
|
||||
|
||||
public function download(FinanceDocument $financeDocument)
|
||||
{
|
||||
if (!$financeDocument->attachment_path) {
|
||||
if (! $financeDocument->attachment_path) {
|
||||
abort(404, 'No attachment found.');
|
||||
}
|
||||
|
||||
$path = storage_path('app/' . $financeDocument->attachment_path);
|
||||
$path = storage_path('app/'.$financeDocument->attachment_path);
|
||||
|
||||
if (!file_exists($path)) {
|
||||
if (! file_exists($path)) {
|
||||
abort(404, 'Attachment file not found.');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user