Browse Source

update API Presence and K3

pull/3/head
ibnu 2 years ago
parent
commit
5f2d7154df
  1. 18
      app/Http/Controllers/Controller.php
  2. 146
      app/Http/Controllers/PresenceController.php
  3. 15
      app/Http/Controllers/ReportK3Controller.php
  4. 1
      app/Models/HumanResource.php
  5. 2218
      rest-client.http
  6. 1
      routes/web.php

18
app/Http/Controllers/Controller.php

@ -3,9 +3,10 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Laravel\Lumen\Routing\Controller as BaseController; use Laravel\Lumen\Routing\Controller as BaseController;
use App\Models\ReportK3Detail;
class Controller extends BaseController class Controller extends BaseController
{ {
protected $pathImage = "assets/image/"; protected $pathImage = "assets/image/";
@ -211,7 +212,7 @@ class Controller extends BaseController
return $query; return $query;
} }
protected function calculateAllCost($activity, $proyek_id){ protected function calculateAllCost($activity_id, $proyek_id){
$humanCostPlanning = $this->calculateAllHumanCost($activity_id, $proyek_id); $humanCostPlanning = $this->calculateAllHumanCost($activity_id, $proyek_id);
$materialCostPlanning = $this->calculateMaterialCost($activity_id, $proyek_id); $materialCostPlanning = $this->calculateMaterialCost($activity_id, $proyek_id);
$toolsCostPlanning = 0; $toolsCostPlanning = 0;
@ -278,4 +279,17 @@ class Controller extends BaseController
return json_decode($response); return json_decode($response);
} }
protected function addDetailK3($dataDetail, $report_id){
foreach ($dataDetail as $value) {
$dataNew = array(
"report_k3_id"=>$report_id,
"checklist_k3_id"=>$value['checklist_id'],
"name_checklist_k3"=>$value['checklist_name'],
"created_by"=>$this->currentName
);
ReportK3Detail::create($dataNew);
}
}
} }

146
app/Http/Controllers/PresenceController.php

