Browse Source

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

Reviewed-on: OSPRO/ADW-Backend#1
pull/3/head
yusuf 2 years ago
parent
commit
6500375845
  1. 1
      .gitignore
  2. 20
      activity_log.txt
  3. 436
      app/Http/Controllers/ActivityController.php
  4. 174
      app/Http/Controllers/ActivityDokumenController.php
  5. 433
      app/Http/Controllers/AssignMaterialController.php
  6. 135
      app/Http/Controllers/AuthController.php
  7. 21
      app/Http/Controllers/Controller.php
  8. 455
      app/Http/Controllers/DashboardController.php
  9. 155
      app/Http/Controllers/DivisiController.php
  10. 415
      app/Http/Controllers/ProjectController.php
  11. 179
      app/Http/Controllers/ProjectDokumenController.php
  12. 297
      app/Http/Controllers/RequestMaterialController.php
  13. 191
      app/Http/Controllers/RoleController.php
  14. 344
      app/Http/Controllers/UserToActivityController.php
  15. 45
      app/Models/AssignMaterial.php
  16. 36
      app/Models/RequestMaterial.php
  17. 39
      app/Models/UserToActivity.php
  18. 6
      config/api.php
  19. 4
      config/auth.php
  20. 5
      config/jwt.php
  21. 0
      database/sql/001-absensi.sql
  22. 51
      routes/web.php

1
.gitignore vendored

@ -1,5 +1,6 @@
/vendor /vendor
/.idea /.idea
/assets
/storage /storage
Homestead.json Homestead.json
Homestead.yaml Homestead.yaml

20
activity_log.txt

@ -0,0 +1,20 @@
2022-07-12 00:13:26: 1379 Penentuan harga project
Added: (10000000 * 1), Cost plan old: 0 | +10000000
Data type (double * double), double | double
Data type origin (double * NULL), string | double
------
2022-07-12 00:13:32: 1378 Contract Management
Deleted: (10000000 * 1), Cost plan old: 20000000 | -10000000
Data type (double * double), double | double
Data type origin (double * double), string | double
------
2022-07-12 00:13:38: 1377 Brainstorming peningkatan layanan masyarakat
Deleted: (10000000 * 1), Cost plan old: 20000000 | -10000000
Data type (double * double), double | double
Data type origin (double * double), string | double
------
2022-07-12 00:13:47: 1379 Penentuan harga project
Deleted: (10000000 * 1), Cost plan old: 10000000 | -0
Data type (double * double), double | double
Data type origin (double * double), string | double
------

436
app/Http/Controllers/ActivityController.php

