<?php

namespace App\Http\Controllers\Admin\Transaction;

use App\DataTables\Gateway\TransactionsDataTable;
use App\Http\Controllers\Controller;
use App\Models\PaymentGateway;
use App\Models\Transaction;

class TransactionController extends Controller
{
    public function index(TransactionsDataTable $dataTable)
    {
        $total_opening_balance = PaymentGateway::sum('gateway_opening_balance');
        $total_credited_amount = Transaction::where('status', 'credit')->sum('amount');
        $total_debited_amount  = Transaction::where('status', 'debit')->sum('amount');
        $current_balance = $total_opening_balance + ( $total_credited_amount - $total_debited_amount );
        return $dataTable->render('admin.payment-gateways.transactions',compact(
            'total_opening_balance',
            'total_credited_amount',
            'total_debited_amount',
            'current_balance',
        ));
    }
}
