diff --git a/app/Http/Controllers/HistoryController.php b/app/Http/Controllers/HistoryController.php index 7becc99..f2dab39 100644 --- a/app/Http/Controllers/HistoryController.php +++ b/app/Http/Controllers/HistoryController.php @@ -6,15 +6,108 @@ use App\Models\Transfer; use App\Models\m_warehouse; use App\Models\asset_status; use Illuminate\Http\Request; +use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Log; class HistoryController extends Controller { - public function historyPeminjaman() + // public function historyPeminjaman() + // { + + + // $data = [ + // 'peminjaman' => asset_status::withTrashed()->orderBy('created_at', 'desc')->get(), + // 'warehouse' => m_warehouse::get(), + // 'active' => 'history-peminjaman', + // ]; + + // return view('dashboard.History.Peminjaman.index', $data); + // } + public function historyPeminjaman(Request $request) { + $perPage = $request->input('perPage', 5); + + $query = asset_status::with(['customer', 'warehouseId', 'warehouse', 'warehouseEnter', 'kondisi_peti']) + ->orderBy('created_at', 'desc'); + + //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%"); + }) + ->orWhereHas('customer', function ($warehouseQuery) use ($search) { + $warehouseQuery->where('name', 'like', "%$search%"); + }) + // ->orWhereHas('peti.customer', function ($customerQuery) use ($search) { + // $customerQuery->where('code_customer', 'like', "%$search%"); + // }) + // ->orWhereHas('peti.tipe_peti', function ($tipePetiQuery) use ($search) { + // $tipePetiQuery->where('type', 'like', "%$search%"); + // }) + // ->orWhere(function ($combinedQuery) use ($search) { + // // Pisahkan code customer dan tipe peti dari pencarian + // list($codeCustomer, $typePeti) = explode(' - ', $search); + // // Cek kesamaan code customer dan tipe peti + // $combinedQuery->whereHas('peti.customer', function ($customerQuery) use ($codeCustomer) { + // $customerQuery->where('code_customer', 'like', "%$codeCustomer%"); + // })->whereHas('peti.tipe_peti', function ($tipePetiQuery) use ($typePeti) { + // $tipePetiQuery->where('type', 'like', "%$typePeti%"); + // }); + // }) + ->orWhere(function ($dateQuery) use ($search) { + try { + // Format tanggal yang diharapkan dari input pengguna + $formattedDate = \Carbon\Carbon::createFromFormat('d-m-Y', $search)->format('Y-m-d'); + + // Cek kesamaan tanggal + $dateQuery->whereDate('exit_at', $formattedDate); + } catch (\Exception $e) { + Log::error('Error parsing date: ' . $e->getMessage()); + } + }) + ->orWhere(function ($dateQuery) use ($search) { + try { + // Format tanggal yang diharapkan dari input pengguna + $formattedDate = \Carbon\Carbon::createFromFormat('d-m-Y', $search)->format('Y-m-d'); + + // Cek kesamaan tanggal + $dateQuery->whereDate('est_pengembalian', $formattedDate); + } catch (\Exception $e) { + Log::error('Error parsing date: ' . $e->getMessage()); + } + }) + ->orWhere('exit_pic', 'like', "%$search%") + ->orWhereHas('warehouse', function ($warehouseQuery) use ($search) { + $warehouseQuery->where('name', 'like', "%$search%") + ->orWhere('address', 'like', "%$search%"); + }); + }); + } + + 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' => asset_status::withTrashed()->orderBy('created_at', 'desc')->get(), + 'peminjaman' => $stores, 'warehouse' => m_warehouse::get(), + 'i' => ($stores->currentPage() - 1) * $stores->perPage() + 1, + 'search' => $search, 'active' => 'history-peminjaman', ]; diff --git a/app/Http/Controllers/PeminjamanController.php b/app/Http/Controllers/PeminjamanController.php index 5b87d08..d9551ff 100644 --- a/app/Http/Controllers/PeminjamanController.php +++ b/app/Http/Controllers/PeminjamanController.php @@ -40,29 +40,6 @@ class PeminjamanController extends Controller ->orWhereHas('customer', function ($warehouseQuery) use ($search) { $warehouseQuery->where('name', 'like', "%$search%"); }) - ->orWhereHas('peti.customer', function ($customerQuery) use ($search) { - $customerQuery->where('code_customer', 'like', "%$search%"); - }) - ->orWhereHas('peti.tipe_peti', function ($tipePetiQuery) use ($search) { - $tipePetiQuery->where('type', 'like', "%$search%"); - }) - ->orWhere(function ($combinedQuery) use ($search) { - // Pisahkan code customer dan tipe peti dari pencarian - list($codeCustomer, $typePeti) = explode(' - ', $search); - - // Cek kesamaan code customer dan tipe peti - $combinedQuery->whereHas('peti.customer', function ($customerQuery) use ($codeCustomer) { - $customerQuery->where('code_customer', 'like', "%$codeCustomer%"); - })->whereHas('peti.tipe_peti', function ($tipePetiQuery) use ($typePeti) { - $tipePetiQuery->where('type', 'like', "%$typePeti%"); - }); - }) - ->orWhere('exit_pic', 'like', "%$search%") - ->orWhereHas('warehouse', function ($warehouseQuery) use ($search) { - $warehouseQuery->where('name', 'like', "%$search%") - ->orWhere('address', 'like', "%$search%"); - }) - ->orWhere(function ($dateQuery) use ($search) { try { // Format tanggal yang diharapkan dari input pengguna diff --git a/resources/views/dashboard/History/Peminjaman/index.blade.php b/resources/views/dashboard/History/Peminjaman/index.blade.php index fbd96fe..1dd2050 100644 --- a/resources/views/dashboard/History/Peminjaman/index.blade.php +++ b/resources/views/dashboard/History/Peminjaman/index.blade.php @@ -18,8 +18,44 @@
+
+
+ +
+ + + + +
+
+
+ +
+ + + + +
+
+ +
- +
@@ -32,12 +68,9 @@ - @php - $no_peminjaman = 1; - @endphp @forelse ($peminjaman as $data_peminjaman) - + @empty + + + @endforelse
No
{{ $no_peminjaman++ }}{{ $i++ }} {{ $data_peminjaman->peti->fix_lot }} {{ $data_peminjaman->peti->customer->name }} {{ $data_peminjaman->peti->customer->code_customer }} - @@ -47,10 +80,46 @@ {{ $data_peminjaman->warehouse->name }}
Data Kosong
+
+
+ + @if (!$peminjaman->isEmpty()) +

Showing {{ $peminjaman->firstItem() }} to + {{ $peminjaman->lastItem() }} of + {{ $peminjaman->total() }} entries

+ @endif +
+
+ @if ($peminjaman->total() > $peminjaman->perPage()) + + @endif +
+
@endsection diff --git a/resources/views/layouts/sidebar.blade.php b/resources/views/layouts/sidebar.blade.php index 7ebfe06..f15e275 100644 --- a/resources/views/layouts/sidebar.blade.php +++ b/resources/views/layouts/sidebar.blade.php @@ -22,22 +22,19 @@ - - @php - $isTransaksiActive = in_array($active, ['menu-user', 'menu-role']); - @endphp - - + - + + - @php - $isPetiActive = in_array($active, ['menu-user', 'menu-role']); - @endphp - + + - - {{-- --}} @else @include('pages.layouts.sidebar_user') @endif diff --git a/resources/views/pages/layouts/sidebar_user.blade.php b/resources/views/pages/layouts/sidebar_user.blade.php index cf9e418..00ed02c 100644 --- a/resources/views/pages/layouts/sidebar_user.blade.php +++ b/resources/views/pages/layouts/sidebar_user.blade.php @@ -22,18 +22,17 @@ -@php - $isTransaksiActive = in_array($active, ['menu-user', 'menu-role']); -@endphp - - + - --}} + -@php - $isPetiActive = in_array($active, ['menu-user', 'menu-role']); -@endphp - + + - -{{-- --}}