Browse Source

Merge pull request 'update clear code' (#61) from dev-wahyun into staging

Reviewed-on: ibnu/generic-ospro-backend#61
pull/1/head
farhantock 8 months ago
parent
commit
6ba759d324
  1. 8
      app/Http/Controllers/AssignMaterialController.php
  2. 319
      app/Http/Controllers/AssignToolsController.php
  3. 280
      app/Http/Controllers/HolidayController.php
  4. 3
      app/Http/Controllers/HumanResourceController.php
  5. 2
      app/Http/Controllers/ReportActivityController.php
  6. 6
      app/Http/Controllers/ReportActivityMaterialController.php
  7. 2
      app/Http/Controllers/UserToActivityController.php
  8. 89
      app/Models/Activity.php
  9. 37
      app/Models/AssignMaterial.php
  10. 34
      app/Models/ProjectRole.php
  11. 396
      app/Models/User.php
  12. 57
      app/Models/UserToActivity.php
  13. 20
      routes/web.php

8
app/Http/Controllers/AssignMaterialController.php

@ -8,7 +8,7 @@ use App\Models\RequestMaterial;
use App\Models\Activity; use App\Models\Activity;
use App\Models\ReportActivityMaterial; use App\Models\ReportActivityMaterial;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Datatables; use Yajra\Datatables\Datatables;
class AssignMaterialController extends Controller class AssignMaterialController extends Controller
{ {
@ -47,7 +47,11 @@ class AssignMaterialController extends Controller
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); if($result) {
return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 400], 400);
}
} 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);
} }

319
app/Http/Controllers/AssignToolsController.php

