Browse Source

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

Reviewed-on: ordo/adw-backend#5
pull/3/head
ibnu 2 years ago
parent
commit
f5a169e83d
  1. 114
      app/Http/Controllers/DashboardBoDController.php
  2. 15
      app/Http/Controllers/DivisiController.php
  3. 300
      app/Http/Controllers/ProjectController.php
  4. 0
      app/Imports/ActivityImport.php
  5. 29
      app/Models/Activity.php
  6. 1
      bootstrap/app.php

114
app/Http/Controllers/DashboardBoDController.php

@ -2,6 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
<<<<<<< HEAD
use App\Helpers\MasterFunctionsHelper; use App\Helpers\MasterFunctionsHelper;
use App\Models\Divisi; use App\Models\Divisi;
use App\Models\Project; use App\Models\Project;
@ -10,6 +11,13 @@ use App\Models\User;
use App\Models\UserToVersionGantt; use App\Models\UserToVersionGantt;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
=======
use App\Models\Project;
use App\Models\Divisi;
use App\Models\ProjectPhase;
use Illuminate\Support\Collection;
use DB;
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
class DashboardBoDController extends Controller class DashboardBoDController extends Controller
{ {
@ -19,6 +27,7 @@ class DashboardBoDController extends Controller
return $year; return $year;
} }
<<<<<<< HEAD
private function curlReq($url, $token){ private function curlReq($url, $token){
$ch = curl_init(); $ch = curl_init();
$headers = [ $headers = [
@ -54,10 +63,15 @@ class DashboardBoDController extends Controller
public function getCompanyCashFlow($year = '%') { public function getCompanyCashFlow($year = '%') {
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0; $totalExpenditure = $totalInvoice = $totalPaidInvoice = 0;
=======
public function getCompanyCashFlow($year = '%') {
$year = $this->interpolateYear($year);
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
// we can't use eloquent's sum() method because someone decided to use varchar as datatype in rencana_biaya field // we can't use eloquent's sum() method because someone decided to use varchar as datatype in rencana_biaya field
$totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))')) $totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
->where('mulai_proyek', 'like', $year) ->where('mulai_proyek', 'like', $year)
<<<<<<< HEAD
/* ->orWhere('akhir_proyek', 'like', $year) */ /* ->orWhere('akhir_proyek', 'like', $year) */
->pluck('sum') ->pluck('sum')
->first(); ->first();
@ -87,10 +101,22 @@ class DashboardBoDController extends Controller
'total_expenditure' => $totalExpenditure, 'total_expenditure' => $totalExpenditure,
'total_invoice' => $totalInvoice, 'total_invoice' => $totalInvoice,
'total_paid_invoice' => $totalPaidInvoice , 'total_paid_invoice' => $totalPaidInvoice ,
=======
->pluck('sum')
->first();
return response()->json([
'data' => [
'total_budget' => (int) $totalBudgets ?? rand(0,10),
'total_expenditure' => rand(0,10), // to do integrasi
'total_invoice' => rand(0,10),
'total_paid_invoice' => rand(0,10),
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
] ]
], 200); ], 200);
} }
<<<<<<< HEAD
public function getInvoiceOutstanding($year = '%'){ public function getInvoiceOutstanding($year = '%'){
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$projects = Project::where('mulai_proyek', 'like', $year) $projects = Project::where('mulai_proyek', 'like', $year)
@ -144,10 +170,27 @@ class DashboardBoDController extends Controller
} }
public function getTotalProjectScheduleHealthPerDivision($year = '%'){ public function getTotalProjectScheduleHealthPerDivision($year = '%'){
=======
public function getProjectPerScheduleHealth($year = '%'){
$year = $this->interpolateYear($year);
// get data plan (vol) in %
// get data actual in %
return response()->json([
'data' => [
'behind-schedule' => rand(0,10),
'warning' => rand(0,10),
'on-schedule' => rand(0,10),
]
], 200);
}
public function getProjectScheduleHealthPerDivision($year = '%'){
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$divisions = Divisi::whereNull('parent')->get(); $divisions = Divisi::whereNull('parent')->get();
foreach($divisions as $division){ foreach($divisions as $division){
<<<<<<< HEAD
$scheduleData = new Collection(); $scheduleData = new Collection();
$behindSchedule = $warning = $onSchedule = 0; $behindSchedule = $warning = $onSchedule = 0;
@ -166,6 +209,12 @@ class DashboardBoDController extends Controller
$scheduleData->prepend($behindSchedule, 'behindSchedule'); $scheduleData->prepend($behindSchedule, 'behindSchedule');
$scheduleData->prepend($warning, 'warning'); $scheduleData->prepend($warning, 'warning');
$scheduleData->prepend($onSchedule, 'onSchedule'); $scheduleData->prepend($onSchedule, 'onSchedule');
=======
$scheduleData = new Collection();
$scheduleData->prepend(rand(0, 10), 'behindSchedule');
$scheduleData->prepend(rand(0, 10), 'warning');
$scheduleData->prepend(rand(0, 10), 'onSchedule');
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
$division->scheduleData = $scheduleData; $division->scheduleData = $scheduleData;
} }
return response()->json([ return response()->json([
@ -175,6 +224,7 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
<<<<<<< HEAD
public function getTotalProjectPerBudgetHealth($year = '%'){ public function getTotalProjectPerBudgetHealth($year = '%'){
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
return response()->json([ return response()->json([
@ -182,10 +232,20 @@ class DashboardBoDController extends Controller
'overrun' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'overrun')->count(), 'overrun' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'overrun')->count(),
'warning' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'warning')->count(), 'warning' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'warning')->count(),
'on-budget' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'on-budget')->count(), 'on-budget' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'on-budget')->count(),
=======
public function getProjectPerBudgetHealth($year = '%'){
$year = $this->interpolateYear($year);
return response()->json([
'data' => [
'overrun' => rand(0,10),
'warning' => rand(0,10),
'on-budget' => rand(0,10),
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
] ]
], 200); ], 200);
} }
<<<<<<< HEAD
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health){ private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health){
return Project::where('divisi_id', $divisi) return Project::where('divisi_id', $divisi)
->where('mulai_proyek', 'like', $year) ->where('mulai_proyek', 'like', $year)
@ -217,6 +277,19 @@ class DashboardBoDController extends Controller
} }
foreach($divisions as $division){ foreach($divisions as $division){
} }
=======
public function getProjectBudgetHealthPerDivision($year = '%'){
$year = $this->interpolateYear($year);
$divisions = Divisi::whereNull('parent')->get();
foreach($divisions as $division){
$budgetData = new Collection();
$budgetData->prepend(rand(0, 10), 'overrun');
$budgetData->prepend(rand(0, 10), 'warning');
$budgetData->prepend(rand(0, 10), 'onBudget');
$division->budgetData = $budgetData;
}
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
return response()->json([ return response()->json([
'data' => [ 'data' => [
$divisions $divisions
@ -224,6 +297,7 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
<<<<<<< HEAD
public function getTotalProjectPerPhase($year = '%'){ public function getTotalProjectPerPhase($year = '%'){
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$projectPhases = ProjectPhase::orderBy('order')->get(); $projectPhases = ProjectPhase::orderBy('order')->get();
@ -232,6 +306,13 @@ class DashboardBoDController extends Controller
->where('mulai_proyek', 'like', $year) ->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */ /* ->orWhere('akhir_proyek', 'like', $year) */
->count(); ->count();
=======
public function getProjectPerPhase($year = '%'){
$year = $this->interpolateYear($year);
$projectPhases = ProjectPhase::orderBy('order')->get();
foreach($projectPhases as $phase){
$phase->totalProject = rand(0,10);
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
} }
return response()->json([ return response()->json([
'data' => [ 'data' => [
@ -243,20 +324,31 @@ class DashboardBoDController extends Controller
private function countTotalProjectInDivision($id, $year){ private function countTotalProjectInDivision($id, $year){
return Project::where('divisi_id', $id) return Project::where('divisi_id', $id)
->where('mulai_proyek', 'like', $year) ->where('mulai_proyek', 'like', $year)
<<<<<<< HEAD
/* ->orWhere('akhir_proyek', 'like', $year) */ /* ->orWhere('akhir_proyek', 'like', $year) */
=======
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
->count(); ->count();
} }
public function getTotalProjectPerDivision($year = '%') { public function getTotalProjectPerDivision($year = '%') {
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
<<<<<<< HEAD
$divisions = Divisi::select('id','name') $divisions = Divisi::select('id','name')
=======
$totalProjectPerDivision = Divisi::select('id','name')
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
->with('children') ->with('children')
->whereNull('parent') ->whereNull('parent')
->get(); ->get();
// to do : count in more than 1 level child // to do : count in more than 1 level child
<<<<<<< HEAD
foreach($divisions as $v){ foreach($divisions as $v){
=======
foreach($totalProjectPerDivision as $v){
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
$v->total = $this->countTotalProjectInDivision($v->id, $year); $v->total = $this->countTotalProjectInDivision($v->id, $year);
foreach($v->children as $d){ foreach($v->children as $d){
$v->total += $this->countTotalProjectInDivision($d->id, $year); $v->total += $this->countTotalProjectInDivision($d->id, $year);
@ -265,14 +357,21 @@ class DashboardBoDController extends Controller
} }
return response()->json([ return response()->json([
<<<<<<< HEAD
'data' => $divisions 'data' => $divisions
=======
'data' => $totalProjectPerDivision
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
], 200); ], 200);
} }
private function countTotalProjectValueInDivision($id, $year){ private function countTotalProjectValueInDivision($id, $year){
return Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))')) return Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
->where('mulai_proyek', 'like', $year) ->where('mulai_proyek', 'like', $year)
<<<<<<< HEAD
/* ->orWhere('akhir_proyek', 'like', $year) */ /* ->orWhere('akhir_proyek', 'like', $year) */
=======
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
->where('divisi_id', $id) ->where('divisi_id', $id)
->pluck('sum') ->pluck('sum')
->first(); ->first();
@ -281,13 +380,21 @@ class DashboardBoDController extends Controller
public function getTotalProjectValuePerDivision($year = '%') { public function getTotalProjectValuePerDivision($year = '%') {
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
<<<<<<< HEAD
$divisions = Divisi::select('id','name') $divisions = Divisi::select('id','name')
=======
$totalProjectValuePerDivision = Divisi::select('id','name')
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
->with('children') ->with('children')
->whereNull('parent') ->whereNull('parent')
->get(); ->get();
// to do : count in more than 1 level child // to do : count in more than 1 level child
<<<<<<< HEAD
foreach($divisions as $v){ foreach($divisions as $v){
=======
foreach($totalProjectValuePerDivision as $v){
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
$v->total = $this->countTotalProjectValueInDivision($v->id, $year); $v->total = $this->countTotalProjectValueInDivision($v->id, $year);
foreach($v->children as $d){ foreach($v->children as $d){
$v->total += $this->countTotalProjectValueInDivision($d->id, $year); $v->total += $this->countTotalProjectValueInDivision($d->id, $year);
@ -296,6 +403,7 @@ class DashboardBoDController extends Controller
} }
return response()->json([ return response()->json([
<<<<<<< HEAD
'data' => $divisions 'data' => $divisions
], 200); ], 200);
} }
@ -330,5 +438,11 @@ class DashboardBoDController extends Controller
'total_manpowers' => User::count() 'total_manpowers' => User::count()
], 200); ], 200);
} }
=======
'data' => $totalProjectValuePerDivision
], 200);
}
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
} }

15
app/Http/Controllers/DivisiController.php

@ -20,8 +20,8 @@ class DivisiController extends Controller
public function add(Request $request){ public function add(Request $request){
$this->validate($request, [ $this->validate($request, [
'name' => 'required', 'name' => 'required',
'description' => 'string' 'description' => 'string',
// 'parent' => 'integer' 'parent' => 'integer'
]); ]);
$data = $request->all(); $data = $request->all();
@ -70,15 +70,10 @@ class DivisiController extends Controller
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200);
} }
public function search(Request $request) public function search()
{ {
$payload = $request->all(); return $this->list();
$dataBuilder = $this->setUpPayload($payload, 'm_divisi'); // cant use builder for this case
$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 list() public function list()

300
app/Http/Controllers/ProjectController.php

@ -2,32 +2,30 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Helpers\MasterFunctionsHelper; use Illuminate\Http\Request;
use App\Models\Project;
use App\Models\UserToProyek;
use App\Models\Activity; use App\Models\Activity;
use App\Models\ActivityDokumen; use App\Models\UserToActivity;
use App\Models\User;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use App\Models\CommentActivity;
use App\Models\DokumenProject; use App\Models\DokumenProject;
use App\Models\FolderDocumentProyek; use App\Models\FolderDocumentProyek;
use App\Models\Holiday;
use App\Models\Image;
use App\Models\Link;
use App\Models\OfficeHours;
use App\Models\Project;
use App\Models\ProjectApproval;
use App\Models\ProjectCharter; use App\Models\ProjectCharter;
use App\Models\ProjectMileStone; use App\Models\ProjectApproval;
use App\Models\ProjectParticipants;
use App\Models\ProjectPhase; use App\Models\ProjectPhase;
use App\Models\ProjectType; use App\Models\ProjectType;
use App\Models\ReportActivity; use App\Models\ProjectMileStone;
use App\Models\ReportActivityMaterial; use App\Models\ProjectParticipants;
use App\Models\ShowHideColumn; use App\Models\ShowHideColumn;
use App\Models\User;
use App\Models\UserToActivity;
use App\Models\UserToProyek;
use App\Models\VersionGantt; use App\Models\VersionGantt;
use Illuminate\Http\Request; use App\Models\Image;
use App\Models\CommentActivity;
use App\Models\Link;
use App\Models\ActivityDokumen;
use App\Models\Holiday;
use App\Models\ReportActivity;
use App\Models\OfficeHours;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1";
@ -215,20 +213,6 @@ class ProjectController extends Controller
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 getManpower($proyek_id){
$manPower = UserToProyek::where('proyek_id', $proyek_id)->get();
$manCount = $manPower->count();
return response()->json(['data'=>$manPower, 'totalRecord'=>$manCount]);
}
public function getAssignedHR($gantt_id){
$results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id')
->where('assign_hr_to_activity.version_gantt_id', $gantt_id)
->get();
return response()->json(['data'=>$results]);
}
public function list() public function list()
{ {
$data = Project::orderBy('id', 'desc')->get(); $data = Project::orderBy('id', 'desc')->get();
@ -245,7 +229,7 @@ class ProjectController extends Controller
$scheduleHealth = "on-track"; $scheduleHealth = "on-track";
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first();
if($rootActivity){ if($rootActivity){
$costVariance = (int)$d->rencana_biaya - $rootActivity->biaya_actual ?? 0; $costVariance = $d->rencana_biaya - $rootActivity->biaya_actual;
$actualCost = $rootActivity->biaya_actual ?? 0; $actualCost = $rootActivity->biaya_actual ?? 0;
$progress = $rootActivity->persentase_progress ?? 0; $progress = $rootActivity->persentase_progress ?? 0;
@ -263,7 +247,7 @@ class ProjectController extends Controller
$lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); $lastActivity = date("d/m/Y", strtotime($rootActivity->end_date));
} }
$d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); $d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek));
$d->plannedCost = (int)$d->rencana_biaya; $d->plannedCost = $d->rencana_biaya;
$d->actualCost = $actualCost; $d->actualCost = $actualCost;
$d->lastActivity = $lastActivity ?? "-"; $d->lastActivity = $lastActivity ?? "-";
$d->costVariance = $costVariance; $d->costVariance = $costVariance;
@ -272,184 +256,126 @@ class ProjectController extends Controller
$d->progress = $progress; $d->progress = $progress;
$d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null; $d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null;
$d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0; $d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0;
$d->projectManager = DB::table('m_proyek') $d->projectManager = DB::table('m_proyek')
->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id') ->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id')
->where('m_proyek.id', $d->id) ->where('m_proyek.id', $d->id)
->pluck('m_users.name') ->pluck('m_users.name')
->first(); ->first();
$d->geolocation = []; if($d->area_kerja != ''){
} $d->geolocation = $this->httpReq($d->area_kerja);
$d->geolocation = [];
$totalPlannedCost = $data->sum('plannedCost'); } else {
$totalActualCost = $data->sum('actualCost'); $d->geolocation = [];
}
}
$totalPlannedCost = $data->sum('plannedCost');
$totalActualCost = $data->sum('actualCost');
$manpowers = User::count(); $manpowers = User::count();
$projectsOnDanger = Project::where('budget_health', 'danger')->count(); $projectsOnDanger = Project::where('budget_health', 'danger')->count();
$projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); $projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name');
$projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name'); $projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name');
try { try {
$projectsByPhase = DB::table('m_proyek') $projectsByPhase = DB::table('m_proyek')
->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total')) ->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total'))
->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id') ->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id')
->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') ->groupBy('m_proyek_phase.name', 'm_proyek_phase.color')
->get(); ->get();
} catch (\DivisionByZeroError $e) { } catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
} }
try { try {
$projectsByType = DB::table('m_proyek') $projectsByType = DB::table('m_proyek')
->select('m_type_proyek.name', DB::raw('count(*) as total')) ->select('m_type_proyek.name', DB::raw('count(*) as total'))
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') ->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id')
->groupBy('m_type_proyek.name') ->groupBy('m_type_proyek.name')
->get(); ->get();
} catch (\DivisionByZeroError $e) { } catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
} }
return response()->json( return response()->json(
[ [
'status'=>'success', 'status'=>'success',
'code'=>200, 'code'=>200,
'data'=>$data, 'data'=>$data,
'totalRecord'=>$countData, 'totalRecord'=>$countData,
'totalPlannedCost' => $totalPlannedCost, 'totalPlannedCost' => $totalPlannedCost,
'totalActualCost' => $totalActualCost, 'totalActualCost' => $totalActualCost,
'totalRevenue' => $totalPlannedCost - $totalActualCost, 'totalRevenue' => $totalPlannedCost - $totalActualCost,
'manpowers' => $manpowers, 'manpowers' => $manpowers,
'projectsOnDanger'=> $projectsOnDanger, 'projectsOnDanger'=> $projectsOnDanger,
'projectPhases' => $projectPhases, 'projectPhases' => $projectPhases,
'projectsByPhase' => $projectsByPhase, 'projectsByPhase' => $projectsByPhase,
'projectTypes' => $projectTypes, 'projectTypes' => $projectTypes,
'projectsByType' => $projectsByType, 'projectsByType' => $projectsByType,
], 200); ], 200);
} }
public function detail($id){ public function getListProjectTask($id){
if(empty($id) || !is_int((int)$id)) $data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*")
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); ->where("assign_hr_to_activity.user_id", $id)
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
$result = Project::find($id); ->groupBy("m_proyek.proyek_id")
->get();
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$gantt = MasterFunctionsHelper::getLatestGantt($id);
$result->projectManager = User::where('id', $result->pm_id)->value('name');
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $gantt['last_gantt_id'])->first();
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200);
}
public function synchronizeReport($gantt_id) if(!$data)
{ return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
$reports = [];
foreach($activities as $activity) {
$activity_id = $activity->id;
$countReports = ReportActivityMaterial::where('activity_id', $activity_id)->count();
if ($countReports === 1) {
$dataReports = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->get();
foreach($dataReports as $dr) {
$reports[] = array(
'activity_id'=>$activity_id,
'min_date'=>$dr->report_date,
'max_date'=>date_modify(date_create($dr->report_date), "1 days")
);
}
}
if ($countReports > 1) {
$firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first();
$lastReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderByDesc('report_date')->first();
$reports[] = array(
'activity_id'=>$activity_id,
'min_date'=>$firstReport->report_date,
'max_date'=>date_modify(date_create($lastReport->report_date), "1 days")
);
}
$activity->reports = $reports;
}
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */
for ($i=0; $i < count($reports); $i++) {
$activity = Activity::find($reports[$i]['activity_id']);
$activity->start_date = $reports[$i]['min_date'];
$activity->end_date = $reports[$i]['max_date'];
$activity->save();
}
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200);
} }
public function setBaseline($gantt_id) public function dashboard($id)
{ {
$activities = Activity::where("version_gantt_id", $gantt_id)->get(); $data = DB::table('m_proyek as mp')
->select('mp.kode_sortname', 'mp.nama as name_project', 'mp.mulai_proyek as start', 'mp.akhir_proyek as finish',
'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm', 'mp.budget_health')
->join('m_users as mu', 'mu.id', '=', 'mp.pm_id')
->where('mp.id', $id)
->first();
foreach ($activities as $activity) { if(!$data)
$activity->update([ return response()->json(['status'=>'failed','message'=>'Data tidak ditemukan!','code'=> 404], 404);
"planned_start"=>$activity->start_date,
"planned_end"=>$activity->end_date,
]);
}
return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200);
}
public function getOverdueActivities(Request $request){ $manpowers = UserToProyek::where('proyek_id', $id)->count();
$payload = $request->all(); $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first();
if(empty($payload['id']) || !is_int((int)$payload['id']))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$result = Project::find($payload['id']); $actualCost = @$rootActivity->biaya_actual ?? 0;
$progress = @$rootActivity->persentase_progress ?? 0;
if(!$result) $commentActivity = DB::table('m_comment_activity as mca')
return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404); ->select('mca.activity_id', 'mca.comment as comment', 'mca.created_by as comment_by', 'mca.created_at as comment_created',
//TODO possible overdue bug 'ma.name as activity')
if(isset($payload['till_date'])) ->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id')
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$payload['till_date'])->orderBy('end_date', 'asc')->get(); ->where('ma.proyek_id', $id)
else ->orderBy('comment_by')
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); ->take(2)
->get();
$result->overdueActivities = $overdueActivities; $data->actual_cost = $actualCost;
$data->progress = $progress;
$data->comment = $commentActivity;
$data->man_power = $manpowers;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); return response()->json(['status'=>'success','code'=>200,'data'=> $data], 200);
} }
public function getInvoiceIntegration(Request $request) { private function httpReq($search){
$search = urlencode($request->search); $ch = curl_init();
if(empty($search)) curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION));
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH');
$response = MasterFunctionsHelper::curlReq($url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w'));
$info = curl_getinfo($ch);
return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); $output = curl_exec($ch);
} curl_close($ch);
public function getReportDistribution(Request $request){ return json_decode($output);
$payload = $request->all();
if(empty($payload['project_id']) || !is_int((int)$payload['project_id']))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$reports = DB::table('assign_material_to_activity as ama')
->select('u.name', 'a.name as activity_name', 'ama.qty_planning', 'ram.qty as qty_real','rm.description as material_name', 'rm.uom as material_unit',
'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date')
->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id')
->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->join('m_users as u', 'u.id', '=', 'ram.user_id')
->where('ama.proyek_id', '=', $payload['project_id'])
->whereNotNull('ram.lat')
->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']])
->get();
return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200);
} }
public function getSCurve(Request $request){
$data = MasterFunctionsHelper::getSCurve($request);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200);
}
} }

