<?php

namespace App\Http\Controllers\Agencies;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;
use Auth;
use DB;
use App\ClientModel;
use App\FundsRegisterModel;
use App\FundsTransactionModel;
use App\LoanProcessModel;

class DashboardAdminController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
 	public function __construct()
    {
        $this->middleware('auth');
    }
	
    public function index()
    {
        $log_id = Auth::user()->id;
        $clients = ClientModel::where('client_userid',$log_id)->count();

        $funds = FundsRegisterModel::select("id","balance","received​_balance")
        ->where('user_id',$log_id)
        ->where('status',1)
        ->get();
        $balance = empty($funds[0]->balance)?'$ 0.00' : number_format($funds[0]->balance,2);
        $received_balance = empty($funds[0]->received​_balance)?'$ 0.00' : number_format($funds[0]->received​_balance,2);
        $count_agency = User::where('parent_id',$log_id)->count();
        $check_agency = $count_agency== 0 ?'No Agency' : $count_agency;
        $withdraw = FundsTransactionModel::where('operation_type',6)->where('user_log',$log_id)->sum('confirm_withdraw');

        
        return view('agencies.dashboard-admin',compact('clients','balance','received_balance','check_agency','withdraw'));
    }

    
}
