Browse Source

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

Reviewed-on: ordo/adw-backend#195
pull/3/head
ibnu 1 year ago
parent
commit
3d6a01da64
  1. 20
      app/Helpers/MasterFunctionsHelper.php
  2. 43
      app/Http/Controllers/ActivityController.php
  3. 2
      app/Http/Controllers/DivisiController.php
  4. 46
      app/Http/Controllers/PresenceController.php
  5. 32
      app/Http/Controllers/ProjectController.php
  6. 22
      app/Http/Controllers/UserToActivityController.php
  7. 124
      app/Models/UserToActivity.php
  8. 1
      routes/web.php

20
app/Helpers/MasterFunctionsHelper.php

@ -36,6 +36,26 @@ class MasterFunctionsHelper
return json_decode($output); return json_decode($output);
} }
public static function countDays($ganttId, $start, $end){
$dayOffs = VersionGantt::where('id', $ganttId)->first()->config_dayoff;
$diff = date_diff($start, $end);
$endCount = clone $end;
$duration = $diff->days + 1;
$daysRemaining = $duration;
// Loop until the remaining days become zero
while ($daysRemaining > 0) {
$endCount->modify('-1 day');
// Check if the current day is a day off (Sunday or Saturday)
$currentDayOfWeek = (int) $endCount->format('w');
if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) {
// continue; // Skip the day off and continue to the next day
$duration--;
}
$daysRemaining--; // Decrease the remaining days by one
}
return $duration;
}
public function getLatestGantt($id) public function getLatestGantt($id)
{ {
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id"); $maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");

43
app/Http/Controllers/ActivityController.php

@ -1,6 +1,7 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Helpers\MasterFunctionsHelper;
use App\Models\Activity; use App\Models\Activity;
use App\Models\CommentActivity; use App\Models\CommentActivity;
use App\Models\Link; use App\Models\Link;
@ -412,6 +413,39 @@ class ActivityController extends Controller
return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200);
} }
public function updateSchedule($ganttId){
if (empty($ganttId) || !is_int((int) $ganttId))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$activities = Activity::where('version_gantt_id', $ganttId)->get();
if (!$activities)
return response()->json(['status' => 'failed', 'message' => 'Activities not found!', 'code' => 404], 404);
$duration = 0;
foreach ($activities as $key => $activity) {
if (isset($activity->planned_start) && isset($activity->planned_end)) {
$today = new DateTime();
$endDate = new DateTime($activity->end_date);
$startDate = new DateTime($activity->start_date);
$plannedStart = new DateTime($activity->planned_start);
$plannedEnd = new DateTime($activity->planned_end);
$duration = MasterFunctionsHelper::countDays($ganttId, $plannedStart, $plannedEnd);
if ($today >= $endDate) {
$endDate = $today;
$rerataBobot = $activity->bobot_planning / $duration;
$bobotActual = $activity->progress * $activity->bobot_planning;
$sisaBobot = $activity->bobot_planning - $bobotActual;
$sisaHari = $sisaBobot / $rerataBobot;
$endDate->modify("+".$sisaHari." Days");
$actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate);
$activity->duration = $actualDuration;
$activity->end_date = $endDate;
$activity->save();
}
}
}
return response()->json(['status' => 'success', 'message' => 'Activities Updated!', 'code' => 200], 200);
}
public function batchUpdate(Request $request, $ganttId) public function batchUpdate(Request $request, $ganttId)
{ {
$entities = $request->all(); $entities = $request->all();
@ -428,15 +462,18 @@ class ActivityController extends Controller
$activityToUpdate = $activity->firstWhere('id', $entity['data']['id']); $activityToUpdate = $activity->firstWhere('id', $entity['data']['id']);
$entity['data']['name'] = $entity['data']['text']; $entity['data']['name'] = $entity['data']['text'];
$entity['data']['persentase_progress'] = $entity['data']['progress'] * 100; $entity['data']['persentase_progress'] = $entity['data']['progress'] * 100;
if (isset($entity['data']['rencana_biaya'])) {
$entity['data']['rencana_biaya'] = str_replace(",", ".", $entity['data']['rencana_biaya']);
}
if (isset($entity['data']['target'])) { if (isset($entity['data']['target'])) {
$this->updateOrder($entity['data']['id'], $entity['data']['target']); $this->updateOrder($entity['data']['id'], $entity['data']['target']);
} }
if(!$activityToUpdate->update($entity['data'])) if (!$activityToUpdate->update($entity['data']))
return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500);
$updatedJobsDone = $activityToUpdate->jobs_done; $updatedJobsDone = $activityToUpdate->jobs_done;
} else if ($entity['entity'] == "link"){ } else if ($entity['entity'] == "link") {
$linkToUpdate = $link->firstWhere('id', $entity['data']['id']); $linkToUpdate = $link->firstWhere('id', $entity['data']['id']);
if(!$linkToUpdate->update($entity['data'])) if (!$linkToUpdate->update($entity['data']))
return response()->json(['status' => 'failed', 'message' => 'Failed to update link !', 'code' => 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to update link !', 'code' => 500], 500);
} }
} }

