Viewing file: DashboardController.php (2.9 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller; use App\Models\Customer; use App\Models\CustomerWallet; use App\Models\Deposit; use App\Models\Notice; use App\Models\Order; use App\Models\Refund; use App\Models\Ticket; use App\Models\Transaction; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB;
class DashboardController extends Controller { public function index(){ $data['totalUsers'] = Customer::count(); $data['totalAmountReceive'] = Deposit::where('status','approved')->sum('amount'); $data['totalUsersBalance'] = CustomerWallet::sum('amount'); $completedOrders = Order::with('orderdetails')->where('status','completed')->get(); $profit = 0; foreach ($completedOrders as $orders){ $profit += $orders->orderdetails->sum('charges'); } $data['todayProfit'] = $profit; $data['totalOrders'] = Order::count(); $data['topCustomers'] = Order::orderBy('customer_id', 'ASC')->groupBy('customer_id')->limit(5)->get(); $orderStatus = Order::select('status', DB::raw('count(*) as total')) ->groupBy('status') ->pluck('total','status')->all(); $data['orderStatus'] = $orderStatus; $transactionType = Transaction::select('type', DB::raw('SUM(amount) as total')) ->groupBy('type') ->pluck('total','type')->all(); $data['transactionType'] = $transactionType;
$orders = Order::where('created_at', '>', now()->subDays(30)) ->select(DB::Raw('count(*) as count'),DB::Raw('DATE(created_at) day')) ->groupBy('day')->get() ->pluck('count','day');
$monthlyOrders=[]; foreach (getLastNDays(30) as $day){ $monthlyOrders[]=isset($orders[trim($day, '"')])?$orders[trim($day, '"')]:0; }
$deposits = Deposit::where('created_at', '>', now()->subDays(30))->where('status','approved') ->select(DB::Raw('count(*) as count'),DB::Raw('DATE(created_at) day')) ->groupBy('day')->get() ->pluck('count','day'); $monthlyDeposits=[]; foreach (getLastNDays(30) as $day){ $monthlyDeposits[]=isset($deposits[trim($day, '"')])?$deposits[trim($day, '"')]:0; } $monthly = []; foreach (getLastNDays(30) as $day){ $day=Carbon::createFromTimeString(str_replace('"','',$day." 0:00:00")); $monthly[]= $day->format('m-d-Y'); } $data['months'] = $monthly; $data['monthlyDeposits'] = $monthlyDeposits; $data['monthlyOrders'] = $monthlyOrders; return view('admin.dashboard',$data); } public function setLocale($type) { $availableLang = get_available_languages();
if (!in_array($type, $availableLang)) abort(400);
session()->put('locale', $type);
return redirect()->back(); }
}
|