Browse Source

fix(remove):adw integration

pull/1/head
farhantock 4 months ago
parent
commit
f19fc03276
  1. 24
      app/Helpers/MasterFunctionsHelper.php
  2. 69
      app/Http/Controllers/DashboardBoDController.php
  3. 101
      app/Http/Controllers/ProjectController.php
  4. 140
      app/Http/Controllers/RequestMaterialController.php
  5. 171
      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;

69
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)
{ {
@ -288,18 +253,18 @@ class DashboardBoDController extends Controller
'on-schedule' => 0, 'on-schedule' => 0,
]; ];
$divisi = Divisi::query() $divisi = Divisi::query()
->where('company_id',$company_id) ->where('company_id', $company_id)
->pluck('id'); ->pluck('id');
$projects = null; $projects = null;
if ($role === 'Super Admin') { if ($role === 'Super Admin') {
$projects = Project::get(); $projects = Project::get();
} elseif ($all_project == 'true') { } elseif ($all_project == 'true') {
$projects = Project::whereIn('divisi_id',$divisi) $projects = Project::whereIn('divisi_id', $divisi)
->where('company_id', $company_id) ->where('company_id', $company_id)
->get(); ->get();
} else { } else {
$projects = Project::whereIn('divisi_id',$divisi) $projects = Project::whereIn('divisi_id', $divisi)
->where('created_by_id', $replaceHierarchy) ->where('created_by_id', $replaceHierarchy)
->get(); ->get();
} }
@ -401,7 +366,7 @@ class DashboardBoDController extends Controller
] ]
]; ];
$divisi = Divisi::query() $divisi = Divisi::query()
->where('company_id',$company_id) ->where('company_id', $company_id)
->pluck('id'); ->pluck('id');
// arr overrun // arr overrun
@ -409,12 +374,12 @@ class DashboardBoDController extends Controller
$response['data']['overrun'] = Project::where('budget_health', 'overrun') $response['data']['overrun'] = Project::where('budget_health', 'overrun')
->count(); ->count();
} elseif ($all_project == 'true') { } elseif ($all_project == 'true') {
$response['data']['overrun'] = Project::whereIn('divisi_id',$divisi) $response['data']['overrun'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'overrun'],['company_id', $company_id]]) ->where([['budget_health', 'overrun'], ['company_id', $company_id]])
->count(); ->count();
} else { } else {
$response['data']['overrun'] = Project::whereIn('divisi_id',$divisi) $response['data']['overrun'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'overrun'],['created_by_id', $replaceHierarchy]]) ->where([['budget_health', 'overrun'], ['created_by_id', $replaceHierarchy]])
->count(); ->count();
} }
// arr warning // arr warning
@ -422,12 +387,12 @@ class DashboardBoDController extends Controller
$response['data']['warning'] = Project::where('budget_health', 'warning') $response['data']['warning'] = Project::where('budget_health', 'warning')
->count(); ->count();
} elseif ($all_project == 'true') { } elseif ($all_project == 'true') {
$response['data']['warning'] = Project::whereIn('divisi_id',$divisi) $response['data']['warning'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'warning'],['company_id', $company_id]]) ->where([['budget_health', 'warning'], ['company_id', $company_id]])
->count(); ->count();
} else { } else {
$response['data']['warning'] = Project::whereIn('divisi_id',$divisi) $response['data']['warning'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'warning'],['created_by_id', $replaceHierarchy]]) ->where([['budget_health', 'warning'], ['created_by_id', $replaceHierarchy]])
->count(); ->count();
} }
// arr on-budget // arr on-budget
@ -435,12 +400,12 @@ class DashboardBoDController extends Controller
$response['data']['on-budget'] = Project::where('budget_health', 'on-budget') $response['data']['on-budget'] = Project::where('budget_health', 'on-budget')
->count(); ->count();
} elseif ($all_project == 'true') { } elseif ($all_project == 'true') {
$response['data']['on-budget'] = Project::whereIn('divisi_id',$divisi) $response['data']['on-budget'] = Project::whereIn('divisi_id', $divisi)
->where([['company_id', $company_id],['budget_health', 'on-budget']]) ->where([['company_id', $company_id], ['budget_health', 'on-budget']])
->count(); ->count();
} else { } else {
$response['data']['on-budget'] = Project::whereIn('divisi_id',$divisi) $response['data']['on-budget'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'on-budget'],['created_by_id', $replaceHierarchy]]) ->where([['budget_health', 'on-budget'], ['created_by_id', $replaceHierarchy]])
->count(); ->count();
} }
return response()->json($response, 200); return response()->json($response, 200);
@ -448,7 +413,7 @@ class DashboardBoDController extends Controller
private function countTotalProjectByBudgetHealthInDivision($divisi, $health) private function countTotalProjectByBudgetHealthInDivision($divisi, $health)
{ {
$project = Project::where([['divisi_id', $divisi],['budget_health', $health]])->count(); $project = Project::where([['divisi_id', $divisi], ['budget_health', $health]])->count();
return $project; return $project;
} }