2
app/Http/Controllers/DivisiController.php

@ -92,7 +92,7 @@ class DivisiController extends Controller
public function list() public function list()
{ {
$parentMenus = Divisi::with('children')->whereNull('parent')->get(); $parentMenus = Divisi::whereNull('parent')->with('children')->get();
$divisions = []; $divisions = [];
foreach($parentMenus as $menu){ foreach($parentMenus as $menu){
$childs = $this->getAllChildren($menu); $childs = $this->getAllChildren($menu);

46
app/Http/Controllers/PresenceController.php

@ -260,13 +260,17 @@ class PresenceController extends Controller
// geom ada di table activity // geom ada di table activity
// $clock_time = // $clock_time =
$user = HumanResource::find($params->user_id); $user = HumanResource::find($params->user_id);
$geom = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id") $geomQuery = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id")
->join("m_activity as ma", "ma.id", "=", "ahta.activity_id") ->join("m_activity as ma", "ma.id", "=", "ahta.activity_id")
->where("ahta.user_id", $params->user_id) ->where("ahta.user_id", $params->user_id)
->whereNotNull("ma.geom") ->whereNotNull("ma.geom")
->whereDate("ma.start_date", "<=", $params->time) ->whereDate("ma.start_date", "<=", $params->time)
->whereDate("ma.end_date", ">=", $params->time) ->whereDate("ma.end_date", ">=", $params->time);
->get(); if (isset($params->report_k3['proyek_id'])) {
$geom = $geomQuery->where("ma.proyek_id", $params->report_k3['proyek_id'])->get();
} else {
$geom = $geomQuery->get();
}
$temp = []; $temp = [];
if (count($geom) > 0) { if (count($geom) > 0) {
foreach($geom as $dataGeom){ foreach($geom as $dataGeom){
@ -342,6 +346,13 @@ class PresenceController extends Controller
"status_assign" => true "status_assign" => true
); );
} }
} else {
// bypass work area restriction
$temp[]=array(
"activity_id" => null,
"boundary" => true,
"status_assign" => true
);
} }
} }
// assign and not in boundary // assign and not in boundary
@ -356,12 +367,21 @@ class PresenceController extends Controller
} }
} }
else{ else{
// not assign if ($user->status_boundary) {
$temp[]=array( // bypass work area restriction
"activity_id" => null, $temp[]=array(
"boundary" => false, "activity_id" => null,
"status_assign" => false "boundary" => true,
); "status_assign" => true
);
} else {
// not assign
$temp[]=array(
"activity_id" => null,
"boundary" => false,
"status_assign" => false
);
}
} }
return $temp; return $temp;
} }

32
app/Http/Controllers/ProjectController.php

