Browse Source

Merge pull request 'staging' (#87) from staging into master

Reviewed-on: ordo/adw-backend#87
pull/3/head
ibnu 2 years ago
parent
commit
3948ecf69d
  1. 74
      app/Helpers/MasterFunctionsHelper.php
  2. 17
      app/Http/Controllers/ActivityController.php

74
app/Helpers/MasterFunctionsHelper.php

@ -120,9 +120,11 @@ class MasterFunctionsHelper {
$minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first();
$begin = new \DateTime($minDate.' Monday');
$begin->modify('last Monday');
if(isset($dataPayload['end_date'])){
$maxDate = $dataPayload['end_date'];
$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 = new \DateInterval('P7D');
@ -133,6 +135,7 @@ class MasterFunctionsHelper {
->where('a.version_gantt_id', '=', $keyGantt['id'])
->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's
$end = new \DateTime($maxDate. ' Friday');
$end->modify('next Friday');
$end->modify('next Friday');
$interval = new \DateInterval('P7D');
}
@ -152,14 +155,35 @@ class MasterFunctionsHelper {
foreach ($period as $dt) {
$minSevenDays = new \Datetime($dt->format("Y-m-d"));
$minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d");
$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['id'])
->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d"))
->whereDate('ama.plan_date', '>', $minSevenDays)
->get();
// $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['id'])
// ->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d"))
// ->whereDate('ama.plan_date', '>', $minSevenDays)
// ->get();
$activities = DB::table('m_activity AS a')
->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id')
->where('a.type_activity', 'task')
->where('a.bobot_planning', '>', 0)
->where('a.version_gantt_id', $keyGantt['id'])
->whereDate('amta.plan_date', '<=',$dt->format("Y-m-d"))
->whereDate('amta.plan_date', '>', $minSevenDays)
->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id');
$dataPlanM = DB::table('m_activity AS a')
->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id')
->where('a.type_activity', 'task')
->where('a.bobot_planning', '>', 0)
->where('a.version_gantt_id', $keyGantt['id'])
->whereDate('a.start_date', '<=',$dt->format("Y-m-d"))
->whereDate('a.start_date', '>', $minSevenDays)
->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id')
->union($activities)
->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')
@ -175,23 +199,33 @@ class MasterFunctionsHelper {
$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;
$sumVolPlan = DB::table(function ($query) use ($keyGantt) {
$query->select('a.*')
->from('m_activity AS a')
->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id')
->where('a.type_activity', 'task')
->where('a.bobot_planning', '>', 0)
->where('a.version_gantt_id', $keyGantt['id'])
->unionAll(function ($query) use ($keyGantt){
$query->select('a.*')
->from('m_activity AS a')
->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id')
->where('a.type_activity', 'task')
->where('a.bobot_planning', '>', 0)
->where('a.version_gantt_id', $keyGantt['id']);
})
->orderBy('id', 'asc');
}, 'subquery')
->sum('bobot_planning');
$dataTempPlan [$x]['activity_id'] = $keyPlanM->id;
$dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan;
$dataTempPlan [$x]['ttl_plan'] = $sumVolPlan;
$dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual;
$dataTempPlan [$x]['duration'] = $keyPlanM->duration;
$dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress;
try {
$dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$dataTempPlan [$x]['percentage'] = $keyPlanM->bobot_planning;
$sumPercentagePlan+= $keyPlanM->bobot_planning;
if(isset($keyPlanM->duration) && $keyPlanM->duration > 0)
$totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100;
else

17
app/Http/Controllers/ActivityController.php

@ -401,7 +401,21 @@ class ActivityController extends Controller
foreach ($data['activities'] as $i => $activity_row) {
$startDate = \DateTime::createFromFormat('Y-m-d H:i:s.uP', $projectStart->mulai_proyek);
$endDate = clone $startDate;
$endDate->modify('+'.$activity_row['duration'].' days');
$endDate->modify('-1 day');
$daysRemaining = $activity_row['duration'];
// Loop until the remaining days become zero
while ($daysRemaining > 0) {
$endDate->modify('+1 day');
// Check if the current day is a day off (Sunday or Saturday)
$currentDayOfWeek = (int)$endDate->format('w');
if (strpos($dayOffs, (string)$currentDayOfWeek) !== false) {
continue; // Skip the day off and continue to the next day
}
$daysRemaining--; // Decrease the remaining days by one
}
$endDate->setTime(23, 59, 59);
$input['name'] = $activity_row['name'];
$input['proyek_id'] = $projectId;
@ -744,6 +758,7 @@ class ActivityController extends Controller
$data = $request->all();
foreach ($data as $value) {
$activity = Activity::find($value['id']);
$activity->duration = $value['duration'];
$activity->start_date = $value['start_date'];
$activity->end_date = $value['end_date'];
$activity->save();

Loading…
Cancel
Save