|
|
@ -11,6 +11,7 @@ use Illuminate\Http\Request; |
|
|
|
use Symfony\Component\Uid\Uuid; |
|
|
|
use Symfony\Component\Uid\Uuid; |
|
|
|
use Illuminate\Http\JsonResponse; |
|
|
|
use Illuminate\Http\JsonResponse; |
|
|
|
use Illuminate\Support\Collection; |
|
|
|
use Illuminate\Support\Collection; |
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
use Illuminate\Support\Facades\Auth; |
|
|
|
use Illuminate\Support\Facades\Auth; |
|
|
|
use App\Http\Requests\ValidasiCreatePeminjaman; |
|
|
|
use App\Http\Requests\ValidasiCreatePeminjaman; |
|
|
|
use App\Http\Requests\ValidasiUpdatePeminjaman; |
|
|
|
use App\Http\Requests\ValidasiUpdatePeminjaman; |
|
|
@ -28,7 +29,7 @@ class PeminjamanController extends Controller |
|
|
|
->where('status', '=', 0) |
|
|
|
->where('status', '=', 0) |
|
|
|
->orderBy('created_at', 'desc'); |
|
|
|
->orderBy('created_at', 'desc'); |
|
|
|
|
|
|
|
|
|
|
|
// Tambahkan logika pencarian |
|
|
|
//logika pencarian |
|
|
|
$search = $request->input('search') ?? ''; |
|
|
|
$search = $request->input('search') ?? ''; |
|
|
|
if ($search) { |
|
|
|
if ($search) { |
|
|
|
$query->where(function ($q) use ($search) { |
|
|
|
$query->where(function ($q) use ($search) { |
|
|
@ -36,27 +37,59 @@ class PeminjamanController extends Controller |
|
|
|
->orWhereHas('peti', function ($warehouseQuery) use ($search) { |
|
|
|
->orWhereHas('peti', function ($warehouseQuery) use ($search) { |
|
|
|
$warehouseQuery->where('fix_lot', 'like', "%$search%"); |
|
|
|
$warehouseQuery->where('fix_lot', 'like', "%$search%"); |
|
|
|
}) |
|
|
|
}) |
|
|
|
->orWhere('exit_at', 'like', "%$search%") |
|
|
|
|
|
|
|
->orWhere('est_pengembalian', 'like', "%$search%") |
|
|
|
|
|
|
|
->orWhere('exit_pic', 'like', "%$search%") |
|
|
|
|
|
|
|
->orWhereHas('customer', function ($warehouseQuery) use ($search) { |
|
|
|
->orWhereHas('customer', function ($warehouseQuery) use ($search) { |
|
|
|
$warehouseQuery->where('name', 'like', "%$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) { |
|
|
|
->orWhereHas('warehouse', function ($warehouseQuery) use ($search) { |
|
|
|
$warehouseQuery->where('name', 'like', "%$search%") |
|
|
|
$warehouseQuery->where('name', 'like', "%$search%") |
|
|
|
->orWhere('address', 'like', "%$search%"); |
|
|
|
->orWhere('address', 'like', "%$search%"); |
|
|
|
}) |
|
|
|
}) |
|
|
|
->orWhere('enter_at', 'like', "%$search%") |
|
|
|
|
|
|
|
->orWhere('enter_pic', 'like', "%$search%") |
|
|
|
->orWhere(function ($dateQuery) use ($search) { |
|
|
|
->orWhereHas('warehouseEnter', function ($warehouseQuery) use ($search) { |
|
|
|
try { |
|
|
|
$warehouseQuery->where('name', 'like', "%$search%"); |
|
|
|
// 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()); |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
->orWhereHas('kondisi_peti', function ($warehouseQuery) use ($search) { |
|
|
|
->orWhere(function ($dateQuery) use ($search) { |
|
|
|
$warehouseQuery->where('nama_kondisi', 'like', "%$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('status', 'like', "%$search%") |
|
|
|
->orWhere('exit_pic', 'like', "%$search%") |
|
|
|
->orWhere('created_by', 'like', "%$search%") |
|
|
|
->orWhereHas('warehouse', function ($warehouseQuery) use ($search) { |
|
|
|
->orWhere('updated_by', 'like', "%$search%"); |
|
|
|
$warehouseQuery->where('name', 'like', "%$search%") |
|
|
|
|
|
|
|
->orWhere('address', 'like', "%$search%"); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -79,6 +112,7 @@ class PeminjamanController extends Controller |
|
|
|
$data = [ |
|
|
|
$data = [ |
|
|
|
'peminjaman' => $stores, |
|
|
|
'peminjaman' => $stores, |
|
|
|
'warehouse' => m_warehouse::get(), |
|
|
|
'warehouse' => m_warehouse::get(), |
|
|
|
|
|
|
|
'i' => ($stores->currentPage() - 1) * $stores->perPage() + 1, |
|
|
|
'search' => $search, |
|
|
|
'search' => $search, |
|
|
|
'active' => 'menu-peminjaman', |
|
|
|
'active' => 'menu-peminjaman', |
|
|
|
]; |
|
|
|
]; |
|
|
|