101
app/Http/Controllers/ProjectController.php

@ -5,13 +5,44 @@ 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};
use App\Helpers\MasterFunctionsHelper; use App\Helpers\MasterFunctionsHelper;
use Carbon\Carbon; use Carbon\Carbon;
@ -49,25 +80,25 @@ class ProjectController extends Controller
->selectRaw('count(*) as total_project') ->selectRaw('count(*) as total_project')
->where('company_id', $request->company_id) ->where('company_id', $request->company_id)
->first(); ->first();
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) { if ($transaction->where([['type_paket', 'Basic'], ['amount', '!=', null]])->exists()) {
if($projectResult['total_project'] < 10) { if ($projectResult['total_project'] < 10) {
$countCreate = true; $countCreate = true;
} }
} elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) { } elseif ($cloneQueryTransaction->where([['type_paket', 'Free'], ['amount', 0]])->exists()) {
if($projectResult['total_project'] < 1) { if ($projectResult['total_project'] < 1) {
$countCreate = true; $countCreate = true;
} }
} else { } else {
$countCreate = true; $countCreate = true;
} }
if($countCreate) { if ($countCreate) {
$result = Project::create($data); $result = Project::create($data);
if (!$result) { if (!$result) {
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500);
} else { } else {
$this->createOfficeHours($result['id']); $this->createOfficeHours($result['id']);
$dataResultInsert = Project::where([['nama', $data['nama']],['mulai_proyek', $data['mulai_proyek']]])->first(); $dataResultInsert = Project::where([['nama', $data['nama']], ['mulai_proyek', $data['mulai_proyek']]])->first();
DB::commit(); DB::commit();
return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200);
} }
@ -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',
@ -198,7 +228,7 @@ class ProjectController extends Controller
private function deleteRelative($project_id, $company_id) private function deleteRelative($project_id, $company_id)
{ {
DB::transaction(function() use($project_id, $company_id) { DB::transaction(function () use ($project_id, $company_id) {
UserToProyek::where('proyek_id', $project_id)->delete(); UserToProyek::where('proyek_id', $project_id)->delete();
UserToActivity::where('proyek_id', $project_id)->delete(); UserToActivity::where('proyek_id', $project_id)->delete();
AssignMaterial::where('proyek_id', $project_id)->delete(); AssignMaterial::where('proyek_id', $project_id)->delete();
@ -217,19 +247,19 @@ class ProjectController extends Controller
RequestMaterial::where('proyek_id', $project_id)->delete(); RequestMaterial::where('proyek_id', $project_id)->delete();
$this->deleteVersionGantt($project_id, $company_id); $this->deleteVersionGantt($project_id, $company_id);
$this->deleteDokumenProject($project_id, $company_id); $this->deleteDokumenProject($project_id, $company_id);
},5); }, 5);
} }
private function deleteVersionGantt($project_id, $company_id) private function deleteVersionGantt($project_id, $company_id)
{ {
DB::transaction(function() use($project_id, $company_id) { DB::transaction(function () use ($project_id, $company_id) {
$dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); $dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id");
$vhIds = $dataVg->all(); $vhIds = $dataVg->all();
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); $activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id');
$activityIds = $activity->all(); $activityIds = $activity->all();
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); $dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get();
$company = Company::find($company_id); $company = Company::find($company_id);
if($company) { if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataRa as $ra) { foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
@ -255,15 +285,15 @@ class ProjectController extends Controller
ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete();
Activity::whereIn("version_gantt_id", $vhIds)->delete(); Activity::whereIn("version_gantt_id", $vhIds)->delete();
ReportActivity::whereIn("activity_id", $activityIds)->delete(); ReportActivity::whereIn("activity_id", $activityIds)->delete();
},5); }, 5);
} }
private function deleteDokumenProject($project_id, $company_id) private function deleteDokumenProject($project_id, $company_id)
{ {
DB::transaction(function() use($project_id, $company_id){ DB::transaction(function () use ($project_id, $company_id) {
$dataDokumen = DokumenProject::where([['type_dokumen', 'project-document-out-folder'],['ref_id', $project_id]])->get(); $dataDokumen = DokumenProject::where([['type_dokumen', 'project-document-out-folder'], ['ref_id', $project_id]])->get();
$company = Company::find($company_id); $company = Company::find($company_id);
if($company) { if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataDokumen as $dokumen) { foreach ($dataDokumen as $dokumen) {
if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) { if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) {
@ -271,7 +301,7 @@ class ProjectController extends Controller
} }
} }
} }
DokumenProject::where([['type_dokumen', 'project-document-out-folder'],['ref_id', $project_id]])->delete(); DokumenProject::where([['type_dokumen', 'project-document-out-folder'], ['ref_id', $project_id]])->delete();
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); $dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id");
$ref_ids = $dataFolder->all(); $ref_ids = $dataFolder->all();
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); $dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get();
@ -281,7 +311,7 @@ class ProjectController extends Controller
} }
} }
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete(); DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete();
},5); }, 5);
} }
public function search(Request $request) public function search(Request $request)
@ -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)
@ -551,7 +580,7 @@ class ProjectController extends Controller
public function setBaselineActivity($activity_id, $gantt_id) public function setBaselineActivity($activity_id, $gantt_id)
{ {
$activity = Activity::where([["version_gantt_id", $gantt_id],['id',$activity_id]])->first(); $activity = Activity::where([["version_gantt_id", $gantt_id], ['id', $activity_id]])->first();
$activity->update([ $activity->update([
"planned_start" => $activity->start_date, "planned_start" => $activity->start_date,
"planned_end" => $activity->end_date, "planned_end" => $activity->end_date,
@ -561,32 +590,12 @@ 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()
->from('assign_hr_to_proyek AS utp') ->from('assign_hr_to_proyek AS utp')
->where([['is_customer', true],['user_id', $id]]) ->where([['is_customer', true], ['user_id', $id]])
->leftJoin('m_users', 'utp.user_id', '=', 'm_users.id') ->leftJoin('m_users', 'utp.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', 'utp.proyek_id', '=', 'm_proyek.id') ->leftJoin('m_proyek', 'utp.proyek_id', '=', 'm_proyek.id')
->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id') ->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')

140
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',
@ -32,36 +34,37 @@ class RequestMaterialController extends Controller
$result = RequestMaterial::create($data); $result = RequestMaterial::create($data);
if(!$result) if (!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to add!', 'code' => 500], 500);
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)) {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$result = RequestMaterial::find($id); $result = RequestMaterial::find($id);
if($result) if ($result)
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
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 delete($id) public function delete($id)
{ {
$data = RequestMaterial::find($id); $data = RequestMaterial::find($id);
if($data) if ($data)
$delete = $data->delete(); $delete = $data->delete();
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
if($delete) if ($delete)
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to delete!', 'code' => 500], 500);
} }
public function search(Request $request) public function search(Request $request)
@ -72,7 +75,7 @@ class RequestMaterialController extends Controller
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
} }
public function list() public function list()
@ -80,35 +83,35 @@ class RequestMaterialController extends Controller
$data = RequestMaterial::all(); $data = RequestMaterial::all();
$countData = $data->count(); $countData = $data->count();
if($data) if ($data)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
return response()->json(['status'=>'failed','message'=>'failed get list request material, please try again later!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'failed get list request material, please try again later!', 'code' => 400], 400);
} }
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
$dataForm = $request->all(); $dataForm = $request->all();
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);
$reqMaterial = RequestMaterial::find($id); $reqMaterial = RequestMaterial::find($id);
if(!$reqMaterial) if (!$reqMaterial)
return response()->json(['status'=>'failed','message'=>'data request material not found!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'data request material not found!', 'code' => 400], 400);
if(!isset($dataForm['status'])){ if (!isset($dataForm['status'])) {
if(!$reqMaterial->update($request->all())) if (!$reqMaterial->update($request->all()))
return response()->json(['status'=>'failed','message'=>'request material failed updated!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'request material failed updated!', 'code' => 400], 400);
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);
} }
if($dataForm['status']=="receipt to warehouse"){ if ($dataForm['status'] == "receipt to warehouse") {
$materialResource = MaterialResource::where('name', 'ilike', $reqMaterial->description)->first(); $materialResource = MaterialResource::where('name', 'ilike', $reqMaterial->description)->first();
if($materialResource){ if ($materialResource) {
$reqMaterial->update($request->all()); $reqMaterial->update($request->all());
$payloadMQty = $materialResource->qty + $reqMaterial->qty_received; $payloadMQty = $materialResource->qty + $reqMaterial->qty_received;
MaterialResource::where('id', $materialResource->id)->update(['qty' => $payloadMQty]); MaterialResource::where('id', $materialResource->id)->update(['qty' => $payloadMQty]);
return response()->json(['status'=>'success', 'code'=>200], 200); return response()->json(['status' => 'success', 'code' => 200], 200);
} }
$reqMaterial->update($request->all()); $reqMaterial->update($request->all());
@ -123,79 +126,32 @@ class RequestMaterialController extends Controller
"created_by" => $this->currentName "created_by" => $this->currentName
); );
if(!MaterialResource::create($preparedMaterialResource )) if (!MaterialResource::create($preparedMaterialResource))
return response()->json(['status'=>'failed','message'=>'add data material resource failed!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'add data material resource failed!', 'code' => 400], 400);
return response()->json(['status'=>'success','message'=>'add data material resource successfully!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'add data material resource successfully!', 'code' => 200], 200);
} }
if($dataForm['status']=="receipt to site"){ if ($dataForm['status'] == "receipt to site") {
$reqMaterial->update($request->all()); $reqMaterial->update($request->all());
$materialResource = MaterialResource::where('name', 'ilike', $reqMaterial->description)->first(); $materialResource = MaterialResource::where('name', 'ilike', $reqMaterial->description)->first();
if(!$materialResource) if (!$materialResource)
return response()->json(['status'=>'failed','message'=>'update status receipt to site request material resource failed, because material is not exist in warehouse!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'update status receipt to site request material resource failed, because material is not exist in warehouse!', 'code' => 400], 400);
$reqMaterial->update($request->all()); $reqMaterial->update($request->all());
$payloadMQty = $materialResource->qty - $reqMaterial->qty_received; $payloadMQty = $materialResource->qty - $reqMaterial->qty_received;
if($payloadMQty < 0) if ($payloadMQty < 0)
return response()->json(['status'=>'failed','message'=>'update status receipt to site request material resource failed, because material is not exist in warehouse!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'update status receipt to site request material resource failed, because material is not exist in warehouse!', 'code' => 400], 400);
MaterialResource::where('id', $materialResource->id)->update(['qty' => $payloadMQty]); MaterialResource::where('id', $materialResource->id)->update(['qty' => $payloadMQty]);
return response()->json(['status'=>'success', 'message'=>'request material status receipt to site successfully updated!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'request material status receipt to site successfully updated!', 'code' => 200], 200);
}
if(!$reqMaterial->update($request->all()))
return response()->json(['status'=>'failed','message'=>'request material failed updated!','code'=>400], 400);
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) { if (!$reqMaterial->update($request->all()))
$search = urlencode($request->name); return response()->json(['status' => 'failed', 'message' => 'request material failed updated!', 'code' => 400], 400);
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); return response()->json(['status' => 'success', 'message' => 'request material successfully updated!', 'code' => 200], 200);
} }
} }

171
app/Http/Controllers/UserToProyekController.php

@ -24,114 +24,115 @@ class UserToProyekController extends Controller
$result = UserToProyek::create($data); $result = UserToProyek::create($data);
if($result){ if ($result) {
return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'assign hr to proyek successfully!', 'code' => 200], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'assign hr to proyek failed!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'assign hr to proyek failed!', 'code' => 400], 400);
} }
} }
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([
["proyek_id" , $request->proyek_id], ["proyek_id", $request->proyek_id],
['is_customer',true] ['is_customer', true]
]); ]);
if($data){ if ($data) {
$data->delete(); $data->delete();
} }
if(is_array($user_IDs) && count($user_IDs) > 0){ if (is_array($user_IDs) && count($user_IDs) > 0) {
$countRes = 0; $countRes = 0;
foreach($user_IDs as $item){ foreach ($user_IDs as $item) {
$dataInsert = array( $dataInsert = array(
"user_id" => $item, "user_id" => $item,
"proyek_id" => $request->proyek_id, "proyek_id" => $request->proyek_id,
"created_by" => $this->currentName, "created_by" => $this->currentName,
'is_customer'=>true, 'is_customer' => true,
'project_role'=> $request->project_role 'project_role' => $request->project_role
); );
$result = UserToProyek::create($dataInsert); $result = UserToProyek::create($dataInsert);
if($result){ if ($result) {
$countRes++; $countRes++;
}else{ } else {
$countRes--; $countRes--;
} }
} }
if($countRes > 0){ if ($countRes > 0) {
return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]); return response()->json(['status' => 'success', 'message' => 'Project customer successfull created', 'code' => 200]);
}else{ } else {
return response()->json(['status'=>'failed' ,'message'=>'Project customer failed created','code'=>400]); return response()->json(['status' => 'failed', 'message' => 'Project customer failed created', 'code' => 400]);
} }
}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==""){ {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die(); die();
} }
$result = UserToProyek::find($id); $result = UserToProyek::find($id);
if($result){ if ($result) {
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'failed get data assign hr to proyek, please try again later!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'failed get data assign hr to proyek, please try again later!', 'code' => 400], 400);
} }
} }
public function update(Request $request, $id) public function update(Request $request, $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);
} }
$data = UserToProyek::find($id); $data = UserToProyek::find($id);
if($data){ if ($data) {
$result = $data->update($request->all()); $result = $data->update($request->all());
}else{ } else {
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'data assign hr to proyek not found!', 'code' => 400], 400);
die(); die();
} }
if($result){ if ($result) {
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'data assign hr to proyek successfully updated!', 'code' => 200], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'data assign hr to proyek failed updated!', 'code' => 400], 400);
} }
} }
public function delete($id, $company_id) public function delete($id, $company_id)
{ {
$data = UserToProyek::find($id); $data = UserToProyek::find($id);
if($data){ if ($data) {
$userId = $data->user_id; $userId = $data->user_id;
$proyekId = $data->proyek_id; $proyekId = $data->proyek_id;
$delete = $data->delete(); $delete = $data->delete();
if($delete){ if ($delete) {
$this->deleteRelative($proyekId, $userId, $company_id); $this->deleteRelative($proyekId, $userId, $company_id);
} }
}else{ } else {
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'data assign hr to proyek not found!', 'code' => 400], 400);
die(); die();
} }
if($delete){ if ($delete) {
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'data assign hr to proyek successfully deleted!', 'code' => 200], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'data assign hr to proyek failed deleted!', 'code' => 400], 400);
} }
} }
@ -141,13 +142,13 @@ class UserToProyekController extends Controller
foreach ($uta as $value) { foreach ($uta as $value) {
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get(); $dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get();
$company = Company::find($company_id); $company = Company::find($company_id);
if($company) { if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataRa as $ra) { foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($images as $image) { foreach ($images as $image) {
if(file_exists($destinationPath['pathImage'].$image->image)){ if (file_exists($destinationPath['pathImage'] . $image->image)) {
unlink($destinationPath['pathImage'].$image->image); unlink($destinationPath['pathImage'] . $image->image);
} }
} }
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
@ -166,7 +167,7 @@ class UserToProyekController extends Controller
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
} }
public function list() public function list()
@ -174,14 +175,15 @@ class UserToProyekController extends Controller
$data = UserToProyek::all(); $data = UserToProyek::all();
$countData = $data->count(); $countData = $data->count();
if($data){ if ($data) {
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'failed get list assign hr to proyek, please try again later!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'failed get list assign hr to proyek, please try again later!', 'code' => 400], 400);
} }
} }
public function select(Request $request){ public function select(Request $request)
{
$search = $request->query('search'); $search = $request->query('search');
@ -190,73 +192,28 @@ class UserToProyekController extends Controller
$include = []; $include = [];
if($idActivity && $idActivity > 0){ if ($idActivity && $idActivity > 0) {
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get(); $dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
foreach($dataF as $val){ foreach ($dataF as $val) {
$include[] = $val->user_id; $include[] = $val->user_id;
} }
} }
if($search && !empty($search)){ if ($search && !empty($search)) {
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') $data = UserToProyek::select("m_users.id as id", "m_users.name as name")->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')
->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%'.$search.'%')->whereIn("m_users.id", $include)->get(); ->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%' . $search . '%')->whereIn("m_users.id", $include)->get();
}else{ } else {
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereIn("m_users.id", $include)->get(); $data = UserToProyek::select("m_users.id as id", "m_users.name as name")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereIn("m_users.id", $include)->get();
} }
if($data instanceof \Illuminate\Database\Eloquent\Collection){ if ($data instanceof \Illuminate\Database\Eloquent\Collection) {
$pm = array( $pm = array(
"id"=>$this->currentId, "id" => $this->currentId,
"name"=> "Project Manager" "name" => "Project Manager"
); );
$data->push($pm); $data->push($pm);
} }
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