Browse Source

Merge pull request 'staging upload 23-03-30' (#7) from staging into master

Reviewed-on: ordo/adw-backend#7
pull/3/head
ibnu 2 years ago
parent
commit
a75adcb843
  1. 191
      app/Http/Controllers/ActivityController.php
  2. 115
      app/Http/Controllers/DashboardBoDController.php
  3. 144
      app/Http/Controllers/ProjectController.php
  4. 29
      app/Models/Activity.php
  5. 2
      app/Models/VersionGantt.php

191
app/Http/Controllers/ActivityController.php

@ -10,6 +10,7 @@ use App\Models\TmpImport;
use App\Models\VersionGantt;
use App\Models\UserToActivity;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ActivityController extends Controller
{
@ -387,7 +388,195 @@ class ActivityController extends Controller
}
return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200);
}
}
private function getLatestGantt($id){
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
$data = array(
"last_gantt_id" => $maxGanttId,
"proyek_id" => $id
);
return $data;
}
public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date)
{
$dataPayload = $request->all();
$allGantt = [];
if(isset($dataPayload['gannt_id'])){
$allGantt = $dataPayload['gannt_id'];
}else{
foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getLatestGantt($val);
}
}
$dataFinal=[];
foreach ($allGantt as $keyGantt) {
$dataProject = Project::find($keyGantt['proyek_id']);
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->first();
if($dataHeader){
$totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
}else{
$totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
}
$minDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id'])
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->min("plan_date");
$maxDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id'])
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->max("plan_date");
$begin = new \DateTime($minDate);
$end = new \DateTime($maxDate);
$end2 = new \DateTime($maxDate);
$interval = \DateInterval::createFromDateString('1 day');
$period = new \DatePeriod($begin, $interval, $end);
$arr_ActualM = [];
$tempDate = [];
$tempPercentage = [];
$tempTtlPercentPlan=0;
$tempTtlPercentActual=0;
$currentACWP = 0;
$budgetControlACWP = 0;
$currentProgressActivity = 0;
$currentBCWP = 0;
$budgetControlBCWP = 0;
foreach ($period as $dt) {
$dataPlanM = DB::table('assign_material_to_activity as ama')
->select('ama.activity_id', 'ama.qty_planning', 'ama.plan_date', 'ama.start_activity', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('ama.proyek_id', '=', $keyGantt['proyek_id'])
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->whereDate('ama.plan_date', $dt->format("Y-m-d"))
->get();
$dataActualM = DB::table('report_activity_material as ram')
->select('ram.activity_id', 'ram.qty', 'ram.report_date', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress')
->join('m_activity as a', 'a.id', '=', 'ram.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->where('a.proyek_id', '=', $keyGantt['proyek_id'])
->whereDate('ram.report_date', $dt->format("Y-m-d"))
->get();
$dataTempPlan = [];
$x = 0;
$sumPercentagePlan=0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
foreach ($dataPlanM as $keyPlanM) {
$sumVolPlan = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyPlanM->activity_id)
->groupBy('activity_id')
->first();
$dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id;
$dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning;
$dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date;
$dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity;
$dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan;
$dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual;
$dataTempPlan [$x]['duration'] = $keyPlanM->duration;
$dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress;
$dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100;
$dataTempPlan [$x]['totalBCWP'] = $totalBCWP;
$x++;
}
$w = 0;
$dataTempReport = [];
$sumPercentageActual=0;
foreach ($dataActualM as $keyActualM) {
$sumVolActual = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyActualM->activity_id)
->groupBy('activity_id')
->first();
$dataTempReport [$w]['activity_id'] = $keyActualM->activity_id;
$dataTempReport [$w]['qty'] = $keyActualM->qty;
$dataTempReport [$w]['report_date'] = $keyActualM->report_date;
$dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning;
$dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan;
$dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual;
$dataTempReport [$w]['duration'] = $keyActualM->duration;
$dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress;
$dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
$sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
$totalACWP += $keyActualM->biaya_actual/$keyActualM->duration;
$dataTempReport [$w]['totalacwp'] = $totalACWP;
$w++;
}
$arr_ActualM[] = array(
'date'=>$dt->format("Y-m-d"),
'percentPlan'=>$sumPercentagePlan,
'percentActual'=>$sumPercentageActual,
'plan'=>$dataTempPlan,
'actual'=>$dataTempReport,
);
if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){
if($dt->format("w")==1){
if($totalACWP > 0 ){
$budgetControlACWP = $currentACWP + $totalACWP;
}
if($totalBCWP > 0 ){
$budgetControlBCWP = $currentBCWP + $totalBCWP;
}
$tempTtlPercentPlan+= $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual;
$currentACWP += $totalACWP;
$currentBCWP += $totalBCWP;
$tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2));
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
}else if($dt->format("Y-m-d") == $end2->format("Y-m-d")) {
$tempTtlPercentPlan+= $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual;
$currentACWP += $totalACWP;
$currentBCWP += $totalBCWP;
$tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2));
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
$tempTtlPercentPlan = 0;
$tempTtlPercentActual = 0;
}
}else{
$tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2));
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
}
}
if(round($totalACWP,0) > $totalRencanaBudget){
$estimatedCost = round($totalACWP,0)+0;
}else{
$estimatedCost = ($totalRencanaBudget+0);
}
$costDeviation = $totalRencanaBudget - $estimatedCost;
if($costDeviation > 0){
$potential = "SAVING";
} else {
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
}
$dataResponse = array(
"date" =>$tempDate,
"percentage" =>$tempPercentage,
"data_details" =>$arr_ActualM,
"budget_control" =>array("current_budget"=> $totalRencanaBudget,
"acwp" => round($totalACWP,0),
"bcwp" => round($totalBCWP,0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)),
"add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation,
"potential" => $potential,
)
);
$dataFinal[] = array(
"proyek_name"=> $dataProject->nama,
"data"=>$dataResponse,
"allGant"=>$allGantt
);
}
return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200);
}
public function import(Request $request)
{

115
app/Http/Controllers/DashboardBoDController.php

@ -2,7 +2,6 @@
namespace App\Http\Controllers;
<<<<<<< HEAD
use App\Helpers\MasterFunctionsHelper;
use App\Models\Divisi;
use App\Models\Project;
@ -11,13 +10,6 @@ use App\Models\User;
use App\Models\UserToVersionGantt;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
=======
use App\Models\Project;
use App\Models\Divisi;
use App\Models\ProjectPhase;
use Illuminate\Support\Collection;
use DB;
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
class DashboardBoDController extends Controller
{
@ -27,7 +19,6 @@ class DashboardBoDController extends Controller
return $year;
}
<<<<<<< HEAD
private function curlReq($url, $token){
$ch = curl_init();
$headers = [
@ -63,15 +54,10 @@ class DashboardBoDController extends Controller
public function getCompanyCashFlow($year = '%') {
$year = $this->interpolateYear($year);
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0;
=======
public function getCompanyCashFlow($year = '%') {
$year = $this->interpolateYear($year);
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
// 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)
<<<<<<< HEAD
/* ->orWhere('akhir_proyek', 'like', $year) */
->pluck('sum')
->first();
@ -101,22 +87,10 @@ class DashboardBoDController extends Controller
'total_expenditure' => $totalExpenditure,
'total_invoice' => $totalInvoice,
'total_paid_invoice' => $totalPaidInvoice ,
=======
->pluck('sum')
->first();
return response()->json([
'data' => [
'total_budget' => (int) $totalBudgets ?? rand(0,10),
'total_expenditure' => rand(0,10), // to do integrasi
'total_invoice' => rand(0,10),
'total_paid_invoice' => rand(0,10),
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
]
], 200);
}
<<<<<<< HEAD
public function getInvoiceOutstanding($year = '%'){
$year = $this->interpolateYear($year);
$projects = Project::where('mulai_proyek', 'like', $year)
@ -170,27 +144,10 @@ class DashboardBoDController extends Controller
}
public function getTotalProjectScheduleHealthPerDivision($year = '%'){
=======
public function getProjectPerScheduleHealth($year = '%'){
$year = $this->interpolateYear($year);
// get data plan (vol) in %
// get data actual in %
return response()->json([
'data' => [
'behind-schedule' => rand(0,10),
'warning' => rand(0,10),
'on-schedule' => rand(0,10),
]
], 200);
}
public function getProjectScheduleHealthPerDivision($year = '%'){
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
$year = $this->interpolateYear($year);
$divisions = Divisi::whereNull('parent')->get();
foreach($divisions as $division){
<<<<<<< HEAD
$scheduleData = new Collection();
$behindSchedule = $warning = $onSchedule = 0;
@ -209,12 +166,6 @@ class DashboardBoDController extends Controller
$scheduleData->prepend($behindSchedule, 'behindSchedule');
$scheduleData->prepend($warning, 'warning');
$scheduleData->prepend($onSchedule, 'onSchedule');
=======
$scheduleData = new Collection();
$scheduleData->prepend(rand(0, 10), 'behindSchedule');
$scheduleData->prepend(rand(0, 10), 'warning');
$scheduleData->prepend(rand(0, 10), 'onSchedule');
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
$division->scheduleData = $scheduleData;
}
return response()->json([
@ -224,7 +175,6 @@ class DashboardBoDController extends Controller
], 200);
}
<<<<<<< HEAD
public function getTotalProjectPerBudgetHealth($year = '%'){
$year = $this->interpolateYear($year);
return response()->json([
@ -232,20 +182,10 @@ class DashboardBoDController extends Controller
'overrun' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'overrun')->count(),
'warning' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'warning')->count(),
'on-budget' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'on-budget')->count(),
=======
public function getProjectPerBudgetHealth($year = '%'){
$year = $this->interpolateYear($year);
return response()->json([
'data' => [
'overrun' => rand(0,10),
'warning' => rand(0,10),
'on-budget' => rand(0,10),
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
]
], 200);
}
<<<<<<< HEAD
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health){
return Project::where('divisi_id', $divisi)
->where('mulai_proyek', 'like', $year)
@ -277,19 +217,6 @@ class DashboardBoDController extends Controller
}
foreach($divisions as $division){
}
=======
public function getProjectBudgetHealthPerDivision($year = '%'){
$year = $this->interpolateYear($year);
$divisions = Divisi::whereNull('parent')->get();
foreach($divisions as $division){
$budgetData = new Collection();
$budgetData->prepend(rand(0, 10), 'overrun');
$budgetData->prepend(rand(0, 10), 'warning');
$budgetData->prepend(rand(0, 10), 'onBudget');
$division->budgetData = $budgetData;
}
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
return response()->json([
'data' => [
$divisions
@ -297,7 +224,6 @@ class DashboardBoDController extends Controller
], 200);
}
<<<<<<< HEAD
public function getTotalProjectPerPhase($year = '%'){
$year = $this->interpolateYear($year);
$projectPhases = ProjectPhase::orderBy('order')->get();
@ -306,13 +232,6 @@ class DashboardBoDController extends Controller
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->count();
=======
public function getProjectPerPhase($year = '%'){
$year = $this->interpolateYear($year);
$projectPhases = ProjectPhase::orderBy('order')->get();
foreach($projectPhases as $phase){
$phase->totalProject = rand(0,10);
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
}
return response()->json([
'data' => [
@ -324,31 +243,19 @@ class DashboardBoDController extends Controller
private function countTotalProjectInDivision($id, $year){
return Project::where('divisi_id', $id)
->where('mulai_proyek', 'like', $year)
<<<<<<< HEAD
/* ->orWhere('akhir_proyek', 'like', $year) */
=======
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
->count();
}
public function getTotalProjectPerDivision($year = '%') {
$year = $this->interpolateYear($year);
<<<<<<< HEAD
$divisions = Divisi::select('id','name')
=======
$totalProjectPerDivision = Divisi::select('id','name')
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
->with('children')
->whereNull('parent')
->get();
// to do : count in more than 1 level child
<<<<<<< HEAD
foreach($divisions as $v){
=======
foreach($totalProjectPerDivision as $v){
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
$v->total = $this->countTotalProjectInDivision($v->id, $year);
foreach($v->children as $d){
$v->total += $this->countTotalProjectInDivision($d->id, $year);
@ -357,21 +264,14 @@ class DashboardBoDController extends Controller
}
return response()->json([
<<<<<<< HEAD
'data' => $divisions
=======
'data' => $totalProjectPerDivision
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
], 200);
}
private function countTotalProjectValueInDivision($id, $year){
return Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
->where('mulai_proyek', 'like', $year)
<<<<<<< HEAD
/* ->orWhere('akhir_proyek', 'like', $year) */
=======
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
->where('divisi_id', $id)
->pluck('sum')
->first();
@ -380,21 +280,13 @@ class DashboardBoDController extends Controller
public function getTotalProjectValuePerDivision($year = '%') {
$year = $this->interpolateYear($year);
<<<<<<< HEAD
$divisions = Divisi::select('id','name')
=======
$totalProjectValuePerDivision = Divisi::select('id','name')
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
->with('children')
->whereNull('parent')
->get();
// to do : count in more than 1 level child
<<<<<<< HEAD
foreach($divisions as $v){
=======
foreach($totalProjectValuePerDivision as $v){
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
$v->total = $this->countTotalProjectValueInDivision($v->id, $year);
foreach($v->children as $d){
$v->total += $this->countTotalProjectValueInDivision($d->id, $year);
@ -403,7 +295,6 @@ class DashboardBoDController extends Controller
}
return response()->json([
<<<<<<< HEAD
'data' => $divisions
], 200);
}
@ -438,11 +329,5 @@ class DashboardBoDController extends Controller
'total_manpowers' => User::count()
], 200);
}
=======
'data' => $totalProjectValuePerDivision
], 200);
}
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
}

144
app/Http/Controllers/ProjectController.php

@ -27,6 +27,8 @@ use App\Models\Holiday;
use App\Models\ReportActivity;
use App\Models\OfficeHours;
use Illuminate\Support\Facades\DB;
use App\Helpers\MasterFunctionsHelper;
use App\Models\ReportActivityMaterial;
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1";
@ -325,6 +327,148 @@ class ProjectController extends Controller
return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200);
}
public function getSCurve(Request $request){
$data = MasterFunctionsHelper::getSCurve($request);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200);
}
public function synchronizeReport($gantt_id)
{
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
$reports = [];
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) {
$reports[] = array(
'activity_id'=>$activity_id,
'min_date'=>$dr->report_date,
'max_date'=>date_modify(date_create($dr->report_date), "1 days")
);
}
}
if ($countReports > 1) {
$firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first();
$lastReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderByDesc('report_date')->first();
$reports[] = array(
'activity_id'=>$activity_id,
'min_date'=>$firstReport->report_date,
'max_date'=>date_modify(date_create($lastReport->report_date), "1 days")
);
}
$activity->reports = $reports;
}
/* 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++) {
$activity = Activity::find($reports[$i]['activity_id']);
$activity->start_date = $reports[$i]['min_date'];
$activity->end_date = $reports[$i]['max_date'];
$activity->save();
}
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200);
}
public function setBaseline($gantt_id)
{
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
foreach ($activities as $activity) {
$activity->update([
"planned_start"=>$activity->start_date,
"planned_end"=>$activity->end_date,
]);
}
return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200);
}
public function getInvoiceIntegration(Request $request) {
$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);
return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200);
}
public function detail($id){
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);
$gantt = MasterFunctionsHelper::getLatestGantt($id);
$result->projectManager = User::where('id', $result->pm_id)->value('name');
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $gantt['last_gantt_id'])->first();
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200);
}
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);
$result = Project::find($payload['id']);
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404);
//TODO possible overdue bug
if(isset($payload['till_date']))
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$payload['till_date'])->orderBy('end_date', 'asc')->get();
else
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get();
$result->overdueActivities = $overdueActivities;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200);
}
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);
$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')
->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']]);
return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200);
}
public function getManpower($proyek_id){
$manPower = UserToProyek::where('proyek_id', $proyek_id)->get();
$manCount = $manPower->count();
return response()->json(['data'=>$manPower, 'totalRecord'=>$manCount]);
}
public function getAssignedHR($gantt_id){
$results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id')
->where('assign_hr_to_activity.version_gantt_id', $gantt_id)
->get();
return response()->json(['data'=>$results]);
}
public function dashboard($id)
{
$data = DB::table('m_proyek as mp')

29
app/Models/Activity.php

@ -85,32 +85,10 @@ class Activity extends Model
private function updateBobot($isDelete = false)
{
<<<<<<< HEAD
$root = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->whereNull('parent_id')
->first();
=======
$rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->where('type_activity', 'header')
->first();
if(Activity::where('version_gantt_id', $this->version_gantt_id)->where("proyek_id", $this->proyek_id)->where('type_activity', 'header')->count() == 0) {
$totalCost = Activity::select(
DB::raw('sum(cast(rencana_biaya as double precision))')
)
->where("proyek_id", $this->proyek_id)
->where("version_gantt_id", $this->version_gantt_id)
->whereNull("parent_id")
->first();
} else {
$totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))
->where("proyek_id", $this->proyek_id)
->where("version_gantt_id", $this->version_gantt_id)
->where("parent_id", $rootActivity->id)
->first();
}
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
if($root->rencana_biaya > 0){
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get();
@ -206,14 +184,7 @@ class Activity extends Model
public function getJobsDoneAttribute()
{
<<<<<<< HEAD
if(!ReportActivityMaterial::where('activity_id', $this->id)->first())
=======
$tmpPercentage = [];
if(!ReportActivityMaterial::where('activity_id', $this->id)->first())
return 0;
if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get())
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
return 0;
if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get())
return 0;

2
app/Models/VersionGantt.php

@ -19,6 +19,8 @@ class VersionGantt extends Model
'config_dayoff',
'auto_schedule',
'calculation_type',
'committed_cost',
'cost_to_complete',
'created_at',
'created_by',
'updated_at',

Loading…
Cancel
Save