@ -1,160 +1,159 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use App\Models\{AssignMaterial,AssignTools,ToolsResource};
use App\Models\AssignTools; use Illuminate\Http\Request;
use Datatables; use Yajra\Datatables\Datatables;
use App\Models\ToolsResource; class AssignToolsController extends Controller
class AssignToolsController extends Controller {
{ public function add(Request $request){
public function add(Request $request){ $this->validate($request, [
$this->validate($request, [ 'activity_id' => 'required',
'activity_id' => 'required', 'tools_id' => 'required',
'tools_id' => 'required', 'qty_planning' => 'required',
'qty_planning' => 'required', ]);
]);
$checkStock = ToolsResource::where("id", $request->tools_id)->first();
$checkStock = ToolsResource::where("id", $request->tools_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'=>'Not enough stock in warehouse!','code'=>400]);
return response()->json(['status'=>'failed','message'=>'Not enough stock in warehouse!','code'=>400]); die();
die(); }
}
$data = $request->all();
$data = $request->all();
$data['created_by'] = $this->currentName;
$data['created_by'] = $this->currentName;
$result = AssignTools::create($data);
$result = AssignTools::create($data); if($result){
if($result){ $checkStock = ToolsResource::find($request->tools_id);
$checkStock = ToolsResource::find($request->tools_id); $newStock = (int)$checkStock->qty - (int)$request->qty_planning;
$newStock = (int)$checkStock->qty - (int)$request->qty_planning; $dataUpdate = array(
$dataUpdate = array( "qty"=>$newStock,
"qty"=>$newStock, "updated_by"=>$this->currentName
"updated_by"=>$this->currentName );
); $checkStock->update($dataUpdate);
$checkStock->update($dataUpdate); return response()->json(['status'=>'success','message'=>'Assign tools success!','code'=>200]);
return response()->json(['status'=>'success','message'=>'Assign tools success!','code'=>200]); }else{
}else{ return response()->json(['status'=>'failed','message'=>'Assign tools failed','code'=>400]);
return response()->json(['status'=>'failed','message'=>'Assign tools failed','code'=>400]); }
} }
}
private function updateFromAdd($data){
private function updateFromAdd($data){ $assignTools = AssignTools::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id)->first();
$assignTools = AssignTools::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id)->first();
$newQty = (int)$assignTools->qty_planning + (int)$data->qty_planning;
$newQty = (int)$assignTools->qty_planning + (int)$data->qty_planning; $dataUpdate = array(
$dataUpdate = array( "qty_planning"=>$newQty,
"qty_planning"=>$newQty, "updated_by"=>$this->currentName
"updated_by"=>$this->currentName );
);
$dataWillUpdate = AssignMaterial::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id);
$dataWillUpdate = AssignMaterial::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id);
return $dataWillUpdate->update($dataUpdate);
return $dataWillUpdate->update($dataUpdate); }
}
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 = AssignTools::find($id);
$data = AssignTools::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 Assign tools not found!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); die();
die(); }
}
if($result){
if($result){ return response()->json(['status'=>'success','message'=>'Assign tools successfully updated!','code'=>200], 200);
return response()->json(['status'=>'success','message'=>'Assign tools successfully updated!','code'=>200], 200); }else{
}else{ return response()->json(['status'=>'failed','message'=>'Assign tools failed updated!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'Assign tools failed updated!','code'=>400], 400); }
} }
}
public function delete($id)
public function delete($id) {
{ $data = AssignTools::find($id);
$data = AssignTools::find($id);
if($data){
if($data){ $id = $data->tools_id;
$id = $data->tools_id; $stock = $data->qty_planning;
$stock = $data->qty_planning; $toolsResource = ToolsResource::find($id);
$toolsResource = ToolsResource::find($id); if($toolsResource){
if($toolsResource){ $oldStock = $toolsResource->qty;
$oldStock = $toolsResource->qty; $newStock = $oldStock + $stock;
$newStock = $oldStock + $stock; $dataUpdate = array(
$dataUpdate = array( "qty"=>$newStock,
"qty"=>$newStock, "updated_by"=>$this->currentName
"updated_by"=>$this->currentName );
); $toolsResource->update($dataUpdate);
$toolsResource->update($dataUpdate); }
}
$delete = $data->delete();
$delete = $data->delete(); }else{
}else{ return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); die();
die(); }
}
if($delete){
if($delete){ return response()->json(['status'=>'success','message'=>'Assign tools successfully deleted!','code'=>200], 200);
return response()->json(['status'=>'success','message'=>'Assign tools successfully deleted!','code'=>200], 200); }else{
}else{ return response()->json(['status'=>'failed','message'=>'Assign tools failed deleted!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'Assign tools failed deleted!','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 = AssignTools::find($id);
$result = AssignTools::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 Assign tools, please try again later!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'failed get data Assign tools, please try again later!','code'=>400], 400); }
} }
}
public function search(Request $request)
public function search(Request $request) {
{ $payload = $request->all();
$payload = $request->all(); $dataBuilder = $this->setUpPayload($payload, 'assign_tools_to_activity');
$dataBuilder = $this->setUpPayload($payload, 'assign_tools_to_activity'); $builder = $dataBuilder['builder'];
$builder = $dataBuilder['builder']; $countBuilder = $dataBuilder['count'];
$countBuilder = $dataBuilder['count']; $dataGet = $builder->get();
$dataGet = $builder->get(); $totalRecord = $countBuilder->count();
$totalRecord = $countBuilder->count(); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); }
}
public function list()
public function list() {
{ $data = AssignTools::all();
$data = AssignTools::all(); $countData = $data->count();
$countData = $data->count();
if($data){
if($data){ return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); }else{
}else{ return response()->json(['status'=>'failed','message'=>'failed get Assign tools, please try again later!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'failed get Assign tools, please try again later!','code'=>400], 400); }
} }
}
public function datatables(Request $request){
public function datatables(Request $request){ $id_activity = $request->query('idact');
$id_activity = $request->query('idact'); $data = AssignTools::select("assign_tools_to_activity.*","m.name as tools_name","m.uom as uom")->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id")->where('assign_tools_to_activity.activity_id', $id_activity)->get();
$data = AssignTools::select("assign_tools_to_activity.*","m.name as tools_name","m.uom as uom")->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id")->where('assign_tools_to_activity.activity_id', $id_activity)->get(); return Datatables::of($data)
return Datatables::of($data) ->addIndexColumn()
->addIndexColumn() ->addColumn('action', function($row){
->addColumn('action', function($row){ $actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-tools-delete"><i class="fa fa-trash"></i></a>';
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-tools-delete"><i class="fa fa-trash"></i></a>'; return $actionBtn;
return $actionBtn; })
}) ->rawColumns(['action'])->make(true);
->rawColumns(['action'])->make(true); }
} }
}