0
app/Imports/ActivityImport.php

29
app/Models/Activity.php

@ -85,10 +85,32 @@ class Activity extends Model
private function updateBobot($isDelete = false) private function updateBobot($isDelete = false)
{ {
<<<<<<< HEAD
$root = Activity::where('version_gantt_id', $this->version_gantt_id) $root = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id) ->where("proyek_id", $this->proyek_id)
->whereNull('parent_id') ->whereNull('parent_id')
->first(); ->first();
=======
$rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->where('type_activity', 'header')
->first();
if(Activity::where('version_gantt_id', $this->version_gantt_id)->where("proyek_id", $this->proyek_id)->where('type_activity', 'header')->count() == 0) {
$totalCost = Activity::select(
DB::raw('sum(cast(rencana_biaya as double precision))')
)
->where("proyek_id", $this->proyek_id)
->where("version_gantt_id", $this->version_gantt_id)
->whereNull("parent_id")
->first();
} else {
$totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))
->where("proyek_id", $this->proyek_id)
->where("version_gantt_id", $this->version_gantt_id)
->where("parent_id", $rootActivity->id)
->first();
}
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
if($root->rencana_biaya > 0){ if($root->rencana_biaya > 0){
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get(); $activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get();
@ -184,7 +206,14 @@ class Activity extends Model
public function getJobsDoneAttribute() public function getJobsDoneAttribute()
{ {
<<<<<<< HEAD
if(!ReportActivityMaterial::where('activity_id', $this->id)->first()) if(!ReportActivityMaterial::where('activity_id', $this->id)->first())
=======
$tmpPercentage = [];
if(!ReportActivityMaterial::where('activity_id', $this->id)->first())
return 0;
if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get())
>>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6
return 0; return 0;
if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get()) if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get())
return 0; return 0;

1
bootstrap/app.php

@ -97,7 +97,6 @@ $app->routeMiddleware([
*/ */
$app->register(App\Providers\CatchAllOptionsRequestsProvider::class); $app->register(App\Providers\CatchAllOptionsRequestsProvider::class);
$app->register(App\Providers\AuthServiceProvider::class); $app->register(App\Providers\AuthServiceProvider::class);
$app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class); $app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class); $app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);

Loading…
Cancel
Save