Browse Source

Merge pull request 'Dev-Farhan' (#305) from Dev-Farhan into staging

Reviewed-on: ordo/adw-backend#305
pull/1/head
farhantock 1 year ago
parent
commit
270e05f783
  1. 135
      app/Helpers/MasterFunctionsHelper.php
  2. 29
      app/Http/Controllers/AuthController.php
  3. 110
      app/Http/Controllers/CompanyController.php
  4. 235
      app/Http/Controllers/Controller.php
  5. 27
      app/Http/Controllers/DashboardBoDController.php
  6. 195
      app/Http/Controllers/MenuCompanyController.php
  7. 339
      app/Http/Controllers/ProjectController.php
  8. 37
      app/Models/Company.php
  9. 12
      app/Models/Divisi.php
  10. 3
      app/Models/HumanResource.php
  11. 27
      app/Models/MenuCompany.php
  12. 5
      app/Models/Project.php
  13. 2
      app/Models/ProjectPhase.php
  14. 2
      app/Models/ProjectRole.php
  15. 2
      app/Models/ProjectType.php
  16. 2
      app/Models/Role.php
  17. 2
      app/Models/RoleMenu.php
  18. 2
      app/Models/Satuan.php
  19. 20
      routes/web.php

135
app/Helpers/MasterFunctionsHelper.php

@ -36,7 +36,8 @@ class MasterFunctionsHelper
return json_decode($output); return json_decode($output);
} }
public static function countDays($ganttId, $start, $end){ public static function countDays($ganttId, $start, $end)
{
$dayOffs = VersionGantt::where('id', $ganttId)->first()->config_dayoff; $dayOffs = VersionGantt::where('id', $ganttId)->first()->config_dayoff;
$diff = date_diff($start, $end); $diff = date_diff($start, $end);
$endCount = clone $end; $endCount = clone $end;
@ -191,7 +192,7 @@ class MasterFunctionsHelper
$end = new \DateTime($maxDate . ' Friday'); $end = new \DateTime($maxDate . ' Friday');
$end->modify('next Friday'); $end->modify('next Friday');
$end->modify('next Friday'); $end->modify('next Friday');
/* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged
$interval = new \DateInterval('P7D'); $interval = new \DateInterval('P7D');
} else { } else {
$actualMaxDate = DB::table('assign_material_to_activity as ama') $actualMaxDate = DB::table('assign_material_to_activity as ama')
@ -279,19 +280,18 @@ class MasterFunctionsHelper
->where('activity_id', '=', $keyPlanM->id) ->where('activity_id', '=', $keyPlanM->id)
->groupBy('activity_id') ->groupBy('activity_id')
->first(); ->first();
if($keyPlanM->duration){ if ($keyPlanM->duration) {
$weekCount = $keyPlanM->duration / 7; $weekCount = $keyPlanM->duration / 7;
$weeklyPlan = $weekCount >= 1 ? $sumVolPlan->ttl_qty_plan / $weekCount : $sumVolPlan->ttl_qty_plan / $weekCount / 7; $weeklyPlan = $weekCount >= 1 ? $sumVolPlan->ttl_qty_plan / $weekCount : $sumVolPlan->ttl_qty_plan / $weekCount / 7;
// $weeklyProgress = $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; // $weeklyProgress = $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
$weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; $weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
// $bobotHari = $keyPlanM->bobot_planning / $keyPlanM->duration; // $bobotHari = $keyPlanM->bobot_planning / $keyPlanM->duration;
}else{ } else {
// $weeklyProgress = 0; // $weeklyProgress = 0;
$weekCount = 1 / 7; $weekCount = 1 / 7;
$weeklyPlan = $weekCount >= 1 ? $sumVolPlan->ttl_qty_plan / $weekCount : $sumVolPlan->ttl_qty_plan / $weekCount / 7; $weeklyPlan = $weekCount >= 1 ? $sumVolPlan->ttl_qty_plan / $weekCount : $sumVolPlan->ttl_qty_plan / $weekCount / 7;
// $weeklyProgress = $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; // $weeklyProgress = $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
$weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; $weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
} }
// $weeklyPlan = $weekCount > 0 ? $keyPlanM->bobot_planning / $weekCount : 0; // $weeklyPlan = $weekCount > 0 ? $keyPlanM->bobot_planning / $weekCount : 0;
@ -485,7 +485,7 @@ class MasterFunctionsHelper
$end = new \DateTime($maxDate . ' Friday'); $end = new \DateTime($maxDate . ' Friday');
// $end->modify('next Friday'); // $end->modify('next Friday');
// $end->modify('next Friday'); // $end->modify('next Friday');
/* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged
$interval = new \DateInterval('P1D'); $interval = new \DateInterval('P1D');
} else { } else {
$actualMaxDate = DB::table('assign_material_to_activity as ama') $actualMaxDate = DB::table('assign_material_to_activity as ama')
@ -539,7 +539,11 @@ class MasterFunctionsHelper
$dataActualM = DB::table('report_activity_material as ram') $dataActualM = DB::table('report_activity_material as ram')
->join('m_activity as ma', 'ma.id', '=', 'ram.activity_id') ->join('m_activity as ma', 'ma.id', '=', 'ram.activity_id')
->select('ram.activity_id', 'ram.qty as qty_actual', 'ma.bobot_planning', 'ma.name', ->select(
'ram.activity_id',
'ram.qty as qty_actual',
'ma.bobot_planning',
'ma.name',
DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'), DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'),
DB::raw('(SELECT SUM(ram.qty) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS sum_qty_actual'), DB::raw('(SELECT SUM(ram.qty) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS sum_qty_actual'),
DB::raw('(SELECT DISTINCT status_activity FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS status_activity'), DB::raw('(SELECT DISTINCT status_activity FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS status_activity'),
@ -556,12 +560,12 @@ class MasterFunctionsHelper
// if (new \DateTime($loopDay) < $today) { // if (new \DateTime($loopDay) < $today) {
// $statusCutOfDate = true; // $statusCutOfDate = true;
// } // }
if (new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday')){ if (new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday')) {
$progressPlanKomulatifWeek[] += round($tmpProgressPlanWeek,2); $progressPlanKomulatifWeek[] += round($tmpProgressPlanWeek, 2);
if (new \DateTime($loopDay . ' Friday') <= new \DateTime($today . ' Friday')) { if (new \DateTime($loopDay . ' Friday') <= new \DateTime($today . ' Friday')) {
// $tempPercentageReal[] = round($tempTtlPercentActual, 2); // $tempPercentageReal[] = round($tempTtlPercentActual, 2);
$progressActualKomulatifWeek[] += round($tmpProgressActualWeek,2); $progressActualKomulatifWeek[] += round($tmpProgressActualWeek, 2);
} }
$dateWeek[] = [$loopDay]; $dateWeek[] = [$loopDay];
} }
@ -577,7 +581,7 @@ class MasterFunctionsHelper
// Menghitung selisih hari // Menghitung selisih hari
$interval = $startDate->diff($endDate); $interval = $startDate->diff($endDate);
// Mengambil hasil selisih hari // Mengambil hasil selisih hari
$duration = (int) $interval->days+1; $duration = (int) $interval->days + 1;
// }else{ // }else{
// $duration = $keyPlanM->duration + 2; // $duration = $keyPlanM->duration + 2;
// } // }
@ -602,22 +606,21 @@ class MasterFunctionsHelper
# hitung untuk persentase progress actual # hitung untuk persentase progress actual
// $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100; // $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100;
// jika total report > dari planning // jika total report > dari planning
if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){ if ($keyActualM->sum_qty_actual > $keyActualM->qty_plan) {
$progressActualWeek = ($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * $keyActualM->bobot_planning; $progressActualWeek = ($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * $keyActualM->bobot_planning;
}else{ } else {
// jika total report < dari planning // jika total report < dari planning
// $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning; // $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning;
if($keyActualM->qty_actual == 0){ if ($keyActualM->qty_actual == 0) {
$progressActualWeek = 0; $progressActualWeek = 0;
}else{ } else {
$progressActualWeek = ($keyActualM->qty_actual / $keyActualM->qty_plan) * $keyActualM->bobot_planning; $progressActualWeek = ($keyActualM->qty_actual / $keyActualM->qty_plan) * $keyActualM->bobot_planning;
} }
} }
if($keyActualM->status_activity == 'done'){ if ($keyActualM->status_activity == 'done') {
$progressActualWeek = $keyActualM->bobot_planning / $keyActualM->count_report; $progressActualWeek = $keyActualM->bobot_planning / $keyActualM->count_report;
} } else {
else{ $progressActualWeek = $progressActualWeek > ($keyActualM->bobot_planning * 95) / 100 ? ($keyActualM->bobot_planning * 95) / 100 : $progressActualWeek;
$progressActualWeek = $progressActualWeek > ($keyActualM->bobot_planning*95)/100 ? ($keyActualM->bobot_planning*95)/100 : $progressActualWeek;
} }
$dataActivityActual[] = array( $dataActivityActual[] = array(
'progressActualDay' => $progressActualWeek, 'progressActualDay' => $progressActualWeek,
@ -640,13 +643,13 @@ class MasterFunctionsHelper
"tmpProgressActualWeek" => $tmpProgressActualWeek, "tmpProgressActualWeek" => $tmpProgressActualWeek,
"progressPlanWeek" => $tmpProgressPlanWeek "progressPlanWeek" => $tmpProgressPlanWeek
); );
} }
$dataFinal[] = array( $dataFinal[] = array(
// "date" => $dateWeek, // "date" => $dateWeek,
"proyek_name" => $dataProject->nama, "proyek_name" => $dataProject->nama,
"data" => ["date" => $dateWeek, "data" => [
"date" => $dateWeek,
"percentagePlan" => $progressPlanKomulatifWeek, "percentagePlan" => $progressPlanKomulatifWeek,
"percentageReal" => $progressActualKomulatifWeek, "percentageReal" => $progressActualKomulatifWeek,
"data_details" => $dataActivityPlanDate "data_details" => $dataActivityPlanDate
@ -696,7 +699,7 @@ class MasterFunctionsHelper
$end = new \DateTime($maxDate . ' Friday'); $end = new \DateTime($maxDate . ' Friday');
$end->modify('next Friday'); $end->modify('next Friday');
$end->modify('next Friday'); $end->modify('next Friday');
/* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged
$interval = new \DateInterval('P7D'); $interval = new \DateInterval('P7D');
} else { } else {
// $maxDate = DB::table('assign_material_to_activity as ama') // $maxDate = DB::table('assign_material_to_activity as ama')
@ -865,7 +868,7 @@ class MasterFunctionsHelper
$sumPercentageActual += $keyActualM->bobot_planning / $reportCount; $sumPercentageActual += $keyActualM->bobot_planning / $reportCount;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else { } else {
if ( $actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) { if ($actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) {
$sumPercentageActual += ($actual * $keyActualM->bobot_planning) * (95 / 100); $sumPercentageActual += ($actual * $keyActualM->bobot_planning) * (95 / 100);
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else { } else {
@ -1008,7 +1011,7 @@ class MasterFunctionsHelper
$end = new \DateTime($maxDate . ' Friday'); $end = new \DateTime($maxDate . ' Friday');
$end->modify('next Friday'); $end->modify('next Friday');
// $end->modify('next Friday'); // $end->modify('next Friday');
/* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged
$interval = new \DateInterval('P7D'); $interval = new \DateInterval('P7D');
} else { } else {
// $maxDate = DB::table('assign_material_to_activity as ama') // $maxDate = DB::table('assign_material_to_activity as ama')
@ -1103,19 +1106,18 @@ class MasterFunctionsHelper
->groupBy('activity_id') ->groupBy('activity_id')
->first(); ->first();
if($keyPlanM->duration){ if ($keyPlanM->duration) {
$weekCount = $keyPlanM->duration / 7; $weekCount = $keyPlanM->duration / 7;
$weeklyPlan = $weekCount >= 1 ? $sumVolPlan->ttl_qty_plan / $weekCount : $sumVolPlan->ttl_qty_plan / $weekCount / 7; $weeklyPlan = $weekCount >= 1 ? $sumVolPlan->ttl_qty_plan / $weekCount : $sumVolPlan->ttl_qty_plan / $weekCount / 7;
// $weeklyProgress = $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; // $weeklyProgress = $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
$weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; $weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
// $bobotHari = $keyPlanM->bobot_planning / $keyPlanM->duration; // $bobotHari = $keyPlanM->bobot_planning / $keyPlanM->duration;
}else{ } else {
// $weeklyProgress = 0; // $weeklyProgress = 0;
$weekCount = 1 / 7; $weekCount = 1 / 7;
$weeklyPlan = $weekCount >= 1 ? $sumVolPlan->ttl_qty_plan / $weekCount : $sumVolPlan->ttl_qty_plan / $weekCount / 7; $weeklyPlan = $weekCount >= 1 ? $sumVolPlan->ttl_qty_plan / $weekCount : $sumVolPlan->ttl_qty_plan / $weekCount / 7;
// $weeklyProgress = $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; // $weeklyProgress = $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
$weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning; $weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
} }
// $weeklyPlan = $sumVolPlan->ttl_qty_plan / $weekCount; // $weeklyPlan = $sumVolPlan->ttl_qty_plan / $weekCount;
@ -1192,7 +1194,7 @@ class MasterFunctionsHelper
$sumPercentageActual += $keyActualM->bobot_planning / $reportCount; $sumPercentageActual += $keyActualM->bobot_planning / $reportCount;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else { } else {
if ( $actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) { if ($actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) {
$sumPercentageActual += ($actual * $keyActualM->bobot_planning) * (95 / 100); $sumPercentageActual += ($actual * $keyActualM->bobot_planning) * (95 / 100);
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual; // $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else { } else {
@ -1351,7 +1353,7 @@ class MasterFunctionsHelper
$end = new \DateTime($maxDate . ' Friday'); $end = new \DateTime($maxDate . ' Friday');
// $end->modify('next Friday'); // $end->modify('next Friday');
// $end->modify('next Friday'); // $end->modify('next Friday');
/* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged
$interval = new \DateInterval('P1D'); $interval = new \DateInterval('P1D');
} else { } else {
$maxDate = $dataProject->akhir_proyek; $maxDate = $dataProject->akhir_proyek;
@ -1422,7 +1424,11 @@ class MasterFunctionsHelper
$dataActualM = DB::table('report_activity_material as ram') $dataActualM = DB::table('report_activity_material as ram')
->join('m_activity as ma', 'ma.id', '=', 'ram.activity_id') ->join('m_activity as ma', 'ma.id', '=', 'ram.activity_id')
->select('ram.activity_id', 'ram.qty as qty_actual', 'ma.bobot_planning', 'ma.name', ->select(
'ram.activity_id',
'ram.qty as qty_actual',
'ma.bobot_planning',
'ma.name',
DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'), DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'),
DB::raw('(SELECT SUM(ram.qty) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS sum_qty_actual'), DB::raw('(SELECT SUM(ram.qty) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS sum_qty_actual'),
DB::raw('(SELECT DISTINCT status_activity FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS status_activity'), DB::raw('(SELECT DISTINCT status_activity FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS status_activity'),
@ -1436,12 +1442,12 @@ class MasterFunctionsHelper
$dataActivityPlan = []; $dataActivityPlan = [];
$dataActivityActual = []; $dataActivityActual = [];
$today = date('Y-m-d'); $today = date('Y-m-d');
if (new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday')){ if (new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday')) {
$progressPlanKomulatifWeek[] += round($tmpProgressPlanWeek,2); $progressPlanKomulatifWeek[] += round($tmpProgressPlanWeek, 2);
if (new \DateTime($loopDay . ' Friday') <= new \DateTime($today . ' Friday')) { if (new \DateTime($loopDay . ' Friday') <= new \DateTime($today . ' Friday')) {
// $tempPercentageReal[] = round($tempTtlPercentActual, 2); // $tempPercentageReal[] = round($tempTtlPercentActual, 2);
$progressActualKomulatifWeek[] += round($tmpProgressActualWeek,2); $progressActualKomulatifWeek[] += round($tmpProgressActualWeek, 2);
} }
$dateWeek[] = [$loopDay]; $dateWeek[] = [$loopDay];
} }
@ -1458,7 +1464,7 @@ class MasterFunctionsHelper
// Menghitung selisih hari // Menghitung selisih hari
$interval = $startDate->diff($endDate); $interval = $startDate->diff($endDate);
// Mengambil hasil selisih hari // Mengambil hasil selisih hari
$duration = (int) $interval->days+1; $duration = (int) $interval->days + 1;
// }else{ // }else{
// $duration = $keyPlanM->duration + 2; // $duration = $keyPlanM->duration + 2;
// } // }
@ -1486,18 +1492,18 @@ class MasterFunctionsHelper
# hitung untuk persentase progress actual # hitung untuk persentase progress actual
// $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100; // $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100;
// jika total report > dari planning // jika total report > dari planning
if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){ if ($keyActualM->sum_qty_actual > $keyActualM->qty_plan) {
$progressActualWeek = (($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) *$keyActualM->bobot_planning/100; $progressActualWeek = (($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) * $keyActualM->bobot_planning / 100;
}else{ } else {
// jika total report < dari planning // jika total report < dari planning
// $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning; // $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning;
if($keyActualM->qty_actual == 0){ if ($keyActualM->qty_actual == 0) {
$progressActualWeek = 0; $progressActualWeek = 0;
}else{ } else {
$progressActualWeek = ($keyActualM->qty_actual / $keyActualM->qty_plan) * $keyActualM->bobot_planning; $progressActualWeek = ($keyActualM->qty_actual / $keyActualM->qty_plan) * $keyActualM->bobot_planning;
} }
} }
if($keyActualM->status_activity == 'done'){ if ($keyActualM->status_activity == 'done') {
// if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){ // if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){
// } // }
@ -1513,9 +1519,8 @@ class MasterFunctionsHelper
// $progressActualWeek = $progressActualWeek > $keyActualM->bobot_planning ? $keyActualM->bobot_planning : $progressActualWeek; // $progressActualWeek = $progressActualWeek > $keyActualM->bobot_planning ? $keyActualM->bobot_planning : $progressActualWeek;
// jika report lebih dari 1 x, maka harusnya di bagi sabanyak jumlah report, // jika report lebih dari 1 x, maka harusnya di bagi sabanyak jumlah report,
// contoh ada 3 report, report ke 1 adalah 5 maka 100/3 dan di looping // contoh ada 3 report, report ke 1 adalah 5 maka 100/3 dan di looping
} } else {
else{ $progressActualWeek = $progressActualWeek > ($keyActualM->bobot_planning * 95) / 100 ? ($keyActualM->bobot_planning * 95) / 100 : $progressActualWeek;
$progressActualWeek = $progressActualWeek > ($keyActualM->bobot_planning*95)/100 ? ($keyActualM->bobot_planning*95)/100 : $progressActualWeek;
} }
$dataActivityActual[] = array( $dataActivityActual[] = array(
'progressActualDay' => $progressActualWeek, 'progressActualDay' => $progressActualWeek,
@ -1539,13 +1544,13 @@ class MasterFunctionsHelper
"tmpProgressActualWeek" => $tmpProgressActualWeek, "tmpProgressActualWeek" => $tmpProgressActualWeek,
"progressPlanWeek" => $tmpProgressPlanWeek "progressPlanWeek" => $tmpProgressPlanWeek
); );
} }
$dataFinal[] = array( $dataFinal[] = array(
// "date" => $dateWeek, // "date" => $dateWeek,
"proyek_name" => $dataProject->nama, "proyek_name" => $dataProject->nama,
"data" => ["date" => $dateWeek, "data" => [
"date" => $dateWeek,
"percentagePlan" => $progressPlanKomulatifWeek, "percentagePlan" => $progressPlanKomulatifWeek,
"percentageReal" => $progressActualKomulatifWeek "percentageReal" => $progressActualKomulatifWeek
// "data_details" => $dataActivityPlanDate // "data_details" => $dataActivityPlanDate
@ -1596,7 +1601,7 @@ class MasterFunctionsHelper
$end = new \DateTime($maxDate . ' Friday'); $end = new \DateTime($maxDate . ' Friday');
// $end->modify('next Friday'); // $end->modify('next Friday');
// $end->modify('next Friday'); // $end->modify('next Friday');
/* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged
$interval = new \DateInterval('P1D'); $interval = new \DateInterval('P1D');
} else { } else {
$maxDate = $dataProject->akhir_proyek; $maxDate = $dataProject->akhir_proyek;
@ -1671,7 +1676,11 @@ class MasterFunctionsHelper
->join('m_version_gantt as mvg', 'mvg.hierarchy_ftth_id', '=', 'mhf.id') ->join('m_version_gantt as mvg', 'mvg.hierarchy_ftth_id', '=', 'mhf.id')
->join('m_activity as ma', 'ma.version_gantt_id', '=', 'mvg.id') ->join('m_activity as ma', 'ma.version_gantt_id', '=', 'mvg.id')
->join('report_activity_material as ram', 'ram.activity_id', '=', 'ma.id') ->join('report_activity_material as ram', 'ram.activity_id', '=', 'ma.id')
->select('ram.activity_id', 'ram.qty as qty_actual', 'ma.bobot_planning', 'ma.name', ->select(
'ram.activity_id',
'ram.qty as qty_actual',
'ma.bobot_planning',
'ma.name',
DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'), DB::raw('(SELECT SUM(amta.qty_planning) FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS qty_plan'),
DB::raw('(SELECT SUM(ram.qty) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS sum_qty_actual'), DB::raw('(SELECT SUM(ram.qty) FROM report_activity_material ram WHERE ram.activity_id = ma.id) AS sum_qty_actual'),
DB::raw('(SELECT DISTINCT status_activity FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS status_activity'), DB::raw('(SELECT DISTINCT status_activity FROM assign_material_to_activity amta WHERE amta.activity_id = ram.activity_id) AS status_activity'),
@ -1686,12 +1695,12 @@ class MasterFunctionsHelper
$dataActivityPlan = []; $dataActivityPlan = [];
$dataActivityActual = []; $dataActivityActual = [];
$today = date('Y-m-d'); $today = date('Y-m-d');
if (new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday')){ if (new \DateTime($loopDay) == new \DateTime($loopDay . ' Friday')) {
$progressPlanKomulatifWeek[] += round($tmpProgressPlanWeek,2); $progressPlanKomulatifWeek[] += round($tmpProgressPlanWeek, 2);
if (new \DateTime($loopDay . ' Friday') <= new \DateTime($today . ' Friday')) { if (new \DateTime($loopDay . ' Friday') <= new \DateTime($today . ' Friday')) {
// $tempPercentageReal[] = round($tempTtlPercentActual, 2); // $tempPercentageReal[] = round($tempTtlPercentActual, 2);
$progressActualKomulatifWeek[] += round($tmpProgressActualWeek,2); $progressActualKomulatifWeek[] += round($tmpProgressActualWeek, 2);
} }
$dateWeek[] = [$loopDay]; $dateWeek[] = [$loopDay];
} }
@ -1711,7 +1720,7 @@ class MasterFunctionsHelper
// Menghitung selisih hari // Menghitung selisih hari
$interval = $startDate->diff($endDate); $interval = $startDate->diff($endDate);
// Mengambil hasil selisih hari // Mengambil hasil selisih hari
$duration = (int) $interval->days+1; $duration = (int) $interval->days + 1;
// }else{ // }else{
// $duration = $keyPlanM->duration + 2; // $duration = $keyPlanM->duration + 2;
// } // }
@ -1742,18 +1751,18 @@ class MasterFunctionsHelper
# hitung untuk persentase progress actual # hitung untuk persentase progress actual
// $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100; // $progressActualWeek = ((((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*100)*$keyActualM->bobot_planning)/100;
// jika total report > dari planning // jika total report > dari planning
if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){ if ($keyActualM->sum_qty_actual > $keyActualM->qty_plan) {
$progressActualWeek = (($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) *$keyActualM->bobot_planning/100; $progressActualWeek = (($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) * $keyActualM->bobot_planning / 100;
}else{ } else {
// jika total report < dari planning // jika total report < dari planning
// $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning; // $progressActualWeek = ((($keyActualM->qty_actual / $keyActualM->sum_qty_actual) * 100) / $keyActualM->qty_plan)*$keyActualM->bobot_planning;
if($keyActualM->qty_actual == 0){ if ($keyActualM->qty_actual == 0) {
$progressActualWeek = 0; $progressActualWeek = 0;
}else{ } else {
$progressActualWeek = ($keyActualM->qty_actual / $keyActualM->qty_plan) * $keyActualM->bobot_planning; $progressActualWeek = ($keyActualM->qty_actual / $keyActualM->qty_plan) * $keyActualM->bobot_planning;
} }
} }
if($keyActualM->status_activity == 'done'){ if ($keyActualM->status_activity == 'done') {
// if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){ // if($keyActualM->sum_qty_actual > $keyActualM->qty_plan){
// } // }
@ -1769,9 +1778,8 @@ class MasterFunctionsHelper
// $progressActualWeek = $progressActualWeek > $keyActualM->bobot_planning ? $keyActualM->bobot_planning : $progressActualWeek; // $progressActualWeek = $progressActualWeek > $keyActualM->bobot_planning ? $keyActualM->bobot_planning : $progressActualWeek;
// jika report lebih dari 1 x, maka harusnya di bagi sabanyak jumlah report, // jika report lebih dari 1 x, maka harusnya di bagi sabanyak jumlah report,
// contoh ada 3 report, report ke 1 adalah 5 maka 100/3 dan di looping // contoh ada 3 report, report ke 1 adalah 5 maka 100/3 dan di looping
} } else {
else{ $progressActualWeek = $progressActualWeek > ($keyActualM->bobot_planning * 95) / 100 ? ($keyActualM->bobot_planning * 95) / 100 : $progressActualWeek;
$progressActualWeek = $progressActualWeek > ($keyActualM->bobot_planning*95)/100 ? ($keyActualM->bobot_planning*95)/100 : $progressActualWeek;
} }
$dataActivityActual[] = array( $dataActivityActual[] = array(
'progressActualDay' => $progressActualWeek, 'progressActualDay' => $progressActualWeek,
@ -1795,13 +1803,13 @@ class MasterFunctionsHelper
"tmpProgressActualWeek" => $tmpProgressActualWeek, "tmpProgressActualWeek" => $tmpProgressActualWeek,
"progressPlanWeek" => $tmpProgressPlanWeek "progressPlanWeek" => $tmpProgressPlanWeek
); );
} }
$dataFinal[] = array( $dataFinal[] = array(
// "date" => $dateWeek, // "date" => $dateWeek,
"proyek_name" => $dataProject->nama, "proyek_name" => $dataProject->nama,
"data" => ["date" => $dateWeek, "data" => [
"date" => $dateWeek,
"percentagePlan" => $progressPlanKomulatifWeek, "percentagePlan" => $progressPlanKomulatifWeek,
"percentageReal" => $progressActualKomulatifWeek "percentageReal" => $progressActualKomulatifWeek
// "data_details" => $dataActivityPlanDate // "data_details" => $dataActivityPlanDate
@ -1849,7 +1857,7 @@ class MasterFunctionsHelper
if (isset($dataPayload['end_date'])) { if (isset($dataPayload['end_date'])) {
$maxDate = $dataPayload['end_date']; $maxDate = $dataPayload['end_date'];
$end = new \DateTime($maxDate); $end = new \DateTime($maxDate);
/* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged /* $interval = \DateInterval::createFromDateString('1 day'); */ // should be using this but its bugged
$interval = new \DateInterval('P7D'); $interval = new \DateInterval('P7D');
} else { } else {
// $maxDate = DB::table('assign_material_to_activity as ama') // $maxDate = DB::table('assign_material_to_activity as ama')
@ -2040,5 +2048,4 @@ class MasterFunctionsHelper
return $dataFinal; return $dataFinal;
} }
} }

