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.
92 lines
4.3 KiB
92 lines
4.3 KiB
12 months ago
|
<?php
|
||
|
|
||
12 months ago
|
namespace App\Http\Controllers\Report;
|
||
12 months ago
|
|
||
|
use App\Models\Peti;
|
||
12 months ago
|
use App\Models\asset_status;
|
||
12 months ago
|
use Illuminate\Http\Request;
|
||
12 months ago
|
use App\Exports\StokOpNameExport;
|
||
12 months ago
|
use Illuminate\Support\Facades\DB;
|
||
12 months ago
|
use App\Http\Controllers\Controller;
|
||
12 months ago
|
use Maatwebsite\Excel\Facades\Excel;
|
||
12 months ago
|
|
||
|
class StokOpNameController extends Controller
|
||
|
{
|
||
|
public function index()
|
||
|
{
|
||
12 months ago
|
// Total Peti Berdasarkan Gudang
|
||
12 months ago
|
$gudangStokOpnames = Peti::with('customer', 'tipe_peti', 'warehouse')
|
||
|
->where('status', 'AKTIF') // Menambahkan kondisi untuk status Aktif
|
||
12 months ago
|
->select('customer_id', 'tipe_peti_id', 'warehouse_id', DB::raw('COUNT(*) as total_petis'))
|
||
|
->groupBy('customer_id', 'tipe_peti_id', 'warehouse_id')
|
||
|
->get();
|
||
12 months ago
|
|
||
|
// Total Peti Berdasarkan Tanggal Sekarang
|
||
12 months ago
|
$todayStokOpnames = Peti::with('customer', 'tipe_peti')
|
||
|
->where('status', 'AKTIF') // Menambahkan kondisi untuk status Aktif
|
||
12 months ago
|
->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
|
||
12 months ago
|
$yesterdayStokOpnames = Peti::with('customer', 'tipe_peti')
|
||
|
->where('status', 'AKTIF') // Menambahkan kondisi untuk status Aktif
|
||
12 months ago
|
->select('customer_id', 'tipe_peti_id', DB::raw('COUNT(*) as total_petis'))
|
||
12 months ago
|
->whereDate('created_at', '<', today()) // Mendapatkan data sebelum tanggal hari ini
|
||
12 months ago
|
->groupBy('customer_id', 'tipe_peti_id')
|
||
|
->get();
|
||
|
|
||
|
// Total Peti
|
||
12 months ago
|
$stokOpnames = Peti::with('customer', 'tipe_peti')
|
||
|
->where('status', 'AKTIF') // Menambahkan kondisi untuk status Aktif
|
||
12 months ago
|
->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,
|
||
12 months ago
|
'gudangStokOpnames' => $gudangStokOpnames, // tambahin ini di array data 'gudangStokOpnames' => $gudangStokOpnames,
|
||
12 months ago
|
'active' => 'menu-Stok_Opname'
|
||
|
];
|
||
|
return view('dashboard.Master_Data.Report.Stok_opname.index', $data);
|
||
|
}
|
||
|
|
||
12 months ago
|
public function export()
|
||
|
{
|
||
|
//total peti
|
||
12 months ago
|
$stokOpnames = Peti::withTrashed()->with('customer', 'tipe_peti')
|
||
12 months ago
|
->where('status', 'AKTIF') // Menambahkan kondisi untuk status Aktif
|
||
12 months ago
|
->select('customer_id', 'tipe_peti_id', DB::raw('COUNT(*) as total_petis'))
|
||
|
->groupBy('customer_id', 'tipe_peti_id')
|
||
|
->get();
|
||
12 months ago
|
|
||
12 months ago
|
// Total Peti Berdasarkan Tanggal Sekarang
|
||
12 months ago
|
$todayStokOpnames = Peti::withTrashed()->with('customer', 'tipe_peti')
|
||
12 months ago
|
->where('status', 'AKTIF') // Menambahkan kondisi untuk status Aktif
|
||
12 months ago
|
->select('customer_id', 'tipe_peti_id', DB::raw('COUNT(*) as total_petis'))
|
||
|
->whereDate('created_at', today())
|
||
|
->groupBy('customer_id', 'tipe_peti_id')
|
||
|
->get();
|
||
12 months ago
|
|
||
12 months ago
|
// Total Peti Berdasarkan Tanggal Sebelum Tanggal Sekarang
|
||
12 months ago
|
$yesterdayStokOpnames = Peti::withTrashed()->with('customer', 'tipe_peti')
|
||
12 months ago
|
->where('status', 'AKTIF') // Menambahkan kondisi untuk status Aktif
|
||
12 months ago
|
->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();
|
||
12 months ago
|
|
||
12 months ago
|
// Total Peti Berdasarkan Gudang
|
||
12 months ago
|
$gudangStokOpnames = Peti::withTrashed()->with('customer', 'tipe_peti', 'warehouse')
|
||
12 months ago
|
->where('status', 'AKTIF') // Menambahkan kondisi untuk status Aktif
|
||
12 months ago
|
->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');
|
||
12 months ago
|
}
|
||
12 months ago
|
}
|