Browse Source

Merge pull request 'Dev-Farhan' (#235) from Dev-Farhan into general

Reviewed-on: ordo/adw-backend#235
pull/3/head
farhantock 1 year ago
parent
commit
316b0f5fa1
  1. 95
      app/Helpers/MasterFunctionsHelper.php
  2. 13
      app/Http/Controllers/ActivityController.php
  3. 2
      app/Http/Controllers/UserToActivityController.php

95
app/Helpers/MasterFunctionsHelper.php

@ -7,7 +7,7 @@ use App\Models\Project;
use App\Models\VersionGantt; use App\Models\VersionGantt;
use App\Models\HierarchyFtth; use App\Models\HierarchyFtth;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use DateTime;
class MasterFunctionsHelper class MasterFunctionsHelper
{ {
@ -223,6 +223,7 @@ class MasterFunctionsHelper
$maxDate = max(new \DateTime($plannedMaxDate), new \DateTime($actualMaxDate)); $maxDate = max(new \DateTime($plannedMaxDate), new \DateTime($actualMaxDate));
$end = new \DateTime($maxDate->format('Y-m-d') . ' Friday'); $end = new \DateTime($maxDate->format('Y-m-d') . ' Friday');
$end->modify('next Friday'); $end->modify('next Friday');
$end->modify('next Friday');
$interval = new \DateInterval('P7D'); $interval = new \DateInterval('P7D');
} }
$period = new \DatePeriod($begin, $interval, $end); $period = new \DatePeriod($begin, $interval, $end);
@ -286,24 +287,32 @@ class MasterFunctionsHelper
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
foreach ($dataPlanM as $keyPlanM) { foreach ($dataPlanM as $keyPlanM) {
$sumVolPlan = DB::table(function ($query) use ($keyGantt) { // $sumVolPlan = DB::table(function ($query) use ($keyGantt) {
$query->select('a.*') // $query->select('a.*')
->from('m_activity AS a') // ->from('m_activity AS a')
->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') // ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id')
->where('a.type_activity', 'task') // ->where('a.type_activity', 'task')
->where('a.bobot_planning', '>', 0) // ->where('a.bobot_planning', '>', 0)
->where('a.version_gantt_id', $keyGantt['id']) // ->where('a.version_gantt_id', $keyGantt['id'])
->unionAll(function ($query) use ($keyGantt) { // ->unionAll(function ($query) use ($keyGantt) {
$query->select('a.*') // $query->select('a.*')
->from('m_activity AS a') // ->from('m_activity AS a')
->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id') // ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id')
->where('a.type_activity', 'task') // ->where('a.type_activity', 'task')
->where('a.bobot_planning', '>', 0) // ->where('a.bobot_planning', '>', 0)
->where('a.version_gantt_id', $keyGantt['id']); // ->where('a.version_gantt_id', $keyGantt['id']);
}) // })
->orderBy('id', 'asc'); // ->orderBy('id', 'asc');
}, 'subquery') // }, 'subquery')
->sum('bobot_planning'); // ->sum('bobot_planning');
$sumVolPlan = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyPlanM->id)
->groupBy('activity_id')
->first();
$weekCount = $keyPlanM->duration / 7;
$weeklyPlan = $sumVolPlan->ttl_qty_plan / $weekCount;
$weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
$dataTempPlan[$x]['activity_id'] = $keyPlanM->id; $dataTempPlan[$x]['activity_id'] = $keyPlanM->id;
$dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan[$x]['ttl_plan'] = $sumVolPlan; $dataTempPlan[$x]['ttl_plan'] = $sumVolPlan;
@ -312,7 +321,7 @@ class MasterFunctionsHelper
$dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress;
try { try {
$dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning;
$sumPercentagePlan += $keyPlanM->bobot_planning; $sumPercentagePlan += $weeklyProgress;
if (isset($keyPlanM->duration) && $keyPlanM->duration > 0) if (isset($keyPlanM->duration) && $keyPlanM->duration > 0)
$totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100; $totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100;
else else
@ -508,11 +517,11 @@ class MasterFunctionsHelper
$minDate = $dataProject->mulai_proyek; $minDate = $dataProject->mulai_proyek;
$begin = new \DateTime($minDate); $begin = new \DateTime($minDate . ' Monday');
$begin->modify('last Monday'); $begin->modify('last Monday');
if (isset($dataPayload['end_date'])) { if (isset($dataPayload['end_date'])) {
$maxDate = $dataPayload['end_date']; $maxDate = $dataPayload['end_date'];
$end = new \DateTime($maxDate); $end = new \DateTime($maxDate . ' Friday');
$end->modify('next Friday'); $end->modify('next 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
@ -587,21 +596,31 @@ class MasterFunctionsHelper
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
foreach ($dataPlanM as $keyPlanM) { foreach ($dataPlanM as $keyPlanM) {
$sumVolPlan = DB::table(function ($query) { // $sumVolPlan = DB::table(function ($query) use ($projectId) {
$query->select('a.*') // $query->select('a.*')
->from('m_activity AS a') // ->from('m_activity AS a')
->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') // ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id')
->where('a.type_activity', 'task') // ->where('a.type_activity', 'task')
->where('a.bobot_planning', '>', 0) // ->where('a.bobot_planning', '>', 0)
->unionAll(function ($query) { // ->where('a.proyek_id', $projectId)
$query->select('a.*') // ->unionAll(function ($query) use ($projectId) {
->from('m_activity AS a') // $query->select('a.*')
->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id') // ->from('m_activity AS a')
->where('a.type_activity', 'task') // ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id')
->where('a.bobot_planning', '>', 0); // ->where('a.type_activity', 'task')
})->orderBy('id', 'asc'); // ->where('a.bobot_planning', '>', 0)
}, 'subquery') // ->where('a.proyek_id', $projectId);
->sum('bobot_planning'); // })->orderBy('id', 'asc');
// }, 'subquery')
// ->sum('bobot_planning');
$sumVolPlan = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyPlanM->id)
->groupBy('activity_id')
->first();
$weekCount = $keyPlanM->duration / 7;
$weeklyPlan = $sumVolPlan->ttl_qty_plan / $weekCount;
$weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
$dataTempPlan[$x]['activity_id'] = $keyPlanM->id; $dataTempPlan[$x]['activity_id'] = $keyPlanM->id;
$dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan[$x]['ttl_plan'] = $sumVolPlan; $dataTempPlan[$x]['ttl_plan'] = $sumVolPlan;
@ -610,7 +629,7 @@ class MasterFunctionsHelper
$dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress;
try { try {
$dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning;
$sumPercentagePlan += $keyPlanM->bobot_planning; $sumPercentagePlan += $weeklyProgress;
if (isset($keyPlanM->duration) && $keyPlanM->duration > 0) if (isset($keyPlanM->duration) && $keyPlanM->duration > 0)
$totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100; $totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100;
else else

13
app/Http/Controllers/ActivityController.php

@ -187,7 +187,7 @@ class ActivityController extends Controller
$actualStartValues = array_column(array_filter($dataFinal, function($item) { $actualStartValues = array_column(array_filter($dataFinal, function($item) {
return isset($item['actual_start']); return isset($item['actual_start']);
}), 'actual_start'); }), 'actual_start');
$returnActualStartOrEnd = count($actualStartValues) == count($dataFinal) ? min($actualStartValues) : null; $returnActualStartOrEnd = min($actualStartValues);
if (isset($parent)) { if (isset($parent)) {
$parent->actual_start = $returnActualStartOrEnd; $parent->actual_start = $returnActualStartOrEnd;
$parent->save(); $parent->save();
@ -534,7 +534,7 @@ class ActivityController extends Controller
->select('m_activity.name') ->select('m_activity.name')
->where('m_activity.proyek_id', $data['columns'][0]['value']) ->where('m_activity.proyek_id', $data['columns'][0]['value'])
->where('m_activity.type_activity', 'task') ->where('m_activity.type_activity', 'task')
->where('m_activity.persentase_progress', '>', 0) // ->where('m_activity.persentase_progress', '>', 0)
->groupByRaw('m_activity.name') ->groupByRaw('m_activity.name')
->get(); ->get();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200);
@ -544,14 +544,14 @@ class ActivityController extends Controller
{ {
$dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); $dataBuilder = $this->setUpPayload($request->all(), 'm_activity');
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$dataGet = $builder->select( 'selfTable.name', 'persentase_progress', $dataGet = $builder->select( 'selfTable.name', 'persentase_progress', 'selfTable.start_date', 'selfTable.end_date', 'duration', 'assign_hr_to_activity.id',
'm_version_gantt.name_version', 'm_users.name as user_name', 'm_version_gantt.name_version', 'm_users.name as user_name',
DB::raw('SUM(report_activity_material.qty) as qty'), 'assign_material_to_activity.qty_planning', DB::raw('SUM(report_activity_material.qty) as qty'), 'assign_material_to_activity.qty_planning',
'assign_material_to_activity.id as join_third_id') 'assign_material_to_activity.id as join_third_id')
->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id') ->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id')
->join('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id') ->leftJoin('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id')
->join('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id') ->leftJoin('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id')
->join('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id') ->leftJoin('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id')
->join('assign_material_to_activity', 'assign_material_to_activity.activity_id', '=', 'selfTable.id') ->join('assign_material_to_activity', 'assign_material_to_activity.activity_id', '=', 'selfTable.id')
->groupBy("selfTable.id") ->groupBy("selfTable.id")
->groupBy("selfTable.name") ->groupBy("selfTable.name")
@ -560,6 +560,7 @@ class ActivityController extends Controller
->groupBy("m_users.name") ->groupBy("m_users.name")
->groupBy("assign_material_to_activity.qty_planning") ->groupBy("assign_material_to_activity.qty_planning")
->groupBy("assign_material_to_activity.id") ->groupBy("assign_material_to_activity.id")
->groupBy("assign_hr_to_activity.id")
->get(); ->get();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200);
} }

2
app/Http/Controllers/UserToActivityController.php

@ -138,6 +138,8 @@ class UserToActivityController extends Controller
$builder->addSelect(DB::raw('SUM(report_activity_material.qty) as volume_actual')); $builder->addSelect(DB::raw('SUM(report_activity_material.qty) as volume_actual'));
$builder->groupBy("m_activity.id"); $builder->groupBy("m_activity.id");
$builder->groupBy("selfTable.id"); $builder->groupBy("selfTable.id");
$builder->groupBy("selfTable.start_date");
$builder->groupBy("selfTable.end_date");
$builder->groupBy("m_users.name"); $builder->groupBy("m_users.name");
$builder->groupBy("assign_material_to_activity.id"); $builder->groupBy("assign_material_to_activity.id");
$builder->groupBy("m_version_gantt.name_version"); $builder->groupBy("m_version_gantt.name_version");

Loading…
Cancel
Save