29
app/Http/Controllers/AuthController.php

@ -11,6 +11,7 @@ use App\Models\Role;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Password; use Illuminate\Support\Facades\Password;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
class AuthController extends Controller class AuthController extends Controller
{ {
public function __construct() public function __construct()
@ -25,8 +26,8 @@ class AuthController extends Controller
$remember = $request->remember; $remember = $request->remember;
$is_mobile = $request->is_mobile; $is_mobile = $request->is_mobile;
if(empty($username) || empty($password)) if (empty($username) || empty($password))
return response()->json(['status'=>'error','message'=>'You must fill all the fields'], 400); return response()->json(['status' => 'error', 'message' => 'You must fill all the fields'], 400);
$usernameCheck = false; $usernameCheck = false;
$passwordCheck = false; $passwordCheck = false;
@ -37,34 +38,38 @@ class AuthController extends Controller
if (User::where('password', md5($password))->exists()) if (User::where('password', md5($password))->exists())
$passwordCheck = true; $passwordCheck = true;
if ($usernameCheck & $passwordCheck){ if ($usernameCheck & $passwordCheck) {
$user = User::where('username', $username)->where('password', md5($password))->first(); $user = User::where('username', $username)->where('password', md5($password))->first();
if($is_mobile){ if ($is_mobile) {
$fcm_token = $request->fcm_token; $fcm_token = $request->fcm_token;
if(!$fcm_token || $fcm_token=="") if (!$fcm_token || $fcm_token == "")
return response()->json(['status'=>'error','message'=>'FCM Token is required'], 400); return response()->json(['status' => 'error', 'message' => 'FCM Token is required'], 400);
$dataUpdateFcm = array( $dataUpdateFcm = array(
"fcm_token"=>$fcm_token "fcm_token" => $fcm_token
); );
$hr = User::find($user->id); $hr = User::find($user->id);
if($hr) if ($hr)
$hr->update($dataUpdateFcm); $hr->update($dataUpdateFcm);
} }
$dataRole = Role::find($user->role_id); $dataRole = Role::find($user->role_id);
$dataHierarchy = $this->getDataHierarchy($user->divisi_id, $user->id);
if($dataRole) if ($dataRole)
$user->role = $dataRole; $user->role = $dataRole;
if (! $token =Auth::login($user)) if ($dataHierarchy)
$user->hierarchy = $dataHierarchy;
if (!$token = Auth::login($user))
return response()->json(['error' => 'Unauthorized'], 401); return response()->json(['error' => 'Unauthorized'], 401);
$ttl = 60; $ttl = 60;
if($remember) if ($remember)
$ttl = 10080; $ttl = 10080;
// todo : change existing md5 hashed function to laravel's originally bcrypt // todo : change existing md5 hashed function to laravel's originally bcrypt
@ -80,7 +85,7 @@ class AuthController extends Controller
'expires_in' => auth()->factory()->getTTL() * $ttl, 'expires_in' => auth()->factory()->getTTL() * $ttl,
), ),
]); ]);
}else { } else {
if (!$usernameCheck && !$passwordCheck) if (!$usernameCheck && !$passwordCheck)
return response()->json(['code' => 201, 'message' => "username and password doesn't match"], 201); return response()->json(['code' => 201, 'message' => "username and password doesn't match"], 201);
if (!$passwordCheck) if (!$passwordCheck)

110
app/Http/Controllers/CompanyController.php

@ -0,0 +1,110 @@
<?php
namespace App\Http\Controllers;
use App\Models\Company;
use Illuminate\Http\Request;
class CompanyController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'name' => 'required',
'description' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = Company::create($data);
if ($result) {
return response()->json(['status' => 'success', 'message' => 'add Company successfully!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'add data Company failed!', 'code' => 400], 400);
}
}
public function edit($id)
{
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die();
}
$result = Company::find($id);
if ($result) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get data Company, please try again later!', 'code' => 400], 400);
}
}
public function update(Request $request, $id)
{
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
}
$data = Company::find($id);
if ($data) {
$result = $data->update($request->all());
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400);
die();
}
if ($result) {
return response()->json(['status' => 'success', 'message' => 'data Company successfully updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company failed updated!', 'code' => 400], 400);
}
}
public function delete($id)
{
$data = Company::find($id);
if ($data) {
$delete = $data->delete();
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company not found!', 'code' => 400], 400);
die();
}
if ($delete) {
return response()->json(['status' => 'success', 'message' => 'data Company successfully deleted!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Company failed deleted!', 'code' => 400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_company');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
}
public function list()
{
$data = Company::all();
$countData = $data->count();
if ($data) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get list Company, please try again later!', 'code' => 400], 400);
}
}
}

235
app/Http/Controllers/Controller.php

@ -1,11 +1,14 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use App\Models\UserToActivity; use App\Models\UserToActivity;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use App\Models\Divisi;
use App\Models\User;
use Laravel\Lumen\Routing\Controller as BaseController; use Laravel\Lumen\Routing\Controller as BaseController;
use App\Models\ReportK3Detail; use App\Models\ReportK3Detail;
@ -16,18 +19,21 @@ class Controller extends BaseController
protected $pathDocument = "assets/file/project/"; protected $pathDocument = "assets/file/project/";
protected $pathTmpImport = "assets/file/tmpimport/"; protected $pathTmpImport = "assets/file/tmpimport/";
protected $pathActivityDocument = "assets/file/activity/"; protected $pathActivityDocument = "assets/file/activity/";
protected $listJoinAll = ['first', 'second', 'third', 'fourth', 'fifth', protected $listJoinAll = [
'sixth', 'seventh', 'eighth', 'ninth', 'tenth']; 'first', 'second', 'third', 'fourth', 'fifth',
'sixth', 'seventh', 'eighth', 'ninth', 'tenth'
];
protected $currentDate; protected $currentDate;
protected $currentName; protected $currentName;
protected $currentId; protected $currentId;
protected $companyId;
public function __construct() public function __construct()
{ {
$this->currentDate = date("Y-m-d H:i:s"); $this->currentDate = date("Y-m-d H:i:s");
$this->currentName = auth()->user() ? auth()->user()->name : "system"; $this->currentName = auth()->user() ? auth()->user()->name : "system";
$this->currentId = auth()->user() ? auth()->user()->id : 0; $this->currentId = auth()->user() ? auth()->user()->id : 0;
$this->companyId = auth()->user() ? auth()->user()->company_id : 0;
$this->pathImage = config('assets.image'); $this->pathImage = config('assets.image');
$this->pathDocument = config('assets.project'); $this->pathDocument = config('assets.project');
$this->pathActivityDocument = config('assets.activity'); $this->pathActivityDocument = config('assets.activity');
@ -36,20 +42,20 @@ class Controller extends BaseController
protected function setUpPayload($condition, $tableSelf) protected function setUpPayload($condition, $tableSelf)
{ {
$alias = "selfTable"; $alias = "selfTable";
$builder = DB::table($tableSelf." AS ".$alias); $builder = DB::table($tableSelf . " AS " . $alias);
// $builder = $builder->select($alias.".*"); // $builder = $builder->select($alias.".*");
if($condition){ if ($condition) {
if(isset($condition['select'])){ if (isset($condition['select'])) {
foreach($condition['select'] as $select){ foreach ($condition['select'] as $select) {
$builder = $builder->addSelect($alias.".".$select); $builder = $builder->addSelect($alias . "." . $select);
} }
}else{ } else {
$builder = $builder->addSelect($alias.".*"); $builder = $builder->addSelect($alias . ".*");
} }
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
@ -57,22 +63,22 @@ class Controller extends BaseController
if (isset($join['column_results'])) { if (isset($join['column_results'])) {
$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);
} }
} }
$builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf); $builder = $builder->leftJoin($tableName, $tableJoin . "." . $columnJoin, '=', $tableName . '.' . $columnSelf);
$no++; $no++;
} }
} }
if(isset($condition['columns'])){ if (isset($condition['columns'])) {
$listWhere = $condition['columns']; $listWhere = $condition['columns'];
$builder = $builder->where(function ($query) use($listWhere, $alias){ $builder = $builder->where(function ($query) use ($listWhere, $alias) {
foreach($listWhere as $where){ foreach ($listWhere as $where) {
$value = $where['value']; $value = $where['value'];
if($value && $value!="" && $value!=" "){ if ($value && $value != "" && $value != " ") {
$column = $where['name']; $column = $where['name'];
$operator = strtolower($where['logic_operator']); // like, =, <>, range $operator = strtolower($where['logic_operator']); // like, =, <>, range
$value2 = isset($where['value1']) ? $where['value1'] : ""; $value2 = isset($where['value1']) ? $where['value1'] : "";
@ -83,22 +89,22 @@ 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'])) {
$builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']); $builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']);
} }
if(isset($condition['orders'])){ if (isset($condition['orders'])) {
$orders = $condition['orders']; $orders = $condition['orders'];
$sortBy = $orders['ascending'] ? "ASC" : "DESC"; $sortBy = $orders['ascending'] ? "ASC" : "DESC";
$columnOrder = $orders['columns']; $columnOrder = $orders['columns'];
foreach($columnOrder as $column){ foreach ($columnOrder as $column) {
$builder = $builder->orderBy($alias.".".$column, $sortBy); $builder = $builder->orderBy($alias . "." . $column, $sortBy);
} }
} }
} }
@ -113,8 +119,8 @@ class Controller extends BaseController
$operator = $listGroupWhere['operator']; $operator = $listGroupWhere['operator'];
$operatorGroup = $listGroupWhere['group_operator']; $operatorGroup = $listGroupWhere['group_operator'];
$listWhere = $listGroupWhere['where']; $listWhere = $listGroupWhere['where'];
if(strtolower($operator)=="and"){ if (strtolower($operator) == "and") {
$builder = $builder->where(function($query) use($operatorGroup, $listWhere, $alias){ $builder = $builder->where(function ($query) use ($operatorGroup, $listWhere, $alias) {
$no = 1; $no = 1;
foreach ($listWhere as $where) { foreach ($listWhere as $where) {
$value = $where['value']; $value = $where['value'];
@ -122,22 +128,22 @@ class Controller extends BaseController
$operator = strtolower($where['logic_operator']); $operator = strtolower($where['logic_operator']);
$value2 = isset($where['value1']) ? $where['value1'] : ""; $value2 = isset($where['value1']) ? $where['value1'] : "";
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias;
if($value && $value!="" && $value!=" "){ if ($value && $value != "" && $value != " ") {
if($operatorGroup=="and"){ if ($operatorGroup == "and") {
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{ } else {
if($no==1){ if ($no == 1) {
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{ } else {
$query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2); $query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2);
} }
} }
} }
$no = $no+1; $no = $no + 1;
} }
}); });
}else if(strtolower($operator)=="or"){ } else if (strtolower($operator) == "or") {
$builder = $builder->orWhere(function($query) use($operatorGroup, $listWhere, $alias){ $builder = $builder->orWhere(function ($query) use ($operatorGroup, $listWhere, $alias) {
$no = 1; $no = 1;
foreach ($listWhere as $where) { foreach ($listWhere as $where) {
$value = $where['value']; $value = $where['value'];
@ -145,13 +151,13 @@ class Controller extends BaseController
$operator = strtolower($where['logic_operator']); $operator = strtolower($where['logic_operator']);
$value2 = isset($where['value1']) ? $where['value1'] : ""; $value2 = isset($where['value1']) ? $where['value1'] : "";
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias;
if($value && $value!="" && $value!=" "){ if ($value && $value != "" && $value != " ") {
if($operatorGroup=="and"){ if ($operatorGroup == "and") {
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{ } else {
if($no==1){ if ($no == 1) {
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{ } else {
$query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2); $query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2);
} }
} }
@ -166,39 +172,40 @@ class Controller extends BaseController
private function whereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2) private function whereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2)
{ {
$query = $oldQuery; $query = $oldQuery;
if($operator=="range"){ if ($operator == "range") {
$query = $query->whereBetween($tableColumn.".".$column, [$value, $value2]); $query = $query->whereBetween($tableColumn . "." . $column, [$value, $value2]);
}else if($operator=="like"){ } else if ($operator == "like") {
$query = $query->where($tableColumn.".".$column, 'like', '%'.$value.'%'); $query = $query->where($tableColumn . "." . $column, 'like', '%' . $value . '%');
}else if($operator=="ilike"){ } else if ($operator == "ilike") {
$query = $query->where($tableColumn.".".$column, '~*', $value); $query = $query->where($tableColumn . "." . $column, '~*', $value);
}else if($operator=="="){ } else if ($operator == "=") {
$query = $query->where($tableColumn.".".$column, $value); $query = $query->where($tableColumn . "." . $column, $value);
}else if($operator=="in"){ } else if ($operator == "in") {
$query = $query->whereIn($tableColumn.".".$column, $value); $query = $query->whereIn($tableColumn . "." . $column, $value);
}else if($operator=="notin"){ } else if ($operator == "notin") {
$query = $query->whereNotIn($tableColumn.".".$column, $value); $query = $query->whereNotIn($tableColumn . "." . $column, $value);
}else{ } else {
$query = $query->where($tableColumn.".".$column, $operator, $value); $query = $query->where($tableColumn . "." . $column, $operator, $value);
} }
return $query; return $query;
} }
private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2){ private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2)
{
$query = $oldQuery; $query = $oldQuery;
if($operator=="range"){ if ($operator == "range") {
$query = $query->whereBetween($column, [$value, $value2]); $query = $query->whereBetween($column, [$value, $value2]);
}else if($operator=="like"){ } else if ($operator == "like") {
$query = $query->where($column, 'like', '%'.$value.'%'); $query = $query->where($column, 'like', '%' . $value . '%');
}else if($operator=="ilike"){ } else if ($operator == "ilike") {
$query = $query->where($column, '~*', $value); $query = $query->where($column, '~*', $value);
}else if($operator=="="){ } else if ($operator == "=") {
$query = $query->where($column, $value); $query = $query->where($column, $value);
}else if($operator=="in"){ } else if ($operator == "in") {
$query = $query->whereIn($column, $value); $query = $query->whereIn($column, $value);
}else if($operator=="notin"){ } else if ($operator == "notin") {
$query = $query->whereNotIn($column, $value); $query = $query->whereNotIn($column, $value);
}else{ } else {
$query = $query->where($column, $operator, $value); $query = $query->where($column, $operator, $value);
} }
return $query; return $query;
@ -207,25 +214,26 @@ class Controller extends BaseController
private function orWhereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2) private function orWhereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2)
{ {
$query = $oldQuery; $query = $oldQuery;
if($operator=="range"){ if ($operator == "range") {
$query = $query->orWhereBetween($tableColumn.".".$column, [$value, $value2]); $query = $query->orWhereBetween($tableColumn . "." . $column, [$value, $value2]);
}else if($operator=="like"){ } else if ($operator == "like") {
$query = $query->orWhere($tableColumn.".".$column, 'like', '%'.$value.'%'); $query = $query->orWhere($tableColumn . "." . $column, 'like', '%' . $value . '%');
}else if($operator=="ilike"){ } else if ($operator == "ilike") {
$query = $query->where($tableColumn.".".$column, '~*', $value); $query = $query->where($tableColumn . "." . $column, '~*', $value);
}else if($operator=="="){ } else if ($operator == "=") {
$query = $query->orWhere($tableColumn.".".$column, $value); $query = $query->orWhere($tableColumn . "." . $column, $value);
}else if($operator=="in"){ } else if ($operator == "in") {
$query = $query->orWhereIn($tableColumn.".".$column, $value); $query = $query->orWhereIn($tableColumn . "." . $column, $value);
}else if($operator=="notin"){ } else if ($operator == "notin") {
$query = $query->orWhereNotIn($tableColumn.".".$column, $value); $query = $query->orWhereNotIn($tableColumn . "." . $column, $value);
}else{ } else {
$query = $query->orWhere($tableColumn.".".$column, $operator, $value); $query = $query->orWhere($tableColumn . "." . $column, $operator, $value);
} }
return $query; return $query;
} }
protected function calculateAllCost($activity_id, $proyek_id){ protected function calculateAllCost($activity_id, $proyek_id)
{
$humanCostPlanning = $this->calculateAllHumanCost($activity_id, $proyek_id); $humanCostPlanning = $this->calculateAllHumanCost($activity_id, $proyek_id);
$materialCostPlanning = $this->calculateMaterialCost($activity_id, $proyek_id); $materialCostPlanning = $this->calculateMaterialCost($activity_id, $proyek_id);
$toolsCostPlanning = 0; $toolsCostPlanning = 0;
@ -236,7 +244,7 @@ class Controller extends BaseController
private function calculateAllHumanCost($activity_id, $proyek_id) private function calculateAllHumanCost($activity_id, $proyek_id)
{ {
$dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate","ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate") $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") ->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("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)
@ -255,12 +263,12 @@ class Controller extends BaseController
$activity = Activity::find($activity_id); $activity = Activity::find($activity_id);
$duration = $activity->duration; $duration = $activity->duration;
$standarRate = $human->standart_rate; $standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100; $maxUsed = $human->max_used / 100;
if ($human->uom_standart_rate == "Hour") { if ($human->uom_standart_rate == "Hour") {
$totalCost = ($standarRate*8*$duration)*$maxUsed; $totalCost = ($standarRate * 8 * $duration) * $maxUsed;
return $totalCost; return $totalCost;
} }
$totalCost = ($standarRate*$duration)*$maxUsed; $totalCost = ($standarRate * $duration) * $maxUsed;
return $totalCost; return $totalCost;
} }
@ -273,17 +281,19 @@ class Controller extends BaseController
return $totalCost; return $totalCost;
} }
protected function getLoc($lat, $lng){ protected function getLoc($lat, $lng)
{
// $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json"); // $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json");
// return $response->json; // return $response->json;
$url = config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json"; $url = config('api.nominatim') . "/reverse?lat=" . $lat . "&lon=" . $lng . "&format=json";
// $token = config('api.adw_token'); // $token = config('api.adw_token');
$response = $this->curlRequest($url); $response = $this->curlRequest($url);
return $response; return $response;
} }
private function curlRequest($url){ private function curlRequest($url)
{
$ch = curl_init(); $ch = curl_init();
// $headers = [ // $headers = [
// 'Authorization: '.$token // 'Authorization: '.$token
@ -300,16 +310,63 @@ class Controller extends BaseController
return json_decode($response); return json_decode($response);
} }
protected function addDetailK3($dataDetail, $report_id){ protected function addDetailK3($dataDetail, $report_id)
{
foreach ($dataDetail as $value) { foreach ($dataDetail as $value) {
$dataNew = array( $dataNew = array(
"report_k3_id"=>$report_id, "report_k3_id" => $report_id,
"checklist_k3_id"=>$value['checklist_id'], "checklist_k3_id" => $value['checklist_id'],
"name_checklist_k3"=>$value['checklist_name'], "name_checklist_k3" => $value['checklist_name'],
"created_by"=>$this->currentName "created_by" => $this->currentName
); );
ReportK3Detail::create($dataNew); ReportK3Detail::create($dataNew);
} }
} }
protected function getDataHierarchy($divisi, $paramUserId)
{
$parentDivisi = Divisi::where('id', $divisi)->get();
$divisions = [];
$tempUser = [];
$userId = [$paramUserId];
// if ($parentDivisi->parent == null){
// }else{
foreach ($parentDivisi as $key) {
$data = $this->getAllChildrenDivisi($key->id);
$divisions[] = $data;
}
if (count($divisions) > 0) {
for ($i = 0; $i < count($divisions[0]); $i++) {
if (User::select('id', 'name', 'divisi_id')->where('divisi_id', $divisions[0][$i]->id)->exists()) {
$tempUser[] = User::select('id', 'name', 'divisi_id')->where('divisi_id', $divisions[0][$i]->id)->get();
}
}
for ($x = 0; $x < count($tempUser); $x++) {
for ($y = 0; $y < count($tempUser[$x]); $y++) {
$userId[] = $tempUser[$x][$y]->id;
}
}
}
return $userId;
// }
// return $userId;
}
private function getAllChildrenDivisi($divisi)
{
$finalData = [];
$divisi = Divisi::where('parent', $divisi)->get();
if (count($divisi) > 0) {
foreach ($divisi as $key) {
$childDivisi = $this->getAllChildrenDivisi($key->id);
$finalData[] = $key;
$finalData = array_merge($finalData, $childDivisi);
}
}
return $finalData;
}
} }

27
app/Http/Controllers/DashboardBoDController.php

@ -41,14 +41,14 @@ class DashboardBoDController extends Controller
private function getInvoiceIntegration($search) private function getInvoiceIntegration($search)
{ {
if(empty($search)) if (empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); return response()->json(['status' => 'error', 'message' => 'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); $url = str_replace("SEARCH", $search, config('api.adw') . '/project_cost?project_no=SEARCH');
$token = config('api.adw_token'); $token = config('api.adw_token');
$response = $this->curlReq($url, $token); $response = $this->curlReq($url, $token);
if(@$response->data->project_no == "") if (@$response->data->project_no == "")
return null; return null;
return $response; return $response;
@ -83,7 +83,6 @@ class DashboardBoDController extends Controller
$totalInvoice += $resp->data->total_invoice_amount ?? 0; $totalInvoice += $resp->data->total_invoice_amount ?? 0;
$totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0; $totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0;
} }
} }
return response()->json([ return response()->json([
@ -148,15 +147,13 @@ class DashboardBoDController extends Controller
} }
$selisihProgress = $planningProgress - $actualProgress; $selisihProgress = $planningProgress - $actualProgress;
try { try {
if ($selisihProgress > 0 && $selisihProgress <= 5){ if ($selisihProgress > 0 && $selisihProgress <= 20) {
$return['warning'] += 1; $return['warning'] += 1;
$projects[$index]->status = 'warning'; $projects[$index]->status = 'warning';
} } elseif ($selisihProgress == 0) {
elseif ($selisihProgress == 0){
$return['on-schedule'] += 1; $return['on-schedule'] += 1;
$projects[$index]->status = 'on-schedule'; $projects[$index]->status = 'on-schedule';
} } else {
else {
$return['behind-schedule'] += 1; $return['behind-schedule'] += 1;
$projects[$index]->status = 'behind-schedule'; $projects[$index]->status = 'behind-schedule';
} }
@ -192,13 +189,11 @@ class DashboardBoDController extends Controller
$actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0; $actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0;
} }
$selisihProgress = $planningProgress - $actualProgress; $selisihProgress = $planningProgress - $actualProgress;
if ($selisihProgress > 0 && $selisihProgress <= 5){ if ($selisihProgress > 0 && $selisihProgress <= 5) {
$warning++; $warning++;
} } elseif ($selisihProgress == 0) {
elseif ($selisihProgress == 0){
$onSchedule++; $onSchedule++;
} } else {
else {
$behindSchedule++; $behindSchedule++;
} }
} }
@ -295,7 +290,7 @@ class DashboardBoDController extends Controller
{ {
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$divisions = Divisi::select('id', 'name','parent','color') $divisions = Divisi::select('id', 'name', 'parent', 'color')
->with('children') ->with('children')
->whereNull('parent') ->whereNull('parent')
->get(); ->get();

195
app/Http/Controllers/MenuCompanyController.php

@ -0,0 +1,195 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\MenuCompany;
use App\Models\RoleMenu;
use Illuminate\Support\Facades\Log;
class MenuCompanyController extends Controller
{
// public function add(Request $request)
// {
// $this->validate($request, [
// 'icon' => 'required',
// 'name' => 'string|required',
// 'url' => 'required|unique:m_company_menu,url',
// 'sequence' => 'required|integer',
// ]);
// $data = $request->all();
// $data['created_by'] = $this->currentName;
// $result = MenuCompany::create($data);
// if ($result) {
// return response()->json(['status' => 'success', 'message' => 'add data menu successfully!', 'code' => 200], 200);
// } else {
// return response()->json(['status' => 'failed', 'message' => 'add data menu failed!', 'code' => 400], 400);
// }
// }
public function addMultiple(Request $request)
{
$menus = $request->all();
if (is_array($menus) && count($menus) > 0) {
$countRes = 0;
foreach ($menus as $menu) {
$dataInsert = array(
"menu_id" => $menu['menu_id'],
"parent_menu_id" => $menu['parent_id'],
"company_id" => $menu['company_id'],
"icon" => $menu['icon'],
"alias_name" => $menu['alias_name'],
"url" => $menu['url'],
"sequence" => $menu['sequence'],
"created_by" => $this->currentName
);
$result = MenuCompany::create($dataInsert);
if ($result) {
$countRes++;
} else {
$countRes--;
}
}
if ($countRes > 0) {
return response()->json(['status' => 'success', 'message' => 'add data menu successfully!', 'code' => 200]);
} else {
return response()->json(['status' => 'failed', 'message' => 'add data menu failed created!', 'code' => 400]);
}
} else {
return response()->json(['status' => 'failed', 'message' => 'add data menu failed created!', 'code' => 400]);
}
}
public function edit($id)
{
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die();
}
$result = MenuCompany::find($id);
if ($result) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get data menu, please try again later!', 'code' => 400], 400);
}
}
public function update(Request $request, $id)
{
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
}
$this->validate($request, [
'icon' => 'required',
'sequence' => 'required|integer',
]);
$data = MenuCompany::find($id);
if ($data) {
$result = $data->update($request->all());
} else {
return response()->json(['status' => 'failed', 'message' => 'data menu not found!', 'code' => 400], 400);
die();
}
if ($result) {
return response()->json(['status' => 'success', 'message' => 'data menu successfully updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data menu failed updated!', 'code' => 400], 400);
}
}
public function delete($id)
{
$data = MenuCompany::find($id);
if ($data) {
$delete = $data->delete();
} else {
return response()->json(['status' => 'failed', 'message' => 'data menu not found!', 'code' => 400], 400);
die();
}
if ($delete) {
return response()->json(['status' => 'success', 'message' => 'data menu successfully deleted!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'data menu failed deleted!', 'code' => 400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_company_menu');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
}
public function listMenu($id)
{
$dataParent = RoleMenu::select("m_company_menu.*")
->join('m_company_menu', 'm_company_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->whereNull('m_company_menu.parent_id')
->where('m_roles.id', $id)
->orderBy('m_company_menu.sequence', 'ASC')
->get();
$finalData = [];
foreach ($dataParent as $data) {
$data->children = $this->getChildrenMenu($data->id, $id);
$finalData[] = $data;
}
return response()->json(['status' => 'success', 'code' => 200, 'data' => $finalData], 200);
}
protected function getChildrenMenu($id, $role_id)
{
$dataChildren = RoleMenu::select("m_company_menu.*")
->join('m_company_menu', 'm_company_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->where('m_roles.id', $role_id)
->where('m_company_menu.parent_id', $id)
->orderBy('m_company_menu.sequence', 'ASC')
->get();
$children = [];
if ($dataChildren) {
foreach ($dataChildren as $data) {
$data->children = $this->getChildrenMenu($data->id, $role_id);
$children[] = $data;
}
}
return $children;
}
public function list()
{
$data = MenuCompany::all();
$countData = $data->count();
if ($data) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get list menu, please try again later!', 'code' => 400], 400);
}
}
}

339
app/Http/Controllers/ProjectController.php

@ -60,19 +60,20 @@ class ProjectController extends Controller
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
$data['created_by_id'] = $this->currentId;
if(empty($data['phase_id'])) if (empty($data['phase_id']))
$data['phase_id'] = 1; $data['phase_id'] = 1;
$result = Project::create($data); $result = Project::create($data);
if(!$result) if (!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500);
$this->createOfficeHours($result->id); $this->createOfficeHours($result->id);
$dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); $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); return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200);
} }
public function edit($id) public function edit($id)
@ -90,57 +91,86 @@ class ProjectController extends Controller
// $result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id') // $result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id')
// ->addSelect(DB::raw('m_divisi.name AS nama_divisi')); // ->addSelect(DB::raw('m_divisi.name AS nama_divisi'));
// } // }
$result = Project::select('value_proyek','scoupe_of_work','kode_sortname','jumlah_stakeholder','nama','mulai_proyek','akhir_proyek', $result = Project::select(
'area_kerja','rencana_biaya','biaya_actual','company','pm_id','type_proyek_id','divisi_id','persentase_progress', 'value_proyek',
'keterangan','durasi_proyek','progress_by_worklog','currency_symbol','late_consequence','assumtion','currency_code', 'scoupe_of_work',
'currency_name','project_objectives','considered_success_when','potential_risk','testing_environment','budget_health', 'kode_sortname',
'phase_id','calculation_status','md.name as divisi_name', 'nickname') 'jumlah_stakeholder',
->join('m_divisi as md','md.id', '=', 'm_proyek.divisi_id') 'nama',
'mulai_proyek',
'akhir_proyek',
'area_kerja',
'rencana_biaya',
'biaya_actual',
'company',
'pm_id',
'type_proyek_id',
'divisi_id',
'persentase_progress',
'keterangan',
'durasi_proyek',
'progress_by_worklog',
'currency_symbol',
'late_consequence',
'assumtion',
'currency_code',
'currency_name',
'project_objectives',
'considered_success_when',
'potential_risk',
'testing_environment',
'budget_health',
'phase_id',
'calculation_status',
'md.name as divisi_name',
'nickname'
)
->join('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id')
->where('m_proyek.id', $id) ->where('m_proyek.id', $id)
->first(); ->first();
if(!$result) if (!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} }
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
if(empty($id) || !is_int((int)$id)) if (empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$data = Project::find($id); $data = Project::find($id);
if(!$data) if (!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
$result = $data->update($request->all()); $result = $data->update($request->all());
if(!$result) if (!$result)
return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500); 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' => 'Data updated!', 'code' => 200], 200);
} }
private function createOfficeHours($proyek_id) private function createOfficeHours($proyek_id)
{ {
$dataCreate = array( $dataCreate = array(
"proyek_id"=>$proyek_id, "proyek_id" => $proyek_id,
"monday_start"=> "08:00:00", "monday_start" => "08:00:00",
"monday_end"=> "16:00:00", "monday_end" => "16:00:00",
"tuesday_start"=> "08:00:00", "tuesday_start" => "08:00:00",
"tuesday_end"=> "16:00:00", "tuesday_end" => "16:00:00",
"wednesday_start"=> "08:00:00", "wednesday_start" => "08:00:00",
"wednesday_end"=> "16:00:00", "wednesday_end" => "16:00:00",
"thursday_start"=> "08:00:00", "thursday_start" => "08:00:00",
"thursday_end"=> "16:00:00", "thursday_end" => "16:00:00",
"friday_start"=> "08:00:00", "friday_start" => "08:00:00",
"friday_end"=> "16:00:00", "friday_end" => "16:00:00",
"saturday_start"=> "08:00:00", "saturday_start" => "08:00:00",
"saturday_end"=> "16:00:00", "saturday_end" => "16:00:00",
"sunday_start"=> "08:00:00", "sunday_start" => "08:00:00",
"sunday_end"=> "16:00:00", "sunday_end" => "16:00:00",
"created_by"=> $this->currentName "created_by" => $this->currentName
); );
OfficeHours::create($dataCreate); OfficeHours::create($dataCreate);
@ -152,15 +182,15 @@ class ProjectController extends Controller
{ {
$data = Project::find($id); $data = Project::find($id);
if(!$data) if (!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
$this->deleteRelative($id); $this->deleteRelative($id);
if(!$data->delete()) if (!$data->delete())
return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500);
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
} }
private function deleteRelative($project_id) private function deleteRelative($project_id)
@ -195,16 +225,16 @@ class ProjectController extends Controller
foreach ($dataRa as $ra) { foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($images as $image) { foreach ($images as $image) {
if(file_exists($this->pathImage.$image->image)){ if (file_exists($this->pathImage . $image->image)) {
unlink($this->pathImage.$image->image); unlink($this->pathImage . $image->image);
} }
} }
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
} }
$dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get();
foreach ($dataAd as $ad) { foreach ($dataAd as $ad) {
if(file_exists($this->pathActivityDocument.$ad->file)){ if (file_exists($this->pathActivityDocument . $ad->file)) {
unlink($this->pathActivityDocument.$ad->file); unlink($this->pathActivityDocument . $ad->file);
} }
} }
ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); ActivityDokumen::whereIn("activity_id", $activityIds)->delete();
@ -222,8 +252,8 @@ class ProjectController extends Controller
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); $dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get();
foreach ($dataDokumen as $dokumen) { foreach ($dataDokumen as $dokumen) {
if(file_exists($this->pathDocument.$dokumen->file)){ if (file_exists($this->pathDocument . $dokumen->file)) {
unlink($this->pathDocument.$dokumen->file); unlink($this->pathDocument . $dokumen->file);
} }
} }
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete();
@ -232,8 +262,8 @@ class ProjectController extends Controller
$ref_ids = $dataFolder->all(); $ref_ids = $dataFolder->all();
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); $dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get();
foreach ($dataDokumen as $dokumen) { foreach ($dataDokumen as $dokumen) {
if(file_exists($this->pathDocument.$dokumen->file)){ if (file_exists($this->pathDocument . $dokumen->file)) {
unlink($this->pathDocument.$dokumen->file); unlink($this->pathDocument . $dokumen->file);
} }
} }
@ -251,7 +281,7 @@ class ProjectController extends Controller
$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()
@ -298,8 +328,8 @@ class ProjectController extends Controller
->get(); ->get();
$countData = $data->count(); $countData = $data->count();
if(!$data) if (!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
$totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost'))); $totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost')));
$totalActualCost = $data->sum('actualCost'); $totalActualCost = $data->sum('actualCost');
@ -328,52 +358,59 @@ class ProjectController extends Controller
return response()->json( return response()->json(
[ [
'status'=>'success', 'status' => 'success',
'code'=>200, 'code' => 200,
'data'=>$data, 'data' => $data,
'totalRecord'=>$countData, 'totalRecord' => $countData,
'totalPlannedCost' => $totalPlannedCost, 'totalPlannedCost' => $totalPlannedCost,
'totalActualCost' => $totalActualCost, 'totalActualCost' => $totalActualCost,
'totalRevenue' => $totalPlannedCost - $totalActualCost, 'totalRevenue' => $totalPlannedCost - $totalActualCost,
'manpowers' => $manpowers, 'manpowers' => $manpowers,
'projectsOnDanger'=> $projectsOnDanger, 'projectsOnDanger' => $projectsOnDanger,
'projectPhases' => $projectPhases, 'projectPhases' => $projectPhases,
'projectsByPhase' => $projectsByPhase, 'projectsByPhase' => $projectsByPhase,
'projectTypes' => $projectTypes, 'projectTypes' => $projectTypes,
'projectsByType' => $projectsByType, 'projectsByType' => $projectsByType,
], 200); ],
200
);
} }
public function getListProjectTask($id){ public function getListProjectTask($id)
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*") {
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id", "m_proyek.*")
->where("assign_hr_to_activity.user_id", $id) ->where("assign_hr_to_activity.user_id", $id)
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id') ->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
->groupBy("m_proyek.proyek_id") ->groupBy("m_proyek.proyek_id")
->get(); ->get();
if(!$data) if (!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} }
public function getSCurve(Request $request){ public function getSCurve(Request $request)
{
$data = MasterFunctionsHelper::getSCurve($request); $data = MasterFunctionsHelper::getSCurve($request);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} }
// testing // testing
public function calculateSCurvetest(Request $request){ public function calculateSCurvetest(Request $request)
{
$data = MasterFunctionsHelper::calculateSCurve($request->project_id); $data = MasterFunctionsHelper::calculateSCurve($request->project_id);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} }
public function calculateSCurve(Request $request){ public function calculateSCurve(Request $request)
{
$sCurve = Project::select('scurve')->where('id', $request->project_id)->first(); $sCurve = Project::select('scurve')->where('id', $request->project_id)->first();
return response()->json(['status'=>'success','code'=>200, 'data' => json_decode($sCurve->scurve)], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => json_decode($sCurve->scurve)], 200);
} }
public function sCurveCommand(Request $request){ public function sCurveCommand(Request $request)
{
Artisan::call('calculate:scurve', [ Artisan::call('calculate:scurve', [
'project_id' => $request->project_id 'project_id' => $request->project_id
]); ]);
@ -388,12 +425,14 @@ class ProjectController extends Controller
// return response()->json(['message' => 'Project not found'], 404); // return response()->json(['message' => 'Project not found'], 404);
} }
public function getLinearSCurve(Request $request){ public function getLinearSCurve(Request $request)
{
$data = MasterFunctionsHelper::getLinearSCurve($request); $data = MasterFunctionsHelper::getLinearSCurve($request);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} }
public static function setSyncDate($activity_id, $activity, $report) { public static function setSyncDate($activity_id, $activity, $report)
{
$status = AssignMaterial::where('activity_id', $activity_id)->first(); $status = AssignMaterial::where('activity_id', $activity_id)->first();
if (!isset($status)) { if (!isset($status)) {
$reports = array( $reports = array(
@ -430,12 +469,12 @@ class ProjectController extends Controller
$activities = Activity::where("version_gantt_id", $gantt_id)->get(); $activities = Activity::where("version_gantt_id", $gantt_id)->get();
$reports = []; $reports = [];
foreach($activities as $activity) { foreach ($activities as $activity) {
$activity_id = $activity->id; $activity_id = $activity->id;
$countReports = ReportActivityMaterial::where('activity_id', $activity_id)->count(); $countReports = ReportActivityMaterial::where('activity_id', $activity_id)->count();
if ($countReports === 1) { if ($countReports === 1) {
$dataReports = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->get(); $dataReports = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->get();
foreach($dataReports as $dr) { foreach ($dataReports as $dr) {
$reports[] = ProjectController::setSyncDate($activity_id, $activity, $dr); $reports[] = ProjectController::setSyncDate($activity_id, $activity, $dr);
} }
} }
@ -456,15 +495,15 @@ class ProjectController extends Controller
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */
for ($i=0; $i < count($reports); $i++) { for ($i = 0; $i < count($reports); $i++) {
$activity = Activity::find($reports[$i]['activity_id']); $activity = Activity::find($reports[$i]['activity_id']);
if($reports[$i]['status'] != 'done'){ if ($reports[$i]['status'] != 'done') {
$reports[$i]['max_date']->modify('-1 day'); $reports[$i]['max_date']->modify('-1 day');
}else if($reports[$i]['status'] == 'done'){ } else if ($reports[$i]['status'] == 'done') {
$activity->actual_end = $reports[$i]['max_date']->setTime(23,59,59); $activity->actual_end = $reports[$i]['max_date']->setTime(23, 59, 59);
} }
$activity->start_date = $reports[$i]['min_date']; //same early $activity->start_date = $reports[$i]['min_date']; //same early
$activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early $activity->end_date = $reports[$i]['max_date']->setTime(23, 59, 59); // same early
$startDate = new DateTime($activity->start_date); $startDate = new DateTime($activity->start_date);
$endDate = new DateTime($activity->end_date); $endDate = new DateTime($activity->end_date);
$duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate); $duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate);
@ -473,7 +512,7 @@ class ProjectController extends Controller
$activity->save(); $activity->save();
} }
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);
} }
public function setBaseline($gantt_id) public function setBaseline($gantt_id)
@ -482,29 +521,30 @@ class ProjectController extends Controller
foreach ($activities as $activity) { foreach ($activities as $activity) {
$activity->update([ $activity->update([
"planned_start"=>$activity->start_date, "planned_start" => $activity->start_date,
"planned_end"=>$activity->end_date, "planned_end" => $activity->end_date,
"early_start"=>$activity->start_date, "early_start" => $activity->start_date,
"early_end"=>$activity->end_date, "early_end" => $activity->end_date,
]); ]);
} }
return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200); return response()->json(['status' => 'success', 'message' => 'Set baseline success!', 'code' => 200], 200);
} }
public function getInvoiceIntegration(Request $request) { public function getInvoiceIntegration(Request $request)
{
$ganttCount = VersionGantt::where('proyek_id', $request->id)->count(); $ganttCount = VersionGantt::where('proyek_id', $request->id)->count();
$search = urlencode($request->search); $search = urlencode($request->search);
if(empty($search)) if (empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); return response()->json(['status' => 'error', 'message' => 'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); $url = str_replace("SEARCH", $search, config('api.adw') . '/project_cost?project_no=SEARCH');
$response = MasterFunctionsHelper::curlReq($url); $response = MasterFunctionsHelper::curlReq($url);
if (isset($request->gantt_id)) { if (isset($request->gantt_id)) {
$response->data->total_cost = $response->data->total_cost / $ganttCount; $response->data->total_cost = $response->data->total_cost / $ganttCount;
} }
return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); return response()->json(['status' => 'success', 'data' => $response, 'code' => 200], 200);
} }
public function getByUser($id) public function getByUser($id)
{ {
@ -515,23 +555,24 @@ class ProjectController extends Controller
['is_customer', true], ['is_customer', true],
['user_id', $id] ['user_id', $id]
]) ])
->leftJoin('m_users', $alias.'.user_id', '=', 'm_users.id') ->leftJoin('m_users', $alias . '.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', $alias.'.proyek_id', '=', 'm_proyek.id') ->leftJoin('m_proyek', $alias . '.proyek_id', '=', 'm_proyek.id')
->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id') ->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
->select('m_proyek.*', 'm_type_proyek.name AS join_second_name','m_users.name AS join_first_name') ->select('m_proyek.*', 'm_type_proyek.name AS join_second_name', 'm_users.name AS join_first_name')
->get(); ->get();
$totalRecord = $userProyek->count(); $totalRecord = $userProyek->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
} }
public function detail(Request $request, $id, $gantt_id = null, $s_curve = null){ public function detail(Request $request, $id, $gantt_id = null, $s_curve = null)
if(empty($id) || !is_int((int)$id)) {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if (empty($id) || !is_int((int)$id))
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' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
if (!isset($gantt_id)) { if (!isset($gantt_id)) {
$gantt = MasterFunctionsHelper::getLatestGantt($id); $gantt = MasterFunctionsHelper::getLatestGantt($id);
$ganttId = $gantt['last_gantt_id']; $ganttId = $gantt['last_gantt_id'];
@ -543,15 +584,13 @@ class ProjectController extends Controller
if (isset($s_curve)) { if (isset($s_curve)) {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first(); $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first();
$actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists(); $actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists();
if($result['type_proyek_id'] === 9) if ($result['type_proyek_id'] === 9) {
{
// $actualEndExist = Activity::where('proyek_id', $id)->exists(); // $actualEndExist = Activity::where('proyek_id', $id)->exists();
$query = Activity::where('proyek_id', $id); $query = Activity::where('proyek_id', $id);
$maxEndDate = Activity::where('proyek_id', $id)->select('end_date') $maxEndDate = Activity::where('proyek_id', $id)->select('end_date')
->orderBy('end_date', 'desc') ->orderBy('end_date', 'desc')
->first(); ->first();
} else {
}else{
// $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); // $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
$maxEndDate = Activity::where('version_gantt_id', $ganttId)->select('end_date') $maxEndDate = Activity::where('version_gantt_id', $ganttId)->select('end_date')
->orderBy('end_date', 'desc') ->orderBy('end_date', 'desc')
@ -591,30 +630,30 @@ class ProjectController extends Controller
$result->header->end_date = $maxEndDate->end_date; $result->header->end_date = $maxEndDate->end_date;
$result->header->planned_start = $plannedStart; $result->header->planned_start = $plannedStart;
$result->header->planned_end = $plannedEnd; $result->header->planned_end = $plannedEnd;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$ganttId], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result, 'gantt' => $ganttId], 200);
} }
public function getOverdueActivities(Request $request){ public function getOverdueActivities(Request $request)
{
$payload = $request->all(); $payload = $request->all();
if(empty($payload['id']) || !is_int((int)$payload['id'])) if (empty($payload['id']) || !is_int((int)$payload['id']))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$result = Project::find($payload['id']); $result = Project::find($payload['id']);
if(!$result) if (!$result)
return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Project not found!', 'code' => 404], 404);
//TODO possible overdue bug //TODO possible overdue bug
$endDate = Activity::where('proyek_id', $payload['id']) $endDate = Activity::where('proyek_id', $payload['id'])
->orderByDesc('end_date') ->orderByDesc('end_date')
->value('end_date'); ->value('end_date');
if(isset($payload['till_date'])) { if (isset($payload['till_date'])) {
if (isset($payload['scurve'])) { if (isset($payload['scurve'])) {
$overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('m_activity.proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get(); $overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('m_activity.proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get();
} else { } else {
$overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get(); $overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get();
}
} }
else { } else {
if (isset($payload['scurve'])) { if (isset($payload['scurve'])) {
$overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('m_activity.proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); $overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('m_activity.proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get();
} else { } else {
@ -623,18 +662,29 @@ class ProjectController extends Controller
} }
$result->overdueActivities = $overdueActivities; $result->overdueActivities = $overdueActivities;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} }
public function getReportDistribution(Request $request){ public function getReportDistribution(Request $request)
{
$payload = $request->all(); $payload = $request->all();
if(empty($payload['project_id']) || !is_int((int)$payload['project_id'])) if (empty($payload['project_id']) || !is_int((int)$payload['project_id']))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$reports = DB::table('assign_material_to_activity as ama') $reports = DB::table('assign_material_to_activity as ama')
->select('u.name', 'a.name as activity_name', 'ama.qty_planning', 'ram.qty as qty_real','rm.description as material_name', 'rm.uom as material_unit', ->select(
'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date') 'u.name',
'a.name as activity_name',
'ama.qty_planning',
'ram.qty as qty_real',
'rm.description as material_name',
'rm.uom as material_unit',
'ram.lat',
'ram.lon',
'ram.description as report_notes',
'ram.report_date'
)
->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id') ->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id')
->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id') ->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id') ->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
@ -643,33 +693,44 @@ class ProjectController extends Controller
->whereNotNull('ram.lat') ->whereNotNull('ram.lat')
->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]); ->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]);
return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $reports], 200);
} }
public function getManpower($proyek_id){ public function getManpower($proyek_id)
{
$manCount = UserToProyek::where('proyek_id', $proyek_id)->count(); $manCount = UserToProyek::where('proyek_id', $proyek_id)->count();
return response()->json(['totalRecord'=>$manCount]); return response()->json(['totalRecord' => $manCount]);
} }
public function getAssignedHR($gantt_id){ public function getAssignedHR($gantt_id)
{
$results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date') $results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id') ->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id')
->where('assign_hr_to_activity.version_gantt_id', $gantt_id) ->where('assign_hr_to_activity.version_gantt_id', $gantt_id)
->get(); ->get();
return response()->json(['data'=>$results]); return response()->json(['data' => $results]);
} }
public function dashboard($id) public function dashboard($id)
{ {
$data = DB::table('m_proyek as mp') $data = DB::table('m_proyek as mp')
->select('mp.kode_sortname', 'mp.nama as name_project', 'mp.mulai_proyek as start', 'mp.akhir_proyek as finish', ->select(
'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm', 'mp.budget_health') 'mp.kode_sortname',
'mp.nama as name_project',
'mp.mulai_proyek as start',
'mp.akhir_proyek as finish',
'mp.rencana_biaya',
'mp.company',
'mp.currency_symbol',
'mu.name as pm',
'mp.budget_health'
)
->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') ->join('m_users as mu', 'mu.id', '=', 'mp.pm_id')
->where('mp.id', $id) ->where('mp.id', $id)
->first(); ->first();
if(!$data) if (!$data)
return response()->json(['status'=>'failed','message'=>'Data tidak ditemukan!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data tidak ditemukan!', 'code' => 404], 404);
$manpowers = UserToProyek::where('proyek_id', $id)->count(); $manpowers = UserToProyek::where('proyek_id', $id)->count();
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first(); $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first();
@ -678,8 +739,13 @@ class ProjectController extends Controller
$progress = @$rootActivity->persentase_progress ?? 0; $progress = @$rootActivity->persentase_progress ?? 0;
$commentActivity = DB::table('m_comment_activity as mca') $commentActivity = DB::table('m_comment_activity as mca')
->select('mca.activity_id', 'mca.comment as comment', 'mca.created_by as comment_by', 'mca.created_at as comment_created', ->select(
'ma.name as activity') 'mca.activity_id',
'mca.comment as comment',
'mca.created_by as comment_by',
'mca.created_at as comment_created',
'ma.name as activity'
)
->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id') ->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id')
->where('ma.proyek_id', $id) ->where('ma.proyek_id', $id)
->orderBy('comment_by') ->orderBy('comment_by')
@ -691,10 +757,11 @@ class ProjectController extends Controller
$data->comment = $commentActivity; $data->comment = $commentActivity;
$data->man_power = $manpowers; $data->man_power = $manpowers;
return response()->json(['status'=>'success','code'=>200,'data'=> $data], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} }
private function httpReq($search){ private function httpReq($search)
{
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION)); curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION));
@ -710,6 +777,4 @@ class ProjectController extends Controller
return json_decode($output); return json_decode($output);
} }
} }

