|
|
@ -22,9 +22,91 @@ class ProductTransactionController extends Controller |
|
|
|
$result = ProductTransaction::create($data); |
|
|
|
$result = ProductTransaction::create($data); |
|
|
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
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 { |
|
|
|
} else { |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Add data Transaction failed!', 'code' => 400], 400); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Add data 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 delete($id) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$data = ProductTransaction::find($id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($data) { |
|
|
|
|
|
|
|
$delete = $data->delete(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'data Transaction not found!', 'code' => 400], 400); |
|
|
|
|
|
|
|
die(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($delete) { |
|
|
|
|
|
|
|
return response()->json(['status' => 'success', 'message' => 'data Transaction successfully deleted!', 'code' => 200], 200); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'data Transaction failed deleted!', '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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function list() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$data = ProductTransaction::all(); |
|
|
|
|
|
|
|
$countData = $data->count(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($data) { |
|
|
|
|
|
|
|
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'failed get list Transaction, please try again later!', 'code' => 400], 400); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|