[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: DashboardController.php
<?php namespace App\Http\Controllers\Vendor; use App\CentralLogics\Helpers; use App\Http\Controllers\Controller; use App\Models\Food; use App\Models\Order; use App\Models\OrderDetail; use App\Models\OrderTransaction; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class DashboardController extends Controller { public function dashboard(Request $request) { $params = [ 'statistics_type' => $request['statistics_type'] ?? 'overall' ]; session()->put('dash_params', $params); $data = self::dashboard_order_stats_data(); $earning = []; $commission = []; $from = Carbon::now()->startOfYear()->format('Y-m-d'); $to = Carbon::now()->endOfYear()->format('Y-m-d'); $restaurant_earnings = OrderTransaction::where(['vendor_id' => Helpers::get_vendor_id()])->select( DB::raw('IFNULL(sum(restaurant_amount),0) as earning'), DB::raw('IFNULL(sum(admin_commission),0) as commission'), DB::raw('YEAR(created_at) year, MONTH(created_at) month') )->whereBetween('created_at', [$from, $to])->groupby('year', 'month')->get()->toArray(); for ($inc = 1; $inc <= 12; $inc++) { $earning[$inc] = 0; $commission[$inc] = 0; foreach ($restaurant_earnings as $match) { if ($match['month'] == $inc) { $earning[$inc] = $match['earning']; $commission[$inc] = $match['commission']; } } } $food_ids = Food::where(['restaurant_id' => Helpers::get_restaurant_id()])->pluck('id')->toArray(); $top_sell = OrderDetail::with(['food'])->whereIn('food_id', $food_ids) ->select('food_id', DB::raw('COUNT(food_id) as count')) ->groupBy('food_id') ->orderBy("count", 'desc') ->take(6) ->get(); $most_rated_foods = Food::rightJoin('reviews', 'reviews.food_id', '=', 'food.id') ->whereIn('food_id', $food_ids) ->groupBy('food_id') ->select(['food_id', DB::raw('AVG(reviews.rating) as ratings_average'), DB::raw('count(*) as total') ]) ->orderBy('total', 'desc') ->take(6) ->get(); $data['top_sell'] = $top_sell; $data['most_rated_foods'] = $most_rated_foods; return view('vendor-views.dashboard', compact('data', 'earning', 'commission', 'params')); } public function restaurant_data() { $new_pending_order = DB::table('orders')->where(['checked' => 0])->where('restaurant_id', Helpers::get_restaurant_id())->where('order_status','pending');; if(config('order_confirmation_model') != 'restaurant') { $new_pending_order = $new_pending_order->where('order_type', 'take_away'); } $new_pending_order = $new_pending_order->count(); $new_confirmed_order = DB::table('orders')->where(['checked' => 0])->where('restaurant_id', Helpers::get_restaurant_id())->whereIn('order_status',['confirmed', 'accepted'])->whereNotNull('confirmed')->count(); return response()->json([ 'success' => 1, 'data' => ['new_pending_order' => $new_pending_order, 'new_confirmed_order' => $new_confirmed_order] ]); } public function order_stats(Request $request) { $params = session('dash_params'); foreach ($params as $key => $value) { if ($key == 'statistics_type') { $params['statistics_type'] = $request['statistics_type']; } } session()->put('dash_params', $params); $data = self::dashboard_order_stats_data(); return response()->json([ 'view' => view('vendor-views.partials._dashboard-order-stats', compact('data'))->render() ], 200); } public function dashboard_order_stats_data() { $params = session('dash_params'); $today = $params['statistics_type'] == 'today' ? 1 : 0; $this_month = $params['statistics_type'] == 'this_month' ? 1 : 0; $confirmed = Order::when($today, function ($query) { return $query->whereDate('created_at', Carbon::today()); })->when($this_month, function ($query) { return $query->whereMonth('created_at', Carbon::now()); })->where(['restaurant_id' => Helpers::get_restaurant_id()])->whereIn('order_status',['confirmed', 'accepted'])->whereNotNull('confirmed')->count(); $cooking = Order::when($today, function ($query) { return $query->whereDate('created_at', Carbon::today()); })->when($this_month, function ($query) { return $query->whereMonth('created_at', Carbon::now()); })->where(['order_status' => 'processing', 'restaurant_id' => Helpers::get_restaurant_id()])->count(); $ready_for_delivery = Order::when($today, function ($query) { return $query->whereDate('created_at', Carbon::today()); })->when($this_month, function ($query) { return $query->whereMonth('created_at', Carbon::now()); })->where(['order_status' => 'handover', 'restaurant_id' => Helpers::get_restaurant_id()])->count(); $food_on_the_way = Order::when($today, function ($query) { return $query->whereDate('created_at', Carbon::today()); })->when($this_month, function ($query) { return $query->whereMonth('created_at', Carbon::now()); })->FoodOnTheWay()->where(['restaurant_id' => Helpers::get_restaurant_id()])->count(); $delivered = Order::when($today, function ($query) { return $query->whereDate('created_at', Carbon::today()); })->when($this_month, function ($query) { return $query->whereMonth('created_at', Carbon::now()); })->where(['order_status' => 'delivered', 'restaurant_id' => Helpers::get_restaurant_id()])->count(); $refunded = Order::when($today, function ($query) { return $query->whereDate('created_at', Carbon::today()); })->when($this_month, function ($query) { return $query->whereMonth('created_at', Carbon::now()); })->where(['order_status' => 'refunded', 'restaurant_id' => Helpers::get_restaurant_id()])->count(); $scheduled = Order::when($today, function ($query) { return $query->whereDate('created_at', Carbon::today()); })->when($this_month, function ($query) { return $query->whereMonth('created_at', Carbon::now()); })->Scheduled()->where(['restaurant_id' => Helpers::get_restaurant_id()])->where(function($q){ if(config('order_confirmation_model') == 'restaurant') { $q->whereNotIn('order_status',['failed','canceled', 'refund_requested', 'refunded']); } else { $q->whereNotIn('order_status',['pending','failed','canceled', 'refund_requested', 'refunded'])->orWhere(function($query){ $query->where('order_status','pending')->where('order_type', 'take_away'); }); } })->count(); $all = Order::when($today, function ($query) { return $query->whereDate('created_at', Carbon::today()); })->when($this_month, function ($query) { return $query->whereMonth('created_at', Carbon::now()); })->where(['restaurant_id' => Helpers::get_restaurant_id()]) ->where(function($q){ $q->whereNotIn('order_status',['pending','failed','canceled', 'refund_requested', 'refunded'])->orWhere(function($query){ $query->where('order_status','pending')->where('order_type', 'take_away'); }); }) ->count(); $data = [ 'confirmed' => $confirmed, 'cooking' => $cooking, 'ready_for_delivery' => $ready_for_delivery, 'food_on_the_way' => $food_on_the_way, 'delivered' => $delivered, 'refunded' => $refunded, 'scheduled' => $scheduled, 'all' => $all, ]; return $data; } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium166.web-hosting.com
Server IP: 162.0.209.40
PHP Version: 8.1.34
Server Software: LiteSpeed
System: Linux premium166.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 75.32 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
No
pkexec:
No
git:
Yes
User Info
Username: kataubyb
User ID (UID): 624
Group ID (GID): 625
Script Owner UID: 624
Current Dir Owner: 624