37
app/Models/Company.php

@ -0,0 +1,37 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Company extends Model
{
protected $table = 'm_company';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
"registration_no",
"company_name",
"address",
"phone_no",
"email",
"description",
"logo_login",
"logo_header",
"favicon_image",
"login_instruction",
"about",
"html_title",
"app_name",
"base_url",
"is_active",
"template_id",
'created_at',
'created_by',
'updated_at',
'updated_by',
'company_id'
];
}

12
app/Models/Divisi.php

@ -19,24 +19,26 @@ class Divisi extends Model
'created_at', 'created_at',
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by' 'updated_by',
'company_id'
]; ];
public static function boot() { public static function boot()
{
parent::boot(); parent::boot();
static::deleting(function($data) { static::deleting(function ($data) {
$data->children()->delete(); $data->children()->delete();
}); });
} }
public function parent() public function parent()
{ {
return $this->belongsTo('App\Models\Divisi','parent')->where('parent', null)->with('parent'); return $this->belongsTo('App\Models\Divisi', 'parent')->where('parent', null)->with('parent');
} }
public function children() public function children()
{ {
return $this->hasMany('App\Models\Divisi','parent')->with('children'); return $this->hasMany('App\Models\Divisi', 'parent')->with('children');
} }
} }

3
app/Models/HumanResource.php

