farhantock
10 months ago
13 changed files with 631 additions and 622 deletions
@ -1,160 +1,159 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\AssignTools; |
||||
use Datatables; |
||||
use App\Models\ToolsResource; |
||||
class AssignToolsController extends Controller |
||||
{ |
||||
public function add(Request $request){ |
||||
$this->validate($request, [ |
||||
'activity_id' => 'required', |
||||
'tools_id' => 'required', |
||||
'qty_planning' => 'required', |
||||
]); |
||||
|
||||
$checkStock = ToolsResource::where("id", $request->tools_id)->first(); |
||||
$currentStock = $checkStock->qty; |
||||
if((int)$currentStock < (int)$request->qty_planning){ |
||||
return response()->json(['status'=>'failed','message'=>'Not enough stock in warehouse!','code'=>400]); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
$data = $request->all(); |
||||
|
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = AssignTools::create($data); |
||||
if($result){ |
||||
$checkStock = ToolsResource::find($request->tools_id); |
||||
$newStock = (int)$checkStock->qty - (int)$request->qty_planning; |
||||
$dataUpdate = array( |
||||
"qty"=>$newStock, |
||||
"updated_by"=>$this->currentName |
||||
); |
||||
$checkStock->update($dataUpdate); |
||||
return response()->json(['status'=>'success','message'=>'Assign tools success!','code'=>200]); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed','code'=>400]); |
||||
} |
||||
} |
||||
|
||||
private function updateFromAdd($data){ |
||||
$assignTools = AssignTools::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id)->first(); |
||||
|
||||
$newQty = (int)$assignTools->qty_planning + (int)$data->qty_planning; |
||||
$dataUpdate = array( |
||||
"qty_planning"=>$newQty, |
||||
"updated_by"=>$this->currentName |
||||
); |
||||
|
||||
$dataWillUpdate = AssignMaterial::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id); |
||||
|
||||
return $dataWillUpdate->update($dataUpdate); |
||||
} |
||||
|
||||
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 = AssignTools::find($id); |
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'Assign tools successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = AssignTools::find($id); |
||||
|
||||
if($data){ |
||||
$id = $data->tools_id; |
||||
$stock = $data->qty_planning; |
||||
$toolsResource = ToolsResource::find($id); |
||||
if($toolsResource){ |
||||
$oldStock = $toolsResource->qty; |
||||
$newStock = $oldStock + $stock; |
||||
$dataUpdate = array( |
||||
"qty"=>$newStock, |
||||
"updated_by"=>$this->currentName |
||||
); |
||||
$toolsResource->update($dataUpdate); |
||||
} |
||||
|
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success','message'=>'Assign tools successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed deleted!','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 = AssignTools::find($id); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get data Assign tools, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'assign_tools_to_activity'); |
||||
$builder = $dataBuilder['builder']; |
||||
$countBuilder = $dataBuilder['count']; |
||||
$dataGet = $builder->get(); |
||||
$totalRecord = $countBuilder->count(); |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||
} |
||||
|
||||
public function list() |
||||
{ |
||||
$data = AssignTools::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 Assign tools, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function datatables(Request $request){ |
||||
$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(); |
||||
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-tools-delete"><i class="fa fa-trash"></i></a>'; |
||||
return $actionBtn; |
||||
}) |
||||
->rawColumns(['action'])->make(true); |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use App\Models\{AssignMaterial,AssignTools,ToolsResource}; |
||||
use Illuminate\Http\Request; |
||||
use Yajra\Datatables\Datatables; |
||||
class AssignToolsController extends Controller |
||||
{ |
||||
public function add(Request $request){ |
||||
$this->validate($request, [ |
||||
'activity_id' => 'required', |
||||
'tools_id' => 'required', |
||||
'qty_planning' => 'required', |
||||
]); |
||||
|
||||
$checkStock = ToolsResource::where("id", $request->tools_id)->first(); |
||||
$currentStock = $checkStock->qty; |
||||
if((int)$currentStock < (int)$request->qty_planning){ |
||||
return response()->json(['status'=>'failed','message'=>'Not enough stock in warehouse!','code'=>400]); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
$data = $request->all(); |
||||
|
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = AssignTools::create($data); |
||||
if($result){ |
||||
$checkStock = ToolsResource::find($request->tools_id); |
||||
$newStock = (int)$checkStock->qty - (int)$request->qty_planning; |
||||
$dataUpdate = array( |
||||
"qty"=>$newStock, |
||||
"updated_by"=>$this->currentName |
||||
); |
||||
$checkStock->update($dataUpdate); |
||||
return response()->json(['status'=>'success','message'=>'Assign tools success!','code'=>200]); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed','code'=>400]); |
||||
} |
||||
} |
||||
|
||||
private function updateFromAdd($data){ |
||||
$assignTools = AssignTools::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id)->first(); |
||||
|
||||
$newQty = (int)$assignTools->qty_planning + (int)$data->qty_planning; |
||||
$dataUpdate = array( |
||||
"qty_planning"=>$newQty, |
||||
"updated_by"=>$this->currentName |
||||
); |
||||
|
||||
$dataWillUpdate = AssignMaterial::where("activity_id", $data->activity_id)->where("tools_id", $data->tools_id); |
||||
|
||||
return $dataWillUpdate->update($dataUpdate); |
||||
} |
||||
|
||||
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 = AssignTools::find($id); |
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'Assign tools successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = AssignTools::find($id); |
||||
|
||||
if($data){ |
||||
$id = $data->tools_id; |
||||
$stock = $data->qty_planning; |
||||
$toolsResource = ToolsResource::find($id); |
||||
if($toolsResource){ |
||||
$oldStock = $toolsResource->qty; |
||||
$newStock = $oldStock + $stock; |
||||
$dataUpdate = array( |
||||
"qty"=>$newStock, |
||||
"updated_by"=>$this->currentName |
||||
); |
||||
$toolsResource->update($dataUpdate); |
||||
} |
||||
|
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Data Assign tools not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success','message'=>'Assign tools successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'Assign tools failed deleted!','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 = AssignTools::find($id); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get data Assign tools, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'assign_tools_to_activity'); |
||||
$builder = $dataBuilder['builder']; |
||||
$countBuilder = $dataBuilder['count']; |
||||
$dataGet = $builder->get(); |
||||
$totalRecord = $countBuilder->count(); |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||
} |
||||
|
||||
public function list() |
||||
{ |
||||
$data = AssignTools::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 Assign tools, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function datatables(Request $request){ |
||||
$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(); |
||||
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-tools-delete"><i class="fa fa-trash"></i></a>'; |
||||
return $actionBtn; |
||||
}) |
||||
->rawColumns(['action'])->make(true); |
||||
} |
||||
} |
||||
|
@ -1,140 +1,140 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\Holiday; |
||||
use Datatables; |
||||
|
||||
class HolidayController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'proyek_id' => 'required', |
||||
'version_gantt_id' => 'required', |
||||
'date' => 'required' |
||||
]); |
||||
|
||||
$data = $request->all(); |
||||
$duration = $request->duration; |
||||
if(!$duration){ |
||||
$data['duration'] = 1; |
||||
} |
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = Holiday::create($data); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'add holiday successfully!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'add holiday 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 = Holiday::find($id); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get data holiday, 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 = Holiday::find($id); |
||||
|
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'data holiday successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = Holiday::find($id); |
||||
|
||||
if($data){ |
||||
$deletedData = $data; |
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success', 'data'=>$deletedData,'message'=>'data holiday successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_holidays'); |
||||
$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 = Holiday::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 holiday, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function datatables(Request $request){ |
||||
$proyek_id = $request->query('proyek_id'); |
||||
$gantt_id = $request->query('gantt_id'); |
||||
|
||||
$data = Holiday::where('proyek_id', $proyek_id)->where('version_gantt_id', $gantt_id)->get(); |
||||
|
||||
return Datatables::of($data) |
||||
->editColumn('date', function($row) { |
||||
$date = date_create($row->date); |
||||
$dateFormat = date_format($date,"d-m-Y"); |
||||
return $dateFormat; |
||||
}) |
||||
->editColumn('duration', function($row) { |
||||
$day = (int)$row->duration > 1 ? "days" : "day"; |
||||
return $row->duration." ".$day; |
||||
}) |
||||
->addIndexColumn() |
||||
->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>'; |
||||
return $actionBtn; |
||||
}) |
||||
|
||||
->rawColumns(['action'])->make(true); |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\Holiday; |
||||
use Yajra\Datatables\Datatables; |
||||
|
||||
class HolidayController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$this->validate($request, [ |
||||
'proyek_id' => 'required', |
||||
'version_gantt_id' => 'required', |
||||
'date' => 'required' |
||||
]); |
||||
|
||||
$data = $request->all(); |
||||
$duration = $request->duration; |
||||
if(!$duration){ |
||||
$data['duration'] = 1; |
||||
} |
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = Holiday::create($data); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'add holiday successfully!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'add holiday 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 = Holiday::find($id); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'failed get data holiday, 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 = Holiday::find($id); |
||||
|
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'data holiday successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function delete($id) |
||||
{ |
||||
$data = Holiday::find($id); |
||||
|
||||
if($data){ |
||||
$deletedData = $data; |
||||
$delete = $data->delete(); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
|
||||
if($delete){ |
||||
return response()->json(['status'=>'success', 'data'=>$deletedData,'message'=>'data holiday successfully deleted!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data holiday failed deleted!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_holidays'); |
||||
$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 = Holiday::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 holiday, please try again later!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function datatables(Request $request){ |
||||
$proyek_id = $request->query('proyek_id'); |
||||
$gantt_id = $request->query('gantt_id'); |
||||
|
||||
$data = Holiday::where('proyek_id', $proyek_id)->where('version_gantt_id', $gantt_id)->get(); |
||||
|
||||
return Datatables::of($data) |
||||
->editColumn('date', function($row) { |
||||
$date = date_create($row->date); |
||||
$dateFormat = date_format($date,"d-m-Y"); |
||||
return $dateFormat; |
||||
}) |
||||
->editColumn('duration', function($row) { |
||||
$day = (int)$row->duration > 1 ? "days" : "day"; |
||||
return $row->duration." ".$day; |
||||
}) |
||||
->addIndexColumn() |
||||
->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>'; |
||||
return $actionBtn; |
||||
}) |
||||
|
||||
->rawColumns(['action'])->make(true); |
||||
} |
||||
} |
||||
|
@ -1,17 +1,17 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class ProjectRole extends Model |
||||
{ |
||||
protected $table = 'm_role_proyek'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' |
||||
]; |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class ProjectRole extends Model |
||||
{ |
||||
protected $table = 'm_role_proyek'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'name', 'description', 'created_at', 'created_by', 'updated_at', 'company_id', 'updated_by' |
||||
]; |
||||
} |
||||
|
@ -1,198 +1,198 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject; |
||||
use Illuminate\Auth\Authenticatable; |
||||
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
use Laravel\Lumen\Auth\Authorizable; |
||||
use Carbon\Carbon; |
||||
|
||||
class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject |
||||
{ |
||||
use Authenticatable, Authorizable, HasFactory; |
||||
|
||||
protected $table = 'm_users'; |
||||
/** |
||||
* The attributes that are mass assignable. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $fillable = [ |
||||
'name', 'email', 'role_id', 'username', 'session_login', 'phone_number', 'email', 'address', |
||||
'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' |
||||
]; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
const DEFAULT_TZ = 'Asia/Jakarta'; |
||||
const INSIDE = "INSIDE"; |
||||
const OUTSIDE = "OUTSIDE"; |
||||
const HOLIDAY = "HOLIDAY"; |
||||
|
||||
/** |
||||
* The attributes excluded from the model's JSON form. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $hidden = [ |
||||
'password', |
||||
]; |
||||
|
||||
/** |
||||
* Get the identifier that will be stored in the subject claim of the JWT. |
||||
* |
||||
* @return mixed |
||||
*/ |
||||
public function getJWTIdentifier() |
||||
{ |
||||
return $this->getKey(); |
||||
} |
||||
|
||||
/** |
||||
* Return a key value array, containing any custom claims to be added to the JWT. |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function getJWTCustomClaims() |
||||
{ |
||||
return []; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get working hours for given timestamp |
||||
* |
||||
* @return array of carbon or NULL in case HOLIDAY |
||||
*/ |
||||
|
||||
public function getWorkingTime(Carbon $ts, $f = "08:00", $t = "17:00", $tz = self::DEFAULT_TZ) |
||||
{ |
||||
$workingTime = array( |
||||
"from" => Carbon::createFromTimeString($f, $tz), |
||||
"to" => Carbon::createFromTimeString($t, $tz) |
||||
); |
||||
|
||||
$userShift = UserShift::where('user_id',) |
||||
->orderByDesc('from_date') |
||||
->first(); |
||||
|
||||
$shift = null; |
||||
if ($userShift !== null) { |
||||
$shiftId = null; |
||||
switch ($ts->shortEnglishDayOfWeek) { |
||||
case "Mon": |
||||
$shiftId = $userShift->mon_shift_id; |
||||
break; |
||||
case "Tue": |
||||
$shiftId = $userShift->tue_shift_id; |
||||
break; |
||||
case "Wed": |
||||
$shiftId = $userShift->wed_shift_id; |
||||
break; |
||||
case "Thu": |
||||
$shiftId = $userShift->thu_shift_id; |
||||
break; |
||||
case "Fri": |
||||
$shiftId = $userShift->fri_shift_id; |
||||
break; |
||||
case "Sat": |
||||
$shiftId = $userShift->sat_shift_id; |
||||
break; |
||||
case "Sun": |
||||
$shiftId = $userShift->sun_shift_id; |
||||
break; |
||||
} |
||||
|
||||
if ($shiftId === null) { |
||||
return null; |
||||
} |
||||
|
||||
$shift = Shift::where('id', $shiftId)->first(); |
||||
} else { |
||||
$shift = Shift::where('is_non_shift', true) |
||||
->orderByDesc('created_at') |
||||
->first(); |
||||
} |
||||
|
||||
|
||||
if ($shift !== null) { |
||||
$from = Carbon::createFromTimeString($shift->start_time, $tz) |
||||
->subMinutes($shift->flex_time_minute); |
||||
$to = Carbon::createFromTimeString($shift->end_time, $tz) |
||||
->addMinutes($shift->flex_time_minute); |
||||
|
||||
/* |
||||
if ($to->lessThan($from)) |
||||
{ |
||||
$to->addDay(); |
||||
} |
||||
*/ |
||||
$workingTime['from'] = $from; |
||||
$workingTime['to'] = $to; |
||||
} |
||||
|
||||
return $workingTime; |
||||
} |
||||
|
||||
/** |
||||
* Get presence status |
||||
*/ |
||||
public function presenceStatus(Carbon $at = null, $tz = self::DEFAULT_TZ) |
||||
{ |
||||
|
||||
$ts = $at; |
||||
if ($at !== null) { |
||||
$ts = Carbon::now($tz); |
||||
} |
||||
$tsSec = $ts->secondsSinceMidnight(); |
||||
|
||||
$status = ""; |
||||
$wt = $this->getWorkingTime($ts, $tz); |
||||
if ($wt === null) { |
||||
$status = self::HOLIDAY; |
||||
} else { |
||||
$from = $wt->from; |
||||
$to = $wt->to; |
||||
$tsFrom = $from->secondsSinceMidnight(); |
||||
$tsTo = $to->secondsSinceMidnight(); |
||||
|
||||
if ($from->greaterThan($to)) { |
||||
$tsMid = 24 * 60 * 60 - $tsFrom; |
||||
if ($tsSec >= $tsFrom || $tsSec < $tsTo) { |
||||
$status = self::INSIDE; |
||||
} else { |
||||
$status = self::OUTSIDE; |
||||
} |
||||
} else { |
||||
if ($tsSec < $tsFrom || $tsSec > $tsTo) { |
||||
$status = self::OUTSIDE; |
||||
} else { |
||||
$status = self::INSIDE; |
||||
} |
||||
} |
||||
} |
||||
|
||||
$clockIn = null; |
||||
$clockOut = null; |
||||
$inout = Presence::where('user_id', $this->id) |
||||
->orderByDesc('clock_in') |
||||
->first(); |
||||
if ($inout !== null) { |
||||
$clockIn = Carbon::parse($inout->clock_in, $tz); |
||||
$clockOut = Carbon::parse($inout->clock_out, $tz); |
||||
} |
||||
|
||||
return array( |
||||
"status" => $status, |
||||
"ts" => $ts, |
||||
"clock_in" => $clockIn, |
||||
"clock_out" => $clockOut |
||||
); |
||||
} |
||||
} |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject; |
||||
use Illuminate\Auth\Authenticatable; |
||||
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
use Laravel\Lumen\Auth\Authorizable; |
||||
use Carbon\Carbon; |
||||
|
||||
class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject |
||||
{ |
||||
use Authenticatable, Authorizable, HasFactory; |
||||
|
||||
protected $table = 'm_users'; |
||||
/** |
||||
* The attributes that are mass assignable. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $fillable = [ |
||||
'name', 'email', 'role_id', 'username', 'session_login', 'phone_number', 'email', 'address', |
||||
'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','company_id' |
||||
]; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
const DEFAULT_TZ = 'Asia/Jakarta'; |
||||
const INSIDE = "INSIDE"; |
||||
const OUTSIDE = "OUTSIDE"; |
||||
const HOLIDAY = "HOLIDAY"; |
||||
|
||||
/** |
||||
* The attributes excluded from the model's JSON form. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $hidden = [ |
||||
'password', |
||||
]; |
||||
|
||||
/** |
||||
* Get the identifier that will be stored in the subject claim of the JWT. |
||||
* |
||||
* @return mixed |
||||
*/ |
||||
public function getJWTIdentifier() |
||||
{ |
||||
return $this->getKey(); |
||||
} |
||||
|
||||
/** |
||||
* Return a key value array, containing any custom claims to be added to the JWT. |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function getJWTCustomClaims() |
||||
{ |
||||
return []; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Get working hours for given timestamp |
||||
* |
||||
* @return array of carbon or NULL in case HOLIDAY |
||||
*/ |
||||
|
||||
public function getWorkingTime(Carbon $ts, $f = "08:00", $t = "17:00", $tz = self::DEFAULT_TZ) |
||||
{ |
||||
$workingTime = array( |
||||
"from" => Carbon::createFromTimeString($f, $tz), |
||||
"to" => Carbon::createFromTimeString($t, $tz) |
||||
); |
||||
|
||||
$userShift = UserShift::where('user_id',) |
||||
->orderByDesc('from_date') |
||||
->first(); |
||||
|
||||
$shift = null; |
||||
if ($userShift !== null) { |
||||
$shiftId = null; |
||||
switch ($ts->shortEnglishDayOfWeek) { |
||||
case "Mon": |
||||
$shiftId = $userShift->mon_shift_id; |
||||
break; |
||||
case "Tue": |
||||
$shiftId = $userShift->tue_shift_id; |
||||
break; |
||||
case "Wed": |
||||
$shiftId = $userShift->wed_shift_id; |
||||
break; |
||||
case "Thu": |
||||
$shiftId = $userShift->thu_shift_id; |
||||
break; |
||||
case "Fri": |
||||
$shiftId = $userShift->fri_shift_id; |
||||
break; |
||||
case "Sat": |
||||
$shiftId = $userShift->sat_shift_id; |
||||
break; |
||||
case "Sun": |
||||
$shiftId = $userShift->sun_shift_id; |
||||
break; |
||||
} |
||||
|
||||
if ($shiftId === null) { |
||||
return null; |
||||
} |
||||
|
||||
$shift = Shift::where('id', $shiftId)->first(); |
||||
} else { |
||||
$shift = Shift::where('is_non_shift', true) |
||||
->orderByDesc('created_at') |
||||
->first(); |
||||
} |
||||
|
||||
|
||||
if ($shift !== null) { |
||||
$from = Carbon::createFromTimeString($shift->start_time, $tz) |
||||
->subMinutes($shift->flex_time_minute); |
||||
$to = Carbon::createFromTimeString($shift->end_time, $tz) |
||||
->addMinutes($shift->flex_time_minute); |
||||
|
||||
/* |
||||
if ($to->lessThan($from)) |
||||
{ |
||||
$to->addDay(); |
||||
} |
||||
*/ |
||||
$workingTime['from'] = $from; |
||||
$workingTime['to'] = $to; |
||||
} |
||||
|
||||
return $workingTime; |
||||
} |
||||
|
||||
/** |
||||
* Get presence status |
||||
*/ |
||||
public function presenceStatus(Carbon $at = null, $tz = self::DEFAULT_TZ) |
||||
{ |
||||
|
||||
$ts = $at; |
||||
if ($at !== null) { |
||||
$ts = Carbon::now($tz); |
||||
} |
||||
$tsSec = $ts->secondsSinceMidnight(); |
||||
|
||||
$status = ""; |
||||
$wt = $this->getWorkingTime($ts, $tz); |
||||
if ($wt === null) { |
||||
$status = self::HOLIDAY; |
||||
} else { |
||||
$from = $wt->from; |
||||
$to = $wt->to; |
||||
$tsFrom = $from->secondsSinceMidnight(); |
||||
$tsTo = $to->secondsSinceMidnight(); |
||||
|
||||
if ($from->greaterThan($to)) { |
||||
$tsMid = 24 * 60 * 60 - $tsFrom; |
||||
if ($tsSec >= $tsFrom || $tsSec < $tsTo) { |
||||
$status = self::INSIDE; |
||||
} else { |
||||
$status = self::OUTSIDE; |
||||
} |
||||
} else { |
||||
if ($tsSec < $tsFrom || $tsSec > $tsTo) { |
||||
$status = self::OUTSIDE; |
||||
} else { |
||||
$status = self::INSIDE; |
||||
} |
||||
} |
||||
} |
||||
|
||||
$clockIn = null; |
||||
$clockOut = null; |
||||
$inout = Presence::where('user_id', $this->id) |
||||
->orderByDesc('clock_in') |
||||
->first(); |
||||
if ($inout !== null) { |
||||
$clockIn = Carbon::parse($inout->clock_in, $tz); |
||||
$clockOut = Carbon::parse($inout->clock_out, $tz); |
||||
} |
||||
|
||||
return array( |
||||
"status" => $status, |
||||
"ts" => $ts, |
||||
"clock_in" => $clockIn, |
||||
"clock_out" => $clockOut |
||||
); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue