Browse Source

fix(remove):adw integration

pull/1/head
farhantock 7 months ago
parent
commit
f19fc03276
  1. 24
      app/Helpers/MasterFunctionsHelper.php
  2. 97
      app/Http/Controllers/DashboardBoDController.php
  3. 601
      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
{
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)
{
$dayOffs = VersionGantt::where('id', $ganttId)->first()->config_dayoff;

97
app/Http/Controllers/DashboardBoDController.php

@ -25,42 +25,7 @@ class DashboardBoDController extends Controller
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)
{
@ -280,28 +245,28 @@ class DashboardBoDController extends Controller
public function getTotalProjectPerScheduleHealth($role_name, $company_id, $all_project, $hierarchy)
{
$role = urldecode($role_name);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
$return = [
'behind-schedule' => 0,
'warning' => 0,
'on-schedule' => 0,
];
$divisi = Divisi::query()
->where('company_id',$company_id)
->pluck('id');
$divisi = Divisi::query()
->where('company_id', $company_id)
->pluck('id');
$projects = null;
if ($role === 'Super Admin') {
$projects = Project::get();
} elseif ($all_project == 'true') {
$projects = Project::whereIn('divisi_id',$divisi)
->where('company_id', $company_id)
->get();
$projects = Project::whereIn('divisi_id', $divisi)
->where('company_id', $company_id)
->get();
} else {
$projects = Project::whereIn('divisi_id',$divisi)
->where('created_by_id', $replaceHierarchy)
->get();
$projects = Project::whereIn('divisi_id', $divisi)
->where('created_by_id', $replaceHierarchy)
->get();
}
foreach ($projects as $index => $project) {
@ -391,7 +356,7 @@ class DashboardBoDController extends Controller
public function getTotalProjectPerBudgetHealth($role_name, $company_id, $all_project, $hierarchy)
{
$role = urldecode($role_name);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
$response = [
'data' => [
@ -400,47 +365,47 @@ class DashboardBoDController extends Controller
'on-budget' => 0,
]
];
$divisi = Divisi::query()
->where('company_id',$company_id)
->pluck('id');
$divisi = Divisi::query()
->where('company_id', $company_id)
->pluck('id');
// arr overrun
// arr overrun
if ($role === 'Super Admin') {
$response['data']['overrun'] = Project::where('budget_health', 'overrun')
->count();
} elseif ($all_project == 'true') {
$response['data']['overrun'] = Project::whereIn('divisi_id',$divisi)
->where([['budget_health', 'overrun'],['company_id', $company_id]])
$response['data']['overrun'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'overrun'], ['company_id', $company_id]])
->count();
} else {
$response['data']['overrun'] = Project::whereIn('divisi_id',$divisi)
->where([['budget_health', 'overrun'],['created_by_id', $replaceHierarchy]])
$response['data']['overrun'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'overrun'], ['created_by_id', $replaceHierarchy]])
->count();
}
// arr warning
// arr warning
if ($role === 'Super Admin') {
$response['data']['warning'] = Project::where('budget_health', 'warning')
->count();
} elseif ($all_project == 'true') {
$response['data']['warning'] = Project::whereIn('divisi_id',$divisi)
->where([['budget_health', 'warning'],['company_id', $company_id]])
$response['data']['warning'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'warning'], ['company_id', $company_id]])
->count();
} else {
$response['data']['warning'] = Project::whereIn('divisi_id',$divisi)
->where([['budget_health', 'warning'],['created_by_id', $replaceHierarchy]])
$response['data']['warning'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'warning'], ['created_by_id', $replaceHierarchy]])
->count();
}
// arr on-budget
// arr on-budget
if ($role === 'Super Admin') {
$response['data']['on-budget'] = Project::where('budget_health', 'on-budget')
->count();
} elseif ($all_project == 'true') {
$response['data']['on-budget'] = Project::whereIn('divisi_id',$divisi)
->where([['company_id', $company_id],['budget_health', 'on-budget']])
$response['data']['on-budget'] = Project::whereIn('divisi_id', $divisi)
->where([['company_id', $company_id], ['budget_health', 'on-budget']])
->count();
} else {
$response['data']['on-budget'] = Project::whereIn('divisi_id',$divisi)
->where([['budget_health', 'on-budget'],['created_by_id', $replaceHierarchy]])
$response['data']['on-budget'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'on-budget'], ['created_by_id', $replaceHierarchy]])
->count();
}
return response()->json($response, 200);
@ -448,8 +413,8 @@ class DashboardBoDController extends Controller
private function countTotalProjectByBudgetHealthInDivision($divisi, $health)
{
$project = Project::where([['divisi_id', $divisi],['budget_health', $health]])->count();
return $project;
$project = Project::where([['divisi_id', $divisi], ['budget_health', $health]])->count();
return $project;
}

