feat: implement barangay system phases 2-14
Complete adaptation from BukidBountyApp to Philippine barangay governance: - Barangay models: Resident, Household, HouseholdMember, Blotter, BlotterHearing, DocumentRequest, RequestPayment, RequestType, BarangayProject, BarangayBudget - Controllers: ResidentController, HouseholdController, BlotterController, BlotterHearingController, DocumentRequestController, RequestTypeController, ProjectController, BudgetController, QRPHController, AdminConsoleController, UserController, FileController, ChapterController, LoginController - Vue pages: Home, ManageResidents, ResidentProfile, ManageHouseholds, ManageBlotters, BlotterDetail, RequestDocument, ManageDocumentRequests, DocumentRequestDetail, ManageRequestTypes, ManageProjects, BudgetLedger, AdminConsole - Barangay roles: PunongBarangay, Kagawad, Secretary, Treasurer, SK, Tanod, BHW, Staff, Resident - UserPermissions matrix rewritten with barangay-specific permission mappings - VueRouteMap replaced with barangay SPA routes - UserActions enum references corrected across all controllers - Removed all market/cooperative/POS/subscription code and models
This commit is contained in:
140
app/Http/Controllers/Barangay/BlotterController.php
Normal file
140
app/Http/Controllers/Barangay/BlotterController.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Barangay;
|
||||
|
||||
use App\Enums\UserActions;
|
||||
use App\Enums\Barangay\BlotterStatus;
|
||||
use App\Http\Controllers\Helpers\Permissions\UserPermissions;
|
||||
use App\Http\Controllers\Helpers\ResponseHelper;
|
||||
use App\Models\Barangay\Blotter;
|
||||
use Hypervel\Http\Request;
|
||||
use Hypervel\Support\Facades\Auth;
|
||||
use Hypervel\Support\Facades\Validator;
|
||||
|
||||
class BlotterController
|
||||
{
|
||||
private function checkRead(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ViewBlotters);
|
||||
}
|
||||
|
||||
private function checkWrite(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ProcessBlotter);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$query = Blotter::with(['assignedOfficer'])->orderByDesc('id');
|
||||
|
||||
if ($status = $request->input('status')) $query->where('status', $status);
|
||||
if ($type = $request->input('incident_type')) $query->where('incident_type', $type);
|
||||
if ($search = $request->input('search')) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('complainant_name', 'like', "%{$search}%")
|
||||
->orWhere('respondent_name', 'like', "%{$search}%")
|
||||
->orWhere('blotter_no', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
$blotters = $query->paginate((int) $request->input('per_page', 20));
|
||||
|
||||
return response()->json(['success' => true, 'data' => $blotters]);
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$blotter = Blotter::with(['assignedOfficer', 'hearings.officer'])
|
||||
->where('hashkey', $request->input('target'))
|
||||
->first();
|
||||
|
||||
if (!$blotter) return ResponseHelper::returnError('Blotter not found', 404);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $blotter]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'complainant_name' => 'required|string|max:255',
|
||||
'complainant_contact' => 'nullable|string|max:30',
|
||||
'complainant_address' => 'nullable|string|max:500',
|
||||
'respondent_name' => 'required|string|max:255',
|
||||
'respondent_contact' => 'nullable|string|max:30',
|
||||
'respondent_address' => 'nullable|string|max:500',
|
||||
'incident_type' => 'required|in:AMICABLE,UNLAWFUL,MINOR,OTHER',
|
||||
'incident_date' => 'required|date',
|
||||
'incident_location' => 'nullable|string|max:500',
|
||||
'narrative' => 'required|string',
|
||||
'complainant_user_id' => 'nullable|integer|exists:users,id',
|
||||
'respondent_user_id' => 'nullable|integer|exists:users,id',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['success' => false, 'errors' => $validator->errors()], 422);
|
||||
}
|
||||
|
||||
$data = $validator->validated();
|
||||
$data['hashkey'] = hash('sha256', uniqid((string) now(), true));
|
||||
$data['blotter_no'] = Blotter::generateBlotterNo();
|
||||
$data['status'] = BlotterStatus::FILED;
|
||||
$data['complaint_date'] = now()->toDateString();
|
||||
$data['filed_by'] = Auth::id();
|
||||
$data['is_active'] = true;
|
||||
$data['created_by'] = Auth::id();
|
||||
$data['updated_by'] = Auth::id();
|
||||
|
||||
$blotter = Blotter::create($data);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $blotter, 'message' => 'Blotter filed successfully']);
|
||||
}
|
||||
|
||||
public function updateStatus(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$blotter = Blotter::where('hashkey', $request->input('target'))->first();
|
||||
if (!$blotter) return ResponseHelper::returnError('Blotter not found', 404);
|
||||
|
||||
$newStatus = BlotterStatus::tryFrom($request->input('status'));
|
||||
if (!$newStatus) return ResponseHelper::returnError('Invalid status', 422);
|
||||
|
||||
$data = ['status' => $newStatus, 'updated_by' => Auth::id()];
|
||||
if ($request->input('resolution')) $data['resolution'] = $request->input('resolution');
|
||||
if ($request->input('endorsed_to')) $data['endorsed_to'] = $request->input('endorsed_to');
|
||||
if ($request->input('settlement_type')) $data['settlement_type'] = $request->input('settlement_type');
|
||||
|
||||
$blotter->update($data);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $blotter, 'message' => 'Status updated']);
|
||||
}
|
||||
|
||||
public function assignOfficer(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$blotter = Blotter::where('hashkey', $request->input('target'))->first();
|
||||
if (!$blotter) return ResponseHelper::returnError('Blotter not found', 404);
|
||||
|
||||
$blotter->update([
|
||||
'assigned_officer_id' => $request->input('officer_id'),
|
||||
'updated_by' => Auth::id(),
|
||||
]);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $blotter, 'message' => 'Officer assigned']);
|
||||
}
|
||||
|
||||
public function statusOptions()
|
||||
{
|
||||
$options = collect(BlotterStatus::cases())->map(fn ($s) => ['value' => $s->value, 'label' => $s->label()]);
|
||||
return response()->json(['success' => true, 'data' => $options]);
|
||||
}
|
||||
}
|
||||
77
app/Http/Controllers/Barangay/BlotterHearingController.php
Normal file
77
app/Http/Controllers/Barangay/BlotterHearingController.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Barangay;
|
||||
|
||||
use App\Enums\UserActions;
|
||||
use App\Http\Controllers\Helpers\Permissions\UserPermissions;
|
||||
use App\Http\Controllers\Helpers\ResponseHelper;
|
||||
use App\Models\Barangay\Blotter;
|
||||
use App\Models\Barangay\BlotterHearing;
|
||||
use Hypervel\Http\Request;
|
||||
use Hypervel\Support\Facades\Auth;
|
||||
use Hypervel\Support\Facades\Validator;
|
||||
|
||||
class BlotterHearingController
|
||||
{
|
||||
private function checkWrite(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ManageBlotterHearings);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$blotter = Blotter::where('hashkey', $request->input('blotter'))->first();
|
||||
if (!$blotter) return ResponseHelper::returnError('Blotter not found', 404);
|
||||
|
||||
$hearings = BlotterHearing::with('officer')
|
||||
->where('blotter_id', $blotter->id)
|
||||
->orderBy('hearing_date')
|
||||
->get();
|
||||
|
||||
return response()->json(['success' => true, 'data' => $hearings]);
|
||||
}
|
||||
|
||||
public function schedule(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'blotter' => 'required|string',
|
||||
'hearing_date' => 'required|date',
|
||||
'officer_id' => 'nullable|integer|exists:users,id',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['success' => false, 'errors' => $validator->errors()], 422);
|
||||
}
|
||||
|
||||
$blotter = Blotter::where('hashkey', $request->input('blotter'))->first();
|
||||
if (!$blotter) return ResponseHelper::returnError('Blotter not found', 404);
|
||||
|
||||
$hearing = BlotterHearing::create([
|
||||
'blotter_id' => $blotter->id,
|
||||
'hearing_date' => $request->input('hearing_date'),
|
||||
'status' => 'SCHEDULED',
|
||||
'officer_id' => $request->input('officer_id', $blotter->assigned_officer_id),
|
||||
'notes' => $request->input('notes'),
|
||||
]);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $hearing, 'message' => 'Hearing scheduled']);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$hearing = BlotterHearing::find($request->input('hearing_id'));
|
||||
if (!$hearing) return ResponseHelper::returnError('Hearing not found', 404);
|
||||
|
||||
$data = $request->only(['status', 'notes', 'resolution', 'next_hearing_date']);
|
||||
$hearing->update($data);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $hearing, 'message' => 'Hearing updated']);
|
||||
}
|
||||
}
|
||||
126
app/Http/Controllers/Barangay/BudgetController.php
Normal file
126
app/Http/Controllers/Barangay/BudgetController.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Barangay;
|
||||
|
||||
use App\Enums\UserActions;
|
||||
use App\Http\Controllers\Helpers\Permissions\UserPermissions;
|
||||
use App\Http\Controllers\Helpers\ResponseHelper;
|
||||
use App\Models\Barangay\BarangayBudget;
|
||||
use Hypervel\Http\Request;
|
||||
use Hypervel\Support\Facades\Auth;
|
||||
use Hypervel\Support\Facades\Validator;
|
||||
|
||||
class BudgetController
|
||||
{
|
||||
private function checkRead(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ViewBarangayBudget);
|
||||
}
|
||||
|
||||
private function checkWrite(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ManageBarangayBudget);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$query = BarangayBudget::with('encodedBy')->orderByDesc('date');
|
||||
|
||||
if ($year = $request->input('year')) $query->byYear((int) $year);
|
||||
if ($category = $request->input('category')) $query->where('category', $category);
|
||||
|
||||
$entries = $query->paginate((int) $request->input('per_page', 30));
|
||||
|
||||
return response()->json(['success' => true, 'data' => $entries]);
|
||||
}
|
||||
|
||||
public function summary(Request $request)
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$year = (int) $request->input('year', date('Y'));
|
||||
|
||||
$income = BarangayBudget::byYear($year)->income()->sum('amount');
|
||||
$expense = BarangayBudget::byYear($year)->expense()->sum('amount');
|
||||
|
||||
$bySource = BarangayBudget::byYear($year)
|
||||
->selectRaw('category, source, SUM(amount) as total')
|
||||
->groupBy('category', 'source')
|
||||
->orderBy('category')
|
||||
->orderByDesc('total')
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'year' => $year,
|
||||
'income' => $income,
|
||||
'expense' => $expense,
|
||||
'balance' => $income - $expense,
|
||||
'by_source' => $bySource,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'fiscal_year' => 'required|integer|min:2020|max:2100',
|
||||
'category' => 'required|in:INCOME,EXPENSE',
|
||||
'source' => 'required|string|max:255',
|
||||
'amount' => 'required|numeric|min:0.01',
|
||||
'description' => 'nullable|string|max:500',
|
||||
'date' => 'required|date',
|
||||
'reference' => 'nullable|string|max:100',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['success' => false, 'errors' => $validator->errors()], 422);
|
||||
}
|
||||
|
||||
$data = $validator->validated();
|
||||
$data['hashkey'] = hash('sha256', uniqid((string) now(), true));
|
||||
$data['encoded_by'] = Auth::id();
|
||||
|
||||
$entry = BarangayBudget::create($data);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $entry, 'message' => 'Budget entry recorded']);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$entry = BarangayBudget::where('hashkey', $request->input('target'))->first();
|
||||
if (!$entry) return ResponseHelper::returnError('Entry not found', 404);
|
||||
|
||||
$data = $request->only(['source', 'amount', 'description', 'date', 'reference', 'category']);
|
||||
$entry->update($data);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $entry, 'message' => 'Budget entry updated']);
|
||||
}
|
||||
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$entry = BarangayBudget::where('hashkey', $request->input('target'))->first();
|
||||
if (!$entry) return ResponseHelper::returnError('Entry not found', 404);
|
||||
|
||||
$entry->delete();
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Budget entry deleted']);
|
||||
}
|
||||
|
||||
public function fiscalYears()
|
||||
{
|
||||
$years = BarangayBudget::distinct()->orderByDesc('fiscal_year')->pluck('fiscal_year');
|
||||
return response()->json(['success' => true, 'data' => $years]);
|
||||
}
|
||||
}
|
||||
210
app/Http/Controllers/Barangay/DocumentRequestController.php
Normal file
210
app/Http/Controllers/Barangay/DocumentRequestController.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Barangay;
|
||||
|
||||
use App\Enums\UserActions;
|
||||
use App\Enums\Barangay\DocumentStatus;
|
||||
use App\Enums\Barangay\PaymentStatus;
|
||||
use App\Http\Controllers\Helpers\Permissions\UserPermissions;
|
||||
use App\Http\Controllers\Helpers\ResponseHelper;
|
||||
use App\Models\Barangay\DocumentRequest;
|
||||
use App\Models\Barangay\RequestPayment;
|
||||
use App\Models\Barangay\RequestType;
|
||||
use Hypervel\Http\Request;
|
||||
use Hypervel\Support\Facades\Auth;
|
||||
use Hypervel\Support\Facades\Validator;
|
||||
|
||||
class DocumentRequestController
|
||||
{
|
||||
private function checkRead(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ViewDocumentRequests);
|
||||
}
|
||||
|
||||
private function checkWrite(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ProcessDocumentRequest);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$query = DocumentRequest::with(['requestType', 'resident', 'processedBy'])->orderByDesc('id');
|
||||
|
||||
if ($status = $request->input('status')) $query->where('status', $status);
|
||||
if ($payStatus = $request->input('payment_status')) $query->where('payment_status', $payStatus);
|
||||
if ($typeId = $request->input('request_type_id')) $query->where('request_type_id', $typeId);
|
||||
if ($search = $request->input('search')) {
|
||||
$query->where('request_no', 'like', "%{$search}%");
|
||||
}
|
||||
|
||||
$requests = $query->paginate((int) $request->input('per_page', 20));
|
||||
|
||||
return response()->json(['success' => true, 'data' => $requests]);
|
||||
}
|
||||
|
||||
public function myRequests(Request $request)
|
||||
{
|
||||
$requests = DocumentRequest::with('requestType')
|
||||
->where('resident_user_id', Auth::id())
|
||||
->orderByDesc('id')
|
||||
->get();
|
||||
|
||||
return response()->json(['success' => true, 'data' => $requests]);
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$doc = DocumentRequest::with(['requestType', 'resident', 'processedBy', 'payments'])
|
||||
->where('hashkey', $request->input('target'))
|
||||
->first();
|
||||
|
||||
if (!$doc) return ResponseHelper::returnError('Request not found', 404);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $doc]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'request_type_id' => 'required|integer|exists:barangay_request_types,id',
|
||||
'purpose' => 'required|string|max:500',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['success' => false, 'errors' => $validator->errors()], 422);
|
||||
}
|
||||
|
||||
$reqType = RequestType::findOrFail($request->input('request_type_id'));
|
||||
|
||||
$doc = DocumentRequest::create([
|
||||
'hashkey' => hash('sha256', uniqid((string) now(), true)),
|
||||
'request_no' => DocumentRequest::generateRequestNo(),
|
||||
'resident_user_id' => Auth::id(),
|
||||
'request_type_id' => $reqType->id,
|
||||
'purpose' => $request->input('purpose'),
|
||||
'fee_amount' => $reqType->base_fee,
|
||||
'payment_status' => PaymentStatus::PENDING,
|
||||
'status' => $reqType->base_fee > 0 ? DocumentStatus::PENDING_PAYMENT : DocumentStatus::PAID,
|
||||
'requested_by' => Auth::id(),
|
||||
]);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $doc, 'message' => 'Document request submitted']);
|
||||
}
|
||||
|
||||
public function updateStatus(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$doc = DocumentRequest::where('hashkey', $request->input('target'))->first();
|
||||
if (!$doc) return ResponseHelper::returnError('Request not found', 404);
|
||||
|
||||
$newStatus = DocumentStatus::tryFrom($request->input('status'));
|
||||
if (!$newStatus) return ResponseHelper::returnError('Invalid status', 422);
|
||||
|
||||
$data = [
|
||||
'status' => $newStatus,
|
||||
'processed_by' => Auth::id(),
|
||||
];
|
||||
|
||||
if ($newStatus === DocumentStatus::CLAIMED) {
|
||||
$data['claimed_at'] = now();
|
||||
}
|
||||
|
||||
if ($request->input('notes')) $data['notes'] = $request->input('notes');
|
||||
|
||||
$doc->update($data);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $doc, 'message' => 'Status updated to ' . $newStatus->label()]);
|
||||
}
|
||||
|
||||
public function confirmPayment(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$doc = DocumentRequest::where('hashkey', $request->input('target'))->first();
|
||||
if (!$doc) return ResponseHelper::returnError('Request not found', 404);
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'method' => 'required|in:CASH,GCASH,QRPH,BANK,WAIVED',
|
||||
'reference' => 'nullable|string|max:100',
|
||||
'amount' => 'nullable|numeric|min:0',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['success' => false, 'errors' => $validator->errors()], 422);
|
||||
}
|
||||
|
||||
$method = $request->input('method');
|
||||
$amount = $request->input('amount', $doc->fee_amount);
|
||||
|
||||
RequestPayment::create([
|
||||
'request_id' => $doc->id,
|
||||
'amount' => $amount,
|
||||
'method' => $method,
|
||||
'reference' => $request->input('reference'),
|
||||
'paid_at' => now(),
|
||||
'verified_by' => Auth::id(),
|
||||
]);
|
||||
|
||||
$doc->update([
|
||||
'payment_status' => PaymentStatus::PAID,
|
||||
'payment_method' => $method,
|
||||
'payment_ref' => $request->input('reference'),
|
||||
'status' => DocumentStatus::PROCESSING,
|
||||
'processed_by' => Auth::id(),
|
||||
]);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $doc, 'message' => 'Payment confirmed']);
|
||||
}
|
||||
|
||||
public function markReady(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$doc = DocumentRequest::where('hashkey', $request->input('target'))->first();
|
||||
if (!$doc) return ResponseHelper::returnError('Request not found', 404);
|
||||
|
||||
$doc->update(['status' => DocumentStatus::READY, 'processed_by' => Auth::id()]);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $doc, 'message' => 'Marked as ready for pickup']);
|
||||
}
|
||||
|
||||
public function markClaimed(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$doc = DocumentRequest::where('hashkey', $request->input('target'))->first();
|
||||
if (!$doc) return ResponseHelper::returnError('Request not found', 404);
|
||||
|
||||
$doc->update([
|
||||
'status' => DocumentStatus::CLAIMED,
|
||||
'claimed_at' => now(),
|
||||
]);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $doc, 'message' => 'Document marked as claimed']);
|
||||
}
|
||||
|
||||
public function cancel(Request $request)
|
||||
{
|
||||
$doc = DocumentRequest::where('hashkey', $request->input('target'))->first();
|
||||
if (!$doc) return ResponseHelper::returnError('Request not found', 404);
|
||||
|
||||
if ($doc->resident_user_id !== Auth::id() && !$this->checkWrite()) {
|
||||
return ResponseHelper::returnUnauthorized();
|
||||
}
|
||||
|
||||
if (in_array($doc->status, [DocumentStatus::CLAIMED, DocumentStatus::CANCELLED])) {
|
||||
return ResponseHelper::returnError('Cannot cancel this request', 422);
|
||||
}
|
||||
|
||||
$doc->update(['status' => DocumentStatus::CANCELLED]);
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Request cancelled']);
|
||||
}
|
||||
}
|
||||
164
app/Http/Controllers/Barangay/HouseholdController.php
Normal file
164
app/Http/Controllers/Barangay/HouseholdController.php
Normal file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Barangay;
|
||||
|
||||
use App\Enums\UserActions;
|
||||
use App\Http\Controllers\Helpers\Permissions\UserPermissions;
|
||||
use App\Http\Controllers\Helpers\ResponseHelper;
|
||||
use App\Models\Barangay\Household;
|
||||
use App\Models\Barangay\HouseholdMember;
|
||||
use App\Models\Barangay\Resident;
|
||||
use Hypervel\Http\Request;
|
||||
use Hypervel\Support\Facades\Auth;
|
||||
use Hypervel\Support\Facades\Validator;
|
||||
|
||||
class HouseholdController
|
||||
{
|
||||
private function checkRead(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ViewResidents);
|
||||
}
|
||||
|
||||
private function checkWrite(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ManageResidents);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$query = Household::with(['head', 'members.resident'])->orderByDesc('id');
|
||||
|
||||
if ($purok = $request->input('purok')) $query->where('purok', $purok);
|
||||
if ($request->input('active_only')) $query->active();
|
||||
|
||||
$households = $query->paginate((int) $request->input('per_page', 20));
|
||||
|
||||
return response()->json(['success' => true, 'data' => $households]);
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$household = Household::with(['head', 'members.resident'])
|
||||
->where('hashkey', $request->input('target'))
|
||||
->first();
|
||||
|
||||
if (!$household) return ResponseHelper::returnError('Household not found', 404);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $household]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'head_resident_id' => 'required|integer|exists:barangay_residents,id',
|
||||
'address' => 'required|string|max:500',
|
||||
'purok' => 'nullable|string|max:100',
|
||||
'barangay' => 'nullable|string|max:100',
|
||||
'city' => 'nullable|string|max:100',
|
||||
'province' => 'nullable|string|max:100',
|
||||
'ownership_type' => 'nullable|in:OWNED,RENTED,SHARED',
|
||||
'monthly_rental' => 'nullable|numeric|min:0',
|
||||
'has_electricity' => 'nullable|boolean',
|
||||
'has_water' => 'nullable|boolean',
|
||||
'housing_material' => 'nullable|string|max:100',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['success' => false, 'errors' => $validator->errors()], 422);
|
||||
}
|
||||
|
||||
$data = $validator->validated();
|
||||
$year = date('Y');
|
||||
$count = Household::whereYear('created_at', $year)->count() + 1;
|
||||
$data['household_no'] = sprintf('HH-%s-%04d', $year, $count);
|
||||
$data['hashkey'] = hash('sha256', uniqid((string) now(), true));
|
||||
$data['member_count'] = 1;
|
||||
$data['is_active'] = true;
|
||||
$data['created_by'] = Auth::id();
|
||||
$data['updated_by'] = Auth::id();
|
||||
|
||||
$household = Household::create($data);
|
||||
|
||||
// Add head as first member
|
||||
HouseholdMember::create([
|
||||
'household_id' => $household->id,
|
||||
'resident_id' => $data['head_resident_id'],
|
||||
'relationship_to_head' => 'HEAD',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $household, 'message' => 'Household created']);
|
||||
}
|
||||
|
||||
public function addMember(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'target' => 'required|string',
|
||||
'resident_id' => 'required|integer|exists:barangay_residents,id',
|
||||
'relationship_to_head' => 'required|string|max:100',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['success' => false, 'errors' => $validator->errors()], 422);
|
||||
}
|
||||
|
||||
$household = Household::where('hashkey', $request->input('target'))->first();
|
||||
if (!$household) return ResponseHelper::returnError('Household not found', 404);
|
||||
|
||||
$existing = HouseholdMember::where('household_id', $household->id)
|
||||
->where('resident_id', $request->input('resident_id'))
|
||||
->first();
|
||||
if ($existing) return ResponseHelper::returnError('Resident is already a member', 422);
|
||||
|
||||
$member = HouseholdMember::create([
|
||||
'household_id' => $household->id,
|
||||
'resident_id' => $request->input('resident_id'),
|
||||
'relationship_to_head' => $request->input('relationship_to_head'),
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$household->increment('member_count');
|
||||
|
||||
return response()->json(['success' => true, 'data' => $member, 'message' => 'Member added']);
|
||||
}
|
||||
|
||||
public function removeMember(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$household = Household::where('hashkey', $request->input('target'))->first();
|
||||
if (!$household) return ResponseHelper::returnError('Household not found', 404);
|
||||
|
||||
$deleted = HouseholdMember::where('household_id', $household->id)
|
||||
->where('resident_id', $request->input('resident_id'))
|
||||
->delete();
|
||||
|
||||
if ($deleted) $household->decrement('member_count');
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Member removed']);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$household = Household::where('hashkey', $request->input('target'))->first();
|
||||
if (!$household) return ResponseHelper::returnError('Household not found', 404);
|
||||
|
||||
$data = $request->except(['target', 'hashkey', 'household_no', 'created_by']);
|
||||
$data['updated_by'] = Auth::id();
|
||||
$household->update($data);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $household, 'message' => 'Household updated']);
|
||||
}
|
||||
}
|
||||
135
app/Http/Controllers/Barangay/ProjectController.php
Normal file
135
app/Http/Controllers/Barangay/ProjectController.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Barangay;
|
||||
|
||||
use App\Enums\UserActions;
|
||||
use App\Http\Controllers\Helpers\Permissions\UserPermissions;
|
||||
use App\Http\Controllers\Helpers\ResponseHelper;
|
||||
use App\Models\Barangay\BarangayProject;
|
||||
use Hypervel\Http\Request;
|
||||
use Hypervel\Support\Facades\Auth;
|
||||
use Hypervel\Support\Facades\Validator;
|
||||
|
||||
class ProjectController
|
||||
{
|
||||
private function checkRead(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ViewBarangayProjects);
|
||||
}
|
||||
|
||||
private function checkWrite(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ManageBarangayProjects);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$query = BarangayProject::orderByDesc('id');
|
||||
|
||||
if ($status = $request->input('status')) $query->where('status', $status);
|
||||
if ($type = $request->input('type')) $query->where('type', $type);
|
||||
if ($year = $request->input('year')) {
|
||||
$query->whereYear('start_date', $year);
|
||||
}
|
||||
|
||||
$projects = $query->paginate((int) $request->input('per_page', 20));
|
||||
|
||||
return response()->json(['success' => true, 'data' => $projects]);
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$project = BarangayProject::where('hashkey', $request->input('target'))->first();
|
||||
if (!$project) return ResponseHelper::returnError('Project not found', 404);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $project]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'project_name' => 'required|string|max:500',
|
||||
'description' => 'nullable|string',
|
||||
'type' => 'required|in:INFRASTRUCTURE,LIVELIHOOD,HEALTH,EDUCATION,ENVIRONMENT,OTHERS',
|
||||
'budget' => 'required|numeric|min:0',
|
||||
'fund_source' => 'required|in:GENERAL_FUND,SK,PROVINCE,NATIONAL,OTHERS',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'nullable|date|after:start_date',
|
||||
'implementing_office' => 'nullable|string|max:255',
|
||||
'contractor' => 'nullable|string|max:255',
|
||||
'location' => 'nullable|string|max:500',
|
||||
'beneficiaries_count' => 'nullable|integer|min:0',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['success' => false, 'errors' => $validator->errors()], 422);
|
||||
}
|
||||
|
||||
$data = $validator->validated();
|
||||
$data['hashkey'] = hash('sha256', uniqid((string) now(), true));
|
||||
$data['status'] = 'PLANNED';
|
||||
$data['created_by'] = Auth::id();
|
||||
$data['updated_by'] = Auth::id();
|
||||
|
||||
$project = BarangayProject::create($data);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $project, 'message' => 'Project created']);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$project = BarangayProject::where('hashkey', $request->input('target'))->first();
|
||||
if (!$project) return ResponseHelper::returnError('Project not found', 404);
|
||||
|
||||
$data = $request->except(['target', 'hashkey', 'created_by']);
|
||||
$data['updated_by'] = Auth::id();
|
||||
$project->update($data);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $project, 'message' => 'Project updated']);
|
||||
}
|
||||
|
||||
public function updateStatus(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$project = BarangayProject::where('hashkey', $request->input('target'))->first();
|
||||
if (!$project) return ResponseHelper::returnError('Project not found', 404);
|
||||
|
||||
$validStatuses = ['PLANNED', 'ONGOING', 'COMPLETED', 'SUSPENDED', 'CANCELLED'];
|
||||
$status = $request->input('status');
|
||||
if (!in_array($status, $validStatuses)) {
|
||||
return ResponseHelper::returnError('Invalid status', 422);
|
||||
}
|
||||
|
||||
$project->update(['status' => $status, 'updated_by' => Auth::id()]);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $project, 'message' => "Project status set to {$status}"]);
|
||||
}
|
||||
|
||||
public function summary()
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$summary = [
|
||||
'total' => BarangayProject::count(),
|
||||
'planned' => BarangayProject::where('status', 'PLANNED')->count(),
|
||||
'ongoing' => BarangayProject::where('status', 'ONGOING')->count(),
|
||||
'completed' => BarangayProject::where('status', 'COMPLETED')->count(),
|
||||
'total_budget' => BarangayProject::sum('budget'),
|
||||
'by_type' => BarangayProject::selectRaw('type, count(*) as count, sum(budget) as budget')
|
||||
->groupBy('type')->get(),
|
||||
];
|
||||
|
||||
return response()->json(['success' => true, 'data' => $summary]);
|
||||
}
|
||||
}
|
||||
95
app/Http/Controllers/Barangay/RequestTypeController.php
Normal file
95
app/Http/Controllers/Barangay/RequestTypeController.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Barangay;
|
||||
|
||||
use App\Enums\UserActions;
|
||||
use App\Http\Controllers\Helpers\Permissions\UserPermissions;
|
||||
use App\Http\Controllers\Helpers\ResponseHelper;
|
||||
use App\Models\Barangay\RequestType;
|
||||
use Hypervel\Http\Request;
|
||||
use Hypervel\Support\Facades\Auth;
|
||||
use Hypervel\Support\Facades\Validator;
|
||||
|
||||
class RequestTypeController
|
||||
{
|
||||
private function checkWrite(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ManageRequestTypes);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$types = RequestType::orderBy('name')->get();
|
||||
return response()->json(['success' => true, 'data' => $types]);
|
||||
}
|
||||
|
||||
public function active()
|
||||
{
|
||||
$types = RequestType::active()->orderBy('name')->get();
|
||||
return response()->json(['success' => true, 'data' => $types]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required|string|max:255',
|
||||
'code' => 'required|string|max:50|unique:barangay_request_types,code',
|
||||
'description' => 'nullable|string',
|
||||
'base_fee' => 'required|numeric|min:0',
|
||||
'processing_days' => 'required|integer|min:1',
|
||||
'requires_clearance' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['success' => false, 'errors' => $validator->errors()], 422);
|
||||
}
|
||||
|
||||
$data = $validator->validated();
|
||||
$data['is_active'] = true;
|
||||
$data['code'] = strtoupper($data['code']);
|
||||
|
||||
$type = RequestType::create($data);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $type, 'message' => 'Request type created']);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$type = RequestType::where('code', $request->input('target'))->first();
|
||||
if (!$type) return ResponseHelper::returnError('Request type not found', 404);
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'nullable|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'base_fee' => 'nullable|numeric|min:0',
|
||||
'processing_days' => 'nullable|integer|min:1',
|
||||
'requires_clearance' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['success' => false, 'errors' => $validator->errors()], 422);
|
||||
}
|
||||
|
||||
$type->update($validator->validated());
|
||||
|
||||
return response()->json(['success' => true, 'data' => $type, 'message' => 'Request type updated']);
|
||||
}
|
||||
|
||||
public function toggleActive(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$type = RequestType::where('code', $request->input('target'))->first();
|
||||
if (!$type) return ResponseHelper::returnError('Request type not found', 404);
|
||||
|
||||
$type->update(['is_active' => !$type->is_active]);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $type]);
|
||||
}
|
||||
}
|
||||
159
app/Http/Controllers/Barangay/ResidentController.php
Normal file
159
app/Http/Controllers/Barangay/ResidentController.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Barangay;
|
||||
|
||||
use App\Enums\UserActions;
|
||||
use App\Http\Controllers\Helpers\Permissions\UserPermissions;
|
||||
use App\Http\Controllers\Helpers\ResponseHelper;
|
||||
use App\Models\Barangay\Resident;
|
||||
use App\Models\User;
|
||||
use Hypervel\Http\Request;
|
||||
use Hypervel\Support\Facades\Auth;
|
||||
use Hypervel\Support\Facades\Validator;
|
||||
|
||||
class ResidentController
|
||||
{
|
||||
private function checkRead(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ViewResidents);
|
||||
}
|
||||
|
||||
private function checkWrite(): bool
|
||||
{
|
||||
return UserPermissions::isActionPermitted(Auth::user()->acct_type, UserActions::ManageResidents);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$query = Resident::with('user')->orderByDesc('id');
|
||||
|
||||
if ($search = $request->input('search')) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('firstname', 'like', "%{$search}%")
|
||||
->orWhere('lastname', 'like', "%{$search}%")
|
||||
->orWhere('middlename', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
if ($purok = $request->input('purok')) $query->where('purok', $purok);
|
||||
if ($request->input('active_only')) $query->active();
|
||||
|
||||
$residents = $query->paginate((int) $request->input('per_page', 20));
|
||||
|
||||
return response()->json(['success' => true, 'data' => $residents]);
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$resident = Resident::with(['user', 'householdMemberships.household'])
|
||||
->where('hashkey', $request->input('target'))
|
||||
->first();
|
||||
|
||||
if (!$resident) return ResponseHelper::returnError('Resident not found', 404);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $resident]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'firstname' => 'required|string|max:100',
|
||||
'lastname' => 'required|string|max:100',
|
||||
'middlename' => 'nullable|string|max:100',
|
||||
'suffix' => 'nullable|string|max:20',
|
||||
'dob' => 'required|date',
|
||||
'birthplace' => 'nullable|string|max:255',
|
||||
'gender' => 'required|in:MALE,FEMALE,OTHER',
|
||||
'civil_status' => 'required|in:SINGLE,MARRIED,WIDOWED,SEPARATED,ANNULLED',
|
||||
'citizenship' => 'nullable|string|max:100',
|
||||
'religion' => 'nullable|string|max:100',
|
||||
'occupation' => 'nullable|string|max:255',
|
||||
'monthly_income' => 'nullable|numeric|min:0',
|
||||
'blood_type' => 'nullable|string|max:5',
|
||||
'voter_status' => 'nullable|boolean',
|
||||
'head_of_household' => 'nullable|boolean',
|
||||
'purok' => 'nullable|string|max:100',
|
||||
'street' => 'nullable|string|max:255',
|
||||
'barangay' => 'nullable|string|max:100',
|
||||
'city' => 'nullable|string|max:100',
|
||||
'province' => 'nullable|string|max:100',
|
||||
'region' => 'nullable|string|max:100',
|
||||
'philhealth_id' => 'nullable|string|max:50',
|
||||
'sss_id' => 'nullable|string|max:50',
|
||||
'gsis_id' => 'nullable|string|max:50',
|
||||
'tin' => 'nullable|string|max:50',
|
||||
'emergency_contact_name' => 'nullable|string|max:255',
|
||||
'emergency_contact_phone' => 'nullable|string|max:30',
|
||||
'emergency_contact_address' => 'nullable|string|max:255',
|
||||
'user_id' => 'nullable|integer|exists:users,id',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['success' => false, 'errors' => $validator->errors()], 422);
|
||||
}
|
||||
|
||||
$data = $validator->validated();
|
||||
$data['hashkey'] = hash('sha256', uniqid((string) now(), true));
|
||||
$data['is_active'] = true;
|
||||
$data['created_by'] = Auth::id();
|
||||
$data['updated_by'] = Auth::id();
|
||||
|
||||
$resident = Resident::create($data);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $resident, 'message' => 'Resident created']);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$resident = Resident::where('hashkey', $request->input('target'))->first();
|
||||
if (!$resident) return ResponseHelper::returnError('Resident not found', 404);
|
||||
|
||||
$data = $request->except(['target', 'hashkey', 'created_by']);
|
||||
$data['updated_by'] = Auth::id();
|
||||
$resident->update($data);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $resident, 'message' => 'Resident updated']);
|
||||
}
|
||||
|
||||
public function setActive(Request $request)
|
||||
{
|
||||
if (!$this->checkWrite()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$resident = Resident::where('hashkey', $request->input('target'))->first();
|
||||
if (!$resident) return ResponseHelper::returnError('Resident not found', 404);
|
||||
|
||||
$resident->update(['is_active' => (bool) $request->input('active', true)]);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $resident]);
|
||||
}
|
||||
|
||||
public function search(Request $request)
|
||||
{
|
||||
if (!$this->checkRead()) return ResponseHelper::returnUnauthorized();
|
||||
|
||||
$term = $request->input('q', '');
|
||||
$residents = Resident::where(function ($q) use ($term) {
|
||||
$q->where('firstname', 'like', "%{$term}%")
|
||||
->orWhere('lastname', 'like', "%{$term}%")
|
||||
->orWhere('middlename', 'like', "%{$term}%");
|
||||
})->active()->limit(20)->get(['id', 'hashkey', 'firstname', 'middlename', 'lastname', 'suffix', 'purok', 'dob']);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $residents]);
|
||||
}
|
||||
|
||||
public function puroks()
|
||||
{
|
||||
$puroks = Resident::distinct()->orderBy('purok')->pluck('purok')->filter()->values();
|
||||
return response()->json(['success' => true, 'data' => $puroks]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user