@ -5,13 +5,44 @@ namespace App\Http\Controllers;
use DateTime;
use DateTime;
use App\Jobs\ProcessSCurve;
use App\Jobs\ProcessSCurve;
use Illuminate\Http\Request;
use Illuminate\Http\Request;
use App\Models\{ReportActivityMaterial,ProjectToChecklistK3,FolderDocumentProyek,ProjectParticipants,ProductTransaction,ProjectChecklists,
use App\Models\{
ProjectMileStone,RequestMaterial,ProjectApproval,CommentActivity,ActivityDokumen,UserToActivity,ShowHideColumn,ReportActivity,ProjectCharter,DokumenProject,
ReportActivityMaterial,
AssignMaterial,ProjectIssues,HierarchyFtth,VersionGantt,UserToProyek,ProjectRisks,ProjectPhase,ProjectType,OfficeHours,AssignTools,ReportK3,Activity,Project,
ProjectToChecklistK3,
Holiday,Company,Image,User,Link
FolderDocumentProyek,
ProjectParticipants,
ProductTransaction,
ProjectChecklists,
ProjectMileStone,
RequestMaterial,
ProjectApproval,
CommentActivity,
ActivityDokumen,
UserToActivity,
ShowHideColumn,
ReportActivity,
ProjectCharter,
DokumenProject,
AssignMaterial,
ProjectIssues,
HierarchyFtth,
VersionGantt,
UserToProyek,
ProjectRisks,
ProjectPhase,
ProjectType,
OfficeHours,
AssignTools,
ReportK3,
Activity,
Project,
Holiday,
Company,
Image,
User,
Link
};
};
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\{Artisan,DB};
use Illuminate\Support\Facades\{Artisan, DB};
use App\Helpers\MasterFunctionsHelper;
use App\Helpers\MasterFunctionsHelper;
use Carbon\Carbon;
use Carbon\Carbon;
@ -20,17 +51,17 @@ const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&
class ProjectController extends Controller
class ProjectController extends Controller
{
{
public function add(Request $request)
public function add(Request $request)
{
{
$this->validate($request, [
$this->validate($request, [
'nama' => 'required',
'nama' => 'required',
'mulai_proyek' => 'required',
'mulai_proyek' => 'required',
'mulai_proyek' => 'required',
'mulai_proyek' => 'required',
'akhir_proyek' => 'required',
'akhir_proyek' => 'required',
'rencana_biaya' => 'required',
'rencana_biaya' => 'required',
'type_proyek_id' => 'required',
'type_proyek_id' => 'required',
'company_id' => 'required'
'company_id' => 'required'
]);
]);
DB::beginTransaction();
DB::beginTransaction();
try {
try {
$data = $request->all();
$data = $request->all();
@ -49,25 +80,25 @@ class ProjectController extends Controller
->selectRaw('count(*) as total_project')
->selectRaw('count(*) as total_project')
->where('company_id', $request->company_id)
->where('company_id', $request->company_id)
->first();
->first();
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) {
if ($transaction->where([['type_paket', 'Basic'], ['amount', '!=', null]])->exists()) {
if($projectResult['total_project'] < 10 ) {
if ($projectResult['total_project'] < 10 ) {
$countCreate = true;
$countCreate = true;
}
}
} elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) {
} elseif ($cloneQueryTransaction->where([['type_paket', 'Free'], ['amount', 0]])->exists()) {
if($projectResult['total_project'] < 1 ) {
if ($projectResult['total_project'] < 1 ) {
$countCreate = true;
$countCreate = true;
}
}
} else {
} else {
$countCreate = true;
$countCreate = true;
}
}
if($countCreate) {
if ($countCreate) {
$result = Project::create($data);
$result = Project::create($data);
if (!$result) {
if (!$result) {
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500);
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500);
} else {
} else {
$this->createOfficeHours($result['id']);
$this->createOfficeHours($result['id']);
$dataResultInsert = Project::where([['nama', $data['nama']],['mulai_proyek', $data['mulai_proyek']]])->first();
$dataResultInsert = Project::where([['nama', $data['nama']], ['mulai_proyek', $data['mulai_proyek']]])->first();
DB::commit();
DB::commit();
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);
}
}
@ -77,68 +108,67 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
} catch (\Throwable $th) {
DB::rollBack();
DB::rollBack();
}
}
}
}
public function edit($id)
public function edit($id)
{
{
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);
}
}
$result = Project::
$result = Project::select(
select(
'value_proyek',
'value_proyek',
'scoupe_of_work',
'scoupe_of_work',
'kode_sortname',
'kode_sortname',
'jumlah_stakeholder',
'jumlah_stakeholder',
'nama',
'nama',
'mulai_proyek',
'mulai_proyek',
'akhir_proyek',
'akhir_proyek',
'area_kerja',
'area_kerja',
'rencana_biaya',
'rencana_biaya',
'biaya_actual',
'biaya_actual',
'company',
'company',
'pm_id',
'pm_id',
'type_proyek_id',
'type_proyek_id',
'divisi_id',
'divisi_id',
'persentase_progress',
'persentase_progress',
'keterangan',
'keterangan',
'durasi_proyek',
'durasi_proyek',
'progress_by_worklog',
'progress_by_worklog',
'currency_symbol',
'currency_symbol',
'late_consequence',
'late_consequence',
'assumtion',
'assumtion',
'currency_code',
'currency_code',
'currency_name',
'currency_name',
'project_objectives',
'project_objectives',
'considered_success_when',
'considered_success_when',
'potential_risk',
'potential_risk',
'testing_environment',
'testing_environment',
'budget_health',
'budget_health',
'phase_id',
'phase_id',
'calculation_status',
'calculation_status',
'md.name as divisi_name',
'md.name as divisi_name',
'm_proyek.company_id'
'm_proyek.company_id'
)
)
->leftJoin('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id')
->leftJoin('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id')
->where('m_proyek.id', $id)
->where('m_proyek.id', $id)
->first();
->first();
if (!$result) {
if (!$result) {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
} else {
} else {
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)
public function update(Request $request, $id)
{
{
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);
}
}
$data = Project::find($id);
$data = Project::find($id);
if ($data) {
if ($data) {
if ($data->update($request->all())) {
if ($data->update($request->all())) {
return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200);
return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200);
} else {
} else {
@ -147,43 +177,43 @@ class ProjectController extends Controller
} else {
} else {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
}
}
}
private function createOfficeHours($proyek_id)
private function createOfficeHours($proyek_id)
{
{
$dataCreate = array(
$dataCreate = array(
"proyek_id" => $proyek_id,
"proyek_id" => $proyek_id,
"monday_start" => "08:00:00",
"monday_start" => "08:00:00",
"monday_end" => "16:00:00",
"monday_end" => "16:00:00",
"tuesday_start" => "08:00:00",
"tuesday_start" => "08:00:00",
"tuesday_end" => "16:00:00",
"tuesday_end" => "16:00:00",
"wednesday_start" => "08:00:00",
"wednesday_start" => "08:00:00",
"wednesday_end" => "16:00:00",
"wednesday_end" => "16:00:00",
"thursday_start" => "08:00:00",
"thursday_start" => "08:00:00",
"thursday_end" => "16:00:00",
"thursday_end" => "16:00:00",
"friday_start" => "08:00:00",
"friday_start" => "08:00:00",
"friday_end" => "16:00:00",
"friday_end" => "16:00:00",
"saturday_start" => "08:00:00",
"saturday_start" => "08:00:00",
"saturday_end" => "16:00:00",
"saturday_end" => "16:00:00",
"sunday_start" => "08:00:00",
"sunday_start" => "08:00:00",
"sunday_end" => "16:00:00",
"sunday_end" => "16:00:00",
"created_by" => $this->currentName
"created_by" => $this->currentName
);
);
OfficeHours::create($dataCreate);
OfficeHours::create($dataCreate);
return true;
return true;
}
}
public function delete($id, $company_id)
public function delete($id, $company_id)
{
{
DB::beginTransaction();
DB::beginTransaction();
$data = Project::find($id);
$data = Project::find($id);
$dateNow = Carbon::now();
$dateNow = Carbon::now();
if ($data) {
if ($data) {
$this->deleteRelative($id, $company_id);
$this->deleteRelative($id, $company_id);
if ($data->delete()) {
if ($data->delete()) {
// if ($data->update(['deleted_at' => $dateNow, 'deleted_by_id' => $this->currentId])) {
// if ($data->update(['deleted_at' => $dateNow, 'deleted_by_id' => $this->currentId])) {
DB::commit();
DB::commit();
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
} else {
} else {
@ -192,13 +222,13 @@ class ProjectController extends Controller
}
}
} else {
} else {
DB::rollBack();
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
}
}
}
private function deleteRelative($project_id, $company_id)
private function deleteRelative($project_id, $company_id)
{
{
DB::transaction(function() use($project_id, $company_id) {
DB::transaction(function () use ($project_id, $company_id) {
UserToProyek::where('proyek_id', $project_id)->delete();
UserToProyek::where('proyek_id', $project_id)->delete();
UserToActivity::where('proyek_id', $project_id)->delete();
UserToActivity::where('proyek_id', $project_id)->delete();
AssignMaterial::where('proyek_id', $project_id)->delete();
AssignMaterial::where('proyek_id', $project_id)->delete();
@ -217,19 +247,19 @@ class ProjectController extends Controller
RequestMaterial::where('proyek_id', $project_id)->delete();
RequestMaterial::where('proyek_id', $project_id)->delete();
$this->deleteVersionGantt($project_id, $company_id);
$this->deleteVersionGantt($project_id, $company_id);
$this->deleteDokumenProject($project_id, $company_id);
$this->deleteDokumenProject($project_id, $company_id);
},5);
}, 5);
}
}
private function deleteVersionGantt($project_id, $company_id)
private function deleteVersionGantt($project_id, $company_id)
{
{
DB::transaction(function() use($project_id, $company_id) {
DB::transaction(function () use ($project_id, $company_id) {
$dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id");
$dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id");
$vhIds = $dataVg->all();
$vhIds = $dataVg->all();
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id');
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id');
$activityIds = $activity->all();
$activityIds = $activity->all();
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get();
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get();
$company = Company::find($company_id);
$company = Company::find($company_id);
if($company) {
if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataRa as $ra) {
foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
@ -255,15 +285,15 @@ class ProjectController extends Controller
ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete();
ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete();
Activity::whereIn("version_gantt_id", $vhIds)->delete();
Activity::whereIn("version_gantt_id", $vhIds)->delete();
ReportActivity::whereIn("activity_id", $activityIds)->delete();
ReportActivity::whereIn("activity_id", $activityIds)->delete();
},5);
}, 5);
}
}
private function deleteDokumenProject($project_id, $company_id)
private function deleteDokumenProject($project_id, $company_id)
{
{
DB::transaction(function() use($project_id, $company_id){
DB::transaction(function () use ($project_id, $company_id) {
$dataDokumen = DokumenProject::where([['type_dokumen', 'project-document-out-folder'],['ref_id', $project_id]])->get();
$dataDokumen = DokumenProject::where([['type_dokumen', 'project-document-out-folder'], ['ref_id', $project_id]])->get();
$company = Company::find($company_id);
$company = Company::find($company_id);
if($company) {
if ($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
foreach ($dataDokumen as $dokumen) {
foreach ($dataDokumen as $dokumen) {
if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) {
if (file_exists($destinationPath['pathDocument'] . $dokumen->file)) {
@ -271,7 +301,7 @@ class ProjectController extends Controller
}
}
}
}
}
}
DokumenProject::where([['type_dokumen', 'project-document-out-folder'],['ref_id', $project_id]])->delete();
DokumenProject::where([['type_dokumen', 'project-document-out-folder'], ['ref_id', $project_id]])->delete();
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id");
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id");
$ref_ids = $dataFolder->all();
$ref_ids = $dataFolder->all();
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get();
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get();
@ -281,24 +311,24 @@ class ProjectController extends Controller
}
}
}
}
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete();
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete();
},5);
}, 5);
}
}
public function search(Request $request)
public function search(Request $request)
{
{
$payload = $request->all();
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_proyek');
$dataBuilder = $this->setUpPayload($payload, 'm_proyek');
$builder = $dataBuilder['builder'];
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
$totalRecord = $countBuilder->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
}
}
public function list()
public function list()
{
{
DB::beginTransaction();
DB::beginTransaction();
try {
try {
$data = Project::select(
$data = Project::select(
@ -383,67 +413,66 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
} catch (\Throwable $th) {
DB::rollBack();
DB::rollBack();
}
}
}
}
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')
->groupBy("m_proyek.proyek_id")
->groupBy("m_proyek.proyek_id")
->get();
->get();
if ($data) {
if ($data) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} else {
} else {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
}
}
public function getSCurve(Request $request)
{
$data = MasterFunctionsHelper::getSCurve($request);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 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 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);
}
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));
public function getSCurve(Request $request)
{
// return response()->json(['message' => 'S Curve calculation queued']);
$data = MasterFunctionsHelper::getSCurve($request);
// }
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
// return response()->json(['message' => 'Project not found'], 404);
}
// testing
public function calculateSCurvetest(Request $request)
public function getLinearSCurve(Request $request)
{
{
$data = MasterFunctionsHelper::calculateSCurve($request->project_id);
$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 function calculateSCurve(Request $request)
public static function setSyncDate($activity_id, $activity, $report)
{
{
$sCurve = Project::select('scurve')->where('id', $request->project_id)->first();
return response()->json(['status' => 'success', 'code' => 200, 'data' => json_decode($sCurve->scurve)], 200);
}
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' => 'Project not found'], 404);
}
public function getLinearSCurve(Request $request)
{
$data = MasterFunctionsHelper::getLinearSCurve($request);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
public static function setSyncDate($activity_id, $activity, $report)
{
DB::beginTransaction();
DB::beginTransaction();
try {
try {
$status = AssignMaterial::where('activity_id', $activity_id)->first();
$status = AssignMaterial::where('activity_id', $activity_id)->first();
@ -478,10 +507,10 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
} catch (\Throwable $th) {
DB::rollBack();
DB::rollBack();
}
}
}
}
public function synchronizeReport($gantt_id)
public function synchronizeReport($gantt_id)
{
{
DB::beginTransaction();
DB::beginTransaction();
try {
try {
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
@ -517,8 +546,8 @@ class ProjectController extends Controller
} else if ($reports[$i]['status'] == 'done') {
} else if ($reports[$i]['status'] == 'done') {
$activity->actual_end = $reports[$i]['max_date']->setTime(23, 59, 59);
$activity->actual_end = $reports[$i]['max_date']->setTime(23, 59, 59);
}
}
$activity->start_date = $reports[$i]['min_date']; //same early
$activity->start_date = $reports[$i]['min_date']; //same early
$activity->end_date = $reports[$i]['max_date']->setTime(23, 59, 59); // same early
$activity->end_date = $reports[$i]['max_date']->setTime(23, 59, 59); // same early
$startDate = new DateTime($activity->start_date);
$startDate = new DateTime($activity->start_date);
$endDate = new DateTime($activity->end_date);
$endDate = new DateTime($activity->end_date);
$duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate);
$duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate);
@ -531,74 +560,54 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
} catch (\Throwable $th) {
DB::rollBack();
DB::rollBack();
}
}
}
}
public function setBaseline($gantt_id)
public function setBaseline($gantt_id)
{
{
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
foreach ($activities as $activity) {
foreach ($activities as $activity) {
$activity->update([
$activity->update([
"planned_start" => $activity->start_date,
"planned_start" => $activity->start_date,
"planned_end" => $activity->end_date,
"planned_end" => $activity->end_date,
"early_start" => $activity->start_date,
"early_start" => $activity->start_date,
"early_end" => $activity->end_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 setBaselineActivity($activity_id, $gantt_id)
public function setBaselineActivity($activity_id, $gantt_id)
{
{
$activity = Activity::where([["version_gantt_id", $gantt_id],['id',$activity_id]])->first();
$activity = Activity::where([["version_gantt_id", $gantt_id], ['id', $activity_id]])->first();
$activity->update([
$activity->update([
"planned_start" => $activity->start_date,
"planned_start" => $activity->start_date,
"planned_end" => $activity->end_date,
"planned_end" => $activity->end_date,
"early_start" => $activity->start_date,
"early_start" => $activity->start_date,
"early_end" => $activity->end_date,
"early_end" => $activity->end_date,
]);
]);
return response()->json(['status' => 'success', 'message' => 'Set baseline activity success!', 'code' => 200], 200);
return response()->json(['status' => 'success', 'message' => 'Set baseline activity success!', 'code' => 200], 200);
}
}
public function getInvoiceIntegration(Request $request)
{
public function getByUser($id)
DB::beginTransaction();
{
try {
$userProyek = UserToProyek::query()
$ganttCount = VersionGantt::where('proyek_id', $request->id)->count();
->from('assign_hr_to_proyek AS utp')
$search = urlencode($request->search);
->where([['is_customer', true], ['user_id', $id]])
if (empty($search)) {
->leftJoin('m_users', 'utp.user_id', '=', 'm_users.id')
return response()->json(['status' => 'error', 'message' => 'Empty query string!'], 400);
->leftJoin('m_proyek', 'utp.proyek_id', '=', 'm_proyek.id')
}
->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
$url = str_replace("SEARCH", $search, config('api.adw') . '/project_cost?project_no=SEARCH');
->select('m_proyek.*', 'm_type_proyek.name AS join_second_name', 'm_users.name AS join_first_name')
->get();
$response = MasterFunctionsHelper::curlReq($url);
$totalRecord = $userProyek->count();
if (isset($request->gantt_id)) {
$response->data->total_cost = $response->data->total_cost / $ganttCount;
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
}
}
DB::commit();
return response()->json(['status' => 'success', 'data' => $response, 'code' => 200], 200);
public function detail(Request $request, $id, $gantt_id = null, $s_curve = null)
} catch (\Throwable $th) {
{
DB::rollBack();
}
}
public function getByUser($id)
{
$userProyek = UserToProyek::query()
->from('assign_hr_to_proyek AS utp')
->where([['is_customer', true],['user_id', $id]])
->leftJoin('m_users', 'utp.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', 'utp.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)
{
DB::beginTransaction();
DB::beginTransaction();
try {
try {
if (empty($id) || !is_int((int)$id)) {
if (empty($id) || !is_int((int)$id)) {
@ -673,10 +682,10 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
} catch (\Throwable $th) {
DB::rollBack();
DB::rollBack();
}
}
}
}
public function getOverdueActivities(Request $request)
public function getOverdueActivities(Request $request)
{
{
DB::beginTransaction();
DB::beginTransaction();
try {
try {
$payload = $request->all();
$payload = $request->all();
@ -712,10 +721,10 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
} catch (\Throwable $th) {
DB::rollBack();
DB::rollBack();
}
}
}
}
public function getReportDistribution(Request $request)
public function getReportDistribution(Request $request)
{
{
DB::beginTransaction();
DB::beginTransaction();
try {
try {
$payload = $request->all();
$payload = $request->all();
@ -750,25 +759,25 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
} catch (\Throwable $th) {
DB::rollBack();
DB::rollBack();
}
}
}
}
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)
->get();
->get();
return response()->json(['data' => $results]);
return response()->json(['data' => $results]);
}
}
public function dashboard($id)
public function dashboard($id)
{
{
DB::beginTransaction();
DB::beginTransaction();
try {
try {
$data = Project::query()
$data = Project::query()
@ -822,23 +831,23 @@ class ProjectController extends Controller
} catch (\Throwable $th) {
} catch (\Throwable $th) {
DB::rollBack();
DB::rollBack();
}
}
}
}
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));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w'));
curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w'));
$info = curl_getinfo($ch);
$info = curl_getinfo($ch);
$output = curl_exec($ch);
$output = curl_exec($ch);
curl_close($ch);
curl_close($ch);
return json_decode($output);
return json_decode($output);
}
}
}
}