Browse Source

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

Reviewed-on: ibnu/generic-ospro-backend#2
pull/3/head
farhantock 12 months ago
parent
commit
dbe378ac57
  1. 368
      app/Helpers/MasterFunctionsHelper.php
  2. 110
      app/Http/Controllers/CompanyController.php
  3. 287
      app/Http/Controllers/Controller.php
  4. 195
      app/Http/Controllers/MenuCompanyController.php
  5. 37
      app/Models/Company.php
  6. 36
      app/Models/Divisi.php
  7. 3
      app/Models/HumanResource.php
  8. 27
      app/Models/MenuCompany.php
  9. 17
      app/Models/Project.php
  10. 2
      app/Models/ProjectPhase.php
  11. 2
      app/Models/ProjectRole.php
  12. 2
      app/Models/ProjectType.php
  13. 2
      app/Models/Role.php
  14. 2
      app/Models/RoleMenu.php
  15. 2
      app/Models/Satuan.php
  16. 34
      routes/web.php

368
app/Helpers/MasterFunctionsHelper.php

@ -36,10 +36,11 @@ class MasterFunctionsHelper
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;
$diff = date_diff($start, $end);
$endCount = clone $end;
$endCount = clone $end;
$duration = $diff->days + 1;
$daysRemaining = $duration;
// Loop until the remaining days become zero
@ -235,7 +236,7 @@ class MasterFunctionsHelper
$end = new \DateTime($maxDate . ' 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');
} else {
$actualMaxDate = DB::table('assign_material_to_activity as ama')
@ -338,9 +339,11 @@ class MasterFunctionsHelper
->where('activity_id', '=', $keyPlanM->id)
->groupBy('activity_id')
->first();
$weekCount = $keyPlanM->duration / 7;
$weekCount = $keyPlanM->duration / $keyPlanM->duration;
$weeklyPlan = $weekCount > 0 ? $sumVolPlan->ttl_qty_plan / $weekCount : 0;
$weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
// $weeklyPlan = $weekCount > 0 ? $keyPlanM->bobot_planning / $weekCount : 0;
// $weeklyProgress = $weeklyPlan * $keyPlanM->bobot_planning;
$dataTempPlan[$x]['activity_id'] = $keyPlanM->id;
$dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan[$x]['ttl_plan'] = $sumVolPlan;
@ -440,7 +443,7 @@ class MasterFunctionsHelper
// if($tempTtlPercentActual >= $keyGantt['progress'])
// $tempTtlPercentActual = $keyGantt['progress'];
// todo
// todo
// if ($tempTtlPercentPlan >= 100)
// $tempTtlPercentPlan = 100;
// $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual
@ -486,8 +489,8 @@ class MasterFunctionsHelper
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
}
$lastReal = $tempPercentageReal[count($tempPercentageReal) - 1];
$totalBCWP = $lastReal * $dataProject->rencana_biaya / 100;
$lastReal = $tempPercentageReal[count($tempPercentageReal) - 1];
$totalBCWP = $lastReal * $dataProject->rencana_biaya / 100;
$dataResponse = array(
"date" => $tempDate,
"percentage" => $tempPercentage,
@ -515,7 +518,7 @@ class MasterFunctionsHelper
return $dataFinal;
}
public function calculateSCurve($projectId)
public function calculateSCurveVWahyu($projectId)
{
DB::enableQueryLog();
@ -552,7 +555,7 @@ class MasterFunctionsHelper
$end = new \DateTime($maxDate . ' 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');
} else {
// $maxDate = DB::table('assign_material_to_activity as ama')
@ -669,6 +672,322 @@ class MasterFunctionsHelper
$x++;
}
$w = 0;
$dataTempReport = [];
$sumPercentageActual = 0;
foreach ($dataActualM as $keyActualM) {
$sumVolActual = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyActualM->activity_id)
->groupBy('activity_id')
->first();
if (!isset($sumVolActual)) {
$sumVolActual = (object) [
'activity_id' => $keyActualM->activity_id,
'ttl_qty_plan' => "0"
];
}
$sumReportActual = DB::table('report_activity_material')
->where('activity_id', $keyActualM->activity_id)
->sum('qty');
$reportCount = DB::table('report_activity_material')->where('activity_id', '=', $keyActualM->activity_id)->count();
$dataTempReport[$w]['activity_id'] = $keyActualM->activity_id;
$dataTempReport[$w]['qty'] = $keyActualM->qty;
$dataTempReport[$w]['report_date'] = $keyActualM->report_date;
$dataTempReport[$w]['bobot_planning'] = $keyActualM->bobot_planning;
$dataTempReport[$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan;
$dataTempReport[$w]['biaya_actual'] = $keyActualM->biaya_actual;
$dataTempReport[$w]['duration'] = $keyActualM->duration;
$dataTempReport[$w]['persentase_progress'] = $keyActualM->persentase_progress;
try {
// assign_material_to_activity
$checkStatusActivity = DB::table('assign_material_to_activity')
->select('activity_id', 'status_activity')
->where('activity_id', '=', $keyActualM->activity_id)
->orderBy('status_activity', 'ASC')
->first();
if (!isset($checkStatusActivity)) {
$checkStatusActivity = (object) [
'activity_id' => $keyActualM->activity_id,
'status_activity' => 'open'
];
}
if ($sumVolActual->ttl_qty_plan == "0") {
$actual = 0;
} else {
$actual = $keyActualM->qty / $sumVolActual->ttl_qty_plan;
}
$dataTempReport[$w]['percentage'] = $actual * $keyActualM->bobot_planning;
// $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
// if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){
if ($checkStatusActivity->status_activity == 'done') {
$sumPercentageActual += $keyActualM->bobot_planning / $reportCount;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else {
if ($actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) {
$sumPercentageActual += ($actual * $keyActualM->bobot_planning) * (95 / 100);
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else {
$sumPercentageActual += $actual * $keyActualM->bobot_planning;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
}
}
// }else {
// if($checkStatusActivity->status_activity == 'done'){
// $sumPercentageActual+=($keyActualM->qty/$keyActualM->qty)*$keyActualM->bobot_planning;
// }else{
// $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
// }
// }
$totalACWP += $keyActualM->duration > 0 ? $keyActualM->biaya_actual / $keyActualM->duration : 0;
} catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]);
}
$dataTempReport[$w]['totalacwp'] = $totalACWP;
$w++;
}
$arr_ActualM[] = array(
'date' => $dt->format("Y-m-d"),
'percentPlan' => $sumPercentagePlan,
'percentActual' => $sumPercentageActual,
'plan' => $dataTempPlan,
'actual' => $dataTempReport,
);
if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') {
$tempTtlPercentPlan += $sumPercentagePlan;
$tempTtlPercentActual += $sumPercentageActual;
// todo
// if ($tempTtlPercentPlan >= 100)
// $tempTtlPercentPlan = 100;
$currentACWP += $totalACWP;
$currentBCWP += $totalBCWP;
$tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2));
$tempPercentagePlan[] = round($tempTtlPercentPlan, 2);
$tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan];
$tempPercentageReal[] = round($tempTtlPercentActual, 2);
if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) {
break;
}
} else {
$tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2));
$tempPercentagePlan[] = round($sumPercentagePlan, 2);
$tempPercentageReal[] = round($sumPercentageActual, 2);
}
$tempDate[] = array($dt->format("Y-m-d"));
}
try {
if (round($totalACWP, 0) > $totalRencanaBudget) {
$estimatedCost = round($totalACWP, 0) + 0;
} else {
$estimatedCost = ($totalRencanaBudget + 0);
}
} catch (\DivisionByZeroError $e) {
return response()->json([
'message' => $e->getMessage(),
"line" => 566,
]);
}
$estimatedCost = $totalACWP > $totalRencanaBudget ? $totalACWP : $totalRencanaBudget;
$costDeviation = $totalRencanaBudget - $estimatedCost;
if ($costDeviation > 0) {
$potential = "SAVING";
} else {
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
}
$lastReal = $tempPercentageReal[count($tempPercentageReal) - 1];
$totalBCWP = $lastReal * $dataProject->rencana_biaya / 100;
$dataResponse = array(
"date" => $tempDate,
"percentage" => $tempPercentage,
"percentagePlan" => $tempPercentagePlan,
"percentageReal" => $tempPercentageReal,
"data_details" => $arr_ActualM,
"budget_control" => array(
"current_budget" => $totalRencanaBudget,
"acwp" => round($totalACWP, 0),
"bcwp" => round($totalBCWP, 0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP, 0)),
"add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation,
"potential" => $potential,
)
);
$dataFinal[] = array(
"proyek_name" => $dataProject->nama,
"data" => $dataResponse,
);
return $dataFinal;
}
public function calculateSCurve($projectId)
{
DB::enableQueryLog();
$dataFinal = [];
$dataPayload = [];
$dataPayload['period'] = 'week';
$totalACWP = 0;
$totalBCWP = 0;
$tempPercentage = [];
$dataProject = Project::find($projectId);
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $projectId)->first();
if (isset($dataPayload['end_date']) && $dataPayload['end_date'] > $dataProject->akhir_proyek) {
$dataPayload['end_date'] = $dataProject->akhir_proyek;
}
if ($dataHeader) {
$totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $projectId)->sum("rencana_biaya");
} else {
$totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $projectId)->sum("rencana_biaya");
}
// $alreadyHasReport = DB::table('report_activity_material as a')
// ->select('a.id')
// ->join('m_activity as b', 'b.id', '=', 'a.activity_id')
// ->exists();
$minDate = $dataProject->mulai_proyek;
$begin = new \DateTime($minDate . ' Monday');
$begin->modify('last Monday');
if (isset($dataPayload['end_date'])) {
$maxDate = $dataPayload['end_date'];
$end = new \DateTime($maxDate . ' Friday');
$end->modify('next Friday');
$end->modify('next Friday');
/* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged
$interval = new \DateInterval('P7D');
} else {
// $maxDate = DB::table('assign_material_to_activity as ama')
// ->where("ama.proyek_id", $projectId)
// ->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
// ->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's
$maxDate = $dataProject->akhir_proyek;
$end = new \DateTime($maxDate);
$end->modify('next Friday');
$end->modify('next Friday');
$interval = new \DateInterval('P7D');
}
$period = new \DatePeriod($begin, $interval, $end);
$arr_ActualM = [];
$tempDate = [];
$tempPercentagePlan = [];
$tempPercentagePlanWhr = [];
$tempPercentageReal = [];
$tempTtlPercentPlan = 0;
$tempTtlPercentActual = 0;
$currentACWP = 0;
$currentBCWP = 0;
foreach ($period as $dt) {
$minSevenDays = new \Datetime($dt->format("Y-m-d"));
$minSevenDays = $minSevenDays->modify('-7 day')->format("Y-m-d");
// $dataPlanM = DB::table('assign_material_to_activity as ama')
// ->select('ama.activity_id', 'ama.qty_planning', 'ama.plan_date', 'ama.start_activity', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress')
// ->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
// ->where('ama.proyek_id', '=', $keyGantt['proyek_id'])
// ->where('a.version_gantt_id', '=', $keyGantt['id'])
// ->whereDate('ama.plan_date', '<=',$dt->format("Y-m-d"))
// ->whereDate('ama.plan_date', '>', $minSevenDays)
// ->get();
$activities = DB::table('m_activity AS a')
->join('assign_material_to_activity AS amta', 'amta.activity_id', '=', 'a.id')
->where('a.type_activity', 'task')
->where('a.bobot_planning', '>', 0)
->where('a.proyek_id', '=', $projectId)
->whereDate('amta.plan_date', '<=', $dt->format("Y-m-d"))
->whereDate('amta.plan_date', '>', $minSevenDays)
->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id');
$dataPlanM = DB::table('m_activity AS a')
->join('assign_hr_to_activity AS ahta', 'ahta.activity_id', '=', 'a.id')
->where('a.type_activity', 'task')
->where('a.bobot_planning', '>', 0)
->where('a.proyek_id', '=', $projectId)
->whereDate('a.start_date', '<=', $dt->format("Y-m-d"))
->whereDate('a.start_date', '>', $minSevenDays)
->select('a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress', 'a.id')
->union($activities)
->get();
$dataActualM = DB::table('report_activity_material as ram')
->select('ram.activity_id', 'ram.qty', 'ram.report_date', 'a.bobot_planning', 'a.biaya_actual', 'a.duration', 'a.persentase_progress')
->join('m_activity as a', 'a.id', '=', 'ram.activity_id')
->where('a.proyek_id', '=', $projectId)
->whereDate('ram.report_date', '<=', $dt->format("Y-m-d"))
->whereDate('ram.report_date', '>', $minSevenDays)
->get();
$dataTempPlan = [];
$x = 0;
$sumPercentagePlan = 0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
foreach ($dataPlanM as $keyPlanM) {
// $sumVolPlan = DB::table(function ($query) use ($projectId) {
// $query->select('a.*')
// ->from('m_activity AS a')
// ->join('assign_material_to_activity as amta', 'amta.activity_id', '=', 'a.id')
// ->where('a.type_activity', 'task')
// ->where('a.bobot_planning', '>', 0)
// ->where('a.proyek_id', $projectId)
// ->unionAll(function ($query) use ($projectId) {
// $query->select('a.*')
// ->from('m_activity AS a')
// ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'a.id')
// ->where('a.type_activity', 'task')
// ->where('a.bobot_planning', '>', 0)
// ->where('a.proyek_id', $projectId);
// })->orderBy('id', 'asc');
// }, 'subquery')
// ->sum('bobot_planning');
$sumVolPlan = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyPlanM->id)
->groupBy('activity_id')
->first();
$weekCount = 1; // jadiin perhari (1)
$weeklyPlan = $sumVolPlan->ttl_qty_plan / $weekCount;
$weeklyProgress = $weeklyPlan / $sumVolPlan->ttl_qty_plan * $keyPlanM->bobot_planning;
// $weeklyPlan = $sumVolPlan->ttl_qty_plan / $weekCount;
// $weeklyProgress = 80;
$dataTempPlan[$x]['activity_id'] = $keyPlanM->id;
$dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan[$x]['ttl_plan'] = $sumVolPlan;
$dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual;
$dataTempPlan[$x]['duration'] = $keyPlanM->duration;
$dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress;
try {
$dataTempPlan[$x]['percentage'] = $keyPlanM->bobot_planning;
$sumPercentagePlan += $weeklyProgress;
if (isset($keyPlanM->duration) && $keyPlanM->duration > 0)
$totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100;
else
$totalBCWP = 0;
$dataTempPlan[$x]['totalBCWP'] = $totalBCWP;
} catch (\DivisionByZeroError $e) {
return response()->json(['message' => $e->getMessage()]);
}
$x++;
}
$w = 0;
$dataTempReport = [];
$sumPercentageActual = 0;
@ -767,9 +1086,9 @@ class MasterFunctionsHelper
$tempPercentagePlan[] = round($tempTtlPercentPlan, 2);
$tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan];
$tempPercentageReal[] = round($tempTtlPercentActual, 2);
if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) {
break;
}
// if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) {
// break;
// }
} else {
$tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2));
$tempPercentagePlan[] = round($sumPercentagePlan, 2);
@ -803,20 +1122,22 @@ class MasterFunctionsHelper
$totalBCWP = $lastReal * $dataProject->rencana_biaya / 100;
$dataResponse = array(
"date" => $tempDate,
"start" => $begin,
"end" => $end,
"percentage" => $tempPercentage,
"percentagePlan" => $tempPercentagePlan,
"percentageReal" => $tempPercentageReal,
"data_details" => $arr_ActualM,
"budget_control" => array(
"current_budget" => $totalRencanaBudget,
"acwp" => round($totalACWP, 0),
"bcwp" => round($totalBCWP, 0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP, 0)),
"add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation,
"potential" => $potential,
)
// "budget_control" => array(
// "current_budget" => $totalRencanaBudget,
// "acwp" => round($totalACWP, 0),
// "bcwp" => round($totalBCWP, 0),
// "rem_to_complete" => ($totalRencanaBudget - round($totalACWP, 0)),
// "add_cost_to_complete" => 0,
// "estimated_at_completion" => $estimatedCost,
// "cost_deviation" => $costDeviation,
// "potential" => $potential,
// )
);
$dataFinal[] = array(
@ -865,7 +1186,7 @@ class MasterFunctionsHelper
if (isset($dataPayload['end_date'])) {
$maxDate = $dataPayload['end_date'];
$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');
} else {
// $maxDate = DB::table('assign_material_to_activity as ama')
@ -1056,5 +1377,4 @@ class MasterFunctionsHelper
return $dataFinal;
}
}

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);
}
}
}

287
app/Http/Controllers/Controller.php

@ -1,11 +1,14 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use App\Models\UserToActivity;
use App\Models\Activity;
use App\Models\AssignMaterial;
use App\Models\User;
use App\Models\Divisi;
use Laravel\Lumen\Routing\Controller as BaseController;
use App\Models\ReportK3Detail;
@ -16,18 +19,21 @@ class Controller extends BaseController
protected $pathDocument = "assets/file/project/";
protected $pathTmpImport = "assets/file/tmpimport/";
protected $pathActivityDocument = "assets/file/activity/";
protected $listJoinAll = ['first', 'second', 'third', 'fourth', 'fifth',
'sixth', 'seventh', 'eighth', 'ninth', 'tenth'];
protected $listJoinAll = [
'first', 'second', 'third', 'fourth', 'fifth',
'sixth', 'seventh', 'eighth', 'ninth', 'tenth'
];
protected $currentDate;
protected $currentName;
protected $currentId;
protected $companyId;
public function __construct()
{
$this->currentDate = date("Y-m-d H:i:s");
$this->currentName = auth()->user() ? auth()->user()->name : "system";
$this->currentId = auth()->user() ? auth()->user()->id : 0;
$this->companyId = auth()->user() ? auth()->user()->company_id : 0;
$this->pathImage = config('assets.image');
$this->pathDocument = config('assets.project');
$this->pathActivityDocument = config('assets.activity');
@ -36,43 +42,43 @@ class Controller extends BaseController
protected function setUpPayload($condition, $tableSelf)
{
$alias = "selfTable";
$builder = DB::table($tableSelf." AS ".$alias);
$builder = DB::table($tableSelf . " AS " . $alias);
// $builder = $builder->select($alias.".*");
if($condition){
if(isset($condition['select'])){
foreach($condition['select'] as $select){
$builder = $builder->addSelect($alias.".".$select);
if ($condition) {
if (isset($condition['select'])) {
foreach ($condition['select'] as $select) {
$builder = $builder->addSelect($alias . "." . $select);
}
}else{
$builder = $builder->addSelect($alias.".*");
} else {
$builder = $builder->addSelect($alias . ".*");
}
if(isset($condition['joins'])){
if (isset($condition['joins'])) {
$selectColumn = [];
$no = 0;
foreach($condition['joins'] as $join){
foreach ($condition['joins'] as $join) {
$tableJoin = isset($join['name1']) ? $join['name1'] : $alias;
$tableName = $join['name'];
$columnJoin = $join['column_join']; // foreign key table sini
$columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan
if (isset($join['column_results'])) {
$columnResult = $join['column_results'];
$columnResult = $join['column_results'];
foreach($columnResult as $sColumn){
$builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn);
}
foreach ($columnResult as $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++;
}
}
if(isset($condition['columns'])){
if (isset($condition['columns'])) {
$listWhere = $condition['columns'];
$builder = $builder->where(function ($query) use($listWhere, $alias){
foreach($listWhere as $where){
$builder = $builder->where(function ($query) use ($listWhere, $alias) {
foreach ($listWhere as $where) {
$value = $where['value'];
if($value && $value!="" && $value!=" "){
if ($value && $value != "" && $value != " ") {
$column = $where['name'];
$operator = strtolower($where['logic_operator']); // like, =, <>, range
$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);
}
$data['count'] = clone $builder;
if(isset($condition['paging'])){
if (isset($condition['paging'])) {
$builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']);
}
if(isset($condition['orders'])){
if (isset($condition['orders'])) {
$orders = $condition['orders'];
$sortBy = $orders['ascending'] ? "ASC" : "DESC";
$columnOrder = $orders['columns'];
foreach($columnOrder as $column){
$builder = $builder->orderBy($alias.".".$column, $sortBy);
foreach ($columnOrder as $column) {
$builder = $builder->orderBy($alias . "." . $column, $sortBy);
}
}
}
@ -113,8 +119,8 @@ class Controller extends BaseController
$operator = $listGroupWhere['operator'];
$operatorGroup = $listGroupWhere['group_operator'];
$listWhere = $listGroupWhere['where'];
if(strtolower($operator)=="and"){
$builder = $builder->where(function($query) use($operatorGroup, $listWhere, $alias){
if (strtolower($operator) == "and") {
$builder = $builder->where(function ($query) use ($operatorGroup, $listWhere, $alias) {
$no = 1;
foreach ($listWhere as $where) {
$value = $where['value'];
@ -122,22 +128,22 @@ class Controller extends BaseController
$operator = strtolower($where['logic_operator']);
$value2 = isset($where['value1']) ? $where['value1'] : "";
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias;
if($value && $value!="" && $value!=" "){
if($operatorGroup=="and"){
if ($value && $value != "" && $value != " ") {
if ($operatorGroup == "and") {
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{
if($no==1){
} else {
if ($no == 1) {
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{
} else {
$query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}
}
}
$no = $no+1;
$no = $no + 1;
}
});
}else if(strtolower($operator)=="or"){
$builder = $builder->orWhere(function($query) use($operatorGroup, $listWhere, $alias){
} else if (strtolower($operator) == "or") {
$builder = $builder->orWhere(function ($query) use ($operatorGroup, $listWhere, $alias) {
$no = 1;
foreach ($listWhere as $where) {
$value = $where['value'];
@ -145,13 +151,13 @@ class Controller extends BaseController
$operator = strtolower($where['logic_operator']);
$value2 = isset($where['value1']) ? $where['value1'] : "";
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias;
if($value && $value!="" && $value!=" "){
if($operatorGroup=="and"){
if ($value && $value != "" && $value != " ") {
if ($operatorGroup == "and") {
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{
if($no==1){
} else {
if ($no == 1) {
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{
} else {
$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)
{
$query = $oldQuery;
if($operator=="range"){
$query = $query->whereBetween($tableColumn.".".$column, [$value, $value2]);
}else if($operator=="like"){
$query = $query->where($tableColumn.".".$column, 'like', '%'.$value.'%');
}else if($operator=="ilike"){
$query = $query->where($tableColumn.".".$column, '~*', $value);
}else if($operator=="="){
$query = $query->where($tableColumn.".".$column, $value);
}else if($operator=="in"){
$query = $query->whereIn($tableColumn.".".$column, $value);
}else if($operator=="notin"){
$query = $query->whereNotIn($tableColumn.".".$column, $value);
}else{
$query = $query->where($tableColumn.".".$column, $operator, $value);
if ($operator == "range") {
$query = $query->whereBetween($tableColumn . "." . $column, [$value, $value2]);
} else if ($operator == "like") {
$query = $query->where($tableColumn . "." . $column, 'like', '%' . $value . '%');
} else if ($operator == "ilike") {
$query = $query->where($tableColumn . "." . $column, '~*', $value);
} else if ($operator == "=") {
$query = $query->where($tableColumn . "." . $column, $value);
} else if ($operator == "in") {
$query = $query->whereIn($tableColumn . "." . $column, $value);
} else if ($operator == "notin") {
$query = $query->whereNotIn($tableColumn . "." . $column, $value);
} else {
$query = $query->where($tableColumn . "." . $column, $operator, $value);
}
return $query;
}
private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2){
private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2)
{
$query = $oldQuery;
if($operator=="range"){
if ($operator == "range") {
$query = $query->whereBetween($column, [$value, $value2]);
}else if($operator=="like"){
$query = $query->where($column, 'like', '%'.$value.'%');
}else if($operator=="ilike"){
} else if ($operator == "like") {
$query = $query->where($column, 'like', '%' . $value . '%');
} else if ($operator == "ilike") {
$query = $query->where($column, '~*', $value);
}else if($operator=="="){
} else if ($operator == "=") {
$query = $query->where($column, $value);
}else if($operator=="in"){
} else if ($operator == "in") {
$query = $query->whereIn($column, $value);
}else if($operator=="notin"){
} else if ($operator == "notin") {
$query = $query->whereNotIn($column, $value);
}else{
} else {
$query = $query->where($column, $operator, $value);
}
return $query;
@ -207,25 +214,26 @@ class Controller extends BaseController
private function orWhereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2)
{
$query = $oldQuery;
if($operator=="range"){
$query = $query->orWhereBetween($tableColumn.".".$column, [$value, $value2]);
}else if($operator=="like"){
$query = $query->orWhere($tableColumn.".".$column, 'like', '%'.$value.'%');
}else if($operator=="ilike"){
$query = $query->where($tableColumn.".".$column, '~*', $value);
}else if($operator=="="){
$query = $query->orWhere($tableColumn.".".$column, $value);
}else if($operator=="in"){
$query = $query->orWhereIn($tableColumn.".".$column, $value);
}else if($operator=="notin"){
$query = $query->orWhereNotIn($tableColumn.".".$column, $value);
}else{
$query = $query->orWhere($tableColumn.".".$column, $operator, $value);
if ($operator == "range") {
$query = $query->orWhereBetween($tableColumn . "." . $column, [$value, $value2]);
} else if ($operator == "like") {
$query = $query->orWhere($tableColumn . "." . $column, 'like', '%' . $value . '%');
} else if ($operator == "ilike") {
$query = $query->where($tableColumn . "." . $column, '~*', $value);
} else if ($operator == "=") {
$query = $query->orWhere($tableColumn . "." . $column, $value);
} else if ($operator == "in") {
$query = $query->orWhereIn($tableColumn . "." . $column, $value);
} else if ($operator == "notin") {
$query = $query->orWhereNotIn($tableColumn . "." . $column, $value);
} else {
$query = $query->orWhere($tableColumn . "." . $column, $operator, $value);
}
return $query;
}
protected function calculateAllCost($activity_id, $proyek_id){
protected function calculateAllCost($activity_id, $proyek_id)
{
$humanCostPlanning = $this->calculateAllHumanCost($activity_id, $proyek_id);
$materialCostPlanning = $this->calculateMaterialCost($activity_id, $proyek_id);
$toolsCostPlanning = 0;
@ -236,11 +244,11 @@ class Controller extends BaseController
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")
->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id")
->where("assign_hr_to_activity.activity_id", $activity_id)->where("assign_hr_to_activity.proyek_id", $proyek_id)
->where("ahp.proyek_id", $proyek_id)
->get();
$dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate", "ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate")
->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id")
->where("assign_hr_to_activity.activity_id", $activity_id)->where("assign_hr_to_activity.proyek_id", $proyek_id)
->where("ahp.proyek_id", $proyek_id)
->get();
$totalCost = 0;
foreach ($dataHuman as $human) {
@ -255,61 +263,110 @@ class Controller extends BaseController
$activity = Activity::find($activity_id);
$duration = $activity->duration;
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100;
$maxUsed = $human->max_used / 100;
if ($human->uom_standart_rate == "Hour") {
$totalCost = ($standarRate*8*$duration)*$maxUsed;
return $totalCost;
$totalCost = ($standarRate * 8 * $duration) * $maxUsed;
return $totalCost;
}
$totalCost = ($standarRate*$duration)*$maxUsed;
$totalCost = ($standarRate * $duration) * $maxUsed;
return $totalCost;
}
private function calculateMaterialCost($activity_id, $proyek_id)
{
$totalCost = AssignMaterial::selectRaw("COALESCE(qty_planning,0)*COALESCE(budget,0) as totalCost")
->where("proyek_id", $proyek_id)
->where("activity_id", $activity_id)
->sum(AssignMaterial::raw("COALESCE(qty_planning, 0) * COALESCE(budget, 0)"));
$totalCost = AssignMaterial::selectRaw("COALESCE(qty_planning,0)*COALESCE(budget,0) as totalCost")
->where("proyek_id", $proyek_id)
->where("activity_id", $activity_id)
->sum(AssignMaterial::raw("COALESCE(qty_planning, 0) * COALESCE(budget, 0)"));
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");
// return $response->json;
$url = config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json";
// $token = config('api.adw_token');
$response = $this->curlRequest($url);
$url = config('api.nominatim') . "/reverse?lat=" . $lat . "&lon=" . $lng . "&format=json";
// $token = config('api.adw_token');
$response = $this->curlRequest($url);
return $response;
}
private function curlRequest($url){
$ch = curl_init();
// $headers = [
// 'Authorization: '.$token
// ];
curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
private function curlRequest($url)
{
$ch = curl_init();
// $headers = [
// 'Authorization: '.$token
// ];
curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if ($response === false)
$response = curl_error($ch);
curl_close($ch);
$response = curl_exec($ch);
if ($response === false)
$response = curl_error($ch);
curl_close($ch);
return json_decode($response);
}
return json_decode($response);
}
protected function addDetailK3($dataDetail, $report_id){
protected function addDetailK3($dataDetail, $report_id)
{
foreach ($dataDetail as $value) {
$dataNew = array(
"report_k3_id"=>$report_id,
"checklist_k3_id"=>$value['checklist_id'],
"name_checklist_k3"=>$value['checklist_name'],
"created_by"=>$this->currentName
"report_k3_id" => $report_id,
"checklist_k3_id" => $value['checklist_id'],
"name_checklist_k3" => $value['checklist_name'],
"created_by" => $this->currentName
);
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;
}
}

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);
}
}
}

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'
];
}

36
app/Models/Divisi.php

@ -6,37 +6,39 @@ use Illuminate\Database\Eloquent\Model;
class Divisi extends Model
{
protected $table = 'm_divisi';
protected $table = 'm_divisi';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name',
protected $fillable = [
'name',
'parent',
'description',
'color',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
public static function boot() {
'description',
'color',
'created_at',
'created_by',
'updated_at',
'updated_by',
'company_id'
];
public static function boot()
{
parent::boot();
static::deleting(function($data) {
static::deleting(function ($data) {
$data->children()->delete();
});
}
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()
{
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_by',
'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'
];
}

17
app/Models/Project.php

@ -30,7 +30,7 @@ class Project extends Model
'durasi_proyek',
'progress_by_worklog',
'status',
'currency_symbol',
'currency_symbol',
'currency_code',
'currency_name',
'project_objectives',
@ -39,16 +39,15 @@ class Project extends Model
'testing_environment',
'budget_health',
'phase_id',
'late_consequence',
'assumtion',
'calculation_status',
'structur_organization',
'scurve',
'late_consequence',
'assumtion',
'calculation_status',
'structur_organization',
'scurve',
'created_at',
'created_by',
'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';
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';
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';
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';
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';
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';
protected $fillable = [
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by', 'company_id'
];
}

34
routes/web.php

@ -1,10 +1,10 @@
<?php
$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('/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->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/add', 'ProjectController@add');
$router->put('/project/update/{id}', 'ProjectController@update');
@ -209,11 +209,11 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/activity/search', 'ActivityController@search');
$router->post('/activity/search-analysis', 'ActivityController@searchAnalysis');
$router->post('/activity/search-analysis-prep', 'ActivityController@searchAnalysisPrep');
$router->post('/activity/import', 'ActivityController@import');
$router->post('/activity/import-update', 'ActivityController@importUpdate');
$router->post('/activity/import-old', 'ActivityController@importOld');
$router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate');
$router->get('/activity/update-schedule/{ganttId}', 'ActivityController@updateSchedule');
$router->post('/activity/import', 'ActivityController@import');
$router->post('/activity/import-update', 'ActivityController@importUpdate');
$router->post('/activity/import-old', 'ActivityController@importOld');
$router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate');
$router->get('/activity/update-schedule/{ganttId}', 'ActivityController@updateSchedule');
$router->post('/task', 'ActivityController@add');
$router->get('/task/edit/{id}', 'ActivityController@edit');
$router->put('/task/{id}', 'ActivityController@update');
@ -413,7 +413,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/report-k3-detail/list', 'ReportK3DetailController@list');
$router->post('/user-to-proyek/add', 'UserToProyekController@add');
$router->post('/user-to-proyek/add-multiple', 'UserToProyekController@addMultiple');
$router->post('/user-to-proyek/add-multiple', 'UserToProyekController@addMultiple');
$router->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit');
$router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update');
$router->post('/user-to-proyek/search', 'UserToProyekController@search');
@ -498,6 +498,20 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/broadcast/search', 'BroadcastController@search');
$router->delete('/broadcast/delete/{id}', 'BroadcastController@delete');
$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