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