Browse Source

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

Reviewed-on: OSPRO/ADW-Backend#1
pull/3/head
yusuf 2 years ago
parent
commit
6500375845
  1. 1
      .gitignore
  2. 20
      activity_log.txt
  3. 304
      app/Http/Controllers/ActivityController.php
  4. 90
      app/Http/Controllers/ActivityDokumenController.php
  5. 147
      app/Http/Controllers/AssignMaterialController.php
  6. 49
      app/Http/Controllers/AuthController.php
  7. 5
      app/Http/Controllers/Controller.php
  8. 83
      app/Http/Controllers/DashboardController.php
  9. 63
      app/Http/Controllers/DivisiController.php
  10. 87
      app/Http/Controllers/ProjectController.php
  11. 87
      app/Http/Controllers/ProjectDokumenController.php
  12. 135
      app/Http/Controllers/RequestMaterialController.php
  13. 71
      app/Http/Controllers/RoleController.php
  14. 108
      app/Http/Controllers/UserToActivityController.php
  15. 45
      app/Models/AssignMaterial.php
  16. 6
      app/Models/RequestMaterial.php
  17. 33
      app/Models/UserToActivity.php
  18. 2
      config/api.php
  19. 5
      config/jwt.php
  20. 0
      database/sql/001-absensi.sql
  21. 31
      routes/web.php

1
.gitignore vendored

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

20
activity_log.txt

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

304
app/Http/Controllers/ActivityController.php

