DONE: add allowance payout trace for admin, improve UI on voting side, increase pagination number
This commit is contained in:
@@ -23,5 +23,20 @@ class AllowanceClaimCode extends Model
|
||||
'expires_at' => 'datetime',
|
||||
'used_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function election()
|
||||
{
|
||||
return $this->belongsTo(Election::class);
|
||||
}
|
||||
|
||||
public function voter()
|
||||
{
|
||||
return $this->belongsTo(Voter::class);
|
||||
}
|
||||
|
||||
public function usedByAdmin()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'used_by_admin_id');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,5 +24,20 @@ class AllowancePayout extends Model
|
||||
protected $casts = [
|
||||
'paid_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function election()
|
||||
{
|
||||
return $this->belongsTo(Election::class);
|
||||
}
|
||||
|
||||
public function voter()
|
||||
{
|
||||
return $this->belongsTo(Voter::class);
|
||||
}
|
||||
|
||||
public function paidByAdmin()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'paid_by_admin_id');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,6 +177,8 @@ class PayoutController extends Controller
|
||||
'status' => 'success',
|
||||
'message' => 'Allowance payout recorded.',
|
||||
'payout' => $payout,
|
||||
'paid_by_admin_name' => $request->user() ? $request->user()->name : null,
|
||||
'paid_by_admin_email' => $request->user() ? $request->user()->email : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API\v1\Admin\Allowance;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Util;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SummaryController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$electionId = (int) Util::getCurrentElection();
|
||||
|
||||
$q = DB::table('allowance_payouts as ap')
|
||||
->leftJoin('users as u', 'u.id', '=', 'ap.paid_by_admin_id')
|
||||
->where('ap.election_id', $electionId)
|
||||
->where('ap.status', 'paid')
|
||||
->selectRaw('ap.paid_by_admin_id as admin_id')
|
||||
->selectRaw('MAX(u.name) as admin_name')
|
||||
->selectRaw('MAX(u.email) as admin_email')
|
||||
->selectRaw('COUNT(*) as payouts_count')
|
||||
->selectRaw('COALESCE(SUM(ap.amount_cents), 0) as total_amount_cents')
|
||||
->selectRaw("COALESCE(SUM(CASE WHEN ap.method = 'cash' THEN ap.amount_cents ELSE 0 END), 0) as cash_amount_cents")
|
||||
->selectRaw("COALESCE(SUM(CASE WHEN ap.method = 'cash' THEN 1 ELSE 0 END), 0) as cash_count")
|
||||
->selectRaw("COALESCE(SUM(CASE WHEN ap.method = 'bank' THEN ap.amount_cents ELSE 0 END), 0) as bank_amount_cents")
|
||||
->selectRaw("COALESCE(SUM(CASE WHEN ap.method = 'bank' THEN 1 ELSE 0 END), 0) as bank_count")
|
||||
->groupBy('ap.paid_by_admin_id')
|
||||
->orderByDesc('total_amount_cents');
|
||||
|
||||
// Optional: filter by method (?method=cash|bank)
|
||||
$method = $request->query('method');
|
||||
if ($method === 'cash' || $method === 'bank') {
|
||||
$q->where('ap.method', $method);
|
||||
}
|
||||
|
||||
$rows = $q->get();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'election_id' => $electionId,
|
||||
'rows' => $rows,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ class GetController extends Controller
|
||||
$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"),
|
||||
DB::raw("(SELECT u.name FROM allowance_payouts ap LEFT JOIN users u ON u.id = ap.paid_by_admin_id 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_paid_by_admin_name"),
|
||||
DB::raw("(SELECT u.email FROM allowance_payouts ap LEFT JOIN users u ON u.id = ap.paid_by_admin_id 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_paid_by_admin_email"),
|
||||
]);
|
||||
|
||||
$q->selectSub(function ($sq) use ($electionId) {
|
||||
|
||||
@@ -40,4 +40,14 @@ class User extends Authenticatable
|
||||
// Do not allow impersonating main admin.
|
||||
return (int) $this->id !== 1;
|
||||
}
|
||||
|
||||
public function allowanceClaimCodes()
|
||||
{
|
||||
return $this->hasMany(AllowanceClaimCode::class, 'used_by_admin_id');
|
||||
}
|
||||
|
||||
public function allowancePayouts()
|
||||
{
|
||||
return $this->hasMany(AllowancePayout::class, 'paid_by_admin_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user