diff --git a/app/Http/Controllers/PeminjamanController.php b/app/Http/Controllers/PeminjamanController.php index 9ec5de1..24e81e5 100644 --- a/app/Http/Controllers/PeminjamanController.php +++ b/app/Http/Controllers/PeminjamanController.php @@ -9,6 +9,7 @@ use App\Models\asset_status; use App\Models\Kondisi_Peti; use Illuminate\Http\Request; use Symfony\Component\Uid\Uuid; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; use App\Http\Requests\ValidasiCreatePeminjaman; use App\Http\Requests\ValidasiUpdatePeminjaman; @@ -34,39 +35,58 @@ class PeminjamanController extends Controller { $perPage = $request->input('perPage', 5); - $query = asset_status::orderBy('created_at', 'desc'); - // $query = asset_status::select(['asset_statuses.*', 'Petis.code_customer', 'customers.lot_no', 'type_petis.type', 'type_petis.size_peti', 'm_warehouses.name as warehouse_name']) - // ->join('Petis', 'peti.id', '=', 'asset_statuses.peti_id') - // ->join('type_petis', 'type_petis.id', '=', 'petis.tipe_peti_id') - // ->join('m_warehouses', 'm_warehouses.id', '=', 'petis.warehouse_id') - // ->join('kondisi_petis', 'kondisipeti_id', '=', 'petis.kondisipeti_id') - // ->orderBy('petis.created_at', 'desc'); - + $query = asset_status::with(['customer', 'warehouseId', 'warehouse', 'warehouseEnter', 'kondisi_peti']) + ->orderBy('created_at', 'desc'); // Tambahkan logika pencarian $search = $request->input('search') ?? ''; if ($search) { $query->where(function ($q) use ($search) { $q->where('mobile_id', 'like', "%$search%") + ->orWhereHas('peti', function ($warehouseQuery) use ($search) { + $warehouseQuery->where('fix_lot', 'like', "%$search%"); + }) ->orWhere('exit_at', 'like', "%$search%") ->orWhere('est_pengembalian', 'like', "%$search%") ->orWhere('exit_pic', 'like', "%$search%") - ->orWhere('customer_id', 'like', "%$search%") - ->orWhere('warehouse_id', 'like', "%$search%") - ->orWhere('exit_warehouse', 'like', "%$search%") + ->orWhereHas('customer', function ($warehouseQuery) use ($search) { + $warehouseQuery->where('name', 'like', "%$search%"); + }) + ->orWhereHas('warehouse', function ($warehouseQuery) use ($search) { + $warehouseQuery->where('name', 'like', "%$search%") + ->orWhere('address', 'like', "%$search%"); + }) ->orWhere('enter_at', 'like', "%$search%") ->orWhere('enter_pic', 'like', "%$search%") - ->orWhere('enter_warehouse', 'like', "%$search%") - ->orWhere('kondisi_peti_id', 'like', "%$search%") + ->orWhereHas('warehouseEnter', function ($warehouseQuery) use ($search) { + $warehouseQuery->where('name', 'like', "%$search%"); + }) + ->orWhereHas('kondisi_peti', function ($warehouseQuery) use ($search) { + $warehouseQuery->where('nama_kondisi', 'like', "%$search%"); + }) ->orWhere('status', 'like', "%$search%") ->orWhere('created_by', 'like', "%$search%") ->orWhere('updated_by', 'like', "%$search%"); }); } - $peminjaman = $query->paginate($perPage); + if ($perPage == 'Semua') { + $chunkSize = 100; + $stores = new Collection(); + $currentPage = 1; + + $query->chunk($chunkSize, function ($storesChunk) use ($stores, &$currentPage) { + foreach ($storesChunk as $store) { + $store->setAttribute('i', ($currentPage - 1) * $storesChunk->perPage() + 1); + $stores->push($store); + $currentPage++; + } + }); + } else { + $stores = $query->paginate($perPage); + } $data = [ - 'peminjaman' => $peminjaman, + 'peminjaman' => $stores, 'warehouse' => m_warehouse::get(), 'search' => $search, 'active' => 'menu-peminjaman', diff --git a/resources/views/dashboard/Master_Data/Manajemen_Peti/Peti/index.blade.php b/resources/views/dashboard/Master_Data/Manajemen_Peti/Peti/index.blade.php index 18acde3..ab53122 100644 --- a/resources/views/dashboard/Master_Data/Manajemen_Peti/Peti/index.blade.php +++ b/resources/views/dashboard/Master_Data/Manajemen_Peti/Peti/index.blade.php @@ -45,32 +45,31 @@
-Showing {{ $peti->firstItem() }} to - {{ $peti->lastItem() }} of +
Showing {{ $peti->firstItem() }} to {{ $peti->lastItem() }} of {{ $peti->total() }} entries
@endifAction | - {{-- + + @php $no_peminjaman = 1; @endphp @forelse ($peminjaman as $data_peminjaman) - @if ($data_peminjaman->enter_warehouse == null) -|||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{{ $no_peminjaman++ }} | -{{ $data_peminjaman->peti->fix_lot }} | -{{ $data_peminjaman->peti->customer->name }} | -{{ $data_peminjaman->peti->customer->code_customer }} - - {{ $data_peminjaman->peti->tipe_peti->type }} | -{{ \Carbon\Carbon::parse($data_peminjaman->exit_at)->format('d/m/Y') }} | -{{ $data_peminjaman->exit_pic }} | -{{ $data_peminjaman->warehouse->name }} | -- - - - - - - - | -||||||||
Data Kosong | +{{ $no_peminjaman++ }} | +{{ $data_peminjaman->peti->fix_lot }} | +{{ $data_peminjaman->peti->customer->name }} | +{{ $data_peminjaman->peti->customer->code_customer }} - + {{ $data_peminjaman->peti->tipe_peti->type }} | +{{ \Carbon\Carbon::parse($data_peminjaman->exit_at)->format('d/m/Y') }} | +{{ $data_peminjaman->exit_pic }} | +{{ $data_peminjaman->warehouse->name }} | ++ + + + + + + + | |||||||
{{ $no_peminjaman++ }} | -{{ $data_peminjaman->peti->fix_lot }} | -{{ $data_peminjaman->peti->customer->name }} | -{{ $data_peminjaman->peti->customer->code_customer }} - - {{ $data_peminjaman->peti->tipe_peti->type }} | -{{ \Carbon\Carbon::parse($data_peminjaman->exit_at)->format('d/m/Y') }} | -{{ $data_peminjaman->exit_pic }} | -{{ $data_peminjaman->warehouse->name }} | -- - - - - - - - | -||||||||
{{ $no_peminjaman++ }} | -{{ $data_peminjaman->peti->fix_lot }} | -{{ $data_peminjaman->peti->customer->name }} | -{{ $data_peminjaman->peti->customer->code_customer }} - - {{ $data_peminjaman->peti->tipe_peti->type }} | -{{ \Carbon\Carbon::parse($data_peminjaman->exit_at)->format('d/m/Y') }} | -{{ $data_peminjaman->exit_pic }} | -{{ $data_peminjaman->warehouse->name }} | -- - - - - - - - | -||||||||
Data Kosong |