280
app/Http/Controllers/HolidayController.php

@ -1,140 +1,140 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Holiday; use App\Models\Holiday;
use Datatables; use Yajra\Datatables\Datatables;
class HolidayController extends Controller class HolidayController extends Controller
{ {
public function add(Request $request) public function add(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'proyek_id' => 'required', 'proyek_id' => 'required',
'version_gantt_id' => 'required', 'version_gantt_id' => 'required',
'date' => 'required' 'date' => 'required'
]); ]);
$data = $request->all(); $data = $request->all();
$duration = $request->duration; $duration = $request->duration;
if(!$duration){ if(!$duration){
$data['duration'] = 1; $data['duration'] = 1;
} }
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
$result = Holiday::create($data); $result = Holiday::create($data);
if($result){ if($result){
return response()->json(['status'=>'success','message'=>'add holiday successfully!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'add holiday successfully!','code'=>200], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'add holiday failed!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'add holiday 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 = Holiday::find($id); $result = Holiday::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 holiday, please try again later!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'failed get data holiday, 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);
} }
$data = Holiday::find($id); $data = Holiday::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 holiday not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400);
die(); die();
} }
if($result){ if($result){
return response()->json(['status'=>'success','message'=>'data holiday successfully updated!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'data holiday successfully updated!','code'=>200], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data holiday failed updated!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data holiday failed updated!','code'=>400], 400);
} }
} }
public function delete($id) public function delete($id)
{ {
$data = Holiday::find($id); $data = Holiday::find($id);
if($data){ if($data){
$deletedData = $data; $deletedData = $data;
$delete = $data->delete(); $delete = $data->delete();
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400);
die(); die();
} }
if($delete){ if($delete){
return response()->json(['status'=>'success', 'data'=>$deletedData,'message'=>'data holiday successfully deleted!','code'=>200], 200); return response()->json(['status'=>'success', 'data'=>$deletedData,'message'=>'data holiday successfully deleted!','code'=>200], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data holiday failed deleted!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data holiday failed deleted!','code'=>400], 400);
} }
} }
public function search(Request $request) public function search(Request $request)
{ {
$payload = $request->all(); $payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_holidays'); $dataBuilder = $this->setUpPayload($payload, 'm_holidays');
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} }
public function list() public function list()
{ {
$data = Holiday::all(); $data = Holiday::all();
$countData = $data->count(); $countData = $data->count();
if($data){ if($data){
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'failed get list holiday, please try again later!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'failed get list holiday, please try again later!','code'=>400], 400);
} }
} }
public function datatables(Request $request){ public function datatables(Request $request){
$proyek_id = $request->query('proyek_id'); $proyek_id = $request->query('proyek_id');
$gantt_id = $request->query('gantt_id'); $gantt_id = $request->query('gantt_id');
$data = Holiday::where('proyek_id', $proyek_id)->where('version_gantt_id', $gantt_id)->get(); $data = Holiday::where('proyek_id', $proyek_id)->where('version_gantt_id', $gantt_id)->get();
return Datatables::of($data) return Datatables::of($data)
->editColumn('date', function($row) { ->editColumn('date', function($row) {
$date = date_create($row->date); $date = date_create($row->date);
$dateFormat = date_format($date,"d-m-Y"); $dateFormat = date_format($date,"d-m-Y");
return $dateFormat; return $dateFormat;
}) })
->editColumn('duration', function($row) { ->editColumn('duration', function($row) {
$day = (int)$row->duration > 1 ? "days" : "day"; $day = (int)$row->duration > 1 ? "days" : "day";
return $row->duration." ".$day; return $row->duration." ".$day;
}) })
->addIndexColumn() ->addIndexColumn()
->addColumn('action', function($row){ ->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-holiday-delete"><i class="fa fa-trash"></i></a>'; $actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-holiday-delete"><i class="fa fa-trash"></i></a>';
return $actionBtn; return $actionBtn;
}) })
->rawColumns(['action'])->make(true); ->rawColumns(['action'])->make(true);
} }
} }

