Browse Source

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

Reviewed-on: ordo/adw-backend#180
pull/3/head
ibnu 1 year ago
parent
commit
e1b8d89558
  1. 13
      app/Http/Controllers/BroadcastController.php
  2. 626
      app/Http/Controllers/Controller.php
  3. 36
      app/Http/Controllers/ProjectController.php
  4. 38
      app/Models/UserToProyek.php
  5. 3
      routes/web.php

13
app/Http/Controllers/BroadcastController.php

@ -15,6 +15,12 @@ class BroadcastController extends Controller
$data = $request->all(); $data = $request->all();
$data['status_send'] = true; $data['status_send'] = true;
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
if (isset($data['send_to_id'])) {
$idArray = $data['send_to_id'];
if (is_array($data['send_to_id'])) {
$data['send_to_id'] = implode(", ", $idArray);
}
}
// dd($data); // dd($data);
$result = Broadcast::create($data); $result = Broadcast::create($data);
if($result){ if($result){
@ -140,8 +146,10 @@ class BroadcastController extends Controller
} }
break; break;
case 'user': case 'users':
$user = User::where("id", $data['send_to_id'])->whereNotNull('fcm_token')->first(); $idArray = explode(", ", $data['send_to_id']);
foreach ($idArray as $key => $value) {
$user = User::where("id", $value)->whereNotNull('fcm_token')->first();
if (isset($user)) { if (isset($user)) {
FCMService::send( FCMService::send(
$user->fcm_token, $user->fcm_token,
@ -151,6 +159,7 @@ class BroadcastController extends Controller
] ]
); );
} }
}
break; break;
default: default:

626
app/Http/Controllers/Controller.php

