|
Server : Apache/2.4.41 (Ubuntu) System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64 User : www-data ( 33) PHP Version : 8.2.12 Disable Function : NONE Directory : /var/www/parassaas.edukrypt.in/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Admin_module;
use App\Models\Billing;
use App\Models\User;
use App\Models\Product;
use App\Helpers\PermissionActivity;
class DashboardController extends Controller
{
public function show(Request $request)
{
$admin_id = $request->session()->get('loggedIn')['id'];
if (!empty($_GET['start']) || isset($_GET['end'])) {
// $daterange = explode("-", $_GET['daterange']);
$start_date = date("Y-m-d", strtotime(trim($_GET['start'])));
$end_date = date("Y-m-d", strtotime(trim($_GET['end'])));
$query = Billing::where('billings.admin_id', $admin_id);
$query->where('billings.payment_status', 'Credit');
$query->whereBetween('billings.created_at', [$start_date, $end_date]);
$query->join('users', 'users.user_unique_id', '=', 'billings.user_unique_id');
$query->join('orderproductgroups', 'billings.id', '=', 'orderproductgroups.billing_id');
$query->join('products', 'products.id', '=', 'orderproductgroups.product_id');
$query->orderBy('billings.id', 'DESC');
$data['billings'] = $query->get(['billings.*', 'users.name', 'users.email', 'users.phone']);
$query = User::where('users.admin_id', $admin_id);
$query->where('users.status', '1');
$query->whereBetween('users.created_at', [$start_date, $end_date]);
$data['totalUsers'] = $query->count();
// product
$query = Product::where('products.admin_id', $admin_id);
$query->where('products.status', '1');
$query->whereBetween('products.created_at', [$start_date, $end_date]);
$data['totalProducts'] = $query->count();
// users
$query = User::where('users.admin_id', $admin_id);
$query->where('users.status', '1');
$query->whereBetween('users.created_at', [$start_date, $end_date]);
$data['users'] = $query->get();
//products
$query = Product::where('products.admin_id', $admin_id);
$query->whereBetween('products.created_at', [$start_date, $end_date]);
$query->join('main_categories', 'main_categories.id', '=', 'products.cat_id');
$query->skip(0)->take(10);
$data['products'] = $query->get(['products.*', 'main_categories.name as category_name']);
// sales
$query = Billing::where('billings.admin_id', $admin_id);
$query->where('billings.payment_status', 'Credit');
$query->whereBetween('billings.created_at', [$start_date, $end_date]);
$query->join('users', 'users.user_unique_id', '=', 'billings.user_unique_id');
$query->join('orderproductgroups', 'billings.id', '=', 'orderproductgroups.billing_id');
$query->join('products', 'products.id', '=', 'orderproductgroups.product_id');
$query->join('main_categories', 'main_categories.id', '=', 'products.cat_id');
$query->orderBy('billings.id', 'DESC');
$query->skip(0)->take(10);
$data['sales'] = $query->get(['billings.*', 'users.name', 'users.email', 'users.phone', 'orderproductgroups.*', 'products.name', 'main_categories.name as category_name']);
} else {
// billing
$query = Billing::where('billings.admin_id', $admin_id);
$query->where('billings.payment_status', 'Credit');
$query->join('users', 'users.user_unique_id', '=', 'billings.user_unique_id');
$query->join('orderproductgroups', 'billings.id', '=', 'orderproductgroups.billing_id');
$query->join('products', 'products.id', '=', 'orderproductgroups.product_id');
$query->orderBy('billings.id', 'DESC');
$query->skip(0)->take(10);
$data['billings'] = $query->get(['billings.*', 'orderproductgroups.quantity', 'orderproductgroups.product_mode', 'users.name', 'users.email', 'users.phone']);
// total user
$query = User::where('users.admin_id', $admin_id);
$query->where('users.status', '1');
$data['totalUsers'] = $query->count();
//totalproduct
$query = Product::where('products.admin_id', $admin_id);
$query->where('products.status', '1');
$data['totalProducts'] = $query->count();
// users
$query = User::where('users.admin_id', $admin_id);
$query->where('users.status', '1');
$query->skip(0)->take(10);
$data['users'] = $query->get();
//product
$query = Product::where('products.admin_id', $admin_id);
$query->join('main_categories', 'main_categories.id', '=', 'products.cat_id');
$query->skip(0)->take(10);
$data['products'] = $query->get(['products.*', 'main_categories.name as category_name']);
// sales
$query = Billing::where('billings.admin_id', $admin_id);
$query->where('billings.payment_status', 'Credit');
$query->join('users', 'users.user_unique_id', '=', 'billings.user_unique_id');
$query->join('orderproductgroups', 'billings.id', '=', 'orderproductgroups.billing_id');
$query->join('products', 'products.id', '=', 'orderproductgroups.product_id');
$query->join('main_categories', 'main_categories.id', '=', 'products.cat_id');
$query->orderBy('billings.id', 'DESC');
$query->skip(0)->take(10);
$data['sales'] = $query->get(['billings.*', 'users.name', 'users.email', 'users.phone', 'orderproductgroups.*', 'products.name', 'main_categories.name as category_name']);
}
$data['mainMenu'] = 'dashboard';
$data['subMenu'] = 'dashboard';
$getTotal = $this->getTotal($data['billings']);
$data['totalAmount'] = $getTotal['totalAmount'];
$data['totalQty'] = $getTotal['totalQty'];
$data['totalUser'] = $getTotal['totalUser'];
// dd($data['sales']);
$modules = Admin_module::get();
return view('admin.dashboard.dashboard', $data);
}
public function getTotal($billings)
{
$total = [];
$totalAmount = 0;
$totalQty = 0;
$totalUser = [];
if (!empty($billings)) {
foreach ($billings as $billing) {
$totalAmount = $totalAmount + $billing->amount;
$totalQty = $totalQty + $billing->quantity;
$totalUser[] = $billing->user_unique_id;
}
}
$_totalUser = count(array_unique($totalUser));
$total['totalAmount'] = $totalAmount;
$total['totalQty'] = $totalQty;
$total['totalUser'] = $_totalUser;
return $total;
}
}