|
|
@ -8,13 +8,15 @@ use App\Models\MaterialResource; |
|
|
|
|
|
|
|
|
|
|
|
class RequestMaterialController extends Controller |
|
|
|
class RequestMaterialController extends Controller |
|
|
|
{ |
|
|
|
{ |
|
|
|
private function sanitizeDecimal($number) { |
|
|
|
private function sanitizeDecimal($number) |
|
|
|
|
|
|
|
{ |
|
|
|
$number = str_replace(".", "", $number); |
|
|
|
$number = str_replace(".", "", $number); |
|
|
|
$number = str_replace(",", ".", $number); |
|
|
|
$number = str_replace(",", ".", $number); |
|
|
|
return $number; |
|
|
|
return $number; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function add(Request $request){ |
|
|
|
public function add(Request $request) |
|
|
|
|
|
|
|
{ |
|
|
|
$this->validate($request, [ |
|
|
|
$this->validate($request, [ |
|
|
|
'proyek_id' => 'required', |
|
|
|
'proyek_id' => 'required', |
|
|
|
'description' => 'required', |
|
|
|
'description' => 'required', |
|
|
@ -38,7 +40,8 @@ class RequestMaterialController extends Controller |
|
|
|
return response()->json(['status' => 'success', 'message' => 'Data added!', 'data' => $result, 'code' => 200], 200); |
|
|
|
return response()->json(['status' => 'success', 'message' => 'Data added!', 'data' => $result, 'code' => 200], 200); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function edit($id){ |
|
|
|
public function edit($id) |
|
|
|
|
|
|
|
{ |
|
|
|
if (empty($id) || !is_int((int)$id)) |
|
|
|
if (empty($id) || !is_int((int)$id)) |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
|
|
|
|
|
|
|
|
|
|
@ -151,51 +154,4 @@ class RequestMaterialController extends Controller |
|
|
|
|
|
|
|
|
|
|
|
return response()->json(['status' => 'success', 'message' => 'request material successfully updated!', 'code' => 200], 200); |
|
|
|
return response()->json(['status' => 'success', 'message' => 'request material successfully updated!', 'code' => 200], 200); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private function curlReq($url, $token){ |
|
|
|
|
|
|
|
$ch = curl_init(); |
|
|
|
|
|
|
|
$headers = [ |
|
|
|
|
|
|
|
'Authorization: '.$token |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response = curl_exec($ch); |
|
|
|
|
|
|
|
if ($response === false) |
|
|
|
|
|
|
|
$response = curl_error($ch); |
|
|
|
|
|
|
|
curl_close($ch); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return json_decode($response); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getMaterialIntegration(Request $request) { |
|
|
|
|
|
|
|
$search = urlencode($request->name); |
|
|
|
|
|
|
|
if(empty($search)) |
|
|
|
|
|
|
|
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); |
|
|
|
|
|
|
|
$url = str_replace("SEARCH", $search, config('api.adw').'/stock_master?name=SEARCH'); |
|
|
|
|
|
|
|
$token = config('api.adw_token'); |
|
|
|
|
|
|
|
$firstResponse = $this->curlReq($url, $token); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($firstResponse->total == 0) |
|
|
|
|
|
|
|
return response()->json(['status'=>'error', 'message' => 'Data not found!', 'code'=>404], 404); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data = $firstResponse->data; |
|
|
|
|
|
|
|
$currentPage = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($firstResponse->last_page > 0) { |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
$currentPage++; |
|
|
|
|
|
|
|
$response = $this->curlReq($url.'&page='.$currentPage, $token); |
|
|
|
|
|
|
|
foreach($response->data as $d){ |
|
|
|
|
|
|
|
array_push($data, $d); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} while ($currentPage < 5); |
|
|
|
|
|
|
|
// let the user narrow down the search by themself |
|
|
|
|
|
|
|
// a searching action with 'cable' keyword could take minutes |
|
|
|
|
|
|
|
// because there are >1k items associated with that keyword |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response()->json(['status'=>'success', 'data'=> $data, 'total' => count($data), 'code'=>200], 200); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|