Browse Source

Merge branch 'staging' of https://git.oslog.id/ibnu/generic-ospro-backend into dev-wahyun

pull/1/head
wahyuun 10 months ago
parent
commit
b54d6d0974
  1. 42
      app/Http/Controllers/Controller.php
  2. 17
      app/Http/Controllers/DivisiController.php
  3. 118
      app/Http/Controllers/MenuController.php
  4. 227
      app/Http/Controllers/UserToActivityController.php
  5. 3
      app/Models/Company.php
  6. 2
      app/Models/RoleMenu.php
  7. 71
      app/Models/User.php
  8. 46
      routes/web.php

42
app/Http/Controllers/Controller.php

@ -13,6 +13,8 @@ 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 RecursiveIteratorIterator;
use RecursiveDirectoryIterator;
class Controller extends BaseController class Controller extends BaseController
{ {
@ -41,10 +43,10 @@ class Controller extends BaseController
protected function setCustomeDirectoryUpload($company_name) protected function setCustomeDirectoryUpload($company_name)
{ {
$pathImage = 'assets/'.$company_name.'/image/'; $pathImage = 'assets/' . $company_name . '/image/';
$pathDocument = 'assets/'.$company_name.'/file/project/'; $pathDocument = 'assets/' . $company_name . '/file/project/';
$pathTmpImport = 'assets/'.$company_name.'/file/tmpimport/'; $pathTmpImport = 'assets/' . $company_name . '/file/tmpimport/';
$pathActivityDocument = 'assets/'.$company_name.'/file/activity/'; $pathActivityDocument = 'assets/' . $company_name . '/file/activity/';
return [ return [
'pathImage' => $pathImage, 'pathImage' => $pathImage,
@ -54,7 +56,19 @@ class Controller extends BaseController
]; ];
} }
protected function setLimitsStorage($company, $dokumen, $name, $initPath, $destinatePath) { public function storage($company_name)
{
$directory = 'assets/' . urldecode($company_name);
$size = 0;
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
$size += $file->getSize();
}
return round($size / 1048576, 2);
}
protected function setLimitsStorage($company, $dokumen, $name, $initPath, $destinatePath)
{
$totalSize = 0; $totalSize = 0;
$sizeFile = $dokumen->getSize(); $sizeFile = $dokumen->getSize();
// Path // Path
@ -63,11 +77,11 @@ class Controller extends BaseController
$folderPathTmpImport = $destinatePath['pathTmpImport']; $folderPathTmpImport = $destinatePath['pathTmpImport'];
$folderPathActivityDocument = $destinatePath['pathActivityDocument']; $folderPathActivityDocument = $destinatePath['pathActivityDocument'];
// Create Directory // Create Directory
if(!file_exists($initPath)) { if (!file_exists($initPath)) {
mkdir($initPath, 0777, true); mkdir($initPath, 0777, true);
} }
// Scanning & Existing Folder // Scanning & Existing Folder
if(file_exists($folderPathImage)) { if (file_exists($folderPathImage)) {
$files = scandir($folderPathImage); $files = scandir($folderPathImage);
foreach ($files as $file) { foreach ($files as $file) {
if (is_file($folderPathImage . '/' . $file)) { if (is_file($folderPathImage . '/' . $file)) {
@ -75,7 +89,7 @@ class Controller extends BaseController
} }
} }
} }
if(file_exists($folderPath)) { if (file_exists($folderPath)) {
$filesImage = scandir($folderPath); $filesImage = scandir($folderPath);
foreach ($filesImage as $file) { foreach ($filesImage as $file) {
if (is_file($folderPath . '/' . $file)) { if (is_file($folderPath . '/' . $file)) {
@ -83,7 +97,7 @@ class Controller extends BaseController
} }
} }
} }
if(file_exists($folderPathTmpImport)) { if (file_exists($folderPathTmpImport)) {
$filesTmpImport = scandir($folderPathTmpImport); $filesTmpImport = scandir($folderPathTmpImport);
foreach ($filesTmpImport as $file) { foreach ($filesTmpImport as $file) {
if (is_file($folderPathTmpImport . '/' . $file)) { if (is_file($folderPathTmpImport . '/' . $file)) {
@ -91,7 +105,7 @@ class Controller extends BaseController
} }
} }
} }
if(file_exists($folderPathActivityDocument)) { if (file_exists($folderPathActivityDocument)) {
$filesActivityDocument = scandir($folderPathActivityDocument); $filesActivityDocument = scandir($folderPathActivityDocument);
foreach ($filesActivityDocument as $file) { foreach ($filesActivityDocument as $file) {
if (is_file($folderPathActivityDocument . '/' . $file)) { if (is_file($folderPathActivityDocument . '/' . $file)) {
@ -105,16 +119,16 @@ class Controller extends BaseController
->where('company_id', $company['id']); ->where('company_id', $company['id']);
$cloneQueryTransaction = clone $transaction; $cloneQueryTransaction = clone $transaction;
$countCreate = false; $countCreate = false;
if($transaction->where([['type_paket','Basic'], ['amount','!=',null]])->exists()) { if ($transaction->where([['type_paket', 'Basic'], ['amount', '!=', null]])->exists()) {
$maximumSize = 500 * 1024 * 1024; $maximumSize = 500 * 1024 * 1024;
$countCreate = true; $countCreate = true;
} elseif ($cloneQueryTransaction->where([['type_paket','Free'], ['amount', 0]])->exists()) { } elseif ($cloneQueryTransaction->where([['type_paket', 'Free'], ['amount', 0]])->exists()) {
$maximumSize = 50 * 1024 * 1024; $maximumSize = 50 * 1024 * 1024;
$countCreate = true; $countCreate = true;
} }
if($countCreate) { if ($countCreate) {
if ($totalSize > $maximumSize) { if ($totalSize > $maximumSize) {
return response()->json(['status'=>'failed','message'=>'Limited storage maximum!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500);
} }
} }
$resultMove = $dokumen->move($folderPath, $name); $resultMove = $dokumen->move($folderPath, $name);

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()

118
app/Http/Controllers/MenuController.php

@ -23,32 +23,33 @@ class MenuController extends Controller
$result = Menu::create($data); $result = Menu::create($data);
if($result){ if ($result) {
return response()->json(['status'=>'success','message'=>'add data menu successfully!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'add data menu successfully!', 'code' => 200], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'add data menu failed!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'add data menu failed!', 'code' => 400], 400);
} }
} }
public function edit($id){ public function edit($id)
if(!$id || (int) $id < 0 || $id==""){ {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die(); die();
} }
$result = Menu::find($id); $result = Menu::find($id);
if($result){ if ($result) {
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'failed get data menu, please try again later!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'failed get data menu, please try again later!', 'code' => 400], 400);
} }
} }
public function update(Request $request, $id) public function update(Request $request, $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);
} }
$this->validate($request, [ $this->validate($request, [
'icon' => 'required', 'icon' => 'required',
@ -58,21 +59,21 @@ class MenuController extends Controller
]); ]);
$data = Menu::find($id); $data = Menu::find($id);
$request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_menu,name']) : ''; $request->name !== $data['name'] ? $this->validate($request, ['name' => 'unique:m_menu,name']) : '';
$request->url !== $data['url'] ? $this->validate($request,['url'=>'unique:m_menu,url']) : ''; $request->url !== $data['url'] ? $this->validate($request, ['url' => 'unique:m_menu,url']) : '';
if($data){ if ($data) {
$result = $data->update($request->all()); $result = $data->update($request->all());
}else{ } else {
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'data menu not found!', 'code' => 400], 400);
die(); die();
} }
if($result){ if ($result) {
return response()->json(['status'=>'success','message'=>'data menu successfully updated!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'data menu successfully updated!', 'code' => 200], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'data menu failed updated!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'data menu failed updated!', 'code' => 400], 400);
} }
} }
@ -80,18 +81,18 @@ class MenuController extends Controller
{ {
$data = Menu::find($id); $data = Menu::find($id);
if($data){ if ($data) {
$delete = $data->delete(); $delete = $data->delete();
}else{ } else {
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'data menu not found!', 'code' => 400], 400);
die(); die();
} }
if($delete){ if ($delete) {
return response()->json(['status'=>'success','message'=>'data menu successfully deleted!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'data menu successfully deleted!', 'code' => 200], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'data menu failed deleted!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'data menu failed deleted!', 'code' => 400], 400);
} }
} }
@ -103,41 +104,52 @@ class MenuController extends Controller
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); $dataGet = $builder->get();
$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 listMenu($id) public function listMenu($id)
{ {
$dataParent = RoleMenu::select("m_menu.*") $dataParent = RoleMenu::select(
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') 'm_menu.*',
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') "t_roles_menu.create",
->whereNull('m_menu.parent_id') "t_roles_menu.read",
->where('m_roles.id', $id) "t_roles_menu.update",
->orderBy('m_menu.sequence', 'ASC') "t_roles_menu.delete"
->get(); )
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->whereNull('m_menu.parent_id')
->where('m_roles.id', $id)
->orderBy('m_menu.sequence', 'ASC')
->get();
$finalData = []; $finalData = [];
foreach($dataParent as $data){ foreach ($dataParent as $data) {
$data->children = $this->getChildrenMenu($data->id, $id); $data->children = $this->getChildrenMenu($data->id, $id);
$finalData[] = $data; $finalData[] = $data;
} }
return response()->json(['status'=>'success','code'=>200,'data'=>$finalData], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $finalData], 200);
} }
protected function getChildrenMenu($id, $role_id) protected function getChildrenMenu($id, $role_id)
{ {
$dataChildren = RoleMenu::select("m_menu.*") $dataChildren = RoleMenu::select(
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') 'm_menu.*',
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') "t_roles_menu.create",
->where('m_roles.id', $role_id) "t_roles_menu.read",
->where('m_menu.parent_id', $id) "t_roles_menu.update",
->orderBy('m_menu.sequence', 'ASC') "t_roles_menu.delete"
->get(); )
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->where('m_roles.id', $role_id)
->where('m_menu.parent_id', $id)
->orderBy('m_menu.sequence', 'ASC')
->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;
} }
@ -150,10 +162,10 @@ class MenuController extends Controller
$data = Menu::all(); $data = Menu::all();
$countData = $data->count(); $countData = $data->count();
if($data){ if ($data) {
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'failed get list menu, please try again later!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'failed get list menu, please try again later!', 'code' => 400], 400);
} }
} }
} }

