Browse Source

Merge pull request 'Dev-Farhan' (#53) from Dev-Farhan into staging

Reviewed-on: ibnu/generic-ospro-backend#53
pull/1/head
farhantock 10 months ago
parent
commit
5338ab7191
  1. 17
      app/Http/Controllers/DivisiController.php
  2. 22
      app/Http/Controllers/MenuController.php
  3. 49
      app/Http/Controllers/UserToActivityController.php
  4. 3
      app/Models/Company.php
  5. 2
      app/Models/RoleMenu.php
  6. 17
      app/Models/User.php

17
app/Http/Controllers/DivisiController.php

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Divisi; use App\Models\Divisi;
use Illuminate\Support\Facades\Log;
class DivisiController extends Controller class DivisiController extends Controller
{ {
@ -83,7 +84,11 @@ class DivisiController extends Controller
public function search(Request $request) public function search(Request $request)
{ {
$parentDivisi = Divisi::whereNull('parent')->with('children')->get(); $companyId = $request->input('columns.0.value');
$parentDivisi = Divisi::whereNull('parent')
->where('company_id', $companyId)
->with('children')
->get();
$divisions = []; $divisions = [];
foreach ($parentDivisi as $objRow) { foreach ($parentDivisi as $objRow) {
$objRow->children = $this->getAllChildren($objRow); $objRow->children = $this->getAllChildren($objRow);
@ -95,16 +100,6 @@ class DivisiController extends Controller
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $divisions, 'totalRecord' => $countData], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $divisions, 'totalRecord' => $countData], 200);
// $payload = $request->all();
// $dataBuilder = $this->setUpPayload($payload, 'm_divisi');
// $builder = $dataBuilder['builder'];
// $countBuilder = $dataBuilder['count'];
// $dataGet = $builder->get();
// $totalRecord = $countBuilder->count();
// return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
//return $this->list();
// cant use builder for this case
} }
public function list() public function list()

22
app/Http/Controllers/MenuController.php

@ -30,7 +30,8 @@ class MenuController extends Controller
} }
} }
public function edit($id){ public function edit($id)
{
if (!$id || (int) $id < 0 || $id == "") { if (!$id || (int) $id < 0 || $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);
die(); die();
@ -108,7 +109,13 @@ class MenuController extends Controller
public function listMenu($id) public function listMenu($id)
{ {
$dataParent = RoleMenu::select("m_menu.*") $dataParent = RoleMenu::select(
'm_menu.*',
"t_roles_menu.create",
"t_roles_menu.read",
"t_roles_menu.update",
"t_roles_menu.delete"
)
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->whereNull('m_menu.parent_id') ->whereNull('m_menu.parent_id')
@ -127,7 +134,13 @@ class MenuController extends Controller
protected function getChildrenMenu($id, $role_id) protected function getChildrenMenu($id, $role_id)
{ {
$dataChildren = RoleMenu::select("m_menu.*") $dataChildren = RoleMenu::select(
'm_menu.*',
"t_roles_menu.create",
"t_roles_menu.read",
"t_roles_menu.update",
"t_roles_menu.delete"
)
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->where('m_roles.id', $role_id) ->where('m_roles.id', $role_id)
@ -136,8 +149,7 @@ class MenuController extends Controller
->get(); ->get();
$children = []; $children = [];
if ($dataChildren) { if ($dataChildren) {
foreach($dataChildren as $data) foreach ($dataChildren as $data) {
{
$data->children = $this->getChildrenMenu($data->id, $role_id); $data->children = $this->getChildrenMenu($data->id, $role_id);
$children[] = $data; $children[] = $data;
} }

49
app/Http/Controllers/UserToActivityController.php

@ -11,7 +11,8 @@ use Datatables;
class UserToActivityController extends Controller class UserToActivityController extends Controller
{ {
public function add(Request $request){ public function add(Request $request)
{
$this->validate($request, [ $this->validate($request, [
'activity_id' => 'required', 'activity_id' => 'required',
'user_id' => 'required' 'user_id' => 'required'
@ -26,7 +27,8 @@ class UserToActivityController extends Controller
return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200]); return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200]);
} }
public function addMultiple(Request $request){ public function addMultiple(Request $request)
{
$users_id = $request->user_id; $users_id = $request->user_id;
$users_role = $request->role_proyek_id; $users_role = $request->role_proyek_id;
@ -75,10 +77,10 @@ class UserToActivityController extends Controller
} else { } else {
return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200]); return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200]);
} }
} }
private function updatedCostPlanning($parent_id) { private function updatedCostPlanning($parent_id)
{
$sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))') $sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))')
->where("parent_id", $parent_id) ->where("parent_id", $parent_id)
->first(); ->first();
@ -89,7 +91,8 @@ class UserToActivityController extends Controller
} }
} }
public function update(Request $request, $id){ public function update(Request $request, $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);
@ -116,7 +119,8 @@ class UserToActivityController extends Controller
return response()->json(['status' => 'failed', 'message' => 'Failed to delete!', 'code' => 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to delete!', 'code' => 500], 500);
} }
public function edit($id){ public function edit($id)
{
if (!$id || (int) $id < 0 || $id == "") { if (!$id || (int) $id < 0 || $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);
die(); die();
@ -136,12 +140,19 @@ class UserToActivityController extends Controller
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$builder->addSelect(DB::raw('SUM(report_activity_material.qty) as volume_actual')); $builder->addSelect(DB::raw('SUM(report_activity_material.qty) as volume_actual'));
$builder->groupBy("m_activity.id"); $builder->groupBy("m_activity.name");
$builder->groupBy("m_activity.persentase_progress");
$builder->groupBy("m_activity.actual_start");
$builder->groupBy("m_activity.actual_end");
$builder->groupBy("m_activity.planned_start");
$builder->groupBy("m_activity.planned_end");
$builder->groupBy("m_activity.start_date");
$builder->groupBy("m_activity.end_date");
$builder->groupBy("m_activity.duration");
$builder->groupBy("selfTable.id"); $builder->groupBy("selfTable.id");
$builder->groupBy("selfTable.start_date"); $builder->groupBy("selfTable.start_date");
$builder->groupBy("selfTable.end_date"); $builder->groupBy("selfTable.end_date");
$builder->groupBy("m_users.name"); $builder->groupBy("assign_material_to_activity.qty_planning");
$builder->groupBy("assign_material_to_activity.id");
$builder->groupBy("m_version_gantt.name_version"); $builder->groupBy("m_version_gantt.name_version");
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
@ -191,11 +202,22 @@ class UserToActivityController extends Controller
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => count($dataGet)], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => count($dataGet)], 200);
} }
public function activityUser(Request $request){ public function activityUser(Request $request)
{
$payload = $request->all(); $payload = $request->all();
$activity = DB::table('m_activity as ma') $activity = DB::table('m_activity as ma')
->select('ahta.id', 'ma.id as activity_id', 'ma.proyek_id', 'ma.name as join_second_name', 'ma.start_date as join_second_start_date', ->select(
'ma.end_date as join_second_end_date', 'ma.persentase_progress', 'mvg.name_version', 'mp.nama as nama_proyek', 'mp.type_proyek_id') 'ahta.id',
'ma.id as activity_id',
'ma.proyek_id',
'ma.name as join_second_name',
'ma.start_date as join_second_start_date',
'ma.end_date as join_second_end_date',
'ma.persentase_progress',
'mvg.name_version',
'mp.nama as nama_proyek',
'mp.type_proyek_id'
)
->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'ma.id') ->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'ma.id')
->join('m_version_gantt as mvg', 'mvg.id', '=', 'ma.version_gantt_id') ->join('m_version_gantt as mvg', 'mvg.id', '=', 'ma.version_gantt_id')
->join('m_proyek as mp', 'mp.id', '=', 'ma.proyek_id') ->join('m_proyek as mp', 'mp.id', '=', 'ma.proyek_id')
@ -262,7 +284,8 @@ class UserToActivityController extends Controller
} }
} }
public function datatables(Request $request){ public function datatables(Request $request)
{
$id_activity = $request->query('idact'); $id_activity = $request->query('idact');
$data = UserToActivity::select("assign_hr_to_activity.id as id", "assign_hr_to_activity.start_date", "assign_hr_to_activity.end_date", "u.name as user_name", "mrp.name as role_name") $data = UserToActivity::select("assign_hr_to_activity.id as id", "assign_hr_to_activity.start_date", "assign_hr_to_activity.end_date", "u.name as user_name", "mrp.name as role_name")
->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id") ->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id")

3
app/Models/Company.php

@ -34,6 +34,7 @@ class Company extends Model
'updated_by', 'updated_by',
'cluster', 'cluster',
'type_account', 'type_account',
'date_register' 'date_register',
'discount_id'
]; ];
} }

