Browse Source

add method

pull/1/head
wahyuun 10 months ago
parent
commit
22e17bdf6d
  1. 54
      app/Http/Controllers/ProductTransactionController.php

54
app/Http/Controllers/ProductTransactionController.php

@ -22,9 +22,59 @@ class ProductTransactionController extends Controller
$result = ProductTransaction::create($data);
if ($result) {
return response()->json(['status' => 'success','data' => $result, 'message' => 'Add Transaction successfully!', 'code' => 200], 200);
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);
}
}

Loading…
Cancel
Save