@ -11,7 +11,6 @@ use App\Models\UserToActivity;
use App\Models\CommentActivity; use App\Models\CommentActivity;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use App\Models\AssignTools; use App\Models\AssignTools;
use App\Models\OfficeHours;
use App\Models\VersionGantt; use App\Models\VersionGantt;
use App\Models\Holiday; use App\Models\Holiday;
use App\Models\ReportActivity; use App\Models\ReportActivity;
@ -33,7 +32,7 @@ class ActivityController extends Controller
} }
return response()->json(['status'=>'success','data'=>$dataGantt,'code'=>200], 200); return response()->json(['status'=>'success','data'=>$dataGantt,'code'=>200], 200);
} }
private function getDataActivity($id) private function getDataActivity($id)
{ {
@ -52,7 +51,7 @@ class ActivityController extends Controller
}else{ }else{
$data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get(); $data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('id', 'asc')->get();
} }
foreach($data as $objRow){ foreach($data as $objRow){
$objRow->text = $objRow->name; $objRow->text = $objRow->name;
if($objRow->parent_id){ if($objRow->parent_id){
@ -153,14 +152,14 @@ class ActivityController extends Controller
$dataPlan = AssignMaterial::where('activity_id', $id)->get(); $dataPlan = AssignMaterial::where('activity_id', $id)->get();
$tmpPercentage1 = []; $tmpPercentage1 = [];
if(!$dataPlan->isEmpty()){ if(!$dataPlan->isEmpty()){
foreach ($dataPlan as $value) { foreach ($dataPlan as $value) {
$qty_plan = $value->qty_planning; $qty_plan = $value->qty_planning;
$status_activity = $value->status_activity; $status_activity = $value->status_activity;
$getDataVolActual = ReportActivityMaterial::where('assign_material_id', '=', $value->id)->sum("qty"); $getDataVolActual = ReportActivityMaterial::where('assign_material_id', '=', $value->id)->sum("qty");
$percentage1 = ($getDataVolActual * 100) / $qty_plan; $percentage1 = ($getDataVolActual * 100) / $qty_plan;
if($status_activity == 'done'){ if($status_activity == 'done'){
$tmpPercentage1[] = 100; $tmpPercentage1[] = 100;
} }
else{ else{
$tmpPercentage1[] = $percentage1 >= 100 ? 90 : $percentage1; $tmpPercentage1[] = $percentage1 >= 100 ? 90 : $percentage1;
} }
@ -169,7 +168,7 @@ class ActivityController extends Controller
$totalPercentage = array_sum($tmpPercentage1) > 0 ? array_sum($tmpPercentage1) / count($tmpPercentage1) : 0; $totalPercentage = array_sum($tmpPercentage1) > 0 ? array_sum($tmpPercentage1) / count($tmpPercentage1) : 0;
}else{ }else{
$totalPercentage = 0; $totalPercentage = 0;
} }
return $totalPercentage; return $totalPercentage;
@ -343,7 +342,7 @@ class ActivityController extends Controller
} }
if($data){ if($data){
$upactual = false; $upactual = false;
$result = $data->update($dataUpdate); $result = $data->update($dataUpdate);
if($result){ if($result){
if($parent && (int)$parent > 0){ if($parent && (int)$parent > 0){
$this->updateCostPlanning($parent); $this->updateCostPlanning($parent);
@ -376,8 +375,8 @@ class ActivityController extends Controller
return response()->json(['status'=>'failed','message'=>'data activity not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data activity not found!','code'=>400], 400);
die(); die();
} }
if($result){ if($result){
return response()->json(['status'=>'success','message'=>'data activity successfully updated!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'data activity successfully updated!','code'=>200], 200);
}else{ }else{
@ -427,7 +426,7 @@ class ActivityController extends Controller
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity not found!','code'=>400], 400); return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity not found!','code'=>400], 400);
die(); die();
} }
if($delete){ if($delete){
return response()->json(['status'=>'success', "action"=>"deleted",'message'=>'data activity successfully deleted!','code'=>200], 200); return response()->json(['status'=>'success', "action"=>"deleted",'message'=>'data activity successfully deleted!','code'=>200], 200);
@ -507,7 +506,7 @@ class ActivityController extends Controller
{ {
$biayaActual = Activity::where("parent_id", $id)->sum("biaya_actual"); $biayaActual = Activity::where("parent_id", $id)->sum("biaya_actual");
$dataActivity = Activity::find($id); $dataActivity = Activity::find($id);
$dataUpdate = array( $dataUpdate = array(
"biaya_actual" => $biayaActual, "biaya_actual" => $biayaActual,
"updated_by" => $this->currentName "updated_by" => $this->currentName
@ -534,136 +533,21 @@ class ActivityController extends Controller
public function calculateAllCost($activity_id, $proyek_id) public function calculateAllCost($activity_id, $proyek_id)
{ {
$humanCostPlanning = $this->calculateHuman($activity_id, $proyek_id);
$materialCostPlanning = 0; $materialCostPlanning = 0;
$toolsCostPlanning = 0; $toolsCostPlanning = 0;
$allCost = $humanCostPlanning + $materialCostPlanning + $toolsCostPlanning; $allCost = $materialCostPlanning + $toolsCostPlanning;
return $allCost; return $allCost;
} }
private function calculateHuman($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();
$totalCost = 0;
foreach ($dataHuman as $human) {
$uom = $human->uom_standart_rate;
$totalCost += $this->calculateHumanCost($human, $activity_id);
}
return $totalCost;
}
private function calculateHumanCost($human, $activity_id)
{
$activity = Activity::find($activity_id);
$duration = $activity->duration;
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100;
$totalCost = ($standarRate*$duration)*$maxUsed;
return $totalCost;
}
private function calculateHumanDay($human, $activity_id)
{
$activity = Activity::find($activity_id);
$duration = $activity->duration;
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100;
$totalCost = ($standarRate*$duration)*$maxUsed;
return $totalCost;
}
private function calculateHumanHours($human, $activity_id, $proyek_id)
{
$hours = OfficeHours::where("proyek_id", $proyek_id)->first();
$activity = Activity::find($activity_id);
$ganttId = $activity->version_gantt_id;
$verGantt = VersionGantt::find($ganttId);
$holiday = Holiday::where("version_gantt_id", $ganttId)->where("proyek_id", $proyek_id)->pluck("date");
$dateHoliday = $holiday->all();
$configOff = $verGantt->config_dayoff;
if($configOff && $configOff!= ""){
$dayOff = explode(",", $verGantt->config_dayoff);
$dayOff = array_map(
function($value) { return (int)$value; },
$dayOff
);
}else{
$dayOff = [];
}
$begin = new \DateTime($activity->start_date);
$end = new \DateTime($activity->end_date);
$end = $end->modify( '+1 day' );
$interval = \DateInterval::createFromDateString('1 day');
$period = new \DatePeriod($begin, $interval, $end);
$totalCost = 0;
foreach ($period as $dt) {
$weekDay = $dt->format("w");
$currentDay = $dt->format("Y-m-d");
if(!in_array($weekDay, $dayOff) && !in_array($currentDay, $dateHoliday))
{
$totalHours = $this->getHourInDay($hours, $weekDay);
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100;
$totalCost += ($standarRate*$totalHours)*$maxUsed;
}
}
return $totalCost;
}
private function getHourInDay($hours, $day)
{
$totalHours = 0;
switch ($day) {
case 1:
$totalHours = ceil(abs(((strtotime($hours->monday_end)-strtotime($hours->monday_start))/60)/60));
break;
case 2:
$totalHours = ceil(abs(((strtotime($hours->tuesday_end)-strtotime($hours->tuesday_start))/60)/60));
break;
case 3:
$totalHours = ceil(abs(((strtotime($hours->wednesday_end)-strtotime($hours->wednesday_start))/60)/60));
break;
case 4:
$totalHours = ceil(abs(((strtotime($hours->thursday_end)-strtotime($hours->thursday_start))/60)/60));
break;
case 5:
$totalHours = ceil(abs(((strtotime($hours->friday_end)-strtotime($hours->friday_start))/60)/60));
break;
case 6:
$totalHours = ceil(abs(((strtotime($hours->saturday_end)-strtotime($hours->saturday_start))/60)/60));
break;
default:
$totalHours = ceil(abs(((strtotime($hours->sunday_end)-strtotime($hours->sunday_start))/60)/60));
break;
}
return $totalHours;
}
private function calculateMaterial($activity_id, $proyek_id)
{
$totalCost = AssignMaterial::selectRaw("ISNULL(qty_planning,0)*ISNULL(budget,0) as totalCost")->where("proyek_id", $proyek_id)->where("activity_id", $activity_id)->sum("totalCost");
return $totalCost;
}
private function calculateTools($activity_id, $proyek_id)
{
}
public function getPercentagePerDay(Request $request) public function getPercentagePerDay(Request $request)
{ {
$dataPayload = $request->all(); $dataPayload = $request->all();
$allGantt = []; $allGantt = [];
foreach ($dataPayload['project_id'] as $val) { foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getMaxVersionGantt($val); $allGantt[] = $this->getMaxVersionGantt($val);
} }
$dataFinal=[]; $dataFinal=[];
foreach ($allGantt as $val) { foreach ($allGantt as $val) {
$dataProject = Project::find($val['proyek_id']); $dataProject = Project::find($val['proyek_id']);
@ -699,7 +583,7 @@ class ActivityController extends Controller
$minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); $minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date");
$maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); $maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date");
} }
$begin = new \DateTime($minDate); $begin = new \DateTime($minDate);
$end = new \DateTime($maxDate); $end = new \DateTime($maxDate);
$end = $end->modify( '+1 day' ); $end = $end->modify( '+1 day' );
@ -712,14 +596,14 @@ class ActivityController extends Controller
}else{ }else{
$totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
} }
$totalRencanaBudget = $totalRencanaBudget->sum; $totalRencanaBudget = $totalRencanaBudget->sum;
$currentPercentage = 0; $currentPercentage = 0;
$dataDate = []; $dataDate = [];
$dataPercen = []; $dataPercen = [];
foreach ($period as $dt) { foreach ($period as $dt) {
$weekDay = $dt->format("w"); $weekDay = $dt->format("w");
$currentDate = $dt->format("Y-m-d"); $currentDate = $dt->format("Y-m-d");
if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday)) if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday))
{ {
$totalPercentage = 0; $totalPercentage = 0;
@ -730,7 +614,7 @@ class ActivityController extends Controller
}else{ }else{
$dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date)")->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get();
} }
foreach ($dataActivity as $activity) { foreach ($dataActivity as $activity) {
$duration = $activity->duration; $duration = $activity->duration;
if($totalRencanaBudget > 0 && $duration > 0){ if($totalRencanaBudget > 0 && $duration > 0){
@ -764,12 +648,12 @@ class ActivityController extends Controller
public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date) public function getCalculateCurvaS(Request $request) // for adw (plan & actual == date)
{ {
$dataPayload = $request->all(); $dataPayload = $request->all();
$allGantt = []; $allGantt = [];
if(isset($dataPayload['gannt_id'])){ if(isset($dataPayload['gannt_id'])){
$allGantt = $dataPayload['gannt_id']; $allGantt = $dataPayload['gannt_id'];
}else{ }else{
foreach ($dataPayload['project_id'] as $val) { foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getMaxVersionGantt($val); $allGantt[] = $this->getMaxVersionGantt($val);
} }
@ -790,7 +674,7 @@ class ActivityController extends Controller
->where("ama.proyek_id", $keyGantt['proyek_id']) ->where("ama.proyek_id", $keyGantt['proyek_id'])
->join('m_activity as a', 'a.id', '=', 'ama.activity_id') ->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->min("plan_date"); ->min("plan_date");
$maxDate = DB::table('assign_material_to_activity as ama') $maxDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id']) ->where("ama.proyek_id", $keyGantt['proyek_id'])
@ -804,7 +688,7 @@ class ActivityController extends Controller
$interval = \DateInterval::createFromDateString('1 day'); $interval = \DateInterval::createFromDateString('1 day');
$period = new \DatePeriod($begin, $interval, $end); $period = new \DatePeriod($begin, $interval, $end);
$arr_ActualM = []; $arr_ActualM = [];
$tempDate = []; $tempDate = [];
$tempPercentage = []; $tempPercentage = [];
$tempTtlPercentPlan=0; $tempTtlPercentPlan=0;
$tempTtlPercentActual=0; $tempTtlPercentActual=0;
@ -814,12 +698,12 @@ class ActivityController extends Controller
$currentProgressActivity = 0; $currentProgressActivity = 0;
$currentBCWP = 0; $currentBCWP = 0;
$budgetControlBCWP = 0; $budgetControlBCWP = 0;
foreach ($period as $dt) { foreach ($period as $dt) {
$dataPlanM = DB::table('assign_material_to_activity as ama') $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') ->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') ->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('ama.proyek_id', '=', $keyGantt['proyek_id']) ->where('ama.proyek_id', '=', $keyGantt['proyek_id'])
->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id']) ->where('a.version_gantt_id', '=', $keyGantt['last_gantt_id'])
->whereDate('ama.plan_date', $dt->format("Y-m-d")) ->whereDate('ama.plan_date', $dt->format("Y-m-d"))
->get(); ->get();
@ -833,7 +717,7 @@ class ActivityController extends Controller
$dataTempPlan = []; $dataTempPlan = [];
$x = 0; $x = 0;
$sumPercentagePlan=0; $sumPercentagePlan=0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0; $totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0; $totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
foreach ($dataPlanM as $keyPlanM) { foreach ($dataPlanM as $keyPlanM) {
@ -845,13 +729,13 @@ class ActivityController extends Controller
$dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id; $dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id;
$dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning; $dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning;
$dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date; $dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date;
$dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity; $dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity;
$dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning; $dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan; $dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan;
$dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual; $dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual;
$dataTempPlan [$x]['duration'] = $keyPlanM->duration; $dataTempPlan [$x]['duration'] = $keyPlanM->duration;
$dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress; $dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress;
$dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; $dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning; $sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100; $totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100;
$dataTempPlan [$x]['totalBCWP'] = $totalBCWP; $dataTempPlan [$x]['totalBCWP'] = $totalBCWP;
@ -869,34 +753,34 @@ class ActivityController extends Controller
->first(); ->first();
$dataTempReport [$w]['activity_id'] = $keyActualM->activity_id; $dataTempReport [$w]['activity_id'] = $keyActualM->activity_id;
$dataTempReport [$w]['qty'] = $keyActualM->qty; $dataTempReport [$w]['qty'] = $keyActualM->qty;
$dataTempReport [$w]['report_date'] = $keyActualM->report_date; $dataTempReport [$w]['report_date'] = $keyActualM->report_date;
$dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning; $dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning;
$dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan; $dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan;
$dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual; $dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual;
$dataTempReport [$w]['duration'] = $keyActualM->duration; $dataTempReport [$w]['duration'] = $keyActualM->duration;
$dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress; $dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress;
$dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; $dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
$sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning; $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
$totalACWP += $keyActualM->biaya_actual/$keyActualM->duration; $totalACWP += $keyActualM->biaya_actual/$keyActualM->duration;
$dataTempReport [$w]['totalacwp'] = $totalACWP; $dataTempReport [$w]['totalacwp'] = $totalACWP;
$w++; $w++;
} }
$arr_ActualM[] = array( $arr_ActualM[] = array(
'date'=>$dt->format("Y-m-d"), 'date'=>$dt->format("Y-m-d"),
'percentPlan'=>$sumPercentagePlan, 'percentPlan'=>$sumPercentagePlan,
'percentActual'=>$sumPercentageActual, 'percentActual'=>$sumPercentageActual,
'plan'=>$dataTempPlan, 'plan'=>$dataTempPlan,
'actual'=>$dataTempReport, 'actual'=>$dataTempReport,
); );
if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){ if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){
if($dt->format("w")==1){ if($dt->format("w")==1){
if($totalACWP > 0 ){ if($totalACWP > 0 ){
$budgetControlACWP = $currentACWP + $totalACWP; $budgetControlACWP = $currentACWP + $totalACWP;
} }
if($totalBCWP > 0 ){ if($totalBCWP > 0 ){
$budgetControlBCWP = $currentBCWP + $totalBCWP; $budgetControlBCWP = $currentBCWP + $totalBCWP;
} }
$tempTtlPercentPlan+= $sumPercentagePlan; $tempTtlPercentPlan+= $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual; $tempTtlPercentActual+= $sumPercentageActual;
@ -916,34 +800,39 @@ class ActivityController extends Controller
$tempTtlPercentPlan = 0; $tempTtlPercentPlan = 0;
$tempTtlPercentActual = 0; $tempTtlPercentActual = 0;
} }
}else{ }else{
$tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2)); $tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2));
$tempDate[] = array($dt->format("Y-m-d"), 0, 0); $tempDate[] = array($dt->format("Y-m-d"), 0, 0);
} }
} }
if(round($totalACWP,0) > $totalRencanaBudget){ if(round($totalACWP,0) > $totalRencanaBudget){
$estimatedCost = round($totalACWP,0)+0; $estimatedCost = round($totalACWP,0)+0;
}else{ }else{
$estimatedCost = ($totalRencanaBudget+0); $estimatedCost = ($totalRencanaBudget+0);
} }
$costDeviation = $totalRencanaBudget - $estimatedCost; $costDeviation = $totalRencanaBudget - $estimatedCost;
if($costDeviation > 0){
$potential = "SAVING";
} else {
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
}
$dataResponse = array( $dataResponse = array(
"date" =>$tempDate, "date" =>$tempDate,
"percentage" =>$tempPercentage, "percentage" =>$tempPercentage,
"data_details" =>$arr_ActualM, "data_details" =>$arr_ActualM,
"budget_control" =>array("current_budget"=> $totalRencanaBudget, "budget_control" =>array("current_budget"=> $totalRencanaBudget,
"acwp" => round($totalACWP,0), "acwp" => round($totalACWP,0),
"bcwp" => round($totalBCWP,0), "bcwp" => round($totalBCWP,0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)), "rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)),
"add_cost_to_complete" => 0, "add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost, "estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation, "cost_deviation" => $costDeviation,
"potential" => $costDeviation > 0 ? "SAVING" : $costDeviation == 0 ? "ON BUDGET" : "OVERRUN" "potential" => $potential,
) )
); );
$dataFinal[] = array( $dataFinal[] = array(
"proyek_name"=> $dataProject->nama, "proyek_name"=> $dataProject->nama,
"data"=>$dataResponse, "data"=>$dataResponse,
@ -952,196 +841,17 @@ class ActivityController extends Controller
} }
return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200); return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200);
}
public function getCalculateCurvaSBackup(Request $request)
{
$dataPayload = $request->all();
$allGantt = [];
foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getMaxVersionGantt($val);
}
$dataFinal=[];
foreach ($allGantt as $val) {
$dataProject = Project::find($val['proyek_id']);
$holidays = Holiday::where("version_gantt_id", $val['last_gantt_id'])->where("proyek_id", $val['proyek_id'])->get();
$dateHoliday = []; //$holiday->all();
foreach ($holidays as $holiday) {
$startH = new \DateTime($holiday->date);
$endH = clone $startH;
$endH->modify('+'.$holiday->duration.' day');
$intervalH = \DateInterval::createFromDateString('1 day');
$periodH = new \DatePeriod($startH, $intervalH, $endH);
foreach ($periodH as $dt) {
$dateHoliday[] = $dt->format("Y-m-d");
}
}
$verGantt = VersionGantt::find($val['last_gantt_id']);
$configOff = $verGantt->config_dayoff;
if($configOff && $configOff!= ""){
$dayOff = explode(",", $verGantt->config_dayoff);
$dayOff = array_map(
function($value) { return (int)$value; },
$dayOff
);
}else{
$dayOff = [];
}
$checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count();
if($checkHeader > 0){
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
$minDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date");
$maxDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date");
}else{
$minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date");
$maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date");
}
$begin = new \DateTime($minDate);
$end = new \DateTime($maxDate);
$end2 = new \DateTime($maxDate);
$end2 = $end2->modify( '-1 day' );
$interval = \DateInterval::createFromDateString('1 day');
$period = new \DatePeriod($begin, $interval, $end);
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
if($dataHeader){
$totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as bigint))'))->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
}else{
$totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as bigint))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
}
$totalRencanaBudget = $totalRencanaBudget->sum;
$currentPercentage = 0;
$currentACWP = 0;
$budgetControlACWP = 0;
$currentProgressActivity = 0;
$currentBCWP = 0;
$budgetControlBCWP = 0;
$dataDate = [];
$dataPercen = [];
$testdata = [];
$countWeek = 0;
foreach ($period as $dt) {
$weekDay = $dt->format("w");
$currentDate = $dt->format("Y-m-d");
$testdata[] = array('weekday' => $weekDay, 'date' =>$currentDate, 'dayof' => $dayOff);
$totalPercentage = isset($totalPercentage) ? $totalPercentage : 0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalProgressActivity = isset($totalProgressActivity) ? $totalProgressActivity : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday))
{
$dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date) - INTERVAL '1 DAY'")->where('type_activity', 'task')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get();
foreach ($dataActivity as $activity) {
$duration = $activity->duration;
if($totalRencanaBudget > 0 && $duration > 0){
$totalPercentage += $activity->bobot_planning/$duration;
if($activity->biaya_actual > 0 && $activity->persentase_progress){
$totalACWP += $activity->biaya_actual/$duration;
$totalProgressActivity += (($activity->persentase_progress*$activity->bobot_planning)/100)/$duration;
$totalBCWP += (((($activity->persentase_progress*$activity->bobot_planning)/100)/$duration)* $totalRencanaBudget)/100;
}
}
}
}
if($currentDate == $end2->format('Y-m-d')){
$currentPercentage = round(($currentPercentage + $totalPercentage), 0);
if($totalACWP > 0 ){
$budgetControlACWP = $currentACWP + $totalACWP;
}
if($totalBCWP > 0 ){
$budgetControlBCWP = $currentBCWP + $totalBCWP;
}
$currentACWP = $totalACWP == 0 ? null : $currentACWP + $totalACWP;
$currentProgressActivity = $totalProgressActivity == 0 ? null : round(($currentProgressActivity + $totalProgressActivity),0);
$currentBCWP = $totalBCWP == 0 ? null :$currentBCWP + $totalBCWP;
$currentPercentage = $currentPercentage > 100 ? 100 : $currentPercentage;
$currentProgressActivity = $currentProgressActivity > 100 ? 100 : $currentProgressActivity;
$dataDate[] = array($currentDate, round($currentBCWP,0), round($currentACWP,0));
$dataPercen[] = array($currentPercentage, $currentProgressActivity);
$totalPercentage = 0;
$totalACWP = 0;
$totalProgressActivity = 0;
$totalBCWP = 0;
}else if($weekDay == "0"){
$currentPercentage = round(($currentPercentage + $totalPercentage), 0);
if($totalACWP > 0 ){
$budgetControlACWP = $currentACWP + $totalACWP;
}
if($totalBCWP > 0 ){
$budgetControlBCWP = $currentBCWP + $totalBCWP;
}
$currentACWP = $totalACWP == 0 ? null : $currentACWP + $totalACWP;
$currentProgressActivity = $totalProgressActivity == 0 ? null : round(($currentProgressActivity + $totalProgressActivity),0);
$currentBCWP = $totalBCWP == 0 ? null :$currentBCWP + $totalBCWP;
$currentPercentage = $currentPercentage > 100 ? 100 : $currentPercentage;
$currentProgressActivity = $currentProgressActivity > 100 ? 100 : $currentProgressActivity;
$dataDate[] = array($currentDate, round($currentBCWP,0), round($currentACWP,0));
$dataPercen[] = array($currentPercentage, $currentProgressActivity);
$totalPercentage = 0;
$totalACWP = 0;
$totalProgressActivity = 0;
$totalBCWP = 0;
}
}
if(round($budgetControlACWP,0) > $totalRencanaBudget){
$estimatedCost = round($budgetControlACWP,0)+0;
}else{
$estimatedCost = ($totalRencanaBudget+0);
}
$costDeviation = $totalRencanaBudget - $estimatedCost;
$dataResponse = array(
"date" =>$dataDate,
"percentage" =>$dataPercen,
"budget_control" =>array("current_budget"=> $totalRencanaBudget,
"acwp" => round($budgetControlACWP,0),
"bcwp" => round($budgetControlBCWP,0),
"rem_to_complete" => ($totalRencanaBudget - round($budgetControlACWP,0)),
"add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation,
"potential" => $costDeviation > 0 ? "SAVING" : $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"
)
);
$dataFinal[] = array(
"proyek_name"=> $dataProject->nama,
"data"=>$dataResponse
);
}
if($dataFinal){
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'test' => array('current'=>$currentDate,'max' =>$end2->format('Y-m-d')), 'totalRecord'=>1], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list percentage day, please try again later!','code'=>400], 400);
}
} }
public function getCalculateCurvaSDays(Request $request) public function getCalculateCurvaSDays(Request $request)
{ {
$dataPayload = $request->all(); $dataPayload = $request->all();
$allGantt = []; $allGantt = [];
foreach ($dataPayload['project_id'] as $val) { foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getMaxVersionGantt($val); $allGantt[] = $this->getMaxVersionGantt($val);
} }
$dataFinal=[]; $dataFinal=[];
foreach ($allGantt as $val) { foreach ($allGantt as $val) {
$dataProject = Project::find($val['proyek_id']); $dataProject = Project::find($val['proyek_id']);
@ -1176,7 +886,7 @@ class ActivityController extends Controller
$minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date"); $minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date");
$maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date"); $maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date");
} }
$begin = new \DateTime($minDate); $begin = new \DateTime($minDate);
$end = new \DateTime($maxDate); $end = new \DateTime($maxDate);
$interval = \DateInterval::createFromDateString('1 day'); $interval = \DateInterval::createFromDateString('1 day');
@ -1187,7 +897,7 @@ class ActivityController extends Controller
}else{ }else{
$totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first(); $totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as integer))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
} }
$totalRencanaBudget = $totalRencanaBudget->sum; $totalRencanaBudget = $totalRencanaBudget->sum;
$currentPercentage = 0; $currentPercentage = 0;
$currentACWP = 0; $currentACWP = 0;
@ -1196,7 +906,7 @@ class ActivityController extends Controller
$dataDate = []; $dataDate = [];
$dataPercen = []; $dataPercen = [];
$testdata = []; $testdata = [];
foreach ($period as $dt) { foreach ($period as $dt) {
$weekDay = $dt->format("w"); $weekDay = $dt->format("w");
$currentDate = $dt->format("Y-m-d"); $currentDate = $dt->format("Y-m-d");
$testdata[] = array('weekday' => $weekDay, 'date' =>$currentDate); $testdata[] = array('weekday' => $weekDay, 'date' =>$currentDate);
@ -1208,19 +918,19 @@ class ActivityController extends Controller
$totalBCWP = 0; $totalBCWP = 0;
$dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date) - INTERVAL '1 DAY'")->where('type_activity', 'task')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get(); $dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date) - INTERVAL '1 DAY'")->where('type_activity', 'task')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get();
foreach ($dataActivity as $activity) { foreach ($dataActivity as $activity) {
$duration = $activity->duration; $duration = $activity->duration;
if($totalRencanaBudget > 0 && $duration > 0){ if($totalRencanaBudget > 0 && $duration > 0){
$totalPercentage += $activity->bobot_planning/$duration; $totalPercentage += $activity->bobot_planning/$duration;
if($activity->biaya_actual > 0 && $activity->persentase_progress){ if($activity->biaya_actual > 0 && $activity->persentase_progress){
$totalACWP += $activity->biaya_actual/$duration; $totalACWP += $activity->biaya_actual/$duration;
$totalProgressActivity += (($activity->persentase_progress*$activity->bobot_planning)/100)/$duration; $totalProgressActivity += (($activity->persentase_progress*$activity->bobot_planning)/100)/$duration;
$totalBCWP += (((($activity->persentase_progress*$activity->bobot_planning)/100)/$duration)* $totalRencanaBudget)/100; $totalBCWP += (((($activity->persentase_progress*$activity->bobot_planning)/100)/$duration)* $totalRencanaBudget)/100;
} }
} }
} }
$currentPercentage = round(($currentPercentage + $totalPercentage), 0); $currentPercentage = round(($currentPercentage + $totalPercentage), 0);
$currentACWP = $totalACWP == 0 ? null : $currentACWP + $totalACWP; $currentACWP = $totalACWP == 0 ? null : $currentACWP + $totalACWP;
$currentProgressActivity = $totalProgressActivity == 0 ? null : round(($currentProgressActivity + $totalProgressActivity),0); $currentProgressActivity = $totalProgressActivity == 0 ? null : round(($currentProgressActivity + $totalProgressActivity),0);
$currentBCWP = $totalBCWP == 0 ? null :$currentBCWP + $totalBCWP; $currentBCWP = $totalBCWP == 0 ? null :$currentBCWP + $totalBCWP;
@ -1230,7 +940,7 @@ class ActivityController extends Controller
$dataDate[] = array($currentDate, $currentBCWP, $currentACWP); $dataDate[] = array($currentDate, $currentBCWP, $currentACWP);
$dataPercen[] = array($currentPercentage, $currentProgressActivity); $dataPercen[] = array($currentPercentage, $currentProgressActivity);
}else{ }else{
$dataDate[] = $currentDate; $dataDate[] = $currentDate;
$dataPercen[] = array($currentPercentage,$currentProgressActivity); $dataPercen[] = array($currentPercentage,$currentProgressActivity);
} }
@ -1286,7 +996,7 @@ class ActivityController extends Controller
foreach($activities as $activity) { foreach($activities as $activity) {
$activity_id = $activity->id; $activity_id = $activity->id;
$countReports = ReportActivity::where('activity_id', $activity_id)->count(); $countReports = ReportActivity::where('activity_id', $activity_id)->count();
if ($countReports === 1) { if ($countReports === 1) {
$dataReports = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->get(); $dataReports = ReportActivity::where('activity_id', $activity_id)->orderBy('report_date')->get();
foreach($dataReports as $dr) { foreach($dataReports as $dr) {
@ -1318,4 +1028,4 @@ class ActivityController extends Controller
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200);
} }
} }

174
app/Http/Controllers/ActivityDokumenController.php

@ -7,93 +7,89 @@ use App\Models\ActivityDokumen;
class ActivityDokumenController extends Controller class ActivityDokumenController extends Controller
{ {
public function dokumenByActivityId($id){
if($id && $id!="" && (int)$id > 0){ public function dokumenByActivityId($id){
$dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400);
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200);
}else{ $dataDokumen = ActivityDokumen::where("activity_id", $id)->get();
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200);
} }
}
public function delete($id)
public function delete($id) {
{ if(empty($id) || !is_int((int)$id))
if($id && $id!="" && (int)$id > 0){ return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
$dokumen = ActivityDokumen::find($id);
if($dokumen){ $document = ActivityDokumen::find($id);
if(file_exists($this->pathActivityDocument.$dokumen->file)){
unlink($this->pathActivityDocument.$dokumen->file); if(!$document)
} return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$dokumen->delete();
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); if(file_exists($this->pathActivityDocument.$document->file))
}else{ unlink($this->pathActivityDocument.$document->file);
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400);
} $document->delete();
}else{ return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200);
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); }
}
} public function uploadProjectDokumen(Request $request)
{
public function uploadProjectDokumen(Request $request) if(!$request->hasFile('dokumen'))
{ return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400);
if($request->hasFile('dokumen')){
$activity_id = $request->activity_id; $activity_id = $request->activity_id;
$dokumen = $request->file('dokumen'); $document = $request->file('dokumen');
$extension = $dokumen->extension(); $name = $document->getClientOriginalName();
$name = $dokumen->getClientOriginalName();
$result = $document->move($this->pathActivityDocument, $name);
$result = $dokumen->move($this->pathActivityDocument, $name);
if($result){ if(!$result)
$data = [ return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
'activity_id' => (int)$activity_id,
'file' => $name, $data = [
'description' => $request->description 'activity_id' => (int)$activity_id,
]; 'file' => $name,
'description' => $request->description
$result = ActivityDokumen::create($data); ];
if($result){ $result = ActivityDokumen::create($data);
return response()->json(['status'=>'success','message'=>'file upload is successfully!','code'=>200], 200);
}else{ if(!$result){
unlink($this->pathActivityDocument.$name); unlink($this->pathActivityDocument.$name);
return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
} }
}else{ return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200);
return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); }
}
}else{ public function searchDocProject(Request $request){
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); $payload = $request->all();
}
} $dataBuilder = $this->setUpPayload($payload, 'm_document_activity');
$builder = $dataBuilder['builder'];
public function searchDocProject(Request $request){ $countBuilder = $dataBuilder['count'];
$payload = $request->all(); $dataGet = $builder->get();
$dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); $totalRecord = $countBuilder->count();
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
$dataGet = $builder->get(); }
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); public function downloadDokumen($id)
} {
if(empty($id) || !is_int((int)$id))
public function downloadDokumen($id) return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
{
if($id && $id!="" && (int)$id > 0){ $document = ActivityDokumen::find($id);
$dokumen = ActivityDokumen::find($id);
if($dokumen){ if(!$document)
if(file_exists($this->pathActivityDocument.$dokumen->file)){ return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
$pathToFile = $this->pathActivityDocument.$dokumen->file;
return response()->download($pathToFile); if(file_exists($this->pathActivityDocument.$document->file)){
}else{ $pathToFile = $this->pathActivityDocument.$document->file;
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); return response()->download($pathToFile);
} }
}else{
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
} }
}else{
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
}
}
} }

