Siopas Inventory PETI for ISTW Website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

83 lines
3.1 KiB

<?php
namespace App\Http\Controllers;
use App\Models\asset_status;
use App\Models\Peti;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class StokOpNameController extends Controller
{
public function index()
{
// Total Peti Berdasarkan Tanggal Sekarang
$todayStokOpnames = Peti::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::with('customer', 'tipe_peti')
->select('customer_id', 'tipe_peti_id', DB::raw('COUNT(*) as total_petis'))
->whereDate('created_at', today()->subDays(1))
->groupBy('customer_id', 'tipe_peti_id')
->get();
// Total Peti Berdasarkan Tabel asset_status
// $totalPetiAssetStatus = asset_status::select('peti_id', DB::raw('COUNT(*) as total_petis'))
// ->groupBy('peti_id')
// ->get();
$petiIds = asset_status::whereHas('peti', function ($query) {
$query->groupBy('customer_id', 'tipe_peti_id');
})
->pluck('peti_id');
// Total Peti
$stokOpnames = Peti::with('customer', 'tipe_peti')
->select('customer_id', 'tipe_peti_id', DB::raw('COUNT(*) as total_petis'))
->groupBy('customer_id', 'tipe_peti_id')
->get();
$petis = Peti::get();
$data = [
'stokOpnames' => $stokOpnames,
'todayStokOpnames' => $todayStokOpnames, // tambahin ini di array data 'todayStokOpnames' => $todayStokOpnames,
'yesterdayStokOpnames' => $yesterdayStokOpnames, // tambahin ini di array data 'yesterdayStokOpnames' => $yesterdayStokOpnames,
'totalPetiAssetStatus' => $petiIds, // Sesuaikan dengan model dan kolom yang sesuai
'assetStatus' => asset_status::get(),
'petis' => $petis,
'active' => 'menu-Stok_Opname'
];
return view('dashboard.Master_Data.Report.Stok_opname.index', $data);
}
// public function index()
// {
// // // Total Peti Berdasarkan Gudang
// // $gudangStokOpnames = Peti::with('customer', 'tipe_peti')
// // ->select('customer_id', 'tipe_peti_id', DB::raw('COUNT(*) as total_petis'))
// // ->groupBy('customer_id', 'tipe_peti_id')
// // ->get();
// $stokOpnames = Peti::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,
// // 'yesterdayStokOpnames' => $yesterdayStokOpnames,
// // 'gudangStokOpnames' => $gudangStokOpnames,
// 'active' => 'menu-Stok_Opname'
// ];
// return view('dashboard.Master_Data.Report.Stok_opname.index', $data);
// }
}