ibnu
1 year ago
26 changed files with 4914 additions and 4243 deletions
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,215 +1,221 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Http\Controllers; |
namespace App\Http\Controllers; |
||||||
|
|
||||||
use Illuminate\Http\Request; |
use Illuminate\Http\Request; |
||||||
use App\Models\AssignMaterial; |
use App\Models\AssignMaterial; |
||||||
use App\Models\RequestMaterial; |
use App\Models\RequestMaterial; |
||||||
use App\Models\Activity; |
use App\Models\Activity; |
||||||
use App\Models\ReportActivityMaterial; |
use App\Models\ReportActivityMaterial; |
||||||
use Datatables; |
use Datatables; |
||||||
|
|
||||||
class AssignMaterialController extends Controller |
class AssignMaterialController extends Controller |
||||||
{ |
{ |
||||||
private function sanitizeDecimal($number) { |
private function sanitizeDecimal($number) { |
||||||
$number = str_replace(".","",$number); |
$number = str_replace(".","",$number); |
||||||
$number = str_replace(",",".",$number); |
$number = str_replace(",",".",$number); |
||||||
return $number; |
return $number; |
||||||
} |
} |
||||||
|
|
||||||
public function add(Request $request){ |
public function add(Request $request){ |
||||||
$this->validate($request, [ |
$this->validate($request, [ |
||||||
'activity_id' => 'required', |
'activity_id' => 'required', |
||||||
'material_id' => 'required', |
'material_id' => 'required', |
||||||
'qty_planning' => 'required' |
'qty_planning' => 'required' |
||||||
]); |
]); |
||||||
|
|
||||||
$activity = Activity::where('id', $request->activity_id)->first(); |
$activity = Activity::where('id', $request->activity_id)->first(); |
||||||
|
|
||||||
$checkStock = RequestMaterial::where("id", $request->material_id)->first(); |
$checkStock = RequestMaterial::where("id", $request->material_id)->first(); |
||||||
$currentStock = $checkStock->qty; |
$currentStock = $checkStock->qty; |
||||||
if((int)$currentStock < (int)$request->qty_planning){ |
if((int)$currentStock < (int)$request->qty_planning){ |
||||||
return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]); |
return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]); |
||||||
} |
} |
||||||
|
|
||||||
$start_date = $activity->start_date; |
$start_date = $activity->start_date; |
||||||
$start_date = substr($start_date, 0, 19); // remove the timezone offset |
$start_date = substr($start_date, 0, 19); // remove the timezone offset |
||||||
$startDate = new \DateTime(date("Y-m-d", strtotime($start_date))); |
$startDate = new \DateTime(date("Y-m-d", strtotime($start_date))); |
||||||
$planDate = new \DateTime(date("Y-m-d", strtotime($request->plan_date))); |
$planDate = new \DateTime(date("Y-m-d", strtotime($request->plan_date))); |
||||||
|
|
||||||
$data = $request->all(); |
$data = $request->all(); |
||||||
$data['created_by'] = $this->currentName; |
$data['created_by'] = $this->currentName; |
||||||
$data['budget'] = $checkStock->price; |
$data['budget'] = $checkStock->price; |
||||||
$data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']); |
$data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']); |
||||||
|
|
||||||
if ($planDate >= $startDate) { |
if ($planDate >= $startDate) { |
||||||
$result = AssignMaterial::create($data); |
$result = AssignMaterial::create($data); |
||||||
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=>200], 200); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 400], 400); |
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function update(Request $request, $id){ |
public function update(Request $request, $id){ |
||||||
if(empty($id) || !is_int((int)$id)) |
if(empty($id) || !is_int((int)$id)) |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
$data = AssignMaterial::find($id); |
$data = AssignMaterial::find($id); |
||||||
if(!$data) |
if(!$data) |
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||||
|
|
||||||
$result = $data->update($request->all()); |
$result = $data->update($request->all()); |
||||||
|
|
||||||
if($result) |
if($result) |
||||||
return response()->json(['status'=>'success','message'=> 'Data updated!','code'=> 200], 200); |
return response()->json(['status'=>'success','message'=> 'Data updated!','code'=> 200], 200); |
||||||
|
|
||||||
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500); |
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500); |
||||||
} |
} |
||||||
|
|
||||||
public function delete($id) |
public function delete($id) |
||||||
{ |
{ |
||||||
$data = AssignMaterial::where('id', $id)->first(); |
$data = AssignMaterial::where('id', $id)->first(); |
||||||
|
$reports = ReportActivityMaterial::where('assign_material_id', $data->id)->get(); |
||||||
if($data->delete()) |
if (isset($reports)) { |
||||||
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=> 200], 200); |
foreach ($reports as $report) { |
||||||
|
$report->delete(); |
||||||
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); |
} |
||||||
} |
} |
||||||
|
|
||||||
public function edit($id){ |
if($data->delete()) |
||||||
if(empty($id) || !is_int((int)$id)) |
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=> 200], 200); |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
|
||||||
|
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); |
||||||
$result = AssignMaterial::find($id); |
} |
||||||
|
|
||||||
if($result) |
public function edit($id){ |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
if(empty($id) || !is_int((int)$id)) |
||||||
|
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
|
||||||
} |
$result = AssignMaterial::find($id); |
||||||
|
|
||||||
public function search(Request $request) |
if($result) |
||||||
{ |
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||||
$payload = $request->all(); |
|
||||||
$dataBuilder = $this->setUpPayload($payload, 'assign_material_to_activity'); |
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||||
$builder = $dataBuilder['builder']; |
} |
||||||
$countBuilder = $dataBuilder['count']; |
|
||||||
$dataGet = $builder->get(); |
public function search(Request $request) |
||||||
$totalRecord = $countBuilder->count(); |
{ |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
$payload = $request->all(); |
||||||
} |
$dataBuilder = $this->setUpPayload($payload, 'assign_material_to_activity'); |
||||||
|
$builder = $dataBuilder['builder']; |
||||||
public function list() |
$countBuilder = $dataBuilder['count']; |
||||||
{ |
$dataGet = $builder->get(); |
||||||
$data = AssignMaterial::all(); |
$totalRecord = $countBuilder->count(); |
||||||
$countData = $data->count(); |
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
|
} |
||||||
if($data) |
|
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
public function list() |
||||||
|
{ |
||||||
return response()->json(['status'=>'failed','message'=>'Failed to get the data!','code'=> 500], 500); |
$data = AssignMaterial::all(); |
||||||
} |
$countData = $data->count(); |
||||||
|
|
||||||
public function datatables(Request $request){ |
if($data) |
||||||
$id_activity = $request->query('idact'); |
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||||
$type = $request->query('type') ?? "material"; |
|
||||||
$data = AssignMaterial::select( |
return response()->json(['status'=>'failed','message'=>'Failed to get the data!','code'=> 500], 500); |
||||||
"assign_material_to_activity.*","m.description as material_name", "m.uom as uom" |
} |
||||||
) |
|
||||||
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
public function datatables(Request $request){ |
||||||
->where('assign_material_to_activity.activity_id', $id_activity) |
$id_activity = $request->query('idact'); |
||||||
->where('assign_material_to_activity.type', $type) |
$type = $request->query('type') ?? "material"; |
||||||
->orderBy('plan_date', 'desc') |
$data = AssignMaterial::select( |
||||||
->get(); |
"assign_material_to_activity.*","m.description as material_name", "m.uom as uom" |
||||||
return Datatables::of($data) |
) |
||||||
->addIndexColumn() |
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
||||||
->addColumn('action', function($row){ |
->where('assign_material_to_activity.activity_id', $id_activity) |
||||||
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-material-delete"><i class="fa fa-trash"></i></a>'; |
->where('assign_material_to_activity.type', $type) |
||||||
return $actionBtn; |
->orderBy('plan_date', 'desc') |
||||||
}) |
->get(); |
||||||
->rawColumns(['action'])->make(true); |
return Datatables::of($data) |
||||||
} |
->addIndexColumn() |
||||||
|
->addColumn('action', function($row){ |
||||||
public function datatablesForReportActivity(Request $request){ |
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-material-delete"><i class="fa fa-trash"></i></a>'; |
||||||
$id_activity = $request->query('idact'); |
return $actionBtn; |
||||||
$data = |
}) |
||||||
AssignMaterial::select( |
->rawColumns(['action'])->make(true); |
||||||
AssignMaterial::raw('SUM(qty_planning) as qty_planning'), |
} |
||||||
"m.description as material_name", |
|
||||||
"assign_material_to_activity.activity_id", |
public function datatablesForReportActivity(Request $request){ |
||||||
"assign_material_to_activity.type" |
$id_activity = $request->query('idact'); |
||||||
// "assign_material_to_activity.material_id", |
$data = |
||||||
) |
AssignMaterial::select( |
||||||
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
AssignMaterial::raw('SUM(qty_planning) as qty_planning'), |
||||||
->groupBy("m.description") |
"m.description as material_name", |
||||||
->groupBy("assign_material_to_activity.activity_id") |
"assign_material_to_activity.activity_id", |
||||||
->groupBy("assign_material_to_activity.type") |
"assign_material_to_activity.type" |
||||||
->where("assign_material_to_activity.activity_id", $id_activity)->get(); |
// "assign_material_to_activity.material_id", |
||||||
return Datatables::of($data) |
) |
||||||
->addIndexColumn() |
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
||||||
->addColumn('qty_sum', function($row){ |
->groupBy("m.description") |
||||||
$val_qty_act = AssignMaterial::select(ReportActivityMaterial::raw('SUM(ram.qty) as qty_sum'),"m.description as material_name1") |
->groupBy("assign_material_to_activity.activity_id") |
||||||
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
->groupBy("assign_material_to_activity.type") |
||||||
->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id") |
->where("assign_material_to_activity.activity_id", $id_activity)->get(); |
||||||
->groupBy("m.description") |
return Datatables::of($data) |
||||||
->where("m.description", strval($row->material_name)) |
->addIndexColumn() |
||||||
->where("ram.activity_id", $row->activity_id)->first(); |
->addColumn('qty_sum', function($row){ |
||||||
return $val_qty_act ? $val_qty_act->qty_sum : '-'; |
$val_qty_act = AssignMaterial::select(ReportActivityMaterial::raw('SUM(ram.qty) as qty_sum'),"m.description as material_name1") |
||||||
}) |
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
||||||
->addColumn('status_activity', function($row){ |
->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id") |
||||||
$val_status = AssignMaterial::select("status_activity") |
->groupBy("m.description") |
||||||
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') |
->where("m.description", strval($row->material_name)) |
||||||
->where('m.description', '=', $row->material_name) |
->where("ram.activity_id", $row->activity_id)->first(); |
||||||
->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); |
return $val_qty_act ? $val_qty_act->qty_sum : '-'; |
||||||
return $val_status ? $val_status->status_activity : null; |
}) |
||||||
}) |
->addColumn('status_activity', function($row){ |
||||||
->addColumn('start_activity', function($row){ |
$val_status = AssignMaterial::select("status_activity") |
||||||
$val_start = AssignMaterial::select("start_activity") |
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') |
||||||
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') |
->where('m.description', '=', $row->material_name) |
||||||
->where('m.description', '=', $row->material_name) |
->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); |
||||||
->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); |
return $val_status ? $val_status->status_activity : null; |
||||||
return $val_start ? $val_start->start_activity : null; |
}) |
||||||
}) |
->addColumn('start_activity', function($row){ |
||||||
->addColumn('finish_activity', function($row){ |
$val_start = AssignMaterial::select("start_activity") |
||||||
$val_finish = AssignMaterial::select("finish_activity") |
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') |
||||||
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') |
->where('m.description', '=', $row->material_name) |
||||||
->where('m.description', '=', $row->material_name) |
->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); |
||||||
->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); |
return $val_start ? $val_start->start_activity : null; |
||||||
return $val_finish ? $val_finish->finish_activity : null; |
}) |
||||||
}) |
->addColumn('finish_activity', function($row){ |
||||||
->addColumn('uom', function($row){ |
$val_finish = AssignMaterial::select("finish_activity") |
||||||
$val_uom = RequestMaterial::select("uom") |
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') |
||||||
->where('description', '=', $row->material_name)->first(); |
->where('m.description', '=', $row->material_name) |
||||||
return $val_uom ? $val_uom->uom : null; |
->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); |
||||||
}) |
return $val_finish ? $val_finish->finish_activity : null; |
||||||
->addColumn('assign_material_id', function($row){ |
}) |
||||||
$assignMaterial =AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
->addColumn('uom', function($row){ |
||||||
->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first(); |
$val_uom = RequestMaterial::select("uom") |
||||||
return $assignMaterial ? $assignMaterial->id : null; |
->where('description', '=', $row->material_name)->first(); |
||||||
}) |
return $val_uom ? $val_uom->uom : null; |
||||||
->addColumn('action', function($row){ |
}) |
||||||
$dataPlan = AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
->addColumn('assign_material_id', function($row){ |
||||||
->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first(); |
$assignMaterial =AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
||||||
$actionBtn = '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="primary btn btn-primary btn-sm btn-lihat-plan" data-toggle="tooltip" title="Lihat Plan" data-placement="top"><i class="fa fa-align-justify"></i></a>'; |
->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first(); |
||||||
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="warning btn btn-warning btn-sm btn-lihat-actual" data-toggle="tooltip" title="Input Progress" data-placement="top"><i class="fa fa-edit" aria-hidden="true"></i></a>'; |
return $assignMaterial ? $assignMaterial->id : null; |
||||||
return $actionBtn; |
}) |
||||||
}) |
->addColumn('action', function($row){ |
||||||
->rawColumns(['action'])->make(true); |
$dataPlan = AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
||||||
} |
->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first(); |
||||||
|
$actionBtn = '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="primary btn btn-primary btn-sm btn-lihat-plan" data-toggle="tooltip" title="Lihat Plan" data-placement="top"><i class="fa fa-align-justify"></i></a>'; |
||||||
public function ForReportActivityByMaterial(Request $request){ |
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="warning btn btn-warning btn-sm btn-lihat-actual" data-toggle="tooltip" title="Input Progress" data-placement="top"><i class="fa fa-edit" aria-hidden="true"></i></a>'; |
||||||
$id_activity = $request->idact; |
return $actionBtn; |
||||||
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") |
}) |
||||||
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
->rawColumns(['action'])->make(true); |
||||||
->where('assign_material_to_activity.activity_id', $id_activity)->get(); |
} |
||||||
foreach ($data as $key) { |
|
||||||
$val_qty_sum = ReportActivityMaterial::where('assign_material_id', '=', $key->id)->sum("qty"); |
public function ForReportActivityByMaterial(Request $request){ |
||||||
} |
$id_activity = $request->idact; |
||||||
$countData = $data->count(); |
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") |
||||||
if($data){ |
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
->where('assign_material_to_activity.activity_id', $id_activity)->get(); |
||||||
}else{ |
foreach ($data as $key) { |
||||||
return response()->json(['status'=>'failed','message'=>'failed get Assign material, please try again later!','code'=>400], 400); |
$val_qty_sum = ReportActivityMaterial::where('assign_material_id', '=', $key->id)->sum("qty"); |
||||||
} |
} |
||||||
} |
$countData = $data->count(); |
||||||
} |
if($data){ |
||||||
|
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'failed get Assign material, please try again later!','code'=>400], 400); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
@ -1,171 +1,177 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Http\Controllers; |
namespace App\Http\Controllers; |
||||||
|
|
||||||
use Illuminate\Http\Request; |
use Illuminate\Http\Request; |
||||||
use App\Models\Broadcast; |
use App\Models\Broadcast; |
||||||
use App\Models\User; |
use App\Models\User; |
||||||
use App\Services\FCMService; |
use App\Services\FCMService; |
||||||
|
|
||||||
class BroadcastController extends Controller |
class BroadcastController extends Controller |
||||||
{ |
{ |
||||||
public function add(Request $request) |
public function add(Request $request) |
||||||
{ |
{ |
||||||
|
|
||||||
$data = $request->all(); |
$data = $request->all(); |
||||||
$data['status_send'] = true; |
$data['created_by'] = $this->currentName; |
||||||
$data['created_by'] = $this->currentName; |
if (isset($data['send_to_id'])) { |
||||||
if (isset($data['send_to_id'])) { |
$idArray = $data['send_to_id']; |
||||||
$idArray = $data['send_to_id']; |
if (is_array($data['send_to_id'])) { |
||||||
if (is_array($data['send_to_id'])) { |
$data['send_to_id'] = implode(", ", $idArray); |
||||||
$data['send_to_id'] = implode(", ", $idArray); |
} |
||||||
} |
} |
||||||
} |
$result = Broadcast::create($data); |
||||||
// dd($data); |
if($result){ |
||||||
$result = Broadcast::create($data); |
$data['status_send'] !== "registered" ? $this->sendNotification($data) : ''; |
||||||
if($result){ |
return response()->json(['status'=>'success','message'=>'add broadcast successfully!','code'=>200], 200); |
||||||
$this->sendNotification($data); |
}else{ |
||||||
return response()->json(['status'=>'success','message'=>'add broadcast successfully!','code'=>200], 200); |
return response()->json(['status'=>'failed','message'=>'add broadcast failed!','code'=>400], 400); |
||||||
}else{ |
} |
||||||
return response()->json(['status'=>'failed','message'=>'add broadcast failed!','code'=>400], 400); |
} |
||||||
} |
|
||||||
} |
public function edit($id){ |
||||||
|
if(!$id || (int) $id < 0 || $id==""){ |
||||||
public function edit($id){ |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
if(!$id || (int) $id < 0 || $id==""){ |
die(); |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
} |
||||||
die(); |
|
||||||
} |
$result = Broadcast::find($id); |
||||||
|
|
||||||
$result = Broadcast::find($id); |
if($result){ |
||||||
|
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||||
if($result){ |
}else{ |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
return response()->json(['status'=>'failed','message'=>'failed get data broadcast, please try again later!','code'=>400], 400); |
||||||
}else{ |
} |
||||||
return response()->json(['status'=>'failed','message'=>'failed get data broadcast, please try again later!','code'=>400], 400); |
} |
||||||
} |
|
||||||
} |
public function update(Request $request, $id) |
||||||
|
{ |
||||||
public function update(Request $request, $id) |
if(!$id || (int) $id < 0 || $id==""){ |
||||||
{ |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
if(!$id || (int) $id < 0 || $id==""){ |
} |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
|
||||||
} |
$data = Broadcast::find($id); |
||||||
|
|
||||||
$data = Broadcast::find($id); |
$status_send = $request->status_send; |
||||||
|
|
||||||
if($data){ |
if($status_send === 'resend' || $status_send === 'send' && !empty($data)) |
||||||
$result = $data->update($request->all()); |
{ |
||||||
}else{ |
$data['status_send'] = $status_send; |
||||||
return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); |
$this->sendNotification($data); |
||||||
die(); |
} |
||||||
} |
|
||||||
|
if($data){ |
||||||
|
$result = $data->update($request->all()); |
||||||
if($result){ |
}else{ |
||||||
return response()->json(['status'=>'success','message'=>'data broadcast successfully updated!','code'=>200], 200); |
return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); |
||||||
}else{ |
die(); |
||||||
return response()->json(['status'=>'failed','message'=>'data broadcast failed updated!','code'=>400], 400); |
} |
||||||
} |
|
||||||
} |
|
||||||
|
if($result){ |
||||||
public function delete($id) |
return response()->json(['status'=>'success','message'=>'data broadcast successfully updated!','code'=>200], 200); |
||||||
{ |
}else{ |
||||||
$data = Broadcast::find($id); |
return response()->json(['status'=>'failed','message'=>'data broadcast failed updated!','code'=>400], 400); |
||||||
|
} |
||||||
if($data){ |
} |
||||||
$delete = $data->delete(); |
|
||||||
}else{ |
public function delete($id) |
||||||
return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); |
{ |
||||||
die(); |
$data = Broadcast::find($id); |
||||||
} |
|
||||||
|
if($data){ |
||||||
|
$delete = $data->delete(); |
||||||
if($delete){ |
}else{ |
||||||
return response()->json(['status'=>'success','message'=>'data broadcast successfully deleted!','code'=>200], 200); |
return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400); |
||||||
}else{ |
die(); |
||||||
return response()->json(['status'=>'failed','message'=>'data broadcast failed deleted!','code'=>400], 400); |
} |
||||||
} |
|
||||||
} |
|
||||||
|
if($delete){ |
||||||
public function search(Request $request) |
return response()->json(['status'=>'success','message'=>'data broadcast successfully deleted!','code'=>200], 200); |
||||||
{ |
}else{ |
||||||
$payload = $request->all(); |
return response()->json(['status'=>'failed','message'=>'data broadcast failed deleted!','code'=>400], 400); |
||||||
$dataBuilder = $this->setUpPayload($payload, 'm_broadcast'); |
} |
||||||
$builder = $dataBuilder['builder']; |
} |
||||||
$countBuilder = $dataBuilder['count']; |
|
||||||
$dataGet = $builder->get(); |
public function search(Request $request) |
||||||
$totalRecord = $countBuilder->count(); |
{ |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
$payload = $request->all(); |
||||||
} |
$dataBuilder = $this->setUpPayload($payload, 'm_broadcast'); |
||||||
|
$builder = $dataBuilder['builder']; |
||||||
public function list() |
$countBuilder = $dataBuilder['count']; |
||||||
{ |
$dataGet = $builder->get(); |
||||||
$data = Broadcast::all(); |
$totalRecord = $countBuilder->count(); |
||||||
$countData = $data->count(); |
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
|
} |
||||||
if($data){ |
|
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
public function list() |
||||||
}else{ |
{ |
||||||
return response()->json(['status'=>'failed','message'=>'failed get list broadcast, please try again later!','code'=>400], 400); |
$data = Broadcast::all(); |
||||||
} |
$countData = $data->count(); |
||||||
} |
|
||||||
|
if($data){ |
||||||
public function sendNotification($data) |
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||||
{ |
}else{ |
||||||
// send_to_type (all, roles, user) |
return response()->json(['status'=>'failed','message'=>'failed get list broadcast, please try again later!','code'=>400], 400); |
||||||
if (isset($data['send_to_type'])) { |
} |
||||||
switch ($data['send_to_type']) { |
} |
||||||
case 'all': |
|
||||||
$users = User::whereNotNull('fcm_token')->get(); |
public function sendNotification($data) |
||||||
if (isset($users)) { |
{ |
||||||
foreach ($users as $user) { |
// send_to_type (all, roles, user) |
||||||
FCMService::send( |
if (isset($data['send_to_type'])) { |
||||||
$user->fcm_token, |
switch ($data['send_to_type']) { |
||||||
[ |
case 'all': |
||||||
'title' => $data['title_notif'], |
$users = User::whereNotNull('fcm_token')->get(); |
||||||
'body' => $data['message_notif'], |
if (isset($users)) { |
||||||
] |
foreach ($users as $user) { |
||||||
); |
FCMService::send( |
||||||
} |
$user->fcm_token, |
||||||
} |
[ |
||||||
break; |
'title' => $data['title_notif'], |
||||||
|
'body' => $data['message_notif'], |
||||||
case 'roles': |
] |
||||||
$users = User::where("role_id", $data['send_to_id'])->whereNotNull('fcm_token')->get(); |
); |
||||||
if (isset($users)) { |
} |
||||||
foreach ($users as $user) { |
} |
||||||
FCMService::send( |
break; |
||||||
$user->fcm_token, |
|
||||||
[ |
case 'roles': |
||||||
'title' => $data['title_notif'], |
$users = User::where("role_id", $data['send_to_id'])->whereNotNull('fcm_token')->get(); |
||||||
'body' => $data['message_notif'], |
if (isset($users)) { |
||||||
] |
foreach ($users as $user) { |
||||||
); |
FCMService::send( |
||||||
} |
$user->fcm_token, |
||||||
} |
[ |
||||||
break; |
'title' => $data['title_notif'], |
||||||
|
'body' => $data['message_notif'], |
||||||
case 'users': |
] |
||||||
$idArray = explode(", ", $data['send_to_id']); |
); |
||||||
foreach ($idArray as $key => $value) { |
} |
||||||
$user = User::where("id", $value)->whereNotNull('fcm_token')->first(); |
} |
||||||
if (isset($user)) { |
break; |
||||||
FCMService::send( |
|
||||||
$user->fcm_token, |
case 'users': |
||||||
[ |
$idArray = explode(", ", $data['send_to_id']); |
||||||
'title' => $data['title_notif'], |
foreach ($idArray as $key => $value) { |
||||||
'body' => $data['message_notif'], |
$user = User::where("id", $value)->whereNotNull('fcm_token')->first(); |
||||||
] |
if (isset($user)) { |
||||||
); |
FCMService::send( |
||||||
} |
$user->fcm_token, |
||||||
} |
[ |
||||||
break; |
'title' => $data['title_notif'], |
||||||
|
'body' => $data['message_notif'], |
||||||
default: |
] |
||||||
# code... |
); |
||||||
break; |
} |
||||||
} |
} |
||||||
} |
break; |
||||||
} |
|
||||||
} |
default: |
||||||
|
# code... |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
@ -1,99 +1,113 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Http\Controllers; |
namespace App\Http\Controllers; |
||||||
|
|
||||||
use Illuminate\Http\Request; |
use Illuminate\Http\Request; |
||||||
use App\Models\Divisi; |
use App\Models\Divisi; |
||||||
|
|
||||||
class DivisiController extends Controller |
class DivisiController extends Controller |
||||||
{ |
{ |
||||||
|
|
||||||
private function getAllChildren($divisi, $depth = 0, $array = []) { |
private function getAllChildren($divisi, $depth = 0, $array = []) { |
||||||
$divisi->depth = $depth; |
$divisi->depth = $depth; |
||||||
array_push($array, $divisi); |
array_push($array, $divisi); |
||||||
foreach($divisi->children as $child){ |
foreach($divisi->children as $child){ |
||||||
$array = $this->getAllChildren($child, $depth + 1, $array); |
$array = $this->getAllChildren($child, $depth + 1, $array); |
||||||
} |
} |
||||||
return $array; |
return $array; |
||||||
} |
} |
||||||
|
|
||||||
public function add(Request $request){ |
public function add(Request $request){ |
||||||
$this->validate($request, [ |
$this->validate($request, [ |
||||||
'name' => 'required', |
'name' => 'string|required|unique:m_divisi,name', |
||||||
'description' => 'string', |
'description' => 'nullable|string', |
||||||
'parent' => 'integer' |
'parent' => 'nullable|integer' |
||||||
]); |
]); |
||||||
|
|
||||||
$data = $request->all(); |
$data = $request->all(); |
||||||
$data['created_by'] = $this->currentName; |
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
$result = Divisi::create($data); |
$result = Divisi::create($data); |
||||||
|
|
||||||
if(!$result) |
if(!$result) |
||||||
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]); |
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]); |
||||||
|
|
||||||
return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]); |
return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]); |
||||||
} |
} |
||||||
|
|
||||||
public function update(Request $request, $id){ |
public function update(Request $request, $id){ |
||||||
if(empty($id) || !is_int((int)$id)) |
if(empty($id) || !is_int((int)$id)) |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
$data = Divisi::find($id); |
$this->validate($request, [ |
||||||
|
'name' => 'string|required', |
||||||
if(!$data) |
'description' => 'nullable|string', |
||||||
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); |
'parent' => 'nullable|integer' |
||||||
|
]); |
||||||
$result = $data->update($request->all()); |
$data = Divisi::find($id); |
||||||
|
|
||||||
if(!$result) |
$request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_divisi,name']) : ''; |
||||||
return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500); |
|
||||||
|
if(!$data) |
||||||
return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); |
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); |
||||||
} |
|
||||||
|
$result = $data->update($request->all()); |
||||||
public function delete($id) |
|
||||||
{ |
if(!$result) |
||||||
if(empty($id) || !is_int((int)$id)) |
return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500); |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
|
||||||
|
return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); |
||||||
$data = Divisi::find($id); |
} |
||||||
|
|
||||||
if(!$data) |
public function delete($id) |
||||||
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); |
{ |
||||||
|
if(empty($id) || !is_int((int)$id)) |
||||||
$delete = $data->delete(); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
if(!$delete) |
$data = Divisi::find($id); |
||||||
return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500); |
|
||||||
|
if(!$data) |
||||||
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); |
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); |
||||||
} |
|
||||||
|
$delete = $data->delete(); |
||||||
public function search() |
|
||||||
{ |
if(!$delete) |
||||||
return $this->list(); |
return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500); |
||||||
// cant use builder for this case |
|
||||||
} |
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); |
||||||
|
} |
||||||
public function list() |
|
||||||
{ |
public function search(Request $request) |
||||||
$parentMenus = Divisi::whereNull('parent')->with('children')->get(); |
{ |
||||||
$divisions = []; |
$payload = $request->all(); |
||||||
foreach($parentMenus as $menu){ |
$dataBuilder = $this->setUpPayload($payload, 'm_divisi'); |
||||||
$childs = $this->getAllChildren($menu); |
$builder = $dataBuilder['builder']; |
||||||
foreach($childs as $d){ |
$countBuilder = $dataBuilder['count']; |
||||||
$d->displayName = ' ' . $d->name; |
$dataGet = $builder->get(); |
||||||
for($i=0; $i < $d->depth; $i++){ |
$totalRecord = $countBuilder->count(); |
||||||
$d->displayName = '--' . $d->displayName ; |
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
} |
//return $this->list(); |
||||||
array_push($divisions, $d); |
// cant use builder for this case |
||||||
} |
} |
||||||
} |
|
||||||
$countData = count($divisions); |
public function list() |
||||||
if($countData == 0) |
{ |
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
$parentMenus = Divisi::with('children')->whereNull('parent')->get(); |
||||||
|
$divisions = []; |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200); |
foreach($parentMenus as $menu){ |
||||||
} |
$childs = $this->getAllChildren($menu); |
||||||
} |
foreach($childs as $d){ |
||||||
|
$d->displayName = ' ' . $d->name; |
||||||
|
for($i=0; $i < $d->depth; $i++){ |
||||||
|
$d->displayName = '--' . $d->displayName ; |
||||||
|
} |
||||||
|
array_push($divisions, $d); |
||||||
|
} |
||||||
|
} |
||||||
|
$countData = count($divisions); |
||||||
|
if($countData == 0) |
||||||
|
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||||
|
|
||||||
|
return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200); |
||||||
|
} |
||||||
|
} |
||||||
|
@ -1,151 +1,159 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Http\Controllers; |
namespace App\Http\Controllers; |
||||||
|
|
||||||
use Illuminate\Http\Request; |
use Illuminate\Http\Request; |
||||||
use App\Models\Menu; |
use App\Models\Menu; |
||||||
use App\Models\RoleMenu; |
use App\Models\RoleMenu; |
||||||
|
|
||||||
class MenuController extends Controller |
class MenuController extends Controller |
||||||
{ |
{ |
||||||
public function add(Request $request) |
public function add(Request $request) |
||||||
{ |
{ |
||||||
$this->validate($request, [ |
$this->validate($request, [ |
||||||
'icon' => 'required', |
'icon' => 'required', |
||||||
'name' => 'required', |
'name' => 'string|required|unique:m_menu,name', |
||||||
'url' => 'required', |
'url' => 'required|unique:m_menu,url', |
||||||
'sequence' => 'required', |
'sequence' => 'required|integer', |
||||||
]); |
]); |
||||||
|
|
||||||
$data = $request->all(); |
$data = $request->all(); |
||||||
|
|
||||||
$data['created_by'] = $this->currentName; |
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
$result = Menu::create($data); |
$result = Menu::create($data); |
||||||
|
|
||||||
if($result){ |
if($result){ |
||||||
return response()->json(['status'=>'success','message'=>'add data menu successfully!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'add data menu successfully!','code'=>200], 200); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'add data menu failed!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'add data menu failed!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function edit($id){ |
public function edit($id){ |
||||||
if(!$id || (int) $id < 0 || $id==""){ |
if(!$id || (int) $id < 0 || $id==""){ |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
die(); |
die(); |
||||||
} |
} |
||||||
|
|
||||||
$result = Menu::find($id); |
$result = Menu::find($id); |
||||||
|
|
||||||
if($result){ |
if($result){ |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'failed get data menu, please try again later!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'failed get data menu, please try again later!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function update(Request $request, $id) |
public function update(Request $request, $id) |
||||||
{ |
{ |
||||||
if(!$id || (int) $id < 0 || $id==""){ |
if(!$id || (int) $id < 0 || $id==""){ |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
} |
} |
||||||
|
$this->validate($request, [ |
||||||
$data = Menu::find($id); |
'icon' => 'required', |
||||||
|
'name' => 'string|required', |
||||||
if($data){ |
'url' => 'required', |
||||||
$result = $data->update($request->all()); |
'sequence' => 'required|integer', |
||||||
}else{ |
]); |
||||||
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); |
$data = Menu::find($id); |
||||||
die(); |
|
||||||
} |
$request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_menu,name']) : ''; |
||||||
|
$request->url !== $data['url'] ? $this->validate($request,['url'=>'unique:m_menu,url']) : ''; |
||||||
|
|
||||||
if($result){ |
if($data){ |
||||||
return response()->json(['status'=>'success','message'=>'data menu successfully updated!','code'=>200], 200); |
$result = $data->update($request->all()); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'data menu failed updated!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); |
||||||
} |
die(); |
||||||
} |
} |
||||||
|
|
||||||
public function delete($id) |
|
||||||
{ |
if($result){ |
||||||
$data = Menu::find($id); |
return response()->json(['status'=>'success','message'=>'data menu successfully updated!','code'=>200], 200); |
||||||
|
}else{ |
||||||
if($data){ |
return response()->json(['status'=>'failed','message'=>'data menu failed updated!','code'=>400], 400); |
||||||
$delete = $data->delete(); |
} |
||||||
}else{ |
} |
||||||
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); |
|
||||||
die(); |
public function delete($id) |
||||||
} |
{ |
||||||
|
$data = Menu::find($id); |
||||||
|
|
||||||
if($delete){ |
if($data){ |
||||||
return response()->json(['status'=>'success','message'=>'data menu successfully deleted!','code'=>200], 200); |
$delete = $data->delete(); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'data menu failed deleted!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); |
||||||
} |
die(); |
||||||
} |
} |
||||||
|
|
||||||
public function search(Request $request) |
|
||||||
{ |
if($delete){ |
||||||
$payload = $request->all(); |
return response()->json(['status'=>'success','message'=>'data menu successfully deleted!','code'=>200], 200); |
||||||
$dataBuilder = $this->setUpPayload($payload, 'm_menu'); |
}else{ |
||||||
$builder = $dataBuilder['builder']; |
return response()->json(['status'=>'failed','message'=>'data menu failed deleted!','code'=>400], 400); |
||||||
$countBuilder = $dataBuilder['count']; |
} |
||||||
$dataGet = $builder->get(); |
} |
||||||
$totalRecord = $countBuilder->count(); |
|
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
public function search(Request $request) |
||||||
} |
{ |
||||||
|
$payload = $request->all(); |
||||||
public function listMenu($id) |
$dataBuilder = $this->setUpPayload($payload, 'm_menu'); |
||||||
{ |
$builder = $dataBuilder['builder']; |
||||||
$dataParent = RoleMenu::select("m_menu.*") |
$countBuilder = $dataBuilder['count']; |
||||||
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') |
$dataGet = $builder->get(); |
||||||
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') |
$totalRecord = $countBuilder->count(); |
||||||
->whereNull('m_menu.parent_id') |
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
->where('m_roles.id', $id) |
} |
||||||
->orderBy('m_menu.sequence', 'ASC') |
|
||||||
->get(); |
public function listMenu($id) |
||||||
|
{ |
||||||
$finalData = []; |
$dataParent = RoleMenu::select("m_menu.*") |
||||||
foreach($dataParent as $data){ |
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') |
||||||
$data->children = $this->getChildrenMenu($data->id, $id); |
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') |
||||||
$finalData[] = $data; |
->whereNull('m_menu.parent_id') |
||||||
} |
->where('m_roles.id', $id) |
||||||
|
->orderBy('m_menu.sequence', 'ASC') |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$finalData], 200); |
->get(); |
||||||
} |
|
||||||
|
$finalData = []; |
||||||
protected function getChildrenMenu($id, $role_id) |
foreach($dataParent as $data){ |
||||||
{ |
$data->children = $this->getChildrenMenu($data->id, $id); |
||||||
$dataChildren = RoleMenu::select("m_menu.*") |
$finalData[] = $data; |
||||||
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') |
} |
||||||
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') |
|
||||||
->where('m_roles.id', $role_id) |
return response()->json(['status'=>'success','code'=>200,'data'=>$finalData], 200); |
||||||
->where('m_menu.parent_id', $id) |
} |
||||||
->orderBy('m_menu.sequence', 'ASC') |
|
||||||
->get(); |
protected function getChildrenMenu($id, $role_id) |
||||||
$children = []; |
{ |
||||||
if($dataChildren){ |
$dataChildren = RoleMenu::select("m_menu.*") |
||||||
foreach($dataChildren as $data) |
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') |
||||||
{ |
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') |
||||||
$data->children = $this->getChildrenMenu($data->id, $role_id); |
->where('m_roles.id', $role_id) |
||||||
$children[] = $data; |
->where('m_menu.parent_id', $id) |
||||||
} |
->orderBy('m_menu.sequence', 'ASC') |
||||||
} |
->get(); |
||||||
return $children; |
$children = []; |
||||||
} |
if($dataChildren){ |
||||||
|
foreach($dataChildren as $data) |
||||||
public function list() |
{ |
||||||
{ |
$data->children = $this->getChildrenMenu($data->id, $role_id); |
||||||
$data = Menu::all(); |
$children[] = $data; |
||||||
$countData = $data->count(); |
} |
||||||
|
} |
||||||
if($data){ |
return $children; |
||||||
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); |
public function list() |
||||||
} |
{ |
||||||
} |
$data = Menu::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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,136 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Http\Controllers; |
||||||
|
|
||||||
|
use Illuminate\Http\Request; |
||||||
|
use App\Models\ProjectChecklists; |
||||||
|
|
||||||
|
class ProjectChecklistsController extends Controller |
||||||
|
{ |
||||||
|
public function add(Request $request) |
||||||
|
{ |
||||||
|
if ($request->status_exist==="") { |
||||||
|
$request->merge(['status_exist' => true]); |
||||||
|
} |
||||||
|
|
||||||
|
$this->validate($request, [ |
||||||
|
'proyek_id' => 'required', |
||||||
|
'item' => 'required|string', |
||||||
|
'status_exist' => 'boolean' |
||||||
|
]); |
||||||
|
|
||||||
|
$data = $request->all(); |
||||||
|
|
||||||
|
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
|
$result = ProjectChecklists::create($data); |
||||||
|
|
||||||
|
if($result){ |
||||||
|
return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'add data project participants 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 = ProjectChecklists::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 participants, 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 = ProjectChecklists::find($id); |
||||||
|
|
||||||
|
if($data){ |
||||||
|
$result = $data->update($request->all()); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); |
||||||
|
die(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if($result){ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function delete($id) |
||||||
|
{ |
||||||
|
$data = ProjectChecklists::find($id); |
||||||
|
|
||||||
|
if($data){ |
||||||
|
$delete = $data->delete(); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); |
||||||
|
die(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if($delete){ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function deleteByProyek($id) |
||||||
|
{ |
||||||
|
$data = ProjectChecklists::where('proyek_id', $id)->delete(); |
||||||
|
|
||||||
|
if($data){ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function customWhere($where, $val) |
||||||
|
{ |
||||||
|
$data = ProjectChecklists::where($where, $val)->orderBy('id', 'asc')->get(); |
||||||
|
|
||||||
|
if($data){ |
||||||
|
return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function search(Request $request) |
||||||
|
{ |
||||||
|
$payload = $request->all(); |
||||||
|
$dataBuilder = $this->setUpPayload($payload, 'project_charter_checklist'); |
||||||
|
$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 = ProjectChecklists::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 project participants, please try again later!','code'=>400], 400); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,136 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Http\Controllers; |
||||||
|
|
||||||
|
use Illuminate\Http\Request; |
||||||
|
use App\Models\ProjectIssues; |
||||||
|
|
||||||
|
class ProjectIssuesController extends Controller |
||||||
|
{ |
||||||
|
public function add(Request $request) |
||||||
|
{ |
||||||
|
if ($request->level_issue === "") { |
||||||
|
$request->merge(['level_issue' => 0]); |
||||||
|
} |
||||||
|
|
||||||
|
$this->validate($request, [ |
||||||
|
'proyek_id' => 'required', |
||||||
|
'description' => 'required|string', |
||||||
|
'level_issue' => 'required|integer' |
||||||
|
]); |
||||||
|
|
||||||
|
$data = $request->all(); |
||||||
|
|
||||||
|
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
|
$result = ProjectIssues::create($data); |
||||||
|
|
||||||
|
if($result){ |
||||||
|
return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'add data project participants 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 = ProjectIssues::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 participants, 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 = ProjectIssues::find($id); |
||||||
|
|
||||||
|
if($data){ |
||||||
|
$result = $data->update($request->all()); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); |
||||||
|
die(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if($result){ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function delete($id) |
||||||
|
{ |
||||||
|
$data = ProjectIssues::find($id); |
||||||
|
|
||||||
|
if($data){ |
||||||
|
$delete = $data->delete(); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); |
||||||
|
die(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if($delete){ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function deleteByProyek($id) |
||||||
|
{ |
||||||
|
$data = ProjectIssues::where('proyek_id', $id)->delete(); |
||||||
|
|
||||||
|
if($data){ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function customWhere($where, $val) |
||||||
|
{ |
||||||
|
$data = ProjectIssues::where($where, $val)->orderBy('id', 'asc')->get(); |
||||||
|
|
||||||
|
if($data){ |
||||||
|
return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function search(Request $request) |
||||||
|
{ |
||||||
|
$payload = $request->all(); |
||||||
|
$dataBuilder = $this->setUpPayload($payload, 'project_charter_issue'); |
||||||
|
$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 = ProjectIssues::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 project participants, please try again later!','code'=>400], 400); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,137 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Http\Controllers; |
||||||
|
|
||||||
|
use Illuminate\Http\Request; |
||||||
|
use App\Models\ProjectRisks; |
||||||
|
|
||||||
|
class ProjectRisksController extends Controller |
||||||
|
{ |
||||||
|
public function add(Request $request) |
||||||
|
{ |
||||||
|
if ($request->level_risk === "") { |
||||||
|
$request->merge(['level_risk' => 0]); |
||||||
|
} |
||||||
|
|
||||||
|
$this->validate($request, [ |
||||||
|
'proyek_id' => 'required', |
||||||
|
'level_risk' => 'required|integer', |
||||||
|
'description' => 'required|string', |
||||||
|
'preventive_risk' => 'required|string' |
||||||
|
]); |
||||||
|
|
||||||
|
$data = $request->all(); |
||||||
|
|
||||||
|
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
|
$result = ProjectRisks::create($data); |
||||||
|
|
||||||
|
if($result){ |
||||||
|
return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'add data project participants 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 = ProjectRisks::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 participants, 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 = ProjectRisks::find($id); |
||||||
|
|
||||||
|
if($data){ |
||||||
|
$result = $data->update($request->all()); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); |
||||||
|
die(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if($result){ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function delete($id) |
||||||
|
{ |
||||||
|
$data = ProjectRisks::find($id); |
||||||
|
|
||||||
|
if($data){ |
||||||
|
$delete = $data->delete(); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400); |
||||||
|
die(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if($delete){ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function deleteByProyek($id) |
||||||
|
{ |
||||||
|
$data = ProjectRisks::where('proyek_id', $id)->delete(); |
||||||
|
|
||||||
|
if($data){ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function customWhere($where, $val) |
||||||
|
{ |
||||||
|
$data = ProjectRisks::where($where, $val)->orderBy('id', 'asc')->get(); |
||||||
|
|
||||||
|
if($data){ |
||||||
|
return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function search(Request $request) |
||||||
|
{ |
||||||
|
$payload = $request->all(); |
||||||
|
$dataBuilder = $this->setUpPayload($payload, 'project_charter_risk'); |
||||||
|
$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 = ProjectRisks::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 project participants, please try again later!','code'=>400], 400); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,101 +1,106 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Http\Controllers; |
namespace App\Http\Controllers; |
||||||
|
|
||||||
use Illuminate\Http\Request; |
use Illuminate\Http\Request; |
||||||
use App\Models\Role; |
use App\Models\Role; |
||||||
|
|
||||||
class RoleController extends Controller |
class RoleController extends Controller |
||||||
{ |
{ |
||||||
|
|
||||||
public function add(Request $request) |
public function add(Request $request) |
||||||
{ |
{ |
||||||
$this->validate($request, [ |
$this->validate($request, [ |
||||||
'name' => 'required', |
'name' => 'string|required|unique:m_roles,name', |
||||||
'description' => 'required' |
'description' => 'required' |
||||||
]); |
]); |
||||||
|
|
||||||
$data = $request->all(); |
$data = $request->all(); |
||||||
|
|
||||||
$data['created_by'] = $this->currentName; |
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
$result = Role::create($data); |
$result = Role::create($data); |
||||||
|
|
||||||
if(!$result) |
if(!$result) |
||||||
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=>500], 500); |
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=>500], 500); |
||||||
|
|
||||||
return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); |
||||||
} |
} |
||||||
|
|
||||||
public function edit( $id){ |
public function edit( $id){ |
||||||
if(empty($id) || !is_int((int)$id)) |
if(empty($id) || !is_int((int)$id)) |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
$result = Role::find($id); |
$result = Role::find($id); |
||||||
|
|
||||||
if(!$result) |
if(!$result) |
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); |
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); |
||||||
|
|
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||||
} |
} |
||||||
|
|
||||||
public function update(Request $request, $id) |
public function update(Request $request, $id) |
||||||
{ |
{ |
||||||
if(empty($id) || !is_int((int)$id)) |
if(empty($id) || !is_int((int)$id)) |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
$data = Role::find($id); |
$this->validate($request, [ |
||||||
|
'name' => 'string|required', |
||||||
if(!$data) |
'description' => 'required' |
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); |
]); |
||||||
|
$data = Role::find($id); |
||||||
$result = $data->update($request->all()); |
$request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_roles,name']) : ''; |
||||||
|
|
||||||
if(!$result) |
if(!$data) |
||||||
return response()->json(['status'=>'failed','message'=>'Failed to update the data!','code'=>500], 500); |
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); |
||||||
|
|
||||||
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200); |
$result = $data->update($request->all()); |
||||||
} |
|
||||||
|
if(!$result) |
||||||
public function delete($id) |
return response()->json(['status'=>'failed','message'=>'Failed to update the data!','code'=>500], 500); |
||||||
{ |
|
||||||
if(empty($id) || !is_int((int)$id)) |
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200); |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
} |
||||||
|
|
||||||
$data = Role::find($id); |
public function delete($id) |
||||||
|
{ |
||||||
if(!$data) |
if(empty($id) || !is_int((int)$id)) |
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
$delete = $data->delete(); |
$data = Role::find($id); |
||||||
|
|
||||||
if(!$delete) |
if(!$data) |
||||||
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=>500], 500); |
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404); |
||||||
|
|
||||||
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); |
$delete = $data->delete(); |
||||||
} |
|
||||||
|
if(!$delete) |
||||||
public function search(Request $request) |
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=>500], 500); |
||||||
{ |
|
||||||
$payload = $request->all(); |
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); |
||||||
|
} |
||||||
$dataBuilder = $this->setUpPayload($payload, 'm_roles'); |
|
||||||
$builder = $dataBuilder['builder']; |
public function search(Request $request) |
||||||
$countBuilder = $dataBuilder['count']; |
{ |
||||||
$dataGet = $builder->get(); |
$payload = $request->all(); |
||||||
$totalRecord = $countBuilder->count(); |
|
||||||
|
$dataBuilder = $this->setUpPayload($payload, 'm_roles'); |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
$builder = $dataBuilder['builder']; |
||||||
} |
$countBuilder = $dataBuilder['count']; |
||||||
|
$dataGet = $builder->get(); |
||||||
public function list() |
$totalRecord = $countBuilder->count(); |
||||||
{ |
|
||||||
$data = Role::all(); |
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
$countData = $data->count(); |
} |
||||||
|
|
||||||
if(!$data) |
public function list() |
||||||
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400); |
{ |
||||||
|
$data = Role::all(); |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
$countData = $data->count(); |
||||||
} |
|
||||||
} |
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); |
||||||
|
} |
||||||
|
} |
||||||
|
@ -1,102 +1,102 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Http\Controllers; |
namespace App\Http\Controllers; |
||||||
|
|
||||||
use Illuminate\Http\Request; |
use Illuminate\Http\Request; |
||||||
use App\Models\Menu; |
use App\Models\Menu; |
||||||
use App\Models\RoleMenu; |
use App\Models\RoleMenu; |
||||||
|
|
||||||
class RoleMenuController extends Controller |
class RoleMenuController extends Controller |
||||||
{ |
{ |
||||||
public function add(Request $request) |
public function add(Request $request) |
||||||
{ |
{ |
||||||
$this->validate($request, [ |
$this->validate($request, [ |
||||||
'role_id' => 'required', |
'role_id' => 'required', |
||||||
'menu_id' => 'required', |
'menu_id' => 'required', |
||||||
]); |
]); |
||||||
|
|
||||||
$data = $request->all(); |
$data = $request->all(); |
||||||
|
|
||||||
$data['created_by'] = $this->currentName; |
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
$result = RoleMenu::create($data); |
$result = RoleMenu::create($data); |
||||||
|
|
||||||
if($result){ |
if($result){ |
||||||
return response()->json(['status'=>'success','message'=>'add data role menu successfully!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'add data role menu successfully!','code'=>200], 200); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'add data role menu failed!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'add data role menu failed!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function update(Request $request, $id) |
public function update(Request $request, $id) |
||||||
{ |
{ |
||||||
if(!$id || (int) $id < 0 || $id==""){ |
if(!$id || (int) $id < 0 || $id==""){ |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
} |
} |
||||||
|
|
||||||
$data = RoleMenu::find($id); |
$data = RoleMenu::find($id); |
||||||
|
|
||||||
if($data){ |
if($data){ |
||||||
$result = $data->update($request->all()); |
$result = $data->update($request->all()); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); |
||||||
die(); |
die(); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
if($result){ |
if($result){ |
||||||
return response()->json(['status'=>'success','message'=>'data role menu successfully updated!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'data role menu successfully updated!','code'=>200], 200); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'data role menu failed updated!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'data role menu failed updated!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function delete($id) |
public function delete($id) |
||||||
{ |
{ |
||||||
$data = RoleMenu::find($id); |
$data = RoleMenu::find($id); |
||||||
|
|
||||||
if($data){ |
if($data){ |
||||||
$delete = $data->delete(); |
$delete = $data->delete(); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); |
||||||
die(); |
die(); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
if($delete){ |
if($delete){ |
||||||
return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function deleteByRole($id) |
public function deleteByRole($id) |
||||||
{ |
{ |
||||||
$data = RoleMenu::where("role_id", $id); |
$data = RoleMenu::where("role_id", $id); |
||||||
|
|
||||||
if($data){ |
if($data){ |
||||||
$delete = $data->delete(); |
$delete = $data->delete(); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); |
||||||
die(); |
die(); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
if($delete){ |
if($delete){ |
||||||
return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function search(Request $request) |
public function search(Request $request) |
||||||
{ |
{ |
||||||
$payload = $request->all(); |
$payload = $request->all(); |
||||||
$dataBuilder = $this->setUpPayload($payload, 't_roles_menu'); |
$dataBuilder = $this->setUpPayload($payload, 't_roles_menu'); |
||||||
$builder = $dataBuilder['builder']; |
$builder = $dataBuilder['builder']; |
||||||
$countBuilder = $dataBuilder['count']; |
$countBuilder = $dataBuilder['count']; |
||||||
$dataGet = $builder->get(); |
$dataGet = $builder->get(); |
||||||
$totalRecord = $countBuilder->count(); |
$totalRecord = $countBuilder->count(); |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,199 +1,220 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Http\Controllers; |
namespace App\Http\Controllers; |
||||||
|
|
||||||
use Illuminate\Http\Request; |
use Illuminate\Http\Request; |
||||||
use App\Models\UserToActivity; |
use App\Models\UserToActivity; |
||||||
use App\Models\Activity; |
use App\Models\Activity; |
||||||
use Datatables; |
use Datatables; |
||||||
|
|
||||||
class UserToActivityController extends Controller |
class UserToActivityController extends Controller |
||||||
{ |
{ |
||||||
public function add(Request $request){ |
public function add(Request $request){ |
||||||
$this->validate($request, [ |
$this->validate($request, [ |
||||||
'activity_id' => 'required', |
'activity_id' => 'required', |
||||||
'user_id' => 'required' |
'user_id' => 'required' |
||||||
]); |
]); |
||||||
|
|
||||||
$data = $request->all(); |
$data = $request->all(); |
||||||
$data['created_by'] = $this->currentName; |
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
if(!UserToActivity::create($data)) |
if(!UserToActivity::create($data)) |
||||||
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]); |
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]); |
||||||
|
|
||||||
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=> 200]); |
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=> 200]); |
||||||
} |
} |
||||||
|
|
||||||
public function addMultiple(Request $request){ |
public function addMultiple(Request $request){ |
||||||
$users_id = $request->user_id; |
$users_id = $request->user_id; |
||||||
$users_role = $request->role_proyek_id; |
$users_role = $request->role_proyek_id; |
||||||
|
|
||||||
// $data = UserToActivity::where("activity_id", $request->activity_id); |
// $data = UserToActivity::where("activity_id", $request->activity_id); |
||||||
// if($data){ |
// if($data){ |
||||||
// $data->delete(); |
// $data->delete(); |
||||||
// } |
// } |
||||||
|
|
||||||
if(is_array($users_id) && count($users_id) > 0){ |
if(is_array($users_id) && count($users_id) > 0){ |
||||||
$countRes = 0; |
$countRes = 0; |
||||||
foreach($users_id as $index => $item){ |
foreach($users_id as $index => $item){ |
||||||
$dataInsert = array( |
$dataInsert = array( |
||||||
"user_id" => $item, |
"user_id" => $item, |
||||||
"activity_id" => $request->activity_id, |
"activity_id" => $request->activity_id, |
||||||
"role_proyek_id" => $users_role[$index], |
"role_proyek_id" => $users_role[$index], |
||||||
"proyek_id" => $request->proyek_id, |
"proyek_id" => $request->proyek_id, |
||||||
"created_by" => $this->currentName, |
"created_by" => $this->currentName, |
||||||
"version_gantt_id" => $request->version_gantt_id |
"version_gantt_id" => $request->version_gantt_id |
||||||
); |
); |
||||||
$result = UserToActivity::create($dataInsert); |
$result = UserToActivity::create($dataInsert); |
||||||
if($result){ |
if($result){ |
||||||
$countRes++; |
$countRes++; |
||||||
}else{ |
}else{ |
||||||
$countRes--; |
$countRes--; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
if($countRes == 0) |
if($countRes == 0) |
||||||
return response()->json(['status'=>'failed' ,'message'=>'Failed to add data!','code'=> 500]); |
return response()->json(['status'=>'failed' ,'message'=>'Failed to add data!','code'=> 500]); |
||||||
|
|
||||||
$allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id); |
$allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id); |
||||||
$dataUpdateCost = array( |
$dataUpdateCost = array( |
||||||
"rencana_biaya"=>$allCost, |
"rencana_biaya"=>$allCost, |
||||||
"updated_by"=> $this->currentName |
"updated_by"=> $this->currentName |
||||||
); |
); |
||||||
$actUpdate = Activity::find($request->activity_id); |
$actUpdate = Activity::find($request->activity_id); |
||||||
if($actUpdate){ |
if($actUpdate){ |
||||||
$actUpdate->update($dataUpdateCost); |
$actUpdate->update($dataUpdateCost); |
||||||
if($actUpdate->parent_id){ |
if($actUpdate->parent_id){ |
||||||
$this->updatedCostPlanning($actUpdate->parent_id); |
$this->updatedCostPlanning($actUpdate->parent_id); |
||||||
} |
} |
||||||
} |
} |
||||||
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]); |
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]); |
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]); |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
private function updatedCostPlanning($parent_id) { |
private function updatedCostPlanning($parent_id) { |
||||||
$sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))') |
$sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))') |
||||||
->where("parent_id", $parent_id) |
->where("parent_id", $parent_id) |
||||||
->first(); |
->first(); |
||||||
if($parent = Activity::find($parent_id)){ |
if($parent = Activity::find($parent_id)){ |
||||||
$parent->update([ |
$parent->update([ |
||||||
"rencana_biaya" => $sumBiaya->sum, |
"rencana_biaya" => $sumBiaya->sum, |
||||||
]); |
]); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function update(Request $request, $id){ |
public function update(Request $request, $id){ |
||||||
if(empty($id) || !is_int((int)$id)) |
if(empty($id) || !is_int((int)$id)) |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
$data = UserToActivity::find($id); |
$data = UserToActivity::find($id); |
||||||
if(!$data) |
if(!$data) |
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||||
|
|
||||||
if(!$data->update($request->all())); |
if(!$data->update($request->all())); |
||||||
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500); |
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500); |
||||||
|
|
||||||
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200); |
||||||
} |
} |
||||||
|
|
||||||
public function delete($id) |
public function delete($id) |
||||||
{ |
{ |
||||||
$data = UserToActivity::find($id); |
$data = UserToActivity::find($id); |
||||||
if(!$data) |
if(!$data) |
||||||
return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400); |
||||||
|
|
||||||
if($data->delete()){ |
if($data->delete()){ |
||||||
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); |
||||||
} |
} |
||||||
|
|
||||||
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); |
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); |
||||||
} |
} |
||||||
|
|
||||||
public function edit($id){ |
public function edit($id){ |
||||||
if(!$id || (int) $id < 0 || $id==""){ |
if(!$id || (int) $id < 0 || $id==""){ |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
die(); |
die(); |
||||||
} |
} |
||||||
|
|
||||||
$result = UserToActivity::find($id); |
$result = UserToActivity::find($id); |
||||||
|
|
||||||
if(!$result) |
if(!$result) |
||||||
return response()->json(['status'=>'failed','message'=>'failed get data tools resource, please try again later!','code'=>400], 400); |
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); |
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||||
} |
} |
||||||
|
|
||||||
public function search(Request $request) |
public function search(Request $request) |
||||||
{ |
{ |
||||||
$payload = $request->all(); |
$payload = $request->all(); |
||||||
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_activity'); |
if (isset($payload['join_column'])) { |
||||||
$builder = $dataBuilder['builder']; |
$join_column = $payload['join_column']; |
||||||
$countBuilder = $dataBuilder['count']; |
unset($payload['join_column']); |
||||||
$dataGet = $builder->get(); |
} |
||||||
$totalRecord = $countBuilder->count(); |
|
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_activity'); |
||||||
} |
$builder = $dataBuilder['builder']; |
||||||
|
$countBuilder = $dataBuilder['count']; |
||||||
public function list() |
if (isset($join_column)) { |
||||||
{ |
$startDate = $join_column['start_date']; |
||||||
$data = UserToActivity::all(); |
$endDate = $join_column['end_date']; |
||||||
$countData = $data->count(); |
$startDate = date("Y-m-d H:i:sO", strtotime($startDate)); |
||||||
|
$endDate = date("Y-m-d H:i:sO", strtotime($endDate)); |
||||||
if($data){ |
$builder->where(function ($query) use ($startDate, $endDate) { |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
$query |
||||||
}else{ |
->where('m_proyek.mulai_proyek', '>=', $startDate) |
||||||
return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); |
->where('m_proyek.akhir_proyek', '<=', $endDate) |
||||||
} |
->where(function ($query) use ($endDate, $startDate) { |
||||||
} |
$query |
||||||
|
->where('m_activity.start_date', '>=', $startDate) |
||||||
public function listFiltered(Request $request) |
->where('m_activity.end_date', '<=', $endDate); |
||||||
{ |
}); |
||||||
$startDate = $request->start_date; |
}); |
||||||
$endDate = $request->end_date; |
} |
||||||
$userId = $request->user_id; |
$dataGet = $builder->get(); |
||||||
$proyekId = $request->proyek_id; |
$totalRecord = $countBuilder->count(); |
||||||
|
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
if (isset($proyekId)) { |
} |
||||||
$data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date') |
|
||||||
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id') |
public function list() |
||||||
->where('m_activity.start_date', '=', $startDate) |
{ |
||||||
->where('m_activity.end_date', '=', $endDate) |
$data = UserToActivity::all(); |
||||||
->where('assign_hr_to_activity.user_id', '=', $userId) |
$countData = $data->count(); |
||||||
->where('assign_hr_to_activity.proyek_id', '=', $proyekId) |
|
||||||
->get(); |
if($data){ |
||||||
}else { |
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||||
$data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date') |
}else{ |
||||||
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id') |
return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); |
||||||
->where('m_activity.start_date', '=', $startDate) |
} |
||||||
->where('m_activity.end_date', '=', $endDate) |
} |
||||||
->where('assign_hr_to_activity.user_id', '=', $userId) |
|
||||||
->get(); |
public function listFiltered(Request $request) |
||||||
} |
{ |
||||||
$countData = $data->count(); |
$startDate = $request->start_date; |
||||||
|
$endDate = $request->end_date; |
||||||
if($data){ |
$userId = $request->user_id; |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
$proyekId = $request->proyek_id; |
||||||
}else{ |
|
||||||
return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); |
if (isset($proyekId)) { |
||||||
} |
$data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date') |
||||||
} |
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id') |
||||||
|
->where('m_activity.start_date', '=', $startDate) |
||||||
public function datatables(Request $request){ |
->where('m_activity.end_date', '=', $endDate) |
||||||
$id_activity = $request->query('idact'); |
->where('assign_hr_to_activity.user_id', '=', $userId) |
||||||
$data = UserToActivity::select("assign_hr_to_activity.id as id", "u.name as user_name", "mrp.name as role_name") |
->where('assign_hr_to_activity.proyek_id', '=', $proyekId) |
||||||
->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id") |
->get(); |
||||||
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") |
}else { |
||||||
->where('assign_hr_to_activity.activity_id', $id_activity) |
$data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date') |
||||||
->get(); |
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id') |
||||||
return Datatables::of($data) |
->where('m_activity.start_date', '=', $startDate) |
||||||
->addIndexColumn() |
->where('m_activity.end_date', '=', $endDate) |
||||||
->addColumn('action', function($row){ |
->where('assign_hr_to_activity.user_id', '=', $userId) |
||||||
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-hr-delete"><i class="fa fa-trash"></i></a>'; |
->get(); |
||||||
return $actionBtn; |
} |
||||||
}) |
$countData = $data->count(); |
||||||
->rawColumns(['action'])->make(true); |
|
||||||
} |
if($data){ |
||||||
} |
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||||
|
}else{ |
||||||
|
return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function datatables(Request $request){ |
||||||
|
$id_activity = $request->query('idact'); |
||||||
|
$data = UserToActivity::select("assign_hr_to_activity.id as id", "u.name as user_name", "mrp.name as role_name") |
||||||
|
->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id") |
||||||
|
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") |
||||||
|
->where('assign_hr_to_activity.activity_id', $id_activity) |
||||||
|
->get(); |
||||||
|
return Datatables::of($data) |
||||||
|
->addIndexColumn() |
||||||
|
->addColumn('action', function($row){ |
||||||
|
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-hr-delete"><i class="fa fa-trash"></i></a>'; |
||||||
|
return $actionBtn; |
||||||
|
}) |
||||||
|
->rawColumns(['action'])->make(true); |
||||||
|
} |
||||||
|
} |
||||||
|
@ -1,214 +1,253 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Http\Controllers; |
namespace App\Http\Controllers; |
||||||
|
|
||||||
use Illuminate\Http\Request; |
use Illuminate\Http\Request; |
||||||
use App\Models\UserToProyek; |
use App\Models\UserToProyek; |
||||||
use App\Models\UserToActivity; |
use App\Models\UserToActivity; |
||||||
use App\Models\ReportActivity; |
use App\Models\ReportActivity; |
||||||
use App\Models\Image; |
use App\Models\Image; |
||||||
|
|
||||||
class UserToProyekController extends Controller |
class UserToProyekController extends Controller |
||||||
{ |
{ |
||||||
public function add(Request $request) |
public function add(Request $request) |
||||||
{ |
{ |
||||||
$this->validate($request, [ |
$this->validate($request, [ |
||||||
'user_id' => 'required', |
'user_id' => 'required', |
||||||
'proyek_id' => 'required' |
'proyek_id' => 'required' |
||||||
]); |
]); |
||||||
|
|
||||||
$data = $request->all(); |
$data = $request->all(); |
||||||
|
|
||||||
$data['created_by'] = $this->currentName; |
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
$result = UserToProyek::create($data); |
$result = UserToProyek::create($data); |
||||||
|
|
||||||
if($result){ |
if($result){ |
||||||
return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200); |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'assign hr to proyek failed!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'assign hr to proyek failed!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function edit($id){ |
public function addMultiple(Request $request){ |
||||||
if(!$id || (int) $id < 0 || $id==""){ |
$user_IDs = $request->user_id; |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
|
||||||
die(); |
$data = UserToProyek::where("proyek_id", $request->proyek_id); |
||||||
} |
|
||||||
|
if($data){ |
||||||
$result = UserToProyek::find($id); |
$data->delete(); |
||||||
|
} |
||||||
if($result){ |
|
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
if(is_array($user_IDs) && count($user_IDs) > 0){ |
||||||
}else{ |
$countRes = 0; |
||||||
return response()->json(['status'=>'failed','message'=>'failed get data assign hr to proyek, please try again later!','code'=>400], 400); |
foreach($user_IDs as $item){ |
||||||
} |
|
||||||
} |
$dataInsert = array( |
||||||
|
"user_id" => $item, |
||||||
public function update(Request $request, $id) |
"proyek_id" => $request->proyek_id, |
||||||
{ |
"created_by" => $this->currentName, |
||||||
if(!$id || (int) $id < 0 || $id==""){ |
'is_customer'=>true |
||||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
); |
||||||
} |
|
||||||
|
$result = UserToProyek::create($dataInsert); |
||||||
$data = UserToProyek::find($id); |
|
||||||
|
if($result){ |
||||||
if($data){ |
$countRes++; |
||||||
$result = $data->update($request->all()); |
}else{ |
||||||
}else{ |
$countRes--; |
||||||
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); |
} |
||||||
die(); |
} |
||||||
} |
if($countRes > 0){ |
||||||
|
return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]); |
||||||
|
}else{ |
||||||
if($result){ |
return response()->json(['status'=>'success' ,'message'=>'Project customer failed created','code'=>400]); |
||||||
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200); |
} |
||||||
}else{ |
}else{ |
||||||
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400); |
return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]); |
||||||
} |
} |
||||||
} |
|
||||||
|
} |
||||||
public function delete($id) |
|
||||||
{ |
public function edit($id){ |
||||||
$data = UserToProyek::find($id); |
if(!$id || (int) $id < 0 || $id==""){ |
||||||
if($data){ |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
$userId = $data->user_id; |
die(); |
||||||
$proyekId = $data->proyek_id; |
} |
||||||
$delete = $data->delete(); |
|
||||||
if($delete){ |
$result = UserToProyek::find($id); |
||||||
$this->deleteRelative($proyekId, $userId); |
|
||||||
} |
if($result){ |
||||||
}else{ |
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||||
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); |
}else{ |
||||||
die(); |
return response()->json(['status'=>'failed','message'=>'failed get data assign hr to proyek, please try again later!','code'=>400], 400); |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
if($delete){ |
public function update(Request $request, $id) |
||||||
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200); |
{ |
||||||
}else{ |
if(!$id || (int) $id < 0 || $id==""){ |
||||||
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
|
||||||
|
$data = UserToProyek::find($id); |
||||||
private function deleteRelative($proyekId, $userId) |
|
||||||
{ |
if($data){ |
||||||
$uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get(); |
$result = $data->update($request->all()); |
||||||
foreach ($uta as $value) { |
}else{ |
||||||
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get(); |
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); |
||||||
foreach ($dataRa as $ra) { |
die(); |
||||||
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); |
} |
||||||
foreach ($images as $image) { |
|
||||||
if(file_exists($this->pathImage.$image->image)){ |
|
||||||
unlink($this->pathImage.$image->image); |
if($result){ |
||||||
} |
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200); |
||||||
} |
}else{ |
||||||
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); |
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400); |
||||||
} |
} |
||||||
ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->delete(); |
} |
||||||
} |
|
||||||
UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->delete(); |
public function delete($id) |
||||||
} |
{ |
||||||
|
$data = UserToProyek::find($id); |
||||||
public function search(Request $request) |
if($data){ |
||||||
{ |
$userId = $data->user_id; |
||||||
$payload = $request->all(); |
$proyekId = $data->proyek_id; |
||||||
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_proyek'); |
$delete = $data->delete(); |
||||||
$builder = $dataBuilder['builder']; |
if($delete){ |
||||||
$countBuilder = $dataBuilder['count']; |
$this->deleteRelative($proyekId, $userId); |
||||||
$dataGet = $builder->get(); |
} |
||||||
$totalRecord = $countBuilder->count(); |
}else{ |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400); |
||||||
} |
die(); |
||||||
|
} |
||||||
public function list() |
|
||||||
{ |
|
||||||
$data = UserToProyek::all(); |
if($delete){ |
||||||
$countData = $data->count(); |
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200); |
||||||
|
}else{ |
||||||
if($data){ |
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400); |
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
} |
||||||
}else{ |
} |
||||||
return response()->json(['status'=>'failed','message'=>'failed get list assign hr to proyek, please try again later!','code'=>400], 400); |
|
||||||
} |
private function deleteRelative($proyekId, $userId) |
||||||
} |
{ |
||||||
|
$uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get(); |
||||||
public function select(Request $request){ |
foreach ($uta as $value) { |
||||||
|
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get(); |
||||||
$search = $request->query('search'); |
foreach ($dataRa as $ra) { |
||||||
|
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); |
||||||
$idProyek = (int)$request->query('idProyek'); |
foreach ($images as $image) { |
||||||
$idActivity = (int)$request->query('idact'); |
if(file_exists($this->pathImage.$image->image)){ |
||||||
|
unlink($this->pathImage.$image->image); |
||||||
$include = []; |
} |
||||||
|
} |
||||||
if($idActivity && $idActivity > 0){ |
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); |
||||||
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get(); |
} |
||||||
foreach($dataF as $val){ |
ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->delete(); |
||||||
$include[] = $val->user_id; |
} |
||||||
} |
UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->delete(); |
||||||
} |
} |
||||||
|
|
||||||
if($search && !empty($search)){ |
public function search(Request $request) |
||||||
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') |
{ |
||||||
->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%'.$search.'%')->whereIn("m_users.id", $include)->get(); |
$payload = $request->all(); |
||||||
}else{ |
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_proyek'); |
||||||
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereIn("m_users.id", $include)->get(); |
$builder = $dataBuilder['builder']; |
||||||
} |
$countBuilder = $dataBuilder['count']; |
||||||
|
$dataGet = $builder->get(); |
||||||
if($data instanceof \Illuminate\Database\Eloquent\Collection){ |
$totalRecord = $countBuilder->count(); |
||||||
$pm = array( |
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
"id"=>$this->currentId, |
} |
||||||
"name"=> "Project Manager" |
|
||||||
); |
public function list() |
||||||
$data->push($pm); |
{ |
||||||
} |
$data = UserToProyek::all(); |
||||||
|
$countData = $data->count(); |
||||||
return response()->json($data); |
|
||||||
} |
if($data){ |
||||||
|
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||||
private function curlReq($url, $token){ |
}else{ |
||||||
$ch = curl_init(); |
return response()->json(['status'=>'failed','message'=>'failed get list assign hr to proyek, please try again later!','code'=>400], 400); |
||||||
$headers = [ |
} |
||||||
'Authorization: '.$token |
} |
||||||
]; |
|
||||||
curl_setopt($ch, CURLOPT_URL, $url); |
public function select(Request $request){ |
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
$search = $request->query('search'); |
||||||
|
|
||||||
$response = curl_exec($ch); |
$idProyek = (int)$request->query('idProyek'); |
||||||
if ($response === false) |
$idActivity = (int)$request->query('idact'); |
||||||
$response = curl_error($ch); |
|
||||||
curl_close($ch); |
$include = []; |
||||||
|
|
||||||
return json_decode($response); |
if($idActivity && $idActivity > 0){ |
||||||
} |
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get(); |
||||||
|
foreach($dataF as $val){ |
||||||
public function getEmployeeIntegration(Request $request) { |
$include[] = $val->user_id; |
||||||
$search = urlencode($request->name); |
} |
||||||
if(empty($search)) |
} |
||||||
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); |
|
||||||
$url = str_replace("SEARCH", $search, config('api.adw').'/employees?emp_name=SEARCH'); |
if($search && !empty($search)){ |
||||||
$token = config('api.adw_token'); |
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') |
||||||
$firstResponse = $this->curlReq($url, $token); |
->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%'.$search.'%')->whereIn("m_users.id", $include)->get(); |
||||||
|
}else{ |
||||||
if($firstResponse->total == 0) |
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereIn("m_users.id", $include)->get(); |
||||||
return response()->json(['status'=>'error', 'message' => 'Data not found!', 'code'=>404], 404); |
} |
||||||
|
|
||||||
$data = $firstResponse->data; |
if($data instanceof \Illuminate\Database\Eloquent\Collection){ |
||||||
return response()->json([$data]); |
$pm = array( |
||||||
$currentPage = 1; |
"id"=>$this->currentId, |
||||||
|
"name"=> "Project Manager" |
||||||
if($firstResponse->last_page > 0) { |
); |
||||||
do { |
$data->push($pm); |
||||||
$currentPage++; |
} |
||||||
$response = $this->curlReq($url.'&page='.$currentPage, $token); |
|
||||||
foreach($response->data as $d){ |
return response()->json($data); |
||||||
array_push($data, $d); |
} |
||||||
} |
|
||||||
} while ($currentPage < $firstResponse->last_page); |
private function curlReq($url, $token){ |
||||||
} |
$ch = curl_init(); |
||||||
|
$headers = [ |
||||||
return response()->json(['status'=>'success', 'data'=> $data, 'total' => count($data), 'code'=>200], 200); |
'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); |
||||||
|
|
||||||
|
return json_decode($response); |
||||||
|
} |
||||||
|
|
||||||
|
public function getEmployeeIntegration(Request $request) { |
||||||
|
$search = urlencode($request->name); |
||||||
|
if(empty($search)) |
||||||
|
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); |
||||||
|
$url = str_replace("SEARCH", $search, config('api.adw').'/employees?emp_name=SEARCH'); |
||||||
|
$token = config('api.adw_token'); |
||||||
|
$firstResponse = $this->curlReq($url, $token); |
||||||
|
|
||||||
|
if($firstResponse->total == 0) |
||||||
|
return response()->json(['status'=>'error', 'message' => 'Data not found!', 'code'=>404], 404); |
||||||
|
|
||||||
|
$data = $firstResponse->data; |
||||||
|
return response()->json([$data]); |
||||||
|
$currentPage = 1; |
||||||
|
|
||||||
|
if($firstResponse->last_page > 0) { |
||||||
|
do { |
||||||
|
$currentPage++; |
||||||
|
$response = $this->curlReq($url.'&page='.$currentPage, $token); |
||||||
|
foreach($response->data as $d){ |
||||||
|
array_push($data, $d); |
||||||
|
} |
||||||
|
} while ($currentPage < $firstResponse->last_page); |
||||||
|
} |
||||||
|
|
||||||
|
return response()->json(['status'=>'success', 'data'=> $data, 'total' => count($data), 'code'=>200], 200); |
||||||
|
} |
||||||
|
} |
||||||
|
@ -1,246 +1,246 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Models; |
namespace App\Models; |
||||||
|
|
||||||
use App\Models\AssignMaterial; |
use App\Models\AssignMaterial; |
||||||
use App\Models\ActivityProgressLog; |
use App\Models\ActivityProgressLog; |
||||||
use App\Models\AssignTools; |
use App\Models\AssignTools; |
||||||
use App\Models\ReportActivityMaterial; |
use App\Models\ReportActivityMaterial; |
||||||
use Illuminate\Database\Eloquent\Model; |
use Illuminate\Database\Eloquent\Model; |
||||||
use Illuminate\Support\Arr; |
use Illuminate\Support\Arr; |
||||||
use Illuminate\Support\Facades\DB; |
use Illuminate\Support\Facades\DB; |
||||||
use Carbon\Carbon; |
use Carbon\Carbon; |
||||||
|
|
||||||
class Activity extends Model |
class Activity extends Model |
||||||
{ |
{ |
||||||
protected $table = 'm_activity'; |
protected $table = 'm_activity'; |
||||||
|
|
||||||
const CREATED_AT = 'created_at'; |
const CREATED_AT = 'created_at'; |
||||||
const UPDATED_AT = 'updated_at'; |
const UPDATED_AT = 'updated_at'; |
||||||
|
|
||||||
// persentase bobot gak kepake yg dipakenya bobot_planning |
// persentase bobot gak kepake yg dipakenya bobot_planning |
||||||
protected $fillable = [ |
protected $fillable = [ |
||||||
'proyek_id', 'parent_id', 'kode_sortname', 'name', 'rencana_biaya', 'start_date', |
'proyek_id', 'parent_id', 'kode_sortname', 'name', 'rencana_biaya', 'start_date', |
||||||
'end_date', 'area_kerja', 'biaya_actual', 'persentase_bobot', 'persentase_progress', |
'end_date', 'area_kerja', 'biaya_actual', 'persentase_bobot', 'persentase_progress', |
||||||
'buffer_radius', 'duration', 'color_progress', 'jumlah_pekerjaan', 'satuan', |
'buffer_radius', 'duration', 'color_progress', 'jumlah_pekerjaan', 'satuan', |
||||||
'description', 'priority', 'bobot_planning', 'type_activity', 'open', 'geom', |
'description', 'priority', 'bobot_planning', 'type_activity', 'open', 'geom', |
||||||
'version_gantt_id', 'budget_plan', 'biaya_material_plan', 'biaya_human_plan', 'biaya_tools_plan', |
'version_gantt_id', 'budget_plan', 'biaya_material_plan', 'biaya_human_plan', 'biaya_tools_plan', |
||||||
'planned_start', 'planned_end', 'satuan_id', 'actual_start', 'actual_end', |
'planned_start', 'planned_end', 'satuan_id', 'actual_start', 'actual_end', |
||||||
'created_at', 'created_by', 'updated_at', 'updated_by', 'sortorder' |
'created_at', 'created_by', 'updated_at', 'updated_by', 'sortorder' |
||||||
]; |
]; |
||||||
|
|
||||||
protected $appends = [ |
protected $appends = [ |
||||||
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools', 'assign_expense' |
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools', 'assign_expense' |
||||||
]; |
]; |
||||||
|
|
||||||
|
|
||||||
public function getStartDateAttribute($value) |
public function getStartDateAttribute($value) |
||||||
{ |
{ |
||||||
if ($value instanceof \DateTime) { |
if ($value instanceof \DateTime) { |
||||||
return Carbon::instance($value) |
return Carbon::instance($value) |
||||||
->timezone(env('APP_TIMEZONE')) |
->timezone(env('APP_TIMEZONE')) |
||||||
->toDateTimeString(); |
->toDateTimeString(); |
||||||
} |
} |
||||||
return Carbon::createFromTimestamp(strtotime($value)) |
return Carbon::createFromTimestamp(strtotime($value)) |
||||||
->timezone(env('APP_TIMEZONE')) |
->timezone(env('APP_TIMEZONE')) |
||||||
->toDateTimeString(); |
->toDateTimeString(); |
||||||
} |
} |
||||||
|
|
||||||
public function getEndDateAttribute($value) |
public function getEndDateAttribute($value) |
||||||
{ |
{ |
||||||
if ($value instanceof \DateTime) { |
if ($value instanceof \DateTime) { |
||||||
return Carbon::instance($value) |
return Carbon::instance($value) |
||||||
->timezone(env('APP_TIMEZONE')) |
->timezone(env('APP_TIMEZONE')) |
||||||
->toDateTimeString(); |
->toDateTimeString(); |
||||||
} |
} |
||||||
return Carbon::createFromTimestamp(strtotime($value)) |
return Carbon::createFromTimestamp(strtotime($value)) |
||||||
->timezone(env('APP_TIMEZONE')) |
->timezone(env('APP_TIMEZONE')) |
||||||
->toDateTimeString(); |
->toDateTimeString(); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
public static function boot() { |
public static function boot() { |
||||||
parent::boot(); |
parent::boot(); |
||||||
|
|
||||||
static::updating(function($data) { |
static::updating(function($data) { |
||||||
$data->logPersentaseProgress(); |
$data->logPersentaseProgress(); |
||||||
}); |
}); |
||||||
|
|
||||||
static::updated(function($data) { |
static::updated(function($data) { |
||||||
$data->updateBobot(); |
$data->updateBobot(); |
||||||
$data->updateCostPlanning(); |
$data->updateCostPlanning(); |
||||||
if($data->bobot_planning){ |
if($data->bobot_planning){ |
||||||
$data->updatePersentaseProgress(); |
$data->updatePersentaseProgress(); |
||||||
} |
} |
||||||
$data->updateCostActual(); |
$data->updateCostActual(); |
||||||
// if($data->start_date != request()->start_date || $data->end_date != request()->end_date) { |
// if($data->start_date != request()->start_date || $data->end_date != request()->end_date) { |
||||||
// $data->updateStartEndDateHeader(); |
// $data->updateStartEndDateHeader(); |
||||||
// } |
// } |
||||||
}); |
}); |
||||||
|
|
||||||
static::deleted(function($data) { |
static::deleted(function($data) { |
||||||
if(Activity::where("parent_id", $data->parent_id)->count() == 0) |
if(Activity::where("parent_id", $data->parent_id)->count() == 0) |
||||||
Activity::find($data->parent_id)->update(["type_activity"=>"task"]); |
Activity::find($data->parent_id)->update(["type_activity"=>"task"]); |
||||||
|
|
||||||
$data->updateBobot(true); |
$data->updateBobot(true); |
||||||
$data->updateCostPlanning(); |
$data->updateCostPlanning(); |
||||||
if($data->bobot_planning){ |
if($data->bobot_planning){ |
||||||
$data->updatePersentaseProgress(); |
$data->updatePersentaseProgress(); |
||||||
} |
} |
||||||
$data->updateCostActual(); |
$data->updateCostActual(); |
||||||
$data->updateStartEndDateHeader(); |
$data->updateStartEndDateHeader(); |
||||||
}); |
}); |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
private function updateBobot($isDelete = false) |
private function updateBobot($isDelete = false) |
||||||
{ |
{ |
||||||
$root = Activity::where('version_gantt_id', $this->version_gantt_id) |
$root = Activity::where('version_gantt_id', $this->version_gantt_id) |
||||||
->where("proyek_id", $this->proyek_id) |
->where("proyek_id", $this->proyek_id) |
||||||
->whereNull('parent_id') |
->whereNull('parent_id') |
||||||
->first(); |
->first(); |
||||||
|
|
||||||
if($root->rencana_biaya > 0){ |
if($root->rencana_biaya > 0){ |
||||||
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get(); |
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get(); |
||||||
foreach ($activities as $activity) { |
foreach ($activities as $activity) { |
||||||
if($isDelete && $activity->id == $this->id) |
if($isDelete && $activity->id == $this->id) |
||||||
continue; |
continue; |
||||||
|
|
||||||
$activity->bobot_planning = ( (int)$activity->rencana_biaya / $root->rencana_biaya) * 100; |
$activity->bobot_planning = ( (int)$activity->rencana_biaya / $root->rencana_biaya) * 100; |
||||||
$activity->updated_by = auth()->user() ? auth()->user()->name : "system"; |
$activity->updated_by = auth()->user() ? auth()->user()->name : "system"; |
||||||
$activity->saveQuietly(); |
$activity->saveQuietly(); |
||||||
|
|
||||||
} |
} |
||||||
} else { |
} else { |
||||||
if($parent = Activity::find($this->parent_id)){ |
if($parent = Activity::find($this->parent_id)){ |
||||||
$totalChildWeight = Activity::where("parent_id", $this->parent_id)->sum('bobot_planning'); |
$totalChildWeight = Activity::where("parent_id", $this->parent_id)->sum('bobot_planning'); |
||||||
$parent->update([ |
$parent->update([ |
||||||
"bobot_planning" => $totalChildWeight |
"bobot_planning" => $totalChildWeight |
||||||
]); |
]); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
private function updateCostActual() |
private function updateCostActual() |
||||||
{ |
{ |
||||||
$actualCost = Activity::where("parent_id", $this->parent_id)->sum("biaya_actual"); |
$actualCost = Activity::where("parent_id", $this->parent_id)->sum("biaya_actual"); |
||||||
$this->biaya_actual = $actualCost; |
$this->biaya_actual = $actualCost; |
||||||
if($parent = Activity::find($this->parent_id)){ |
if($parent = Activity::find($this->parent_id)){ |
||||||
$parent->update([ |
$parent->update([ |
||||||
"biaya_actual" => $actualCost |
"biaya_actual" => $actualCost |
||||||
]); |
]); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
private function updatePersentaseProgress() |
private function updatePersentaseProgress() |
||||||
{ |
{ |
||||||
if($parent = Activity::find($this->parent_id)){ |
if($parent = Activity::find($this->parent_id)){ |
||||||
$parentActWeight = $parent->bobot_planning; |
$parentActWeight = $parent->bobot_planning; |
||||||
|
|
||||||
if ($parentActWeight == 0) { |
if ($parentActWeight == 0) { |
||||||
$parent->update([ |
$parent->update([ |
||||||
"persentase_progress" => 0 |
"persentase_progress" => 0 |
||||||
]); |
]); |
||||||
return; |
return; |
||||||
} |
} |
||||||
|
|
||||||
$totalChildProportionalProgress = 0; |
$totalChildProportionalProgress = 0; |
||||||
$childs = Activity::where("parent_id", $parent->id)->get(); |
$childs = Activity::where("parent_id", $parent->id)->get(); |
||||||
foreach($childs as $child){ |
foreach($childs as $child){ |
||||||
$currentActWeight = $child->bobot_planning; |
$currentActWeight = $child->bobot_planning; |
||||||
$currentActProportionalProgress = ($currentActWeight / $parentActWeight) * $child->persentase_progress; |
$currentActProportionalProgress = ($currentActWeight / $parentActWeight) * $child->persentase_progress; |
||||||
$totalChildProportionalProgress += $currentActProportionalProgress; |
$totalChildProportionalProgress += $currentActProportionalProgress; |
||||||
} |
} |
||||||
$parent->update([ |
$parent->update([ |
||||||
"persentase_progress" => $totalChildProportionalProgress |
"persentase_progress" => $totalChildProportionalProgress |
||||||
]); |
]); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
private function updateCostPlanning() { |
private function updateCostPlanning() { |
||||||
$sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) |
$sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) |
||||||
->where("parent_id", $this->parent_id) |
->where("parent_id", $this->parent_id) |
||||||
->first(); |
->first(); |
||||||
$this->rencana_biaya = $sumBiaya->sum; |
$this->rencana_biaya = $sumBiaya->sum; |
||||||
if($parent = Activity::find($this->parent_id)){ |
if($parent = Activity::find($this->parent_id)){ |
||||||
$parent->update([ |
$parent->update([ |
||||||
"rencana_biaya" => $sumBiaya->sum, |
"rencana_biaya" => $sumBiaya->sum, |
||||||
]); |
]); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
private function logPersentaseProgress() |
private function logPersentaseProgress() |
||||||
{ |
{ |
||||||
ActivityProgressLog::create([ |
ActivityProgressLog::create([ |
||||||
'version_gantt_id' => $this->version_gantt_id, |
'version_gantt_id' => $this->version_gantt_id, |
||||||
'activity_id' => request()->id, |
'activity_id' => request()->id, |
||||||
'old_percentage' => $this->persentase_progress, |
'old_percentage' => $this->persentase_progress, |
||||||
'new_percentage' => request()->persentase_progress, |
'new_percentage' => request()->persentase_progress, |
||||||
'variance' => $this->persentase_progress - request()->persentase_progress, |
'variance' => $this->persentase_progress - request()->persentase_progress, |
||||||
'created_by'=> "system" |
'created_by'=> "system" |
||||||
]); |
]); |
||||||
} |
} |
||||||
|
|
||||||
private function updateStartEndDateHeader() |
private function updateStartEndDateHeader() |
||||||
{ |
{ |
||||||
$earliestStartDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->oldest('start_date')->pluck('start_date')->first(); |
$earliestStartDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->oldest('start_date')->pluck('start_date')->first(); |
||||||
$latestEndDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->latest('end_date')->pluck('end_date')->first(); |
$latestEndDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->latest('end_date')->pluck('end_date')->first(); |
||||||
if($header = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNull('parent_id')->first()) { |
if($header = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNull('parent_id')->first()) { |
||||||
$header->start_date = $earliestStartDate; |
$header->start_date = $earliestStartDate; |
||||||
$header->end_date = $latestEndDate; |
$header->end_date = $latestEndDate; |
||||||
$header->saveQuietly(); |
$header->saveQuietly(); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function getJobsDoneAttribute() |
public function getJobsDoneAttribute() |
||||||
{ |
{ |
||||||
if(!ReportActivityMaterial::where('activity_id', $this->id)->first()) |
if(!ReportActivityMaterial::where('activity_id', $this->id)->first()) |
||||||
return 0; |
return 0; |
||||||
if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get()) |
if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get()) |
||||||
return 0; |
return 0; |
||||||
if($dataPlan->isEmpty()) |
if($dataPlan->isEmpty()) |
||||||
return 0; |
return 0; |
||||||
if($dataPlan[0]->status_activity == 'done') |
if($dataPlan[0]->status_activity == 'done') |
||||||
return 100; |
return 100; |
||||||
return $this->persentase_progress; |
return $this->persentase_progress; |
||||||
} |
} |
||||||
|
|
||||||
public function getAssignHrAttribute() |
public function getAssignHrAttribute() |
||||||
{ |
{ |
||||||
return Arr::flatten(UserToActivity::select("u.name as name") |
return Arr::flatten(UserToActivity::select("u.name as name") |
||||||
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") |
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") |
||||||
->where('assign_hr_to_activity.activity_id', $this->id) |
->where('assign_hr_to_activity.activity_id', $this->id) |
||||||
->get() |
->get() |
||||||
->toArray()); |
->toArray()); |
||||||
} |
} |
||||||
|
|
||||||
public function getAssignMaterialAttribute() |
public function getAssignMaterialAttribute() |
||||||
{ |
{ |
||||||
return Arr::flatten(AssignMaterial::select("m.description as name") |
return Arr::flatten(AssignMaterial::select("m.description as name") |
||||||
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
||||||
->where('assign_material_to_activity.activity_id', $this->id) |
->where('assign_material_to_activity.activity_id', $this->id) |
||||||
->where('assign_material_to_activity.type', "material") |
->where('assign_material_to_activity.type', "material") |
||||||
->get() |
->get() |
||||||
->toArray()); |
->toArray()); |
||||||
} |
} |
||||||
|
|
||||||
public function getAssignExpenseAttribute() |
public function getAssignExpenseAttribute() |
||||||
{ |
{ |
||||||
return Arr::flatten(AssignMaterial::select("m.description as name") |
return Arr::flatten(AssignMaterial::select("m.description as name") |
||||||
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") |
||||||
->where('assign_material_to_activity.activity_id', $this->id) |
->where('assign_material_to_activity.activity_id', $this->id) |
||||||
->where('assign_material_to_activity.type', "expense") |
->where('assign_material_to_activity.type', "expense") |
||||||
->get() |
->get() |
||||||
->toArray()); |
->toArray()); |
||||||
} |
} |
||||||
|
|
||||||
public function getAssignToolsAttribute() |
public function getAssignToolsAttribute() |
||||||
{ |
{ |
||||||
return Arr::flatten(AssignTools::select("m.name as name") |
return Arr::flatten(AssignTools::select("m.name as name") |
||||||
->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id") |
->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id") |
||||||
->where('assign_tools_to_activity.activity_id', $this->id) |
->where('assign_tools_to_activity.activity_id', $this->id) |
||||||
->get() |
->get() |
||||||
->toArray()); |
->toArray()); |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
@ -1,46 +1,46 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Models; |
namespace App\Models; |
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model; |
use Illuminate\Database\Eloquent\Model; |
||||||
use App\Models\RequestMaterial; |
use App\Models\RequestMaterial; |
||||||
use App\Models\Activity; |
use App\Models\Activity; |
||||||
use App\Models\ReportActivityMaterial; |
use App\Models\ReportActivityMaterial; |
||||||
|
|
||||||
class AssignMaterial extends Model |
class AssignMaterial extends Model |
||||||
{ |
{ |
||||||
protected $table = 'assign_material_to_activity'; |
protected $table = 'assign_material_to_activity'; |
||||||
|
|
||||||
const CREATED_AT = 'created_at'; |
const CREATED_AT = 'created_at'; |
||||||
const UPDATED_AT = 'updated_at'; |
const UPDATED_AT = 'updated_at'; |
||||||
|
|
||||||
protected $fillable = [ |
protected $fillable = [ |
||||||
'proyek_id', 'activity_id', 'material_id', 'qty_planning', |
'proyek_id', 'activity_id', 'material_id', 'qty_planning', |
||||||
'budget', 'plan_date', 'status_activity', 'type', |
'budget', 'plan_date', 'status_activity', 'type', |
||||||
'created_at', 'created_by', 'updated_at', 'updated_by' |
'created_at', 'created_by', 'updated_at', 'updated_by' |
||||||
]; |
]; |
||||||
|
|
||||||
protected $casts = [ |
protected $casts = [ |
||||||
'id' => 'integer', |
'id' => 'integer', |
||||||
'budget' => 'string', |
'budget' => 'string', |
||||||
]; |
]; |
||||||
|
|
||||||
public static function boot() { |
public static function boot() { |
||||||
parent::boot(); |
parent::boot(); |
||||||
|
|
||||||
static::created(function($data) { |
static::created(function($data) { |
||||||
$activity = Activity::find($data->activity_id); |
$activity = Activity::find($data->activity_id); |
||||||
$material = RequestMaterial::where("id", $data->material_id)->first(); |
$material = RequestMaterial::where("id", $data->material_id)->first(); |
||||||
$activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning); |
$activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning); |
||||||
$activity->save(); |
$activity->save(); |
||||||
}); |
}); |
||||||
|
|
||||||
static::deleted(function($data) { |
static::deleted(function($data) { |
||||||
$reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete(); |
$reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete(); |
||||||
$activity = Activity::where('id', $data->activity_id)->first(); |
$activity = Activity::where('id', $data->activity_id)->first(); |
||||||
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); |
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); |
||||||
$activity->save(); |
$activity->save(); |
||||||
}); |
}); |
||||||
|
|
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -1,54 +1,54 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Models; |
namespace App\Models; |
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model; |
use Illuminate\Database\Eloquent\Model; |
||||||
|
|
||||||
class Project extends Model |
class Project extends Model |
||||||
{ |
{ |
||||||
protected $table = 'm_proyek'; |
protected $table = 'm_proyek'; |
||||||
|
|
||||||
const CREATED_AT = 'created_at'; |
const CREATED_AT = 'created_at'; |
||||||
const UPDATED_AT = 'updated_at'; |
const UPDATED_AT = 'updated_at'; |
||||||
|
|
||||||
protected $fillable = [ |
protected $fillable = [ |
||||||
'kode_sortname', |
'kode_sortname', |
||||||
'jumlah_stakeholder', |
'jumlah_stakeholder', |
||||||
'nama', |
'nama', |
||||||
'mulai_proyek', |
'mulai_proyek', |
||||||
'akhir_proyek', |
'akhir_proyek', |
||||||
'area_kerja', |
'area_kerja', |
||||||
'lokasi_kantor', |
'lokasi_kantor', |
||||||
'rencana_biaya', |
'rencana_biaya', |
||||||
'biaya_actual', |
'biaya_actual', |
||||||
'company', |
'company', |
||||||
'pm_id', |
'pm_id', |
||||||
'type_proyek_id', |
'type_proyek_id', |
||||||
'divisi_id', |
'divisi_id', |
||||||
'persentase_progress', |
'persentase_progress', |
||||||
'keterangan', |
'keterangan', |
||||||
'durasi_proyek', |
'durasi_proyek', |
||||||
'progress_by_worklog', |
'progress_by_worklog', |
||||||
'status', |
'status', |
||||||
'currency_simbol', |
'currency_symbol', |
||||||
'currency_code', |
'currency_code', |
||||||
'currency_name', |
'currency_name', |
||||||
'project_objectives', |
'project_objectives', |
||||||
'considered_success_when', |
'considered_success_when', |
||||||
'potential_risk', |
'potential_risk', |
||||||
'testing_environment', |
'testing_environment', |
||||||
'currency_code', |
'budget_health', |
||||||
'currency_symbol', |
'phase_id', |
||||||
'currency_name', |
'late_consequence', |
||||||
'budget_health', |
'assumtion', |
||||||
'phase_id', |
'calculation_status', |
||||||
'calculation_status', |
'structur_organization', |
||||||
'scurve', |
'scurve', |
||||||
'created_at', |
'created_at', |
||||||
'created_by', |
'created_by', |
||||||
'updated_at', |
'updated_at', |
||||||
'updated_by' |
'updated_by' |
||||||
]; |
]; |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
@ -0,0 +1,23 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Models; |
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model; |
||||||
|
|
||||||
|
class ProjectChecklists extends Model |
||||||
|
{ |
||||||
|
protected $table = 'project_charter_checklist'; |
||||||
|
|
||||||
|
const CREATED_AT = 'created_at'; |
||||||
|
const UPDATED_AT = 'updated_at'; |
||||||
|
|
||||||
|
protected $fillable = [ |
||||||
|
'proyek_id', |
||||||
|
'item', |
||||||
|
'status_exist', |
||||||
|
'created_at', |
||||||
|
'created_by', |
||||||
|
'updated_at', |
||||||
|
'updated_by' |
||||||
|
]; |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Models; |
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model; |
||||||
|
|
||||||
|
class ProjectIssues extends Model |
||||||
|
{ |
||||||
|
protected $table = 'project_charter_issue'; |
||||||
|
|
||||||
|
const CREATED_AT = 'created_at'; |
||||||
|
const UPDATED_AT = 'updated_at'; |
||||||
|
|
||||||
|
protected $fillable = [ |
||||||
|
'proyek_id', |
||||||
|
'description', |
||||||
|
'level_issue', |
||||||
|
'created_at', |
||||||
|
'created_by', |
||||||
|
'updated_at', |
||||||
|
'updated_by' |
||||||
|
]; |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Models; |
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model; |
||||||
|
|
||||||
|
class ProjectRisks extends Model |
||||||
|
{ |
||||||
|
protected $table = 'project_charter_risk'; |
||||||
|
|
||||||
|
const CREATED_AT = 'created_at'; |
||||||
|
const UPDATED_AT = 'updated_at'; |
||||||
|
|
||||||
|
protected $fillable = [ |
||||||
|
'proyek_id', |
||||||
|
'description', |
||||||
|
'level_risk', |
||||||
|
'preventive_risk', |
||||||
|
'created_at', |
||||||
|
'created_by', |
||||||
|
'updated_at', |
||||||
|
'updated_by' |
||||||
|
]; |
||||||
|
} |
@ -1,73 +1,73 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Models; |
namespace App\Models; |
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model; |
use Illuminate\Database\Eloquent\Model; |
||||||
use App\Models\Activity; |
use App\Models\Activity; |
||||||
use App\Models\AssignMaterial; |
use App\Models\AssignMaterial; |
||||||
use Carbon\Carbon; |
use Carbon\Carbon; |
||||||
|
|
||||||
class ReportActivityMaterial extends Model |
class ReportActivityMaterial extends Model |
||||||
{ |
{ |
||||||
protected $table = 'report_activity_material'; |
protected $table = 'report_activity_material'; |
||||||
|
|
||||||
const CREATED_AT = 'created_at'; |
const CREATED_AT = 'created_at'; |
||||||
const UPDATED_AT = 'updated_at'; |
const UPDATED_AT = 'updated_at'; |
||||||
|
|
||||||
protected $fillable = [ |
protected $fillable = [ |
||||||
'activity_id', 'user_id', 'qty', 'lat', 'lon','assign_material_id', |
'activity_id', 'user_id', 'qty', 'lat', 'lon','assign_material_id', |
||||||
'report_date', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' |
'report_date', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' |
||||||
]; |
]; |
||||||
|
|
||||||
public function getReportDateAttribute($value) |
public function getReportDateAttribute($value) |
||||||
{ |
{ |
||||||
return Carbon::createFromTimestamp(strtotime($value)) |
return Carbon::createFromTimestamp(strtotime($value)) |
||||||
->timezone(env('APP_TIMEZONE')) |
->timezone(env('APP_TIMEZONE')) |
||||||
->toDateTimeString(); |
->toDateTimeString(); |
||||||
} |
} |
||||||
|
|
||||||
public static function boot() { |
public static function boot() { |
||||||
parent::boot(); |
parent::boot(); |
||||||
|
|
||||||
static::created(function($data) { |
static::created(function($data) { |
||||||
$activity = Activity::find($data->activity_id); |
$activity = Activity::find($data->activity_id); |
||||||
$assignedMaterial = AssignMaterial::find($data->assign_material_id); |
$assignedMaterial = AssignMaterial::find($data->assign_material_id); |
||||||
|
|
||||||
$biayaActual = $activity->biaya_actual + floatval($assignedMaterial->budget) * floatval($data->qty); |
$biayaActual = $activity->biaya_actual + floatval($assignedMaterial->budget) * floatval($data->qty); |
||||||
|
|
||||||
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); |
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); |
||||||
if($dataPlan[0]->status_activity == 'done'){ |
if($dataPlan[0]->status_activity == 'done'){ |
||||||
$percentage = 100; |
$percentage = 100; |
||||||
} else { |
} else { |
||||||
$totalPlan = $dataPlan->sum('qty_planning'); |
$totalPlan = $dataPlan->sum('qty_planning'); |
||||||
$totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); |
$totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); |
||||||
$percentage = ($totalVolumeActual * 100) / $totalPlan; |
$percentage = ($totalVolumeActual * 100) / $totalPlan; |
||||||
$percentage = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; |
$percentage = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; |
||||||
} |
} |
||||||
|
|
||||||
$activity->update([ |
$activity->update([ |
||||||
"persentase_progress" => $percentage, |
"persentase_progress" => $percentage, |
||||||
"biaya_actual" => $biayaActual, |
"biaya_actual" => $biayaActual, |
||||||
]); |
]); |
||||||
|
|
||||||
$activity->save(); |
$activity->save(); |
||||||
}); |
}); |
||||||
|
|
||||||
static::deleted(function($data) { |
static::deleted(function($data) { |
||||||
|
|
||||||
$activity = Activity::find($data->activity_id); |
$activity = Activity::find($data->activity_id); |
||||||
$assignedMaterial = AssignMaterial::find($data->assign_material_id); |
$assignedMaterial = AssignMaterial::find($data->assign_material_id); |
||||||
|
|
||||||
$activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty); |
$activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty); |
||||||
|
|
||||||
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); |
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); |
||||||
$totalPlan = $dataPlan->sum('qty_planning'); |
$totalPlan = $dataPlan->sum('qty_planning'); |
||||||
$totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); |
$totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); |
||||||
$percentage = ($totalVolumeActual * 100) / $totalPlan; |
$percentage = ($totalVolumeActual * 100) / $totalPlan; |
||||||
$activity->persentase_progress = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; |
$activity->persentase_progress = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; |
||||||
$activity->save(); |
$activity->save(); |
||||||
|
|
||||||
}); |
}); |
||||||
|
|
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue