DONE: centralize theme color, interactive dashboard, increase winner result, refer TODO
This commit is contained in:
@@ -37,10 +37,65 @@ class SummaryController extends Controller
|
||||
|
||||
$rows = $q->get();
|
||||
|
||||
$defaultCashCents = 30000;
|
||||
$defaultBankCents = 15000;
|
||||
|
||||
$outstandingCash = (int) DB::table('voter as v')
|
||||
->where('v.election_id', $electionId)
|
||||
->where('v.kehadiran', 1)
|
||||
->where(function ($outer) use ($electionId) {
|
||||
$outer->whereExists(function ($sub) use ($electionId) {
|
||||
$sub->select(DB::raw(1))
|
||||
->from('result as r')
|
||||
->whereColumn('r.voter_id', 'v.id')
|
||||
->where('r.election_id', $electionId);
|
||||
})->orWhere(function ($q) {
|
||||
$q->whereNotNull('v.fizikal_registration_verified_at')
|
||||
->whereRaw('COALESCE(v.saham, 0) < 500');
|
||||
});
|
||||
})
|
||||
->whereNotExists(function ($sub) use ($electionId) {
|
||||
$sub->select(DB::raw(1))
|
||||
->from('allowance_payouts as ap')
|
||||
->whereColumn('ap.voter_id', 'v.id')
|
||||
->where('ap.election_id', $electionId)
|
||||
->where('ap.method', 'cash')
|
||||
->where('ap.status', 'paid');
|
||||
})
|
||||
->count();
|
||||
|
||||
$outstandingBank = (int) DB::table('voter as v')
|
||||
->where('v.election_id', $electionId)
|
||||
->where('v.kehadiran', 2)
|
||||
->whereExists(function ($sub) use ($electionId) {
|
||||
$sub->select(DB::raw(1))
|
||||
->from('result as r')
|
||||
->whereColumn('r.voter_id', 'v.id')
|
||||
->where('r.election_id', $electionId);
|
||||
})
|
||||
->whereNotExists(function ($sub) use ($electionId) {
|
||||
$sub->select(DB::raw(1))
|
||||
->from('allowance_payouts as ap')
|
||||
->whereColumn('ap.voter_id', 'v.id')
|
||||
->where('ap.election_id', $electionId)
|
||||
->where('ap.method', 'bank')
|
||||
->where('ap.status', 'paid');
|
||||
})
|
||||
->count();
|
||||
|
||||
$outstandingAllowanceCents = ($outstandingCash * $defaultCashCents) + ($outstandingBank * $defaultBankCents);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'election_id' => $electionId,
|
||||
'rows' => $rows,
|
||||
'outstanding_allowance' => [
|
||||
'cents' => $outstandingAllowanceCents,
|
||||
'cash_count' => $outstandingCash,
|
||||
'bank_count' => $outstandingBank,
|
||||
'default_cash_cents' => $defaultCashCents,
|
||||
'default_bank_cents' => $defaultBankCents,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API\v1\Election;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Voter;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AttendanceSummaryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Aggregate attendance for a specific election (by primary key), for admin reporting.
|
||||
* Kehadiran: null/0 = belum ditetapkan, 1 = fizikal, 2 = maya.
|
||||
*/
|
||||
public function __invoke($id)
|
||||
{
|
||||
$electionId = (int) $id;
|
||||
|
||||
$row = Voter::query()
|
||||
->where('election_id', $electionId)
|
||||
->selectRaw('COUNT(*) as total_registered')
|
||||
->selectRaw('COALESCE(SUM(CASE WHEN kehadiran IS NULL OR kehadiran = 0 THEN 1 ELSE 0 END), 0) as unset')
|
||||
->selectRaw('COALESCE(SUM(CASE WHEN kehadiran = 1 THEN 1 ELSE 0 END), 0) as fizikal')
|
||||
->selectRaw('COALESCE(SUM(CASE WHEN kehadiran = 2 THEN 1 ELSE 0 END), 0) as maya')
|
||||
->selectRaw('COALESCE(SUM(CASE WHEN kehadiran IN (1, 2) THEN 1 ELSE 0 END), 0) as marked_present')
|
||||
->selectRaw('COALESCE(SUM(CASE WHEN kehadiran = 1 AND fizikal_registration_verified_at IS NULL THEN 1 ELSE 0 END), 0) as fizikal_reg_pending')
|
||||
->selectRaw('COALESCE(SUM(CASE WHEN kehadiran = 1 AND fizikal_registration_verified_at IS NOT NULL THEN 1 ELSE 0 END), 0) as fizikal_reg_verified')
|
||||
->first();
|
||||
|
||||
$total = (int) ($row ? $row->total_registered : 0);
|
||||
$marked = (int) ($row ? $row->marked_present : 0);
|
||||
|
||||
$votersWhoVoted = (int) DB::table('result')
|
||||
->where('election_id', $electionId)
|
||||
->select(DB::raw('COUNT(DISTINCT voter_id) as c'))
|
||||
->value('c');
|
||||
|
||||
return response()->json([
|
||||
'election_id' => $electionId,
|
||||
'total_registered' => $total,
|
||||
'unset' => (int) ($row ? $row->unset : 0),
|
||||
'fizikal' => (int) ($row ? $row->fizikal : 0),
|
||||
'maya' => (int) ($row ? $row->maya : 0),
|
||||
'marked_present' => $marked,
|
||||
'attendance_rate' => $total > 0 ? round(($marked / $total) * 100, 2) : 0.0,
|
||||
'fizikal_registration_pending' => (int) ($row ? $row->fizikal_reg_pending : 0),
|
||||
'fizikal_registration_verified' => (int) ($row ? $row->fizikal_reg_verified : 0),
|
||||
'voters_who_voted' => $votersWhoVoted,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API\v1\Election;
|
||||
|
||||
use App\Election;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Util;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RegisterNextSessionController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$this->validateRequest($request);
|
||||
|
||||
if (Util::getElectionStatus() !== 3) {
|
||||
return response()->json([
|
||||
'status' => 'failed',
|
||||
'message' => 'Daftar sesi baharu hanya tersedia selepas undian telah tamat.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
Util::ensureDraftElectionAfterCompletedCycle();
|
||||
|
||||
$election = Election::find(Util::getCurrentElection());
|
||||
if ($request->filled('name')) {
|
||||
$election->update(['name' => $request->name]);
|
||||
}
|
||||
|
||||
$user = $request->user();
|
||||
activity()
|
||||
->withProperties([
|
||||
'election_id' => (int) $election->id,
|
||||
'election_name' => (string) $request->input('name', ''),
|
||||
'registered_by_admin_id' => $user ? (int) $user->id : null,
|
||||
'registered_by_admin_email' => $user ? $user->email : null,
|
||||
'ip' => $request->ip(),
|
||||
'user_agent' => $request->userAgent(),
|
||||
])
|
||||
->log('election register next session');
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Sesi mengundi baharu didaftarkan. Sila lengkapkan maklumat calon sebelum memulakan undian.',
|
||||
'election' => $election->fresh(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function validateRequest($request)
|
||||
{
|
||||
$id = Auth::id();
|
||||
$this->validate($request, [
|
||||
'password' => 'required|password:users,password,' . $id,
|
||||
'name' => 'nullable|string|max:60',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ class StartController extends Controller
|
||||
{
|
||||
$this->validateRequest($request);
|
||||
|
||||
Util::ensureDraftElectionAfterCompletedCycle();
|
||||
|
||||
if ($this->hasNoNominee())
|
||||
return response()->json([
|
||||
'status' => 'failed',
|
||||
|
||||
@@ -48,8 +48,7 @@ class StopController extends Controller
|
||||
'status'=>3,
|
||||
'name'=>$request->name,
|
||||
'end'=>date('Y-m-d H:i:s')
|
||||
]);
|
||||
Election::create();
|
||||
]);
|
||||
}
|
||||
|
||||
private function validateRequest($request)
|
||||
|
||||
@@ -13,6 +13,7 @@ class AddController extends Controller
|
||||
|
||||
public function __invoke (Request $request)
|
||||
{
|
||||
Util::ensureDraftElectionAfterCompletedCycle();
|
||||
$this->validateRequest($request);
|
||||
$nominee = $this->insertNominee($request);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ class AddController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
Util::ensureDraftElectionAfterCompletedCycle();
|
||||
$this->validateRequest($request);
|
||||
$this->insertPartylist($request);
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Util;
|
||||
use App\Election;
|
||||
use App\Position;
|
||||
|
||||
class AddPositionController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
Util::ensureDraftElectionAfterCompletedCycle();
|
||||
$this->validateRequest($request);
|
||||
$this->insertPosition($request);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ class AddController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
Util::ensureDraftElectionAfterCompletedCycle();
|
||||
$this->validateRequest($request);
|
||||
$voter = $this->insertVoter($request);
|
||||
|
||||
|
||||
@@ -113,6 +113,47 @@ class GetController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
// Vote status: 1 = has voted, 0 = has not voted (for this election)
|
||||
$hasVoted = request('has_voted');
|
||||
if ($hasVoted !== null && $hasVoted !== '') {
|
||||
$hv = (string) $hasVoted;
|
||||
if ($hv === '1' || $hv === 'true' || $hv === 'yes') {
|
||||
$q->whereExists(function ($sub) use ($electionId) {
|
||||
$sub->from('result')
|
||||
->whereColumn('result.voter_id', 'voter.id')
|
||||
->where('result.election_id', $electionId);
|
||||
});
|
||||
} elseif ($hv === '0' || $hv === 'false' || $hv === 'no') {
|
||||
$q->whereNotExists(function ($sub) use ($electionId) {
|
||||
$sub->from('result')
|
||||
->whereColumn('result.voter_id', 'voter.id')
|
||||
->where('result.election_id', $electionId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Cash allowance payment status (matches admin "Status" column: cash_paid_at)
|
||||
$cashStatus = request('cash_status');
|
||||
if ($cashStatus !== null && $cashStatus !== '') {
|
||||
if ($cashStatus === 'paid') {
|
||||
$q->whereExists(function ($sub) use ($electionId) {
|
||||
$sub->from('allowance_payouts')
|
||||
->whereColumn('allowance_payouts.voter_id', 'voter.id')
|
||||
->where('allowance_payouts.election_id', $electionId)
|
||||
->where('allowance_payouts.method', 'cash')
|
||||
->where('allowance_payouts.status', 'paid');
|
||||
});
|
||||
} elseif ($cashStatus === 'unpaid') {
|
||||
$q->whereNotExists(function ($sub) use ($electionId) {
|
||||
$sub->from('allowance_payouts')
|
||||
->whereColumn('allowance_payouts.voter_id', 'voter.id')
|
||||
->where('allowance_payouts.election_id', $electionId)
|
||||
->where('allowance_payouts.method', 'cash')
|
||||
->where('allowance_payouts.status', 'paid');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Return all voters with pagination
|
||||
return $q->paginate(1000);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class SyncApplicableVotersController extends Controller
|
||||
'selected_no_kp.*' => 'nullable|string|max:60',
|
||||
]);
|
||||
|
||||
Util::ensureDraftElectionAfterCompletedCycle();
|
||||
$electionId = Util::getCurrentElection();
|
||||
$selected = collect($request->input('selected_no_kp', []))
|
||||
->map(function ($v) {
|
||||
|
||||
Reference in New Issue
Block a user