@ -11,7 +11,6 @@ use App\Models\UserToActivity;
use App\Models\CommentActivity;
use App\Models\AssignMaterial;
use App\Models\AssignTools;
use App\Models\OfficeHours;
use App\Models\VersionGantt;
use App\Models\Holiday;
use App\Models\ReportActivity;
@ -534,128 +533,13 @@ class ActivityController extends Controller
public function calculateAllCost($activity_id, $proyek_id)
{
$humanCostPlanning = $this->calculateHuman($activity_id, $proyek_id);
$materialCostPlanning = 0;
$toolsCostPlanning = 0;
$allCost = $humanCostPlanning + $materialCostPlanning + $toolsCostPlanning;
$allCost = $materialCostPlanning + $toolsCostPlanning;
return $allCost;
}
private function calculateHuman($activity_id, $proyek_id)
{
$dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate","ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate")->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id")
->where("assign_hr_to_activity.activity_id", $activity_id)->where("assign_hr_to_activity.proyek_id", $proyek_id)
->where("ahp.proyek_id", $proyek_id)
->get();
$totalCost = 0;
foreach ($dataHuman as $human) {
$uom = $human->uom_standart_rate;
$totalCost += $this->calculateHumanCost($human, $activity_id);
}
return $totalCost;
}
private function calculateHumanCost($human, $activity_id)
{
$activity = Activity::find($activity_id);
$duration = $activity->duration;
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100;
$totalCost = ($standarRate*$duration)*$maxUsed;
return $totalCost;
}
private function calculateHumanDay($human, $activity_id)
{
$activity = Activity::find($activity_id);
$duration = $activity->duration;
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100;
$totalCost = ($standarRate*$duration)*$maxUsed;
return $totalCost;
}
private function calculateHumanHours($human, $activity_id, $proyek_id)
{
$hours = OfficeHours::where("proyek_id", $proyek_id)->first();
$activity = Activity::find($activity_id);
$ganttId = $activity->version_gantt_id;
$verGantt = VersionGantt::find($ganttId);
$holiday = Holiday::where("version_gantt_id", $ganttId)->where("proyek_id", $proyek_id)->pluck("date");
$dateHoliday = $holiday->all();
$configOff = $verGantt->config_dayoff;
if($configOff && $configOff!= ""){
$dayOff = explode(",", $verGantt->config_dayoff);
$dayOff = array_map(
function($value) { return (int)$value; },
$dayOff
);
}else{
$dayOff = [];
}
$begin = new \DateTime($activity->start_date);
$end = new \DateTime($activity->end_date);
$end = $end->modify( '+1 day' );
$interval = \DateInterval::createFromDateString('1 day');
$period = new \DatePeriod($begin, $interval, $end);
$totalCost = 0;
foreach ($period as $dt) {
$weekDay = $dt->format("w");
$currentDay = $dt->format("Y-m-d");
if(!in_array($weekDay, $dayOff) && !in_array($currentDay, $dateHoliday))
{
$totalHours = $this->getHourInDay($hours, $weekDay);
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100;
$totalCost += ($standarRate*$totalHours)*$maxUsed;
}
}
return $totalCost;
}
private function getHourInDay($hours, $day)
{
$totalHours = 0;
switch ($day) {
case 1:
$totalHours = ceil(abs(((strtotime($hours->monday_end)-strtotime($hours->monday_start))/60)/60));
break;
case 2:
$totalHours = ceil(abs(((strtotime($hours->tuesday_end)-strtotime($hours->tuesday_start))/60)/60));
break;
case 3:
$totalHours = ceil(abs(((strtotime($hours->wednesday_end)-strtotime($hours->wednesday_start))/60)/60));
break;
case 4:
$totalHours = ceil(abs(((strtotime($hours->thursday_end)-strtotime($hours->thursday_start))/60)/60));
break;
case 5:
$totalHours = ceil(abs(((strtotime($hours->friday_end)-strtotime($hours->friday_start))/60)/60));
break;
case 6:
$totalHours = ceil(abs(((strtotime($hours->saturday_end)-strtotime($hours->saturday_start))/60)/60));
break;
default:
$totalHours = ceil(abs(((strtotime($hours->sunday_end)-strtotime($hours->sunday_start))/60)/60));
break;
}
return $totalHours;
}
private function calculateMaterial($activity_id, $proyek_id)
{
$totalCost = AssignMaterial::selectRaw("ISNULL(qty_planning,0)*ISNULL(budget,0) as totalCost")->where("proyek_id", $proyek_id)->where("activity_id", $activity_id)->sum("totalCost");
return $totalCost;
}
private function calculateTools($activity_id, $proyek_id)
{
}
public function getPercentagePerDay(Request $request)
{
$dataPayload = $request->all();
@ -928,6 +812,11 @@ class ActivityController extends Controller
$estimatedCost = ($totalRencanaBudget+0);
}
$costDeviation = $totalRencanaBudget - $estimatedCost;
if($costDeviation > 0){
$potential = "SAVING";
} else {
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
}
$dataResponse = array(
"date" =>$tempDate,
@ -940,7 +829,7 @@ class ActivityController extends Controller
"add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation,
"potential" => $costDeviation > 0 ? "SAVING" : $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"
"potential" => $potential,
)
);
@ -955,185 +844,6 @@ class ActivityController extends Controller
}
public function getCalculateCurvaSBackup(Request $request)
{
$dataPayload = $request->all();
$allGantt = [];
foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getMaxVersionGantt($val);
}
$dataFinal=[];
foreach ($allGantt as $val) {
$dataProject = Project::find($val['proyek_id']);
$holidays = Holiday::where("version_gantt_id", $val['last_gantt_id'])->where("proyek_id", $val['proyek_id'])->get();
$dateHoliday = []; //$holiday->all();
foreach ($holidays as $holiday) {
$startH = new \DateTime($holiday->date);
$endH = clone $startH;
$endH->modify('+'.$holiday->duration.' day');
$intervalH = \DateInterval::createFromDateString('1 day');
$periodH = new \DatePeriod($startH, $intervalH, $endH);
foreach ($periodH as $dt) {
$dateHoliday[] = $dt->format("Y-m-d");
}
}
$verGantt = VersionGantt::find($val['last_gantt_id']);
$configOff = $verGantt->config_dayoff;
if($configOff && $configOff!= ""){
$dayOff = explode(",", $verGantt->config_dayoff);
$dayOff = array_map(
function($value) { return (int)$value; },
$dayOff
);
}else{
$dayOff = [];
}
$checkHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->count();
if($checkHeader > 0){
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
$minDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date");
$maxDate = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date");
}else{
$minDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->min("start_date");
$maxDate = Activity::whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->max("end_date");
}
$begin = new \DateTime($minDate);
$end = new \DateTime($maxDate);
$end2 = new \DateTime($maxDate);
$end2 = $end2->modify( '-1 day' );
$interval = \DateInterval::createFromDateString('1 day');
$period = new \DatePeriod($begin, $interval, $end);
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
if($dataHeader){
$totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as bigint))'))->where('parent_id', $dataHeader->id)->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
}else{
$totalRencanaBudget = Activity::select(DB::raw('sum(cast(rencana_biaya as bigint))'))->whereNull('parent_id')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->first();
}
$totalRencanaBudget = $totalRencanaBudget->sum;
$currentPercentage = 0;
$currentACWP = 0;
$budgetControlACWP = 0;
$currentProgressActivity = 0;
$currentBCWP = 0;
$budgetControlBCWP = 0;
$dataDate = [];
$dataPercen = [];
$testdata = [];
$countWeek = 0;
foreach ($period as $dt) {
$weekDay = $dt->format("w");
$currentDate = $dt->format("Y-m-d");
$testdata[] = array('weekday' => $weekDay, 'date' =>$currentDate, 'dayof' => $dayOff);
$totalPercentage = isset($totalPercentage) ? $totalPercentage : 0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalProgressActivity = isset($totalProgressActivity) ? $totalProgressActivity : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
if(!in_array($weekDay, $dayOff) && !in_array($currentDate, $dateHoliday))
{
$dataActivity = Activity::whereRaw("'".$currentDate."' BETWEEN DATE(m_activity.start_date) AND DATE(m_activity.end_date) - INTERVAL '1 DAY'")->where('type_activity', 'task')->where("proyek_id", $val['proyek_id'])->where("version_gantt_id", $val['last_gantt_id'])->get();
foreach ($dataActivity as $activity) {
$duration = $activity->duration;
if($totalRencanaBudget > 0 && $duration > 0){
$totalPercentage += $activity->bobot_planning/$duration;
if($activity->biaya_actual > 0 && $activity->persentase_progress){
$totalACWP += $activity->biaya_actual/$duration;
$totalProgressActivity += (($activity->persentase_progress*$activity->bobot_planning)/100)/$duration;
$totalBCWP += (((($activity->persentase_progress*$activity->bobot_planning)/100)/$duration)* $totalRencanaBudget)/100;
}
}
}
}
if($currentDate == $end2->format('Y-m-d')){
$currentPercentage = round(($currentPercentage + $totalPercentage), 0);
if($totalACWP > 0 ){
$budgetControlACWP = $currentACWP + $totalACWP;
}
if($totalBCWP > 0 ){
$budgetControlBCWP = $currentBCWP + $totalBCWP;
}
$currentACWP = $totalACWP == 0 ? null : $currentACWP + $totalACWP;
$currentProgressActivity = $totalProgressActivity == 0 ? null : round(($currentProgressActivity + $totalProgressActivity),0);
$currentBCWP = $totalBCWP == 0 ? null :$currentBCWP + $totalBCWP;
$currentPercentage = $currentPercentage > 100 ? 100 : $currentPercentage;
$currentProgressActivity = $currentProgressActivity > 100 ? 100 : $currentProgressActivity;
$dataDate[] = array($currentDate, round($currentBCWP,0), round($currentACWP,0));
$dataPercen[] = array($currentPercentage, $currentProgressActivity);
$totalPercentage = 0;
$totalACWP = 0;
$totalProgressActivity = 0;
$totalBCWP = 0;
}else if($weekDay == "0"){
$currentPercentage = round(($currentPercentage + $totalPercentage), 0);
if($totalACWP > 0 ){
$budgetControlACWP = $currentACWP + $totalACWP;
}
if($totalBCWP > 0 ){
$budgetControlBCWP = $currentBCWP + $totalBCWP;
}
$currentACWP = $totalACWP == 0 ? null : $currentACWP + $totalACWP;
$currentProgressActivity = $totalProgressActivity == 0 ? null : round(($currentProgressActivity + $totalProgressActivity),0);
$currentBCWP = $totalBCWP == 0 ? null :$currentBCWP + $totalBCWP;
$currentPercentage = $currentPercentage > 100 ? 100 : $currentPercentage;
$currentProgressActivity = $currentProgressActivity > 100 ? 100 : $currentProgressActivity;
$dataDate[] = array($currentDate, round($currentBCWP,0), round($currentACWP,0));
$dataPercen[] = array($currentPercentage, $currentProgressActivity);
$totalPercentage = 0;
$totalACWP = 0;
$totalProgressActivity = 0;
$totalBCWP = 0;
}
}
if(round($budgetControlACWP,0) > $totalRencanaBudget){
$estimatedCost = round($budgetControlACWP,0)+0;
}else{
$estimatedCost = ($totalRencanaBudget+0);
}
$costDeviation = $totalRencanaBudget - $estimatedCost;
$dataResponse = array(
"date" =>$dataDate,
"percentage" =>$dataPercen,
"budget_control" =>array("current_budget"=> $totalRencanaBudget,
"acwp" => round($budgetControlACWP,0),
"bcwp" => round($budgetControlBCWP,0),
"rem_to_complete" => ($totalRencanaBudget - round($budgetControlACWP,0)),
"add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation,
"potential" => $costDeviation > 0 ? "SAVING" : $costDeviation == 0 ? "ON BUDGET" : "OVERRUN"
)
);
$dataFinal[] = array(
"proyek_name"=> $dataProject->nama,
"data"=>$dataResponse
);
}
if($dataFinal){
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'test' => array('current'=>$currentDate,'max' =>$end2->format('Y-m-d')), 'totalRecord'=>1], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list percentage day, please try again later!','code'=>400], 400);
}
}
public function getCalculateCurvaSDays(Request $request)
{
$dataPayload = $request->all();

90
app/Http/Controllers/ActivityDokumenController.php

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

147
app/Http/Controllers/AssignMaterialController.php

@ -4,50 +4,12 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\AssignMaterial;
use App\Models\MaterialResource;
use App\Models\RequestMaterial;
use App\Models\Activity;
use App\Models\ReportActivityMaterial;
use Datatables;
class AssignMaterialController extends Controller
{
public function add_backup(Request $request){
$this->validate($request, [
'activity_id' => 'required',
'material_id' => 'required',
'qty_planning' => 'required',
'budget' => 'required'
]);
$checkStock = MaterialResource::where("id", $request->material_id)->first();
$currentStock = $checkStock->qty;
if((int)$currentStock < (int)$request->qty_planning){
return response()->json(['status'=>'failed','message'=>'Not enough stock in warehouse!','code'=>400]);
die();
}
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = AssignMaterial::create($data);
if($result){
$checkStock = MaterialResource::find($request->material_id);
$newStock = (int)$checkStock->qty - (int)$request->qty_planning;
$dataUpdate = array(
"qty"=>$newStock,
"updated_by"=>$this->currentName
);
$checkStock->update($dataUpdate);
return response()->json(['status'=>'success','message'=>'Assign material successfull created','code'=>200]);
}else{
return response()->json(['status'=>'failed','message'=>'Assign material failed created','code'=>400]);
}
}
public function add(Request $request){
$this->validate($request, [
@ -60,117 +22,57 @@ class AssignMaterialController extends Controller
$currentStock = $checkStock->qty;
$price = $checkStock->price;
if((int)$currentStock < (int)$request->qty_planning){
return response()->json(['status'=>'failed','message'=>'Not enough stock !','code'=>400]);
die();
return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]);
}
$data = $request->all();
$data['created_by'] = $this->currentName;
$data['budget'] = $price;
$result = AssignMaterial::create($data);
if($result){
$updateActivity = Activity::find($request->activity_id);
if($updateActivity){
$costPlanOld = $updateActivity==null? 0 : (int)$updateActivity->rencana_biaya;
$costPlanNew = $costPlanOld + ($price*$request->qty_planning);
$updateActivity->rencana_biaya = $costPlanNew;
$updateActivity->save();
return response()->json(['status'=>'success','message'=>'Assign material successfull created, and update cost plan success '.$costPlanNew,'code'=>200]);
}else{
return response()->json(['status'=>'success','message'=>'Assign material successfull created','code'=>200]);
}
}else{
return response()->json(['status'=>'failed','message'=>'Assign material failed created','code'=>400]);
}
}
private function updateFromAdd($data){
$assignMaterial = AssignMaterial::where("activity_id", $data->activity_id)->where("material_id", $data->material_id)->first();
$newQty = (int)$assignMaterial->qty_planning + (int)$data->qty_planning;
if(!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]);
$newBudget = $assignMaterial->budget > $data->budget ? $assignMaterial->budget : $data->budget;
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=>200]);
$dataUpdate = array(
"qty_planning"=>$newQty,
"budget"=>$newBudget,
"updated_by"=>$this->currentName
);
$dataWillUpdate = AssignMaterial::where("activity_id", $data->activity_id)->where("material_id", $data->material_id);
return $dataWillUpdate->update($dataUpdate);
}
public function update(Request $request, $id){
if(!$id || (int) $id < 0 || $id==""){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
}
$data = AssignMaterial::find($id);
if($data){
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'Data Assign material not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'Assign material successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Assign material failed updated!','code'=>400], 400);
}
if($result)
return response()->json(['status'=>'success','message'=> 'Data updated!','code'=> 200], 200);
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500);
}
public function delete($id)
{
$data = AssignMaterial::find($id);
$data = AssignMaterial::where('id', $id)->first();
if($data){
$id = $data->material_id;
$stock = $data->qty_planning;
$materialResource = MaterialResource::find($id);
if($materialResource){
$oldStock = $materialResource->qty;
$newStock = $oldStock + $stock;
$dataUpdate = array(
"qty"=>$newStock,
"updated_by"=>$this->currentName
);
$materialResource->update($dataUpdate);
}
$activity = Activity::where('id', $data->activity_id)->first();
$activity->rencana_biaya -= $data->budget * $data->qty_planning;
$activity->save();
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'Data Assign material not found!','code'=>400], 400);
die();
}
if($data->delete())
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=> 200], 200);
if($delete){
return response()->json(['status'=>'success','message'=>'Assign material successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Assign material failed deleted!','code'=>400], 400);
}
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500);
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = AssignMaterial::find($id);
if($result){
if($result)
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data Assign material, please try again later!','code'=>400], 400);
}
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
}
public function search(Request $request)
@ -189,11 +91,10 @@ class AssignMaterialController extends Controller
$data = AssignMaterial::all();
$countData = $data->count();
if($data){
if($data)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get Assign material, please try again later!','code'=>400], 400);
}
return response()->json(['status'=>'failed','message'=>'Failed to get the data!','code'=> 500], 500);
}
public function datatables(Request $request){

49
app/Http/Controllers/AuthController.php

@ -4,19 +4,13 @@ namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Models\User;
use App\Models\Role;
use App\Models\Project;
use App\Models\UserProject;
class AuthController extends Controller
{
/**
* Create a new AuthController instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth:api', ['except' => ['login']]);
@ -26,27 +20,19 @@ class AuthController extends Controller
{
$username = $request->username;
$password = $request->password;
$remember = $request->remember;
$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);
}
$credentials = array(
"username"=> $username,
"password"=> md5($password)
);
$user = User::where('username', $username)->where('password', md5($password))
->first();
$user = User::where('username', $username)->where('password', md5($password))->first();
if($is_mobile){
$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);
die();
}
$dataUpdateFcm = array(
"fcm_token"=>$fcm_token
@ -54,34 +40,33 @@ class AuthController extends Controller
$hr = User::find($user->id);
if($hr){
$result = $hr->update($dataUpdateFcm);
}
if($hr)
$hr->update($dataUpdateFcm);
}
$dataRole = Role::find($user->role_id);
if($dataRole){
if($dataRole)
$user->role = $dataRole;
}
if (! $token =Auth::login($user)) {
if (! $token =Auth::login($user))
return response()->json(['error' => 'Unauthorized'], 401);
}
return $this->respondWithToken($token, $user);
}
$ttl = 60;
if($remember)
$ttl = 10080;
// todo : change existing md5 hashed function to laravel's originally bcrypt
/* $token = auth()->setTTL($ttl)->attempt(['username' => $username, 'password' => Hash::make($password)]); */
/* dd(response()->json(['code'=>'200', 'token' => $token, 'ttl' => $ttl])); */
protected function respondWithToken($token, $user)
{
return response()->json([
'code' => 200,
'data' => array(
'data_user' => $user,
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth()->factory()->getTTL() * 60
'expires_in' => auth()->factory()->getTTL() * $ttl,
),
]);
}

5
app/Http/Controllers/Controller.php

@ -251,11 +251,6 @@ class Controller extends BaseController
return $totalCost;
}
private function calculateToolsCost($activity_id, $proyek_id)
{
}
protected function updatedCostPlanning($id)
{
$sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))->where("parent_id", $id)->first();