@ -77,7 +77,7 @@ class ProjectController extends Controller
$result = Project::query() $result = Project::query()
->from('m_proyek AS mp') ->from('m_proyek AS mp')
->where('mp.id', $id) ->where('mp.id', $id)
->selectRaw('kode_sortname,jumlah_stakeholder,nama,mulai_proyek,akhir_proyek,area_kerja,lokasi_kantor,rencana_biaya,biaya_actual,company,pm_id,type_proyek_id,divisi_id,persentase_progress,keterangan,durasi_proyek,progress_by_worklog,currency_symbol,late_consequence,assumtion,currency_code,currency_name,project_objectives,considered_success_when,potential_risk,testing_environment,budget_health,phase_id,calculation_status'); ->selectRaw('value_proyek,scoupe_of_work,kode_sortname,jumlah_stakeholder,nama,mulai_proyek,akhir_proyek,area_kerja,rencana_biaya,biaya_actual,company,pm_id,type_proyek_id,divisi_id,persentase_progress,keterangan,durasi_proyek,progress_by_worklog,currency_symbol,late_consequence,assumtion,currency_code,currency_name,project_objectives,considered_success_when,potential_risk,testing_environment,budget_health,phase_id,calculation_status');
if (!is_null($result->first()['divisi_id'])) { if (!is_null($result->first()['divisi_id'])) {
$result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id') $result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id')
@ -416,17 +416,21 @@ class ProjectController extends Controller
$firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first(); $firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first();
$reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport); $reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport);
} }
$successor = Link::where('t_activity_id', $activity->id)->first();
if ($successor) {
$predecessor = Activity::find($successor->s_activity_id);
$activity->start_date = $predecessor->end_date;
$end_date = new DateTime($activity->start_date);
$end_date->modify("+" . $activity->duration . " days");
$activity->end_date = $end_date->format("Y-m-d H:i:sO");
}
$activity->save();
} }
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */
for ($i=0; $i < count($reports); $i++) { for ($i=0; $i < count($reports); $i++) {
$activity = Activity::find($reports[$i]['activity_id']); $activity = Activity::find($reports[$i]['activity_id']);
$successor = Link::where('t_activity_id', $activity->id)->first();
if ($successor) {
$predecessor = Activity::find($successor->s_activity_id);
$activity->start_date = $predecessor->end_date;
}
if($reports[$i]['status'] != 'done'){ if($reports[$i]['status'] != 'done'){
$reports[$i]['max_date']->modify('-1 day'); $reports[$i]['max_date']->modify('-1 day');
}else if($reports[$i]['status'] == 'done'){ }else if($reports[$i]['status'] == 'done'){
@ -434,22 +438,14 @@ class ProjectController extends Controller
} }
$activity->start_date = $reports[$i]['min_date']; //same early $activity->start_date = $reports[$i]['min_date']; //same early
$activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early $activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early
$startDate = new DateTime($activity->start_date);
$endDate = new DateTime($activity->end_date);
$duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate);
$activity->duration = $duration;
$activity->actual_start = $reports[$i]['min_date']; $activity->actual_start = $reports[$i]['min_date'];
$activity->save(); $activity->save();
} }
foreach($activities as $activity) {
$successor = Link::where('t_activity_id', $activity->id)->first();
if ($successor) {
$predecessor = Activity::find($successor->s_activity_id);
$activity->start_date = $predecessor->end_date;
$end_date = new DateTime($activity->start_date);
$end_date->modify("+" . $activity->duration . " days");
$activity->end_date = $end_date->format("Y-m-d H:i:sO");
}
$activity->save();
}
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200);
} }

