From a72135a55ba6396dd5d8e6f9ed1ac8657c7de60f Mon Sep 17 00:00:00 2001 From: farhan048 Date: Thu, 19 Oct 2023 12:59:08 +0700 Subject: [PATCH 1/8] 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 2/8] 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 3/8] 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 4/8] 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 5/8] 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 6/8] 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 bf4132753865436db6ad7516409c294ba5a81424 Mon Sep 17 00:00:00 2001 From: ibnu Date: Mon, 13 Nov 2023 21:59:55 +0700 Subject: [PATCH 7/8] update summary and s curve --- app/Helpers/MasterFunctionsHelper.php | 322 +++++++++++++++++++++++++- 1 file changed, 320 insertions(+), 2 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 53f0be8..eedd5e6 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -309,9 +309,11 @@ class MasterFunctionsHelper ->where('activity_id', '=', $keyPlanM->id) ->groupBy('activity_id') ->first(); - $weekCount = $keyPlanM->duration / 7; + $weekCount = $keyPlanM->duration / $keyPlanM->duration; $weeklyPlan = $weekCount > 0 ? $sumVolPlan->ttl_qty_plan / $weekCount : 0; $weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; + // $weeklyPlan = $weekCount > 0 ? $keyPlanM->bobot_planning / $weekCount : 0; + // $weeklyProgress = $weeklyPlan * $keyPlanM->bobot_planning; $dataTempPlan[$x]['activity_id'] = $keyPlanM->id; $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; $dataTempPlan[$x]['ttl_plan'] = $sumVolPlan; @@ -486,7 +488,7 @@ class MasterFunctionsHelper return $dataFinal; } - public function calculateSCurve($projectId) + public function calculateSCurveVWahyu($projectId) { DB::enableQueryLog(); @@ -798,6 +800,322 @@ class MasterFunctionsHelper return $dataFinal; } + public function calculateSCurve($projectId) + { + DB::enableQueryLog(); + + $dataFinal = []; + $dataPayload = []; + $dataPayload['period'] = 'week'; + $totalACWP = 0; + $totalBCWP = 0; + $tempPercentage = []; + + $dataProject = Project::find($projectId); + $dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $projectId)->first(); + if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) { + $dataPayload['end_date'] = $dataProject->akhir_proyek; + } + + if ($dataHeader) { + $totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $projectId)->sum("rencana_biaya"); + } else { + $totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $projectId)->sum("rencana_biaya"); + } + + // $alreadyHasReport = DB::table('report_activity_material as a') + // ->select('a.id') + // ->join('m_activity as b', 'b.id', '=', 'a.activity_id') + // ->exists(); + + $minDate = $dataProject->mulai_proyek; + + $begin = new \DateTime($minDate . ' Monday'); + $begin->modify('last Monday'); + if (isset($dataPayload['end_date'])) { + $maxDate = $dataPayload['end_date']; + $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 = new \DateInterval('P7D'); + } else { + // $maxDate = DB::table('assign_material_to_activity as ama') + // ->where("ama.proyek_id", $projectId) + // ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') + // ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's + $maxDate = $dataProject->akhir_proyek; + $end = new \DateTime($maxDate); + $end->modify('next Friday'); + $end->modify('next Friday'); + $interval = new \DateInterval('P7D'); + } + $period = new \DatePeriod($begin, $interval, $end); + + $arr_ActualM = []; + $tempDate = []; + $tempPercentagePlan = []; + $tempPercentagePlanWhr = []; + $tempPercentageReal = []; + $tempTtlPercentPlan = 0; + $tempTtlPercentActual = 0; + + $currentACWP = 0; + $currentBCWP = 0; + + foreach ($period as $dt) { + $minSevenDays = new \Datetime($dt->format("Y-m-d")); + $minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d"); + // $dataPlanM = DB::table('assign_material_to_activity as ama') + // ->select('ama.activity_id', 'ama.qty_planning', 'ama.plan_date', 'ama.start_activity', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress') + // ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') + // ->where('ama.proyek_id', '=', $keyGantt['proyek_id']) + // ->where('a.version_gantt_id', '=', $keyGantt['id']) + // ->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d")) + // ->whereDate('ama.plan_date', '>', $minSevenDays) + // ->get(); + + $activities = DB::table('m_activity AS a') + ->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.proyek_id', '=', $projectId) + ->whereDate('amta.plan_date', '<=', $dt->format("Y-m-d")) + ->whereDate('amta.plan_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id'); + + $dataPlanM = DB::table('m_activity AS a') + ->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id') + ->where('a.type_activity', 'task') + ->where('a.bobot_planning', '>', 0) + ->where('a.proyek_id', '=', $projectId) + ->whereDate('a.start_date', '<=', $dt->format("Y-m-d")) + ->whereDate('a.start_date', '>', $minSevenDays) + ->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id') + ->union($activities) + ->get(); + + $dataActualM = DB::table('report_activity_material as ram') + ->select('ram.activity_id', 'ram.qty', 'ram.report_date', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress') + ->join('m_activity as a', 'a.id', '=', 'ram.activity_id') + ->where('a.proyek_id', '=', $projectId) + ->whereDate('ram.report_date', '<=', $dt->format("Y-m-d")) + ->whereDate('ram.report_date', '>', $minSevenDays) + ->get(); + $dataTempPlan = []; + $x = 0; + $sumPercentagePlan = 0; + $totalACWP = isset($totalACWP) ? $totalACWP : 0; + $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; + + foreach ($dataPlanM as $keyPlanM) { + // $sumVolPlan = DB::table(function ($query) use ($projectId) { + // $query->select('a.*') + // ->from('m_activity AS a') + // ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id') + // ->where('a.type_activity', 'task') + // ->where('a.bobot_planning', '>', 0) + // ->where('a.proyek_id', $projectId) + // ->unionAll(function ($query) use ($projectId) { + // $query->select('a.*') + // ->from('m_activity AS a') + // ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id') + // ->where('a.type_activity', 'task') + // ->where('a.bobot_planning', '>', 0) + // ->where('a.proyek_id', $projectId); + // })->orderBy('id', 'asc'); + // }, 'subquery') + // ->sum('bobot_planning'); + $sumVolPlan = DB::table('assign_material_to_activity') + ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) + ->where('activity_id', '=', $keyPlanM->id) + ->groupBy('activity_id') + ->first(); + + $weekCount = $keyPlanM->duration / $keyPlanM->duration; // jadiin perhari (1) + $weeklyPlan = $sumVolPlan->ttl_qty_plan / $weekCount; + $weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; + + // $weeklyPlan = $sumVolPlan->ttl_qty_plan / $weekCount; + // $weeklyProgress = 80; + $dataTempPlan[$x]['activity_id'] = $keyPlanM->id; + $dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning; + $dataTempPlan[$x]['ttl_plan'] = $sumVolPlan; + $dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual; + $dataTempPlan[$x]['duration'] = $keyPlanM->duration; + $dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress; + try { + $dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning; + $sumPercentagePlan += $weeklyProgress; + if (isset($keyPlanM->duration) && $keyPlanM->duration > 0) + $totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100; + else + $totalBCWP = 0; + $dataTempPlan[$x]['totalBCWP'] = $totalBCWP; + } catch (\DivisionByZeroError $e) { + return response()->json(['message' => $e->getMessage()]); + } + $x++; + } + + $w = 0; + $dataTempReport = []; + $sumPercentageActual = 0; + foreach ($dataActualM as $keyActualM) { + $sumVolActual = DB::table('assign_material_to_activity') + ->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan')) + ->where('activity_id', '=', $keyActualM->activity_id) + ->groupBy('activity_id') + ->first(); + if (!isset($sumVolActual)) { + $sumVolActual = (object) [ + 'activity_id' => $keyActualM->activity_id, + 'ttl_qty_plan' => "0" + ]; + } + $sumReportActual = DB::table('report_activity_material') + ->where('activity_id', $keyActualM->activity_id) + ->sum('qty'); + $reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count(); + $dataTempReport[$w]['activity_id'] = $keyActualM->activity_id; + $dataTempReport[$w]['qty'] = $keyActualM->qty; + $dataTempReport[$w]['report_date'] = $keyActualM->report_date; + $dataTempReport[$w]['bobot_planning'] = $keyActualM->bobot_planning; + $dataTempReport[$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan; + $dataTempReport[$w]['biaya_actual'] = $keyActualM->biaya_actual; + $dataTempReport[$w]['duration'] = $keyActualM->duration; + $dataTempReport[$w]['persentase_progress'] = $keyActualM->persentase_progress; + try { + // assign_material_to_activity + $checkStatusActivity = DB::table('assign_material_to_activity') + ->select('activity_id', 'status_activity') + ->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; + } + $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){ + if ($checkStatusActivity->status_activity == 'done') { + $sumPercentageActual += $keyActualM->bobot_planning / $reportCount; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } else { + 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 { + $sumPercentageActual += $actual * $keyActualM->bobot_planning; + // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; + } + } + // }else { + // if($checkStatusActivity->status_activity == 'done'){ + // $sumPercentageActual+=($keyActualM->qty/$keyActualM->qty)*$keyActualM->bobot_planning; + // }else{ + // $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; + // } + // } + + + $totalACWP += $keyActualM->duration > 0 ? $keyActualM->biaya_actual / $keyActualM->duration : 0; + } catch (\DivisionByZeroError $e) { + return response()->json(['message' => $e->getMessage()]); + } + $dataTempReport[$w]['totalacwp'] = $totalACWP; + $w++; + } + + $arr_ActualM[] = array( + 'date' => $dt->format("Y-m-d"), + 'percentPlan' => $sumPercentagePlan, + 'percentActual' => $sumPercentageActual, + 'plan' => $dataTempPlan, + 'actual' => $dataTempReport, + ); + if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') { + $tempTtlPercentPlan += $sumPercentagePlan; + $tempTtlPercentActual += $sumPercentageActual; + // todo + // if ($tempTtlPercentPlan >= 100) + // $tempTtlPercentPlan = 100; + + $currentACWP += $totalACWP; + $currentBCWP += $totalBCWP; + + $tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2)); + $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); + $tempPercentageReal[] = round($sumPercentageActual, 2); + } + $tempDate[] = array($dt->format("Y-m-d")); + } + + try { + if (round($totalACWP, 0) > $totalRencanaBudget) { + $estimatedCost = round($totalACWP, 0) + 0; + } else { + $estimatedCost = ($totalRencanaBudget + 0); + } + } catch (\DivisionByZeroError $e) { + return response()->json([ + 'message' => $e->getMessage(), + "line" => 566, + ]); + } + $estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget; + + $costDeviation = $totalRencanaBudget - $estimatedCost; + if ($costDeviation > 0) { + $potential = "SAVING"; + } else { + $potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"; + } + + $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; + $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; + $dataResponse = array( + "date" => $tempDate, + "percentage" => $tempPercentage, + "percentagePlan" => $tempPercentagePlan, + "percentageReal" => $tempPercentageReal, + "data_details" => $arr_ActualM, + "budget_control" => array( + "current_budget" => $totalRencanaBudget, + "acwp" => round($totalACWP, 0), + "bcwp" => round($totalBCWP, 0), + "rem_to_complete" => ($totalRencanaBudget - round($totalACWP, 0)), + "add_cost_to_complete" => 0, + "estimated_at_completion" => $estimatedCost, + "cost_deviation" => $costDeviation, + "potential" => $potential, + ) + ); + + $dataFinal[] = array( + "proyek_name" => $dataProject->nama, + "data" => $dataResponse, + ); + + return $dataFinal; + } + public function calculateProgressBasedOnSimple($keyGantt) { DB::enableQueryLog(); From 3afb8b1c4f2c23bc74acf1b3f6bb6cc68a3191ab Mon Sep 17 00:00:00 2001 From: ibnu Date: Wed, 15 Nov 2023 11:13:35 +0700 Subject: [PATCH 8/8] update curva --- app/Helpers/MasterFunctionsHelper.php | 30 ++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index eedd5e6..78f3326 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -932,7 +932,7 @@ class MasterFunctionsHelper ->groupBy('activity_id') ->first(); - $weekCount = $keyPlanM->duration / $keyPlanM->duration; // jadiin perhari (1) + $weekCount = 1; // jadiin perhari (1) $weeklyPlan = $sumVolPlan->ttl_qty_plan / $weekCount; $weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; @@ -1056,9 +1056,9 @@ class MasterFunctionsHelper $tempPercentagePlan[] = round($tempTtlPercentPlan, 2); $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; $tempPercentageReal[] = round($tempTtlPercentActual, 2); - if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) { - break; - } + // if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) { + // break; + // } } else { $tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2)); $tempPercentagePlan[] = round($sumPercentagePlan, 2); @@ -1092,20 +1092,22 @@ class MasterFunctionsHelper $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; $dataResponse = array( "date" => $tempDate, + "start" => $begin, + "end" => $end, "percentage" => $tempPercentage, "percentagePlan" => $tempPercentagePlan, "percentageReal" => $tempPercentageReal, "data_details" => $arr_ActualM, - "budget_control" => array( - "current_budget" => $totalRencanaBudget, - "acwp" => round($totalACWP, 0), - "bcwp" => round($totalBCWP, 0), - "rem_to_complete" => ($totalRencanaBudget - round($totalACWP, 0)), - "add_cost_to_complete" => 0, - "estimated_at_completion" => $estimatedCost, - "cost_deviation" => $costDeviation, - "potential" => $potential, - ) + // "budget_control" => array( + // "current_budget" => $totalRencanaBudget, + // "acwp" => round($totalACWP, 0), + // "bcwp" => round($totalBCWP, 0), + // "rem_to_complete" => ($totalRencanaBudget - round($totalACWP, 0)), + // "add_cost_to_complete" => 0, + // "estimated_at_completion" => $estimatedCost, + // "cost_deviation" => $costDeviation, + // "potential" => $potential, + // ) ); $dataFinal[] = array(