83
app/Http/Controllers/DashboardController.php

@ -6,8 +6,7 @@ use Illuminate\Http\Request;
use App\Models\Project;
use App\Models\Activity;
use App\Models\ReportActivity;
use App\Models\UserToActivity;
use DB;
use App\Models\Role;
class DashboardController extends Controller
{
@ -25,11 +24,10 @@ class DashboardController extends Controller
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
}
if($dataPayload){
if(!$dataFinal)
return response()->json(['status'=>'failed','message'=>'Data not found','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
}
}
public function getMaxVersionGantt($id){
@ -48,14 +46,12 @@ class DashboardController extends Controller
foreach ($dataMaxVersionGantt as $val) {
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
}
if($dataPayload){
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
}else{
if(!$dataFinal)
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
}
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
}
public function list()
@ -63,30 +59,22 @@ class DashboardController extends Controller
$data = Role::all();
$countData = $data->count();
if($data){
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{
if(!$data)
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
}
}
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}
public function getActivityByProjectId($projectId) {
$output = [];
$data = Activity::select('id')->where('proyek_id', $projectId)->get();
if (count($data) > 0) {
foreach ($data as $actData) {
$output[] = $actData->id;
}
}
return $output;
}
/* for statusProyek, I want something output like this
/*
const statusProyek = [
{
"id": "1",
@ -109,17 +97,14 @@ class DashboardController extends Controller
*/
public function statusProyek(Request $request) {
$dataPayload = $request->all();
$reqProject = [];
$dataFinal = [];
$reqProject = $dataFinal = [];
if (!isset($dataPayload['project_id'])) {
if (!isset($dataPayload['project_id']))
return response()->json(['status'=>'failed','message'=>'Undefined project_id','code'=>400], 400);
}
foreach ($dataPayload['project_id'] as $val) {
$prj["project_id"] = $val;
$prj["activity_id"] = $this->getActivityByProjectId($val);
$reqProject[] = $prj;
}
@ -133,24 +118,20 @@ class DashboardController extends Controller
$sum_jumlah_pekerjaan = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->sum("jumlah_pekerjaan");
$count_activity = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->count("id");
$count_activity_done = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('persentase_progress', '100')->where('version_gantt_id', $last_version_gantt)->count("id");
$progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->sum("persentase_progress");
$count_progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->count("persentase_progress");
$progress_actual = Activity::select('id', 'bobot_planning', 'persentase_progress')->where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->get();
$current_progress = 0;
foreach($progress_actual as $objRow) {
$current_progress += ($objRow->bobot_planning * $objRow->persentase_progress) / 100;
}
if (count($reqProject[$i]['activity_id']) > 0) {
for ($j=0; $j < count($reqProject[$i]['activity_id']); $j++) {
$sum_job_count_report = ReportActivity::whereIn('activity_id', $reqProject[$i]['activity_id'])->sum("job_count_report");
}
}
if (!isset($queryProject->id)) {
if (!isset($queryProject->id))
return response()->json(['status'=>'failed','message'=>'Project with id='.$reqProject[$i]['project_id'].' is not found!','code'=>400], 400);
}
$now = time();
$akhir_proyek = strtotime($queryProject->akhir_proyek);
@ -176,31 +157,28 @@ class DashboardController extends Controller
}
}
if($dataFinal){
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>count($dataFinal)], 200);
}else{
if(empty($dataFinal))
return response()->json(['status'=>'failed','message'=>'failed get status proyek, please try again later!','code'=>400], 400);
}
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>count($dataFinal)], 200);
}
public function curvaS(Request $request)
{
$dataPayload = $request->all();
$dataMaxVersionGantt = [];
$dataFinal=[];
foreach ($dataPayload['project_id'] as $val) {
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val);
}
$dataFinal=[];
foreach ($dataMaxVersionGantt as $val) {
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
$totalCostPlanning = Activity::where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->sum('rencana_biaya');
$dataBobotPlan =[];
for ($i=0; $i < count($data); $i++) {
$tmpp = 0;
$tmpa = 0;
$tmpbc = 0;
$tmpac = 0;
$tmpp = $tmpa = $tmpbc = $tmpac = 0;
for ($x=$i; $x >= 0 ; $x--) {
$tmpp += $data[$x]['bobot_planning'];
$tmpa += ($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100;
@ -209,6 +187,7 @@ class DashboardController extends Controller
}
$data[$i]['cal_bobot_p'] = round($tmpp,2);
if($i > 0 ){
if($data[$i-1]['cal_bobot_a'] != null){
if($data[$i-1]['cal_bobot_a'] == round($tmpa,2)){
@ -219,12 +198,6 @@ class DashboardController extends Controller
}else{
$data[$i]['cal_bobot_a'] = null;
}
}else{
$data[$i]['cal_bobot_a'] = round($tmpa,2);
}
$data[$i]['cal_budget_cost'] = round($tmpbc,2);
if($i > 0 ){
if($data[$i-1]['cal_actual_cost'] != null){
if($data[$i-1]['cal_actual_cost'] == round($tmpac,2)){
$data[$i]['cal_actual_cost'] = null;
@ -235,18 +208,18 @@ class DashboardController extends Controller
$data[$i]['cal_actual_cost'] = null;
}
}else{
$data[$i]['cal_bobot_a'] = round($tmpa,2);
$data[$i]['cal_actual_cost'] = round($tmpac,2);
}
$data[$i]['cal_budget_cost'] = round($tmpbc,2);
}
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) && count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
}
if($dataPayload){
return response()->json(['status'=>'success','code'=>200, 'data'=>$dataFinal, 'totalRecord'=>1], 200);
}else{
if(!$dataFinal)
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
}
return response()->json(['status'=>'success','code'=>200, 'data'=>$dataFinal, 'totalRecord'=>1], 200);
}
}

