Browse Source

Merge pull request 'dev-ibnu' (#134) from dev-ibnu into staging

Reviewed-on: ordo/adw-backend#134
pull/3/head
ibnu 1 year ago
parent
commit
593e5594ae
  1. 76
      app/Http/Controllers/Controller.php
  2. 113
      app/Http/Controllers/PresenceController.php
  3. 17
      app/Http/Controllers/ProjectController.php
  4. 4
      app/Models/Project.php
  5. 3
      routes/web.php

76
app/Http/Controllers/Controller.php

@ -34,71 +34,6 @@ class Controller extends BaseController
}
protected function setUpPayload($condition, $tableSelf)
{
$alias = "selfTable";
$builder = DB::table($tableSelf." AS ".$alias);
$builder = $builder->select($alias.".*");
if($condition){
if(isset($condition['joins'])){
$selectColumn = [];
$no = 0;
foreach($condition['joins'] as $join){
$tableJoin = isset($join['name1']) ? $join['name1'] : $alias;
$tableName = $join['name'];
$columnJoin = $join['column_join']; // foreign key table sini
$columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan
$columnResult = $join['column_results'];
foreach($columnResult as $sColumn){
$builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn);
}
$builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf);
$no++;
}
}
if(isset($condition['columns'])){
$listWhere = $condition['columns'];
$builder = $builder->where(function ($query) use($listWhere, $alias){
foreach($listWhere as $where){
$value = $where['value'];
if($value && $value!="" && $value!=" "){
$column = $where['name'];
$operator = strtolower($where['logic_operator']); // like, =, <>, range
$value2 = isset($where['value1']) ? $where['value1'] : "";
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias;
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}
}
});
}
if(isset($condition['group_column'])){
$builder = $this->groupWhere($builder, $condition['group_column'], $alias);
}
$data['count'] = clone $builder;
if(isset($condition['paging'])){
$builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']);
}
if(isset($condition['orders'])){
$orders = $condition['orders'];
$sortBy = $orders['ascending'] ? "ASC" : "DESC";
$columnOrder = $orders['columns'];
foreach($columnOrder as $column){
$builder = $builder->orderBy($alias.".".$column, $sortBy);
}
}
}
$data['builder'] = $builder;
return $data;
}
// new version for custom select in selfTable
protected function setUpPayloadSelect($condition, $tableSelf)
{
$alias = "selfTable";
$builder = DB::table($tableSelf." AS ".$alias);
@ -108,8 +43,11 @@ class Controller extends BaseController
foreach($condition['select'] as $select){
$builder = $builder->addSelect($alias.".".$select);
}
}else{
$builder = $builder->addSelect($alias.".*");
}
if(isset($condition['joins'])){
if(isset($condition['joins'])){
$selectColumn = [];
$no = 0;
foreach($condition['joins'] as $join){
$tableJoin = isset($join['name1']) ? $join['name1'] : $alias;
@ -124,7 +62,7 @@ class Controller extends BaseController
$builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf);
$no++;
}
}
}
if(isset($condition['columns'])){
$listWhere = $condition['columns'];
@ -161,15 +99,11 @@ class Controller extends BaseController
$builder = $builder->orderBy($alias.".".$column, $sortBy);
}
}
}else{
$builder = $builder->select($alias.".*");
}
$data['builder'] = $builder;
return $data;
}
private function groupWhere($oldBuilder, $groupWhere, $alias)
{
$builder = $oldBuilder;

113
app/Http/Controllers/PresenceController.php

@ -270,26 +270,105 @@ class PresenceController extends Controller
ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary"));
}
if(count($check)>0){
if($check[0]->boundary){
$temp[]=array(
"activity_id" => $dataGeom->id,
"boundary" => $check[0]->boundary,
"status_assign" => true
);
}
if($check[0]->boundary){
$temp[]=array(
"activity_id" => $dataGeom->id,
"boundary" => $check[0]->boundary,
"status_assign" => true
);
}
}
}
// assign and not in boundary
if(count($temp) < 1){
$temp[]=array(
"activity_id" => null,
"boundary" => false,
"status_assign" => true
// "geom" => $geom,
// "cek" => $check[0]->boundary
);
}
// assign and not in boundary
if(count($temp) < 1){
$temp[]=array(
"activity_id" => null,
"boundary" => false,
"status_assign" => true
// "geom" => $geom,
// "cek" => $check[0]->boundary
);
}
}
else{
// not assign
$temp[]=array(
"activity_id" => null,
"boundary" => false,
"status_assign" => false
);
}
return $temp;
}
public function checkLocationTest(Request $request){
// cek user tersebut apakah punya assign task yang ada bondary nya
// geom ada di table activity
// $clock_time =
$params = $request;
$geom = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id")
->join("m_activity as ma", "ma.id", "=", "ahta.activity_id")
->where("ahta.user_id", $params->user_id)
->whereNotNull("ma.geom")
->whereDate("ma.start_date", "<=", $params->time)
->whereDate("ma.end_date", ">=", $params->time)
->get();
$temp = [];
if (count($geom) > 0) {
foreach($geom as $dataGeom){
$valGeom = json_decode($dataGeom->geom);
if($params->clock_in_out['type']=="out"){
if($valGeom->type == "FeatureCollection"){
// return count($valGeom->features);
$multiArea = $valGeom->features;
foreach($multiArea as $area){
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'),
ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary"));
if($check[0]->boundary){
break;
}
}
}else{
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'),
ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary"));
}
}else{
if($valGeom->type == "FeatureCollection"){
// return count($valGeom->features);
$multiArea = $valGeom->features;
foreach($multiArea as $area){
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'),
ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary"));
if($check[0]->boundary){
break;
}
}
}else{
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'),
ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary"));
}
}
if(count($check)>0){
if($check[0]->boundary){
$temp[]=array(
"activity_id" => $dataGeom->id,
"boundary" => $check[0]->boundary,
"status_assign" => true
);
}
}
}
// assign and not in boundary
if(count($temp) < 1){
$temp[]=array(
"activity_id" => null,
"boundary" => false,
"status_assign" => true
// "geom" => $geom,
// "cek" => $check[0]->boundary
);
}
}
else{
// not assign
$temp[]=array(

17
app/Http/Controllers/ProjectController.php

@ -214,20 +214,7 @@ class ProjectController extends Controller
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function searchCustom(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayloadSelect($payload, 'm_proyek');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
}
public function list()
{
@ -291,7 +278,7 @@ class ProjectController extends Controller
}
try {
$projectsByType = DB::table('m_proyek')
->select('m_type_proyek.name', DB::raw('count(*) as total'))
->select('m_type_proyek.name', DB::raw('count(id) as total'))
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id')
->groupBy('m_type_proyek.name')
->get();

4
app/Models/Project.php

@ -42,8 +42,8 @@ class Project extends Model
'currency_name',
'budget_health',
'phase_id',
'calculation_status',
'scurve',
'calculation_status',
'scurve',
'created_at',
'created_by',
'updated_at',

3
routes/web.php

@ -53,7 +53,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject');
$router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen');
$router->post('/project/search', 'ProjectController@searchCustom');
$router->post('/project/search', 'ProjectController@search');
$router->post('/project/add', 'ProjectController@add');
$router->put('/project/update/{id}', 'ProjectController@update');
$router->get('/project/edit/{id}', 'ProjectController@edit');
@ -236,6 +236,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/comment-activity/list', 'CommentActivityController@list');
$router->post('/presence/add', 'PresenceController@add');
$router->post('/presence/test', 'PresenceController@checkLocationTest');
$router->get('/presence/edit/{id}', 'PresenceController@edit');
$router->put('/presence/update/{id}', 'PresenceController@update');
$router->post('/presence/search', 'PresenceController@search');

Loading…
Cancel
Save