433
app/Http/Controllers/AssignMaterialController.php

@ -4,277 +4,178 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use App\Models\MaterialResource;
use App\Models\RequestMaterial; use App\Models\RequestMaterial;
use App\Models\Activity;
use App\Models\ReportActivityMaterial; use App\Models\ReportActivityMaterial;
use Datatables; use Datatables;
class AssignMaterialController extends Controller class AssignMaterialController extends Controller
{ {
public function add_backup(Request $request){
$this->validate($request, [
'activity_id' => 'required',
'material_id' => 'required',
'qty_planning' => 'required',
'budget' => 'required'
]);
$checkStock = MaterialResource::where("id", $request->material_id)->first(); public function add(Request $request){
$currentStock = $checkStock->qty; $this->validate($request, [
if((int)$currentStock < (int)$request->qty_planning){ 'activity_id' => 'required',
return response()->json(['status'=>'failed','message'=>'Not enough stock in warehouse!','code'=>400]); 'material_id' => 'required',
die(); 'qty_planning' => 'required'
} ]);
$checkStock = RequestMaterial::where("id", $request->material_id)->first();
$currentStock = $checkStock->qty;
$data = $request->all(); $price = $checkStock->price;
if((int)$currentStock < (int)$request->qty_planning){
$data['created_by'] = $this->currentName; return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]);
}
$result = AssignMaterial::create($data);
if($result){ $data = $request->all();
$checkStock = MaterialResource::find($request->material_id); $data['created_by'] = $this->currentName;
$newStock = (int)$checkStock->qty - (int)$request->qty_planning; $data['budget'] = $price;
$dataUpdate = array(
"qty"=>$newStock, $result = AssignMaterial::create($data);
"updated_by"=>$this->currentName if(!$result)
); return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]);
$checkStock->update($dataUpdate);
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=>200]);
return response()->json(['status'=>'success','message'=>'Assign material successfull created','code'=>200]);
}else{ }
return response()->json(['status'=>'failed','message'=>'Assign material failed created','code'=>400]);
} public function update(Request $request, $id){
} if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
public function add(Request $request){
$this->validate($request, [ $data = AssignMaterial::find($id);
'activity_id' => 'required', if(!$data)
'material_id' => 'required', return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
'qty_planning' => 'required'
]); $result = $data->update($request->all());
$checkStock = RequestMaterial::where("id", $request->material_id)->first(); if($result)
$currentStock = $checkStock->qty; return response()->json(['status'=>'success','message'=> 'Data updated!','code'=> 200], 200);
$price = $checkStock->price;
if((int)$currentStock < (int)$request->qty_planning){ return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500);
return response()->json(['status'=>'failed','message'=>'Not enough stock !','code'=>400]); }
die();
} public function delete($id)
{
$data = $request->all(); $data = AssignMaterial::where('id', $id)->first();
$data['created_by'] = $this->currentName; if($data->delete())
$data['budget'] = $price; return response()->json(['status'=>'success','message'=>'Data deleted!','code'=> 200], 200);
$result = AssignMaterial::create($data); return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500);
if($result){ }
$updateActivity = Activity::find($request->activity_id); public function edit($id){
if($updateActivity){ if(empty($id) || !is_int((int)$id))
$costPlanOld = $updateActivity==null? 0 : (int)$updateActivity->rencana_biaya; return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$costPlanNew = $costPlanOld + ($price*$request->qty_planning);
$updateActivity->rencana_biaya = $costPlanNew; $result = AssignMaterial::find($id);
$updateActivity->save();
return response()->json(['status'=>'success','message'=>'Assign material successfull created, and update cost plan success '.$costPlanNew,'code'=>200]); if($result)
}else{ return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
return response()->json(['status'=>'success','message'=>'Assign material successfull created','code'=>200]);
} return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
}else{ }
return response()->json(['status'=>'failed','message'=>'Assign material failed created','code'=>400]);
} public function search(Request $request)
} {
$payload = $request->all();
private function updateFromAdd($data){ $dataBuilder = $this->setUpPayload($payload, 'assign_material_to_activity');
$assignMaterial = AssignMaterial::where("activity_id", $data->activity_id)->where("material_id", $data->material_id)->first(); $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$newQty = (int)$assignMaterial->qty_planning + (int)$data->qty_planning; $dataGet = $builder->get();
$totalRecord = $countBuilder->count();
$newBudget = $assignMaterial->budget > $data->budget ? $assignMaterial->budget : $data->budget; return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
$dataUpdate = array(
"qty_planning"=>$newQty, public function list()
"budget"=>$newBudget, {
"updated_by"=>$this->currentName $data = AssignMaterial::all();
); $countData = $data->count();
$dataWillUpdate = AssignMaterial::where("activity_id", $data->activity_id)->where("material_id", $data->material_id); if($data)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
return $dataWillUpdate->update($dataUpdate);
} return response()->json(['status'=>'failed','message'=>'Failed to get the data!','code'=> 500], 500);
}
public function update(Request $request, $id){
public function datatables(Request $request){
if(!$id || (int) $id < 0 || $id==""){ $id_activity = $request->query('idact');
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); $data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom")->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")->where('assign_material_to_activity.activity_id', $id_activity)->get();
} return Datatables::of($data)
$data = AssignMaterial::find($id); ->addIndexColumn()
if($data){ ->addColumn('action', function($row){
$result = $data->update($request->all()); $actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-material-delete"><i class="fa fa-trash"></i></a>';
}else{ return $actionBtn;
return response()->json(['status'=>'failed','message'=>'Data Assign material not found!','code'=>400], 400); })
die(); ->rawColumns(['action'])->make(true);
} }
if($result){ public function datatablesForReportActivity(Request $request){
return response()->json(['status'=>'success','message'=>'Assign material successfully updated!','code'=>200], 200); $id_activity = $request->query('idact');
}else{ $data = AssignMaterial::select(AssignMaterial::raw('SUM(qty_planning) as qty_planning'), "m.description as material_name", "assign_material_to_activity.activity_id as activity_id")
return response()->json(['status'=>'failed','message'=>'Assign material failed updated!','code'=>400], 400); ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
} ->groupBy("m.description")
} ->groupBy("assign_material_to_activity.activity_id")
->where("assign_material_to_activity.activity_id", $id_activity)->get();
public function delete($id) return Datatables::of($data)
{ ->addIndexColumn()
$data = AssignMaterial::find($id); ->addColumn('qty_sum', function($row){
$val_qty_act = AssignMaterial::select(ReportActivityMaterial::raw('SUM(ram.qty) as qty_sum'),"m.description as material_name1")
if($data){ ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
$id = $data->material_id; ->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id")
$stock = $data->qty_planning; ->groupBy("m.description")
$materialResource = MaterialResource::find($id); ->where("m.description", strval($row->material_name))
if($materialResource){ ->where("ram.activity_id", $row->activity_id)->first();
$oldStock = $materialResource->qty; return $val_qty_act ? $val_qty_act->qty_sum : '-';
$newStock = $oldStock + $stock; })
$dataUpdate = array( ->addColumn('status_activity', function($row){
"qty"=>$newStock, $val_status = AssignMaterial::select("status_activity")
"updated_by"=>$this->currentName ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
); ->where('m.description', '=', $row->material_name)
$materialResource->update($dataUpdate); ->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
} return $val_status ? $val_status->status_activity : null;
$activity = Activity::where('id', $data->activity_id)->first(); })
$activity->rencana_biaya -= $data->budget * $data->qty_planning; ->addColumn('start_activity', function($row){
$activity->save(); $val_start = AssignMaterial::select("start_activity")
$delete = $data->delete(); ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
}else{ ->where('m.description', '=', $row->material_name)
return response()->json(['status'=>'failed','message'=>'Data Assign material not found!','code'=>400], 400); ->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
die(); return $val_start ? $val_start->start_activity : null;
} })
->addColumn('finish_activity', function($row){
if($delete){ $val_finish = AssignMaterial::select("finish_activity")
return response()->json(['status'=>'success','message'=>'Assign material successfully deleted!','code'=>200], 200); ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
}else{ ->where('m.description', '=', $row->material_name)
return response()->json(['status'=>'failed','message'=>'Assign material failed deleted!','code'=>400], 400); ->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
} return $val_finish ? $val_finish->finish_activity : null;
} })
->addColumn('uom', function($row){
public function edit($id){ $val_uom = RequestMaterial::select("uom")
if(!$id || (int) $id < 0 || $id==""){ ->where('description', '=', $row->material_name)->first();
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return $val_uom ? $val_uom->uom : null;
die(); })
} ->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" data-material-name="'.$row->material_name.'" class="primary btn btn-primary btn-sm btn-lihat-plan" data-toggle="tooltip" title="Lihat Plan" data-placement="top"><i class="fa fa-align-justify"></i></a>';
$result = AssignMaterial::find($id); $actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" data-material-name="'.$row->material_name.'" class="warning btn btn-warning btn-sm btn-lihat-actual" data-toggle="tooltip" title="Input Progress" data-placement="top"><i class="fa fa-edit" aria-hidden="true"></i></a>';
return $actionBtn;
if($result){ })
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); ->rawColumns(['action'])->make(true);
}else{ }
return response()->json(['status'=>'failed','message'=>'failed get data Assign material, please try again later!','code'=>400], 400);
} public function ForReportActivityByMaterial(Request $request){
} $id_activity = $request->idact;
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom")
public function search(Request $request) ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
{ ->where('assign_material_to_activity.activity_id', $id_activity)->get();
$payload = $request->all(); foreach ($data as $key) {
$dataBuilder = $this->setUpPayload($payload, 'assign_material_to_activity'); # code...
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $val_qty_sum = ReportActivityMaterial::where('assign_material_id', '=', $key->id)->sum("qty");
$dataGet = $builder->get(); }
$totalRecord = $countBuilder->count(); $countData = $data->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); if($data){
} return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{
public function list() return response()->json(['status'=>'failed','message'=>'failed get Assign material, please try again later!','code'=>400], 400);
{ }
$data = AssignMaterial::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 Assign material, please try again later!','code'=>400], 400);
}
}
public function datatables(Request $request){
$id_activity = $request->query('idact');
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom")->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")->where('assign_material_to_activity.activity_id', $id_activity)->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-material-delete"><i class="fa fa-trash"></i></a>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
public function datatablesForReportActivity(Request $request){
$id_activity = $request->query('idact');
$data = AssignMaterial::select(AssignMaterial::raw('SUM(qty_planning) as qty_planning'), "m.description as material_name", "assign_material_to_activity.activity_id as activity_id")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->groupBy("m.description")
->groupBy("assign_material_to_activity.activity_id")
->where("assign_material_to_activity.activity_id", $id_activity)->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('qty_sum', function($row){
$val_qty_act = AssignMaterial::select(ReportActivityMaterial::raw('SUM(ram.qty) as qty_sum'),"m.description as material_name1")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id")
->groupBy("m.description")
->where("m.description", strval($row->material_name))
->where("ram.activity_id", $row->activity_id)->first();
return $val_qty_act ? $val_qty_act->qty_sum : '-';
})
->addColumn('status_activity', function($row){
$val_status = AssignMaterial::select("status_activity")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->where('m.description', '=', $row->material_name)
->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
return $val_status ? $val_status->status_activity : null;
})
->addColumn('start_activity', function($row){
$val_start = AssignMaterial::select("start_activity")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->where('m.description', '=', $row->material_name)
->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
return $val_start ? $val_start->start_activity : null;
})
->addColumn('finish_activity', function($row){
$val_finish = AssignMaterial::select("finish_activity")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->where('m.description', '=', $row->material_name)
->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
return $val_finish ? $val_finish->finish_activity : null;
})
->addColumn('uom', function($row){
$val_uom = RequestMaterial::select("uom")
->where('description', '=', $row->material_name)->first();
return $val_uom ? $val_uom->uom : null;
})
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" data-material-name="'.$row->material_name.'" class="primary btn btn-primary btn-sm btn-lihat-plan" data-toggle="tooltip" title="Lihat Plan" data-placement="top"><i class="fa fa-align-justify"></i></a>';
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" data-material-name="'.$row->material_name.'" class="warning btn btn-warning btn-sm btn-lihat-actual" data-toggle="tooltip" title="Input Progress" data-placement="top"><i class="fa fa-edit" aria-hidden="true"></i></a>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
public function ForReportActivityByMaterial(Request $request){
$id_activity = $request->idact;
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $id_activity)->get();
foreach ($data as $key) {
# code...
$val_qty_sum = ReportActivityMaterial::where('assign_material_id', '=', $key->id)->sum("qty");
}
$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 Assign material, please try again later!','code'=>400], 400);
}
}
} }

