|
|
@ -2,11 +2,14 @@ |
|
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API\v1\PeminjamanApi; |
|
|
|
namespace App\Http\Controllers\API\v1\PeminjamanApi; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use App\Models\BarangMasuk; |
|
|
|
|
|
|
|
use App\Models\asset_status; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
use App\Helpers\ResponseFormatter; |
|
|
|
use App\Helpers\ResponseFormatter; |
|
|
|
|
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
use App\Http\Controllers\Controller; |
|
|
|
use App\Http\Controllers\Controller; |
|
|
|
use App\Models\asset_status; |
|
|
|
use Illuminate\Database\QueryException; |
|
|
|
use App\Models\BarangMasuk; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PeminjamanApiController extends Controller |
|
|
|
class PeminjamanApiController extends Controller |
|
|
|
{ |
|
|
|
{ |
|
|
@ -54,8 +57,61 @@ class PeminjamanApiController extends Controller |
|
|
|
]); |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public function store(Request $request) |
|
|
|
|
|
|
|
// { |
|
|
|
|
|
|
|
// $mobile_id = $request->input('mobile_id'); |
|
|
|
|
|
|
|
// $peti_id = $request->input('peti_id'); |
|
|
|
|
|
|
|
// $customer_id = $request->input('customer_id'); |
|
|
|
|
|
|
|
// $warehouse_id = $request->input('warehouse_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'); |
|
|
|
|
|
|
|
// $created_by = $request->input('created_by'); |
|
|
|
|
|
|
|
// $created_at = $request->input('created_at'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $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->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->customer_id = $customer_id; |
|
|
|
|
|
|
|
// $newRecord->warehouse_id = $warehouse_id; |
|
|
|
|
|
|
|
// $newRecord->exit_at = $exit_at; |
|
|
|
|
|
|
|
// $newRecord->exit_pic = $exit_pic; |
|
|
|
|
|
|
|
// $newRecord->exit_warehouse = $exit_warehouse; |
|
|
|
|
|
|
|
// $newRecord->est_pengembalian = $est_pengembalian; |
|
|
|
|
|
|
|
// $newRecord->created_by = $created_by; |
|
|
|
|
|
|
|
// $newRecord->created_at = $created_at; |
|
|
|
|
|
|
|
// $newRecord->save(); |
|
|
|
|
|
|
|
// return ResponseFormatter::success([ |
|
|
|
|
|
|
|
// 'message' => 'Data peminjaman berhasil ditambahkan', |
|
|
|
|
|
|
|
// 'peminjam' => $newRecord |
|
|
|
|
|
|
|
// ]); |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function store(Request $request) |
|
|
|
public function store(Request $request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
DB::beginTransaction(); |
|
|
|
|
|
|
|
|
|
|
|
$mobile_id = $request->input('mobile_id'); |
|
|
|
$mobile_id = $request->input('mobile_id'); |
|
|
|
$peti_id = $request->input('peti_id'); |
|
|
|
$peti_id = $request->input('peti_id'); |
|
|
|
$customer_id = $request->input('customer_id'); |
|
|
|
$customer_id = $request->input('customer_id'); |
|
|
@ -64,7 +120,6 @@ class PeminjamanApiController extends Controller |
|
|
|
$exit_pic = $request->input('exit_pic'); |
|
|
|
$exit_pic = $request->input('exit_pic'); |
|
|
|
$exit_warehouse = $request->input('exit_warehouse'); |
|
|
|
$exit_warehouse = $request->input('exit_warehouse'); |
|
|
|
$est_pengembalian = $request->input('est_pengembalian'); |
|
|
|
$est_pengembalian = $request->input('est_pengembalian'); |
|
|
|
// $status = $request->input('status'); |
|
|
|
|
|
|
|
$created_by = $request->input('created_by'); |
|
|
|
$created_by = $request->input('created_by'); |
|
|
|
$created_at = $request->input('created_at'); |
|
|
|
$created_at = $request->input('created_at'); |
|
|
|
|
|
|
|
|
|
|
@ -73,35 +128,61 @@ class PeminjamanApiController extends Controller |
|
|
|
->first(); |
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
|
|
if ($existingRecord) { |
|
|
|
if ($existingRecord) { |
|
|
|
$existingRecord->exit_at = $exit_at; |
|
|
|
$data = [ |
|
|
|
$existingRecord->exit_pic = $exit_pic; |
|
|
|
'exit_at' => $exit_at, |
|
|
|
$existingRecord->exit_warehouse = $exit_warehouse; |
|
|
|
'exit_pic' => $exit_pic, |
|
|
|
$existingRecord->est_pengembalian = $est_pengembalian; |
|
|
|
'exit_warehouse' => $exit_warehouse, |
|
|
|
// $existingRecord->status = $status; |
|
|
|
'est_pengembalian' => $est_pengembalian, |
|
|
|
$existingRecord->created_by = $created_by; |
|
|
|
'created_by' => $created_by, |
|
|
|
$existingRecord->created_at = $created_at; |
|
|
|
'created_at' => $created_at, |
|
|
|
$existingRecord->save(); |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
asset_status::where('mobile_id', $mobile_id) |
|
|
|
|
|
|
|
->where('peti_id', $peti_id) |
|
|
|
|
|
|
|
->update($data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DB::commit(); |
|
|
|
|
|
|
|
|
|
|
|
return ResponseFormatter::success([ |
|
|
|
return ResponseFormatter::success([ |
|
|
|
'message' => 'Data peminjaman berhasil ditambahkan', |
|
|
|
'message' => 'Data peminjaman berhasil diupdate', |
|
|
|
'peminjam' => $existingRecord |
|
|
|
'peminjam' => asset_status::where('mobile_id', $mobile_id) |
|
|
|
|
|
|
|
->where('peti_id', $peti_id) |
|
|
|
|
|
|
|
->first(), |
|
|
|
]); |
|
|
|
]); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$newRecord = new asset_status; |
|
|
|
$data = [ |
|
|
|
$newRecord->mobile_id = $mobile_id; |
|
|
|
'mobile_id' => $mobile_id, |
|
|
|
$newRecord->peti_id = $peti_id; |
|
|
|
'peti_id' => $peti_id, |
|
|
|
$newRecord->customer_id = $customer_id; |
|
|
|
'customer_id' => $customer_id, |
|
|
|
$newRecord->warehouse_id = $warehouse_id; |
|
|
|
'warehouse_id' => $warehouse_id, |
|
|
|
$newRecord->exit_at = $exit_at; |
|
|
|
'exit_at' => $exit_at, |
|
|
|
$newRecord->exit_pic = $exit_pic; |
|
|
|
'exit_pic' => $exit_pic, |
|
|
|
$newRecord->exit_warehouse = $exit_warehouse; |
|
|
|
'exit_warehouse' => $exit_warehouse, |
|
|
|
$newRecord->est_pengembalian = $est_pengembalian; |
|
|
|
'est_pengembalian' => $est_pengembalian, |
|
|
|
// $newRecord->status = $status; |
|
|
|
'created_by' => $created_by, |
|
|
|
$newRecord->created_by = $created_by; |
|
|
|
'created_at' => $created_at, |
|
|
|
$newRecord->created_at = $created_at; |
|
|
|
]; |
|
|
|
$newRecord->save(); |
|
|
|
|
|
|
|
|
|
|
|
asset_status::create($data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DB::commit(); |
|
|
|
|
|
|
|
|
|
|
|
return ResponseFormatter::success([ |
|
|
|
return ResponseFormatter::success([ |
|
|
|
'message' => 'Data peminjaman berhasil ditambahkan', |
|
|
|
'message' => 'Data peminjaman berhasil ditambahkan', |
|
|
|
'peminjam' => $newRecord |
|
|
|
'peminjam' => asset_status::where('mobile_id', $mobile_id) |
|
|
|
|
|
|
|
->where('peti_id', $peti_id) |
|
|
|
|
|
|
|
->first(), |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (QueryException $e) { |
|
|
|
|
|
|
|
DB::rollBack(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Log the error for further investigation |
|
|
|
|
|
|
|
Log::error('Error processing request: ' . $e->getMessage()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResponseFormatter::error([ |
|
|
|
|
|
|
|
'message' => 'Error while processing the request.', |
|
|
|
|
|
|
|
'error' => $e->getMessage() |
|
|
|
]); |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|