From a72135a55ba6396dd5d8e6f9ed1ac8657c7de60f Mon Sep 17 00:00:00 2001 From: farhan048 Date: Thu, 19 Oct 2023 12:59:08 +0700 Subject: [PATCH 01/13] resolve conflict --- app/Models/HumanResource.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Models/HumanResource.php b/app/Models/HumanResource.php index 222a835..1f28852 100644 --- a/app/Models/HumanResource.php +++ b/app/Models/HumanResource.php @@ -33,6 +33,7 @@ class HumanResource extends Model 'updated_at', 'updated_by', 'divisi_id', - 'status_boundary' + 'status_boundary', + 'company_id' ]; } From b5e3bf60fd1fdef001cd7c247eebf6b86af93e27 Mon Sep 17 00:00:00 2001 From: farhan048 Date: Thu, 19 Oct 2023 15:46:26 +0700 Subject: [PATCH 02/13] update field for ospro general --- app/Http/Controllers/CompanyController.php | 85 ++++++++ app/Http/Controllers/Controller.php | 235 +++++++++++---------- app/Models/Company.php | 37 ++++ app/Models/Divisi.php | 36 ++-- app/Models/Menu.php | 2 +- app/Models/ProjectPhase.php | 2 +- app/Models/ProjectRole.php | 2 +- app/Models/ProjectType.php | 2 +- app/Models/Role.php | 2 +- app/Models/RoleMenu.php | 2 +- app/Models/Satuan.php | 2 +- 11 files changed, 270 insertions(+), 137 deletions(-) create mode 100644 app/Http/Controllers/CompanyController.php create mode 100644 app/Models/Company.php diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php new file mode 100644 index 0000000..d71519b --- /dev/null +++ b/app/Http/Controllers/CompanyController.php @@ -0,0 +1,85 @@ +currentDate = date("Y-m-d H:i:s"); $this->currentName = auth()->user() ? auth()->user()->name : "system"; $this->currentId = auth()->user() ? auth()->user()->id : 0; - + $this->companyId = auth()->user() ? auth()->user()->company_id : 0; $this->pathImage = config('assets.image'); $this->pathDocument = config('assets.project'); $this->pathActivityDocument = config('assets.activity'); @@ -36,41 +40,41 @@ class Controller extends BaseController protected function setUpPayload($condition, $tableSelf) { $alias = "selfTable"; - $builder = DB::table($tableSelf." AS ".$alias); + $builder = DB::table($tableSelf . " AS " . $alias); // $builder = $builder->select($alias.".*"); - if($condition){ - if(isset($condition['select'])){ - foreach($condition['select'] as $select){ - $builder = $builder->addSelect($alias.".".$select); + if ($condition) { + if (isset($condition['select'])) { + foreach ($condition['select'] as $select) { + $builder = $builder->addSelect($alias . "." . $select); } - }else{ - $builder = $builder->addSelect($alias.".*"); + } else { + $builder = $builder->addSelect($alias . ".*"); } - if(isset($condition['joins'])){ + if (isset($condition['joins'])) { $selectColumn = []; $no = 0; - foreach($condition['joins'] as $join){ + foreach ($condition['joins'] as $join) { $tableJoin = isset($join['name1']) ? $join['name1'] : $alias; $tableName = $join['name']; $columnJoin = $join['column_join']; // foreign key table sini $columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan $columnResult = $join['column_results']; - foreach($columnResult as $sColumn){ - $builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn); + foreach ($columnResult as $sColumn) { + $builder = $builder->addSelect($tableName . "." . $sColumn . " as join_" . $this->listJoinAll[$no] . "_" . $sColumn); } - $builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf); + $builder = $builder->leftJoin($tableName, $tableJoin . "." . $columnJoin, '=', $tableName . '.' . $columnSelf); $no++; } } - if(isset($condition['columns'])){ + if (isset($condition['columns'])) { $listWhere = $condition['columns']; - $builder = $builder->where(function ($query) use($listWhere, $alias){ - foreach($listWhere as $where){ + $builder = $builder->where(function ($query) use ($listWhere, $alias) { + foreach ($listWhere as $where) { $value = $where['value']; - if($value && $value!="" && $value!=" "){ + if ($value && $value != "" && $value != " ") { $column = $where['name']; $operator = strtolower($where['logic_operator']); // like, =, <>, range $value2 = isset($where['value1']) ? $where['value1'] : ""; @@ -81,22 +85,22 @@ class Controller extends BaseController }); } - if(isset($condition['group_column'])){ + if (isset($condition['group_column'])) { $builder = $this->groupWhere($builder, $condition['group_column'], $alias); } $data['count'] = clone $builder; - if(isset($condition['paging'])){ + if (isset($condition['paging'])) { $builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']); } - if(isset($condition['orders'])){ + if (isset($condition['orders'])) { $orders = $condition['orders']; $sortBy = $orders['ascending'] ? "ASC" : "DESC"; $columnOrder = $orders['columns']; - foreach($columnOrder as $column){ - $builder = $builder->orderBy($alias.".".$column, $sortBy); + foreach ($columnOrder as $column) { + $builder = $builder->orderBy($alias . "." . $column, $sortBy); } } } @@ -111,8 +115,8 @@ class Controller extends BaseController $operator = $listGroupWhere['operator']; $operatorGroup = $listGroupWhere['group_operator']; $listWhere = $listGroupWhere['where']; - if(strtolower($operator)=="and"){ - $builder = $builder->where(function($query) use($operatorGroup, $listWhere, $alias){ + if (strtolower($operator) == "and") { + $builder = $builder->where(function ($query) use ($operatorGroup, $listWhere, $alias) { $no = 1; foreach ($listWhere as $where) { $value = $where['value']; @@ -120,22 +124,22 @@ class Controller extends BaseController $operator = strtolower($where['logic_operator']); $value2 = isset($where['value1']) ? $where['value1'] : ""; $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; - if($value && $value!="" && $value!=" "){ - if($operatorGroup=="and"){ + if ($value && $value != "" && $value != " ") { + if ($operatorGroup == "and") { $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); - }else{ - if($no==1){ + } else { + if ($no == 1) { $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); - }else{ + } else { $query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2); } } } - $no = $no+1; + $no = $no + 1; } }); - }else if(strtolower($operator)=="or"){ - $builder = $builder->orWhere(function($query) use($operatorGroup, $listWhere, $alias){ + } else if (strtolower($operator) == "or") { + $builder = $builder->orWhere(function ($query) use ($operatorGroup, $listWhere, $alias) { $no = 1; foreach ($listWhere as $where) { $value = $where['value']; @@ -143,13 +147,13 @@ class Controller extends BaseController $operator = strtolower($where['logic_operator']); $value2 = isset($where['value1']) ? $where['value1'] : ""; $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; - if($value && $value!="" && $value!=" "){ - if($operatorGroup=="and"){ + if ($value && $value != "" && $value != " ") { + if ($operatorGroup == "and") { $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); - }else{ - if($no==1){ + } else { + if ($no == 1) { $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); - }else{ + } else { $query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2); } } @@ -164,39 +168,40 @@ class Controller extends BaseController private function whereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2) { $query = $oldQuery; - if($operator=="range"){ - $query = $query->whereBetween($tableColumn.".".$column, [$value, $value2]); - }else if($operator=="like"){ - $query = $query->where($tableColumn.".".$column, 'like', '%'.$value.'%'); - }else if($operator=="ilike"){ - $query = $query->where($tableColumn.".".$column, '~*', $value); - }else if($operator=="="){ - $query = $query->where($tableColumn.".".$column, $value); - }else if($operator=="in"){ - $query = $query->whereIn($tableColumn.".".$column, $value); - }else if($operator=="notin"){ - $query = $query->whereNotIn($tableColumn.".".$column, $value); - }else{ - $query = $query->where($tableColumn.".".$column, $operator, $value); + if ($operator == "range") { + $query = $query->whereBetween($tableColumn . "." . $column, [$value, $value2]); + } else if ($operator == "like") { + $query = $query->where($tableColumn . "." . $column, 'like', '%' . $value . '%'); + } else if ($operator == "ilike") { + $query = $query->where($tableColumn . "." . $column, '~*', $value); + } else if ($operator == "=") { + $query = $query->where($tableColumn . "." . $column, $value); + } else if ($operator == "in") { + $query = $query->whereIn($tableColumn . "." . $column, $value); + } else if ($operator == "notin") { + $query = $query->whereNotIn($tableColumn . "." . $column, $value); + } else { + $query = $query->where($tableColumn . "." . $column, $operator, $value); } return $query; } - private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2){ + private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2) + { $query = $oldQuery; - if($operator=="range"){ + if ($operator == "range") { $query = $query->whereBetween($column, [$value, $value2]); - }else if($operator=="like"){ - $query = $query->where($column, 'like', '%'.$value.'%'); - }else if($operator=="ilike"){ + } else if ($operator == "like") { + $query = $query->where($column, 'like', '%' . $value . '%'); + } else if ($operator == "ilike") { $query = $query->where($column, '~*', $value); - }else if($operator=="="){ + } else if ($operator == "=") { $query = $query->where($column, $value); - }else if($operator=="in"){ + } else if ($operator == "in") { $query = $query->whereIn($column, $value); - }else if($operator=="notin"){ + } else if ($operator == "notin") { $query = $query->whereNotIn($column, $value); - }else{ + } else { $query = $query->where($column, $operator, $value); } return $query; @@ -205,25 +210,26 @@ class Controller extends BaseController private function orWhereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2) { $query = $oldQuery; - if($operator=="range"){ - $query = $query->orWhereBetween($tableColumn.".".$column, [$value, $value2]); - }else if($operator=="like"){ - $query = $query->orWhere($tableColumn.".".$column, 'like', '%'.$value.'%'); - }else if($operator=="ilike"){ - $query = $query->where($tableColumn.".".$column, '~*', $value); - }else if($operator=="="){ - $query = $query->orWhere($tableColumn.".".$column, $value); - }else if($operator=="in"){ - $query = $query->orWhereIn($tableColumn.".".$column, $value); - }else if($operator=="notin"){ - $query = $query->orWhereNotIn($tableColumn.".".$column, $value); - }else{ - $query = $query->orWhere($tableColumn.".".$column, $operator, $value); + if ($operator == "range") { + $query = $query->orWhereBetween($tableColumn . "." . $column, [$value, $value2]); + } else if ($operator == "like") { + $query = $query->orWhere($tableColumn . "." . $column, 'like', '%' . $value . '%'); + } else if ($operator == "ilike") { + $query = $query->where($tableColumn . "." . $column, '~*', $value); + } else if ($operator == "=") { + $query = $query->orWhere($tableColumn . "." . $column, $value); + } else if ($operator == "in") { + $query = $query->orWhereIn($tableColumn . "." . $column, $value); + } else if ($operator == "notin") { + $query = $query->orWhereNotIn($tableColumn . "." . $column, $value); + } else { + $query = $query->orWhere($tableColumn . "." . $column, $operator, $value); } return $query; } - protected function calculateAllCost($activity_id, $proyek_id){ + protected function calculateAllCost($activity_id, $proyek_id) + { $humanCostPlanning = $this->calculateAllHumanCost($activity_id, $proyek_id); $materialCostPlanning = $this->calculateMaterialCost($activity_id, $proyek_id); $toolsCostPlanning = 0; @@ -234,11 +240,11 @@ 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") - ->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(); + $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) { @@ -253,58 +259,61 @@ class Controller extends BaseController $activity = Activity::find($activity_id); $duration = $activity->duration; $standarRate = $human->standart_rate; - $maxUsed = $human->max_used/100; + $maxUsed = $human->max_used / 100; if ($human->uom_standart_rate == "Hour") { - $totalCost = ($standarRate*8*$duration)*$maxUsed; - return $totalCost; + $totalCost = ($standarRate * 8 * $duration) * $maxUsed; + return $totalCost; } - $totalCost = ($standarRate*$duration)*$maxUsed; + $totalCost = ($standarRate * $duration) * $maxUsed; return $totalCost; } private function calculateMaterialCost($activity_id, $proyek_id) { - $totalCost = AssignMaterial::selectRaw("COALESCE(qty_planning,0)*COALESCE(budget,0) as totalCost") - ->where("proyek_id", $proyek_id) - ->where("activity_id", $activity_id) - ->sum(AssignMaterial::raw("COALESCE(qty_planning, 0) * COALESCE(budget, 0)")); + $totalCost = AssignMaterial::selectRaw("COALESCE(qty_planning,0)*COALESCE(budget,0) as totalCost") + ->where("proyek_id", $proyek_id) + ->where("activity_id", $activity_id) + ->sum(AssignMaterial::raw("COALESCE(qty_planning, 0) * COALESCE(budget, 0)")); return $totalCost; } - protected function getLoc($lat, $lng){ + protected function getLoc($lat, $lng) + { // $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json"); // return $response->json; - $url = config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json"; - // $token = config('api.adw_token'); - $response = $this->curlRequest($url); + $url = config('api.nominatim') . "/reverse?lat=" . $lat . "&lon=" . $lng . "&format=json"; + // $token = config('api.adw_token'); + $response = $this->curlRequest($url); return $response; } - private function curlRequest($url){ - $ch = curl_init(); - // $headers = [ - // 'Authorization: '.$token - // ]; - curl_setopt($ch, CURLOPT_URL, $url); - // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + private function curlRequest($url) + { + $ch = curl_init(); + // $headers = [ + // 'Authorization: '.$token + // ]; + curl_setopt($ch, CURLOPT_URL, $url); + // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - $response = curl_exec($ch); - if ($response === false) - $response = curl_error($ch); - curl_close($ch); + $response = curl_exec($ch); + if ($response === false) + $response = curl_error($ch); + curl_close($ch); - return json_decode($response); - } + return json_decode($response); + } - protected function addDetailK3($dataDetail, $report_id){ + protected function addDetailK3($dataDetail, $report_id) + { foreach ($dataDetail as $value) { $dataNew = array( - "report_k3_id"=>$report_id, - "checklist_k3_id"=>$value['checklist_id'], - "name_checklist_k3"=>$value['checklist_name'], - "created_by"=>$this->currentName + "report_k3_id" => $report_id, + "checklist_k3_id" => $value['checklist_id'], + "name_checklist_k3" => $value['checklist_name'], + "created_by" => $this->currentName ); ReportK3Detail::create($dataNew); diff --git a/app/Models/Company.php b/app/Models/Company.php new file mode 100644 index 0000000..7b85e58 --- /dev/null +++ b/app/Models/Company.php @@ -0,0 +1,37 @@ +children()->delete(); }); } public function parent() { - return $this->belongsTo('App\Models\Divisi','parent')->where('parent', null)->with('parent'); + return $this->belongsTo('App\Models\Divisi', 'parent')->where('parent', null)->with('parent'); } public function children() { - return $this->hasMany('App\Models\Divisi','parent')->with('children'); + return $this->hasMany('App\Models\Divisi', 'parent')->with('children'); } } diff --git a/app/Models/Menu.php b/app/Models/Menu.php index a507545..951f6da 100644 --- a/app/Models/Menu.php +++ b/app/Models/Menu.php @@ -13,6 +13,6 @@ class Menu extends Model protected $fillable = [ 'parent_id', 'icon', 'name', 'alias_name', 'url', 'sequence', - 'created_at', 'created_by', 'updated_at', 'updated_by' + 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' ]; } diff --git a/app/Models/ProjectPhase.php b/app/Models/ProjectPhase.php index 1a82a81..ffe1ed4 100644 --- a/app/Models/ProjectPhase.php +++ b/app/Models/ProjectPhase.php @@ -12,6 +12,6 @@ class ProjectPhase extends Model const UPDATED_AT = 'updated_at'; protected $fillable = [ - 'name', 'color', 'order', 'created_at', 'created_by', 'updated_at', 'updated_by' + 'name', 'color', 'order', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' ]; } diff --git a/app/Models/ProjectRole.php b/app/Models/ProjectRole.php index 52a7b46..9d15c1a 100644 --- a/app/Models/ProjectRole.php +++ b/app/Models/ProjectRole.php @@ -12,6 +12,6 @@ class ProjectRole extends Model const UPDATED_AT = 'updated_at'; protected $fillable = [ - 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' + 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' ]; } diff --git a/app/Models/ProjectType.php b/app/Models/ProjectType.php index 9edca0e..f6e9604 100644 --- a/app/Models/ProjectType.php +++ b/app/Models/ProjectType.php @@ -12,6 +12,6 @@ class ProjectType extends Model const UPDATED_AT = 'updated_at'; protected $fillable = [ - 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' + 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' ]; } diff --git a/app/Models/Role.php b/app/Models/Role.php index 73de4a2..4fdc897 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -12,6 +12,6 @@ class Role extends Model const UPDATED_AT = 'updated_at'; protected $fillable = [ - 'name', 'description', 'default_page', 'created_at', 'created_by', 'updated_at', 'updated_by' + 'name', 'description', 'default_page', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' ]; } diff --git a/app/Models/RoleMenu.php b/app/Models/RoleMenu.php index 3540ea6..2a59ede 100644 --- a/app/Models/RoleMenu.php +++ b/app/Models/RoleMenu.php @@ -12,6 +12,6 @@ class RoleMenu extends Model const UPDATED_AT = 'updated_at'; protected $fillable = [ - 'role_id', 'menu_id', 'created_at', 'created_by', 'updated_at', 'updated_by' + 'role_id', 'menu_id', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id', "create", "read", "update", "delete" ]; } diff --git a/app/Models/Satuan.php b/app/Models/Satuan.php index 05305af..9779db6 100644 --- a/app/Models/Satuan.php +++ b/app/Models/Satuan.php @@ -12,6 +12,6 @@ class Satuan extends Model const UPDATED_AT = 'updated_at'; protected $fillable = [ - 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' + 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' ]; } From 79e044fbd50874a8895847b5fa42aa83794e0c14 Mon Sep 17 00:00:00 2001 From: farhan048 Date: Fri, 20 Oct 2023 17:27:40 +0700 Subject: [PATCH 03/13] company mangement --- app/Http/Controllers/CompanyController.php | 139 ++++++++++++--------- app/Models/Company.php | 2 +- routes/web.php | 26 ++-- 3 files changed, 99 insertions(+), 68 deletions(-) diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index d71519b..7e8938d 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -7,79 +7,104 @@ use Illuminate\Http\Request; class CompanyController extends Controller { - /** - * Display a listing of the resource. - * - * @return \Illuminate\Http\Response - */ - public function index() + public function add(Request $request) { - // - } + $this->validate($request, [ + 'name' => 'required', + 'description' => 'required' + ]); - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - // + $data = $request->all(); + + $data['created_by'] = $this->currentName; + + $result = Company::create($data); + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'add Company successfully!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'add data Company failed!', 'code' => 400], 400); + } } - /** - * Store a newly created resource in storage. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response - */ - public function store(Request $request) + public function edit($id) { - // + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + die(); + } + + $result = Company::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get data Company, please try again later!', 'code' => 400], 400); + } } - /** - * Display the specified resource. - * - * @param \App\Company $company - * @return \Illuminate\Http\Response - */ - public function show(Company $company) + public function update(Request $request, $id) { - // + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $data = Company::find($id); + + if ($data) { + $result = $data->update($request->all()); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400); + die(); + } + + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data Company successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Company failed updated!', 'code' => 400], 400); + } } - /** - * Show the form for editing the specified resource. - * - * @param \App\Company $company - * @return \Illuminate\Http\Response - */ - public function edit(Company $company) + public function delete($id) { - // + $data = Company::find($id); + + if ($data) { + $delete = $data->delete(); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400); + die(); + } + + + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'data Company successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Company failed deleted!', 'code' => 400], 400); + } } - /** - * Update the specified resource in storage. - * - * @param \Illuminate\Http\Request $request - * @param \App\Company $company - * @return \Illuminate\Http\Response - */ - public function update(Request $request, Company $company) + public function search(Request $request) { - // + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_company'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); } - /** - * Remove the specified resource from storage. - * - * @param \App\Company $company - * @return \Illuminate\Http\Response - */ - public function destroy(Company $company) + public function list() { - // + $data = Company::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list Company, please try again later!', 'code' => 400], 400); + } } } diff --git a/app/Models/Company.php b/app/Models/Company.php index 7b85e58..db52f7d 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; class Company extends Model { - protected $table = 'm_divisi'; + protected $table = 'm_company'; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; diff --git a/routes/web.php b/routes/web.php index 73b90db..bf32671 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,10 +1,10 @@ get('/', function () use ($router) { - return $router->app->version(); + return $router->app->version(); }); -$router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($router) { +$router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($router) { $router->post('/login', 'AuthController@login'); $router->post('/menu/add', 'MenuController@add'); @@ -53,7 +53,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject'); $router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen'); - $router->get('/project-by-customer/{id}','ProjectController@getByUser'); + $router->get('/project-by-customer/{id}', 'ProjectController@getByUser'); $router->post('/project/search', 'ProjectController@search'); $router->post('/project/add', 'ProjectController@add'); $router->put('/project/update/{id}', 'ProjectController@update'); @@ -207,11 +207,11 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId'); $router->post('/activity/search', 'ActivityController@search'); $router->post('/activity/search-analysis', 'ActivityController@searchAnalysis'); - $router->post('/activity/import', 'ActivityController@import'); - $router->post('/activity/import-update', 'ActivityController@importUpdate'); - $router->post('/activity/import-old', 'ActivityController@importOld'); - $router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate'); - $router->get('/activity/update-schedule/{ganttId}', 'ActivityController@updateSchedule'); + $router->post('/activity/import', 'ActivityController@import'); + $router->post('/activity/import-update', 'ActivityController@importUpdate'); + $router->post('/activity/import-old', 'ActivityController@importOld'); + $router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate'); + $router->get('/activity/update-schedule/{ganttId}', 'ActivityController@updateSchedule'); $router->post('/task', 'ActivityController@add'); $router->get('/task/edit/{id}', 'ActivityController@edit'); $router->put('/task/{id}', 'ActivityController@update'); @@ -411,7 +411,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->get('/report-k3-detail/list', 'ReportK3DetailController@list'); $router->post('/user-to-proyek/add', 'UserToProyekController@add'); - $router->post('/user-to-proyek/add-multiple', 'UserToProyekController@addMultiple'); + $router->post('/user-to-proyek/add-multiple', 'UserToProyekController@addMultiple'); $router->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit'); $router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update'); $router->post('/user-to-proyek/search', 'UserToProyekController@search'); @@ -496,6 +496,12 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout $router->post('/broadcast/search', 'BroadcastController@search'); $router->delete('/broadcast/delete/{id}', 'BroadcastController@delete'); $router->get('/broadcast/list', 'BroadcastController@list'); - }); + $router->post('/company-management/add', 'CompanyController@add'); + $router->get('/company-management/edit/{id}', 'CompanyController@edit'); + $router->put('/company-management/update/{id}', 'CompanyController@update'); + $router->post('/company-management/search', 'CompanyController@search'); + $router->delete('/company-management/delete/{id}', 'CompanyController@delete'); + $router->get('/company-management/list', 'CompanyController@list'); + }); }); From b737208d2a07956ba70654f6154dbab220acf872 Mon Sep 17 00:00:00 2001 From: farhan048 Date: Tue, 24 Oct 2023 19:21:56 +0700 Subject: [PATCH 04/13] Merge branch 'staging' of https://git.oslog.id/ordo/adw-backend into Dev-Farhan --- app/Helpers/MasterFunctionsHelper.php | 6 ++++++ app/Http/Controllers/ActivityController.php | 13 +++++++++++++ app/Models/Activity.php | 12 +++++++++--- app/Models/HierarchyFtth.php | 16 +++++++++++----- app/Models/VersionGantt.php | 7 +++++++ routes/web.php | 1 + 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 1bed1bb..add9de1 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -708,6 +708,9 @@ class MasterFunctionsHelper $tempTtlPercentPlan += $sumPercentagePlan; $tempTtlPercentActual += $sumPercentageActual; + if ($tempTtlPercentPlan >= 100) + $tempTtlPercentPlan = 100; + $currentACWP += $totalACWP; $currentBCWP += $totalBCWP; @@ -715,6 +718,9 @@ class MasterFunctionsHelper $tempPercentagePlan[] = round($tempTtlPercentPlan, 2); $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; $tempPercentageReal[] = round($tempTtlPercentActual, 2); + if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) { + break; + } } else { $tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2)); $tempPercentagePlan[] = round($sumPercentagePlan, 2); diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index df66558..0e23cdb 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -527,6 +527,19 @@ class ActivityController extends Controller return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); } + public function searchAnalysisPrep(Request $request) + { + $data = $request->all(); + $dataGet = DB::table('m_activity') + ->select('m_activity.name') + ->where('m_activity.proyek_id', $data['columns'][0]['value']) + ->where('m_activity.type_activity', 'task') + ->where('m_activity.persentase_progress', '>', 0) + ->groupByRaw('m_activity.name') + ->get(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); + } + public function searchAnalysis(Request $request) { $dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 3a8e54c..5d9c1e7 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -79,8 +79,14 @@ class Activity extends Model }); static::deleted(function($data) { - if(Activity::where("parent_id", $data->parent_id)->count() == 0) - Activity::find($data->parent_id)->update(["type_activity"=>"task"]); + if (isset($data->parent_id)) { + if(Activity::where("parent_id", $data->parent_id)->count() == 0) { + $activity = Activity::find($data->parent_id); + if ($activity) { + $activity->update(["type_activity"=>"task"]); + } + } + } $data->updateBobot(true); $data->updateCostPlanning(); @@ -100,7 +106,7 @@ class Activity extends Model ->whereNull('parent_id') ->first(); - if($root->rencana_biaya > 0){ + if(isset($root) && $root->rencana_biaya > 0){ $activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get(); foreach ($activities as $activity) { if($isDelete && $activity->id == $this->id) diff --git a/app/Models/HierarchyFtth.php b/app/Models/HierarchyFtth.php index fae503c..1a0ba8c 100644 --- a/app/Models/HierarchyFtth.php +++ b/app/Models/HierarchyFtth.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use App\Models\VersionGantt; class HierarchyFtth extends Model { @@ -14,15 +15,20 @@ class HierarchyFtth extends Model protected $fillable = [ 'name', 'parent_id', 'project_id', 'created_at', 'updated_at', 'progress', 'bobot_planning' ]; - + public static function boot() { parent::boot(); static::deleted(function($data) { - $ftths = HierarchyFtth::where('parent_id', $data->id)->get(); - foreach ($ftths as $ftth) { - $ftth->delete(); - } + $ftths = HierarchyFtth::where('parent_id', $data->id)->get(); + foreach ($ftths as $ftth) { + $ftth->delete(); + } + + $gantts = VersionGantt::where('hierarchy_ftth_id', $data->id)->get(); + foreach ($gantts as $gantt) { + $gantt->delete(); + } }); } } diff --git a/app/Models/VersionGantt.php b/app/Models/VersionGantt.php index 765ddf1..39b9b0f 100644 --- a/app/Models/VersionGantt.php +++ b/app/Models/VersionGantt.php @@ -38,6 +38,13 @@ class VersionGantt extends Model static::updated(function($data) { $data->updateActDuration(); + }); + + static::deleted(function ($data) { + $activities = Activity::where('version_gantt_id', $data->id)->get(); + foreach ($activities as $activity) { + $activity->delete(); + } }); } diff --git a/routes/web.php b/routes/web.php index bf32671..3cab9d8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -207,6 +207,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro $router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId'); $router->post('/activity/search', 'ActivityController@search'); $router->post('/activity/search-analysis', 'ActivityController@searchAnalysis'); + $router->post('/activity/search-analysis-prep', 'ActivityController@searchAnalysisPrep'); $router->post('/activity/import', 'ActivityController@import'); $router->post('/activity/import-update', 'ActivityController@importUpdate'); $router->post('/activity/import-old', 'ActivityController@importOld'); From 9722947c281d909d5248954f7eaad5ef9580b5e7 Mon Sep 17 00:00:00 2001 From: farhan048 Date: Wed, 25 Oct 2023 15:30:47 +0700 Subject: [PATCH 05/13] remove plan --- app/Helpers/MasterFunctionsHelper.php | 49 +++++++++++++-------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 24c7325..ec7b010 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -36,10 +36,11 @@ class MasterFunctionsHelper return json_decode($output); } - public static function countDays($ganttId, $start, $end){ + public static function countDays($ganttId, $start, $end) + { $dayOffs = VersionGantt::where('id', $ganttId)->first()->config_dayoff; $diff = date_diff($start, $end); - $endCount = clone $end; + $endCount = clone $end; $duration = $diff->days + 1; $daysRemaining = $duration; // Loop until the remaining days become zero @@ -206,7 +207,7 @@ class MasterFunctionsHelper $end = new \DateTime($maxDate . ' Friday'); $end->modify('next Friday'); $end->modify('next Friday'); - /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged + /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged $interval = new \DateInterval('P7D'); } else { $actualMaxDate = DB::table('assign_material_to_activity as ama') @@ -402,7 +403,7 @@ class MasterFunctionsHelper // if($tempTtlPercentActual >= $keyGantt['progress']) // $tempTtlPercentActual = $keyGantt['progress']; - // todo + // todo // if ($tempTtlPercentPlan >= 100) // $tempTtlPercentPlan = 100; // $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual @@ -448,8 +449,8 @@ class MasterFunctionsHelper $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; } - $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; - $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; + $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; + $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; $dataResponse = array( "date" => $tempDate, "percentage" => $tempPercentage, @@ -514,7 +515,7 @@ class MasterFunctionsHelper $end = new \DateTime($maxDate); $end->modify('next Friday'); $end->modify('next Friday'); - /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged + /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged $interval = new \DateInterval('P7D'); } else { // $maxDate = DB::table('assign_material_to_activity as ama') @@ -655,17 +656,17 @@ class MasterFunctionsHelper ->where('activity_id', '=', $keyActualM->activity_id) ->orderBy('status_activity', 'ASC') ->first(); - if (!isset($checkStatusActivity)) { - $checkStatusActivity = (object) [ - 'activity_id' => $keyActualM->activity_id, - 'status_activity' => 'open' - ]; - } - if ($sumVolActual->ttl_qty_plan == "0") { - $actual = 0; - } else { - $actual = $keyActualM->qty / $sumVolActual->ttl_qty_plan; - } + if (!isset($checkStatusActivity)) { + $checkStatusActivity = (object) [ + 'activity_id' => $keyActualM->activity_id, + 'status_activity' => 'open' + ]; + } + if ($sumVolActual->ttl_qty_plan == "0") { + $actual = 0; + } else { + $actual = $keyActualM->qty / $sumVolActual->ttl_qty_plan; + } $dataTempReport[$w]['percentage'] = $actual * $keyActualM->bobot_planning; // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; // if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){ @@ -673,7 +674,7 @@ class MasterFunctionsHelper $sumPercentageActual += $keyActualM->bobot_planning / $reportCount; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; } else { - if ( $actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) { + if ($actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) { $sumPercentageActual += ($actual * $keyActualM->bobot_planning) * (95 / 100); // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; } else { @@ -708,13 +709,10 @@ class MasterFunctionsHelper if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') { $tempTtlPercentPlan += $sumPercentagePlan; $tempTtlPercentActual += $sumPercentageActual; - // todo + // todo // if ($tempTtlPercentPlan >= 100) // $tempTtlPercentPlan = 100; - if ($tempTtlPercentPlan >= 100) - $tempTtlPercentPlan = 100; - $currentACWP += $totalACWP; $currentBCWP += $totalBCWP; @@ -755,7 +753,7 @@ class MasterFunctionsHelper } $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; - $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; + $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; $dataResponse = array( "date" => $tempDate, "percentage" => $tempPercentage, @@ -820,7 +818,7 @@ class MasterFunctionsHelper if (isset($dataPayload['end_date'])) { $maxDate = $dataPayload['end_date']; $end = new \DateTime($maxDate); - /* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged + /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged $interval = new \DateInterval('P7D'); } else { // $maxDate = DB::table('assign_material_to_activity as ama') @@ -1009,5 +1007,4 @@ class MasterFunctionsHelper return $dataFinal; } - } From eeaa33fcc4441cda454042075f3cd41130ae10a7 Mon Sep 17 00:00:00 2001 From: farhan048 Date: Mon, 13 Nov 2023 18:45:01 +0700 Subject: [PATCH 06/13] menu ospro General --- app/Http/Controllers/Controller.php | 48 +++++ .../Controllers/MenuCompanyController.php | 195 ++++++++++++++++++ app/Models/Menu.php | 2 +- app/Models/MenuCompany.php | 27 +++ app/Models/Project.php | 17 +- routes/web.php | 8 + 6 files changed, 287 insertions(+), 10 deletions(-) create mode 100644 app/Http/Controllers/MenuCompanyController.php create mode 100644 app/Models/MenuCompany.php diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 31f6ef2..02049ab 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -7,6 +7,8 @@ use Illuminate\Support\Facades\Http; use App\Models\UserToActivity; use App\Models\Activity; use App\Models\AssignMaterial; +use App\Models\User; +use App\Models\Divisi; use Laravel\Lumen\Routing\Controller as BaseController; use App\Models\ReportK3Detail; @@ -321,4 +323,50 @@ class Controller extends BaseController ReportK3Detail::create($dataNew); } } + + protected function getDataHierarchy($divisi, $paramUserId) + { + $parentDivisi = Divisi::where('id', $divisi)->get(); + $divisions = []; + $tempUser = []; + $userId = [$paramUserId]; + // if ($parentDivisi->parent == null){ + + // }else{ + foreach ($parentDivisi as $key) { + $data = $this->getAllChildrenDivisi($key->id); + $divisions[] = $data; + } + if (count($divisions) > 0) { + for ($i = 0; $i < count($divisions[0]); $i++) { + if (User::select('id', 'name', 'divisi_id')->where('divisi_id', $divisions[0][$i]->id)->exists()) { + $tempUser[] = User::select('id', 'name', 'divisi_id')->where('divisi_id', $divisions[0][$i]->id)->get(); + } + } + + for ($x = 0; $x < count($tempUser); $x++) { + for ($y = 0; $y < count($tempUser[$x]); $y++) { + $userId[] = $tempUser[$x][$y]->id; + } + } + } + + return $userId; + // } + // return $userId; + } + + private function getAllChildrenDivisi($divisi) + { + $finalData = []; + $divisi = Divisi::where('parent', $divisi)->get(); + if (count($divisi) > 0) { + foreach ($divisi as $key) { + $childDivisi = $this->getAllChildrenDivisi($key->id); + $finalData[] = $key; + $finalData = array_merge($finalData, $childDivisi); + } + } + return $finalData; + } } diff --git a/app/Http/Controllers/MenuCompanyController.php b/app/Http/Controllers/MenuCompanyController.php new file mode 100644 index 0000000..2b79748 --- /dev/null +++ b/app/Http/Controllers/MenuCompanyController.php @@ -0,0 +1,195 @@ +validate($request, [ + // 'icon' => 'required', + // 'name' => 'string|required', + // 'url' => 'required|unique:m_company_menu,url', + // 'sequence' => 'required|integer', + // ]); + + // $data = $request->all(); + + // $data['created_by'] = $this->currentName; + + // $result = MenuCompany::create($data); + + // if ($result) { + // return response()->json(['status' => 'success', 'message' => 'add data menu successfully!', 'code' => 200], 200); + // } else { + // return response()->json(['status' => 'failed', 'message' => 'add data menu failed!', 'code' => 400], 400); + // } + // } + + public function addMultiple(Request $request) + { + $menus = $request->all(); + + if (is_array($menus) && count($menus) > 0) { + $countRes = 0; + foreach ($menus as $menu) { + + $dataInsert = array( + "menu_id" => $menu['menu_id'], + "parent_menu_id" => $menu['parent_id'], + "company_id" => $menu['company_id'], + "icon" => $menu['icon'], + "alias_name" => $menu['alias_name'], + "url" => $menu['url'], + "sequence" => $menu['sequence'], + "created_by" => $this->currentName + ); + + $result = MenuCompany::create($dataInsert); + + if ($result) { + $countRes++; + } else { + $countRes--; + } + } + + if ($countRes > 0) { + return response()->json(['status' => 'success', 'message' => 'add data menu successfully!', 'code' => 200]); + } else { + return response()->json(['status' => 'failed', 'message' => 'add data menu failed created!', 'code' => 400]); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'add data menu failed created!', 'code' => 400]); + } + } + + + public function edit($id) + { + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + die(); + } + + $result = MenuCompany::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get data menu, please try again later!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + $this->validate($request, [ + 'icon' => 'required', + 'sequence' => 'required|integer', + ]); + $data = MenuCompany::find($id); + + + if ($data) { + $result = $data->update($request->all()); + } else { + return response()->json(['status' => 'failed', 'message' => 'data menu not found!', 'code' => 400], 400); + die(); + } + + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data menu successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data menu failed updated!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $data = MenuCompany::find($id); + + if ($data) { + $delete = $data->delete(); + } else { + return response()->json(['status' => 'failed', 'message' => 'data menu not found!', 'code' => 400], 400); + die(); + } + + + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'data menu successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data menu failed deleted!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_company_menu'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function listMenu($id) + { + $dataParent = RoleMenu::select("m_company_menu.*") + ->join('m_company_menu', 'm_company_menu.id', '=', 't_roles_menu.menu_id') + ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') + ->whereNull('m_company_menu.parent_id') + ->where('m_roles.id', $id) + ->orderBy('m_company_menu.sequence', 'ASC') + ->get(); + + $finalData = []; + foreach ($dataParent as $data) { + $data->children = $this->getChildrenMenu($data->id, $id); + $finalData[] = $data; + } + + return response()->json(['status' => 'success', 'code' => 200, 'data' => $finalData], 200); + } + + protected function getChildrenMenu($id, $role_id) + { + $dataChildren = RoleMenu::select("m_company_menu.*") + ->join('m_company_menu', 'm_company_menu.id', '=', 't_roles_menu.menu_id') + ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') + ->where('m_roles.id', $role_id) + ->where('m_company_menu.parent_id', $id) + ->orderBy('m_company_menu.sequence', 'ASC') + ->get(); + $children = []; + if ($dataChildren) { + foreach ($dataChildren as $data) { + $data->children = $this->getChildrenMenu($data->id, $role_id); + $children[] = $data; + } + } + return $children; + } + + public function list() + { + $data = MenuCompany::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list menu, please try again later!', 'code' => 400], 400); + } + } +} diff --git a/app/Models/Menu.php b/app/Models/Menu.php index 951f6da..a507545 100644 --- a/app/Models/Menu.php +++ b/app/Models/Menu.php @@ -13,6 +13,6 @@ class Menu extends Model protected $fillable = [ 'parent_id', 'icon', 'name', 'alias_name', 'url', 'sequence', - 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id' + 'created_at', 'created_by', 'updated_at', 'updated_by' ]; } diff --git a/app/Models/MenuCompany.php b/app/Models/MenuCompany.php new file mode 100644 index 0000000..6038bda --- /dev/null +++ b/app/Models/MenuCompany.php @@ -0,0 +1,27 @@ +group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro $router->post('/company-management/search', 'CompanyController@search'); $router->delete('/company-management/delete/{id}', 'CompanyController@delete'); $router->get('/company-management/list', 'CompanyController@list'); + + $router->post('/menu-company/add-multiple', 'MenuCompanyController@addMultiple'); + $router->get('/menu-company/edit/{id}', 'MenuCompanyController@edit'); + $router->put('/menu-company/update/{id}', 'MenuCompanyController@update'); + $router->delete('/menu-company/delete/{id}', 'MenuCompanyController@delete'); + $router->post('/menu-company/search', 'MenuCompanyController@search'); + $router->get('/menu-company/management/{id}', 'MenuCompanyController@listMenu'); + $router->get('/menu-company/list', 'MenuCompanyController@list'); }); }); From d023856cb3980040efc2239eae057e4946d15ee4 Mon Sep 17 00:00:00 2001 From: ibnu Date: Thu, 21 Dec 2023 16:37:45 +0700 Subject: [PATCH 07/13] update where proyek_id --- app/Http/Controllers/UserToActivityController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index 9703946..5a2238d 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -202,6 +202,7 @@ class UserToActivityController extends Controller ->where('ahta.user_id', $payload['user_id']) ->where('ma.start_date', '<=', $payload['start_date']) ->where('ma.end_date', '>=', $payload['end_date']) + ->where('ma.proyek', '>=', $payload['proyek_id']) ->get(); if ($payload['status'] != "") { From 8110897a3b1338de914ab14acd0ba32b59d23e40 Mon Sep 17 00:00:00 2001 From: ibnu Date: Thu, 21 Dec 2023 17:06:49 +0700 Subject: [PATCH 08/13] update add divisi name --- app/Http/Controllers/DashboardBoDController.php | 5 +++-- app/Models/Project.php | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index af68816..70bb309 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -350,8 +350,9 @@ class DashboardBoDController extends Controller public function getDetailExpenditure($year = '%') { $year = $this->interpolateYear($year); - $projects = Project::where('mulai_proyek', 'like', $year) - /* ->orWhere('akhir_proyek', 'like', $year) */ + $projects = Project::select('m_proyek.*', 'md.name as divisi_name') + ->where('mulai_proyek', 'like', $year) + ->join('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id') ->orderBy('id', 'desc') ->get(); foreach ($projects as $project) { diff --git a/app/Models/Project.php b/app/Models/Project.php index 1e575d6..2721944 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -15,6 +15,7 @@ class Project extends Model 'kode_sortname', 'jumlah_stakeholder', 'nama', + 'nickname', 'mulai_proyek', 'akhir_proyek', 'area_kerja', From 657095bfddef75b2ce8cada1798cac9f1f589e48 Mon Sep 17 00:00:00 2001 From: ibnu Date: Thu, 21 Dec 2023 17:50:45 +0700 Subject: [PATCH 09/13] add nickname add logic get data --- app/Http/Controllers/ProjectController.php | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 104b128..dd215ce 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -80,18 +80,24 @@ class ProjectController extends Controller if (empty($id) || !is_int((int)$id)) return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); - $result = Project::query() - ->from('m_proyek AS mp') - ->where('mp.id', $id) - ->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'])) { - $result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id') - ->addSelect(DB::raw('m_divisi.name AS nama_divisi')); - } - - $result = $result->first(); - + // $result = Project::query() + // ->from('m_proyek AS mp') + // ->where('mp.id', $id) + // ->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'])) { + // $result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id') + // ->addSelect(DB::raw('m_divisi.name AS nama_divisi')); + // } + $result = Project::select('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','md.name as divisi_name', 'nickname') + ->join('m_divisi as md','md.id', '=', 'm_proyek.divisi_id') + ->where('m_proyek.id', $id) + ->first(); if(!$result) return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); From 59b170c7b9fb82a3744bab9e6ebc27f7f953d5bf Mon Sep 17 00:00:00 2001 From: ibnu Date: Thu, 21 Dec 2023 18:05:03 +0700 Subject: [PATCH 10/13] update user-activity --- app/Http/Controllers/UserToActivityController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index 5a2238d..c8a4f38 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -202,7 +202,7 @@ class UserToActivityController extends Controller ->where('ahta.user_id', $payload['user_id']) ->where('ma.start_date', '<=', $payload['start_date']) ->where('ma.end_date', '>=', $payload['end_date']) - ->where('ma.proyek', '>=', $payload['proyek_id']) + ->where('ma.proyek', $payload['proyek_id']) ->get(); if ($payload['status'] != "") { From d512aad318c5cc199f053cb73b2512866649018a Mon Sep 17 00:00:00 2001 From: ibnu Date: Thu, 21 Dec 2023 18:12:32 +0700 Subject: [PATCH 11/13] update user-activity --- app/Http/Controllers/UserToActivityController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/UserToActivityController.php b/app/Http/Controllers/UserToActivityController.php index c8a4f38..bbd1b40 100644 --- a/app/Http/Controllers/UserToActivityController.php +++ b/app/Http/Controllers/UserToActivityController.php @@ -202,7 +202,7 @@ class UserToActivityController extends Controller ->where('ahta.user_id', $payload['user_id']) ->where('ma.start_date', '<=', $payload['start_date']) ->where('ma.end_date', '>=', $payload['end_date']) - ->where('ma.proyek', $payload['proyek_id']) + ->where('ma.proyek_id', $payload['proyek_id']) ->get(); if ($payload['status'] != "") { From c313683113ced3059af66fd37c335fff1770b93e Mon Sep 17 00:00:00 2001 From: farhantock Date: Wed, 27 Dec 2023 10:18:29 +0700 Subject: [PATCH 12/13] add Hierarchy --- app/Http/Controllers/AuthController.php | 37 +- app/Http/Controllers/Controller.php | 2 +- app/Http/Controllers/ProjectController.php | 600 +++++++++++---------- app/Models/Project.php | 2 + 4 files changed, 351 insertions(+), 290 deletions(-) diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index bb31e8c..37ae48f 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -11,6 +11,7 @@ use App\Models\Role; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Password; use Illuminate\Validation\ValidationException; + class AuthController extends Controller { public function __construct() @@ -25,46 +26,50 @@ class AuthController extends Controller $remember = $request->remember; $is_mobile = $request->is_mobile; - if(empty($username) || empty($password)) - return response()->json(['status'=>'error','message'=>'You must fill all the fields'], 400); + if (empty($username) || empty($password)) + return response()->json(['status' => 'error', 'message' => 'You must fill all the fields'], 400); $usernameCheck = false; $passwordCheck = false; - - if (User::where('username', $username)->exists()) + + if (User::where('username', $username)->exists()) $usernameCheck = true; - if (User::where('password', md5($password))->exists()) + if (User::where('password', md5($password))->exists()) $passwordCheck = true; - if ($usernameCheck & $passwordCheck){ + if ($usernameCheck & $passwordCheck) { $user = User::where('username', $username)->where('password', md5($password))->first(); - if($is_mobile){ + if ($is_mobile) { $fcm_token = $request->fcm_token; - if(!$fcm_token || $fcm_token=="") - return response()->json(['status'=>'error','message'=>'FCM Token is required'], 400); + if (!$fcm_token || $fcm_token == "") + return response()->json(['status' => 'error', 'message' => 'FCM Token is required'], 400); $dataUpdateFcm = array( - "fcm_token"=>$fcm_token + "fcm_token" => $fcm_token ); $hr = User::find($user->id); - if($hr) + if ($hr) $hr->update($dataUpdateFcm); } $dataRole = Role::find($user->role_id); + $dataHierarchy = $this->getDataHierarchy($user->divisi_id, $user->id); - if($dataRole) + if ($dataRole) $user->role = $dataRole; - if (! $token =Auth::login($user)) + if ($dataHierarchy) + $user->hierarchy = $dataHierarchy; + + if (!$token = Auth::login($user)) return response()->json(['error' => 'Unauthorized'], 401); $ttl = 60; - if($remember) + if ($remember) $ttl = 10080; // todo : change existing md5 hashed function to laravel's originally bcrypt @@ -80,13 +85,13 @@ class AuthController extends Controller 'expires_in' => auth()->factory()->getTTL() * $ttl, ), ]); - }else { + } else { if (!$usernameCheck && !$passwordCheck) return response()->json(['code' => 201, 'message' => "username and password doesn't match"], 201); if (!$passwordCheck) return response()->json(['code' => 201, 'message' => "password doesn't match"], 201); if (!$usernameCheck) return response()->json(['code' => 201, 'message' => "username doesn't match"], 201); - } + } } } diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 02049ab..50966ce 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -7,8 +7,8 @@ use Illuminate\Support\Facades\Http; use App\Models\UserToActivity; use App\Models\Activity; use App\Models\AssignMaterial; -use App\Models\User; use App\Models\Divisi; +use App\Models\User; use Laravel\Lumen\Routing\Controller as BaseController; use App\Models\ReportK3Detail; diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index ca92810..ed9603e 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -50,7 +50,7 @@ class ProjectController extends Controller { $this->validate($request, [ 'nama' => 'required', - 'mulai_proyek' => 'required', + 'mulai_proyek' => 'required', 'akhir_proyek' => 'required', 'rencana_biaya' => 'required', 'type_proyek_id' => 'required' @@ -59,81 +59,82 @@ class ProjectController extends Controller $data = $request->all(); $data['created_by'] = $this->currentName; + $data['created_by_id'] = $this->currentId; - if(empty($data['phase_id'])) + if (empty($data['phase_id'])) $data['phase_id'] = 1; $result = Project::create($data); - if(!$result) - return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500); + if (!$result) + return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500); $this->createOfficeHours($result->id); $dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); - return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200); + return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200); } - public function edit($id) - { - if (empty($id) || !is_int((int)$id)) - return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + public function edit($id) + { + if (empty($id) || !is_int((int)$id)) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); - $result = Project::query() - ->from('m_proyek AS mp') - ->where('mp.id', $id) - ->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'); + $result = Project::query() + ->from('m_proyek AS mp') + ->where('mp.id', $id) + ->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'])) { - $result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id') - ->addSelect(DB::raw('m_divisi.name AS nama_divisi')); - } + if (!is_null($result->first()['divisi_id'])) { + $result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id') + ->addSelect(DB::raw('m_divisi.name AS nama_divisi')); + } - $result = $result->first(); + $result = $result->first(); - if(!$result) - return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); + if (!$result) + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); - return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); } public function update(Request $request, $id) { - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + if (empty($id) || !is_int((int)$id)) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); $data = Project::find($id); - if(!$data) - return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); + if (!$data) + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); $result = $data->update($request->all()); - if(!$result) - return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500); + if (!$result) + return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500); - return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200); + return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200); } private function createOfficeHours($proyek_id) { $dataCreate = array( - "proyek_id"=>$proyek_id, - "monday_start"=> "08:00:00", - "monday_end"=> "16:00:00", - "tuesday_start"=> "08:00:00", - "tuesday_end"=> "16:00:00", - "wednesday_start"=> "08:00:00", - "wednesday_end"=> "16:00:00", - "thursday_start"=> "08:00:00", - "thursday_end"=> "16:00:00", - "friday_start"=> "08:00:00", - "friday_end"=> "16:00:00", - "saturday_start"=> "08:00:00", - "saturday_end"=> "16:00:00", - "sunday_start"=> "08:00:00", - "sunday_end"=> "16:00:00", - "created_by"=> $this->currentName + "proyek_id" => $proyek_id, + "monday_start" => "08:00:00", + "monday_end" => "16:00:00", + "tuesday_start" => "08:00:00", + "tuesday_end" => "16:00:00", + "wednesday_start" => "08:00:00", + "wednesday_end" => "16:00:00", + "thursday_start" => "08:00:00", + "thursday_end" => "16:00:00", + "friday_start" => "08:00:00", + "friday_end" => "16:00:00", + "saturday_start" => "08:00:00", + "saturday_end" => "16:00:00", + "sunday_start" => "08:00:00", + "sunday_end" => "16:00:00", + "created_by" => $this->currentName ); OfficeHours::create($dataCreate); @@ -145,15 +146,15 @@ class ProjectController extends Controller { $data = Project::find($id); - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + if (!$data) + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); $this->deleteRelative($id); - if(!$data->delete()) - return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500); + if (!$data->delete()) + return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500); - return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); + return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200); } private function deleteRelative($project_id) @@ -168,12 +169,12 @@ class ProjectController extends Controller ProjectChecklists::where('proyek_id', $project_id)->delete(); ProjectIssues::where('proyek_id', $project_id)->delete(); ProjectRisks::where('proyek_id', $project_id)->delete(); - ProjectToChecklistK3::where('proyek_id', $project_id)->delete(); - HierarchyFtth::where('project_id', $project_id)->delete(); - AssignTools::where('proyek_id', $project_id)->delete(); - OfficeHours::where('proyek_id', $project_id)->delete(); - ReportK3::where('proyek_id', $project_id)->delete(); - RequestMaterial::where('proyek_id', $project_id)->delete(); + ProjectToChecklistK3::where('proyek_id', $project_id)->delete(); + HierarchyFtth::where('project_id', $project_id)->delete(); + AssignTools::where('proyek_id', $project_id)->delete(); + OfficeHours::where('proyek_id', $project_id)->delete(); + ReportK3::where('proyek_id', $project_id)->delete(); + RequestMaterial::where('proyek_id', $project_id)->delete(); $this->deleteVersionGantt($project_id); $this->deleteDokumenProject($project_id); } @@ -188,16 +189,16 @@ class ProjectController extends Controller foreach ($dataRa as $ra) { $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); foreach ($images as $image) { - if(file_exists($this->pathImage.$image->image)){ - unlink($this->pathImage.$image->image); + if (file_exists($this->pathImage . $image->image)) { + unlink($this->pathImage . $image->image); } } Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); } $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); foreach ($dataAd as $ad) { - if(file_exists($this->pathActivityDocument.$ad->file)){ - unlink($this->pathActivityDocument.$ad->file); + if (file_exists($this->pathActivityDocument . $ad->file)) { + unlink($this->pathActivityDocument . $ad->file); } } ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); @@ -215,8 +216,8 @@ class ProjectController extends Controller $dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); foreach ($dataDokumen as $dokumen) { - if(file_exists($this->pathDocument.$dokumen->file)){ - unlink($this->pathDocument.$dokumen->file); + if (file_exists($this->pathDocument . $dokumen->file)) { + unlink($this->pathDocument . $dokumen->file); } } DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); @@ -225,8 +226,8 @@ class ProjectController extends Controller $ref_ids = $dataFolder->all(); $dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); foreach ($dataDokumen as $dokumen) { - if(file_exists($this->pathDocument.$dokumen->file)){ - unlink($this->pathDocument.$dokumen->file); + if (file_exists($this->pathDocument . $dokumen->file)) { + unlink($this->pathDocument . $dokumen->file); } } @@ -240,11 +241,11 @@ class ProjectController extends Controller $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); $builder = $dataBuilder['builder']; $countBuilder = $dataBuilder['count']; - // $builder->where("selfTable.created_by",$this->currentName); + // $builder->where("selfTable.created_by",$this->currentName); $dataGet = $builder->get(); $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); } public function list() @@ -286,101 +287,116 @@ class ProjectController extends Controller 'created_by', 'updated_at', 'updated_by' - )->orderBy('id', 'desc') - // ->where("created_by",$this->currentName) - ->get(); + )->orderBy('id', 'desc') + // ->where("created_by",$this->currentName) + ->get(); $countData = $data->count(); - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + if (!$data) + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); - $totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost'))); - $totalActualCost = $data->sum('actualCost'); + $totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost'))); + $totalActualCost = $data->sum('actualCost'); $manpowers = User::count(); $projectsOnDanger = Project::where('budget_health', 'overrun')->count(); - $projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); - $projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name'); - try { - $projectsByPhase = DB::table('m_proyek') - ->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total')) - ->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id') - ->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') - ->get(); - } catch (\Exception $e) { - return response()->json(['message' => $e->getMessage()]); - } - try { - $projectsByType = DB::table('m_proyek') - ->select('m_type_proyek.name', DB::raw('count(m_type_proyek.id) as total')) - ->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') - ->groupBy('m_type_proyek.name') - ->get(); - } catch (\Exception $e) { - return response()->json(['message' => $e->getMessage()]); - } + $projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); + $projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name'); + try { + $projectsByPhase = DB::table('m_proyek') + ->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total')) + ->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id') + ->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') + ->get(); + } catch (\Exception $e) { + return response()->json(['message' => $e->getMessage()]); + } + try { + $projectsByType = DB::table('m_proyek') + ->select('m_type_proyek.name', DB::raw('count(m_type_proyek.id) as total')) + ->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') + ->groupBy('m_type_proyek.name') + ->get(); + } catch (\Exception $e) { + return response()->json(['message' => $e->getMessage()]); + } return response()->json( - [ - 'status'=>'success', - 'code'=>200, - 'data'=>$data, - 'totalRecord'=>$countData, - 'totalPlannedCost' => $totalPlannedCost, - 'totalActualCost' => $totalActualCost, - 'totalRevenue' => $totalPlannedCost - $totalActualCost, - 'manpowers' => $manpowers, - 'projectsOnDanger'=> $projectsOnDanger, - 'projectPhases' => $projectPhases, - 'projectsByPhase' => $projectsByPhase, - 'projectTypes' => $projectTypes, - 'projectsByType' => $projectsByType, - ], 200); + [ + 'status' => 'success', + 'code' => 200, + 'data' => $data, + 'totalRecord' => $countData, + 'totalPlannedCost' => $totalPlannedCost, + 'totalActualCost' => $totalActualCost, + 'totalRevenue' => $totalPlannedCost - $totalActualCost, + 'manpowers' => $manpowers, + 'projectsOnDanger' => $projectsOnDanger, + 'projectPhases' => $projectPhases, + 'projectsByPhase' => $projectsByPhase, + 'projectTypes' => $projectTypes, + 'projectsByType' => $projectsByType, + ], + 200 + ); } - public function getListProjectTask($id){ - $data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*") + public function getListProjectTask($id) + { + $data = UserToActivity::select("assign_hr_to_activity.user_id as user_id", "m_proyek.*") ->where("assign_hr_to_activity.user_id", $id) ->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id') ->groupBy("m_proyek.proyek_id") ->get(); - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + if (!$data) + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); - return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); } - public function getSCurve(Request $request){ + public function getSCurve(Request $request) + { $data = MasterFunctionsHelper::getSCurve($request); - return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); - } + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); + } - public function calculateSCurve(Request $request){ - $sCurve = Project::select('scurve')->where('id', $request->project_id)->first(); - return response()->json(['status'=>'success','code'=>200, 'data' => json_decode($sCurve->scurve)], 200); - } + // testing + public function calculateSCurvetest(Request $request) + { + $data = MasterFunctionsHelper::calculateSCurve($request->project_id); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); + } - public function sCurveCommand(Request $request){ - Artisan::call('calculate:scurve', [ - 'project_id' => $request->project_id - ]); - // $project = Project::find($request->project_id); + public function calculateSCurve(Request $request) + { + $sCurve = Project::select('scurve')->where('id', $request->project_id)->first(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => json_decode($sCurve->scurve)], 200); + } - // if ($project) { - // dispatch(new ProcessSCurve($project)); + public function sCurveCommand(Request $request) + { + Artisan::call('calculate:scurve', [ + 'project_id' => $request->project_id + ]); + // $project = Project::find($request->project_id); + + // if ($project) { + // dispatch(new ProcessSCurve($project)); - // return response()->json(['message' => 'S Curve calculation queued']); - // } + // return response()->json(['message' => 'S Curve calculation queued']); + // } - // return response()->json(['message' => 'Project not found'], 404); - } + // return response()->json(['message' => 'Project not found'], 404); + } - public function getLinearSCurve(Request $request){ + public function getLinearSCurve(Request $request) + { $data = MasterFunctionsHelper::getLinearSCurve($request); - return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); } - public static function setSyncDate($activity_id, $activity, $report) { + public static function setSyncDate($activity_id, $activity, $report) + { $status = AssignMaterial::where('activity_id', $activity_id)->first(); if (!isset($status)) { $reports = array( @@ -412,17 +428,17 @@ class ProjectController extends Controller return $reports; } - public function synchronizeReport($gantt_id) + public function synchronizeReport($gantt_id) { $activities = Activity::where("version_gantt_id", $gantt_id)->get(); $reports = []; - foreach($activities as $activity) { + foreach ($activities as $activity) { $activity_id = $activity->id; $countReports = ReportActivityMaterial::where('activity_id', $activity_id)->count(); if ($countReports === 1) { $dataReports = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->get(); - foreach($dataReports as $dr) { + foreach ($dataReports as $dr) { $reports[] = ProjectController::setSyncDate($activity_id, $activity, $dr); } } @@ -443,15 +459,15 @@ class ProjectController extends Controller /* return response()->json(['status'=>'success','data'=> $reports,'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']); - if($reports[$i]['status'] != 'done'){ + if ($reports[$i]['status'] != 'done') { $reports[$i]['max_date']->modify('-1 day'); - }else if($reports[$i]['status'] == 'done'){ - $activity->actual_end = $reports[$i]['max_date']->setTime(23,59,59); + } else if ($reports[$i]['status'] == 'done') { + $activity->actual_end = $reports[$i]['max_date']->setTime(23, 59, 59); } $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); @@ -460,7 +476,7 @@ class ProjectController extends Controller $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); } public function setBaseline($gantt_id) @@ -469,127 +485,139 @@ class ProjectController extends Controller foreach ($activities as $activity) { $activity->update([ - "planned_start"=>$activity->start_date, - "planned_end"=>$activity->end_date, - "early_start"=>$activity->start_date, - "early_end"=>$activity->end_date, + "planned_start" => $activity->start_date, + "planned_end" => $activity->end_date, + "early_start" => $activity->start_date, + "early_end" => $activity->end_date, ]); } - return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200); + return response()->json(['status' => 'success', 'message' => 'Set baseline success!', 'code' => 200], 200); } - public function getInvoiceIntegration(Request $request) { - $ganttCount = VersionGantt::where('proyek_id', $request->id)->count(); + public function getInvoiceIntegration(Request $request) + { + $ganttCount = VersionGantt::where('proyek_id', $request->id)->count(); $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'); + 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); - if (isset($request->gantt_id)) { - $response->data->total_cost = $response->data->total_cost / $ganttCount; - } + if (isset($request->gantt_id)) { + $response->data->total_cost = $response->data->total_cost / $ganttCount; + } + + return response()->json(['status' => 'success', 'data' => $response, 'code' => 200], 200); + } + public function getByUser($id) + { + $alias = "utp"; + $userProyek = UserToProyek::query() + ->from('assign_hr_to_proyek AS ' . $alias) + ->where([ + ['is_customer', true], + ['user_id', $id] + ]) + ->leftJoin('m_users', $alias . '.user_id', '=', 'm_users.id') + ->leftJoin('m_proyek', $alias . '.proyek_id', '=', 'm_proyek.id') + ->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id') + ->select('m_proyek.*', 'm_type_proyek.name AS join_second_name', 'm_users.name AS join_first_name') + ->get(); + $totalRecord = $userProyek->count(); - return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200); } - public function getByUser($id) - { - $alias = "utp"; - $userProyek = UserToProyek::query() - ->from('assign_hr_to_proyek AS ' . $alias) - ->where([ - ['is_customer', true], - ['user_id', $id] - ]) - ->leftJoin('m_users', $alias.'.user_id', '=', 'm_users.id') - ->leftJoin('m_proyek', $alias.'.proyek_id', '=', 'm_proyek.id') - ->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id') - ->select('m_proyek.*', 'm_type_proyek.name AS join_second_name','m_users.name AS join_first_name') - ->get(); - $totalRecord = $userProyek->count(); - - return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200); - } - public function detail(Request $request, $id, $gantt_id = null, $s_curve = null){ - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + public function detail(Request $request, $id, $gantt_id = null, $s_curve = null) + { + if (empty($id) || !is_int((int)$id)) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); $result = Project::find($id); - if(!$result) - return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); - if (!isset($gantt_id)) { - $gantt = MasterFunctionsHelper::getLatestGantt($id); - $ganttId = $gantt['last_gantt_id']; - } else { - $ganttId = $gantt_id; - } + if (!$result) + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); + if (!isset($gantt_id)) { + $gantt = MasterFunctionsHelper::getLatestGantt($id); + $ganttId = $gantt['last_gantt_id']; + } else { + $ganttId = $gantt_id; + } $result->projectManager = User::where('id', $result->pm_id)->value('name'); - if (isset($s_curve)) { - $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first(); - $actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists(); - if($result['type_proyek_id'] === 9) - { - $actualEndExist = Activity::where('proyek_id', $id)->exists(); - $query = Activity::where('proyek_id', $id); - }else{ - $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); - $query = Activity::where('version_gantt_id', $ganttId); - } - } else { - $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first(); - $actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); - $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); - $query = Activity::where('version_gantt_id', $ganttId); - } - - if ($actualStartExist) { - $startDate = $query->orderBy('actual_start')->value('start_date'); - } else { - $startDate = $query->orderBy('start_date')->value('start_date'); - } - if($actualEndExist) - { - $maxEndDate = $query->max('id'); - $endDate = $query->where('id',$maxEndDate)->first()->end_date; - } - - $plannedStart = Activity::where('version_gantt_id', $ganttId) - ->orderBy('planned_start') - ->value('planned_start'); - $plannedEnd = Activity::where('version_gantt_id', $ganttId) - ->orderByDesc('planned_end') - ->value('planned_end'); - $result->header->start_date = $startDate; - $result->header->end_date = $endDate; - $result->header->planned_start = $plannedStart; - $result->header->planned_end = $plannedEnd; - return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$ganttId], 200); + if (isset($s_curve)) { + $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first(); + $actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists(); + if ($result['type_proyek_id'] === 9) { + // $actualEndExist = Activity::where('proyek_id', $id)->exists(); + $query = Activity::where('proyek_id', $id); + $maxEndDate = Activity::where('proyek_id', $id)->select('end_date') + ->orderBy('end_date', 'desc') + ->first(); + } else { + // $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); + $maxEndDate = Activity::where('version_gantt_id', $ganttId)->select('end_date') + ->orderBy('end_date', 'desc') + ->first(); + $query = Activity::where('version_gantt_id', $ganttId); + } + } else { + $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first(); + $actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); + // $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); + $maxEndDate = Activity::where('version_gantt_id', $ganttId)->select('end_date') + ->orderBy('end_date', 'desc') + ->first(); + $query = Activity::where('version_gantt_id', $ganttId); + } + + if ($actualStartExist) { + $startDate = $query->orderBy('actual_start')->value('start_date'); + } else { + $startDate = $query->orderBy('start_date')->value('start_date'); + } + // if($actualEndExist) + // { + // // $maxEndDate = $query->max('id'); + // // get last end_date + // // $endDate = $query->where('id',$maxEndDate)->first()->end_date; + + // } + + $plannedStart = Activity::where('version_gantt_id', $ganttId) + ->orderBy('planned_start') + ->value('planned_start'); + $plannedEnd = Activity::where('version_gantt_id', $ganttId) + ->orderByDesc('planned_end') + ->value('planned_end'); + $result->header->start_date = $startDate; + $result->header->end_date = $maxEndDate->end_date; + $result->header->planned_start = $plannedStart; + $result->header->planned_end = $plannedEnd; + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result, 'gantt' => $ganttId], 200); } - public function getOverdueActivities(Request $request){ + public function getOverdueActivities(Request $request) + { $payload = $request->all(); - if(empty($payload['id']) || !is_int((int)$payload['id'])) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + if (empty($payload['id']) || !is_int((int)$payload['id'])) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); $result = Project::find($payload['id']); - if(!$result) - return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404); + if (!$result) + return response()->json(['status' => 'failed', 'message' => 'Project not found!', 'code' => 404], 404); //TODO possible overdue bug $endDate = Activity::where('proyek_id', $payload['id']) ->orderByDesc('end_date') ->value('end_date'); - if(isset($payload['till_date'])) { + if (isset($payload['till_date'])) { if (isset($payload['scurve'])) { - $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get(); + $overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('m_activity.proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get(); } else { - $overdueActivities = Activity::where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get(); + $overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get(); } - } - else { + } else { if (isset($payload['scurve'])) { $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); } else { @@ -598,53 +626,75 @@ class ProjectController extends Controller } $result->overdueActivities = $overdueActivities; - return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); } - public function getReportDistribution(Request $request){ + public function getReportDistribution(Request $request) + { $payload = $request->all(); - if(empty($payload['project_id']) || !is_int((int)$payload['project_id'])) - return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); + if (empty($payload['project_id']) || !is_int((int)$payload['project_id'])) + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); $reports = DB::table('assign_material_to_activity as ama') - ->select('u.name', 'a.name as activity_name', 'ama.qty_planning', 'ram.qty as qty_real','rm.description as material_name', 'rm.uom as material_unit', - 'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date') + ->select( + 'u.name', + 'a.name as activity_name', + 'ama.qty_planning', + 'ram.qty as qty_real', + 'rm.description as material_name', + 'rm.uom as material_unit', + 'ram.lat', + 'ram.lon', + 'ram.description as report_notes', + 'ram.report_date' + ) ->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id') ->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id') ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') ->join('m_users as u', 'u.id', '=', 'ram.user_id') ->where('ama.proyek_id', '=', $payload['project_id']) ->whereNotNull('ram.lat') - ->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]); + ->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]); - return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $reports], 200); } - public function getManpower($proyek_id){ + public function getManpower($proyek_id) + { $manCount = UserToProyek::where('proyek_id', $proyek_id)->count(); - return response()->json(['totalRecord'=>$manCount]); + return response()->json(['totalRecord' => $manCount]); } - public function getAssignedHR($gantt_id){ + public function getAssignedHR($gantt_id) + { $results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date') ->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id') ->where('assign_hr_to_activity.version_gantt_id', $gantt_id) ->get(); - return response()->json(['data'=>$results]); + return response()->json(['data' => $results]); } public function dashboard($id) { $data = DB::table('m_proyek as mp') - ->select('mp.kode_sortname', 'mp.nama as name_project', 'mp.mulai_proyek as start', 'mp.akhir_proyek as finish', - 'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm', 'mp.budget_health') - ->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') - ->where('mp.id', $id) - ->first(); - - if(!$data) - return response()->json(['status'=>'failed','message'=>'Data tidak ditemukan!','code'=> 404], 404); + ->select( + 'mp.kode_sortname', + 'mp.nama as name_project', + 'mp.mulai_proyek as start', + 'mp.akhir_proyek as finish', + 'mp.rencana_biaya', + 'mp.company', + 'mp.currency_symbol', + 'mu.name as pm', + 'mp.budget_health' + ) + ->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') + ->where('mp.id', $id) + ->first(); + + if (!$data) + return response()->json(['status' => 'failed', 'message' => 'Data tidak ditemukan!', 'code' => 404], 404); $manpowers = UserToProyek::where('proyek_id', $id)->count(); $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first(); @@ -653,38 +703,42 @@ class ProjectController extends Controller $progress = @$rootActivity->persentase_progress ?? 0; $commentActivity = DB::table('m_comment_activity as mca') - ->select('mca.activity_id', 'mca.comment as comment', 'mca.created_by as comment_by', 'mca.created_at as comment_created', - 'ma.name as activity') - ->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id') - ->where('ma.proyek_id', $id) - ->orderBy('comment_by') - ->take(2) - ->get(); + ->select( + 'mca.activity_id', + 'mca.comment as comment', + 'mca.created_by as comment_by', + 'mca.created_at as comment_created', + 'ma.name as activity' + ) + ->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id') + ->where('ma.proyek_id', $id) + ->orderBy('comment_by') + ->take(2) + ->get(); $data->actual_cost = $actualCost; $data->progress = $progress; $data->comment = $commentActivity; $data->man_power = $manpowers; - return response()->json(['status'=>'success','code'=>200,'data'=> $data], 200); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); } - private function httpReq($search){ - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION)); + private function httpReq($search) + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION)); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w')); $info = curl_getinfo($ch); - $output = curl_exec($ch); - curl_close($ch); + $output = curl_exec($ch); + curl_close($ch); - return json_decode($output); + return json_decode($output); } - } - diff --git a/app/Models/Project.php b/app/Models/Project.php index 115c9b6..5ac9382 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -23,8 +23,10 @@ class Project extends Model 'biaya_actual', 'company', 'pm_id', + 'scoupe_of_work', 'type_proyek_id', 'divisi_id', + 'value_proyek', 'persentase_progress', 'keterangan', 'durasi_proyek', From 11cda6e40cf4efcf04fa33bc157757006634ce8f Mon Sep 17 00:00:00 2001 From: farhantock Date: Wed, 27 Dec 2023 10:18:45 +0700 Subject: [PATCH 13/13] update early warning to 20% --- .../Controllers/DashboardBoDController.php | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index deb8065..65f6a39 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -41,14 +41,14 @@ class DashboardBoDController extends Controller private function getInvoiceIntegration($search) { - if(empty($search)) - return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); + 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'); + $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 == "") + if (@$response->data->project_no == "") return null; return $response; @@ -83,7 +83,6 @@ class DashboardBoDController extends Controller $totalInvoice += $resp->data->total_invoice_amount ?? 0; $totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0; } - } return response()->json([ @@ -147,15 +146,13 @@ class DashboardBoDController extends Controller } $selisihProgress = $planningProgress - $actualProgress; try { - if ($selisihProgress > 0 && $selisihProgress <= 5){ + if ($selisihProgress > 0 && $selisihProgress <= 20) { $return['warning'] += 1; $projects[$index]->status = 'warning'; - } - elseif ($selisihProgress == 0){ + } elseif ($selisihProgress == 0) { $return['on-schedule'] += 1; $projects[$index]->status = 'on-schedule'; - } - else { + } else { $return['behind-schedule'] += 1; $projects[$index]->status = 'behind-schedule'; } @@ -191,13 +188,11 @@ class DashboardBoDController extends Controller $actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0; } $selisihProgress = $planningProgress - $actualProgress; - if ($selisihProgress > 0 && $selisihProgress <= 5){ + if ($selisihProgress > 0 && $selisihProgress <= 5) { $warning++; - } - elseif ($selisihProgress == 0){ + } elseif ($selisihProgress == 0) { $onSchedule++; - } - else { + } else { $behindSchedule++; } } @@ -294,7 +289,7 @@ class DashboardBoDController extends Controller { $year = $this->interpolateYear($year); - $divisions = Divisi::select('id', 'name','parent','color') + $divisions = Divisi::select('id', 'name', 'parent', 'color') ->with('children') ->whereNull('parent') ->get();