From 8d4f404f3ffe83850d8bad415d2a250ef03ad553 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 20 Jul 2023 10:50:10 +0700 Subject: [PATCH] Fix date range --- app/Helpers/MasterFunctionsHelper.php | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 9108ceb..9e0551b 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -143,10 +143,10 @@ class MasterFunctionsHelper { $dataFinal=[]; $dataPayload = []; - $dataPayload['period'] = 'week'; - $totalACWP = 0; - $totalBCWP = 0; - $tempPercentage = []; + $dataPayload['period'] = 'week'; + $totalACWP = 0; + $totalBCWP = 0; + $tempPercentage = []; $dataProject = Project::find($keyGantt['proyek_id']); $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['id'])->first(); @@ -168,19 +168,19 @@ class MasterFunctionsHelper { ->join('m_activity as b', 'b.id', '=', 'a.activity_id') ->where('b.version_gantt_id', '=', $keyGantt['id']) ->exists(); - // note : delete this + // note : delete this // if(!$alreadyHasReport) // return $dataFinal; $minDate = Activity::where('version_gantt_id', $keyGantt['id'])->whereNull('parent_id')->pluck('start_date')->first(); $begin = new \DateTime($minDate.' Monday'); - $begin->modify('last 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'); + $end->modify('next Friday'); + $end->modify('next Friday'); /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged $interval = new \DateInterval('P7D'); } else { @@ -190,8 +190,8 @@ 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'); + $end->modify('next Friday'); + $end->modify('next Friday'); $interval = new \DateInterval('P7D'); } $period = new \DatePeriod($begin, $interval, $end); @@ -210,6 +210,7 @@ class MasterFunctionsHelper { foreach ($period as $dt) { $minSevenDays = new \Datetime($dt->format("Y-m-d")); $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); + $tempDate[] = array($dt->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') @@ -254,7 +255,7 @@ class MasterFunctionsHelper { $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; foreach ($dataPlanM as $keyPlanM) { - $sumVolPlan = DB::table(function ($query) use ($keyGantt) { + $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') @@ -301,10 +302,10 @@ class MasterFunctionsHelper { ->where('activity_id', '=', $keyActualM->activity_id) ->groupBy('activity_id') ->first(); - $sumReportActual = DB::table('report_activity_material') - ->where('activity_id', $keyActualM->activity_id) - ->sum('qty'); - $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); + $sumReportActual = DB::table('report_activity_material') + ->where('activity_id', $keyActualM->activity_id) + ->sum('qty'); + $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); $dataTempReport [$w]['activity_id'] = $keyActualM->activity_id; $dataTempReport [$w]['qty'] = $keyActualM->qty; $dataTempReport [$w]['report_date'] = $keyActualM->report_date; @@ -392,7 +393,6 @@ class MasterFunctionsHelper { $tempPercentagePlan[] = round($sumPercentagePlan, 2); $tempPercentageReal[] = round($sumPercentageActual, 2); } - $tempDate[] = array($dt->format("Y-m-d")); } try {