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 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;

97
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)
{ {
@ -280,28 +245,28 @@ class DashboardBoDController extends Controller
public function getTotalProjectPerScheduleHealth($role_name, $company_id, $all_project, $hierarchy) public function getTotalProjectPerScheduleHealth($role_name, $company_id, $all_project, $hierarchy)
{ {
$role = urldecode($role_name); $role = urldecode($role_name);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy); $replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
$return = [ $return = [
'behind-schedule' => 0, 'behind-schedule' => 0,
'warning' => 0, 'warning' => 0,
'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();
} }
foreach ($projects as $index => $project) { foreach ($projects as $index => $project) {
@ -391,7 +356,7 @@ class DashboardBoDController extends Controller
public function getTotalProjectPerBudgetHealth($role_name, $company_id, $all_project, $hierarchy) public function getTotalProjectPerBudgetHealth($role_name, $company_id, $all_project, $hierarchy)
{ {
$role = urldecode($role_name); $role = urldecode($role_name);
$replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy); $replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy);
$response = [ $response = [
'data' => [ 'data' => [
@ -400,47 +365,47 @@ class DashboardBoDController extends Controller
'on-budget' => 0, 'on-budget' => 0,
] ]
]; ];
$divisi = Divisi::query() $divisi = Divisi::query()
->where('company_id',$company_id) ->where('company_id', $company_id)
->pluck('id'); ->pluck('id');
// arr overrun // arr overrun
if ($role === 'Super Admin') { if ($role === 'Super Admin') {
$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
if ($role === 'Super Admin') { if ($role === 'Super Admin') {
$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
if ($role === 'Super Admin') { if ($role === 'Super Admin') {
$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,8 +413,8 @@ 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;
} }

601
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;
@ -20,17 +51,17 @@ const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&
class ProjectController extends Controller class ProjectController extends Controller
{ {
public function add(Request $request) public function add(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'nama' => 'required', 'nama' => 'required',
'mulai_proyek' => 'required', 'mulai_proyek' => 'required',
'mulai_proyek' => 'required', 'mulai_proyek' => 'required',
'akhir_proyek' => 'required', 'akhir_proyek' => 'required',
'rencana_biaya' => 'required', 'rencana_biaya' => 'required',
'type_proyek_id' => 'required', 'type_proyek_id' => 'required',
'company_id' => 'required' 'company_id' => 'required'
]); ]);
DB::beginTransaction(); DB::beginTransaction();
try { try {
$data = $request->all(); $data = $request->all();
@ -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);
} }
@ -77,68 +108,67 @@ class ProjectController extends Controller
} catch (\Throwable $th) { } catch (\Throwable $th) {
DB::rollBack(); DB::rollBack();
} }
} }
public function edit($id) public function edit($id)
{ {
if (empty($id) || !is_int((int)$id)) { if (empty($id) || !is_int((int)$id)) {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
} }
$result = Project:: $result = Project::select(
select( 'value_proyek',
'value_proyek', 'scoupe_of_work',
'scoupe_of_work', 'kode_sortname',
'kode_sortname', 'jumlah_stakeholder',
'jumlah_stakeholder', 'nama',
'nama', 'mulai_proyek',
'mulai_proyek', 'akhir_proyek',
'akhir_proyek', 'area_kerja',
'area_kerja', 'rencana_biaya',
'rencana_biaya', 'biaya_actual',
'biaya_actual', 'company',
'company', 'pm_id',
'pm_id', 'type_proyek_id',
'type_proyek_id', 'divisi_id',
'divisi_id', 'persentase_progress',
'persentase_progress', 'keterangan',
'keterangan', 'durasi_proyek',
'durasi_proyek', 'progress_by_worklog',
'progress_by_worklog', 'currency_symbol',
'currency_symbol', 'late_consequence',
'late_consequence', 'assumtion',
'assumtion', 'currency_code',
'currency_code', 'currency_name',
'currency_name', 'project_objectives',
'project_objectives', 'considered_success_when',
'considered_success_when', 'potential_risk',
'potential_risk', 'testing_environment',
'testing_environment', 'budget_health',
'budget_health', 'phase_id',
'phase_id', 'calculation_status',
'calculation_status', 'md.name as divisi_name',
'md.name as divisi_name', 'm_proyek.company_id'
'm_proyek.company_id' )
) ->leftJoin('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id')
->leftJoin('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id') ->where('m_proyek.id', $id)
->where('m_proyek.id', $id) ->first();
->first(); if (!$result) {
if (!$result) {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
} else { } else {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} }
} }
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
if (empty($id) || !is_int((int)$id)) { if (empty($id) || !is_int((int)$id)) {
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400);
} }
$data = Project::find($id); $data = Project::find($id);
if ($data) { if ($data) {
if ($data->update($request->all())) { if ($data->update($request->all())) {
return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200);
} else { } else {
@ -147,43 +177,43 @@ 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);
} }
} }
private function createOfficeHours($proyek_id) private function createOfficeHours($proyek_id)
{ {
$dataCreate = array( $dataCreate = array(
"proyek_id" => $proyek_id, "proyek_id" => $proyek_id,
"monday_start" => "08:00:00", "monday_start" => "08:00:00",
"monday_end" => "16:00:00", "monday_end" => "16:00:00",
"tuesday_start" => "08:00:00", "tuesday_start" => "08:00:00",
"tuesday_end" => "16:00:00", "tuesday_end" => "16:00:00",
"wednesday_start" => "08:00:00", "wednesday_start" => "08:00:00",
"wednesday_end" => "16:00:00", "wednesday_end" => "16:00:00",
"thursday_start" => "08:00:00", "thursday_start" => "08:00:00",
"thursday_end" => "16:00:00", "thursday_end" => "16:00:00",
"friday_start" => "08:00:00", "friday_start" => "08:00:00",
"friday_end" => "16:00:00", "friday_end" => "16:00:00",
"saturday_start" => "08:00:00", "saturday_start" => "08:00:00",
"saturday_end" => "16:00:00", "saturday_end" => "16:00:00",
"sunday_start" => "08:00:00", "sunday_start" => "08:00:00",
"sunday_end" => "16:00:00", "sunday_end" => "16:00:00",
"created_by" => $this->currentName "created_by" => $this->currentName
); );
OfficeHours::create($dataCreate); OfficeHours::create($dataCreate);
return true; return true;
} }
public function delete($id, $company_id) public function delete($id, $company_id)
{ {
DB::beginTransaction(); DB::beginTransaction();
$data = Project::find($id); $data = Project::find($id);
$dateNow = Carbon::now(); $dateNow = Carbon::now();
if ($data) { if ($data) {
$this->deleteRelative($id, $company_id); $this->deleteRelative($id, $company_id);
if ($data->delete()) { 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(); DB::commit();
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
} else { } else {
@ -192,13 +222,13 @@ class ProjectController extends Controller
} }
} else { } else {
DB::rollBack(); 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) 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,24 +311,24 @@ 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)
{ {
$payload = $request->all(); $payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_proyek'); $dataBuilder = $this->setUpPayload($payload, 'm_proyek');
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$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()
{ {
DB::beginTransaction(); DB::beginTransaction();
try { try {
$data = Project::select( $data = Project::select(
@ -383,67 +413,66 @@ class ProjectController extends Controller
} catch (\Throwable $th) { } catch (\Throwable $th) {
DB::rollBack(); DB::rollBack();
} }
} }
public function getListProjectTask($id) public function getListProjectTask($id)
{ {
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id", "m_proyek.*") $data = UserToActivity::select("assign_hr_to_activity.user_id as user_id", "m_proyek.*")
->where("assign_hr_to_activity.user_id", $id) ->where("assign_hr_to_activity.user_id", $id)
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id') ->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
->groupBy("m_proyek.proyek_id") ->groupBy("m_proyek.proyek_id")
->get(); ->get();
if ($data) { if ($data) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} 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)
{
$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));
public function getSCurve(Request $request)
{ // return response()->json(['message' => 'S Curve calculation queued']);
$data = MasterFunctionsHelper::getSCurve($request); // }
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} // return response()->json(['message' => 'Project not found'], 404);
}
// testing
public function calculateSCurvetest(Request $request) public function getLinearSCurve(Request $request)
{ {
$data = MasterFunctionsHelper::calculateSCurve($request->project_id); $data = MasterFunctionsHelper::getLinearSCurve($request);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} }
public function calculateSCurve(Request $request) public static function setSyncDate($activity_id, $activity, $report)
{ {
$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)
{
DB::beginTransaction(); DB::beginTransaction();
try { try {
$status = AssignMaterial::where('activity_id', $activity_id)->first(); $status = AssignMaterial::where('activity_id', $activity_id)->first();
@ -478,10 +507,10 @@ class ProjectController extends Controller
} catch (\Throwable $th) { } catch (\Throwable $th) {
DB::rollBack(); DB::rollBack();
} }
} }
public function synchronizeReport($gantt_id) public function synchronizeReport($gantt_id)
{ {
DB::beginTransaction(); DB::beginTransaction();
try { try {
$activities = Activity::where("version_gantt_id", $gantt_id)->get(); $activities = Activity::where("version_gantt_id", $gantt_id)->get();
@ -517,8 +546,8 @@ class ProjectController extends Controller
} else if ($reports[$i]['status'] == 'done') { } else if ($reports[$i]['status'] == 'done') {
$activity->actual_end = $reports[$i]['max_date']->setTime(23, 59, 59); $activity->actual_end = $reports[$i]['max_date']->setTime(23, 59, 59);
} }
$activity->start_date = $reports[$i]['min_date']; //same early $activity->start_date = $reports[$i]['min_date']; //same early
$activity->end_date = $reports[$i]['max_date']->setTime(23, 59, 59); // same early $activity->end_date = $reports[$i]['max_date']->setTime(23, 59, 59); // same early
$startDate = new DateTime($activity->start_date); $startDate = new DateTime($activity->start_date);
$endDate = new DateTime($activity->end_date); $endDate = new DateTime($activity->end_date);
$duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate); $duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate);
@ -531,74 +560,54 @@ class ProjectController extends Controller
} catch (\Throwable $th) { } catch (\Throwable $th) {
DB::rollBack(); DB::rollBack();
} }
} }
public function setBaseline($gantt_id) public function setBaseline($gantt_id)
{ {
$activities = Activity::where("version_gantt_id", $gantt_id)->get(); $activities = Activity::where("version_gantt_id", $gantt_id)->get();
foreach ($activities as $activity) { foreach ($activities as $activity) {
$activity->update([ $activity->update([
"planned_start" => $activity->start_date, "planned_start" => $activity->start_date,
"planned_end" => $activity->end_date, "planned_end" => $activity->end_date,
"early_start" => $activity->start_date, "early_start" => $activity->start_date,
"early_end" => $activity->end_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) 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,
"early_start" => $activity->start_date, "early_start" => $activity->start_date,
"early_end" => $activity->end_date, "early_end" => $activity->end_date,
]); ]);
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)
{ public function getByUser($id)
DB::beginTransaction(); {
try { $userProyek = UserToProyek::query()
$ganttCount = VersionGantt::where('proyek_id', $request->id)->count(); ->from('assign_hr_to_proyek AS utp')
$search = urlencode($request->search); ->where([['is_customer', true], ['user_id', $id]])
if (empty($search)) { ->leftJoin('m_users', 'utp.user_id', '=', 'm_users.id')
return response()->json(['status' => 'error', 'message' => 'Empty query string!'], 400); ->leftJoin('m_proyek', 'utp.proyek_id', '=', 'm_proyek.id')
} ->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
$url = str_replace("SEARCH", $search, config('api.adw') . '/project_cost?project_no=SEARCH'); ->select('m_proyek.*', 'm_type_proyek.name AS join_second_name', 'm_users.name AS join_first_name')
->get();
$response = MasterFunctionsHelper::curlReq($url); $totalRecord = $userProyek->count();
if (isset($request->gantt_id)) {
$response->data->total_cost = $response->data->total_cost / $ganttCount; return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
} }
DB::commit();
return response()->json(['status' => 'success', 'data' => $response, 'code' => 200], 200); public function detail(Request $request, $id, $gantt_id = null, $s_curve = null)
} 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)
{
DB::beginTransaction(); DB::beginTransaction();
try { try {
if (empty($id) || !is_int((int)$id)) { if (empty($id) || !is_int((int)$id)) {
@ -673,10 +682,10 @@ class ProjectController extends Controller
} catch (\Throwable $th) { } catch (\Throwable $th) {
DB::rollBack(); DB::rollBack();
} }
} }
public function getOverdueActivities(Request $request) public function getOverdueActivities(Request $request)
{ {
DB::beginTransaction(); DB::beginTransaction();
try { try {
$payload = $request->all(); $payload = $request->all();
@ -712,10 +721,10 @@ class ProjectController extends Controller
} catch (\Throwable $th) { } catch (\Throwable $th) {
DB::rollBack(); DB::rollBack();
} }
} }
public function getReportDistribution(Request $request) public function getReportDistribution(Request $request)
{ {
DB::beginTransaction(); DB::beginTransaction();
try { try {
$payload = $request->all(); $payload = $request->all();
@ -750,25 +759,25 @@ class ProjectController extends Controller
} catch (\Throwable $th) { } catch (\Throwable $th) {
DB::rollBack(); DB::rollBack();
} }
} }
public function getManpower($proyek_id) public function getManpower($proyek_id)
{ {
$manCount = UserToProyek::where('proyek_id', $proyek_id)->count(); $manCount = UserToProyek::where('proyek_id', $proyek_id)->count();
return response()->json(['totalRecord' => $manCount]); return response()->json(['totalRecord' => $manCount]);
} }
public function getAssignedHR($gantt_id) 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') $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') ->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id')
->where('assign_hr_to_activity.version_gantt_id', $gantt_id) ->where('assign_hr_to_activity.version_gantt_id', $gantt_id)
->get(); ->get();
return response()->json(['data' => $results]); return response()->json(['data' => $results]);
} }
public function dashboard($id) public function dashboard($id)
{ {
DB::beginTransaction(); DB::beginTransaction();
try { try {
$data = Project::query() $data = Project::query()
@ -822,23 +831,23 @@ class ProjectController extends Controller
} catch (\Throwable $th) { } catch (\Throwable $th) {
DB::rollBack(); DB::rollBack();
} }
} }
private function httpReq($search) private function httpReq($search)
{ {
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION)); curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w')); curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w'));
$info = curl_getinfo($ch); $info = curl_getinfo($ch);
$output = curl_exec($ch); $output = curl_exec($ch);
curl_close($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 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())) 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);
}
private function curlReq($url, $token){
$ch = curl_init();
$headers = [
'Authorization: '.$token
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if ($response === false)
$response = curl_error($ch);
curl_close($ch);
return json_decode($response);
}
public function getMaterialIntegration(Request $request) {
$search = urlencode($request->name);
if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/stock_master?name=SEARCH');
$token = config('api.adw_token');
$firstResponse = $this->curlReq($url, $token);
if($firstResponse->total == 0)
return response()->json(['status'=>'error', 'message' => 'Data not found!', 'code'=>404], 404);
$data = $firstResponse->data;
$currentPage = 1;
if($firstResponse->last_page > 0) {
do {
$currentPage++;
$response = $this->curlReq($url.'&page='.$currentPage, $token);
foreach($response->data as $d){
array_push($data, $d);
}
} while ($currentPage < 5);
// let the user narrow down the search by themself
// a searching action with 'cable' keyword could take minutes
// because there are >1k items associated with that keyword
}
return response()->json(['status'=>'success', 'data'=> $data, 'total' => count($data), 'code'=>200], 200); 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