135
app/Http/Controllers/AuthController.php

@ -4,85 +4,70 @@ namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Models\User; use App\Models\User;
use App\Models\Role; use App\Models\Role;
use App\Models\Project;
use App\Models\UserProject;
class AuthController extends Controller class AuthController extends Controller
{ {
/** public function __construct()
* Create a new AuthController instance. {
* $this->middleware('auth:api', ['except' => ['login']]);
* @return void }
*/
public function __construct() public function login(Request $request)
{ {
$this->middleware('auth:api', ['except' => ['login']]); $username = $request->username;
} $password = $request->password;
$remember = $request->remember;
public function login(Request $request) $is_mobile = $request->is_mobile;
{
$username = $request->username; if(empty($username) || empty($password))
$password = $request->password; return response()->json(['status'=>'error','message'=>'You must fill all the fields'], 400);
$is_mobile = $request->is_mobile;
$user = User::where('username', $username)->where('password', md5($password))->first();
if(empty($username) || empty($password)){
return response()->json(['status'=>'error','message'=>'You must fill all the fields'], 400); if($is_mobile){
} $fcm_token = $request->fcm_token;
$credentials = array( if(!$fcm_token || $fcm_token=="")
"username"=> $username, return response()->json(['status'=>'error','message'=>'FCM Token is required'], 400);
"password"=> md5($password)
); $dataUpdateFcm = array(
"fcm_token"=>$fcm_token
$user = User::where('username', $username)->where('password', md5($password)) );
->first();
$hr = User::find($user->id);
if($is_mobile){
$fcm_token = $request->fcm_token; if($hr)
$hr->update($dataUpdateFcm);
if(!$fcm_token || $fcm_token==""){ }
return response()->json(['status'=>'error','message'=>'FCM Token is required'], 400);
die(); $dataRole = Role::find($user->role_id);
}
if($dataRole)
$dataUpdateFcm = array( $user->role = $dataRole;
"fcm_token"=>$fcm_token
); if (! $token =Auth::login($user))
return response()->json(['error' => 'Unauthorized'], 401);
$hr = User::find($user->id);
$ttl = 60;
if($hr){ if($remember)
$result = $hr->update($dataUpdateFcm); $ttl = 10080;
}
} // todo : change existing md5 hashed function to laravel's originally bcrypt
/* $token = auth()->setTTL($ttl)->attempt(['username' => $username, 'password' => Hash::make($password)]); */
$dataRole = Role::find($user->role_id); /* dd(response()->json(['code'=>'200', 'token' => $token, 'ttl' => $ttl])); */
if($dataRole){ return response()->json([
$user->role = $dataRole; 'code' => 200,
} 'data' => array(
'data_user' => $user,
'access_token' => $token,
if (! $token =Auth::login($user)) { 'token_type' => 'bearer',
return response()->json(['error' => 'Unauthorized'], 401); 'expires_in' => auth()->factory()->getTTL() * $ttl,
} ),
]);
return $this->respondWithToken($token, $user); }
}
protected function respondWithToken($token, $user)
{
return response()->json([
'code' => 200,
'data' => array(
'data_user' => $user,
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth()->factory()->getTTL() * 60
),
]);
}
} }

21
app/Http/Controllers/Controller.php

@ -10,7 +10,7 @@ class Controller extends BaseController
protected $pathImage = "assets/image/"; protected $pathImage = "assets/image/";
protected $pathDocument = "assets/file/project/"; protected $pathDocument = "assets/file/project/";
protected $pathActivityDocument = "assets/file/activity/"; protected $pathActivityDocument = "assets/file/activity/";
protected $listJoinAll = ['first', 'second', 'third', 'fourth', 'fifth', protected $listJoinAll = ['first', 'second', 'third', 'fourth', 'fifth',
'sixth', 'seventh', 'eighth', 'ninth', 'tenth']; 'sixth', 'seventh', 'eighth', 'ninth', 'tenth'];
protected $currentDate; protected $currentDate;
protected $currentName; protected $currentName;
@ -35,14 +35,14 @@ class Controller extends BaseController
if($condition){ if($condition){
if(isset($condition['joins'])){ if(isset($condition['joins'])){
$selectColumn = []; $selectColumn = [];
$no = 0; $no = 0;
foreach($condition['joins'] as $join){ foreach($condition['joins'] as $join){
$tableJoin = isset($join['name1']) ? $join['name1'] : $alias; $tableJoin = isset($join['name1']) ? $join['name1'] : $alias;
$tableName = $join['name']; $tableName = $join['name'];
$columnJoin = $join['column_join']; // foreign key table sini $columnJoin = $join['column_join']; // foreign key table sini
$columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan $columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan
$columnResult = $join['column_results']; $columnResult = $join['column_results'];
foreach($columnResult as $sColumn){ foreach($columnResult as $sColumn){
$builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn); $builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn);
} }
@ -50,7 +50,7 @@ class Controller extends BaseController
$no++; $no++;
} }
} }
if(isset($condition['columns'])){ if(isset($condition['columns'])){
$listWhere = $condition['columns']; $listWhere = $condition['columns'];
@ -71,7 +71,7 @@ class Controller extends BaseController
if(isset($condition['group_column'])){ if(isset($condition['group_column'])){
$builder = $this->groupWhere($builder, $condition['group_column'], $alias); $builder = $this->groupWhere($builder, $condition['group_column'], $alias);
} }
$data['count'] = clone $builder; $data['count'] = clone $builder;
if(isset($condition['paging'])){ if(isset($condition['paging'])){
@ -225,7 +225,7 @@ class Controller extends BaseController
->where("assign_hr_to_activity.activity_id", $activity_id)->where("assign_hr_to_activity.proyek_id", $proyek_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) ->where("ahp.proyek_id", $proyek_id)
->get(); ->get();
$totalCost = 0; $totalCost = 0;
foreach ($dataHuman as $human) { foreach ($dataHuman as $human) {
$uom = $human->uom_standart_rate; $uom = $human->uom_standart_rate;
@ -242,7 +242,7 @@ class Controller extends BaseController
$standarRate = $human->standart_rate; $standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100; $maxUsed = $human->max_used/100;
$totalCost = ($standarRate*$duration)*$maxUsed; $totalCost = ($standarRate*$duration)*$maxUsed;
return $totalCost; return $totalCost;
} }
private function calculateMaterialCost($activity_id, $proyek_id) private function calculateMaterialCost($activity_id, $proyek_id)
@ -251,11 +251,6 @@ class Controller extends BaseController
return $totalCost; return $totalCost;
} }
private function calculateToolsCost($activity_id, $proyek_id)
{
}
protected function updatedCostPlanning($id) protected function updatedCostPlanning($id)
{ {
$sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))->where("parent_id", $id)->first(); $sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))->where("parent_id", $id)->first();
@ -272,4 +267,4 @@ class Controller extends BaseController
} }
} }
} }
} }

455
app/Http/Controllers/DashboardController.php

