DONE: settle disable vote for voter with saham under 500, fix issue on...

This commit is contained in:
ISMAIL MASSERAN
2026-04-19 07:52:11 +00:00
parent ed369aec46
commit f5b831a857
9 changed files with 285 additions and 24 deletions
@@ -52,9 +52,21 @@ class PayoutController extends Controller
], 422);
}
// Enforce "must have voted" (officer check)
$hasVoted = Result::where('election_id', $electionId)->where('voter_id', $voterId)->exists();
if (!$hasVoted) {
// Tunai: normally must have voted; exception — fizikal hadir & layak mesyuarat tetapi tidak dibenarkan
// mengundi kerana saham < RM500 (same rule as claim code).
$kehadiran = (int) $voter->kehadiran;
$saham = (float) $voter->saham;
$canVoteBySaham = $saham >= 500.0;
$canProceedToVote = $kehadiran !== 0
&& ($kehadiran !== 1 || $voter->fizikal_registration_verified_at !== null);
$eligibleCashPayoutWithoutVote = $method === 'cash'
&& $kehadiran === 1
&& $canProceedToVote
&& !$canVoteBySaham;
if (!$hasVoted && !$eligibleCashPayoutWithoutVote) {
return response()->json([
'status' => 'failed',
'message' => 'Voter has not voted yet.',
@@ -48,9 +48,21 @@ class ClaimCodeController extends Controller
], 422);
}
// Must have voted
$hasVoted = Result::where('election_id', $electionId)->where('voter_id', $voterId)->exists();
if (!$hasVoted) {
// Tunai: normally must have voted; exception — fizikal hadir & layak mesyuarat tetapi tidak dibenarkan
// mengundi kerana saham < RM500 (same rule as voter UI).
$kehadiran = (int) $voter->kehadiran;
$saham = (float) $voter->saham;
$canVoteBySaham = $saham >= 500.0;
$canProceedToVote = $kehadiran !== 0
&& ($kehadiran !== 1 || $voter->fizikal_registration_verified_at !== null);
$eligibleClaimCashWithoutVote = $method === 'cash'
&& $kehadiran === 1
&& $canProceedToVote
&& !$canVoteBySaham;
if (!$hasVoted && !$eligibleClaimCashWithoutVote) {
return response()->json([
'status' => 'failed',
'message' => 'Sila undi terlebih dahulu sebelum menuntut elaun.',
@@ -45,6 +45,13 @@ class GetController extends Controller
->where('allowance_payouts.status', 'paid');
}, 'cash_payout_id');
// Latest paid cash payout — Rujukan / Nota for admin allowance modal ($electionId bound as int)
$eid = (int) $electionId;
$q->addSelect([
DB::raw("(SELECT ap.reference FROM allowance_payouts ap WHERE ap.voter_id = voter.id AND ap.election_id = {$eid} AND ap.method = 'cash' AND ap.status = 'paid' ORDER BY ap.id DESC LIMIT 1) as cash_payout_reference"),
DB::raw("(SELECT ap.note FROM allowance_payouts ap WHERE ap.voter_id = voter.id AND ap.election_id = {$eid} AND ap.method = 'cash' AND ap.status = 'paid' ORDER BY ap.id DESC LIMIT 1) as cash_payout_note"),
]);
$q->selectSub(function ($sq) use ($electionId) {
$sq->from('allowance_payouts')
->selectRaw('MAX(paid_at)')