Browse Source

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

Reviewed-on: ibnu/generic-ospro-backend#9
pull/1/head
farhantock 1 year ago
parent
commit
6a96d30ad6
  1. 18
      app/Http/Controllers/CompanyController.php
  2. 45
      app/Http/Controllers/MenuCompanyController.php
  3. 91
      app/Http/Controllers/ProjectController.php
  4. 3
      app/Models/Company.php

18
app/Http/Controllers/CompanyController.php

@ -3,6 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Company; use App\Models\Company;
use App\Models\MenuCompany;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class CompanyController extends Controller class CompanyController extends Controller
@ -10,18 +11,22 @@ class CompanyController extends Controller
public function add(Request $request) public function add(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'name' => 'required', 'company_name' => 'required',
'description' => 'required' 'registration_no' => 'required',
'template_id' => 'required',
'is_active' => 'required'
]); ]);
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
if(isset($data['base_url']) && $data['base_url'] != NULL) {
$data['base_url'] = json_encode($data['base_url'], true);
}
$result = Company::create($data); $result = Company::create($data);
if ($result) { if ($result) {
return response()->json(['status' => 'success', 'message' => 'add Company successfully!', 'code' => 200], 200); return response()->json(['status' => 'success','data' => $result, 'message' => 'add Company successfully!', 'code' => 200], 200);
} else { } else {
return response()->json(['status' => 'failed', 'message' => 'add data Company failed!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'add data Company failed!', 'code' => 400], 400);
} }
@ -51,6 +56,10 @@ class CompanyController extends Controller
$data = Company::find($id); $data = Company::find($id);
if(isset($data['base_url']) && $data['base_url'] != NULL) {
$data->update(['base_url'=>null]);
$data['base_url'] = json_encode($data['base_url'], true);
}
if ($data) { if ($data) {
$result = $data->update($request->all()); $result = $data->update($request->all());
} else { } else {
@ -71,6 +80,7 @@ class CompanyController extends Controller
$data = Company::find($id); $data = Company::find($id);
if ($data) { if ($data) {
MenuCompany::where('company_id',$id)->delete();
$delete = $data->delete(); $delete = $data->delete();
} else { } else {
return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400);

45
app/Http/Controllers/MenuCompanyController.php

@ -9,33 +9,15 @@ use Illuminate\Support\Facades\Log;
class MenuCompanyController extends Controller class MenuCompanyController extends Controller
{ {
// public function add(Request $request)
// {
// $this->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) public function addMultiple(Request $request)
{ {
$menus = $request->all(); $menus = $request->all();
if (is_array($menus) && count($menus) > 0) { $data = MenuCompany::where('company_id',$menus[0]['company_id']);
if($data){
$data->delete();
}
if (is_array($menus) && count($menus) > 0 && isset($menus[0]['menu_id'])) {
$countRes = 0; $countRes = 0;
foreach ($menus as $menu) { foreach ($menus as $menu) {
@ -60,12 +42,17 @@ class MenuCompanyController extends Controller
} }
if ($countRes > 0) { if ($countRes > 0) {
return response()->json(['status' => 'success', 'message' => 'add data menu successfully!', 'code' => 200]); return response()->json(['status' => 'success', 'message' => 'Add data menu successfully!', 'code' => 200]);
} else { } else {
return response()->json(['status' => 'failed', 'message' => 'add data menu failed created!', 'code' => 400]); return response()->json(['status' => 'failed', 'message' => 'Add data menu failed created!', 'code' => 500]);
} }
} else { } else {
return response()->json(['status' => 'failed', 'message' => 'add data menu failed created!', 'code' => 400]); if(isset($data))
{
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' => 500]);
}
} }
} }
@ -120,15 +107,15 @@ class MenuCompanyController extends Controller
if ($data) { if ($data) {
$delete = $data->delete(); $delete = $data->delete();
} else { } else {
return response()->json(['status' => 'failed', 'message' => 'data menu not found!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'Data menu not found!', 'code' => 400], 400);
die(); die();
} }
if ($delete) { if ($delete) {
return response()->json(['status' => 'success', 'message' => 'data menu successfully deleted!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Data menu successfully deleted!', 'code' => 200], 200);
} else { } else {
return response()->json(['status' => 'failed', 'message' => 'data menu failed deleted!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'Data menu failed deleted!', 'code' => 400], 400);
} }
} }

91
app/Http/Controllers/ProjectController.php

@ -59,6 +59,7 @@ class ProjectController extends Controller
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $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; $data['phase_id'] = 1;
@ -334,10 +335,13 @@ class ProjectController extends Controller
'projectsByPhase' => $projectsByPhase, 'projectsByPhase' => $projectsByPhase,
'projectTypes' => $projectTypes, 'projectTypes' => $projectTypes,
'projectsByType' => $projectsByType, 'projectsByType' => $projectsByType,
], 200); ],
200
);
} }
public function getListProjectTask($id){ public function getListProjectTask($id)
{
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id", "m_proyek.*") $data = UserToActivity::select("assign_hr_to_activity.user_id as user_id", "m_proyek.*")
->where("assign_hr_to_activity.user_id", $id) ->where("assign_hr_to_activity.user_id", $id)
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id') ->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
@ -350,17 +354,20 @@ class ProjectController extends Controller
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); $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){ public function calculateSCurve(Request $request)
{
$sCurve = Project::select('scurve')->where('id', $request->project_id)->first(); $sCurve = Project::select('scurve')->where('id', $request->project_id)->first();
return response()->json(['status' => 'success', 'code' => 200, 'data' => json_decode($sCurve->scurve)], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => json_decode($sCurve->scurve)], 200);
} }
public function sCurveCommand(Request $request){ public function sCurveCommand(Request $request)
{
Artisan::call('calculate:scurve', [ Artisan::call('calculate:scurve', [
'project_id' => $request->project_id 'project_id' => $request->project_id
]); ]);
@ -375,12 +382,14 @@ class ProjectController extends Controller
// 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); $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(); $status = AssignMaterial::where('activity_id', $activity_id)->first();
if (!isset($status)) { if (!isset($status)) {
$reports = array( $reports = array(
@ -479,7 +488,8 @@ class ProjectController extends Controller
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) { public function getInvoiceIntegration(Request $request)
{
$ganttCount = VersionGantt::where('proyek_id', $request->id)->count(); $ganttCount = VersionGantt::where('proyek_id', $request->id)->count();
$search = urlencode($request->search); $search = urlencode($request->search);
if (empty($search)) if (empty($search))
@ -511,7 +521,8 @@ class ProjectController extends Controller
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
} }
public function detail(Request $request, $id, $gantt_id = null, $s_curve = null){ public function detail(Request $request, $id, $gantt_id = null, $s_curve = null)
{
if (empty($id) || !is_int((int)$id)) if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
@ -530,8 +541,7 @@ class ProjectController extends Controller
if (isset($s_curve)) { if (isset($s_curve)) {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first(); $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first();
$actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists(); $actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists();
if($result['type_proyek_id'] === 9) if ($result['type_proyek_id'] === 9) {
{
$actualEndExist = Activity::where('proyek_id', $id)->exists(); $actualEndExist = Activity::where('proyek_id', $id)->exists();
$query = Activity::where('proyek_id', $id); $query = Activity::where('proyek_id', $id);
} else { } else {
@ -550,8 +560,7 @@ class ProjectController extends Controller
} else { } else {
$startDate = $query->orderBy('start_date')->value('start_date'); $startDate = $query->orderBy('start_date')->value('start_date');
} }
if($actualEndExist) if ($actualEndExist) {
{
$maxEndDate = $query->max('id'); $maxEndDate = $query->max('id');
$endDate = $query->where('id', $maxEndDate)->first()->end_date; $endDate = $query->where('id', $maxEndDate)->first()->end_date;
} }
@ -569,7 +578,8 @@ class ProjectController extends Controller
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result, 'gantt' => $ganttId], 200); 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(); $payload = $request->all();
if (empty($payload['id']) || !is_int((int)$payload['id'])) if (empty($payload['id']) || !is_int((int)$payload['id']))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
@ -588,8 +598,7 @@ class ProjectController extends Controller
} else { } 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::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'])) { if (isset($payload['scurve'])) {
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get();
} else { } else {
@ -601,15 +610,26 @@ class ProjectController extends Controller
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(); $payload = $request->all();
if (empty($payload['project_id']) || !is_int((int)$payload['project_id'])) if (empty($payload['project_id']) || !is_int((int)$payload['project_id']))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$reports = DB::table('assign_material_to_activity as ama') $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', ->select(
'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date') '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('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id')
->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id') ->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id') ->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
@ -621,12 +641,14 @@ class ProjectController extends Controller
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(); $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') $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') ->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id')
->where('assign_hr_to_activity.version_gantt_id', $gantt_id) ->where('assign_hr_to_activity.version_gantt_id', $gantt_id)
@ -637,8 +659,17 @@ class ProjectController extends Controller
public function dashboard($id) public function dashboard($id)
{ {
$data = DB::table('m_proyek as mp') $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', ->select(
'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm', 'mp.budget_health') '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') ->join('m_users as mu', 'mu.id', '=', 'mp.pm_id')
->where('mp.id', $id) ->where('mp.id', $id)
->first(); ->first();
@ -653,8 +684,13 @@ class ProjectController extends Controller
$progress = @$rootActivity->persentase_progress ?? 0; $progress = @$rootActivity->persentase_progress ?? 0;
$commentActivity = DB::table('m_comment_activity as mca') $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', ->select(
'ma.name as activity') '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') ->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id')
->where('ma.proyek_id', $id) ->where('ma.proyek_id', $id)
->orderBy('comment_by') ->orderBy('comment_by')
@ -669,7 +705,8 @@ class ProjectController extends Controller
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} }
private function httpReq($search){ private function httpReq($search)
{
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION)); curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION));
@ -685,6 +722,4 @@ class ProjectController extends Controller
return json_decode($output); return json_decode($output);
} }
} }

3
app/Models/Company.php

@ -31,7 +31,6 @@ class Company extends Model
'created_at', 'created_at',
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by', 'updated_by'
'company_id'
]; ];
} }

Loading…
Cancel
Save