Browse Source

Merge branch 'staging' into dev-wahyun

pull/3/head
wahyun 1 year ago
parent
commit
b97e4c23cc
  1. 25
      app/Http/Controllers/ActivityController.php
  2. 4
      app/Http/Controllers/ProjectController.php
  3. 37
      app/Http/Controllers/ReportActivityMaterialController.php
  4. 2
      app/Models/ReportActivityMaterial.php

25
app/Http/Controllers/ActivityController.php

@ -3,6 +3,7 @@ namespace App\Http\Controllers;
use App\Helpers\MasterFunctionsHelper; use App\Helpers\MasterFunctionsHelper;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial;
use App\Models\CommentActivity; use App\Models\CommentActivity;
use App\Models\Link; use App\Models\Link;
use App\Models\Project; use App\Models\Project;
@ -185,14 +186,12 @@ 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 = count($actualStartValues) > 0 ? min($actualStartValues) : null;
}else{ }else{
$actualEndValues = array_column(array_filter($dataFinal, function($item) { $actualEndValues = array_column(array_filter($dataFinal, function($item) {
return isset($item['actual_end']); return isset($item['actual_end']);
}), 'actual_end'); }), 'actual_end');
$returnActualStartOrEnd = count($actualEndValues) == count($dataFinal) ? max($actualEndValues) : null;
$returnActualStartOrEnd = count($actualEndValues) > 0 ? max($actualEndValues) : null;
} }
// return json_encode(["min"=>$minActualStart, "max"=>$maxActualStart]); // return json_encode(["min"=>$minActualStart, "max"=>$maxActualStart]);
@ -422,7 +421,14 @@ class ActivityController extends Controller
return response()->json(['status' => 'failed', 'message' => 'Activities not found!', 'code' => 404], 404); return response()->json(['status' => 'failed', 'message' => 'Activities not found!', 'code' => 404], 404);
$duration = 0; $duration = 0;
foreach ($activities as $key => $activity) { foreach ($activities as $key => $activity) {
if (isset($activity->planned_start) && isset($activity->planned_end)) { $assignMaterial = AssignMaterial::where('activity_id', $activity->id)->first();
if (isset($assignMaterial)) {
$statusActivity = $assignMaterial->status_activity;
} else {
$statusActivity = '';
}
if (isset($activity->planned_start) && isset($activity->planned_end) && $statusActivity != "done") {
// todo check report for no report / progress == 0
$today = new DateTime(); $today = new DateTime();
$endDate = new DateTime($activity->end_date); $endDate = new DateTime($activity->end_date);
$startDate = new DateTime($activity->start_date); $startDate = new DateTime($activity->start_date);
@ -431,11 +437,12 @@ class ActivityController extends Controller
$duration = MasterFunctionsHelper::countDays($ganttId, $plannedStart, $plannedEnd); $duration = MasterFunctionsHelper::countDays($ganttId, $plannedStart, $plannedEnd);
if ($today >= $endDate) { if ($today >= $endDate) {
$endDate = $today; $endDate = $today;
$rerataBobot = $duration > 0 ? $activity->bobot_planning / $duration : 0; $bobotPlanning = (int) $activity->bobot_planning;
$bobotActual = $activity->progress * $activity->bobot_planning; $rerataBobot = $duration > 0 ? $bobotPlanning / $duration : 0;
$sisaBobot = $activity->bobot_planning - $bobotActual; $bobotActual = (int) $activity->persentase_progress/100 * $bobotPlanning;
$sisaBobot = $bobotPlanning - $bobotActual;
$sisaHari = $rerataBobot > 0 ? $sisaBobot / $rerataBobot : 0; $sisaHari = $rerataBobot > 0 ? $sisaBobot / $rerataBobot : 0;
$endDate->modify("+".$sisaHari." Days"); $endDate->modify("+".ceil($sisaHari)." Days");
$actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate); $actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate);
$activity->duration = $actualDuration; $activity->duration = $actualDuration;
$activity->end_date = $endDate; $activity->end_date = $endDate;

4
app/Http/Controllers/ProjectController.php

@ -466,12 +466,16 @@ class ProjectController extends Controller
} }
public function getInvoiceIntegration(Request $request) { public function getInvoiceIntegration(Request $request) {
$ganttCount = VersionGantt::where('proyek_id', $request->id)->count();
$search = urlencode($request->search); $search = urlencode($request->search);
if(empty($search)) if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH');
$response = MasterFunctionsHelper::curlReq($url); $response = MasterFunctionsHelper::curlReq($url);
if (isset($request->gantt_id)) {
$response->data->total_cost = $response->data->total_cost / $ganttCount;
}
return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200);
} }

37
app/Http/Controllers/ReportActivityMaterialController.php

@ -2,11 +2,13 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Helpers\MasterFunctionsHelper;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ReportActivityMaterial; use App\Models\ReportActivityMaterial;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use Datatables; use Datatables;
use DateTime;
class ReportActivityMaterialController extends Controller class ReportActivityMaterialController extends Controller
{ {
@ -63,9 +65,22 @@ class ReportActivityMaterialController extends Controller
$sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning'); $sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning');
$sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty'); $sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty');
$dataUpdate = array( $dataUpdate = array(
"actual_start" => null,
"actual_end" => null,
"persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100, "persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100,
"updated_by" => $this->currentName "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); Activity::where('id', $request->activity_id)->update($dataUpdate);
} }
@ -112,12 +127,22 @@ class ReportActivityMaterialController extends Controller
$type = $request->query('type'); $type = $request->query('type');
$materialName = $request->query('materialName'); $materialName = $request->query('materialName');
if($type == 'plan'){ 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") $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") ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $id_activity) ->where('assign_material_to_activity.activity_id', $id_activity)
->where('m.description', $materialName) ->where('m.description', $materialName)
->orderBy('assign_material_to_activity.id', 'asc') ->orderBy('assign_material_to_activity.id', 'asc')
->get(); ->get();
if ($baselineDuration > 0) {
foreach ($data as $key => $value) {
$data[$key]->qty_planning = number_format($value->qty_planning / $baselineDuration, 1);
}
}
return Datatables::of($data) return Datatables::of($data)
->addIndexColumn() ->addIndexColumn()
->addColumn('action', function($row){ ->addColumn('action', function($row){
@ -129,7 +154,12 @@ class ReportActivityMaterialController extends Controller
}) })
->rawColumns(['action'])->make(true); ->rawColumns(['action'])->make(true);
}else{ }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("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_req_material as m", "m.id", "=", "amta.material_id")
->join("m_users as u", "u.id", "=", "report_activity_material.user_id") ->join("m_users as u", "u.id", "=", "report_activity_material.user_id")
@ -137,6 +167,11 @@ class ReportActivityMaterialController extends Controller
->where('m.description', $materialName) ->where('m.description', $materialName)
->orderBy('report_activity_material.report_date', 'asc') ->orderBy('report_activity_material.report_date', 'asc')
->get(); ->get();
if ($baselineDuration > 0) {
foreach ($data as $key => $value) {
$data[$key]->qty_planning = number_format($value->qty_planning / $baselineDuration, 1);
}
}
return Datatables::of($data) return Datatables::of($data)
->addIndexColumn() ->addIndexColumn()
->addColumn('action', function($row){ ->addColumn('action', function($row){

2
app/Models/ReportActivityMaterial.php

@ -59,6 +59,8 @@ class ReportActivityMaterial extends Model
$assignedMaterial = AssignMaterial::find($data->assign_material_id); $assignedMaterial = AssignMaterial::find($data->assign_material_id);
$activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty); $activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty);
$activity->actual_start = null;
$activity->actual_end = null;
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get();
$totalPlan = $dataPlan->sum('qty_planning'); $totalPlan = $dataPlan->sum('qty_planning');

Loading…
Cancel
Save