Browse Source

fix(remove):adw integration

pull/1/head
farhantock 7 months ago
parent
commit
cc49700795
  1. 54
      app/Helpers/MasterFunctionsHelper.php
  2. 4
      app/Http/Controllers/Controller.php
  3. 75
      app/Http/Controllers/DashboardBoDController.php
  4. 570
      app/Http/Controllers/ProjectController.php
  5. 140
      app/Http/Controllers/RequestMaterialController.php
  6. 167
      app/Http/Controllers/UserToProyekController.php

54
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;
@ -867,7 +843,7 @@ class MasterFunctionsHelper
$end = new \DateTime($maxDate . ' Friday');
$end->modify('next Friday');
$end->modify('next Friday');
/* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged
/* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged
$interval = new \DateInterval('P7D');
} else {
// $maxDate = DB::table('assign_material_to_activity as ama')
@ -1022,17 +998,17 @@ class MasterFunctionsHelper
->where('activity_id', '=', $keyActualM->activity_id)
->orderBy('status_activity', 'ASC')
->first();
if (!isset($checkStatusActivity)) {
$checkStatusActivity = (object) [
'activity_id' => $keyActualM->activity_id,
'status_activity' => 'open'
];
}
if ($sumVolActual->ttl_qty_plan == "0") {
$actual = 0;
} else {
$actual = $keyActualM->qty / $sumVolActual->ttl_qty_plan;
}
if (!isset($checkStatusActivity)) {
$checkStatusActivity = (object) [
'activity_id' => $keyActualM->activity_id,
'status_activity' => 'open'
];
}
if ($sumVolActual->ttl_qty_plan == "0") {
$actual = 0;
} else {
$actual = $keyActualM->qty / $sumVolActual->ttl_qty_plan;
}
$dataTempReport[$w]['percentage'] = $actual * $keyActualM->bobot_planning;
// $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
// if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){
@ -1040,7 +1016,7 @@ class MasterFunctionsHelper
$sumPercentageActual += $keyActualM->bobot_planning / $reportCount;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else {
if ( $actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) {
if ($actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) {
$sumPercentageActual += ($actual * $keyActualM->bobot_planning) * (95 / 100);
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else {
@ -1075,7 +1051,7 @@ class MasterFunctionsHelper
if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') {
$tempTtlPercentPlan += $sumPercentagePlan;
$tempTtlPercentActual += $sumPercentageActual;
// todo
// todo
// if ($tempTtlPercentPlan >= 100)
// $tempTtlPercentPlan = 100;
@ -1119,7 +1095,7 @@ class MasterFunctionsHelper
}
$lastReal = $tempPercentageReal[count($tempPercentageReal) - 1];
$totalBCWP = $lastReal * $dataProject->rencana_biaya / 100;
$totalBCWP = $lastReal * $dataProject->rencana_biaya / 100;
$dataResponse = array(
"date" => $tempDate,
"start" => $begin,

4
app/Http/Controllers/Controller.php

@ -295,11 +295,7 @@ class Controller extends BaseController
private function curlRequest($url)
{
$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);

75
app/Http/Controllers/DashboardBoDController.php

@ -21,38 +21,6 @@ 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);
$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 == "")
return null;
return $response;
}
// to do
public function getCompanyCashFlow($year = '%')
@ -63,27 +31,22 @@ class DashboardBoDController extends Controller
// we can't use eloquent's sum() method because someone decided to use varchar as datatype in rencana_biaya field
$totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->pluck('sum')
->first();
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->get();
foreach ($projects as $project) {
$project->expenses = 0;
$resp = null;
if ($project->kode_sortname != "") {
$resp = $this->getInvoiceIntegration($project->kode_sortname);
/* $resp = $project->kode_sortname; */
$cost = $resp->data->total_cost ?? 0;
$cost = 0;
$cost = substr($cost, 0, strpos($cost, "."));
$totalExpenditure += (int) $cost;
$totalInvoice += $resp->data->total_invoice_amount ?? 0;
$totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0;
$totalInvoice += 0;
$totalPaidInvoice += 0;
}
}
return response()->json([
@ -100,19 +63,15 @@ class DashboardBoDController extends Controller
{
$year = $this->interpolateYear($year);
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->get();
$return = [];
foreach ($projects as $project) {
$resp = null;
if ($project->kode_sortname != "") {
$resp = $this->getInvoiceIntegration($project->kode_sortname);
array_push($return, [
'project' => $project->nama,
'project_code' => $project->kode_sortname,
'invoiced' => $resp->data->total_invoice_amount ?? 0,
'paid' => $resp->data->total_invoice_paid_amount ?? 0,
'response' => $resp,
'invoiced' => 0,
'paid' => 0,
]);
}
}
@ -147,15 +106,13 @@ class DashboardBoDController extends Controller
}
$selisihProgress = $planningProgress - $actualProgress;
try {
if ($selisihProgress > 0 && $selisihProgress <= 5){
if ($selisihProgress > 0 && $selisihProgress <= 5) {
$return['warning'] += 1;
$projects[$index]->status = 'warning';
}
elseif ($selisihProgress == 0){
} elseif ($selisihProgress == 0) {
$return['on-schedule'] += 1;
$projects[$index]->status = 'on-schedule';
}
else {
} else {
$return['behind-schedule'] += 1;
$projects[$index]->status = 'behind-schedule';
}
@ -191,13 +148,11 @@ class DashboardBoDController extends Controller
$actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0;
}
$selisihProgress = $planningProgress - $actualProgress;
if ($selisihProgress > 0 && $selisihProgress <= 5){
if ($selisihProgress > 0 && $selisihProgress <= 5) {
$warning++;
}
elseif ($selisihProgress == 0){
} elseif ($selisihProgress == 0) {
$onSchedule++;
}
else {
} else {
$behindSchedule++;
}
}
@ -294,7 +249,7 @@ class DashboardBoDController extends Controller
{
$year = $this->interpolateYear($year);
$divisions = Divisi::select('id', 'name','parent','color')
$divisions = Divisi::select('id', 'name', 'parent', 'color')
->with('children')
->whereNull('parent')
->get();
@ -358,15 +313,13 @@ class DashboardBoDController extends Controller
$lastGantt = MasterFunctionsHelper::getLatestGantt($project->id);
if ($project->kode_sortname != "") {
$resp = $this->getInvoiceIntegration($project->kode_sortname);
$project->invoice = [
'invoiced' => $resp->data->total_invoice_amount ?? 0,
'paid' => $resp->data->total_invoice_paid_amount ?? 0,
'invoiced' => 0,
'paid' => 0,
];
}
$project->pm = User::find($project->pm_id);
/* $project->header = Activity::where('proyek_id', $project->id)->where('version_gantt_id', $lastGantt['last_gantt_id'])->whereNull('parent_id')->first(); */
if (!isset($lastGantt['last_gantt_id'])) {
$project->manPowers = 0;
} else {

570
app/Http/Controllers/ProjectController.php

@ -50,7 +50,7 @@ class ProjectController extends Controller
{
$this->validate($request, [
'nama' => 'required',
'mulai_proyek' => 'required',
'mulai_proyek' => 'required',
'akhir_proyek' => 'required',
'rencana_biaya' => 'required',
'type_proyek_id' => 'required'
@ -60,80 +60,80 @@ class ProjectController extends Controller
$data['created_by'] = $this->currentName;
if(empty($data['phase_id']))
if (empty($data['phase_id']))
$data['phase_id'] = 1;
$result = Project::create($data);
if(!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500);
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500);
$this->createOfficeHours($result->id);
$dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first();
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);
}
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::query()
->from('m_proyek AS mp')
->where('mp.id', $id)
->selectRaw('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');
$result = Project::query()
->from('m_proyek AS mp')
->where('mp.id', $id)
->selectRaw('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');
if (!is_null($result->first()['divisi_id'])) {
$result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id')
->addSelect(DB::raw('m_divisi.name AS nama_divisi'));
}
if (!is_null($result->first()['divisi_id'])) {
$result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id')
->addSelect(DB::raw('m_divisi.name AS nama_divisi'));
}
$result = $result->first();
$result = $result->first();
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
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)
{
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);
$data = Project::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
$result = $data->update($request->all());
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500);
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500);
return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200);
return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200);
}
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
"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);
@ -145,15 +145,15 @@ class ProjectController extends Controller
{
$data = Project::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
$this->deleteRelative($id);
if(!$data->delete())
return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500);
if (!$data->delete())
return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500);
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
}
private function deleteRelative($project_id)
@ -168,12 +168,12 @@ class ProjectController extends Controller
ProjectChecklists::where('proyek_id', $project_id)->delete();
ProjectIssues::where('proyek_id', $project_id)->delete();
ProjectRisks::where('proyek_id', $project_id)->delete();
ProjectToChecklistK3::where('proyek_id', $project_id)->delete();
HierarchyFtth::where('project_id', $project_id)->delete();
AssignTools::where('proyek_id', $project_id)->delete();
OfficeHours::where('proyek_id', $project_id)->delete();
ReportK3::where('proyek_id', $project_id)->delete();
RequestMaterial::where('proyek_id', $project_id)->delete();
ProjectToChecklistK3::where('proyek_id', $project_id)->delete();
HierarchyFtth::where('project_id', $project_id)->delete();
AssignTools::where('proyek_id', $project_id)->delete();
OfficeHours::where('proyek_id', $project_id)->delete();
ReportK3::where('proyek_id', $project_id)->delete();
RequestMaterial::where('proyek_id', $project_id)->delete();
$this->deleteVersionGantt($project_id);
$this->deleteDokumenProject($project_id);
}
@ -188,16 +188,16 @@ class ProjectController extends Controller
foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($images as $image) {
if(file_exists($this->pathImage.$image->image)){
unlink($this->pathImage.$image->image);
if (file_exists($this->pathImage . $image->image)) {
unlink($this->pathImage . $image->image);
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
}
$dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get();
foreach ($dataAd as $ad) {
if(file_exists($this->pathActivityDocument.$ad->file)){
unlink($this->pathActivityDocument.$ad->file);
if (file_exists($this->pathActivityDocument . $ad->file)) {
unlink($this->pathActivityDocument . $ad->file);
}
}
ActivityDokumen::whereIn("activity_id", $activityIds)->delete();
@ -215,8 +215,8 @@ class ProjectController extends Controller
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get();
foreach ($dataDokumen as $dokumen) {
if(file_exists($this->pathDocument.$dokumen->file)){
unlink($this->pathDocument.$dokumen->file);
if (file_exists($this->pathDocument . $dokumen->file)) {
unlink($this->pathDocument . $dokumen->file);
}
}
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete();
@ -225,8 +225,8 @@ class ProjectController extends Controller
$ref_ids = $dataFolder->all();
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get();
foreach ($dataDokumen as $dokumen) {
if(file_exists($this->pathDocument.$dokumen->file)){
unlink($this->pathDocument.$dokumen->file);
if (file_exists($this->pathDocument . $dokumen->file)) {
unlink($this->pathDocument . $dokumen->file);
}
}
@ -240,11 +240,11 @@ class ProjectController extends Controller
$dataBuilder = $this->setUpPayload($payload, 'm_proyek');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
// $builder->where("selfTable.created_by",$this->currentName);
// $builder->where("selfTable.created_by",$this->currentName);
$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()
@ -286,101 +286,109 @@ class ProjectController extends Controller
'created_by',
'updated_at',
'updated_by'
)->orderBy('id', 'desc')
// ->where("created_by",$this->currentName)
->get();
)->orderBy('id', 'desc')
// ->where("created_by",$this->currentName)
->get();
$countData = $data->count();
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
$totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost')));
$totalActualCost = $data->sum('actualCost');
$totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost')));
$totalActualCost = $data->sum('actualCost');
$manpowers = User::count();
$projectsOnDanger = Project::where('budget_health', 'overrun')->count();
$projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name');
$projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name');
try {
$projectsByPhase = DB::table('m_proyek')
->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total'))
->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id')
->groupBy('m_proyek_phase.name', 'm_proyek_phase.color')
->get();
} catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()]);
}
try {
$projectsByType = DB::table('m_proyek')
->select('m_type_proyek.name', DB::raw('count(m_type_proyek.id) as total'))
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id')
->groupBy('m_type_proyek.name')
->get();
} catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()]);
}
$projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name');
$projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name');
try {
$projectsByPhase = DB::table('m_proyek')
->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total'))
->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id')
->groupBy('m_proyek_phase.name', 'm_proyek_phase.color')
->get();
} catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()]);
}
try {
$projectsByType = DB::table('m_proyek')
->select('m_type_proyek.name', DB::raw('count(m_type_proyek.id) as total'))
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id')
->groupBy('m_type_proyek.name')
->get();
} catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()]);
}
return response()->json(
[
'status'=>'success',
'code'=>200,
'data'=>$data,
'totalRecord'=>$countData,
'totalPlannedCost' => $totalPlannedCost,
'totalActualCost' => $totalActualCost,
'totalRevenue' => $totalPlannedCost - $totalActualCost,
'manpowers' => $manpowers,
'projectsOnDanger'=> $projectsOnDanger,
'projectPhases' => $projectPhases,
'projectsByPhase' => $projectsByPhase,
'projectTypes' => $projectTypes,
'projectsByType' => $projectsByType,
], 200);
[
'status' => 'success',
'code' => 200,
'data' => $data,
'totalRecord' => $countData,
'totalPlannedCost' => $totalPlannedCost,
'totalActualCost' => $totalActualCost,
'totalRevenue' => $totalPlannedCost - $totalActualCost,
'manpowers' => $manpowers,
'projectsOnDanger' => $projectsOnDanger,
'projectPhases' => $projectPhases,
'projectsByPhase' => $projectsByPhase,
'projectTypes' => $projectTypes,
'projectsByType' => $projectsByType,
],
200
);
}
public function getListProjectTask($id){
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*")
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)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
public function getSCurve(Request $request){
public function getSCurve(Request $request)
{
$data = MasterFunctionsHelper::getSCurve($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){
$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 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 sCurveCommand(Request $request)
{
Artisan::call('calculate:scurve', [
'project_id' => $request->project_id
]);
// $project = Project::find($request->project_id);
// if ($project) {
// dispatch(new ProcessSCurve($project));
// if ($project) {
// dispatch(new ProcessSCurve($project));
// return response()->json(['message' => 'S Curve calculation queued']);
// }
// return response()->json(['message' => 'S Curve calculation queued']);
// }
// return response()->json(['message' => 'Project not found'], 404);
}
// return response()->json(['message' => 'Project not found'], 404);
}
public function getLinearSCurve(Request $request){
public function getLinearSCurve(Request $request)
{
$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 static function setSyncDate($activity_id, $activity, $report) {
public static function setSyncDate($activity_id, $activity, $report)
{
$status = AssignMaterial::where('activity_id', $activity_id)->first();
if (!isset($status)) {
$reports = array(
@ -412,17 +420,17 @@ class ProjectController extends Controller
return $reports;
}
public function synchronizeReport($gantt_id)
public function synchronizeReport($gantt_id)
{
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
$reports = [];
foreach($activities as $activity) {
foreach ($activities as $activity) {
$activity_id = $activity->id;
$countReports = ReportActivityMaterial::where('activity_id', $activity_id)->count();
if ($countReports === 1) {
$dataReports = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->get();
foreach($dataReports as $dr) {
foreach ($dataReports as $dr) {
$reports[] = ProjectController::setSyncDate($activity_id, $activity, $dr);
}
}
@ -443,15 +451,15 @@ class ProjectController extends Controller
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */
for ($i=0; $i < count($reports); $i++) {
for ($i = 0; $i < count($reports); $i++) {
$activity = Activity::find($reports[$i]['activity_id']);
if($reports[$i]['status'] != 'done'){
if ($reports[$i]['status'] != 'done') {
$reports[$i]['max_date']->modify('-1 day');
}else if($reports[$i]['status'] == 'done'){
$activity->actual_end = $reports[$i]['max_date']->setTime(23,59,59);
} 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->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);
@ -460,7 +468,7 @@ class ProjectController extends Controller
$activity->save();
}
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200);
return response()->json(['status' => 'success', 'message' => 'Synchronize to report success!', 'code' => 200], 200);
}
public function setBaseline($gantt_id)
@ -469,127 +477,113 @@ class ProjectController extends Controller
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,
"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 getInvoiceIntegration(Request $request) {
$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;
}
public function getByUser($id)
{
$alias = "utp";
$userProyek = UserToProyek::query()
->from('assign_hr_to_proyek AS ' . $alias)
->where([
['is_customer', true],
['user_id', $id]
])
->leftJoin('m_users', $alias . '.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', $alias . '.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', 'data'=> $response, 'code'=>200], 200);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
}
public function getByUser($id)
{
$alias = "utp";
$userProyek = UserToProyek::query()
->from('assign_hr_to_proyek AS ' . $alias)
->where([
['is_customer', true],
['user_id', $id]
])
->leftJoin('m_users', $alias.'.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', $alias.'.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){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
public function detail(Request $request, $id, $gantt_id = null, $s_curve = null)
{
if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$result = Project::find($id);
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
if (!isset($gantt_id)) {
$gantt = MasterFunctionsHelper::getLatestGantt($id);
$ganttId = $gantt['last_gantt_id'];
} else {
$ganttId = $gantt_id;
}
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
if (!isset($gantt_id)) {
$gantt = MasterFunctionsHelper::getLatestGantt($id);
$ganttId = $gantt['last_gantt_id'];
} else {
$ganttId = $gantt_id;
}
$result->projectManager = User::where('id', $result->pm_id)->value('name');
if (isset($s_curve)) {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first();
$actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists();
if($result['type_proyek_id'] === 9)
{
$actualEndExist = Activity::where('proyek_id', $id)->exists();
$query = Activity::where('proyek_id', $id);
}else{
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
$query = Activity::where('version_gantt_id', $ganttId);
}
} else {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first();
$actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists();
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
$query = Activity::where('version_gantt_id', $ganttId);
}
if ($actualStartExist) {
$startDate = $query->orderBy('actual_start')->value('start_date');
} else {
$startDate = $query->orderBy('start_date')->value('start_date');
}
if($actualEndExist)
{
$maxEndDate = $query->max('id');
$endDate = $query->where('id',$maxEndDate)->first()->end_date;
}
$plannedStart = Activity::where('version_gantt_id', $ganttId)
->orderBy('planned_start')
->value('planned_start');
$plannedEnd = Activity::where('version_gantt_id', $ganttId)
->orderByDesc('planned_end')
->value('planned_end');
$result->header->start_date = $startDate;
$result->header->end_date = $endDate;
$result->header->planned_start = $plannedStart;
$result->header->planned_end = $plannedEnd;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$ganttId], 200);
if (isset($s_curve)) {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first();
$actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists();
if ($result['type_proyek_id'] === 9) {
$actualEndExist = Activity::where('proyek_id', $id)->exists();
$query = Activity::where('proyek_id', $id);
} else {
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
$query = Activity::where('version_gantt_id', $ganttId);
}
} else {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first();
$actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists();
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
$query = Activity::where('version_gantt_id', $ganttId);
}
if ($actualStartExist) {
$startDate = $query->orderBy('actual_start')->value('start_date');
} else {
$startDate = $query->orderBy('start_date')->value('start_date');
}
if ($actualEndExist) {
$maxEndDate = $query->max('id');
$endDate = $query->where('id', $maxEndDate)->first()->end_date;
}
$plannedStart = Activity::where('version_gantt_id', $ganttId)
->orderBy('planned_start')
->value('planned_start');
$plannedEnd = Activity::where('version_gantt_id', $ganttId)
->orderByDesc('planned_end')
->value('planned_end');
$result->header->start_date = $startDate;
$result->header->end_date = $endDate;
$result->header->planned_start = $plannedStart;
$result->header->planned_end = $plannedEnd;
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result, 'gantt' => $ganttId], 200);
}
public function getOverdueActivities(Request $request){
public function getOverdueActivities(Request $request)
{
$payload = $request->all();
if(empty($payload['id']) || !is_int((int)$payload['id']))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if (empty($payload['id']) || !is_int((int)$payload['id']))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$result = Project::find($payload['id']);
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404);
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Project not found!', 'code' => 404], 404);
//TODO possible overdue bug
$endDate = Activity::where('proyek_id', $payload['id'])
->orderByDesc('end_date')
->value('end_date');
if(isset($payload['till_date'])) {
if (isset($payload['till_date'])) {
if (isset($payload['scurve'])) {
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get();
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get();
} else {
$overdueActivities = Activity::where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get();
$overdueActivities = Activity::where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get();
}
}
else {
} else {
if (isset($payload['scurve'])) {
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get();
} else {
@ -598,53 +592,75 @@ class ProjectController extends Controller
}
$result->overdueActivities = $overdueActivities;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
}
public function getReportDistribution(Request $request){
public function getReportDistribution(Request $request)
{
$payload = $request->all();
if(empty($payload['project_id']) || !is_int((int)$payload['project_id']))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if (empty($payload['project_id']) || !is_int((int)$payload['project_id']))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$reports = DB::table('assign_material_to_activity as ama')
->select('u.name', 'a.name as activity_name', 'ama.qty_planning', 'ram.qty as qty_real','rm.description as material_name', 'rm.uom as material_unit',
'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date')
->select(
'u.name',
'a.name as activity_name',
'ama.qty_planning',
'ram.qty as qty_real',
'rm.description as material_name',
'rm.uom as material_unit',
'ram.lat',
'ram.lon',
'ram.description as report_notes',
'ram.report_date'
)
->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id')
->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->join('m_users as u', 'u.id', '=', 'ram.user_id')
->where('ama.proyek_id', '=', $payload['project_id'])
->whereNotNull('ram.lat')
->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]);
->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]);
return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $reports], 200);
}
public function getManpower($proyek_id){
public function getManpower($proyek_id)
{
$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')
->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]);
return response()->json(['data' => $results]);
}
public function dashboard($id)
{
$data = DB::table('m_proyek as mp')
->select('mp.kode_sortname', 'mp.nama as name_project', 'mp.mulai_proyek as start', 'mp.akhir_proyek as finish',
'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm', 'mp.budget_health')
->join('m_users as mu', 'mu.id', '=', 'mp.pm_id')
->where('mp.id', $id)
->first();
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data tidak ditemukan!','code'=> 404], 404);
->select(
'mp.kode_sortname',
'mp.nama as name_project',
'mp.mulai_proyek as start',
'mp.akhir_proyek as finish',
'mp.rencana_biaya',
'mp.company',
'mp.currency_symbol',
'mu.name as pm',
'mp.budget_health'
)
->join('m_users as mu', 'mu.id', '=', 'mp.pm_id')
->where('mp.id', $id)
->first();
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data tidak ditemukan!', 'code' => 404], 404);
$manpowers = UserToProyek::where('proyek_id', $id)->count();
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first();
@ -653,38 +669,42 @@ class ProjectController extends Controller
$progress = @$rootActivity->persentase_progress ?? 0;
$commentActivity = DB::table('m_comment_activity as mca')
->select('mca.activity_id', 'mca.comment as comment', 'mca.created_by as comment_by', 'mca.created_at as comment_created',
'ma.name as activity')
->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id')
->where('ma.proyek_id', $id)
->orderBy('comment_by')
->take(2)
->get();
->select(
'mca.activity_id',
'mca.comment as comment',
'mca.created_by as comment_by',
'mca.created_at as comment_created',
'ma.name as activity'
)
->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id')
->where('ma.proyek_id', $id)
->orderBy('comment_by')
->take(2)
->get();
$data->actual_cost = $actualCost;
$data->progress = $progress;
$data->comment = $commentActivity;
$data->man_power = $manpowers;
return response()->json(['status'=>'success','code'=>200,'data'=> $data], 200);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
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_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);
$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);
}
}

167
app/Http/Controllers/UserToProyekController.php

@ -23,113 +23,114 @@ 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
'is_customer' => true
);
$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'=>'success' ,'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' => 'success', 'message' => 'Project customer failed created', 'code' => 400]);
}
}else{
return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]);
} else {
return response()->json(['status' => 'success', 'message' => 'Project customer successfull 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)
{
$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);
}
}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,8 +142,8 @@ class UserToProyekController extends Controller
foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($images as $image) {
if(file_exists($this->pathImage.$image->image)){
unlink($this->pathImage.$image->image);
if (file_exists($this->pathImage . $image->image)) {
unlink($this->pathImage . $image->image);
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
@ -160,7 +161,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()
@ -168,14 +169,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');
@ -184,73 +186,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