示例#1
0
 /**
  * { FindBranchByName }
  *
  * @param     
  *1. name
  *2. org id
  *
  * @return
  * 1. id
  * 2. name
  * 
  * Step:
  * 1. get data
  * 2. validate
  * 3. returning data
  */
 public function FindBranchByName($org_id = null, $name = null)
 {
     //1. get data
     if (is_null($org_id)) {
         App::abort(403, 'Id Organisasi tidak ada');
     }
     $APIBranch = new APIBranch();
     $search = array_merge(['name' => $name]);
     $branch = $APIBranch->getIndex($org_id, ['search' => $search]);
     //2. validate
     if ($branch['status'] != 'success') {
         return abort(404);
     }
     //3. returning data
     $datas = [];
     foreach ($branch['data']['data'] as $key => $dt) {
         $datas[$key]['id'] = $dt['id'];
         $datas[$key]['name'] = ucwords($dt['name']);
     }
     return $datas;
 }
示例#2
0
 /**
  * { create }
  *
  * @param     
  * 1. id
  * 2. org_id
  *
  * @return
  * 1. Layout
  * 2. page_attributes
  * 3. page_datas
  * 
  * steps
  * 1. validate
  * 2. get data
  * 3. set page attributes
  * 4. set page datas
  * 5. generate view
  */
 public function create($org_id = null, $id = null)
 {
     //1. validate
     if (is_null($org_id)) {
         App::abort(403, 'Id Organisasi tidak ada');
     }
     // 2 & 3
     $APIOrg = new APIOrg();
     $organisation = $APIOrg->getShow($org_id);
     $APIEmployee = new APIEmployee();
     $employees = $APIEmployee->getIndex($org_id, []);
     $APIBranch = new APIBranch();
     $APIChart = new APIChart();
     $branches = $APIBranch->getIndex($org_id, []);
     $positions = $APIChart->getPositions($org_id, []);
     $departments = $APIChart->getDepartments($org_id, []);
     $maritalstatuses = $APIEmployee->getMaritalStatuses($org_id, []);
     $grades = $APIEmployee->getGrades($org_id, []);
     if (!is_null($id)) {
         //2. get data
         $data = $APIEmployee->getShow($org_id, $id);
         //3. set page attributes
         $current_route = route(Route::CurrentRouteName(), ['org_id' => $org_id, 'id' => $id]);
         $this->page_attributes->page_subtitle = 'Edit Karyawan ' . $data['data']['name'];
         $this->page_attributes->breadcrumb = array_merge($this->page_attributes->breadcrumb, [$organisation['data']['name'] => route('org.show', ['id' => $org_id]), 'Karyawan' => route('employee.index', ['org_id' => $org_id]), 'Edit Karyawan ' . $data['data']['name'] => $current_route]);
     } else {
         //2. get data
         $data['data'] = null;
         //3. set page attributes
         $current_route = route(Route::CurrentRouteName(), ['org_id' => $org_id]);
         $this->page_attributes->page_subtitle = 'Karyawan Baru';
         $this->page_attributes->breadcrumb = array_merge($this->page_attributes->breadcrumb, [$organisation['data']['name'] => route('org.show', ['id' => $org_id]), 'Karyawan' => route('employee.index', ['org_id' => $org_id]), 'Karyawan Baru' => $current_route]);
     }
     $APIEmployee = new APIEmployee();
     $employees = $APIEmployee->getIndex($org_id, []);
     //4. set page datas
     $this->page_datas->datas['branches'] = $branches['data']['data'];
     $this->page_datas->datas['positions'] = $positions['data'];
     $this->page_datas->datas['departments'] = $departments['data'];
     $this->page_datas->datas['maritalstatuses'] = $maritalstatuses['data'];
     $this->page_datas->datas['grades'] = $grades['data'];
     $this->page_datas->datas['employees'] = $employees['data']['data'];
     $this->page_datas->datas['employee'] = $data['data'];
     $this->page_datas->datas['id'] = $org_id;
     $this->page_datas->datas['name'] = $organisation['data']['name'];
     $this->page_datas->datas['code'] = $organisation['data']['code'];
     //5. generate view
     $view_source = $this->view_source_root . '.create';
     $route_source = $current_route;
     return $this->generateView($view_source, $route_source);
 }