63
app/Http/Controllers/DivisiController.php

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

87
app/Http/Controllers/ProjectController.php

@ -14,12 +14,8 @@ use App\Models\ProjectCharter;
use App\Models\ProjectApproval;
use App\Models\ProjectMileStone;
use App\Models\ProjectParticipants;
use App\Models\UserToVersionGantt;
use App\Models\RequestMaterial;
use App\Models\ShowHideColumn;
use App\Models\ToolsProject;
use App\Models\VersionGantt;
use App\Models\MaterialProject;
use App\Models\Image;
use App\Models\CommentActivity;
use App\Models\Link;
@ -30,6 +26,7 @@ use App\Models\OfficeHours;
class ProjectController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
@ -46,51 +43,43 @@ class ProjectController extends Controller
$result = Project::create($data);
if($result){
if(!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500);
$this->createOfficeHours($result->id);
$dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first();
return response()->json(['status'=>'success','message'=>'add data project successfully!', 'data_result' =>$dataResultInsert, 'code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add data project failed!','code'=>400], 400);
}
return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200);
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = Project::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data project, please try again later!','code'=>400], 400);
}
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200);
}
public function update(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id==""){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
}
$data = Project::find($id);
if($data){
if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data project not found!','code'=>400], 400);
die();
}
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500);
if($result){
return response()->json(['status'=>'success','message'=>'data project successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project failed updated!','code'=>400], 400);
}
return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200);
}
private function createOfficeHours($proyek_id)
@ -123,20 +112,15 @@ class ProjectController extends Controller
{
$data = Project::find($id);
if($data){
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$this->deleteRelative($id);
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data project not found!','code'=>400], 400);
die();
}
if(!$data->delete())
return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500);
if($delete){
return response()->json(['status'=>'success','message'=>'data project successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project failed deleted!','code'=>400], 400);
}
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
}
private function deleteRelative($project_id)
@ -210,11 +194,13 @@ class ProjectController extends Controller
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_proyek');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
@ -223,21 +209,22 @@ class ProjectController extends Controller
$data = Project::all();
$countData = $data->count();
if($data){
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list project, please try again later!','code'=>400], 400);
}
}
public function getListProjectTask($id){
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*")->where("assign_hr_to_activity.user_id", $id)->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
->groupBy("m_proyek.proyek_id")->get();
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*")
->where("assign_hr_to_activity.user_id", $id)
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
->groupBy("m_proyek.proyek_id")
->get();
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if($data){
return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list project, please try again later!','code'=>400], 400);
}
}
}

