diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 1351b7a..24ba04b 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -408,9 +408,9 @@ class ProjectController extends Controller $currentACWP = 0; $currentBCWP = 0; - foreach($period as $x){ - echo $x->format("Y-m-d")."\n"; - } exit(); + /* foreach($period as $x){ */ + /* echo $x->format("Y-m-d")."\n"; */ + /* } exit(); */ foreach ($period as $dt) { $minSevenDays = new \Datetime($dt->format("Y-m-d")); $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); @@ -761,5 +761,35 @@ class ProjectController extends Controller return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 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 getInvoiceIntegration(Request $request) { + $search = urlencode($request->search); + if(empty($search)) + return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); + $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); + $token = config('api.adw_token'); + $response = $this->curlReq($url, $token); + + if($response->data->project_no == "") + return response()->json(['status'=>'error', 'message' => 'Project '.$search.' not found!', 'code'=>404], 404); + + return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); + } }