@ -1,313 +1,313 @@
<?php <?php
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 App\Models\UserToActivity; use App\Models\UserToActivity;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use Laravel\Lumen\Routing\Controller as BaseController; use Laravel\Lumen\Routing\Controller as BaseController;
use App\Models\ReportK3Detail; use App\Models\ReportK3Detail;
class Controller extends BaseController class Controller extends BaseController
{ {
protected $pathImage = "assets/image/"; protected $pathImage = "assets/image/";
protected $pathDocument = "assets/file/project/"; protected $pathDocument = "assets/file/project/";
protected $pathTmpImport = "assets/file/tmpimport/"; protected $pathTmpImport = "assets/file/tmpimport/";
protected $pathActivityDocument = "assets/file/activity/"; protected $pathActivityDocument = "assets/file/activity/";
protected $listJoinAll = ['first', 'second', 'third', 'fourth', 'fifth', protected $listJoinAll = ['first', 'second', 'third', 'fourth', 'fifth',
'sixth', 'seventh', 'eighth', 'ninth', 'tenth']; 'sixth', 'seventh', 'eighth', 'ninth', 'tenth'];
protected $currentDate; protected $currentDate;
protected $currentName; protected $currentName;
protected $currentId; protected $currentId;
public function __construct() public function __construct()
{ {
$this->currentDate = date("Y-m-d H:i:s"); $this->currentDate = date("Y-m-d H:i:s");
$this->currentName = auth()->user() ? auth()->user()->name : "system"; $this->currentName = auth()->user() ? auth()->user()->name : "system";
$this->currentId = auth()->user() ? auth()->user()->id : 0; $this->currentId = auth()->user() ? auth()->user()->id : 0;
$this->pathImage = config('assets.image'); $this->pathImage = config('assets.image');
$this->pathDocument = config('assets.project'); $this->pathDocument = config('assets.project');
$this->pathActivityDocument = config('assets.activity'); $this->pathActivityDocument = config('assets.activity');
} }
protected function setUpPayload($condition, $tableSelf) protected function setUpPayload($condition, $tableSelf)
{ {
$alias = "selfTable"; $alias = "selfTable";
$builder = DB::table($tableSelf." AS ".$alias); $builder = DB::table($tableSelf." AS ".$alias);
// $builder = $builder->select($alias.".*"); // $builder = $builder->select($alias.".*");
if($condition){ if($condition){
if(isset($condition['select'])){ if(isset($condition['select'])){
foreach($condition['select'] as $select){ foreach($condition['select'] as $select){
$builder = $builder->addSelect($alias.".".$select); $builder = $builder->addSelect($alias.".".$select);
} }
}else{ }else{
$builder = $builder->addSelect($alias.".*"); $builder = $builder->addSelect($alias.".*");
} }
if(isset($condition['joins'])){ if(isset($condition['joins'])){
$selectColumn = []; $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;
$tableName = $join['name']; $tableName = $join['name'];
$columnJoin = $join['column_join']; // foreign key table sini $columnJoin = $join['column_join']; // foreign key table sini
$columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan $columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan
$columnResult = $join['column_results']; $columnResult = $join['column_results'];
foreach($columnResult as $sColumn){ foreach($columnResult as $sColumn){
$builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn); $builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn);
} }
$builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf); $builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf);
$no++; $no++;
} }
} }
if(isset($condition['columns'])){ if(isset($condition['columns'])){
$listWhere = $condition['columns']; $listWhere = $condition['columns'];
$builder = $builder->where(function ($query) use($listWhere, $alias){ $builder = $builder->where(function ($query) use($listWhere, $alias){
foreach($listWhere as $where){ foreach($listWhere as $where){
$value = $where['value']; $value = $where['value'];
if($value && $value!="" && $value!=" "){ if($value && $value!="" && $value!=" "){
$column = $where['name']; $column = $where['name'];
$operator = strtolower($where['logic_operator']); // like, =, <>, range $operator = strtolower($where['logic_operator']); // like, =, <>, range
$value2 = isset($where['value1']) ? $where['value1'] : ""; $value2 = isset($where['value1']) ? $where['value1'] : "";
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias;
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
} }
} }
}); });
} }
if(isset($condition['group_column'])){ if(isset($condition['group_column'])){
$builder = $this->groupWhere($builder, $condition['group_column'], $alias); $builder = $this->groupWhere($builder, $condition['group_column'], $alias);
} }
$data['count'] = clone $builder; $data['count'] = clone $builder;
if(isset($condition['paging'])){ if(isset($condition['paging'])){
$builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']); $builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']);
} }
if(isset($condition['orders'])){ if(isset($condition['orders'])){
$orders = $condition['orders']; $orders = $condition['orders'];
$sortBy = $orders['ascending'] ? "ASC" : "DESC"; $sortBy = $orders['ascending'] ? "ASC" : "DESC";
$columnOrder = $orders['columns']; $columnOrder = $orders['columns'];
foreach($columnOrder as $column){ foreach($columnOrder as $column){
$builder = $builder->orderBy($alias.".".$column, $sortBy); $builder = $builder->orderBy($alias.".".$column, $sortBy);
} }
} }
} }
$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;
$listGroupWhere = $groupWhere; $listGroupWhere = $groupWhere;
$operator = $listGroupWhere['operator']; $operator = $listGroupWhere['operator'];
$operatorGroup = $listGroupWhere['group_operator']; $operatorGroup = $listGroupWhere['group_operator'];
$listWhere = $listGroupWhere['where']; $listWhere = $listGroupWhere['where'];
if(strtolower($operator)=="and"){ if(strtolower($operator)=="and"){
$builder = $builder->where(function($query) use($operatorGroup, $listWhere, $alias){ $builder = $builder->where(function($query) use($operatorGroup, $listWhere, $alias){
$no = 1; $no = 1;
foreach ($listWhere as $where) { foreach ($listWhere as $where) {
$value = $where['value']; $value = $where['value'];
$column = $where['name']; $column = $where['name'];
$operator = strtolower($where['logic_operator']); $operator = strtolower($where['logic_operator']);
$value2 = isset($where['value1']) ? $where['value1'] : ""; $value2 = isset($where['value1']) ? $where['value1'] : "";
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias;
if($value && $value!="" && $value!=" "){ if($value && $value!="" && $value!=" "){
if($operatorGroup=="and"){ if($operatorGroup=="and"){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{ }else{
if($no==1){ if($no==1){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{ }else{
$query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2); $query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2);
} }
} }
} }
$no = $no+1; $no = $no+1;
} }
}); });
}else if(strtolower($operator)=="or"){ }else if(strtolower($operator)=="or"){
$builder = $builder->orWhere(function($query) use($operatorGroup, $listWhere, $alias){ $builder = $builder->orWhere(function($query) use($operatorGroup, $listWhere, $alias){
$no = 1; $no = 1;
foreach ($listWhere as $where) { foreach ($listWhere as $where) {
$value = $where['value']; $value = $where['value'];
$column = $where['name']; $column = $where['name'];
$operator = strtolower($where['logic_operator']); $operator = strtolower($where['logic_operator']);
$value2 = isset($where['value1']) ? $where['value1'] : ""; $value2 = isset($where['value1']) ? $where['value1'] : "";
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias; $tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias;
if($value && $value!="" && $value!=" "){ if($value && $value!="" && $value!=" "){
if($operatorGroup=="and"){ if($operatorGroup=="and"){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{ }else{
if($no==1){ if($no==1){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2); $query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{ }else{
$query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2); $query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2);
} }
} }
} }
$no++; $no++;
} }
}); });
} }
return $builder; return $builder;
} }
private function whereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2) private function whereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2)
{ {
$query = $oldQuery; $query = $oldQuery;
if($operator=="range"){ if($operator=="range"){
$query = $query->whereBetween($tableColumn.".".$column, [$value, $value2]); $query = $query->whereBetween($tableColumn.".".$column, [$value, $value2]);
}else if($operator=="like"){ }else if($operator=="like"){
$query = $query->where($tableColumn.".".$column, 'like', '%'.$value.'%'); $query = $query->where($tableColumn.".".$column, 'like', '%'.$value.'%');
}else if($operator=="ilike"){ }else if($operator=="ilike"){
$query = $query->where($tableColumn.".".$column, '~*', $value); $query = $query->where($tableColumn.".".$column, '~*', $value);
}else if($operator=="="){ }else if($operator=="="){
$query = $query->where($tableColumn.".".$column, $value); $query = $query->where($tableColumn.".".$column, $value);
}else if($operator=="in"){ }else if($operator=="in"){
$query = $query->whereIn($tableColumn.".".$column, $value); $query = $query->whereIn($tableColumn.".".$column, $value);
}else if($operator=="notin"){ }else if($operator=="notin"){
$query = $query->whereNotIn($tableColumn.".".$column, $value); $query = $query->whereNotIn($tableColumn.".".$column, $value);
}else{ }else{
$query = $query->where($tableColumn.".".$column, $operator, $value); $query = $query->where($tableColumn.".".$column, $operator, $value);
} }
return $query; return $query;
} }
private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2){ private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2){
$query = $oldQuery; $query = $oldQuery;
if($operator=="range"){ if($operator=="range"){
$query = $query->whereBetween($column, [$value, $value2]); $query = $query->whereBetween($column, [$value, $value2]);
}else if($operator=="like"){ }else if($operator=="like"){
$query = $query->where($column, 'like', '%'.$value.'%'); $query = $query->where($column, 'like', '%'.$value.'%');
}else if($operator=="ilike"){ }else if($operator=="ilike"){
$query = $query->where($column, '~*', $value); $query = $query->where($column, '~*', $value);
}else if($operator=="="){ }else if($operator=="="){
$query = $query->where($column, $value); $query = $query->where($column, $value);
}else if($operator=="in"){ }else if($operator=="in"){
$query = $query->whereIn($column, $value); $query = $query->whereIn($column, $value);
}else if($operator=="notin"){ }else if($operator=="notin"){
$query = $query->whereNotIn($column, $value); $query = $query->whereNotIn($column, $value);
}else{ }else{
$query = $query->where($column, $operator, $value); $query = $query->where($column, $operator, $value);
} }
return $query; return $query;
} }
private function orWhereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2) private function orWhereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2)
{ {
$query = $oldQuery; $query = $oldQuery;
if($operator=="range"){ if($operator=="range"){
$query = $query->orWhereBetween($tableColumn.".".$column, [$value, $value2]); $query = $query->orWhereBetween($tableColumn.".".$column, [$value, $value2]);
}else if($operator=="like"){ }else if($operator=="like"){
$query = $query->orWhere($tableColumn.".".$column, 'like', '%'.$value.'%'); $query = $query->orWhere($tableColumn.".".$column, 'like', '%'.$value.'%');
}else if($operator=="ilike"){ }else if($operator=="ilike"){
$query = $query->where($tableColumn.".".$column, '~*', $value); $query = $query->where($tableColumn.".".$column, '~*', $value);
}else if($operator=="="){ }else if($operator=="="){
$query = $query->orWhere($tableColumn.".".$column, $value); $query = $query->orWhere($tableColumn.".".$column, $value);
}else if($operator=="in"){ }else if($operator=="in"){
$query = $query->orWhereIn($tableColumn.".".$column, $value); $query = $query->orWhereIn($tableColumn.".".$column, $value);
}else if($operator=="notin"){ }else if($operator=="notin"){
$query = $query->orWhereNotIn($tableColumn.".".$column, $value); $query = $query->orWhereNotIn($tableColumn.".".$column, $value);
}else{ }else{
$query = $query->orWhere($tableColumn.".".$column, $operator, $value); $query = $query->orWhere($tableColumn.".".$column, $operator, $value);
} }
return $query; return $query;
} }
protected function calculateAllCost($activity_id, $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;
$allCost = $humanCostPlanning + $materialCostPlanning + $toolsCostPlanning; $allCost = $humanCostPlanning + $materialCostPlanning + $toolsCostPlanning;
return $allCost; return $allCost;
} }
private function calculateAllHumanCost($activity_id, $proyek_id) private function calculateAllHumanCost($activity_id, $proyek_id)
{ {
$dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate","ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate") $dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate","ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate")
->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id") ->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id")
->where("assign_hr_to_activity.activity_id", $activity_id)->where("assign_hr_to_activity.proyek_id", $proyek_id) ->where("assign_hr_to_activity.activity_id", $activity_id)->where("assign_hr_to_activity.proyek_id", $proyek_id)
->where("ahp.proyek_id", $proyek_id) ->where("ahp.proyek_id", $proyek_id)
->get(); ->get();
$totalCost = 0; $totalCost = 0;
foreach ($dataHuman as $human) { foreach ($dataHuman as $human) {
$totalCost += $this->calculateHumanCost($human, $activity_id); $totalCost += $this->calculateHumanCost($human, $activity_id);
} }
return $totalCost; return $totalCost;
} }
private function calculateHumanCost($human, $activity_id) private function calculateHumanCost($human, $activity_id)
{ {
$activity = Activity::find($activity_id); $activity = Activity::find($activity_id);
$duration = $activity->duration; $duration = $activity->duration;
$standarRate = $human->standart_rate; $standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100; $maxUsed = $human->max_used/100;
if ($human->uom_standart_rate == "Hour") { if ($human->uom_standart_rate == "Hour") {
$totalCost = ($standarRate*8*$duration)*$maxUsed; $totalCost = ($standarRate*8*$duration)*$maxUsed;
return $totalCost; return $totalCost;
} }
$totalCost = ($standarRate*$duration)*$maxUsed; $totalCost = ($standarRate*$duration)*$maxUsed;
return $totalCost; return $totalCost;
} }
private function calculateMaterialCost($activity_id, $proyek_id) private function calculateMaterialCost($activity_id, $proyek_id)
{ {
$totalCost = AssignMaterial::selectRaw("COALESCE(qty_planning,0)*COALESCE(budget,0) as totalCost") $totalCost = AssignMaterial::selectRaw("COALESCE(qty_planning,0)*COALESCE(budget,0) as totalCost")
->where("proyek_id", $proyek_id) ->where("proyek_id", $proyek_id)
->where("activity_id", $activity_id) ->where("activity_id", $activity_id)
->sum(AssignMaterial::raw("COALESCE(qty_planning, 0) * COALESCE(budget, 0)")); ->sum(AssignMaterial::raw("COALESCE(qty_planning, 0) * COALESCE(budget, 0)"));
return $totalCost; return $totalCost;
} }
protected function getLoc($lat, $lng){ protected function getLoc($lat, $lng){
// $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json"); // $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json");
// return $response->json; // return $response->json;
$url = config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json"; $url = config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json";
// $token = config('api.adw_token'); // $token = config('api.adw_token');
$response = $this->curlRequest($url); $response = $this->curlRequest($url);
return $response; return $response;
} }
private function curlRequest($url){ private function curlRequest($url){
$ch = curl_init(); $ch = curl_init();
// $headers = [ // $headers = [
// 'Authorization: '.$token // 'Authorization: '.$token
// ]; // ];
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch); $response = curl_exec($ch);
if ($response === false) if ($response === false)
$response = curl_error($ch); $response = curl_error($ch);
curl_close($ch); curl_close($ch);
return json_decode($response); return json_decode($response);
} }
protected function addDetailK3($dataDetail, $report_id){ protected function addDetailK3($dataDetail, $report_id){
foreach ($dataDetail as $value) { foreach ($dataDetail as $value) {
$dataNew = array( $dataNew = array(
"report_k3_id"=>$report_id, "report_k3_id"=>$report_id,
"checklist_k3_id"=>$value['checklist_id'], "checklist_k3_id"=>$value['checklist_id'],
"name_checklist_k3"=>$value['checklist_name'], "name_checklist_k3"=>$value['checklist_name'],
"created_by"=>$this->currentName "created_by"=>$this->currentName
); );
ReportK3Detail::create($dataNew); ReportK3Detail::create($dataNew);
} }
} }
} }

