Browse Source

update logic search

pull/3/head
ibnu 1 year ago
parent
commit
523f076def
  1. 72
      app/Http/Controllers/Controller.php
  2. 2
      app/Http/Controllers/HumanResourceController.php
  3. 79
      app/Http/Controllers/PresenceController.php
  4. 39
      app/Http/Controllers/ProjectController.php
  5. 4
      app/Models/Activity.php
  6. 3
      routes/web.php

72
app/Http/Controllers/Controller.php

@ -34,71 +34,6 @@ class Controller extends BaseController
} }
protected function setUpPayload($condition, $tableSelf) 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"; $alias = "selfTable";
$builder = DB::table($tableSelf." AS ".$alias); $builder = DB::table($tableSelf." AS ".$alias);
@ -108,8 +43,11 @@ class Controller extends BaseController
foreach($condition['select'] as $select){ foreach($condition['select'] as $select){
$builder = $builder->addSelect($alias.".".$select); $builder = $builder->addSelect($alias.".".$select);
} }
}else{
$builder = $builder->addSelect($alias.".*");
} }
if(isset($condition['joins'])){ if(isset($condition['joins'])){
$selectColumn = [];
$no = 0; $no = 0;
foreach($condition['joins'] as $join){ foreach($condition['joins'] as $join){
$tableJoin = isset($join['name1']) ? $join['name1'] : $alias; $tableJoin = isset($join['name1']) ? $join['name1'] : $alias;
@ -161,15 +99,11 @@ class Controller extends BaseController
$builder = $builder->orderBy($alias.".".$column, $sortBy); $builder = $builder->orderBy($alias.".".$column, $sortBy);
} }
} }
}else{
$builder = $builder->select($alias.".*");
} }
$data['builder'] = $builder; $data['builder'] = $builder;
return $data; return $data;
} }
private function groupWhere($oldBuilder, $groupWhere, $alias) private function groupWhere($oldBuilder, $groupWhere, $alias)
{ {
$builder = $oldBuilder; $builder = $oldBuilder;

2
app/Http/Controllers/HumanResourceController.php

@ -112,7 +112,7 @@ class HumanResourceController extends Controller
public function list() public function list()
{ {
$data = HumanResource::all(); $data = HumanResource::select('id', 'name')->get();
$countData = $data->count(); $countData = $data->count();
if($data){ if($data){

79
app/Http/Controllers/PresenceController.php

@ -301,6 +301,85 @@ class PresenceController extends Controller
return $temp; 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(
"activity_id" => null,
"boundary" => false,
"status_assign" => false
);
}
return $temp;
}
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);

39
app/Http/Controllers/ProjectController.php

@ -218,7 +218,44 @@ class ProjectController extends Controller
public function list() public function list()
{ {
$data = Project::select("id", "nama", "kode_sortname")->orderBy('id', 'desc')->get(); $data = Project::select(
'id',
'kode_sortname',
'jumlah_stakeholder',
'nama',
'mulai_proyek',
'akhir_proyek',
'area_kerja',
'lokasi_kantor',
'rencana_biaya',
'biaya_actual',
'company',
'pm_id',
'type_proyek_id',
'divisi_id',
'persentase_progress',
'keterangan',
'durasi_proyek',
'progress_by_worklog',
'status',
'currency_symbol',
'currency_code',
'currency_name',
'project_objectives',
'considered_success_when',
'potential_risk',
'testing_environment',
'currency_code',
'currency_symbol',
'currency_name',
'budget_health',
'phase_id',
'calculation_status',
'created_at',
'created_by',
'updated_at',
'updated_by'
)->orderBy('id', 'desc')->get();
$countData = $data->count(); $countData = $data->count();
if(!$data) if(!$data)

4
app/Models/Activity.php

@ -71,8 +71,8 @@ class Activity extends Model
$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();
// } // }
@ -86,8 +86,8 @@ class Activity extends Model
$data->updateCostPlanning(); $data->updateCostPlanning();
if($data->bobot_planning){ if($data->bobot_planning){
$data->updatePersentaseProgress(); $data->updatePersentaseProgress();
$data->updateCostActual();
} }
$data->updateCostActual();
$data->updateStartEndDateHeader(); $data->updateStartEndDateHeader();
}); });

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->post('/document-activity/search', 'ActivityDokumenController@searchDocProject');
$router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen'); $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->post('/project/add', 'ProjectController@add');
$router->put('/project/update/{id}', 'ProjectController@update'); $router->put('/project/update/{id}', 'ProjectController@update');
$router->get('/project/edit/{id}', 'ProjectController@edit'); $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->get('/comment-activity/list', 'CommentActivityController@list');
$router->post('/presence/add', 'PresenceController@add'); $router->post('/presence/add', 'PresenceController@add');
$router->post('/presence/test', 'PresenceController@checkLocationTest');
$router->get('/presence/edit/{id}', 'PresenceController@edit'); $router->get('/presence/edit/{id}', 'PresenceController@edit');
$router->put('/presence/update/{id}', 'PresenceController@update'); $router->put('/presence/update/{id}', 'PresenceController@update');
$router->post('/presence/search', 'PresenceController@search'); $router->post('/presence/search', 'PresenceController@search');

Loading…
Cancel
Save