diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index dce8f9e..5655cdb 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -186,14 +186,12 @@ class ActivityController extends Controller $actualStartValues = array_column(array_filter($dataFinal, function($item) { return isset($item['actual_start']); }), 'actual_start'); - - $returnActualStartOrEnd = count($actualStartValues) > 0 ? min($actualStartValues) : null; + $returnActualStartOrEnd = count($actualStartValues) == count($dataFinal) ? min($actualStartValues) : null; }else{ $actualEndValues = array_column(array_filter($dataFinal, function($item) { return isset($item['actual_end']); }), 'actual_end'); - - $returnActualStartOrEnd = count($actualEndValues) > 0 ? max($actualEndValues) : null; + $returnActualStartOrEnd = count($actualEndValues) == count($dataFinal) ? max($actualEndValues) : null; } // return json_encode(["min"=>$minActualStart, "max"=>$maxActualStart]); diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index 0ec323c..e451129 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -2,11 +2,13 @@ namespace App\Http\Controllers; +use App\Helpers\MasterFunctionsHelper; use Illuminate\Http\Request; use App\Models\ReportActivityMaterial; use App\Models\Activity; use App\Models\AssignMaterial; use Datatables; +use DateTime; class ReportActivityMaterialController extends Controller { @@ -68,6 +70,17 @@ class ReportActivityMaterialController extends Controller "persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100, "updated_by" => $this->currentName ); + if ($sumReportActivityMaterial > 0) { + $data = []; + $reportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->get(); + foreach ($reportActivityMaterial as $value) { + $data[] = $value; + } + $actualStartValues = array_column(array_filter($data, function($item) { + return isset($item['report_date']); + }), 'report_date'); + $dataUpdate["actual_start"] = min($actualStartValues); + } Activity::where('id', $request->activity_id)->update($dataUpdate); } @@ -114,12 +127,22 @@ class ReportActivityMaterialController extends Controller $type = $request->query('type'); $materialName = $request->query('materialName'); if($type == 'plan'){ + $activity = Activity::findOrFail($id_activity); + $baselineDuration = 0; + if (isset($activity->planned_start) && isset($activity->planned_end)) { + $baselineDuration = MasterFunctionsHelper::countDays($activity->version_gantt_id, new DateTime($activity->planned_start), new DateTime($activity->planned_end)); + } $data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") ->where('assign_material_to_activity.activity_id', $id_activity) ->where('m.description', $materialName) ->orderBy('assign_material_to_activity.id', 'asc') ->get(); + if ($baselineDuration > 0) { + foreach ($data as $key => $value) { + $data[$key]->qty_planning = number_format($value->qty_planning / $baselineDuration, 1); + } + } return Datatables::of($data) ->addIndexColumn() ->addColumn('action', function($row){ @@ -131,7 +154,12 @@ class ReportActivityMaterialController extends Controller }) ->rawColumns(['action'])->make(true); }else{ - $data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity") + $activity = Activity::findOrFail($id_activity); + $baselineDuration = 0; + if (isset($activity->planned_start) && isset($activity->planned_end)) { + $baselineDuration = MasterFunctionsHelper::countDays($activity->version_gantt_id, new DateTime($activity->planned_start), new DateTime($activity->planned_end)); + } + $data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity", "amta.qty_planning") ->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id") ->join("m_req_material as m", "m.id", "=", "amta.material_id") ->join("m_users as u", "u.id", "=", "report_activity_material.user_id") @@ -139,6 +167,11 @@ class ReportActivityMaterialController extends Controller ->where('m.description', $materialName) ->orderBy('report_activity_material.report_date', 'asc') ->get(); + if ($baselineDuration > 0) { + foreach ($data as $key => $value) { + $data[$key]->qty_planning = number_format($value->qty_planning / $baselineDuration, 1); + } + } return Datatables::of($data) ->addIndexColumn() ->addColumn('action', function($row){