36
app/Http/Controllers/ProjectController.php

@ -215,7 +215,7 @@ class ProjectController extends Controller
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} }
public function list() public function list()
{ {
@ -322,12 +322,12 @@ class ProjectController extends Controller
$data = MasterFunctionsHelper::getSCurve($request); $data = MasterFunctionsHelper::getSCurve($request);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200);
} }
public function calculateSCurve(Request $request){ public function calculateSCurve(Request $request){
$sCurve = Project::select('scurve')->where('id', $request->project_id)->first(); $sCurve = Project::select('scurve')->where('id', $request->project_id)->first();
return response()->json(['status'=>'success','code'=>200, 'data' => json_decode($sCurve->scurve)], 200); return response()->json(['status'=>'success','code'=>200, 'data' => json_decode($sCurve->scurve)], 200);
} }
public function sCurveCommand(Request $request){ public function sCurveCommand(Request $request){
Artisan::call('calculate:scurve', [ Artisan::call('calculate:scurve', [
'project_id' => $request->project_id 'project_id' => $request->project_id
@ -342,7 +342,7 @@ class ProjectController extends Controller
// return response()->json(['message' => 'Project not found'], 404); // return response()->json(['message' => 'Project not found'], 404);
} }
public function getLinearSCurve(Request $request){ public function getLinearSCurve(Request $request){
$data = MasterFunctionsHelper::getLinearSCurve($request); $data = MasterFunctionsHelper::getLinearSCurve($request);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200);
@ -400,7 +400,7 @@ class ProjectController extends Controller
if ($successor) { if ($successor) {
$predecessor = Activity::find($successor->s_activity_id); $predecessor = Activity::find($successor->s_activity_id);
$activity->start_date = $predecessor->end_date; $activity->start_date = $predecessor->end_date;
} }
if($reports[$i]['status'] != 'done'){ if($reports[$i]['status'] != 'done'){
$reports[$i]['max_date']->modify('-1 day'); $reports[$i]['max_date']->modify('-1 day');
}else if($reports[$i]['status'] == 'done'){ }else if($reports[$i]['status'] == 'done'){
@ -439,10 +439,26 @@ class ProjectController extends Controller
$response = MasterFunctionsHelper::curlReq($url); $response = MasterFunctionsHelper::curlReq($url);
// return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200);
return response()->json(['status'=>'success', 'data'=> '', 'code'=>200], 200);
} }
public function getByUser($id)
{
$alias = "utp";
$userProyek = UserToProyek::query()
->from('assign_hr_to_proyek AS ' . $alias)
->where([
['is_customer', true],
['user_id', $id]
])
->leftJoin('m_users', $alias.'.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', $alias.'.proyek_id', '=', 'm_proyek.id')
->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
->select('m_proyek.*', 'm_type_proyek.name AS join_second_name','m_users.name AS join_first_name')
->get();
$totalRecord = $userProyek->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
}
public function detail($id){ public function detail($id){
if(empty($id) || !is_int((int)$id)) if(empty($id) || !is_int((int)$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);
@ -483,7 +499,7 @@ class ProjectController extends Controller
$result->header->end_date = $endDate; $result->header->end_date = $endDate;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$gantt], 200); return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$gantt], 200);
} }
public function getOverdueActivities(Request $request){ public function getOverdueActivities(Request $request){
$payload = $request->all(); $payload = $request->all();
if(empty($payload['id']) || !is_int((int)$payload['id'])) if(empty($payload['id']) || !is_int((int)$payload['id']))
@ -532,7 +548,7 @@ class ProjectController extends Controller
->where('ama.proyek_id', '=', $payload['project_id']) ->where('ama.proyek_id', '=', $payload['project_id'])
->whereNotNull('ram.lat') ->whereNotNull('ram.lat')
->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]); ->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]);
return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200); return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200);
} }