227
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'
@ -20,24 +21,25 @@ class UserToActivityController extends Controller
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
if(!UserToActivity::create($data)) if (!UserToActivity::create($data))
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]); return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500]);
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;
// $data = UserToActivity::where("activity_id", $request->activity_id); // $data = UserToActivity::where("activity_id", $request->activity_id);
// if($data){ // if($data){
// $data->delete(); // $data->delete();
// } // }
if(is_array($users_id) && count($users_id) > 0){ if (is_array($users_id) && count($users_id) > 0) {
$countRes = 0; $countRes = 0;
foreach($users_id as $index => $item){ foreach ($users_id as $index => $item) {
$dataInsert = array( $dataInsert = array(
"user_id" => $item, "user_id" => $item,
"activity_id" => $request->activity_id, "activity_id" => $request->activity_id,
@ -45,89 +47,91 @@ class UserToActivityController extends Controller
"proyek_id" => $request->proyek_id, "proyek_id" => $request->proyek_id,
"start_date" => $request->start_date, "start_date" => $request->start_date,
"end_date" => $request->end_date, "end_date" => $request->end_date,
"created_by" => $this->currentName, "created_by" => $this->currentName,
"version_gantt_id" => $request->version_gantt_id "version_gantt_id" => $request->version_gantt_id
); );
$result = UserToActivity::create($dataInsert); $result = UserToActivity::create($dataInsert);
if($result){ if ($result) {
$countRes++; $countRes++;
}else{ } else {
$countRes--; $countRes--;
} }
} }
if($countRes == 0) if ($countRes == 0)
return response()->json(['status'=>'failed' ,'message'=>'Failed to add data!','code'=> 500]); return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500]);
$allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id); $allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id);
$dataUpdateCost = array( $dataUpdateCost = array(
"rencana_biaya"=>$allCost, "rencana_biaya" => $allCost,
"updated_by"=> $this->currentName "updated_by" => $this->currentName
); );
$actUpdate = Activity::find($request->activity_id); $actUpdate = Activity::find($request->activity_id);
if($actUpdate){ if ($actUpdate) {
$actUpdate->update($dataUpdateCost); $actUpdate->update($dataUpdateCost);
if($actUpdate->parent_id){ if ($actUpdate->parent_id) {
$this->updatedCostPlanning($actUpdate->parent_id); $this->updatedCostPlanning($actUpdate->parent_id);
} }
} }
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]); return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200]);
}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();
if($parent = Activity::find($parent_id)){ if ($parent = Activity::find($parent_id)) {
$parent->update([ $parent->update([
"rencana_biaya" => $sumBiaya->sum, "rencana_biaya" => $sumBiaya->sum,
]); ]);
} }
} }
public function update(Request $request, $id){ public function update(Request $request, $id)
if(empty($id) || !is_int((int)$id)) {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$data = UserToActivity::find($id); $data = UserToActivity::find($id);
if(!$data) if (!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
if(!$data->update($request->all())); if (!$data->update($request->all()));
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500);
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200);
} }
public function delete($id) public function delete($id)
{ {
$data = UserToActivity::find($id); $data = UserToActivity::find($id);
if(!$data) if (!$data)
return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'data user to activity gantt Project not found!', 'code' => 400], 400);
if($data->delete()){ if ($data->delete()) {
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
} }
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==""){ {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die(); die();
} }
$result = UserToActivity::find($id); $result = UserToActivity::find($id);
if(!$result) if (!$result)
return response()->json(['status'=>'failed','message'=>'failed get data tools resource, please try again later!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'failed get data tools resource, please try again later!', 'code' => 400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} }
public function searchAnalysis(Request $request) public function searchAnalysis(Request $request)
@ -135,14 +139,21 @@ class UserToActivityController extends Controller
$dataBuilder = $this->setUpPayload($request->all(), 'assign_hr_to_activity'); $dataBuilder = $this->setUpPayload($request->all(), 'assign_hr_to_activity');
$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("selfTable.id"); $builder->groupBy("m_activity.persentase_progress");
$builder->groupBy("selfTable.start_date"); $builder->groupBy("m_activity.actual_start");
$builder->groupBy("selfTable.end_date"); $builder->groupBy("m_activity.actual_end");
$builder->groupBy("m_users.name"); $builder->groupBy("m_activity.planned_start");
$builder->groupBy("assign_material_to_activity.id"); $builder->groupBy("m_activity.planned_end");
$builder->groupBy("m_version_gantt.name_version"); $builder->groupBy("m_activity.start_date");
$builder->groupBy("m_activity.end_date");
$builder->groupBy("m_activity.duration");
$builder->groupBy("selfTable.id");
$builder->groupBy("selfTable.start_date");
$builder->groupBy("selfTable.end_date");
$builder->groupBy("assign_material_to_activity.qty_planning");
$builder->groupBy("m_version_gantt.name_version");
$dataGet = $builder->get(); $dataGet = $builder->get();
$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);
@ -165,7 +176,7 @@ class UserToActivityController extends Controller
$status = $join_column['status']; $status = $join_column['status'];
$startDate = date("Y-m-d H:i:sO", strtotime($startDate)); $startDate = date("Y-m-d H:i:sO", strtotime($startDate));
$endDate = date("Y-m-d H:i:sO", strtotime($endDate)); $endDate = date("Y-m-d H:i:sO", strtotime($endDate));
$builder->where(function ($query) use ($startDate, $endDate) { $builder->where(function ($query) use ($startDate, $endDate) {
$query $query
->where('m_proyek.mulai_proyek', '>=', $startDate) ->where('m_proyek.mulai_proyek', '>=', $startDate)
->where('m_proyek.akhir_proyek', '<=', $endDate) ->where('m_proyek.akhir_proyek', '<=', $endDate)
@ -188,22 +199,33 @@ class UserToActivityController extends Controller
$dataGet = $filteredData; $dataGet = $filteredData;
} }
// $totalRecord = $countBuilder->count(); // $totalRecord = $countBuilder->count();
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',
->join('assign_hr_to_activity as ahta', 'ahta.activity_id', '=', 'ma.id') 'ma.id as activity_id',
->join('m_version_gantt as mvg', 'mvg.id', '=', 'ma.version_gantt_id') 'ma.proyek_id',
->join('m_proyek as mp', 'mp.id', '=', 'ma.proyek_id') 'ma.name as join_second_name',
->where('ahta.user_id', $payload['user_id']) 'ma.start_date as join_second_start_date',
->where('ma.start_date', '<=', $payload['end_date']) 'ma.end_date as join_second_end_date',
->where('ma.end_date', '>=', $payload['start_date']) 'ma.persentase_progress',
->where('ma.proyek_id', $payload['proyek_id']) 'mvg.name_version',
->get(); 'mp.nama as nama_proyek',
'mp.type_proyek_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_proyek as mp', 'mp.id', '=', 'ma.proyek_id')
->where('ahta.user_id', $payload['user_id'])
->where('ma.start_date', '<=', $payload['end_date'])
->where('ma.end_date', '>=', $payload['start_date'])
->where('ma.proyek_id', $payload['proyek_id'])
->get();
if ($payload['status'] != "") { if ($payload['status'] != "") {
$filteredData = []; $filteredData = [];
@ -215,7 +237,7 @@ class UserToActivityController extends Controller
} }
$activity = $filteredData; $activity = $filteredData;
} }
return response()->json(['status'=>'success','code'=>200,'data'=>$activity, 'totalRecord'=>count($activity)], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $activity, 'totalRecord' => count($activity)], 200);
} }
public function list() public function list()
@ -223,46 +245,47 @@ class UserToActivityController extends Controller
$data = UserToActivity::all(); $data = UserToActivity::all();
$countData = $data->count(); $countData = $data->count();
if($data){ if ($data) {
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'failed get list user to activity gantt, please try again later!', 'code' => 400], 400);
} }
} }
public function listFiltered(Request $request) public function listFiltered(Request $request)
{ {
$startDate = $request->start_date; $startDate = $request->start_date;
$endDate = $request->end_date; $endDate = $request->end_date;
$userId = $request->user_id; $userId = $request->user_id;
$proyekId = $request->proyek_id; $proyekId = $request->proyek_id;
if (isset($proyekId)) { if (isset($proyekId)) {
$data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date') $data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id') ->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id')
->where('m_activity.start_date', '=', $startDate) ->where('m_activity.start_date', '=', $startDate)
->where('m_activity.end_date', '=', $endDate) ->where('m_activity.end_date', '=', $endDate)
->where('assign_hr_to_activity.user_id', '=', $userId) ->where('assign_hr_to_activity.user_id', '=', $userId)
->where('assign_hr_to_activity.proyek_id', '=', $proyekId) ->where('assign_hr_to_activity.proyek_id', '=', $proyekId)
->get(); ->get();
}else { } else {
$data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date') $data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id') ->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id')
->where('m_activity.start_date', '=', $startDate) ->where('m_activity.start_date', '=', $startDate)
->where('m_activity.end_date', '=', $endDate) ->where('m_activity.end_date', '=', $endDate)
->where('assign_hr_to_activity.user_id', '=', $userId) ->where('assign_hr_to_activity.user_id', '=', $userId)
->get(); ->get();
} }
$countData = $data->count(); $countData = $data->count();
if($data){ if ($data) {
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
}else{ } else {
return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'failed get list user to activity gantt, please try again later!', 'code' => 400], 400);
} }
} }
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")
@ -271,8 +294,8 @@ class UserToActivityController extends Controller
->get(); ->get();
return Datatables::of($data) return Datatables::of($data)
->addIndexColumn() ->addIndexColumn()
->addColumn('action', function($row){ ->addColumn('action', function ($row) {
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-hr-delete"><i class="fa fa-trash"></i></a>'; $actionBtn = '<a href="javascript:void(0)" data-id="' . $row->id . '" class="delete btn btn-danger btn-sm btn-hr-delete"><i class="fa fa-trash"></i></a>';
return $actionBtn; return $actionBtn;
}) })
->rawColumns(['action'])->make(true); ->rawColumns(['action'])->make(true);

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'
]; ];
} }

