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