Browse Source

Merge branch 'staging' of https://git.oslog.id/ordo/adw-backend into Dev-Farhan

pull/3/head
farhan048 2 years ago
parent
commit
1d280d4f50
  1. 6
      app/Console/Commands/syncHumanResourceIntegration.php
  2. 146
      app/Http/Controllers/ActivityController.php
  3. 8
      app/Http/Controllers/Controller.php
  4. 22
      app/Http/Controllers/DashboardBoDController.php
  5. 48
      app/Http/Controllers/HierarchyFtthController.php
  6. 10
      app/Http/Controllers/ProjectController.php
  7. 9
      app/Http/Controllers/ProjectDokumenController.php
  8. 2
      app/Http/Controllers/RequestMaterialController.php
  9. 13
      app/Http/Controllers/UserToActivityController.php
  10. 2
      app/Http/Controllers/UserToProyekController.php
  11. 2
      app/Models/Activity.php

6
app/Console/Commands/syncHumanResourceIntegration.php

@ -39,9 +39,9 @@ class syncHumanResourceIntegration extends Command
*/
public function handle()
{
$url = config('api.adw').'/employees?page=1';
echo "Requesting to " . $url;
$response = MasterFunctionsHelper::curlReq($url);
// $url = config('api.adw').'/employees?page=1';
// echo "Requesting to " . $url;
$response = null;
if(!$response)
return;

146
app/Http/Controllers/ActivityController.php

@ -11,13 +11,19 @@ use App\Models\VersionGantt;
use App\Models\UserToActivity;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class ActivityController extends Controller
{
public function getByGanttId($id, $proyek_id)
{
if(Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) {
$this->cloneTemplate($id, $proyek_id);
$gantt = VersionGantt::find($id);
if(Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) {
if(!$gantt->hierarchy_ftth_id) {
$this->cloneTemplate($id, $proyek_id);
} else {
$this->cloneTemplate($id, $proyek_id, $gantt->hierarchy_ftth_id);
}
}
$dataGantt = $this->getDataActivity($id);
@ -40,9 +46,9 @@ class ActivityController extends Controller
$dataHeader->type = "header";
$dataHeader->text = $dataHeader->name;
$finalData[] = $dataHeader;
$data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('id', 'asc')->get();
$data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('sortorder', 'asc')->get();
}else{
$data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get();
$data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('sortorder', 'asc')->get();
}
foreach($data as $objRow){
@ -95,7 +101,7 @@ class ActivityController extends Controller
private function getChildren($gantt_id, $parent_id)
{
$finalData = [];
$data = Activity::where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('id', 'asc')->get();
$data = Activity::where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('sortorder', 'asc')->get();
foreach($data as $objRow){
$objRow->parent = $parent_id;
$objRow->text = $objRow->name;
@ -120,21 +126,35 @@ class ActivityController extends Controller
return $finalData;
}
private function cloneTemplate($id, $proyek_id)
{
$project = Project::find($proyek_id);
$rootActivity = Activity::create([
'version_gantt_id'=>$id,
'proyek_id'=>$proyek_id,
'name'=> $project->nama,
'kode_sortname'=>$project->kode_sortname,
'start_date'=> $project->mulai_proyek,
'end_date'=> $project->akhir_proyek,
'rencana_biaya'=> $project->rencana_biaya,
'type_activity'=> 'project',
'created_by'=>$this->currentName,
]);
private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null) {
$project = Project::find($proyek_id);
if($hierarchy_ftth_id){
$gantt = VersionGantt::find($id);
$rootActivity = Activity::create([
'version_gantt_id'=>$id,
'proyek_id'=>$proyek_id,
'name'=> $gantt->name_version,
'start_date'=> $project->mulai_proyek,
'end_date'=> $project->akhir_proyek,
'rencana_biaya'=> $project->rencana_biaya,
'type_activity'=> 'project',
'created_by'=>$this->currentName,
'sortorder'=>1
]);
} else {
$rootActivity = Activity::create([
'version_gantt_id'=>$id,
'proyek_id'=>$proyek_id,
'name'=> $project->nama,
'kode_sortname'=>$project->kode_sortname,
'start_date'=> $project->mulai_proyek,
'end_date'=> $project->akhir_proyek,
'rencana_biaya'=> $project->rencana_biaya,
'type_activity'=> 'project',
'created_by'=>$this->currentName,
'sortorder'=>1
]);
}
$resultTypeProject = TemplateGantt::where('proyek_type_id', $project->type_proyek_id)
->whereNull('parent_id')
@ -143,6 +163,7 @@ class ActivityController extends Controller
foreach($resultTypeProject as $objRow){
$childActivities = TemplateGantt::where("parent_id", $objRow->id)->count();
$max = Activity::where('version_gantt_id', $id)->max('sortorder');
$resultNew = Activity::create([
'type_activity'=> $childActivities > 0 ? "project" : "task",
'version_gantt_id'=>$id,
@ -151,7 +172,8 @@ class ActivityController extends Controller
'name'=> $objRow->name_activity,
'start_date'=>date("Y-m-d H:i:s"),
'end_date'=>date("Y-m-d H:i:s"),
'created_by'=>$this->currentName
'created_by'=>$this->currentName,
'sortorder'=>$max+1
]);
$this->getChildrenTemplate($id, $objRow->id, $project->type_project_id, $proyek_id, $resultNew->id, $project->mulai_proyek);
}
@ -162,6 +184,7 @@ class ActivityController extends Controller
$data = TemplateGantt::where('parent_id', $parent_id)->orderByRaw('id ASC')->get();
foreach($data as $objRow){
$childActivities = TemplateGantt::where("parent_id", $objRow->id)->count();
$max = Activity::where('version_gantt_id', $id)->max('sortorder');
$resultNew = Activity::create([
'type_activity'=> $childActivities > 0 ? "project" : "task",
'version_gantt_id'=>$id,
@ -170,7 +193,8 @@ class ActivityController extends Controller
'name'=> $objRow->name_activity,
'start_date'=>$firstDay,
'end_date'=>$firstDay,
'created_by'=>$this->currentName
'created_by'=>$this->currentName,
'sortorder'=>$max+1
]);
$this->getChildrenTemplate($id, $objRow->id, $type_proyek_id, $proyek_id, $resultNew->id, $firstDay);
}
@ -186,6 +210,8 @@ class ActivityController extends Controller
$data['name'] = $request->text;
$data['persentase_progress'] = $request->progress;
$data['created_by'] = $this->currentName;
$max = Activity::where('version_gantt_id', $request->version_gantt_id)->max('sortorder');
$data['sortorder'] = $max + 1;
$data['type_activity'] = "task";
$parent = $data['parent_id'] ?? null;
@ -227,8 +253,13 @@ class ActivityController extends Controller
$dataUpdate['name'] = $request->text;
$dataUpdate['persentase_progress'] = $request->progress*100;
$dataUpdate['updated_by'] = $this->currentName;
unset($dataUpdate['sortorder']);
if($data->type_activity!='header')
$dataUpdate['type_activity'] = $request->type;
if($request->has("target")){
$this->updateOrder($id, $request->target);
}
if(!$data->update($dataUpdate))
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed updated!','code'=>400], 400);
@ -236,6 +267,29 @@ class ActivityController extends Controller
return response()->json(['status'=>'success','update_bobot'=> $updateBobot, 'data'=>$dataUpdate, 'action'=>'updated','message'=>'Activity updated!','code'=>200], 200);
}
private function updateOrder($taskId, $target){
$nextTask = false;
$targetId = $target;
if(strpos($target, "next:") === 0){
$targetId = substr($target, strlen("next:"));
$nextTask = true;
}
if($targetId == "null")
return;
$targetOrder = Activity::find($targetId)->sortorder;
if($nextTask)
$targetOrder++;
Activity::where("sortorder", ">=", $targetOrder)->increment("sortorder");
$updatedTask = Activity::find($taskId);
$updatedTask->sortorder = $targetOrder;
$updatedTask->save();
}
public function updateRegular(Request $request, $id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
@ -295,6 +349,51 @@ class ActivityController extends Controller
$activityStack = [];
$hasWeight = false;
foreach ($data['activities'] as $key => $value) {
if(isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0){
$hasWeight = true;
break;
}
}
if(!$hasWeight){
foreach ($data['activities'] as $key => $value) {
if($key == 0){
$data['activities'][$key]['weight'] = 100;
} else {
$parentWeight = 0;
$siblingsCount = 1;
$i = $key;
while($i > 0){
if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level']-1){
$parentWeight = $data['activities'][$i - 1]['weight'];
break;
}
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){
$siblingsCount++;
}
$i--;
}
$i = $key+1;
while($i < count($data['activities'])){
if ($data['activities'][$i]['level'] == $data['activities'][$key]['level']-1){
break;
}
// Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']);
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){
$siblingsCount++;
}
$i++;
}
$data['activities'][$key]['weight'] = $parentWeight / $siblingsCount;
}
};
}
foreach ($data['activities'] as $i => $activity_row) {
$startDate = \DateTime::createFromFormat('d-m-y', $activity_row['start_date']);
$endDate = \DateTime::createFromFormat('d-m-y', $activity_row['end_date']);
@ -309,7 +408,8 @@ class ActivityController extends Controller
$input['bobot_planning'] = $activity_row['weight'];
$input['persentase_progress'] = 0;
$input['type_activity'] = $i == 0 ? "header" : "task";
$input['created_by'] = $this->currentName;
$input['created_by'] = $this->currentName;
$input['sortorder'] = $activity_row['no'];
if (!$activity = Activity::create($input)) {
Activity::where('version_gantt_id', $data['ganttId'])->delete();

8
app/Http/Controllers/Controller.php

@ -227,14 +227,14 @@ class Controller extends BaseController
private function calculateAllHumanCost($activity_id, $proyek_id)
{
$dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate","ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate")->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id")
$dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate","ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate")
->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id")
->where("assign_hr_to_activity.activity_id", $activity_id)->where("assign_hr_to_activity.proyek_id", $proyek_id)
->where("ahp.proyek_id", $proyek_id)
->get();
$totalCost = 0;
foreach ($dataHuman as $human) {
$uom = $human->uom_standart_rate;
$totalCost += $this->calculateHumanCost($human, $activity_id);
}
@ -247,6 +247,10 @@ class Controller extends BaseController
$duration = $activity->duration;
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100;
if ($human->uom_standart_rate == "Hour") {
$totalCost = ($standarRate*8*$duration)*$maxUsed;
return $totalCost;
}
$totalCost = ($standarRate*$duration)*$maxUsed;
return $totalCost;
}

22
app/Http/Controllers/DashboardBoDController.php

@ -37,17 +37,17 @@ class DashboardBoDController extends Controller
}
private function getInvoiceIntegration($search) {
if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH');
$token = config('api.adw_token');
$response = $this->curlReq($url, $token);
if(@$response->data->project_no == "")
return null;
return $response;
// if(empty($search))
// return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
//
// $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH');
// $token = config('api.adw_token');
// $response = $this->curlReq($url, $token);
//
// if(@$response->data->project_no == "")
// return null;
//
return null;
}
// to do

48
app/Http/Controllers/HierarchyFtthController.php

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\HierarchyFtth;
use App\Models\VersionGantt;
use Illuminate\Support\Facades\Log;
class HierarchyFtthController extends Controller
{
@ -106,18 +107,26 @@ class HierarchyFtthController extends Controller
->where('proyek_id', $project_id)
->groupBy('hierarchy_ftth_id')
->get();
if($ftthIds){
foreach ($ftthIds as $ftthId) {
$gantts = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('progress');
$ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count();
$ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id);
if($ftth){
$round = $gantts/$ganttCount;
$ftth->progress = round($round, 2);
try {
$ftth->save();
} catch (\Exception $e) {
// Log the error or handle it in some other way
Log::error($e->getMessage());
}
foreach ($ftthIds as $ftthId) {
$gantts = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('progress');
$ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count();
$ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id);
$round = $gantts/$ganttCount;
$ftth->progress = round($round, 2);
$ftth->save();
if($ftth->parent_id){
$this->countParent($ftth);
if($ftth->parent_id){
$this->countParent($ftth);
}
}
}
}
}
@ -126,11 +135,18 @@ class HierarchyFtthController extends Controller
$parent = HierarchyFtth::find($ftth->parent_id);
$children = HierarchyFtth::where('parent_id', $ftth->parent_id)->sum('progress');
$childrenCount = HierarchyFtth::where('parent_id', $ftth->parent_id)->count();
$round = $children/$childrenCount;
$parent->progress = round($round, 2);
$parent->save();
if($parent->parent_id) {
$this->countParent($parent);
if($parent){
$round = $children/$childrenCount;
$parent->progress = round($round, 2);
try {
$parent->save();
} catch (\Exception $e) {
// Log the error or handle it in some other way
Log::error($e->getMessage());
}
if($parent->parent_id) {
$this->countParent($parent);
}
}
}

10
app/Http/Controllers/ProjectController.php

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

9
app/Http/Controllers/ProjectDokumenController.php

@ -94,7 +94,12 @@ class ProjectDokumenController extends Controller
if(!file_exists($this->pathDocument.$document->file))
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$pathToFile = $this->pathDocument.$document->file;
return response()->download($pathToFile);
$pathToFile = $this->pathDocument.$document->file;
$name = pathinfo($pathToFile, PATHINFO_FILENAME) . "." . pathinfo($pathToFile, PATHINFO_EXTENSION);
$headers = [
'Content-Disposition' => 'attachment; filename="'.$name.'"'
];
// dd($name, $headers);
return response()->download($pathToFile, $name, $headers);
}
}

2
app/Http/Controllers/RequestMaterialController.php

@ -170,7 +170,7 @@ class RequestMaterialController extends Controller
}
public function getMaterialIntegration(Request $request) {
$search = urlencode($request->name);
$search = null;
if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/stock_master?name=SEARCH');

13
app/Http/Controllers/UserToActivityController.php

@ -26,19 +26,20 @@ class UserToActivityController extends Controller
public function addMultiple(Request $request){
$users_id = $request->user_id;
$users_role = $request->role_proyek_id;
$data = UserToActivity::where("activity_id", $request->activity_id);
if($data){
$data->delete();
}
// $data = UserToActivity::where("activity_id", $request->activity_id);
// if($data){
// $data->delete();
// }
if(is_array($users_id) && count($users_id) > 0){
$countRes = 0;
foreach($users_id as $item){
foreach($users_id as $index => $item){
$dataInsert = array(
"user_id" => $item,
"activity_id" => $request->activity_id,
"role_proyek_id" => $request->role_proyek_id,
"role_proyek_id" => $users_role[$index],
"proyek_id" => $request->proyek_id,
"created_by" => $this->currentName
);

2
app/Http/Controllers/UserToProyekController.php

@ -185,7 +185,7 @@ class UserToProyekController extends Controller
}
public function getEmployeeIntegration(Request $request) {
$search = urlencode($request->name);
$search = null;
if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/employees?emp_name=SEARCH');

2
app/Models/Activity.php

@ -26,7 +26,7 @@ class Activity extends Model
'description', 'priority', 'bobot_planning', 'type_activity', 'open', 'geom',
'version_gantt_id', 'budget_plan', 'biaya_material_plan', 'biaya_human_plan', 'biaya_tools_plan',
'planned_start', 'planned_end', 'satuan_id',
'created_at', 'created_by', 'updated_at', 'updated_by'
'created_at', 'created_by', 'updated_at', 'updated_by', 'sortorder'
];
protected $appends = [

Loading…
Cancel
Save