|
|
@ -24,81 +24,60 @@ class PetiController extends Controller |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Display a listing of the resource. |
|
|
|
* 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) |
|
|
|
public function index(Request $request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$perPage = $request->input('perPage', 5); |
|
|
|
$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']) |
|
|
|
$query = Peti::with(['customer', 'warehouse', 'tipe_peti', 'kondisipeti', 'transfer', 'assetStatuses']) |
|
|
|
->join('customers', 'customers.id', '=', 'petis.customer_id') |
|
|
|
->orderBy('created_at', 'desc'); |
|
|
|
->join('type_petis', 'type_petis.id', '=', 'petis.tipe_peti_id') |
|
|
|
// Tambahkan logika pencarian |
|
|
|
->join('m_warehouses', 'm_warehouses.id', '=', 'petis.warehouse_id') |
|
|
|
$search = $request->input('search') ?? ''; |
|
|
|
->join('kondisi_petis', 'kondisipeti_id', '=', 'petis.kondisipeti_id') |
|
|
|
|
|
|
|
->orderBy('petis.created_at', 'desc'); |
|
|
|
|
|
|
|
// Tambahkan logika pencarian |
|
|
|
// Tambahkan 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) { |
|
|
|
$q->where('petis.fix_lot', 'like', "%$search%") |
|
|
|
$q->where('fix_lot', 'like', "%$search%") |
|
|
|
->orWhere('petis.created_by', 'like', "%$search%") |
|
|
|
->orWhere('created_by', 'like', "%$search%") |
|
|
|
->orWhere('customers.name', 'like', "%$search%") |
|
|
|
->orWhereHas('customer', function ($customerQuery) use ($search) { |
|
|
|
->orWhere('m_warehouses.name', 'like', "%$search%") |
|
|
|
$customerQuery->where('name', 'like', "%$search%") |
|
|
|
->orWhere('customers.code_customer', 'like', "%$search%") |
|
|
|
->orWhere('code_customer', 'like', "%$search%") |
|
|
|
->orWhere('type_petis.type', 'like', "%$search%") |
|
|
|
->orWhere('lot_no', 'like', "%$search%"); |
|
|
|
->orWhere('type_petis.size_peti', 'like', "%$search%") |
|
|
|
}) |
|
|
|
->orWhere('customers.lot_no', 'like', "%$search%") |
|
|
|
->orWhereHas('warehouse', function ($warehouseQuery) use ($search) { |
|
|
|
->orWhere('kondisi_petis.nama_kondisi', 'like', "%$search%") |
|
|
|
$warehouseQuery->where('name', 'like', "%$search%"); |
|
|
|
->orWhere('petis.packing_no', 'like', "%$search%") |
|
|
|
}) |
|
|
|
->orWhere('petis.status', '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') { |
|
|
|
if ($perPage == 'Semua') { |
|
|
|
$chunkSize = 100; |
|
|
|
$chunkSize = 100; |
|
|
|
$stores = new Collection(); |
|
|
|
$petis = new Collection(); |
|
|
|
$currentPage = 1; |
|
|
|
$currentPage = 1; |
|
|
|
|
|
|
|
|
|
|
|
$query->chunk($chunkSize, function ($storesChunk) use ($stores, &$currentPage) { |
|
|
|
$query->chunk($chunkSize, function ($petiChunk) use ($petis, &$currentPage) { |
|
|
|
foreach ($storesChunk as $store) { |
|
|
|
foreach ($petiChunk as $peti) { |
|
|
|
$store->setAttribute('i', ($currentPage - 1) * $storesChunk->perPage() + 1); |
|
|
|
$peti->setAttribute('i', ($currentPage - 1) * $petiChunk->perPage() + 1); |
|
|
|
$stores->push($store); |
|
|
|
$petis->push($peti); |
|
|
|
$currentPage++; |
|
|
|
$currentPage++; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$stores = $query->paginate($perPage); |
|
|
|
$petis = $query->paginate($perPage); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$data = [ |
|
|
|
$data = [ |
|
|
|
// 'peti' => Peti::orderBy('created_at', 'desc')->paginate(10), |
|
|
|
'peti' => $petis, |
|
|
|
'peti' => $stores, |
|
|
|
|
|
|
|
'kondisiPeti' => Kondisi_Peti::all(), |
|
|
|
'kondisiPeti' => Kondisi_Peti::all(), |
|
|
|
'i' => ($stores->currentPage() - 1) * $stores->perPage() + 1, |
|
|
|
'i' => ($petis->currentPage() - 1) * $petis->perPage() + 1, |
|
|
|
'search' => $search, |
|
|
|
'search' => $search, |
|
|
|
'active' => 'menu-peti', |
|
|
|
'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) |
|
|
|
public function importPeti(Request $request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Excel::import(new PetiImport, request()->file('file')); |
|
|
|
$import = new PetiImport; |
|
|
|
return redirect()->route('dashboard.peti.index')->with('success', 'Data peti berhasil di import'); |
|
|
|
|
|
|
|
|
|
|
|
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())]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|