|
|
|
@ -24,81 +24,60 @@ class PetiController extends Controller
|
|
|
|
|
/** |
|
|
|
|
* Display a listing of the resource. |
|
|
|
|
*/ |
|
|
|
|
// public function index() |
|
|
|
|
// { |
|
|
|
|
// $data = [ |
|
|
|
|
// // 'peti' => Peti::orderBy('created_at', 'desc')->get(), |
|
|
|
|
// 'peti' => Peti::orderBy('created_at', 'desc')->get(), |
|
|
|
|
// 'kondisiPeti' => Kondisi_Peti::all(), |
|
|
|
|
// 'active' => 'menu-peti', |
|
|
|
|
// ]; |
|
|
|
|
// return view('dashboard.Master_Data.Manajemen_Peti.Peti.index', $data); |
|
|
|
|
// } |
|
|
|
|
// public function index() |
|
|
|
|
// { |
|
|
|
|
// // $perPage = 10; // Jumlah data per halaman, sesuaikan dengan kebutuhan Anda |
|
|
|
|
|
|
|
|
|
// // $peti = Peti::orderBy('created_at', 'desc')->paginate($perPage); |
|
|
|
|
// $peti = Peti::orderBy('created_at', 'desc')->get(); |
|
|
|
|
// $kondisiPeti = Kondisi_Peti::all(); |
|
|
|
|
|
|
|
|
|
// $data = [ |
|
|
|
|
// 'peti' => $peti, |
|
|
|
|
// 'kondisiPeti' => $kondisiPeti, |
|
|
|
|
// 'active' => 'menu-peti', |
|
|
|
|
// ]; |
|
|
|
|
|
|
|
|
|
// return view('dashboard.Master_Data.Manajemen_Peti.Peti.index', $data); |
|
|
|
|
// } |
|
|
|
|
public function index(Request $request) |
|
|
|
|
{ |
|
|
|
|
$perPage = $request->input('perPage', 5); |
|
|
|
|
|
|
|
|
|
$query = Peti::select(['petis.*', 'customers.code_customer', 'customers.lot_no', 'type_petis.type', 'type_petis.size_peti', 'm_warehouses.name as warehouse_name']) |
|
|
|
|
->join('customers', 'customers.id', '=', 'petis.customer_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 = 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('petis.fix_lot', 'like', "%$search%") |
|
|
|
|
->orWhere('petis.created_by', 'like', "%$search%") |
|
|
|
|
->orWhere('customers.name', 'like', "%$search%") |
|
|
|
|
->orWhere('m_warehouses.name', 'like', "%$search%") |
|
|
|
|
->orWhere('customers.code_customer', 'like', "%$search%") |
|
|
|
|
->orWhere('type_petis.type', 'like', "%$search%") |
|
|
|
|
->orWhere('type_petis.size_peti', 'like', "%$search%") |
|
|
|
|
->orWhere('customers.lot_no', 'like', "%$search%") |
|
|
|
|
->orWhere('kondisi_petis.nama_kondisi', 'like', "%$search%") |
|
|
|
|
->orWhere('petis.packing_no', 'like', "%$search%") |
|
|
|
|
->orWhere('petis.status', 'like', "%$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; |
|
|
|
|
$stores = new Collection(); |
|
|
|
|
$petis = 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); |
|
|
|
|
$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 { |
|
|
|
|
$stores = $query->paginate($perPage); |
|
|
|
|
$petis = $query->paginate($perPage); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$data = [ |
|
|
|
|
// 'peti' => Peti::orderBy('created_at', 'desc')->paginate(10), |
|
|
|
|
'peti' => $stores, |
|
|
|
|
'peti' => $petis, |
|
|
|
|
'kondisiPeti' => Kondisi_Peti::all(), |
|
|
|
|
'i' => ($stores->currentPage() - 1) * $stores->perPage() + 1, |
|
|
|
|
'i' => ($petis->currentPage() - 1) * $petis->perPage() + 1, |
|
|
|
|
'search' => $search, |
|
|
|
|
'active' => 'menu-peti', |
|
|
|
|
]; |
|
|
|
@ -343,9 +322,55 @@ class PetiController extends Controller
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// public function importPeti(Request $request) |
|
|
|
|
// { |
|
|
|
|
// $import = new PetiImport; |
|
|
|
|
// Excel::import($import, request()->file('file')); |
|
|
|
|
|
|
|
|
|
// // Cek apakah ada data yang berhasil diimpor |
|
|
|
|
// if ($import->getRowCount() > 0) { |
|
|
|
|
// return redirect()->route('dashboard.peti.index')->with('success', 'Data Peti berhasil diimport'); |
|
|
|
|
// } else { |
|
|
|
|
// $errors = $import->getErrors(); |
|
|
|
|
|
|
|
|
|
// if ($errors) { |
|
|
|
|
// foreach ($errors as $error) { |
|
|
|
|
// foreach ($error->all() as $message) { |
|
|
|
|
// // Tampilkan pesan kesalahan untuk setiap baris |
|
|
|
|
// // Simpan pesan flash dengan kategori 'error' |
|
|
|
|
// session()->flash('error', $message); |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
// // Redirect back with import data and error message |
|
|
|
|
// return redirect()->back()->with('import', $import)->with('error', 'Data Import Peti gagal di import.'); |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
public function importPeti(Request $request) |
|
|
|
|
{ |
|
|
|
|
Excel::import(new PetiImport, request()->file('file')); |
|
|
|
|
return redirect()->route('dashboard.peti.index')->with('success', 'Data peti berhasil di import'); |
|
|
|
|
$import = new PetiImport; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
Excel::import($import, request()->file('file')); |
|
|
|
|
|
|
|
|
|
if ($import->getRowCount() > 0) { |
|
|
|
|
return redirect()->route('dashboard.peti.index')->with('success', 'Data Peti berhasil diimport'); |
|
|
|
|
} else { |
|
|
|
|
$errors = $import->getErrors(); |
|
|
|
|
|
|
|
|
|
if (!empty($errors)) { |
|
|
|
|
session()->flash('error', $errors); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return redirect()->back()->with('import', $import)->with('error', 'Data Peti gagal di import.'); |
|
|
|
|
} |
|
|
|
|
} catch (\Maatwebsite\Excel\Validators\ValidationException $e) { |
|
|
|
|
$failures = $e->failures(); |
|
|
|
|
|
|
|
|
|
foreach ($failures as $failure) { |
|
|
|
|
session()->flash('error', ['Baris ' . $failure->row() => implode(', ', $failure->errors())]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|