diff --git a/app/Http/Controllers/API/v1/AssetStatusApi/AssetStatusApiController.php b/app/Http/Controllers/API/v1/AssetStatusApi/AssetStatusApiController.php deleted file mode 100644 index 291e9ee..0000000 --- a/app/Http/Controllers/API/v1/AssetStatusApi/AssetStatusApiController.php +++ /dev/null @@ -1,23 +0,0 @@ -get(); - return ResponseFormatter::success([ - 'message' => 'Data asset berhasil diambil', - '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 628d17a..3027fb6 100644 --- a/app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php +++ b/app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php @@ -19,28 +19,20 @@ class PeminjamanApiController extends Controller 'warehouseEnter' ])->get(); + // Menghapus atribut yang terkait dengan "enter" + foreach ($peminjaman as $peminjamanItem) { + unset($peminjamanItem->enter_at); + unset($peminjamanItem->enter_pic); + unset($peminjamanItem->enter_warehouse); + unset($peminjamanItem->kondisi_peti); + } + return ResponseFormatter::success([ 'message' => 'Data peminjaman berhasil diambil', 'asset_status' => $peminjaman, ]); } - // 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.tipe_peti:id,type,size_peti,description', - // 'warehouse', - // 'warehouseEnter' - // ])->paginate(10); - - // return ResponseFormatter::success([ - // 'message' => 'Data peminjaman berhasil diambil', - // 'asset_status' => $peminjaman, - // ]); - // } - - public function getWarehouseEnter() { $warehouse = \App\Models\m_warehouse::get(); diff --git a/app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php b/app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php index 8814028..2052f1d 100644 --- a/app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php +++ b/app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php @@ -8,7 +8,23 @@ use App\Http\Controllers\Controller; class PengembalianBarangApiController 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.tipe_peti:id,type,size_peti,description', + 'warehouse', + 'warehouseEnter' + ])->get(); + + return ResponseFormatter::success([ + 'message' => 'Data peminjaman berhasil diambil', + 'asset_status' => $peminjaman, + ]); + } + + public function create() { $pengembalian = \App\Models\asset_status::with([ 'peti.customer:id,name,code_customer,lot_no,nip,no_hp,tgl_lahir,jenis_kelamin,agama,address', diff --git a/app/Http/Controllers/API/v1/PetiApi/PetiApiController.php b/app/Http/Controllers/API/v1/PetiApi/PetiApiController.php new file mode 100644 index 0000000..b2196d7 --- /dev/null +++ b/app/Http/Controllers/API/v1/PetiApi/PetiApiController.php @@ -0,0 +1,93 @@ +get(); + + if (!$petis) { + return ResponseFormatter::error([ + 'message' => 'Data peti tidak ditemukan', + ], 'Data Not Found', 404); + } + + return ResponseFormatter::success([ + 'message' => 'Data peti berhasil diambil', + 'petis' => $petis, + ], 200); + } + + public function show($id) + { + $peti = \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', + ])->find($id); + + if (!$peti) { + return ResponseFormatter::error([ + 'message' => 'Data peti tidak ditemukan', + ], 'Data Not Found', 404); + } + + return ResponseFormatter::success([ + 'message' => 'Data peti berhasil diambil', + 'peti' => $peti, + ], 200); + } + + public function edit($id) + { + $peti = \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', + ])->find($id); + + if (!$peti) { + return ResponseFormatter::error([ + 'message' => 'Data peti tidak ditemukan', + ], 'Data Not Found', 404); + } + + return ResponseFormatter::success([ + 'message' => 'Data peti berhasil diambil', + 'petis' => $peti, + ], 200); + } + + public function update(Request $request, $id) + { + $peti = \App\Models\Peti::find($id); + + if (!$peti) { + return ResponseFormatter::error([ + 'message' => 'Data peti tidak ditemukan', + ], 'Data Not Found', 404); + } + + // $peti->update($request->all()); + + $peti->update([ + 'warehouse_id' => $request->warehouse_id, + 'updated_by' => $request->updated_by, + ]); + + return ResponseFormatter::success([ + 'message' => 'Data peti berhasil diupdate', + 'petis' => $peti, + ], 200); + } +} diff --git a/database/migrations/2023_10_23_075245_create_users_table.php b/database/migrations/2023_10_23_075245_create_users_table.php index 2e35b64..481ba44 100644 --- a/database/migrations/2023_10_23_075245_create_users_table.php +++ b/database/migrations/2023_10_23_075245_create_users_table.php @@ -25,7 +25,7 @@ return new class extends Migration $table->string('foto', 255)->nullable(); $table->string('jenis_kelamin', 20)->nullable(); $table->string('agama', 15)->nullable(); - $table->foreignId('role_id')->constrained('m_roles')->onDelete('cascade'); + $table->foreignId('role_id')->nullable()->constrained('m_roles')->onDelete('cascade')->nullable(); $table->bigInteger('warehouse_id')->unsigned()->nullable(); $table->foreign('warehouse_id')->references('id')->on('m_warehouses')->onDelete('set null'); $table->text('address')->nullable(); diff --git a/routes/api.php b/routes/api.php index ccb3529..f301346 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,5 +1,6 @@ group(function () { Route::get('/asset-status/peminjaman/show/{id}', [App\Http\Controllers\API\v1\PeminjamanApi\PeminjamanApiController::class, 'show'])->name('peminjaman-barang.show'); 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::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\AssetStatusApi\AssetStatusApiController::class, 'index'])->name('peti.barang'); + Route::get('/peti-asset', [App\Http\Controllers\API\v1\PetiApi\PetiApiController::class, 'index'])->name('peti.barang'); + Route::get('/peti-asset/show/{id}', [App\Http\Controllers\API\v1\PetiApi\PetiApiController::class, 'show'])->name('peti.barang.show'); + Route::get('/peti-asset/edit/{id}', [App\Http\Controllers\API\v1\PetiApi\PetiApiController::class, 'edit'])->name('peti.barang.edit'); + 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'); });