@ -6,247 +6,220 @@ use Illuminate\Http\Request;
use App\Models\Project; use App\Models\Project;
use App\Models\Activity; use App\Models\Activity;
use App\Models\ReportActivity; use App\Models\ReportActivity;
use App\Models\UserToActivity; use App\Models\Role;
use DB;
class DashboardController extends Controller class DashboardController extends Controller
{ {
public function costPlanningActual(Request $request) public function costPlanningActual(Request $request)
{ {
$dataPayload = $request->all(); $dataPayload = $request->all();
$dataMaxVersionGantt = []; $dataMaxVersionGantt = [];
foreach ($dataPayload['project_id'] as $val) { foreach ($dataPayload['project_id'] as $val) {
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val); $dataMaxVersionGantt[] = $this->getMaxVersionGantt($val);
} }
$dataFinal=[]; $dataFinal=[];
foreach ($dataMaxVersionGantt as $val) { foreach ($dataMaxVersionGantt as $val) {
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.rencana_biaya', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get(); $data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.rencana_biaya', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data); $dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
} }
if($dataPayload){ if(!$dataFinal)
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200); return response()->json(['status'=>'failed','message'=>'Data not found','code'=> 404], 404);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
} }
}
public function getMaxVersionGantt($id){
public function getMaxVersionGantt($id){ $data = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $id)->first();
$data = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $id)->first(); return array("last_version_gantt"=>$data->last_version_gantt, "proyek_id" => $id, "proyek_name" => $data->proyek_name);
return array("last_version_gantt"=>$data->last_version_gantt, "proyek_id" => $id, "proyek_name" => $data->proyek_name); }
}
public function percentagePlanningActual(Request $request)
public function percentagePlanningActual(Request $request) {
{ $dataPayload = $request->all();
$dataPayload = $request->all(); $dataMaxVersionGantt = [];
$dataMaxVersionGantt = []; foreach ($dataPayload['project_id'] as $val) {
foreach ($dataPayload['project_id'] as $val) { $dataMaxVersionGantt[] = $this->getMaxVersionGantt($val);
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val); }
} $dataFinal=[];
$dataFinal=[]; foreach ($dataMaxVersionGantt as $val) {
foreach ($dataMaxVersionGantt as $val) { $data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get(); $dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data); }
} if(!$dataFinal)
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
if($dataPayload){
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
}else{ }
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
} public function list()
} {
$data = Role::all();
public function list() $countData = $data->count();
{
$data = Role::all(); if(!$data)
$countData = $data->count(); return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
if($data){ return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); }
}else{
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); public function getActivityByProjectId($projectId) {
} $output = [];
} $data = Activity::select('id')->where('proyek_id', $projectId)->get();
foreach ($data as $actData) {
$output[] = $actData->id;
}
return $output;
}
public function getActivityByProjectId($projectId) { /*
$output = []; const statusProyek = [
$data = Activity::select('id')->where('proyek_id', $projectId)->get(); {
if (count($data) > 0) { "id": "1",
foreach ($data as $actData) { "proyek_name": "Pembuatan Aplikasi Survey Covid Varian Baru", // ambil dari m_proyek
$output[] = $actData->id; "total_task": 80, // ambil dari m_activity -> SUM(jumlah_pekerjaan) where proyek_id berdasarkan proyek_id terpilih
} "task_on_progress": 60, // ambil dari report_activity -> SUM(job_count_report) where activity_id berdasarkan activity_id terpilih
} "day_left": 7, // ambil dari m_proyek, cari sisa hari (end_date - hari ini)
return $output; "percentage": 75 // (task_on_progress / total_task * 100)
} },
{
/* for statusProyek, I want something output like this "id": "2",
const statusProyek = [ "proyek_name": "Pembangunan Jembatan Layang",
{ "total_task": 70, // SELECT SUM(jumlah_pekerjaan) FROM public.m_activity WHERE proyek_id IN (11);
"id": "1", "task_on_progress": 70, // SELECT SUM(job_count_report) FROM public.report_activity WHERE activity_id IN (349, 355);
"proyek_name": "Pembuatan Aplikasi Survey Covid Varian Baru", // ambil dari m_proyek "day_left": 0,
"total_task": 80, // ambil dari m_activity -> SUM(jumlah_pekerjaan) where proyek_id berdasarkan proyek_id terpilih "percentage": 100
"task_on_progress": 60, // ambil dari report_activity -> SUM(job_count_report) where activity_id berdasarkan activity_id terpilih },
"day_left": 7, // ambil dari m_proyek, cari sisa hari (end_date - hari ini) ...
"percentage": 75 // (task_on_progress / total_task * 100) ]
}, */
{ public function statusProyek(Request $request) {
"id": "2", $dataPayload = $request->all();
"proyek_name": "Pembangunan Jembatan Layang", $reqProject = $dataFinal = [];
"total_task": 70, // SELECT SUM(jumlah_pekerjaan) FROM public.m_activity WHERE proyek_id IN (11);
"task_on_progress": 70, // SELECT SUM(job_count_report) FROM public.report_activity WHERE activity_id IN (349, 355); if (!isset($dataPayload['project_id']))
"day_left": 0, return response()->json(['status'=>'failed','message'=>'Undefined project_id','code'=>400], 400);
"percentage": 100
}, foreach ($dataPayload['project_id'] as $val) {
... $prj["project_id"] = $val;
] $prj["activity_id"] = $this->getActivityByProjectId($val);
*/ $reqProject[] = $prj;
public function statusProyek(Request $request) { }
$dataPayload = $request->all();
$reqProject = []; if (count($reqProject) > 0) {
$dataFinal = []; $row = [];
if (!isset($dataPayload['project_id'])) { for ($i=0; $i < count($reqProject); $i++) {
return response()->json(['status'=>'failed','message'=>'Undefined project_id','code'=>400], 400); $dataMaxVersionGantt = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $reqProject[$i]['project_id'])->first();
} $last_version_gantt = $dataMaxVersionGantt->last_version_gantt;
$queryProject = Project::select('id', 'nama', 'mulai_proyek', 'akhir_proyek')->where('id',$reqProject[$i]['project_id'])->first();
foreach ($dataPayload['project_id'] as $val) { $sum_jumlah_pekerjaan = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->sum("jumlah_pekerjaan");
$prj["project_id"] = $val; $count_activity = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->count("id");
$prj["activity_id"] = $this->getActivityByProjectId($val); $count_activity_done = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('persentase_progress', '100')->where('version_gantt_id', $last_version_gantt)->count("id");
$count_progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->count("persentase_progress");
$reqProject[] = $prj; $progress_actual = Activity::select('id', 'bobot_planning', 'persentase_progress')->where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->get();
} $current_progress = 0;
if (count($reqProject) > 0) { foreach($progress_actual as $objRow) {
$row = []; $current_progress += ($objRow->bobot_planning * $objRow->persentase_progress) / 100;
}
for ($i=0; $i < count($reqProject); $i++) { if (count($reqProject[$i]['activity_id']) > 0) {
$dataMaxVersionGantt = Activity::select(Activity::raw('MAX(version_gantt_id) as last_version_gantt'))->where("proyek_id", $reqProject[$i]['project_id'])->first(); for ($j=0; $j < count($reqProject[$i]['activity_id']); $j++) {
$last_version_gantt = $dataMaxVersionGantt->last_version_gantt; $sum_job_count_report = ReportActivity::whereIn('activity_id', $reqProject[$i]['activity_id'])->sum("job_count_report");
$queryProject = Project::select('id', 'nama', 'mulai_proyek', 'akhir_proyek')->where('id',$reqProject[$i]['project_id'])->first(); }
$sum_jumlah_pekerjaan = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->sum("jumlah_pekerjaan"); }
$count_activity = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->count("id"); if (!isset($queryProject->id))
$count_activity_done = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('persentase_progress', '100')->where('version_gantt_id', $last_version_gantt)->count("id"); return response()->json(['status'=>'failed','message'=>'Project with id='.$reqProject[$i]['project_id'].' is not found!','code'=>400], 400);
$progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->sum("persentase_progress");
$count_progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->count("persentase_progress"); $now = time();
$akhir_proyek = strtotime($queryProject->akhir_proyek);
$progress_actual = Activity::select('id', 'bobot_planning', 'persentase_progress')->where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->get(); $datediff = $akhir_proyek - $now;
$current_progress = 0;
foreach($progress_actual as $objRow) { $mulai_proyek = strtotime($queryProject->mulai_proyek);
$current_progress += ($objRow->bobot_planning * $objRow->persentase_progress) / 100; $total_kontrak = $akhir_proyek - $mulai_proyek;
}
$row["id"] = $queryProject->id;
if (count($reqProject[$i]['activity_id']) > 0) { $row["proyek_name"] = $queryProject->nama;
for ($j=0; $j < count($reqProject[$i]['activity_id']); $j++) { $row["mulai_proyek"] = $queryProject->mulai_proyek;
$sum_job_count_report = ReportActivity::whereIn('activity_id', $reqProject[$i]['activity_id'])->sum("job_count_report"); $row["akhir_proyek"] = $queryProject->akhir_proyek;
} $row["total_kontrak"] = round($total_kontrak / (60 * 60 * 24));
} $row["total_task"] = $sum_jumlah_pekerjaan;
$row["task_on_progress"] = $sum_job_count_report;
if (!isset($queryProject->id)) { $row["count_activity"] = $count_activity;
return response()->json(['status'=>'failed','message'=>'Project with id='.$reqProject[$i]['project_id'].' is not found!','code'=>400], 400); $row["count_activity_done"] = $count_activity_done;
} $row["day_left"] = round($datediff / (60 * 60 * 24));
$row["percentage"] = round($current_progress,3);
$now = time(); $row["count_progress_percentage"] = $count_progress_percentage;
$akhir_proyek = strtotime($queryProject->akhir_proyek);
$datediff = $akhir_proyek - $now; $dataFinal[] = $row;
}
$mulai_proyek = strtotime($queryProject->mulai_proyek); }
$total_kontrak = $akhir_proyek - $mulai_proyek;
if(empty($dataFinal))
$row["id"] = $queryProject->id; return response()->json(['status'=>'failed','message'=>'failed get status proyek, please try again later!','code'=>400], 400);
$row["proyek_name"] = $queryProject->nama;
$row["mulai_proyek"] = $queryProject->mulai_proyek; return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>count($dataFinal)], 200);
$row["akhir_proyek"] = $queryProject->akhir_proyek; }
$row["total_kontrak"] = round($total_kontrak / (60 * 60 * 24));
$row["total_task"] = $sum_jumlah_pekerjaan; public function curvaS(Request $request)
$row["task_on_progress"] = $sum_job_count_report; {
$row["count_activity"] = $count_activity; $dataPayload = $request->all();
$row["count_activity_done"] = $count_activity_done; $dataMaxVersionGantt = [];
$row["day_left"] = round($datediff / (60 * 60 * 24)); $dataFinal=[];
$row["percentage"] = round($current_progress,3);
$row["count_progress_percentage"] = $count_progress_percentage; foreach ($dataPayload['project_id'] as $val) {
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val);
$dataFinal[] = $row; }
}
} foreach ($dataMaxVersionGantt as $val) {
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
if($dataFinal){ $totalCostPlanning = Activity::where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->sum('rencana_biaya');
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>count($dataFinal)], 200);
}else{ for ($i=0; $i < count($data); $i++) {
return response()->json(['status'=>'failed','message'=>'failed get status proyek, please try again later!','code'=>400], 400); $tmpp = $tmpa = $tmpbc = $tmpac = 0;
} for ($x=$i; $x >= 0 ; $x--) {
$tmpp += $data[$x]['bobot_planning'];
} $tmpa += ($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100;
$tmpbc += ((($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100)*$totalCostPlanning)/100;
public function curvaS(Request $request) $tmpac += $data[$x]['biaya_actual'];
{ }
$dataPayload = $request->all();
$dataMaxVersionGantt = []; $data[$i]['cal_bobot_p'] = round($tmpp,2);
foreach ($dataPayload['project_id'] as $val) {
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val); if($i > 0 ){
} if($data[$i-1]['cal_bobot_a'] != null){
$dataFinal=[]; if($data[$i-1]['cal_bobot_a'] == round($tmpa,2)){
foreach ($dataMaxVersionGantt as $val) { $data[$i]['cal_bobot_a'] = null;
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get(); }else{
$totalCostPlanning = Activity::where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->sum('rencana_biaya'); $data[$i]['cal_bobot_a'] = round($tmpa,2);
$dataBobotPlan =[]; }
for ($i=0; $i < count($data); $i++) { }else{
$tmpp = 0; $data[$i]['cal_bobot_a'] = null;
$tmpa = 0; }
$tmpbc = 0; if($data[$i-1]['cal_actual_cost'] != null){
$tmpac = 0; if($data[$i-1]['cal_actual_cost'] == round($tmpac,2)){
for ($x=$i; $x >= 0 ; $x--) { $data[$i]['cal_actual_cost'] = null;
$tmpp += $data[$x]['bobot_planning']; }else{
$tmpa += ($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100; $data[$i]['cal_actual_cost'] = round($tmpac,2);
$tmpbc += ((($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100)*$totalCostPlanning)/100; }
$tmpac += $data[$x]['biaya_actual']; }else{
} $data[$i]['cal_actual_cost'] = null;
}
$data[$i]['cal_bobot_p'] = round($tmpp,2); }else{
if($i > 0 ){ $data[$i]['cal_bobot_a'] = round($tmpa,2);
if($data[$i-1]['cal_bobot_a'] != null){ $data[$i]['cal_actual_cost'] = round($tmpac,2);
if($data[$i-1]['cal_bobot_a'] == round($tmpa,2)){ }
$data[$i]['cal_bobot_a'] = null; $data[$i]['cal_budget_cost'] = round($tmpbc,2);
}else{ }
$data[$i]['cal_bobot_a'] = round($tmpa,2);
} $dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
}else{ }
$data[$i]['cal_bobot_a'] = null;
} if(!$dataFinal)
}else{ return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
$data[$i]['cal_bobot_a'] = round($tmpa,2);
} return response()->json(['status'=>'success','code'=>200, 'data'=>$dataFinal, 'totalRecord'=>1], 200);
$data[$i]['cal_budget_cost'] = round($tmpbc,2); }
}
if($i > 0 ){
if($data[$i-1]['cal_actual_cost'] != null){
if($data[$i-1]['cal_actual_cost'] == round($tmpac,2)){
$data[$i]['cal_actual_cost'] = null;
}else{
$data[$i]['cal_actual_cost'] = round($tmpac,2);
}
}else{
$data[$i]['cal_actual_cost'] = null;
}
}else{
$data[$i]['cal_actual_cost'] = round($tmpac,2);
}
}
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
}
if($dataPayload){
return response()->json(['status'=>'success','code'=>200, 'data'=>$dataFinal, 'totalRecord'=>1], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
}
}
}

155
app/Http/Controllers/DivisiController.php

@ -6,82 +6,81 @@ use Illuminate\Http\Request;
use App\Models\Divisi; use App\Models\Divisi;
class DivisiController extends Controller 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' => 'required' 'description' => 'required'
]); ]);
$data = $request->all();
$data['created_by'] = $this->currentName; $data = $request->all();
$data['created_by'] = $this->currentName;
$result = Divisi::create($data);
if($result){ $result = Divisi::create($data);
return response()->json(['status'=>'success','message'=>'Master divisi successfull created','code'=>200]);
}else{ if(!$result)
return response()->json(['status'=>'failed','message'=>'Master divisi failed created','code'=>400]); return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]);
}
} return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]);
}
public function update(Request $request, $id){
public function update(Request $request, $id){
if(!$id || (int) $id < 0 || $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 = Divisi::find($id); $data = Divisi::find($id);
if($data){
$result = $data->update($request->all()); if(!$data)
}else{ return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'failed','message'=>'Data Master divisi not found!','code'=>400], 400);
die(); $result = $data->update($request->all());
}
if(!$result)
if($result){ return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Master divisi successfully updated!','code'=>200], 200);
}else{ return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200);
return response()->json(['status'=>'failed','message'=>'Master divisi failed updated!','code'=>400], 400); }
}
} public function delete($id)
{
public function delete($id) if(empty($id) || !is_int((int)$id))
{ return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = Divisi::find($id);
$data = Divisi::find($id);
if($data){
$delete = $data->delete(); if(!$data)
}else{ return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'failed','message'=>'data Master divisi not found!','code'=>400], 400);
die(); $delete = $data->delete();
}
if(!$delete)
if($delete){ return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Master divisi successfully deleted!','code'=>200], 200);
}else{ return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200);
return response()->json(['status'=>'failed','message'=>'Master divisi failed deleted!','code'=>400], 400); }
}
} public function search(Request $request)
{
public function search(Request $request) $payload = $request->all();
{
$payload = $request->all(); $dataBuilder = $this->setUpPayload($payload, 'm_divisi');
$dataBuilder = $this->setUpPayload($payload, 'm_divisi'); $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()
{ {
$data = Divisi::all(); $data = Divisi::all();
$countData = $data->count(); $countData = $data->count();
if($data){ if(!$data)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list tools request, please try again later!','code'=>400], 400); return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
} }
}
} }

415
app/Http/Controllers/ProjectController.php