3
app/Http/Controllers/HumanResourceController.php

@ -22,7 +22,8 @@ class HumanResourceController extends Controller
'name' => 'required', 'name' => 'required',
'ktp_number' => 'required|string|unique:m_users,ktp_number', 'ktp_number' => 'required|string|unique:m_users,ktp_number',
'employee_type' => 'required', 'employee_type' => 'required',
'company_id' => 'required' 'company_id' => 'required',
'username' => 'unique:m_users,username'
]); ]);
$data = $request->all(); $data = $request->all();

2
app/Http/Controllers/ReportActivityController.php

@ -6,7 +6,7 @@ use Illuminate\Http\Request;
use App\Models\ReportActivity; use App\Models\ReportActivity;
use App\Models\Activity; use App\Models\Activity;
use App\Models\Image; use App\Models\Image;
use Datatables; use Yajra\Datatables\Datatables;
class ReportActivityController extends Controller class ReportActivityController extends Controller
{ {

6
app/Http/Controllers/ReportActivityMaterialController.php

@ -8,7 +8,7 @@ use Illuminate\Support\Facades\DB;
use App\Models\ReportActivityMaterial; use App\Models\ReportActivityMaterial;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use Datatables; use Yajra\Datatables\Datatables;
use DateTime; use DateTime;
class ReportActivityMaterialController extends Controller class ReportActivityMaterialController extends Controller
@ -72,10 +72,10 @@ class ReportActivityMaterialController extends Controller
// actual < plan // actual < plan
$persentaseProgress = $sumReportActivityMaterial/$sumAssignMaterial*100; $persentaseProgress = $sumReportActivityMaterial/$sumAssignMaterial*100;
} }
$dataUpdate = array( $dataUpdate = array(
"actual_start" => null, "actual_start" => null,
"actual_end" => null, "actual_end" => null,
"persentase_progress" => $persentaseProgress, "persentase_progress" => $persentaseProgress,
"updated_by" => $this->currentName "updated_by" => $this->currentName
); );

2
app/Http/Controllers/UserToActivityController.php