@ -33,6 +33,7 @@ class HumanResource extends Model
'updated_at', 'updated_at',
'updated_by', 'updated_by',
'divisi_id', 'divisi_id',
'status_boundary' 'status_boundary',
'company_id'
]; ];
} }

27
app/Models/MenuCompany.php

@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class MenuCompany extends Model
{
protected $table = 'm_company_menu';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'menu_id',
'parent_menu_id',
'company_id',
'icon',
'alias_name',
'url',
'sequence',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}

5
app/Models/Project.php

@ -50,8 +50,7 @@ class Project extends Model
'created_at', 'created_at',
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by' 'updated_by',
'created_by_id'
]; ];
} }

2
app/Models/ProjectPhase.php

@ -12,6 +12,6 @@ class ProjectPhase extends Model
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'name', 'color', 'order', 'created_at', 'created_by', 'updated_at', 'updated_by' 'name', 'color', 'order', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
]; ];
} }

2
app/Models/ProjectRole.php

@ -12,6 +12,6 @@ class ProjectRole extends Model
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
]; ];
} }

2
app/Models/ProjectType.php

@ -12,6 +12,6 @@ class ProjectType extends Model
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
]; ];
} }

2
app/Models/Role.php

@ -12,6 +12,6 @@ class Role extends Model
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'name', 'description', 'default_page', 'created_at', 'created_by', 'updated_at', 'updated_by' 'name', 'description', 'default_page', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
]; ];
} }

