Browse Source

Update: Api Peminjaman dan Pengembalian

master
unknown 1 year ago
parent
commit
3d5e12937d
  1. 5
      app/Http/Controllers/API/v1/AssetStatusApi/AssetStatusApiController.php
  2. 35
      app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php
  3. 83
      app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php
  4. 5
      app/Models/asset_status.php
  5. 1
      routes/api.php

5
app/Http/Controllers/API/v1/AssetStatusApi/AssetStatusApiController.php

@ -11,10 +11,9 @@ class AssetStatusApiController extends Controller
public function index() public function index()
{ {
$m_asset = \App\Models\Peti::with(['warehouse', 'tipe_peti', 'customer'])->get(); $m_asset = \App\Models\Peti::with(['warehouse', 'tipe_peti', 'customer'])->get();
return ResponseFormatter::success([ return ResponseFormatter::success([
'message' => 'Data asset berhasil diambil', 'message' => 'Data asset berhasil diambil',
'asset' => $m_asset 'asset' => $m_asset,
]); ], 200);
} }
} }

35
app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php

@ -12,11 +12,21 @@ class PeminjamanApiController extends Controller
{ {
public function index() 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([ return ResponseFormatter::success([
'message' => 'Data peminjaman berhasil diambil', '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) public function store(Request $request)
{ {
$this->validate($request, [ // $this->validate($request, [
'peti_id' => 'required', // 'peti_id' => 'required',
'exit_at' => 'required', // 'exit_at' => 'required',
'exit_pic' => 'required', // 'exit_pic' => 'required',
'exit_warehouse' => 'required', // 'exit_warehouse' => 'required',
'est_pengembalian' => 'required', // 'est_pengembalian' => 'required',
'created_by' => 'required', // 'kondisi_peti' => 'required',
'updated_by' => 'required', // 'created_by' => 'required',
]); // 'updated_by' => 'required',
// ]);
$peminjaman = asset_status::create([ $peminjaman = asset_status::create([
'peti_id' => $request->peti_id, 'peti_id' => $request->peti_id,
@ -49,7 +60,7 @@ class PeminjamanApiController extends Controller
'exit_warehouse' => $request->exit_warehouse, 'exit_warehouse' => $request->exit_warehouse,
'est_pengembalian' => $request->est_pengembalian, 'est_pengembalian' => $request->est_pengembalian,
'created_by' => $request->created_by, 'created_by' => $request->created_by,
'updated_by' => $request->updated_by, // 'updated_by' => $request->updated_by,
]); ]);
return ResponseFormatter::success([ return ResponseFormatter::success([

83
app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php

@ -0,0 +1,83 @@
<?php
namespace App\Http\Controllers\API\v1\PengembalianApi;
use Illuminate\Http\Request;
use App\Helpers\ResponseFormatter;
use App\Http\Controllers\Controller;
class PengembalianBarangApiController extends Controller
{
public function index()
{
$pengembalian = \App\Models\asset_status::with(['peti.customer', 'peti.tipe_peti', 'warehouse'])->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);
// }

5
app/Models/asset_status.php

@ -37,6 +37,11 @@ class asset_status extends Model
return $this->belongsTo(m_warehouse::class, 'exit_warehouse'); return $this->belongsTo(m_warehouse::class, 'exit_warehouse');
} }
public function warehouseEnter()
{
return $this->belongsTo(m_warehouse::class, 'enter_warehouse');
}
public function peti() public function peti()
{ {
return $this->belongsTo(Peti::class, 'peti_id'); return $this->belongsTo(Peti::class, 'peti_id');

1
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::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::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::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'); Route::get('/peti-asset', [App\Http\Controllers\API\v1\AssetStatusApi\AssetStatusApiController::class, 'index'])->name('peti.barang');

Loading…
Cancel
Save