601
app/Http/Controllers/ProjectController.php

@ -5,13 +5,44 @@ namespace App\Http\Controllers;
use DateTime;
use App\Jobs\ProcessSCurve;
use Illuminate\Http\Request;
use App\Models\{ReportActivityMaterial,ProjectToChecklistK3,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 App\Models\{
ReportActivityMaterial,
ProjectToChecklistK3,
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\Support\Facades\{Artisan,DB};
use Illuminate\Support\Facades\{Artisan, DB};
use App\Helpers\MasterFunctionsHelper;
use Carbon\Carbon;
@ -20,17 +51,17 @@ const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&
class ProjectController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'nama' => 'required',
'mulai_proyek' => 'required',
'mulai_proyek' => 'required',
'akhir_proyek' => 'required',
'rencana_biaya' => 'required',
'type_proyek_id' => 'required',
'company_id' => 'required'
]);
public function add(Request $request)
{
$this->validate($request, [
'nama' => 'required',
'mulai_proyek' => 'required',
'mulai_proyek' => 'required',
'akhir_proyek' => 'required',
'rencana_biaya' => 'required',
'type_proyek_id' => 'required',
'company_id' => 'required'
]);
DB::beginTransaction();
try {
$data = $request->all();
@ -49,25 +80,25 @@ class ProjectController extends Controller
->selectRaw('count(*) as total_project')
->where('company_id', $request->company_id)
->first();
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) {
if($projectResult['total_project'] < 10) {
if ($transaction->where([['type_paket', 'Basic'], ['amount', '!=', null]])->exists()) {
if ($projectResult['total_project'] < 10) {
$countCreate = true;
}
} elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) {
if($projectResult['total_project'] < 1) {
} elseif ($cloneQueryTransaction->where([['type_paket', 'Free'], ['amount', 0]])->exists()) {
if ($projectResult['total_project'] < 1) {
$countCreate = true;
}
} else {
$countCreate = true;
}
if($countCreate) {
if ($countCreate) {
$result = Project::create($data);
if (!$result) {
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500);
} else {
$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();
return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200);
}
@ -77,68 +108,67 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
DB::rollBack();
}
}
}
public function edit($id)
{
if (empty($id) || !is_int((int)$id)) {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
public function edit($id)
{
if (empty($id) || !is_int((int)$id)) {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
}
$result = Project::
select(
'value_proyek',
'scoupe_of_work',
'kode_sortname',
'jumlah_stakeholder',
'nama',
'mulai_proyek',
'akhir_proyek',
'area_kerja',
'rencana_biaya',
'biaya_actual',
'company',
'pm_id',
'type_proyek_id',
'divisi_id',
'persentase_progress',
'keterangan',
'durasi_proyek',
'progress_by_worklog',
'currency_symbol',
'late_consequence',
'assumtion',
'currency_code',
'currency_name',
'project_objectives',
'considered_success_when',
'potential_risk',
'testing_environment',
'budget_health',
'phase_id',
'calculation_status',
'md.name as divisi_name',
'm_proyek.company_id'
)
->leftJoin('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id')
->where('m_proyek.id', $id)
->first();
if (!$result) {
$result = Project::select(
'value_proyek',
'scoupe_of_work',
'kode_sortname',
'jumlah_stakeholder',
'nama',
'mulai_proyek',
'akhir_proyek',
'area_kerja',
'rencana_biaya',
'biaya_actual',
'company',
'pm_id',
'type_proyek_id',
'divisi_id',
'persentase_progress',
'keterangan',
'durasi_proyek',
'progress_by_worklog',
'currency_symbol',
'late_consequence',
'assumtion',
'currency_code',
'currency_name',
'project_objectives',
'considered_success_when',
'potential_risk',
'testing_environment',
'budget_health',
'phase_id',
'calculation_status',
'md.name as divisi_name',
'm_proyek.company_id'
)
->leftJoin('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id')
->where('m_proyek.id', $id)
->first();
if (!$result) {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
} else {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
}
}
}
public function update(Request $request, $id)
{
if (empty($id) || !is_int((int)$id)) {
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400);
public function update(Request $request, $id)
{
if (empty($id) || !is_int((int)$id)) {
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400);
}
$data = Project::find($id);
$data = Project::find($id);
if ($data) {
if ($data) {
if ($data->update($request->all())) {
return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200);
} else {
@ -147,43 +177,43 @@ class ProjectController extends Controller
} else {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
}
private function createOfficeHours($proyek_id)
{
$dataCreate = array(
"proyek_id" => $proyek_id,
"monday_start" => "08:00:00",
"monday_end" => "16:00:00",
"tuesday_start" => "08:00:00",
"tuesday_end" => "16:00:00",
"wednesday_start" => "08:00:00",
"wednesday_end" => "16:00:00",
"thursday_start" => "08:00:00",
"thursday_end" => "16:00:00",
"friday_start" => "08:00:00",
"friday_end" => "16:00:00",
"saturday_start" => "08:00:00",
"saturday_end" => "16:00:00",
"sunday_start" => "08:00:00",
"sunday_end" => "16:00:00",
"created_by" => $this->currentName
);
OfficeHours::create($dataCreate);
return true;
}
public function delete($id, $company_id)
{
}
private function createOfficeHours($proyek_id)
{
$dataCreate = array(
"proyek_id" => $proyek_id,
"monday_start" => "08:00:00",
"monday_end" => "16:00:00",
"tuesday_start" => "08:00:00",
"tuesday_end" => "16:00:00",
"wednesday_start" => "08:00:00",
"wednesday_end" => "16:00:00",
"thursday_start" => "08:00:00",
"thursday_end" => "16:00:00",
"friday_start" => "08:00:00",
"friday_end" => "16:00:00",
"saturday_start" => "08:00:00",
"saturday_end" => "16:00:00",
"sunday_start" => "08:00:00",
"sunday_end" => "16:00:00",
"created_by" => $this->currentName
);
OfficeHours::create($dataCreate);
return true;
}
public function delete($id, $company_id)
{
DB::beginTransaction();
$data = Project::find($id);
$data = Project::find($id);
$dateNow = Carbon::now();
if ($data) {
if ($data) {
$this->deleteRelative($id, $company_id);
if ($data->delete()) {
// if ($data->update(['deleted_at' => $dateNow, 'deleted_by_id' => $this->currentId])) {
// if ($data->update(['deleted_at' => $dateNow, 'deleted_by_id' => $this->currentId])) {
DB::commit();
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
} else {
@ -192,13 +222,13 @@ class ProjectController extends Controller
}
} else {
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
}
}
private function deleteRelative($project_id, $company_id)
{
DB::transaction(function() use($project_id, $company_id) {
private function deleteRelative($project_id, $company_id)
{
DB::transaction(function () use ($project_id, $company_id) {
UserToProyek::where('proyek_id', $project_id)->delete();
UserToActivity::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();
$this->deleteVersionGantt($project_id, $company_id);
$this->deleteDokumenProject($project_id, $company_id);
},5);
}
}, 5);
}
private function deleteVersionGantt($project_id, $company_id)
{
DB::transaction(function() use($project_id, $company_id) {
private function deleteVersionGantt($project_id, $company_id)
{
DB::transaction(function () use ($project_id, $company_id) {
$dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id");
$vhIds = $dataVg->all();
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id');
$activityIds = $activity->all();
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get();
$company = Company::find($company_id);
if($company) {
if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataRa as $ra) {
$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();
Activity::whereIn("version_gantt_id", $vhIds)->delete();
ReportActivity::whereIn("activity_id", $activityIds)->delete();
},5);
}
}, 5);
}
private function deleteDokumenProject($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();
private function deleteDokumenProject($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();
$company = Company::find($company_id);
if($company) {
if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataDokumen as $dokumen) {
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");
$ref_ids = $dataFolder->all();
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get();
@ -281,24 +311,24 @@ class ProjectController extends Controller
}
}
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete();
},5);
}
}, 5);
}
public function search(Request $request)
{
$payload = $request->all();
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_proyek');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
$dataBuilder = $this->setUpPayload($payload, 'm_proyek');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$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()
{
DB::beginTransaction();
try {
$data = Project::select(
@ -383,67 +413,66 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
DB::rollBack();
}
}
}
public function getListProjectTask($id)
{
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id", "m_proyek.*")
->where("assign_hr_to_activity.user_id", $id)
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
->groupBy("m_proyek.proyek_id")
->get();
public function getListProjectTask($id)
{
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id", "m_proyek.*")
->where("assign_hr_to_activity.user_id", $id)
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
->groupBy("m_proyek.proyek_id")
->get();
if ($data) {
if ($data) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
}
public function getSCurve(Request $request)
{
$data = MasterFunctionsHelper::getSCurve($request);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
// testing
public function calculateSCurvetest(Request $request)
{
$data = MasterFunctionsHelper::calculateSCurve($request->project_id);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
public function calculateSCurve(Request $request)
{
$sCurve = Project::select('scurve')->where('id', $request->project_id)->first();
return response()->json(['status' => 'success', 'code' => 200, 'data' => json_decode($sCurve->scurve)], 200);
}
public function sCurveCommand(Request $request)
{
Artisan::call('calculate:scurve', [
'project_id' => $request->project_id
]);
// $project = Project::find($request->project_id);
}
public function getSCurve(Request $request)
{
$data = MasterFunctionsHelper::getSCurve($request);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
// testing
public function calculateSCurvetest(Request $request)
{
$data = MasterFunctionsHelper::calculateSCurve($request->project_id);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
public function calculateSCurve(Request $request)
{
$sCurve = Project::select('scurve')->where('id', $request->project_id)->first();
return response()->json(['status' => 'success', 'code' => 200, 'data' => json_decode($sCurve->scurve)], 200);
}
public function sCurveCommand(Request $request)
{
Artisan::call('calculate:scurve', [
'project_id' => $request->project_id
]);
// $project = Project::find($request->project_id);
// if ($project) {
// dispatch(new ProcessSCurve($project));
// return response()->json(['message' => 'S Curve calculation queued']);
// }
// return response()->json(['message' => 'Project not found'], 404);
}
public function getLinearSCurve(Request $request)
{
$data = MasterFunctionsHelper::getLinearSCurve($request);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
public static function setSyncDate($activity_id, $activity, $report)
{
// if ($project) {
// dispatch(new ProcessSCurve($project));
// return response()->json(['message' => 'S Curve calculation queued']);
// }
// return response()->json(['message' => 'Project not found'], 404);
}
public function getLinearSCurve(Request $request)
{
$data = MasterFunctionsHelper::getLinearSCurve($request);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
public static function setSyncDate($activity_id, $activity, $report)
{
DB::beginTransaction();
try {
$status = AssignMaterial::where('activity_id', $activity_id)->first();
@ -478,10 +507,10 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
DB::rollBack();
}
}
}
public function synchronizeReport($gantt_id)
{
public function synchronizeReport($gantt_id)
{
DB::beginTransaction();
try {
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
@ -517,8 +546,8 @@ class ProjectController extends Controller
} else if ($reports[$i]['status'] == 'done') {
$activity->actual_end = $reports[$i]['max_date']->setTime(23, 59, 59);
}
$activity->start_date = $reports[$i]['min_date']; //same early
$activity->end_date = $reports[$i]['max_date']->setTime(23, 59, 59); // same early
$activity->start_date = $reports[$i]['min_date']; //same early
$activity->end_date = $reports[$i]['max_date']->setTime(23, 59, 59); // same early
$startDate = new DateTime($activity->start_date);
$endDate = new DateTime($activity->end_date);
$duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate);
@ -531,74 +560,54 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
DB::rollBack();
}
}
public function setBaseline($gantt_id)
{
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
foreach ($activities as $activity) {
$activity->update([
"planned_start" => $activity->start_date,
"planned_end" => $activity->end_date,
"early_start" => $activity->start_date,
"early_end" => $activity->end_date,
]);
}
}
public function setBaseline($gantt_id)
{
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
foreach ($activities as $activity) {
$activity->update([
"planned_start" => $activity->start_date,
"planned_end" => $activity->end_date,
"early_start" => $activity->start_date,
"early_end" => $activity->end_date,
]);
}
return response()->json(['status' => 'success', 'message' => 'Set baseline success!', 'code' => 200], 200);
}
return response()->json(['status' => 'success', 'message' => 'Set baseline success!', 'code' => 200], 200);
}
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([
"planned_start" => $activity->start_date,
"planned_end" => $activity->end_date,
"early_start" => $activity->start_date,
"early_end" => $activity->end_date,
]);
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)
{
$userProyek = UserToProyek::query()
->from('assign_hr_to_proyek AS utp')
->where([['is_customer', true],['user_id', $id]])
->leftJoin('m_users', 'utp.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', 'utp.proyek_id', '=', 'm_proyek.id')
->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
->select('m_proyek.*', 'm_type_proyek.name AS join_second_name', 'm_users.name AS join_first_name')
->get();
$totalRecord = $userProyek->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
}
public function detail(Request $request, $id, $gantt_id = null, $s_curve = null)
{
return response()->json(['status' => 'success', 'message' => 'Set baseline activity success!', 'code' => 200], 200);
}
public function getByUser($id)
{
$userProyek = UserToProyek::query()
->from('assign_hr_to_proyek AS utp')
->where([['is_customer', true], ['user_id', $id]])
->leftJoin('m_users', 'utp.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', 'utp.proyek_id', '=', 'm_proyek.id')
->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
->select('m_proyek.*', 'm_type_proyek.name AS join_second_name', 'm_users.name AS join_first_name')
->get();
$totalRecord = $userProyek->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
}
public function detail(Request $request, $id, $gantt_id = null, $s_curve = null)
{
DB::beginTransaction();
try {
if (empty($id) || !is_int((int)$id)) {
@ -673,10 +682,10 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
DB::rollBack();
}
}
}
public function getOverdueActivities(Request $request)
{
public function getOverdueActivities(Request $request)
{
DB::beginTransaction();
try {
$payload = $request->all();
@ -712,10 +721,10 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
DB::rollBack();
}
}
}
public function getReportDistribution(Request $request)
{
public function getReportDistribution(Request $request)
{
DB::beginTransaction();
try {
$payload = $request->all();
@ -750,25 +759,25 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
DB::rollBack();
}
}
public function getManpower($proyek_id)
{
$manCount = UserToProyek::where('proyek_id', $proyek_id)->count();
return response()->json(['totalRecord' => $manCount]);
}
public function getAssignedHR($gantt_id)
{
$results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id')
->where('assign_hr_to_activity.version_gantt_id', $gantt_id)
->get();
return response()->json(['data' => $results]);
}
public function dashboard($id)
{
}
public function getManpower($proyek_id)
{
$manCount = UserToProyek::where('proyek_id', $proyek_id)->count();
return response()->json(['totalRecord' => $manCount]);
}
public function getAssignedHR($gantt_id)
{
$results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id')
->where('assign_hr_to_activity.version_gantt_id', $gantt_id)
->get();
return response()->json(['data' => $results]);
}
public function dashboard($id)
{
DB::beginTransaction();
try {
$data = Project::query()
@ -822,23 +831,23 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
DB::rollBack();
}
}
}
private function httpReq($search)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION));
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'));
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'));
$info = curl_getinfo($ch);
$info = curl_getinfo($ch);
$output = curl_exec($ch);
curl_close($ch);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output);
}
return json_decode($output);
}
}