@ -14,12 +14,8 @@ use App\Models\ProjectCharter;
use App\Models\ProjectApproval; use App\Models\ProjectApproval;
use App\Models\ProjectMileStone; use App\Models\ProjectMileStone;
use App\Models\ProjectParticipants; use App\Models\ProjectParticipants;
use App\Models\UserToVersionGantt;
use App\Models\RequestMaterial;
use App\Models\ShowHideColumn; use App\Models\ShowHideColumn;
use App\Models\ToolsProject;
use App\Models\VersionGantt; use App\Models\VersionGantt;
use App\Models\MaterialProject;
use App\Models\Image; use App\Models\Image;
use App\Models\CommentActivity; use App\Models\CommentActivity;
use App\Models\Link; use App\Models\Link;
@ -30,214 +26,205 @@ use App\Models\OfficeHours;
class ProjectController extends Controller class ProjectController extends Controller
{ {
public function add(Request $request)
{ public function add(Request $request)
$this->validate($request, [ {
'nama' => 'required', $this->validate($request, [
'mulai_proyek' => 'required', 'nama' => 'required',
'akhir_proyek' => 'required', 'mulai_proyek' => 'required',
'rencana_biaya' => 'required', 'akhir_proyek' => 'required',
'type_proyek_id' => 'required' 'rencana_biaya' => 'required',
]); 'type_proyek_id' => 'required'
]);
$data = $request->all();
$data = $request->all();
$data['created_by'] = $this->currentName;
$data['created_by'] = $this->currentName;
$result = Project::create($data);
$result = Project::create($data);
if($result){
$this->createOfficeHours($result->id); if(!$result)
$dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'add data project successfully!', 'data_result' =>$dataResultInsert, 'code'=>200], 200);
}else{ $this->createOfficeHours($result->id);
return response()->json(['status'=>'failed','message'=>'add data project failed!','code'=>400], 400); $dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first();
}
} return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200);
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){ public function edit($id){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if(empty($id) || !is_int((int)$id))
die(); return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
}
$result = Project::find($id);
$result = Project::find($id);
if(!$result)
if($result){ return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{ return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200);
return response()->json(['status'=>'failed','message'=>'failed get data project, please try again later!','code'=>400], 400); }
}
} public function update(Request $request, $id)
{
public function update(Request $request, $id) if(empty($id) || !is_int((int)$id))
{ return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); $data = Project::find($id);
}
if(!$data)
$data = Project::find($id); return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
if($data){ $result = $data->update($request->all());
$result = $data->update($request->all());
}else{ if(!$result)
return response()->json(['status'=>'failed','message'=>'data project not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500);
die();
} return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200);
}
if($result){ private function createOfficeHours($proyek_id)
return response()->json(['status'=>'success','message'=>'data project successfully updated!','code'=>200], 200); {
}else{ $dataCreate = array(
return response()->json(['status'=>'failed','message'=>'data project failed updated!','code'=>400], 400); "proyek_id"=>$proyek_id,
} "monday_start"=> "08:00:00",
} "monday_end"=> "16:00:00",
"tuesday_start"=> "08:00:00",
private function createOfficeHours($proyek_id) "tuesday_end"=> "16:00:00",
{ "wednesday_start"=> "08:00:00",
$dataCreate = array( "wednesday_end"=> "16:00:00",
"proyek_id"=>$proyek_id, "thursday_start"=> "08:00:00",
"monday_start"=> "08:00:00", "thursday_end"=> "16:00:00",
"monday_end"=> "16:00:00", "friday_start"=> "08:00:00",
"tuesday_start"=> "08:00:00", "friday_end"=> "16:00:00",
"tuesday_end"=> "16:00:00", "saturday_start"=> "08:00:00",
"wednesday_start"=> "08:00:00", "saturday_end"=> "16:00:00",
"wednesday_end"=> "16:00:00", "sunday_start"=> "08:00:00",
"thursday_start"=> "08:00:00", "sunday_end"=> "16:00:00",
"thursday_end"=> "16:00:00", "created_by"=> $this->currentName
"friday_start"=> "08:00:00", );
"friday_end"=> "16:00:00",
"saturday_start"=> "08:00:00", OfficeHours::create($dataCreate);
"saturday_end"=> "16:00:00",
"sunday_start"=> "08:00:00", return true;
"sunday_end"=> "16:00:00", }
"created_by"=> $this->currentName
); public function delete($id)
{
OfficeHours::create($dataCreate); $data = Project::find($id);
return true; if(!$data)
} return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
public function delete($id) $this->deleteRelative($id);
{
$data = Project::find($id); if(!$data->delete())
return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500);
if($data){
$this->deleteRelative($id); return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
$delete = $data->delete(); }
}else{
return response()->json(['status'=>'failed','message'=>'data project not found!','code'=>400], 400); private function deleteRelative($project_id)
die(); {
} UserToProyek::where('proyek_id', $project_id)->delete();
UserToActivity::where('proyek_id', $project_id)->delete();
AssignMaterial::where('proyek_id', $project_id)->delete();
if($delete){ ProjectCharter::where('proyek_id', $project_id)->delete();
return response()->json(['status'=>'success','message'=>'data project successfully deleted!','code'=>200], 200); ProjectApproval::where('proyek_id', $project_id)->delete();
}else{ ProjectMileStone::where('proyek_id', $project_id)->delete();
return response()->json(['status'=>'failed','message'=>'data project failed deleted!','code'=>400], 400); ProjectParticipants::where('proyek_id', $project_id)->delete();
} $this->deleteVersionGantt($project_id);
} $this->deleteDokumenProject($project_id);
}
private function deleteRelative($project_id)
{ private function deleteVersionGantt($project_id)
UserToProyek::where('proyek_id', $project_id)->delete(); {
UserToActivity::where('proyek_id', $project_id)->delete(); $dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id");
AssignMaterial::where('proyek_id', $project_id)->delete(); $vhIds = $dataVg->all();
ProjectCharter::where('proyek_id', $project_id)->delete(); $activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id');
ProjectApproval::where('proyek_id', $project_id)->delete(); $activityIds = $activity->all();
ProjectMileStone::where('proyek_id', $project_id)->delete(); $dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get();
ProjectParticipants::where('proyek_id', $project_id)->delete(); foreach ($dataRa as $ra) {
$this->deleteVersionGantt($project_id); $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
$this->deleteDokumenProject($project_id); foreach ($images as $image) {
} if(file_exists($this->pathImage.$image->image)){
unlink($this->pathImage.$image->image);
private function deleteVersionGantt($project_id) }
{ }
$dataVg = VersionGantt::where("proyek_id", $project_id)->pluck("id"); Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
$vhIds = $dataVg->all(); }
$activity = Activity::whereIn("version_gantt_id", $vhIds)->pluck('id'); $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get();
$activityIds = $activity->all(); foreach ($dataAd as $ad) {
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); if(file_exists($this->pathActivityDocument.$ad->file)){
foreach ($dataRa as $ra) { unlink($this->pathActivityDocument.$ad->file);
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); }
foreach ($images as $image) { }
if(file_exists($this->pathImage.$image->image)){ ActivityDokumen::whereIn("activity_id", $activityIds)->delete();
unlink($this->pathImage.$image->image); CommentActivity::whereIn("activity_id", $activityIds)->delete();
} Holiday::where("proyek_id", $project_id)->delete();
} VersionGantt::where("proyek_id", $project_id)->delete();
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); Link::whereIn("version_gantt_id", $vhIds)->delete();
} ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete();
$dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); Activity::whereIn("version_gantt_id", $vhIds)->delete();
foreach ($dataAd as $ad) { ReportActivity::whereIn("activity_id", $activityIds)->delete();
if(file_exists($this->pathActivityDocument.$ad->file)){ }
unlink($this->pathActivityDocument.$ad->file);
} private function deleteDokumenProject($project_id)
} {
ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); $dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get();
CommentActivity::whereIn("activity_id", $activityIds)->delete();
Holiday::where("proyek_id", $project_id)->delete(); foreach ($dataDokumen as $dokumen) {
VersionGantt::where("proyek_id", $project_id)->delete(); if(file_exists($this->pathDocument.$dokumen->file)){
Link::whereIn("version_gantt_id", $vhIds)->delete(); unlink($this->pathDocument.$dokumen->file);
ShowHideColumn::whereIn("version_gantt_id", $vhIds)->delete(); }
Activity::whereIn("version_gantt_id", $vhIds)->delete(); }
ReportActivity::whereIn("activity_id", $activityIds)->delete(); DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete();
}
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id");
private function deleteDokumenProject($project_id) $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-out-folder")->where('ref_id', $project_id)->get(); foreach ($dataDokumen as $dokumen) {
if(file_exists($this->pathDocument.$dokumen->file)){
foreach ($dataDokumen as $dokumen) { unlink($this->pathDocument.$dokumen->file);
if(file_exists($this->pathDocument.$dokumen->file)){ }
unlink($this->pathDocument.$dokumen->file); }
}
} DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete();
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); }
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); public function search(Request $request)
$ref_ids = $dataFolder->all(); {
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); $payload = $request->all();
foreach ($dataDokumen as $dokumen) {
if(file_exists($this->pathDocument.$dokumen->file)){ $dataBuilder = $this->setUpPayload($payload, 'm_proyek');
unlink($this->pathDocument.$dokumen->file); $builder = $dataBuilder['builder'];
} $countBuilder = $dataBuilder['count'];
} $dataGet = $builder->get();
$totalRecord = $countBuilder->count();
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete();
} return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function search(Request $request)
{ public function list()
$payload = $request->all(); {
$dataBuilder = $this->setUpPayload($payload, 'm_proyek'); $data = Project::all();
$builder = $dataBuilder['builder']; $countData = $data->count();
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); if(!$data)
$totalRecord = $countBuilder->count(); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}
public function list()
{ public function getListProjectTask($id){
$data = Project::all(); $data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*")
$countData = $data->count(); ->where("assign_hr_to_activity.user_id", $id)
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
if($data){ ->groupBy("m_proyek.proyek_id")
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); ->get();
}else{
return response()->json(['status'=>'failed','message'=>'failed get list project, please try again later!','code'=>400], 400); if(!$data)
} return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
}
return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200);
public function getListProjectTask($id){ }
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*")->where("assign_hr_to_activity.user_id", $id)->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
->groupBy("m_proyek.proyek_id")->get();
if($data){
return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list project, please try again later!','code'=>400], 400);
}
}
} }

179
app/Http/Controllers/ProjectDokumenController.php

@ -7,93 +7,94 @@ use App\Models\DokumenProject;
class ProjectDokumenController extends Controller class ProjectDokumenController extends Controller
{ {
public function dokumenByProyekId($id){ public function dokumenByProyekId($id){
if($id && $id!="" && (int)$id > 0){ if(empty($id) || !is_int((int)$id)) {
$dataDokumen = DokumenProject::where("ref_id", $id)->get(); return response()->json(['status'=>'failed','message'=>'project id is required!','code'=>400], 400);
}
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200);
}else{ $document = DokumenProject::where("ref_id", $id)->get();
return response()->json(['status'=>'failed','message'=>'project id is required!','code'=>400], 400);
} if(count($document) == 0)
} return response()->json(['status'=>'','message'=>'Data not found!' ,'code'=>404], 404);
public function delete($id) return response()->json(['status'=>'success','data'=> $document ,'code'=>200], 200);
{ }
if($id && $id!="" && (int)$id > 0){
$dokumen = DokumenProject::find($id); public function delete($id)
if($dokumen){ {
if(file_exists($this->pathDocument.$dokumen->file)){ if(empty($id) || !is_int((int)$id)) {
unlink($this->pathDocument.$dokumen->file); return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
} }
$dokumen->delete();
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); $document = DokumenProject::find($id);
}else{ if(!$document){
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
} }
}else{
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); if(file_exists($this->pathDocument.$document->file)){
} unlink($this->pathDocument.$document->file);
} }
public function uploadProjectDokumen(Request $request) $document->delete();
{
if($request->hasFile('dokumen')){ return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
$dokumen = $request->file('dokumen'); }
$ref_id = $request->ref_id;
$extension = $dokumen->extension(); public function uploadProjectDokumen(Request $request)
$name = $dokumen->getClientOriginalName(); {
if($request->hasFile('dokumen')){
$result = $dokumen->move($this->pathDocument, $name); $document = $request->file('dokumen');
if($result){ $ref_id = $request->ref_id;
$data = [ $name = $document->getClientOriginalName();
'ref_id' => (int)$ref_id,
'file' => $name, $result = $document->move($this->pathDocument, $name);
'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document' // project-document-in-folder / project-document-out-folder if($result){
]; $data = [
'ref_id' => (int)$ref_id,
$result = DokumenProject::create($data); 'file' => $name,
'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document'
if($result){ ];
return response()->json(['status'=>'success','message'=>'file upload is successfully!','code'=>200], 200);
}else{ $result = DokumenProject::create($data);
unlink($this->pathDocument.$name);
return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); if(!$result){
} unlink($this->pathDocument.$name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}else{ }
return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400); return response()->json(['status'=>'success','message'=>'Upload successful!','code'=>200], 200);
}
}else{ }
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
} }
} return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400);
}
public function searchDocProject(Request $request){
$payload = $request->all(); public function searchDocProject(Request $request){
$dataBuilder = $this->setUpPayload($payload, 'document_project'); $payload = $request->all();
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $dataBuilder = $this->setUpPayload($payload, 'document_project');
$dataGet = $builder->get(); $builder = $dataBuilder['builder'];
$totalRecord = $countBuilder->count(); $countBuilder = $dataBuilder['count'];
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); $dataGet = $builder->get();
} $totalRecord = $countBuilder->count();
public function downloadDokumen($id) return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
{ }
if($id && $id!="" && (int)$id > 0){
$dokumen = DokumenProject::find($id); public function downloadDokumen($id)
if($dokumen){ {
if(file_exists($this->pathDocument.$dokumen->file)){ if(empty($id) || !is_int((int)$id))
$pathToFile = $this->pathDocument.$dokumen->file; return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
return response()->download($pathToFile);
}else{ $document = DokumenProject::find($id);
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400);
} if(!$document)
}else{ return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400);
} if(!file_exists($this->pathDocument.$document->file))
}else{ return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
} $pathToFile = $this->pathDocument.$document->file;
} return response()->download($pathToFile);
}
} }

297
app/Http/Controllers/RequestMaterialController.php

