diff --git a/app/Http/Controllers/API/v1/AssetStatusApi/AssetStatusApiController.php b/app/Http/Controllers/API/v1/AssetStatusApi/AssetStatusApiController.php index 1e62553..0df022b 100644 --- a/app/Http/Controllers/API/v1/AssetStatusApi/AssetStatusApiController.php +++ b/app/Http/Controllers/API/v1/AssetStatusApi/AssetStatusApiController.php @@ -11,10 +11,9 @@ class AssetStatusApiController extends Controller public function index() { $m_asset = \App\Models\Peti::with(['warehouse', 'tipe_peti', 'customer'])->get(); - return ResponseFormatter::success([ 'message' => 'Data asset berhasil diambil', - 'asset' => $m_asset - ]); + 'asset' => $m_asset, + ], 200); } } diff --git a/app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php b/app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php index bab6500..3bf3244 100644 --- a/app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php +++ b/app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php @@ -12,11 +12,21 @@ class PeminjamanApiController extends Controller { public function index() { - $peminjaman = \App\Models\asset_status::with(['peti.customer', 'peti.tipe_peti', 'warehouse'])->get(); + $peminjaman = \App\Models\asset_status::with(['peti.customer', 'peti.tipe_peti', 'warehouse', 'warehouseEnter'])->get(); return ResponseFormatter::success([ 'message' => 'Data peminjaman berhasil diambil', - 'asset_status' => $peminjaman + 'asset_status' => $peminjaman, + ]); + } + + public function getWarehouseEnter() + { + $warehouse = \App\Models\m_warehouse::get(); + + return ResponseFormatter::success([ + 'message' => 'Data warehouse berhasil diambil', + 'warehouse' => $warehouse, ]); } @@ -32,15 +42,16 @@ class PeminjamanApiController extends Controller public function store(Request $request) { - $this->validate($request, [ - 'peti_id' => 'required', - 'exit_at' => 'required', - 'exit_pic' => 'required', - 'exit_warehouse' => 'required', - 'est_pengembalian' => 'required', - 'created_by' => 'required', - 'updated_by' => 'required', - ]); + // $this->validate($request, [ + // 'peti_id' => 'required', + // 'exit_at' => 'required', + // 'exit_pic' => 'required', + // 'exit_warehouse' => 'required', + // 'est_pengembalian' => 'required', + // 'kondisi_peti' => 'required', + // 'created_by' => 'required', + // 'updated_by' => 'required', + // ]); $peminjaman = asset_status::create([ 'peti_id' => $request->peti_id, @@ -49,7 +60,7 @@ class PeminjamanApiController extends Controller 'exit_warehouse' => $request->exit_warehouse, 'est_pengembalian' => $request->est_pengembalian, 'created_by' => $request->created_by, - 'updated_by' => $request->updated_by, + // 'updated_by' => $request->updated_by, ]); return ResponseFormatter::success([ diff --git a/app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php b/app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php new file mode 100644 index 0000000..afb8d64 --- /dev/null +++ b/app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php @@ -0,0 +1,83 @@ +get(); + + return ResponseFormatter::success([ + 'message' => 'Data pengembalian berhasil diambil', + 'asset_status' => $pengembalian + ]); + } + + + public function update(Request $request, $id) + { + + $pengembalian = \App\Models\asset_status::find($id); + + if (!$pengembalian) { + return ResponseFormatter::error([ + 'message' => 'Data pengembalian tidak ditemukan', + ], 'Data Not Found', 404); + } + + $pengembalian->update([ + 'enter_at' => $request->enter_at, + 'enter_pic' => $request->enter_pic, + 'enter_warehouse' => $request->enter_warehouse, + 'kondisi_peti' => $request->kondisi_peti, + 'updated_by' => $request->updated_by, + ]); + + return ResponseFormatter::success([ + 'message' => 'Data pengembalian berhasil diupdate', + 'asset_status' => $pengembalian + ]); + } +} + + + // try { + // // $this->validate($request, [ + // // 'enter_at' => 'required', + // // 'enter_pic' => 'required', + // // 'enter_warehouse' => 'required', + // // 'kondisi_peti' => 'required', + // // 'updated_by' => 'required', + // // ]); + + // $pengembalian = \App\Models\asset_status::find($id); + + // if (!$pengembalian) { + // return ResponseFormatter::error([ + // 'message' => 'Data pengembalian tidak ditemukan', + // ], 'Data Not Found', 404); + // } + + // $pengembalian->update([ + // 'enter_at' => $request->enter_at, + // 'enter_pic' => $request->enter_pic, + // 'enter_warehouse' => $request->enter_warehouse, + // 'kondisi_peti' => $request->kondisi_peti, + // 'updated_by' => $request->updated_by, + // ]); + + // return ResponseFormatter::success([ + // 'message' => 'Data pengembalian berhasil diupdate', + // 'asset_status' => $pengembalian + // ]); + // } catch (\Exception $e) { + // return ResponseFormatter::error([ + // 'message' => 'Terjadi kesalahan dalam memperbarui data pengembalian', + // 'error' => $e->getMessage(), + // ], 'Update Failed', 500); + // } diff --git a/app/Models/asset_status.php b/app/Models/asset_status.php index c931931..708092c 100644 --- a/app/Models/asset_status.php +++ b/app/Models/asset_status.php @@ -37,6 +37,11 @@ class asset_status extends Model return $this->belongsTo(m_warehouse::class, 'exit_warehouse'); } + public function warehouseEnter() + { + return $this->belongsTo(m_warehouse::class, 'enter_warehouse'); + } + public function peti() { return $this->belongsTo(Peti::class, 'peti_id'); diff --git a/routes/api.php b/routes/api.php index 4314422..0b1004c 100644 --- a/routes/api.php +++ b/routes/api.php @@ -28,6 +28,7 @@ Route::prefix('v1')->group(function () { Route::get('/asset-status', [App\Http\Controllers\API\v1\PeminjamanApi\PeminjamanApiController::class, 'index'])->name('peminjaman-barang'); Route::post('/asset-status/store', [App\Http\Controllers\API\v1\PeminjamanApi\PeminjamanApiController::class, 'store'])->name('peminjaman-barang.store'); Route::get('/asset-status/show/{id}', [App\Http\Controllers\API\v1\PeminjamanApi\PeminjamanApiController::class, 'show'])->name('peminjaman-barang.show'); + Route::put('/asset-status/update/{id}', [App\Http\Controllers\API\v1\PengembalianApi\PengembalianBarangApiController::class, 'update'])->name('peminjaman-barang.update'); Route::get('/peti-asset', [App\Http\Controllers\API\v1\AssetStatusApi\AssetStatusApiController::class, 'index'])->name('peti.barang');