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.

99 lines
3.6 KiB

1 year ago
<?php
12 months ago
namespace App\Http\Controllers\Report;
1 year ago
use App\Models\Peti;
12 months ago
use App\Models\asset_status;
1 year ago
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
12 months ago
use App\Http\Controllers\Controller;
1 year ago
use Maatwebsite\Excel\Facades\Excel;
use App\Exports\PetternLotPetiExport;
class PetternLotPetiController extends Controller
{
// public function index()
// {
// $data = [
// 'peti' => Peti::withTrashed()->get(),
// 'active' => 'menu-Pettern_Lot_Peti'
// ];
// return view('dashboard.Master_Data.Report.Pattern_lot_peti.index', $data);
// }
public function index(Request $request)
1 year ago
{
$perPage = $request->input('perPage', 5);
$query = Peti::with(['customer', 'warehouse', 'tipe_peti', 'kondisipeti', 'transfer', 'assetStatuses'])
->orderBy('created_at', 'desc');
// Tambahkan logika pencarian
$search = $request->input('search') ?? '';
// Tambahkan logika pencarian
$search = $request->input('search') ?? '';
if ($search) {
$query->where(function ($q) use ($search) {
$q->where('fix_lot', 'like', "%$search%")
->orWhere('created_by', 'like', "%$search%")
->orWhereHas('customer', function ($customerQuery) use ($search) {
$customerQuery->where('name', 'like', "%$search%")
->orWhere('code_customer', 'like', "%$search%")
->orWhere('lot_no', 'like', "%$search%");
})
->orWhereHas('warehouse', function ($warehouseQuery) use ($search) {
$warehouseQuery->where('name', 'like', "%$search%");
})
->orWhereHas('tipe_peti', function ($tipePetiQuery) use ($search) {
$tipePetiQuery->where('type', 'like', "%$search%")
->orWhere('size_peti', 'like', "%$search%");
})
->orWhereHas('kondisipeti', function ($kondisiPetiQuery) use ($search) {
$kondisiPetiQuery->where('nama_kondisi', 'like', "%$search%");
})
->orWhere('packing_no', 'like', "%$search%")
->orWhere('status', 'like', "%$search%");
});
}
if ($perPage == 'Semua') {
$chunkSize = 100;
$petis = new Collection();
$currentPage = 1;
$query->chunk($chunkSize, function ($petiChunk) use ($petis, &$currentPage) {
foreach ($petiChunk as $peti) {
$peti->setAttribute('i', ($currentPage - 1) * $petiChunk->perPage() + 1);
$petis->push($peti);
$currentPage++;
}
});
} else {
$petis = $query->paginate($perPage);
}
1 year ago
$data = [
'peti' => $petis,
'i' => ($petis->currentPage() - 1) * $petis->perPage() + 1,
'search' => $search,
1 year ago
'active' => 'menu-Pettern_Lot_Peti'
];
return view('dashboard.Master_Data.Report.Pattern_lot_peti.index', $data);
1 year ago
}
public function show($id)
{
// dd('test');
$data = [
'peti' => Peti::find($id),
'assetStatus' => asset_status::where('peti_id', $id)->get(),
'active' => 'menu-Pettern_Lot_Peti'
];
return view('dashboard.Master_Data.Report.Pattern_lot_peti.detail_peti', $data);
}
1 year ago
public function export()
{
// dd('test');
return Excel::download(new PetternLotPetiExport, 'PATTERN_LOT_PETI.xlsx');
1 year ago
}
}