@ -5,9 +5,7 @@ namespace App\Http\Controllers;
use Log; use Log;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Presence; use App\Models\Presence;
// use App\Models\Activity; use App\Models\ReportK3;
// use GuzzleHttp\Client;
// use Illuminate\Support\Facades\Http;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -23,9 +21,7 @@ class PresenceController extends Controller
$statusBoundary = false; $statusBoundary = false;
$date = date_create($request->clock_time); $date = date_create($request->clock_time);
// assign and in boundary // assign and in boundary
if(count($checkLocation) > 0 && $checkLocation[0]['boundary']){ if(count($checkLocation) > 0 && $checkLocation[0]['boundary']){
// $checkLocation[0]['status_assign'] ? $statusBoundary = true
// :
$statusBoundary = true; $statusBoundary = true;
} }
@ -124,23 +120,151 @@ class PresenceController extends Controller
} }
} }
public function reportK3(Request $request){
// return response()->json(['status'=>'success', 'message'=>$request->report_k3['detail'],'code'=>200], 200);
$this->validate($request, [
'user_id' => 'required'
]);
$dataFormK3 = array(
"user_id" => $request->user_id,
"proyek_id" => $request->report_k3['proyek_id'],
"report_date" => $request->time,
"description" => $request->report_k3['description']
);
$checkLocation = $this->checkLocation($request);
$statusBoundary = false;
$date = date_create($request->time);
// assign and in boundary
if(count($checkLocation) > 0 && $checkLocation[0]['boundary']){
$statusBoundary = true;
}
// not assign
if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){
$data=array(
'id' => null,
'boundary' => $statusBoundary
);
return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda belum di assign ke area kerja.','code'=>200], 200);
}
// assign and not in boundary
if($checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){
$data=array(
'id' => null,
'boundary' => true
);
return response()->json(['status'=>'failed', 'data'=>$data, 'message'=>'Tidak dapat melakukan presensi. Anda berada di luar area kerja.','code'=>200], 200);
}
if($request->clock_in_out['type']=="out"){
$clock_out_loc = $this->getLoc($request->clock_in_out['clock_out_lat'], $request->clock_in_out['clock_out_lng'])->display_name;
$dataUpdate = array(
"clock_out"=>$request->time,
"clock_out_lat" => $request->clock_in_out['clock_out_lat'],
"clock_out_lng" => $request->clock_in_out['clock_out_lng'],
"updated_by"=>$this->currentName,
"clock_out_loc" => $clock_out_loc,
"clock_out_boundary" => $statusBoundary
);
$resultUpdate = $this->updateFormAdd($dataUpdate, $request->user_id);
if($resultUpdate && $resultUpdate > 0){
if($statusBoundary){
for ($i=0; $i < count($checkLocation); $i++) {
# code...
DB::table('clock_in_out_boundary')->insert([
"clock_in_out_id" => $resultUpdate,
"user_id" => $request->user_id,
"activity_id" => $checkLocation[$i]['activity_id'],
"type" => $request->clock_in_out['type'],
"created_at" => $date,
"created_by" => $this->currentName
]);
};
};
$data=array(
'presence_id' => $resultUpdate,
'boundary' => $statusBoundary
);
return response()->json(['status'=>'success', 'data'=>$data,'message'=>'clock out success!','code'=>200], 200);
}
else{
return response()->json(['status'=>'failed','message'=>'clock out failed please try again!','code'=>400], 400);
}
die();
}
$onlyDate = date_format($date,"Y-m-d");
$clock_in_loc = $this->getLoc($request->clock_in_out['clock_in_lat'], $request->clock_in_out['clock_in_lng'])->display_name;
$dataFormPresence = array(
'user_id' => $request->user_id,
'clock_in' => $request->time,
'date_presence' => $onlyDate,
'created_by' => $this->currentName,
'clock_in_lat' => $request->clock_in_out['clock_in_lat'],
'clock_in_lng' => $request->clock_in_out['clock_in_lng'],
'clock_in_loc' => $clock_in_loc,
'clock_in_boundary' => $statusBoundary
);
$result = Presence::create($dataFormPresence);
$data=array(
'presence_id' => $result->id,
'boundary' => $statusBoundary
);
if($result){
if($statusBoundary){
$insertk3 = $this->insertK3($dataFormK3, $request->report_k3['detail']) ;
for ($i=0; $i < count($checkLocation); $i++) {
# code...
DB::table('clock_in_out_boundary')->insert([
"clock_in_out_id" => $result->id,
"user_id" => $request->user_id,
"activity_id" => $checkLocation[$i]['activity_id'],
"type" => $request->type,
"created_at" => $date,
"created_by" => $this->currentName
]);
};
$data['report_id'] = $insertk3->id;
};
return response()->json(['status'=>'success', 'data'=> $data, 'message'=>'clock in successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'clock in failed!','code'=>400], 400);
}
}
private function insertK3($params, $details){
$insert = ReportK3::create($params);
if($insert && $details){
$this->addDetailK3($details, $insert->id);
}
return $insert;
}
private function checkLocation($params){ private function checkLocation($params){
// cek user tersebut apakah punya assign task yang ada bondary nya // cek user tersebut apakah punya assign task yang ada bondary nya
// geom ada di table activity // geom ada di table activity
// $clock_time =
$geom = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id") $geom = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id")
->join("m_activity as ma", "ma.id", "=", "ahta.activity_id") ->join("m_activity as ma", "ma.id", "=", "ahta.activity_id")
->where("ahta.user_id", $params->user_id) ->where("ahta.user_id", $params->user_id)
->whereDate("ma.start_date", "<=", $params->clock_time) ->whereDate("ma.start_date", "<=", $params->time)
->whereDate("ma.end_date", ">=", $params->clock_time) ->whereDate("ma.end_date", ">=", $params->time)
->get(); ->get();
$temp = []; $temp = [];
if (count($geom) > 0) { if (count($geom) > 0) {
foreach($geom as $dataGeom){ foreach($geom as $dataGeom){
$valGeom = json_decode($dataGeom->geom); $valGeom = json_decode($dataGeom->geom);
if($params->type=="out"){ if($params->clock_in_out['type']=="out"){
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), ST_GeomFromText('POINT(".$params->clock_out_lng." ".$params->clock_out_lat.")', 4326)) as boundary")); $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{ }else{
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_lng." ".$params->clock_in_lat.")', 4326)) as boundary")); $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"));
} }
foreach ($check as $key) { foreach ($check as $key) {
// assign and in boundary // assign and in boundary

15
app/Http/Controllers/ReportK3Controller.php

@ -8,7 +8,7 @@ use App\Models\ReportK3Detail;
use App\Models\ProjectToChecklistK3; use App\Models\ProjectToChecklistK3;
use App\Models\ChecklistK3; use App\Models\ChecklistK3;
use App\Models\Image; use App\Models\Image;
use DB; use Illuminate\Support\Facades\DB;
class ReportK3Controller extends Controller class ReportK3Controller extends Controller
{ {
@ -35,19 +35,6 @@ class ReportK3Controller extends Controller
return response()->json(['status'=>'failed','message'=>'add data report k3 failed!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'add data report k3 failed!','code'=>400], 400);
} }
} }
private function addDetailK3($dataDetail, $report_id){
foreach ($dataDetail as $value) {
$dataNew = array(
"report_k3_id"=>$report_id,
"checklist_k3_id"=>$value['checklist_id'],
"name_checklist_k3"=>$value['checklist_name'],
"created_by"=>$this->currentName
);
ReportK3Detail::create($dataNew);
}
}
public function edit($id){ public function edit($id){
if(!$id || (int) $id < 0 || $id==""){ if(!$id || (int) $id < 0 || $id==""){

1
app/Models/HumanResource.php

@ -34,6 +34,5 @@ class HumanResource extends Model
'updated_by', 'updated_by',
'divisi_id', 'divisi_id',
'status_boundary' 'status_boundary'
]; ];
} }

2218
rest-client.http

File diff suppressed because it is too large Load Diff

1
routes/web.php

@ -230,6 +230,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->delete('/presence/delete/{id}', 'PresenceController@delete'); $router->delete('/presence/delete/{id}', 'PresenceController@delete');
$router->get('/presence/list', 'PresenceController@list'); $router->get('/presence/list', 'PresenceController@list');
$router->get('/presence/clockinout/{id}', 'PresenceController@clockinout'); $router->get('/presence/clockinout/{id}', 'PresenceController@clockinout');
$router->post('/presence/reportk3', 'PresenceController@reportK3');
$router->get('/presence/bulk-update-location', 'PresenceController@bulkUpdateLocation'); $router->get('/presence/bulk-update-location', 'PresenceController@bulkUpdateLocation');
$router->post('/permit/add', 'AbsentController@add'); $router->post('/permit/add', 'AbsentController@add');

Loading…
Cancel
Save