87
app/Http/Controllers/ProjectDokumenController.php

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

135
app/Http/Controllers/RequestMaterialController.php

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

71
app/Http/Controllers/RoleController.php

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

108
app/Http/Controllers/UserToActivityController.php

@ -4,10 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\UserToActivity;
use App\Models\ReportActivity;
use App\Models\Activity;
use App\Models\Image;
use App\Models\UserToProyek;
use Datatables;
class UserToActivityController extends Controller
@ -17,37 +14,20 @@ class UserToActivityController extends Controller
'activity_id' => 'required',
'user_id' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = UserToActivity::create($data);
if($result){
$updateActivity = Activity::find($request->activity_id);
$getWorkingHours = UserToProyek::where('user_id', $request->user_id)->first();
if($updateActivity && $getWorkingHours){
$costPlanOld = $updateActivity==null? 0 : (int)$updateActivity->rencana_biaya;
if($getWorkingHours->uom_standart_rate == "Day"){
$costUser = $getWorkingHours->standart_rate * $updateActivity->duration;
}else if($getWorkingHours->uom_standart_rate == "Hour"){
$costUser = ($getWorkingHours->standart_rate * 8) * $updateActivity->duration; // assumption standart working is 8 hours
}
$costPlanNew = $costPlanOld + $costUser;
$updateActivity->rencana_biaya = $costPlanNew;
$updateActivity->save();
return response()->json(['status'=>'success','message'=>'user to activity gantt Project successfull created, and cost plant successfull update '.$costPlanNew,'code'=>200]);
}else{
return response()->json(['status'=>'success','message'=>'user to activity gantt Project successfull created','code'=>200]);
}
}else{
return response()->json(['status'=>'failed','message'=>'user to activity gantt Project failed created','code'=>400]);
}
if(!UserToActivity::create($data))
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]);
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=> 200]);
}
public function addMultiple(Request $request){
$users_id = $request->user_id;
$data = UserToActivity::where("activity_id", $request->activity_id);
if($data){
$data->delete();
}
@ -55,7 +35,6 @@ class UserToActivityController extends Controller
if(is_array($users_id) && count($users_id) > 0){
$countRes = 0;
foreach($users_id as $item){
$dataInsert = array(
"user_id" => $item,
"activity_id" => $request->activity_id,
@ -63,9 +42,7 @@ class UserToActivityController extends Controller
"proyek_id" => $request->proyek_id,
"created_by" => $this->currentName
);
$result = UserToActivity::create($dataInsert);
if($result){
$countRes++;
}else{
@ -73,7 +50,9 @@ class UserToActivityController extends Controller
}
}
if($countRes > 0){
if($countRes == 0)
return response()->json(['status'=>'failed' ,'message'=>'Failed to add data!','code'=> 500]);
$allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id);
$dataUpdateCost = array(
"rencana_biaya"=>$allCost,
@ -86,74 +65,38 @@ class UserToActivityController extends Controller
$this->updatedCostPlanning($actUpdate->parent_id);
}
}
return response()->json(['status'=>'success' ,'message'=>'user to activity gantt Project successfull created','code'=>200]);
}else{
return response()->json(['status'=>'success' ,'message'=>'user to activity gantt Project failed created','code'=>400]);
}
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]);
}else{
return response()->json(['status'=>'success' ,'message'=>'user to activity gantt Project successfull created','code'=>200]);
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]);
}
}
public function update(Request $request, $id){
if(!$id || (int) $id < 0 || $id==""){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
}
$data = UserToActivity::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400);
die();
}
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if($result){
return response()->json(['status'=>'success','message'=>'user to activity gantt Project successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'user to activity gantt Project failed updated!','code'=>400], 400);
}
if(!$data->update($request->all()));
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200);
}
public function delete($id)
{
$data = UserToActivity::find($id);
if($data){
$userId = $data->user_id;
$activityId = $data->activity_id;
$delete = $data->delete();
if($delete){
$this->deleteRelative($activityId, $userId);
}
}else{
if(!$data)
return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'user to activity gantt Project successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'user to activity gantt Project failed deleted!','code'=>400], 400);
}
if($data->delete()){
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
}
private function deleteRelative($id, $userId)
{
$dataRa = ReportActivity::where("activity_id", $id)->where("user_id", $userId)->get();
foreach ($dataRa as $ra) {
$image = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($image as $value) {
if(file_exists($this->pathImage.$value->image)){
unlink($this->pathImage.$value->image);
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
}
ReportActivity::where("activity_id", $id)->where("user_id", $userId)->delete();
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500);
}
public function edit($id){
@ -164,11 +107,10 @@ class UserToActivityController extends Controller
$result = UserToActivity::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
if(!$result)
return response()->json(['status'=>'failed','message'=>'failed get data tools resource, please try again later!','code'=>400], 400);
}
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}
public function search(Request $request)

45
app/Models/AssignMaterial.php

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

6
app/Models/RequestMaterial.php

@ -11,6 +11,12 @@ class RequestMaterial extends Model
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $casts = [
'id' => 'integer',
'price' => 'float',
'qty' => 'float',
];
protected $fillable = [
'description',
'required_date',

33
app/Models/UserToActivity.php

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

2
config/api.php

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

5
config/jwt.php

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

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

31
routes/web.php

@ -1,18 +1,5 @@
<?php
/** @var \Laravel\Lumen\Routing\Router $router */
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$router->get('/', function () use ($router) {
return $router->app->version();
});
@ -20,14 +7,6 @@ $router->get('/', function () use ($router) {
$router->group(['prefix'=>'api'], function () use ($router) {
$router->post('/login', 'AuthController@login');
$router->post('/role/search', 'RoleController@search');
$router->post('/role/add', 'RoleController@add');
$router->get('/role/edit/{id}', 'RoleController@edit');
$router->put('/role/update/{id}', 'RoleController@update');
$router->delete('/role/delete/{id}', 'RoleController@delete');
$router->get('/role/list', 'RoleController@list');
$router->post('/menu/add', 'MenuController@add');
$router->get('/menu/edit/{id}', 'MenuController@edit');
$router->put('/menu/update/{id}', 'MenuController@update');
@ -41,15 +20,21 @@ $router->group(['prefix'=>'api'], function () use ($router) {
$router->delete('/role-menu/delete-byrole/{id}', 'RoleMenuController@deleteByRole');
$router->post('/role-menu/search', 'RoleMenuController@search');
$router->get('/role-menu/get-role/{id}', 'RoleMenuController@listMenu');
$router->get('/document-project/download/{id}', 'ProjectDokumenController@downloadDokumen');
$router->group(['middleware' => 'auth'], function () use ($router) {
$router->post('/role/search', 'RoleController@search');
$router->post('/role/add', 'RoleController@add');
$router->get('/role/edit/{id}', 'RoleController@edit');
$router->put('/role/update/{id}', 'RoleController@update');
$router->delete('/role/delete/{id}', 'RoleController@delete');
$router->get('/role/list', 'RoleController@list');
$router->post('/document-project/upload', 'ProjectDokumenController@uploadProjectDokumen');
$router->get('/document-project/get/{id}', 'ProjectDokumenController@dokumenByProyekId');
$router->delete('/document-project/delete/{id}', 'ProjectDokumenController@delete');
$router->post('/document-project/search', 'ProjectDokumenController@searchDocProject');
$router->get('/document-project/download/{id}', 'ProjectDokumenController@downloadDokumen');
$router->post('/document-activity/upload', 'ActivityDokumenController@uploadProjectDokumen');
$router->get('/document-activity/get/{id}', 'ActivityDokumenController@dokumenByActivityId');

Loading…
Cancel
Save