@ -8,165 +8,140 @@ use App\Models\MaterialResource;
class RequestMaterialController extends Controller class RequestMaterialController extends Controller
{ {
public function add(Request $request){ public function add(Request $request){
$this->validate($request, [
$this->validate($request, [ 'proyek_id' => 'required',
'proyek_id' => 'required', 'description' => 'required',
'description' => 'required', 'required_date' => 'required',
'required_date' => 'required', 'qty' => 'required',
'qty' => 'required', 'uom' => 'required',
'uom' => 'required', 'fom_date' => 'required',
'fom_date' => 'required', ]);
]);
$data = $request->all();
$data = $request->all();
$data['status'] = "fom";
$data['status'] = "fom"; $data['created_by'] = $this->currentName;
$data['created_by'] = $this->currentName;
$result = RequestMaterial::create($data);
$result = RequestMaterial::create($data);
if(!$result)
if($result){ return response()->json(['status'=>'failed','message'=>'Failed to add!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'request material successfully!', 'data'=>$result, 'code'=>200], 200);
}else{ return response()->json(['status'=>'success','message'=>'Data added!', 'data'=>$result, 'code'=>200], 200);
return response()->json(['status'=>'failed','message'=>'request material failed!','code'=>400], 400); }
}
} public function edit($id){
if(empty($id) || !is_int((int)$id))
public function edit($id){ return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); $result = RequestMaterial::find($id);
die();
} if($result)
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
$result = RequestMaterial::find($id);
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if($result){ }
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{ public function delete($id)
return response()->json(['status'=>'failed','message'=>'failed get data request material, please try again later!','code'=>400], 400); {
} $data = RequestMaterial::find($id);
}
if($data)
$delete = $data->delete();
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
if($delete)
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
public function delete($id) return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500);
{ }
$data = RequestMaterial::find($id);
public function search(Request $request)
if($data){ {
$delete = $data->delete(); $payload = $request->all();
}else{ $dataBuilder = $this->setUpPayload($payload, 'm_req_material');
return response()->json(['status'=>'failed','message'=>'data request material not found!','code'=>400], 400); $builder = $dataBuilder['builder'];
die(); $countBuilder = $dataBuilder['count'];
} $dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
if($delete){ }
return response()->json(['status'=>'success','message'=>'request material successfully deleted!','code'=>200], 200);
}else{ public function list()
return response()->json(['status'=>'failed','message'=>'request material failed deleted!','code'=>400], 400); {
} $data = RequestMaterial::all();
} $countData = $data->count();
public function search(Request $request) if($data)
{ return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_req_material'); return response()->json(['status'=>'failed','message'=>'failed get list request material, please try again later!','code'=>400], 400);
$builder = $dataBuilder['builder']; }
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); public function update(Request $request, $id)
$totalRecord = $countBuilder->count(); {
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); $dataForm = $request->all();
} if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
public function list()
{ $reqMaterial = RequestMaterial::find($id);
$data = RequestMaterial::all(); if(!$reqMaterial)
$countData = $data->count(); return response()->json(['status'=>'failed','message'=>'data request material not found!','code'=>400], 400);
if($data){ if(!isset($dataForm['status'])){
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); if(!$reqMaterial->update($request->all()))
}else{ return response()->json(['status'=>'failed','message'=>'request material failed updated!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'failed get list request material, please try again later!','code'=>400], 400); return response()->json(['status'=>'success','message'=>'request material successfully updated!','code'=>200], 200);
} }
}
if($dataForm['status']=="receipt to warehouse"){
public function update(Request $request, $id) $materialResource = MaterialResource::where('name', 'ilike', $reqMaterial->description)->first();
{ if($materialResource){
$dataForm = $request->all(); $reqMaterial->update($request->all());
if(!$id || (int) $id < 0 || $id==""){ $payloadMQty = $materialResource->qty + $reqMaterial->qty_received;
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); MaterialResource::where('id', $materialResource->id)->update(['qty' => $payloadMQty]);
die(); return response()->json(['status'=>'success', 'code'=>200], 200);
} }
$data = RequestMaterial::find($id);
if($data){ $reqMaterial->update($request->all());
if(!isset($dataForm['status'])){
$resultUpdate = $data->update($request->all()); $preparedMaterialResource = array(
if($resultUpdate){ "name" => $dataForm['description'],
return response()->json(['status'=>'success','message'=>'request material successfully updated!','code'=>200], 200); "uom" => $dataForm['uom'],
}else{ "unit_price" => 0,
return response()->json(['status'=>'failed','message'=>'request material failed updated!','code'=>400], 400); "description" => $dataForm['description'],
} "qty" => $reqMaterial->qty_received,
die(); "status" => "Barang tersedia",
} "created_by" => $this->currentName
if($dataForm['status']=="receipt to warehouse"){ );
$dataM = MaterialResource::where('name', 'ilike', $data->description)->first();
if($dataM){ if(!MaterialResource::create($preparedMaterialResource ))
$result = $data->update($request->all()); return response()->json(['status'=>'failed','message'=>'add data material resource failed!','code'=>400], 400);
$payloadMQty = $dataM->qty + $data->qty_received;
$resultUpdateM = MaterialResource::where('id', $dataM->id)->update(['qty' => $payloadMQty]); return response()->json(['status'=>'success','message'=>'add data material resource successfully!','code'=>200], 200);
return response()->json(['status'=>'success', 'code'=>200], 200); }
}else{
$result = $data->update($request->all()); if($dataForm['status']=="receipt to site"){
$dataPayloadM = array( $reqMaterial->update($request->all());
"name" => $dataForm['description'],
"uom" => $dataForm['uom'], $materialResource = MaterialResource::where('name', 'ilike', $reqMaterial->description)->first();
"unit_price" => 0, if(!$materialResource)
"description" => $dataForm['description'], return response()->json(['status'=>'failed','message'=>'update status receipt to site request material resource failed, because material is not exist in warehouse!','code'=>400], 400);
"qty" => $data->qty_received,
"status" => "Barang tersedia", $reqMaterial->update($request->all());
"created_by" => $this->currentName $payloadMQty = $materialResource->qty - $reqMaterial->qty_received;
);
$result = MaterialResource::create($dataPayloadM); if($payloadMQty < 0)
if($result){ return response()->json(['status'=>'failed','message'=>'update status receipt to site request material resource failed, because material is not exist in warehouse!','code'=>400], 400);
return response()->json(['status'=>'success','message'=>'add data material resource successfully!','code'=>200], 200);
}else{ MaterialResource::where('id', $materialResource->id)->update(['qty' => $payloadMQty]);
return response()->json(['status'=>'failed','message'=>'add data material resource failed!','code'=>400], 400); return response()->json(['status'=>'success', 'message'=>'request material status receipt to site successfully updated!','code'=>200], 200);
} }
}
if(!$reqMaterial->update($request->all()))
}else if($dataForm['status']=="receipt to site"){ return response()->json(['status'=>'failed','message'=>'request material failed updated!','code'=>400], 400);
$result = $data->update($request->all());
$dataM = MaterialResource::where('name', 'ilike', $data->description)->first(); return response()->json(['status'=>'success','message'=>'request material successfully updated!','code'=>200], 200);
if($dataM){ }
$result = $data->update($request->all());
$payloadMQty = $dataM->qty - $data->qty_received;
if($payloadMQty < 0){
return response()->json(['status'=>'failed','message'=>'update status receipt to site request material resource failed, because material is not exist in warehouse!','code'=>400], 400);
die();
}
$resultUpdateM = MaterialResource::where('id', $dataM->id)->update(['qty' => $payloadMQty]);
return response()->json(['status'=>'success', 'message'=>'request material status receipt to site successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'update status receipt to site request material resource failed, because material is not exist in warehouse!','code'=>400], 400);
}
}else{
$resultUpdate = $data->update($request->all());
if($resultUpdate){
return response()->json(['status'=>'success','message'=>'request material successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'request material failed updated!','code'=>400], 400);
}
}
}else{
return response()->json(['status'=>'failed','message'=>'data request material not found!','code'=>400], 400);
die();
}
}
} }

191
app/Http/Controllers/RoleController.php

@ -4,105 +4,98 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Role; use App\Models\Role;
class RoleController extends Controller class RoleController extends Controller
{ {
public function add(Request $request)
{ public function add(Request $request)
$this->validate($request, [ {
'name' => 'required', $this->validate($request, [
'description' => 'required' 'name' => 'required',
]); 'description' => 'required'
]);
$data = $request->all();
$data = $request->all();
$data['created_by'] = $this->currentName;
$data['created_by'] = $this->currentName;
$result = Role::create($data);
$result = Role::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'add data role successfully!','code'=>200], 200); if(!$result)
}else{ return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=>500], 500);
return response()->json(['status'=>'failed','message'=>'add data role failed!','code'=>400], 400);
} return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200);
} }
public function edit($id){ public function edit( $id){
if(!$id || (int) $id < 0 || $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);
die();
} $result = Role::find($id);
$result = Role::find($id); if(!$result)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{ }
return response()->json(['status'=>'failed','message'=>'failed get data role, please try again later!','code'=>400], 400);
} public function update(Request $request, $id)
} {
if(empty($id) || !is_int((int)$id))
public function update(Request $request, $id) return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
{
if(!$id || (int) $id < 0 || $id==""){ $data = Role::find($id);
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
} if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
$data = Role::find($id);
$result = $data->update($request->all());
if($data){
$result = $data->update($request->all()); if(!$result)
}else{ return response()->json(['status'=>'failed','message'=>'Failed to update the data!','code'=>500], 500);
return response()->json(['status'=>'failed','message'=>'data role not found!','code'=>400], 400);
die(); return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200);
} }
public function delete($id)
if($result){ {
return response()->json(['status'=>'success','message'=>'data role successfully updated!','code'=>200], 200); if(empty($id) || !is_int((int)$id))
}else{ return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'data role failed updated!','code'=>400], 400);
} $data = Role::find($id);
}
if(!$data)
public function delete($id) return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
{
$data = Role::find($id); $delete = $data->delete();
if($data){ if(!$delete)
$delete = $data->delete(); return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=>500], 500);
}else{
return response()->json(['status'=>'failed','message'=>'data role not found!','code'=>400], 400); return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
die(); }
}
public function search(Request $request)
{
if($delete){ $payload = $request->all();
return response()->json(['status'=>'success','message'=>'data role successfully deleted!','code'=>200], 200);
}else{ $dataBuilder = $this->setUpPayload($payload, 'm_roles');
return response()->json(['status'=>'failed','message'=>'data role failed deleted!','code'=>400], 400); $builder = $dataBuilder['builder'];
} $countBuilder = $dataBuilder['count'];
} $dataGet = $builder->get();
$totalRecord = $countBuilder->count();
public function search(Request $request)
{ return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
$payload = $request->all(); }
$dataBuilder = $this->setUpPayload($payload, 'm_roles');
$builder = $dataBuilder['builder']; public function list()
$countBuilder = $dataBuilder['count']; {
$dataGet = $builder->get(); $data = Role::all();
$totalRecord = $countBuilder->count(); $countData = $data->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} if(!$data)
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
public function list()
{ return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
$data = Role::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 role, please try again later!','code'=>400], 400);
}
}
} }

344
app/Http/Controllers/UserToActivityController.php

@ -4,209 +4,151 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\UserToActivity; use App\Models\UserToActivity;
use App\Models\ReportActivity;
use App\Models\Activity; use App\Models\Activity;
use App\Models\Image;
use App\Models\UserToProyek;
use Datatables; use Datatables;
class UserToActivityController extends Controller class UserToActivityController extends Controller
{ {
public function add(Request $request){ public function add(Request $request){
$this->validate($request, [ $this->validate($request, [
'activity_id' => 'required', 'activity_id' => 'required',
'user_id' => 'required' 'user_id' => 'required'
]); ]);
$data = $request->all();
$data['created_by'] = $this->currentName; $data = $request->all();
$data['created_by'] = $this->currentName;
$result = UserToActivity::create($data);
if($result){ if(!UserToActivity::create($data))
$updateActivity = Activity::find($request->activity_id); return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]);
$getWorkingHours = UserToProyek::where('user_id', $request->user_id)->first();
if($updateActivity && $getWorkingHours){ return response()->json(['status'=>'success','message'=>'Data added!', 'code'=> 200]);
$costPlanOld = $updateActivity==null? 0 : (int)$updateActivity->rencana_biaya; }
if($getWorkingHours->uom_standart_rate == "Day"){
$costUser = $getWorkingHours->standart_rate * $updateActivity->duration; public function addMultiple(Request $request){
}else if($getWorkingHours->uom_standart_rate == "Hour"){ $users_id = $request->user_id;
$costUser = ($getWorkingHours->standart_rate * 8) * $updateActivity->duration; // assumption standart working is 8 hours
} $data = UserToActivity::where("activity_id", $request->activity_id);
$costPlanNew = $costPlanOld + $costUser; if($data){
$updateActivity->rencana_biaya = $costPlanNew; $data->delete();
$updateActivity->save(); }
return response()->json(['status'=>'success','message'=>'user to activity gantt Project successfull created, and cost plant successfull update '.$costPlanNew,'code'=>200]);
}else{ if(is_array($users_id) && count($users_id) > 0){
return response()->json(['status'=>'success','message'=>'user to activity gantt Project successfull created','code'=>200]); $countRes = 0;
} foreach($users_id as $item){
}else{ $dataInsert = array(
return response()->json(['status'=>'failed','message'=>'user to activity gantt Project failed created','code'=>400]); "user_id" => $item,
} "activity_id" => $request->activity_id,
} "role_proyek_id" => $request->role_proyek_id,
"proyek_id" => $request->proyek_id,
public function addMultiple(Request $request){ "created_by" => $this->currentName
$users_id = $request->user_id; );
$result = UserToActivity::create($dataInsert);
$data = UserToActivity::where("activity_id", $request->activity_id); if($result){
$countRes++;
if($data){ }else{
$data->delete(); $countRes--;
} }
}
if(is_array($users_id) && count($users_id) > 0){
$countRes = 0; if($countRes == 0)
foreach($users_id as $item){ return response()->json(['status'=>'failed' ,'message'=>'Failed to add data!','code'=> 500]);
$dataInsert = array( $allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id);
"user_id" => $item, $dataUpdateCost = array(
"activity_id" => $request->activity_id, "rencana_biaya"=>$allCost,
"role_proyek_id" => $request->role_proyek_id, "updated_by"=> $this->currentName
"proyek_id" => $request->proyek_id, );
"created_by" => $this->currentName $actUpdate = Activity::find($request->activity_id);
); if($actUpdate){
$actUpdate->update($dataUpdateCost);
$result = UserToActivity::create($dataInsert); if($actUpdate->parent_id){
$this->updatedCostPlanning($actUpdate->parent_id);
if($result){ }
$countRes++; }
}else{ return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]);
$countRes--; }else{
} return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]);
} }
if($countRes > 0){ }
$allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id);
$dataUpdateCost = array( public function update(Request $request, $id){
"rencana_biaya"=>$allCost, if(empty($id) || !is_int((int)$id))
"updated_by"=> $this->currentName return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
);
$actUpdate = Activity::find($request->activity_id); $data = UserToActivity::find($id);
if($actUpdate){ if(!$data)
$actUpdate->update($dataUpdateCost); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if($actUpdate->parent_id){
$this->updatedCostPlanning($actUpdate->parent_id); if(!$data->update($request->all()));
} return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500);
}
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200);
return response()->json(['status'=>'success' ,'message'=>'user to activity gantt Project successfull created','code'=>200]); }
}else{
return response()->json(['status'=>'success' ,'message'=>'user to activity gantt Project failed created','code'=>400]); public function delete($id)
} {
}else{ $data = UserToActivity::find($id);
return response()->json(['status'=>'success' ,'message'=>'user to activity gantt Project successfull created','code'=>200]); if(!$data)
} return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400);
} if($data->delete()){
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
public function update(Request $request, $id){ }
if(!$id || (int) $id < 0 || $id==""){ return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500);
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); }
}
$data = UserToActivity::find($id); public function edit($id){
if($data){ if(!$id || (int) $id < 0 || $id==""){
$result = $data->update($request->all()); return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
}else{ die();
return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400); }
die();
} $result = UserToActivity::find($id);
if($result){ if(!$result)
return response()->json(['status'=>'success','message'=>'user to activity gantt Project successfully updated!','code'=>200], 200); return response()->json(['status'=>'failed','message'=>'failed get data tools resource, please try again later!','code'=>400], 400);
}else{
return response()->json(['status'=>'failed','message'=>'user to activity gantt Project failed updated!','code'=>400], 400); return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
} }
}
public function search(Request $request)
public function delete($id) {
{ $payload = $request->all();
$data = UserToActivity::find($id); $dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_activity');
if($data){ $builder = $dataBuilder['builder'];
$userId = $data->user_id; $countBuilder = $dataBuilder['count'];
$activityId = $data->activity_id; $dataGet = $builder->get();
$delete = $data->delete(); $totalRecord = $countBuilder->count();
if($delete){ return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
$this->deleteRelative($activityId, $userId); }
}
}else{ public function list()
return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400); {
die(); $data = UserToActivity::all();
} $countData = $data->count();
if($data){
if($delete){ return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
return response()->json(['status'=>'success','message'=>'user to activity gantt Project successfully deleted!','code'=>200], 200); }else{
}else{ return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'user to activity gantt Project failed deleted!','code'=>400], 400); }
} }
}
public function datatables(Request $request){
private function deleteRelative($id, $userId) $id_activity = $request->query('idact');
{ $data = UserToActivity::select("assign_hr_to_activity.id as id", "u.name as user_name", "mrp.name as role_name")
$dataRa = ReportActivity::where("activity_id", $id)->where("user_id", $userId)->get(); ->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id")
foreach ($dataRa as $ra) { ->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id")
$image = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); ->where('assign_hr_to_activity.activity_id', $id_activity)
foreach ($image as $value) { ->get();
if(file_exists($this->pathImage.$value->image)){ return Datatables::of($data)
unlink($this->pathImage.$value->image); ->addIndexColumn()
} ->addColumn('action', function($row){
} $actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-hr-delete"><i class="fa fa-trash"></i></a>';
return $actionBtn;
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); })
} ->rawColumns(['action'])->make(true);
ReportActivity::where("activity_id", $id)->where("user_id", $userId)->delete(); }
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = UserToActivity::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data tools resource, please try again later!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_activity');
$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()
{
$data = UserToActivity::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 user to activity gantt, please try again later!','code'=>400], 400);
}
}
public function datatables(Request $request){
$id_activity = $request->query('idact');
$data = UserToActivity::select("assign_hr_to_activity.id as id", "u.name as user_name", "mrp.name as role_name")
->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id")
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id")
->where('assign_hr_to_activity.activity_id', $id_activity)
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-hr-delete"><i class="fa fa-trash"></i></a>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
} }

45
app/Models/AssignMaterial.php

