<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Transaction;
use Illuminate\Http\Request;

class TransactionController extends Controller
{
    public function index()
    {
        $pageTitle    = 'Card Transactions';
        $remarks      = Transaction::where('virtual_card_id', '>', 0)->distinct('remark')->orderBy('remark')->get('remark');
        $transactions = Transaction::where('virtual_card_id', '>', 0)->filter(['virtual_card_id', 'trx_type', 'remark'])->dateFilter()->searchable(['trx', 'user:username'])->filter(['trx_type', 'remark'])->latest()->paginate(getPaginate());
        $cards        =  Transaction::where('virtual_card_id', '>', 0)->get()->map(function ($transaction) {
            return $transaction->card;
        })->unique();

        return view('admin.transaction.list', compact('pageTitle', 'transactions', 'remarks', 'cards'));
    }
}
