|
|
|
@ -24,7 +24,57 @@ class ProductTransactionController extends Controller
|
|
|
|
|
if ($result) { |
|
|
|
|
return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Add Transaction successfully!', 'code' => 200], 200); |
|
|
|
|
} else { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Add data Transaction failed!', 'code' => 400], 400); |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Add Transaction failed!', 'code' => 400], 400); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function edit($id) |
|
|
|
|
{ |
|
|
|
|
if (!$id || (int) $id < 0 || $id == "") { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400); |
|
|
|
|
die(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$result = ProductTransaction::find($id); |
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); |
|
|
|
|
} else { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Failed get data transaction, please try again later!', 'code' => 400], 400); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function update(Request $request, $id) |
|
|
|
|
{ |
|
|
|
|
if(!$id || (int) $id < 0 || $id==""){ |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$data = ProductTransaction::find($id); |
|
|
|
|
|
|
|
|
|
if($data){ |
|
|
|
|
$result = $data->update($request->all()); |
|
|
|
|
}else{ |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Data transaction not found!','code'=>400], 400); |
|
|
|
|
die(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($result){ |
|
|
|
|
return response()->json(['status'=>'success','message'=>'Data transaction successfully updated!','code'=>200], 200); |
|
|
|
|
}else{ |
|
|
|
|
return response()->json(['status'=>'failed','message'=>'Data transaction failed updated!','code'=>400], 400); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function search(Request $request) |
|
|
|
|
{ |
|
|
|
|
$payload = $request->all(); |
|
|
|
|
$dataBuilder = $this->setUpPayload($payload, 't_transaction'); |
|
|
|
|
$builder = $dataBuilder['builder']; |
|
|
|
|
$countBuilder = $dataBuilder['count']; |
|
|
|
|
$dataGet = $builder->get(); |
|
|
|
|
$totalRecord = $countBuilder->count(); |
|
|
|
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|