71
app/Models/User.php

@ -11,7 +11,7 @@ use Illuminate\Database\Eloquent\Model;
use Laravel\Lumen\Auth\Authorizable; use Laravel\Lumen\Auth\Authorizable;
use Carbon\Carbon; use Carbon\Carbon;
class User extends Model implements AuthenticatableContract, AuthorizableContract,JWTSubject class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject
{ {
use Authenticatable, Authorizable, HasFactory; use Authenticatable, Authorizable, HasFactory;
@ -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';
@ -74,41 +74,39 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
public function getWorkingTime(Carbon $ts, $f = "08:00", $t = "17:00", $tz = self::DEFAULT_TZ) public function getWorkingTime(Carbon $ts, $f = "08:00", $t = "17:00", $tz = self::DEFAULT_TZ)
{ {
$workingTime = array( $workingTime = array(
"from"=> Carbon::createFromTimeString($f, $tz), "from" => Carbon::createFromTimeString($f, $tz),
"to"=> Carbon::createFromTimeString($t, $tz) "to" => Carbon::createFromTimeString($t, $tz)
); );
$userShift = UserShift::where('user_id', ) $userShift = UserShift::where('user_id',)
->orderByDesc('from_date') ->orderByDesc('from_date')
->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; case "Tue":
case "Tue": $shiftId = $userShift->tue_shift_id;
$shiftId = $userShift->tue_shift_id; break;
break; case "Wed":
case "Wed": $shiftId = $userShift->wed_shift_id;
$shiftId = $userShift->wed_shift_id; break;
break; case "Thu":
case "Thu": $shiftId = $userShift->thu_shift_id;
$shiftId = $userShift->thu_shift_id; break;
break; case "Fri":
case "Fri": $shiftId = $userShift->fri_shift_id;
$shiftId = $userShift->fri_shift_id; break;
break; case "Sat":
case "Sat": $shiftId = $userShift->sat_shift_id;
$shiftId = $userShift->sat_shift_id; break;
break; case "Sun":
case "Sun": $shiftId = $userShift->sun_shift_id;
$shiftId = $userShift->sun_shift_id; break;
break;
} }
if ($shiftId === null) { if ($shiftId === null) {
@ -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;
@ -168,7 +163,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
$tsTo = $to->secondsSinceMidnight(); $tsTo = $to->secondsSinceMidnight();
if ($from->greaterThan($to)) { if ($from->greaterThan($to)) {
$tsMid = 24*60*60 - $tsFrom; $tsMid = 24 * 60 * 60 - $tsFrom;
if ($tsSec >= $tsFrom || $tsSec < $tsTo) { if ($tsSec >= $tsFrom || $tsSec < $tsTo) {
$status = self::INSIDE; $status = self::INSIDE;
} else { } else {
@ -194,7 +189,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
} }
return array( return array(
"status"=>$status, "status" => $status,
"ts" => $ts, "ts" => $ts,
"clock_in" => $clockIn, "clock_in" => $clockIn,
"clock_out" => $clockOut "clock_out" => $clockOut

46
routes/web.php

@ -6,18 +6,18 @@ $router->get('/', function () use ($router) {
$router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($router) { $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($router) {
$router->post('/login', 'AuthController@login'); $router->post('/login', 'AuthController@login');
// Landing Route // Landing Route
$router->post('/send-email', 'AuthController@sendEmail'); $router->post('/send-email', 'AuthController@sendEmail');
$router->post('/company-management-user/add', 'CompanyController@add'); $router->post('/company-management-user/add', 'CompanyController@add');
$router->post('/product-transaction/add','ProductTransactionController@add'); $router->post('/product-transaction/add', 'ProductTransactionController@add');
$router->post('/company-management-user/search', 'CompanyController@search'); $router->post('/company-management-user/search', 'CompanyController@search');
$router->post('/human-resource-user/add', 'HumanResourceController@add_user'); $router->post('/human-resource-user/add', 'HumanResourceController@add_user');
$router->get('/company-management-user/edit/{id}', 'CompanyController@edit'); $router->get('/company-management-user/edit/{id}', 'CompanyController@edit');
$router->post('/demo-management-user/add', 'DemoController@add'); $router->post('/demo-management-user/add', 'DemoController@add');
$router->post('/role-user/add', 'RoleController@add'); $router->post('/role-user/add', 'RoleController@add');
$router->post('/menu-company-user/add-multiple', 'MenuCompanyController@addMultiple'); $router->post('/menu-company-user/add-multiple', 'MenuCompanyController@addMultiple');
$router->post('/role-menu-user/add-multiple', 'RoleMenuController@addMultiple'); $router->post('/role-menu-user/add-multiple', 'RoleMenuController@addMultiple');
$router->post('/refferal-code/search', 'RefferalCodeController@search'); $router->post('/refferal-code/search', 'RefferalCodeController@search');
$router->post('/menu/add', 'MenuController@add'); $router->post('/menu/add', 'MenuController@add');
$router->get('/menu/edit/{id}', 'MenuController@edit'); $router->get('/menu/edit/{id}', 'MenuController@edit');
@ -78,7 +78,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->delete('/project/delete/{id}/{company_id}', 'ProjectController@delete'); $router->delete('/project/delete/{id}/{company_id}', 'ProjectController@delete');
$router->get('/project/list', 'ProjectController@list'); $router->get('/project/list', 'ProjectController@list');
$router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline'); $router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline');
$router->get('/project/set-baseline-activity/{activity_id}/{gantt_id}', 'ProjectController@setBaselineActivity'); $router->get('/project/set-baseline-activity/{activity_id}/{gantt_id}', 'ProjectController@setBaselineActivity');
$router->get('/project/synchronize-report/{gantt_id}', 'ProjectController@synchronizeReport'); $router->get('/project/synchronize-report/{gantt_id}', 'ProjectController@synchronizeReport');
$router->get('/project/manpower/{proyek_id}', 'ProjectController@getManpower'); $router->get('/project/manpower/{proyek_id}', 'ProjectController@getManpower');
$router->get('/project/manpower/assigned/{gantt_id}', 'ProjectController@getAssignedHR'); $router->get('/project/manpower/assigned/{gantt_id}', 'ProjectController@getAssignedHR');
@ -369,17 +369,17 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->get('/project-issues/list', 'ProjectIssuesController@list'); $router->get('/project-issues/list', 'ProjectIssuesController@list');
$router->get('/project-issues/{where}/{val}', 'ProjectIssuesController@customWhere'); $router->get('/project-issues/{where}/{val}', 'ProjectIssuesController@customWhere');
$router->get('/kanban-board/list', 'KanbanBoardController@list'); $router->get('/kanban-board/list', 'KanbanBoardController@list');
$router->post('/kanban-board/add', 'KanbanBoardController@add'); $router->post('/kanban-board/add', 'KanbanBoardController@add');
$router->put('/kanban-board/update/{id}', 'KanbanBoardController@update'); $router->put('/kanban-board/update/{id}', 'KanbanBoardController@update');
$router->delete('/kanban-board/delete/{id}', 'KanbanBoardController@delete'); $router->delete('/kanban-board/delete/{id}', 'KanbanBoardController@delete');
$router->post('/kanban-board/search', 'KanbanBoardController@search'); $router->post('/kanban-board/search', 'KanbanBoardController@search');
$router->get('/kanban-card/get-data/{project_id}/{gantt_id}/{board_id}', 'KanbanCardController@getData'); $router->get('/kanban-card/get-data/{project_id}/{gantt_id}/{board_id}', 'KanbanCardController@getData');
$router->post('/kanban-card/add', 'KanbanCardController@add'); $router->post('/kanban-card/add', 'KanbanCardController@add');
$router->put('/kanban-card/update/{id}', 'KanbanCardController@update'); $router->put('/kanban-card/update/{id}', 'KanbanCardController@update');
$router->delete('/kanban-card/delete/{id}', 'KanbanCardController@delete'); $router->delete('/kanban-card/delete/{id}', 'KanbanCardController@delete');
$router->post('/kanban-card/search', 'KanbanCardController@search'); $router->post('/kanban-card/search', 'KanbanCardController@search');
$router->post('/project-risks/add', 'ProjectRisksController@add'); $router->post('/project-risks/add', 'ProjectRisksController@add');
$router->get('/project-risks/edit/{id}', 'ProjectRisksController@edit'); $router->get('/project-risks/edit/{id}', 'ProjectRisksController@edit');
@ -587,5 +587,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/demo-management/search', 'DemoController@search'); $router->post('/demo-management/search', 'DemoController@search');
$router->delete('/demo-management/delete/{id}', 'DemoController@delete'); $router->delete('/demo-management/delete/{id}', 'DemoController@delete');
$router->get('/demo-management/list', 'DemoController@list'); $router->get('/demo-management/list', 'DemoController@list');
$router->get('information-storage/{company_name}', 'Controller@storage');
}); });
}); });

Loading…
Cancel
Save