22
app/Http/Controllers/UserToActivityController.php

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\UserToActivity; use App\Models\UserToActivity;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial;
use Datatables; use Datatables;
class UserToActivityController extends Controller class UserToActivityController extends Controller
@ -26,7 +27,7 @@ class UserToActivityController extends Controller
public function addMultiple(Request $request){ public function addMultiple(Request $request){
$users_id = $request->user_id; $users_id = $request->user_id;
$users_role = $request->role_proyek_id; $users_role = $request->role_proyek_id;
// $data = UserToActivity::where("activity_id", $request->activity_id); // $data = UserToActivity::where("activity_id", $request->activity_id);
// if($data){ // if($data){
@ -41,8 +42,10 @@ class UserToActivityController extends Controller
"activity_id" => $request->activity_id, "activity_id" => $request->activity_id,
"role_proyek_id" => $users_role[$index], "role_proyek_id" => $users_role[$index],
"proyek_id" => $request->proyek_id, "proyek_id" => $request->proyek_id,
"created_by" => $this->currentName, "start_date" => $request->start_date,
"version_gantt_id" => $request->version_gantt_id "end_date" => $request->end_date,
"created_by" => $this->currentName,
"version_gantt_id" => $request->version_gantt_id
); );
$result = UserToActivity::create($dataInsert); $result = UserToActivity::create($dataInsert);
if($result){ if($result){
@ -140,6 +143,7 @@ class UserToActivityController extends Controller
if (isset($join_column)) { if (isset($join_column)) {
$startDate = $join_column['start_date']; $startDate = $join_column['start_date'];
$endDate = $join_column['end_date']; $endDate = $join_column['end_date'];
$status = $join_column['status'];
$startDate = date("Y-m-d H:i:sO", strtotime($startDate)); $startDate = date("Y-m-d H:i:sO", strtotime($startDate));
$endDate = date("Y-m-d H:i:sO", strtotime($endDate)); $endDate = date("Y-m-d H:i:sO", strtotime($endDate));
$builder->where(function ($query) use ($startDate, $endDate) { $builder->where(function ($query) use ($startDate, $endDate) {
@ -154,6 +158,16 @@ class UserToActivityController extends Controller
}); });
} }
$dataGet = $builder->get(); $dataGet = $builder->get();
if (isset($status) && $status != "") {
$filteredData = [];
foreach ($dataGet as $value) {
$assignMaterial = AssignMaterial::where('activity_id', $value->activity_id)->first();
if ($assignMaterial->status_activity == $status) {
$filteredData[] = $value;
}
}
$dataGet = $filteredData;
}
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} }
@ -204,7 +218,7 @@ class UserToActivityController extends Controller
public function datatables(Request $request){ public function datatables(Request $request){
$id_activity = $request->query('idact'); $id_activity = $request->query('idact');
$data = UserToActivity::select("assign_hr_to_activity.id as id", "u.name as user_name", "mrp.name as role_name") $data = UserToActivity::select("assign_hr_to_activity.id as id", "assign_hr_to_activity.start_date", "assign_hr_to_activity.end_date", "u.name as user_name", "mrp.name as role_name")
->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id") ->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id")
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") ->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id")
->where('assign_hr_to_activity.activity_id', $id_activity) ->where('assign_hr_to_activity.activity_id', $id_activity)

124
app/Models/UserToActivity.php

@ -1,61 +1,63 @@
<?php <?php
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Models\Activity; use App\Models\Activity;
class UserToActivity extends Model class UserToActivity extends Model
{ {
protected $table = 'assign_hr_to_activity'; protected $table = 'assign_hr_to_activity';
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'user_id', 'user_id',
'proyek_id', 'proyek_id',
'version_gantt_id', 'version_gantt_id',
'role_proyek_id', 'role_proyek_id',
'activity_id', 'activity_id',
'created_at', 'start_date',
'created_by', 'end_date',
'updated_at', 'created_at',
'updated_by' 'created_by',
]; 'updated_at',
'updated_by'
public static function boot() { ];
parent::boot();
public static function boot() {
static::created(function($data) { parent::boot();
$activity = Activity::find($data->activity_id);
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); static::created(function($data) {
$activity = Activity::find($data->activity_id);
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100); $getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first();
if($getWorkingHours->uom_standart_rate == "Hour") $salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
if($getWorkingHours->uom_standart_rate == "Hour")
$activity->rencana_biaya += $salary; $salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
$activity->save();
}); $activity->rencana_biaya += $salary;
$activity->save();
static::deleted(function($data) { });
$activity = Activity::find($data->activity_id);
static::deleted(function($data) {
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); $activity = Activity::find($data->activity_id);
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
if($getWorkingHours->uom_standart_rate == "Hour"){ $getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first();
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100); $salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
} if($getWorkingHours->uom_standart_rate == "Hour"){
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
$activity->rencana_biaya -= $salary; }
if ($activity->rencana_biaya < 0) {
$activity->rencana_biaya = 0; $activity->rencana_biaya -= $salary;
} if ($activity->rencana_biaya < 0) {
$activity->save(); $activity->rencana_biaya = 0;
}); }
$activity->save();
} });
} }
}

1
routes/web.php

@ -209,6 +209,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/activity/import-update', 'ActivityController@importUpdate'); $router->post('/activity/import-update', 'ActivityController@importUpdate');
$router->post('/activity/import-old', 'ActivityController@importOld'); $router->post('/activity/import-old', 'ActivityController@importOld');
$router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate'); $router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate');
$router->get('/activity/update-schedule/{ganttId}', 'ActivityController@updateSchedule');
$router->post('/task', 'ActivityController@add'); $router->post('/task', 'ActivityController@add');
$router->get('/task/edit/{id}', 'ActivityController@edit'); $router->get('/task/edit/{id}', 'ActivityController@edit');
$router->put('/task/{id}', 'ActivityController@update'); $router->put('/task/{id}', 'ActivityController@update');

Loading…
Cancel
Save