diff --git a/app/Http/Controllers/API/v1/CustomerApi/CustomerApiController.php b/app/Http/Controllers/API/v1/CustomerApi/CustomerApiController.php new file mode 100644 index 0000000..4cf0cc7 --- /dev/null +++ b/app/Http/Controllers/API/v1/CustomerApi/CustomerApiController.php @@ -0,0 +1,21 @@ +orderBy('created_at', 'DESC')->get(); + + return ResponseFormatter::success([ + 'status' => true, + 'message' => 'Data warehouse berhasil diambil', + 'customers' => $customers + ], 200); + } +} diff --git a/app/Http/Controllers/API/v1/KondisiPetiApi/KondisiPetiApiController.php b/app/Http/Controllers/API/v1/KondisiPetiApi/KondisiPetiApiController.php new file mode 100644 index 0000000..10ff635 --- /dev/null +++ b/app/Http/Controllers/API/v1/KondisiPetiApi/KondisiPetiApiController.php @@ -0,0 +1,20 @@ + 'Data kondisi peti berhasil diambil', + 'kondisi_peti' => $kondisi, + ]); + } +} diff --git a/app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php b/app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php index 3027fb6..b6e967c 100644 --- a/app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php +++ b/app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php @@ -13,7 +13,8 @@ class PeminjamanApiController extends Controller public function index() { $peminjaman = \App\Models\asset_status::with([ - 'peti.customer:id,name,code_customer,lot_no,nip,no_hp,tgl_lahir,jenis_kelamin,agama,address', + 'peti.customer:id,name,code_customer,lot_no,address', + // 'peti.customer', 'peti.tipe_peti:id,type,size_peti,description', 'warehouse', 'warehouseEnter' @@ -55,30 +56,49 @@ 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', - // 'kondisi_peti' => 'required', - // 'created_by' => 'required', - // 'updated_by' => 'required', - // ]); + $mobile_id = $request->input('mobile_id'); + $peti_id = $request->input('peti_id'); + $exit_at = $request->input('exit_at'); + $exit_pic = $request->input('exit_pic'); + $exit_warehouse = $request->input('exit_warehouse'); + $est_pengembalian = $request->input('est_pengembalian'); + // $status = $request->input('status'); + $created_by = $request->input('created_by'); + $created_at = $request->input('created_at'); - $peminjaman = asset_status::create([ - 'peti_id' => $request->peti_id, - 'exit_at' => $request->exit_at, - 'exit_pic' => $request->exit_pic, - 'exit_warehouse' => $request->exit_warehouse, - 'est_pengembalian' => $request->est_pengembalian, - 'created_by' => $request->created_by, - // 'updated_by' => $request->updated_by, - ]); + $existingRecord = asset_status::where('mobile_id', $mobile_id) + ->where('peti_id', $peti_id) + ->first(); - return ResponseFormatter::success([ - 'message' => 'Data peminjaman berhasil ditambahkan', - 'peminjam' => $peminjaman - ]); + if ($existingRecord) { + $existingRecord->exit_at = $exit_at; + $existingRecord->exit_pic = $exit_pic; + $existingRecord->exit_warehouse = $exit_warehouse; + $existingRecord->est_pengembalian = $est_pengembalian; + // $existingRecord->status = $status; + $existingRecord->created_by = $created_by; + $existingRecord->created_at = $created_at; + $existingRecord->save(); + return ResponseFormatter::success([ + 'message' => 'Data peminjaman berhasil ditambahkan', + 'peminjam' => $existingRecord + ]); + } else { + $newRecord = new asset_status; + $newRecord->mobile_id = $mobile_id; + $newRecord->peti_id = $peti_id; + $newRecord->exit_at = $exit_at; + $newRecord->exit_pic = $exit_pic; + $newRecord->exit_warehouse = $exit_warehouse; + $newRecord->est_pengembalian = $est_pengembalian; + // $newRecord->status = $status; + $newRecord->created_by = $created_by; + $newRecord->created_at = $created_at; + $newRecord->save(); + return ResponseFormatter::success([ + 'message' => 'Data peminjaman berhasil ditambahkan', + 'peminjam' => $newRecord + ]); + } } } diff --git a/app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php b/app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php index 2052f1d..411457b 100644 --- a/app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php +++ b/app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php @@ -62,65 +62,43 @@ class PengembalianBarangApiController extends Controller ]); } - public function update(Request $request, $id) + public function update(Request $request) { + $petiId = $request->peti_id; - $pengembalian = \App\Models\asset_status::find($id); + // Cari data terakhir dengan kondisi peti_id dan status 0 + $lastPetiData = \App\Models\asset_status::where('peti_id', $petiId) + ->where('status', 0) // Hanya data dengan status 0 + ->orderBy('id', 'desc') + ->first(); - if (!$pengembalian) { + if (!$lastPetiData) { return ResponseFormatter::error([ - 'message' => 'Data pengembalian tidak ditemukan', + 'message' => 'Tidak ada data terakhir dengan peti_id, status 0 yang memenuhi kriteria', ], '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 - ]); + // Lakukan pembaruan hanya jika status-nya 0 + if ($lastPetiData->status == 0) { + $lastPetiData->update([ + 'enter_at' => $request->enter_at, + 'enter_pic' => $request->enter_pic, + 'enter_warehouse' => $request->enter_warehouse, + 'kondisi_peti_id' => $request->kondisi_peti_id, + 'updated_by' => $request->updated_by, + ]); + + // Ubah status menjadi 1 setelah pembaruan berhasil + $lastPetiData->update(['status' => 1]); + + return ResponseFormatter::success([ + 'message' => 'Data pengembalian berhasil diupdate', + 'asset_status' => $lastPetiData + ]); + } else { + return ResponseFormatter::error([ + 'message' => 'Data tidak dapat diupdate karena status bukan 0', + ], 'Invalid Status', 400); + } } } - - - // 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/Http/Controllers/API/v1/PetiApi/PetiApiController.php b/app/Http/Controllers/API/v1/PetiApi/PetiApiController.php index b2196d7..201c443 100644 --- a/app/Http/Controllers/API/v1/PetiApi/PetiApiController.php +++ b/app/Http/Controllers/API/v1/PetiApi/PetiApiController.php @@ -11,9 +11,12 @@ class PetiApiController extends Controller public function index() { $petis = \App\Models\Peti::with([ - 'customer:id,name,code_customer,lot_no,nip,no_hp,tgl_lahir,jenis_kelamin,agama,address', - 'tipe_peti:id,type,size_peti,description', - 'warehouse:id,name,address', + // 'customer:id,name,code_customer,lot_no,nip,no_hp,tgl_lahir,jenis_kelamin,agama,address', + // 'tipe_peti:id,type,size_peti,description', + // 'warehouse:id,name,address', + 'customer', + 'tipe_peti', + 'warehouse', ])->get(); if (!$petis) { diff --git a/app/Http/Controllers/API/v1/TipePetiApi/TipePetiApiController.php b/app/Http/Controllers/API/v1/TipePetiApi/TipePetiApiController.php new file mode 100644 index 0000000..6884957 --- /dev/null +++ b/app/Http/Controllers/API/v1/TipePetiApi/TipePetiApiController.php @@ -0,0 +1,21 @@ + true, + 'message' => 'Data warehouse berhasil diambil', + 'tipe_peti' => $tipePeti + ]); + } +} diff --git a/composer.lock b/composer.lock index 7a0b2f8..dd75276 100644 --- a/composer.lock +++ b/composer.lock @@ -9591,5 +9591,5 @@ "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/routes/api.php b/routes/api.php index f301346..3b4f57c 100644 --- a/routes/api.php +++ b/routes/api.php @@ -32,7 +32,7 @@ Route::prefix('v1')->group(function () { Route::get('/asset-status/pengembalian', [App\Http\Controllers\API\v1\PengembalianApi\PengembalianBarangApiController::class, 'index'])->name('pengembalian-barang'); Route::get('/asset-status/pengembalian/create', [App\Http\Controllers\API\v1\PengembalianApi\PengembalianBarangApiController::class, 'create'])->name('pengembalian-barang.create'); - Route::put('/asset-status/update/{id}', [App\Http\Controllers\API\v1\PengembalianApi\PengembalianBarangApiController::class, 'update'])->name('pengembalian-barang.update'); + Route::post('/asset-status/update', [App\Http\Controllers\API\v1\PengembalianApi\PengembalianBarangApiController::class, 'update'])->name('pengembalian-barang.update'); Route::get('/asset-status/pengembalian/show/{id}', [App\Http\Controllers\API\v1\PengembalianApi\PengembalianBarangApiController::class, 'show'])->name('pengembalian-barang.show'); Route::get('/peti-asset', [App\Http\Controllers\API\v1\PetiApi\PetiApiController::class, 'index'])->name('peti.barang'); @@ -41,6 +41,12 @@ Route::prefix('v1')->group(function () { Route::put('/peti-asset/update/{id}', [App\Http\Controllers\API\v1\PetiApi\PetiApiController::class, 'update'])->name('peti.barang.update'); Route::get('/m-warehouse', [App\Http\Controllers\API\v1\WarehouseApi\WarehouseApiController::class, 'index'])->name('warehouse'); + + Route::get('/m-customer', [App\Http\Controllers\API\v1\CustomerApi\CustomerApiController::class, 'index'])->name('customer'); + + Route::get('/m-type-peti', [App\Http\Controllers\API\v1\TipePetiApi\TipePetiApiController::class, 'index'])->name('type-peti'); + + Route::get('/m-kondisi-peti', [App\Http\Controllers\API\v1\KondisiPetiApi\KondisiPetiApiController::class, 'index'])->name('kondisi-peti'); }); Route::middleware('auth:sanctum')->get('/user', function (Request $request) {