- Created AdminBarangayController to strictly scope barangay management to LGU boundaries - Created AdminTenantController for LGU admins to fetch their own tenant configurations - Updated sidebar to expose Barangays to LGU admins under the Areas menu - Updated frontend UI to hide the City selection dropdown from LGU admins and dynamically inject their city_municipality_id - Handled form validation issues caused by hidden required fields - Implemented LGU dashboard routes and views - Enforced 2 free QR code allocations on resident signup
58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin;
|
|
|
|
use App\Http\Controllers\Api\V1\ApiController;
|
|
use App\Models\Household;
|
|
use App\Models\PartnerStore;
|
|
use App\Models\QrCodeBatch;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class DashboardController extends ApiController
|
|
{
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$tenantId = $request->user()->tenant_id;
|
|
|
|
$pendingHouseholdsCount = Household::where('tenant_id', $tenantId)
|
|
->where('verification_status', 'pending')
|
|
->count();
|
|
|
|
$activeHouseholdsCount = Household::where('tenant_id', $tenantId)
|
|
->where('verification_status', 'approved')
|
|
->count();
|
|
|
|
$pendingStoresCount = PartnerStore::where('tenant_id', $tenantId)
|
|
->where('status', 'pending_kyc')
|
|
->count();
|
|
|
|
$totalQrBatches = QrCodeBatch::where('tenant_id', $tenantId)->count();
|
|
|
|
$recentPendingHouseholds = Household::where('tenant_id', $tenantId)
|
|
->where('verification_status', 'pending')
|
|
->with(['head', 'barangay'])
|
|
->latest()
|
|
->take(5)
|
|
->get()
|
|
->map(function ($h) {
|
|
return [
|
|
'id' => $h->uuid,
|
|
'full_name' => $h->head ? $h->head->full_name : '—',
|
|
'address_line' => $h->address_line,
|
|
'has_proof' => (bool)$h->proof_of_residency_uploaded,
|
|
];
|
|
});
|
|
|
|
return $this->ok([
|
|
'metrics' => [
|
|
'pending_households' => $pendingHouseholdsCount,
|
|
'active_households' => $activeHouseholdsCount,
|
|
'pending_stores' => $pendingStoresCount,
|
|
'total_qr_batches' => $totalQrBatches,
|
|
],
|
|
'recent_pending_households' => $recentPendingHouseholds,
|
|
]);
|
|
}
|
|
}
|