|
|
|
@ -2,11 +2,14 @@
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API\v1\PeminjamanApi; |
|
|
|
|
|
|
|
|
|
use App\Models\BarangMasuk; |
|
|
|
|
use App\Models\asset_status; |
|
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
use App\Helpers\ResponseFormatter; |
|
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
use Illuminate\Support\Facades\Log; |
|
|
|
|
use App\Http\Controllers\Controller; |
|
|
|
|
use App\Models\asset_status; |
|
|
|
|
use App\Models\BarangMasuk; |
|
|
|
|
use Illuminate\Database\QueryException; |
|
|
|
|
|
|
|
|
|
class PeminjamanApiController extends Controller |
|
|
|
|
{ |
|
|
|
@ -54,54 +57,132 @@ 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) |
|
|
|
|
{ |
|
|
|
|
$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'); |
|
|
|
|
// $status = $request->input('status'); |
|
|
|
|
$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->status = $status; |
|
|
|
|
$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->status = $status; |
|
|
|
|
$newRecord->created_by = $created_by; |
|
|
|
|
$newRecord->created_at = $created_at; |
|
|
|
|
$newRecord->save(); |
|
|
|
|
return ResponseFormatter::success([ |
|
|
|
|
'message' => 'Data peminjaman berhasil ditambahkan', |
|
|
|
|
'peminjam' => $newRecord |
|
|
|
|
try { |
|
|
|
|
DB::beginTransaction(); |
|
|
|
|
|
|
|
|
|
$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) { |
|
|
|
|
$data = [ |
|
|
|
|
'exit_at' => $exit_at, |
|
|
|
|
'exit_pic' => $exit_pic, |
|
|
|
|
'exit_warehouse' => $exit_warehouse, |
|
|
|
|
'est_pengembalian' => $est_pengembalian, |
|
|
|
|
'created_by' => $created_by, |
|
|
|
|
'created_at' => $created_at, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
asset_status::where('mobile_id', $mobile_id) |
|
|
|
|
->where('peti_id', $peti_id) |
|
|
|
|
->update($data); |
|
|
|
|
|
|
|
|
|
DB::commit(); |
|
|
|
|
|
|
|
|
|
return ResponseFormatter::success([ |
|
|
|
|
'message' => 'Data peminjaman berhasil diupdate', |
|
|
|
|
'peminjam' => asset_status::where('mobile_id', $mobile_id) |
|
|
|
|
->where('peti_id', $peti_id) |
|
|
|
|
->first(), |
|
|
|
|
]); |
|
|
|
|
} else { |
|
|
|
|
$data = [ |
|
|
|
|
'mobile_id' => $mobile_id, |
|
|
|
|
'peti_id' => $peti_id, |
|
|
|
|
'customer_id' => $customer_id, |
|
|
|
|
'warehouse_id' => $warehouse_id, |
|
|
|
|
'exit_at' => $exit_at, |
|
|
|
|
'exit_pic' => $exit_pic, |
|
|
|
|
'exit_warehouse' => $exit_warehouse, |
|
|
|
|
'est_pengembalian' => $est_pengembalian, |
|
|
|
|
'created_by' => $created_by, |
|
|
|
|
'created_at' => $created_at, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
asset_status::create($data); |
|
|
|
|
|
|
|
|
|
DB::commit(); |
|
|
|
|
|
|
|
|
|
return ResponseFormatter::success([ |
|
|
|
|
'message' => 'Data peminjaman berhasil ditambahkan', |
|
|
|
|
'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() |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|