add controllers, servoices

This commit is contained in:
root
2026-03-09 02:52:13 -04:00
parent c8de5f7edc
commit d76c871cb7
501 changed files with 34439 additions and 21843 deletions
@@ -0,0 +1,53 @@
<?php
namespace App\Services\Reimbursements;
use App\Models\Expense;
use App\Models\ReimbursementBatchItem;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use RuntimeException;
class ReimbursementDonationService
{
public function markDonation(int $expenseId, int $userId): void
{
if ($expenseId <= 0) {
throw new RuntimeException('Invalid expense id.');
}
$expense = Expense::query()->find($expenseId);
if (!$expense) {
throw new RuntimeException('Expense not found.');
}
if (!empty($expense->reimbursement_id)) {
throw new RuntimeException('Expense is already tied to a reimbursement.');
}
$now = now();
DB::beginTransaction();
try {
ReimbursementBatchItem::query()
->where('expense_id', $expenseId)
->whereNull('unassigned_at')
->update(['unassigned_at' => $now]);
$expense->update([
'category' => 'Donation',
'status' => 'approved',
'status_reason' => 'Marked as Donation (non-reimbursable).',
'approved_by' => $userId ?: null,
'updated_by' => $userId ?: null,
'reimbursement_id' => null,
]);
DB::commit();
} catch (\Throwable $e) {
DB::rollBack();
Log::error('Failed to mark donation: ' . $e->getMessage(), ['expense_id' => $expenseId]);
throw new RuntimeException('Unable to mark donation right now.');
}
}
}