Browse Source

update API: kondisiPeti/TipePeti/CustimerApi

master
unknown 1 year ago
parent
commit
fcb092b5a8
  1. 21
      app/Http/Controllers/API/v1/CustomerApi/CustomerApiController.php
  2. 20
      app/Http/Controllers/API/v1/KondisiPetiApi/KondisiPetiApiController.php
  3. 62
      app/Http/Controllers/API/v1/PeminjamanApi/PeminjamanApiController.php
  4. 66
      app/Http/Controllers/API/v1/PengembalianApi/PengembalianBarangApiController.php
  5. 9
      app/Http/Controllers/API/v1/PetiApi/PetiApiController.php
  6. 21
      app/Http/Controllers/API/v1/TipePetiApi/TipePetiApiController.php
  7. 2
      composer.lock
  8. 8
      routes/api.php

21
app/Http/Controllers/API/v1/CustomerApi/CustomerApiController.php

@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers\API\v1\CustomerApi;
use Illuminate\Http\Request;
use App\Helpers\ResponseFormatter;
use App\Http\Controllers\Controller;
class CustomerApiController extends Controller
{
public function index()
{
$customers = \App\Models\customer::select('id', 'name', 'code_customer', 'lot_no', 'no_tlp', 'address', 'created_by', 'updated_by')->orderBy('created_at', 'DESC')->get();
return ResponseFormatter::success([
'status' => true,
'message' => 'Data warehouse berhasil diambil',
'customers' => $customers
], 200);
}
}

20
app/Http/Controllers/API/v1/KondisiPetiApi/KondisiPetiApiController.php

@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\API\v1\KondisiPetiApi;
use Illuminate\Http\Request;
use App\Helpers\ResponseFormatter;
use App\Http\Controllers\Controller;
class KondisiPetiApiController extends Controller
{
public function index()
{
$kondisi = \App\Models\kondisi_peti::get();
return ResponseFormatter::success([
'message' => 'Data kondisi peti berhasil diambil',
'kondisi_peti' => $kondisi,
]);
}
}

62
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();
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' => $peminjaman
'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
]);
}
}
}

66
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([
// 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' => $request->kondisi_peti,
'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' => $pengembalian
'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);
// }

9
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) {

21
app/Http/Controllers/API/v1/TipePetiApi/TipePetiApiController.php

@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers\API\v1\TipePetiApi;
use Illuminate\Http\Request;
use App\Helpers\ResponseFormatter;
use App\Http\Controllers\Controller;
class TipePetiApiController extends Controller
{
public function index()
{
$tipePeti = \App\Models\Type_peti::get();
return ResponseFormatter::success([
'status' => true,
'message' => 'Data warehouse berhasil diambil',
'tipe_peti' => $tipePeti
]);
}
}

2
composer.lock generated

@ -9591,5 +9591,5 @@
"php": "^8.1"
},
"platform-dev": [],
"plugin-api-version": "2.6.0"
"plugin-api-version": "2.3.0"
}

8
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) {

Loading…
Cancel
Save