with('customer', 'tipe_peti', 'warehouse') ->select('customer_id', 'tipe_peti_id', 'warehouse_id', DB::raw('COUNT(*) as total_petis')) ->groupBy('customer_id', 'tipe_peti_id', 'warehouse_id') ->get(); // Total Peti Berdasarkan Tanggal Sekarang $todayStokOpnames = Peti::withTrashed()->with('customer', 'tipe_peti') ->select('customer_id', 'tipe_peti_id', DB::raw('COUNT(*) as total_petis')) ->whereDate('created_at', today()) ->groupBy('customer_id', 'tipe_peti_id') ->get(); // Total Peti Berdasarkan Tanggal Sebelum Tanggal Sekarang $yesterdayStokOpnames = Peti::withTrashed()->with('customer', 'tipe_peti') ->select('customer_id', 'tipe_peti_id', DB::raw('COUNT(*) as total_petis')) ->whereDate('created_at', '<', today()) // Mendapatkan data sebelum tanggal hari ini ->groupBy('customer_id', 'tipe_peti_id') ->get(); // Total Peti $stokOpnames = Peti::withTrashed()->with('customer', 'tipe_peti') ->select('customer_id', 'tipe_peti_id', DB::raw('COUNT(*) as total_petis')) ->groupBy('customer_id', 'tipe_peti_id') ->get(); $data = [ 'stokOpnames' => $stokOpnames, 'todayStokOpnames' => $todayStokOpnames, // tambahin ini di array data 'todayStokOpnames' => $todayStokOpnames, 'yesterdayStokOpnames' => $yesterdayStokOpnames, // tambahin ini di array data 'yesterdayStokOpnames' => $yesterdayStokOpnames, 'gudangStokOpnames' => $gudangStokOpnames, // tambahin ini di array data 'gudangStokOpnames' => $gudangStokOpnames, 'active' => 'menu-Stok_Opname' ]; return view('dashboard.Master_Data.Report.Stok_opname.index', $data); } public function export() { //total peti $stokOpnames = Peti::withTrashed()->with('customer', 'tipe_peti') ->select('customer_id', 'tipe_peti_id', DB::raw('COUNT(*) as total_petis')) ->groupBy('customer_id', 'tipe_peti_id') ->get(); // Total Peti Berdasarkan Tanggal Sekarang $todayStokOpnames = Peti::withTrashed()->with('customer', 'tipe_peti') ->select('customer_id', 'tipe_peti_id', DB::raw('COUNT(*) as total_petis')) ->whereDate('created_at', today()) ->groupBy('customer_id', 'tipe_peti_id') ->get(); // Total Peti Berdasarkan Tanggal Sebelum Tanggal Sekarang $yesterdayStokOpnames = Peti::withTrashed()->with('customer', 'tipe_peti') ->select('customer_id', 'tipe_peti_id', DB::raw('COUNT(*) as total_petis')) ->whereDate('created_at', '<', today()) // Mendapatkan data sebelum tanggal hari ini ->groupBy('customer_id', 'tipe_peti_id') ->get(); // Total Peti Berdasarkan Gudang $gudangStokOpnames = Peti::withTrashed()->with('customer', 'tipe_peti', 'warehouse') ->select('customer_id', 'tipe_peti_id', 'warehouse_id', DB::raw('COUNT(*) as total_petis')) ->groupBy('customer_id', 'tipe_peti_id', 'warehouse_id') ->get(); return Excel::download(new StokOpNameExport($stokOpnames, $todayStokOpnames, $yesterdayStokOpnames, $gudangStokOpnames), 'stok_opname.xlsx'); } }