@ -7,7 +7,7 @@ use App\Models\UserToActivity;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Datatables; use Yajra\Datatables\Datatables;
class UserToActivityController extends Controller class UserToActivityController extends Controller
{ {

89
app/Models/Activity.php

@ -33,6 +33,9 @@ class Activity extends Model
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools', 'assign_expense' 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools', 'assign_expense'
]; ];
protected $casts = [
'rencana_biaya' => 'double'
];
public function getStartDateAttribute($value) public function getStartDateAttribute($value)
{ {
@ -61,58 +64,60 @@ class Activity extends Model
public static function boot() { public static function boot() {
parent::boot(); parent::boot();
DB::transaction(function() {
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 (isset($data->parent_id)) { if (isset($data->parent_id)) {
if(Activity::where("parent_id", $data->parent_id)->count() == 0) { if(Activity::where("parent_id", $data->parent_id)->count() == 0) {
$activity = Activity::find($data->parent_id); $activity = Activity::find($data->parent_id);
if ($activity) { if ($activity) {
$activity->update(["type_activity"=>"task"]); $activity->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();
}); });
},5);
} }
private function updateBobot($isDelete = false) private function updateBobot($isDelete = false)
{ {
$root = Activity::where('version_gantt_id', $this->version_gantt_id) $root = Activity::where([
->where("proyek_id", $this->proyek_id) ['version_gantt_id', $this->version_gantt_id],
->whereNull('parent_id') ['proyek_id', $this->proyek_id]
])
->whereNull('parent_id')
->first(); ->first();
if(isset($root) && $root->rencana_biaya > 0){ if(isset($root) && doubleval($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],['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 = ( doubleval($activity->rencana_biaya) / doubleval($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();

37
app/Models/AssignMaterial.php

@ -3,10 +3,8 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Models\RequestMaterial; use App\Models\{Activity,RequestMaterial,ReportActivityMaterial};
use App\Models\Activity; use Illuminate\Support\Facades\DB;
use App\Models\ReportActivityMaterial;
class AssignMaterial extends Model class AssignMaterial extends Model
{ {
protected $table = 'assign_material_to_activity'; protected $table = 'assign_material_to_activity';
@ -23,24 +21,25 @@ class AssignMaterial extends Model
protected $casts = [ protected $casts = [
'id' => 'integer', 'id' => 'integer',
'budget' => 'string', 'budget' => 'string',
'qty_planning' => 'float'
]; ];
public static function boot() { public static function boot() {
parent::boot(); parent::boot();
DB::transaction(function () {
static::created(function($data) { static::created(function($data) {
$activity = Activity::find($data->activity_id); $activity = Activity::find((int)$data->activity_id);
$material = RequestMaterial::where("id", $data->material_id)->first(); $material = RequestMaterial::find((int)$data->material_id);
$activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning); $activity->rencana_biaya += (doubleval($material->price) * doubleval($data->qty_planning));
$activity->save(); $activity->save();
}); });
static::deleted(function($data) { static::deleted(function($data) {
$reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete(); ReportActivityMaterial::where('assign_material_id', $data->id)->delete();
$activity = Activity::where('id', $data->activity_id)->first(); $activity = Activity::find($data->activity_id);
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); $activity->rencana_biaya -= (doubleval($data->budget) * doubleval($data->qty_planning));
$activity->save(); $activity->save();
}); });
}, 5);
} }
} }

34
app/Models/ProjectRole.php

@ -1,17 +1,17 @@
<?php <?php
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class ProjectRole extends Model class ProjectRole extends Model
{ {
protected $table = 'm_role_proyek'; protected $table = 'm_role_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 = [
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' 'name', 'description', 'created_at', 'created_by', 'updated_at', 'company_id', 'updated_by'
]; ];
} }

396
app/Models/User.php

@ -1,198 +1,198 @@
<?php <?php
namespace App\Models; namespace App\Models;
use Tymon\JWTAuth\Contracts\JWTSubject; use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Auth\Authenticatable; use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Laravel\Lumen\Auth\Authorizable; use Laravel\Lumen\Auth\Authorizable;
use Carbon\Carbon; use Carbon\Carbon;
class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject
{ {
use Authenticatable, Authorizable, HasFactory; use Authenticatable, Authorizable, HasFactory;
protected $table = 'm_users'; protected $table = 'm_users';
/** /**
* The attributes that are mass assignable. * The attributes that are mass assignable.
* *
* @var array * @var array
*/ */
protected $fillable = [ protected $fillable = [
'name', 'email', 'role_id', 'username', 'session_login', 'phone_number', 'email', 'address', 'name', 'email', 'role_id', 'username', 'session_login', 'phone_number', 'email', 'address',
'fcm_token', 'gender', 'birth_place', 'birth_date', 'blood_type', 'ktp_number', 'working_hours', 'fcm_token', 'gender', 'birth_place', 'birth_date', 'blood_type', 'ktp_number', 'working_hours',
'created_at', 'created_by', 'updated_at', 'updated_by', 'status_resource', 'discount_id' 'created_at', 'created_by', 'updated_at', 'updated_by', 'status_resource', 'discount_id','company_id'
]; ];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
const DEFAULT_TZ = 'Asia/Jakarta'; const DEFAULT_TZ = 'Asia/Jakarta';
const INSIDE = "INSIDE"; const INSIDE = "INSIDE";
const OUTSIDE = "OUTSIDE"; const OUTSIDE = "OUTSIDE";
const HOLIDAY = "HOLIDAY"; const HOLIDAY = "HOLIDAY";
/** /**
* The attributes excluded from the model's JSON form. * The attributes excluded from the model's JSON form.
* *
* @var array * @var array
*/ */
protected $hidden = [ protected $hidden = [
'password', 'password',
]; ];
/** /**
* Get the identifier that will be stored in the subject claim of the JWT. * Get the identifier that will be stored in the subject claim of the JWT.
* *
* @return mixed * @return mixed
*/ */
public function getJWTIdentifier() public function getJWTIdentifier()
{ {
return $this->getKey(); return $this->getKey();
} }
/** /**
* Return a key value array, containing any custom claims to be added to the JWT. * Return a key value array, containing any custom claims to be added to the JWT.
* *
* @return array * @return array
*/ */
public function getJWTCustomClaims() public function getJWTCustomClaims()
{ {
return []; return [];
} }
/** /**
* Get working hours for given timestamp * Get working hours for given timestamp
* *
* @return array of carbon or NULL in case HOLIDAY * @return array of carbon or NULL in case HOLIDAY
*/ */
public function getWorkingTime(Carbon $ts, $f = "08:00", $t = "17:00", $tz = self::DEFAULT_TZ) public function getWorkingTime(Carbon $ts, $f = "08:00", $t = "17:00", $tz = self::DEFAULT_TZ)
{ {
$workingTime = array( $workingTime = array(
"from" => Carbon::createFromTimeString($f, $tz), "from" => Carbon::createFromTimeString($f, $tz),
"to" => Carbon::createFromTimeString($t, $tz) "to" => Carbon::createFromTimeString($t, $tz)
); );
$userShift = UserShift::where('user_id',) $userShift = UserShift::where('user_id',)
->orderByDesc('from_date') ->orderByDesc('from_date')
->first(); ->first();
$shift = null; $shift = null;
if ($userShift !== null) { if ($userShift !== null) {
$shiftId = null; $shiftId = null;
switch ($ts->shortEnglishDayOfWeek) { switch ($ts->shortEnglishDayOfWeek) {
case "Mon": case "Mon":
$shiftId = $userShift->mon_shift_id; $shiftId = $userShift->mon_shift_id;
break; break;
case "Tue": case "Tue":
$shiftId = $userShift->tue_shift_id; $shiftId = $userShift->tue_shift_id;
break; break;
case "Wed": case "Wed":
$shiftId = $userShift->wed_shift_id; $shiftId = $userShift->wed_shift_id;
break; break;
case "Thu": case "Thu":
$shiftId = $userShift->thu_shift_id; $shiftId = $userShift->thu_shift_id;
break; break;
case "Fri": case "Fri":
$shiftId = $userShift->fri_shift_id; $shiftId = $userShift->fri_shift_id;
break; break;
case "Sat": case "Sat":
$shiftId = $userShift->sat_shift_id; $shiftId = $userShift->sat_shift_id;
break; break;
case "Sun": case "Sun":
$shiftId = $userShift->sun_shift_id; $shiftId = $userShift->sun_shift_id;
break; break;
} }
if ($shiftId === null) { if ($shiftId === null) {
return null; return null;
} }
$shift = Shift::where('id', $shiftId)->first(); $shift = Shift::where('id', $shiftId)->first();
} else { } else {
$shift = Shift::where('is_non_shift', true) $shift = Shift::where('is_non_shift', true)
->orderByDesc('created_at') ->orderByDesc('created_at')
->first(); ->first();
} }
if ($shift !== null) { if ($shift !== null) {
$from = Carbon::createFromTimeString($shift->start_time, $tz) $from = Carbon::createFromTimeString($shift->start_time, $tz)
->subMinutes($shift->flex_time_minute); ->subMinutes($shift->flex_time_minute);
$to = Carbon::createFromTimeString($shift->end_time, $tz) $to = Carbon::createFromTimeString($shift->end_time, $tz)
->addMinutes($shift->flex_time_minute); ->addMinutes($shift->flex_time_minute);
/* /*
if ($to->lessThan($from)) if ($to->lessThan($from))
{ {
$to->addDay(); $to->addDay();
} }
*/ */
$workingTime['from'] = $from; $workingTime['from'] = $from;
$workingTime['to'] = $to; $workingTime['to'] = $to;
} }
return $workingTime; return $workingTime;
} }
/** /**
* Get presence status * Get presence status
*/ */
public function presenceStatus(Carbon $at = null, $tz = self::DEFAULT_TZ) public function presenceStatus(Carbon $at = null, $tz = self::DEFAULT_TZ)
{ {
$ts = $at; $ts = $at;
if ($at !== null) { if ($at !== null) {
$ts = Carbon::now($tz); $ts = Carbon::now($tz);
} }
$tsSec = $ts->secondsSinceMidnight(); $tsSec = $ts->secondsSinceMidnight();
$status = ""; $status = "";
$wt = $this->getWorkingTime($ts, $tz); $wt = $this->getWorkingTime($ts, $tz);
if ($wt === null) { if ($wt === null) {
$status = self::HOLIDAY; $status = self::HOLIDAY;
} else { } else {
$from = $wt->from; $from = $wt->from;
$to = $wt->to; $to = $wt->to;
$tsFrom = $from->secondsSinceMidnight(); $tsFrom = $from->secondsSinceMidnight();
$tsTo = $to->secondsSinceMidnight(); $tsTo = $to->secondsSinceMidnight();
if ($from->greaterThan($to)) { if ($from->greaterThan($to)) {
$tsMid = 24 * 60 * 60 - $tsFrom; $tsMid = 24 * 60 * 60 - $tsFrom;
if ($tsSec >= $tsFrom || $tsSec < $tsTo) { if ($tsSec >= $tsFrom || $tsSec < $tsTo) {
$status = self::INSIDE; $status = self::INSIDE;
} else { } else {
$status = self::OUTSIDE; $status = self::OUTSIDE;
} }
} else { } else {
if ($tsSec < $tsFrom || $tsSec > $tsTo) { if ($tsSec < $tsFrom || $tsSec > $tsTo) {
$status = self::OUTSIDE; $status = self::OUTSIDE;
} else { } else {
$status = self::INSIDE; $status = self::INSIDE;
} }
} }
} }
$clockIn = null; $clockIn = null;
$clockOut = null; $clockOut = null;
$inout = Presence::where('user_id', $this->id) $inout = Presence::where('user_id', $this->id)
->orderByDesc('clock_in') ->orderByDesc('clock_in')
->first(); ->first();
if ($inout !== null) { if ($inout !== null) {
$clockIn = Carbon::parse($inout->clock_in, $tz); $clockIn = Carbon::parse($inout->clock_in, $tz);
$clockOut = Carbon::parse($inout->clock_out, $tz); $clockOut = Carbon::parse($inout->clock_out, $tz);
} }
return array( return array(
"status" => $status, "status" => $status,
"ts" => $ts, "ts" => $ts,
"clock_in" => $clockIn, "clock_in" => $clockIn,
"clock_out" => $clockOut "clock_out" => $clockOut
); );
} }
} }

57
app/Models/UserToActivity.php

@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Models\Activity; use App\Models\Activity;
use Illuminate\Support\Facades\DB;
class UserToActivity extends Model class UserToActivity extends Model
{ {
@ -29,35 +30,37 @@ class UserToActivity extends Model
public static function boot() { public static function boot() {
parent::boot(); parent::boot();
static::created(function($data) { DB::transaction(function(){
$activity = Activity::find($data->activity_id); static::created(function($data) {
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); $activity = Activity::find($data->activity_id);
$getWorkingHours = UserToProyek::where([['user_id', $data->user_id],['proyek_id', $activity->proyek_id]])->first();
$salary = 0;
if($getWorkingHours->uom_standart_rate == "Hour") {
$salary = (doubleval($getWorkingHours->standart_rate) * 8) * (int)$activity->duration * ($getWorkingHours->max_used / 100);
} else {
$salary = (doubleval($getWorkingHours->standart_rate) * (int)$activity->duration) * ($getWorkingHours->max_used / 100);
}
$activity->rencana_biaya += doubleval($salary);
$activity->save();
});
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100); static::deleted(function($data) {
$activity = Activity::find($data->activity_id);
if($getWorkingHours->uom_standart_rate == "Hour") $getWorkingHours = UserToProyek::where([['user_id', $data->user_id],['proyek_id', $activity->proyek_id]])->first();
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100); $salary = 0;
if($getWorkingHours->uom_standart_rate == "Hour"){
$activity->rencana_biaya += $salary; $salary = (doubleval($getWorkingHours->standart_rate) * 8) * (int)$activity->duration * ($getWorkingHours->max_used / 100);
$activity->save(); } else {
}); $salary = (doubleval($getWorkingHours->standart_rate) * (int)$activity->duration) * ($getWorkingHours->max_used / 100);
}
static::deleted(function($data) { $activity->rencana_biaya -= doubleval($salary);
$activity = Activity::find($data->activity_id);
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first();
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
if($getWorkingHours->uom_standart_rate == "Hour"){
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
}
$activity->rencana_biaya -= $salary;
if ($activity->rencana_biaya < 0) {
$activity->rencana_biaya = 0;
}
$activity->save();
});
if ($activity->rencana_biaya < 0) {
$activity->rencana_biaya = 0;
}
$activity->save();
});
}, 5);
} }
} }

20
routes/web.php

@ -141,16 +141,6 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/human-resource/check-old-password/{id}', 'HumanResourceController@checkOldPassword'); $router->post('/human-resource/check-old-password/{id}', 'HumanResourceController@checkOldPassword');
$router->get('/human-resource/sync', 'HumanResourceController@sync'); $router->get('/human-resource/sync', 'HumanResourceController@sync');
$router->post('/refferal-code/search', 'RefferalCodeController@search');
$router->post('/refferal-code/add', 'RefferalCodeController@add');
$router->get('/refferal-code/edit/{id}', 'RefferalCodeController@edit');
$router->put('/refferal-code/update/{id}', 'RefferalCodeController@update');
$router->post('/product-transaction/search', 'ProductTransactionController@search');
$router->post('/product-transaction/add', 'ProductTransactionController@add');
$router->get('/product-transaction/edit/{id}', 'ProductTransactionController@edit');
$router->put('/product-transaction/update/{id}', 'ProductTransactionController@update');
$router->post('/project-role/search', 'ProjectRoleController@search'); $router->post('/project-role/search', 'ProjectRoleController@search');
$router->post('/project-role/add', 'ProjectRoleController@add'); $router->post('/project-role/add', 'ProjectRoleController@add');
$router->get('/project-role/edit/{id}', 'ProjectRoleController@edit'); $router->get('/project-role/edit/{id}', 'ProjectRoleController@edit');
@ -599,7 +589,15 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->delete('/demo-management/delete/{id}', 'DemoController@delete'); $router->delete('/demo-management/delete/{id}', 'DemoController@delete');
$router->get('/demo-management/list', 'DemoController@list'); $router->get('/demo-management/list', 'DemoController@list');
$router->get('information-storage/{company_name}', 'Controller@storage'); $router->get('/information-storage/{company_name}', 'Controller@storage');
$router->post('/register-user','UserRegisterController@add');
$router->post('/refferal-code/search', 'RefferalCodeController@search');
$router->post('/refferal-code/add', 'RefferalCodeController@add');
$router->get('/refferal-code/edit/{id}', 'RefferalCodeController@edit');
$router->put('/refferal-code/update/{id}', 'RefferalCodeController@update');
$router->post('/product-transaction/edit/{id}', 'ProductTransactionController@add'); $router->post('/product-transaction/edit/{id}', 'ProductTransactionController@add');
$router->put('/product-transaction/update/{id}', 'ProductTransactionController@update'); $router->put('/product-transaction/update/{id}', 'ProductTransactionController@update');
$router->post('/product-transaction/search', 'ProductTransactionController@search'); $router->post('/product-transaction/search', 'ProductTransactionController@search');

Loading…
Cancel
Save