middleware('auth'); } /** * Show the application dashboard. * * @return \Illuminate\Contracts\Support\Renderable */ public function index() { $datas['title'] = 'Dashboard'; // $datas['ref_user'] = \DB::select("SELECT * FROM users WHERE user_status_id = 1"); if (Auth::user()->role == 3) { return $this->bsGetView('content.dashboard_pemda',$datas); }else{ return $this->bsGetView('content.dashboard',$datas); } } public function home() { $datas['title'] = 'Dashboard'; // $datas['ref_user'] = \DB::select("SELECT * FROM users WHERE user_status_id = 1"); if (Auth::user()->role == 3) { return $this->bsGetView('content.dashboard_pemda',$datas); }else{ return $this->bsGetView('content.dashboard',$datas); } } public function data(Request $request) { $getDate = $this->convertDate($request->tanggal_filter); $getDateYear = $this->convertDateYear($request->tanggal_filter); $getDateMonth = $this->convertDateMonth($request->tanggal_filter); $data['p_outlet'] = \DB::table('merchant')->count('mid'); $data['p_order'] = \DB::table('orders')->select('orders.*') ->join('users','users.user_id','orders.user_id') // ->whereYear('crtdt',$request->tahun) ->whereDate('crtdt',$getDate) ->when(request('merchant_filter') != 'all', function ($query) { $query->where('users.mid', request('merchant_filter')); }) ->count('order_id'); $data['p_transaction'] = \DB::table('payment') ->whereDate('crtdt',$getDate) // ->whereYear('crtdt',$request->tahun) ->when(request('merchant_filter') != 'all', function ($query) { $query->where('mid', request('merchant_filter')); })->count('payment_id'); $data['p_product'] = \DB::table('product') ->when(request('merchant_filter') != 'all', function ($query) { $query->where('mid', request('merchant_filter')); }) ->count('product_id'); $data['stock_minimum'] = \DB::table('product_outlet') ->join('product','product.product_id','product_outlet.product_id') ->join('merchant','merchant.mid','product.mid') ->join('outlet','outlet.outlet_id','product_outlet.outlet_id') ->when(request('merchant_filter') != 'all', function ($query) { $query->where('product.mid', request('merchant_filter')); }) ->orderBy('stock_qty')->limit('10')->get(); $data['best_product'] = DB::table("orders_product") ->join("product", function($join){ $join->on("product.product_id", "=", "orders_product.product_id"); }) ->selectRaw("sum (qty) as jumlah,product_nm") ->limit(10) ->orderBy("jumlah","desc") ->groupBy("product_nm") ->when(request('merchant_filter') != 'all', function ($query) { $query->where('product.mid', request('merchant_filter')); }) ->get(); for ($bulan=1; $bulan <= 12; $bulan++) { $grafik = \DB::table('payment')->whereMonth('crtdt','=',$bulan) ->whereYear('crtdt',$getDateYear) // ->whereYear('crtdt',$request->tahun) ->when(request('merchant_filter') != 'all', function ($query) { $query->where('mid', request('merchant_filter')); })->count('payment_id'); $temp_grafik[] = $grafik; } $data_grafik['Transaction'] = $temp_grafik; $data['grafik'] = $data_grafik; // GRAPH TIME for ($time=1; $time <= 24; $time++) { $grafik_time = \DB::table('payment') // ->whereYear('crtdt',$request->tahun) // ->whereMonth('crtdt','=',date('m')) // ->whereDay('crtdt', date('d')) ->whereDate('crtdt',$getDate) ->whereRaw('EXTRACT(HOUR FROM crtdt) = ?',[$time]) ->when(request('merchant_filter') != 'all', function ($query) { $query->where('mid', request('merchant_filter')); })->count('payment_id'); $temp_grafik_time[] = $grafik_time; } $data_grafik_time['Transaction'] = $temp_grafik_time; $data['grafik_time'] = $data_grafik_time; // GRAPH TIME // GRAPH WEEK for ($week=0; $week <= 6; $week++) { $grafik_week = \DB::table('payment') ->whereYear('crtdt',$getDateYear) ->whereMonth('crtdt','=',$getDateMonth) // ->whereYear('crtdt',$request->tahun) // ->whereMonth('crtdt','=',date('m')) ->whereRaw('EXTRACT(dow FROM crtdt) = ?',[$week]) ->when(request('merchant_filter') != 'all', function ($query) { $query->where('mid', request('merchant_filter')); })->count('payment_id'); $temp_grafik_week[] = $grafik_week; } $data_grafik_week['Transaction'] = $temp_grafik_week; $data['grafik_week'] = $data_grafik_week; // GRAPH WEEK $filterMerchant = ''; if ($request->merchant_filter != null) { if ($request->merchant_filter == 'all') { $filterMerchant = ''; }else{ $checkMid = DB::table('merchant')->where('mid',$request->merchant_filter)->count(); if ($checkMid > 0) { $filterMerchant = " and p.mid = '".$request->merchant_filter."' "; }else{ $filterMerchant = " and p.mid = '$' "; } } } $dtable = \DB::select("SELECT m.mid , m.merchant_nm , o.outlet_id , o.outlet_nm , p.crtdt::date, sum(distinct p.total_amount) as total_amount, sum(distinct b.tax_amount) as tax, sum(distinct b.charge_amount) as charge , sum(distinct b.bill_amount) as gross_sales, sum(omd.base_price * omd.qty) + sum(op.base_price * op.qty) as cogs, sum(distinct b.bill_amount) - (sum(omd.base_price * omd.qty) + sum(op.base_price * op.qty)) as gross_profit, count(distinct p.payment_id) as count_trx, count(distinct op.order_id) as count_order from payment p left join merchant m on p.mid = m.mid left join outlet o on o.outlet_id = p.outlet_id left join bill b on b.bill_id = p.bill_id left join bill_orders_product bop on bop.bill_id = b.bill_id left join orders_product op on bop.order_product_id = op.order_product_id left join orders_modifier_detail omd on op.order_product_id = omd.order_product_id where p.payment_status_id = 1 ".$filterMerchant." group by m.mid , m.merchant_nm , o.outlet_id , o.outlet_nm , p.crtdt::date "); $total_sales = 0; $total_tax = 0; $total_trx = 0; foreach ($dtable as $v) { $total_sales += $v->gross_sales; $total_tax += $v->tax; $total_trx += $v->count_trx; } $data['p_omzet'] = $total_sales; $data['p_tax'] = $total_tax; return response()->json([ 'rc' => 0, 'rm' => "sukses", 'data'=> $data ]); } public function data_pemda(Request $request) { $getDate = $this->convertDate($request->tanggal_filter); $getDateYear = $this->convertDateYear($request->tanggal_filter); $getDateMonth = $this->convertDateMonth($request->tanggal_filter); $data['p_outlet'] = \DB::table('merchant')->count('mid'); $data['p_order'] = \DB::table('orders')->select('orders.*') ->join('users','users.user_id','orders.user_id') // ->whereYear('crtdt',$request->tahun) ->whereDate('crtdt',$getDate) ->when(request('merchant_filter') != 'all', function ($query) { $query->where('users.mid', request('merchant_filter')); }) ->when(request('outlet_filter') != 'all', function ($query) { $query->where('orders.outlet_id', request('outlet_filter')); }) ->count('order_id'); $data['p_transaction'] = \DB::table('payment') ->whereDate('crtdt',$getDate) // ->whereYear('crtdt',$request->tahun) ->when(request('outlet_filter') != 'all', function ($query) { $query->where('payment.outlet_id', request('outlet_filter')); }) ->when(request('merchant_filter') != 'all', function ($query) { $query->where('mid', request('merchant_filter')); })->count('payment_id'); $data['p_product'] = \DB::table('product') ->when(request('merchant_filter') != 'all', function ($query) { $query->where('product.mid', request('merchant_filter')); }) // ->when(request('outlet_filter') != 'all', function ($query) { // $query->where('users.outlet_id', request('outlet_filter')); // }) ->count('product_id'); for ($bulan=1; $bulan <= 12; $bulan++) { $grafik = \DB::table('payment')->whereMonth('crtdt','=',$bulan) ->whereYear('crtdt',$getDateYear) // ->whereYear('crtdt',$request->tahun) ->when(request('merchant_filter') != 'all', function ($query) { $query->where('mid', request('merchant_filter')); })->count('payment_id'); $temp_grafik[] = $grafik; } $data_grafik['Transaction'] = $temp_grafik; $data['grafik'] = $data_grafik; // GRAPH TIME for ($time=1; $time <= 24; $time++) { $grafik_time = \DB::table('payment') // ->whereYear('crtdt',$request->tahun) // ->whereMonth('crtdt','=',date('m')) // ->whereDay('crtdt', date('d')) ->whereDate('crtdt',$getDate) ->whereRaw('EXTRACT(HOUR FROM crtdt) = ?',[$time]) ->when(request('merchant_filter') != 'all', function ($query) { $query->where('mid', request('merchant_filter')); })->count('payment_id'); $temp_grafik_time[] = $grafik_time; } $data_grafik_time['Transaction'] = $temp_grafik_time; $data['grafik_time'] = $data_grafik_time; $filterMerchant = ''; if ($request->merchant_filter != null) { if ($request->merchant_filter == 'all') { $filterMerchant = ''; }else{ $checkMid = DB::table('merchant')->where('mid',$request->merchant_filter)->count(); if ($checkMid > 0) { $filterMerchant = " and p.mid = '".$request->merchant_filter."' "; }else{ $filterMerchant = " and p.mid = '$' "; } } } $filterOutlet = ''; if ($request->outlet_filter != null) { if ($request->outlet_filter == 'all') { $filterOutlet = ''; }else{ $checkOutlet = DB::table('outlet')->where('outlet_id',$request->outlet_filter)->count(); if ($checkOutlet > 0) { $filterOutlet = " and o.outlet_id = '".$request->outlet_filter."' "; }else{ $filterOutlet = " and o.outlet_id = '$' "; } } } $dtable = \DB::select("SELECT m.mid , m.merchant_nm , o.outlet_id , o.outlet_nm , p.crtdt::date, sum(distinct p.total_amount) as total_amount, sum(distinct b.tax_amount) as tax, sum(distinct b.charge_amount) as charge , sum(distinct b.bill_amount) as gross_sales, sum(omd.base_price * omd.qty) + sum(op.base_price * op.qty) as cogs, sum(distinct b.bill_amount) - (sum(omd.base_price * omd.qty) + sum(op.base_price * op.qty)) as gross_profit, count(distinct p.payment_id) as count_trx, count(distinct op.order_id) as count_order from payment p left join merchant m on p.mid = m.mid left join outlet o on o.outlet_id = p.outlet_id left join bill b on b.bill_id = p.bill_id left join bill_orders_product bop on bop.bill_id = b.bill_id left join orders_product op on bop.order_product_id = op.order_product_id left join orders_modifier_detail omd on op.order_product_id = omd.order_product_id where p.payment_status_id = 1 ".$filterMerchant.$filterOutlet." group by m.mid , m.merchant_nm , o.outlet_id , o.outlet_nm , p.crtdt::date "); $total_sales = 0; $total_tax = 0; $total_trx = 0; foreach ($dtable as $v) { $total_sales += $v->gross_sales; $total_tax += $v->tax; $total_trx += $v->count_trx; } $data['p_omzet'] = $total_sales; $data['p_tax'] = $total_tax; return response()->json([ 'rc' => 0, 'rm' => "sukses", 'data'=> $data ]); } public function set_session_theme(Request $request) { Session::put('theme', $request->input('theme')); return response()->json([ 'rc' => 1, 'rm' => $request->input('theme') ]); } public function set_bahasa(Request $request) { App::setLocale('en'); Session::put('bahasa', $request->input('bahasa')); return Redirect::back(); } }