|
|
|
<?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()
|
|
|
|
{
|
|
|
|
$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',
|
|
|
|
'peti.tipe_peti:id,type,size_peti,description',
|
|
|
|
'warehouse',
|
|
|
|
'warehouseEnter'
|
|
|
|
])
|
|
|
|
->where('updated_by', '=', null)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
return ResponseFormatter::success([
|
|
|
|
'message' => 'Data peminjaman berhasil diambil',
|
|
|
|
'asset_status' => $pengembalian,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function show($id)
|
|
|
|
{
|
|
|
|
$pengembalian = \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'
|
|
|
|
])->find($id);
|
|
|
|
|
|
|
|
if (!$pengembalian) {
|
|
|
|
return ResponseFormatter::error([
|
|
|
|
'message' => 'Data pengembalian tidak ditemukan',
|
|
|
|
], 'Data Not Found', 404);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
// }
|