140
app/Http/Controllers/RequestMaterialController.php

@ -8,13 +8,15 @@ use App\Models\MaterialResource;
class RequestMaterialController extends Controller
{
private function sanitizeDecimal($number) {
$number = str_replace(".","",$number);
$number = str_replace(",",".",$number);
private function sanitizeDecimal($number)
{
$number = str_replace(".", "", $number);
$number = str_replace(",", ".", $number);
return $number;
}
public function add(Request $request){
public function add(Request $request)
{
$this->validate($request, [
'proyek_id' => 'required',
'description' => 'required',
@ -32,36 +34,37 @@ class RequestMaterialController extends Controller
$result = RequestMaterial::create($data);
if(!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add!','code'=> 500], 500);
if (!$result)
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){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
public function edit($id)
{
if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$result = RequestMaterial::find($id);
if($result)
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
if ($result)
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)
{
$data = RequestMaterial::find($id);
if($data)
if ($data)
$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)
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
if ($delete)
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)
@ -72,7 +75,7 @@ class RequestMaterialController extends Controller
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$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()
@ -80,35 +83,35 @@ class RequestMaterialController extends Controller
$data = RequestMaterial::all();
$countData = $data->count();
if($data)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
if ($data)
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)
{
$dataForm = $request->all();
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);
$reqMaterial = RequestMaterial::find($id);
if(!$reqMaterial)
return response()->json(['status'=>'failed','message'=>'data request material not found!','code'=>400], 400);
if (!$reqMaterial)
return response()->json(['status' => 'failed', 'message' => 'data request material not found!', 'code' => 400], 400);
if(!isset($dataForm['status'])){
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);
if (!isset($dataForm['status'])) {
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);
}
if($dataForm['status']=="receipt to warehouse"){
if ($dataForm['status'] == "receipt to warehouse") {
$materialResource = MaterialResource::where('name', 'ilike', $reqMaterial->description)->first();
if($materialResource){
if ($materialResource) {
$reqMaterial->update($request->all());
$payloadMQty = $materialResource->qty + $reqMaterial->qty_received;
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());
@ -123,79 +126,32 @@ class RequestMaterialController extends Controller
"created_by" => $this->currentName
);
if(!MaterialResource::create($preparedMaterialResource ))
return response()->json(['status'=>'failed','message'=>'add data material resource failed!','code'=>400], 400);
if (!MaterialResource::create($preparedMaterialResource))
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());
$materialResource = MaterialResource::where('name', 'ilike', $reqMaterial->description)->first();
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);
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);
$reqMaterial->update($request->all());
$payloadMQty = $materialResource->qty - $reqMaterial->qty_received;
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);
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);
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) {
$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
}
if (!$reqMaterial->update($request->all()))
return response()->json(['status' => 'failed', 'message' => 'request material failed updated!', 'code' => 400], 400);
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);
if($result){
return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'assign hr to proyek failed!','code'=>400], 400);
if ($result) {
return response()->json(['status' => 'success', 'message' => 'assign hr to proyek successfully!', 'code' => 200], 200);
} else {
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;
$data = UserToProyek::where([
["proyek_id" , $request->proyek_id],
['is_customer',true]
["proyek_id", $request->proyek_id],
['is_customer', true]
]);
if($data){
if ($data) {
$data->delete();
}
if(is_array($user_IDs) && count($user_IDs) > 0){
if (is_array($user_IDs) && count($user_IDs) > 0) {
$countRes = 0;
foreach($user_IDs as $item){
foreach ($user_IDs as $item) {
$dataInsert = array(
"user_id" => $item,
"proyek_id" => $request->proyek_id,
"created_by" => $this->currentName,
'is_customer'=>true,
'project_role'=> $request->project_role
'is_customer' => true,
'project_role' => $request->project_role
);
$result = UserToProyek::create($dataInsert);
if($result){
if ($result) {
$countRes++;
}else{
} else {
$countRes--;
}
}
if($countRes > 0){
return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]);
}else{
return response()->json(['status'=>'failed' ,'message'=>'Project customer failed created','code'=>400]);
if ($countRes > 0) {
return response()->json(['status' => 'success', 'message' => 'Project customer successfull created', 'code' => 200]);
} else {
return response()->json(['status' => 'failed', 'message' => 'Project customer failed created', 'code' => 400]);
}
}else{
return response()->json(['status'=>'failed' ,'message'=>'Project customer failed created','code'=>200]);
} else {
return response()->json(['status' => 'failed', 'message' => 'Project customer failed created', 'code' => 200]);
}
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
public function edit($id)
{
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die();
}
$result = UserToProyek::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data assign hr to proyek, please try again later!','code'=>400], 400);
if ($result) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
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)
{
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);
}
$data = UserToProyek::find($id);
if($data){
if ($data) {
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
} else {
return response()->json(['status' => 'failed', 'message' => 'data assign hr to proyek not found!', 'code' => 400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400);
if ($result) {
return response()->json(['status' => 'success', 'message' => 'data assign hr to proyek successfully updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data assign hr to proyek failed updated!', 'code' => 400], 400);
}
}
public function delete($id, $company_id)
{
$data = UserToProyek::find($id);
if($data){
if ($data) {
$userId = $data->user_id;
$proyekId = $data->proyek_id;
$delete = $data->delete();
if($delete){
if ($delete) {
$this->deleteRelative($proyekId, $userId, $company_id);
}
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
} else {
return response()->json(['status' => 'failed', 'message' => 'data assign hr to proyek not found!', 'code' => 400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400);
if ($delete) {
return response()->json(['status' => 'success', 'message' => 'data assign hr to proyek successfully deleted!', 'code' => 200], 200);
} else {
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) {
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get();
$company = Company::find($company_id);
if($company) {
if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($images as $image) {
if(file_exists($destinationPath['pathImage'].$image->image)){
unlink($destinationPath['pathImage'].$image->image);
if (file_exists($destinationPath['pathImage'] . $image->image)) {
unlink($destinationPath['pathImage'] . $image->image);
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
@ -166,7 +167,7 @@ class UserToProyekController extends Controller
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$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()
@ -174,14 +175,15 @@ class UserToProyekController extends Controller
$data = UserToProyek::all();
$countData = $data->count();
if($data){
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list assign hr to proyek, please try again later!','code'=>400], 400);
if ($data) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
} else {
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');
@ -190,73 +192,28 @@ class UserToProyekController extends Controller
$include = [];
if($idActivity && $idActivity > 0){
if ($idActivity && $idActivity > 0) {
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
foreach($dataF as $val){
foreach ($dataF as $val) {
$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')
->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%'.$search.'%')->whereIn("m_users.id", $include)->get();
}else{
->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%' . $search . '%')->whereIn("m_users.id", $include)->get();
} 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();
}
if($data instanceof \Illuminate\Database\Eloquent\Collection){
if ($data instanceof \Illuminate\Database\Eloquent\Collection) {
$pm = array(
"id"=>$this->currentId,
"name"=> "Project Manager"
"id" => $this->currentId,
"name" => "Project Manager"
);
$data->push($pm);
}
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