2
app/Models/RoleMenu.php

@ -12,6 +12,6 @@ class RoleMenu extends Model
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'role_id', 'menu_id', 'created_at', 'created_by', 'updated_at', 'updated_by' 'role_id', 'menu_id', 'create', 'read', 'update', 'delete', 'created_at', 'created_by', 'updated_at', 'updated_by'
]; ];
} }

17
app/Models/User.php

@ -24,7 +24,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
protected $fillable = [ protected $fillable = [
'name', 'email', 'role_id', 'username', 'session_login', 'phone_number', 'email', 'address', 'name', 'email', 'role_id', 'username', 'session_login', 'phone_number', 'email', 'address',
'fcm_token', 'gender', 'birth_place', 'birth_date', 'blood_type', 'ktp_number', 'working_hours', 'fcm_token', 'gender', 'birth_place', 'birth_date', 'blood_type', 'ktp_number', 'working_hours',
'created_at', 'created_by', 'updated_at', 'updated_by', 'status_resource' 'created_at', 'created_by', 'updated_at', 'updated_by', 'status_resource', 'discount_id'
]; ];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
@ -83,11 +83,9 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
->first(); ->first();
$shift = null; $shift = null;
if ($userShift !== null) if ($userShift !== null) {
{
$shiftId = null; $shiftId = null;
switch ($ts->shortEnglishDayOfWeek) switch ($ts->shortEnglishDayOfWeek) {
{
case "Mon": case "Mon":
$shiftId = $userShift->mon_shift_id; $shiftId = $userShift->mon_shift_id;
break; break;
@ -123,8 +121,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
} }
if ($shift !== null) if ($shift !== null) {
{
$from = Carbon::createFromTimeString($shift->start_time, $tz) $from = Carbon::createFromTimeString($shift->start_time, $tz)
->subMinutes($shift->flex_time_minute); ->subMinutes($shift->flex_time_minute);
$to = Carbon::createFromTimeString($shift->end_time, $tz) $to = Carbon::createFromTimeString($shift->end_time, $tz)
@ -150,16 +147,14 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
{ {
$ts = $at; $ts = $at;
if ($at !== null) if ($at !== null) {
{
$ts = Carbon::now($tz); $ts = Carbon::now($tz);
} }
$tsSec = $ts->secondsSinceMidnight(); $tsSec = $ts->secondsSinceMidnight();
$status = ""; $status = "";
$wt = $this->getWorkingTime($ts, $tz); $wt = $this->getWorkingTime($ts, $tz);
if ($wt === null) if ($wt === null) {
{
$status = self::HOLIDAY; $status = self::HOLIDAY;
} else { } else {
$from = $wt->from; $from = $wt->from;

Loading…
Cancel
Save