|
|
@ -1,14 +1,16 @@ |
|
|
|
<?php |
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers; |
|
|
|
namespace App\Http\Controllers; |
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Http; |
|
|
|
|
|
|
|
use App\Models\UserToActivity; |
|
|
|
|
|
|
|
use App\Models\Activity; |
|
|
|
use App\Models\Activity; |
|
|
|
|
|
|
|
use App\Models\UserToProyek; |
|
|
|
use App\Models\AssignMaterial; |
|
|
|
use App\Models\AssignMaterial; |
|
|
|
use Laravel\Lumen\Routing\Controller as BaseController; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use App\Models\ReportK3Detail; |
|
|
|
use App\Models\ReportK3Detail; |
|
|
|
|
|
|
|
use App\Models\UserToActivity; |
|
|
|
|
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Http; |
|
|
|
|
|
|
|
use Laravel\Lumen\Routing\Controller as BaseController; |
|
|
|
|
|
|
|
|
|
|
|
class Controller extends BaseController |
|
|
|
class Controller extends BaseController |
|
|
|
{ |
|
|
|
{ |
|
|
@ -16,8 +18,10 @@ class Controller extends BaseController |
|
|
|
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 = [ |
|
|
|
'sixth', 'seventh', 'eighth', 'ninth', 'tenth']; |
|
|
|
'first', 'second', 'third', 'fourth', 'fifth', |
|
|
|
|
|
|
|
'sixth', 'seventh', 'eighth', 'ninth', 'tenth' |
|
|
|
|
|
|
|
]; |
|
|
|
protected $currentDate; |
|
|
|
protected $currentDate; |
|
|
|
protected $currentName; |
|
|
|
protected $currentName; |
|
|
|
protected $currentId; |
|
|
|
protected $currentId; |
|
|
@ -33,6 +37,74 @@ class Controller extends BaseController |
|
|
|
$this->pathActivityDocument = config('assets.activity'); |
|
|
|
$this->pathActivityDocument = config('assets.activity'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function setUpPayloadByUser($condition) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$alias = "utp"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$userProyek = UserToProyek::from('assign_hr_to_proyek AS ' . $alias); |
|
|
|
|
|
|
|
$userProyek = $userProyek->where([ |
|
|
|
|
|
|
|
['is_customer', true], |
|
|
|
|
|
|
|
// $condition['user_id']['user_id'] |
|
|
|
|
|
|
|
['user_id', 1561] |
|
|
|
|
|
|
|
])->select('m_proyek.*', 'm_type_proyek.name AS nama_type_proyek'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($condition['joins'])) { |
|
|
|
|
|
|
|
$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) { |
|
|
|
|
|
|
|
$userProyek = $userProyek->addSelect($tableName . "." . $sColumn . " as join_" . $this->listJoinAll[$no] . "_" . $sColumn); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$userProyek = $userProyek->leftJoin($tableName, $tableJoin . "." . $columnJoin, '=', $tableName . '.' . $columnSelf); |
|
|
|
|
|
|
|
$no++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$userProyek->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($condition['columns'])) { |
|
|
|
|
|
|
|
$listWhere = $condition['columns']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$userProyek = $userProyek->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'])) { |
|
|
|
|
|
|
|
$userProyek = $this->groupWhere($userProyek, $condition['group_column'], $alias); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data['count'] = clone $userProyek; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($condition['paging'])) { |
|
|
|
|
|
|
|
$userProyek = $userProyek->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) { |
|
|
|
|
|
|
|
$userProyek = $userProyek->orderBy($alias . "." . $column, $sortBy); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$data['userProyek'] = $userProyek; |
|
|
|
|
|
|
|
return $data; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected function setUpPayload($condition, $tableSelf) |
|
|
|
protected function setUpPayload($condition, $tableSelf) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$alias = "selfTable"; |
|
|
|
$alias = "selfTable"; |
|
|
@ -175,7 +247,8 @@ class Controller extends BaseController |
|
|
|
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]); |
|
|
@ -216,7 +289,8 @@ class Controller extends BaseController |
|
|
|
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; |
|
|
@ -264,7 +338,8 @@ class Controller extends BaseController |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
@ -274,7 +349,8 @@ class Controller extends BaseController |
|
|
|
return $response; |
|
|
|
return $response; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private function curlRequest($url){ |
|
|
|
private function curlRequest($url) |
|
|
|
|
|
|
|
{ |
|
|
|
$ch = curl_init(); |
|
|
|
$ch = curl_init(); |
|
|
|
// $headers = [ |
|
|
|
// $headers = [ |
|
|
|
// 'Authorization: '.$token |
|
|
|
// 'Authorization: '.$token |
|
|
@ -291,7 +367,8 @@ class Controller extends BaseController |
|
|
|
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, |
|
|
|