fix tests
This commit is contained in:
@@ -8,6 +8,7 @@ use Illuminate\Console\Command;
|
||||
class AttendanceAutoPublishCommand extends Command
|
||||
{
|
||||
protected $signature = 'attendance:auto-publish';
|
||||
|
||||
protected $description = 'Auto-publish attendance days per "second Sunday backward" rule.';
|
||||
|
||||
public function handle(AttendanceAutoPublishJobService $service): int
|
||||
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Console\Command;
|
||||
class CheckMissedPaymentsCommand extends Command
|
||||
{
|
||||
protected $signature = 'payments:check-missed';
|
||||
|
||||
protected $description = 'Checks for users who missed payments and sends reminders.';
|
||||
|
||||
public function handle(PaymentMissedCheckService $service): int
|
||||
@@ -15,6 +16,7 @@ class CheckMissedPaymentsCommand extends Command
|
||||
$users = $service->findUsersWithMissedPayments();
|
||||
if (empty($users)) {
|
||||
$this->info('No missed payments found.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Console\Command;
|
||||
class CleanupExpiredNotificationsCommand extends Command
|
||||
{
|
||||
protected $signature = 'notifications:cleanup';
|
||||
|
||||
protected $description = 'Deletes expired notifications from the database.';
|
||||
|
||||
public function handle(NotificationCleanupService $service): int
|
||||
@@ -16,6 +17,7 @@ class CleanupExpiredNotificationsCommand extends Command
|
||||
|
||||
if ($count <= 0) {
|
||||
$this->info('No expired notifications found to soft delete.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Console\Command;
|
||||
class CleanupPasswordResetsCommand extends Command
|
||||
{
|
||||
protected $signature = 'cleanup:password-resets {--days=30}';
|
||||
|
||||
protected $description = 'Delete password reset requests older than N days.';
|
||||
|
||||
public function handle(PasswordResetCleanupService $service): int
|
||||
|
||||
@@ -9,6 +9,7 @@ use Illuminate\Console\Command;
|
||||
class ConfigUpdateCommand extends Command
|
||||
{
|
||||
protected $signature = 'config:update {task?} {--task=} {--dry} {--force} {--tz=}';
|
||||
|
||||
protected $description = 'Run a configuration update task (weekly cron).';
|
||||
|
||||
public function handle(ConfigUpdateService $service): int
|
||||
@@ -19,18 +20,20 @@ class ConfigUpdateCommand extends Command
|
||||
$tzName = (string) ($this->option('tz') ?: (config('School')->attendance['timezone'] ?? 'UTC'));
|
||||
$tz = new DateTimeZone($tzName);
|
||||
|
||||
if ($task === '' || !in_array($task, $service->availableTasks(), true)) {
|
||||
$this->error('Invalid or missing --task. Available: ' . implode(', ', $service->availableTasks()));
|
||||
if ($task === '' || ! in_array($task, $service->availableTasks(), true)) {
|
||||
$this->error('Invalid or missing --task. Available: '.implode(', ', $service->availableTasks()));
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$result = $service->runTask($task, $dry, $force, $tz);
|
||||
if (!$result['ok']) {
|
||||
if (! $result['ok']) {
|
||||
$this->error($result['message'] ?? "Task '{$task}' failed.");
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->info("Task '{$task}' finished successfully." . ($dry ? ' [DRY RUN]' : ''));
|
||||
$this->info("Task '{$task}' finished successfully.".($dry ? ' [DRY RUN]' : ''));
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Console\Command;
|
||||
class DeleteInactiveUsersCommand extends Command
|
||||
{
|
||||
protected $signature = 'users:delete-inactive-users {--minutes=15}';
|
||||
|
||||
protected $description = 'Delete users that are inactive and created more than N minutes ago.';
|
||||
|
||||
public function handle(InactiveUserCleanupService $service): int
|
||||
|
||||
@@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Event;
|
||||
class DeleteUnverifiedUsersCommand extends Command
|
||||
{
|
||||
protected $signature = 'users:delete-unverified {--timeout=86400}';
|
||||
|
||||
protected $description = 'Delete unverified users older than the configured timeout (seconds).';
|
||||
|
||||
public function handle(): int
|
||||
|
||||
@@ -39,6 +39,7 @@ class InventoryReconcile extends Command
|
||||
|
||||
if (empty($result['discrepancies'])) {
|
||||
$this->info('✅ All item quantities match movement ledger.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -62,7 +63,7 @@ class InventoryReconcile extends Command
|
||||
qtyChange: -$d['variance'],
|
||||
type: 'adjust',
|
||||
reason: 'Auto-reconciliation: stored qty differed from movement sum',
|
||||
note: 'Reconciled from ' . $d['stored_quantity'] . ' to ' . $d['movement_sum'],
|
||||
note: 'Reconciled from '.$d['stored_quantity'].' to '.$d['movement_sum'],
|
||||
performedBy: null
|
||||
);
|
||||
$this->line(" Fixed item #{$d['id']} ({$d['name']}): variance was {$d['variance']}");
|
||||
|
||||
@@ -8,12 +8,13 @@ use Illuminate\Console\Command;
|
||||
class RecalculateAttendanceCommand extends Command
|
||||
{
|
||||
protected $signature = 'attendance:recalculate-summary';
|
||||
|
||||
protected $description = 'Recalculates the attendance summary records from raw attendance data.';
|
||||
|
||||
public function handle(AttendanceSummaryRebuildService $service): int
|
||||
{
|
||||
$result = $service->rebuild();
|
||||
$this->info('Attendance summary recalculation finished. Inserted: ' . $result['inserted']);
|
||||
$this->info('Attendance summary recalculation finished. Inserted: '.$result['inserted']);
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Console\Command;
|
||||
class SendAbsenteesSummaryCommand extends Command
|
||||
{
|
||||
protected $signature = 'attendance:absentees-summary';
|
||||
|
||||
protected $description = 'Sends daily attendance summaries for absences to parents.';
|
||||
|
||||
public function handle(AttendanceDailySummaryService $service): int
|
||||
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Console\Command;
|
||||
class SendLatesSummaryCommand extends Command
|
||||
{
|
||||
protected $signature = 'attendance:lates-summary';
|
||||
|
||||
protected $description = 'Sends daily attendance summaries for lates to parents.';
|
||||
|
||||
public function handle(AttendanceDailySummaryService $service): int
|
||||
|
||||
@@ -9,6 +9,7 @@ use Illuminate\Console\Command;
|
||||
class SendMonthlyPaymentNotificationsCommand extends Command
|
||||
{
|
||||
protected $signature = 'payments:monthly-reminder {--force} {--email=} {--type=}';
|
||||
|
||||
protected $description = 'Send monthly payment reminders on the first Saturday of every month.';
|
||||
|
||||
public function handle(PaymentNotificationService $service): int
|
||||
@@ -19,8 +20,9 @@ class SendMonthlyPaymentNotificationsCommand extends Command
|
||||
|
||||
if ($email !== '') {
|
||||
$user = User::query()->where('email', $email)->first();
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
$this->error('Invalid --email provided.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
@@ -30,12 +32,14 @@ class SendMonthlyPaymentNotificationsCommand extends Command
|
||||
'force' => true,
|
||||
]);
|
||||
|
||||
$this->info('Test reminder sent for ' . $email . '.');
|
||||
$this->info('Test reminder sent for '.$email.'.');
|
||||
|
||||
return $result['failed'] > 0 ? self::FAILURE : self::SUCCESS;
|
||||
}
|
||||
|
||||
if (!$force && !$this->isFirstSaturday(now())) {
|
||||
if (! $force && ! $this->isFirstSaturday(now())) {
|
||||
$this->info('Not the first Saturday of the month. Use --force to override.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Console\Command;
|
||||
class SendTestPaymentNotificationCommand extends Command
|
||||
{
|
||||
protected $signature = 'payments:send-test {--email=} {--type=no_payment}';
|
||||
|
||||
protected $description = 'Send a single test non-payment or installment reminder to a specific email.';
|
||||
|
||||
public function handle(PaymentTestNotificationService $service): int
|
||||
@@ -15,18 +16,20 @@ class SendTestPaymentNotificationCommand extends Command
|
||||
$email = (string) $this->option('email');
|
||||
$type = (string) $this->option('type');
|
||||
|
||||
if ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
if ($email === '' || ! filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$this->error('Usage: php artisan payments:send-test --email=addr@example.com [--type=no_payment|installment]');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$result = $service->send($email, $type);
|
||||
if (!$result['ok']) {
|
||||
$this->error('Failed to send test reminder to ' . $email . '.');
|
||||
if (! $result['ok']) {
|
||||
$this->error('Failed to send test reminder to '.$email.'.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->info('Sent test reminder to ' . $email . '.');
|
||||
$this->info('Sent test reminder to '.$email.'.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Console\Command;
|
||||
class SyncPaypalPaymentsCommand extends Command
|
||||
{
|
||||
protected $signature = 'payments:sync-paypal {--dry-run} {--report-only}';
|
||||
|
||||
protected $description = 'Sync PayPal payments to internal payments table from paypal_payments.';
|
||||
|
||||
public function handle(PaypalPaymentSyncService $service): int
|
||||
@@ -18,7 +19,7 @@ class SyncPaypalPaymentsCommand extends Command
|
||||
$result = $service->sync($dryRun, $reportOnly);
|
||||
|
||||
$this->info(sprintf('[%s] %d PayPal payments processed.', $result['mode'], $result['processed']));
|
||||
if (!empty($result['failed'])) {
|
||||
if (! empty($result['failed'])) {
|
||||
$this->error(sprintf('[%s] Failed transactions: %s', $result['mode'], implode(', ', $result['failed'])));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,5 @@ namespace App\Events;
|
||||
|
||||
class DeleteUnverifiedUser
|
||||
{
|
||||
public function __construct(public int $userId)
|
||||
{
|
||||
}
|
||||
public function __construct(public int $userId) {}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,5 @@ class WhatsappInvitesSend
|
||||
use Dispatchable;
|
||||
use SerializesModels;
|
||||
|
||||
public function __construct(public array $payload)
|
||||
{
|
||||
}
|
||||
public function __construct(public array $payload) {}
|
||||
}
|
||||
|
||||
@@ -3,33 +3,34 @@
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
if (!function_exists('utc_now')) {
|
||||
if (! function_exists('utc_now')) {
|
||||
function utc_now(): string
|
||||
{
|
||||
return CarbonImmutable::now('UTC')->toDateTimeString();
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('local_date')) {
|
||||
if (! function_exists('local_date')) {
|
||||
function local_date(string $utcDateTime, string $format = 'Y-m-d H:i:s'): string
|
||||
{
|
||||
try {
|
||||
$carbon = CarbonImmutable::parse($utcDateTime)->setTimezone(config('app.timezone'));
|
||||
|
||||
return $carbon->format($format);
|
||||
} catch (\Throwable $e) {
|
||||
} catch (Throwable $e) {
|
||||
return CarbonImmutable::parse($utcDateTime)->format($format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('user_timezone')) {
|
||||
if (! function_exists('user_timezone')) {
|
||||
function user_timezone(): string
|
||||
{
|
||||
return (string) (config('School')->attendance['timezone'] ?? config('app.timezone', 'America/New_York'));
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('pbkdf2_hash')) {
|
||||
if (! function_exists('pbkdf2_hash')) {
|
||||
function pbkdf2_hash(string $password, string $algo = 'sha256', int $iterations = 100000, int $length = 64): string
|
||||
{
|
||||
$salt = random_bytes(16);
|
||||
@@ -41,7 +42,7 @@ if (!function_exists('pbkdf2_hash')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('pbkdf2_verify')) {
|
||||
if (! function_exists('pbkdf2_verify')) {
|
||||
function pbkdf2_verify(string $password, string $storedHash): bool
|
||||
{
|
||||
$delim = strpos($storedHash, '$') !== false ? '$' : ':';
|
||||
@@ -62,14 +63,15 @@ if (!function_exists('pbkdf2_verify')) {
|
||||
}
|
||||
|
||||
$calc = hash_pbkdf2($algo, $password, $salt, (int) $iterations, strlen($derived), true);
|
||||
|
||||
return hash_equals($derived, $calc);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('verify_stored_password')) {
|
||||
if (! function_exists('verify_stored_password')) {
|
||||
function verify_stored_password(string $password, ?string $storedHash): bool
|
||||
{
|
||||
if (!$storedHash) {
|
||||
if (! $storedHash) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,7 @@ class AdministratorAbsenceController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected AdministratorAbsenceService $service
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
@@ -34,7 +33,7 @@ class AdministratorAbsenceController extends Controller
|
||||
}
|
||||
|
||||
$payload = $request->all();
|
||||
if (!array_key_exists('dates', $payload) || !array_key_exists('reason', $payload)) {
|
||||
if (! array_key_exists('dates', $payload) || ! array_key_exists('reason', $payload)) {
|
||||
$json = json_decode($request->getContent() ?: '', true);
|
||||
if (is_array($json)) {
|
||||
$payload = array_merge($payload, $json);
|
||||
|
||||
@@ -11,8 +11,7 @@ class AdministratorDashboardController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected AdministratorDashboardService $service
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function metrics(): JsonResponse
|
||||
{
|
||||
@@ -25,4 +24,4 @@ class AdministratorDashboardController extends Controller
|
||||
$this->service->userSearch((string) $request->query('query', ''))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,7 @@ class AdministratorEnrollmentController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected AdministratorEnrollmentService $service
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@@ -39,13 +38,13 @@ class AdministratorEnrollmentController extends Controller
|
||||
}
|
||||
|
||||
$payload = $request->all();
|
||||
if (!array_key_exists('enrollment_status', $payload)) {
|
||||
if (! array_key_exists('enrollment_status', $payload)) {
|
||||
$json = json_decode($request->getContent() ?: '', true);
|
||||
if (is_array($json) && array_key_exists('enrollment_status', $json)) {
|
||||
$payload['enrollment_status'] = $json['enrollment_status'];
|
||||
}
|
||||
}
|
||||
if (!array_key_exists('enrollment_status', $payload)) {
|
||||
if (! array_key_exists('enrollment_status', $payload)) {
|
||||
$payload['enrollment_status'] = $request->query('enrollment_status');
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@ class AdministratorNotificationController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected AdministratorNotificationService $service
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function alerts(): JsonResponse
|
||||
{
|
||||
@@ -23,7 +22,7 @@ class AdministratorNotificationController extends Controller
|
||||
public function saveAlerts(Request $request): JsonResponse
|
||||
{
|
||||
$payload = $request->all();
|
||||
if (!array_key_exists('subjects', $payload)) {
|
||||
if (! array_key_exists('subjects', $payload)) {
|
||||
$json = json_decode($request->getContent() ?: '', true);
|
||||
if (is_array($json)) {
|
||||
$payload = array_merge($payload, $json);
|
||||
@@ -60,7 +59,7 @@ class AdministratorNotificationController extends Controller
|
||||
public function savePrintRecipients(Request $request): JsonResponse
|
||||
{
|
||||
$payload = $request->all();
|
||||
if (!array_key_exists('notify', $payload)) {
|
||||
if (! array_key_exists('notify', $payload)) {
|
||||
$json = json_decode($request->getContent() ?: '', true);
|
||||
if (is_array($json)) {
|
||||
$payload = array_merge($payload, $json);
|
||||
|
||||
@@ -16,18 +16,18 @@ use App\Http\Resources\Promotions\PromotionReminderResource;
|
||||
use App\Http\Resources\Promotions\StudentPromotionResource;
|
||||
use App\Models\PromotionAuditLog;
|
||||
use App\Models\PromotionReminderLog;
|
||||
use App\Models\SectionPlacementBatch;
|
||||
use App\Models\StudentPromotionRecord;
|
||||
use App\Services\Promotions\LevelProgressionService;
|
||||
use App\Services\Promotions\Placement\SectionPlacementPreviewService;
|
||||
use App\Services\Promotions\PromotionAuditService;
|
||||
use App\Services\Promotions\PromotionEligibilityService;
|
||||
use App\Services\Promotions\PromotionEnrollmentService;
|
||||
use App\Services\Promotions\PromotionQueryService;
|
||||
use App\Services\Promotions\PromotionReminderService;
|
||||
use App\Services\Promotions\PromotionStatusService;
|
||||
use App\Services\Promotions\Placement\SectionPlacementPreviewService;
|
||||
use App\Models\SectionPlacementBatch;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -54,6 +54,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
public function index(AdminListPromotionsRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->query->list($request->filters());
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'data' => StudentPromotionResource::collection($result['data']),
|
||||
@@ -73,6 +74,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
if ($record instanceof JsonResponse) {
|
||||
return $record;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'data' => new StudentPromotionResource($this->query->detail($record)),
|
||||
@@ -82,6 +84,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
public function summary(AdminListPromotionsRequest $request): JsonResponse
|
||||
{
|
||||
$counts = $this->query->countsByStatus($request->filters());
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'counts_by_status' => $counts,
|
||||
@@ -125,6 +128,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
};
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Promotion eligibility evaluation failed', ['exception' => $e]);
|
||||
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'Failed to evaluate promotion eligibility.',
|
||||
@@ -137,7 +141,6 @@ class AdministratorPromotionController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function createPlacementPreview(Request $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validate([
|
||||
@@ -157,6 +160,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Section placement preview generation failed', ['exception' => $e]);
|
||||
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => $e->getMessage(),
|
||||
@@ -172,7 +176,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
public function showPlacementBatch(int $batchId): JsonResponse
|
||||
{
|
||||
$batch = SectionPlacementBatch::query()->find($batchId);
|
||||
if (!$batch) {
|
||||
if (! $batch) {
|
||||
return response()->json(['ok' => false, 'message' => 'Placement batch not found.'], Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -188,6 +192,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
$batch = $this->sectionPlacement->finalize($batchId, $this->getCurrentUserId());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Section placement finalization failed', ['batch_id' => $batchId, 'exception' => $e]);
|
||||
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => $e->getMessage(),
|
||||
@@ -211,7 +216,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
$userId = $this->getCurrentUserId();
|
||||
|
||||
try {
|
||||
$updated = !empty($payload['force'])
|
||||
$updated = ! empty($payload['force'])
|
||||
? $this->statusService->forceStatus($record, $payload['status'], $userId, $payload['notes'] ?? null)
|
||||
: $this->statusService->transition($record, $payload['status'], $userId, $payload['notes'] ?? null);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
@@ -244,7 +249,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
return $record;
|
||||
}
|
||||
$records = collect([$record]);
|
||||
} elseif ($applyTo === 'filter' && !empty($payload['promotion_ids'])) {
|
||||
} elseif ($applyTo === 'filter' && ! empty($payload['promotion_ids'])) {
|
||||
$records = StudentPromotionRecord::query()
|
||||
->whereIn('promotion_id', $payload['promotion_ids'])
|
||||
->get();
|
||||
@@ -305,6 +310,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
'promotion_id' => $promotionId,
|
||||
'exception' => $e,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'Failed to send reminder.',
|
||||
@@ -321,6 +327,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
{
|
||||
$userId = $this->getCurrentUserId();
|
||||
$result = $this->reminders->dispatchScheduledReminders(null, $userId);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'result' => $result,
|
||||
@@ -337,6 +344,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
->forPromotion((int) $record->getKey())
|
||||
->orderByDesc('id')
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'reminders' => PromotionReminderResource::collection($rows),
|
||||
@@ -353,6 +361,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
->forPromotion((int) $record->getKey())
|
||||
->orderByDesc('id')
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'entries' => PromotionAuditLogResource::collection($rows),
|
||||
@@ -362,6 +371,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
public function expireDeadlines(): JsonResponse
|
||||
{
|
||||
$result = $this->enrollmentService->markExpiredDeadlines(null, $this->getCurrentUserId());
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'result' => $result,
|
||||
@@ -404,6 +414,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
public function levelProgressions(): JsonResponse
|
||||
{
|
||||
$rows = $this->progression->list(false);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'levels' => LevelProgressionResource::collection($rows),
|
||||
@@ -413,6 +424,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
public function upsertLevelProgression(UpsertLevelProgressionRequest $request): JsonResponse
|
||||
{
|
||||
$row = $this->progression->upsertMapping($request->validated());
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'level' => new LevelProgressionResource($row),
|
||||
@@ -422,6 +434,7 @@ class AdministratorPromotionController extends BaseApiController
|
||||
public function seedLevelProgressions(): JsonResponse
|
||||
{
|
||||
$created = $this->progression->seedDefaults();
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'created' => $created,
|
||||
@@ -431,12 +444,13 @@ class AdministratorPromotionController extends BaseApiController
|
||||
private function findOrFail(int $promotionId): StudentPromotionRecord|JsonResponse
|
||||
{
|
||||
$record = StudentPromotionRecord::query()->find($promotionId);
|
||||
if (!$record) {
|
||||
if (! $record) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'Promotion record not found.',
|
||||
], Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@ class AdministratorTeacherSubmissionController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected AdministratorTeacherSubmissionService $service
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
|
||||
@@ -18,8 +18,7 @@ class EmergencyContactController extends Controller
|
||||
public function __construct(
|
||||
private EmergencyContactDirectoryService $directoryService,
|
||||
private EmergencyContactCrudService $crudService
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@@ -38,10 +37,10 @@ class EmergencyContactController extends Controller
|
||||
|
||||
$payload = $validator->validated();
|
||||
$parentIds = [];
|
||||
if (!empty($payload['parent_ids'])) {
|
||||
if (! empty($payload['parent_ids'])) {
|
||||
$parentIds = array_values(array_unique(array_map('intval', $payload['parent_ids'])));
|
||||
}
|
||||
if (!empty($payload['parent_id'])) {
|
||||
if (! empty($payload['parent_id'])) {
|
||||
$parentIds[] = (int) $payload['parent_id'];
|
||||
}
|
||||
$parentIds = array_values(array_unique(array_filter($parentIds)));
|
||||
|
||||
@@ -61,9 +61,6 @@ class TeacherClassAssignmentController extends BaseApiController
|
||||
], $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -23,8 +23,8 @@ class AdminAttendanceApiController extends Controller
|
||||
{
|
||||
return new DailyAttendanceResource(
|
||||
$this->queryService->buildDailyAttendanceData(
|
||||
(string)$request->query('semester', $this->attendanceService->currentSemester()),
|
||||
(string)$request->query('school_year', $this->attendanceService->currentSchoolYear())
|
||||
(string) $request->query('semester', $this->attendanceService->currentSemester()),
|
||||
(string) $request->query('school_year', $this->attendanceService->currentSchoolYear())
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -60,4 +60,4 @@ class AdminAttendanceApiController extends Controller
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,7 @@ class AttendanceCommentTemplateController extends Controller
|
||||
public function __construct(
|
||||
protected AttendanceCommentTemplateService $service,
|
||||
protected ApplicationUrlService $urls,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function bootstrapUrls(): JsonResponse
|
||||
{
|
||||
@@ -75,7 +74,7 @@ class AttendanceCommentTemplateController extends Controller
|
||||
}
|
||||
|
||||
$data = $validator->validated();
|
||||
if (!array_key_exists('is_active', $data)) {
|
||||
if (! array_key_exists('is_active', $data)) {
|
||||
$data['is_active'] = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
@@ -27,7 +26,7 @@ class EarlyDismissalsController extends BaseApiController
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$schoolYear = $request->query('school_year');
|
||||
$semester = $request->query('semester');
|
||||
$semester = $request->query('semester');
|
||||
|
||||
$query = DB::table('parent_attendance_reports as par')
|
||||
->select([
|
||||
@@ -62,15 +61,15 @@ class EarlyDismissalsController extends BaseApiController
|
||||
foreach ($rows as $row) {
|
||||
$date = $row->report_date ?? 'Unknown';
|
||||
$groups[$date][] = [
|
||||
'id' => $row->id,
|
||||
'firstname' => $row->firstname,
|
||||
'lastname' => $row->lastname,
|
||||
'id' => $row->id,
|
||||
'firstname' => $row->firstname,
|
||||
'lastname' => $row->lastname,
|
||||
'class_section_name' => $row->class_section_name,
|
||||
'dismiss_time' => $row->dismiss_time,
|
||||
'reason' => $row->reason,
|
||||
'status' => $row->status,
|
||||
'school_year' => $row->school_year,
|
||||
'semester' => $row->semester,
|
||||
'dismiss_time' => $row->dismiss_time,
|
||||
'reason' => $row->reason,
|
||||
'status' => $row->status,
|
||||
'school_year' => $row->school_year,
|
||||
'semester' => $row->semester,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -82,13 +81,13 @@ class EarlyDismissalsController extends BaseApiController
|
||||
$signatureByDate = [];
|
||||
foreach ($signatures as $sig) {
|
||||
$signatureByDate[(string) $sig->report_date] = [
|
||||
'filename' => $sig->filename,
|
||||
'filename' => $sig->filename,
|
||||
'original_name' => $sig->original_name,
|
||||
];
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'groups' => $groups,
|
||||
'groups' => $groups,
|
||||
'signatureByDate' => $signatureByDate,
|
||||
]);
|
||||
}
|
||||
@@ -108,7 +107,7 @@ class EarlyDismissalsController extends BaseApiController
|
||||
])
|
||||
->leftJoin('student_class as sc', function ($j) {
|
||||
$j->on('sc.student_id', '=', 's.id')
|
||||
->where('sc.school_year', '=', Configuration::getConfigValueByKey('school_year'));
|
||||
->where('sc.school_year', '=', Configuration::getConfigValueByKey('school_year'));
|
||||
})
|
||||
->leftJoin('classSection as cs', 'cs.class_section_id', '=', 'sc.class_section_id')
|
||||
->where('s.is_active', 1)
|
||||
@@ -125,10 +124,10 @@ class EarlyDismissalsController extends BaseApiController
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'student_id' => ['required', 'integer', 'min:1', 'exists:students,id'],
|
||||
'date' => ['required', 'date_format:Y-m-d'],
|
||||
'student_id' => ['required', 'integer', 'min:1', 'exists:students,id'],
|
||||
'date' => ['required', 'date_format:Y-m-d'],
|
||||
'dismiss_time' => ['required', 'date_format:H:i'],
|
||||
'reason' => ['nullable', 'string', 'max:2000'],
|
||||
'reason' => ['nullable', 'string', 'max:2000'],
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
@@ -138,7 +137,7 @@ class EarlyDismissalsController extends BaseApiController
|
||||
$data = $validator->validated();
|
||||
|
||||
$schoolYear = (string) Configuration::getConfigValueByKey('school_year');
|
||||
$semester = (string) Configuration::getConfigValueByKey('semester');
|
||||
$semester = (string) Configuration::getConfigValueByKey('semester');
|
||||
|
||||
$sc = DB::table('student_class')
|
||||
->where('student_id', $data['student_id'])
|
||||
@@ -153,18 +152,18 @@ class EarlyDismissalsController extends BaseApiController
|
||||
->value('parent_id') ?? Auth::id();
|
||||
|
||||
DB::table('parent_attendance_reports')->insert([
|
||||
'parent_id' => $parentId ?? Auth::id(),
|
||||
'student_id' => $data['student_id'],
|
||||
'parent_id' => $parentId ?? Auth::id(),
|
||||
'student_id' => $data['student_id'],
|
||||
'class_section_id' => $classSectionId,
|
||||
'report_date' => $data['date'],
|
||||
'type' => 'early_dismissal',
|
||||
'dismiss_time' => $data['dismiss_time'],
|
||||
'reason' => $data['reason'] ?? null,
|
||||
'semester' => $semester,
|
||||
'school_year' => $schoolYear,
|
||||
'status' => 'new',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
'report_date' => $data['date'],
|
||||
'type' => 'early_dismissal',
|
||||
'dismiss_time' => $data['dismiss_time'],
|
||||
'reason' => $data['reason'] ?? null,
|
||||
'semester' => $semester,
|
||||
'school_year' => $schoolYear,
|
||||
'status' => 'new',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return $this->success([], 'Early dismissal saved.', Response::HTTP_CREATED);
|
||||
@@ -177,9 +176,9 @@ class EarlyDismissalsController extends BaseApiController
|
||||
public function uploadSignature(Request $request): JsonResponse
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'report_date' => ['required', 'date_format:Y-m-d'],
|
||||
'school_year' => ['nullable', 'string', 'max:16'],
|
||||
'semester' => ['nullable', 'string', 'max:32'],
|
||||
'report_date' => ['required', 'date_format:Y-m-d'],
|
||||
'school_year' => ['nullable', 'string', 'max:16'],
|
||||
'semester' => ['nullable', 'string', 'max:32'],
|
||||
'signature_file' => ['required', 'file', 'mimes:jpg,jpeg,png,webp,gif,pdf', 'max:5120'],
|
||||
]);
|
||||
|
||||
@@ -187,13 +186,13 @@ class EarlyDismissalsController extends BaseApiController
|
||||
return $this->respondValidationError($validator->errors()->toArray());
|
||||
}
|
||||
|
||||
$file = $request->file('signature_file');
|
||||
$file = $request->file('signature_file');
|
||||
$reportDate = $request->input('report_date');
|
||||
$schoolYear = $request->input('school_year') ?: (string) Configuration::getConfigValueByKey('school_year');
|
||||
$semester = $request->input('semester') ?: (string) Configuration::getConfigValueByKey('semester');
|
||||
$semester = $request->input('semester') ?: (string) Configuration::getConfigValueByKey('semester');
|
||||
|
||||
$dir = storage_path('uploads/early_dismissal_signatures');
|
||||
if (!is_dir($dir)) {
|
||||
$dir = storage_path('uploads/early_dismissal_signatures');
|
||||
if (! is_dir($dir)) {
|
||||
mkdir($dir, 0755, true);
|
||||
}
|
||||
|
||||
@@ -203,21 +202,21 @@ class EarlyDismissalsController extends BaseApiController
|
||||
->where('semester', $semester)
|
||||
->first();
|
||||
|
||||
if ($existing?->filename && file_exists($dir . '/' . $existing->filename)) {
|
||||
unlink($dir . '/' . $existing->filename);
|
||||
if ($existing?->filename && file_exists($dir.'/'.$existing->filename)) {
|
||||
unlink($dir.'/'.$existing->filename);
|
||||
}
|
||||
|
||||
$filename = uniqid('sig_', true) . '.' . $file->getClientOriginalExtension();
|
||||
$filename = uniqid('sig_', true).'.'.$file->getClientOriginalExtension();
|
||||
$file->move($dir, $filename);
|
||||
|
||||
EarlyDismissalSignature::updateOrCreate(
|
||||
['report_date' => $reportDate, 'school_year' => $schoolYear, 'semester' => $semester],
|
||||
[
|
||||
'filename' => $filename,
|
||||
'filename' => $filename,
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'mime_type' => $file->getClientMimeType(),
|
||||
'file_size' => $file->getSize(),
|
||||
'uploaded_by' => Auth::id(),
|
||||
'mime_type' => $file->getClientMimeType(),
|
||||
'file_size' => $file->getSize(),
|
||||
'uploaded_by' => Auth::id(),
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class LateSlipLogsController extends BaseApiController
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$log = $this->queryService->find($id);
|
||||
if (!$log) {
|
||||
if (! $log) {
|
||||
return $this->error('Late slip log not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class LateSlipLogsController extends BaseApiController
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$log = $this->queryService->find($id);
|
||||
if (!$log) {
|
||||
if (! $log) {
|
||||
return $this->error('Late slip log not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -65,11 +65,12 @@ class LateSlipLogsController extends BaseApiController
|
||||
try {
|
||||
$deleted = $this->commandService->delete($log);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Late slip log delete failed: ' . $e->getMessage());
|
||||
Log::error('Late slip log delete failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Unable to delete late slip log.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!$deleted) {
|
||||
if (! $deleted) {
|
||||
return $this->error('Unable to delete late slip log.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ class StaffAttendanceApiController extends Controller
|
||||
{
|
||||
return new StaffMonthResource(
|
||||
$this->staffAttendanceService->monthData(
|
||||
(string)$request->query('semester'),
|
||||
(string)$request->query('school_year')
|
||||
(string) $request->query('semester'),
|
||||
(string) $request->query('school_year')
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -33,9 +33,9 @@ class StaffAttendanceApiController extends Controller
|
||||
{
|
||||
return new AdminAttendanceResource(
|
||||
$this->staffAttendanceService->adminsAttendanceData(
|
||||
(string)$request->query('date'),
|
||||
(string)$request->query('semester'),
|
||||
(string)$request->query('school_year')
|
||||
(string) $request->query('date'),
|
||||
(string) $request->query('semester'),
|
||||
(string) $request->query('school_year')
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -75,9 +75,9 @@ class StaffAttendanceApiController extends Controller
|
||||
public function monthCsv(Request $request): StreamedResponse
|
||||
{
|
||||
return $this->staffAttendanceService->monthCsv(
|
||||
(string)$request->query('semester'),
|
||||
(string)$request->query('school_year'),
|
||||
(string)$request->query('scope')
|
||||
(string) $request->query('semester'),
|
||||
(string) $request->query('school_year'),
|
||||
(string) $request->query('scope')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ class TeacherAttendanceApiController extends Controller
|
||||
|
||||
public function grid(Request $request): TeacherGridResource
|
||||
{
|
||||
$semester = (string)($request->query('semester') ?: $this->attendanceService->currentSemester());
|
||||
$schoolYear = (string)($request->query('school_year') ?: $this->attendanceService->currentSchoolYear());
|
||||
$date = (string)($request->query('date') ?: now()->toDateString());
|
||||
$sectionCode = (int)$request->query('class_section_id', 0);
|
||||
$semester = (string) ($request->query('semester') ?: $this->attendanceService->currentSemester());
|
||||
$schoolYear = (string) ($request->query('school_year') ?: $this->attendanceService->currentSchoolYear());
|
||||
$date = (string) ($request->query('date') ?: now()->toDateString());
|
||||
$sectionCode = (int) $request->query('class_section_id', 0);
|
||||
|
||||
return new TeacherGridResource(
|
||||
$this->queryService->teacherGrid($semester, $schoolYear, $date, $sectionCode)
|
||||
@@ -42,7 +42,7 @@ class TeacherAttendanceApiController extends Controller
|
||||
return new TeacherAttendanceFormResource(
|
||||
$this->queryService->teacherAttendanceFormData(
|
||||
$guard,
|
||||
(int)$request->query('class_section_id', 0)
|
||||
(int) $request->query('class_section_id', 0)
|
||||
)
|
||||
);
|
||||
} catch (Throwable $e) {
|
||||
@@ -66,9 +66,6 @@ class TeacherAttendanceApiController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
@@ -78,4 +75,4 @@ class TeacherAttendanceApiController extends Controller
|
||||
|
||||
return $userId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,9 @@ class AttendanceManagementController extends BaseApiController
|
||||
'reason' => ['nullable', 'string', 'max:255'],
|
||||
'notes' => ['nullable', 'string'],
|
||||
]);
|
||||
if ($validator->fails()) return $this->respondValidationError($validator->errors()->toArray());
|
||||
if ($validator->fails()) {
|
||||
return $this->respondValidationError($validator->errors()->toArray());
|
||||
}
|
||||
try {
|
||||
return $this->success(['event' => $this->service->manualEntry($validator->validated(), $request->user())], 'Manual attendance entry recorded.', Response::HTTP_CREATED);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
@@ -63,7 +65,9 @@ class AttendanceManagementController extends BaseApiController
|
||||
'authorized' => ['nullable'],
|
||||
'reason' => ['nullable', 'string', 'max:255'],
|
||||
]);
|
||||
if ($validator->fails()) return $this->respondValidationError($validator->errors()->toArray());
|
||||
if ($validator->fails()) {
|
||||
return $this->respondValidationError($validator->errors()->toArray());
|
||||
}
|
||||
try {
|
||||
return $this->success(['event' => $this->service->badgeScan($validator->validated(), $request->user())], 'Badge scan classified.');
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
@@ -91,7 +95,9 @@ class AttendanceManagementController extends BaseApiController
|
||||
'reason' => ['nullable', 'string', 'max:255'],
|
||||
'notes' => ['nullable', 'string'],
|
||||
]);
|
||||
if ($validator->fails()) return $this->respondValidationError($validator->errors()->toArray());
|
||||
if ($validator->fails()) {
|
||||
return $this->respondValidationError($validator->errors()->toArray());
|
||||
}
|
||||
try {
|
||||
return $this->success(['event' => $this->service->exitEntry($validator->validated(), $request->user())], 'Exit attendance entry recorded.', Response::HTTP_CREATED);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
@@ -113,7 +119,9 @@ class AttendanceManagementController extends BaseApiController
|
||||
'report_status' => ['nullable', 'string', 'max:48'],
|
||||
'reason' => ['nullable', 'string', 'max:255'],
|
||||
]);
|
||||
if ($validator->fails()) return $this->respondValidationError($validator->errors()->toArray());
|
||||
if ($validator->fails()) {
|
||||
return $this->respondValidationError($validator->errors()->toArray());
|
||||
}
|
||||
try {
|
||||
return $this->success(['event' => $this->service->markAbsent($validator->validated(), $request->user())], 'Absence recorded.', Response::HTTP_CREATED);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
@@ -130,7 +138,9 @@ class AttendanceManagementController extends BaseApiController
|
||||
'final_decision' => ['nullable', 'string', 'max:255'],
|
||||
'notes' => ['nullable', 'string'],
|
||||
]);
|
||||
if ($validator->fails()) return $this->respondValidationError($validator->errors()->toArray());
|
||||
if ($validator->fails()) {
|
||||
return $this->respondValidationError($validator->errors()->toArray());
|
||||
}
|
||||
try {
|
||||
return $this->success(['event' => $this->service->completeFollowUp($id, $validator->validated(), $request->user())], 'Follow-up completed.');
|
||||
} catch (\RuntimeException $e) {
|
||||
@@ -147,7 +157,9 @@ class AttendanceManagementController extends BaseApiController
|
||||
'slip_number' => ['nullable', 'string', 'max:64'],
|
||||
'late_slip_log_id' => ['nullable', 'integer'],
|
||||
]);
|
||||
if ($validator->fails()) return $this->respondValidationError($validator->errors()->toArray());
|
||||
if ($validator->fails()) {
|
||||
return $this->respondValidationError($validator->errors()->toArray());
|
||||
}
|
||||
try {
|
||||
return $this->success(['reprint' => $this->service->reprintLateSlip($id, $validator->validated(), $request->user())], 'Late slip reprint logged.', Response::HTTP_CREATED);
|
||||
} catch (\RuntimeException $e) {
|
||||
|
||||
@@ -12,8 +12,7 @@ class AttendanceTrackingController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected AttendanceTrackingService $service
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function pendingViolations(Request $request): JsonResponse
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ class AuthController extends BaseApiController
|
||||
}
|
||||
|
||||
$user = User::query()->whereRaw('LOWER(email) = ?', [$email])->first();
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
$security->logIpAttempt((string) $ip);
|
||||
Log::notice('api_login: unknown email', [
|
||||
'ip' => (string) $ip,
|
||||
@@ -111,7 +111,7 @@ class AuthController extends BaseApiController
|
||||
$security->logSuccessfulLogin($user->fresh(), $request);
|
||||
|
||||
$fresh = $user->fresh();
|
||||
if (!$fresh) {
|
||||
if (! $fresh) {
|
||||
Log::warning('api_login: fresh user reload failed after successful verification', [
|
||||
'ip' => (string) $ip,
|
||||
'email' => $this->maskEmail($email),
|
||||
@@ -139,7 +139,7 @@ class AuthController extends BaseApiController
|
||||
[$local, $domain] = explode('@', $email, 2);
|
||||
$localPrefix = substr($local, 0, min(2, strlen($local)));
|
||||
|
||||
return $localPrefix . str_repeat('*', max(strlen($local) - strlen($localPrefix), 0)) . '@' . $domain;
|
||||
return $localPrefix.str_repeat('*', max(strlen($local) - strlen($localPrefix), 0)).'@'.$domain;
|
||||
}
|
||||
|
||||
public function refresh(Request $request): JsonResponse
|
||||
@@ -160,7 +160,7 @@ class AuthController extends BaseApiController
|
||||
public function me(): JsonResponse
|
||||
{
|
||||
$user = Auth::user();
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
return $this->respondError('Unauthorized.', 401);
|
||||
}
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ class AuthSessionController extends Controller
|
||||
[$local, $domain] = explode('@', $email, 2);
|
||||
$localPrefix = substr($local, 0, min(2, strlen($local)));
|
||||
|
||||
return $localPrefix . str_repeat('*', max(strlen($local) - strlen($localPrefix), 0)) . '@' . $domain;
|
||||
return $localPrefix.str_repeat('*', max(strlen($local) - strlen($localPrefix), 0)).'@'.$domain;
|
||||
}
|
||||
|
||||
/** Closes the current web session. */
|
||||
|
||||
@@ -44,7 +44,7 @@ class IpBanController extends BaseApiController
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$ban = $this->queryService->find($id);
|
||||
if (!$ban) {
|
||||
if (! $ban) {
|
||||
return $this->error('IP record not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -67,11 +67,12 @@ class IpBanController extends BaseApiController
|
||||
try {
|
||||
$ban = $this->commandService->banNow($id ? (int) $id : null, $ip ? (string) $ip : null, $hours);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('IP ban failed: ' . $e->getMessage());
|
||||
Log::error('IP ban failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Unable to ban IP.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!$ban) {
|
||||
if (! $ban) {
|
||||
return $this->error('IP record not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -90,9 +91,10 @@ class IpBanController extends BaseApiController
|
||||
try {
|
||||
if ($all) {
|
||||
$count = $this->commandService->unbanAll();
|
||||
|
||||
return $this->success([
|
||||
'count' => $count,
|
||||
], $count . ' IP(s) unbanned.');
|
||||
], $count.' IP(s) unbanned.');
|
||||
}
|
||||
|
||||
$ban = $this->commandService->unbanOne(
|
||||
@@ -100,11 +102,12 @@ class IpBanController extends BaseApiController
|
||||
$validated['ip'] ?? null
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('IP unban failed: ' . $e->getMessage());
|
||||
Log::error('IP unban failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Unable to unban IP.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!$ban) {
|
||||
if (! $ban) {
|
||||
return $this->error('IP record not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Api\Auth;
|
||||
|
||||
use App\Http\Controllers\Api\Core\BaseApiController;
|
||||
use App\Http\Requests\Auth\RegisterRequest;
|
||||
use App\Http\Resources\Auth\RegisterResource;
|
||||
use App\Services\Auth\ApiRegistrationService;
|
||||
use App\Services\Auth\RegistrationCaptchaService;
|
||||
@@ -50,7 +51,7 @@ class RegisterController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), \App\Http\Requests\Auth\RegisterRequest::ruleset());
|
||||
$validator = Validator::make($request->all(), RegisterRequest::ruleset());
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'message' => 'Validation failed.',
|
||||
|
||||
@@ -56,7 +56,7 @@ class RolePermissionController extends BaseApiController
|
||||
public function showRole(int $roleId): JsonResponse
|
||||
{
|
||||
$role = Role::query()->find($roleId);
|
||||
if (!$role) {
|
||||
if (! $role) {
|
||||
return $this->error('Role not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,8 @@ class RolePermissionController extends BaseApiController
|
||||
try {
|
||||
$role = $this->roleCrudService->create($request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Role store failed: ' . $e->getMessage());
|
||||
Log::error('Role store failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to create role.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -82,14 +83,15 @@ class RolePermissionController extends BaseApiController
|
||||
public function updateRole(RoleUpdateRequest $request, int $roleId): JsonResponse
|
||||
{
|
||||
$role = Role::query()->find($roleId);
|
||||
if (!$role) {
|
||||
if (! $role) {
|
||||
return $this->error('Role not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
$role = $this->roleCrudService->update($role, $request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Role update failed: ' . $e->getMessage());
|
||||
Log::error('Role update failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to update role.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -101,14 +103,15 @@ class RolePermissionController extends BaseApiController
|
||||
public function deleteRole(int $roleId): JsonResponse
|
||||
{
|
||||
$role = Role::query()->find($roleId);
|
||||
if (!$role) {
|
||||
if (! $role) {
|
||||
return $this->error('Role not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->roleCrudService->delete($role);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Role delete failed: ' . $e->getMessage());
|
||||
Log::error('Role delete failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to delete role.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -144,11 +147,12 @@ class RolePermissionController extends BaseApiController
|
||||
$actorId
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Assign roles failed: ' . $e->getMessage());
|
||||
Log::error('Assign roles failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to update roles.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to update roles.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -169,7 +173,7 @@ class RolePermissionController extends BaseApiController
|
||||
public function showPermission(int $permissionId): JsonResponse
|
||||
{
|
||||
$permission = Permission::query()->find($permissionId);
|
||||
if (!$permission) {
|
||||
if (! $permission) {
|
||||
return $this->error('Permission not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -183,7 +187,8 @@ class RolePermissionController extends BaseApiController
|
||||
try {
|
||||
$permission = $this->permissionCrudService->create($request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Permission store failed: ' . $e->getMessage());
|
||||
Log::error('Permission store failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to create permission.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -195,14 +200,15 @@ class RolePermissionController extends BaseApiController
|
||||
public function updatePermission(PermissionUpdateRequest $request, int $permissionId): JsonResponse
|
||||
{
|
||||
$permission = Permission::query()->find($permissionId);
|
||||
if (!$permission) {
|
||||
if (! $permission) {
|
||||
return $this->error('Permission not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
$permission = $this->permissionCrudService->update($permission, $request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Permission update failed: ' . $e->getMessage());
|
||||
Log::error('Permission update failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to update permission.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -214,14 +220,15 @@ class RolePermissionController extends BaseApiController
|
||||
public function deletePermission(int $permissionId): JsonResponse
|
||||
{
|
||||
$permission = Permission::query()->find($permissionId);
|
||||
if (!$permission) {
|
||||
if (! $permission) {
|
||||
return $this->error('Permission not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->permissionCrudService->delete($permission);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Permission delete failed: ' . $e->getMessage());
|
||||
Log::error('Permission delete failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to delete permission.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -242,16 +249,14 @@ class RolePermissionController extends BaseApiController
|
||||
try {
|
||||
$this->permissionService->saveRolePermissions($roleId, $request->validated()['permissions'] ?? []);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Role permissions update failed: ' . $e->getMessage());
|
||||
Log::error('Role permissions update failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to update role permissions.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
return $this->success(null, 'Permissions saved successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -6,9 +6,9 @@ use App\Http\Controllers\Api\Core\BaseApiController;
|
||||
use App\Http\Requests\Roles\RoleSwitchRequest;
|
||||
use App\Services\Roles\RoleSwitchService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RoleSwitcherController extends BaseApiController
|
||||
{
|
||||
@@ -56,9 +56,6 @@ class RoleSwitcherController extends BaseApiController
|
||||
], 'Role switched successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -19,8 +19,7 @@ class SessionTimeoutController extends Controller
|
||||
|
||||
public function __construct(
|
||||
private ApplicationUrlService $urls,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Returns timeout metadata for the web portal.
|
||||
|
||||
@@ -17,8 +17,7 @@ class BadgeController extends Controller
|
||||
protected BadgePdfService $badgePdfService,
|
||||
protected BadgePrintLogService $badgePrintLogService,
|
||||
protected BadgeFormDataService $badgeFormDataService
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function generatePdf(Request $request)
|
||||
{
|
||||
@@ -166,7 +165,7 @@ class BadgeController extends Controller
|
||||
|
||||
if (is_string($ids)) {
|
||||
$ids = array_filter(array_map('trim', explode(',', $ids)), 'strlen');
|
||||
} elseif (!is_array($ids)) {
|
||||
} elseif (! is_array($ids)) {
|
||||
$ids = $ids ? [$ids] : [];
|
||||
}
|
||||
|
||||
@@ -199,7 +198,7 @@ class BadgeController extends Controller
|
||||
|
||||
if (is_string($ids)) {
|
||||
$ids = array_filter(array_map('trim', explode(',', $ids)), 'strlen');
|
||||
} elseif (!is_array($ids)) {
|
||||
} elseif (! is_array($ids)) {
|
||||
$ids = $ids ? [$ids] : [];
|
||||
}
|
||||
|
||||
@@ -208,9 +207,6 @@ class BadgeController extends Controller
|
||||
return array_values(array_filter($ids, static fn ($v) => $v > 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -4,6 +4,4 @@ namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Api\Core\BaseApiController as CoreBaseApiController;
|
||||
|
||||
class BaseApiController extends CoreBaseApiController
|
||||
{
|
||||
}
|
||||
class BaseApiController extends CoreBaseApiController {}
|
||||
|
||||
@@ -20,15 +20,16 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
class ClassPreparationController extends BaseApiController
|
||||
{
|
||||
private ClassPreparationService $service;
|
||||
|
||||
private StickerCountService $stickerCounts;
|
||||
|
||||
private ClassRosterService $roster;
|
||||
|
||||
public function __construct(
|
||||
ClassPreparationService $service,
|
||||
StickerCountService $stickerCounts,
|
||||
ClassRosterService $roster
|
||||
)
|
||||
{
|
||||
) {
|
||||
parent::__construct();
|
||||
$this->service = $service;
|
||||
$this->stickerCounts = $stickerCounts;
|
||||
@@ -77,7 +78,8 @@ class ClassPreparationController extends BaseApiController
|
||||
try {
|
||||
$count = $this->service->saveAdjustments($classSectionId, $schoolYear, $validated['adjustments']);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Class prep adjustment save failed: ' . $e->getMessage());
|
||||
Log::error('Class prep adjustment save failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Unable to save adjustments.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -94,8 +94,9 @@ class ClassProgressController extends BaseApiController
|
||||
$filters['semester'] = $filters['semester'] ?? ($meta['semester'] ?? null);
|
||||
$paginator = $this->queryService->listReports($auth, $filters);
|
||||
|
||||
if (!empty($filters['group_by_week'])) {
|
||||
if (! empty($filters['group_by_week'])) {
|
||||
$grouped = ClassProgressGroupCollection::fromPaginator($paginator);
|
||||
|
||||
return $this->respondSuccess($grouped, 'Progress reports retrieved.');
|
||||
}
|
||||
|
||||
@@ -135,6 +136,7 @@ class ClassProgressController extends BaseApiController
|
||||
Log::error('Failed to create class progress reports.', [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return $this->respondError('Unable to save progress reports.', 500);
|
||||
}
|
||||
|
||||
@@ -170,6 +172,7 @@ class ClassProgressController extends BaseApiController
|
||||
Log::error('Failed to update class progress report.', [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return $this->respondError('Unable to update progress report.', 500);
|
||||
}
|
||||
|
||||
@@ -184,6 +187,7 @@ class ClassProgressController extends BaseApiController
|
||||
Log::error('Failed to delete class progress report.', [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return $this->respondError('Unable to delete progress report.', 500);
|
||||
}
|
||||
|
||||
@@ -193,7 +197,7 @@ class ClassProgressController extends BaseApiController
|
||||
public function downloadAttachment(int $attachment): BinaryFileResponse|JsonResponse
|
||||
{
|
||||
$record = ClassProgressAttachment::query()->find($attachment);
|
||||
if (!$record || !$record->file_path) {
|
||||
if (! $record || ! $record->file_path) {
|
||||
return $this->respondError('Attachment not found.', 404);
|
||||
}
|
||||
|
||||
@@ -202,11 +206,12 @@ class ClassProgressController extends BaseApiController
|
||||
}
|
||||
|
||||
$path = $this->attachmentService->resolvePath($record->file_path);
|
||||
if (!$path) {
|
||||
if (! $path) {
|
||||
return $this->respondError('Attachment missing.', 404);
|
||||
}
|
||||
|
||||
$downloadName = $record->original_name ?: basename($path);
|
||||
|
||||
return response()->download($path, $downloadName);
|
||||
}
|
||||
|
||||
@@ -214,12 +219,12 @@ class ClassProgressController extends BaseApiController
|
||||
{
|
||||
$this->authorize('view', $class_progress);
|
||||
|
||||
if (!$class_progress->attachment_path) {
|
||||
if (! $class_progress->attachment_path) {
|
||||
return $this->respondError('Attachment not found.', 404);
|
||||
}
|
||||
|
||||
$path = $this->attachmentService->resolvePath($class_progress->attachment_path);
|
||||
if (!$path) {
|
||||
if (! $path) {
|
||||
return $this->respondError('Attachment missing.', 404);
|
||||
}
|
||||
|
||||
@@ -228,19 +233,18 @@ class ClassProgressController extends BaseApiController
|
||||
|
||||
/**
|
||||
* @param mixed $user
|
||||
* @return User|JsonResponse
|
||||
*/
|
||||
private function requireAuthenticatedUser($user): User|JsonResponse
|
||||
{
|
||||
if (!$user instanceof User) {
|
||||
if (! $user instanceof User) {
|
||||
$user = auth()->user();
|
||||
}
|
||||
|
||||
if (!$user instanceof User) {
|
||||
if (! $user instanceof User) {
|
||||
$user = $this->laravelRequest->user();
|
||||
}
|
||||
|
||||
if (!$user instanceof User) {
|
||||
if (! $user instanceof User) {
|
||||
return $this->respondError('Unauthorized.', Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class ClassController extends BaseApiController
|
||||
|
||||
$section = $this->queryService->find((int) $classSection->id);
|
||||
|
||||
if (!$section) {
|
||||
if (! $section) {
|
||||
return $this->error('Class section not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ class ClassController extends BaseApiController
|
||||
{
|
||||
$this->authorize('delete', $classSection);
|
||||
|
||||
if (!$this->commandService->delete($classSection)) {
|
||||
if (! $this->commandService->delete($classSection)) {
|
||||
return $this->error('Class section not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,8 @@ class ClassController extends BaseApiController
|
||||
try {
|
||||
$created = $this->seedService->seedDefaults();
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Seeding default classes failed: ' . $e->getMessage());
|
||||
Log::error('Seeding default classes failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Unable to seed default classes.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,13 @@ use Illuminate\Http\Request;
|
||||
class CommunicationController extends BaseApiController
|
||||
{
|
||||
private CommunicationStudentService $students;
|
||||
|
||||
private CommunicationTemplateService $templates;
|
||||
|
||||
private CommunicationFamilyService $families;
|
||||
|
||||
private CommunicationPreviewService $previewService;
|
||||
|
||||
private CommunicationSendService $sendService;
|
||||
|
||||
public function __construct(
|
||||
@@ -76,7 +80,7 @@ class CommunicationController extends BaseApiController
|
||||
$teacherName = $this->resolveTeacherName();
|
||||
$result = $this->previewService->buildPreview($templateKey, $studentId, $familyId, $vars, $teacherName);
|
||||
|
||||
if (!$result['ok']) {
|
||||
if (! $result['ok']) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => $result['message'] ?? 'Preview failed.',
|
||||
@@ -116,7 +120,7 @@ class CommunicationController extends BaseApiController
|
||||
}
|
||||
|
||||
$student = $this->students->getStudentBasic($studentId);
|
||||
if (!$student) {
|
||||
if (! $student) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'Student not found.',
|
||||
@@ -137,11 +141,11 @@ class CommunicationController extends BaseApiController
|
||||
'recipients' => $recipients,
|
||||
'cc' => $cc,
|
||||
'bcc' => $bcc,
|
||||
'student_name' => trim(($student['firstname'] ?? '') . ' ' . ($student['lastname'] ?? '')),
|
||||
'student_name' => trim(($student['firstname'] ?? '').' '.($student['lastname'] ?? '')),
|
||||
'sent_by' => $senderId,
|
||||
]);
|
||||
|
||||
if (!$result['ok']) {
|
||||
if (! $result['ok']) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'Failed to send email.',
|
||||
@@ -175,15 +179,14 @@ class CommunicationController extends BaseApiController
|
||||
{
|
||||
$user = auth()->user();
|
||||
if ($user) {
|
||||
$name = trim(($user->firstname ?? '') . ' ' . ($user->lastname ?? ''));
|
||||
$name = trim(($user->firstname ?? '').' '.($user->lastname ?? ''));
|
||||
|
||||
return $name !== '' ? $name : 'Teacher';
|
||||
}
|
||||
|
||||
return 'Teacher';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -14,8 +14,11 @@ use Illuminate\Http\Request;
|
||||
class CompetitionScoresController extends BaseApiController
|
||||
{
|
||||
private CompetitionScoresContextService $contextService;
|
||||
|
||||
private CompetitionScoresQueryService $queryService;
|
||||
|
||||
private CompetitionScoresRosterService $rosterService;
|
||||
|
||||
private CompetitionScoresSaveService $saveService;
|
||||
|
||||
public function __construct(
|
||||
@@ -100,7 +103,7 @@ class CompetitionScoresController extends BaseApiController
|
||||
}
|
||||
|
||||
$competition = Competition::query()->find($id);
|
||||
if (!$competition) {
|
||||
if (! $competition) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'Competition not found.',
|
||||
@@ -120,7 +123,7 @@ class CompetitionScoresController extends BaseApiController
|
||||
], 422);
|
||||
}
|
||||
|
||||
if (!in_array($classSectionId, $allowedClassIds, true)) {
|
||||
if (! in_array($classSectionId, $allowedClassIds, true)) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'You are not assigned to that class.',
|
||||
@@ -170,7 +173,7 @@ class CompetitionScoresController extends BaseApiController
|
||||
}
|
||||
|
||||
$competition = Competition::query()->find($id);
|
||||
if (!$competition) {
|
||||
if (! $competition) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'Competition not found.',
|
||||
@@ -194,7 +197,7 @@ class CompetitionScoresController extends BaseApiController
|
||||
], 422);
|
||||
}
|
||||
|
||||
if (!in_array($classSectionId, $allowedClassIds, true)) {
|
||||
if (! in_array($classSectionId, $allowedClassIds, true)) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'You are not assigned to that class.',
|
||||
@@ -205,7 +208,7 @@ class CompetitionScoresController extends BaseApiController
|
||||
$scores = is_array($scores) ? $scores : [];
|
||||
[$cleanScores, $invalidScores] = $this->saveService->filterScores($scores);
|
||||
|
||||
if (!empty($invalidScores)) {
|
||||
if (! empty($invalidScores)) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'Scores must be whole numbers (no decimals).',
|
||||
@@ -222,9 +225,6 @@ class CompetitionScoresController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -313,9 +313,6 @@ class CompetitionWinnersController extends BaseApiController
|
||||
return response()->json($result, $result['ok'] ? Response::HTTP_OK : Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedAdminOrForbidden(): int|JsonResponse
|
||||
{
|
||||
$user = $this->getCurrentUser();
|
||||
@@ -361,7 +358,6 @@ class CompetitionWinnersController extends BaseApiController
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $row
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function rowToArray(mixed $row): array
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Validation\Validator as ValidatorContract;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -16,7 +17,8 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
class BaseApiController extends Controller
|
||||
{
|
||||
protected Request $laravelRequest;
|
||||
protected ValidatorContract|null $validator = null;
|
||||
|
||||
protected ?ValidatorContract $validator = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -26,19 +28,19 @@ class BaseApiController extends Controller
|
||||
protected function success($data = null, string $message = 'Success', int $code = Response::HTTP_OK): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'status' => true,
|
||||
'message' => $message,
|
||||
'data' => $data,
|
||||
'data' => $data,
|
||||
], $code);
|
||||
}
|
||||
|
||||
protected function error(string $message = 'An error occurred', int $code = Response::HTTP_BAD_REQUEST, ?array $errors = null): JsonResponse
|
||||
{
|
||||
$payload = [
|
||||
'status' => false,
|
||||
'status' => false,
|
||||
'message' => $message,
|
||||
];
|
||||
if (!empty($errors)) {
|
||||
if (! empty($errors)) {
|
||||
$payload['errors'] = $errors;
|
||||
}
|
||||
|
||||
@@ -91,6 +93,7 @@ class BaseApiController extends Controller
|
||||
{
|
||||
$payload = $this->payloadData();
|
||||
$errors = $this->validateRequest($payload, $rules);
|
||||
|
||||
return empty($errors);
|
||||
}
|
||||
|
||||
@@ -100,6 +103,7 @@ class BaseApiController extends Controller
|
||||
if (is_array($json)) {
|
||||
return $json;
|
||||
}
|
||||
|
||||
return array_merge($this->laravelRequest->query->all(), $this->laravelRequest->request->all());
|
||||
}
|
||||
|
||||
@@ -116,71 +120,88 @@ class BaseApiController extends Controller
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/^max_length\\[(\\d+)\\]$/', $part, $m)) {
|
||||
$result[] = 'max:' . $m[1];
|
||||
$result[] = 'max:'.$m[1];
|
||||
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/^min_length\\[(\\d+)\\]$/', $part, $m)) {
|
||||
$result[] = 'min:' . $m[1];
|
||||
$result[] = 'min:'.$m[1];
|
||||
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/^in_list\\[(.+)\\]$/', $part, $m)) {
|
||||
$result[] = 'in:' . $m[1];
|
||||
$result[] = 'in:'.$m[1];
|
||||
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/^greater_than_equal_to\\[(.+)\\]$/', $part, $m)) {
|
||||
$result[] = 'gte:' . $m[1];
|
||||
$result[] = 'gte:'.$m[1];
|
||||
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/^less_than_equal_to\\[(.+)\\]$/', $part, $m)) {
|
||||
$result[] = 'lte:' . $m[1];
|
||||
$result[] = 'lte:'.$m[1];
|
||||
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/^valid_date\\[(.+)\\]$/', $part, $m)) {
|
||||
$result[] = 'date_format:' . $m[1];
|
||||
$result[] = 'date_format:'.$m[1];
|
||||
|
||||
continue;
|
||||
}
|
||||
if ($part === 'valid_email') {
|
||||
$result[] = 'email';
|
||||
|
||||
continue;
|
||||
}
|
||||
if ($part === 'permit_empty') {
|
||||
$result[] = 'nullable';
|
||||
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/^is_unique\\[([^\\.]+)\\.([^\\]]+)\\]$/', $part, $m)) {
|
||||
$result[] = 'unique:' . $m[1] . ',' . $m[2];
|
||||
$result[] = 'unique:'.$m[1].','.$m[2];
|
||||
|
||||
continue;
|
||||
}
|
||||
if ($part === 'string') {
|
||||
$result[] = 'string';
|
||||
|
||||
continue;
|
||||
}
|
||||
if ($part === 'integer') {
|
||||
$result[] = 'integer';
|
||||
|
||||
continue;
|
||||
}
|
||||
if ($part === 'numeric') {
|
||||
$result[] = 'numeric';
|
||||
|
||||
continue;
|
||||
}
|
||||
if ($part === 'required') {
|
||||
$result[] = 'required';
|
||||
|
||||
continue;
|
||||
}
|
||||
if ($part === 'alpha_numeric') {
|
||||
$result[] = 'alpha_num';
|
||||
|
||||
continue;
|
||||
}
|
||||
if ($part === 'in_array') {
|
||||
$result[] = 'in_array';
|
||||
|
||||
continue;
|
||||
}
|
||||
if ($part === 'valid_url') {
|
||||
$result[] = 'url';
|
||||
|
||||
continue;
|
||||
}
|
||||
if (strpos($part, 'max_size') === 0) {
|
||||
$result[] = str_replace('max_size', 'max', $part);
|
||||
|
||||
continue;
|
||||
}
|
||||
$result[] = $part;
|
||||
@@ -191,11 +212,11 @@ class BaseApiController extends Controller
|
||||
|
||||
protected function paginate($source, int $page = 1, int $perPage = 20): array
|
||||
{
|
||||
$page = max(1, $page);
|
||||
$page = max(1, $page);
|
||||
$perPage = max(1, $perPage);
|
||||
$offset = ($page - 1) * $perPage;
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
if ($source instanceof EloquentBuilder || $source instanceof \Illuminate\Database\Query\Builder) {
|
||||
if ($source instanceof EloquentBuilder || $source instanceof Builder) {
|
||||
$total = $source->toBase()->getCountForPagination();
|
||||
$items = $source->offset($offset)->limit($perPage)->get()->toArray();
|
||||
} elseif (is_array($source)) {
|
||||
@@ -206,9 +227,9 @@ class BaseApiController extends Controller
|
||||
'data' => [],
|
||||
'pagination' => [
|
||||
'current_page' => $page,
|
||||
'per_page' => $perPage,
|
||||
'total' => 0,
|
||||
'total_pages' => 0,
|
||||
'per_page' => $perPage,
|
||||
'total' => 0,
|
||||
'total_pages' => 0,
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -217,9 +238,9 @@ class BaseApiController extends Controller
|
||||
'data' => array_values($items),
|
||||
'pagination' => [
|
||||
'current_page' => $page,
|
||||
'per_page' => $perPage,
|
||||
'total' => $total,
|
||||
'total_pages' => (int) ceil($total / $perPage),
|
||||
'per_page' => $perPage,
|
||||
'total' => $total,
|
||||
'total_pages' => (int) ceil($total / $perPage),
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -233,29 +254,30 @@ class BaseApiController extends Controller
|
||||
if ($userId <= 0) {
|
||||
$userId = (int) (optional($this->laravelRequest->user())->id ?? 0);
|
||||
}
|
||||
|
||||
return $userId > 0 ? $userId : null;
|
||||
}
|
||||
|
||||
protected function getCurrentUser(): ?object
|
||||
{
|
||||
$userId = $this->getCurrentUserId();
|
||||
if (!$userId) {
|
||||
if (! $userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var User|null $row */
|
||||
$row = User::query()->find($userId);
|
||||
if (!$row) {
|
||||
if (! $row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$firstname = (string) ($row->firstname ?? '');
|
||||
$lastname = (string) ($row->lastname ?? '');
|
||||
$email = $row->email;
|
||||
$lastname = (string) ($row->lastname ?? '');
|
||||
$email = $row->email;
|
||||
|
||||
$name = trim($firstname . ' ' . $lastname);
|
||||
$name = trim($firstname.' '.$lastname);
|
||||
if ($name === '') {
|
||||
$name = $email ?? 'User #' . $userId;
|
||||
$name = $email ?? 'User #'.$userId;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -269,13 +291,13 @@ class BaseApiController extends Controller
|
||||
->values()
|
||||
->all();
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Unable to load user roles: ' . $e->getMessage());
|
||||
Log::error('Unable to load user roles: '.$e->getMessage());
|
||||
$roles = [];
|
||||
}
|
||||
|
||||
return (object) [
|
||||
'id' => (int) $userId,
|
||||
'name' => $name,
|
||||
'id' => (int) $userId,
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'roles' => $roles,
|
||||
];
|
||||
|
||||
@@ -17,8 +17,11 @@ use Illuminate\Http\JsonResponse;
|
||||
class DiscountController extends BaseApiController
|
||||
{
|
||||
private DiscountContextService $context;
|
||||
|
||||
private DiscountVoucherService $voucherService;
|
||||
|
||||
private DiscountParentService $parentService;
|
||||
|
||||
private DiscountApplyService $applyService;
|
||||
|
||||
public function __construct(
|
||||
@@ -69,6 +72,7 @@ class DiscountController extends BaseApiController
|
||||
public function listVouchers(): JsonResponse
|
||||
{
|
||||
$vouchers = $this->voucherService->listAll();
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'vouchers' => DiscountVoucherResource::collection($vouchers),
|
||||
@@ -78,6 +82,7 @@ class DiscountController extends BaseApiController
|
||||
public function storeVoucher(StoreDiscountVoucherRequest $request): JsonResponse
|
||||
{
|
||||
$voucher = $this->voucherService->create($request->validated());
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'voucher' => new DiscountVoucherResource($voucher),
|
||||
@@ -87,6 +92,7 @@ class DiscountController extends BaseApiController
|
||||
public function updateVoucher(UpdateDiscountVoucherRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$voucher = $this->voucherService->update($id, $request->validated());
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'voucher' => new DiscountVoucherResource($voucher),
|
||||
@@ -96,6 +102,7 @@ class DiscountController extends BaseApiController
|
||||
public function showVoucher(int $id): JsonResponse
|
||||
{
|
||||
$voucher = $this->voucherService->find($id);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'voucher' => new DiscountVoucherResource($voucher),
|
||||
@@ -105,14 +112,12 @@ class DiscountController extends BaseApiController
|
||||
public function deleteVoucher(int $id): JsonResponse
|
||||
{
|
||||
$this->voucherService->delete($id);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -14,9 +14,13 @@ use Illuminate\Http\Request;
|
||||
class BroadcastEmailController extends BaseApiController
|
||||
{
|
||||
private BroadcastEmailSenderOptionsService $senderOptions;
|
||||
|
||||
private BroadcastEmailRecipientService $recipients;
|
||||
|
||||
private BroadcastEmailComposerService $composer;
|
||||
|
||||
private BroadcastEmailDispatchService $dispatch;
|
||||
|
||||
private BroadcastEmailImageService $imageService;
|
||||
|
||||
public function __construct(
|
||||
@@ -140,7 +144,7 @@ class BroadcastEmailController extends BaseApiController
|
||||
public function uploadImage(Request $request): JsonResponse
|
||||
{
|
||||
$file = $request->file('image');
|
||||
if (!$file || !$file->isValid()) {
|
||||
if (! $file || ! $file->isValid()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => 'No image uploaded',
|
||||
@@ -148,7 +152,7 @@ class BroadcastEmailController extends BaseApiController
|
||||
}
|
||||
|
||||
$result = $this->imageService->store($file);
|
||||
if (!$result['ok']) {
|
||||
if (! $result['ok']) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => $result['error'] ?? 'Upload failed',
|
||||
@@ -174,6 +178,7 @@ class BroadcastEmailController extends BaseApiController
|
||||
foreach (explode(',', $value) as $piece) {
|
||||
$ids[] = (int) $piece;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
$ids[] = (int) $value;
|
||||
|
||||
@@ -46,7 +46,7 @@ class EmailController extends BaseApiController
|
||||
$attachments
|
||||
);
|
||||
|
||||
if (!$ok) {
|
||||
if (! $ok) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'Email failed to send.',
|
||||
|
||||
@@ -8,7 +8,6 @@ use App\Http\Resources\Email\EmailExtractorCompareResource;
|
||||
use App\Http\Resources\Email\EmailExtractorEmailsResource;
|
||||
use App\Services\Email\EmailExtractorService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EmailExtractorController extends BaseApiController
|
||||
{
|
||||
|
||||
@@ -49,7 +49,7 @@ class ExamDraftController extends BaseApiController
|
||||
}
|
||||
|
||||
$result = $this->teacherService->store($guard, $request->validated(), $request->file('draft_file'));
|
||||
if (!$result['ok']) {
|
||||
if (! $result['ok']) {
|
||||
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Unable to save.'], 422);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class ExamDraftController extends BaseApiController
|
||||
}
|
||||
|
||||
$result = $this->adminService->uploadLegacy($guard, $request->validated(), $request->file('old_exam_file'));
|
||||
if (!$result['ok']) {
|
||||
if (! $result['ok']) {
|
||||
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Unable to save.'], 422);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ class ExamDraftController extends BaseApiController
|
||||
}
|
||||
|
||||
$result = $this->adminService->review($guard, $request->validated(), $request->file('final_file'));
|
||||
if (!$result['ok']) {
|
||||
if (! $result['ok']) {
|
||||
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Unable to save.'], 422);
|
||||
}
|
||||
|
||||
@@ -113,9 +113,6 @@ class ExamDraftController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -51,6 +51,7 @@ class ExpenseController extends BaseApiController
|
||||
$rows = $this->queryService->listAll();
|
||||
$rows = array_map(function ($row) {
|
||||
$row['receipt_url'] = $this->receiptService->receiptUrl($row['receipt_path'] ?? null);
|
||||
|
||||
return $row;
|
||||
}, $rows);
|
||||
|
||||
@@ -63,7 +64,7 @@ class ExpenseController extends BaseApiController
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$row = $this->queryService->findById($id);
|
||||
if (!$row) {
|
||||
if (! $row) {
|
||||
return response()->json(['ok' => false, 'message' => 'Expense not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -121,7 +122,7 @@ class ExpenseController extends BaseApiController
|
||||
}
|
||||
|
||||
$expense = Expense::query()->find($id);
|
||||
if (!$expense) {
|
||||
if (! $expense) {
|
||||
return response()->json(['ok' => false, 'message' => 'Expense not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -131,7 +132,7 @@ class ExpenseController extends BaseApiController
|
||||
if ($request->hasFile('receipt')) {
|
||||
$receiptName = $this->receiptService->storeReceipt($request->file('receipt'));
|
||||
}
|
||||
if (!empty($payload['remove_receipt'])) {
|
||||
if (! empty($payload['remove_receipt'])) {
|
||||
$receiptName = null;
|
||||
}
|
||||
|
||||
@@ -176,7 +177,7 @@ class ExpenseController extends BaseApiController
|
||||
}
|
||||
|
||||
$expense = Expense::query()->find($id);
|
||||
if (!$expense) {
|
||||
if (! $expense) {
|
||||
return response()->json(['ok' => false, 'message' => 'Expense not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -190,9 +191,6 @@ class ExpenseController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -103,7 +103,7 @@ class ExtraChargesController extends BaseApiController
|
||||
public function update(UpdateExtraChargeRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$charge = AdditionalCharge::query()->find($id);
|
||||
if (!$charge) {
|
||||
if (! $charge) {
|
||||
return response()->json(['ok' => false, 'error' => 'Charge not found'], 404);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ class ExtraChargesController extends BaseApiController
|
||||
public function void(int $id): JsonResponse
|
||||
{
|
||||
$charge = AdditionalCharge::query()->find($id);
|
||||
if (!$charge) {
|
||||
if (! $charge) {
|
||||
return response()->json(['ok' => false, 'error' => 'Charge not found'], 404);
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ class ExtraChargesController extends BaseApiController
|
||||
public function reverse(int $id): JsonResponse
|
||||
{
|
||||
$charge = AdditionalCharge::query()->find($id);
|
||||
if (!$charge) {
|
||||
if (! $charge) {
|
||||
return response()->json(['ok' => false, 'error' => 'Charge not found'], 404);
|
||||
}
|
||||
|
||||
@@ -151,9 +151,6 @@ class ExtraChargesController extends BaseApiController
|
||||
], $ok ? 200 : 422);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -72,7 +72,7 @@ class FamilyAdminController extends BaseApiController
|
||||
$schoolYear
|
||||
);
|
||||
|
||||
if (!$family) {
|
||||
if (! $family) {
|
||||
return $this->error('Family not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -92,8 +92,9 @@ class FamilyAdminController extends BaseApiController
|
||||
$payload['reply_to_name'] ?? null
|
||||
);
|
||||
|
||||
if (!$ok) {
|
||||
if (! $ok) {
|
||||
Log::warning('Compose email failed for family admin', ['recipient' => $payload['recipient']]);
|
||||
|
||||
return $this->error('Unable to send email.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,8 @@ class FamilyController extends BaseApiController
|
||||
try {
|
||||
$result = $this->mutationService->bootstrapFamilies();
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Family bootstrap failed: ' . $e->getMessage());
|
||||
Log::error('Family bootstrap failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Family bootstrap failed.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -69,7 +70,7 @@ class FamilyController extends BaseApiController
|
||||
(string) ($payload['relation'] ?? 'secondary')
|
||||
);
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Unable to attach guardian.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -88,11 +89,12 @@ class FamilyController extends BaseApiController
|
||||
(string) ($payload['relation'] ?? 'secondary')
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Attach guardian by email failed: ' . $e->getMessage());
|
||||
Log::error('Attach guardian by email failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Unable to attach guardian.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Unable to attach guardian.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -156,11 +158,12 @@ class FamilyController extends BaseApiController
|
||||
try {
|
||||
$result = $this->mutationService->importSecondParentsFromLegacy();
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Legacy second parent import failed: ' . $e->getMessage());
|
||||
Log::error('Legacy second parent import failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Legacy import failed.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!($result['ok'] ?? true)) {
|
||||
if (! ($result['ok'] ?? true)) {
|
||||
return $this->error($result['message'] ?? 'Legacy import failed.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,12 +38,14 @@ class BalanceCarryforwardController extends Controller
|
||||
public function waive(CarryforwardAdjustmentRequest $request, int $carryforward): JsonResponse
|
||||
{
|
||||
$data = $request->validated();
|
||||
|
||||
return response()->json(['ok' => true, 'carryforward' => $this->service->waive($carryforward, (float) $data['amount'], $data['reason'] ?? null, optional($request->user())->id)]);
|
||||
}
|
||||
|
||||
public function adjust(CarryforwardAdjustmentRequest $request, int $carryforward): JsonResponse
|
||||
{
|
||||
$data = $request->validated();
|
||||
|
||||
return response()->json(['ok' => true, 'carryforward' => $this->service->adjust($carryforward, (float) $data['amount'], $data['reason'] ?? null)]);
|
||||
}
|
||||
|
||||
@@ -55,10 +57,13 @@ class BalanceCarryforwardController extends Controller
|
||||
public function reportCsv(Request $request): StreamedResponse
|
||||
{
|
||||
$rows = $this->service->csvRows($this->service->report($request->query()));
|
||||
|
||||
return response()->streamDownload(function () use ($rows) {
|
||||
$out = fopen('php://output', 'w');
|
||||
foreach ($rows as $row) fputcsv($out, $row);
|
||||
foreach ($rows as $row) {
|
||||
fputcsv($out, $row);
|
||||
}
|
||||
fclose($out);
|
||||
}, 'carryforward_report_' . date('Ymd_His') . '.csv', ['Content-Type' => 'text/csv']);
|
||||
}, 'carryforward_report_'.date('Ymd_His').'.csv', ['Content-Type' => 'text/csv']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,9 +143,6 @@ class ChargeController extends BaseApiController
|
||||
], $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -15,15 +15,24 @@ class EventChargeController extends Controller
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$q = EventCharge::query();
|
||||
foreach (['parent_id','student_id','event_id','school_year','semester'] as $field) {
|
||||
if ($request->filled($field)) $q->where($field, $request->query($field));
|
||||
foreach (['parent_id', 'student_id', 'event_id', 'school_year', 'semester'] as $field) {
|
||||
if ($request->filled($field)) {
|
||||
$q->where($field, $request->query($field));
|
||||
}
|
||||
}
|
||||
if ($request->filled('status')) {
|
||||
$status = $request->query('status');
|
||||
if (Schema::hasColumn('event_charges', 'status')) $q->where('status', $status);
|
||||
elseif ($status === 'paid') $q->where('event_paid', 1);
|
||||
elseif ($status === 'pending') $q->where(function ($qq) { $qq->whereNull('event_paid')->orWhere('event_paid', 0); });
|
||||
if (Schema::hasColumn('event_charges', 'status')) {
|
||||
$q->where('status', $status);
|
||||
} elseif ($status === 'paid') {
|
||||
$q->where('event_paid', 1);
|
||||
} elseif ($status === 'pending') {
|
||||
$q->where(function ($qq) {
|
||||
$qq->whereNull('event_paid')->orWhere('event_paid', 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json(['ok' => true, 'event_charges' => $q->orderByDesc('id')->paginate((int) $request->query('per_page', 25))]);
|
||||
}
|
||||
|
||||
@@ -31,8 +40,11 @@ class EventChargeController extends Controller
|
||||
{
|
||||
$data = $this->normalizePayload($request->validated());
|
||||
$data['created_by'] = optional($request->user())->id;
|
||||
if (Schema::hasColumn('event_charges', 'status')) $data['status'] = $data['status'] ?? 'draft';
|
||||
if (Schema::hasColumn('event_charges', 'status')) {
|
||||
$data['status'] = $data['status'] ?? 'draft';
|
||||
}
|
||||
$charge = EventCharge::query()->create($data);
|
||||
|
||||
return response()->json(['ok' => true, 'event_charge' => $charge], 201);
|
||||
}
|
||||
|
||||
@@ -45,6 +57,7 @@ class EventChargeController extends Controller
|
||||
{
|
||||
$charge = EventCharge::query()->findOrFail($eventCharge);
|
||||
$charge->fill($this->normalizePayload($request->validated()))->save();
|
||||
|
||||
return response()->json(['ok' => true, 'event_charge' => $charge->fresh()]);
|
||||
}
|
||||
|
||||
@@ -56,38 +69,58 @@ class EventChargeController extends Controller
|
||||
public function approve(int $eventCharge): JsonResponse
|
||||
{
|
||||
$charge = EventCharge::query()->findOrFail($eventCharge);
|
||||
if (Schema::hasColumn('event_charges', 'status')) $charge->status = 'approved';
|
||||
if (Schema::hasColumn('event_charges', 'charged')) $charge->charged = 1;
|
||||
if (Schema::hasColumn('event_charges', 'status')) {
|
||||
$charge->status = 'approved';
|
||||
}
|
||||
if (Schema::hasColumn('event_charges', 'charged')) {
|
||||
$charge->charged = 1;
|
||||
}
|
||||
$charge->save();
|
||||
|
||||
return response()->json(['ok' => true, 'event_charge' => $charge->fresh()]);
|
||||
}
|
||||
|
||||
public function void(int $eventCharge): JsonResponse
|
||||
{
|
||||
$charge = EventCharge::query()->findOrFail($eventCharge);
|
||||
if (Schema::hasColumn('event_charges', 'status')) $charge->status = 'voided';
|
||||
if (Schema::hasColumn('event_charges', 'charged')) $charge->charged = 0;
|
||||
if (Schema::hasColumn('event_charges', 'status')) {
|
||||
$charge->status = 'voided';
|
||||
}
|
||||
if (Schema::hasColumn('event_charges', 'charged')) {
|
||||
$charge->charged = 0;
|
||||
}
|
||||
$charge->save();
|
||||
|
||||
return response()->json(['ok' => true, 'event_charge' => $charge->fresh()]);
|
||||
}
|
||||
|
||||
public function attachToInvoice(Request $request, int $eventCharge): JsonResponse
|
||||
{
|
||||
$request->validate(['invoice_id' => ['required','integer']]);
|
||||
$request->validate(['invoice_id' => ['required', 'integer']]);
|
||||
$charge = EventCharge::query()->findOrFail($eventCharge);
|
||||
$invoiceId = (int) $request->input('invoice_id');
|
||||
abort_if(!DB::table('invoices')->where('id', $invoiceId)->exists(), 404, 'Invoice not found.');
|
||||
if (Schema::hasColumn('event_charges', 'invoice_id')) $charge->invoice_id = $invoiceId;
|
||||
if (Schema::hasColumn('event_charges', 'status')) $charge->status = 'invoiced';
|
||||
if (Schema::hasColumn('event_charges', 'charged')) $charge->charged = 1;
|
||||
abort_if(! DB::table('invoices')->where('id', $invoiceId)->exists(), 404, 'Invoice not found.');
|
||||
if (Schema::hasColumn('event_charges', 'invoice_id')) {
|
||||
$charge->invoice_id = $invoiceId;
|
||||
}
|
||||
if (Schema::hasColumn('event_charges', 'status')) {
|
||||
$charge->status = 'invoiced';
|
||||
}
|
||||
if (Schema::hasColumn('event_charges', 'charged')) {
|
||||
$charge->charged = 1;
|
||||
}
|
||||
$charge->save();
|
||||
return response()->json(['ok' => true, 'event_charge' => $charge->fresh(), 'warning' => Schema::hasColumn('event_charges','invoice_id') ? null : 'invoice_id column does not exist; charge marked as charged only.']);
|
||||
|
||||
return response()->json(['ok' => true, 'event_charge' => $charge->fresh(), 'warning' => Schema::hasColumn('event_charges', 'invoice_id') ? null : 'invoice_id column does not exist; charge marked as charged only.']);
|
||||
}
|
||||
|
||||
private function normalizePayload(array $data): array
|
||||
{
|
||||
if (isset($data['title']) && !isset($data['event_name'])) $data['event_name'] = $data['title'];
|
||||
if (isset($data['title']) && ! isset($data['event_name'])) {
|
||||
$data['event_name'] = $data['title'];
|
||||
}
|
||||
unset($data['title'], $data['invoice_id']);
|
||||
return array_filter($data, fn($v) => $v !== null);
|
||||
|
||||
return array_filter($data, fn ($v) => $v !== null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class FinanceNotificationController extends Controller
|
||||
public function sendPaymentReceipt(Request $request, int $payment): JsonResponse
|
||||
{
|
||||
$p = DB::table('payments')->where('id', $payment)->first();
|
||||
abort_if(!$p, 404, 'Payment not found.');
|
||||
abort_if(! $p, 404, 'Payment not found.');
|
||||
$receipt = $this->service->nextReceiptNumber($p->school_year ?? date('Y'));
|
||||
$log = $this->service->log([
|
||||
'parent_id' => $p->parent_id ?? null,
|
||||
@@ -25,34 +25,39 @@ class FinanceNotificationController extends Controller
|
||||
'notification_type' => 'payment_receipt',
|
||||
'channel' => 'database',
|
||||
'recipient' => (string) ($p->parent_id ?? ''),
|
||||
'subject' => 'Payment receipt ' . $receipt,
|
||||
'subject' => 'Payment receipt '.$receipt,
|
||||
], optional($request->user())->id);
|
||||
|
||||
return response()->json(['ok' => true, 'receipt_number' => $receipt, 'notification_log' => $log]);
|
||||
}
|
||||
|
||||
public function sendRefundReceipt(Request $request, int $refund): JsonResponse
|
||||
{
|
||||
$log = $this->service->log(['refund_id' => $refund, 'notification_type' => 'refund_receipt', 'channel' => 'database', 'subject' => 'Refund receipt'], optional($request->user())->id);
|
||||
|
||||
return response()->json(['ok' => true, 'notification_log' => $log]);
|
||||
}
|
||||
|
||||
public function sendInvoiceStatement(Request $request, int $invoice): JsonResponse
|
||||
{
|
||||
$inv = DB::table('invoices')->where('id', $invoice)->first();
|
||||
abort_if(!$inv, 404, 'Invoice not found.');
|
||||
abort_if(! $inv, 404, 'Invoice not found.');
|
||||
$log = $this->service->log(['parent_id' => $inv->parent_id ?? null, 'invoice_id' => $invoice, 'notification_type' => 'statement_available', 'channel' => 'database', 'subject' => 'Statement available'], optional($request->user())->id);
|
||||
|
||||
return response()->json(['ok' => true, 'notification_log' => $log]);
|
||||
}
|
||||
|
||||
public function sendOverdueReminder(Request $request, int $parent): JsonResponse
|
||||
{
|
||||
$log = $this->service->log(['parent_id' => $parent, 'notification_type' => 'overdue_balance_reminder', 'channel' => 'database', 'subject' => 'Overdue balance reminder'], optional($request->user())->id);
|
||||
|
||||
return response()->json(['ok' => true, 'notification_log' => $log]);
|
||||
}
|
||||
|
||||
public function sendInstallmentReminder(Request $request, int $installment): JsonResponse
|
||||
{
|
||||
$log = $this->service->log(['installment_id' => $installment, 'notification_type' => 'installment_reminder', 'channel' => 'database', 'subject' => 'Installment reminder'], optional($request->user())->id);
|
||||
|
||||
return response()->json(['ok' => true, 'notification_log' => $log]);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ namespace App\Http\Controllers\Api\Finance;
|
||||
use App\Http\Controllers\Api\Core\BaseApiController;
|
||||
use App\Http\Requests\Finance\FinancialReportRequest;
|
||||
use App\Http\Requests\Finance\FinancialSummaryRequest;
|
||||
use App\Http\Requests\Finance\StakeholderFinancialAnalysisRequest;
|
||||
use App\Http\Requests\Finance\FinancialUnpaidParentsRequest;
|
||||
use App\Http\Requests\Finance\ParentPaymentFollowUpRequest;
|
||||
use App\Http\Requests\Finance\FollowUpNoteRequest;
|
||||
use App\Http\Requests\Finance\ParentPaymentFollowUpRequest;
|
||||
use App\Http\Requests\Finance\StakeholderFinancialAnalysisRequest;
|
||||
use App\Http\Resources\Finance\FinancialReportResource;
|
||||
use App\Http\Resources\Finance\FinancialSummaryResource;
|
||||
use App\Http\Resources\Finance\FinancialUnpaidParentResource;
|
||||
@@ -16,9 +16,9 @@ use App\Services\Finance\FinancialPdfReportService;
|
||||
use App\Services\Finance\FinancialReportService;
|
||||
use App\Services\Finance\FinancialSchoolYearService;
|
||||
use App\Services\Finance\FinancialSummaryService;
|
||||
use App\Services\Finance\StakeholderFinancialAnalysisService;
|
||||
use App\Services\Finance\FinancialUnpaidParentsService;
|
||||
use App\Services\Finance\ParentPaymentFollowUpService;
|
||||
use App\Services\Finance\StakeholderFinancialAnalysisService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
@@ -82,9 +82,6 @@ class FinancialController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function parentPaymentFollowups(ParentPaymentFollowUpRequest $request): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
@@ -104,7 +101,7 @@ class FinancialController extends BaseApiController
|
||||
fputcsv($out, $row);
|
||||
}
|
||||
fclose($out);
|
||||
}, 'parent_payment_followups_' . ($report['schoolYear'] ?? 'report') . '_' . date('Ymd_His') . '.csv', ['Content-Type' => 'text/csv']);
|
||||
}, 'parent_payment_followups_'.($report['schoolYear'] ?? 'report').'_'.date('Ymd_His').'.csv', ['Content-Type' => 'text/csv']);
|
||||
}
|
||||
|
||||
public function storeParentFollowUpNote(FollowUpNoteRequest $request, int $parent): JsonResponse
|
||||
@@ -118,18 +115,21 @@ class FinancialController extends BaseApiController
|
||||
public function markParentContacted(FollowUpNoteRequest $request, int $parent): JsonResponse
|
||||
{
|
||||
$payload = array_merge($request->validated(), ['status' => $request->input('status', 'contacted')]);
|
||||
|
||||
return response()->json(['ok' => true, 'note' => $this->parentPaymentFollowUpService->storeNote($parent, $payload, optional($request->user())->id)], 201);
|
||||
}
|
||||
|
||||
public function storePromiseToPay(FollowUpNoteRequest $request, int $parent): JsonResponse
|
||||
{
|
||||
$payload = array_merge($request->validated(), ['status' => 'promise_to_pay']);
|
||||
|
||||
return response()->json(['ok' => true, 'note' => $this->parentPaymentFollowUpService->storeNote($parent, $payload, optional($request->user())->id)], 201);
|
||||
}
|
||||
|
||||
public function resolveParentFollowUp(FollowUpNoteRequest $request, int $parent): JsonResponse
|
||||
{
|
||||
$payload = array_merge($request->validated(), ['status' => 'resolved']);
|
||||
|
||||
return response()->json(['ok' => true, 'note' => $this->parentPaymentFollowUpService->storeNote($parent, $payload, optional($request->user())->id)], 201);
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ class FinancialController extends BaseApiController
|
||||
fputcsv($out, $row);
|
||||
}
|
||||
fclose($out);
|
||||
}, 'stakeholder_financial_analysis_' . $schoolYear . '_' . date('Ymd_His') . '.csv', ['Content-Type' => 'text/csv']);
|
||||
}, 'stakeholder_financial_analysis_'.$schoolYear.'_'.date('Ymd_His').'.csv', ['Content-Type' => 'text/csv']);
|
||||
}
|
||||
|
||||
public function downloadCsv(FinancialReportRequest $request): StreamedResponse
|
||||
@@ -200,7 +200,7 @@ class FinancialController extends BaseApiController
|
||||
|
||||
$breakdown = $report['paymentBreakdown'] ?? [];
|
||||
|
||||
$filename = 'financial_report_' . date('Ymd_His') . '.csv';
|
||||
$filename = 'financial_report_'.date('Ymd_His').'.csv';
|
||||
|
||||
return response()->streamDownload(function () use ($report, $paymentsMap, $refundsMap, $discountsMap, $breakdown) {
|
||||
$out = fopen('php://output', 'w');
|
||||
@@ -309,6 +309,6 @@ class FinancialController extends BaseApiController
|
||||
|
||||
return response()->streamDownload(function () use ($pdfBytes) {
|
||||
echo $pdfBytes;
|
||||
}, 'Financial_Report_' . $schoolYear . '.pdf', ['Content-Type' => 'application/pdf']);
|
||||
}, 'Financial_Report_'.$schoolYear.'.pdf', ['Content-Type' => 'application/pdf']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,17 +13,52 @@ class InstallmentPlanController extends Controller
|
||||
{
|
||||
public function __construct(private InstallmentPlanService $service) {}
|
||||
|
||||
public function index(Request $request): JsonResponse { return response()->json(['ok' => true, 'plans' => $this->service->list($request->query())]); }
|
||||
public function store(InstallmentPlanRequest $request, int $invoice): JsonResponse { return response()->json(['ok' => true, 'plan' => $this->service->createForInvoice($invoice, $request->validated(), optional($request->user())->id)], 201); }
|
||||
public function show(int $plan): JsonResponse { return response()->json(['ok' => true, 'plan' => $this->service->show($plan)]); }
|
||||
public function activate(Request $request, int $plan): JsonResponse { return response()->json(['ok' => true, 'plan' => $this->service->activate($plan, optional($request->user())->id)]); }
|
||||
public function cancel(int $plan): JsonResponse { return response()->json(['ok' => true, 'plan' => $this->service->cancel($plan)]); }
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
return response()->json(['ok' => true, 'plans' => $this->service->list($request->query())]);
|
||||
}
|
||||
|
||||
public function store(InstallmentPlanRequest $request, int $invoice): JsonResponse
|
||||
{
|
||||
return response()->json(['ok' => true, 'plan' => $this->service->createForInvoice($invoice, $request->validated(), optional($request->user())->id)], 201);
|
||||
}
|
||||
|
||||
public function show(int $plan): JsonResponse
|
||||
{
|
||||
return response()->json(['ok' => true, 'plan' => $this->service->show($plan)]);
|
||||
}
|
||||
|
||||
public function activate(Request $request, int $plan): JsonResponse
|
||||
{
|
||||
return response()->json(['ok' => true, 'plan' => $this->service->activate($plan, optional($request->user())->id)]);
|
||||
}
|
||||
|
||||
public function cancel(int $plan): JsonResponse
|
||||
{
|
||||
return response()->json(['ok' => true, 'plan' => $this->service->cancel($plan)]);
|
||||
}
|
||||
|
||||
public function restructure(InstallmentPlanRequest $request, int $plan): JsonResponse
|
||||
{
|
||||
$old = $this->service->cancel($plan);
|
||||
|
||||
return response()->json(['ok' => true, 'old_plan' => $old, 'message' => 'Old plan cancelled. Create a replacement plan against the invoice to preserve audit history.']);
|
||||
}
|
||||
public function allocatePayment(PaymentAllocationRequest $request, int $payment): JsonResponse { return response()->json(['ok' => true, 'result' => $this->service->allocatePayment($payment, $request->validated())]); }
|
||||
public function due(): JsonResponse { return response()->json(['ok' => true, 'installments' => $this->service->due(false)]); }
|
||||
public function overdue(): JsonResponse { $this->service->markOverdue(); return response()->json(['ok' => true, 'installments' => $this->service->due(true)]); }
|
||||
|
||||
public function allocatePayment(PaymentAllocationRequest $request, int $payment): JsonResponse
|
||||
{
|
||||
return response()->json(['ok' => true, 'result' => $this->service->allocatePayment($payment, $request->validated())]);
|
||||
}
|
||||
|
||||
public function due(): JsonResponse
|
||||
{
|
||||
return response()->json(['ok' => true, 'installments' => $this->service->due(false)]);
|
||||
}
|
||||
|
||||
public function overdue(): JsonResponse
|
||||
{
|
||||
$this->service->markOverdue();
|
||||
|
||||
return response()->json(['ok' => true, 'installments' => $this->service->due(true)]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ class InvoiceController extends BaseApiController
|
||||
$status = $request->validated()['status'];
|
||||
$updated = Invoice::updateInvoiceStatus($invoiceId, $status);
|
||||
|
||||
if (!$updated) {
|
||||
if (! $updated) {
|
||||
return response()->json(['ok' => false, 'message' => 'Invoice not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -151,12 +151,9 @@ class InvoiceController extends BaseApiController
|
||||
|
||||
return response()->streamDownload(function () use ($pdfBytes) {
|
||||
echo $pdfBytes;
|
||||
}, 'invoice_' . $invoiceId . '.pdf', ['Content-Type' => 'application/pdf']);
|
||||
}, 'invoice_'.$invoiceId.'.pdf', ['Content-Type' => 'application/pdf']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -82,7 +82,7 @@ class PaymentController extends BaseApiController
|
||||
$payload = $validator->validated();
|
||||
$updated = $this->balanceService->updateBalance($paymentId, (float) $payload['paid_amount']);
|
||||
|
||||
if (!$updated) {
|
||||
if (! $updated) {
|
||||
return response()->json(['ok' => false, 'message' => 'Payment not found.'], 404);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,9 +69,6 @@ class PaymentEventChargesController extends BaseApiController
|
||||
return response()->json(['ok' => true, 'students' => $students]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -8,8 +8,8 @@ use App\Http\Requests\Payments\PaymentManualUpdateRequest;
|
||||
use App\Services\Payments\PaymentManualService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class PaymentManualController extends BaseApiController
|
||||
{
|
||||
@@ -87,7 +87,8 @@ class PaymentManualController extends BaseApiController
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return response()->json(['ok' => false, 'message' => $e->getMessage()], 422);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Manual payment record failed: ' . $e->getMessage());
|
||||
Log::error('Manual payment record failed: '.$e->getMessage());
|
||||
|
||||
return response()->json(['ok' => false, 'message' => 'Unable to record payment.'], 400);
|
||||
}
|
||||
|
||||
@@ -115,7 +116,8 @@ class PaymentManualController extends BaseApiController
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return response()->json(['ok' => false, 'message' => $e->getMessage()], 422);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Manual payment edit failed: ' . $e->getMessage());
|
||||
Log::error('Manual payment edit failed: '.$e->getMessage());
|
||||
|
||||
return response()->json(['ok' => false, 'message' => 'Unable to update payment.'], 400);
|
||||
}
|
||||
|
||||
@@ -125,12 +127,10 @@ class PaymentManualController extends BaseApiController
|
||||
public function file(Request $request, string $filename)
|
||||
{
|
||||
$mode = (string) ($request->query('mode') ?? 'download');
|
||||
|
||||
return $this->service->serveCheckFile($filename, $mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -83,7 +83,7 @@ class PaymentTransactionController extends BaseApiController
|
||||
|
||||
$updated = $this->service->updateStatus($transactionId, (string) $status);
|
||||
|
||||
if (!$updated) {
|
||||
if (! $updated) {
|
||||
return response()->json(['ok' => false, 'message' => 'Transaction not found.'], 404);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class PaypalTransactionsController extends BaseApiController
|
||||
$payload = $request->validated();
|
||||
$rows = $this->service->listAll($payload['q'] ?? null);
|
||||
|
||||
$filename = 'paypal_transactions_' . date('Ymd_His') . '.csv';
|
||||
$filename = 'paypal_transactions_'.date('Ymd_His').'.csv';
|
||||
|
||||
return response()->streamDownload(function () use ($rows) {
|
||||
$out = fopen('php://output', 'w');
|
||||
|
||||
@@ -52,7 +52,7 @@ class PurchaseOrderController extends BaseApiController
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$data = $this->queryService->find($id);
|
||||
if (!$data) {
|
||||
if (! $data) {
|
||||
return response()->json(['ok' => false, 'message' => 'Purchase order not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class PurchaseOrderController extends BaseApiController
|
||||
$validator = Validator::make($data, [
|
||||
'po_number' => ['required', 'string', 'max:60'],
|
||||
'supplier_id' => ['required', 'integer', 'min:1', 'exists:suppliers,id'],
|
||||
'status' => ['nullable', 'string', 'in:' . implode(',', PurchaseOrder::allowedStatuses())],
|
||||
'status' => ['nullable', 'string', 'in:'.implode(',', PurchaseOrder::allowedStatuses())],
|
||||
'order_date' => ['nullable', 'date'],
|
||||
'expected_date' => ['nullable', 'date'],
|
||||
'notes' => ['nullable', 'string', 'max:5000'],
|
||||
@@ -88,7 +88,7 @@ class PurchaseOrderController extends BaseApiController
|
||||
}
|
||||
|
||||
$payload = $validator->validated();
|
||||
if (!empty($payload['order_date']) && !empty($payload['expected_date'])) {
|
||||
if (! empty($payload['order_date']) && ! empty($payload['expected_date'])) {
|
||||
$orderTs = strtotime((string) $payload['order_date']);
|
||||
$expectedTs = strtotime((string) $payload['expected_date']);
|
||||
if ($orderTs !== false && $expectedTs !== false && $expectedTs < $orderTs) {
|
||||
@@ -136,7 +136,7 @@ class PurchaseOrderController extends BaseApiController
|
||||
$payload = $validator->validated();
|
||||
|
||||
$po = PurchaseOrder::query()->find($id);
|
||||
if (!$po) {
|
||||
if (! $po) {
|
||||
return response()->json(['ok' => false, 'message' => 'Purchase order not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ class PurchaseOrderController extends BaseApiController
|
||||
}
|
||||
|
||||
$po = PurchaseOrder::query()->find($id);
|
||||
if (!$po) {
|
||||
if (! $po) {
|
||||
return response()->json(['ok' => false, 'message' => 'Purchase order not found.'], 404);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class RefundController extends BaseApiController
|
||||
public function show(int $refundId): JsonResponse
|
||||
{
|
||||
$refund = $this->queryService->find($refundId);
|
||||
if (!$refund) {
|
||||
if (! $refund) {
|
||||
return response()->json(['ok' => false, 'message' => 'Refund not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ class RefundController extends BaseApiController
|
||||
$result = $this->requestService->requestRefund($payload, $guard);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Refund request failed.', ['error' => $e->getMessage()]);
|
||||
|
||||
return response()->json(['ok' => false, 'message' => 'Failed to submit refund request.'], 500);
|
||||
}
|
||||
|
||||
@@ -212,9 +213,6 @@ class RefundController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -93,6 +93,7 @@ class ReimbursementController extends BaseApiController
|
||||
} catch (RuntimeException $e) {
|
||||
$message = $e->getMessage();
|
||||
$status = str_contains($message, 'not found') ? 404 : (str_contains($message, 'already') ? 409 : 422);
|
||||
|
||||
return response()->json(['ok' => false, 'message' => $message], $status);
|
||||
} catch (\Throwable $e) {
|
||||
return response()->json(['ok' => false, 'message' => 'Unable to mark donation right now.'], 500);
|
||||
@@ -144,7 +145,7 @@ class ReimbursementController extends BaseApiController
|
||||
|
||||
$adminIdRaw = $payload['admin_id'] ?? null;
|
||||
$adminId = ($adminIdRaw === '' || $adminIdRaw === null) ? null : (int) $adminIdRaw;
|
||||
$reimbursementId = !empty($payload['reimbursement_id']) ? (int) $payload['reimbursement_id'] : null;
|
||||
$reimbursementId = ! empty($payload['reimbursement_id']) ? (int) $payload['reimbursement_id'] : null;
|
||||
|
||||
try {
|
||||
$result = $this->assignmentService->updateAssignment(
|
||||
@@ -184,6 +185,7 @@ class ReimbursementController extends BaseApiController
|
||||
} catch (RuntimeException $e) {
|
||||
$message = $e->getMessage();
|
||||
$status = str_contains($message, 'check file') ? 409 : 404;
|
||||
|
||||
return response()->json(['ok' => false, 'message' => $message], $status);
|
||||
} catch (\Throwable $e) {
|
||||
return response()->json(['ok' => false, 'message' => 'Unable to lock batch right now.'], 500);
|
||||
@@ -204,7 +206,7 @@ class ReimbursementController extends BaseApiController
|
||||
$adminId = (int) $payload['admin_id'];
|
||||
|
||||
$batch = ReimbursementBatch::query()->find($batchId);
|
||||
if (!$batch) {
|
||||
if (! $batch) {
|
||||
return response()->json(['ok' => false, 'message' => 'Batch not found.'], 404);
|
||||
}
|
||||
if (strtolower((string) ($batch->status ?? '')) !== ReimbursementBatch::STATUS_OPEN) {
|
||||
@@ -231,7 +233,7 @@ class ReimbursementController extends BaseApiController
|
||||
|
||||
return response(file_get_contents($meta['path']), 200, [
|
||||
'Content-Type' => $meta['mime'],
|
||||
'Content-Disposition' => $disposition . '; filename="' . $meta['download_name'] . '"',
|
||||
'Content-Disposition' => $disposition.'; filename="'.$meta['download_name'].'"',
|
||||
'Content-Length' => (string) $meta['size'],
|
||||
'ETag' => $meta['etag'],
|
||||
'Last-Modified' => $meta['last_modified'],
|
||||
@@ -281,7 +283,7 @@ class ReimbursementController extends BaseApiController
|
||||
return response()->json(['ok' => false, 'message' => $e->getMessage()], 404);
|
||||
}
|
||||
|
||||
if (!$ok) {
|
||||
if (! $ok) {
|
||||
return response()->json(['ok' => false, 'message' => 'Failed to send email. Please try again.'], 500);
|
||||
}
|
||||
|
||||
@@ -301,7 +303,7 @@ class ReimbursementController extends BaseApiController
|
||||
|
||||
return response()->streamDownload(function () use ($csv) {
|
||||
$out = fopen('php://output', 'w');
|
||||
fprintf($out, chr(0xEF) . chr(0xBB) . chr(0xBF));
|
||||
fprintf($out, chr(0xEF).chr(0xBB).chr(0xBF));
|
||||
foreach ($csv['rows'] as $row) {
|
||||
fputcsv($out, $row);
|
||||
}
|
||||
@@ -318,7 +320,7 @@ class ReimbursementController extends BaseApiController
|
||||
|
||||
return response()->streamDownload(function () use ($csv) {
|
||||
$out = fopen('php://output', 'w');
|
||||
fprintf($out, chr(0xEF) . chr(0xBB) . chr(0xBF));
|
||||
fprintf($out, chr(0xEF).chr(0xBB).chr(0xBF));
|
||||
foreach ($csv['rows'] as $row) {
|
||||
fputcsv($out, $row);
|
||||
}
|
||||
@@ -436,7 +438,7 @@ class ReimbursementController extends BaseApiController
|
||||
}
|
||||
|
||||
$reimb = Reimbursement::query()->find($id);
|
||||
if (!$reimb) {
|
||||
if (! $reimb) {
|
||||
return response()->json(['ok' => false, 'message' => 'Reimbursement not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -464,7 +466,7 @@ class ReimbursementController extends BaseApiController
|
||||
if ($request->hasFile('receipt')) {
|
||||
$receiptName = $this->fileService->storeReceipt($request->file('receipt'));
|
||||
}
|
||||
if (!empty($payload['remove_receipt'])) {
|
||||
if (! empty($payload['remove_receipt'])) {
|
||||
$receiptName = null;
|
||||
}
|
||||
|
||||
@@ -478,9 +480,6 @@ class ReimbursementController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -61,7 +61,7 @@ class FrontendController extends BaseApiController
|
||||
public function fetchUser(): JsonResponse
|
||||
{
|
||||
$user = auth()->user();
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
return $this->error('Unauthorized.', Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,6 @@ class InfoIconController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -19,7 +19,7 @@ class LandingPageController extends BaseApiController
|
||||
public function index(LandingTeacherRequest $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
return $this->error('Unauthorized.', Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class LandingPageController extends BaseApiController
|
||||
public function teacher(LandingTeacherRequest $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
return $this->error('Unauthorized.', Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class LandingPageController extends BaseApiController
|
||||
public function parent(): JsonResponse
|
||||
{
|
||||
$user = auth()->user();
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
return $this->error('Unauthorized.', Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ class PageController extends BaseApiController
|
||||
private function renderStatic(string $filename, string $type): JsonResponse
|
||||
{
|
||||
$result = $this->pageService->load($filename, $type);
|
||||
if (!$result['ok']) {
|
||||
if (! $result['ok']) {
|
||||
return $this->error($result['error'], Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
namespace App\Http\Controllers\Api\Grading;
|
||||
|
||||
use App\Http\Controllers\Api\Core\BaseApiController;
|
||||
use App\Http\Requests\Grading\BelowSixtyEmailRequest;
|
||||
use App\Http\Requests\Grading\AllDecisionsRequest;
|
||||
use App\Http\Requests\Grading\BelowSixtyDecisionDetailsRequest;
|
||||
use App\Http\Requests\Grading\BelowSixtyDecisionListRequest;
|
||||
use App\Http\Requests\Grading\BelowSixtyDecisionSaveRequest;
|
||||
use App\Http\Requests\Grading\BelowSixtyDecisionSendRequest;
|
||||
use App\Http\Requests\Grading\BelowSixtyEmailRequest;
|
||||
use App\Http\Requests\Grading\BelowSixtyListRequest;
|
||||
use App\Http\Requests\Grading\BelowSixtyMeetingRequest;
|
||||
use App\Http\Requests\Grading\BelowSixtyMeetingSaveRequest;
|
||||
use App\Http\Requests\Grading\BelowSixtySendRequest;
|
||||
use App\Http\Requests\Grading\BelowSixtyStatusRequest;
|
||||
use App\Http\Requests\Grading\BelowSixtyListRequest;
|
||||
use App\Http\Requests\Grading\GenerateAllDecisionsRequest;
|
||||
use App\Http\Requests\Grading\GradingLockAllRequest;
|
||||
use App\Http\Requests\Grading\GradingLockRequest;
|
||||
@@ -23,8 +23,8 @@ use App\Http\Requests\Grading\GradingScoreShowRequest;
|
||||
use App\Http\Requests\Grading\GradingScoreUpdateRequest;
|
||||
use App\Http\Requests\Grading\PlacementBatchRequest;
|
||||
use App\Http\Requests\Grading\PlacementBatchUpdateRequest;
|
||||
use App\Http\Requests\Grading\PlacementLevelsRequest;
|
||||
use App\Http\Requests\Grading\PlacementLevelRequest;
|
||||
use App\Http\Requests\Grading\PlacementLevelsRequest;
|
||||
use App\Http\Requests\Grading\PlacementRequest;
|
||||
use App\Http\Resources\Grading\BelowSixtyStudentResource;
|
||||
use App\Http\Resources\Grading\GradingScoreResource;
|
||||
@@ -419,9 +419,6 @@ class GradingController extends BaseApiController
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Http\Controllers\Api\Incidents;
|
||||
|
||||
use App\Http\Controllers\Api\Core\BaseApiController;
|
||||
use App\Http\Requests\Incidents\IncidentCancelRequest;
|
||||
use App\Http\Requests\Incidents\IncidentCloseRequest;
|
||||
use App\Http\Requests\Incidents\IncidentListRequest;
|
||||
use App\Http\Requests\Incidents\IncidentStateRequest;
|
||||
use App\Http\Resources\Incidents\IncidentAnalysisStudentResource;
|
||||
@@ -209,9 +208,6 @@ class IncidentController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -31,7 +31,7 @@ class InventoryCategoryController extends BaseApiController
|
||||
public function store(InventoryCategoryStoreRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->categories->create($request->validated());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to save category.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class InventoryCategoryController extends BaseApiController
|
||||
return $this->error($e->getMessage(), Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to update category.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class InventoryCategoryController extends BaseApiController
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->categories->delete($id);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to delete category.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ class InventoryController extends BaseApiController
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$item = $this->items->find($id);
|
||||
if (!$item) {
|
||||
if (! $item) {
|
||||
return $this->error('Item not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class InventoryController extends BaseApiController
|
||||
}
|
||||
|
||||
$result = $this->items->create($request->validated(), $actor);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to create item.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ class InventoryController extends BaseApiController
|
||||
}
|
||||
|
||||
$result = $this->items->update($id, $request->validated(), $actor);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to update item.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ class InventoryController extends BaseApiController
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->items->delete($id);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to delete item.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ class InventoryController extends BaseApiController
|
||||
}
|
||||
|
||||
$result = $this->items->auditClassroom($id, $request->validated(), $actor);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to audit item.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ class InventoryController extends BaseApiController
|
||||
}
|
||||
|
||||
$result = $this->items->adjustStock($id, $request->validated(), $actor);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to adjust stock.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -131,6 +131,7 @@ class InventoryController extends BaseApiController
|
||||
public function summary(string $type): JsonResponse
|
||||
{
|
||||
$payload = $this->summary->summary($type, request()->query('school_year'));
|
||||
|
||||
return $this->success($payload);
|
||||
}
|
||||
|
||||
@@ -140,6 +141,7 @@ class InventoryController extends BaseApiController
|
||||
request()->query('school_year'),
|
||||
request()->query('type')
|
||||
);
|
||||
|
||||
return $this->success($payload);
|
||||
}
|
||||
|
||||
@@ -157,7 +159,7 @@ class InventoryController extends BaseApiController
|
||||
$payload['item_id'] ?? null
|
||||
);
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Unable to load distribution form.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -174,11 +176,12 @@ class InventoryController extends BaseApiController
|
||||
try {
|
||||
$result = $this->distribution->distribute($actor, $request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Inventory distribution failed: ' . $e->getMessage());
|
||||
Log::error('Inventory distribution failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Unable to distribute inventory.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Unable to distribute inventory.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -247,7 +250,7 @@ class InventoryController extends BaseApiController
|
||||
public function reorderRequest(int $id): JsonResponse
|
||||
{
|
||||
$item = InventoryItem::with('preferredSupplier')->find($id);
|
||||
if (!$item) {
|
||||
if (! $item) {
|
||||
return $this->error('Item not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -340,9 +343,6 @@ class InventoryController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -36,7 +36,7 @@ class InventoryMovementController extends BaseApiController
|
||||
}
|
||||
|
||||
$result = $this->movements->create($request->validated(), $actor);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to create movement.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class InventoryMovementController extends BaseApiController
|
||||
public function update(InventoryMovementUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->movements->update($id, $request->validated());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to update movement.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class InventoryMovementController extends BaseApiController
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->movements->delete($id);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to delete movement.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class InventoryMovementController extends BaseApiController
|
||||
public function bulkDelete(InventoryMovementBulkDeleteRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->movements->bulkDelete($request->validated()['ids']);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Bulk delete failed.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class InventoryMovementController extends BaseApiController
|
||||
}
|
||||
|
||||
$result = $this->movements->voidMovement($id, $reason, $actor);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to void movement.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -117,16 +117,13 @@ class InventoryMovementController extends BaseApiController
|
||||
}
|
||||
|
||||
$result = $this->movements->correctMovement($id, $qtyChange, $reason, $actor);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to correct movement.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->success(['message' => 'Correction movement created.']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -33,7 +33,7 @@ class SupplierController extends BaseApiController
|
||||
public function store(SupplierStoreRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->suppliers->create($request->validated());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to save supplier.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class SupplierController extends BaseApiController
|
||||
public function update(SupplierUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->suppliers->update($id, $request->validated());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to update supplier.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class SupplierController extends BaseApiController
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->suppliers->delete($id);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to delete supplier.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class SupplyCategoryController extends BaseApiController
|
||||
public function store(SupplyCategoryStoreRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->categories->create($request->validated());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to save category.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class SupplyCategoryController extends BaseApiController
|
||||
public function update(SupplyCategoryUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->categories->update($id, $request->validated());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to update category.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class SupplyCategoryController extends BaseApiController
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->categories->delete($id);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to delete category.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class MessagesController extends BaseApiController
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$message = $this->queryService->findForUser($id);
|
||||
if (!$message) {
|
||||
if (! $message) {
|
||||
return $this->error('Message not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,8 @@ class MessagesController extends BaseApiController
|
||||
try {
|
||||
$message = $this->commandService->create($guard, $request->validated(), $request->file('attachment'));
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Message send failed: ' . $e->getMessage());
|
||||
Log::error('Message send failed: '.$e->getMessage());
|
||||
|
||||
return $this->error($e->getMessage(), Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
@@ -150,7 +151,7 @@ class MessagesController extends BaseApiController
|
||||
public function update(MessageUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$message = Message::query()->find($id);
|
||||
if (!$message) {
|
||||
if (! $message) {
|
||||
return $this->error('Message not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -159,7 +160,8 @@ class MessagesController extends BaseApiController
|
||||
try {
|
||||
$updated = $this->commandService->update($message, $request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Message update failed: ' . $e->getMessage());
|
||||
Log::error('Message update failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Unable to update message.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -171,7 +173,7 @@ class MessagesController extends BaseApiController
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$message = Message::query()->find($id);
|
||||
if (!$message) {
|
||||
if (! $message) {
|
||||
return $this->error('Message not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -180,11 +182,12 @@ class MessagesController extends BaseApiController
|
||||
try {
|
||||
$trashed = $this->commandService->trash($message);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Message delete failed: ' . $e->getMessage());
|
||||
Log::error('Message delete failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Unable to delete message.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!$trashed) {
|
||||
if (! $trashed) {
|
||||
return $this->error('Unable to delete message.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -220,9 +223,6 @@ class MessagesController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -117,11 +117,12 @@ class WhatsappController extends BaseApiController
|
||||
try {
|
||||
$result = $this->inviteService->send($request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('WhatsApp invite send failed: ' . $e->getMessage());
|
||||
Log::error('WhatsApp invite send failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Invite processing failed.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Invite processing failed.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -140,11 +141,12 @@ class WhatsappController extends BaseApiController
|
||||
try {
|
||||
$result = $this->membershipService->updateMembership($request->validated(), $userId);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('WhatsApp membership update failed: ' . $e->getMessage());
|
||||
Log::error('WhatsApp membership update failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to save membership.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
$code = str_contains((string) ($result['message'] ?? ''), 'missing')
|
||||
? Response::HTTP_INTERNAL_SERVER_ERROR
|
||||
: Response::HTTP_UNPROCESSABLE_ENTITY;
|
||||
@@ -158,9 +160,6 @@ class WhatsappController extends BaseApiController
|
||||
], 'Membership saved.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -59,7 +59,7 @@ class NotificationController extends BaseApiController
|
||||
}
|
||||
|
||||
$row = $this->showService->getForUser($guard, $notificationId);
|
||||
if (!$row) {
|
||||
if (! $row) {
|
||||
return response()->json(['ok' => false, 'message' => 'Notification not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ class NotificationController extends BaseApiController
|
||||
$result = $this->sendService->send($payload, $guard);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Notification send failed.', ['error' => $e->getMessage()]);
|
||||
|
||||
return response()->json(['ok' => false, 'message' => 'Failed to send notification.'], 500);
|
||||
}
|
||||
|
||||
@@ -114,7 +115,7 @@ class NotificationController extends BaseApiController
|
||||
public function destroy(int $notificationId): JsonResponse
|
||||
{
|
||||
$deleted = $this->managementService->delete($notificationId);
|
||||
if (!$deleted) {
|
||||
if (! $deleted) {
|
||||
return response()->json(['ok' => false, 'message' => 'Notification not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -124,7 +125,7 @@ class NotificationController extends BaseApiController
|
||||
public function restore(int $notificationId): JsonResponse
|
||||
{
|
||||
$restored = $this->managementService->restore($notificationId);
|
||||
if (!$restored) {
|
||||
if (! $restored) {
|
||||
return response()->json(['ok' => false, 'message' => 'Notification not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -139,7 +140,7 @@ class NotificationController extends BaseApiController
|
||||
}
|
||||
|
||||
$ok = $this->readService->markRead($guard, $notificationId);
|
||||
if (!$ok) {
|
||||
if (! $ok) {
|
||||
return response()->json(['ok' => false, 'message' => 'Notification not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -167,9 +168,6 @@ class NotificationController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace App\Http\Controllers\Api\Parents;
|
||||
|
||||
use App\Http\Controllers\Api\Core\BaseApiController;
|
||||
use App\Http\Requests\Parents\ParentAttendanceReportSubmitRequest;
|
||||
use App\Http\Requests\Parents\ParentAttendanceReportListRequest;
|
||||
use App\Http\Requests\Parents\ParentAttendanceReportCheckRequest;
|
||||
use App\Http\Requests\Parents\ParentAttendanceReportListRequest;
|
||||
use App\Http\Requests\Parents\ParentAttendanceReportSubmitRequest;
|
||||
use App\Http\Requests\Parents\ParentAttendanceReportUpdateRequest;
|
||||
use App\Http\Resources\Parents\ParentAttendanceReportResource;
|
||||
use App\Services\Parents\ParentAttendanceReportService;
|
||||
@@ -116,9 +116,6 @@ class ParentAttendanceReportController extends BaseApiController
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function parentIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$parentId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -4,18 +4,18 @@ namespace App\Http\Controllers\Api\Parents;
|
||||
|
||||
use App\Http\Controllers\Api\Core\BaseApiController;
|
||||
use App\Http\Requests\Parents\ParentAttendanceRequest;
|
||||
use App\Http\Requests\Parents\ParentEmergencyContactRequest;
|
||||
use App\Http\Requests\Parents\ParentEnrollmentActionRequest;
|
||||
use App\Http\Requests\Parents\ParentEnrollmentRequest;
|
||||
use App\Http\Requests\Parents\ParentEmergencyContactRequest;
|
||||
use App\Http\Requests\Parents\ParentEventParticipationRequest;
|
||||
use App\Http\Requests\Parents\ParentInvoiceRequest;
|
||||
use App\Http\Requests\Parents\ParentProfileUpdateRequest;
|
||||
use App\Http\Requests\Parents\ParentRegistrationRequest;
|
||||
use App\Http\Requests\Parents\ParentStudentUpdateRequest;
|
||||
use App\Http\Resources\Invoices\InvoiceResource;
|
||||
use App\Http\Resources\Parents\ParentAttendanceResource;
|
||||
use App\Http\Resources\Parents\ParentEmergencyContactResource;
|
||||
use App\Http\Resources\Parents\ParentStudentResource;
|
||||
use App\Http\Resources\Invoices\InvoiceResource;
|
||||
use App\Services\Parents\ParentAttendanceService;
|
||||
use App\Services\Parents\ParentEmergencyContactService;
|
||||
use App\Services\Parents\ParentEnrollmentService;
|
||||
|
||||
@@ -140,20 +140,21 @@ class ParentPromotionController extends BaseApiController
|
||||
private function loadOwnedRecord(int $promotionId, int $parentId): StudentPromotionRecord|JsonResponse
|
||||
{
|
||||
$record = StudentPromotionRecord::query()->find($promotionId);
|
||||
if (!$record) {
|
||||
if (! $record) {
|
||||
return response()->json(['ok' => false, 'message' => 'Promotion record not found.'], Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
$owns = (int) $record->parent_id === $parentId;
|
||||
if (!$owns) {
|
||||
if (! $owns) {
|
||||
$studentParentId = (int) (Student::query()
|
||||
->where('id', $record->student_id)
|
||||
->value('parent_id') ?? 0);
|
||||
$owns = $studentParentId === $parentId;
|
||||
}
|
||||
if (!$owns) {
|
||||
if (! $owns) {
|
||||
return response()->json(['ok' => false, 'message' => 'You are not authorised to view this promotion record.'], Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
@@ -168,6 +169,7 @@ class ParentPromotionController extends BaseApiController
|
||||
if ($parentId <= 0) {
|
||||
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
return $parentId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\User;
|
||||
use App\Services\PrintRequests\PrintRequestsPortalService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
@@ -59,7 +60,7 @@ class PrintRequestsController extends BaseApiController
|
||||
return $this->respondValidationError($validator->errors()->toArray());
|
||||
}
|
||||
|
||||
/** @var \Illuminate\Http\UploadedFile $file */
|
||||
/** @var UploadedFile $file */
|
||||
$file = $request->file('file');
|
||||
$model = $this->portal->storeTeacherUpload($validator->validated(), $file, $uid);
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class ReportCardsController extends BaseApiController
|
||||
$classSectionId = (int) ($payload['class_section_id'] ?? 0);
|
||||
|
||||
$result = $this->service->completeness($schoolYear, $semester, $classSectionId);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Unable to generate completeness report.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -101,11 +101,12 @@ class ReportCardsController extends BaseApiController
|
||||
try {
|
||||
$result = $this->service->generateSingleReport($studentId, $request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Report card PDF generation failed: ' . $e->getMessage());
|
||||
Log::error('Report card PDF generation failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to generate report card.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Unable to generate report card.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -113,7 +114,7 @@ class ReportCardsController extends BaseApiController
|
||||
|
||||
return response($result['pdf'], 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => $disposition . '; filename="' . ($result['filename'] ?? 'ReportCard.pdf') . '"',
|
||||
'Content-Disposition' => $disposition.'; filename="'.($result['filename'] ?? 'ReportCard.pdf').'"',
|
||||
'Cache-Control' => 'private, max-age=0, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
@@ -124,11 +125,12 @@ class ReportCardsController extends BaseApiController
|
||||
try {
|
||||
$result = $this->service->generateClassReport($classSectionId, $request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Class report card PDF generation failed: ' . $e->getMessage());
|
||||
Log::error('Class report card PDF generation failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to generate class report cards.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Unable to generate class report cards.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -136,7 +138,7 @@ class ReportCardsController extends BaseApiController
|
||||
|
||||
return response($result['pdf'], 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => $disposition . '; filename="' . ($result['filename'] ?? 'ClassReportCards.pdf') . '"',
|
||||
'Content-Disposition' => $disposition.'; filename="'.($result['filename'] ?? 'ClassReportCards.pdf').'"',
|
||||
'Cache-Control' => 'private, max-age=0, must-revalidate',
|
||||
'Pragma' => 'public',
|
||||
]);
|
||||
@@ -148,6 +150,7 @@ class ReportCardsController extends BaseApiController
|
||||
if ($value !== '') {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return trim((string) (Configuration::getConfig('school_year') ?? ''));
|
||||
}
|
||||
|
||||
@@ -157,6 +160,7 @@ class ReportCardsController extends BaseApiController
|
||||
if ($value !== '') {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return trim((string) (Configuration::getConfig('semester') ?? ''));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,13 +27,13 @@ class SlipPrinterController extends BaseApiController
|
||||
|
||||
$result = $this->service->print($request->validated(), $guard);
|
||||
|
||||
if (!$result['ok']) {
|
||||
if (! $result['ok']) {
|
||||
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Print failed.'], 422);
|
||||
}
|
||||
|
||||
return response($result['pdf'], 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="' . $result['filename'] . '"',
|
||||
'Content-Disposition' => 'inline; filename="'.$result['filename'].'"',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -78,19 +78,16 @@ class SlipPrinterController extends BaseApiController
|
||||
|
||||
$result = $this->service->reprint((int) $request->validated()['id'], $guard);
|
||||
|
||||
if (!$result['ok']) {
|
||||
if (! $result['ok']) {
|
||||
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Slip not found.'], 404);
|
||||
}
|
||||
|
||||
return response($result['pdf'], 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="' . $result['filename'] . '"',
|
||||
'Content-Disposition' => 'inline; filename="'.$result['filename'].'"',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -64,17 +64,18 @@ class StickersController extends BaseApiController
|
||||
try {
|
||||
$result = $this->printService->generate($request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Sticker print failed: ' . $e->getMessage());
|
||||
Log::error('Sticker print failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to generate stickers.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Unable to generate stickers.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return response($result['pdf'], 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="' . ($result['filename'] ?? 'Student_Stickers.pdf') . '"',
|
||||
'Content-Disposition' => 'inline; filename="'.($result['filename'] ?? 'Student_Stickers.pdf').'"',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class RolePermissionController extends BaseApiController
|
||||
public function showRole(int $roleId): JsonResponse
|
||||
{
|
||||
$role = Role::query()->find($roleId);
|
||||
if (!$role) {
|
||||
if (! $role) {
|
||||
return $this->error('Role not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,8 @@ class RolePermissionController extends BaseApiController
|
||||
try {
|
||||
$role = $this->roleCrudService->create($request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Role store failed: ' . $e->getMessage());
|
||||
Log::error('Role store failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to create role.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -81,14 +82,15 @@ class RolePermissionController extends BaseApiController
|
||||
public function updateRole(RoleUpdateRequest $request, int $roleId): JsonResponse
|
||||
{
|
||||
$role = Role::query()->find($roleId);
|
||||
if (!$role) {
|
||||
if (! $role) {
|
||||
return $this->error('Role not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
$role = $this->roleCrudService->update($role, $request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Role update failed: ' . $e->getMessage());
|
||||
Log::error('Role update failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to update role.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -100,14 +102,15 @@ class RolePermissionController extends BaseApiController
|
||||
public function deleteRole(int $roleId): JsonResponse
|
||||
{
|
||||
$role = Role::query()->find($roleId);
|
||||
if (!$role) {
|
||||
if (! $role) {
|
||||
return $this->error('Role not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->roleCrudService->delete($role);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Role delete failed: ' . $e->getMessage());
|
||||
Log::error('Role delete failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to delete role.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -138,11 +141,12 @@ class RolePermissionController extends BaseApiController
|
||||
(int) (auth()->id() ?? 0)
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Assign roles failed: ' . $e->getMessage());
|
||||
Log::error('Assign roles failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to update roles.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to update roles.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -163,7 +167,7 @@ class RolePermissionController extends BaseApiController
|
||||
public function showPermission(int $permissionId): JsonResponse
|
||||
{
|
||||
$permission = Permission::query()->find($permissionId);
|
||||
if (!$permission) {
|
||||
if (! $permission) {
|
||||
return $this->error('Permission not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -177,7 +181,8 @@ class RolePermissionController extends BaseApiController
|
||||
try {
|
||||
$permission = $this->permissionCrudService->create($request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Permission store failed: ' . $e->getMessage());
|
||||
Log::error('Permission store failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to create permission.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -189,14 +194,15 @@ class RolePermissionController extends BaseApiController
|
||||
public function updatePermission(PermissionUpdateRequest $request, int $permissionId): JsonResponse
|
||||
{
|
||||
$permission = Permission::query()->find($permissionId);
|
||||
if (!$permission) {
|
||||
if (! $permission) {
|
||||
return $this->error('Permission not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
$permission = $this->permissionCrudService->update($permission, $request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Permission update failed: ' . $e->getMessage());
|
||||
Log::error('Permission update failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to update permission.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -208,14 +214,15 @@ class RolePermissionController extends BaseApiController
|
||||
public function deletePermission(int $permissionId): JsonResponse
|
||||
{
|
||||
$permission = Permission::query()->find($permissionId);
|
||||
if (!$permission) {
|
||||
if (! $permission) {
|
||||
return $this->error('Permission not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->permissionCrudService->delete($permission);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Permission delete failed: ' . $e->getMessage());
|
||||
Log::error('Permission delete failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to delete permission.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -236,7 +243,8 @@ class RolePermissionController extends BaseApiController
|
||||
try {
|
||||
$this->permissionService->saveRolePermissions($roleId, $request->validated()['permissions'] ?? []);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Role permissions update failed: ' . $e->getMessage());
|
||||
Log::error('Role permissions update failed: '.$e->getMessage());
|
||||
|
||||
return $this->error('Failed to update role permissions.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace App\Http\Controllers\Api;
|
||||
use App\Http\Requests\Roles\RoleSwitchRequest;
|
||||
use App\Services\Roles\RoleSwitchService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RoleSwitcherController extends BaseApiController
|
||||
{
|
||||
|
||||
@@ -23,12 +23,13 @@ use Illuminate\Support\Facades\Schema;
|
||||
class ScannerController extends BaseApiController
|
||||
{
|
||||
private const LATE_CUTOFF_CONFIG_KEY = 'attendance_late_cutoff_time';
|
||||
|
||||
private const DEFAULT_LATE_CUTOFF = '10:00 AM';
|
||||
|
||||
public function process(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->json()->all();
|
||||
if (!is_array($data) || $data === []) {
|
||||
if (! is_array($data) || $data === []) {
|
||||
$data = $request->all();
|
||||
}
|
||||
|
||||
@@ -41,10 +42,11 @@ class ScannerController extends BaseApiController
|
||||
|
||||
if ($badgeCode === '') {
|
||||
$this->logScan($badgeCode, null, null, $action, 'rejected', $operatorId, $stationId, 'Badge code is required.', $scannedAt);
|
||||
|
||||
return response()->json($this->failure('Badge code is required.'), 400);
|
||||
}
|
||||
|
||||
if (!in_array($scanStatus, ['present', 'late'], true)) {
|
||||
if (! in_array($scanStatus, ['present', 'late'], true)) {
|
||||
$scanStatus = 'present';
|
||||
}
|
||||
|
||||
@@ -59,6 +61,7 @@ class ScannerController extends BaseApiController
|
||||
}
|
||||
|
||||
$this->logScan($badgeCode, null, null, $action, 'not_found', $operatorId, $stationId, 'Badge not found.', $scannedAt);
|
||||
|
||||
return response()->json($this->failure('Badge not found.'), 404);
|
||||
}
|
||||
|
||||
@@ -74,8 +77,9 @@ class ScannerController extends BaseApiController
|
||||
}
|
||||
|
||||
$assignment = $this->studentAssignment((int) $student->id, $term['semester'], $term['school_year']);
|
||||
if (!$assignment) {
|
||||
if (! $assignment) {
|
||||
$this->logScan($badgeCode, 'student', (int) $student->id, $action, 'rejected', $operatorId, $stationId, 'Student has no class assignment for current term.', $scannedAt);
|
||||
|
||||
return response()->json($this->failure('Student has no class assignment for current term.'), 409);
|
||||
}
|
||||
|
||||
@@ -150,7 +154,7 @@ class ScannerController extends BaseApiController
|
||||
$operatorId,
|
||||
$existing ? (string) ($oldStatus ?? '') : null
|
||||
);
|
||||
$warnings[] = 'Student arrived after ' . $lateCutoff->format('h:i A') . '. Late slip receipt generated.';
|
||||
$warnings[] = 'Student arrived after '.$lateCutoff->format('h:i A').'. Late slip receipt generated.';
|
||||
}
|
||||
|
||||
return response()->json($this->successPayload([
|
||||
@@ -194,7 +198,7 @@ class ScannerController extends BaseApiController
|
||||
|
||||
$person = [
|
||||
'id' => (int) $user->id,
|
||||
'name' => trim((string) ($user->firstname ?? '') . ' ' . (string) ($user->lastname ?? '')),
|
||||
'name' => trim((string) ($user->firstname ?? '').' '.(string) ($user->lastname ?? '')),
|
||||
'email' => $user->email,
|
||||
'role' => $roleName,
|
||||
'badgeCode' => $badgeCode,
|
||||
@@ -238,7 +242,7 @@ class ScannerController extends BaseApiController
|
||||
})
|
||||
->first();
|
||||
|
||||
if (!$user || !$this->isStaffUser((int) $user->id)) {
|
||||
if (! $user || ! $this->isStaffUser((int) $user->id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -255,7 +259,7 @@ class ScannerController extends BaseApiController
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$name = trim((string) ($role->role_name ?? ''));
|
||||
if ($name !== '' && !in_array($name, ['parent', 'guest', 'student'], true)) {
|
||||
if ($name !== '' && ! in_array($name, ['parent', 'guest', 'student'], true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -287,7 +291,7 @@ class ScannerController extends BaseApiController
|
||||
}
|
||||
|
||||
$row = $builder->orderByDesc('sc.id')->first();
|
||||
if (!$row && Schema::hasColumn('student_class', 'school_year')) {
|
||||
if (! $row && Schema::hasColumn('student_class', 'school_year')) {
|
||||
$row = DB::table('student_class as sc')
|
||||
->select('sc.class_section_id', 'cs.class_id', 'cs.class_section_name')
|
||||
->leftJoin('classSection as cs', 'cs.class_section_id', '=', 'sc.class_section_id')
|
||||
@@ -329,8 +333,9 @@ class ScannerController extends BaseApiController
|
||||
->where('school_year', $schoolYear)
|
||||
->first();
|
||||
|
||||
if (!$record) {
|
||||
if (! $record) {
|
||||
$this->addAttendanceRecord($classSectionId, $studentId, $schoolId, $newStatus, $semester, $schoolYear, $operatorId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -383,6 +388,7 @@ class ScannerController extends BaseApiController
|
||||
'updated_at' => utc_now(),
|
||||
]);
|
||||
$record->save();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -424,13 +430,13 @@ class ScannerController extends BaseApiController
|
||||
return [
|
||||
'id' => (int) ($student['id'] ?? 0),
|
||||
'schoolId' => $student['school_id'] ?? null,
|
||||
'name' => trim((string) ($student['firstname'] ?? '') . ' ' . (string) ($student['lastname'] ?? '')),
|
||||
'name' => trim((string) ($student['firstname'] ?? '').' '.(string) ($student['lastname'] ?? '')),
|
||||
'firstName' => $student['firstname'] ?? null,
|
||||
'lastName' => $student['lastname'] ?? null,
|
||||
'grade' => $student['registration_grade'] ?? null,
|
||||
'classSectionId' => isset($assignment['class_section_id']) ? (int) $assignment['class_section_id'] : null,
|
||||
'classSectionName' => $assignment['class_section_name'] ?? null,
|
||||
'badgeCode' => !empty($student['rfid_tag']) ? $student['rfid_tag'] : ($student['school_id'] ?? null),
|
||||
'badgeCode' => ! empty($student['rfid_tag']) ? $student['rfid_tag'] : ($student['school_id'] ?? null),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -527,7 +533,7 @@ class ScannerController extends BaseApiController
|
||||
$outstandingBalance = 0.0;
|
||||
$paymentStatus = 'Unknown';
|
||||
|
||||
if (!empty($payments)) {
|
||||
if (! empty($payments)) {
|
||||
$latest = $payments[0];
|
||||
$paymentStatus = (string) ($latest['status'] ?? 'Unknown');
|
||||
$outstandingBalance = (float) ($latest['balance'] ?? 0);
|
||||
@@ -550,7 +556,7 @@ class ScannerController extends BaseApiController
|
||||
{
|
||||
$issues = [];
|
||||
$payments = $summary['payments'] ?? [];
|
||||
if (!empty($payments)) {
|
||||
if (! empty($payments)) {
|
||||
$latest = $payments[0];
|
||||
$balance = (float) ($latest['balance'] ?? 0);
|
||||
$status = strtolower(trim((string) ($latest['status'] ?? '')));
|
||||
@@ -559,9 +565,9 @@ class ScannerController extends BaseApiController
|
||||
'category' => 'payment',
|
||||
'severity' => 'critical',
|
||||
'title' => 'Payment balance due',
|
||||
'detail' => '$' . number_format($balance, 2) . ' outstanding',
|
||||
'detail' => '$'.number_format($balance, 2).' outstanding',
|
||||
];
|
||||
} elseif ($status !== '' && !in_array($status, ['paid', 'full', 'full payment', 'complete', 'completed'], true)) {
|
||||
} elseif ($status !== '' && ! in_array($status, ['paid', 'full', 'full payment', 'complete', 'completed'], true)) {
|
||||
$issues[] = [
|
||||
'category' => 'payment',
|
||||
'severity' => 'warning',
|
||||
@@ -578,7 +584,7 @@ class ScannerController extends BaseApiController
|
||||
'category' => 'grades',
|
||||
'severity' => (float) $semesterScore < 60 ? 'critical' : 'warning',
|
||||
'title' => 'Grade concern',
|
||||
'detail' => 'Semester score ' . number_format((float) $semesterScore, 1),
|
||||
'detail' => 'Semester score '.number_format((float) $semesterScore, 1),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -587,7 +593,7 @@ class ScannerController extends BaseApiController
|
||||
$issues[] = [
|
||||
'category' => 'grades',
|
||||
'severity' => 'warning',
|
||||
'title' => $label . ' average below target',
|
||||
'title' => $label.' average below target',
|
||||
'detail' => number_format((float) $grading[$key], 1),
|
||||
];
|
||||
}
|
||||
@@ -599,7 +605,7 @@ class ScannerController extends BaseApiController
|
||||
'category' => 'attendance',
|
||||
'severity' => 'warning',
|
||||
'title' => 'Repeated lateness',
|
||||
'detail' => (int) $attendance['late'] . ' late attendance records',
|
||||
'detail' => (int) $attendance['late'].' late attendance records',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -647,7 +653,7 @@ class ScannerController extends BaseApiController
|
||||
{
|
||||
$label = trim(str_replace('_', ' ', $flagType));
|
||||
if ($label !== '') {
|
||||
return ucwords($label) . ' flag';
|
||||
return ucwords($label).' flag';
|
||||
}
|
||||
|
||||
return match ($category) {
|
||||
@@ -679,10 +685,10 @@ class ScannerController extends BaseApiController
|
||||
|
||||
private function createLateSlipPayload(array $student, array $assignment, array $term, \DateTimeImmutable $schoolNow, \DateTimeImmutable $lateCutoff, int $operatorId, ?string $previousStatus): array
|
||||
{
|
||||
$studentName = trim((string) ($student['firstname'] ?? '') . ' ' . (string) ($student['lastname'] ?? ''));
|
||||
$studentName = trim((string) ($student['firstname'] ?? '').' '.(string) ($student['lastname'] ?? ''));
|
||||
$grade = (string) ($student['registration_grade'] ?? $assignment['class_section_name'] ?? '');
|
||||
$cutoffLabel = $lateCutoff->format('h:i A');
|
||||
$reason = 'Arrived after ' . $cutoffLabel;
|
||||
$reason = 'Arrived after '.$cutoffLabel;
|
||||
$adminName = $this->operatorName($operatorId);
|
||||
$slip = [
|
||||
'school_year' => $term['school_year'],
|
||||
@@ -714,7 +720,7 @@ class ScannerController extends BaseApiController
|
||||
$logId = (int) ($created->id ?? 0);
|
||||
$logged = $logId > 0;
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Badge scan late slip log failed: ' . $e->getMessage());
|
||||
Log::error('Badge scan late slip log failed: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -735,15 +741,15 @@ class ScannerController extends BaseApiController
|
||||
'reason' => $reason,
|
||||
'adminName' => $adminName,
|
||||
'cutoffTime' => $cutoffLabel,
|
||||
'message' => 'Late slip receipt generated for arrival after ' . $cutoffLabel . '.',
|
||||
'message' => 'Late slip receipt generated for arrival after '.$cutoffLabel.'.',
|
||||
'text' => implode("\n", [
|
||||
'Al Rahma School at ISGL',
|
||||
'School Year: ' . $slip['school_year'],
|
||||
'Student Name: ' . $studentName,
|
||||
'Date: ' . $displayDate . ' Time In: ' . $displayTime,
|
||||
'Grade: ' . $grade,
|
||||
'Reason: ' . $reason,
|
||||
'Admin: ' . $adminName,
|
||||
'School Year: '.$slip['school_year'],
|
||||
'Student Name: '.$studentName,
|
||||
'Date: '.$displayDate.' Time In: '.$displayTime,
|
||||
'Grade: '.$grade,
|
||||
'Reason: '.$reason,
|
||||
'Admin: '.$adminName,
|
||||
]),
|
||||
];
|
||||
}
|
||||
@@ -760,18 +766,19 @@ class ScannerController extends BaseApiController
|
||||
$date = $schoolNow->format('Y-m-d');
|
||||
|
||||
foreach (['H:i:s', 'H:i', 'g:i A', 'h:i A', 'g:i a', 'h:i a'] as $format) {
|
||||
$parsed = \DateTimeImmutable::createFromFormat('!' . $format, $configured, $timezone);
|
||||
$parsed = \DateTimeImmutable::createFromFormat('!'.$format, $configured, $timezone);
|
||||
if ($parsed instanceof \DateTimeImmutable) {
|
||||
return $schoolNow->setTime((int) $parsed->format('H'), (int) $parsed->format('i'), (int) $parsed->format('s'));
|
||||
}
|
||||
}
|
||||
|
||||
$timestamp = strtotime($date . ' ' . $configured);
|
||||
$timestamp = strtotime($date.' '.$configured);
|
||||
if ($timestamp !== false) {
|
||||
return (new \DateTimeImmutable('@' . $timestamp))->setTimezone($timezone);
|
||||
return (new \DateTimeImmutable('@'.$timestamp))->setTimezone($timezone);
|
||||
}
|
||||
|
||||
Log::warning(self::LATE_CUTOFF_CONFIG_KEY . ' has invalid value "' . $configured . '"; using ' . self::DEFAULT_LATE_CUTOFF);
|
||||
Log::warning(self::LATE_CUTOFF_CONFIG_KEY.' has invalid value "'.$configured.'"; using '.self::DEFAULT_LATE_CUTOFF);
|
||||
|
||||
return $schoolNow->setTime(10, 0, 0);
|
||||
}
|
||||
|
||||
@@ -780,6 +787,7 @@ class ScannerController extends BaseApiController
|
||||
$timezone = new \DateTimeZone('America/New_York');
|
||||
try {
|
||||
$utc = new \DateTimeZone('UTC');
|
||||
|
||||
return (new \DateTimeImmutable($scannedAt, $utc))->setTimezone($timezone);
|
||||
} catch (\Throwable) {
|
||||
return new \DateTimeImmutable('now', $timezone);
|
||||
@@ -792,7 +800,7 @@ class ScannerController extends BaseApiController
|
||||
try {
|
||||
$user = User::query()->select('firstname', 'lastname', 'email')->find($operatorId);
|
||||
if ($user) {
|
||||
$name = trim((string) ($user->firstname ?? '') . ' ' . (string) ($user->lastname ?? ''));
|
||||
$name = trim((string) ($user->firstname ?? '').' '.(string) ($user->lastname ?? ''));
|
||||
if ($name !== '') {
|
||||
return $name;
|
||||
}
|
||||
@@ -800,7 +808,7 @@ class ScannerController extends BaseApiController
|
||||
return (string) ($user->email ?? '');
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Badge scan operator lookup failed: ' . $e->getMessage());
|
||||
Log::error('Badge scan operator lookup failed: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -833,7 +841,7 @@ class ScannerController extends BaseApiController
|
||||
private function logScan(string $badgeCode, ?string $personType, ?int $personId, string $action, string $status, int $operatorId, string $stationId, string $message, string $scannedAt): void
|
||||
{
|
||||
try {
|
||||
if (!Schema::hasTable('badge_scan_logs')) {
|
||||
if (! Schema::hasTable('badge_scan_logs')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -850,7 +858,7 @@ class ScannerController extends BaseApiController
|
||||
'created_at' => utc_now(),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Badge scan log failed: ' . $e->getMessage());
|
||||
Log::error('Badge scan log failed: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,9 +135,6 @@ class FinalController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -158,9 +158,6 @@ class HomeworkController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
@@ -135,9 +135,6 @@ class MidtermController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user