Browse Source

move curl req to helper

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
4272c9062e
  1. 32
      app/Helpers/MasterFunctionsHelper.php
  2. 2
      app/Http/Controllers/ActivityController.php
  3. 44
      app/Http/Controllers/ProjectController.php
  4. 3
      composer.json

32
app/Helpers/MasterFunctionsHelper.php

@ -0,0 +1,32 @@
<?php
namespace App\Helpers;
class MasterFunctionsHelper {
public static function curlReq($url, $token = ""){
if(!$token)
$token = config('api.adw_token');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$headers = [
'Authorization: '.$token
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w'));
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output);
}
}

2
app/Http/Controllers/ActivityController.php

@ -57,7 +57,7 @@ class ActivityController extends Controller
$objRow->end_date = date_format($endDate,"Y-m-d H:i:s");
$objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start),"Y-m-d H:i:s") : NULL;
$objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end),"Y-m-d H:i:s") : NULL;
$objRow->progress = (int) $objRow->persentase_progress / 100;
$objRow->progress = $objRow->persentase_progress / 100;
$objRow->type = $type;
$finalData[] = $objRow;
$finalData = array_merge($finalData, $dataChildren);

44
app/Http/Controllers/ProjectController.php

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Helpers\MasterFunctionsHelper;
use App\Models\Activity;
use App\Models\ActivityDokumen;
use App\Models\AssignMaterial;
@ -262,12 +263,7 @@ class ProjectController extends Controller
->where('m_proyek.id', $d->id)
->pluck('m_users.name')
->first();
if($d->area_kerja != ''){
$d->geolocation = $this->httpReq($d->area_kerja);
$d->geolocation = [];
} else {
$d->geolocation = [];
}
$d->geolocation = [];
}
$totalPlannedCost = $data->sum('plannedCost');
@ -313,21 +309,6 @@ class ProjectController extends Controller
], 200);
}
private function httpReq($search){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w'));
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output);
}
private function getLatestGantt($id){
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
$data = array(
@ -674,30 +655,13 @@ 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);
$response = MasterFunctionsHelper::curlReq($url);
if($response->data->project_no == "")
return response()->json(['status'=>'error', 'message' => 'Project '.$search.' not found!', 'code'=>404], 404);

3
composer.json

@ -18,6 +18,9 @@
"phpunit/phpunit": "^9.5.10"
},
"autoload": {
"files": [
"app/Helpers/MasterFunctionsHelper.php"
],
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",

Loading…
Cancel
Save