Custom Backend OSPRO Surveyor Indonesia
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
3.6 KiB

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ReportActivity;
use App\Models\Activity;
use App\Models\Project;
use DB;
class ControlMonitoringController extends Controller
{
public function search(Request $request)
{
// payload same like in goland API oke
$payload = $request->all();
// second parameter is table name
$dataBuilder = $this->setUpPayload($payload, 'm_proyek');
// builder for get data
$builder = $dataBuilder['builder'];
// builder for count data
$countBuilder = $dataBuilder['count'];
// execute builder
$dataGet = $builder->get();
// get another child data
if($request->has("child_data")){
$newDataGet = [];
$child_data = $request->child_data;
$date_start = $child_data['start_date'];
$date_end = $child_data['date_end'];
foreach ($dataGet as $value) {
$ganttId = $this->getMaxVersionGantt($value->id);
$allActivityIds = Activity::where("version_gantt_id", $ganttId)->where("proyek_id", $value->id)->pluck("id");
$value->volume_planning = Activity::where("version_gantt_id", $ganttId)->where("proyek_id", $value->id)->sum("jumlah_pekerjaan");
$value->biaya_actual = Activity::where("version_gantt_id", $ganttId)->where("proyek_id", $value->id)->sum("biaya_actual");
$value->volume_actual = ReportActivity::where("activity_id", $allActivityIds->all())->sum("job_count_report");
$listAct = [];
$activityIds = ReportActivity::select("ma.id as id")->join("m_activity as ma", "ma.id", "=", "report_activity.activity_id")->where("ma.version_gantt_id", $ganttId)->where("ma.proyek_id", $value->id)->whereBetween("report_activity.report_date", [$date_start, $date_end])->groupBy("ma.id")->get()->pluck('id');
$dataActivity = Activity::select("m_activity.*", "ms.name as uom")->leftJoin("m_satuan as ms", "ms.id","=","m_activity.satuan_id")->whereIn("m_activity.id", $activityIds->all())->get();
foreach($dataActivity as $act){
$act->list_report = ReportActivity::select("report_activity.*", "mu.name as user_name", "mi.image as image_url")->leftJoin("m_users as mu", "mu.id", "=", "report_activity.user_id")->leftJoin("m_image as mi", function($join){
$join->on("mi.ref_id", "=", "report_activity.id")->where("mi.category", "report_activity");
})->where("report_activity.activity_id", $act->id)->whereBetween("report_activity.report_date", [$date_start, $date_end])->get();
// $act->list_report = ReportActivity::select("report_activity.*", "mu.name as user_name")->leftJoin("m_users as mu", "mu.id", "=", "report_activity.user_id")->where("report_activity.activity_id", $act->id)->whereBetween("report_activity.report_date", [$date_start, $date_end])->get();
$listAct[] = $act;
}
$value->report_data = $listAct;
$newDataGet[] = $value;
}
$dataGet = $newDataGet;
}
// execute count builder
$totalRecord = $countBuilder->count();
// dd($totalRecord);
// send response about the result
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
private function getMaxVersionGantt($id){
return Activity::where("proyek_id", $id)->max("version_gantt_id");
}
}