Browse Source

Merge pull request 'staging' (#136) from staging into master

Reviewed-on: ordo/adw-backend#136
pull/3/head
ibnu 1 year ago
parent
commit
3678d9a0ed
  1. 76
      app/Http/Controllers/Controller.php
  2. 2
      app/Http/Controllers/HumanResourceController.php
  3. 141
      app/Http/Controllers/PresenceController.php
  4. 56
      app/Http/Controllers/ProjectController.php
  5. 4
      app/Models/Activity.php
  6. 4
      app/Models/Project.php
  7. 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;

2
app/Http/Controllers/HumanResourceController.php

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

141
app/Http/Controllers/PresenceController.php

@ -263,33 +263,136 @@ class PresenceController extends Controller
foreach($geom as $dataGeom){
$valGeom = json_decode($dataGeom->geom);
if($params->clock_in_out['type']=="out"){
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'),
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{
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'),
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
);
}
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 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"));
}
}
}
// 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
);
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(

56
app/Http/Controllers/ProjectController.php

@ -214,24 +214,48 @@ 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()
{
$data = Project::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();
if(!$data)
@ -254,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/Activity.php

@ -71,8 +71,8 @@ class Activity extends Model
$data->updateCostPlanning();
if($data->bobot_planning){
$data->updatePersentaseProgress();
$data->updateCostActual();
}
$data->updateCostActual();
// if($data->start_date != request()->start_date || $data->end_date != request()->end_date) {
// $data->updateStartEndDateHeader();
// }
@ -86,8 +86,8 @@ class Activity extends Model
$data->updateCostPlanning();
if($data->bobot_planning){
$data->updatePersentaseProgress();
$data->updateCostActual();
}
$data->updateCostActual();
$data->updateStartEndDateHeader();
});

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