@ -3,6 +3,9 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Models\RequestMaterial;
use App\Models\Activity;
use Carbon\Carbon;
class AssignMaterial extends Model class AssignMaterial extends Model
{ {
@ -13,5 +16,47 @@ class AssignMaterial extends Model
protected $fillable = [ protected $fillable = [
'proyek_id', 'activity_id', 'material_id', 'qty_planning', 'budget', 'plan_date','created_at', 'created_by', 'updated_at', 'updated_by' 'proyek_id', 'activity_id', 'material_id', 'qty_planning', 'budget', 'plan_date','created_at', 'created_by', 'updated_at', 'updated_by'
];
protected $casts = [
'id' => 'integer',
'budget' => 'float',
'qty_planning' => 'float',
]; ];
public static function boot() {
parent::boot();
static::created(function($data) {
$activity = Activity::find($data->activity_id);
$material = RequestMaterial::where("id", $data->material_id)->first();
$old = $activity->rencana_biaya;
$activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning);
$activity->save();
$msg = Carbon::now()->toDateTimeString() . ": ".$activity->id." ".$activity->name.PHP_EOL;
$msg .= "Added: ".$material->desc." (".floatval($material->price)." * ".floatval($data->qty_planning)."), Cost plan old: ".$old." | +".$activity->rencana_biaya.PHP_EOL;
$msg .= "Data type (".gettype(floatval($material->price))." * ".gettype(floatval($material->qty_planning))."), ".gettype(floatval($old))." | ".gettype(floatval($activity->rencana_biaya)).PHP_EOL;
$msg .= "Data type origin (".gettype($material->price)." * ".gettype($material->qty_planning)."), ".gettype($old)." | ".gettype($activity->rencana_biaya).PHP_EOL;
$msg .= "------".PHP_EOL;
file_put_contents('activity_log.txt', $msg, FILE_APPEND | LOCK_EX);
});
static::deleted(function($data) {
$activity = Activity::where('id', $data->activity_id)->first();
$old = $activity->rencana_biaya;
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning);
$activity->save();
$material = RequestMaterial::where("id", $data->material_id)->first();
$msg = Carbon::now()->toDateTimeString() . ": ".$activity->id." ".$activity->name.PHP_EOL;
$msg .= "Deleted: ".$material->desc." (".floatval($data->budget)." * ".floatval($data->qty_planning)."), Cost plan old: ".$old." | -".$activity->rencana_biaya.PHP_EOL;
$msg .= "Data type (".gettype(floatval($data->budget))." * ".gettype(floatval($data->qty_planning))."), ".gettype(floatval($old))." | ".gettype(floatval($activity->rencana_biaya)).PHP_EOL;
$msg .= "Data type origin (".gettype($data->budget)." * ".gettype($data->qty_planning)."), ".gettype($old)." | ".gettype($activity->rencana_biaya).PHP_EOL;
$msg .= "------".PHP_EOL;
file_put_contents('activity_log.txt', $msg, FILE_APPEND | LOCK_EX);
});
}
} }

36
app/Models/RequestMaterial.php

@ -11,23 +11,29 @@ class RequestMaterial extends Model
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $casts = [
'id' => 'integer',
'price' => 'float',
'qty' => 'float',
];
protected $fillable = [ protected $fillable = [
'description', 'description',
'required_date', 'required_date',
'qty', 'qty',
'uom', 'uom',
'qty_received', 'qty_received',
'fom_date', 'fom_date',
'pr_date', 'pr_date',
'po_date', 'po_date',
'received_date', 'received_date',
'delivery_date', 'delivery_date',
'status', 'status',
'proyek_id', 'proyek_id',
'created_at', 'created_at',
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by', 'updated_by',
'price' 'price'
]; ];
} }

39
app/Models/UserToActivity.php

@ -3,6 +3,7 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Models\Activity;
class UserToActivity extends Model class UserToActivity extends Model
{ {
@ -17,9 +18,41 @@ class UserToActivity extends Model
'version_gantt_id', 'version_gantt_id',
'role_proyek_id', 'role_proyek_id',
'activity_id', 'activity_id',
'created_at', 'created_at',
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by' 'updated_by'
]; ];
public static function boot() {
parent::boot();
static::created(function($data) {
$activity = Activity::find($data->activity_id);
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first();
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
if($getWorkingHours->uom_standart_rate == "Hour")
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
$activity->rencana_biaya += $salary;
$activity->save();
});
static::deleted(function($data) {
$activity = Activity::find($data->activity_id);
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first();
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
if($getWorkingHours->uom_standart_rate == "Hour"){
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
}
$activity->rencana_biaya -= $salary;
$activity->save();
});
}
} }

6
config/api.php

@ -1,7 +1,5 @@
<?php <?php
return [ return [
'golang' => env('API_GOLANG', 'http://127.0.0.1:8090'),
'paxel' => env('API_PAXEL', 'https://paxel.oslogdev.com/db/search'),
'nominatim' => env('API_NOMINATIM', 'https://nominatim.oslogdev.com') 'nominatim' => env('API_NOMINATIM', 'https://nominatim.oslogdev.com')
]; ];
?> ?>

4
config/auth.php

@ -1,4 +1,4 @@
<?php <?php
return [ return [
'defaults' => [ 'defaults' => [
@ -19,4 +19,4 @@ return [
] ]
]; ];
?> ?>

5
config/jwt.php

@ -0,0 +1,5 @@
<?php
return [
'nominatim' => env('API_NOMINATIM', 'https://nominatim.oslogdev.com')
];
?>

0
sql/001-absensi.sql → database/sql/001-absensi.sql

51
routes/web.php

@ -1,33 +1,12 @@
<?php <?php
/** @var \Laravel\Lumen\Routing\Router $router */
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$router->get('/', function () use ($router) { $router->get('/', function () use ($router) {
return $router->app->version(); return $router->app->version();
}); });
$router->group(['prefix'=>'api'], function () use ($router) { $router->group(['prefix'=>'api'], function () use ($router) {
$router->post('/login', 'AuthController@login'); $router->post('/login', 'AuthController@login');
$router->post('/role/search', 'RoleController@search');
$router->post('/role/add', 'RoleController@add');
$router->get('/role/edit/{id}', 'RoleController@edit');
$router->put('/role/update/{id}', 'RoleController@update');
$router->delete('/role/delete/{id}', 'RoleController@delete');
$router->get('/role/list', 'RoleController@list');
$router->post('/menu/add', 'MenuController@add'); $router->post('/menu/add', 'MenuController@add');
$router->get('/menu/edit/{id}', 'MenuController@edit'); $router->get('/menu/edit/{id}', 'MenuController@edit');
$router->put('/menu/update/{id}', 'MenuController@update'); $router->put('/menu/update/{id}', 'MenuController@update');
@ -41,22 +20,28 @@ $router->group(['prefix'=>'api'], function () use ($router) {
$router->delete('/role-menu/delete-byrole/{id}', 'RoleMenuController@deleteByRole'); $router->delete('/role-menu/delete-byrole/{id}', 'RoleMenuController@deleteByRole');
$router->post('/role-menu/search', 'RoleMenuController@search'); $router->post('/role-menu/search', 'RoleMenuController@search');
$router->get('/role-menu/get-role/{id}', 'RoleMenuController@listMenu'); $router->get('/role-menu/get-role/{id}', 'RoleMenuController@listMenu');
$router->get('/document-project/download/{id}', 'ProjectDokumenController@downloadDokumen');
$router->group(['middleware' => 'auth'], function () use ($router) { $router->group(['middleware' => 'auth'], function () use ($router) {
$router->post('/role/search', 'RoleController@search');
$router->post('/role/add', 'RoleController@add');
$router->get('/role/edit/{id}', 'RoleController@edit');
$router->put('/role/update/{id}', 'RoleController@update');
$router->delete('/role/delete/{id}', 'RoleController@delete');
$router->get('/role/list', 'RoleController@list');
$router->post('/document-project/upload', 'ProjectDokumenController@uploadProjectDokumen'); $router->post('/document-project/upload', 'ProjectDokumenController@uploadProjectDokumen');
$router->get('/document-project/get/{id}', 'ProjectDokumenController@dokumenByProyekId'); $router->get('/document-project/get/{id}', 'ProjectDokumenController@dokumenByProyekId');
$router->delete('/document-project/delete/{id}', 'ProjectDokumenController@delete'); $router->delete('/document-project/delete/{id}', 'ProjectDokumenController@delete');
$router->post('/document-project/search', 'ProjectDokumenController@searchDocProject'); $router->post('/document-project/search', 'ProjectDokumenController@searchDocProject');
$router->get('/document-project/download/{id}', 'ProjectDokumenController@downloadDokumen');
$router->post('/document-activity/upload', 'ActivityDokumenController@uploadProjectDokumen'); $router->post('/document-activity/upload', 'ActivityDokumenController@uploadProjectDokumen');
$router->get('/document-activity/get/{id}', 'ActivityDokumenController@dokumenByActivityId'); $router->get('/document-activity/get/{id}', 'ActivityDokumenController@dokumenByActivityId');
$router->delete('/document-activity/delete/{id}', 'ActivityDokumenController@delete'); $router->delete('/document-activity/delete/{id}', 'ActivityDokumenController@delete');
$router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject'); $router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject');
$router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen'); $router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen');
$router->post('/project/search', 'ProjectController@search'); $router->post('/project/search', 'ProjectController@search');
$router->post('/project/add', 'ProjectController@add'); $router->post('/project/add', 'ProjectController@add');
$router->put('/project/update/{id}', 'ProjectController@update'); $router->put('/project/update/{id}', 'ProjectController@update');
@ -122,9 +107,9 @@ $router->group(['prefix'=>'api'], function () use ($router) {
$router->get('/request-material/list', 'RequestMaterialController@list'); $router->get('/request-material/list', 'RequestMaterialController@list');
$router->put('/request-material/update-warehouse-site/{id}', 'RequestMaterialController@updateWarehouseSite'); $router->put('/request-material/update-warehouse-site/{id}', 'RequestMaterialController@updateWarehouseSite');
$router->post('/material-to-project/assign', 'MaterialProjectController@assignMaterial'); $router->post('/material-to-project/assign', 'MaterialProjectController@assignMaterial');
$router->post('/material-resource/add', 'MaterialResourceController@add'); $router->post('/material-resource/add', 'MaterialResourceController@add');
$router->post('/material-resource/search', 'MaterialResourceController@search'); $router->post('/material-resource/search', 'MaterialResourceController@search');
$router->get('/material-resource/update/{id}', 'MaterialResourceController@edit'); $router->get('/material-resource/update/{id}', 'MaterialResourceController@edit');
@ -166,7 +151,7 @@ $router->group(['prefix'=>'api'], function () use ($router) {
$router->delete('/user-to-version-gantt/delete/{id}', 'UserToVersionGanttController@delete'); $router->delete('/user-to-version-gantt/delete/{id}', 'UserToVersionGanttController@delete');
$router->get('/user-to-version-gantt/list', 'UserToVersionGanttController@list'); $router->get('/user-to-version-gantt/list', 'UserToVersionGanttController@list');
$router->get('/user-to-version-gantt/get-by-gantt/{gantt_id}', 'UserToVersionGanttController@getByUserGantt'); $router->get('/user-to-version-gantt/get-by-gantt/{gantt_id}', 'UserToVersionGanttController@getByUserGantt');
$router->post('/user-to-activity/add', 'UserToActivityController@add'); $router->post('/user-to-activity/add', 'UserToActivityController@add');
$router->post('/user-to-activity/add-multiple', 'UserToActivityController@addMultiple'); $router->post('/user-to-activity/add-multiple', 'UserToActivityController@addMultiple');
$router->get('/user-to-activity/edit/{id}', 'UserToActivityController@edit'); $router->get('/user-to-activity/edit/{id}', 'UserToActivityController@edit');
@ -189,7 +174,7 @@ $router->group(['prefix'=>'api'], function () use ($router) {
$router->get('/activity/set-baseline/{gantt_id}', 'ActivityController@setBaseline'); $router->get('/activity/set-baseline/{gantt_id}', 'ActivityController@setBaseline');
$router->post('/activity/get-curva-s', 'ActivityController@getCalculateCurvaS'); $router->post('/activity/get-curva-s', 'ActivityController@getCalculateCurvaS');
$router->get('/activity/synchronize-report/{gantt_id}', 'ActivityController@synchronizeReport'); $router->get('/activity/synchronize-report/{gantt_id}', 'ActivityController@synchronizeReport');
$router->post('/link', 'LinkController@add'); $router->post('/link', 'LinkController@add');
$router->put('/link/{id}', 'LinkController@update'); $router->put('/link/{id}', 'LinkController@update');
$router->delete('/link/{id}', 'LinkController@delete'); $router->delete('/link/{id}', 'LinkController@delete');
@ -296,7 +281,7 @@ $router->group(['prefix'=>'api'], function () use ($router) {
$router->post('/dashboard/search-user-presence', 'DashboardController@searchUserPresencePoints'); $router->post('/dashboard/search-user-presence', 'DashboardController@searchUserPresencePoints');
$router->post('/dashboard/status-proyek', 'DashboardController@statusProyek'); $router->post('/dashboard/status-proyek', 'DashboardController@statusProyek');
$router->post('/dashboard/curva-s', 'DashboardController@curvaS'); $router->post('/dashboard/curva-s', 'DashboardController@curvaS');
$router->post('/report-activity/add', 'ReportActivityController@add'); $router->post('/report-activity/add', 'ReportActivityController@add');
$router->get('/report-activity/edit/{id}', 'ReportActivityController@edit'); $router->get('/report-activity/edit/{id}', 'ReportActivityController@edit');
$router->put('/report-activity/update/{id}', 'ReportActivityController@update'); $router->put('/report-activity/update/{id}', 'ReportActivityController@update');
@ -313,7 +298,7 @@ $router->group(['prefix'=>'api'], function () use ($router) {
$router->get('/report-activity-material/datatables', 'ReportActivityMaterialController@datatables'); $router->get('/report-activity-material/datatables', 'ReportActivityMaterialController@datatables');
$router->post('/report-activity-material/update-status', 'ReportActivityMaterialController@updateStatusStartFinish'); $router->post('/report-activity-material/update-status', 'ReportActivityMaterialController@updateStatusStartFinish');
$router->get('/report-activity-material/test', 'ReportActivityMaterialController@countForProgressTest'); $router->get('/report-activity-material/test', 'ReportActivityMaterialController@countForProgressTest');
$router->post('/waypoint/add', 'WaypointController@add'); $router->post('/waypoint/add', 'WaypointController@add');
$router->get('/waypoint/edit/{id}', 'WaypointController@edit'); $router->get('/waypoint/edit/{id}', 'WaypointController@edit');
@ -420,5 +405,5 @@ $router->group(['prefix'=>'api'], function () use ($router) {
$router->delete('/project-to-checklist-k3/delete/{id}', 'ProjectToChecklistK3Controller@delete'); $router->delete('/project-to-checklist-k3/delete/{id}', 'ProjectToChecklistK3Controller@delete');
$router->get('/project-to-checklist-k3/list', 'ProjectToChecklistK3Controller@list'); $router->get('/project-to-checklist-k3/list', 'ProjectToChecklistK3Controller@list');
}); });
}); });

Loading…
Cancel
Save