|
|
|
@ -2,28 +2,130 @@
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers; |
|
|
|
|
|
|
|
|
|
use App\Http\Requests\ValidasiUpdatePengembalian; |
|
|
|
|
use App\Models\Peti; |
|
|
|
|
use App\Models\m_warehouse; |
|
|
|
|
use App\Models\asset_status; |
|
|
|
|
use App\Models\Kondisi_Peti; |
|
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
use Illuminate\Support\Collection; |
|
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
|
use Illuminate\Support\Facades\Auth; |
|
|
|
|
use App\Http\Requests\ValidasiUpdatePengembalian; |
|
|
|
|
|
|
|
|
|
class PengembalianController extends Controller |
|
|
|
|
{ |
|
|
|
|
public function index() |
|
|
|
|
public function index(Request $request) |
|
|
|
|
{ |
|
|
|
|
$pengembalian = asset_status::orderBy('created_at', 'desc')->get(); |
|
|
|
|
$perPage = $request->input('perPage', 5); |
|
|
|
|
$query = asset_status::with(['customer', 'warehouseId', 'warehouse', 'warehouseEnter', 'kondisi_peti']) |
|
|
|
|
->where('status', '=', 1) |
|
|
|
|
->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%"); |
|
|
|
|
}) // sudah cari fix lot |
|
|
|
|
->orWhereHas('customer', function ($warehouseQuery) use ($search) { |
|
|
|
|
$warehouseQuery->where('name', 'like', "%$search%"); |
|
|
|
|
}) // sudah cari nama customer |
|
|
|
|
->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()); |
|
|
|
|
} |
|
|
|
|
}) // sudah cari est pengembalian (tanggal pengembalian) |
|
|
|
|
->orWhere('exit_pic', 'like', "%$search%") // sudah cari exit pic (nama peminjam) |
|
|
|
|
->orWhereHas('warehouse', function ($warehouseQuery) use ($search) { |
|
|
|
|
$warehouseQuery->where('name', 'like', "%$search%") |
|
|
|
|
->orWhere('address', 'like', "%$search%"); |
|
|
|
|
}) // sudah cari warehouse (lokasi peminjaman) |
|
|
|
|
->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('enter_at', $formattedDate); |
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
Log::error('Error parsing date: ' . $e->getMessage()); |
|
|
|
|
} |
|
|
|
|
}) // sudah cari enter at (tanggal pengembalian) |
|
|
|
|
->orWhere('enter_pic', 'like', "%$search%") // sudah cari enter pic (nama pengembali) |
|
|
|
|
->orWhereHas('warehouseEnter', function ($warehouseQuery) use ($search) { |
|
|
|
|
$warehouseQuery->where('name', 'like', "%$search%"); |
|
|
|
|
}) // sudah cari warehouse enter (lokasi pengembalian) |
|
|
|
|
->orWhereHas('kondisi_peti', function ($warehouseQuery) use ($search) { |
|
|
|
|
$warehouseQuery->where('nama_kondisi', 'like', "%$search%"); |
|
|
|
|
}) // sudah cari kondisi peti |
|
|
|
|
->orWhere(function ($statusQuery) use ($search) { |
|
|
|
|
if (strtolower($search) === 'return') { |
|
|
|
|
$statusQuery->where('status', 1); |
|
|
|
|
} else { |
|
|
|
|
$statusQuery->where('status', 'like', "%$search%"); |
|
|
|
|
} |
|
|
|
|
}); // sudah cari status |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Periksa apakah perPage adalah 'Semua' |
|
|
|
|
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() + $store->getQueueableId()); |
|
|
|
|
$stores->push($store); |
|
|
|
|
$currentPage++; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
// Hitung halaman berdasarkan parameter halaman yang diberikan atau default ke halaman pertama |
|
|
|
|
$page = $request->input('page') ?? 1; |
|
|
|
|
|
|
|
|
|
// Paginasi dengan parameter halaman |
|
|
|
|
$stores = $query->paginate($perPage, ['*'], 'page', $page); |
|
|
|
|
|
|
|
|
|
// Hitung nomor urutan untuk setiap item di halaman |
|
|
|
|
$stores->each(function ($store) use ($page, $perPage) { |
|
|
|
|
$store->setAttribute('i', ($page - 1) * $perPage + $store->getQueueableId()); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$data = [ |
|
|
|
|
'peminjaman' => $pengembalian, |
|
|
|
|
'peminjaman' => $stores, |
|
|
|
|
'warehouse' => m_warehouse::get(), |
|
|
|
|
'i' => ($stores->currentPage() - 1) * $stores->perPage() + 1, |
|
|
|
|
'search' => $search, |
|
|
|
|
'active' => 'menu-pengembalian', |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
return view('dashboard.Pengembalian.index', $data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Show the form for creating a new resource. |
|
|
|
|
*/ |
|
|
|
|