2
app/Models/RoleMenu.php

@ -12,6 +12,6 @@ class RoleMenu extends Model
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'role_id', 'menu_id', 'created_at', 'created_by', 'updated_at', 'updated_by' 'role_id', 'menu_id', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id', "create", "read", "update", "delete"
]; ];
} }

2
app/Models/Satuan.php

@ -12,6 +12,6 @@ class Satuan extends Model
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
]; ];
} }

20
routes/web.php

@ -4,7 +4,7 @@ $router->get('/', function () use ($router) {
return $router->app->version(); return $router->app->version();
}); });
$router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($router) { $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($router) {
$router->post('/login', 'AuthController@login'); $router->post('/login', 'AuthController@login');
$router->post('/menu/add', 'MenuController@add'); $router->post('/menu/add', 'MenuController@add');
@ -53,7 +53,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject'); $router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject');
$router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen'); $router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen');
$router->get('/project-by-customer/{id}','ProjectController@getByUser'); $router->get('/project-by-customer/{id}', 'ProjectController@getByUser');
$router->post('/project/search', 'ProjectController@search'); $router->post('/project/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');
@ -503,6 +503,20 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/broadcast/search', 'BroadcastController@search'); $router->post('/broadcast/search', 'BroadcastController@search');
$router->delete('/broadcast/delete/{id}', 'BroadcastController@delete'); $router->delete('/broadcast/delete/{id}', 'BroadcastController@delete');
$router->get('/broadcast/list', 'BroadcastController@list'); $router->get('/broadcast/list', 'BroadcastController@list');
});
$router->post('/company-management/add', 'CompanyController@add');
$router->get('/company-management/edit/{id}', 'CompanyController@edit');
$router->put('/company-management/update/{id}', 'CompanyController@update');
$router->post('/company-management/search', 'CompanyController@search');
$router->delete('/company-management/delete/{id}', 'CompanyController@delete');
$router->get('/company-management/list', 'CompanyController@list');
$router->post('/menu-company/add-multiple', 'MenuCompanyController@addMultiple');
$router->get('/menu-company/edit/{id}', 'MenuCompanyController@edit');
$router->put('/menu-company/update/{id}', 'MenuCompanyController@update');
$router->delete('/menu-company/delete/{id}', 'MenuCompanyController@delete');
$router->post('/menu-company/search', 'MenuCompanyController@search');
$router->get('/menu-company/management/{id}', 'MenuCompanyController@listMenu');
$router->get('/menu-company/list', 'MenuCompanyController@list');
});
}); });

Loading…
Cancel
Save