Browse Source

fix(remove):adw integration

pull/1/head
farhantock 7 months ago
parent
commit
f19fc03276
  1. 24
      app/Helpers/MasterFunctionsHelper.php
  2. 35
      app/Http/Controllers/DashboardBoDController.php
  3. 63
      app/Http/Controllers/ProjectController.php
  4. 56
      app/Http/Controllers/RequestMaterialController.php
  5. 55
      app/Http/Controllers/UserToProyekController.php

24
app/Helpers/MasterFunctionsHelper.php

@ -12,30 +12,6 @@ use DateTime;
class MasterFunctionsHelper 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);
}
public static function countDays($ganttId, $start, $end) public static function countDays($ganttId, $start, $end)
{ {
$dayOffs = VersionGantt::where('id', $ganttId)->first()->config_dayoff; $dayOffs = VersionGantt::where('id', $ganttId)->first()->config_dayoff;

35
app/Http/Controllers/DashboardBoDController.php

@ -25,42 +25,7 @@ class DashboardBoDController extends Controller
return $year; return $year;
} }
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);
}
private function getInvoiceIntegration($search)
{
if (empty($search))
return response()->json(['status' => 'error', 'message' => 'Empty query string!'], 400);
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');
$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 == "")
if (@$response->data->project_no == "")
return null;
return $response;
}
public function getCompanyCashFlow($company_id, $all_project, $hierarchy, $role_name) public function getCompanyCashFlow($company_id, $all_project, $hierarchy, $role_name)
{ {

63
app/Http/Controllers/ProjectController.php

@ -5,10 +5,41 @@ namespace App\Http\Controllers;
use DateTime; use DateTime;
use App\Jobs\ProcessSCurve; use App\Jobs\ProcessSCurve;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\{ReportActivityMaterial,ProjectToChecklistK3,FolderDocumentProyek,ProjectParticipants,ProductTransaction,ProjectChecklists, use App\Models\{
ProjectMileStone,RequestMaterial,ProjectApproval,CommentActivity,ActivityDokumen,UserToActivity,ShowHideColumn,ReportActivity,ProjectCharter,DokumenProject, ReportActivityMaterial,
AssignMaterial,ProjectIssues,HierarchyFtth,VersionGantt,UserToProyek,ProjectRisks,ProjectPhase,ProjectType,OfficeHours,AssignTools,ReportK3,Activity,Project, ProjectToChecklistK3,
Holiday,Company,Image,User,Link FolderDocumentProyek,
ProjectParticipants,
ProductTransaction,
ProjectChecklists,
ProjectMileStone,
RequestMaterial,
ProjectApproval,
CommentActivity,
ActivityDokumen,
UserToActivity,
ShowHideColumn,
ReportActivity,
ProjectCharter,
DokumenProject,
AssignMaterial,
ProjectIssues,
HierarchyFtth,
VersionGantt,
UserToProyek,
ProjectRisks,
ProjectPhase,
ProjectType,
OfficeHours,
AssignTools,
ReportK3,
Activity,
Project,
Holiday,
Company,
Image,
User,
Link
}; };
use Illuminate\Database\Query\Builder; use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\{Artisan, DB}; use Illuminate\Support\Facades\{Artisan, DB};
@ -85,8 +116,7 @@ class ProjectController extends Controller
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
} }
$result = Project:: $result = Project::select(
select(
'value_proyek', 'value_proyek',
'scoupe_of_work', 'scoupe_of_work',
'kode_sortname', 'kode_sortname',
@ -398,7 +428,6 @@ class ProjectController extends Controller
} else { } else {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
} }
} }
public function getSCurve(Request $request) public function getSCurve(Request $request)
@ -561,27 +590,7 @@ class ProjectController extends Controller
return response()->json(['status' => 'success', 'message' => 'Set baseline activity success!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Set baseline activity success!', 'code' => 200], 200);
} }
public function getInvoiceIntegration(Request $request)
{
DB::beginTransaction();
try {
$ganttCount = VersionGantt::where('proyek_id', $request->id)->count();
$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');
$response = MasterFunctionsHelper::curlReq($url);
if (isset($request->gantt_id)) {
$response->data->total_cost = $response->data->total_cost / $ganttCount;
}
DB::commit();
return response()->json(['status' => 'success', 'data' => $response, 'code' => 200], 200);
} catch (\Throwable $th) {
DB::rollBack();
}
}
public function getByUser($id) public function getByUser($id)
{ {
$userProyek = UserToProyek::query() $userProyek = UserToProyek::query()

56
app/Http/Controllers/RequestMaterialController.php

@ -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);
}
} }

55
app/Http/Controllers/UserToProyekController.php

@ -31,7 +31,8 @@ class UserToProyekController extends Controller
} }
} }
public function addMultiple(Request $request){ public function addMultiple(Request $request)
{
$user_IDs = $request->user_id; $user_IDs = $request->user_id;
$data = UserToProyek::where([ $data = UserToProyek::where([
@ -71,10 +72,10 @@ class UserToProyekController extends Controller
} else { } else {
return response()->json(['status' => 'failed', 'message' => 'Project customer failed created', 'code' => 200]); return response()->json(['status' => 'failed', 'message' => 'Project customer failed created', 'code' => 200]);
} }
} }
public function edit($id){ public function edit($id)
{
if (!$id || (int) $id < 0 || $id == "") { if (!$id || (int) $id < 0 || $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);
die(); die();
@ -181,7 +182,8 @@ class UserToProyekController extends Controller
} }
} }
public function select(Request $request){ public function select(Request $request)
{
$search = $request->query('search'); $search = $request->query('search');
@ -214,49 +216,4 @@ class UserToProyekController extends Controller
return response()->json($data); return response()->json($data);
} }
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 getEmployeeIntegration(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').'/employees?emp_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;
return response()->json([$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 < $firstResponse->last_page);
}
return response()->json(['status'=>'success', 'data'=> $data, 'total' => count($data), 'code'=>200], 200);
}
} }

Loading…
Cancel
Save