38
app/Models/UserToProyek.php

@ -1,19 +1,19 @@
<?php <?php
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class UserToProyek extends Model class UserToProyek extends Model
{ {
protected $table = 'assign_hr_to_proyek'; protected $table = 'assign_hr_to_proyek';
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'user_id', 'proyek_id', 'rbs', 'project_role', 'group_r', 'max_used', 'standart_rate', 'user_id', 'proyek_id', 'rbs', 'project_role', 'group_r', 'max_used', 'standart_rate',
'uom_standart_rate', 'overtime_rate', 'uom_overtime_rate', 'cost_per_used', 'accrue_at', 'uom_standart_rate', 'overtime_rate', 'uom_overtime_rate', 'cost_per_used', 'accrue_at',
'base_calender', 'is_customer', 'created_at', 'created_by', 'updated_at', 'updated_by' 'base_calender', 'is_customer', 'created_at', 'created_by', 'updated_at', 'updated_by'
]; ];
} }

3
routes/web.php

@ -1,7 +1,7 @@
<?php <?php
$router->get('/', function () use ($router) { $router->get('/', function () use ($router) {
return $router->app->version(); return $router->app->version();
}); });
$router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($router) { $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($router) {
@ -53,6 +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->get('/project-by-customer/{id}','ProjectController@getByUser');
$router->post('/project/search', 'ProjectController@search'); $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');

Loading…
Cancel
Save