commit 891b57a5c6121c7c6b9e96039cae29a286c2d60b Author: Imam Syahid Hudzaifah Date: Tue Aug 12 08:48:46 2025 +0700 remove be diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..84c4462 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +# Git-related files and directories +.git +.gitignore +.gitattributes + +# Specific paths +/app/src/api/vendor +/app/src/api/log + +# Common files to ignore +README.md +LICENSE + +# OS generated files +.DS_Store +Thumbs.db diff --git a/Dockerfile.backend b/Dockerfile.backend new file mode 100644 index 0000000..e3ed96d --- /dev/null +++ b/Dockerfile.backend @@ -0,0 +1,56 @@ +# Use the official PHP 7.3 Apache base image +FROM php:7.3-apache + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + libpng-dev \ + libjpeg-dev \ + libfreetype6-dev \ + libzip-dev \ + unzip \ + git \ + curl \ + rsyslog + +# Install PHP extensions +RUN docker-php-ext-install pdo pdo_mysql mysqli zip +RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ +RUN docker-php-ext-install -j$(nproc) gd + +# Install Composer version 1 +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=1.10.22 + +WORKDIR /app + +# Copying Config Files +COPY ./be/src/api/composer.json ./src/api/composer.json +COPY ./be/src/api/Aiko/ ./src/api/Aiko/ +COPY ./be/src/api/Helper/ ./src/api/Helper/ +RUN cd /app/src/api && composer install + +# Copying controllers +COPY ./be . +RUN cd /app/src/api && composer dump-autoload -o +RUN chmod -R 777 /app/src/api/log && chmod -R 777 /app/src/api/vendor + + +# Configure Apache +COPY apache-config.conf /etc/apache2/sites-available/000-default.conf +COPY custom-logging.conf /etc/apache2/conf-available/custom-logging.conf + +RUN a2enmod proxy && \ + a2enmod proxy_http && \ + a2enmod proxy_balancer && \ + a2enmod lbmethod_byrequests && \ + a2enmod rewrite && \ + a2enconf custom-logging + +# Copy rsyslog configuration +COPY rsyslog.conf /etc/rsyslog.conf + +# Create and set permissions for the start script +COPY entrypoint-backend.sh /usr/local/bin/start-services.sh +RUN chmod +x /usr/local/bin/start-services.sh + +# Use the script as the entry point +CMD ["/usr/local/bin/start-services.sh"] diff --git a/Dockerfile.frontend b/Dockerfile.frontend new file mode 100644 index 0000000..c73bd55 --- /dev/null +++ b/Dockerfile.frontend @@ -0,0 +1,19 @@ +FROM mcr.microsoft.com/devcontainers/typescript-node:20 +MAINTAINER Imam Syahid Hudzaifa +WORKDIR /app +COPY ./fe/package*.json ./ +RUN npm install + +COPY ./fe . +# Default app name is hcportal, but can be overridden at runtime +ENV APP_NAME=hcportal +EXPOSE 4200 + +# Copy the entrypoint script +COPY entrypoint-frontend.sh /entrypoint.sh + +# Make the entrypoint script executable +RUN chmod +x /entrypoint.sh + +# Set the entrypoint +ENTRYPOINT ["/entrypoint.sh"] diff --git a/admin/controller/AdminController.php b/admin/controller/AdminController.php new file mode 100755 index 0000000..eed5105 --- /dev/null +++ b/admin/controller/AdminController.php @@ -0,0 +1,1619 @@ +ActionAjaxOff = array('index','importDataQuestion','importDataActivities','getDataDashboard','exportexcel','test','downloadtemplateimportDataActivities','exportDataMonitoringReport','downloadtemplateimportDataLineRunning','importDataLineRunning', 'downloadtemplateUpdateDataActivities'); + $this->obj = new Admin($this->registry); + $this->upload = new Upload($this->registry); + $this->module = 'admin'; + } + + public function test() + { + $approvalpattern = new Approvalpattern($this->registry); + $action='bisnis-travel-overseas'; + $grade=5; + $bu='KS'; + $country='IDN'; + $subarea='129'; + $nik='16000390'; + $startDate='1970-01-01'; + $endDate='1970-01-01'; + $list=$approvalpattern->getPattern($action, $grade, $bu, $country, $subarea, $nik, $startDate, $endDate); + // var_dump($list);die(); + + + Http::ResponseJson($list); + } + + public function index() + { + $this->user_auth(); + $this->check_rule(); + $this->proses_request(); + } + + private function user_auth() + { + $tok = new Token(); + + //cek X-XSRF-TOKEN cookie + $xsrf = Http::GetXsrfHeader(); + $csrfToken = $tok->cek_cookie($xsrf); + + // cek Auth Token + $tkn = Http::CekTokenAuthHeader(); + $valid = $tok->check_tokenAuthUser($tkn); + + } + private function proses_request() + { + switch ($this->method) { + case 'POST': + $this->prosesPOST(); + break; + case 'GET': + $this->getData(); + break; + case 'DELETE': + $this->prosesDELETE(); + break; + default: + Http::ErrorQueryResponse('method not permit'); + break; + } + } + private function check_rule() + { + $rule = new Rule($this->registry); + + $this->method = $_SERVER['REQUEST_METHOD']; + + switch ($this->method) { + case 'POST': + $jtext = Http::GetBodyRequest(); + $this->oJson = json_decode($jtext); + $this->action = $this->oJson->action; + break; + case 'GET': + $this->action = Http::GetvarData('action'); + break; + case 'DELETE': + $this->action = Http::GetvarData('action'); + break; + + default: + Http::ErrorQueryResponse('operation not permit'); + break; + } + + $hasAccess = $rule->hasAccess($this->module, $this->action); + + // if ($hasAccess == false) { + // Http::ErrorQueryResponse('operation not permit'); + // } + } + private function getData() + { + + switch ($this->action) { + case 'getDataGmbQuestionType': + $this->getDataGmbQuestionType(); + break; + case 'getDataRefManunfactures': + $params['event_id'] = Http::GetvarData('event_id'); + $this->getDataRefManunfactures($params); + break; + case 'getDataQuestionSection': + $params['ref_manunfacture_products_id'] = Http::GetvarData('ref_manunfacture_products_id'); + $this->getDataQuestionSection($params); + break; + case 'viewDataEventGemba': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['search'] = Http::GetvarData('search'); + $this->viewDataEventGemba($params); + break; + case 'getDataGmbEventDetail': + $params['id'] = Http::GetvarData('id'); + $this->getDataGmbEventDetail($params); + break; + case 'getDataRefManunfacturesProduct': + $params['ref_manunfactures_id'] = Http::GetvarData('ref_manunfactures_id'); + $this->getDataRefManunfacturesProduct($params); + break; + + case 'getDataGmbEventDetailByAssesor': + $params['id'] = Http::GetvarData('id'); + $this->getDataGmbEventDetailByAssesor($params); + break; + case 'getQuestionList': + $params['type'] = Http::GetvarData('type'); + $params['id'] = Http::GetvarData('id'); + $params['assesor_id'] = Http::GetvarData('assesor_id'); + $params['event_id'] = Http::GetvarData('event_id'); + $this->getQuestionList($params); + break; + case 'getDataReportEvent': + $params['event_id'] = Http::GetvarData('event_id'); + $params['assesor_id'] = Http::GetvarData('assesor_id'); + $this->getDataReportEvent($params); + break; + case 'generateReport': + $params['event_id'] = Http::GetvarData('event_id'); + $params['assesor_id'] = Http::GetvarData('assesor_id'); + $this->generateReport($params); + break; + case 'sendReport': + $params['event_id'] = Http::GetvarData('event_id'); + $params['assesor_id'] = Http::GetvarData('assesor_id'); + $params['mail'] = Http::GetvarData('mail'); + $this->sendReport($params); + break; + case 'getDataQuestionGroup': + $this->getDataQuestionGroup(); + break; + case 'setMarkAsRead': + $params['id'] = Http::GetvarData('id'); + $params['source'] = Http::GetvarData('source'); + $this->setMarkAsRead($params); + break; + case 'viewDataMasterQuestionCategory': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['category_name'] = Http::GetvarData('category_name'); + $this->viewDataMasterQuestionCategory($params); + break; + case 'getDataQuestionCategory': + $this->getDataQuestionCategory(); + break; + case 'getDataManufatureProduct': + $this->getDataManufatureProduct(); + break; + case 'viewDataMasterQuestionGroup': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['group_name'] = Http::GetvarData('group_name'); + $this->viewDataMasterQuestionGroup($params); + break; + case 'viewDataMasterQuestionSection': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['section_name'] = Http::GetvarData('section_name'); + $params['section_code'] = Http::GetvarData('section_code'); + $params['ref_manufacture_products_id'] = Http::GetvarData('ref_manufacture_products_id'); + $this->viewDataMasterQuestionSection($params); + break; + case 'viewDataMasterQuestionType': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['type_name'] = Http::GetvarData('type_name'); + $params['code_type'] = Http::GetvarData('code_type'); + $this->viewDataMasterQuestionType($params); + break; + case 'viewDataMasterQuestion': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['question'] = Http::GetvarData('question'); + $params['question_code'] = Http::GetvarData('question_code'); + $params['question_description'] = Http::GetvarData('question_description'); + $params['is_need_upload_file'] = Http::GetvarData('is_need_upload_file'); + $params['is_publish'] = Http::GetvarData('is_publish'); + $params['gmb_question_group_id'] = Http::GetvarData('gmb_question_group_id'); + $params['gmb_question_types_id'] = Http::GetvarData('gmb_question_types_id'); + $params['gmb_question_category_id'] = Http::GetvarData('gmb_question_category_id'); + $params['gmb_question_section_id'] = Http::GetvarData('gmb_question_section_id'); + $params['ref_manufacture_products_id'] = Http::GetvarData('ref_manufacture_products_id'); + $this->viewDataMasterQuestion($params); + break; + case 'getDataCompany': + $this->getDataCompany(); + break; + case 'getDataSubArea': + $params['company_id'] = Http::GetvarData('company_id'); + $this->getDataSubArea($params); + break; + case 'getDataSubAreaRefManufacture': + $params['ref_manunfactures_id'] = Http::GetvarData('ref_manunfactures_id'); + $this->getDataSubAreaRefManufacture($params); + break; + case 'getDataGedung': + $params['sub_area_id'] = Http::GetvarData('sub_area_id'); + $this->getDataGedung($params); + break; + case 'getDataRefShiftGroup': + $params['sub_area_id'] = Http::GetvarData('sub_area_id'); + $this->getDataRefShiftGroup($params); + break; + case 'getDataSector': + $params['gedung_id'] = Http::GetvarData('gedung_id'); + $this->getDataSector($params); + break; + case 'getDataLine': + $params['sector_id'] = Http::GetvarData('sector_id'); + $this->getDataLine($params); + break; + case 'getDataDivision': + $params['company_id'] = Http::GetvarData('company_id'); + $this->getDataDivision($params); + break; + case 'getDataDepartment': + $params['company_id'] = Http::GetvarData('company_id'); + $params['division_id'] = Http::GetvarData('division_id'); + $this->getDataDepartment($params); + break; + case 'getDataBusinessUnit': + $params['line_id'] = Http::GetvarData('line_id'); + $this->getDataBusinessUnit($params); + break; + case 'getDataCategory': + $this->getDataCategory(); + break; + case 'getDataRiskLevel': + $this->getDataRiskLevel(); + break; + case 'getDataWorkScopes': + $this->getDataWorkScopes(); + break; + case 'getDataSection': + $params['gmbs_business_unit_id'] = Http::GetvarData('gmbs_business_unit_id'); + $params['department_id'] = Http::GetvarData('department_id'); + $this->getDataSection($params); + break; + case 'viewDataMasterRefBusinessUnit': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['bu_name'] = Http::GetvarData('bu_name'); + $this->viewDataMasterRefBusinessUnit($params); + break; + case 'viewDataMasterBusinessUnit': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['bu_name'] = Http::GetvarData('bu_name'); + $params['search'] = Http::GetvarData('search'); + $this->viewDataMasterBusinessUnit($params); + break; + case 'viewDataMasterQuestionCategorySelf': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['category_name'] = Http::GetvarData('category_name'); + $this->viewDataMasterQuestionCategorySelf($params); + break; + case 'viewDataMasterQuestionSectionSelf': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['section_name'] = Http::GetvarData('section_name'); + $params['company_id'] = Http::GetvarData('company_id'); + $params['sub_area_id'] = Http::GetvarData('sub_area_id'); + $params['gedung_id'] = Http::GetvarData('gedung_id'); + $params['sector_id'] = Http::GetvarData('sector_id'); + $params['line_id'] = Http::GetvarData('line_id'); + $params['gmbs_business_unit_id'] = Http::GetvarData('gmbs_business_unit_id'); + $params['department_id'] = Http::GetvarData('department_id'); + $this->viewDataMasterQuestionSectionSelf($params); + break; + case 'viewDataMasterRiskLevel': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $this->viewDataMasterRiskLevel($params); + break; + case 'viewDataMasterWorkScopes': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $this->viewDataMasterWorkScopes($params); + break; + case 'viewDataMasterActivities': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['description'] = Http::GetvarData('description'); + $params['ref_manunfactures_id'] = Http::GetvarData('ref_manunfactures_id'); + $params['sub_area_id'] = Http::GetvarData('sub_area_id'); + $params['gedung_id'] = Http::GetvarData('gedung_id'); + $params['sector_id'] = Http::GetvarData('sector_id'); + $params['line_id'] = Http::GetvarData('line_id'); + $params['gmbs_business_unit_id'] = Http::GetvarData('gmbs_business_unit_id'); + $params['gmbs_question_section_id'] = Http::GetvarData('gmbs_question_section_id'); + $params['gmbs_question_category_id'] = Http::GetvarData('gmbs_question_category_id'); + $params['gmbs_ref_risk_level_id'] = Http::GetvarData('gmbs_ref_risk_level_id'); + $params['gmbs_ref_work_scopes_id'] = Http::GetvarData('gmbs_ref_work_scopes_id'); + $params['department_id'] = Http::GetvarData('department_id'); + $params['search'] = Http::GetvarData('search'); + $this->viewDataMasterActivities($params); + break; + case 'viewDataLineRunning': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['bu_name'] = Http::GetvarData('bu_name'); + $this->viewDataLineRunning($params); + break; + case 'viewDataEventPic': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['bu_name'] = Http::GetvarData('bu_name'); + $this->viewDataEventPic($params); + break; + case 'getDataPicEvent': + $params['gmbs_department_group_shift_id'] = Http::GetvarData('gmbs_department_group_shift_id'); + $this->getDataPicEvent($params); + break; + case 'getDataEventGembaSelf': + $params['id'] = Http::GetvarData('id'); + $this->getDataEventGembaSelf($params); + break; + case 'viewDataMonitoringGembaSelf': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['event_id'] = Http::GetvarData('event_id'); + $params['ref_manunfactures_id'] = Http::GetvarData('ref_manunfactures_id'); + $params['sub_area_id'] = Http::GetvarData('sub_area_id'); + $params['gedung_id'] = Http::GetvarData('gedung_id'); + $params['sector_id'] = Http::GetvarData('sector_id'); + $params['line_id'] = Http::GetvarData('line_id'); + $params['date'] = Http::GetvarData('date'); + $params['department_id'] = Http::GetvarData('department_id'); + $this->viewDataMonitoringGembaSelf($params); + break; + case 'viewDataMonitoringGembaSelfGroupDepartment': + $params['offset'] = Http::GetvarData('offset'); + $params['jumPage'] = Http::GetvarData('jumPage'); + $params['event_id'] = Http::GetvarData('event_id'); + $params['ref_manunfactures_id'] = Http::GetvarData('ref_manunfactures_id'); + $params['sub_area_id'] = Http::GetvarData('sub_area_id'); + $params['gedung_id'] = Http::GetvarData('gedung_id'); + $params['sector_id'] = Http::GetvarData('sector_id'); + $params['line_id'] = Http::GetvarData('line_id'); + $params['date'] = Http::GetvarData('date'); + $this->viewDataMonitoringGembaSelfGroupDepartment($params); + break; + case 'getDataReffBusinessUnit': + $params['ref_manunfactures_id'] = Http::GetvarData('ref_manunfactures_id'); + $this->getDataReffBusinessUnit($params); + break; + case 'searchEmp': + $search= Http::GetvarData('search'); + $params['search']= $search; + $params['department_id']= Http::GetvarData('department_id'); + $params['sub_area_id']= Http::GetvarData('sub_area_id'); + $this->searchEmp($params); + default: + Http::ErrorQueryResponse('operation not permit'); + break; + } + } + + private function prosesPOST() + { + switch ($this->action) { + case 'saveEventGemba': + $this->cekToken(); + $this->saveEventGemba($this->oJson); + break; + case 'saveDataIssues': + $this->cekToken(); + $this->saveDataIssues($this->oJson); + break; + case 'updateGeneralIssues': + $this->cekToken(); + $this->updateGeneralIssues($this->oJson); + break; + case 'saveDataMasterQuestionCategory': + $this->cekToken(); + $this->saveDataMasterQuestionCategory($this->oJson); + break; + case 'saveDataMasterQuestionGroup': + $this->cekToken(); + $this->saveDataMasterQuestionGroup($this->oJson); + break; + case 'saveDataMasterQuestionSection': + $this->cekToken(); + $this->saveDataMasterQuestionSection($this->oJson); + break; + case 'saveDataMasterQuestionType': + $this->cekToken(); + $this->saveDataMasterQuestionType($this->oJson); + break; + case 'saveDataMasterQuestion': + $this->cekToken(); + $this->saveDataMasterQuestion($this->oJson); + break; + case 'saveDataMasterRefBusinessUnit': + $this->cekToken(); + $this->saveDataMasterRefBusinessUnit($this->oJson); + break; + case 'saveDataMasterBusinessUnit': + $this->cekToken(); + $this->saveDataMasterBusinessUnit($this->oJson); + break; + case 'saveDataMasterQuestionCategorySelf': + $this->cekToken(); + $this->saveDataMasterQuestionCategorySelf($this->oJson); + break; + case 'saveDataMasterQuestionSectionSelf': + $this->cekToken(); + $this->saveDataMasterQuestionSectionSelf($this->oJson); + break; + case 'saveDataMasterRiskLevel': + $this->cekToken(); + $this->saveDataMasterRiskLevel($this->oJson); + break; + case 'saveDataMasterWorkScopes': + $this->cekToken(); + $this->saveDataMasterWorkScopes($this->oJson); + break; + case 'saveDataMasterActivities': + $this->cekToken(); + $this->saveDataMasterActivities($this->oJson); + break; + case 'saveDataLineRunning': + $this->cekToken(); + $this->saveDataLineRunning($this->oJson); + break; + case 'saveDataEventPic': + $this->cekToken(); + $this->saveDataEventPic($this->oJson); + break; + default: + Http::ErrorQueryResponse('operation not permit'); + break; + } + } + + private function prosesDELETE() + { + $this->cekToken(); + switch ($this->action) { + case 'deleteGembaEvent': + $id = Http::GetVarData('data'); + $this->deleteGembaEvent($id); + break; + case 'deleteQuestionCategory': + $id = Http::GetVarData('data'); + $this->deleteQuestionCategory($id); + break; + case 'deleteQuestionGroup': + $id = Http::GetVarData('data'); + $this->deleteQuestionGroup($id); + break; + case 'deleteQuestionSection': + $id = Http::GetVarData('data'); + $this->deleteQuestionSection($id); + break; + case 'deleteQuestionType': + $id = Http::GetVarData('data'); + $this->deleteQuestionType($id); + break; + case 'deleteQuestion': + $id = Http::GetVarData('data'); + $this->deleteQuestion($id); + break; + case 'deleteActivities': + $id = Http::GetVarData('data'); + $data_array = Http::GetVarData('data_array'); + $this->deleteActivities($id,$data_array); + break; + case 'deleteWorkScopes': + $id = Http::GetVarData('data'); + $data_array = Http::GetVarData('data_array'); + $this->deleteWorkScopes($id,$data_array); + break; + case 'deleteRiskLevel': + $id = Http::GetVarData('data'); + $data_array = Http::GetVarData('data_array'); + $this->deleteRiskLevel($id,$data_array); + break; + case 'deleteQuestionSectionSelf': + $id = Http::GetVarData('data'); + $data_array = Http::GetVarData('data_array'); + $this->deleteQuestionSectionSelf($id,$data_array); + break; + case 'deleteQuestionCategorySelf': + $id = Http::GetVarData('data'); + $data_array = Http::GetVarData('data_array'); + $this->deleteQuestionCategorySelf($id,$data_array); + break; + case 'deleteRefBusinessUnit': + $id = Http::GetVarData('data'); + $data_array = Http::GetVarData('data_array'); + $this->deleteRefBusinessUnit($id,$data_array); + break; + case 'deleteBusinessUnit': + $id = Http::GetVarData('data'); + $data_array = Http::GetVarData('data_array'); + $this->deleteBusinessUnit($id,$data_array); + break; + case 'deleteLineRunning': + $id = Http::GetVarData('data'); + $data_array = Http::GetVarData('data_array'); + $this->deleteLineRunning($id,$data_array); + break; + default: + Http:: ErrorQueryResponse(' action not allowed'); + break; + } + } + + public function saveEventGemba($oJson) + { + $result = $this->obj->saveEventGemba($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data EVent Admin', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data EVent Admin', 'token' => $_SESSION['token']), 'json'); + } + } + + public function saveDataIssues($oJson) + { + $mail = new Mail($this->registry); + $results = $this->obj->saveDataIssues($oJson, $mail); + Http::ResponseJson( + array( + 'moreInfo' => $results['moreInfo'], + 'status' => $results['status'], + 'pesan' => $results['messages'], + 'token' => $_SESSION['token'], + ), + 'json' + ); + } + + public function updateGeneralIssues($oJson) + { + $results = $this->obj->updateGeneralIssues($oJson); + Http::ResponseJson( + array( + 'moreInfo' => $results['moreInfo'], + 'status' => $results['status'], + 'pesan' => $results['messages'], + 'token' => $_SESSION['token'], + ), + 'json' + ); + } + + + public function deleteGembaEvent($id) + { + $result = $this->obj->deleteGembaEvent($id); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + private function getDataGmbQuestionType() + { + $rs = $this->obj->getDataGmbQuestionType(); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataRefManunfactures($params) + { + $rs = $this->obj->getDataRefManunfactures($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataRefManunfacturesProduct($params) + { + $rs = $this->obj->getDataRefManunfacturesProduct($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataQuestionSection($params) + { + $rs = $this->obj->getDataQuestionSection($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataQuestionCategory() + { + $rs = $this->obj->getDataQuestionCategory(); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function viewDataEventGemba($params) + { + $rs = $this->obj->viewDataEventGemba($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataGmbEventDetail($params) + { + $rs = $this->obj->getDataGmbEventDetail($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataGmbEventDetailByAssesor($params) + { + $rs = $this->obj->getDataGmbEventDetailByAssesor($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getQuestionList($params) + { + $rs = $this->obj->getQuestionList($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + + private function cekToken() + { + $token = new Token(); + $clientToken = Http::GetTokenHeader(); + $valid = $token->check_token($clientToken); + if (!$valid) { + Http:: ErrorQueryResponse('Error Token'); + } + } + + + private function searchEmp($search) + { + $rs = $this->obj->searchEmp($search); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function getDataDashboard() + { + $score = new \modules\gemba\scoring\model\Scoring($this->registry); + + $params['event_id']=21; + $params['assesors']=[array('nik'=>"17000375"),array('nik'=>"16000390")]; + $params['type']=[array('id'=>55)]; + $params['category']=[array('id'=>1)]; + + $result=$score->getDataDashboard($params); + + return Http::ResponseJson($result,1); + } + + public function importDataQuestion() + { + $rule = new Rule($this->registry); + $action = Http::GetvarData('action', 'POST'); + + $file = Http::GetFile('fileprofiles'); + // $result = $this->upload->importDataQuestion($file); + + // if ($result == true) { + Http::ResponseJson(array( + 'pesan' => 'Berhasil Upload Data', + 'status' => 1, + 'data'=>[]), '1' + ); + // } else { + // Http::ErrorQueryResponse(array( + // 'pesan' => 'Gagal Upload Data', + // 'status' => 0), 'json' + // ); + // } + } + + public function exportexcel() + { + $link = Http::GetVarData('rt'); + $list = explode('/', $link); + + + if (isset($list[3])) { + + $params['event_id']=$list[3]; + $params['assesor_id']=$list[4]; + + $rs = $this->obj->getDataReport($params); + // var_dump($rs);die(); + + if (is_array($rs)) { + // $fileName = 'gemba-report-'.strtotime(date('Y-m-d H:i:s')).'.pdf'; + $fileName = 'gemba-report-'.strtotime(date('Y-m-d H:i:s')).'.xls'; + $this->registry->template->filename = $fileName; + $this->registry->template->list=$rs; + $this->registry->template->generate=false; + $this->registry->template->show('report'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + + } + + } + + private function generateReport($params) + { + $rs = $this->obj->getDataReport($params); + if ($rs != false) { + $fileName = 'gemba-report-'.strtotime(date('Y-m-d H:i:s')).'.pdf'; + $this->obj->updateReportName($params,$fileName); + $this->registry->template->list=$rs; + $this->registry->template->filename = $fileName; + $this->registry->template->generate=true; + $this->registry->template->show('reportpdf'); + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataReportEvent($params) + { + $rs = $this->obj->getDataReport($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function sendReport($params) + { + $mail = new Mail($this->registry); + + $rs = $this->obj->sendReport($params, $mail); + + if (is_array($rs)) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataQuestionGroup() + { + $rs = $this->obj->getDataQuestionGroup(); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataManufatureProduct() + { + $rs = $this->obj->getDataManufatureProduct(); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function setMarkAsRead($params) + { + $rs = $this->obj->setMarkAsRead($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function viewDataMasterQuestionCategory($params) + { + $rs = $this->obj->viewDataMasterQuestionCategory($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function saveDataMasterQuestionCategory($oJson) + { + $result = $this->obj->saveDataMasterQuestionCategory($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + public function deleteQuestionCategory($id) + { + $result = $this->obj->deleteQuestionCategory($id); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + private function viewDataMasterQuestionGroup($params) + { + $rs = $this->obj->viewDataMasterQuestionGroup($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function saveDataMasterQuestionGroup($oJson) + { + $result = $this->obj->saveDataMasterQuestionGroup($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + public function deleteQuestionGroup($id) + { + $result = $this->obj->deleteQuestionGroup($id); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + private function viewDataMasterQuestionSection($params) + { + $rs = $this->obj->viewDataMasterQuestionSection($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function saveDataMasterQuestionSection($oJson) + { + $result = $this->obj->saveDataMasterQuestionSection($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + public function deleteQuestionSection($id) + { + $result = $this->obj->deleteQuestionSection($id); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + private function viewDataMasterQuestionType($params) + { + $rs = $this->obj->viewDataMasterQuestionType($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function saveDataMasterQuestionType($oJson) + { + $result = $this->obj->saveDataMasterQuestionType($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + public function deleteQuestionType($id) + { + $result = $this->obj->deleteQuestionType($id); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + private function viewDataMasterQuestion($params) + { + $rs = $this->obj->viewDataMasterQuestion($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function saveDataMasterQuestion($oJson) + { + $result = $this->obj->saveDataMasterQuestion($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + public function deleteQuestion($id) + { + $result = $this->obj->deleteQuestion($id); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + private function getDataCompany() + { + $rs = $this->obj->getDataCompany(); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataSubArea($params) + { + $rs = $this->obj->getDataSubArea($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataSubAreaRefManufacture($params) + { + $rs = $this->obj->getDataSubAreaRefManufacture($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataGedung($params) + { + $rs = $this->obj->getDataGedung($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataRefShiftGroup($params) + { + $rs = $this->obj->getDataRefShiftGroup($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataSector($params) + { + $rs = $this->obj->getDataSector($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataLine($params) + { + $rs = $this->obj->getDataLine($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataDivision($params) + { + $rs = $this->obj->getDataDivision($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataDepartment($params) + { + $rs = $this->obj->getDataDepartment($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataBusinessUnit($params) + { + $rs = $this->obj->getDataBusinessUnit($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataCategory() + { + $rs = $this->obj->getDataCategory(); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataRiskLevel() + { + $rs = $this->obj->getDataRiskLevel(); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataWorkScopes() + { + $rs = $this->obj->getDataWorkScopes(); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataSection($params) + { + $rs = $this->obj->getDataSection($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function saveDataMasterRefBusinessUnit($oJson) + { + $result = $this->obj->saveDataMasterRefBusinessUnit($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + private function viewDataMasterRefBusinessUnit($params) + { + $rs = $this->obj->viewDataMasterRefBusinessUnit($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function saveDataMasterBusinessUnit($oJson) + { + $result = $this->obj->saveDataMasterBusinessUnit($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + private function viewDataMasterBusinessUnit($params) + { + $rs = $this->obj->viewDataMasterBusinessUnit($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function saveDataMasterQuestionCategorySelf($oJson) + { + $result = $this->obj->saveDataMasterQuestionCategorySelf($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + private function viewDataMasterQuestionCategorySelf($params) + { + $rs = $this->obj->viewDataMasterQuestionCategorySelf($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function saveDataMasterQuestionSectionSelf($oJson) + { + $result = $this->obj->saveDataMasterQuestionSectionSelf($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + private function viewDataMasterQuestionSectionSelf($params) + { + $rs = $this->obj->viewDataMasterQuestionSectionSelf($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function viewDataMasterRiskLevel($params) + { + $rs = $this->obj->viewDataMasterRiskLevel($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function saveDataMasterRiskLevel($oJson) + { + $result = $this->obj->saveDataMasterRiskLevel($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + private function viewDataMasterWorkScopes($params) + { + $rs = $this->obj->viewDataMasterWorkScopes($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function saveDataMasterWorkScopes($oJson) + { + $result = $this->obj->saveDataMasterWorkScopes($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + private function viewDataMasterActivities($params) + { + $rs = $this->obj->viewDataMasterActivities($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function saveDataMasterActivities($oJson) + { + $result = $this->obj->saveDataMasterActivities($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + public function saveDataLineRunning($oJson) + { + $result = $this->obj->saveDataLineRunning($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + private function viewDataLineRunning($params) + { + $rs = $this->obj->viewDataLineRunning($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function viewDataEventPic($params) + { + $rs = $this->obj->viewDataEventPic($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function saveDataEventPic($oJson) + { + $result = $this->obj->saveDataEventPic($oJson); + if ($result == true) { + Http::ResponseJson(array('pesan' => 'Berhasil simpan Data Master', 'token' => $_SESSION['token']), '1'); + } else { + Http::ErrorQueryResponse(array('pesan' => 'Gagal Simpan Data Master', 'token' => $_SESSION['token']), 'json'); + } + } + + private function getDataPicEvent($params) + { + $rs = $this->obj->getDataPicEvent($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function importDataActivities() + { + $rule = new Rule($this->registry); + $action = Http::GetvarData('action', 'POST'); + + $file = Http::GetFile('fileprofiles'); + $result = $this->upload->importDataActivities($file); + + // if ($result == true) { + Http::ResponseJson($result, '1'); + // } else { + // Http::ErrorQueryResponse(array( + // 'pesan' => 'Gagal Upload Data', + // 'status' => 0), 'json' + // ); + // } + } + + private function getDataEventGembaSelf($params) + { + $rs = $this->obj->getDataEventGembaSelf($params); + if ($rs != false) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function viewDataMonitoringGembaSelf($params) + { + $rs = $this->obj->viewDataMonitoringGembaSelf($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function viewDataMonitoringGembaSelfGroupDepartment($params) + { + $rs = $this->obj->viewDataMonitoringGembaSelfGroupDepartment($params); + if ($rs != false) { + Http::ResponseJson(array($rs), '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + private function getDataReffBusinessUnit($params) + { + $rs = $this->obj->getDataReffBusinessUnit($params); + if (is_array($rs)) { + Http::ResponseJson($rs, '1'); + } else { + Http::ErrorQueryResponse('Query Error'); + } + } + + public function downloadtemplateimportDataActivities() + { + $link = Http::GetVarData('rt'); + $list = explode('/', $link); + + $list_bu = $this->obj->getDataBusinessUnit(array()); + $this->registry->template->list_bu=$list_bu; + $list_scope = $this->obj->getDataWorkScopes(); + $this->registry->template->list_scope=$list_scope; + $list_section = $this->obj->getDataSection(array()); + $this->registry->template->list_section=$list_section; + $list_department = $this->obj->getDataDivisionDepartment(array()); + $this->registry->template->list_department=$list_department; + $list_category = $this->obj->getDataCategory(); + $this->registry->template->list_category=$list_category; + $list_risk = $this->obj->getDataRiskLevel(); + $this->registry->template->list_risk=$list_risk; + $this->registry->template->show('template-upload-master-activities'); + + } + + public function downloadtemplateUpdateDataActivities() + { + $link = Http::GetVarData('rt'); + $list = explode('/', $link); + + $list_bu = $this->obj->getDataBusinessUnit(array()); + $this->registry->template->list_bu=$list_bu; + $list_scope = $this->obj->getDataWorkScopes(); + $this->registry->template->list_scope=$list_scope; + $list_section = $this->obj->getDataSection(array()); + $this->registry->template->list_section=$list_section; + $list_department = $this->obj->getDataDivisionDepartment(array()); + $this->registry->template->list_department=$list_department; + $list_category = $this->obj->getDataCategory(); + $this->registry->template->list_category=$list_category; + $list_risk = $this->obj->getDataRiskLevel(); + $this->registry->template->list_risk=$list_risk; + + $list_data = $this->obj->viewDataMasterActivitiesDownload(); + $this->registry->template->list_activities = $list_data; + $this->registry->template->show('template-update-master-activities'); + } + + public function exportDataMonitoringReport() + { + $link = Http::GetVarData('rt'); + $list = explode('/', $link); + + if ($list[3] !== "undefined") { + $params['event_id'] = $list[3]; + } else { + $params['event_id'] = NULL; + } + if ($list[4] !== "undefined") { + $params['ref_manunfactures_id'] = $list[4]; + } else { + $params['ref_manunfactures_id'] = NULL; + } + if ($list[5] !== "undefined") { + $params['sub_area_id'] = $list[5]; + } else { + $params['sub_area_id'] = NULL; + } + if ($list[6] !== "undefined") { + $params['gedung_id'] = $list[6]; + } else { + $params['gedung_id'] = NULL; + } + if ($list[7] !== "undefined") { + $params['sector_id'] = $list[7]; + } else { + $params['sector_id'] = NULL; + } + if ($list[8] !== "undefined") { + $params['line_id'] = $list[8]; + } else { + $params['line_id'] = NULL; + } + if ($list[9] !== "NaN-NaN-NaN") { + $params['date'] = $list[9]; + } else { + $params['date'] = NULL; + } + + // $params['event_id'] = $list[3]; + // $params['ref_manunfactures_id'] = $list[4]; + // $params['sub_area_id'] = $list[5]; + // $params['gedung_id'] = $list[6]; + // $params['sector_id'] = $list[7]; + // $params['line_id'] = $list[8]; + // $params['date'] = $list[9]; + + // var_dump($list[10]); + + if(isset($list[10])){ + if (isset($list[10]) && $list[10] !== "") { + $params['department_id'] = isset($list[10])?$list[10]:''; + } else { + $params['department_id'] = NULL; + } + } + $params['type'] = 'export'; + + // var_dump($params); + + $rs = $this->obj->viewDataMonitoringGembaSelf($params); + // var_dump($rs); + $this->registry->template->list=$rs['aData']; + $this->registry->template->show('export-data-monitoring-self'); + + } + + public function deleteActivities($id,$data_array) + { + $result = $this->obj->deleteActivities($id,$data_array); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + public function deleteWorkScopes($id,$data_array) + { + $result = $this->obj->deleteWorkScopes($id,$data_array); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + public function deleteRiskLevel($id,$data_array) + { + $result = $this->obj->deleteRiskLevel($id,$data_array); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + public function deleteQuestionSectionSelf($id,$data_array) + { + $result = $this->obj->deleteQuestionSectionSelf($id,$data_array); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + public function deleteQuestionCategorySelf($id,$data_array) + { + $result = $this->obj->deleteQuestionCategorySelf($id,$data_array); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + public function deleteRefBusinessUnit($id,$data_array) + { + $result = $this->obj->deleteRefBusinessUnit($id,$data_array); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + public function deleteBusinessUnit($id,$data_array) + { + $result = $this->obj->deleteBusinessUnit($id,$data_array); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + public function deleteLineRunning($id,$data_array) + { + $result = $this->obj->deleteLineRunning($id,$data_array); + if ($result == true) { + Http::ResponseJson(array('status' => 1), '1'); + } else { + Http::ErrorQueryResponse('gagal hapus data'); + } + } + + public function downloadtemplateimportDataLineRunning() + { + $link = Http::GetVarData('rt'); + $list = explode('/', $link); + + $list_sector_line = $this->obj->getDataRefGedungSectorLine(array()); + $this->registry->template->list_sector_line=$list_sector_line; + $ref_shift_group = $this->obj->getDataRefShiftGroupAll(array()); + $this->registry->template->ref_shift_group=$ref_shift_group; + $this->registry->template->show('template-upload-line-running'); + + } + + public function importDataLineRunning() + { + $rule = new Rule($this->registry); + $action = Http::GetvarData('action', 'POST'); + + $file = Http::GetFile('fileprofiles'); + $result = $this->upload->importDataLineRunning($file); + + // if ($result == true) { + Http::ResponseJson($result, '1'); + // } else { + // Http::ErrorQueryResponse(array( + // 'pesan' => 'Gagal Upload Data', + // 'status' => 0), 'json' + // ); + // } + } +} diff --git a/admin/controller/index.html b/admin/controller/index.html new file mode 100755 index 0000000..c942a79 --- /dev/null +++ b/admin/controller/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/admin/index.html b/admin/index.html new file mode 100755 index 0000000..c942a79 --- /dev/null +++ b/admin/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/admin/model/Admin.php b/admin/model/Admin.php new file mode 100755 index 0000000..1b7d38b --- /dev/null +++ b/admin/model/Admin.php @@ -0,0 +1,6073 @@ +dbBuilderSelectJoin( + 'gmb_events t1 + INNER JOIN ref_manufacture_products t2 ON t1.ref_manunfacture_products_id = t2.id + INNER JOIN ref_manunfactures t3 ON t2.ref_manunfactures_id = t3.id + INNER JOIN ref_master_category_product_plant t4 ON t2.ref_master_category_product_plant_id = t4.id', + [ + 't1.id', + 't1.event_name', + 't1.decscription', + 't1.event_date', + 't1.start_date_time', + 't1.end_date_time', + 't2.ref_manunfactures_id', + 't2.ref_master_category_product_plant_id', + 't3.plan_name as ref_manunfactures_name', + 't4.category_name as category_name', + 't1.gmb_question_group_id', + 't1.ref_manunfacture_products_id' + ], + [], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + $stmtRespons = $this->setStatementGetResponCount(); + + foreach ($rs as $k => $v) { + $rs[$k]['responCount'] = $this->getResponsCount($stmtRespons, $v['id']); + } + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmb_events t1', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataGmbEventDetail($params) + { + try { + + $event = $this->dbBuilderSelectJoin( + 'gmb_events t1 + INNER JOIN ref_manufacture_products t2 ON t1.ref_manunfacture_products_id = t2.id + INNER JOIN ref_manunfactures t3 ON t2.ref_manunfactures_id = t3.id + INNER JOIN ref_master_category_product_plant t4 ON t2.ref_master_category_product_plant_id = t4.id', + [ + 't1.*', + 't3.plan_name as ref_manunfactures_name', + 't4.category_name as ref_manunfacture_products_name' + ], + [ + ['field' => 'id', 'key' => 't1.id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ] + ); + + + + $gmb_event_types = $this->dbBuilderSelectJoin( + 'gmb_event_types t1 + INNER JOIN gmb_question_types t2 ON t1.gmb_question_types_id = t2.id', + [ + 't2.*', + 't1.weight', + '1 as edit' + ], + [ + ['field' => 'gmb_events_id', 'key' => 't1.gmb_events_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ] + ); + + $gmb_event_sections = $this->dbBuilderSelectJoin( + 'gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id', + [ + 't2.*', + 't1.weight', + '1 as edit' + ], + [ + ['field' => 'gmb_events_id', 'key' => 't1.gmb_events_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ] + ); + + $gmb_event_category = $this->dbBuilderSelectJoin( + 'gmb_event_category t1 + INNER JOIN gmb_question_category t2 ON t1.gmb_question_category_id = t2.id', + [ + 't2.*', + 't1.weight', + '1 as edit' + ], + [ + ['field' => 'gmb_events_id', 'key' => 't1.gmb_events_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ] + ); + + $gmb_event_asessor = $this->dbBuilderSelectJoin( + 'gmb_event_asessor t1 + INNER JOIN employement a ON t1.employement_nik = a.nik + INNER JOIN emp_profiles b on a.`emp_profile_id` = b.`id` + LEFT JOIN gmb_event_questions t2 ON t1.gmb_events_id = t2.gmb_events_id + LEFT JOIN gmb_asessor_result t3 ON t2.id = t3.gmb_event_questions_id AND t3.gmb_event_asessor_id = t1.id', + [ + "t1.id", + "t1.file_report", + "a.`nik` `empno`", + "concat(a.`nik` , ' - ',COALESCE(first_name, ''), ' ',COALESCE(middle_name, ''), ' ', COALESCE(last_name, '')) `fullname`", + "IF(office_mail, office_mail, emp_email) as email_address", + "'1' AS saved", + "getEmpName(a.`nik`) as name", + "COUNT(*) as total_question", + "SUM(IF(t3.id is not null, 1,0)) as total_answer", + "ROUND((SUM(IF(t3.id is not null, 1,0))/COUNT(*))*100,2) as percentage", + ], + [ + ['field' => 'gmb_events_id', 'key' => 't1.gmb_events_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ], + "GROUP BY + t1.id, + t1.employement_nik, + t1.gmb_events_id" + ); + + $stmt = $this->setStatementGetIssues(); + $stmt->bindValue(':event_id', $params['id'], PDO::PARAM_INT); + $stmt->execute(); + $gmb_event_issues = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $stmtAssIssue = $this->setStatementGetResponCountAssIssue(); + foreach ($gmb_event_issues as $k => $val) { + $gmb_event_issues[$k]['responCount'] = $this->getResponsCount($stmtAssIssue, $val['gmb_asessor_result_id']); + } + + $stmt = $this->setStatementGetGeneralIssues(); + $stmt->bindValue(':event_id', $params['id'], PDO::PARAM_INT); + $stmt->execute(); + $gmb_general_issues = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $stmtGetcountGenIssue = $this->setStatementGetResponCountGenIssue(); + foreach ($gmb_general_issues as $k => $val) { + $gmb_general_issues[$k]['responCount'] = $this->getResponsCount($stmtGetcountGenIssue, $val['id']); + } + + $stmt = $this->setStatementGetResponCountGeneralIssue(); + $stmt->bindValue(':id', $params['id'], PDO::PARAM_INT); + $stmt->execute(); + $rsGenIssue = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $stmt = $this->setStatementGetResponCountIssue(); + $stmt->bindValue(':id', $params['id'], PDO::PARAM_INT); + $stmt->execute(); + $rsIssue = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach ($gmb_event_asessor as $key => $value) { + $gmb_event_asessor[$key]['score'] = $this->getScoreAssesor($value['id']); + } + foreach ($gmb_event_issues as $k => $v) { + $gmb_event_issues[$k]['images'] = ""; + if (!empty($v['file_location'])) { + $gmb_event_issues[$k]['images'] = $this->registry->config->server_address . '/upload/genba-client/' . $v['file_location']; + } + } + $rData['event'] = $event; + $rData['gmb_event_types'] = $gmb_event_types; + $rData['gmb_event_sections'] = $gmb_event_sections; + $rData['gmb_event_category'] = $gmb_event_category; + $rData['gmb_event_asessor'] = $gmb_event_asessor; + $rData['gmb_event_issues'] = $gmb_event_issues; + $rData['gmb_general_issues'] = $gmb_general_issues; + $rData['responCountGeneralIssue'] = count($rsGenIssue) > 0 ? $rsGenIssue[0]['total'] : 0; + $rData['responCountIssue'] = count($rsIssue) > 0 ? $rsIssue[0]['total'] : 0; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataGmbEventDetailByAssesor($params) + { + try { + + $event = $this->dbBuilderSelectJoin( + 'gmb_event_asessor a + INNER JOIN employement b ON a.employement_nik = b.nik + INNER JOIN emp_profiles c on b.`emp_profile_id` = c.`id` + INNER JOIN gmb_events t1 ON a.gmb_events_id = t1.id + INNER JOIN ref_manufacture_products t2 ON t1.ref_manunfacture_products_id = t2.id + INNER JOIN ref_manunfactures t3 ON t2.ref_manunfactures_id = t3.id + INNER JOIN ref_master_category_product_plant t4 ON t2.ref_master_category_product_plant_id = t4.id', + [ + 't1.*', + 't3.plan_name as ref_manunfactures_name', + 't4.category_name as ref_manunfacture_products_name', + "b.`nik` `empno`", + "concat(b.`nik` , ' - ',COALESCE(first_name, ''), ' ',COALESCE(middle_name, ''), ' ', COALESCE(last_name, '')) `fullname`", + "IF(office_mail, office_mail, emp_email) as email_address", + "'1' AS saved", + "getEmpName(b.`nik`) as assesor_name" + ], + [ + ['field' => 'id', 'key' => 'a.id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ] + ); + + $gmb_event_types = $this->dbBuilderSelectJoin( + 'gmb_event_types t1 + INNER JOIN gmb_question_types t2 ON t1.gmb_question_types_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_types_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id', + [ + 't2.*', + 'COUNT(t3.id) as total_question', + 'SUM(IF(t6.id is not null, 1,0)) as total_answer', + 'ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage', + 'sum(t3.max_score) as total_max_score', + 'ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score', + 'ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2) as ach_result_section', + 't4.gmb_events_id as event_id' + ], + [ + ['field' => 'id', 'key' => 't5.id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ], + " GROUP BY + t1.id" + ); + + $gmb_event_category = $this->dbBuilderSelectJoin( + 'gmb_event_category t1 + INNER JOIN gmb_question_category t2 ON t1.gmb_question_category_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_category_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id', + [ + 't2.*', + 'COUNT(t3.id) as total_question', + 'SUM(IF(t6.id is not null, 1,0)) as total_answer', + 'ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage', + 'sum(t3.max_score) as total_max_score', + 'ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score', + 'ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2) as ach_result_section', + 't4.gmb_events_id as event_id' + ], + [ + ['field' => 'id', 'key' => 't5.id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ], + " GROUP BY + t1.id" + ); + + $gmb_event_sections = $this->dbBuilderSelectJoin( + 'gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + LEFT JOIN gmb_asessor_result_notes t7 ON t6.id = t7.gmb_asessor_result_id', + [ + 't2.*', + 't7.note', + 'COUNT(t3.id) as total_question', + 'SUM(IF(t6.id is not null, 1,0)) as total_answer', + 'ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage', + 'sum(t3.max_score) as total_max_score', + 'ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score', + 'ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2) as ach_result_section', + 't4.gmb_events_id as event_id' + ], + [ + ['field' => 'id', 'key' => 't5.id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ], + " GROUP BY + t1.id " + ); + + + + $rData['event'] = $event; + $rData['gmb_event_types'] = $gmb_event_types; + $rData['gmb_event_category'] = $gmb_event_category; + $rData['gmb_event_sections'] = $gmb_event_sections; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getQuestionList($params) + { + try { + + if ($params['type'] == 'type') { + $question = $this->dbBuilderSelectJoin( + 'gmb_event_types t1 + INNER JOIN gmb_question_types t2 ON t1.gmb_question_types_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_types_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + LEFT JOIN gmb_answer_detail t7 ON t6.gmb_answer_detail_id = t7.id + LEFT JOIN gmb_asessor_result_notes t8 ON t8.gmb_asessor_result_id = t6.id + LEFT JOIN gmb_assesor_result_files t9 ON t9.gmb_asessor_result_id = t6.id ', + [ + 't3.id', + 't3.question_code', + 't3.question', + 't7.answer_label', + 't6.score', + 't8.note', + 't9.file_location as file' + ], + [ + ['field' => 'gmb_question_types_id', 'key' => 't1.gmb_question_types_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ['field' => 'id', 'key' => 't5.id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_STR], + ] + ); + } + + if ($params['type'] == 'category') { + $question = $this->dbBuilderSelectJoin( + 'gmb_event_category t1 + INNER JOIN gmb_question_category t2 ON t1.gmb_question_category_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_category_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + LEFT JOIN gmb_answer_detail t7 ON t6.gmb_answer_detail_id = t7.id + LEFT JOIN gmb_asessor_result_notes t8 ON t8.gmb_asessor_result_id = t6.id + LEFT JOIN gmb_assesor_result_files t9 ON t9.gmb_asessor_result_id = t6.id', + [ + 't3.id', + 't3.question_code', + 't3.question', + 't7.answer_label', + 't6.score', + 't8.note', + 't9.file_location as file' + ], + [ + ['field' => 'gmb_question_types_id', 'key' => 't1.gmb_question_category_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ['field' => 'id', 'key' => 't5.id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_STR], + ] + ); + } + + if ($params['type'] == 'section') { + $question = $this->dbBuilderSelectJoin( + 'gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + LEFT JOIN gmb_answer_detail t7 ON t6.gmb_answer_detail_id = t7.id + LEFT JOIN gmb_asessor_result_notes t8 ON t8.gmb_asessor_result_id = t6.id + LEFT JOIN gmb_assesor_result_files t9 ON t9.gmb_asessor_result_id = t6.id', + [ + 't3.id', + 't3.question_code', + 't3.question', + 't7.answer_label', + 't6.score', + 't6.gmb_answer_detail_id', + 't8.note', + 't9.file_location as file' + ], + [ + ['field' => 'gmb_question_types_id', 'key' => 't1.gmb_question_section_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ['field' => 'id', 'key' => 't5.id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_STR], + ] + ); + } + + foreach ($question as $key => $value) { + $question[$key]['pilihan'] = $this->dbBuilderSelectJoin( + 'gmb_answer_detail t1', + [ + 't1.*', + ], + [ + ['field' => 'gmb_questions_id', 'key' => 't1.gmb_questions_id', 'val' => $value['id'], 'bind' => PDO::PARAM_STR], + ] + ); + } + + + $rData['question'] = $question; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + + public function getDataGmbQuestionType() + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_types t1', + [ + 't1.*' + ], + [] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataRefManunfactures($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'ref_manunfactures t1', + [ + 't1.*' + ], + [] + ); + + if ($params['event_id']) { + $rs = $this->dbBuilderSelectJoin( + 'ref_manunfactures t1 + INNER JOIN gmbs_events t2 ON t1.id = t2.ref_manufactures_id', + [ + 't1.*' + ], + [ + ['field' => 'id', 'key' => 't2.id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR], + ] + ); + } + + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataRefManunfacturesProduct($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'ref_manufacture_products t1 + INNER JOIN ref_master_category_product_plant t2 ON t1.ref_master_category_product_plant_id =t2.id', + [ + 't1.id', + 't2.category_name', + '0 as edit' + ], + [ + ['field' => 'ref_manunfactures_id', 'key' => 't1.ref_manunfactures_id', 'val' => $params['ref_manunfactures_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataQuestionSection($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_section t1', + [ + 't1.*', + '0 as edit' + ], + [ + ['field' => 'ref_manufacture_products_id', 'key' => 't1.ref_manufacture_products_id', 'val' => $params['ref_manunfacture_products_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataQuestionCategory() + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_category t1', + [ + 't1.*', + '0 as edit' + ], + [] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveEventGemba($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + $event_date = date("Y-m-d", strtotime($data->event_date)); + $start_time = date("H:i", strtotime($data->start_date_time)); + $end_time = date("H:i", strtotime($data->end_date_time)); + $start_date_time = new DateTime($event_date . ' ' . $start_time); + $end_date_time = new DateTime($event_date . ' ' . $end_time); + + if (!isset($data->id)) { + $event = $this->dbBuilderInsert( + 'gmb_events', + [ + ['key' => 'event_name', 'val' => $data->event_name, 'bind' => PDO::PARAM_STR], + ['key' => 'decscription', 'val' => $data->description, 'bind' => PDO::PARAM_STR], + ['key' => 'event_date', 'val' => $event_date, 'bind' => PDO::PARAM_STR], + ['key' => 'start_date_time', 'val' => $start_date_time->format('Y-m-d H:i'), 'bind' => PDO::PARAM_STR], + ['key' => 'end_date_time', 'val' => $end_date_time->format('Y-m-d H:i'), 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manunfacture_products_id', 'val' => $data->ref_manunfacture_products_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_group_id', 'val' => $data->gmb_question_group_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$event) { + return false; + } + } else { + $event = $data->id; + $event_update = $this->dbBuilderUpdate('gmb_events', [ + ['key' => 'event_name', 'val' => $data->event_name, 'bind' => PDO::PARAM_STR], + ['key' => 'decscription', 'val' => $data->description, 'bind' => PDO::PARAM_STR], + ['key' => 'event_date', 'val' => $event_date, 'bind' => PDO::PARAM_STR], + ['key' => 'start_date_time', 'val' => $start_date_time->format('Y-m-d H:i'), 'bind' => PDO::PARAM_STR], + ['key' => 'end_date_time', 'val' => $end_date_time->format('Y-m-d H:i'), 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manunfacture_products_id', 'val' => $data->ref_manunfacture_products_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_group_id', 'val' => $data->gmb_question_group_id, 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $event, 'bind' => PDO::PARAM_INT], + ]); + + if (!$event_update) { + return false; + } + + $this->dbBuilderDelete('gmb_event_types', 'gmb_events_id', $event); + $this->dbBuilderDelete('gmb_event_sections', 'gmb_events_id', $event); + $this->dbBuilderDelete('gmb_event_category', 'gmb_events_id', $event); + $this->dbBuilderDelete('gmb_event_asessor', 'gmb_events_id', $event); + $this->dbBuilderDelete('gmb_questions', 'gmb_events_id', $event); + } + + + + foreach ($data->type as $key => $value) { + $event_types = $this->dbBuilderInsert( + 'gmb_event_types', + [ + ['key' => 'gmb_events_id', 'val' => $event, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $value->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_types_id', 'val' => $value->id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$event_types) { + return false; + } + } + + foreach ($data->section as $key => $value) { + + $event_sections = $this->dbBuilderInsert( + 'gmb_event_sections', + [ + ['key' => 'gmb_events_id', 'val' => $event, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $value->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_section_id', 'val' => $value->id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$event_sections) { + return false; + } + } + + foreach ($data->gmb_question_category_id as $key => $value) { + + $event_category = $this->dbBuilderInsert( + 'gmb_event_category', + [ + ['key' => 'gmb_events_id', 'val' => $event, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $value->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_category_id', 'val' => $value->id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$event_category) { + return false; + } + } + + foreach ($data->asessor as $key => $value) { + $event_asessor = $this->dbBuilderInsert( + 'gmb_event_asessor', + [ + ['key' => 'gmb_events_id', 'val' => $event, 'bind' => PDO::PARAM_STR], + ['key' => 'employement_nik', 'val' => $value->nik->empno, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$event_asessor) { + return false; + } + + $mail = new Mail($this->registry); + + $address_cc = array(); + + $maildata['address'] = $value->nik->email_address; + $maildata['address_cc_mail'] = $address_cc; + $maildata['addressname'] = ""; + $maildata['empreqname'] = ""; + $maildata['attachmentlocation'] = ''; + $maildata['attachmentfilename'] = ''; + $maildata['subject'] = "Genba Event"; + $maildata['link'] = ''; + + $maildata['message'] = "Genba Event Invite"; + + $rsmail = $mail->sendMail($maildata); + + if (!$rsmail) { + throw new Exception("3"); + } + } + + foreach ($data->type as $i => $vi) { + foreach ($data->section as $j => $vj) { + foreach ($data->gmb_question_category_id as $k => $vk) { + $question = $this->dbBuilderSelectJoin( + 'gmb_questions t1', + [ + 't1.*' + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR], + ['field' => 'gmb_question_section_id', 'key' => 't1.gmb_question_section_id', 'val' => $vj->id, 'bind' => PDO::PARAM_STR], + ['field' => 'gmb_question_types_id', 'key' => 't1.gmb_question_types_id', 'val' => $vi->id, 'bind' => PDO::PARAM_STR], + ['field' => 'gmb_question_category_id', 'key' => 't1.gmb_question_category_id', 'val' => $vk->id, 'bind' => PDO::PARAM_STR], + ['field' => 'gmb_question_group_id', 'key' => 't1.gmb_question_group_id', 'val' => $data->gmb_question_group_id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($question) > 0) { + $event_questions = $this->dbBuilderInsert( + 'gmb_event_questions', + [ + ['key' => 'gmb_events_id', 'val' => $event, 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_questions_id', 'val' => $question[0]['id'], 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$event_questions) { + return false; + } + } + } + } + } + + // return false; + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveEventGemba: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveEventGemba: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteGembaEvent($id) + { + try { + + $this->registry->db->beginTransaction(); + + $this->dbBuilderDelete('gmb_events', 'id', $id); + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteGembaEvent: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteGembaEvent: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function getScoreAssesor($id) + { + try { + $sql = "SELECT + ROUND(SUM(tab.score),2) as score + FROM + ( + SELECT + t2.*, + t7.note, + COUNT(t3.id) as total_question, + SUM(IF(t6.id is not null, 1,0)) as total_answer, + ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage, + sum(t3.max_score) as total_max_score, + ((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100 as score, + ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2) as ach_result_section, + t4.gmb_events_id as event_id + FROM + gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + LEFT JOIN gmb_asessor_result_notes t7 ON t6.id = t7.gmb_asessor_result_id + WHERE + t5.id =:assesor_id + GROUP BY + t1.id + ) tab"; + + $stmt = $this->registry->db->prepare($sql); + $stmt->bindValue(':assesor_id', $id, PDO::PARAM_STR); + $stmt->execute(); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + + return count($rs) > 0 ? $rs[0]['score'] : 0; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataReport($params) + { + try { + + $event = $this->dbBuilderSelectJoin( + 'gmb_events t1 + INNER JOIN ref_manufacture_products t2 ON t1.ref_manunfacture_products_id = t2.id + INNER JOIN ref_manunfactures t3 ON t2.ref_manunfactures_id = t3.id + INNER JOIN ref_master_category_product_plant t4 ON t2.ref_master_category_product_plant_id = t4.id', + [ + 't1.*', + 't3.plan_name as ref_manunfactures_name', + 't4.category_name as ref_manunfacture_products_name' + ], + [ + ['field' => 'id', 'key' => 't1.id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + if ($params['assesor_id'] != '') { + $event = $this->dbBuilderSelectJoin( + 'gmb_event_asessor a + INNER JOIN employement b ON a.employement_nik = b.nik + INNER JOIN emp_profiles c on b.`emp_profile_id` = c.`id` + INNER JOIN gmb_events t1 ON a.gmb_events_id = t1.id + INNER JOIN ref_manufacture_products t2 ON t1.ref_manunfacture_products_id = t2.id + INNER JOIN ref_manunfactures t3 ON t2.ref_manunfactures_id = t3.id + INNER JOIN ref_master_category_product_plant t4 ON t2.ref_master_category_product_plant_id = t4.id', + [ + 't1.*', + 't3.plan_name as ref_manunfactures_name', + 't4.category_name as ref_manunfacture_products_name', + "b.`nik` `empno`", + "concat(b.`nik` , ' - ',COALESCE(first_name, ''), ' ',COALESCE(middle_name, ''), ' ', COALESCE(last_name, '')) `fullname`", + "IF(office_mail, office_mail, emp_email) as email_address", + "'1' AS saved", + "getEmpName(b.`nik`) as assesor_name" + ], + [ + ['field' => 'id', 'key' => 'a.id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_STR], + ] + ); + } + + + + + + $section_where = "WHERE t1.gmb_events_id={$params['event_id']}"; + + if ($params['assesor_id'] != '') { + $section_where .= " AND t5.id={$params['assesor_id']}"; + } + + $sql_event_sections = "SELECT + tab.*, + ROUND(avg(tab.score),2) as score, + ROUND(avg(tab.ach_result_section),2) as ach_result_section + FROM + ( + SELECT + t2.*, + COUNT(t3.id) as total_question, + SUM(IF(t6.id is not null, 1,0)) as total_answer, + ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage, + sum(t3.max_score) as total_max_score, + ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score, + ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2)*100 as ach_result_section, + t4.gmb_events_id as event_id, + (SELECT + a.question_code + FROM + gmb_questions a + INNER JOIN gmb_question_section b ON a.gmb_question_section_id = b.id + WHERE + b.id=t1.gmb_question_section_id + ORDER BY + a.id ASC LIMIT 1 + ) first_question, + (SELECT + a.question_code + FROM + gmb_questions a + INNER JOIN gmb_question_section b ON a.gmb_question_section_id = b.id + WHERE + b.id=t1.gmb_question_section_id + ORDER BY + a.id DESC LIMIT 1 + ) last_question + FROM + gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + $section_where + GROUP BY + t1.id,t5.id + ) tab + GROUP BY + tab.id"; + + // var_dump($sql_event_sections);die(); + + $stmt_event_sections = $this->registry->db->prepare($sql_event_sections); + $stmt_event_sections->execute(); + $gmb_event_sections = $stmt_event_sections->fetchAll(PDO::FETCH_ASSOC); + + // $section_where=[]; + + // array_push($section_where, + // ['field' => 'gmb_events_id','key' => 't1.gmb_events_id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR] + // ); + + // if($params['assesor_id'] != ''){ + // array_push($section_where, + // ['field' => 'id','key' => 't5.id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_STR] + // ); + // } + + // $gmb_event_sections=$this->dbBuilderSelectJoin('gmb_event_sections t1 + // INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + // INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + // INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + // INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + // LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id', + // [ + // 't2.*', + // 'COUNT(t3.id) as total_question', + // 'SUM(IF(t6.id is not null, 1,0)) as total_answer', + // 'ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage', + // 'sum(t3.max_score) as total_max_score', + // 'ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score', + // 'ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2)*100 as ach_result_section', + // 't4.gmb_events_id as event_id', + // '(SELECT + // a.question_code + // FROM + // gmb_questions a + // INNER JOIN gmb_question_section b ON a.gmb_question_section_id = b.id + // WHERE + // b.id=t1.gmb_question_section_id + // ORDER BY + // a.id ASC LIMIT 1 + // ) first_question', + // '(SELECT + // a.question_code + // FROM + // gmb_questions a + // INNER JOIN gmb_question_section b ON a.gmb_question_section_id = b.id + // WHERE + // b.id=t1.gmb_question_section_id + // ORDER BY + // a.id DESC LIMIT 1 + // ) last_question' + // ], + // $section_where, + // " GROUP BY + // t1.id " + // ); + + $gmb_event_types = $this->dbBuilderSelectJoin( + 'gmb_event_types t1 + INNER JOIN gmb_question_types t2 ON t1.gmb_question_types_id = t2.id', + [ + 't2.id', + 't2.type_name as name', + 't1.weight', + '"types" as type' + ], + [ + ['field' => 'gmb_events_id', 'key' => 't1.gmb_events_id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + $gmb_event_category = $this->dbBuilderSelectJoin( + 'gmb_event_category t1 + INNER JOIN gmb_question_category t2 ON t1.gmb_question_category_id = t2.id', + [ + 't2.id', + 't2.category_name as name', + 't1.weight', + '"category" as type' + ], + [ + ['field' => 'gmb_events_id', 'key' => 't1.gmb_events_id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + + $header = array(); + + foreach ($gmb_event_category as $key => $value) { + $gmb_event_category[$key]['total_score'] = 0; + $gmb_event_category[$key]['total_max_score'] = 0; + array_push($header, $gmb_event_category[$key]); + } + + foreach ($gmb_event_types as $key => $value) { + $gmb_event_types[$key]['total_score'] = 0; + $gmb_event_types[$key]['total_max_score'] = 0; + array_push($header, $gmb_event_types[$key]); + } + $total_all_max_score = 0; + foreach ($gmb_event_sections as $i => $vi) { + $category_type = array(); + foreach ($header as $j => $vj) { + $where = $section_where; + + if ($vj['type'] == 'category') { + // array_push($where, + // ['field' => 'gmb_question_category_id','key' => 't3.gmb_question_category_id', 'val' => $vj['id'], 'bind' => PDO::PARAM_STR] + // ); + // array_push($where, + // ['field' => 'gmb_question_section_id','key' => 't2.id', 'val' => $vi['id'], 'bind' => PDO::PARAM_STR] + // ); + + $where .= " AND t2.id={$vi['id']} AND t3.gmb_question_category_id={$vj['id']}"; + + // $category=$this->dbBuilderSelectJoin('gmb_event_sections t1 + // INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + // INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + // INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + // INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + // LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + // INNER JOIN gmb_event_category t7 ON t3.gmb_question_category_id = t7.gmb_question_category_id', + // [ + // 't7.*', + // 'COUNT(t3.id) as total_question', + // 'SUM(IF(t6.id is not null, 1,0)) as total_answer', + // 'ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage', + // 'sum(t3.max_score) as total_max_score', + // 'sum(IFNULL(t6.score,0)) as total_score', + // 'ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t7.weight/100))*100,2) as score', + // 'ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t7.weight/100))/ (t7.weight/100)),2)*100 as ach_result_section', + // 't4.gmb_events_id as event_id' + // ], + // $where, + // " GROUP BY + // t1.id " + // ); + + $sql_category = "SELECT + tab.*, + round(avg(tab.total_score),1) as total_score, + round(avg(tab.total_max_score),1) as total_max_score, + avg(tab.score) as score, + avg(tab.ach_result_section) as ach_result_section + FROM + ( + SELECT + t7.*, + COUNT(t3.id) as total_question, + SUM(IF(t6.id is not null, 1,0)) as total_answer, + ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage, + sum(t3.max_score) as total_max_score, + ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score, + ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2)*100 as ach_result_section, + t4.gmb_events_id as event_id, + sum(IFNULL(t6.score,0)) as total_score + FROM + gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + INNER JOIN gmb_event_category t7 ON t3.gmb_question_category_id = t7.gmb_question_category_id + $where + GROUP BY + t1.id,t5.id + ) tab + GROUP BY + tab.id"; + + // var_dump($sql_category);die(); + + $stmt_category = $this->registry->db->prepare($sql_category); + $stmt_category->execute(); + $category = $stmt_category->fetchAll(PDO::FETCH_ASSOC); + + foreach ($category as $k => $vk) { + $category[$k]['name'] = $header[$j]['name']; + $category[$k]['type'] = $header[$j]['type']; + $header[$j]['total_score'] += $vk['total_score']; + $header[$j]['total_max_score'] += $vk['total_max_score']; + $total_all_max_score += $vk['total_max_score']; + array_push($category_type, $category[$k]); + } + } + + if ($vj['type'] == 'types') { + // array_push($where, + // ['field' => 'gmb_question_types_id','key' => 't3.gmb_question_types_id', 'val' => $vj['id'], 'bind' => PDO::PARAM_STR] + // ); + // array_push($where, + // ['field' => 'gmb_question_section_id','key' => 't2.id', 'val' => $vi['id'], 'bind' => PDO::PARAM_STR] + // ); + // $category=$this->dbBuilderSelectJoin('gmb_event_sections t1 + // INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + // INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + // INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + // INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + // LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + // INNER JOIN gmb_event_types t7 ON t3.gmb_question_types_id = t7.gmb_question_types_id', + // [ + // 't7.*', + // 'COUNT(t3.id) as total_question', + // 'SUM(IF(t6.id is not null, 1,0)) as total_answer', + // 'ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage', + // 'sum(t3.max_score) as total_max_score', + // 'sum(IFNULL(t6.score,0)) as total_score', + // 'ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t7.weight/100))*100,2) as score', + // 'ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t7.weight/100))/ (t7.weight/100)),2)*100 as ach_result_section', + // 't4.gmb_events_id as event_id' + // ], + // $where, + // " GROUP BY + // t1.id " + // ); + + $where .= " AND t2.id={$vi['id']} AND t3.gmb_question_types_id={$vj['id']}"; + + $sql_types = "SELECT + tab.*, + round(avg(tab.total_score),1) as total_score, + round(avg(tab.total_max_score),1) as total_max_score, + avg(tab.score) as score, + avg(tab.ach_result_section) as ach_result_section + FROM + ( + SELECT + t7.*, + COUNT(t3.id) as total_question, + SUM(IF(t6.id is not null, 1,0)) as total_answer, + ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage, + sum(t3.max_score) as total_max_score, + ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score, + ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2)*100 as ach_result_section, + t4.gmb_events_id as event_id, + sum(IFNULL(t6.score,0)) as total_score + FROM + gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + INNER JOIN gmb_event_types t7 ON t3.gmb_question_types_id = t7.gmb_question_types_id + $where + GROUP BY + t1.id,t5.id + ) tab + GROUP BY + tab.id"; + + $stmt_types = $this->registry->db->prepare($sql_types); + $stmt_types->execute(); + $types = $stmt_types->fetchAll(PDO::FETCH_ASSOC); + + foreach ($types as $k => $vk) { + $types[$k]['name'] = $header[$j]['name']; + $types[$k]['type'] = $header[$j]['type']; + $header[$j]['total_score'] += $vk['total_score']; + $header[$j]['total_max_score'] += $vk['total_max_score']; + $total_all_max_score += $vk['total_max_score']; + array_push($category_type, $types[$k]); + } + } + } + + $gmb_event_sections[$i]['category_type'] = $category_type; + } + + foreach ($header as $key => $value) { + $header[$key]['percentage_max_score'] = ROUND((($value['total_max_score'] / $total_all_max_score) * 100), 2); + $header[$key]['percentage_score'] = ROUND((($value['total_score'] / $total_all_max_score) * 100), 2); + $header[$key]['total_score_item'] = ROUND((($value['total_score'] / $value['total_max_score']) * 100), 2); + } + + $score_event = array_sum(array_column($gmb_event_sections, 'score')); + $all_weight = array_sum(array_column($gmb_event_sections, 'weight')); + + + $rData['score_event'] = ($score_event / $all_weight) * 100; + $rData['event'] = $event; + $rData['total_all_max_score'] = $total_all_max_score; + $rData['header'] = $header; + $rData['gmb_event_sections'] = $gmb_event_sections; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', Line: ' . $e->getLine() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', Line: ' . $e->getLine() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function sendMail($params, $mail) + { + try { + $profiles = new Profiles($this->registry); + $empReq = $profiles->getEmailInfo(\Helper::getSessionVar('username')); + $empReqto = $profiles->getEmailInfo($params->empno); + + $maildata['address'] = $empReqto[0]['mail_address']; + $maildata['addressname'] = $empReqto[0]['full_name']; + $maildata['empreqname'] = $empReq[0]['full_name']; + $maildata['empreqnik'] = \Helper::getSessionVar('username'); + $maildata['attachmentlocation'] = ''; + $maildata['attachmentfilename'] = ""; + $maildata['subject'] = $params->subject; + // $link=$this->registry->config->server_address . 'gembareport/'. $fileName; + $maildata['link'] = ''; + + $maildata['message'] = " + + + +
+ + + +
+
+
+
+

Dear " . $empReqto[0]['full_name'] . ",

+

" . $params->content . "

+
+
+ Regards,
+ HCPORTAL SYSTEM

+
Email is sent automatically by the hcportal system [" . \Helper::ubah_tgl_no_space(date('Y-m-d')) . "]
Please do not reply!

+ "; + + return $mail->sendMail($maildata); + } catch (PDOException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function saveDataIssues($attributes, $mail, $isUpdate = false) + { + $this->registry->db->beginTransaction(); + try { + + $nik = \Helper::getSessionVar('username'); + $message = "PAYROLL.MESSAGE.FAILMESERRREQ"; + $status = "PAYROLL.MESSAGE.FAILED"; + + $response = $this->sendResponse([], $message, $status); + + $stmtIns = $this->setStatementInsStatus(); + $stmtUpd = $this->setStatementUpdStatus(); + + $attributes->due_date = \Helper::utcToIso($attributes->due_date); + $dataExist = $this->checkDataIfExist($attributes); + if ($dataExist) { + $stmt = $stmtUpd; + } else { + $stmt = $stmtIns; + } + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + $result = $this->processData($stmt, $attributes, $nik); + if ($result) { + if (isset($attributes->empno) && !empty($attributes->empno)) { + $attributes->subject = "GENBA - PIC assignment"; + $attributes->content = "Dengan berlangsungnya kegiatan GENBA, kami menugaskan bapak/ibu untuk menjadi PIC dalam menghandle issue assessment tentng " . $attributes->issues . "."; + $setMail = $this->sendMail($attributes, $mail); + } + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + $response = $this->sendResponse([], $message, $status); + + $this->registry->db->commit(); + } + + return $response; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + private function processData($stmt, $attributes, $nik) + { + try { + $stmt->bindValue(':gmb_asessor_result_id', $attributes->gmb_asessor_result_id, PDO::PARAM_STR); + $stmt->bindValue(':note', $attributes->note, PDO::PARAM_STR); + $stmt->bindValue(':pic', $attributes->empno, PDO::PARAM_STR); + $stmt->bindValue(':risk_level', $attributes->risk_level, PDO::PARAM_STR); + $stmt->bindValue(':status', $attributes->status, PDO::PARAM_STR); + $stmt->execute(); + + return true; + } catch (PDOexception $e) { + $this->registry + ->log + ->error('Message :' + . $e->getMessage() . ', Line: ' + . $e->getLine() . ', File: ' + . $e->getFile() . ', User: ' + . $nik); + + return false; + } catch (ErrorException $e) { + $this->registry + ->log + ->error('Message :' + . $e->getMessage() . ', Line: ' + . $e->getLine() . ', File: ' + . $e->getFile() . ', User: ' + . $nik); + + return false; + } + } + + public function checkDataIfExist($attributes) + { + try { + $stmt = $this->setStatementGetStatus(); + $stmt->bindValue(':id', $attributes->gmb_asessor_result_id, PDO::PARAM_STR); + $stmt->execute(); + + return $stmt->rowCount() > 0 ? true : false; + } catch (PDOException $e) { + $this->registry->log->error('message: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('message: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getResponsCount($stmt, $id) + { + try { + $stmt->bindValue(':id', $id, PDO::PARAM_STR); + $stmt->execute(); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + return count($rs) > 0 ? $rs[0]['total'] : 0; + } catch (PDOException $e) { + $this->registry->log->error('message: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('message: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function updateGeneralIssues($attributes) + { + $this->registry->db->beginTransaction(); + try { + + $nik = \Helper::getSessionVar('username'); + $message = "PAYROLL.MESSAGE.FAILMESERRREQ"; + $status = "PAYROLL.MESSAGE.FAILED"; + + $response = $this->sendResponse([], $message, $status); + + $stmt = $this->setStatementUpdDueDate(); + + $attributes->due_date = \Helper::utcToIso($attributes->due_date); + + $stmt->bindValue(':id', $attributes->id, PDO::PARAM_STR); + // $stmt->bindValue(':due_date', $attributes->due_date, PDO::PARAM_STR); + $stmt->bindValue(':pic', $attributes->empno, PDO::PARAM_STR); + $stmt->execute(); + + if ($stmt) { + if (isset($attributes->empno) && !empty($attributes->empno)) { + $attributes->subject = "GENBA - PIC assignment"; + $attributes->content = "Dengan berlangsungnya kegiatan GENBA, kami menugaskan bapak/ibu untuk menjadi PIC dalam menghandle issue general."; + // $setMail = $this->sendMail($attributes, $mail); + } + $message = "PAYROLL.MESSAGE.SUCCMESUPD"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + $response = $this->sendResponse([], $message, $status); + + $this->registry->db->commit(); + } + + return $response; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function updateReportName($params, $file_name) + { + try { + $this->registry->db->beginTransaction(); + + if (!$params['assesor_id']) { + $event_update = $this->dbBuilderUpdate('gmb_events', [ + ['key' => 'file_report', 'val' => $file_name, 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_INT], + ]); + + if (!$event_update) { + return false; + } + } else { + $event_update = $this->dbBuilderUpdate('gmb_event_asessor', [ + ['key' => 'file_report', 'val' => $file_name, 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_INT], + ]); + + if (!$event_update) { + return false; + } + } + + + $this->registry->db->commit(); + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-updateReportName: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-updateReportName: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function sendReport($params, $mail) + { + try { + + $fileName = ''; + if (!$params['assesor_id']) { + $rs = $this->dbBuilderSelectJoin( + 'gmb_events t1', + [ + 't1.file_report' + ], + [ + ['field' => 'id', 'key' => 't1.id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR] + ] + ); + + + if (count($rs) > 0) { + $fileName = $rs[0]['file_report']; + } + } else { + $rs = $this->dbBuilderSelectJoin( + 'gmb_event_asessor t1', + [ + 't1.file_report' + ], + [ + ['field' => 'id', 'key' => 't1.id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_STR] + ] + ); + + + if (count($rs) > 0) { + $fileName = $rs[0]['file_report']; + } + } + + $mail_list = explode(';', $params['mail']); + $address = $mail_list[0]; + + if (count($mail_list) > 0) { + array_splice($mail_list, 0, 1); + } + + $address_cc = $mail_list; + + $maildata['address'] = $address; + $maildata['address_cc_mail'] = $address_cc; + $maildata['addressname'] = ""; + $maildata['empreqname'] = ""; + $maildata['attachmentlocation'] = ''; + $maildata['attachmentfilename'] = $fileName; + $maildata['subject'] = "Genba Result Report"; + $link = $this->registry->config->base_link_access_doc . '/gembareport/' . $fileName; + $maildata['link'] = ''; + + + + $rsmail = $mail->sendMail($maildata); + // var_dump($rsmail);die(); + + if (!$rsmail) { + throw new Exception("3"); + } + // } + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + $response = $this->sendResponse([], $message, $status); + + return $response; + } catch (PDOException $e) { + $this->registry->log->error('module Admin / sendReport:' . $e->getMessage() . 'line :' . $e->getLine()); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module Admin / sendReport:' . $e->getMessage() . 'line :' . $e->getLine()); + return false; + } + } + + public function getDataQuestionGroup() + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_group t1', + [ + 't1.*', + '0 as edit' + ], + [] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataManufatureProduct() + { + try { + $rs = $this->dbBuilderSelectJoin( + 'ref_manufacture_products t1 + INNER JOIN ref_manunfactures t2 ON t1.ref_manunfactures_id = t2.id + INNER JOIN ref_master_category_product_plant t3 ON t1.ref_master_category_product_plant_id = t3.id', + [ + 't1.*', + 't2.plan_name', + 't3.category_name' + ], + [] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function setMarkAsRead($attributes) + { + $this->registry->db->beginTransaction(); + try { + $nik = \Helper::getSessionVar('username'); + + $message = "PAYROLL.MESSAGE.FAILMESERRREQ"; + $status = "PAYROLL.MESSAGE.FAILED"; + + $response = $this->sendResponse([], $message, $status); + + $stmtCheckGenIssue = $this->setStatementCheckGenIssueRead(); + $stmtInsGenIssue = $this->setStatementInsGenIssueRead(); + $stmtCheckIssue = $this->setStatementCheckIssueRead(); + $stmtInsIssue = $this->setStatementInsIssueRead(); + + $stmtCheck = $stmtCheckIssue; + $stmtIns = $stmtInsIssue; + if ($attributes['source'] == 'general') { + $stmtCheck = $stmtCheckGenIssue; + $stmtIns = $stmtInsGenIssue; + } + + $check = $this->processByIdAndNik($stmtCheck, $attributes['id'], $nik); + if ($check->rowCount() == 0) { + $rs = $this->processByIdAndNik($stmtIns, $attributes['id'], $nik); + if ($rs) { + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + } + } + + $response = $this->sendResponse([], $message, $status); + + $this->registry->db->commit(); + + return [$response]; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function processByIdAndNik($stmt, $id, $nik) + { + try { + $stmt->bindValue(':id', $id, PDO::PARAM_STR); + $stmt->bindValue(':nik', $nik, PDO::PARAM_STR); + $stmt->execute(); + + return $stmt; + } catch (PDOException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function viewDataMasterQuestionCategory($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_category t1', + [ + 't1.*' + ], + [ + ['field' => 'category_name', 'key' => 't1.category_name', 'val' => $params['category_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmb_question_category t1', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestionCategory($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmb_question_category', + [ + ['key' => 'category_name', 'val' => $data->category_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmb_question_category', + [ + ['key' => 'category_name', 'val' => $data->category_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionCategory: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionCategory: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestionCategory($id) + { + try { + + $this->registry->db->beginTransaction(); + + + $this->dbBuilderDelete('gmb_question_category', 'id', $id); + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionCategory: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionCategory: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterQuestionGroup($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_group t1', + [ + 't1.*' + ], + [ + ['field' => 'group_name', 'key' => 't1.group_name', 'val' => $params['group_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmb_question_group t1', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestionGroup($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmb_question_group', + [ + ['key' => 'group_name', 'val' => $data->group_name, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmb_question_group', + [ + ['key' => 'group_name', 'val' => $data->group_name, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionGroup: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionGroup: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestionGroup($id) + { + try { + + $this->registry->db->beginTransaction(); + + + $this->dbBuilderDelete('gmb_question_group', 'id', $id); + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionGroup: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionGroup: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterQuestionSection($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_section t1 + INNER JOIN ref_manufacture_products t2 ON t1.ref_manufacture_products_id = t2.id + INNER JOIN ref_manunfactures t3 ON t2.ref_manunfactures_id = t3.id + INNER JOIN ref_master_category_product_plant t4 ON t2.ref_master_category_product_plant_id = t4.id', + [ + 't1.*', + 't3.plan_name', + 't4.category_name' + ], + [ + ['field' => 'ref_manufacture_products_id', 'key' => 't1.ref_manufacture_products_id', 'val' => $params['ref_manufacture_products_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'ref_manufacture_products_id', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'section_name', 'key' => 't1.section_name', 'val' => $params['section_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE', 'start_symbol' => ' ( '], + ['field' => 'section_code', 'key' => 't1.section_code', 'val' => $params['section_code'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE', 'end_symbol' => ' ) '], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmb_question_section t1', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestionSection($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmb_question_section', + [ + ['key' => 'section_name', 'val' => $data->section_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'section_code', 'val' => $data->section_code, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manufacture_products_id', 'val' => $data->ref_manufacture_products_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmb_question_section', + [ + ['key' => 'section_name', 'val' => $data->section_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'section_code', 'val' => $data->section_code, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manufacture_products_id', 'val' => $data->ref_manufacture_products_id, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionSection: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionSection: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestionSection($id) + { + try { + + $this->registry->db->beginTransaction(); + + + $this->dbBuilderDelete('gmb_question_section', 'id', $id); + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionSection: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionSection: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterQuestionType($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_types t1', + [ + 't1.*' + ], + [ + ['field' => 'type_name', 'key' => 't1.type_name', 'val' => $params['type_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ['field' => 'code_type', 'key' => 't1.code_type', 'val' => $params['code_type'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmb_question_types t1', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestionType($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmb_question_types', + [ + ['key' => 'type_name', 'val' => $data->type_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'code_type', 'val' => $data->code_type, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmb_question_types', + [ + ['key' => 'type_name', 'val' => $data->type_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'code_type', 'val' => $data->code_type, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionType: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionType: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestionType($id) + { + try { + + $this->registry->db->beginTransaction(); + + + $this->dbBuilderDelete('gmb_question_types', 'id', $id); + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionType: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionType: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterQuestion($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmb_questions t1 + INNER JOIN gmb_question_group t2 ON t1.gmb_question_group_id = t2.id + INNER JOIN gmb_question_types t3 ON t1.gmb_question_types_id = t3.id + INNER JOIN gmb_question_category t4 ON t1.gmb_question_category_id = t4.id + INNER JOIN gmb_question_section t5 ON t1.gmb_question_section_id = t5.id + INNER JOIN ref_manufacture_products t6 ON t5.ref_manufacture_products_id = t6.id + INNER JOIN ref_manunfactures t7 ON t6.ref_manunfactures_id = t7.id + INNER JOIN ref_master_category_product_plant t8 ON t6.ref_master_category_product_plant_id = t8.id', + [ + 't1.*', + 't2.group_name', + 't3.type_name', + 't4.category_name', + 't5.section_name', + 't7.plan_name', + 't8.category_name as category_product_name' + ], + [ + ['field' => 'question_code', 'key' => 't1.question_code', 'val' => $params['question_code'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ['field' => 'question', 'key' => 't1.question', 'val' => $params['question'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ['field' => 'question_description', 'key' => 't1.question_description', 'val' => $params['question_description'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ['field' => 'is_need_upload_file', 'key' => 't1.is_need_upload_file', 'val' => $params['is_need_upload_file'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'is_need_upload_file', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => $params['is_publish'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'is_publish', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'gmb_question_types_id', 'key' => 't1.gmb_question_types_id', 'val' => $params['gmb_question_types_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'gmb_question_types_id', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'gmb_question_group_id', 'key' => 't1.gmb_question_group_id', 'val' => $params['gmb_question_group_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'gmb_question_group_id', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'gmb_question_category_id', 'key' => 't1.gmb_question_category_id', 'val' => $params['gmb_question_category_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'gmb_question_category_id', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'gmb_question_section_id', 'key' => 't1.gmb_question_section_id', 'val' => $params['gmb_question_section_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'gmb_question_section_id', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'ref_manufacture_products_id', 'key' => 't5.ref_manufacture_products_id', 'val' => $params['ref_manufacture_products_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'ref_manufacture_products_id', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmb_questions t1', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestion($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmb_questions', + [ + ['key' => 'section_name', 'val' => $data->section_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'section_code', 'val' => $data->section_code, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manufacture_products_id', 'val' => $data->ref_manufacture_products_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmb_questions', + [ + ['key' => 'section_name', 'val' => $data->section_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'section_code', 'val' => $data->section_code, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manufacture_products_id', 'val' => $data->ref_manufacture_products_id, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestion: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestion: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestion($id) + { + try { + + $this->registry->db->beginTransaction(); + + + $this->dbBuilderDelete('gmb_questions', 'id', $id); + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestion: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestion: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function getDataCompany() + { + try { + $rs = $this->dbBuilderSelectJoin( + 'company t1', + [ + 't1.*' + ], + [] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataSubArea($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'sub_area t1', + [ + 't1.*' + ], + [ + ['field' => 'company_id', 'key' => 't1.company_id', 'val' => $params['company_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataSubAreaRefManufacture($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'sub_area t1 + INNER JOIN ref_manufacture_sub_area t2 ON t1.id=t2.sub_area_id', + [ + 't1.*' + ], + [ + ['field' => 'ref_manunfactures_id', 'key' => 't2.ref_manunfactures_id', 'val' => $params['ref_manunfactures_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataGedung($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gedung t1', + [ + 't1.*' + ], + [ + ['field' => 'sub_area_id', 'key' => 't1.sub_area_id', 'val' => $params['sub_area_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataRefShiftGroup($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'ref_shift_group t1', + [ + 't1.*' + ], + [ + ['field' => 'sub_area_id', 'key' => 't1.sub_area_id', 'val' => $params['sub_area_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataSector($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gedung_sector t1', + [ + 't1.*' + ], + [ + ['field' => 'gedung_id', 'key' => 't1.gedung_id', 'val' => $params['gedung_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataLine($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gedung_sector_line t1', + [ + 't1.*' + ], + [ + ['field' => 'gedung_sector_id', 'key' => 't1.gedung_sector_id', 'val' => $params['sector_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataDivision($params) + { + try { + + if (isset($params['company_id'])) { + $company = $params['company_id']; + } else { + $company = \Helper::getSessionVar('empSite'); + } + + $rs = $this->dbBuilderSelectJoin( + 'division t1 + INNER JOIN `division_department` t2 ON t1.`id` = t2.`division_id`', + [ + 'DISTINCT(t1.`id`)', + 't1.`description`' + ], + [ + ['field' => 'bu', 'key' => 't2.bu', 'val' => $company, 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataDepartment($params) + { + try { + + $where = []; + + if (isset($params['company_id'])) { + $company = $params['company_id']; + } else { + $company = \Helper::getSessionVar('empSite'); + } + + + array_push($where, ['field' => 'bu', 'key' => 't1.bu', 'val' => $company, 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + + + if (isset($params['division_id'])) { + array_push($where, ['field' => 'division_id', 'key' => 't1.division_id', 'val' => $params['division_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + $rs = $this->dbBuilderSelectJoin( + '`division_department` t1 INNER JOIN + `department` t2 ON t1.`department_id` = t2.`id`', + [ + 't2.id', + 't2.description' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataBusinessUnit($params) + { + try { + $where = []; + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => 1, 'bind' => PDO::PARAM_STR]); + + if (isset($params['line_id'])) { + array_push($where, ['field' => 'gedung_sector_line_id', 'key' => 't1.gedung_sector_line_id', 'val' => $params['line_id'], 'bind' => PDO::PARAM_STR]); + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_business_unit t1 + INNER JOIN gedung_sector_line t2 ON t1.gedung_sector_line_id = t2.id + INNER JOIN gedung_sector t3 ON t2.gedung_sector_id = t3.id + INNER JOIN gedung t4 ON t3.gedung_id = t4.id', + [ + 't1.*', + 't2.line_number', + 't3.sector_name', + 't4.gedung_name' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataSection($params) + { + try { + $where = []; + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => 1, 'bind' => PDO::PARAM_STR]); + + if (isset($params['gmbs_business_unit_id'])) { + array_push($where, ['field' => 'gmbs_business_unit_id', 'key' => 't1.gmbs_business_unit_id', 'val' => $params['gmbs_business_unit_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if (isset($params['department_id'])) { + array_push($where, ['field' => 'department_id', 'key' => 't1.department_id', 'val' => $params['department_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_question_section t1 + INNER JOIN gmbs_business_unit t2 ON t1.gmbs_business_unit_id = t2.id + INNER JOIN gedung_sector_line t3 ON t2.gedung_sector_line_id = t3.id + INNER JOIN gedung_sector t4 ON t3.gedung_sector_id = t4.id + INNER JOIN gedung t5 ON t4.gedung_id = t5.id + INNER JOIN sub_area t6 ON t5.sub_area_id = t6.id + INNER JOIN company t7 ON t6.company_id = t7.id + INNER JOIN department t8 ON t1.department_id = t8.id', + [ + 't1.*', + 't2.bu_name', + 't7.description as company_name', + 't6.description as sub_area_name', + 't5.gedung_name as gedung_name', + 't4.sector_name as sector_name', + 't3.line_number as line_name', + 't8.description as department_name' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataCategory() + { + try { + $where = []; + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => 1, 'bind' => PDO::PARAM_STR]); + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_question_category t1', + [ + 't1.*' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataRiskLevel() + { + try { + $where = []; + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => 1, 'bind' => PDO::PARAM_STR]); + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_ref_risk_level t1', + [ + 't1.*' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataWorkScopes() + { + try { + $where = []; + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => 1, 'bind' => PDO::PARAM_STR]); + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_ref_work_scopes t1', + [ + 't1.*' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterRefBusinessUnit($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmbs_ref_business_unit', + [ + ['key' => 'bu_name', 'val' => $data->bu_name, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $data->description, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manunfactures_id', 'val' => $data->ref_manunfactures_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmbs_ref_business_unit', + [ + ['key' => 'bu_name', 'val' => $data->bu_name, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $data->description, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manunfactures_id', 'val' => $data->ref_manunfactures_id, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterRefBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterRefBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterRefBusinessUnit($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_ref_business_unit t1 + INNER JOIN ref_manunfactures t2 ON t1.ref_manunfactures_id = t2.id ', + [ + 't1.id', + 't1.bu_name', + 't1.description', + 't1.ref_manunfactures_id as ref_manunfactures_id', + 't2.plan_name' + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR], + ['field' => 'bu_name', 'key' => 't1.bu_name', 'val' => $params['bu_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_ref_business_unit t1 + INNER JOIN ref_manunfactures t2 ON t1.ref_manunfactures_id = t2.id ', + [ + 'count(t1.id) as total', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR], + ] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterBusinessUnit($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + $gmbs_ref_business_unit = $this->dbBuilderSelectJoin( + 'gmbs_ref_business_unit t1', + [ + 't1.*' + ], + [ + ['field' => 'id', 'key' => 't1.id', 'val' => $data->gmbs_ref_business_unit_id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmbs_business_unit', + [ + ['key' => 'bu_name', 'val' => $gmbs_ref_business_unit[0]['bu_name'], 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $gmbs_ref_business_unit[0]['description'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_business_unit_id', 'val' => $data->gmbs_ref_business_unit_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gedung_sector_line_id', 'val' => $data->line_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmbs_business_unit', + [ + ['key' => 'bu_name', 'val' => $gmbs_ref_business_unit[0]['bu_name'], 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $gmbs_ref_business_unit[0]['description'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_business_unit_id', 'val' => $data->gmbs_ref_business_unit_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gedung_sector_line_id', 'val' => $data->line_id, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + $message = "Terjadi duplikasi data dalam insert / update data"; + $status = "PAYROLL.MESSAGE.FAILED"; + + $this->sendResponse([], $message, $status); + + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterBusinessUnit($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_business_unit t1 + INNER JOIN gedung_sector_line t2 ON t1.gedung_sector_line_id = t2.id + INNER JOIN gedung_sector t3 ON t2.gedung_sector_id = t3.id + INNER JOIN gedung t4 ON t3.gedung_id = t4.id + INNER JOIN sub_area t5 ON t4.sub_area_id = t5.id + INNER JOIN company t6 ON t5.company_id = t6.id + INNER JOIN gmbs_ref_business_unit t7 ON t1.gmbs_ref_business_unit_id = t7.id', + [ + 't1.id', + 't1.bu_name', + 't1.description', + 't1.gedung_sector_line_id as line_id', + 't2.gedung_sector_id as sector_id', + 't3.gedung_id', + 't4.sub_area_id', + 't5.company_id', + 't6.description as company_name', + 't5.description as sub_area_name', + 't4.gedung_name as gedung_name', + 't3.sector_name as sector_name', + 't2.line_number as line_name', + 't1.gmbs_ref_business_unit_id as gmbs_ref_business_unit_id', + 't7.ref_manunfactures_id as ref_manunfactures_id' + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR], + ['field' => 'bu_name', 'key' => 't1.bu_name', 'val' => $params['bu_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ['field' => 'bu_name', 'key' => 't1.bu_name', 'val' => $params['search'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_business_unit t1 + INNER JOIN gedung_sector_line t2 ON t1.gedung_sector_line_id = t2.id + INNER JOIN gedung_sector t3 ON t2.gedung_sector_id = t3.id + INNER JOIN gedung t4 ON t3.gedung_id = t4.id + INNER JOIN sub_area t5 ON t4.sub_area_id = t5.id + INNER JOIN company t6 ON t5.company_id = t6.id', + [ + 'count(t1.id) as total', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR], + ['field' => 'bu_name', 'key' => 't1.bu_name', 'val' => $params['bu_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ['field' => 'bu_name', 'key' => 't1.bu_name', 'val' => $params['search'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestionCategorySelf($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmbs_question_category', + [ + ['key' => 'category_name', 'val' => $data->category_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmbs_question_category', + [ + ['key' => 'category_name', 'val' => $data->category_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionCategorySelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionCategorySelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterQuestionCategorySelf($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_question_category t1', + [ + 't1.*' + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR], + ['field' => 'category_name', 'key' => 't1.category_name', 'val' => $params['category_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_question_category t1', + [ + 'count(t1.id) as total', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR] + ] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestionSectionSelf($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + foreach ($data->section_list as $key => $value) { + $master = $this->dbBuilderInsert( + 'gmbs_question_section', + [ + ['key' => 'section_name', 'val' => $value->section_name, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_business_unit_id', 'val' => $data->gmbs_business_unit_id, 'bind' => PDO::PARAM_STR], + ['key' => 'department_id', 'val' => $data->department_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } + } else { + foreach ($data->section_list as $key => $value) { + $master_update = $this->dbBuilderUpdate( + 'gmbs_question_section', + [ + ['key' => 'section_name', 'val' => $value->section_name, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_business_unit_id', 'val' => $data->gmbs_business_unit_id, 'bind' => PDO::PARAM_STR], + ['key' => 'department_id', 'val' => $data->department_id, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionSectionSelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionSectionSelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterQuestionSectionSelf($params) + { + try { + + $where = []; + + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR]); + + array_push($where, ['field' => 'company_id', 'key' => 't6.company_id', 'val' => $params['company_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'company_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gmbs_business_unit_id', 'key' => 't1.gmbs_business_unit_id', 'val' => $params['gmbs_business_unit_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gmbs_business_unit_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'line_id', 'key' => 't2.gedung_sector_line_id', 'val' => $params['line_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'line_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'sector_id', 'key' => 't3.gedung_sector_id', 'val' => $params['sector_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'sector_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gedung_id', 'key' => 't4.gedung_id', 'val' => $params['gedung_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gedung_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'sub_area_id', 'key' => 't5.sub_area_id', 'val' => $params['sub_area_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'sub_area_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'department_id', 'key' => 't1.department_id', 'val' => $params['department_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'department_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + if ($params['section_name']) { + array_push($where, ['field' => 'section_name', 'key' => 't1.section_name', 'val' => $params['section_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_question_section t1 + INNER JOIN gmbs_business_unit t2 ON t1.gmbs_business_unit_id = t2.id + INNER JOIN gedung_sector_line t3 ON t2.gedung_sector_line_id = t3.id + INNER JOIN gedung_sector t4 ON t3.gedung_sector_id = t4.id + INNER JOIN gedung t5 ON t4.gedung_id = t5.id + INNER JOIN sub_area t6 ON t5.sub_area_id = t6.id + INNER JOIN company t7 ON t6.company_id = t7.id + INNER JOIN department t8 ON t1.department_id = t8.id', + [ + 't1.id', + 't1.section_name', + 't1.gmbs_business_unit_id', + 't1.department_id', + 't2.bu_name', + 't2.gedung_sector_line_id as line_id', + 't3.gedung_sector_id as sector_id', + 't4.gedung_id', + 't5.sub_area_id', + 't6.company_id', + 't7.description as company_name', + 't6.description as sub_area_name', + 't5.gedung_name as gedung_name', + 't4.sector_name as sector_name', + 't3.line_number as line_name', + 't8.description as department_name' + ], + $where, + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_question_section t1 + INNER JOIN gmbs_business_unit t2 ON t1.gmbs_business_unit_id = t2.id + INNER JOIN gedung_sector_line t3 ON t2.gedung_sector_line_id = t3.id + INNER JOIN gedung_sector t4 ON t3.gedung_sector_id = t4.id + INNER JOIN gedung t5 ON t4.gedung_id = t5.id + INNER JOIN sub_area t6 ON t5.sub_area_id = t6.id + INNER JOIN company t7 ON t6.company_id = t7.id + INNER JOIN department t8 ON t1.department_id = t8.id', + [ + 'count(t1.id) as total', + ], + $where + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterRiskLevel($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmbs_ref_risk_level', + [ + ['key' => 'risk_level_name', 'val' => $data->risk_level_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmbs_ref_risk_level', + [ + ['key' => 'risk_level_name', 'val' => $data->risk_level_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterRiskLevel: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterRiskLevel: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterRiskLevel($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_ref_risk_level t1', + [ + 't1.*', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR] + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_ref_risk_level t1', + [ + 'count(t1.id) as total', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR] + ] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterWorkScopes($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmbs_ref_work_scopes', + [ + ['key' => 'scope_name', 'val' => $data->scope_name, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $data->description, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmbs_ref_work_scopes', + [ + ['key' => 'scope_name', 'val' => $data->scope_name, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $data->description, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterWorkScopes: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterWorkScopes: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterWorkScopes($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_ref_work_scopes t1', + [ + 't1.*', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR] + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_ref_work_scopes t1', + [ + 'count(t1.id) as total', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR] + ] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterActivities($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + foreach ($data->activities as $key => $value) { + $master = $this->dbBuilderInsert( + 'gmbs_activities', + [ + ['key' => 'order_no', 'val' => $value->order_no, 'bind' => PDO::PARAM_STR], + ['key' => 'is_publish', 'val' => $value->is_publish, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $value->description, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $value->description, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_question_category_id', 'val' => $value->gmbs_question_category_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_question_section_id', 'val' => $data->gmbs_question_section_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_risk_level_id', 'val' => $value->gmbs_ref_risk_level_id, 'bind' => PDO::PARAM_STR], + ['key' => 'reference_link', 'val' => $value->reference_link, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + + foreach ($value->answer_detail as $j => $vj) { + $detail = $this->dbBuilderInsert( + 'gmbs_answer_detail', + [ + ['key' => 'answer_score', 'val' => $vj->answer_score, 'bind' => PDO::PARAM_STR], + ['key' => 'answer_label', 'val' => $vj->answer_label, 'bind' => PDO::PARAM_STR], + ['key' => 'order', 'val' => $vj->order, 'bind' => PDO::PARAM_STR], + ['key' => 'qualitative_answer', 'val' => $vj->qualitative_answer, 'bind' => PDO::PARAM_STR], + ['key' => 'is_require_note', 'val' => $vj->is_require_note, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_activities_id', 'val' => $master, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$detail) { + return false; + } + } + } + } else { + foreach ($data->activities as $key => $value) { + $master_update = $this->dbBuilderUpdate( + 'gmbs_activities', + [ + ['key' => 'order_no', 'val' => $value->order_no, 'bind' => PDO::PARAM_STR], + ['key' => 'is_publish', 'val' => $value->is_publish, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $value->description, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_question_category_id', 'val' => $value->gmbs_question_category_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_question_section_id', 'val' => $data->gmbs_question_section_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_risk_level_id', 'val' => $value->gmbs_ref_risk_level_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_work_scopes_id', 'val' => $value->gmbs_ref_work_scopes_id, 'bind' => PDO::PARAM_STR], + ['key' => 'reference_link', 'val' => $value->reference_link, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + + $this->dbBuilderDelete('gmbs_answer_detail', 'gmbs_activities_id', $data->id); + + foreach ($value->answer_detail as $j => $vj) { + $detail = $this->dbBuilderInsert( + 'gmbs_answer_detail', + [ + ['key' => 'answer_score', 'val' => $vj->answer_score, 'bind' => PDO::PARAM_STR], + ['key' => 'answer_label', 'val' => $vj->answer_label, 'bind' => PDO::PARAM_STR], + ['key' => 'order', 'val' => $vj->order, 'bind' => PDO::PARAM_STR], + ['key' => 'qualitative_answer', 'val' => $vj->qualitative_answer, 'bind' => PDO::PARAM_STR], + ['key' => 'is_require_note', 'val' => $vj->is_require_note, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_activities_id', 'val' => $data->id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$detail) { + return false; + } + } + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterActivities: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterActivities: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterActivities($params) + { + try { + + $where = []; + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR]); + + array_push($where, ['field' => 'gmbs_question_category_id', 'key' => 't1.gmbs_question_category_id', 'val' => $params['gmbs_question_category_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gmbs_question_category_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gmbs_question_section_id', 'key' => 't1.gmbs_question_section_id', 'val' => $params['gmbs_question_section_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gmbs_question_section_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gmbs_ref_risk_level_id', 'key' => 't1.gmbs_ref_risk_level_id', 'val' => $params['gmbs_ref_risk_level_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gmbs_ref_risk_level_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gmbs_ref_work_scopes_id', 'key' => 't1.gmbs_ref_work_scopes_id', 'val' => $params['gmbs_ref_work_scopes_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gmbs_ref_work_scopes_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gmbs_business_unit_id', 'key' => 't3.gmbs_business_unit_id', 'val' => $params['gmbs_business_unit_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gmbs_business_unit_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'line_id', 'key' => 't6.gedung_sector_line_id', 'val' => $params['line_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'line_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'sector_id', 'key' => 't7.gedung_sector_id', 'val' => $params['sector_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'sector_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gedung_id', 'key' => 't8.gedung_id', 'val' => $params['gedung_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gedung_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'sub_area_id', 'key' => 't9.sub_area_id', 'val' => $params['sub_area_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'sub_area_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'department_id', 'key' => 't3.department_id', 'val' => $params['department_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'department_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + if ($params['description']) { + array_push($where, ['field' => 'description', 'key' => 't1.description', 'val' => $params['description'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['search']) { + array_push($where, ['field' => 'description', 'key' => 't1.description', 'val' => $params['search'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_activities t1 + INNER JOIN gmbs_question_category t2 ON t1.gmbs_question_category_id = t2.id + INNER JOIN gmbs_question_section t3 ON t1.gmbs_question_section_id = t3.id + INNER JOIN gmbs_ref_risk_level t4 ON t1.gmbs_ref_risk_level_id = t4.id + INNER JOIN gmbs_ref_work_scopes t5 ON t1.gmbs_ref_work_scopes_id = t5.id + INNER JOIN gmbs_business_unit t6 ON t3.gmbs_business_unit_id = t6.id + INNER JOIN gedung_sector_line t7 ON t6.gedung_sector_line_id = t7.id + INNER JOIN gedung_sector t8 ON t7.gedung_sector_id = t8.id + INNER JOIN gedung t9 ON t8.gedung_id = t9.id + INNER JOIN sub_area t10 ON t9.sub_area_id = t10.id + INNER JOIN ref_manufacture_sub_area t11 ON t11.sub_area_id = t10.id + INNER JOIN ref_manunfactures t12 ON t11.ref_manunfactures_id = t12.id + INNER JOIN department t13 ON t3.department_id = t13.id', + [ + 't1.id', + 't1.order_no', + 't1.is_publish', + 't1.description', + 't1.reference_link', + 't1.gmbs_question_category_id', + 't1.gmbs_question_section_id', + 't1.gmbs_ref_risk_level_id', + 't1.gmbs_ref_work_scopes_id', + 't2.category_name', + 't3.section_name', + 't4.risk_level_name', + 't5.scope_name', + 't12.plan_name as ref_manufacture', + 't10.description as sub_area', + 't9.gedung_name as gedung', + 't8.sector_name as sector', + 't7.line_number as line', + 't7.line_number as line', + 't13.description as department', + 't6.bu_name as bu_name', + ], + $where, + "ORDER BY t3.section_name ASC, t1.order_no ASC LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_activities t1 + INNER JOIN gmbs_question_category t2 ON t1.gmbs_question_category_id = t2.id + INNER JOIN gmbs_question_section t3 ON t1.gmbs_question_section_id = t3.id + INNER JOIN gmbs_ref_risk_level t4 ON t1.gmbs_ref_risk_level_id = t4.id + INNER JOIN gmbs_ref_work_scopes t5 ON t1.gmbs_ref_work_scopes_id = t5.id + INNER JOIN gmbs_business_unit t6 ON t3.gmbs_business_unit_id = t6.id + INNER JOIN gedung_sector_line t7 ON t6.gedung_sector_line_id = t7.id + INNER JOIN gedung_sector t8 ON t7.gedung_sector_id = t8.id + INNER JOIN gedung t9 ON t8.gedung_id = t9.id + INNER JOIN sub_area t10 ON t9.sub_area_id = t10.id', + [ + 'count(t1.id) as total', + ], + $where + ); + + foreach ($rs as $key => $value) { + $rs[$key]['answer_detail'] = $this->dbBuilderSelectJoin( + 'gmbs_answer_detail t1', + [ + 't1.*', + ], + [ + ['field' => 'gmbs_activities_id', 'key' => 't1.gmbs_activities_id', 'val' => $value['id']], + ] + ); + } + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataLineRunning($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmbs_line_running', + [ + ['key' => 'running_date', 'val' => date('Y-m-d', strtotime($data->running_date)), 'bind' => PDO::PARAM_STR], + ['key' => 'ref_shift_group_id', 'val' => $data->ref_shift_group_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gedung_sector_line_id', 'val' => $data->line_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmbs_line_running', + [ + ['key' => 'running_date', 'val' => date('Y-m-d', strtotime($data->running_date)), 'bind' => PDO::PARAM_STR], + ['key' => 'ref_shift_group_id', 'val' => $data->ref_shift_group_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gedung_sector_line_id', 'val' => $data->line_id, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataLineRunning: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataLineRunning: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataLineRunning($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_line_running t1 + INNER JOIN gedung_sector_line t2 ON t1.gedung_sector_line_id = t2.id + INNER JOIN gedung_sector t3 ON t2.gedung_sector_id = t3.id + INNER JOIN gedung t4 ON t3.gedung_id = t4.id + INNER JOIN sub_area t5 ON t4.sub_area_id = t5.id + INNER JOIN company t6 ON t5.company_id = t6.id + INNER JOIN ref_shift_group t7 ON t1.ref_shift_group_id = t7.id', + [ + 't1.id', + 't1.running_date', + 't1.ref_shift_group_id', + 't1.gedung_sector_line_id as line_id', + 't2.gedung_sector_id as sector_id', + 't3.gedung_id', + 't4.sub_area_id', + 't5.company_id', + 't6.description as company_name', + 't5.description as sub_area_name', + 't4.gedung_name as gedung_name', + 't3.sector_name as sector_name', + 't2.line_number as line_name', + 't7.shift_group_name as shift_group_name' + ], + [ + // ['field' => 'running_date','key' => 't1.running_date', 'val' => $params['running_date'], 'bind' => PDO::PARAM_STR,'opr'=>'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_line_running t1 + INNER JOIN gedung_sector_line t2 ON t1.gedung_sector_line_id = t2.id + INNER JOIN gedung_sector t3 ON t2.gedung_sector_id = t3.id + INNER JOIN gedung t4 ON t3.gedung_id = t4.id + INNER JOIN sub_area t5 ON t4.sub_area_id = t5.id + INNER JOIN company t6 ON t5.company_id = t6.id', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataEventPic($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + + foreach ($data->pic as $key => $value) { + if (!$value->id) { + $master = $this->dbBuilderInsert( + 'gmbs_event_pic', + [ + ['key' => 'pic_nik', 'val' => $value->nik, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_shift_group_id', 'val' => $data->ref_shift_group_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_department_group_shift_id', 'val' => $data->gmbs_department_group_shift_id, 'bind' => PDO::PARAM_STR], + ['key' => 'action_by', 'val' => \Helper::getSessionVar('username'), 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } + } + + foreach ($data->delete as $key => $value) { + if (!$value->id) { + $this->dbBuilderDelete('gmbs_event_pic', 'id', $value->id); + } + } + + + + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataEventPic: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataEventPic: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataEventPic($params) + { + try { + + $userCekAdmin = $this->getCekUserAdminSelf($params); + $sub_area_id = ''; + $department_id = ''; + + $where = []; + + + + if ($userCekAdmin) { + $sub_area_id = $userCekAdmin['sub_area_id']; + $department_id = $userCekAdmin['department_id']; + if ($userCekAdmin['is_admin'] == '0') { + array_push($where, ['field' => 'department_id', 'key' => 't9.department_id', 'val' => $department_id, 'bind' => PDO::PARAM_STR]); + array_push($where, ['field' => 'sub_area_id', 'key' => 't6.sub_area_id', 'val' => $sub_area_id, 'bind' => PDO::PARAM_STR]); + } + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_events t1 + INNER JOIN ref_manunfactures t2 ON t1.ref_manufactures_id = t2.id + LEFT JOIN gmbs_event_member_lines t3 ON t1.id = t3.gmbs_events_id + LEFT JOIN gedung_sector_line t4 ON t3.gedung_sector_line_id = t4.id + LEFT JOIN gedung_sector t5 ON t4.gedung_sector_id = t5.id + LEFT JOIN gedung t6 ON t5.gedung_id = t6.id + LEFT JOIN sub_area t7 ON t6.sub_area_id = t7.id + LEFT JOIN company t8 ON t7.company_id = t8.id + LEFT JOIN gmbs_event_member_line_departments t9 ON t9.gmbs_event_member_lines_id = t3.id + LEFT JOIN gmbs_department_group_shift t10 ON t10.gmbs_event_member_line_departments_id = t9.id + LEFT JOIN ref_shift_group t11 ON t10.ref_shift_group_id = t11.id + LEFT JOIN department t12 ON t9.department_id = t12.id', + [ + 't1.id', + 't1.description', + 't1.start_date', + 't1.end_date', + 't1.ref_manufactures_id', + 't2.plan_name' + ], + $where, + "GROUP BY t1.id ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_events t1 + INNER JOIN ref_manunfactures t2 ON t1.ref_manufactures_id = t2.id', + [ + 'count(t1.id) as total', + ], + [] + ); + + foreach ($rs as $key => $value) { + $where_line = []; + array_push($where_line, ['field' => 'gmbs_events_id', 'key' => 't1.gmbs_events_id', 'val' => $value['id'], 'bind' => PDO::PARAM_STR]); + if ($userCekAdmin) { + $sub_area_id = $userCekAdmin['sub_area_id']; + $department_id = $userCekAdmin['department_id']; + if ($userCekAdmin['is_admin'] == '0') { + array_push($where_line, ['field' => 'department_id', 'key' => 't7.department_id', 'val' => $department_id, 'bind' => PDO::PARAM_STR]); + array_push($where_line, ['field' => 'sub_area_id', 'key' => 't6.sub_area_id', 'val' => $sub_area_id, 'bind' => PDO::PARAM_STR]); + } + } + $rs[$key]['member_line'] = $this->dbBuilderSelectJoin( + 'gmbs_event_member_lines t1 + INNER JOIN gedung_sector_line t2 ON t1.gedung_sector_line_id = t2.id + INNER JOIN gedung_sector t3 ON t2.gedung_sector_id = t3.id + INNER JOIN gedung t4 ON t3.gedung_id = t4.id + INNER JOIN sub_area t5 ON t4.sub_area_id = t5.id + INNER JOIN company t6 ON t5.company_id = t6.id + INNER JOIN gmbs_event_member_line_departments t7 ON t7.gmbs_event_member_lines_id = t1.id + INNER JOIN gmbs_department_group_shift t8 ON t8.gmbs_event_member_line_departments_id = t7.id + INNER JOIN ref_shift_group t9 ON t8.ref_shift_group_id = t9.id + INNER JOIN department t10 ON t7.department_id = t10.id ', + [ + 't1.*', + 't2.gedung_sector_id as sector_id', + 't3.gedung_id', + 't4.sub_area_id', + 't5.company_id', + 't6.description as company_name', + 't5.description as sub_area_name', + 't4.gedung_name as gedung_name', + 't3.sector_name as sector_name', + 't2.line_number as line_name', + 't9.shift_group_name', + 't8.ref_shift_group_id', + 't8.id as gmbs_department_group_shift_id', + 't10.id as department_id', + 't10.description as department_name', + '(SELECT COUNT(*) FROM gmbs_event_pic WHERE gmbs_department_group_shift_id=t8.id) as total_pic' + ], + $where_line + ); + } + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataPicEvent($params) + { + try { + + $gmbs_event_pic = $this->dbBuilderSelectJoin( + 'gmbs_event_pic t1', + [ + 't1.id', + 't1.pic_nik as nik', + 'getEmpName(t1.pic_nik) as emp_name', + ], + [ + ['field' => 'gmbs_department_group_shift_id', 'key' => 't1.gmbs_department_group_shift_id', 'val' => $params['gmbs_department_group_shift_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + + $rData['gmbs_event_pic'] = $gmbs_event_pic; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataEventGembaSelf($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gmbs_events t1', + [ + 't1.*' + ], + [] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function viewDataMonitoringGembaSelf($params) + { + try { + + $where = []; + + array_push($where, ['field' => 'qualitative_answer', 'key' => 't3.qualitative_answer', 'val' => 'Tidak Standar', 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + + if ($params['event_id']) { + array_push($where, ['field' => 'gmbs_events_id', 'key' => 't8.gmbs_events_id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['ref_manunfactures_id']) { + array_push($where, ['field' => 'ref_manufactures_id', 'key' => 't9.ref_manufactures_id', 'val' => $params['ref_manunfactures_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['sub_area_id']) { + array_push($where, ['field' => 'sub_area_id', 'key' => 't14.sub_area_id', 'val' => $params['sub_area_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['gedung_id']) { + array_push($where, ['field' => 'gedung_id', 'key' => 't13.gedung_id', 'val' => $params['gedung_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['sector_id']) { + array_push($where, ['field' => 'gedung_sector_id', 'key' => 't12.gedung_sector_id', 'val' => $params['sector_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['line_id']) { + array_push($where, ['field' => 'gedung_sector_line_id', 'key' => 't11.gedung_sector_line_id', 'val' => $params['line_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['date']) { + array_push($where, ['field' => 'action_date', 'key' => 't1.action_date', 'val' => date('Y-m-d', strtotime($params['date'])), 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['department_id'] && $params['department_id'] != '') { + array_push($where, ['field' => 'department_id', 'key' => 't6.department_id', 'val' => $params['department_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + $limit = ''; + + if (isset($params['offset'])) { + $limit = "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}"; + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_event_pic_activities t1 + INNER JOIN gmbs_activities t2 ON t1.gmbs_activities_id = t2.id + INNER JOIN gmbs_answer_detail t3 ON t1.gmbs_answer_detail_id = t3.id + INNER JOIN gmbs_event_pic t4 ON t1.gmbs_event_pic_id = t4.id + INNER JOIN gmbs_department_group_shift t5 ON t4.gmbs_department_group_shift_id = t5.id + INNER JOIN gmbs_event_member_line_departments t6 ON t5.gmbs_event_member_line_departments_id = t6.id + INNER JOIN department t7 ON t6.department_id = t7.id + INNER JOIN gmbs_event_member_lines t8 ON t6.gmbs_event_member_lines_id = t8.id + INNER JOIN gmbs_events t9 ON t8.gmbs_events_id = t9.id + INNER JOIN gmbs_question_section t10 ON t2.gmbs_question_section_id = t10.id + INNER JOIN gmbs_business_unit t11 ON t10.gmbs_business_unit_id = t11.id + INNER JOIN gedung_sector_line t12 ON t11.gedung_sector_line_id = t12.id + INNER JOIN gedung_sector t13 ON t12.gedung_sector_id = t13.id + INNER JOIN gedung t14 ON t13.gedung_id = t14.id + LEFT JOIN gmbs_event_pic_activity_notes t15 ON t15.gmbs_event_pic_activities_id = t1.id', + [ + 't1.id', + 't7.description as department_name', + 't11.bu_name', + 't12.line_number as line_name', + 't10.section_name', + 't2.description as activities', + 't4.pic_nik', + 'getEmpName(t4.pic_nik) as pic_name', + 't15.note', + 't1.action_date as date_time' + ], + $where, + $limit + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_event_pic_activities t1 + INNER JOIN gmbs_activities t2 ON t1.gmbs_activities_id = t2.id + INNER JOIN gmbs_answer_detail t3 ON t1.gmbs_answer_detail_id = t3.id + INNER JOIN gmbs_event_pic t4 ON t1.gmbs_event_pic_id = t4.id + INNER JOIN gmbs_department_group_shift t5 ON t4.gmbs_department_group_shift_id = t5.id + INNER JOIN gmbs_event_member_line_departments t6 ON t5.gmbs_event_member_line_departments_id = t6.id + INNER JOIN department t7 ON t6.department_id = t7.id + INNER JOIN gmbs_event_member_lines t8 ON t6.gmbs_event_member_lines_id = t8.id + INNER JOIN gmbs_events t9 ON t8.gmbs_events_id = t9.id + INNER JOIN gmbs_question_section t10 ON t2.gmbs_question_section_id = t10.id + INNER JOIN gmbs_business_unit t11 ON t10.gmbs_business_unit_id = t11.id + INNER JOIN gedung_sector_line t12 ON t11.gedung_sector_line_id = t12.id + INNER JOIN gedung_sector t13 ON t12.gedung_sector_id = t13.id + INNER JOIN gedung t14 ON t13.gedung_id = t14.id + LEFT JOIN gmbs_event_pic_activity_notes t15 ON t15.gmbs_event_pic_activities_id = t1.id', + [ + 'count(t1.id) as total', + ], + $where + ); + + if (isset($rs) && count($rs) !== 0) { + $qImg = "SELECT * FROM gmbs_event_pic_activity_img WHERE gmbs_event_pic_activities_id = :id"; + $stmtImg = $this->registry->db->prepare($qImg); + + $pushData = array(); + + foreach ($rs as $value) { + $stmtImg->bindValue(':id', $value['id'], PDO::PARAM_STR); + $stmtImg->execute(); + $resImg = $stmtImg->fetchAll(PDO::FETCH_ASSOC); + + $value['photo'] = array(); + + if (isset($resImg) && count($resImg) !== 0) { + foreach ($resImg as $img) { + $value['photo'][] = array('img' => $this->registry->config->server_address . 'hcportal_docs/upload/self-genba/' . $img['img']); + } + } + + $pushData[] = $value; + } + } + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $pushData; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function viewDataMonitoringGembaSelfGroupDepartment($params) + { + try { + + $where = []; + + if ($params['event_id']) { + array_push($where, ['field' => 'gmbs_events_id', 'key' => 't8.gmbs_events_id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['ref_manunfactures_id']) { + array_push($where, ['field' => 'ref_manufactures_id', 'key' => 't9.ref_manufactures_id', 'val' => $params['ref_manunfactures_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['sub_area_id']) { + array_push($where, ['field' => 'sub_area_id', 'key' => 't14.sub_area_id', 'val' => $params['sub_area_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['gedung_id']) { + array_push($where, ['field' => 'gedung_id', 'key' => 't13.gedung_id', 'val' => $params['gedung_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['sector_id']) { + array_push($where, ['field' => 'gedung_sector_id', 'key' => 't12.gedung_sector_id', 'val' => $params['sector_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['line_id']) { + array_push($where, ['field' => 'gedung_sector_line_id', 'key' => 't11.gedung_sector_line_id', 'val' => $params['line_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['date']) { + array_push($where, ['field' => 'action_date', 'key' => 't4.action_date', 'val' => date('Y-m-d', strtotime($params['date'])), 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_event_member_line_departments t1 + LEFT JOIN gmbs_department_group_shift t2 ON t2.gmbs_event_member_line_departments_id = t1.id + LEFT JOIN gmbs_event_pic t3 ON t3.gmbs_department_group_shift_id = t2.id + LEFT JOIN gmbs_event_pic_activities t4 ON t4.gmbs_event_pic_id = t3.id + LEFT JOIN gmbs_activities t5 ON t4.gmbs_activities_id = t5.id + LEFT JOIN gmbs_answer_detail t6 ON t4.gmbs_answer_detail_id = t6.id AND t6.qualitative_answer = "Tidak Standar" + INNER JOIN department t7 ON t1.department_id = t7.id + INNER JOIN gmbs_event_member_lines t8 ON t1.gmbs_event_member_lines_id = t8.id + INNER JOIN gmbs_events t9 ON t8.gmbs_events_id = t9.id + LEFT JOIN gmbs_question_section t10 ON t5.gmbs_question_section_id = t10.id + LEFT JOIN gmbs_business_unit t11 ON t10.gmbs_business_unit_id = t11.id + LEFT JOIN gedung_sector_line t12 ON t11.gedung_sector_line_id = t12.id + LEFT JOIN gedung_sector t13 ON t12.gedung_sector_id = t13.id + LEFT JOIN gedung t14 ON t13.gedung_id = t14.id', + [ + 't14.sub_area_id', + 't13.gedung_id', + 't12.gedung_sector_id', + 't11.gedung_sector_line_id', + 't8.gmbs_events_id', + 't9.ref_manufactures_id', + 't7.id as department_id', + 't7.description as department', + 't5.gmbs_question_section_id', + 'SUM(IF(t6.id is not null,1,0)) as total' + ], + $where, + "GROUP BY t7.id" + ); + + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataReffBusinessUnit($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_ref_business_unit t1', + [ + 't1.*' + ], + [ + ['field' => 'ref_manunfactures_id', 'key' => 't1.ref_manunfactures_id', 'val' => $params['ref_manunfactures_id'], 'bind' => PDO::PARAM_STR], + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => 1, 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function searchEmp($params) + { + try { + $sql = $this->sqlSearchEmp(); + $stmt = $this->registry->db->prepare($sql); + $stmt->bindValue(':search', '%' . $params['search'] . '%', PDO::PARAM_STR); + $stmt->bindValue(':department_id', $params['department_id'], PDO::PARAM_STR); + $stmt->bindValue(':sub_area_id', $params['sub_area_id'], PDO::PARAM_STR); + $stmt->execute(); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getCekUserAdminSelf($params) + { + try { + + $nik = \Helper::getSessionVar('username'); + $rs = $this->dbBuilderSelectJoin( + 'employement t1 + INNER JOIN emp_job t2 ON t1.nik=t2.nik AND t2.id=(SELECT id FROM emp_job WHERE nik = t1.nik AND effective_date<=now() ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t3 ON t2.mpp_detail_id = t3.id + INNER JOIN org_layer t4 ON t3.org_layer_id = t4.id + INNER JOIN emp_personal_sub_area t5 ON t1.nik=t5.nik AND t5.id=(SELECT id FROM emp_personal_sub_area WHERE nik = t1.nik AND effective_date<=now() ORDER BY effective_date DESC LIMIT 1) + LEFT JOIN gmbs_ref_admin t6 ON t1.nik = t6.nik', + [ + 't1.nik', + 't4.entity_id', + 't4.division_id', + 't4.department_id', + 't5.sub_area_id', + 'IF(t6.id is not null,1,0) is_admin' + ], + [ + ['field' => 'nik', 'key' => 't1.nik', 'val' => $nik, 'bind' => PDO::PARAM_STR], + ] + ); + + + return $rs[0]; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataDivisionDepartment($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'division_department t1 + INNER JOIN division t2 ON t1.division_id = t2.id + INNER JOIN department t3 ON t1.department_id = t3.id', + [ + 't1.department_id', + 't1.division_id', + 't2.description as division', + 't3.description as department' + ], + [ + // ['field' => 'nik','key' => 't1.nik', 'val' => $nik, 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function deleteActivities($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_event_pic_activities t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_activities_id', 'key' => 't1.gmbs_activities_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_activities = $this->dbBuilderUpdate('gmbs_activities', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_activities) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_activities', 'id', $id); + } + } + + + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteActivities: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteActivities: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteWorkScopes($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + $rs = $this->dbBuilderSelectJoin( + 'gmbs_activities t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_ref_work_scopes_id', 'key' => 't1.gmbs_ref_work_scopes_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_ref_work_scopes = $this->dbBuilderUpdate('gmbs_ref_work_scopes', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_ref_work_scopes) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_ref_work_scopes', 'id', $id); + } + } + + + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteWorkScopes: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteWorkScopes: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteRiskLevel($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + $rs = $this->dbBuilderSelectJoin( + 'gmbs_activities t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_ref_risk_level', 'key' => 't1.gmbs_ref_risk_level', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_ref_risk_level = $this->dbBuilderUpdate('gmbs_ref_risk_level', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_ref_risk_level) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_ref_risk_level', 'id', $id); + } + } + + + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteRiskLevel: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteRiskLevel: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestionSectionSelf($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + $rs = $this->dbBuilderSelectJoin( + 'gmbs_activities t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_question_section_id', 'key' => 't1.gmbs_question_section_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_question_section = $this->dbBuilderUpdate('gmbs_question_section', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_question_section) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_question_section', 'id', $id); + } + } + + + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionSectionSelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionSectionSelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestionCategorySelf($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + $rs = $this->dbBuilderSelectJoin( + 'gmbs_activities t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_question_category_id', 'key' => 't1.gmbs_question_category_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_question_category = $this->dbBuilderUpdate('gmbs_question_category', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_question_category) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_question_category', 'id', $id); + } + } + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionCategorySelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionCategorySelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteRefBusinessUnit($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + $rs = $this->dbBuilderSelectJoin( + 'gmbs_business_unit t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_ref_business_unit_id', 'key' => 't1.gmbs_ref_business_unit_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_ref_business_unit = $this->dbBuilderUpdate('gmbs_ref_business_unit', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_ref_business_unit) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_ref_business_unit', 'id', $id); + } + } + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteRefBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteRefBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteBusinessUnit($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (!isset($data_array)) { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_question_section t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_business_unit_id', 'key' => 't1.gmbs_business_unit_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_business_unit = $this->dbBuilderUpdate('gmbs_business_unit', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_business_unit) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_business_unit', 'id', $id); + } + } else { + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + $rs = $this->dbBuilderSelectJoin( + 'gmbs_question_section t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_business_unit_id', 'key' => 't1.gmbs_business_unit_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_business_unit = $this->dbBuilderUpdate('gmbs_business_unit', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_business_unit) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_business_unit', 'id', $id); + } + } + } + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteLineRunning($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + $data_array = json_decode($data_array, true); + + if (!$data_array) { + $data_array = array(); + } + + if (count($data_array) == 0) { + array_push($data_array, $id); + } + + + foreach ($data_array as $key => $value) { + $id = $value; + $this->dbBuilderDelete('gmbs_line_running', 'id', $id); + } + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteLineRunning: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + -$status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteLineRunning: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function getDataRefGedungSectorLine($params) + { + try { + $where = []; + + $rs = $this->dbBuilderSelectJoin( + 'gedung_sector_line t1 + INNER JOIN gedung_sector t2 ON t1.gedung_sector_id = t2.id + INNER JOIN gedung t3 ON t2.gedung_id = t3.id + INNER JOIN sub_area t4 ON t3.sub_area_id = t4.id + INNER JOIN company t5 ON t4.company_id = t5.id', + [ + 't1.id as gedung_sector_line_id', + 't1.line_number', + 't1.gedung_sector_id', + 't2.sector_name', + 't3.gedung_name', + 't4.description as sub_area', + 't5.description as company' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataRefShiftGroupAll($params) + { + try { + $where = []; + + $rs = $this->dbBuilderSelectJoin( + 'ref_shift_group t1 + INNER JOIN sub_area t2 ON t1.sub_area_id = t2.id + INNER JOIN company t3 ON t2.company_id = t3.id ', + [ + 't1.id as ref_shift_group_id', + 't1.shift_group_name', + 't2.description as sub_area', + 't3.description as company' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getBusinessTitle($divisionId, $departmentId, $subAreaId) + { + try { + $sql = "SELECT bt.id as id,bt.description AS name + FROM ndc_business_titles bt + INNER JOIN org_layer ol ON ol.bt_id=bt.id + INNER JOIN sub_area sa ON ol.entity_id=sa.company_id + WHERE ol.division_id = :divisionId + AND ol.department_id = :departmentId + AND sa.id = :subAreaId + AND sa.country_id='IDN'"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':divisionId', $divisionId, PDO::PARAM_STR); + $stmt->bindParam(':departmentId', $departmentId, PDO::PARAM_STR); + $stmt->bindParam(':subAreaId', $subAreaId, PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getOrgLayer($divisionId, $departmentId, $subAreaId) + { + try { + $sql = " + SELECT + ol.id AS id, + ol.description AS name + FROM + org_layer ol + INNER JOIN sub_area sa ON sa.company_id = ol.entity_id + WHERE + sa.id = :subAreaId + AND sa.country_id = 'IDN' -- param country + AND ol.division_id = :divisionId + AND ol.department_id = :departmentId + GROUP BY + ol.id, + ol.description;"; + + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':divisionId', $divisionId, PDO::PARAM_STR); + $stmt->bindParam(':departmentId', $departmentId, PDO::PARAM_STR); + $stmt->bindParam(':subAreaId', $subAreaId, PDO::PARAM_STR); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getMpp($divisionId, $departmentId, $subAreaId, $olId) + { + try { + $sql = " + SELECT + mpp.id AS id, + mpp.description AS name + FROM + org_layer ol + INNER JOIN mpp_detail mpp ON ol.id = mpp.id + INNER JOIN mpp_detail_transaction mdt ON mpp.id = mdt.mpp_detail_id + AND mdt.effective_date =( + SELECT + MAX(effective_date) + FROM + mpp_detail_transaction + WHERE + mpp_detail_id = mpp.id + AND is_active = '1' + ORDER BY + effective_date DESC + LIMIT + 1 + ) + INNER JOIN sub_area sa ON sa.company_id = ol.entity_id + WHERE + sa.id = :subAreaId + AND sa.country_id = 'IDN' -- param country + AND ol.division_id = :divisionId + AND ol.department_id = :departmentId + AND ol.id = :olId + GROUP BY + mpp.id, + mpp.description; + "; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':divisionId', $divisionId, PDO::PARAM_STR); + $stmt->bindParam(':departmentId', $departmentId, PDO::PARAM_STR); + $stmt->bindParam(':subAreaId', $subAreaId, PDO::PARAM_STR); + $stmt->bindParam(':olId', $olId, PDO::PARAM_STR); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getLineListData() + { + try { + $sql = "select a.*, b.*, c.*, d.*, e.*, g.*, a.id as id, g.id as gmbs_business_unit_id + from gedung_sector_line a + INNER JOIN gedung_sector b on a.gedung_sector_id = b.id + INNER JOIN gedung c on b.gedung_id = c.id + INNER JOIN ref_manufacture_sub_area d on c.sub_area_id = d.sub_area_id + INNER JOIN ref_manunfactures e on d.ref_manunfactures_id = e.id + LEFT JOIN gmbs_business_unit g on a.id = g.gedung_sector_line_id;"; + + $stmt = $this->registry->db->prepare($sql); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function GetBusinessUnits($search = null) + { + try { + $sql = "SELECT id, bu_name as name FROM gmbs_business_unit WHERE is_publish = 1"; + if ($search !== null) { + $sql .= " AND bu_name LIKE :search"; + } + + $stmt = $this->registry->db->prepare($sql); + + if ($search !== null) { + $stmt->bindValue(':search', '%' . $search . '%', PDO::PARAM_STR); + } + + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getSector($buId = null, $search = null, $sectorId = null) + { + try { + $sql = "SELECT gedung_sector.id, + CASE + WHEN gedung_sector.sector_name = '-' THEN gedung.gedung_name + ELSE CONCAT(gedung.gedung_name, '-', gedung_sector.sector_name) + END as name + FROM + gedung_sector_line + INNER JOIN gedung_sector ON gedung_sector_line.gedung_sector_id = gedung_sector.id + INNER JOIN gedung ON gedung.id = gedung_sector.gedung_id + LEFT JOIN gmbs_business_unit ON gmbs_business_unit.gedung_sector_line_id = gedung_sector_line.id"; + $conditions = []; + $params = []; + + if ($sectorId !== null) { + $conditions[] = "gedung_sector.id = :sectorId"; + $params[':sectorId'] = $sectorId; + } + + if ($buId !== null) { + $conditions[] = "gmbs_business_unit.id = :buId"; + $params[':buId'] = $buId; + } + + if ($search !== null) { + $conditions[] = "(gedung.gedung_name LIKE :search OR + (gedung_sector.sector_name != '-' AND gedung_sector.sector_name LIKE :search) OR + CASE + WHEN gedung_sector.sector_name = '-' THEN gedung.gedung_name + ELSE CONCAT(gedung.gedung_name, '-', gedung_sector.sector_name) + END LIKE :search)"; + $params[':search'] = '%' . $search . '%'; + } + + if (!empty($conditions)) { + $sql .= " WHERE " . implode(" AND ", $conditions); + } + + $sql .= " GROUP BY gedung_sector.id"; + + $stmt = $this->registry->db->prepare($sql); + + foreach ($params as $key => &$val) { + $stmt->bindParam($key, $val, is_int($val) ? PDO::PARAM_INT : PDO::PARAM_STR); + } + + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getTeamMember($nik) { + try { + $sql = "SELECT c.id as mppId, a.nik, getEmpName(a.nik) as emp_name, a.grade + FROM employement a + INNER JOIN emp_job b ON a.nik=b.nik + AND b.effective_date=(SELECT max(ej.effective_date) + FROM emp_job ej + WHERE ej.nik=a.nik + AND ej.effective_date<=current_date()) + INNER JOIN mpp_detail c ON b.mpp_detail_id=c.id + INNER JOIN mpp_detail_transaction d ON c.id=d.mpp_detail_id + AND d.effective_date=(SELECT max(mt.effective_date) + FROM mpp_detail_transaction mt + WHERE mt.mpp_detail_id=c.id + AND mt.effective_date<=current_date()) + WHERE a.status='active' + AND LEFT(a.grade,1)>=3 + AND ( + a.nik = :nik + OR + d.level_code LIKE CONCAT( + '%', '-', + (SELECT md.id + FROM emp_job ej2 + INNER JOIN mpp_detail md ON ej2.mpp_detail_id = md.id + WHERE ej2.nik = :nik + AND ej2.effective_date = ( + SELECT MAX(ej3.effective_date) + FROM emp_job ej3 + WHERE ej3.nik = :nik + AND ej3.effective_date <= current_date() + ) + ), + '-', '%' + ) + ) + "; + + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':nik', $nik, PDO::PARAM_STR); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + + public function getGedungSectorLines($buId = null, $sectorId = null, $search = null) + { + try { + $sql = "SELECT + gedung_sector_line.id as id, gedung_sector_line.line_number as name + FROM + gedung_sector_line + INNER JOIN gedung_sector ON gedung_sector_line.gedung_sector_id = gedung_sector.id + INNER JOIN gedung ON gedung.id = gedung_sector.gedung_id + LEFT JOIN gmbs_business_unit ON gmbs_business_unit.gedung_sector_line_id = gedung_sector_line.id + WHERE 1=1"; + + $params = array(); + + if ($buId != null) { + $sql .= " AND gmbs_business_unit.id = :buId"; + $params[":buId"] = $buId; + } + + if ($sectorId !== null) { + $sql .= " AND gedung_sector.id = :sectorId"; + $params[':sectorId'] = $sectorId; + } + + if ($search !== null) { + $sql .= " AND gedung_sector_line.line_number LIKE :search"; + $params[':search'] = '%' . $search . '%'; + } + + $sql .= " GROUP BY gedung_sector_line.id LIMIT 10"; + + $stmt = $this->registry->db->prepare($sql); + foreach ($params as $key => $value) { + $stmt->bindValue($key, $value); + } + + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function searchEmployee($search) + { + try { + $search = '%' . $search . '%'; + $sql = " + SELECT + emp.nik, + CONCAT_WS( + ' ', + ep.title, + ep.first_name, + ep.middle_name, + ep.last_name + ) as name, + ep.first_name, + ep.last_name, + ep.id AS emp_id, + IFNULL(ep.`office_mail`,`emp_email`)AS email, + ep.`photo_address` AS profile_picture, + usr.`group` AS `group_id`, + g.`group` AS `group_name`, + job.job_title as position_name, + CASE + WHEN emp.flag_app = 'SAP' THEN 1 + ELSE 0 + END AS is_employee, + CASE + WHEN emp.status = 'active' THEN 1 + ELSE 0 + END AS is_active + FROM + emp_profiles ep + INNER JOIN employement emp ON ep.id = emp.emp_profile_id + INNER JOIN `user` usr ON emp.nik = usr.username + INNER JOIN `group` g ON usr.`group` = g.groupid + LEFT JOIN emp_job job ON emp.nik = job.nik + AND job.id = ( + SELECT + id + FROM + emp_job + WHERE + nik = emp.nik + ORDER BY + id DESC + LIMIT + 1 + ) + WHERE + emp.status = 'active' AND + ( + CONCAT_WS( + ' ', + IF(LENGTH(ep.title), ep.title, NULL), + IF(LENGTH(ep.first_name), ep.first_name, NULL), + IF(LENGTH(ep.middle_name), ep.middle_name, NULL), + IF(LENGTH(ep.last_name), ep.last_name, NULL) + ) LIKE :search OR (emp.nik LIKE :search) + ) LIMIT 10"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':search', $search, PDO::PARAM_STR); + + $stmt->execute(); + + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getRefManufactures() + { + try { + $sql = "SELECT * FROM ref_manunfactures"; + $stmt = $this->registry->db->prepare($sql); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getSubAreaFromManufacture($id) + { + try { + $sql = "SELECT id, description as name + FROM sub_area WHERE id IN + ( + SELECT sub_area_id FROM ref_manufacture_sub_area WHERE ref_manunfactures_id = :id + ) + "; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':id', $id, PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getDivisionFromSubArea($id) + { + try { + $sql = "SELECT divs.id AS id, divs.description AS name FROM org_layer ol + INNER JOIN division divs ON ol.division_id=divs.id + INNER JOIN sub_area sa ON sa.company_id=ol.entity_id + WHERE sa.id=:id + AND sa.country_id='IDN' + GROUP BY divs.id ,divs.description;"; + + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':id', $id, PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getDepartmentDivisionName($departmentId) + { + try { + $this->registry->log->error('departmentId: ' . $departmentId); + $sql = "SELECT department.id AS id, department.description as department, division.description as division + FROM department + INNER JOIN division ON division.id = department.division_id + WHERE department.id = :departmentId LIMIT 1"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':departmentId', $departmentId, PDO::PARAM_STR); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getDepartmentFromDivision($divisionId, $subAreaId) + { + try { + $sql = "SELECT dept.id AS id, dept.description AS name + FROM org_layer ol + INNER JOIN department dept ON ol.department_id=dept.id + INNER JOIN sub_area sa ON sa.company_id=ol.entity_id + WHERE sa.id=:subAreaId -- param area + AND ol.division_id=:divisionId -- param division + GROUP BY dept.id,dept.description;"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':subAreaId', $subAreaId, PDO::PARAM_INT); + $stmt->bindParam(':divisionId', $divisionId, PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getManufactureArea($id) + { + try { + $sql = "SELECT id, area as name FROM ref_manufacture_area WHERE ref_manunfactures_id = :id"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':id', $id, PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getSubAreaByNik($nik) + { + try { + // First, check for admin subareas + $sqlAdmin = "SELECT DISTINCT(subarea_id) FROM user_admin_subarea WHERE username = :user"; + $stmtAdmin = $this->registry->db->prepare($sqlAdmin); + $stmtAdmin->bindValue(':user', $nik, PDO::PARAM_STR); + $stmtAdmin->execute(); + $rsAdmin = $stmtAdmin->fetchAll(PDO::FETCH_ASSOC); + + if ($rsAdmin) { + $subareaIds = array_column($rsAdmin, 'subarea_id'); + return $subareaIds; + } + + // If no admin subareas, check for personal subareas + $sql = "SELECT sub_area_id FROM emp_personal_sub_area + WHERE nik = :nik AND effective_date <= CURRENT_DATE + ORDER BY effective_date DESC, id DESC LIMIT 1"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindValue(':nik', $nik, PDO::PARAM_STR); + $stmt->execute(); + $rs = $stmt->fetch(PDO::FETCH_ASSOC); + return $rs ? [$rs['sub_area_id']] : []; + } catch (PDOException $e) { + $this->registry->log->error('module gemba: ' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba: ' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + + public function viewDataMasterActivitiesDownload() + { + try { + $sql = "SELECT + t1.id, + t1.order_no, + t1.is_publish, + t1.description, + t1.gmbs_question_category_id, + t1.gmbs_question_section_id, + t1.gmbs_ref_risk_level_id, + t1.gmbs_ref_work_scopes_id, + t1.reference_link, + t1.gmbs_ref_risk_level_id, + t3.department_id, + t3.gmbs_business_unit_id + FROM gmbs_activities t1 + INNER JOIN gmbs_question_category t2 ON t1.gmbs_question_category_id = t2.id + INNER JOIN gmbs_question_section t3 ON t1.gmbs_question_section_id = t3.id + ORDER BY t3.section_name ASC"; + + $stmt = $this->registry->db->prepare($sql); + $stmt->execute(); + $rsdata = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $qDetail = "SELECT * FROM gmbs_answer_detail WHERE gmbs_activities_id = :id"; + + $stmtDetail = $this->registry->db->prepare($qDetail); + + $dataArr = array(); + + if (isset($rsdata) && count($rsdata) !== 0) { + foreach ($rsdata as $val) { + $stmtDetail->bindValue(':id', $val['id'], PDO::PARAM_STR); + $stmtDetail->execute(); + $rsdataDetail = $stmtDetail->fetchAll(PDO::FETCH_ASSOC); + + if (isset($rsdataDetail) && count($rsdataDetail) !== 0) { + foreach ($rsdataDetail as $valDetail) { + if ($valDetail['answer_label'] == 'YES') { + $val['answer_score_yes'] = $valDetail['answer_score']; + $val['is_require_note_yes'] = $valDetail['is_require_note']; + } else { + $val['answer_score_no'] = $valDetail['answer_score']; + $val['is_require_note_no'] = $valDetail['is_require_note']; + } + } + } + + $dataArr[] = $val; + } + } + + return $dataArr; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataEmployee($empId) + { + $this->registry->log->error($empId); + try { + $sql = "select + a.first_name, + concat_ws( + ' ', + ifnull(a.middle_name, ''), + ifnull(a.last_name, '') + ) as last_name, + e.description as job_position, + e.division_id as division_id, + e.department_id as department_id, + e.id as org_layer_id, + bt.id as bt_id, + mpp.id as mpp_id, + emp_personal_sub_area.sub_area_id as sub_area_id, + a.photo_address AS profile_picture, + IFNULL(office_mail, emp_email) AS email, + ref_manufacture_sub_area.ref_manunfactures_id AS ref_manufactures_id +FROM + emp_profiles a + inner join employement b on a.id = b.emp_profile_id + inner join emp_job c on b.nik = c.nik + and c.effective_date =( + select + max(ej.effective_date) + from + emp_job ej + where + ej.nik = b.nik + and ej.effective_date <= current_date() + ) + inner join mpp_detail d on c.mpp_detail_id = d.id + inner join org_layer e on d.org_layer_id = e.id + INNER JOIN emp_personal_sub_area ON c.nik = emp_personal_sub_area.nik + INNER JOIN sub_area sa ON e.entity_id = sa.company_id + INNER JOIN ndc_business_titles bt ON bt.id = e.bt_id + LEFT JOIN ref_manufacture_sub_area ON ref_manufacture_sub_area.sub_area_id = emp_personal_sub_area.sub_area_id + INNER JOIN mpp_detail mpp ON e.id = mpp.id +where + a.id = :emp_id +ORDER BY + emp_personal_sub_area.effective_date DESC +LIMIT + 1;"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindValue(':emp_id', $empId, PDO::PARAM_INT); + $stmt->execute(); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + if (count($rs) == 0) { + return null; + } + return $rs[0]; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } +} diff --git a/admin/model/Adminquerytrait.php b/admin/model/Adminquerytrait.php new file mode 100755 index 0000000..ef5113d --- /dev/null +++ b/admin/model/Adminquerytrait.php @@ -0,0 +1,3939 @@ +=:expdate) as tab"; + + $sqlScale = 'SELECT a.id AS idMasterGemba,a.kpi,a.description,b.target,b.uom,b.id AS kpi_scale_id FROM master_kpi a INNER JOIN kpi_scale b ON a.id=b.kpi_id WHERE b.id=:kpiPeopleID AND YEAR(b.effective_date)=:year'; + $sqlScaleNew = "SELECT + a.id AS idMasterGemba, + a.kpi,a.description, + c.target_value as `target`,b.uom,b.id AS kpi_scale_id, + a.kpi_ref_function_id + FROM master_kpi a + INNER JOIN kpi_scale b ON a.id=b.kpi_id + INNER JOIN kpi_scale_detail c on b.id=c.kpi_scale_id + WHERE b.id=:kpiPeopleID AND YEAR(b.effective_date)=:year"; + + $sqlCheckApproval = 'SELECT COUNT(`employement_has_kpi_scale_id`) as total FROM `emp_kpi_approval` WHERE `employement_has_kpi_scale_id`=:id'; + + + $sqlPeopleMonitoring = "SELECT + ehks.id, + ehks.kpi_scale_id, + Round(( ehks.bobot * 100 ), 2) AS weight, + ehks.efective_date as effective_date, + ehks.expired_date, + ehks.value_type, + ehks.employement_nik, + ehks.value_category, + 'kpi' as type_kpi, + ehks.is_allow_more_than_100, + null as general_kpi_scale_id, + null as org_layer_kpi_id, + (SELECT bobot FROM emp_kpi_quarter_target WHERE employement_has_kpi_scale_id = ehks.id AND periode ='Q1') as q1_bobot, + (SELECT bobot FROM emp_kpi_quarter_target WHERE employement_has_kpi_scale_id = ehks.id AND periode ='Q2') as q2_bobot, + (SELECT bobot FROM emp_kpi_quarter_target WHERE employement_has_kpi_scale_id = ehks.id AND periode ='Q3') as q3_bobot, + (SELECT bobot FROM emp_kpi_quarter_target WHERE employement_has_kpi_scale_id = ehks.id AND periode ='Q4') as q4_bobot, + (SELECT bobot FROM emp_kpi_quarter_target WHERE employement_has_kpi_scale_id = ehks.id AND periode ='S1') as s1_bobot, + (SELECT bobot FROM emp_kpi_quarter_target WHERE employement_has_kpi_scale_id = ehks.id AND periode ='S2') as s2_bobot, + ehks.efective_date as date_kpi, + '0' as target_sharing, + '0' as result_sharing + FROM + `employement_has_kpi_scale` ehks + LEFT JOIN emp_kpi_approval app ON app.employement_has_kpi_scale_id = ehks.id + WHERE + ehks.`employement_nik` = :nik + AND Year(ehks.`efective_date`) = :year + UNION + SELECT + t1.id, + t2.kpi_scale_id, + round((t1.yearly_weight *100),2) as weight, + DATE_FORMAT(t3.effective_date, '%Y-%m-%d') as effective_date, + t3.expired_date, + t2.value_type, + t1.nik as employement_nik, + t2.value_category, + 'kpi_general' as type_kpi, + t2.is_allow_more_than_100, + t1.general_kpi_scale_id, + null as org_layer_kpi_id, + (SELECT weight FROM general_kpi_detail_weight WHERE general_kpi_emp_id = t1.id AND period_value ='Q1') as q1_bobot, + (SELECT weight FROM general_kpi_detail_weight WHERE general_kpi_emp_id = t1.id AND period_value ='Q2') as q2_bobot, + (SELECT weight FROM general_kpi_detail_weight WHERE general_kpi_emp_id = t1.id AND period_value ='Q3') as q3_bobot, + (SELECT weight FROM general_kpi_detail_weight WHERE general_kpi_emp_id = t1.id AND period_value ='Q4') as q4_bobot, + (SELECT weight FROM general_kpi_detail_weight WHERE general_kpi_emp_id = t1.id AND period_value ='S1') as s1_bobot, + (SELECT weight FROM general_kpi_detail_weight WHERE general_kpi_emp_id = t1.id AND period_value ='S2') as s2_bobot, + DATE_FORMAT(t3.effective_date, '%Y-%m-%d') as date_kpi, + t2.target_sharing, + t2.result_sharing + FROM + general_kpi_emp t1 + INNER JOIN general_kpi_scale t2 ON t1.general_kpi_scale_id = t2.id + INNER JOIN kpi_scale t3 ON t2.kpi_scale_id = t3.id + WHERE + t1.nik=:nik + AND + YEAR(t3.effective_date)=:year + AND + t1.status='2' + UNION + SELECT + t2.id, + t1.kpi_scale_id, + round((t2.bobot),2) as weight, + DATE_FORMAT(t1.efective_date, '%Y-%m-%d') as effective_date, + t2.expired_date, + t1.value_type, + t2.employement_nik, + t1.value_category, + 'kpi_position' as type_kpi, + '0' as is_allow_more_than_100, + null as general_kpi_scale_id, + t2.org_layer_kpi_id, + (SELECT bobot FROM employement_kpi_position_periode_setting WHERE employement_kpi_position_id = t2.id AND periode ='Q1') as q1_bobot, + (SELECT bobot FROM employement_kpi_position_periode_setting WHERE employement_kpi_position_id = t2.id AND periode ='Q2') as q2_bobot, + (SELECT bobot FROM employement_kpi_position_periode_setting WHERE employement_kpi_position_id = t2.id AND periode ='Q3') as q3_bobot, + (SELECT bobot FROM employement_kpi_position_periode_setting WHERE employement_kpi_position_id = t2.id AND periode ='Q4') as q4_bobot, + (SELECT bobot FROM employement_kpi_position_periode_setting WHERE employement_kpi_position_id = t2.id AND periode ='S1') as s1_bobot, + (SELECT bobot FROM employement_kpi_position_periode_setting WHERE employement_kpi_position_id = t2.id AND periode ='S2') as s2_bobot, + t2.efective_date as date_kpi, + '0' as target_sharing, + '0' as result_sharing + FROM + org_layer_kpi t1 + INNER JOIN employement_kpi_position t2 ON t1.id=t2.org_layer_kpi_id AND t2.id = (SELECT id FROM employement_kpi_position WHERE org_layer_kpi_id = t1.id AND employement_nik = :nik AND efective_date <= now() ORDER BY efective_date DESC LIMIT 1) + INNER JOIN employement t3 ON t2.employement_nik = t3.nik + WHERE + t3.nik = :nik + AND + t2.`year` = :year + AND + t2.status='2'"; + + + $sql['sqlPeople'] = $sqlPeople; + $sql['sqlTotBobot'] = $sqlTotBobot; + $sql['sqlScale'] = $sqlScale; + $sql['sqlScaleNew'] = $sqlScaleNew; + $sql['sqlCheckApproval'] = $sqlCheckApproval; + $sql['sqlPeopleMonitoring'] = $sqlPeopleMonitoring; + return $sql; + } + + function sqlViewDataGembaMonitoring() + { + $sqlPeople = 'SELECT id,kpi_scale_id,round((bobot*100),2) as weight,efective_date,expired_date,value_type,employement_nik,value_category FROM `employement_has_kpi_scale` WHERE `employement_nik`=:nik AND YEAR(`efective_date`)=:year'; + + $sqlTotBobot = "select ifnull(sum(totweight),0) as totweight from (SELECT ROUND((bobot*100),2) AS totweight + FROM `employement_has_kpi_scale` WHERE `employement_nik`=:nik AND YEAR(`efective_date`)=:year + AND `expired_date` >=:expdate) as tab"; + + $sqlScale = 'SELECT a.id AS idMasterGemba,a.kpi,a.description,b.target,b.uom,b.id AS kpi_scale_id FROM master_kpi a INNER JOIN kpi_scale b ON a.id=b.kpi_id WHERE b.id=:kpiPeopleID AND YEAR(b.effective_date)=:year'; + $sqlScaleNew = "SELECT + a.id AS idMasterGemba, + a.kpi,a.description, + c.target_value as `target`,b.uom,b.id AS kpi_scale_id + FROM master_kpi a + INNER JOIN kpi_scale b ON a.id=b.kpi_id + INNER JOIN kpi_scale_detail c on b.id=c.kpi_scale_id + WHERE b.id=:kpiPeopleID AND YEAR(b.effective_date)=:year"; + + $sqlCheckApproval = 'SELECT COUNT(`employement_has_kpi_scale_id`) as total FROM `emp_kpi_approval` WHERE `employement_has_kpi_scale_id`=:id'; + + $sqlPeopleMonitoring = "SELECT + ehks.id, + ehks.kpi_scale_id, + Round(( ehks.bobot * 100 ), 2) AS weight, + ehks.efective_date, + ehks.expired_date, + ehks.value_type, + ehks.employement_nik, + ehks.value_category, + CONCAT_WS(' ',t4.first_name, t4.last_name ) as name, + t5.description as jabatan + FROM + `employement_has_kpi_scale` ehks + LEFT JOIN emp_kpi_approval app ON app.employement_has_kpi_scale_id = ehks.id + LEFT JOIN employement t3 ON ehks.employement_nik = t3.nik + LEFT JOIN emp_profiles t4 ON t3.emp_profile_id = t4.id + LEFT OUTER JOIN job_title t5 ON t3.positionID = t5.positionID + WHERE + Year(ehks.`efective_date`) = :year + AND + LEFT(t3.positionID,2) = 'PM' + ORDER BY + ehks.employement_nik LIMIT 20"; + + $sqlPeopleMonitoring = "SELECT + ehks.id, + ehks.kpi_scale_id, + Round(( ehks.bobot * 100 ), 2) AS weight, + ehks.efective_date, + ehks.expired_date, + ehks.value_type, + ehks.employement_nik, + ehks.value_category, + CONCAT_WS(' ',t4.first_name, t4.last_name ) as name, + t5.description as jabatan, + t6.`month`, + t7.result_quantitative, + a.id AS idMasterGemba, + a.kpi,a.description, + c.target_value as `target`,b.uom,b.id AS kpi_scale_id + FROM + `employement_has_kpi_scale` ehks + LEFT JOIN emp_kpi_approval app ON app.employement_has_kpi_scale_id = ehks.id + LEFT JOIN employement t3 ON ehks.employement_nik = t3.nik + LEFT JOIN emp_profiles t4 ON t3.emp_profile_id = t4.id + LEFT OUTER JOIN job_title t5 ON t3.positionID = t5.positionID + LEFT JOIN emp_kpi_monthly_target t6 ON t6.employement_has_kpi_scale_id = ehks.id + LEFT JOIN kpi_result t7 ON t7.employement_has_kpi_scale_id = t6.employement_has_kpi_scale_id and DATE_FORMAT(t7.result_date,'%m') = t6.`month` + INNER JOIN kpi_scale b ON b.id=ehks.kpi_scale_id + LEFT JOIN master_kpi a ON a.id=b.kpi_id + INNER JOIN kpi_scale_detail c on b.id=c.kpi_scale_id + WHERE + Year(ehks.`efective_date`) = :year + AND + LEFT(t3.positionID,2) = 'PM' + ORDER BY + ehks.employement_nik"; + + + $sql['sqlPeople'] = $sqlPeople; + $sql['sqlTotBobot'] = $sqlTotBobot; + $sql['sqlScale'] = $sqlScale; + $sql['sqlScaleNew'] = $sqlScaleNew; + $sql['sqlCheckApproval'] = $sqlCheckApproval; + $sql['sqlPeopleMonitoring'] = $sqlPeopleMonitoring; + return $sql; + } + + function sqlViewDataGembaMonitoring1() + { + $sqlPeople = 'SELECT id,kpi_scale_id,round((bobot*100),2) as weight,efective_date,expired_date,value_type,employement_nik,value_category FROM `employement_has_kpi_scale` WHERE `employement_nik`=:nik AND YEAR(`efective_date`)=:year'; + + $sqlTotBobot = "select ifnull(sum(totweight),0) as totweight from (SELECT ROUND((bobot*100),2) AS totweight + FROM `employement_has_kpi_scale` WHERE `employement_nik`=:nik AND YEAR(`efective_date`)=:year + AND `expired_date` >=:expdate) as tab"; + + $sqlScale = 'SELECT a.id AS idMasterGemba,a.kpi,a.description,b.target,b.uom,b.id AS kpi_scale_id FROM master_kpi a INNER JOIN kpi_scale b ON a.id=b.kpi_id WHERE b.id=:kpiPeopleID AND YEAR(b.effective_date)=:year'; + $sqlScaleNew = "SELECT + a.id AS idMasterGemba, + a.kpi,a.description, + c.target_value as `target`,b.uom,b.id AS kpi_scale_id + FROM master_kpi a + INNER JOIN kpi_scale b ON a.id=b.kpi_id + INNER JOIN kpi_scale_detail c on b.id=c.kpi_scale_id + WHERE b.id=:kpiPeopleID AND YEAR(b.effective_date)=:year"; + + $sqlCheckApproval = 'SELECT COUNT(`employement_has_kpi_scale_id`) as total FROM `emp_kpi_approval` WHERE `employement_has_kpi_scale_id`=:id'; + + $sqlPeopleMonitoring = "SELECT + ehks.id, + ehks.kpi_scale_id, + Round(( ehks.bobot * 100 ), 2) AS weight, + ehks.efective_date, + ehks.expired_date, + ehks.value_type, + ehks.employement_nik, + ehks.value_category, + CONCAT_WS(' ',t4.first_name, t4.last_name ) as name, + t5.description as jabatan, + LEFT(t3.positionID,2) as bu, + (select description from company where id=ol.entity_id) as company, + (select description from division where id=ol.division_id) as division, + (select description from department where id=ol.department_id) as department, + period.type as type_periode, + ksd.target_value + FROM + `employement_has_kpi_scale` ehks + LEFT JOIN emp_kpi_approval app ON app.employement_has_kpi_scale_id = ehks.id + LEFT JOIN employement t3 ON ehks.employement_nik = t3.nik + LEFT JOIN emp_profiles t4 ON t3.emp_profile_id = t4.id + LEFT OUTER JOIN job_title t5 ON t3.positionID = t5.positionID + LEFT JOIN (SELECT ej.* FROM emp_job ej ORDER BY ej.effective_date DESC) AS ej ON t3.nik = ej.nik + LEFT JOIN org_layer ol ON ej.layer_id = ol.id + LEFT JOIN emp_preiode_apraisal_quarter period ON period.nik = t3.nik AND period.id = (SELECT id FROM `emp_preiode_apraisal_quarter` WHERE `nik`=t3.nik AND `effective_date` <=ehks.efective_date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN kpi_scale_detail ksd ON ksd.kpi_scale_id = ehks.kpi_scale_id + WHERE + Year(ehks.`efective_date`) = :year + AND + LEFT(t3.positionID,2) = 'KS' + AND + period.type IN('yearly','semester') + -- AND + -- ehks.employement_nik='16000390' + ORDER BY + ehks.employement_nik"; + + // $sqlPeopleMonitoring = "SELECT + // ehks.id, + // ehks.kpi_scale_id, + // Round(( ehks.bobot * 100 ), 2) AS weight, + // ehks.efective_date, + // ehks.expired_date, + // ehks.value_type, + // ehks.employement_nik, + // ehks.value_category, + // CONCAT_WS(' ',t4.first_name, t4.last_name ) as name, + // t5.description as jabatan, + // t6.`month`, + // t7.result_quantitative, + // a.id AS idMasterGemba, + // a.kpi,a.description, + // c.target_value as `target`,b.uom,b.id AS kpi_scale_id + // FROM + // `employement_has_kpi_scale` ehks + // LEFT JOIN emp_kpi_approval app ON app.employement_has_kpi_scale_id = ehks.id + // LEFT JOIN employement t3 ON ehks.employement_nik = t3.nik + // LEFT JOIN emp_profiles t4 ON t3.emp_profile_id = t4.id + // LEFT OUTER JOIN job_title t5 ON t3.positionID = t5.positionID + // LEFT JOIN emp_kpi_monthly_target t6 ON t6.employement_has_kpi_scale_id = ehks.id + // LEFT JOIN kpi_result t7 ON t7.employement_has_kpi_scale_id = t6.employement_has_kpi_scale_id and DATE_FORMAT(t7.result_date,'%m') = t6.`month` + // INNER JOIN kpi_scale b ON b.id=ehks.kpi_scale_id + // LEFT JOIN master_kpi a ON a.id=b.kpi_id + // INNER JOIN kpi_scale_detail c on b.id=c.kpi_scale_id + // WHERE + // Year(ehks.`efective_date`) = :year + // AND + // LEFT(t3.positionID,2) = 'PM' + // ORDER BY + // ehks.employement_nik"; + + $sqlExportDataMonitoringTarget = "SELECT + (select description from company where id=ol.entity_id) as company, + (select description from division where id=ol.division_id) as division, + (select description from department where id=ol.department_id) as department, + t5.description as jabatan, + ehks.employement_nik, + CONCAT_WS(' ',t4.first_name, t4.last_name ) as name, + period.type as type_periode, + mk.kpi, + mk.description, + ehks.efective_date, + ehks.expired_date, + ehks.uom, + Round(( ehks.bobot * 100 ), 2) AS weight, + ehks.value_type, + ehks.value_category, + ksd.target_value, + ekmt.* + FROM + `employement_has_kpi_scale` ehks + LEFT JOIN emp_kpi_approval app ON app.employement_has_kpi_scale_id = ehks.id + LEFT JOIN employement t3 ON ehks.employement_nik = t3.nik + LEFT JOIN emp_profiles t4 ON t3.emp_profile_id = t4.id + LEFT OUTER JOIN job_title t5 ON t3.positionID = t5.positionID + LEFT JOIN (SELECT ej.* FROM emp_job ej ORDER BY ej.effective_date DESC) AS ej ON t3.nik = ej.nik + LEFT JOIN org_layer ol ON ej.layer_id = ol.id + LEFT JOIN emp_preiode_apraisal_quarter period ON period.nik = t3.nik AND period.id = (SELECT id FROM `emp_preiode_apraisal_quarter` WHERE `nik`=t3.nik AND `effective_date` <=ehks.efective_date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN kpi_scale ks ON ehks.kpi_scale_id = ks.id + INNER JOIN master_kpi mk ON ks.kpi_id = mk.id + INNER JOIN kpi_scale_detail ksd ON ksd.kpi_scale_id = ks.id + INNER JOIN emp_kpi_monthly_target ekmt ON ekmt.employement_has_kpi_scale_id = ehks.id + WHERE + Year(ehks.`efective_date`) = :year + AND + LEFT(t3.positionID,2) = 'KS' + AND + period.type IN('yearly','semester') + ORDER BY + ehks.employement_nik"; + + + $sqlExportDataMonitoringTarget = "SELECT + tab.* + FROM + (SELECT + t7.`entity_id` as company, + t9.description as division, + t8.description as department, + ifnull(t10.description,t7.description) as jabatan, + t1.employement_nik, + CONCAT_WS(' ',t4.first_name, t4.last_name ) as name, + t11.type as type_periode, + t13.kpi, + t13.description, + t1.efective_date, + t1.expired_date, + t12.uom, + if(t16.bobot,t16.bobot,Round(( t1.bobot * 100 ), 2)) AS weight, + t1.value_type, + t1.value_category, + if(t11.type='semester',t16.target, t14.target_value) as target_value, + t15.employement_has_kpi_scale_id, + t15.id, + t15.max, + t15.min, + t15.`month`, + t15.target, + t15.`year`, + t17.result_quantitative, + FORMAT(kpiGetAch(t1.value_category,t15.target,t15.min,t15.max,t17.result_quantitative,LEFT(t3.positionID,2))*100,2) as archievement, + FORMAT(kpiScores(kpiGetAch(t1.value_category,t15.target,t15.min,t15.max,t17.result_quantitative,LEFT(t3.positionID,2)),IF(t16.bobot is not null,t16.bobot/100,t1.bobot),t1.is_allow_more_than_100)*100,2) as score, + t11.type as periode, + t16.periode as periode_quarter, + t1.is_allow_more_than_100, + 'Regular' as kpi_type, + if(t2.approvedDate is not null,'Approve','Waiting Approval') as status_kpi, + if(t18.`timestamp` is not null,'Approve','Waiting Approval') as status_pa, + t1.id as has_kpi_id, + t1.bobot * 100 as yearly_weight + FROM + `employement_has_kpi_scale` t1 + LEFT JOIN emp_kpi_approval t2 ON t2.employement_has_kpi_scale_id = t1.id + LEFT JOIN employement t3 ON t1.employement_nik = t3.nik + LEFT JOIN emp_profiles t4 ON t3.emp_profile_id = t4.id + inner join emp_job t5 on t3.nik=t5.nik and t5.effective_date=(select max(ej.effective_date) from emp_job ej where ej.nik=t3.nik and ej.effective_date<=NOW()) + inner join mpp_detail t6 on t5.mpp_detail_id=t6.id + inner join org_layer t7 on t6.org_layer_id=t7.id + left outer join department t8 on t7.department_id=t8.id + left outer join division t9 on t7.division_id=t9.id + left outer join ndc_business_titles t10 on t7.`bt_id`=t10.id + LEFT JOIN emp_preiode_apraisal_quarter t11 ON t11.nik = t3.nik AND t11.id = (SELECT id FROM `emp_preiode_apraisal_quarter` WHERE `nik`=t3.nik AND `effective_date` <=t1.efective_date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN kpi_scale t12 ON t1.kpi_scale_id = t12.id + INNER JOIN master_kpi t13 ON t12.kpi_id = t13.id + INNER JOIN kpi_scale_detail t14 ON t14.kpi_scale_id = t12.id + INNER JOIN emp_kpi_monthly_target t15 ON t15.employement_has_kpi_scale_id = t1.id + LEFT JOIN emp_kpi_quarter_target t16 ON t1.id = t16.employement_has_kpi_scale_id AND (t16.periode = 'S1' OR t16.periode = 'S2') + LEFT JOIN kpi_result t17 ON t17.employement_has_kpi_scale_id = t15.employement_has_kpi_scale_id and DATE_FORMAT(t17.result_date,'%m') = t15.`month` + LEFT JOIN kpi_score_approval t18 ON t1.id = t18.employement_has_kpi_scale_id AND (SELECT id FROM kpi_score_approval WHERE employement_has_kpi_scale_id = t1.id ORDER BY id DESC LIMIT 1) + WHERE + Year(t1.`efective_date`) = :year + AND + LEFT(t3.positionID,2) = :bu + AND + t11.type IN('yearly','semester') + and + t3.`status`='active' + UNION + SELECT + t7.`entity_id` as company, + t9.description as division, + t8.description as department, + ifnull(t10.description,t7.description) as jabatan, + t2.nik as employement_nik, + CONCAT_WS(' ',t4.first_name, t4.last_name ) as name, + t11.type as type_periode, + t13.kpi, + t13.description, + t12.effective_date as efective_date, + t12.expired_date, + t12.uom, + if(t16.weight ,t16.weight * 100 ,Round(( t2.yearly_weight * 100 ), 2)) AS weight, + t1.value_type, + t1.value_category, + if(t11.type='semester',t16.target, t14.target_value) as target_value, + (5000000+t2.id) as employement_has_kpi_scale_id, + t15.id, + t15.max, + t15.min, + t15.`month`, + t15.target, + t15.`year`, + t17.result_quantitative, + FORMAT(kpiGetAch(t1.value_category,t15.target,t15.min,t15.max,t17.result_quantitative,LEFT(t3.positionID,2))*100,2) as archievement, + FORMAT(kpiScores(kpiGetAch(t1.value_category,t15.target,t15.min,t15.max,t17.result_quantitative,LEFT(t3.positionID,2)),IF(t16.weight is not null,t16.weight,t2.yearly_weight),'1')*100,2) as score, + t11.type as periode, + t16.period_value as periode_quarter, + '1' as is_allow_more_than_100, + 'General' as kpi_type, + if(t2.status ='2','Approve','Waiting Approval') as status_kpi, + 'Approve' as status_pa, + t2.id as has_kpi_id, + t2.yearly_weight * 100 as yearly_weight + FROM + general_kpi_scale t1 + INNER JOIN general_kpi_emp t2 ON t1.id = t2.general_kpi_scale_id + LEFT JOIN employement t3 ON t2.nik = t3.nik + LEFT JOIN emp_profiles t4 ON t3.emp_profile_id = t4.id + inner join emp_job t5 on t3.nik=t5.nik and t5.effective_date=(select max(ej.effective_date) from emp_job ej where ej.nik=t3.nik and ej.effective_date<=NOW()) + inner join mpp_detail t6 on t5.mpp_detail_id=t6.id + inner join org_layer t7 on t6.org_layer_id=t7.id + left outer join department t8 on t7.department_id=t8.id + left outer join division t9 on t7.division_id=t9.id + left outer join ndc_business_titles t10 on t7.`bt_id`=t10.id + INNER JOIN kpi_scale t12 ON t1.kpi_scale_id = t12.id + LEFT JOIN emp_preiode_apraisal_quarter t11 ON t11.nik = t3.nik AND t11.id = (SELECT id FROM `emp_preiode_apraisal_quarter` WHERE `nik`=t3.nik AND `effective_date` <= t12.effective_date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN master_kpi t13 ON t12.kpi_id = t13.id + INNER JOIN kpi_scale_detail t14 ON t14.kpi_scale_id = t12.id + INNER JOIN general_kpi_monthly_target t15 ON t15.general_kpi_scale_id = t1.id + LEFT JOIN general_kpi_detail_weight t16 ON t2.id = t16.general_kpi_emp_id AND (t16.period_value = 'S1' OR t16.period_value = 'S2') + LEFT JOIN general_kpi_emp_result t17 ON t17.general_kpi_emp_id = t2.id AND t15.id = t17.monthly_target_id + WHERE + Year(t12.effective_date ) = :year + AND + LEFT(t3.positionID,2) = :bu + AND + t11.type IN('yearly','semester') + and + t3.`status`='active' + AND + t1.target_sharing ='1' + AND + t1.result_sharing ='0' + UNION + SELECT + t7.`entity_id` as company, + t9.description as division, + t8.description as department, + ifnull(t10.description,t7.description) as jabatan, + t2.nik as employement_nik, + CONCAT_WS(' ',t4.first_name, t4.last_name ) as name, + t11.type as type_periode, + t13.kpi, + t13.description, + t12.effective_date as efective_date, + t12.expired_date, + t12.uom, + if(t16.weight ,t16.weight * 100 ,Round(( t2.yearly_weight * 100 ), 2)) AS weight, + t1.value_type, + t1.value_category, + if(t11.type='semester',t16.target, t14.target_value) as target_value, + (5000000+t15.general_kpi_emp_id) as employement_has_kpi_scale_id, + t15.id, + t15.max, + t15.min, + t15.`month`, + t15.target, + t15.`year`, + t17.result_quantitative, + FORMAT(kpiGetAch(t1.value_category,t15.target,t15.min,t15.max,t17.result_quantitative,LEFT(t3.positionID,2))*100,2) as archievement, + FORMAT(kpiScores(kpiGetAch(t1.value_category,t15.target,t15.min,t15.max,t17.result_quantitative,LEFT(t3.positionID,2)),IF(t16.weight is not null,t16.weight,t2.yearly_weight),'1')*100,2) as score, + t11.type as periode, + t16.period_value as periode_quarter, + '1' as is_allow_more_than_100, + 'General' as kpi_type, + if(t2.status ='2','Approve','Waiting Approval') as status_kpi, + 'Approve' as status_pa, + t2.id as has_kpi_id, + t2.yearly_weight * 100 as yearly_weight + FROM + general_kpi_scale t1 + INNER JOIN general_kpi_emp t2 ON t1.id = t2.general_kpi_scale_id + LEFT JOIN employement t3 ON t2.nik = t3.nik + LEFT JOIN emp_profiles t4 ON t3.emp_profile_id = t4.id + inner join emp_job t5 on t3.nik=t5.nik and t5.effective_date=(select max(ej.effective_date) from emp_job ej where ej.nik=t3.nik and ej.effective_date<=NOW()) + inner join mpp_detail t6 on t5.mpp_detail_id=t6.id + inner join org_layer t7 on t6.org_layer_id=t7.id + left outer join department t8 on t7.department_id=t8.id + left outer join division t9 on t7.division_id=t9.id + left outer join ndc_business_titles t10 on t7.`bt_id`=t10.id + INNER JOIN kpi_scale t12 ON t1.kpi_scale_id = t12.id + LEFT JOIN emp_preiode_apraisal_quarter t11 ON t11.nik = t3.nik AND t11.id = (SELECT id FROM `emp_preiode_apraisal_quarter` WHERE `nik`=t3.nik AND `effective_date` <= t12.effective_date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN master_kpi t13 ON t12.kpi_id = t13.id + INNER JOIN kpi_scale_detail t14 ON t14.kpi_scale_id = t12.id + INNER JOIN general_kpi_emp_monthly_target t15 ON t15.general_kpi_emp_id = t2.id + LEFT JOIN general_kpi_detail_weight t16 ON t2.id = t16.general_kpi_emp_id AND (t16.period_value = 'S1' OR t16.period_value = 'S2') + LEFT JOIN general_kpi_emp_result t17 ON t17.general_kpi_emp_id = t2.id AND t15.id = t17.monthly_target_id + WHERE + Year(t12.effective_date ) = :year + AND + LEFT(t3.positionID,2) = :bu + AND + t11.type IN('yearly','semester') + and + t3.`status`='active' + AND + t1.target_sharing ='0' + AND + t1.result_sharing ='0') tab + ORDER BY + tab.employement_nik"; + + + $sql['sqlPeople'] = $sqlPeople; + $sql['sqlTotBobot'] = $sqlTotBobot; + $sql['sqlScale'] = $sqlScale; + $sql['sqlScaleNew'] = $sqlScaleNew; + $sql['sqlCheckApproval'] = $sqlCheckApproval; + $sql['sqlPeopleMonitoring'] = $sqlPeopleMonitoring; + $sql['sqlExportDataMonitoringTarget'] = $sqlExportDataMonitoringTarget; + return $sql; + } + + + function sqlViewDataGembaEmployeeResult() + { + $sqlCheckBuUser = "SELECT LEFT(emp.positionID,2) as bu FROM employement emp WHERE emp.nik=:nik"; + $sqlPeople = "SELECT + a.id, + MAX(a.kpi_scale_id) as kpi_scale_id, + round((a.bobot*100),2) as weight, + MAX(a.expired_date) as expired_date, + MAX(a.value_category) as value_category, + MAX(a.value_type) as value_type, + min(d.min) as min, + max(d.max) as max, + MAX(a.is_allow_more_than_100) as is_allow_more_than_100, + (SELECT bobot FROM emp_kpi_quarter_target WHERE employement_has_kpi_scale_id = a.id AND periode ='Q1') as q1_bobot, + (SELECT bobot FROM emp_kpi_quarter_target WHERE employement_has_kpi_scale_id = a.id AND periode ='Q2') as q2_bobot, + (SELECT bobot FROM emp_kpi_quarter_target WHERE employement_has_kpi_scale_id = a.id AND periode ='Q3') as q3_bobot, + (SELECT bobot FROM emp_kpi_quarter_target WHERE employement_has_kpi_scale_id = a.id AND periode ='Q4') as q4_bobot, + (SELECT bobot FROM emp_kpi_quarter_target WHERE employement_has_kpi_scale_id = a.id AND periode ='S1') as s1_bobot, + (SELECT bobot FROM emp_kpi_quarter_target WHERE employement_has_kpi_scale_id = a.id AND periode ='S2') as s2_bobot, + MAX(a.employement_nik) as employement_nik, + MAX(a.'personal') as type_kpi + FROM + `employement_has_kpi_scale` a + join emp_kpi_approval b on a.id=b.employement_has_kpi_scale_id + left join emp_kpi_monthly_target d on d.employement_has_kpi_scale_id = a.id + WHERE + `employement_nik`=:nik + AND YEAR(`efective_date`)=:year + group by a.id + UNION + SELECT + * + FROM + ( + SELECT + t1.id, + max(t1.kpi_scale_id) as kpi_scale_id, + round((t2.bobot),2) as weight, + max(t4.expired_date) as expired_date, + max(t1.value_category) as value_category, + max(t1.value_type) as value_type, + min(t5.min) as min, + max(t5.max) as max, + 0 as is_allow_more_than_100, + (SELECT bobot FROM org_layer_kpi_quarter_target WHERE org_layer_id = t1.id AND periode ='Q1') as q1_bobot, + (SELECT bobot FROM org_layer_kpi_quarter_target WHERE org_layer_id = t1.id AND periode ='Q2') as q2_bobot, + (SELECT bobot FROM org_layer_kpi_quarter_target WHERE org_layer_id = t1.id AND periode ='Q3') as q3_bobot, + (SELECT bobot FROM org_layer_kpi_quarter_target WHERE org_layer_id = t1.id AND periode ='Q4') as q4_bobot, + (SELECT bobot FROM org_layer_kpi_quarter_target WHERE org_layer_id = t1.id AND periode ='S1') as s1_bobot, + (SELECT bobot FROM org_layer_kpi_quarter_target WHERE org_layer_id = t1.id AND periode ='S2') as s2_bobot, + MAX(t2.employement_nik) as employement_nik, + MAX(t1.'kpi_position') as type_kpi + FROM + org_layer_kpi t1 + INNER JOIN employement_kpi_position t2 ON t1.id=t2.org_layer_kpi_id AND t2.id = (SELECT id FROM employement_kpi_position WHERE org_layer_kpi_id = t1.id AND efective_date <= now() ORDER BY efective_date DESC LIMIT 1) + INNER JOIN employement t3 ON t2.employement_nik = t3.nik + INNER JOIN kpi_scale t4 ON t1.kpi_scale_id = t4.id + INNER JOIN org_layer_kpi_monthly_target t5 ON t1.org_layer_id = t5.org_layer_kpi_id + WHERE + t3.nik = :nik + AND + YEAR(t4.effective_date)=:year + ORDER BY t1.id + ) tab + WHERE + tab.id is not null"; + + $sqlPeopleScore = 'SELECT Adminscores(Gembagetach(:value_category, :target_value, :min, :max, :result,:bu),:bobot,:is_allow_100) as score'; + + $sqlScale = 'SELECT a.id AS idMasterGemba,a.kpi,a.description,b.target,b.uom,b.id AS kpi_scale_id FROM master_kpi a INNER JOIN kpi_scale b ON a.id=b.kpi_id WHERE b.id=:kpiPeopleID AND YEAR(b.effective_date)=:year'; + + $sqlScaleNew = "SELECT + a.id AS idMasterGemba, + a.kpi,a.description, + round(c.target_value,2) as `target`,b.uom,b.id AS kpi_scale_id, + a.kpi_ref_function_id + FROM master_kpi a + INNER JOIN kpi_scale b ON a.id=b.kpi_id + INNER JOIN kpi_scale_detail c on b.id=c.kpi_scale_id + WHERE b.id=:kpiPeopleID AND YEAR(b.effective_date)=:year"; + + $sqlCheckApproval = 'SELECT COUNT(`employement_has_kpi_scale_id`) as total FROM `emp_kpi_approval` WHERE `employement_has_kpi_scale_id`=:id'; + + $sqlCheckResult = "SELECT DATE_FORMAT(`result_Date`,'%M %Y') as resultDate, result_quantitative as kpiValue, result FROM kpi_result WHERE `employement_has_kpi_scale_id`=:id and DATE_FORMAT(`result_Date`,'%Y')=:year order by result_Date desc limit 1"; + $sqlResultAvg = "SELECT avg(result_quantitative) as kpiValue FROM kpi_result WHERE `employement_has_kpi_scale_id`=:id and DATE_FORMAT(`result_Date`,'%Y')=:year"; + $sqlResultTotal = "SELECT sum(result_quantitative) as kpiValue FROM kpi_result WHERE `employement_has_kpi_scale_id`=:id and DATE_FORMAT(`result_Date`,'%Y')=:year"; + $sqlResultMax = "SELECT max(result_quantitative) as kpiValue FROM kpi_result WHERE `employement_has_kpi_scale_id`=:id and DATE_FORMAT(`result_Date`,'%Y')=:year"; + // pa approval + $sqlPaApproval = "select count(a.id) as total from employement_has_behivor_performance a inner join `pa_approval` b on a.id=b.`employement_has_behivor_performance_id` where a.employement_nik=:nik and year(a.result_date)=:year"; + + $sql['sqlPeople'] = $sqlPeople; + $sql['sqlScale'] = $sqlScale; + $sql['sqlScaleNew'] = $sqlScaleNew; + $sql['sqlCheckApproval'] = $sqlCheckApproval; + $sql['sqlCheckResult'] = $sqlCheckResult; + $sql['sqlResultAvg'] = $sqlResultAvg; + $sql['sqlPaApprovalNew'] = $sqlPaApproval; + $sql['sqlResultTotal'] = $sqlResultTotal; + $sql['sqlResultMax'] = $sqlResultMax; + $sql['sqlPeopleScore'] = $sqlPeopleScore; + $sql['sqlCheckBuUser'] = $sqlCheckBuUser; + + return $sql; + } + + function sqlDeleteGembaPeople() + { + $sqlget = 'select kpi_scale_id from employement_has_kpi_scale where id=:id and employement_nik=:nik'; + $sql = 'delete from employement_has_kpi_scale where id=:id and employement_nik=:nik'; + $sql1 = 'delete from kpi_scale where `id`=:id'; + + $sql2['sqlget'] = $sqlget; + $sql2['sql'] = $sql; + $sql2['sql1'] = $sql1; + + return $sql2; + } + + function sqlExportToExcel() + { + $userAllbu = array('15000204', '19000303', '18000632', '22000235'); + $userAllArea = array('19000069', '21000130'); + $use = \Helper::getSessionVar('username'); + $bu = \Helper::getSessionVar('empSite'); + $whereBu = ''; + if (!in_array($use, $userAllbu)) { + $whereBu = " AND LEFT(a.positionID,2)='" . $bu . "' HAVING sub_area_id IN (SELECT subarea_id FROM `user_admin_subarea` WHERE `username`='{$use}')"; + } + + if (!in_array($use, $userAllbu) && in_array($use, $userAllArea)) { + $whereBu = " AND LEFT(a.positionID,2)='" . $bu . "' "; + } + + + $where = " ((left(positionID,2) LIKE :bu) + AND ( mid(positionID,3,2) LIKE :divisi) AND ( MID(positionID,5,2) LIKE :department)) "; + + $table = "(SELECT `nik`, + CONCAT(title,\" \",first_name,\" \",last_name) `name`, + a.positionID `positionID` , + (SELECT sub_area_id FROM emp_personal_sub_area WHERE nik=a.nik AND effective_date<=CURRENT_DATE() ORDER BY effective_date DESC ,id DESC LIMIT 1) AS sub_area_id + FROM employement a join emp_profiles b on a.`emp_profile_id`=b.`id` + where left(a.grade,1)>2 + {$whereBu} + ) AS tab"; + $sql = "SELECT + SQL_CALC_FOUND_ROWS + `nik`, + `name`, + `positionID` + FROM {$table}"; + + + $sql2['sql'] = $sql; + + return $sql2; + } + + public function sqlGembaMonitoringProgress() + { + $sqlGembaPeople = "select + a.id, + a.kpi_scale_id, + a.bobot, + a.value_type + from `employement_has_kpi_scale` a inner join emp_kpi_approval b on a.id=b.`employement_has_kpi_scale_id` + where a.`employement_nik`=:nik and a.efective_date<=:end and a.expired_date>=:start and year(a.efective_date)=:year and year(a.expired_date)=:year"; + + // total kpi in current year + $sqlKPIAll = "SELECT count(id) as total FROM employement_has_kpi_scale + where employement_nik=:nik and year(efective_date)=:year and year(expired_date)=:year"; + + // total KPI active in periode selected + $sqlGembaActive = 'select + a.id, + a.kpi_scale_id, + round((bobot*100),2) as weight + from `employement_has_kpi_scale` a + where + a.`employement_nik`=:nik and a.efective_date<=:end and a.expired_date>=:start and year(a.efective_date)=:year and year(a.expired_date)=:year'; + //cek jumlah kpi target setting + $sqlTS = "select count(id) as tot from kpi_scale_detail where kpi_scale_id=:kpi_scale_id"; + + //cek jumlah result submit per kpi + $sqlTotalResult = ' select count(id) as total from kpi_result where employement_has_kpi_scale_id=:id'; + + $sqlCekApproval = "select count(id) as tot from `employement_has_kpi_scale` where employement_nik=:nik and efective_date<=:end and expired_date>=:start and id not in (select employement_has_kpi_scale_id from emp_kpi_approval) and year(efective_date)=:year and year(expired_date)=:year"; + + $sqlTsteEmp = ' select count(id) as total from employement_has_behivor_performance where employement_nik=:nik and periode=:periode and year(result_date)=:year'; + + // get tste N+1 + $sqlTsteN = 'select count(a.id) as total from employement_has_behivor_performance a inner join `result_behavior_n1` b on a.id=b.`employement_has_behivor_performance_id` where a.employement_nik=:nik and a.periode=:periode and year(a.result_date)=:year'; + + // pa approval + $sqlPaApproval = ' select count(a.id) as total from employement_has_behivor_performance a inner join `pa_approval` b on a.id=b.`employement_has_behivor_performance_id` where a.employement_nik=:nik and a.periode=:periode and year(a.result_date)=:year'; + + // pa approval + $sqlPaApprovalNew = ' select count(a.id) as total from employement_has_behivor_performance a inner join `pa_approval` b on a.id=b.`employement_has_behivor_performance_id` where a.employement_nik=:nik and and year(a.result_date)=:year'; + + + + return array( + 'sqlGembaPeople' => $sqlGembaPeople, + 'sqlKPIAll' => $sqlKPIAll, + 'sqlGembaActive' => $sqlGembaActive, + 'sqlTS' => $sqlTS, + 'sqlTotalResult' => $sqlTotalResult, + 'sqlCekApproval' => $sqlCekApproval, + 'sqlTsteEmp' => $sqlTsteEmp, + 'sqlTsteN' => $sqlTsteN, + 'sqlPaApproval' => $sqlPaApproval, + 'sqlPaApprovalNew' => $sqlPaApprovalNew + ); + } + + + function sqlSearchEmp() + { + $sql = "SELECT distinct e.nik, + e.nik_atasan, + e.grade, + e.emp_profile_id, + e.status, + e.hired_date, + e.flag_app, + e.effective_date, + CONCAT_WS(' ',CONCAT(p.title,'. '), p.first_name,p.middle_name,p.last_name) as fullname, + p.first_name, + p.middle_name, + p.last_name, + p.nick_name, + p.title, + p.gender, + p.date_join, + ej.job_title, + ej.layer_id, + ol.description as org_layer_description + FROM + employement e + LEFT JOIN emp_profiles p ON p.id = e.emp_profile_id + LEFT JOIN emp_job ej ON ej.nik = e.nik AND ej.id=(SELECT id FROM emp_job WHERE nik = e.nik AND effective_date <= now() ORDER BY effective_date DESC LIMIT 1) + LEFT JOIN mpp_detail md ON md.id = ej.mpp_detail_id + LEFT JOIN org_layer ol ON md.org_layer_id = ol.id + LEFT JOIN emp_personal_sub_area epsa ON epsa.nik = e.nik AND epsa.id=(SELECT id FROM emp_personal_sub_area WHERE nik = e.nik AND effective_date <= now() ORDER BY effective_date DESC LIMIT 1) + WHERE + e.status = 'active' + AND + ( + e.nik LIKE :search + OR p.first_name LIKE :search + OR p.middle_name LIKE :search + OR p.last_name LIKE :search + OR p.nick_name LIKE :search + ) + AND ol.department_id=:department_id + AND epsa.sub_area_id=:sub_area_id + ORDER BY e.nik, p.first_name, p.middle_name, p.last_name, p.nick_name + LIMIT 50"; + return $sql; + } + + public function sqlSaveGembaPeopleGeneral() + { + $sqlInsertGemba = 'INSERT INTO `master_kpi` + ( + `kpi`, + `description`) + VALUES + ( + :kpi, + :description)'; + + $sqlInsertScale = 'INSERT INTO `kpi_scale` + ( + `kpi_id`, + `effective_date`, + `target`, + `uom`, + `expired_date`) + VALUES + ( + :kpi_id, + :effective_date, + :target, + :uom, + :expired_date) '; + + $sqlInsertGembaEmp = 'INSERT INTO `employement_has_kpi_scale` + ( + `efective_date`, + `bobot`, + `kpi_scale_id`, + `employement_nik`, + `expired_date`, + `value_type`, + `targetID`, + `value_category`, + `additional_note`, + `is_allow_more_than_100`) + VALUES + ( + :efective_date, + :bobot, + :kpi_scale_id, + :employement_nik, + :expired_date, + :value_type, + :targetID, + :value_category, + :additional_note, + :is_allow_more_than_100)'; + + $sqlScaleDetail = 'insert into kpi_scale_detail(`no_urut`,`description`,`start`,`finish`,`type`,`kpi_scale_id`,target_value)values(:noUrut,:description,:min,:max,:type,:kpiScaleId,:target_value)'; + + $sqlMonthlyTarget = "INSERT INTO emp_kpi_monthly_target + (target, `year`, `month`, employement_has_kpi_scale_id, min, max) + VALUES + (:target, :year, :month, :employement_has_kpi_scale_id, :min, :max)"; + + $sqlQuarterTarget = "INSERT INTO emp_kpi_quarter_target + (target, `year`, `periode`, employement_has_kpi_scale_id, min, max, bobot) + VALUES + (:target, :year, :periode, :employement_has_kpi_scale_id, :min, :max, :bobot)"; + + + $sqlInsertGeneralGembaScale = "INSERT INTO general_kpi_scale + (kpi_scale_id, country_id, bu, managed_by, value_category, value_type, target_sharing, result_sharing,status) + VALUES + (:kpi_scale_id, :country_id, :bu, :managed_by, :value_category, :value_type, :target_sharing, :result_sharing,:status)"; + + $sqlInsertGeneralGembaEmp = "INSERT INTO general_kpi_emp + (nik, general_kpi_scale_id, yearly_weight, assign_by, is_setting_bobot, status) + VALUES + (:nik, :general_kpi_scale_id, :yearly_weight, :assign_by, :is_setting_bobot, :status)"; + + $sqlUpdateGeneralGembaEmp = "UPDATE general_kpi_emp + SET nik=:nik, yearly_weight=:yearly_weight, general_kpi_scale_id=:general_kpi_scale_id, assign_by=:assign_by, is_setting_bobot =:is_setting_bobot,status=:status + WHERE + id=:id"; + + $sqlInsertGeneralGembaDetailWeight = "INSERT INTO general_kpi_detail_weight + (period_type, period_value, weight, general_kpi_emp_id, target) + VALUES + (:period_type, :period_value, :weight, :general_kpi_emp_id, :target)"; + + $sqlUpdateGeneralGembaDetailWeight = "UPDATE general_kpi_detail_weight + SET period_type=:period_type, period_value=:period_value, weight=:weight, general_kpi_emp_id=:general_kpi_emp_id, target=:target + WHERE + period_value=:period_value AND general_kpi_emp_id=:general_kpi_emp_id"; + + $sqlMonthlyTargetGeneral = "INSERT INTO general_kpi_monthly_target + (target, `year`, `month`, general_kpi_scale_id, min, max) + VALUES + (:target, :year, :month, :general_kpi_scale_id, :min, :max)"; + + $sql['sqlInsertGemba'] = $sqlInsertGemba; + $sql['sqlInsertScale'] = $sqlInsertScale; + $sql['sqlInsertGeneralGembaScale'] = $sqlInsertGeneralGembaScale; + $sql['sqlInsertGeneralGembaEmp'] = $sqlInsertGeneralGembaEmp; + $sql['sqlUpdateGeneralGembaEmp'] = $sqlUpdateGeneralGembaEmp; + $sql['sqlInsertGeneralGembaDetailWeight'] = $sqlInsertGeneralGembaDetailWeight; + $sql['sqlUpdateGeneralGembaDetailWeight'] = $sqlUpdateGeneralGembaDetailWeight; + $sql['sqlInsertGembaEmp'] = $sqlInsertGembaEmp; + $sql['sqlScaleDetail'] = $sqlScaleDetail; + $sql['sqlMonthlyTargetGeneral'] = $sqlMonthlyTargetGeneral; + $sql['sqlQuarterTarget'] = $sqlQuarterTarget; + + return $sql; + } + + function sqlViewDataGembaGeneral() + { + $sqlPeople = 'SELECT + t3.kpi, + t3.description, + DATE_FORMAT(t2.effective_date, "%Y-%m-%d") as start_date, + t2.expired_date, + t2.uom, + t1.*, + getEmpName(t1.managed_by) as manage_by_name + FROM + general_kpi_scale t1 + INNER JOIN kpi_scale t2 ON t1.kpi_scale_id = t2.id + INNER JOIN master_kpi t3 ON t2.kpi_id = t3.id + WHERE + t1.managed_by =:nik + AND + YEAR(t2.effective_date)=:year'; + + $sqlTotBobot = "select ifnull(sum(totweight),0) as totweight from (SELECT ROUND((bobot*100),2) AS totweight + FROM `employement_has_kpi_scale` WHERE `employement_nik`=:nik AND YEAR(`efective_date`)=:year + AND `expired_date` >=:expdate) as tab"; + + $sqlScale = 'SELECT a.id AS idMasterGemba,a.kpi,a.description,b.target,b.uom,b.id AS kpi_scale_id FROM master_kpi a INNER JOIN kpi_scale b ON a.id=b.kpi_id WHERE b.id=:kpiPeopleID AND YEAR(b.effective_date)=:year'; + $sqlScaleNew = "SELECT + a.id AS idMasterGemba, + a.kpi,a.description, + c.target_value as `target`,b.uom,b.id AS kpi_scale_id + FROM master_kpi a + INNER JOIN kpi_scale b ON a.id=b.kpi_id + INNER JOIN kpi_scale_detail c on b.id=c.kpi_scale_id + WHERE b.id=:kpiPeopleID AND YEAR(b.effective_date)=:year"; + + $sqlCheckApproval = 'SELECT COUNT(`employement_has_kpi_scale_id`) as total FROM `emp_kpi_approval` WHERE `employement_has_kpi_scale_id`=:id'; + + $sqlPeopleMonitoring = 'SELECT ehks.id, + ehks.kpi_scale_id, + Round(( ehks.bobot * 100 ), 2) AS weight, + ehks.efective_date, + ehks.expired_date, + ehks.value_type, + ehks.employement_nik, + ehks.value_category, + ehks.is_allow_more_than_100 + FROM `employement_has_kpi_scale` ehks + LEFT JOIN emp_kpi_approval app ON app.employement_has_kpi_scale_id = ehks.id + WHERE ehks.`employement_nik` = :nik + AND Year(ehks.`efective_date`) = :year'; + + + $sql['sqlPeople'] = $sqlPeople; + $sql['sqlTotBobot'] = $sqlTotBobot; + $sql['sqlScale'] = $sqlScale; + $sql['sqlScaleNew'] = $sqlScaleNew; + $sql['sqlCheckApproval'] = $sqlCheckApproval; + $sql['sqlPeopleMonitoring'] = $sqlPeopleMonitoring; + return $sql; + } + + function sqlViewGembaPeopleDetailGeneral($params) + { + $where = ''; + if (isset($params['nik'])) { + $where .= " AND t1.nik = '{$params['nik']}' "; + } + + $sql1 = 'SELECT + KS.`id` AS kpiScaleId, + KS.`effective_date` AS effectiveDate, + KS.`expired_date` AS expiredDate, + KS.`target`, + KS.`uom`, + MK.`id` AS kpiId, + MK.`kpi`, + MK.`description`, + GK.`id` AS AdminGeneralScaleId, + GK.`value_type` as valueType, + GK.`value_category` as valueCategory, + GK.target_sharing, + MK.kpi_ref_function_id, + krf.function_name, + YEAR(KS.effective_date) as year + FROM kpi_scale KS + LEFT JOIN master_kpi MK ON MK.`id`=KS.`kpi_id` + LEFT JOIN general_kpi_scale GK ON GK.`kpi_scale_id`=KS.`id` + LEFT JOIN kpi_ref_function krf ON MK.kpi_ref_function_id = krf.id + WHERE KS.`id`=:id'; + $sqlDetail = 'select description,start as min,finish as max,`type`, target_value from kpi_scale_detail where kpi_scale_id=:id order by no_urut asc'; + + $sqlListEmp = "SELECT + t1.nik, + t1.id, + (t1.yearly_weight*100) as bobot, + CONCAT_WS(' ',CONCAT(t5.title,'. '), t5.first_name,t5.middle_name,t5.last_name) as fullname, + t6.`type` + FROM + general_kpi_emp t1 + INNER JOIN general_kpi_scale t2 ON t1.general_kpi_scale_id = t2.id + INNER JOIN kpi_scale t3 ON t2.kpi_scale_id = t3.id + LEFT JOIN employement t4 ON t1.nik = t4.nik + LEFT JOIN emp_profiles t5 ON t5.id = t4.emp_profile_id + LEFT JOIN emp_preiode_apraisal_quarter t6 ON t6.nik = t4.nik AND t6.id = (SELECT id FROM `emp_preiode_apraisal_quarter` WHERE `nik`=t4.nik AND `effective_date` <=DATE_FORMAT(t3.effective_date, '%Y-%m-%d') ORDER BY effective_date DESC LIMIT 1) + WHERE + t1.general_kpi_scale_id = :general_kpi_scale_id + {$where}"; + + $sqlMonthlyTarget = 'select + DISTINCT + t1.*, target as target_value + from + general_kpi_monthly_target t1 + LEFT JOIN general_kpi_scale t2 ON t1.general_kpi_scale_id = t2.id + where + general_kpi_scale_id=:general_kpi_scale_id + order by month asc'; + + $sqlQuarterTarget = "select *, target as target_value from emp_kpi_quarter_target where employement_has_kpi_scale_id=:employement_has_kpi_scale_id AND periode like '%Q%' order by id asc"; + $sqlPeriodSetting = "SELECT + id, + weight*100 as bobot, + null as min, + null as max, + target, + target as target_value, + period_type, + period_value as view, + period_value as value + FROM + general_kpi_detail_weight + WHERE + general_kpi_emp_id =:general_kpi_emp_id"; + + $sqlGetPAApproval = "SELECT DISTINCT a.result_date,periode, a.employement_nik, MONTH(a.result_date) as month, year(a.result_date) as year + FROM + `employement_has_behivor_performance` a + INNER JOIN pa_approval b ON a.id = b.employement_has_behivor_performance_id + INNER JOIN employement_has_kpi_scale c on a.employement_nik = c.employement_nik + WHERE c.id=:employement_has_kpi_scale_id + AND year(result_date)=:year + ORDER BY a.result_date ASC"; + + $sql['sql'] = $sql1; + $sql['sqlListEmp'] = $sqlListEmp; + $sql['sqlMonthlyTarget'] = $sqlMonthlyTarget; + $sql['sqlQuarterTarget'] = $sqlQuarterTarget; + $sql['sqlPeriodSetting'] = $sqlPeriodSetting; + $sql['sqlGetPAApproval'] = $sqlGetPAApproval; + $sql['sqlDetail'] = $sqlDetail; + return $sql; + } + + function sqlDeleteGembaPeopleGeneral() + { + $sqlget = 'select + t1.kpi_scale_id + from + general_kpi_scale t1 + where + t1.id =:id + and + t1.managed_by =:nik'; + + $sql = 'delete from general_kpi_scale where id=:id and managed_by=:nik'; + + $sql1 = 'delete from kpi_scale where `id`=:id'; + + $sql2['sqlget'] = $sqlget; + $sql2['sql'] = $sql; + $sql2['sql1'] = $sql1; + + return $sql2; + } + + + function sqlUpdateGembaPeopleGeneral() + { + + $sqlUpdateScale = 'UPDATE `kpi_scale` SET + `kpi_id`=:kpi_id, + `effective_date`=:effective_date, + `expired_date`=:expired_date, + `target`=:target, + `uom`=:uom + WHERE `id`=:kpi_scale_id'; + + $sqlUpdateGembaGeneralScale = 'UPDATE general_kpi_scale + SET + value_category=:value_category, + value_type=:value_type + WHERE id=:id AND managed_by=:managed_by'; + + $deleteGembaScaleDetail = 'delete from kpi_scale_detail where kpi_scale_id=:emp_kpi_scale_id'; + + $sqlScaleDetail = 'insert into kpi_scale_detail(`no_urut`,`description`,`start`,`finish`,`type`,`kpi_scale_id`,target_value)values(:noUrut,:description,:min,:max,:type,:kpiScaleId,:target_value)'; + + $deleteMonthlyTarget = 'delete from general_kpi_monthly_target where general_kpi_scale_id=:general_kpi_scale_id'; + + $sqlMonthlyTarget = "INSERT INTO general_kpi_monthly_target + (target, `year`, `month`, general_kpi_scale_id, min, max) + VALUES + (:target, :year, :month, :general_kpi_scale_id, :min, :max)"; + + $sql['sqlUpdateScale'] = $sqlUpdateScale; + $sql['sqlUpdateGembaGeneralScale'] = $sqlUpdateGembaGeneralScale; + $sql['deleteGembaScaleDetail'] = $deleteGembaScaleDetail; + $sql['sqlScaleDetail'] = $sqlScaleDetail; + $sql['deleteMonthlyTarget'] = $deleteMonthlyTarget; + $sql['sqlMonthlyTarget'] = $sqlMonthlyTarget; + + return $sql; + } + + function sqlEmp() + { + $sql = "SELECT distinct e.nik, + e.nik_atasan, + e.grade, + e.emp_profile_id, + e.status, + e.hired_date, + e.flag_app, + e.effective_date, + CONCAT_WS(' ',CONCAT(p.title,'. '), p.first_name,p.middle_name,p.last_name) as fullname, + p.first_name, + p.middle_name, + p.last_name, + p.nick_name, + p.title, + p.gender, + p.date_join, + ej.job_title, + ej.layer_id, + ol.description as org_layer_description, + period.`type` + FROM + employement e + LEFT JOIN emp_profiles p ON p.id = e.emp_profile_id + LEFT JOIN (SELECT ej.nik, ej.job_title, ej.layer_id, ej.effective_date FROM emp_job ej ORDER BY ej.effective_date DESC) as ej ON e.nik = ej.nik + LEFT JOIN org_layer ol ON ej.layer_id = ol.id + LEFT JOIN emp_preiode_apraisal_quarter period ON period.nik = e.nik AND period.id = (SELECT id FROM `emp_preiode_apraisal_quarter` WHERE `nik`=e.nik AND `effective_date` <=CURDATE() ORDER BY effective_date DESC LIMIT 1) + WHERE + e.status = 'active' + AND + e.nik LIKE :nik"; + + return $sql; + } + + public function setStatementApprovalIns() + { + try { + $sql = "INSERT INTO kpi_general_approval + (approval_type,approval_status,approval_level,is_last_approval,approved_by,is_group,general_kpi_scale_id,days_limit_approval,is_limit_approval) + VALUES + (:approval_type,:approval_status,:approval_level,:is_last_approval,:approved_by,:is_group,:transaction_id,:days_limit_approval,:is_limit_approval)"; + + return $this->registry->db->prepare($sql); + } catch (ErrorException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function setStatementGroupApprovalIns() + { + try { + $sql = "INSERT INTO kpi_general_group_approval + (approval_id,nik_app) + VALUES + (:emp_absence_approval_id,:nik_app)"; + + return $this->registry->db->prepare($sql); + } catch (ErrorException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + function sqlViewDataGembaGeneralApproval() + { + $sqlPeopleApproval = "SELECT + CONCAT_WS(' ', t5.`first_name`, t5.`middle_name`, t5.`last_name`) AS nama, + t7.kpi, + t7.description, + DATE_FORMAT(t6.effective_date, '%Y-%m-%d') as start_date, + t6.expired_date, + t6.uom, + t3.*, + t1.approval_status, + t1.approved_by, + t1.approval_type, + YEAR(t6.effective_date) as years + FROM + kpi_general_approval t1 + LEFT JOIN kpi_general_group_approval t2 on t1.id = t2.approval_id + LEFT JOIN general_kpi_scale t3 on t1.general_kpi_scale_id = t3.id + LEFT JOIN employement t4 ON t3.managed_by = t4.nik + LEFT JOIN emp_profiles t5 ON t4.emp_profile_id = t5.id + INNER JOIN kpi_scale t6 ON t3.kpi_scale_id = t6.id + INNER JOIN master_kpi t7 ON t6.kpi_id = t7.id + WHERE + t1.approval_status = :type + AND (t1.approved_by = :nik OR t2.nik_app = :nik)"; + + $sql['sqlPeopleApproval'] = $sqlPeopleApproval; + return $sql; + } + + + public function getQueryApprovalGembaGeneral() + { + $sql = "SELECT a.id, + pe.id as pengajuan_id, + a.approved_by as nik, + a.approval_type as `type`, + a.approval_status, + a.approval_status as `status`, + a.approval_level, + :approved_by AS approved_by, + a.approved_date as processed_at, + a.is_last_approval, + a.days_limit_approval, + a.is_limit_approval, + a.reject_comment as notes, + '1970-01-01' AS start_date, + '1970-01-01' AS end_date, + pe.managed_by as created_by, + '1970-01-01' as created_at + FROM kpi_general_approval a + LEFT JOIN general_kpi_scale pe ON a.general_kpi_scale_id = pe.id + WHERE pe.id = :transaction_id + ORDER BY a.approval_level ASC"; + return $sql; + } + + public function setQueryUpdateApprovalGembaGeneral() + { + $sql = "UPDATE kpi_general_approval + SET approval_status = :approval_status, + approved_date = NOW(), + approved_by = :approved_by, + reject_comment = :reject_comment + WHERE id = :id"; + return $sql; + } + + public function setQueryUpdateNextApprovalGembaGeneral() + { + $sql = "UPDATE kpi_general_approval SET approval_status='1' WHERE id=:id"; + return $sql; + } + + public function getQueryLevelApprovalGembaGeneral() + { + $sql = "SELECT approval_level + FROM ( + SELECT a.id, + pe.id as pengajuan_id, + a.approved_by as nik, + a.approval_type as `type`, + a.approval_status, + a.approval_status as `status`, + a.approval_level, + a.approved_by AS approved_by, + a.approved_date as processed_at, + a.is_last_approval, + a.days_limit_approval, + a.is_limit_approval, + a.reject_comment as notes, + '1970-01-01' AS start_date, + '1970-01-01' AS end_date, + pe.managed_by as created_by, + '1970-01-01' as created_at + FROM kpi_general_approval a + LEFT JOIN general_kpi_scale pe ON a.general_kpi_scale_id = pe.id + WHERE pe.id = :transaction_id + ) AS t + WHERE t.approved_by = :approved_by + ORDER BY t.approval_level ASC"; + return $sql; + } + + function sqlSearchEmpByNik() + { + $sql = "SELECT distinct e.nik, + e.nik_atasan, + e.grade, + e.emp_profile_id, + e.status, + e.hired_date, + e.flag_app, + e.effective_date, + CONCAT_WS(' ',CONCAT(p.title,'. '), p.first_name,p.middle_name,p.last_name) as fullname, + p.first_name, + p.middle_name, + p.last_name, + p.nick_name, + p.title, + p.gender, + p.date_join, + ej.job_title, + ej.layer_id, + ol.description as org_layer_description, + period.`type` + FROM + employement e + LEFT JOIN emp_profiles p ON p.id = e.emp_profile_id + LEFT JOIN (SELECT ej.nik, ej.job_title, ej.layer_id, ej.effective_date FROM emp_job ej ORDER BY ej.effective_date DESC) as ej ON e.nik = ej.nik + LEFT JOIN org_layer ol ON ej.layer_id = ol.id + LEFT JOIN emp_preiode_apraisal_quarter period ON period.nik = e.nik AND period.id = (SELECT id FROM `emp_preiode_apraisal_quarter` WHERE `nik`=e.nik AND `effective_date` <=CURDATE() ORDER BY effective_date DESC LIMIT 1) + WHERE + e.status = 'active' + AND ( + e.nik = :nik + ) + ORDER BY e.nik, p.first_name, p.middle_name, p.last_name, p.nick_name + LIMIT 50"; + return $sql; + } + + + public function sqlsaveGembaPosition() + { + $sqlInsertGemba = 'INSERT INTO `master_kpi` + ( + `kpi`, + `description`) + VALUES + ( + :kpi, + :description)'; + + $sqlInsertScale = 'INSERT INTO `kpi_scale` + ( + `kpi_id`, + `effective_date`, + `target`, + `uom`, + `expired_date`) + VALUES + ( + :kpi_id, + :effective_date, + :target, + :uom, + :expired_date) '; + + $sqlInsertGembaPosition = 'INSERT INTO `org_layer_kpi` + ( + `efective_date`, + `bobot`, + `kpi_scale_id`, + `mpp_detail_id`, + `expired_date`, + `value_type`, + `targetID`, + `value_category`, + `additional_note`, + `is_allow_more_than_100`, + `status`) + VALUES + ( + :efective_date, + :bobot, + :kpi_scale_id, + :mpp_detail_id, + :expired_date, + :value_type, + :targetID, + :value_category, + :additional_note, + :is_allow_more_than_100, + :status)'; + + $sqlScaleDetail = 'insert into kpi_scale_detail(`no_urut`,`description`,`start`,`finish`,`type`,`kpi_scale_id`,target_value)values(:noUrut,:description,:min,:max,:type,:kpiScaleId,:target_value)'; + + $sqlMonthlyTarget = "INSERT INTO org_layer_kpi_monthly_target + (target, `year`, `month`, org_layer_kpi_id, min, max) + VALUES + (:target, :year, :month, :org_layer_kpi_id, :min, :max)"; + + $sqlQuarterTarget = "INSERT INTO org_layer_kpi_quarter_target + (target, `year`, `periode`, org_layer_kpi_id, min, max, bobot) + VALUES + (:target, :year, :periode, :org_layer_kpi_id, :min, :max, :bobot)"; + + $sql['sqlInsertGemba'] = $sqlInsertGemba; + $sql['sqlInsertScale'] = $sqlInsertScale; + $sql['sqlInsertGembaPosition'] = $sqlInsertGembaPosition; + $sql['sqlScaleDetail'] = $sqlScaleDetail; + $sql['sqlMonthlyTarget'] = $sqlMonthlyTarget; + $sql['sqlQuarterTarget'] = $sqlQuarterTarget; + + return $sql; + } + + function sqlViewDataGembaPosition() + { + $sqlPosition = "SELECT + t1.id, + t1.kpi_scale_id, + round(SUM((t1.bobot*100)),2) as weight, + t1.efective_date, + t1.expired_date, + t1.value_type, + t1.org_layer_id, + t1.mpp_detail_id, + t1.value_category, + 'kpi' as type_kpi, + '2' as status, + t3.description as org_layer, + count(t1.id) as total_kpi + FROM + org_layer_kpi t1 + INNER JOIN mpp_detail t2 ON t1.mpp_detail_id = t2.id + INNER JOIN org_layer t3 ON t2.org_layer_id = t3.id + WHERE + YEAR(`efective_date`)=:year + AND + (t1.mpp_detail_id = :mpp_detail_id OR :mpp_detail_id = '') + GROUP BY t1.mpp_detail_id LIMIT 25"; + + $sqlPositionDetail = "SELECT + t1.id, + t1.kpi_scale_id, + round((t1.bobot*100),2) as weight, + t1.efective_date, + t1.expired_date, + t1.value_type, + t1.org_layer_id, + t1.mpp_detail_id, + t1.value_category, + 'kpi' as type_kpi, + t1.status, + t3.description as org_layer + FROM + org_layer_kpi t1 + INNER JOIN mpp_detail t2 ON t1.mpp_detail_id = t2.id + INNER JOIN org_layer t3 ON t2.org_layer_id = t3.id + WHERE + YEAR(`efective_date`)=:year + AND + t1.mpp_detail_id=:mpp_detail_id"; + + $sqlTotBobot = "select ifnull(sum(totweight),0) as totweight from (SELECT ROUND((bobot*100),2) AS totweight + FROM `employement_has_kpi_scale` WHERE `employement_nik`=:nik AND YEAR(`efective_date`)=:year + AND `expired_date` >=:expdate) as tab"; + + $sqlScale = 'SELECT a.id AS idMasterGemba,a.kpi,a.description,b.target,b.uom,b.id AS kpi_scale_id FROM master_kpi a INNER JOIN kpi_scale b ON a.id=b.kpi_id WHERE b.id=:kpiPeopleID AND YEAR(b.effective_date)=:year'; + $sqlScaleNew = "SELECT + a.id AS idMasterGemba, + a.kpi,a.description, + c.target_value as `target`,b.uom,b.id AS kpi_scale_id + FROM master_kpi a + INNER JOIN kpi_scale b ON a.id=b.kpi_id + INNER JOIN kpi_scale_detail c on b.id=c.kpi_scale_id + WHERE b.id=:kpiPeopleID AND YEAR(b.effective_date)=:year"; + + $sqlCheckApproval = 'SELECT COUNT(`employement_has_kpi_scale_id`) as total FROM `emp_kpi_approval` WHERE `employement_has_kpi_scale_id`=:id'; + + $sqlPositionMonitoring = "SELECT + t1.id, + t1.kpi_scale_id, + round((t1.bobot*100),2) as weight, + DATE_FORMAT(t1.efective_date, '%Y-%m-%d') as effective_date, + t1.expired_date, + t1.value_type, + '' as employement_nik, + t1.value_category, + 'kpi_position' as type_kpi, + '0' as is_allow_more_than_100, + null as general_kpi_scale_id, + t1.id as org_layer_kpi_id, + (SELECT bobot FROM org_layer_kpi_quarter_target WHERE org_layer_kpi_id = t1.id AND periode ='Q1') as q1_bobot, + (SELECT bobot FROM org_layer_kpi_quarter_target WHERE org_layer_kpi_id = t1.id AND periode ='Q2') as q2_bobot, + (SELECT bobot FROM org_layer_kpi_quarter_target WHERE org_layer_kpi_id = t1.id AND periode ='Q3') as q3_bobot, + (SELECT bobot FROM org_layer_kpi_quarter_target WHERE org_layer_kpi_id = t1.id AND periode ='Q4') as q4_bobot, + (SELECT bobot FROM org_layer_kpi_quarter_target WHERE org_layer_kpi_id = t1.id AND periode ='S1') as s1_bobot, + (SELECT bobot FROM org_layer_kpi_quarter_target WHERE org_layer_kpi_id = t1.id AND periode ='S2') as s2_bobot, + t1.efective_date as date_kpi + FROM + org_layer_kpi t1 + INNER JOIN mpp_detail t2 ON t1.mpp_detail_id = t2.id + INNER JOIN org_layer t3 ON t2.org_layer_id = t3.id + WHERE + t2.id = :mpp_detail_id + AND + YEAR(t1.efective_date) = :year + AND + t1.status ='2'"; + + + $sql['sqlPosition'] = $sqlPosition; + $sql['sqlPositionDetail'] = $sqlPositionDetail; + $sql['sqlTotBobot'] = $sqlTotBobot; + $sql['sqlScale'] = $sqlScale; + $sql['sqlScaleNew'] = $sqlScaleNew; + $sql['sqlCheckApproval'] = $sqlCheckApproval; + $sql['sqlPositionMonitoring'] = $sqlPositionMonitoring; + return $sql; + } + + function sqlViewGembaPositionDetail() + { + $sql1 = 'SELECT + KS.`id` AS kpiScaleId, + KS.`effective_date` AS effectiveDate, + KS.`expired_date` AS expiredDate, + KS.`target`, + KS.`uom`, + MK.`id` AS kpiId, + MK.`kpi`, + MK.`description`, + EK.`id` AS empGembaScaleId, + (EK.`bobot`*100) AS bobot, + EK.`value_type` as valueType, + EK.`targetID`, + EK.`value_category` as valueCategory, + EK.`additional_note` as additional_note, + EK.`is_allow_more_than_100` as is_allow_more_than_100, + EK.org_layer_id, + layer.description as org_layer + FROM kpi_scale KS + LEFT JOIN master_kpi MK ON MK.`id`=KS.`kpi_id` + LEFT JOIN org_layer_kpi EK ON EK.`kpi_scale_id`=KS.`id` + LEFT JOIN org_layer layer ON EK.org_layer_id = layer.id + WHERE KS.`id`=:id'; + + $sqlDetail = 'select description,start as min,finish as max,`type`, target_value from kpi_scale_detail where kpi_scale_id=:id order by no_urut asc'; + $sqlMonthlyTarget = 'select + DISTINCT + t1.*, target as target_value + from + org_layer_kpi_monthly_target t1 + LEFT JOIN employement_has_kpi_scale t2 ON t1.org_layer_kpi_id = t2.id + where + org_layer_kpi_id=:org_layer_kpi_id + order by month asc'; + $sqlQuarterTarget = "select *, target as target_value from org_layer_kpi_quarter_target where org_layer_kpi_id=:org_layer_kpi_id AND periode like '%Q%' order by id asc"; + $sqlSemesterTarget = "select *, target as target_value from org_layer_kpi_quarter_target where org_layer_kpi_id=:org_layer_kpi_id AND periode like '%S%' order by id asc"; + $sqlGetPAApproval = "SELECT DISTINCT a.result_date,periode, a.org_layer_id, MONTH(a.result_date) as month, year(a.result_date) as year + FROM + `employement_has_behivor_performance` a + INNER JOIN pa_approval b ON a.id = b.employement_has_behivor_performance_id + INNER JOIN employement_has_kpi_scale c on a.org_layer_id = c.org_layer_id + WHERE c.id=:org_layer_kpi_id + AND year(result_date)=:year + ORDER BY a.result_date ASC"; + + $sqlGetExpiredDay = "SELECT * FROM kpi_ref_set_expired WHERE bu=:bu"; + + $sql['sql'] = $sql1; + $sql['sqlDetail'] = $sqlDetail; + $sql['sqlMonthlyTarget'] = $sqlMonthlyTarget; + $sql['sqlQuarterTarget'] = $sqlQuarterTarget; + $sql['sqlSemesterTarget'] = $sqlSemesterTarget; + $sql['sqlGetPAApproval'] = $sqlGetPAApproval; + $sql['sqlGetExpiredDay'] = $sqlGetExpiredDay; + return $sql; + } + + + public function setStatementApprovalGembaPositionIns() + { + try { + $sql = "INSERT INTO kpi_position_approval + (approval_type,approval_status,approval_level,is_last_approval,approved_by,is_group,org_layer_kpi_id,days_limit_approval,is_limit_approval) + VALUES + (:approval_type,:approval_status,:approval_level,:is_last_approval,:approved_by,:is_group,:transaction_id,:days_limit_approval,:is_limit_approval)"; + + return $this->registry->db->prepare($sql); + } catch (ErrorException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function setStatementGroupApprovalGembaPositionIns() + { + try { + $sql = "INSERT INTO kpi_position_group_approval + (approval_id,nik_app) + VALUES + (:emp_absence_approval_id,:nik_app)"; + + return $this->registry->db->prepare($sql); + } catch (ErrorException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + function sqlViewDataGembaPositionApproval() + { + $sqlPeopleApproval = "SELECT + t7.kpi, + t7.description, + DATE_FORMAT(t6.effective_date, '%Y-%m-%d') as start_date, + t6.expired_date, + t6.uom, + t3.*, + t1.approval_status, + t1.approved_by, + t1.approval_type, + YEAR(t6.effective_date) as years, + t5.description as org_layer + FROM + kpi_position_approval t1 + LEFT JOIN kpi_position_group_approval t2 on t1.id = t2.approval_id + LEFT JOIN org_layer_kpi t3 on t1.org_layer_kpi_id = t3.id + INNER JOIN mpp_detail t4 ON t3.mpp_detail_id = t4.id + INNER JOIN org_layer t5 ON t4.org_layer_id = t5.id + INNER JOIN kpi_scale t6 ON t3.kpi_scale_id = t6.id + INNER JOIN master_kpi t7 ON t6.kpi_id = t7.id + WHERE + t1.approval_status = :type + AND (t1.approved_by = :nik OR t2.nik_app = :nik)"; + + $sql['sqlPeopleApproval'] = $sqlPeopleApproval; + return $sql; + } + + public function getQueryApprovalGembaPosition() + { + $sql = "SELECT a.id, + pe.id as pengajuan_id, + a.approved_by as nik, + a.approval_type as `type`, + a.approval_status, + a.approval_status as `status`, + a.approval_level, + :approved_by AS approved_by, + a.approved_date as processed_at, + a.is_last_approval, + a.days_limit_approval, + a.is_limit_approval, + a.reject_comment as notes, + '1970-01-01' AS start_date, + '1970-01-01' AS end_date, + '1970-01-01' as created_at + FROM kpi_position_approval a + LEFT JOIN org_layer_kpi pe ON a.org_layer_kpi_id = pe.id + WHERE pe.id = :transaction_id + ORDER BY a.approval_level ASC"; + return $sql; + } + + public function setQueryUpdateApprovalGembaPosition() + { + $sql = "UPDATE kpi_position_approval + SET approval_status = :approval_status, + approved_date = NOW(), + approved_by = :approved_by, + reject_comment = :reject_comment + WHERE id = :id"; + return $sql; + } + + public function setQueryUpdateNextApprovalGembaPosition() + { + $sql = "UPDATE kpi_position_approval SET approval_status='1' WHERE id=:id"; + return $sql; + } + + public function getQueryLevelApprovalGembaPosition() + { + $sql = "SELECT approval_level + FROM ( + SELECT a.id, + pe.id as pengajuan_id, + a.approved_by as nik, + a.approval_type as `type`, + a.approval_status, + a.approval_status as `status`, + a.approval_level, + a.approved_by AS approved_by, + a.approved_date as processed_at, + a.is_last_approval, + a.days_limit_approval, + a.is_limit_approval, + a.reject_comment as notes, + '1970-01-01' AS start_date, + '1970-01-01' AS end_date, + '1970-01-01' as created_at + FROM kpi_position_approval a + LEFT JOIN org_layer_kpi pe ON a.org_layer_kpi_id = pe.id + WHERE pe.id = :transaction_id + ) AS t + WHERE t.approved_by = :approved_by + ORDER BY t.approval_level ASC"; + return $sql; + } + + + public function setStatementApprovalEmpGembaPositionIns() + { + try { + $sql = "INSERT INTO employement_kpi_position_approval + (approval_type,approval_status,approval_level,is_last_approval,approved_by,is_group,employement_kpi_position_id,days_limit_approval,is_limit_approval) + VALUES + (:approval_type,:approval_status,:approval_level,:is_last_approval,:approved_by,:is_group,:transaction_id,:days_limit_approval,:is_limit_approval)"; + + return $this->registry->db->prepare($sql); + } catch (ErrorException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function setStatementGroupApprovalEmpGembaPositionIns() + { + try { + $sql = "INSERT INTO employement_kpi_position_group_approval + (approval_id,nik_app) + VALUES + (:emp_absence_approval_id,:nik_app)"; + + return $this->registry->db->prepare($sql); + } catch (ErrorException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getQueryApprovalEmpGembaPosition() + { + $sql = "SELECT a.id, + pe.id as pengajuan_id, + a.approved_by as nik, + a.approval_type as `type`, + a.approval_status, + a.approval_status as `status`, + a.approval_level, + :approved_by AS approved_by, + a.approved_date as processed_at, + a.is_last_approval, + a.days_limit_approval, + a.is_limit_approval, + a.reject_comment as notes, + '1970-01-01' AS start_date, + '1970-01-01' AS end_date, + '1970-01-01' as created_at + FROM employement_kpi_position_approval a + LEFT JOIN employement_kpi_position pe ON a.employement_kpi_position_id = pe.id + WHERE pe.id = :transaction_id + ORDER BY a.approval_level ASC"; + return $sql; + } + + public function setQueryUpdateApprovalEmpGembaPosition() + { + $sql = "UPDATE employement_kpi_position_approval + SET approval_status = :approval_status, + approved_date = NOW(), + approved_by = :approved_by, + reject_comment = :reject_comment + WHERE id = :id"; + return $sql; + } + + public function setQueryUpdateNextApprovalEmpGembaPosition() + { + $sql = "UPDATE employement_kpi_position_approval SET approval_status='1' WHERE id=:id"; + return $sql; + } + + public function getQueryLevelApprovalEmpGembaPosition() + { + $sql = "SELECT approval_level + FROM ( + SELECT a.id, + pe.id as pengajuan_id, + a.approved_by as nik, + a.approval_type as `type`, + a.approval_status, + a.approval_status as `status`, + a.approval_level, + a.approved_by AS approved_by, + a.approved_date as processed_at, + a.is_last_approval, + a.days_limit_approval, + a.is_limit_approval, + a.reject_comment as notes, + '1970-01-01' AS start_date, + '1970-01-01' AS end_date, + '1970-01-01' as created_at + FROM employement_kpi_position_approval a + LEFT JOIN employement_kpi_position pe ON a.employement_kpi_position_id = pe.id + WHERE pe.id = :transaction_id + ) AS t + WHERE t.approved_by = :approved_by + ORDER BY t.approval_level ASC"; + return $sql; + } + + function sqlGembaRefFunction($params) + { + + $table = "kpi_ref_function t1"; + + $where = "((t1.function_name LIKE :search) OR (t1.description LIKE :search))"; + + $sql = "SELECT + t1.* + FROM {$table} + WHERE {$where} + LIMIT {$params['offset']}, {$params['jumPage']}"; + + $sqlFilter = 'SELECT FOUND_ROWS() as filter'; + + $sqltotal = "SELECT + count(t1.id) as total + FROM {$table} + WHERE {$where}"; + + $sql1['data'] = $sql; + $sql1['total'] = $sqltotal; + $sql1['filter'] = $sqlFilter; + + return $sql1; + } + + function sqlGembaMaster($params) + { + + $table = "master_kpi t1 + LEFT JOIN kpi_ref_function t2 ON t1.kpi_ref_function_id = t2.id"; + + $where = "((t1.kpi LIKE :search) OR (t1.description LIKE :search))"; + + $sql = "SELECT + t1.*, + t2.function_name + FROM {$table} + WHERE {$where} + ORDER BY id asc + LIMIT {$params['offset']}, {$params['jumPage']}"; + + $sqlFilter = 'SELECT FOUND_ROWS() as filter'; + + $sqltotal = "SELECT + count(t1.id) as total + FROM {$table} + WHERE {$where}"; + + $sql1['data'] = $sql; + $sql1['total'] = $sqltotal; + $sql1['filter'] = $sqlFilter; + + return $sql1; + } + + function sqlViewDataGembaPositionApprovalTm() + { + $sqlPeopleApproval = "SELECT + t7.kpi, + t7.description, + DATE_FORMAT(t6.effective_date, '%Y-%m-%d') as start_date, + t6.expired_date, + t6.uom, + t3.*, + t1.approval_status, + t1.approved_by, + t1.approval_type, + YEAR(t6.effective_date) as years, + t5.description as org_layer + FROM + kpi_position_approval t1 + LEFT JOIN kpi_position_group_approval t2 on t1.id = t2.approval_id + LEFT JOIN org_layer_kpi t3 on t1.org_layer_kpi_id = t3.id + INNER JOIN mpp_detail t4 ON t3.mpp_detail_id = t4.id + INNER JOIN org_layer t5 ON t4.org_layer_id = t5.id + INNER JOIN kpi_scale t6 ON t3.kpi_scale_id = t6.id + INNER JOIN master_kpi t7 ON t6.kpi_id = t7.id + WHERE + t1.approval_status = :type + AND (t1.approved_by = :nik OR t2.nik_app = :nik)"; + + $sqlPeopleApproval = "SELECT + t1.employement_nik, + getEmpName(t1.employement_nik) as emp_name, + DATE_FORMAT(t1.efective_date, '%Y-%m-%d') as start_date, + t1.efective_date, + t1.expired_date, + t1.`year`, + t1.status, + t1.status_tm, + t1.status_tm as approval_status, + t1.notes, + t4.kpi, + t4.description, + t3.uom, + t2.value_category, + t2.value_type, + t1.id, + t1.org_layer_kpi_id, + t1.bobot as bobot_emp_set, + t2.bobot*100 as bobot + FROM + employement_kpi_position t1 + LEFT JOIN org_layer_kpi t2 ON t1.org_layer_kpi_id = t2.id + LEFT JOIN kpi_scale t3 ON t2.kpi_scale_id = t3.id + LEFT JOIN master_kpi t4 ON t3.kpi_id = t4.id + WHERE + t1.status_tm = :type"; + + $sql['sqlPeopleApproval'] = $sqlPeopleApproval; + return $sql; + } + + + function sqlViewDataPaResultKalibrasi($params) + { + + $table = "pa_result t1 + LEFT JOIN employement t2 ON t1.nik = t2.nik + LEFT JOIN emp_personal_sub_area t3 ON t3.id =(select id from emp_personal_sub_area where nik=t2.nik and effective_date<=current_date() order by effective_date desc ,id desc limit 1)"; + + $where = "((getEmpName(t1.nik) LIKE :search) OR (t1.nik LIKE :search)) AND t1.tahun = :tahun AND (left(positionID,2) LIKE :bu OR :bu = '') + AND + (mid(positionID,3,2) LIKE :divisi OR :divisi = '' OR :divisi ='All') + AND + (MID(positionID,5,2) LIKE :department OR :department = '' OR :department ='All') + AND + (t3.sub_area_id = :sub_area_id OR :sub_area_id = '' OR :sub_area_id ='All') + AND + (t1.periode = :periode OR :periode = '' OR :periode ='All')"; + + $sql = "SELECT + t1.id, + t1.nik, + getEmpName(t1.nik) as emp_name, + t1.periode, + t1.tahun, + t1.kpi, + t1.ip, + t1.nilai_mutu1, + t1.nilai_kalibrasi, + t1.kalibrasi_oleh, + getEmpName(t1.kalibrasi_oleh) as emp_name_kalibrasi, + t1.kalibrasi_date + FROM {$table} + WHERE {$where} + LIMIT {$params['offset']}, {$params['jumPage']}"; + + $sqlFilter = 'SELECT FOUND_ROWS() as filter'; + + $sqltotal = "SELECT + count(t1.id) as total + FROM {$table} + WHERE {$where}"; + + $sql1['data'] = $sql; + $sql1['total'] = $sqltotal; + $sql1['filter'] = $sqlFilter; + + return $sql1; + } + + function sqlViewDataGembaFinalResult() + { + + $sql = "SELECT `id`, `year`, `month`, `score`, `ref_level_color_id` FROM `kpi_final_result_month_acc` where `nik`= :nik"; + + return $sql; + } + + function sqlViewDataGembaFinalResultMonth() + { + + $sql = "SELECT + `id`, `year`, `month`, `score`, `ref_level_color_id` + from + `kpi_final_result_month_acc` + where + `year`=:qyear and `month`=:qmonth and (`ref_level_color_id`=1 or `ref_level_color_id`=2 or `ref_level_color_id`=0 )"; + + return $sql; + } + + function sqlViewDataGembaFinalResultYear() + { + $sql = "SELECT + `id`, `year`, `score`, `ref_level_color_id` + from + `kpi_final_result_periode_acc` + where + `nik`=:nik and `periode`=:qtype and `year`<=:qyear and (`ref_level_color_id`=1 or `ref_level_color_id`=2 or `ref_level_color_id`=0 )"; + + return $sql; + } + + function sqlViewDataGembaFinalResultPeriodic() + { + $sql = "SELECT + `id`, `year`, `score`, `ref_level_color_id` + from + `kpi_final_result_periode_acc` + where + `nik`=:nik and `periode`=:qtype and `year`=:qyear and (`ref_level_color_id`=1 or `ref_level_color_id`=2 or `ref_level_color_id`=0 )"; + + return $sql; + } + + function sqlViewNikByBuDv() + { + + $sql = "SELECT + t1.nik, + concat_ws(' ',IFNULL(t2.first_name,''),IFNULL(t2.middle_name,''),IFNULL(t2.last_name,'')) as fullName, + t7.description as division_name, + t8.description as department_name, + t4.description as mpp_name, + t5.description as layer_name, + t10.description as business_title_name, + t11.description as job_title, + t9.description as work_location + from employement t1 + inner join emp_profiles t2 on t1.emp_profile_id=t2.id + inner join emp_job t3 on t1.nik=t3.nik and t3.effective_date=(select max(t31.effective_date) from emp_job t31 where t31.nik=t1.nik and t31.effective_date<=:effective_date) + inner join mpp_detail t4 on t3.mpp_detail_id=t4.id + inner join org_layer t5 on t4.org_layer_id=t5.id + inner join emp_personal_sub_area t6 on t1.nik=t6.nik and t6.effective_date=(select max(t61.effective_date) from emp_personal_sub_area t61 where t61.nik=t1.nik and t61.effective_date<=:effective_date) + left outer join division t7 on t5.division_id=t7.id + left outer join department t8 on t5.department_id=t8.id + left outer join sub_area t9 on t6.sub_area_id=t9.id + inner join ndc_business_titles t10 on t5.bt_id=t10.id + inner join job_code t11 on t10.job_code_id=t11.id + inner join (select nik from kpi_final_result_month_acc group by nik) t12 on t12.nik=t1.nik + where + t1.`status`='active' + AND t5.entity_id=:bu + AND t5.division_id=:divisi + AND t5.department_id=:department + AND t6.sub_area_id=:area"; + + return $sql; + } + + function sqlViewNikByBuDvPeriodic() + { + $sql = "SELECT + t1.nik, + concat_ws(' ',IFNULL(t2.first_name,''),IFNULL(t2.middle_name,''),IFNULL(t2.last_name,'')) as fullName, + t7.description as division_name, + t8.description as department_name, + t4.description as mpp_name, + t5.description as layer_name, + t10.description as business_title_name, + t11.description as job_title, + t9.description as work_location + from employement t1 + inner join emp_profiles t2 on t1.emp_profile_id=t2.id + inner join emp_job t3 on t1.nik=t3.nik and t3.effective_date=(select max(t31.effective_date) from emp_job t31 where t31.nik=t1.nik and t31.effective_date<=:effective_date) + inner join mpp_detail t4 on t3.mpp_detail_id=t4.id + inner join org_layer t5 on t4.org_layer_id=t5.id + inner join emp_personal_sub_area t6 on t1.nik=t6.nik and t6.effective_date=(select max(t61.effective_date) from emp_personal_sub_area t61 where t61.nik=t1.nik and t61.effective_date<=:effective_date) + left outer join division t7 on t5.division_id=t7.id + left outer join department t8 on t5.department_id=t8.id + left outer join sub_area t9 on t6.sub_area_id=t9.id + inner join ndc_business_titles t10 on t5.bt_id=t10.id + inner join job_code t11 on t10.job_code_id=t11.id + inner join (select nik from kpi_final_result_periode_acc group by nik) t12 on t12.nik=t1.nik + where + t1.`status`='active' + AND t5.entity_id=:bu + AND t5.division_id=:divisi + AND t5.department_id=:department + AND t6.sub_area_id=:area"; + + return $sql; + } + + function sqlViewDataMonitoringPip($params) + { + $field = "t1.nik, + getEmpName(t1.nik) as emp_name, + t5.description as bt_name, + t6.description as division_name, + t7.description as department_name, + t9.description as sub_area_name, + getEmpName(t10.nik_atasan) as atasan_name, + t1.`id`, + t1.`year`, + t1.`month`, + t1.`score`, + t1.`ref_level_color_id`, + t11.color, + (SELECT + a.pip_state + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + b.periode_value =:qmonth + AND + b.`year` = :qyear + AND + a.nik = t1.nik) as pip_state, + (SELECT + a.pip_status + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + b.periode_value =:qmonth + AND + b.`year` = :qyear + AND + a.nik = t1.nik) as status"; + + $table = "`kpi_final_result_month_acc` t1 + INNER JOIN emp_job t2 ON t1.nik = t2.nik AND t2.id = (SELECT id FROM emp_job WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t3 ON t2.mpp_detail_id = t3.id + INNER JOIN org_layer t4 ON t3.org_layer_id = t4.id + INNER JOIN ndc_business_titles t5 ON t4.bt_id = t5.id + INNER JOIN division t6 ON t4.division_id = t6.id + INNER JOIN department t7 ON t4.department_id = t7.id + INNER JOIN emp_personal_sub_area t8 ON t8.nik = t1.nik AND t8.id = (SELECT id FROM emp_personal_sub_area WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN sub_area t9 ON t8.sub_area_id = t9.id + INNER JOIN employement t10 ON t10.nik = t1.nik + INNER JOIN kpi_ref_level_color t11 ON t1.ref_level_color_id = t11.id "; + + + $where = "t1.`year`=:qyear + and + t1.`month`=:qmonth + and + (t1.`ref_level_color_id`=1 or t1.`ref_level_color_id`=2 or t1.`ref_level_color_id`=0 )"; + + $sql = "SELECT + $field + from + $table + where + $where + LIMIT {$params['offset']}, {$params['jumPage']}"; + + $total = "SELECT + count(*) as total + from + $table + where + $where"; + + return array("data" => $sql, "total" => $total); + } + + + + function sqlGetTotalPip($params) + { + $field = "COUNT(*) as total"; + + $table = "`kpi_final_result_month_acc` t1 + INNER JOIN emp_job t2 ON t1.nik = t2.nik AND t2.id = (SELECT id FROM emp_job WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t3 ON t2.mpp_detail_id = t3.id + INNER JOIN org_layer t4 ON t3.org_layer_id = t4.id + INNER JOIN ndc_business_titles t5 ON t4.bt_id = t5.id + INNER JOIN division t6 ON t4.division_id = t6.id + INNER JOIN department t7 ON t4.department_id = t7.id + INNER JOIN emp_personal_sub_area t8 ON t8.nik = t1.nik AND t8.id = (SELECT id FROM emp_personal_sub_area WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN sub_area t9 ON t8.sub_area_id = t9.id + INNER JOIN employement t10 ON t10.nik = t1.nik + INNER JOIN kpi_ref_level_color t11 ON t1.ref_level_color_id = t11.id "; + + $w_pip_state = 't1.nik not in ( + SELECT + a.nik + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + b.periode_value =:periode_value + AND + b.`year` = :qyear + )'; + + if ($params['type'] > 0) { + $w_pip_state = " t1.nik in ( + SELECT + a.nik + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + b.periode_value =:periode_value + AND + b.`year` = :qyear + AND a.pip_state = {$params['type']} + )"; + } + + + $where = "t1.`year`=:qyear + and + t1.`month`=:qmonth + and + (t1.`ref_level_color_id`=1 or t1.`ref_level_color_id`=2 or t1.`ref_level_color_id`=0 ) + and + {$w_pip_state}"; + + $sql = "SELECT + $field + from + $table + where + $where"; + + return array("data" => $sql); + } + + function sqlGetAllAvailableLine() + { + $sql = `select * + from gedung_sector_line a + INNER JOIN gedung_sector b on a.gedung_sector_id = b.id + INNER JOIN gedung c on b.gedung_id = c.id + INNER JOIN ref_manufacture_sub_area d on c.sub_area_id = d.sub_area_id + INNER JOIN ref_manunfactures e on d.ref_manunfactures_id = e.id + INNER JOIN ref_manufacture_area f on e.id = f.ref_manunfactures_id + LEFT JOIN gmbs_business_unit g on a.id = g.gedung_sector_line_id;`; + return $sql; + } + + function sqlGetTotalPipN1($params) + { + $field = "COUNT(*) as total"; + + $table = "`kpi_final_result_month_acc` t1 + INNER JOIN emp_job t2 ON t1.nik = t2.nik AND t2.id = (SELECT id FROM emp_job WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t3 ON t2.mpp_detail_id = t3.id + INNER JOIN org_layer t4 ON t3.org_layer_id = t4.id + INNER JOIN ndc_business_titles t5 ON t4.bt_id = t5.id + INNER JOIN division t6 ON t4.division_id = t6.id + INNER JOIN department t7 ON t4.department_id = t7.id + INNER JOIN emp_personal_sub_area t8 ON t8.nik = t1.nik AND t8.id = (SELECT id FROM emp_personal_sub_area WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN sub_area t9 ON t8.sub_area_id = t9.id + INNER JOIN employement t10 ON t10.nik = t1.nik + INNER JOIN kpi_ref_level_color t11 ON t1.ref_level_color_id = t11.id "; + + $w_pip_state = 't1.nik not in ( + SELECT + a.nik + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + )'; + + if ($params['type'] > 0) { + $w_pip_state = " t1.nik in ( + SELECT + a.nik + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + a.pip_state = {$params['type']} + )"; + } + + + $where = "t10.nik_atasan =:nik_atasan + and + :qyear=:qyear + and + :periode_value=:periode_value + and + :qmonth=:qmonth + and + (t1.`ref_level_color_id`=1 or t1.`ref_level_color_id`=2 or t1.`ref_level_color_id`=0 ) + and + {$w_pip_state}"; + + $sql = "SELECT + $field + from + $table + where + $where"; + + return array("data" => $sql); + } + + function sqlGetDetailRegistrasiPip($params) + { + $field = "t2.*, + t1.kpi_scale_id, + t1.value_type, + t1.value_category, + t1.is_allow_more_than_100, + t3.color"; + + $table = "employement_has_kpi_scale t1 + INNER JOIN kpi_final_result t2 ON t1.id = t2.employement_has_kpi_scale_id + INNER JOIN kpi_ref_level_color t3 ON t2.ref_level_color_id = t3.id "; + + $where = "t1.employement_nik = :nik + AND + t2.`month` = :month + AND + t2.`year` = :year + AND + t3.`id` IN (1,2)"; + + $sql = "SELECT + $field + from + $table + where + $where"; + + return array("data" => $sql); + } + + public function sqlSaveRegisterPip() + { + + $sqlGetLastPipLevelMonth = 'SELECT + t1.`month`, + t1.`year`, + t3.periode_value, + t2.pip_state + FROM + kpi_final_result_month_acc t1 + LEFT JOIN pip_register t2 ON t1.nik = t2.nik + LEFT JOIN pip_register_monthly_value t3 ON t2.id = t3.register_id AND t3.periode_value = t1.`month` AND t3.`year` = t1.`year` + WHERE + t1.nik = :nik + AND + t1.`year` = :year + GROUP BY t1.`month`,t1.`year` + ORDER BY t1.`month` ASC'; + + $sqlInsertPipRegister = 'INSERT INTO `pip_register` + ( + `register_date`, + `register_by`, + `nik`, + `pip_status`, + `pip_state`, + `pip_periode`, + `ta_status` + ) + VALUES + ( + :register_date, + :register_by, + :nik, + :pip_status, + :pip_state, + :pip_periode, + :ta_status + )'; + + $sqlUpdatePipRegister = 'UPDATE + `pip_register` + SET + pip_status =:pip_status + WHERE + id=:id'; + + $sqlInsertPipRegisterMonthlyValue = 'INSERT INTO `pip_register_monthly_value` + ( + `register_id`, + `year`, + `periode_value`, + `score` + ) + VALUES + ( + :register_id, + :year, + :periode_value, + :score)'; + + $sqlInsertPipProjectAssignment = 'INSERT INTO `pip_project_assignment` + ( + `project_title`, + `kpi_final_result_id`, + `register_id`, + `identification_problem`, + `improvement_initiative`, + `target_kpi_score`, + `note` + ) + VALUES + ( + :project_title, + :kpi_final_result_id, + :register_id, + :identification_problem, + :improvement_initiative, + :target_kpi_score, + :note)'; + + $sql['sqlGetLastPipLevelMonth'] = $sqlGetLastPipLevelMonth; + $sql['sqlInsertPipRegister'] = $sqlInsertPipRegister; + $sql['sqlInsertPipRegisterMonthlyValue'] = $sqlInsertPipRegisterMonthlyValue; + $sql['sqlInsertPipProjectAssignment'] = $sqlInsertPipProjectAssignment; + $sql['sqlUpdatePipRegister'] = $sqlUpdatePipRegister; + + return $sql; + } + + function sqlGetDetailRegistrasiPipSubmit($params) + { + $field = "t2.*, + t1.kpi_scale_id, + t1.value_type, + t1.value_category, + t1.is_allow_more_than_100, + t3.color, + t4.identification_problem, + t4.improvement_initiative, + t4.note, + Round(t4.target_kpi_score, 2) target_kpi_score, + t4.register_id, + t4.id as pip_project_assignment_id"; + + $table = "employement_has_kpi_scale t1 + INNER JOIN kpi_final_result t2 ON t1.id = t2.employement_has_kpi_scale_id + INNER JOIN kpi_ref_level_color t3 ON t2.ref_level_color_id = t3.id + INNER JOIN pip_project_assignment t4 ON t4.kpi_final_result_id = t2.id "; + + $where = "t1.employement_nik = :nik + AND + t2.`month` = :month + AND + t2.`year` = :year"; + + $sql = "SELECT + $field + from + $table + where + $where"; + + return array("data" => $sql); + } + + function sqlViewDataMonitoringPipN1($params) + { + $field = "t1.nik, + getEmpName(t1.nik) as emp_name, + t5.description as bt_name, + t6.description as division_name, + t7.description as department_name, + t9.description as sub_area_name, + getEmpName(t10.nik_atasan) as atasan_name, + t1.`id`, + t1.`year`, + t1.`month`, + t1.`score`, + t1.`ref_level_color_id`, + t11.color, + (SELECT + a.pip_state + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + b.periode_value =t1.`month` + AND + b.`year` = t1.`year` + AND + a.nik = t1.nik) as pip_state, + (SELECT + a.id + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + b.periode_value =t1.`month` + AND + b.`year` = t1.`year` + AND + a.nik = t1.nik) as pip_register_id"; + + $table = "`kpi_final_result_month_acc` t1 + INNER JOIN emp_job t2 ON t1.nik = t2.nik AND t2.id = (SELECT id FROM emp_job WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t3 ON t2.mpp_detail_id = t3.id + INNER JOIN org_layer t4 ON t3.org_layer_id = t4.id + INNER JOIN ndc_business_titles t5 ON t4.bt_id = t5.id + INNER JOIN division t6 ON t4.division_id = t6.id + INNER JOIN department t7 ON t4.department_id = t7.id + INNER JOIN emp_personal_sub_area t8 ON t8.nik = t1.nik AND t8.id = (SELECT id FROM emp_personal_sub_area WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN sub_area t9 ON t8.sub_area_id = t9.id + INNER JOIN employement t10 ON t10.nik = t1.nik + INNER JOIN kpi_ref_level_color t11 ON t1.ref_level_color_id = t11.id + INNER JOIN pip_register t12 ON t10.nik = t12.nik "; + + + $where = "(t1.`ref_level_color_id`=1 or t1.`ref_level_color_id`=2 or t1.`ref_level_color_id`=0 ) + AND + (SELECT + a.pip_state + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + b.periode_value =t1.`month` + AND + b.`year` = t1.`year` + AND + a.nik = t1.nik) is not null + AND + t12.pip_status = 'register' + AND + t10.nik_atasan = :nik_atasan"; + + $sql = "SELECT + $field + from + $table + where + $where + LIMIT {$params['offset']}, {$params['jumPage']}"; + + $total = "SELECT + count(*) as total + from + $table + where + $where"; + + return array("data" => $sql, "total" => $total); + } + + function sqlViewDataMonitoringPipTeam($params) + { + $field = "t1.nik, + getEmpName(t1.nik) as emp_name, + t5.description as bt_name, + t6.description as division_name, + t7.description as department_name, + t9.description as sub_area_name, + getEmpName(t1.nik_atasan) as atasan_name, + t12.pip_state, + t12.pip_status"; + + $table = "`employement` t1 + INNER JOIN emp_job t2 ON t1.nik = t2.nik AND t2.id = (SELECT id FROM emp_job WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t3 ON t2.mpp_detail_id = t3.id + INNER JOIN org_layer t4 ON t3.org_layer_id = t4.id + INNER JOIN ndc_business_titles t5 ON t4.bt_id = t5.id + INNER JOIN division t6 ON t4.division_id = t6.id + INNER JOIN department t7 ON t4.department_id = t7.id + INNER JOIN emp_personal_sub_area t8 ON t8.nik = t1.nik AND t8.id = (SELECT id FROM emp_personal_sub_area WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN sub_area t9 ON t8.sub_area_id = t9.id + INNER JOIN pip_register t12 ON t12.nik = t1.nik AND t12.id = (SELECT id FROM pip_register WHERE nik = t1.nik ORDER BY id DESC LIMIT 1)"; + + + $where = "t1.nik_atasan = :nik_atasan"; + + $sql = "SELECT + $field + from + $table + where + $where + LIMIT {$params['offset']}, {$params['jumPage']}"; + + $total = "SELECT + count(*) as total + from + $table + where + $where"; + + return array("data" => $sql, "total" => $total); + } + + function sqlGetHistoryPipEmp($params) + { + $sqlYear = "SELECT + t2.`year` + FROM + pip_register t1 + INNER JOIN pip_register_monthly_value t2 ON t1.id = t2.register_id + WHERE + t1.nik = :nik + GROUP BY t2.`year` + ORDER BY t2.`year` ASC"; + + $sqlMonth = "SELECT + t1.pip_state, + LPAD((t2.periode_value+1), 2, '0') as periode_value, + t2.score, + t1.pip_status + FROM + pip_register t1 + INNER JOIN pip_register_monthly_value t2 ON t1.id = t2.register_id + WHERE + t1.nik = :nik + AND + t2.`year` =:year + ORDER BY t2.periode_value ASC"; + + return array("sqlYear" => $sqlYear, "sqlMonth" => $sqlMonth); + } + + function sqlGetPipMonitoringMonthlyReport($params) + { + $field = "t2.nik_atasan, + getEmpName(t2.nik_atasan) as atasan_name, + t6.description as department_name"; + + $table = "pip_register t1 + INNER JOIN employement t2 ON t1.nik = t2.nik + INNER JOIN emp_job t3 ON t2.nik_atasan = t3.nik AND t3.id = (SELECT id FROM emp_job WHERE nik = t2.nik_atasan AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t4 ON t3.mpp_detail_id = t4.id + INNER JOIN org_layer t5 ON t4.org_layer_id = t5.id + INNER JOIN department t6 ON t5.department_id = t6.id"; + + + $where = ""; + + $sql = "SELECT + $field + from + $table + $where + ORDER BY + t2.nik_atasan ASC + LIMIT {$params['offset']}, {$params['jumPage']}"; + + $total = "SELECT + count(*) as total + from + $table + $where"; + + $sqlGetPipList = "SELECT + t2.nik, + getEmpName(t2.nik) as emp_name, + t6.description as business_titles_name, + t11.description AS kpi_name, + t7.project_title, + round(t7.target_kpi_score,2) as target_kpi_score + FROM + pip_register t1 + INNER JOIN employement t2 ON t1.nik = t2.nik + INNER JOIN emp_job t3 ON t2.nik_atasan = t3.nik AND t3.id = (SELECT id FROM emp_job WHERE nik = t2.nik_atasan AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t4 ON t3.mpp_detail_id = t4.id + INNER JOIN org_layer t5 ON t4.org_layer_id = t5.id + INNER JOIN ndc_business_titles t6 ON t5.bt_id = t6.id + INNER JOIN pip_project_assignment t7 ON t1.id = t7.register_id + INNER JOIN kpi_final_result t8 ON t7.kpi_final_result_id = t8.id + INNER JOIN employement_has_kpi_scale t9 ON t8.employement_has_kpi_scale_id = t9.id + INNER JOIN kpi_scale t10 ON t9.kpi_scale_id = t10.id + INNER JOIN master_kpi t11 ON t10.kpi_id = t11.id + WHERE + t2.nik_atasan = :nik_atasan + ORDER BY + t2.nik ASC"; + + return array( + "data" => $sql, + "total" => $total, + "pip_list" => $sqlGetPipList + ); + } + + function sqlViewDataListPipMonitoring($params) + { + $field = "t1.nik, + getEmpName(t1.nik) as emp_name, + t5.description as bt_name, + t6.description as division_name, + t7.description as department_name, + t9.description as sub_area_name, + getEmpName(t10.nik_atasan) as atasan_name, + t1.`id`, + t1.`year`, + t1.`month`, + t1.`score`, + t1.`ref_level_color_id`, + t11.color, + (SELECT + a.pip_state + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + a.id = t12.id) as pip_state, + (SELECT + a.id + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + a.id = t12.id) as pip_register_id, + t12.pip_status as status"; + + $table = "`kpi_final_result_month_acc` t1 + INNER JOIN emp_job t2 ON t1.nik = t2.nik AND t2.id = (SELECT id FROM emp_job WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t3 ON t2.mpp_detail_id = t3.id + INNER JOIN org_layer t4 ON t3.org_layer_id = t4.id + INNER JOIN ndc_business_titles t5 ON t4.bt_id = t5.id + INNER JOIN division t6 ON t4.division_id = t6.id + INNER JOIN department t7 ON t4.department_id = t7.id + INNER JOIN emp_personal_sub_area t8 ON t8.nik = t1.nik AND t8.id = (SELECT id FROM emp_personal_sub_area WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN sub_area t9 ON t8.sub_area_id = t9.id + INNER JOIN employement t10 ON t10.nik = t1.nik + INNER JOIN kpi_ref_level_color t11 ON t1.ref_level_color_id = t11.id + INNER JOIN pip_register t12 ON t10.nik = t12.nik AND t12.id = (SELECT id FROM pip_register WHERE nik = t10.nik ORDER BY id DESC LIMIT 1) "; + + + $where = "(t1.`ref_level_color_id`=1 or t1.`ref_level_color_id`=2 or t1.`ref_level_color_id`=0 ) + AND + (SELECT + a.pip_state + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + b.periode_value =t1.`month` + AND + b.`year` = t1.`year` + AND + a.nik = t1.nik) is not null"; + + $sql = "SELECT + $field + from + $table + where + $where + GROUP BY t1.nik + LIMIT {$params['offset']}, {$params['jumPage']}"; + + $total = "SELECT + count(*) as total + from + $table + where + $where + GROUP BY t1.nik"; + + return array("data" => $sql, "total" => $total); + } + + function sqlGetDataFormPipEvaluation($params) + { + $sqlInfoParticipant = "SELECT + t1.nik, + getEmpName(t1.nik) as emp_name, + t5.description as bt_name, + t6.description as division_name, + t7.description as department_name, + t9.description as sub_area_name, + getEmpName(t1.nik_atasan) as atasan_name + FROM + employement t1 + INNER JOIN emp_job t2 ON t1.nik = t2.nik AND t2.id = (SELECT id FROM emp_job WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t3 ON t2.mpp_detail_id = t3.id + INNER JOIN org_layer t4 ON t3.org_layer_id = t4.id + INNER JOIN ndc_business_titles t5 ON t4.bt_id = t5.id + INNER JOIN division t6 ON t4.division_id = t6.id + INNER JOIN department t7 ON t4.department_id = t7.id + INNER JOIN emp_personal_sub_area t8 ON t8.nik = t1.nik AND t8.id = (SELECT id FROM emp_personal_sub_area WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN sub_area t9 ON t8.sub_area_id = t9.id + WHERE + t1.nik = :nik"; + + + $sqlHistoriPip = "SELECT + t1.nik, + t1.pip_state, + t1.pip_status, + t2.periode_value, + t2.`year`, + round(t3.score,2) score, + t4.name as color_name, + t4.`level` as level_color, + t4.color, + (SELECT + b.color + FROM + kpi_final_result_month_acc a + LEFT JOIN kpi_ref_level_color b ON a.ref_level_color_id = b.id + WHERE + a.nik = t1.nik + AND + a.`month` = (t2.periode_value+1) + AND + a.`year` = t2.`year`) as color_after, + (SELECT + round(a.score,2) + FROM + kpi_final_result_month_acc a + LEFT JOIN kpi_ref_level_color b ON a.ref_level_color_id = b.id + WHERE + a.nik = t1.nik + AND + a.`month` = (t2.periode_value+1) + AND + a.`year` = t2.`year`) as score_after + FROM + pip_register t1 + INNER JOIN pip_register_monthly_value t2 ON t1.id = t2.register_id + LEFT JOIN kpi_final_result_month_acc t3 ON t3.nik = t1.nik AND t3.`month` = t2.periode_value AND t3.`year` = t2.`year` + LEFT JOIN kpi_ref_level_color t4 ON t3.ref_level_color_id = t4.id + WHERE + t1.nik = :nik + AND + t2.`year` =:year + AND + t2.periode_value <=:month + ORDER BY + t1.pip_state ASC, t2.periode_value ASC "; + + + + $sqlSummaryFinalResult = "SELECT + t3.id as pip_project_assignment_id, + t1.nik, + t1.pip_state, + t1.pip_status, + t2.periode_value, + t2.`year`, + t3.improvement_initiative, + t7.kpi as kpi_name, + t7.description as kpi_desc, + round(t4.ach,2) as ach_actual, + round(t4.result_quantitative,2) as actual, + t8.name as color_name, + t8.`level` as level_color, + t8.color, + round(t4.target,2) as target, + round((t4.result_quantitative - t4.target),2) as gap, + (SELECT + round(a.ach,2) + FROM + kpi_final_result a + LEFT JOIN kpi_ref_level_color b ON a.ref_level_color_id = b.id + WHERE + a.employement_has_kpi_scale_id = t4.employement_has_kpi_scale_id + AND + a.`month` = (t4.month+1) + AND + a.`year` = t4.`year`) as ach_after, + (SELECT + b.color + FROM + kpi_final_result a + LEFT JOIN kpi_ref_level_color b ON a.ref_level_color_id = b.id + WHERE + a.employement_has_kpi_scale_id = t4.employement_has_kpi_scale_id + AND + a.`month` = (t4.month+1) + AND + a.`year` = t4.`year`) as color_after + FROM + pip_register t1 + INNER JOIN pip_register_monthly_value t2 ON t1.id = t2.register_id + INNER JOIN pip_project_assignment t3 ON t3.register_id = t1.id + INNER JOIN kpi_final_result t4 ON t3.kpi_final_result_id = t4.id + INNER JOIN employement_has_kpi_scale t5 ON t4.employement_has_kpi_scale_id = t5.id + INNER JOIN kpi_scale t6 ON t5.kpi_scale_id = t6.id + INNER JOIN master_kpi t7 ON t6.kpi_id = t7.id + LEFT JOIN kpi_ref_level_color t8 ON t4.ref_level_color_id = t8.id + WHERE + t1.nik = :nik + AND + t2.`year` =:year + AND + t4.month =:month + ORDER BY + t1.pip_state"; + + $sqlStatusPIP = "SELECT + round(a.score,2) as score, + b.*, + if(b.id=1 OR b.id=2,'Failed', 'Success') as status_pip + FROM + kpi_final_result_month_acc a + LEFT JOIN kpi_ref_level_color b ON a.ref_level_color_id = b.id + WHERE + a.nik = :nik + AND + a.`month` = (:month + 1) + AND + a.`year` = :year"; + + + return array( + "sqlInfoParticipant" => $sqlInfoParticipant, + "sqlHistoriPip" => $sqlHistoriPip, + "sqlSummaryFinalResult" => $sqlSummaryFinalResult, + "sqlStatusPIP" => $sqlStatusPIP, + ); + } + + + function sqlViewDataListPipMonitoringServices($params) + { + $field = "t1.nik, + getEmpName(t1.nik) as emp_name, + t5.description as bt_name, + t6.description as division_name, + t7.description as department_name, + t9.description as sub_area_name, + getEmpName(t10.nik_atasan) as atasan_name, + t1.`id`, + t1.`year`, + t1.`month`, + t1.`score`, + t1.`ref_level_color_id`, + t11.color, + (SELECT + a.pip_state + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + a.id = t12.id) as pip_state, + (SELECT + a.id + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + a.id = t12.id) as pip_register_id, + t12.pip_status as status, + t13.pip_action"; + + $table = "`kpi_final_result_month_acc` t1 + INNER JOIN emp_job t2 ON t1.nik = t2.nik AND t2.id = (SELECT id FROM emp_job WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t3 ON t2.mpp_detail_id = t3.id + INNER JOIN org_layer t4 ON t3.org_layer_id = t4.id + INNER JOIN ndc_business_titles t5 ON t4.bt_id = t5.id + INNER JOIN division t6 ON t4.division_id = t6.id + INNER JOIN department t7 ON t4.department_id = t7.id + INNER JOIN emp_personal_sub_area t8 ON t8.nik = t1.nik AND t8.id = (SELECT id FROM emp_personal_sub_area WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN sub_area t9 ON t8.sub_area_id = t9.id + INNER JOIN employement t10 ON t10.nik = t1.nik + INNER JOIN kpi_ref_level_color t11 ON t1.ref_level_color_id = t11.id + INNER JOIN pip_register t12 ON t10.nik = t12.nik AND t12.id = (SELECT id FROM pip_register WHERE nik = t12.nik ORDER BY id DESC LIMIT 1) + LEFT JOIN pip_register_action t13 ON t12.id = t13.pip_register_id"; + + + $where = "(t1.`ref_level_color_id`=1 or t1.`ref_level_color_id`=2 or t1.`ref_level_color_id`=0 ) + AND + (SELECT + a.pip_state + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + b.periode_value =t1.`month` + AND + b.`year` = t1.`year` + AND + a.nik = t1.nik) is not null"; + + $sql = "SELECT + $field + from + $table + where + $where + GROUP BY t1.nik + LIMIT {$params['offset']}, {$params['jumPage']}"; + + $total = "SELECT + count(*) as total + from + $table + where + $where + GROUP BY t1.nik"; + + return array("data" => $sql, "total" => $total); + } + + function sqlViewDataListPipMonitoringAction($params) + { + $field = "t1.nik, + getEmpName(t1.nik) as emp_name, + t5.description as bt_name, + t6.description as division_name, + t7.description as department_name, + t9.description as sub_area_name, + getEmpName(t10.nik_atasan) as atasan_name, + t1.`id`, + t1.`year`, + t1.`month`, + t1.`score`, + t1.`ref_level_color_id`, + t11.color, + (SELECT + a.pip_state + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + b.periode_value =t1.`month` + AND + b.`year` = t1.`year` + AND + a.nik = t1.nik) as pip_state, + (SELECT + a.id + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + b.periode_value =t1.`month` + AND + b.`year` = t1.`year` + AND + a.nik = t1.nik) as pip_register_id, + t12.pip_status as status, + t13.pip_action, + t14.status as pip_action_status"; + + $table = "`kpi_final_result_month_acc` t1 + INNER JOIN emp_job t2 ON t1.nik = t2.nik AND t2.id = (SELECT id FROM emp_job WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t3 ON t2.mpp_detail_id = t3.id + INNER JOIN org_layer t4 ON t3.org_layer_id = t4.id + INNER JOIN ndc_business_titles t5 ON t4.bt_id = t5.id + INNER JOIN division t6 ON t4.division_id = t6.id + INNER JOIN department t7 ON t4.department_id = t7.id + INNER JOIN emp_personal_sub_area t8 ON t8.nik = t1.nik AND t8.id = (SELECT id FROM emp_personal_sub_area WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN sub_area t9 ON t8.sub_area_id = t9.id + INNER JOIN employement t10 ON t10.nik = t1.nik + INNER JOIN kpi_ref_level_color t11 ON t1.ref_level_color_id = t11.id + INNER JOIN pip_register t12 ON t10.nik = t12.nik AND t12.id = (SELECT id FROM pip_register WHERE nik = t12.nik ORDER BY id DESC LIMIT 1) + INNER JOIN pip_register_action t13 ON t12.id = t13.pip_register_id + INNER JOIN pip_register_action_status t14 ON t13.id = t14.pip_register_action_id "; + + + $where = "(t1.`ref_level_color_id`=1 or t1.`ref_level_color_id`=2 or t1.`ref_level_color_id`=0 ) + AND + (SELECT + a.pip_state + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + b.periode_value =t1.`month` + AND + b.`year` = t1.`year` + AND + a.nik = t1.nik) is not null"; + + $sql = "SELECT + $field + from + $table + where + $where + GROUP BY t1.nik + LIMIT {$params['offset']}, {$params['jumPage']}"; + + $total = "SELECT + count(*) as total + from + $table + where + $where + GROUP BY t1.nik"; + + return array("data" => $sql, "total" => $total); + } + + function sqlViewDataListPipMonitoringTa($params) + { + $field = "t1.nik, + getEmpName(t1.nik) as emp_name, + t5.description as bt_name, + t6.description as division_name, + t7.description as department_name, + t9.description as sub_area_name, + getEmpName(t10.nik_atasan) as atasan_name, + t1.`id`, + t1.`year`, + t1.`month`, + t1.`score`, + t1.`ref_level_color_id`, + t11.color, + (SELECT + a.pip_state + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + a.id = t12.id) as pip_state, + (SELECT + a.id + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + a.id = t12.id) as pip_register_id, + t12.ta_status as status, + t13.pip_action"; + + $table = "`kpi_final_result_month_acc` t1 + INNER JOIN emp_job t2 ON t1.nik = t2.nik AND t2.id = (SELECT id FROM emp_job WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t3 ON t2.mpp_detail_id = t3.id + INNER JOIN org_layer t4 ON t3.org_layer_id = t4.id + INNER JOIN ndc_business_titles t5 ON t4.bt_id = t5.id + INNER JOIN division t6 ON t4.division_id = t6.id + INNER JOIN department t7 ON t4.department_id = t7.id + INNER JOIN emp_personal_sub_area t8 ON t8.nik = t1.nik AND t8.id = (SELECT id FROM emp_personal_sub_area WHERE nik = t1.nik AND effective_date <= :date ORDER BY effective_date DESC LIMIT 1) + INNER JOIN sub_area t9 ON t8.sub_area_id = t9.id + INNER JOIN employement t10 ON t10.nik = t1.nik + INNER JOIN kpi_ref_level_color t11 ON t1.ref_level_color_id = t11.id + INNER JOIN pip_register t12 ON t10.nik = t12.nik AND t12.id = (SELECT id FROM pip_register WHERE nik = t12.nik ORDER BY id DESC LIMIT 1) + LEFT JOIN pip_register_action t13 ON t12.id = t13.pip_register_id"; + + + $where = "(t1.`ref_level_color_id`=1 or t1.`ref_level_color_id`=2 or t1.`ref_level_color_id`=0 ) + AND + (SELECT + a.pip_state + FROM + pip_register a + INNER JOIN pip_register_monthly_value b ON a.id = b.register_id + WHERE + b.periode_value =t1.`month` + AND + b.`year` = t1.`year` + AND + a.nik = t1.nik) is not null"; + + $sql = "SELECT + $field + from + $table + where + $where + GROUP BY t1.nik + LIMIT {$params['offset']}, {$params['jumPage']}"; + + $total = "SELECT + count(*) as total + from + $table + where + $where + GROUP BY t1.nik"; + + return array("data" => $sql, "total" => $total); + } + + public function setStatementGetIssues() + { + $sql = "SELECT c.id as gmb_asessor_result_id,a.note as issues, concat(bx.section_code,'-',bx.section_name) as section, + h.type_name as `type`, i.category_name as category, concat(d.employement_nik,' - ',getEmpName(d.employement_nik)) as assessor, + e.status,e.risk_level,t1.due_date,concat(e.pic,' - ',getEmpName(e.pic)) as pic,e.note,t1.feedback, + e.pic as pic_nik, getEmpName(e.pic) as pic_name,ix.file_location + FROM gmb_asessor_result_notes a + inner join gmb_event_sections b on a.gmb_event_sections_id=b.id + INNER JOIN gmb_question_section bx on b.gmb_question_section_id=bx.id + INNER JOIN gmb_asessor_result c on a.gmb_asessor_result_id=c.id + INNER JOIN gmb_event_asessor d on c.gmb_event_asessor_id=d.id + INNER JOIN gmb_answer_detail f on c.gmb_answer_detail_id=f.id + INNER JOIN gmb_questions g on f.gmb_questions_id=g.id + INNER JOIN gmb_question_types h on g.gmb_question_types_id=h.id + INNER JOIN gmb_question_category i on g.gmb_question_category_id=i.id + LEFT JOIN gmb_assesor_result_files ix on ix.gmb_asessor_result_id=c.id + LEFT JOIN gmb_asessor_result_status e on c.id=e.gmb_asessor_result_id + LEFT JOIN gmb_event_question_feedback t1 on e.gmb_asessor_result_id=t1.gmb_asessor_result_status_gmb_asessor_result_id + where b.gmb_events_id=:event_id"; + + return $this->registry->db->prepare($sql); + } + + public function setStatementGetStatus() + { + $sql = "SELECT gmb_asessor_result_id + FROM gmb_asessor_result_status a + where gmb_asessor_result_id=:id"; + + return $this->registry->db->prepare($sql); + } + + public function setStatementInsStatus() + { + $sql = "INSERT INTO gmb_asessor_result_status + (gmb_asessor_result_id,note,pic,risk_level,status) + values + (:gmb_asessor_result_id,:note,:pic,:risk_level,:status)"; + + return $this->registry->db->prepare($sql); + } + + public function setStatementUpdStatus() + { + $sql = "UPDATE gmb_asessor_result_status SET + note=:note, + pic=:pic, + risk_level=:risk_level, + status=:status + WHERE gmb_asessor_result_id=:gmb_asessor_result_id"; + + return $this->registry->db->prepare($sql); + } + + public function setStatementGetGeneralIssues() + { + $sql = "SELECT a.id,a.issues,a.file_address,a.status,a.risk_level,b.due_date,a.pic as pic_nik,getEmpName(a.pic) as pic_name,a.created_by,getEmpName(a.created_by) as created_by_name,a.created_date, + b.feedback + FROM gmb_event_issues a + LEFT JOIN gmb_event_issue_feedback b on a.id=b.gmb_event_issues_id + WHERE a.gmb_events_id=:event_id + ORDER BY a.id desc"; + + return $this->registry->db->prepare($sql); + } + + public function setStatementUpdDueDate() + { + $sql = "UPDATE gmb_event_issues SET + pic=:pic + WHERE id=:id"; + + return $this->registry->db->prepare($sql); + } + + public function setStatementGetResponCount() + { + $sql = "SELECT sum(total) as total from ( + SELECT count(b.gmb_event_issues_id) as total, 'general' as type + FROM gmb_event_issues a + INNER JOIN gmb_event_issue_feedback b on b.gmb_event_issues_id=a.id + LEFT JOIN gmb_issue_feedback_respond_read c on b.gmb_event_issues_id=c.issue_feedback_id + WHERE a.gmb_events_id=:id and b.feedback is not null and b.gmb_event_issues_id not in + (select b.issue_feedback_id from gmb_event_issue_feedback a + RIGHT JOIN gmb_issue_feedback_respond_read b on a.gmb_event_issues_id=b.issue_feedback_id + where a.gmb_events_id=:id + ) + UNION + SELECT count(b.gmb_asessor_result_status_gmb_asessor_result_id) as total, 'assessment' as type + FROM gmb_asessor_result_status a + INNER JOIN gmb_event_question_feedback b on b.gmb_asessor_result_status_gmb_asessor_result_id=a.gmb_asessor_result_id + INNER JOIN gmb_asessor_result t1 on a.gmb_asessor_result_id=t1.id + INNER JOIN gmb_event_questions t2 on t2.id=t1.gmb_event_questions_id + LEFT JOIN gmb_question_feedback_respond_read c on b.gmb_asessor_result_status_gmb_asessor_result_id=c.question_feedback_id + WHERE t2.gmb_events_id=:id and b.feedback is not null and b.gmb_asessor_result_status_gmb_asessor_result_id not in + (select b.question_feedback_id from gmb_event_question_feedback a + RIGHT JOIN gmb_question_feedback_respond_read b on a.gmb_asessor_result_status_gmb_asessor_result_id=b.question_feedback_id + where t2.gmb_events_id=:id + ) + ) as tab"; + + return $this->registry->db->prepare($sql); + } + + public function setStatementGetResponCountGeneralIssue() + { + $sql = "SELECT count(b.gmb_event_issues_id) as total + FROM gmb_event_issues a + INNER JOIN gmb_event_issue_feedback b on b.gmb_event_issues_id=a.id + LEFT JOIN gmb_issue_feedback_respond_read c on b.gmb_event_issues_id=c.issue_feedback_id + WHERE a.gmb_events_id=:id and b.feedback is not null and b.gmb_event_issues_id not in + (select b.issue_feedback_id from gmb_event_issue_feedback a + RIGHT JOIN gmb_issue_feedback_respond_read b on a.gmb_event_issues_id=b.issue_feedback_id + where a.gmb_events_id=:id + ) + "; + + return $this->registry->db->prepare($sql); + } + + public function setStatementGetResponCountIssue() + { + $sql = "SELECT count(b.gmb_asessor_result_status_gmb_asessor_result_id) as total + FROM gmb_asessor_result_status a + INNER JOIN gmb_event_question_feedback b on b.gmb_asessor_result_status_gmb_asessor_result_id=a.gmb_asessor_result_id + INNER JOIN gmb_asessor_result t1 on a.gmb_asessor_result_id=t1.id + INNER JOIN gmb_event_questions t2 on t2.id=t1.gmb_event_questions_id + LEFT JOIN gmb_question_feedback_respond_read c on b.gmb_asessor_result_status_gmb_asessor_result_id=c.question_feedback_id + WHERE t2.gmb_events_id=:id and b.feedback is not null and b.gmb_asessor_result_status_gmb_asessor_result_id not in + (select b.question_feedback_id from gmb_event_question_feedback a + RIGHT JOIN gmb_question_feedback_respond_read b on a.gmb_asessor_result_status_gmb_asessor_result_id=b.question_feedback_id + where t2.gmb_events_id=:id + ) + "; + + return $this->registry->db->prepare($sql); + } + + public function setStatementGetResponCountGenIssue() + { + $sql = "SELECT count(b.gmb_event_issues_id) as total + FROM gmb_event_issues a + INNER JOIN gmb_event_issue_feedback b on b.gmb_event_issues_id=a.id + LEFT JOIN gmb_issue_feedback_respond_read c on b.gmb_event_issues_id=c.issue_feedback_id + WHERE a.id=:id and b.feedback is not null and b.gmb_event_issues_id not in + (select b.issue_feedback_id from gmb_event_issue_feedback a + RIGHT JOIN gmb_issue_feedback_respond_read b on a.gmb_event_issues_id=b.issue_feedback_id + where a.id=:id + ) + "; + + return $this->registry->db->prepare($sql); + } + + public function setStatementGetResponCountAssIssue() + { + $sql = "SELECT count(b.gmb_asessor_result_status_gmb_asessor_result_id) as total + FROM gmb_asessor_result_status a + INNER JOIN gmb_event_question_feedback b on b.gmb_asessor_result_status_gmb_asessor_result_id=a.gmb_asessor_result_id + LEFT JOIN gmb_question_feedback_respond_read c on b.gmb_asessor_result_status_gmb_asessor_result_id=c.question_feedback_id + WHERE a.gmb_asessor_result_id=:id and b.feedback is not null and b.gmb_asessor_result_status_gmb_asessor_result_id not in + (select b.question_feedback_id from gmb_event_question_feedback a + RIGHT JOIN gmb_question_feedback_respond_read b on a.gmb_asessor_result_status_gmb_asessor_result_id=b.question_feedback_id + where a.gmb_asessor_result_id=:id + ) + "; + + return $this->registry->db->prepare($sql); + } + + public function setStatementCheckGenIssueRead() + { + $sql = "SELECT a.id + FROM gmb_issue_feedback_respond_read a + WHERE a.issue_feedback_id=:id and nik=:nik + "; + + return $this->registry->db->prepare($sql); + } + + public function setStatementCheckIssueRead() + { + $sql = "SELECT a.id + FROM gmb_question_feedback_respond_read a + WHERE a.question_feedback_id=:id and nik=:nik + "; + + return $this->registry->db->prepare($sql); + } + + public function setStatementInsGenIssueRead() + { + $sql = "INSERT INTO gmb_issue_feedback_respond_read (issue_feedback_id,nik) values (:id,:nik)"; + + return $this->registry->db->prepare($sql); + } + + public function setStatementInsIssueRead() + { + $sql = "INSERT INTO gmb_question_feedback_respond_read (question_feedback_id,nik) values (:id,:nik)"; + + return $this->registry->db->prepare($sql); + } +} diff --git a/admin/model/DbBuilderHelper.php b/admin/model/DbBuilderHelper.php new file mode 100755 index 0000000..192a9f1 --- /dev/null +++ b/admin/model/DbBuilderHelper.php @@ -0,0 +1,432 @@ +registry->db->prepare($sql); + + for ($i = 0; $i < $ctr; $i++) { + $bind = isset($column[$i]['bind']) ? $column[$i]['bind'] : PDO::PARAM_STR; + $cKey = $column[$i]['key']; + $stmt->bindValue(":$cKey", $column[$i]['val'], $bind); + } + + for ($i = 0; $i < $ctrWhere; $i++) { + $bind = isset($where[$i]['bind']) ? $where[$i]['bind'] : PDO::PARAM_STR; + $wKey = $where[$i]['key']; + $stmt->bindValue(":$wKey", $where[$i]['val'], $bind); + } + + $this->checkDebugMode($stmt); + + $stmt->execute(); + + return true; + } catch (PDOException $e) { + $this->registry + ->log + ->error('CompleteRegisterHelper / action : dbBuilderUpdate : ' + . $e->getMessage() . ', Line: ' + . $e->getLine()); + return false; + } catch (ErrorException $e) { + $this->registry + ->log + ->error('CompleteRegisterHelper / action : dbBuilderUpdate : ' + . $e->getMessage() . ', Line: ' + . $e->getLine()); + return false; + } + } + + + public function dbBuilderInsert($table, $column = [], $insertId = false) + { + + try { + + $sql = "INSERT INTO $table "; + $ctr = count($column); + $columnKey = ''; + $binderKey = ''; + + for ($i = 0; $i < $ctr; $i++) { + $cKey = $column[$i]['key']; + $next = $i + 1; + + if ($i === 0) { + $columnKey .= '('; + $binderKey .= '('; + } + + $columnKey .= "`$cKey`"; + $binderKey .= ":$cKey"; + + if ($next < $ctr) { + $columnKey .= ', '; + $binderKey .= ', '; + } + + if ($next === $ctr) { + $columnKey .= ')'; + $binderKey .= ')'; + } + } + + $sql .= "$columnKey VALUES $binderKey"; + $stmt = $this->registry->db->prepare($sql); + + for ($i = 0; $i < $ctr; $i++) { + $bind = isset($column[$i]['bind']) ? $column[$i]['bind'] : PDO::PARAM_STR; + $cKey = $column[$i]['key']; + $stmt->bindValue(":$cKey", $column[$i]['val'], $bind); + } + + $this->checkDebugMode($stmt); + + $stmt->execute(); + + if ($insertId) { + return $this->registry->db->lastInsertId(); + } + + return true; + } catch (PDOException $e) { + $this->registry + ->log + ->error('CompleteRegisterHelper / action : dbBuilderInsert : ' + . $e->getMessage() . ', Line: ' + . $e->getLine()); + return false; + } catch (ErrorException $e) { + $this->registry + ->log + ->error('CompleteRegisterHelper / action : dbBuilderInsert : ' + . $e->getMessage() . ', Line: ' + . $e->getLine()); + return false; + } + } + + public function dbBuilderDelete($table, $columnWhere, $id, $bind = PDO::PARAM_INT) + { + try { + + $sql = "DELETE FROM $table WHERE $columnWhere = :id"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindValue(':id', $id, $bind); + + $this->checkDebugMode($stmt); + + $stmt->execute(); + + return true; + } catch (PDOException $e) { + $this->registry + ->log + ->error('CompleteRegisterHelper / action : dbBuilderDelete : ' + . $e->getMessage() . ', Line: ' + . $e->getLine()); + return false; + } catch (ErrorException $e) { + $this->registry + ->log + ->error('CompleteRegisterHelper / action : dbBuilderDelete : ' + . $e->getMessage() . ', Line: ' + . $e->getLine()); + return false; + } + } + + public function dbBuilderDeleteMultiWhere($table, $where = []) + { + try { + + $sql = "DELETE FROM $table WHERE [[rw]] "; + $stmt = $this->registry->db->prepare($sql); + + $ctrWhere = count($where); + $whereColumn = ''; + for ($i = 0; $i < $ctrWhere; $i++) { + $exp = isset($where[$i]['exp']) ? $where[$i]['exp'] : ' AND '; + $opr = isset($where[$i]['opr']) ? $where[$i]['opr'] : ' = '; + + $wKey = $where[$i]['key']; + if ($i == 0) { + $whereColumn .= "`$wKey` $opr :$wKey"; + continue; + } + $whereColumn .= "$exp `$wKey` $opr :$wKey"; + } + + $sql = str_replace('[[rw]]', $whereColumn, $sql); + $stmt = $this->registry->db->prepare($sql); + for ($i = 0; $i < $ctrWhere; $i++) { + $bind = isset($where[$i]['bind']) ? $where[$i]['bind'] : PDO::PARAM_INT; + $wKey = $where[$i]['key']; + $stmt->bindValue(":$wKey", $where[$i]['val'], $bind); + } + + $this->checkDebugMode($stmt); + + $stmt->execute(); + + return true; + } catch (PDOException $e) { + $this->registry + ->log + ->error('CompleteRegisterHelper / action : dbBuilderDeleteMultiWhere : ' + . $e->getMessage() . ', Line: ' + . $e->getLine()); + return false; + } catch (ErrorException $e) { + $this->registry + ->log + ->error('CompleteRegisterHelper / action : dbBuilderDeleteMultiWhere : ' + . $e->getMessage() . ', Line: ' + . $e->getLine()); + return false; + } + } + + public function dbBuilderSelect($table, $column = ['*'], $where = []) + { + try { + $sql = "SELECT [[rc]] FROM $table WHERE [[rw]]"; + + $ctrColumn = count($column); + $keyColumn = ''; + for ($i = 0; $i < $ctrColumn; $i++) { + $cKey = $column[$i]; + $next = $i + 1; + $keyColumn .= $cKey === '*' ? $cKey : "`$cKey`"; + if ($next < $ctrColumn) { + $keyColumn .= ', '; + } + } + + $sql = str_replace('[[rc]]', $keyColumn, $sql); + + $ctrWhere = count($where); + $whereColumn = ''; + for ($i = 0; $i < $ctrWhere; $i++) { + $exp = isset($where[$i]['exp']) ? $where[$i]['exp'] : ' AND '; + $opr = isset($where[$i]['opr']) ? $where[$i]['opr'] : ' = '; + $wKey = $where[$i]['key']; + if ($i == 0) { + $whereColumn .= "`$wKey` $opr :$wKey"; + continue; + } + $whereColumn .= "$exp `$wKey` $opr :$wKey"; + } + + if (count($where) === 0) { + $sql = str_replace('WHERE', '', $sql); + } + + $sql = str_replace('[[rw]]', $whereColumn, $sql); + + $stmt = $this->registry->db->prepare($sql); + for ($i = 0; $i < $ctrWhere; $i++) { + $bind = isset($where[$i]['bind']) ? $where[$i]['bind'] : PDO::PARAM_STR; + $wKey = $where[$i]['key']; + $stmt->bindValue(":$wKey", $where[$i]['val'], $bind); + } + + $this->checkDebugMode($stmt); + + $stmt->execute(); + + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOexception $e) { + $this->registry + ->log + ->error('CompleteRegisterHelper / action : dbBuilderSelect : ' + . $e->getMessage() . ', Line: ' + . $e->getLine()); + return array(); + } catch (ErrorException $e) { + $this->registry + ->log + ->error('CompleteRegisterHelper / action : dbBuilderSelect : ' + . $e->getMessage() . ', Line: ' + . $e->getLine()); + return array(); + } + } + + private function checkDebugMode($stmt) + { + if ($this->enabledDebugMode) { + $stmt->debugDumpParams(); + die(); + } + } + + public function dbBuilderSelectJoin($table, $column = ['*'], $where = [],$order="") + { + try { + $sql = "SELECT [[rc]] FROM $table WHERE [[rw]] $order"; + + + + $ctrColumn = count($column); + $keyColumn = ''; + for ($i = 0; $i < $ctrColumn; $i++) { + $cKey = $column[$i]; + $next = $i + 1; + $keyColumn .= $cKey === '*' ? $cKey : "$cKey"; + if ($next < $ctrColumn) { + $keyColumn .= ', '; + } + } + + $sql = str_replace('[[rc]]', $keyColumn, $sql); + + $ctrWhere = count($where); + $whereColumn = ''; + for ($i = 0; $i < $ctrWhere; $i++) { + $startSymbol = isset($where[$i]['start_symbol']) ? $where[$i]['start_symbol'] : ''; + $endSymbol = isset($where[$i]['end_symbol']) ? $where[$i]['end_symbol'] : ''; + $exp = isset($where[$i]['exp']) ? $where[$i]['exp'] : ' AND '; + $opr = isset($where[$i]['opr']) ? $where[$i]['opr'] : ' = '; + $wField = isset($where[$i]['field'])?$where[$i]['field']:$where[$i]['key']; + $wVal = isset($where[$i]['val'])?$where[$i]['val']:''; + $wKey = isset($where[$i]['key'])?$where[$i]['key']:''; + if ($i == 0) { + if($wKey == ''){ + $whereColumn .= "$startSymbol :$wField $opr '$wVal' $endSymbol"; + }else{ + if($opr == 'in'){ + $whereColumn .= "$startSymbol $wKey $opr ('". implode("','", $wVal) . "') $endSymbol"; + }else if($opr == 'IS NULL'){ + $whereColumn .= "$wKey $opr"; + }else if($opr == 'between'){ + $start = isset($where[$i]['start'])?$where[$i]['start']:''; + $end = isset($where[$i]['end'])?$where[$i]['end']:''; + + $whereColumn .= "$wKey $opr '".$start."' AND '".$end."'"; + }else{ + $whereColumn .= "$startSymbol $wKey $opr :$wField $endSymbol"; + } + } + continue; + } + + if($wKey == ''){ + $whereColumn .= " $exp $startSymbol :$wField $opr '$wVal' $endSymbol"; + }else{ + if($opr == 'in'){ + $whereColumn .= " $exp $startSymbol $wKey $opr ('". implode("','", $wVal) . "') $endSymbol"; + }else if($opr == 'IS NULL'){ + $whereColumn .= "$exp $wKey $opr"; + }else if($opr == 'between'){ + $start = isset($where[$i]['start'])?$where[$i]['start']:''; + $end = isset($where[$i]['end'])?$where[$i]['end']:''; + + $whereColumn .= "$exp $wKey $opr '".$start."' AND '".$end."'"; + }else{ + $whereColumn .= " $exp $startSymbol $wKey $opr :$wField $endSymbol"; + } + } + + } + + + if (count($where) === 0) { + $sql = str_replace('WHERE', '', $sql); + } + + $sql = str_replace('[[rw]]', $whereColumn, $sql); + + $stmt = $this->registry->db->prepare($sql); + + for ($i = 0; $i < $ctrWhere; $i++) { + $bind = isset($where[$i]['bind']) ? $where[$i]['bind'] : PDO::PARAM_STR; + $wField = isset($where[$i]['field'])?$where[$i]['field']:$where[$i]['key']; + $opr = isset($where[$i]['opr']) ? $where[$i]['opr'] : ' = '; + $wKey = isset($where[$i]['key'])?$where[$i]['key']:''; + if($wKey != ''){ + if($opr == 'LIKE'){ + $stmt->bindValue(":$wField", '%'.$where[$i]['val'].'%', $bind); + }else if($opr == 'in'){ + }else if($opr == 'IS NULL'){ + }else if($opr == 'between'){ + }else{ + $stmt->bindValue(":$wField", $where[$i]['val'], $bind); + } + } + + + + } + + // var_dump($stmt); + // die(); + + $this->checkDebugMode($stmt); + + $stmt->execute(); + + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOexception $e) { + $this->registry + ->log + ->error('CompleteRegisterHelper / action : dbBuilderSelect : ' + . $e->getMessage() . ', Line: ' + . $e->getLine().' , table : ' + .$table ); + return array(); + } catch (ErrorException $e) { + $this->registry + ->log + ->error('CompleteRegisterHelper / action : dbBuilderSelect : ' + . $e->getMessage() . ', Line: ' + . $e->getLine().' , table : ' + .$table); + return array(); + } + } + +} diff --git a/admin/model/Upload.php b/admin/model/Upload.php new file mode 100755 index 0000000..8ad1c66 --- /dev/null +++ b/admin/model/Upload.php @@ -0,0 +1,751 @@ +saveFile($file); + $objWorkSheet = $this->getWorkSheet($filename['newfilename'], 0); + + $data = $this->getDataQuestionUpload($objWorkSheet); + + return $this->saveDataQuestionList($data); + } + + private function getWorkSheet($fileName, $sheetIndex) + { + $objPHPExcel = new PHPExcel(); + $inputFileType = \PHPExcel_IOFactory::identify($fileName); + $objReader = \PHPExcel_IOFactory::createReader($inputFileType); + $objReader->setReadDataOnly(true); + $objPHPExcel = $objReader->load($fileName); + $total_sheets = $objPHPExcel->getSheetCount(); + $objWorkSheet = $objPHPExcel->setActiveSheetIndex($sheetIndex); + return $objWorkSheet; + } + + private function saveFile($file) + { + $filename = $file->getClientOriginalName(); + $mimeType = $file->getClientMimeType(); + $fileExtension = $file->guessExtension(); + $mimeClientAlowed = array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel'); + if (!in_array($mimeType, $mimeClientAlowed)) { + throw new Exception('error file type'); + } + $targetPath = $this->registry->config->base_storage. '/uploadfile/gemba_question/'; + $targetFile = str_replace('//', '/', $targetPath); + $obj11 = $file->move($targetFile, $filename); + $newfilename = $targetFile . $filename; + return array('filename' => $filename, 'newfilename' => $newfilename); + } + + public function getDataQuestionUpload($objWorkSheet) + { + $startRow = 3; + $endRow = $objWorkSheet->getHighestRow(); + $kodeSoalCol = $this->getColomIndex('A'); + $areaCol = $this->getColomIndex('B'); + $soalCol = $this->getColomIndex('C'); + $detailSoalCol = $this->getColomIndex('D'); + $kodeTypeSoalCol = $this->getColomIndex('E'); + $idCategoryCol = $this->getColomIndex('F'); + $sectionIdCol = $this->getColomIndex('G'); + $jumlahJawabanCol = $this->getColomIndex('H'); + $itemJawabanCol = $this->getColomIndex('I'); + $scoreJawabanCol = $this->getColomIndex('J'); + $groupQuestionCol = $this->getColomIndex('K'); + + $data = array(); + + for ($i = $startRow; $i <= $endRow; $i++) { + $item = array(); + $kodeSoal = $objWorkSheet->getCellByColumnAndRow($kodeSoalCol, $i)->getFormattedValue(); + $area = $objWorkSheet->getCellByColumnAndRow($areaCol, $i)->getFormattedValue(); + $soal = $objWorkSheet->getCellByColumnAndRow($soalCol, $i)->getFormattedValue(); + $detailSoal = $objWorkSheet->getCellByColumnAndRow($detailSoalCol, $i)->getFormattedValue(); + $kodeTypeSoal = $objWorkSheet->getCellByColumnAndRow($kodeTypeSoalCol, $i)->getFormattedValue(); + $idCategory = $objWorkSheet->getCellByColumnAndRow($idCategoryCol, $i)->getFormattedValue(); + $sectionId = $objWorkSheet->getCellByColumnAndRow($sectionIdCol, $i)->getFormattedValue(); + $jumlahJawaban = $objWorkSheet->getCellByColumnAndRow($jumlahJawabanCol, $i)->getFormattedValue(); + $itemJawaban = $objWorkSheet->getCellByColumnAndRow($itemJawabanCol, $i)->getFormattedValue(); + $scoreJawaban = $objWorkSheet->getCellByColumnAndRow($scoreJawabanCol, $i)->getFormattedValue(); + + if ($kodeSoal) { + $item['kode_soal'] = $kodeSoal; + $item['area'] = $area; + $item['soal'] = $soal; + $item['detail_soal'] = $detailSoal; + $item['kode_type_soal'] = $kodeTypeSoal; + $item['id_category'] = $idCategory; + $item['section_id'] = $sectionId; + $item['jumlah_jawaban'] = $jumlahJawaban; + $item['item_jawaban'] = $itemJawaban; + $item['score_jawaban'] = $scoreJawaban; + array_push($data, $item); + } + } + + $data_soal = $this->unique_att_rev($data, false, 'kode_soal'); + + foreach ($data_soal as $key => $value) { + $data_soal[$key]['detail'] = array_filter($data, function ($var) use ($value) { + return ($var['kode_soal'] == $value['kode_soal']); + }); + } + + return $data_soal; + } + + private function getColomIndex($col) + { + $idx = \PHPExcel_Cell::columnIndexFromString($col); + return $idx - 1; + } + + public function unique_att_rev($array, $keep_key_assoc = false, $keys) + { + $duplicate_keys = array(); + $tmp = array(); + + foreach ($array as $key => $val) { + if (!in_array($val[$keys], $tmp)) + $tmp[] = $val[$keys]; + else + $duplicate_keys[] = $key; + } + + foreach ($duplicate_keys as $key) + unset($array[$key]); + + return $keep_key_assoc ? $array : array_values($array); + } + + public function saveDataQuestionList($data,$upload=false) + { + try { + if(!$upload){ + $this->registry->db->beginTransaction(); + } + + // var_dump($data);die(); + + // $item['kode_soal'] = $kodeSoal; + // $item['area'] = $area; + // $item['soal'] = $soal; + // $item['detail_soal'] = $detailSoal; + // $item['kode_type_soal'] = $kodeTypeSoal; + // $item['id_category'] = $idCategory; + // $item['section_id'] = $sectionId; + // $item['jumlah_jawaban'] = $jumlahJawaban; + // $item['item_jawaban'] = $itemJawaban; + // $item['score_jawaban'] = $scoreJawaban; + + + foreach ($data as $i => $q) { + + $type=$this->dbBuilderSelectJoin('gmb_question_types t1', + [ + 't1.*' + ], + [ + ['field' => 'code_type','key' => 't1.code_type', 'val' => $q['kode_type_soal'], 'bind' => PDO::PARAM_STR], + ] + ); + + $this->registry->log->error($q['kode_type_soal'].' '.$i.' '.$q['kode_soal']); + + $question = $this->dbBuilderInsert('gmb_questions', [ + ['key' => 'question_code', 'val' => $q['kode_soal'], 'bind' => PDO::PARAM_STR], + ['key' => 'question', 'val' => $q['soal'], 'bind' => PDO::PARAM_STR], + ['key' => 'question_description', 'val' => $q['soal'], 'bind' => PDO::PARAM_STR], + ['key' => 'jum_answer', 'val' => $q['jumlah_jawaban'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_types_id', 'val' => $type[0]['id'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_section_id', 'val' => $q['section_id'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_category_id', 'val' => $q['id_category'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_group_id', 'val' => '1', 'bind' => PDO::PARAM_STR], + ], + true); + + if (!$question) { + return false; + } + + foreach ($q['detail'] as $j => $item) { + if($item['detail_soal'] != '' && $item['detail_soal']){ + $question_item = $this->dbBuilderInsert('gmb_qustion_items', [ + ['key' => 'item_name', 'val' => $item['detail_soal'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_questions_id', 'val' => $question, 'bind' => PDO::PARAM_STR], + ], + true); + + if (!$question_item) { + return false; + } + } + } + $order=1; + foreach ($q['detail'] as $j => $answer) { + if($answer['item_jawaban'] != '' && $answer['item_jawaban']){ + $gmb_answer_detail = $this->dbBuilderInsert('gmb_answer_detail', [ + ['key' => 'answer_score', 'val' => $answer['score_jawaban'], 'bind' => PDO::PARAM_STR], + ['key' => 'answer_label', 'val' => $answer['item_jawaban'], 'bind' => PDO::PARAM_STR], + ['key' => 'order', 'val' => $order, 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_questions_id', 'val' => $question, 'bind' => PDO::PARAM_STR], + ], + true); + + if (!$gmb_answer_detail) { + return false; + } + $order++; + } + } + } + + // return false; + + if(!$upload){ + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + }else{ + return true; + } + + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveEventGemba: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveEventGemba: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function importDataActivities($file) + { + $filename = $this->saveFile($file); + $objWorkSheet = $this->getWorkSheet($filename['newfilename'], 0); + + $data = $this->getDataActivitiesUpload($objWorkSheet); + + // var_dump($data); + // die(); + + return $this->saveDataActivitiesList($data); + } + + public function getDataActivitiesUpload($objWorkSheet) + { + $startRow = 2; + $endRow = $objWorkSheet->getHighestRow(); + $endColumn = $objWorkSheet->getHighestColumn(); + + if ($endColumn == 'N') { + $idCol = $this->getColomIndex('A'); + $businessUnitIdCol = $this->getColomIndex('B'); + $refWorkScopeIdCol = $this->getColomIndex('C'); + $sectionIdCol = $this->getColomIndex('D'); + $departmentIdCol = $this->getColomIndex('E'); + $activitiesCol = $this->getColomIndex('F'); + $yesScoreCol = $this->getColomIndex('G'); + $noScoreCol = $this->getColomIndex('H'); + $yesNoteCol = $this->getColomIndex('I'); + $noNoteCol = $this->getColomIndex('J'); + $orderNoCol = $this->getColomIndex('K'); + $categoryIdCol = $this->getColomIndex('L'); + $riskLevelIdCol = $this->getColomIndex('M'); + $linkReveranceCol = $this->getColomIndex('N'); + + $data = array(); + + for ($i = $startRow; $i <= $endRow; $i++) { + $item = array(); + $id = $objWorkSheet->getCellByColumnAndRow($idCol, $i)->getFormattedValue(); + $businessUnitId = $objWorkSheet->getCellByColumnAndRow($businessUnitIdCol, $i)->getFormattedValue(); + $refWorkScopeId = $objWorkSheet->getCellByColumnAndRow($refWorkScopeIdCol, $i)->getFormattedValue(); + $sectionId = $objWorkSheet->getCellByColumnAndRow($sectionIdCol, $i)->getFormattedValue(); + $departmentId = $objWorkSheet->getCellByColumnAndRow($departmentIdCol, $i)->getFormattedValue(); + $activities = $objWorkSheet->getCellByColumnAndRow($activitiesCol, $i)->getFormattedValue(); + $yesScore = $objWorkSheet->getCellByColumnAndRow($yesScoreCol, $i)->getFormattedValue(); + $noScore = $objWorkSheet->getCellByColumnAndRow($noScoreCol, $i)->getFormattedValue(); + $categoryId = $objWorkSheet->getCellByColumnAndRow($categoryIdCol, $i)->getFormattedValue(); + $riskLevelId = $objWorkSheet->getCellByColumnAndRow($riskLevelIdCol, $i)->getFormattedValue(); + $orderNo = $objWorkSheet->getCellByColumnAndRow($orderNoCol, $i)->getFormattedValue(); + $yesRequired = $objWorkSheet->getCellByColumnAndRow($yesNoteCol, $i)->getFormattedValue(); + $noRequired = $objWorkSheet->getCellByColumnAndRow($noNoteCol, $i)->getFormattedValue(); + $linkReverance = $objWorkSheet->getCellByColumnAndRow($linkReveranceCol, $i)->getFormattedValue(); + + if ($businessUnitId) { + $item['id'] = $id; + $item['description'] = $activities; + $item['gmbs_question_category_id'] = $categoryId; + $item['gmbs_question_section_id'] = $sectionId; + $item['gmbs_ref_risk_level_id'] = $riskLevelId; + $item['gmbs_ref_work_scopes_id'] = $refWorkScopeId; + $item['score_yes'] = $yesScore; + $item['score_no'] = $noScore; + $item['order_no'] = $orderNo; + $item['yes_required_note'] = $yesRequired; + $item['no_required_note'] = $noRequired; + $item['reference_link'] = $linkReverance; + array_push($data, $item); + } + } + } else { + $businessUnitIdCol = $this->getColomIndex('A'); + $refWorkScopeIdCol = $this->getColomIndex('B'); + $sectionIdCol = $this->getColomIndex('C'); + $departmentIdCol = $this->getColomIndex('D'); + $activitiesCol = $this->getColomIndex('E'); + $yesScoreCol = $this->getColomIndex('F'); + $noScoreCol = $this->getColomIndex('G'); + $yesNoteCol = $this->getColomIndex('H'); + $noNoteCol = $this->getColomIndex('I'); + $orderNoCol = $this->getColomIndex('J'); + $categoryIdCol = $this->getColomIndex('K'); + $riskLevelIdCol = $this->getColomIndex('L'); + $linkReveranceCol = $this->getColomIndex('M'); + + $data = array(); + + for ($i = $startRow; $i <= $endRow; $i++) { + $item = array(); + $businessUnitId = $objWorkSheet->getCellByColumnAndRow($businessUnitIdCol, $i)->getFormattedValue(); + $refWorkScopeId = $objWorkSheet->getCellByColumnAndRow($refWorkScopeIdCol, $i)->getFormattedValue(); + $sectionId = $objWorkSheet->getCellByColumnAndRow($sectionIdCol, $i)->getFormattedValue(); + $departmentId = $objWorkSheet->getCellByColumnAndRow($departmentIdCol, $i)->getFormattedValue(); + $activities = $objWorkSheet->getCellByColumnAndRow($activitiesCol, $i)->getFormattedValue(); + $yesScore = $objWorkSheet->getCellByColumnAndRow($yesScoreCol, $i)->getFormattedValue(); + $noScore = $objWorkSheet->getCellByColumnAndRow($noScoreCol, $i)->getFormattedValue(); + $categoryId = $objWorkSheet->getCellByColumnAndRow($categoryIdCol, $i)->getFormattedValue(); + $riskLevelId = $objWorkSheet->getCellByColumnAndRow($riskLevelIdCol, $i)->getFormattedValue(); + $orderNo = $objWorkSheet->getCellByColumnAndRow($orderNoCol, $i)->getFormattedValue(); + $yesRequired = $objWorkSheet->getCellByColumnAndRow($yesNoteCol, $i)->getFormattedValue(); + $noRequired = $objWorkSheet->getCellByColumnAndRow($noNoteCol, $i)->getFormattedValue(); + $linkReverance = $objWorkSheet->getCellByColumnAndRow($linkReveranceCol, $i)->getFormattedValue(); + + if ($businessUnitId) { + $item['description'] = $activities; + $item['gmbs_question_category_id'] = $categoryId; + $item['gmbs_question_section_id'] = $sectionId; + $item['gmbs_ref_risk_level_id'] = $riskLevelId; + $item['gmbs_ref_work_scopes_id'] = $refWorkScopeId; + $item['score_yes'] = $yesScore; + $item['score_no'] = $noScore; + $item['order_no'] = $orderNo; + $item['yes_required_note'] = $yesRequired; + $item['no_required_note'] = $noRequired; + $item['reference_link'] = $linkReverance; + array_push($data, $item); + } + } + } + + return $data; + } + + public function saveDataActivitiesList($data,$upload=false) + { + try { + if(!$upload){ + $this->registry->db->beginTransaction(); + } + + $error=0; + $error_message=[]; + + // $result = array(); + // foreach ($data as $key => $value){ + // $filterArr = array_filter($result, function ($var) use ($value) { + // return $var['gmbs_question_category_id'] == $value['gmbs_question_category_id'] && $var['gmbs_question_section_id'] == $value['gmbs_question_section_id'] && $var['description'] == $value['description']; + // }); + + // if (!$filterArr) { + // $result[] = $value; + // } + // } + + foreach ($data as $i => $q) { + + if (isset($q['id']) && $q['id']) { + $master_update = $this->dbBuilderUpdate('gmbs_activities', + [ + ['key' => 'order_no', 'val' => $q['order_no'], 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $q['description'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_question_category_id', 'val' => $q['gmbs_question_category_id'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_question_section_id', 'val' => $q['gmbs_question_section_id'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_risk_level_id', 'val' => $q['gmbs_ref_risk_level_id'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_work_scopes_id', 'val' => $q['gmbs_ref_work_scopes_id'], 'bind' => PDO::PARAM_STR], + ['key' => 'reference_link', 'val' => $q['reference_link'], 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $q['id'], 'bind' => PDO::PARAM_INT], + ]); + + if (!$master_update) { + return false; + } + + $this->dbBuilderDelete('gmbs_answer_detail', 'gmbs_activities_id', $q['id']); + + $question_item = $this->dbBuilderInsert('gmbs_answer_detail', [ + ['key' => 'answer_score', 'val' => $q['score_yes'], 'bind' => PDO::PARAM_STR], + ['key' => 'answer_label', 'val' => 'YES', 'bind' => PDO::PARAM_STR], + ['key' => 'order', 'val' => 1, 'bind' => PDO::PARAM_STR], + ['key' => 'qualitative_answer', 'val' => 'Standar', 'bind' => PDO::PARAM_STR], + ['key' => 'is_require_note', 'val' => $q['yes_required_note'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_activities_id', 'val' => $q['id'], 'bind' => PDO::PARAM_STR], + ], + true); + + if (!$question_item) { + return false; + } + + $question_item = $this->dbBuilderInsert('gmbs_answer_detail', [ + ['key' => 'answer_score', 'val' => $q['score_no'], 'bind' => PDO::PARAM_STR], + ['key' => 'answer_label', 'val' => 'NO', 'bind' => PDO::PARAM_STR], + ['key' => 'order', 'val' => 2, 'bind' => PDO::PARAM_STR], + ['key' => 'qualitative_answer', 'val' => 'Tidak Standar', 'bind' => PDO::PARAM_STR], + ['key' => 'is_require_note', 'val' => $q['no_required_note'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_activities_id', 'val' => $q['id'], 'bind' => PDO::PARAM_STR], + ], + true); + + if (!$question_item) { + return false; + } + } else { + $question = $this->dbBuilderInsert('gmbs_activities', [ + ['key' => 'order_no', 'val' => $q['order_no'], 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $q['description'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_question_category_id', 'val' => $q['gmbs_question_category_id'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_question_section_id', 'val' => $q['gmbs_question_section_id'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_risk_level_id', 'val' => $q['gmbs_ref_risk_level_id'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_work_scopes_id', 'val' => $q['gmbs_ref_work_scopes_id'], 'bind' => PDO::PARAM_STR], + ['key' => 'is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR], + ['key' => 'reference_link', 'val' => $q['reference_link'], 'bind' => PDO::PARAM_STR], + ], + true); + + if (!$question) { + $gmbs_question_category=$this->dbBuilderSelectJoin('gmbs_question_category t1', + [ + 't1.*' + ], + [ + ['field' => 'id','key' => 't1.id', 'val' => $q['gmbs_question_category_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + if(count($gmbs_question_category) == 0){ + array_push($error_message,array( + "note"=>"gmbs_question_category id ".$q['gmbs_question_category_id']." not found" + )); + $error++; + } + + $gmbs_question_section=$this->dbBuilderSelectJoin('gmbs_question_section t1', + [ + 't1.*' + ], + [ + ['field' => 'id','key' => 't1.id', 'val' => $q['gmbs_question_section_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + if(count($gmbs_question_section) == 0){ + array_push($error_message,array( + "note"=>"gmbs_question_section id ".$q['gmbs_question_section_id']." not found" + )); + $error++; + } + + $gmbs_ref_risk_level=$this->dbBuilderSelectJoin('gmbs_ref_risk_level t1', + [ + 't1.*' + ], + [ + ['field' => 'id','key' => 't1.id', 'val' => $q['gmbs_ref_risk_level_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + if(count($gmbs_ref_risk_level) == 0){ + array_push($error_message,array( + "note"=>"gmbs_ref_risk_level id ".$q['gmbs_ref_risk_level_id']." not found" + )); + $error++; + } + + $gmbs_ref_work_scopes=$this->dbBuilderSelectJoin('gmbs_ref_work_scopes t1', + [ + 't1.*' + ], + [ + ['field' => 'id','key' => 't1.id', 'val' => $q['gmbs_ref_work_scopes_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + if(count($gmbs_ref_work_scopes) == 0){ + array_push($error_message,array( + "note"=>"gmbs_ref_work_scopes id ".$q['gmbs_ref_work_scopes_id']." not found" + )); + $error++; + } + + continue; + } + + $question_item = $this->dbBuilderInsert('gmbs_answer_detail', [ + ['key' => 'answer_score', 'val' => $q['score_yes'], 'bind' => PDO::PARAM_STR], + ['key' => 'answer_label', 'val' => 'YES', 'bind' => PDO::PARAM_STR], + ['key' => 'order', 'val' => 1, 'bind' => PDO::PARAM_STR], + ['key' => 'qualitative_answer', 'val' => 'Standar', 'bind' => PDO::PARAM_STR], + ['key' => 'is_require_note', 'val' => $q['yes_required_note'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_activities_id', 'val' => $question, 'bind' => PDO::PARAM_STR], + ], + true); + + if (!$question_item) { + return false; + } + + $question_item = $this->dbBuilderInsert('gmbs_answer_detail', [ + ['key' => 'answer_score', 'val' => $q['score_no'], 'bind' => PDO::PARAM_STR], + ['key' => 'answer_label', 'val' => 'NO', 'bind' => PDO::PARAM_STR], + ['key' => 'order', 'val' => 2, 'bind' => PDO::PARAM_STR], + ['key' => 'qualitative_answer', 'val' => 'Tidak Standar', 'bind' => PDO::PARAM_STR], + ['key' => 'is_require_note', 'val' => $q['no_required_note'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_activities_id', 'val' => $question, 'bind' => PDO::PARAM_STR], + ], + true); + + if (!$question_item) { + return false; + } + } + + } + + // return false; + + if($error == 0){ + $this->registry->db->commit(); + return array( + 'pesan' => 'Berhasil Upload Data', + 'status' => 1, + 'moreInfo'=>$error_message); + }else{ + return array( + 'pesan' => 'Gagal Upload Data', + 'status' => 0, + 'moreInfo'=>[]); + } + + // if(!$upload){ + // $this->registry->db->commit(); + + // $message = "PAYROLL.MESSAGE.SUCCMESINS"; + // $status = "PAYROLL.MESSAGE.SUCCESS"; + + // return $this->sendResponse([], $message, $status); + // }else{ + // return true; + // } + + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveEventGemba: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveEventGemba: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function importDataLineRunning($file) + { + $filename = $this->saveFile($file); + $objWorkSheet = $this->getWorkSheet($filename['newfilename'], 0); + + $data = $this->getDataLineRunningUpload($objWorkSheet); + + // var_dump($data); + // die(); + + return $this->saveDataLineRunningList($data); + } + + public function getDataLineRunningUpload($objWorkSheet) + { + $startRow = 2; + $endRow = $objWorkSheet->getHighestRow(); + $runningDateCol = $this->getColomIndex('A'); + $lineIdCol = $this->getColomIndex('B'); + $shiftGroupIdCol = $this->getColomIndex('C'); + + $data = array(); + + for ($i = $startRow; $i <= $endRow; $i++) { + $item = array(); + $runningDate = \PHPExcel_Style_NumberFormat::toFormattedString($objWorkSheet->getCellByColumnAndRow($runningDateCol, $i)->getValue(), 'YYYY-MM-DD'); + $lineId = $objWorkSheet->getCellByColumnAndRow($lineIdCol, $i)->getFormattedValue(); + $shiftGroupId = $objWorkSheet->getCellByColumnAndRow($shiftGroupIdCol, $i)->getFormattedValue(); + + if ($runningDate) { + $item['running_date'] = $runningDate; + $item['ref_shift_group_id'] = $shiftGroupId; + $item['gedung_sector_line_id'] = $lineId; + array_push($data, $item); + } + } + + return $data; + } + + public function saveDataLineRunningList($data,$upload=false) + { + try { + if(!$upload){ + $this->registry->db->beginTransaction(); + } + + $error=0; + $error_message=[]; + foreach ($data as $i => $q) { + $question = $this->dbBuilderInsert('gmbs_line_running', [ + ['key' => 'running_date', 'val' => $q['running_date'], 'bind' => PDO::PARAM_STR], + ['key' => 'ref_shift_group_id', 'val' => $q['ref_shift_group_id'], 'bind' => PDO::PARAM_STR], + ['key' => 'gedung_sector_line_id', 'val' => $q['gedung_sector_line_id'], 'bind' => PDO::PARAM_STR], + ], + true); + + if (!$question) { + $gedung_sector_line=$this->dbBuilderSelectJoin('gedung_sector_line t1', + [ + 't1.*' + ], + [ + ['field' => 'id','key' => 't1.id', 'val' => $q['gedung_sector_line_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + if(count($gedung_sector_line) == 0){ + array_push($error_message,array( + "note"=>"gedung_sector_line id ".$q['gedung_sector_line_id']." not found" + )); + $error++; + } + + $ref_shift_group=$this->dbBuilderSelectJoin('ref_shift_group t1', + [ + 't1.*' + ], + [ + ['field' => 'id','key' => 't1.id', 'val' => $q['ref_shift_group_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + if(count($ref_shift_group) == 0){ + array_push($error_message,array( + "note"=>"ref_shift_group id ".$q['ref_shift_group_id']." not found" + )); + $error++; + } + + continue; + } + + } + + // return false; + + if($error == 0){ + $this->registry->db->commit(); + return array( + 'pesan' => 'Berhasil Upload Data', + 'status' => 1, + 'moreInfo'=>$error_message); + }else{ + return array( + 'pesan' => 'Gagal Upload Data', + 'status' => 0, + 'moreInfo'=>[]); + } + + // if(!$upload){ + // $this->registry->db->commit(); + + // $message = "PAYROLL.MESSAGE.SUCCMESINS"; + // $status = "PAYROLL.MESSAGE.SUCCESS"; + + // return $this->sendResponse([], $message, $status); + // }else{ + // return true; + // } + + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveEventGemba: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveEventGemba: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + + +} diff --git a/admin/model/index.html b/admin/model/index.html new file mode 100755 index 0000000..c942a79 --- /dev/null +++ b/admin/model/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/admin/views/export-data-monitoring-self.php b/admin/views/export-data-monitoring-self.php new file mode 100755 index 0000000..68b9bb4 --- /dev/null +++ b/admin/views/export-data-monitoring-self.php @@ -0,0 +1,67 @@ +getProperties()->setCreator("Nabati") + ->setLastModifiedBy("Nabati") + ->setTitle("Office 2007 XLSX TEMPLATE UPLOAD ") + ->setSubject("TEMPLATE UPLOAD ") + ->setDescription("TEMPLATE UPLOAD ") + ->setKeywords("office 2007 openxml php") + ->setCategory("TEMPLATE UPLOAD "); + +$cel = 1; +$condition = "new, second, scrap"; +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', 'No') + ->setCellValue('B1', 'Department') + ->setCellValue('C1', 'Business Unit') + ->setCellValue('D1', 'Line') + ->setCellValue('E1', 'Section') + ->setCellValue('F1', 'Activities') + ->setCellValue('G1', 'PIC') + ->setCellValue('H1', 'Note') + ->setCellValue('I1', 'Date Time') + ->setCellValue('J1', 'Photo'); +$row=2; +foreach ($list as $key => $value) { + $photoStr = ""; + if (isset($value['photo']) && count($value['photo']) !== 0) { + foreach ($value['photo'] as $val) { + $photoStr .= $val['img'] .", "; + } + } + $objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A'.($row+$key), ($key+1)) + ->setCellValue('B'.($row+$key), $value['department_name']) + ->setCellValue('C'.($row+$key), $value['bu_name']) + ->setCellValue('D'.($row+$key), $value['line_name']) + ->setCellValue('E'.($row+$key), $value['section_name']) + ->setCellValue('F'.($row+$key), $value['activities']) + ->setCellValue('G'.($row+$key), $value['pic_name']) + ->setCellValue('H'.($row+$key), $value['note']) + ->setCellValue('I'.($row+$key), $value['date_time']) + ->setCellValue('J'.($row+$key), $photoStr); +} + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + +// Redirect output to a client’s web browser (Excel2007) +header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); +header('Content-Disposition: attachment;filename="export-data-monitoring.xlsx"'); +header('Cache-Control: max-age=0'); +// If you're serving to IE 9, then the following may be needed +header('Cache-Control: max-age=1'); + +// If you're serving to IE over SSL, then the following may be needed +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past +header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified +header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 +header('Pragma: public'); // HTTP/1.0 + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save('php://output'); +$objPHPExcel->disconnectWorksheets(); +unset($objPHPExcel); +exit; \ No newline at end of file diff --git a/admin/views/report.php b/admin/views/report.php new file mode 100755 index 0000000..1c27dc6 --- /dev/null +++ b/admin/views/report.php @@ -0,0 +1,203 @@ +getProperties()->setCreator("Syamsudin") + ->setLastModifiedBy("Syamsudin") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Export Data") + ->setDescription("Export Data") + ->setKeywords("office 2007 openxml php") + ->setCategory("Export Data"); + // $myJSON = json_encode($list); + + // echo $myJSON; +// // var_dump($list); +// die(); + +$event=$list['event']; +$assesor=''; +$manufacture_name=''; +$products_name=''; + +if($event){ + $assesor=isset($event[0]['fullname'])?$event[0]['fullname']:''; + $manufacture_name=$event[0]['ref_manunfactures_name']; + $products_name=$event[0]['ref_manunfacture_products_name']; +} + +$cel = 2; +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A' . $cel, 'Nama Pabrik') + ->setCellValue('B' . ($cel), $manufacture_name) + ->setCellValue('A' . ($cel+1), 'Nama Produk') + ->setCellValue('B' . ($cel+1), $products_name) + ->setCellValue('A' . ($cel+2), 'Assesor') + ->setCellValue('B' . ($cel+2), $assesor); + +$cel = 5; +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('E' . $cel, 'SCORE') + ->setCellValue('E' . ($cel+1), 'Result (Actual) Grouping :'); + +$cel = 5; +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('E' . $cel, 'SCORE') + ->setCellValue('E' . ($cel+1), 'Result (Actual) Grouping :'); + +$column='J'; +$header=$list['header']; +for ($i=0; $i < count($header); $i++) { + $objPHPExcel->setActiveSheetIndex(0) + ->setCellValue($column.'' . ($cel), $header[$i]['name']); + $objPHPExcel->setActiveSheetIndex(0) + ->setCellValue($column.'' . ($cel+1), ($header[$i]['total_score']/$list['total_all_max_score'])*100); + $column++; + $column++; + $column++; + $column++; +} + +$cel = 7; + +$event_section=$list['gmb_event_sections']; + +for ($i=0; $i < count($event_section); $i++) { + $objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A' . ($cel+1), $event_section[$i]['first_question']) + ->setCellValue('B' . ($cel+1), '-') + ->setCellValue('C' . ($cel+1), $event_section[$i]['last_question']) + ->setCellValue('D' . ($cel+1), $event_section[$i]['section_name']) + ->setCellValue('E' . ($cel+1), $event_section[$i]['ach_result_section']) + ->setCellValue('F' . ($cel+1), $event_section[$i]['score']) + ->setCellValue('G' . ($cel+1), '/') + ->setCellValue('H' . ($cel+1), $event_section[$i]['weight']); + + $column='J'; + $header=$event_section[$i]['category_type']; + foreach ($header as $key => $value) { + $objPHPExcel->setActiveSheetIndex(0) + ->setCellValue($column.'' . ($cel+1), $value['total_score']); + $column++; + $objPHPExcel->setActiveSheetIndex(0) + ->setCellValue($column.'' . ($cel+1), '/'); + $column++; + $objPHPExcel->setActiveSheetIndex(0) + ->setCellValue($column.'' . ($cel+1), $value['total_max_score']); + $column++; + $column++; + } + + $cel++; +} + +$column='J'; +$header=$list['header']; +// var_dump($header);die(); +for ($i=0; $i < count($header); $i++) { + $objPHPExcel->setActiveSheetIndex(0) + ->setCellValue($column.'' . ($cel+1), ($header[$i]['total_score']/$header[$i]['total_max_score'])*100); + $column++; + $column++; + $column++; + $column++; +} +$cel++; +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A' . ($cel+1), 'PLANT SECTION ACHIEVEMENT'); +$cel++; + +for ($i=0; $i < count($event_section); $i++) { + $objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A' . ($cel+1), 'SECTION SCORE') + ->setCellValue('A' . ($cel+2), $event_section[$i]['ach_result_section']) + ->setCellValue('C' . ($cel+1), 'VALUES') + ->setCellValue('D' . ($cel+1), $event_section[$i]['section_name']) + ->setCellValue('E' . ($cel+1), 'Grand Total'); + $cel++; + $header=$event_section[$i]['category_type']; + foreach ($header as $key => $value) { + // var_dump($value);die(); + if($value['type'] == 'types'){ + $score=ROUND(($value['total_score']/$value['total_max_score'])*100,2); + $objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('C' . ($cel+1), $value['name']) + ->setCellValue('D' . ($cel+1), $score) + ->setCellValue('E' . ($cel+1), $score); + $cel++; + } + + + + } + + $cel++; + $cel++; +} + + +foreach(range('A',$column) as $columnID) { + $objPHPExcel->getActiveSheet() + ->getColumnDimension($columnID) + ->setAutoSize(true); +} + +// $style = array( +// 'alignment' => array( +// 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, +// ) +// ); + +$objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);; + +// Rename worksheet +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + + + +if($generate){ + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="gemba-report-'.strtotime(date('Y-m-d')).'.xls"'); + header('Cache-Control: max-age=0'); + // If you're serving to IE 9, then the following may be needed + header('Cache-Control: max-age=1'); + + // If you're serving to IE over SSL, then the following may be needed + header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past + header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified + header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 + header ('Pragma: public'); // HTTP/1.0 + + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); + $objWriter->save(str_replace(__FILE__,'/hcportal_docs/gembareport/'.$filename,__FILE__)); + $objPHPExcel->disconnectWorksheets(); + unset($objPHPExcel); + // $obj->sendMailAttAwnReport($filename,$mail); +}else{ + // Redirect output to a client’s web browser (Excel2007) + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="gemba-report.xls"'); + header('Cache-Control: max-age=0'); + // If you're serving to IE 9, then the following may be needed + header('Cache-Control: max-age=1'); + + // If you're serving to IE over SSL, then the following may be needed + header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past + header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified + header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 + header ('Pragma: public'); // HTTP/1.0 + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); + $objWriter->save('php://output'); + $objPHPExcel->disconnectWorksheets(); + unset($objPHPExcel); +} + + +exit; + +// var_dump($objPHPExcel); diff --git a/admin/views/reportpdf.php b/admin/views/reportpdf.php new file mode 100755 index 0000000..88adfd3 --- /dev/null +++ b/admin/views/reportpdf.php @@ -0,0 +1,94 @@ + $value) { + $html_header.="{$value['name']}"; +} + +$event_section=$list['gmb_event_sections']; +$html_section=""; +foreach ($event_section as $key => $value) { + $no=$key+1; + + $html_section.=""; + $html_section.="{$no}"; + $html_section.="{$value['section_name']}"; + $html_section.="{$value['ach_result_section']}"; + foreach ($value['category_type'] as $j => $vj) { + $score=ROUND(($vj['total_score']/$vj['total_max_score'])*100,2); + $html_section.="{$score}"; + } + $html_section.=""; +} + +$html = " + + + +
+ + + +
+
+
+
+ + + + + + + + + + + +
Subject:Genba Result Report
Periode:
+

Dear All Leaders,

+

Dengan berlangsungnya kegiatan GENBA pada periode diatas, berikut kami lampirkan laporan GENBA serta performance per Plant dan per area diantaranya :

+ + + + + + + + + + $html_header + + $html_section + + + + +
NOArea/ProcesTotal ScoreScore Category
+

Demikian laporan performance GENBA ini kami sampaikan, mohon kerjasamanya untuk dapat melakukan improvement terkait dengan temuan guna meningkatkan score performance untuk menjadikan kondisi yang lebih baik.

+
+
+

SALAM IMPROVEMENT

+"; +$dompdf->set_paper('A4', 'portrait'); + +$dompdf->load_html($html); +$dompdf->set_option('isRemoteEnabled', TRUE); + +// $dompdf->setPaper('A4', 'landscape'); +$dompdf->render(); +$dompdf->stream($filename); +$output = $dompdf->output(); +file_put_contents('hcportal_docs/gembareport/'.$filename, $output); +?> diff --git a/admin/views/template-update-master-activities.php b/admin/views/template-update-master-activities.php new file mode 100755 index 0000000..6dd407e --- /dev/null +++ b/admin/views/template-update-master-activities.php @@ -0,0 +1,186 @@ +getProperties()->setCreator("Nabati") + ->setLastModifiedBy("Nabati") + ->setTitle("Office 2007 XLSX TEMPLATE UPLOAD ") + ->setSubject("TEMPLATE UPLOAD ") + ->setDescription("TEMPLATE UPLOAD ") + ->setKeywords("office 2007 openxml php") + ->setCategory("TEMPLATE UPLOAD "); + +$cel = 1; +$condition = "new, second, scrap"; + +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', 'Activities ID') + ->setCellValue('B1', 'Business Unit') + ->setCellValue('C1', 'Scope ID') + ->setCellValue('D1', 'Section ID') + ->setCellValue('E1', 'Department ID') + ->setCellValue('F1', 'Questionnaire') + ->setCellValue('G1', 'YES') + ->setCellValue('H1', 'NO') + ->setCellValue('I1', 'YES REQUIRED NOTE') + ->setCellValue('J1', 'NO REQUIRED NOTE') + ->setCellValue('K1', 'ORDER NO') + ->setCellValue('L1', 'Category ID') + ->setCellValue('M1', 'Risk Level ID') + ->setCellValue('N1', 'Link Reverance'); + +$row=2; +foreach ($list_activities as $key => $value) { + if ($value && isset($value)) { + $objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A'.($row+$key), $value['id']) + ->setCellValue('B'.($row+$key), $value['gmbs_business_unit_id']) + ->setCellValue('C'.($row+$key), $value['gmbs_ref_work_scopes_id']) + ->setCellValue('D'.($row+$key), $value['gmbs_question_section_id']) + ->setCellValue('E'.($row+$key), $value['department_id']) + ->setCellValue('F'.($row+$key), $value['description']) + ->setCellValue('G'.($row+$key), isset($value['answer_score_yes']) ? $value['answer_score_yes'] : 0) + ->setCellValue('H'.($row+$key), isset($value['answer_score_no']) ? $value['answer_score_no'] : 0) + ->setCellValue('I'.($row+$key), isset($value['is_require_note_yes']) ? $value['is_require_note_yes'] : 0) + ->setCellValue('J'.($row+$key), isset($value['is_require_note_no']) ? $value['is_require_note_no'] : 1) + ->setCellValue('K'.($row+$key), $value['order_no']) + ->setCellValue('L'.($row+$key), $value['gmbs_question_category_id']) + ->setCellValue('M'.($row+$key), $value['gmbs_ref_risk_level_id']) + ->setCellValue('N'.($row+$key), $value['reference_link']); + } +} + +$objWorkSheet = $objPHPExcel->createSheet(1); +$objPHPExcel->setActiveSheetIndex(1) + ->setCellValue('A1', 'ID') + ->setCellValue('B1', 'BU NAME') + ->setCellValue('C1', 'DESCRIPTION') + ->setCellValue('D1', 'PLAN') + ->setCellValue('E1', 'GEDUNG') + ->setCellValue('F1', 'SECTOR') + ->setCellValue('G1', 'LINE'); + +$objPHPExcel->getActiveSheet()->setTitle('BUSINESS UNIT'); + +$row=2; +foreach ($list_bu as $key => $value) { + $objPHPExcel->setActiveSheetIndex(1) + ->setCellValue('A'.($row+$key), $value['id']) + ->setCellValue('B'.($row+$key), $value['bu_name']) + ->setCellValue('C'.($row+$key), $value['description']) + ->setCellValue('D'.($row+$key), $value['description']) + ->setCellValue('E'.($row+$key), $value['gedung_name']) + ->setCellValue('F'.($row+$key), $value['sector_name']) + ->setCellValue('G'.($row+$key), $value['line_number']); +} + +$objWorkSheet = $objPHPExcel->createSheet(2); +$objPHPExcel->setActiveSheetIndex(2) + ->setCellValue('A1', 'ID') + ->setCellValue('B1', 'SCOPE NAME') + ->setCellValue('C1', 'DESCRIPTION'); + +$objPHPExcel->getActiveSheet()->setTitle('WORK SCOPE'); + +$row=2; +foreach ($list_scope as $key => $value) { + $objPHPExcel->setActiveSheetIndex(2) + ->setCellValue('A'.($row+$key), $value['id']) + ->setCellValue('B'.($row+$key), $value['scope_name']) + ->setCellValue('C'.($row+$key), $value['description']); +} + +$objWorkSheet = $objPHPExcel->createSheet(3); +$objPHPExcel->setActiveSheetIndex(3) + ->setCellValue('A1', 'ID') + ->setCellValue('B1', 'SECTION NAME') + ->setCellValue('C1', 'COMPANY') + ->setCellValue('D1', 'SUB AREA') + ->setCellValue('E1', 'GEDUNG') + ->setCellValue('F1', 'SECTOR') + ->setCellValue('G1', 'LINE') + ->setCellValue('H1', 'BUSINESS UNIT') + ->setCellValue('I1', 'DEPARTMENT'); + +$objPHPExcel->getActiveSheet()->setTitle('SECTION'); + +$row=2; +foreach ($list_section as $key => $value) { + $objPHPExcel->setActiveSheetIndex(3) + ->setCellValue('A'.($row+$key), $value['id']) + ->setCellValue('B'.($row+$key), $value['section_name']) + ->setCellValue('C'.($row+$key), $value['company_name']) + ->setCellValue('D'.($row+$key), $value['sub_area_name']) + ->setCellValue('E'.($row+$key), $value['gedung_name']) + ->setCellValue('F'.($row+$key), $value['sector_name']) + ->setCellValue('G'.($row+$key), $value['line_name']) + ->setCellValue('H'.($row+$key), $value['bu_name']) + ->setCellValue('I'.($row+$key), $value['department_name']); +} + +$objWorkSheet = $objPHPExcel->createSheet(4); +$objPHPExcel->setActiveSheetIndex(4) + ->setCellValue('A1', 'ID') + ->setCellValue('B1', 'DIVISION') + ->setCellValue('C1', 'DEPARTMENT'); + +$objPHPExcel->getActiveSheet()->setTitle('DEPARTMENT'); + +$row=2; +foreach ($list_department as $key => $value) { + $objPHPExcel->setActiveSheetIndex(4) + ->setCellValue('A'.($row+$key), $value['department_id']) + ->setCellValue('B'.($row+$key), $value['division']) + ->setCellValue('C'.($row+$key), $value['department']); +} + +$objWorkSheet = $objPHPExcel->createSheet(5); +$objPHPExcel->setActiveSheetIndex(5) + ->setCellValue('A1', 'ID') + ->setCellValue('B1', 'CATEGORY'); + +$objPHPExcel->getActiveSheet()->setTitle('SECTION'); + +$row=2; +foreach ($list_category as $key => $value) { + $objPHPExcel->setActiveSheetIndex(5) + ->setCellValue('A'.($row+$key), $value['id']) + ->setCellValue('B'.($row+$key), $value['category_name']); +} + +$objWorkSheet = $objPHPExcel->createSheet(6); +$objPHPExcel->setActiveSheetIndex(6) + ->setCellValue('A1', 'ID') + ->setCellValue('B1', 'RISK LEVEL'); + +$objPHPExcel->getActiveSheet()->setTitle('RISK LEVEL'); + +$row=2; +foreach ($list_risk as $key => $value) { + $objPHPExcel->setActiveSheetIndex(6) + ->setCellValue('A'.($row+$key), $value['id']) + ->setCellValue('B'.($row+$key), $value['risk_level_name']); +} + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); +$datePeriode = date('Y-m-d'); + +// Redirect output to a client’s web browser (Excel2007) +header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); +header('Content-Disposition: attachment;filename="template-edit-activities-'. $datePeriode .'.xlsx"'); +header('Cache-Control: max-age=0'); +// If you're serving to IE 9, then the following may be needed +header('Cache-Control: max-age=1'); + +// If you're serving to IE over SSL, then the following may be needed +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past +header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified +header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 +header('Pragma: public'); // HTTP/1.0 + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save('php://output'); +$objPHPExcel->disconnectWorksheets(); +unset($objPHPExcel); +exit; \ No newline at end of file diff --git a/admin/views/template-upload-line-running.php b/admin/views/template-upload-line-running.php new file mode 100755 index 0000000..3b95cc9 --- /dev/null +++ b/admin/views/template-upload-line-running.php @@ -0,0 +1,157 @@ +getProperties()->setCreator("Nabati") + ->setLastModifiedBy("Nabati") + ->setTitle("Office 2007 XLSX TEMPLATE UPLOAD ") + ->setSubject("TEMPLATE UPLOAD ") + ->setDescription("TEMPLATE UPLOAD ") + ->setKeywords("office 2007 openxml php") + ->setCategory("TEMPLATE UPLOAD "); + +$cel = 1; +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', 'RUNNING DATE') + ->setCellValue('B1', 'LINE ID') + ->setCellValue('C1', 'SHIFT GROUP ID') + ->setCellValue('A2', '2024-01-01') + ->setCellValue('B2', '1') + ->setCellValue('C2', '2'); + +$objWorkSheet = $objPHPExcel->createSheet(1); +$objPHPExcel->setActiveSheetIndex(1) + ->setCellValue('A1', 'ID LINE') + ->setCellValue('B1', 'COMPANY') + ->setCellValue('C1', 'SUB AREA') + ->setCellValue('D1', 'GEDUNG') + ->setCellValue('E1', 'SECTOR') + ->setCellValue('F1', 'LINE'); + +$objPHPExcel->getActiveSheet()->setTitle('Gedung Sector Line'); + +$row=2; +foreach ($list_sector_line as $key => $value) { + $objPHPExcel->setActiveSheetIndex(1) + ->setCellValue('A'.($row+$key), $value['gedung_sector_line_id']) + ->setCellValue('B'.($row+$key), $value['company']) + ->setCellValue('C'.($row+$key), $value['sub_area']) + ->setCellValue('D'.($row+$key), $value['gedung_name']) + ->setCellValue('E'.($row+$key), $value['sector_name']) + ->setCellValue('F'.($row+$key), $value['line_number']); +} + +$objWorkSheet = $objPHPExcel->createSheet(2); +$objPHPExcel->setActiveSheetIndex(2) + ->setCellValue('A1', 'ID SHIFT GROUP') + ->setCellValue('B1', 'COMPANY') + ->setCellValue('C1', 'SUB AREA') + ->setCellValue('D1', 'SHIFT GROUP'); + +$objPHPExcel->getActiveSheet()->setTitle('Shift Group'); + +$row=2; +foreach ($ref_shift_group as $key => $value) { + $objPHPExcel->setActiveSheetIndex(2) + ->setCellValue('A'.($row+$key), $value['ref_shift_group_id']) + ->setCellValue('B'.($row+$key), $value['company']) + ->setCellValue('C'.($row+$key), $value['sub_area']) + ->setCellValue('D'.($row+$key), $value['shift_group_name']); +} + +// $objWorkSheet = $objPHPExcel->createSheet(3); +// $objPHPExcel->setActiveSheetIndex(3) +// ->setCellValue('A1', 'ID') +// ->setCellValue('B1', 'SECTION NAME') +// ->setCellValue('C1', 'COMPANY') +// ->setCellValue('D1', 'SUB AREA') +// ->setCellValue('E1', 'GEDUNG') +// ->setCellValue('F1', 'SECTOR') +// ->setCellValue('G1', 'LINE') +// ->setCellValue('H1', 'BUSINESS UNIT') +// ->setCellValue('I1', 'DEPARTMENT'); + +// $objPHPExcel->getActiveSheet()->setTitle('SECTION'); + +// $row=2; +// foreach ($list_section as $key => $value) { +// $objPHPExcel->setActiveSheetIndex(3) +// ->setCellValue('A'.($row+$key), $value['id']) +// ->setCellValue('B'.($row+$key), $value['section_name']) +// ->setCellValue('C'.($row+$key), $value['company_name']) +// ->setCellValue('D'.($row+$key), $value['sub_area_name']) +// ->setCellValue('E'.($row+$key), $value['gedung_name']) +// ->setCellValue('F'.($row+$key), $value['sector_name']) +// ->setCellValue('G'.($row+$key), $value['line_name']) +// ->setCellValue('H'.($row+$key), $value['bu_name']) +// ->setCellValue('I'.($row+$key), $value['department_name']); +// } + +// $objWorkSheet = $objPHPExcel->createSheet(4); +// $objPHPExcel->setActiveSheetIndex(4) +// ->setCellValue('A1', 'ID') +// ->setCellValue('B1', 'DIVISION') +// ->setCellValue('C1', 'DEPARTMENT'); + +// $objPHPExcel->getActiveSheet()->setTitle('DEPARTMENT'); + +// $row=2; +// foreach ($list_department as $key => $value) { +// $objPHPExcel->setActiveSheetIndex(4) +// ->setCellValue('A'.($row+$key), $value['department_id']) +// ->setCellValue('B'.($row+$key), $value['division']) +// ->setCellValue('C'.($row+$key), $value['department']); +// } + +// $objWorkSheet = $objPHPExcel->createSheet(5); +// $objPHPExcel->setActiveSheetIndex(5) +// ->setCellValue('A1', 'ID') +// ->setCellValue('B1', 'CATEGORY'); + +// $objPHPExcel->getActiveSheet()->setTitle('SECTION'); + +// $row=2; +// foreach ($list_category as $key => $value) { +// $objPHPExcel->setActiveSheetIndex(5) +// ->setCellValue('A'.($row+$key), $value['id']) +// ->setCellValue('B'.($row+$key), $value['category_name']); +// } + +// $objWorkSheet = $objPHPExcel->createSheet(6); +// $objPHPExcel->setActiveSheetIndex(6) +// ->setCellValue('A1', 'ID') +// ->setCellValue('B1', 'RISK LEVEL'); + +// $objPHPExcel->getActiveSheet()->setTitle('RISK LEVEL'); + +// $row=2; +// foreach ($list_risk as $key => $value) { +// $objPHPExcel->setActiveSheetIndex(6) +// ->setCellValue('A'.($row+$key), $value['id']) +// ->setCellValue('B'.($row+$key), $value['risk_level_name']); +// } + + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + +// Redirect output to a client’s web browser (Excel2007) +header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); +header('Content-Disposition: attachment;filename="template-upload-activities.xlsx"'); +header('Cache-Control: max-age=0'); +// If you're serving to IE 9, then the following may be needed +header('Cache-Control: max-age=1'); + +// If you're serving to IE over SSL, then the following may be needed +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past +header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified +header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 +header('Pragma: public'); // HTTP/1.0 + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save('php://output'); +$objPHPExcel->disconnectWorksheets(); +unset($objPHPExcel); +unset($objWriter); +exit; \ No newline at end of file diff --git a/admin/views/template-upload-master-activities.php b/admin/views/template-upload-master-activities.php new file mode 100755 index 0000000..445a67b --- /dev/null +++ b/admin/views/template-upload-master-activities.php @@ -0,0 +1,172 @@ +getProperties()->setCreator("Nabati") + ->setLastModifiedBy("Nabati") + ->setTitle("Office 2007 XLSX TEMPLATE UPLOAD ") + ->setSubject("TEMPLATE UPLOAD ") + ->setDescription("TEMPLATE UPLOAD ") + ->setKeywords("office 2007 openxml php") + ->setCategory("TEMPLATE UPLOAD "); + +$cel = 1; +$condition = "new, second, scrap"; +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', 'Business Unit ID') + ->setCellValue('B1', 'Scope ID') + ->setCellValue('C1', 'Section ID') + ->setCellValue('D1', 'Department ID') + ->setCellValue('E1', 'Questionnaire') + ->setCellValue('F1', 'YES') + ->setCellValue('G1', 'NO') + ->setCellValue('H1', 'YES REQUIRED NOTE') + ->setCellValue('I1', 'NO REQUIRED NOTE') + ->setCellValue('J1', 'ORDER NO') + ->setCellValue('K1', 'Category ID') + ->setCellValue('L1', 'Risk Level ID') + ->setCellValue('M1', 'Link Reverance'); + +// $objPHPExcel->setActiveSheetIndex(0) +// ->setCellValue('A2', '16000390') +// ->setCellValue('B2', '2022-11-01') +// ->setCellValue('C2', '89') +// ->setCellValue('D2', '2') +// ->setCellValue('E2', 'new') +// ->setCellValue('F2', 'Baru'); + +$objWorkSheet = $objPHPExcel->createSheet(1); +$objPHPExcel->setActiveSheetIndex(1) + ->setCellValue('A1', 'ID') + ->setCellValue('B1', 'BU NAME') + ->setCellValue('C1', 'DESCRIPTION') + ->setCellValue('D1', 'PLAN') + ->setCellValue('E1', 'GEDUNG') + ->setCellValue('F1', 'SECTOR') + ->setCellValue('G1', 'LINE'); + +$objPHPExcel->getActiveSheet()->setTitle('BUSINESS UNIT'); + +$row=2; +foreach ($list_bu as $key => $value) { + $objPHPExcel->setActiveSheetIndex(1) + ->setCellValue('A'.($row+$key), $value['id']) + ->setCellValue('B'.($row+$key), $value['bu_name']) + ->setCellValue('C'.($row+$key), $value['description']) + ->setCellValue('D'.($row+$key), $value['description']) + ->setCellValue('E'.($row+$key), $value['gedung_name']) + ->setCellValue('F'.($row+$key), $value['sector_name']) + ->setCellValue('G'.($row+$key), $value['line_number']); +} + +$objWorkSheet = $objPHPExcel->createSheet(2); +$objPHPExcel->setActiveSheetIndex(2) + ->setCellValue('A1', 'ID') + ->setCellValue('B1', 'SCOPE NAME') + ->setCellValue('C1', 'DESCRIPTION'); + +$objPHPExcel->getActiveSheet()->setTitle('WORK SCOPE'); + +$row=2; +foreach ($list_scope as $key => $value) { + $objPHPExcel->setActiveSheetIndex(2) + ->setCellValue('A'.($row+$key), $value['id']) + ->setCellValue('B'.($row+$key), $value['scope_name']) + ->setCellValue('C'.($row+$key), $value['description']); +} + +$objWorkSheet = $objPHPExcel->createSheet(3); +$objPHPExcel->setActiveSheetIndex(3) + ->setCellValue('A1', 'ID') + ->setCellValue('B1', 'SECTION NAME') + ->setCellValue('C1', 'COMPANY') + ->setCellValue('D1', 'SUB AREA') + ->setCellValue('E1', 'GEDUNG') + ->setCellValue('F1', 'SECTOR') + ->setCellValue('G1', 'LINE') + ->setCellValue('H1', 'BUSINESS UNIT') + ->setCellValue('I1', 'DEPARTMENT'); + +$objPHPExcel->getActiveSheet()->setTitle('SECTION'); + +$row=2; +foreach ($list_section as $key => $value) { + $objPHPExcel->setActiveSheetIndex(3) + ->setCellValue('A'.($row+$key), $value['id']) + ->setCellValue('B'.($row+$key), $value['section_name']) + ->setCellValue('C'.($row+$key), $value['company_name']) + ->setCellValue('D'.($row+$key), $value['sub_area_name']) + ->setCellValue('E'.($row+$key), $value['gedung_name']) + ->setCellValue('F'.($row+$key), $value['sector_name']) + ->setCellValue('G'.($row+$key), $value['line_name']) + ->setCellValue('H'.($row+$key), $value['bu_name']) + ->setCellValue('I'.($row+$key), $value['department_name']); +} + +$objWorkSheet = $objPHPExcel->createSheet(4); +$objPHPExcel->setActiveSheetIndex(4) + ->setCellValue('A1', 'ID') + ->setCellValue('B1', 'DIVISION') + ->setCellValue('C1', 'DEPARTMENT'); + +$objPHPExcel->getActiveSheet()->setTitle('DEPARTMENT'); + +$row=2; +foreach ($list_department as $key => $value) { + $objPHPExcel->setActiveSheetIndex(4) + ->setCellValue('A'.($row+$key), $value['department_id']) + ->setCellValue('B'.($row+$key), $value['division']) + ->setCellValue('C'.($row+$key), $value['department']); +} + +$objWorkSheet = $objPHPExcel->createSheet(5); +$objPHPExcel->setActiveSheetIndex(5) + ->setCellValue('A1', 'ID') + ->setCellValue('B1', 'CATEGORY'); + +$objPHPExcel->getActiveSheet()->setTitle('SECTION'); + +$row=2; +foreach ($list_category as $key => $value) { + $objPHPExcel->setActiveSheetIndex(5) + ->setCellValue('A'.($row+$key), $value['id']) + ->setCellValue('B'.($row+$key), $value['category_name']); +} + +$objWorkSheet = $objPHPExcel->createSheet(6); +$objPHPExcel->setActiveSheetIndex(6) + ->setCellValue('A1', 'ID') + ->setCellValue('B1', 'RISK LEVEL'); + +$objPHPExcel->getActiveSheet()->setTitle('RISK LEVEL'); + +$row=2; +foreach ($list_risk as $key => $value) { + $objPHPExcel->setActiveSheetIndex(6) + ->setCellValue('A'.($row+$key), $value['id']) + ->setCellValue('B'.($row+$key), $value['risk_level_name']); +} + + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + +// Redirect output to a client’s web browser (Excel2007) +header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); +header('Content-Disposition: attachment;filename="template-upload-activities.xlsx"'); +header('Cache-Control: max-age=0'); +// If you're serving to IE 9, then the following may be needed +header('Cache-Control: max-age=1'); + +// If you're serving to IE over SSL, then the following may be needed +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past +header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified +header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 +header('Pragma: public'); // HTTP/1.0 + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save('php://output'); +$objPHPExcel->disconnectWorksheets(); +unset($objPHPExcel); +exit; \ No newline at end of file diff --git a/admin/views/ttd-1-pma.php b/admin/views/ttd-1-pma.php new file mode 100755 index 0000000..582b252 --- /dev/null +++ b/admin/views/ttd-1-pma.php @@ -0,0 +1,3 @@ + + # The ServerName directive sets the request scheme, hostname and por + # the server uses to identify itself. This is used when creating + # redirection URLs. In the context of virtual hosts, the ServerName + # specifies what hostname must appear in the request's Host: header + # match this virtual host. For the default virtual host (this file) + # value is not decisive as it is used as a last resort host regardless. + # However, you must set it for any further virtual host explicitly. + #ServerName www.example.com + + ServerAdmin webmaster@localhost + DocumentRoot / + ProxyPass /hcportal http://127.0.0.1:80/app retry=1 acquire=3000 timeout=600 Keepalive=On + + DirectoryIndex index.php + AllowOverride All + Require all granted + + + # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, + # error, crit, alert, emerg. + # It is also possible to configure the loglevel for particular + # modules, e.g. + #LogLevel info ssl:warn + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + # For most configuration files from conf-available/, which are + # enabled or disabled at a global level, it is possible to + # include a line for only one particular virtual host. For example the + # following line enables the CGI configuration for this host only + # after it has been globally disabled with "a2disconf". + #Include conf-available/serve-cgi-bin.conf + diff --git a/custom-logging.conf b/custom-logging.conf new file mode 100644 index 0000000..da968a9 --- /dev/null +++ b/custom-logging.conf @@ -0,0 +1,12 @@ +# Disable access log +CustomLog /dev/null common + +# Send error log to stderr +ErrorLog /proc/self/fd/2 + +# Set log level to warn to capture important issues +LogLevel warn + +# Redirect PHP errors to stderr +php_flag log_errors on +php_value error_log /proc/self/fd/2 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fe4d9db --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +services: + fe: + container_name: frontend + build: + context: . + dockerfile: Dockerfile.frontend + networks: + - hcportalnetwork + volumes: + - ./fe:/app + ports: + - 4200:4200 + be: + container_name: backend + build: + context: . + dockerfile: dockerfile.backend + networks: + - hcportalnetwork + volumes: + - ./be:/app + owasp: + container_name: owasp-hcportal + image: owasp/modsecurity-crs:3.3.5-nginx-202401080101 + environment: + - backend=http://be:80 + networks: + - hcportalnetwork + ports: + - 8888:80 + links: + - be + depends_on: + - be +networks: + hcportalnetwork: + driver: bridge diff --git a/entrypoint-backend.sh b/entrypoint-backend.sh new file mode 100644 index 0000000..adc5096 --- /dev/null +++ b/entrypoint-backend.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# ANSI color codes +RED='\033[0;31m' +YELLOW='\033[1;33m' +GREEN='\033[0;32m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Function to color the log output +color_log() { + while IFS= read -r line; do + if [[ $line == *"PHP Fatal error:"* ]] || [[ $line == *"ERROR:"* ]] || [[ $line == *"Error:"* ]]; then + echo -e "${RED}$line${NC}" + elif [[ $line == *"PHP Warning:"* ]]; then + echo -e "${YELLOW}$line${NC}" + elif [[ $line == *"PHP Notice:"* ]]; then + echo -e "${GREEN}$line${NC}" + else + echo -e "${BLUE}$line${NC}" + fi + done +} + +# Start Apache in foreground and pipe through color_log +apache2-foreground 2>&1 | color_log diff --git a/entrypoint-frontend.sh b/entrypoint-frontend.sh new file mode 100644 index 0000000..c97cb38 --- /dev/null +++ b/entrypoint-frontend.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Exit immediately if a command exits with a non-zero status +set -e + +# Navigate to the app directory +cd /app + +# Install dependencies if node_modules doesn't exist +if [ ! -d "node_modules" ]; then + echo "Installing dependencies..." + npm install +fi + +# Get the app name from environment variable or use default +APP_NAME=${APP_NAME:-hcportal} + +# Serve the application +echo "Starting ${APP_NAME}..." +npx nx serve ${APP_NAME} --host 0.0.0.0 --port 4200 diff --git a/fe b/fe new file mode 160000 index 0000000..cbe98dc --- /dev/null +++ b/fe @@ -0,0 +1 @@ +Subproject commit cbe98dcb438770c2921573f2e21cf6bbf7b002ef diff --git a/mpp.php b/mpp.php new file mode 100644 index 0000000..226b070 --- /dev/null +++ b/mpp.php @@ -0,0 +1,222 @@ +ActionAjaxOff = array('index'); + $this->apiModule = 'genbaadmin'; + $this->obj = new Admin($this->registry); + $this->generalActions = '*'; + } + + public function index() + { + $this->isAuthorized(); + } + + + protected function getLineList() + { + $rs = $this->obj->getLineListData(); + if (is_array($rs)) { + Http::ResponseJson($rs); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } + + protected function getManufactureList() + { + $rs = $this->obj->getRefManufactures(); + if (is_array($rs)) { + Http::ResponseJson($rs); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } + + protected function getSubAreaFromManufacture() + { + $id = $this->apiParams->manId; + $rs = $this->obj->getSubAreaFromManufacture($id); + if (is_array($rs)) { + Http::ResponseJson($rs); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } + + protected function getDivisionFromSubArea() + { + $id = $this->apiParams->subAreaId; + $rs = $this->obj->getDivisionFromSubArea($id); + if (is_array($rs)) { + Http::ResponseJson($rs); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } + + protected function getDepartmentName() + { + $departmentId = $this->apiParams->departmentId; + $rs = $this->obj->getDepartmentDivisionName($departmentId); + if (is_array($rs)) { + Http::ResponseJson($rs[0]); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } + + protected function getDataEmployee() + { + $empId = $this->apiParams->empId; + $rs = $this->obj->getDataEmployee($empId); + if (is_array($rs)) { + Http::ResponseJson($rs); + } else { + Http::ErrorQueryResponse('User Not Found', 'json'); + } + } + + protected function getDepartmentFromDivision() + { + $id = $this->apiParams->divisionId; + $subAreaId = $this->apiParams->subAreaId; + $rs = $this->obj->getDepartmentFromDivision($id, $subAreaId); + if (is_array($rs)) { + Http::ResponseJson($rs); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } + protected function searchEmp() + { + $search = $this->apiParams->search; + $rs = $this->obj->searchEmployee($search); + if (is_array($rs)) { + Http::ResponseJson($rs); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } + + protected function getManufactureArea() + { + $manufacture_id = $this->apiParams->manId; + $rs = $this->obj->getManufactureArea($manufacture_id); + if (is_array($rs)) { + Http::ResponseJson($rs); + } else { + Http::ResponseJson([], 'json'); + } + } + protected function getForemanList() {} + + protected function getBu() + { + $search = $this->apiParams->search ?? null; + $rs = $this->obj->GetBusinessUnits($search); + if (is_array($rs)) { + Http::ResponseJson($rs); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } + + protected function getTeamMember() + { + $nik = $this->apiParams->nik ?? null; + if (empty($nik)) { + Http::ErrorQueryResponse('NIK is required', 'json'); + return; + } + $rs = $this->obj->getTeamMember($nik); + if (is_array($rs)) { + Http::responseJson($rs); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } + + protected function getGedung() + { + $buId = $this->apiParams->buId ?? null; + $search = $this->apiParams->search ?? null; + $sectorId = $this->apiParams->id ?? null; + $rs = $this->obj->getSector($buId, $search, $sectorId); + if (is_array($rs)) { + Http::responseJson($rs); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } + + protected function getLineByGedung() + { + $buId = $this->apiParams->buId ?? null; + $sectorId = $this->apiParams->sectorId ?? null; + $search = $this->apiParams->search ?? null; + $rs = $this->obj->getGedungSectorLines($buId, $sectorId, $search); + if (is_array($rs)) { + Http::responseJson($rs); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } + + protected function getBusinessTitle() + { + $id = $this->apiParams->divisionId; + $subAreaId = $this->apiParams->subAreaId; + $departmentId = $this->apiParams->departmentId; + $rs = $this->obj->getBusinessTitle($id, $departmentId, $subAreaId); + if (is_array($rs)) { + Http::ResponseJson($rs); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } + + protected function getOrgLayer() + { + $id = $this->apiParams->divisionId; + $subAreaId = $this->apiParams->subAreaId; + $departmentId = $this->apiParams->departmentId; + $rs = $this->obj->getOrgLayer($id, $departmentId, $subAreaId); + if (is_array($rs)) { + Http::ResponseJson($rs); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } + + protected function getMpp() + { + $id = $this->apiParams->divisionId; + $subAreaId = $this->apiParams->subAreaId; + $departmentId = $this->apiParams->departmentId; + $olId = $this->apiParams->olId; + $rs = $this->obj->getMpp($id, $departmentId, $subAreaId, $olId); + if (is_array($rs)) { + Http::ResponseJson($rs); + } else { + Http::ErrorQueryResponse('Query Error', 'json'); + } + } +} diff --git a/mppdb.php b/mppdb.php new file mode 100644 index 0000000..1b7d38b --- /dev/null +++ b/mppdb.php @@ -0,0 +1,6073 @@ +dbBuilderSelectJoin( + 'gmb_events t1 + INNER JOIN ref_manufacture_products t2 ON t1.ref_manunfacture_products_id = t2.id + INNER JOIN ref_manunfactures t3 ON t2.ref_manunfactures_id = t3.id + INNER JOIN ref_master_category_product_plant t4 ON t2.ref_master_category_product_plant_id = t4.id', + [ + 't1.id', + 't1.event_name', + 't1.decscription', + 't1.event_date', + 't1.start_date_time', + 't1.end_date_time', + 't2.ref_manunfactures_id', + 't2.ref_master_category_product_plant_id', + 't3.plan_name as ref_manunfactures_name', + 't4.category_name as category_name', + 't1.gmb_question_group_id', + 't1.ref_manunfacture_products_id' + ], + [], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + $stmtRespons = $this->setStatementGetResponCount(); + + foreach ($rs as $k => $v) { + $rs[$k]['responCount'] = $this->getResponsCount($stmtRespons, $v['id']); + } + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmb_events t1', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataGmbEventDetail($params) + { + try { + + $event = $this->dbBuilderSelectJoin( + 'gmb_events t1 + INNER JOIN ref_manufacture_products t2 ON t1.ref_manunfacture_products_id = t2.id + INNER JOIN ref_manunfactures t3 ON t2.ref_manunfactures_id = t3.id + INNER JOIN ref_master_category_product_plant t4 ON t2.ref_master_category_product_plant_id = t4.id', + [ + 't1.*', + 't3.plan_name as ref_manunfactures_name', + 't4.category_name as ref_manunfacture_products_name' + ], + [ + ['field' => 'id', 'key' => 't1.id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ] + ); + + + + $gmb_event_types = $this->dbBuilderSelectJoin( + 'gmb_event_types t1 + INNER JOIN gmb_question_types t2 ON t1.gmb_question_types_id = t2.id', + [ + 't2.*', + 't1.weight', + '1 as edit' + ], + [ + ['field' => 'gmb_events_id', 'key' => 't1.gmb_events_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ] + ); + + $gmb_event_sections = $this->dbBuilderSelectJoin( + 'gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id', + [ + 't2.*', + 't1.weight', + '1 as edit' + ], + [ + ['field' => 'gmb_events_id', 'key' => 't1.gmb_events_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ] + ); + + $gmb_event_category = $this->dbBuilderSelectJoin( + 'gmb_event_category t1 + INNER JOIN gmb_question_category t2 ON t1.gmb_question_category_id = t2.id', + [ + 't2.*', + 't1.weight', + '1 as edit' + ], + [ + ['field' => 'gmb_events_id', 'key' => 't1.gmb_events_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ] + ); + + $gmb_event_asessor = $this->dbBuilderSelectJoin( + 'gmb_event_asessor t1 + INNER JOIN employement a ON t1.employement_nik = a.nik + INNER JOIN emp_profiles b on a.`emp_profile_id` = b.`id` + LEFT JOIN gmb_event_questions t2 ON t1.gmb_events_id = t2.gmb_events_id + LEFT JOIN gmb_asessor_result t3 ON t2.id = t3.gmb_event_questions_id AND t3.gmb_event_asessor_id = t1.id', + [ + "t1.id", + "t1.file_report", + "a.`nik` `empno`", + "concat(a.`nik` , ' - ',COALESCE(first_name, ''), ' ',COALESCE(middle_name, ''), ' ', COALESCE(last_name, '')) `fullname`", + "IF(office_mail, office_mail, emp_email) as email_address", + "'1' AS saved", + "getEmpName(a.`nik`) as name", + "COUNT(*) as total_question", + "SUM(IF(t3.id is not null, 1,0)) as total_answer", + "ROUND((SUM(IF(t3.id is not null, 1,0))/COUNT(*))*100,2) as percentage", + ], + [ + ['field' => 'gmb_events_id', 'key' => 't1.gmb_events_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ], + "GROUP BY + t1.id, + t1.employement_nik, + t1.gmb_events_id" + ); + + $stmt = $this->setStatementGetIssues(); + $stmt->bindValue(':event_id', $params['id'], PDO::PARAM_INT); + $stmt->execute(); + $gmb_event_issues = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $stmtAssIssue = $this->setStatementGetResponCountAssIssue(); + foreach ($gmb_event_issues as $k => $val) { + $gmb_event_issues[$k]['responCount'] = $this->getResponsCount($stmtAssIssue, $val['gmb_asessor_result_id']); + } + + $stmt = $this->setStatementGetGeneralIssues(); + $stmt->bindValue(':event_id', $params['id'], PDO::PARAM_INT); + $stmt->execute(); + $gmb_general_issues = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $stmtGetcountGenIssue = $this->setStatementGetResponCountGenIssue(); + foreach ($gmb_general_issues as $k => $val) { + $gmb_general_issues[$k]['responCount'] = $this->getResponsCount($stmtGetcountGenIssue, $val['id']); + } + + $stmt = $this->setStatementGetResponCountGeneralIssue(); + $stmt->bindValue(':id', $params['id'], PDO::PARAM_INT); + $stmt->execute(); + $rsGenIssue = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $stmt = $this->setStatementGetResponCountIssue(); + $stmt->bindValue(':id', $params['id'], PDO::PARAM_INT); + $stmt->execute(); + $rsIssue = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach ($gmb_event_asessor as $key => $value) { + $gmb_event_asessor[$key]['score'] = $this->getScoreAssesor($value['id']); + } + foreach ($gmb_event_issues as $k => $v) { + $gmb_event_issues[$k]['images'] = ""; + if (!empty($v['file_location'])) { + $gmb_event_issues[$k]['images'] = $this->registry->config->server_address . '/upload/genba-client/' . $v['file_location']; + } + } + $rData['event'] = $event; + $rData['gmb_event_types'] = $gmb_event_types; + $rData['gmb_event_sections'] = $gmb_event_sections; + $rData['gmb_event_category'] = $gmb_event_category; + $rData['gmb_event_asessor'] = $gmb_event_asessor; + $rData['gmb_event_issues'] = $gmb_event_issues; + $rData['gmb_general_issues'] = $gmb_general_issues; + $rData['responCountGeneralIssue'] = count($rsGenIssue) > 0 ? $rsGenIssue[0]['total'] : 0; + $rData['responCountIssue'] = count($rsIssue) > 0 ? $rsIssue[0]['total'] : 0; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataGmbEventDetailByAssesor($params) + { + try { + + $event = $this->dbBuilderSelectJoin( + 'gmb_event_asessor a + INNER JOIN employement b ON a.employement_nik = b.nik + INNER JOIN emp_profiles c on b.`emp_profile_id` = c.`id` + INNER JOIN gmb_events t1 ON a.gmb_events_id = t1.id + INNER JOIN ref_manufacture_products t2 ON t1.ref_manunfacture_products_id = t2.id + INNER JOIN ref_manunfactures t3 ON t2.ref_manunfactures_id = t3.id + INNER JOIN ref_master_category_product_plant t4 ON t2.ref_master_category_product_plant_id = t4.id', + [ + 't1.*', + 't3.plan_name as ref_manunfactures_name', + 't4.category_name as ref_manunfacture_products_name', + "b.`nik` `empno`", + "concat(b.`nik` , ' - ',COALESCE(first_name, ''), ' ',COALESCE(middle_name, ''), ' ', COALESCE(last_name, '')) `fullname`", + "IF(office_mail, office_mail, emp_email) as email_address", + "'1' AS saved", + "getEmpName(b.`nik`) as assesor_name" + ], + [ + ['field' => 'id', 'key' => 'a.id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ] + ); + + $gmb_event_types = $this->dbBuilderSelectJoin( + 'gmb_event_types t1 + INNER JOIN gmb_question_types t2 ON t1.gmb_question_types_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_types_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id', + [ + 't2.*', + 'COUNT(t3.id) as total_question', + 'SUM(IF(t6.id is not null, 1,0)) as total_answer', + 'ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage', + 'sum(t3.max_score) as total_max_score', + 'ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score', + 'ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2) as ach_result_section', + 't4.gmb_events_id as event_id' + ], + [ + ['field' => 'id', 'key' => 't5.id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ], + " GROUP BY + t1.id" + ); + + $gmb_event_category = $this->dbBuilderSelectJoin( + 'gmb_event_category t1 + INNER JOIN gmb_question_category t2 ON t1.gmb_question_category_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_category_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id', + [ + 't2.*', + 'COUNT(t3.id) as total_question', + 'SUM(IF(t6.id is not null, 1,0)) as total_answer', + 'ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage', + 'sum(t3.max_score) as total_max_score', + 'ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score', + 'ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2) as ach_result_section', + 't4.gmb_events_id as event_id' + ], + [ + ['field' => 'id', 'key' => 't5.id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ], + " GROUP BY + t1.id" + ); + + $gmb_event_sections = $this->dbBuilderSelectJoin( + 'gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + LEFT JOIN gmb_asessor_result_notes t7 ON t6.id = t7.gmb_asessor_result_id', + [ + 't2.*', + 't7.note', + 'COUNT(t3.id) as total_question', + 'SUM(IF(t6.id is not null, 1,0)) as total_answer', + 'ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage', + 'sum(t3.max_score) as total_max_score', + 'ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score', + 'ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2) as ach_result_section', + 't4.gmb_events_id as event_id' + ], + [ + ['field' => 'id', 'key' => 't5.id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ], + " GROUP BY + t1.id " + ); + + + + $rData['event'] = $event; + $rData['gmb_event_types'] = $gmb_event_types; + $rData['gmb_event_category'] = $gmb_event_category; + $rData['gmb_event_sections'] = $gmb_event_sections; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getQuestionList($params) + { + try { + + if ($params['type'] == 'type') { + $question = $this->dbBuilderSelectJoin( + 'gmb_event_types t1 + INNER JOIN gmb_question_types t2 ON t1.gmb_question_types_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_types_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + LEFT JOIN gmb_answer_detail t7 ON t6.gmb_answer_detail_id = t7.id + LEFT JOIN gmb_asessor_result_notes t8 ON t8.gmb_asessor_result_id = t6.id + LEFT JOIN gmb_assesor_result_files t9 ON t9.gmb_asessor_result_id = t6.id ', + [ + 't3.id', + 't3.question_code', + 't3.question', + 't7.answer_label', + 't6.score', + 't8.note', + 't9.file_location as file' + ], + [ + ['field' => 'gmb_question_types_id', 'key' => 't1.gmb_question_types_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ['field' => 'id', 'key' => 't5.id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_STR], + ] + ); + } + + if ($params['type'] == 'category') { + $question = $this->dbBuilderSelectJoin( + 'gmb_event_category t1 + INNER JOIN gmb_question_category t2 ON t1.gmb_question_category_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_category_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + LEFT JOIN gmb_answer_detail t7 ON t6.gmb_answer_detail_id = t7.id + LEFT JOIN gmb_asessor_result_notes t8 ON t8.gmb_asessor_result_id = t6.id + LEFT JOIN gmb_assesor_result_files t9 ON t9.gmb_asessor_result_id = t6.id', + [ + 't3.id', + 't3.question_code', + 't3.question', + 't7.answer_label', + 't6.score', + 't8.note', + 't9.file_location as file' + ], + [ + ['field' => 'gmb_question_types_id', 'key' => 't1.gmb_question_category_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ['field' => 'id', 'key' => 't5.id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_STR], + ] + ); + } + + if ($params['type'] == 'section') { + $question = $this->dbBuilderSelectJoin( + 'gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + LEFT JOIN gmb_answer_detail t7 ON t6.gmb_answer_detail_id = t7.id + LEFT JOIN gmb_asessor_result_notes t8 ON t8.gmb_asessor_result_id = t6.id + LEFT JOIN gmb_assesor_result_files t9 ON t9.gmb_asessor_result_id = t6.id', + [ + 't3.id', + 't3.question_code', + 't3.question', + 't7.answer_label', + 't6.score', + 't6.gmb_answer_detail_id', + 't8.note', + 't9.file_location as file' + ], + [ + ['field' => 'gmb_question_types_id', 'key' => 't1.gmb_question_section_id', 'val' => $params['id'], 'bind' => PDO::PARAM_STR], + ['field' => 'id', 'key' => 't5.id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_STR], + ] + ); + } + + foreach ($question as $key => $value) { + $question[$key]['pilihan'] = $this->dbBuilderSelectJoin( + 'gmb_answer_detail t1', + [ + 't1.*', + ], + [ + ['field' => 'gmb_questions_id', 'key' => 't1.gmb_questions_id', 'val' => $value['id'], 'bind' => PDO::PARAM_STR], + ] + ); + } + + + $rData['question'] = $question; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + + public function getDataGmbQuestionType() + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_types t1', + [ + 't1.*' + ], + [] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataRefManunfactures($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'ref_manunfactures t1', + [ + 't1.*' + ], + [] + ); + + if ($params['event_id']) { + $rs = $this->dbBuilderSelectJoin( + 'ref_manunfactures t1 + INNER JOIN gmbs_events t2 ON t1.id = t2.ref_manufactures_id', + [ + 't1.*' + ], + [ + ['field' => 'id', 'key' => 't2.id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR], + ] + ); + } + + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataRefManunfacturesProduct($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'ref_manufacture_products t1 + INNER JOIN ref_master_category_product_plant t2 ON t1.ref_master_category_product_plant_id =t2.id', + [ + 't1.id', + 't2.category_name', + '0 as edit' + ], + [ + ['field' => 'ref_manunfactures_id', 'key' => 't1.ref_manunfactures_id', 'val' => $params['ref_manunfactures_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataQuestionSection($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_section t1', + [ + 't1.*', + '0 as edit' + ], + [ + ['field' => 'ref_manufacture_products_id', 'key' => 't1.ref_manufacture_products_id', 'val' => $params['ref_manunfacture_products_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataQuestionCategory() + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_category t1', + [ + 't1.*', + '0 as edit' + ], + [] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveEventGemba($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + $event_date = date("Y-m-d", strtotime($data->event_date)); + $start_time = date("H:i", strtotime($data->start_date_time)); + $end_time = date("H:i", strtotime($data->end_date_time)); + $start_date_time = new DateTime($event_date . ' ' . $start_time); + $end_date_time = new DateTime($event_date . ' ' . $end_time); + + if (!isset($data->id)) { + $event = $this->dbBuilderInsert( + 'gmb_events', + [ + ['key' => 'event_name', 'val' => $data->event_name, 'bind' => PDO::PARAM_STR], + ['key' => 'decscription', 'val' => $data->description, 'bind' => PDO::PARAM_STR], + ['key' => 'event_date', 'val' => $event_date, 'bind' => PDO::PARAM_STR], + ['key' => 'start_date_time', 'val' => $start_date_time->format('Y-m-d H:i'), 'bind' => PDO::PARAM_STR], + ['key' => 'end_date_time', 'val' => $end_date_time->format('Y-m-d H:i'), 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manunfacture_products_id', 'val' => $data->ref_manunfacture_products_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_group_id', 'val' => $data->gmb_question_group_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$event) { + return false; + } + } else { + $event = $data->id; + $event_update = $this->dbBuilderUpdate('gmb_events', [ + ['key' => 'event_name', 'val' => $data->event_name, 'bind' => PDO::PARAM_STR], + ['key' => 'decscription', 'val' => $data->description, 'bind' => PDO::PARAM_STR], + ['key' => 'event_date', 'val' => $event_date, 'bind' => PDO::PARAM_STR], + ['key' => 'start_date_time', 'val' => $start_date_time->format('Y-m-d H:i'), 'bind' => PDO::PARAM_STR], + ['key' => 'end_date_time', 'val' => $end_date_time->format('Y-m-d H:i'), 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manunfacture_products_id', 'val' => $data->ref_manunfacture_products_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_group_id', 'val' => $data->gmb_question_group_id, 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $event, 'bind' => PDO::PARAM_INT], + ]); + + if (!$event_update) { + return false; + } + + $this->dbBuilderDelete('gmb_event_types', 'gmb_events_id', $event); + $this->dbBuilderDelete('gmb_event_sections', 'gmb_events_id', $event); + $this->dbBuilderDelete('gmb_event_category', 'gmb_events_id', $event); + $this->dbBuilderDelete('gmb_event_asessor', 'gmb_events_id', $event); + $this->dbBuilderDelete('gmb_questions', 'gmb_events_id', $event); + } + + + + foreach ($data->type as $key => $value) { + $event_types = $this->dbBuilderInsert( + 'gmb_event_types', + [ + ['key' => 'gmb_events_id', 'val' => $event, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $value->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_types_id', 'val' => $value->id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$event_types) { + return false; + } + } + + foreach ($data->section as $key => $value) { + + $event_sections = $this->dbBuilderInsert( + 'gmb_event_sections', + [ + ['key' => 'gmb_events_id', 'val' => $event, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $value->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_section_id', 'val' => $value->id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$event_sections) { + return false; + } + } + + foreach ($data->gmb_question_category_id as $key => $value) { + + $event_category = $this->dbBuilderInsert( + 'gmb_event_category', + [ + ['key' => 'gmb_events_id', 'val' => $event, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $value->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_question_category_id', 'val' => $value->id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$event_category) { + return false; + } + } + + foreach ($data->asessor as $key => $value) { + $event_asessor = $this->dbBuilderInsert( + 'gmb_event_asessor', + [ + ['key' => 'gmb_events_id', 'val' => $event, 'bind' => PDO::PARAM_STR], + ['key' => 'employement_nik', 'val' => $value->nik->empno, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$event_asessor) { + return false; + } + + $mail = new Mail($this->registry); + + $address_cc = array(); + + $maildata['address'] = $value->nik->email_address; + $maildata['address_cc_mail'] = $address_cc; + $maildata['addressname'] = ""; + $maildata['empreqname'] = ""; + $maildata['attachmentlocation'] = ''; + $maildata['attachmentfilename'] = ''; + $maildata['subject'] = "Genba Event"; + $maildata['link'] = ''; + + $maildata['message'] = "Genba Event Invite"; + + $rsmail = $mail->sendMail($maildata); + + if (!$rsmail) { + throw new Exception("3"); + } + } + + foreach ($data->type as $i => $vi) { + foreach ($data->section as $j => $vj) { + foreach ($data->gmb_question_category_id as $k => $vk) { + $question = $this->dbBuilderSelectJoin( + 'gmb_questions t1', + [ + 't1.*' + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR], + ['field' => 'gmb_question_section_id', 'key' => 't1.gmb_question_section_id', 'val' => $vj->id, 'bind' => PDO::PARAM_STR], + ['field' => 'gmb_question_types_id', 'key' => 't1.gmb_question_types_id', 'val' => $vi->id, 'bind' => PDO::PARAM_STR], + ['field' => 'gmb_question_category_id', 'key' => 't1.gmb_question_category_id', 'val' => $vk->id, 'bind' => PDO::PARAM_STR], + ['field' => 'gmb_question_group_id', 'key' => 't1.gmb_question_group_id', 'val' => $data->gmb_question_group_id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($question) > 0) { + $event_questions = $this->dbBuilderInsert( + 'gmb_event_questions', + [ + ['key' => 'gmb_events_id', 'val' => $event, 'bind' => PDO::PARAM_STR], + ['key' => 'gmb_questions_id', 'val' => $question[0]['id'], 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$event_questions) { + return false; + } + } + } + } + } + + // return false; + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveEventGemba: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveEventGemba: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteGembaEvent($id) + { + try { + + $this->registry->db->beginTransaction(); + + $this->dbBuilderDelete('gmb_events', 'id', $id); + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteGembaEvent: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteGembaEvent: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function getScoreAssesor($id) + { + try { + $sql = "SELECT + ROUND(SUM(tab.score),2) as score + FROM + ( + SELECT + t2.*, + t7.note, + COUNT(t3.id) as total_question, + SUM(IF(t6.id is not null, 1,0)) as total_answer, + ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage, + sum(t3.max_score) as total_max_score, + ((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100 as score, + ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2) as ach_result_section, + t4.gmb_events_id as event_id + FROM + gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + LEFT JOIN gmb_asessor_result_notes t7 ON t6.id = t7.gmb_asessor_result_id + WHERE + t5.id =:assesor_id + GROUP BY + t1.id + ) tab"; + + $stmt = $this->registry->db->prepare($sql); + $stmt->bindValue(':assesor_id', $id, PDO::PARAM_STR); + $stmt->execute(); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + + return count($rs) > 0 ? $rs[0]['score'] : 0; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataReport($params) + { + try { + + $event = $this->dbBuilderSelectJoin( + 'gmb_events t1 + INNER JOIN ref_manufacture_products t2 ON t1.ref_manunfacture_products_id = t2.id + INNER JOIN ref_manunfactures t3 ON t2.ref_manunfactures_id = t3.id + INNER JOIN ref_master_category_product_plant t4 ON t2.ref_master_category_product_plant_id = t4.id', + [ + 't1.*', + 't3.plan_name as ref_manunfactures_name', + 't4.category_name as ref_manunfacture_products_name' + ], + [ + ['field' => 'id', 'key' => 't1.id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + if ($params['assesor_id'] != '') { + $event = $this->dbBuilderSelectJoin( + 'gmb_event_asessor a + INNER JOIN employement b ON a.employement_nik = b.nik + INNER JOIN emp_profiles c on b.`emp_profile_id` = c.`id` + INNER JOIN gmb_events t1 ON a.gmb_events_id = t1.id + INNER JOIN ref_manufacture_products t2 ON t1.ref_manunfacture_products_id = t2.id + INNER JOIN ref_manunfactures t3 ON t2.ref_manunfactures_id = t3.id + INNER JOIN ref_master_category_product_plant t4 ON t2.ref_master_category_product_plant_id = t4.id', + [ + 't1.*', + 't3.plan_name as ref_manunfactures_name', + 't4.category_name as ref_manunfacture_products_name', + "b.`nik` `empno`", + "concat(b.`nik` , ' - ',COALESCE(first_name, ''), ' ',COALESCE(middle_name, ''), ' ', COALESCE(last_name, '')) `fullname`", + "IF(office_mail, office_mail, emp_email) as email_address", + "'1' AS saved", + "getEmpName(b.`nik`) as assesor_name" + ], + [ + ['field' => 'id', 'key' => 'a.id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_STR], + ] + ); + } + + + + + + $section_where = "WHERE t1.gmb_events_id={$params['event_id']}"; + + if ($params['assesor_id'] != '') { + $section_where .= " AND t5.id={$params['assesor_id']}"; + } + + $sql_event_sections = "SELECT + tab.*, + ROUND(avg(tab.score),2) as score, + ROUND(avg(tab.ach_result_section),2) as ach_result_section + FROM + ( + SELECT + t2.*, + COUNT(t3.id) as total_question, + SUM(IF(t6.id is not null, 1,0)) as total_answer, + ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage, + sum(t3.max_score) as total_max_score, + ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score, + ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2)*100 as ach_result_section, + t4.gmb_events_id as event_id, + (SELECT + a.question_code + FROM + gmb_questions a + INNER JOIN gmb_question_section b ON a.gmb_question_section_id = b.id + WHERE + b.id=t1.gmb_question_section_id + ORDER BY + a.id ASC LIMIT 1 + ) first_question, + (SELECT + a.question_code + FROM + gmb_questions a + INNER JOIN gmb_question_section b ON a.gmb_question_section_id = b.id + WHERE + b.id=t1.gmb_question_section_id + ORDER BY + a.id DESC LIMIT 1 + ) last_question + FROM + gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + $section_where + GROUP BY + t1.id,t5.id + ) tab + GROUP BY + tab.id"; + + // var_dump($sql_event_sections);die(); + + $stmt_event_sections = $this->registry->db->prepare($sql_event_sections); + $stmt_event_sections->execute(); + $gmb_event_sections = $stmt_event_sections->fetchAll(PDO::FETCH_ASSOC); + + // $section_where=[]; + + // array_push($section_where, + // ['field' => 'gmb_events_id','key' => 't1.gmb_events_id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR] + // ); + + // if($params['assesor_id'] != ''){ + // array_push($section_where, + // ['field' => 'id','key' => 't5.id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_STR] + // ); + // } + + // $gmb_event_sections=$this->dbBuilderSelectJoin('gmb_event_sections t1 + // INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + // INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + // INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + // INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + // LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id', + // [ + // 't2.*', + // 'COUNT(t3.id) as total_question', + // 'SUM(IF(t6.id is not null, 1,0)) as total_answer', + // 'ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage', + // 'sum(t3.max_score) as total_max_score', + // 'ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score', + // 'ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2)*100 as ach_result_section', + // 't4.gmb_events_id as event_id', + // '(SELECT + // a.question_code + // FROM + // gmb_questions a + // INNER JOIN gmb_question_section b ON a.gmb_question_section_id = b.id + // WHERE + // b.id=t1.gmb_question_section_id + // ORDER BY + // a.id ASC LIMIT 1 + // ) first_question', + // '(SELECT + // a.question_code + // FROM + // gmb_questions a + // INNER JOIN gmb_question_section b ON a.gmb_question_section_id = b.id + // WHERE + // b.id=t1.gmb_question_section_id + // ORDER BY + // a.id DESC LIMIT 1 + // ) last_question' + // ], + // $section_where, + // " GROUP BY + // t1.id " + // ); + + $gmb_event_types = $this->dbBuilderSelectJoin( + 'gmb_event_types t1 + INNER JOIN gmb_question_types t2 ON t1.gmb_question_types_id = t2.id', + [ + 't2.id', + 't2.type_name as name', + 't1.weight', + '"types" as type' + ], + [ + ['field' => 'gmb_events_id', 'key' => 't1.gmb_events_id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + $gmb_event_category = $this->dbBuilderSelectJoin( + 'gmb_event_category t1 + INNER JOIN gmb_question_category t2 ON t1.gmb_question_category_id = t2.id', + [ + 't2.id', + 't2.category_name as name', + 't1.weight', + '"category" as type' + ], + [ + ['field' => 'gmb_events_id', 'key' => 't1.gmb_events_id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + + $header = array(); + + foreach ($gmb_event_category as $key => $value) { + $gmb_event_category[$key]['total_score'] = 0; + $gmb_event_category[$key]['total_max_score'] = 0; + array_push($header, $gmb_event_category[$key]); + } + + foreach ($gmb_event_types as $key => $value) { + $gmb_event_types[$key]['total_score'] = 0; + $gmb_event_types[$key]['total_max_score'] = 0; + array_push($header, $gmb_event_types[$key]); + } + $total_all_max_score = 0; + foreach ($gmb_event_sections as $i => $vi) { + $category_type = array(); + foreach ($header as $j => $vj) { + $where = $section_where; + + if ($vj['type'] == 'category') { + // array_push($where, + // ['field' => 'gmb_question_category_id','key' => 't3.gmb_question_category_id', 'val' => $vj['id'], 'bind' => PDO::PARAM_STR] + // ); + // array_push($where, + // ['field' => 'gmb_question_section_id','key' => 't2.id', 'val' => $vi['id'], 'bind' => PDO::PARAM_STR] + // ); + + $where .= " AND t2.id={$vi['id']} AND t3.gmb_question_category_id={$vj['id']}"; + + // $category=$this->dbBuilderSelectJoin('gmb_event_sections t1 + // INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + // INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + // INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + // INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + // LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + // INNER JOIN gmb_event_category t7 ON t3.gmb_question_category_id = t7.gmb_question_category_id', + // [ + // 't7.*', + // 'COUNT(t3.id) as total_question', + // 'SUM(IF(t6.id is not null, 1,0)) as total_answer', + // 'ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage', + // 'sum(t3.max_score) as total_max_score', + // 'sum(IFNULL(t6.score,0)) as total_score', + // 'ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t7.weight/100))*100,2) as score', + // 'ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t7.weight/100))/ (t7.weight/100)),2)*100 as ach_result_section', + // 't4.gmb_events_id as event_id' + // ], + // $where, + // " GROUP BY + // t1.id " + // ); + + $sql_category = "SELECT + tab.*, + round(avg(tab.total_score),1) as total_score, + round(avg(tab.total_max_score),1) as total_max_score, + avg(tab.score) as score, + avg(tab.ach_result_section) as ach_result_section + FROM + ( + SELECT + t7.*, + COUNT(t3.id) as total_question, + SUM(IF(t6.id is not null, 1,0)) as total_answer, + ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage, + sum(t3.max_score) as total_max_score, + ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score, + ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2)*100 as ach_result_section, + t4.gmb_events_id as event_id, + sum(IFNULL(t6.score,0)) as total_score + FROM + gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + INNER JOIN gmb_event_category t7 ON t3.gmb_question_category_id = t7.gmb_question_category_id + $where + GROUP BY + t1.id,t5.id + ) tab + GROUP BY + tab.id"; + + // var_dump($sql_category);die(); + + $stmt_category = $this->registry->db->prepare($sql_category); + $stmt_category->execute(); + $category = $stmt_category->fetchAll(PDO::FETCH_ASSOC); + + foreach ($category as $k => $vk) { + $category[$k]['name'] = $header[$j]['name']; + $category[$k]['type'] = $header[$j]['type']; + $header[$j]['total_score'] += $vk['total_score']; + $header[$j]['total_max_score'] += $vk['total_max_score']; + $total_all_max_score += $vk['total_max_score']; + array_push($category_type, $category[$k]); + } + } + + if ($vj['type'] == 'types') { + // array_push($where, + // ['field' => 'gmb_question_types_id','key' => 't3.gmb_question_types_id', 'val' => $vj['id'], 'bind' => PDO::PARAM_STR] + // ); + // array_push($where, + // ['field' => 'gmb_question_section_id','key' => 't2.id', 'val' => $vi['id'], 'bind' => PDO::PARAM_STR] + // ); + // $category=$this->dbBuilderSelectJoin('gmb_event_sections t1 + // INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + // INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + // INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + // INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + // LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + // INNER JOIN gmb_event_types t7 ON t3.gmb_question_types_id = t7.gmb_question_types_id', + // [ + // 't7.*', + // 'COUNT(t3.id) as total_question', + // 'SUM(IF(t6.id is not null, 1,0)) as total_answer', + // 'ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage', + // 'sum(t3.max_score) as total_max_score', + // 'sum(IFNULL(t6.score,0)) as total_score', + // 'ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t7.weight/100))*100,2) as score', + // 'ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t7.weight/100))/ (t7.weight/100)),2)*100 as ach_result_section', + // 't4.gmb_events_id as event_id' + // ], + // $where, + // " GROUP BY + // t1.id " + // ); + + $where .= " AND t2.id={$vi['id']} AND t3.gmb_question_types_id={$vj['id']}"; + + $sql_types = "SELECT + tab.*, + round(avg(tab.total_score),1) as total_score, + round(avg(tab.total_max_score),1) as total_max_score, + avg(tab.score) as score, + avg(tab.ach_result_section) as ach_result_section + FROM + ( + SELECT + t7.*, + COUNT(t3.id) as total_question, + SUM(IF(t6.id is not null, 1,0)) as total_answer, + ROUND((SUM(IF(t6.id is not null, 1,0))/COUNT(t3.id))*100,2) as percentage, + sum(t3.max_score) as total_max_score, + ROUND(((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))*100,2) as score, + ROUND((((sum(IFNULL(t6.score,0)) / sum(t3.max_score)) * (t1.weight/100))/ (t1.weight/100)),2)*100 as ach_result_section, + t4.gmb_events_id as event_id, + sum(IFNULL(t6.score,0)) as total_score + FROM + gmb_event_sections t1 + INNER JOIN gmb_question_section t2 ON t1.gmb_question_section_id = t2.id + INNER JOIN gmb_questions t3 ON t2.id = t3.gmb_question_section_id + INNER JOIN gmb_event_questions t4 ON t1.gmb_events_id = t4.gmb_events_id AND t3.id = t4.gmb_questions_id + INNER JOIN gmb_event_asessor t5 ON t4.gmb_events_id = t5.gmb_events_id + LEFT JOIN gmb_asessor_result t6 ON t4.id = t6.gmb_event_questions_id AND t6.gmb_event_asessor_id = t5.id + INNER JOIN gmb_event_types t7 ON t3.gmb_question_types_id = t7.gmb_question_types_id + $where + GROUP BY + t1.id,t5.id + ) tab + GROUP BY + tab.id"; + + $stmt_types = $this->registry->db->prepare($sql_types); + $stmt_types->execute(); + $types = $stmt_types->fetchAll(PDO::FETCH_ASSOC); + + foreach ($types as $k => $vk) { + $types[$k]['name'] = $header[$j]['name']; + $types[$k]['type'] = $header[$j]['type']; + $header[$j]['total_score'] += $vk['total_score']; + $header[$j]['total_max_score'] += $vk['total_max_score']; + $total_all_max_score += $vk['total_max_score']; + array_push($category_type, $types[$k]); + } + } + } + + $gmb_event_sections[$i]['category_type'] = $category_type; + } + + foreach ($header as $key => $value) { + $header[$key]['percentage_max_score'] = ROUND((($value['total_max_score'] / $total_all_max_score) * 100), 2); + $header[$key]['percentage_score'] = ROUND((($value['total_score'] / $total_all_max_score) * 100), 2); + $header[$key]['total_score_item'] = ROUND((($value['total_score'] / $value['total_max_score']) * 100), 2); + } + + $score_event = array_sum(array_column($gmb_event_sections, 'score')); + $all_weight = array_sum(array_column($gmb_event_sections, 'weight')); + + + $rData['score_event'] = ($score_event / $all_weight) * 100; + $rData['event'] = $event; + $rData['total_all_max_score'] = $total_all_max_score; + $rData['header'] = $header; + $rData['gmb_event_sections'] = $gmb_event_sections; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', Line: ' . $e->getLine() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', Line: ' . $e->getLine() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function sendMail($params, $mail) + { + try { + $profiles = new Profiles($this->registry); + $empReq = $profiles->getEmailInfo(\Helper::getSessionVar('username')); + $empReqto = $profiles->getEmailInfo($params->empno); + + $maildata['address'] = $empReqto[0]['mail_address']; + $maildata['addressname'] = $empReqto[0]['full_name']; + $maildata['empreqname'] = $empReq[0]['full_name']; + $maildata['empreqnik'] = \Helper::getSessionVar('username'); + $maildata['attachmentlocation'] = ''; + $maildata['attachmentfilename'] = ""; + $maildata['subject'] = $params->subject; + // $link=$this->registry->config->server_address . 'gembareport/'. $fileName; + $maildata['link'] = ''; + + $maildata['message'] = " + + + +
+ + + +
+
+
+
+

Dear " . $empReqto[0]['full_name'] . ",

+

" . $params->content . "

+
+
+ Regards,
+ HCPORTAL SYSTEM

+
Email is sent automatically by the hcportal system [" . \Helper::ubah_tgl_no_space(date('Y-m-d')) . "]
Please do not reply!

+ "; + + return $mail->sendMail($maildata); + } catch (PDOException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function saveDataIssues($attributes, $mail, $isUpdate = false) + { + $this->registry->db->beginTransaction(); + try { + + $nik = \Helper::getSessionVar('username'); + $message = "PAYROLL.MESSAGE.FAILMESERRREQ"; + $status = "PAYROLL.MESSAGE.FAILED"; + + $response = $this->sendResponse([], $message, $status); + + $stmtIns = $this->setStatementInsStatus(); + $stmtUpd = $this->setStatementUpdStatus(); + + $attributes->due_date = \Helper::utcToIso($attributes->due_date); + $dataExist = $this->checkDataIfExist($attributes); + if ($dataExist) { + $stmt = $stmtUpd; + } else { + $stmt = $stmtIns; + } + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + $result = $this->processData($stmt, $attributes, $nik); + if ($result) { + if (isset($attributes->empno) && !empty($attributes->empno)) { + $attributes->subject = "GENBA - PIC assignment"; + $attributes->content = "Dengan berlangsungnya kegiatan GENBA, kami menugaskan bapak/ibu untuk menjadi PIC dalam menghandle issue assessment tentng " . $attributes->issues . "."; + $setMail = $this->sendMail($attributes, $mail); + } + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + $response = $this->sendResponse([], $message, $status); + + $this->registry->db->commit(); + } + + return $response; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + private function processData($stmt, $attributes, $nik) + { + try { + $stmt->bindValue(':gmb_asessor_result_id', $attributes->gmb_asessor_result_id, PDO::PARAM_STR); + $stmt->bindValue(':note', $attributes->note, PDO::PARAM_STR); + $stmt->bindValue(':pic', $attributes->empno, PDO::PARAM_STR); + $stmt->bindValue(':risk_level', $attributes->risk_level, PDO::PARAM_STR); + $stmt->bindValue(':status', $attributes->status, PDO::PARAM_STR); + $stmt->execute(); + + return true; + } catch (PDOexception $e) { + $this->registry + ->log + ->error('Message :' + . $e->getMessage() . ', Line: ' + . $e->getLine() . ', File: ' + . $e->getFile() . ', User: ' + . $nik); + + return false; + } catch (ErrorException $e) { + $this->registry + ->log + ->error('Message :' + . $e->getMessage() . ', Line: ' + . $e->getLine() . ', File: ' + . $e->getFile() . ', User: ' + . $nik); + + return false; + } + } + + public function checkDataIfExist($attributes) + { + try { + $stmt = $this->setStatementGetStatus(); + $stmt->bindValue(':id', $attributes->gmb_asessor_result_id, PDO::PARAM_STR); + $stmt->execute(); + + return $stmt->rowCount() > 0 ? true : false; + } catch (PDOException $e) { + $this->registry->log->error('message: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('message: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getResponsCount($stmt, $id) + { + try { + $stmt->bindValue(':id', $id, PDO::PARAM_STR); + $stmt->execute(); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + return count($rs) > 0 ? $rs[0]['total'] : 0; + } catch (PDOException $e) { + $this->registry->log->error('message: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('message: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function updateGeneralIssues($attributes) + { + $this->registry->db->beginTransaction(); + try { + + $nik = \Helper::getSessionVar('username'); + $message = "PAYROLL.MESSAGE.FAILMESERRREQ"; + $status = "PAYROLL.MESSAGE.FAILED"; + + $response = $this->sendResponse([], $message, $status); + + $stmt = $this->setStatementUpdDueDate(); + + $attributes->due_date = \Helper::utcToIso($attributes->due_date); + + $stmt->bindValue(':id', $attributes->id, PDO::PARAM_STR); + // $stmt->bindValue(':due_date', $attributes->due_date, PDO::PARAM_STR); + $stmt->bindValue(':pic', $attributes->empno, PDO::PARAM_STR); + $stmt->execute(); + + if ($stmt) { + if (isset($attributes->empno) && !empty($attributes->empno)) { + $attributes->subject = "GENBA - PIC assignment"; + $attributes->content = "Dengan berlangsungnya kegiatan GENBA, kami menugaskan bapak/ibu untuk menjadi PIC dalam menghandle issue general."; + // $setMail = $this->sendMail($attributes, $mail); + } + $message = "PAYROLL.MESSAGE.SUCCMESUPD"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + $response = $this->sendResponse([], $message, $status); + + $this->registry->db->commit(); + } + + return $response; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function updateReportName($params, $file_name) + { + try { + $this->registry->db->beginTransaction(); + + if (!$params['assesor_id']) { + $event_update = $this->dbBuilderUpdate('gmb_events', [ + ['key' => 'file_report', 'val' => $file_name, 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_INT], + ]); + + if (!$event_update) { + return false; + } + } else { + $event_update = $this->dbBuilderUpdate('gmb_event_asessor', [ + ['key' => 'file_report', 'val' => $file_name, 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_INT], + ]); + + if (!$event_update) { + return false; + } + } + + + $this->registry->db->commit(); + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-updateReportName: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-updateReportName: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function sendReport($params, $mail) + { + try { + + $fileName = ''; + if (!$params['assesor_id']) { + $rs = $this->dbBuilderSelectJoin( + 'gmb_events t1', + [ + 't1.file_report' + ], + [ + ['field' => 'id', 'key' => 't1.id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR] + ] + ); + + + if (count($rs) > 0) { + $fileName = $rs[0]['file_report']; + } + } else { + $rs = $this->dbBuilderSelectJoin( + 'gmb_event_asessor t1', + [ + 't1.file_report' + ], + [ + ['field' => 'id', 'key' => 't1.id', 'val' => $params['assesor_id'], 'bind' => PDO::PARAM_STR] + ] + ); + + + if (count($rs) > 0) { + $fileName = $rs[0]['file_report']; + } + } + + $mail_list = explode(';', $params['mail']); + $address = $mail_list[0]; + + if (count($mail_list) > 0) { + array_splice($mail_list, 0, 1); + } + + $address_cc = $mail_list; + + $maildata['address'] = $address; + $maildata['address_cc_mail'] = $address_cc; + $maildata['addressname'] = ""; + $maildata['empreqname'] = ""; + $maildata['attachmentlocation'] = ''; + $maildata['attachmentfilename'] = $fileName; + $maildata['subject'] = "Genba Result Report"; + $link = $this->registry->config->base_link_access_doc . '/gembareport/' . $fileName; + $maildata['link'] = ''; + + + + $rsmail = $mail->sendMail($maildata); + // var_dump($rsmail);die(); + + if (!$rsmail) { + throw new Exception("3"); + } + // } + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + $response = $this->sendResponse([], $message, $status); + + return $response; + } catch (PDOException $e) { + $this->registry->log->error('module Admin / sendReport:' . $e->getMessage() . 'line :' . $e->getLine()); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module Admin / sendReport:' . $e->getMessage() . 'line :' . $e->getLine()); + return false; + } + } + + public function getDataQuestionGroup() + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_group t1', + [ + 't1.*', + '0 as edit' + ], + [] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataManufatureProduct() + { + try { + $rs = $this->dbBuilderSelectJoin( + 'ref_manufacture_products t1 + INNER JOIN ref_manunfactures t2 ON t1.ref_manunfactures_id = t2.id + INNER JOIN ref_master_category_product_plant t3 ON t1.ref_master_category_product_plant_id = t3.id', + [ + 't1.*', + 't2.plan_name', + 't3.category_name' + ], + [] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function setMarkAsRead($attributes) + { + $this->registry->db->beginTransaction(); + try { + $nik = \Helper::getSessionVar('username'); + + $message = "PAYROLL.MESSAGE.FAILMESERRREQ"; + $status = "PAYROLL.MESSAGE.FAILED"; + + $response = $this->sendResponse([], $message, $status); + + $stmtCheckGenIssue = $this->setStatementCheckGenIssueRead(); + $stmtInsGenIssue = $this->setStatementInsGenIssueRead(); + $stmtCheckIssue = $this->setStatementCheckIssueRead(); + $stmtInsIssue = $this->setStatementInsIssueRead(); + + $stmtCheck = $stmtCheckIssue; + $stmtIns = $stmtInsIssue; + if ($attributes['source'] == 'general') { + $stmtCheck = $stmtCheckGenIssue; + $stmtIns = $stmtInsGenIssue; + } + + $check = $this->processByIdAndNik($stmtCheck, $attributes['id'], $nik); + if ($check->rowCount() == 0) { + $rs = $this->processByIdAndNik($stmtIns, $attributes['id'], $nik); + if ($rs) { + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + } + } + + $response = $this->sendResponse([], $message, $status); + + $this->registry->db->commit(); + + return [$response]; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function processByIdAndNik($stmt, $id, $nik) + { + try { + $stmt->bindValue(':id', $id, PDO::PARAM_STR); + $stmt->bindValue(':nik', $nik, PDO::PARAM_STR); + $stmt->execute(); + + return $stmt; + } catch (PDOException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('Message: ' . $e->getMessage() . ' Line: ' . $e->getLine() . ' File: ' . $e->getFile() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function viewDataMasterQuestionCategory($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_category t1', + [ + 't1.*' + ], + [ + ['field' => 'category_name', 'key' => 't1.category_name', 'val' => $params['category_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmb_question_category t1', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestionCategory($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmb_question_category', + [ + ['key' => 'category_name', 'val' => $data->category_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmb_question_category', + [ + ['key' => 'category_name', 'val' => $data->category_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionCategory: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionCategory: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestionCategory($id) + { + try { + + $this->registry->db->beginTransaction(); + + + $this->dbBuilderDelete('gmb_question_category', 'id', $id); + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionCategory: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionCategory: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterQuestionGroup($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_group t1', + [ + 't1.*' + ], + [ + ['field' => 'group_name', 'key' => 't1.group_name', 'val' => $params['group_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmb_question_group t1', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestionGroup($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmb_question_group', + [ + ['key' => 'group_name', 'val' => $data->group_name, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmb_question_group', + [ + ['key' => 'group_name', 'val' => $data->group_name, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionGroup: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionGroup: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestionGroup($id) + { + try { + + $this->registry->db->beginTransaction(); + + + $this->dbBuilderDelete('gmb_question_group', 'id', $id); + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionGroup: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionGroup: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterQuestionSection($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_section t1 + INNER JOIN ref_manufacture_products t2 ON t1.ref_manufacture_products_id = t2.id + INNER JOIN ref_manunfactures t3 ON t2.ref_manunfactures_id = t3.id + INNER JOIN ref_master_category_product_plant t4 ON t2.ref_master_category_product_plant_id = t4.id', + [ + 't1.*', + 't3.plan_name', + 't4.category_name' + ], + [ + ['field' => 'ref_manufacture_products_id', 'key' => 't1.ref_manufacture_products_id', 'val' => $params['ref_manufacture_products_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'ref_manufacture_products_id', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'section_name', 'key' => 't1.section_name', 'val' => $params['section_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE', 'start_symbol' => ' ( '], + ['field' => 'section_code', 'key' => 't1.section_code', 'val' => $params['section_code'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE', 'end_symbol' => ' ) '], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmb_question_section t1', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestionSection($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmb_question_section', + [ + ['key' => 'section_name', 'val' => $data->section_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'section_code', 'val' => $data->section_code, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manufacture_products_id', 'val' => $data->ref_manufacture_products_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmb_question_section', + [ + ['key' => 'section_name', 'val' => $data->section_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'section_code', 'val' => $data->section_code, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manufacture_products_id', 'val' => $data->ref_manufacture_products_id, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionSection: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionSection: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestionSection($id) + { + try { + + $this->registry->db->beginTransaction(); + + + $this->dbBuilderDelete('gmb_question_section', 'id', $id); + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionSection: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionSection: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterQuestionType($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmb_question_types t1', + [ + 't1.*' + ], + [ + ['field' => 'type_name', 'key' => 't1.type_name', 'val' => $params['type_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ['field' => 'code_type', 'key' => 't1.code_type', 'val' => $params['code_type'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmb_question_types t1', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestionType($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmb_question_types', + [ + ['key' => 'type_name', 'val' => $data->type_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'code_type', 'val' => $data->code_type, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmb_question_types', + [ + ['key' => 'type_name', 'val' => $data->type_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'code_type', 'val' => $data->code_type, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionType: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionType: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestionType($id) + { + try { + + $this->registry->db->beginTransaction(); + + + $this->dbBuilderDelete('gmb_question_types', 'id', $id); + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionType: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionType: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterQuestion($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmb_questions t1 + INNER JOIN gmb_question_group t2 ON t1.gmb_question_group_id = t2.id + INNER JOIN gmb_question_types t3 ON t1.gmb_question_types_id = t3.id + INNER JOIN gmb_question_category t4 ON t1.gmb_question_category_id = t4.id + INNER JOIN gmb_question_section t5 ON t1.gmb_question_section_id = t5.id + INNER JOIN ref_manufacture_products t6 ON t5.ref_manufacture_products_id = t6.id + INNER JOIN ref_manunfactures t7 ON t6.ref_manunfactures_id = t7.id + INNER JOIN ref_master_category_product_plant t8 ON t6.ref_master_category_product_plant_id = t8.id', + [ + 't1.*', + 't2.group_name', + 't3.type_name', + 't4.category_name', + 't5.section_name', + 't7.plan_name', + 't8.category_name as category_product_name' + ], + [ + ['field' => 'question_code', 'key' => 't1.question_code', 'val' => $params['question_code'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ['field' => 'question', 'key' => 't1.question', 'val' => $params['question'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ['field' => 'question_description', 'key' => 't1.question_description', 'val' => $params['question_description'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ['field' => 'is_need_upload_file', 'key' => 't1.is_need_upload_file', 'val' => $params['is_need_upload_file'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'is_need_upload_file', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => $params['is_publish'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'is_publish', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'gmb_question_types_id', 'key' => 't1.gmb_question_types_id', 'val' => $params['gmb_question_types_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'gmb_question_types_id', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'gmb_question_group_id', 'key' => 't1.gmb_question_group_id', 'val' => $params['gmb_question_group_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'gmb_question_group_id', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'gmb_question_category_id', 'key' => 't1.gmb_question_category_id', 'val' => $params['gmb_question_category_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'gmb_question_category_id', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'gmb_question_section_id', 'key' => 't1.gmb_question_section_id', 'val' => $params['gmb_question_section_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'gmb_question_section_id', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ['field' => 'ref_manufacture_products_id', 'key' => 't5.ref_manufacture_products_id', 'val' => $params['ref_manufacture_products_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( '], + ['field' => 'ref_manufacture_products_id', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'end_symbol' => ' ) ', 'exp' => ' OR '], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmb_questions t1', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestion($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmb_questions', + [ + ['key' => 'section_name', 'val' => $data->section_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'section_code', 'val' => $data->section_code, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manufacture_products_id', 'val' => $data->ref_manufacture_products_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmb_questions', + [ + ['key' => 'section_name', 'val' => $data->section_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ['key' => 'section_code', 'val' => $data->section_code, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manufacture_products_id', 'val' => $data->ref_manufacture_products_id, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestion: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestion: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestion($id) + { + try { + + $this->registry->db->beginTransaction(); + + + $this->dbBuilderDelete('gmb_questions', 'id', $id); + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestion: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestion: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function getDataCompany() + { + try { + $rs = $this->dbBuilderSelectJoin( + 'company t1', + [ + 't1.*' + ], + [] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataSubArea($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'sub_area t1', + [ + 't1.*' + ], + [ + ['field' => 'company_id', 'key' => 't1.company_id', 'val' => $params['company_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataSubAreaRefManufacture($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'sub_area t1 + INNER JOIN ref_manufacture_sub_area t2 ON t1.id=t2.sub_area_id', + [ + 't1.*' + ], + [ + ['field' => 'ref_manunfactures_id', 'key' => 't2.ref_manunfactures_id', 'val' => $params['ref_manunfactures_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataGedung($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gedung t1', + [ + 't1.*' + ], + [ + ['field' => 'sub_area_id', 'key' => 't1.sub_area_id', 'val' => $params['sub_area_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataRefShiftGroup($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'ref_shift_group t1', + [ + 't1.*' + ], + [ + ['field' => 'sub_area_id', 'key' => 't1.sub_area_id', 'val' => $params['sub_area_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataSector($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gedung_sector t1', + [ + 't1.*' + ], + [ + ['field' => 'gedung_id', 'key' => 't1.gedung_id', 'val' => $params['gedung_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataLine($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gedung_sector_line t1', + [ + 't1.*' + ], + [ + ['field' => 'gedung_sector_id', 'key' => 't1.gedung_sector_id', 'val' => $params['sector_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataDivision($params) + { + try { + + if (isset($params['company_id'])) { + $company = $params['company_id']; + } else { + $company = \Helper::getSessionVar('empSite'); + } + + $rs = $this->dbBuilderSelectJoin( + 'division t1 + INNER JOIN `division_department` t2 ON t1.`id` = t2.`division_id`', + [ + 'DISTINCT(t1.`id`)', + 't1.`description`' + ], + [ + ['field' => 'bu', 'key' => 't2.bu', 'val' => $company, 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataDepartment($params) + { + try { + + $where = []; + + if (isset($params['company_id'])) { + $company = $params['company_id']; + } else { + $company = \Helper::getSessionVar('empSite'); + } + + + array_push($where, ['field' => 'bu', 'key' => 't1.bu', 'val' => $company, 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + + + if (isset($params['division_id'])) { + array_push($where, ['field' => 'division_id', 'key' => 't1.division_id', 'val' => $params['division_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + $rs = $this->dbBuilderSelectJoin( + '`division_department` t1 INNER JOIN + `department` t2 ON t1.`department_id` = t2.`id`', + [ + 't2.id', + 't2.description' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataBusinessUnit($params) + { + try { + $where = []; + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => 1, 'bind' => PDO::PARAM_STR]); + + if (isset($params['line_id'])) { + array_push($where, ['field' => 'gedung_sector_line_id', 'key' => 't1.gedung_sector_line_id', 'val' => $params['line_id'], 'bind' => PDO::PARAM_STR]); + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_business_unit t1 + INNER JOIN gedung_sector_line t2 ON t1.gedung_sector_line_id = t2.id + INNER JOIN gedung_sector t3 ON t2.gedung_sector_id = t3.id + INNER JOIN gedung t4 ON t3.gedung_id = t4.id', + [ + 't1.*', + 't2.line_number', + 't3.sector_name', + 't4.gedung_name' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataSection($params) + { + try { + $where = []; + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => 1, 'bind' => PDO::PARAM_STR]); + + if (isset($params['gmbs_business_unit_id'])) { + array_push($where, ['field' => 'gmbs_business_unit_id', 'key' => 't1.gmbs_business_unit_id', 'val' => $params['gmbs_business_unit_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if (isset($params['department_id'])) { + array_push($where, ['field' => 'department_id', 'key' => 't1.department_id', 'val' => $params['department_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_question_section t1 + INNER JOIN gmbs_business_unit t2 ON t1.gmbs_business_unit_id = t2.id + INNER JOIN gedung_sector_line t3 ON t2.gedung_sector_line_id = t3.id + INNER JOIN gedung_sector t4 ON t3.gedung_sector_id = t4.id + INNER JOIN gedung t5 ON t4.gedung_id = t5.id + INNER JOIN sub_area t6 ON t5.sub_area_id = t6.id + INNER JOIN company t7 ON t6.company_id = t7.id + INNER JOIN department t8 ON t1.department_id = t8.id', + [ + 't1.*', + 't2.bu_name', + 't7.description as company_name', + 't6.description as sub_area_name', + 't5.gedung_name as gedung_name', + 't4.sector_name as sector_name', + 't3.line_number as line_name', + 't8.description as department_name' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataCategory() + { + try { + $where = []; + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => 1, 'bind' => PDO::PARAM_STR]); + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_question_category t1', + [ + 't1.*' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataRiskLevel() + { + try { + $where = []; + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => 1, 'bind' => PDO::PARAM_STR]); + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_ref_risk_level t1', + [ + 't1.*' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataWorkScopes() + { + try { + $where = []; + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => 1, 'bind' => PDO::PARAM_STR]); + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_ref_work_scopes t1', + [ + 't1.*' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterRefBusinessUnit($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmbs_ref_business_unit', + [ + ['key' => 'bu_name', 'val' => $data->bu_name, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $data->description, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manunfactures_id', 'val' => $data->ref_manunfactures_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmbs_ref_business_unit', + [ + ['key' => 'bu_name', 'val' => $data->bu_name, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $data->description, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_manunfactures_id', 'val' => $data->ref_manunfactures_id, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterRefBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterRefBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterRefBusinessUnit($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_ref_business_unit t1 + INNER JOIN ref_manunfactures t2 ON t1.ref_manunfactures_id = t2.id ', + [ + 't1.id', + 't1.bu_name', + 't1.description', + 't1.ref_manunfactures_id as ref_manunfactures_id', + 't2.plan_name' + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR], + ['field' => 'bu_name', 'key' => 't1.bu_name', 'val' => $params['bu_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_ref_business_unit t1 + INNER JOIN ref_manunfactures t2 ON t1.ref_manunfactures_id = t2.id ', + [ + 'count(t1.id) as total', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR], + ] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterBusinessUnit($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + $gmbs_ref_business_unit = $this->dbBuilderSelectJoin( + 'gmbs_ref_business_unit t1', + [ + 't1.*' + ], + [ + ['field' => 'id', 'key' => 't1.id', 'val' => $data->gmbs_ref_business_unit_id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmbs_business_unit', + [ + ['key' => 'bu_name', 'val' => $gmbs_ref_business_unit[0]['bu_name'], 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $gmbs_ref_business_unit[0]['description'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_business_unit_id', 'val' => $data->gmbs_ref_business_unit_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gedung_sector_line_id', 'val' => $data->line_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmbs_business_unit', + [ + ['key' => 'bu_name', 'val' => $gmbs_ref_business_unit[0]['bu_name'], 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $gmbs_ref_business_unit[0]['description'], 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_business_unit_id', 'val' => $data->gmbs_ref_business_unit_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gedung_sector_line_id', 'val' => $data->line_id, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + $message = "Terjadi duplikasi data dalam insert / update data"; + $status = "PAYROLL.MESSAGE.FAILED"; + + $this->sendResponse([], $message, $status); + + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterBusinessUnit($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_business_unit t1 + INNER JOIN gedung_sector_line t2 ON t1.gedung_sector_line_id = t2.id + INNER JOIN gedung_sector t3 ON t2.gedung_sector_id = t3.id + INNER JOIN gedung t4 ON t3.gedung_id = t4.id + INNER JOIN sub_area t5 ON t4.sub_area_id = t5.id + INNER JOIN company t6 ON t5.company_id = t6.id + INNER JOIN gmbs_ref_business_unit t7 ON t1.gmbs_ref_business_unit_id = t7.id', + [ + 't1.id', + 't1.bu_name', + 't1.description', + 't1.gedung_sector_line_id as line_id', + 't2.gedung_sector_id as sector_id', + 't3.gedung_id', + 't4.sub_area_id', + 't5.company_id', + 't6.description as company_name', + 't5.description as sub_area_name', + 't4.gedung_name as gedung_name', + 't3.sector_name as sector_name', + 't2.line_number as line_name', + 't1.gmbs_ref_business_unit_id as gmbs_ref_business_unit_id', + 't7.ref_manunfactures_id as ref_manunfactures_id' + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR], + ['field' => 'bu_name', 'key' => 't1.bu_name', 'val' => $params['bu_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ['field' => 'bu_name', 'key' => 't1.bu_name', 'val' => $params['search'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_business_unit t1 + INNER JOIN gedung_sector_line t2 ON t1.gedung_sector_line_id = t2.id + INNER JOIN gedung_sector t3 ON t2.gedung_sector_id = t3.id + INNER JOIN gedung t4 ON t3.gedung_id = t4.id + INNER JOIN sub_area t5 ON t4.sub_area_id = t5.id + INNER JOIN company t6 ON t5.company_id = t6.id', + [ + 'count(t1.id) as total', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR], + ['field' => 'bu_name', 'key' => 't1.bu_name', 'val' => $params['bu_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ['field' => 'bu_name', 'key' => 't1.bu_name', 'val' => $params['search'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestionCategorySelf($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmbs_question_category', + [ + ['key' => 'category_name', 'val' => $data->category_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmbs_question_category', + [ + ['key' => 'category_name', 'val' => $data->category_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionCategorySelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionCategorySelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterQuestionCategorySelf($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_question_category t1', + [ + 't1.*' + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR], + ['field' => 'category_name', 'key' => 't1.category_name', 'val' => $params['category_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_question_category t1', + [ + 'count(t1.id) as total', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR] + ] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterQuestionSectionSelf($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + foreach ($data->section_list as $key => $value) { + $master = $this->dbBuilderInsert( + 'gmbs_question_section', + [ + ['key' => 'section_name', 'val' => $value->section_name, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_business_unit_id', 'val' => $data->gmbs_business_unit_id, 'bind' => PDO::PARAM_STR], + ['key' => 'department_id', 'val' => $data->department_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } + } else { + foreach ($data->section_list as $key => $value) { + $master_update = $this->dbBuilderUpdate( + 'gmbs_question_section', + [ + ['key' => 'section_name', 'val' => $value->section_name, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_business_unit_id', 'val' => $data->gmbs_business_unit_id, 'bind' => PDO::PARAM_STR], + ['key' => 'department_id', 'val' => $data->department_id, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionSectionSelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterQuestionSectionSelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterQuestionSectionSelf($params) + { + try { + + $where = []; + + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR]); + + array_push($where, ['field' => 'company_id', 'key' => 't6.company_id', 'val' => $params['company_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'company_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gmbs_business_unit_id', 'key' => 't1.gmbs_business_unit_id', 'val' => $params['gmbs_business_unit_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gmbs_business_unit_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'line_id', 'key' => 't2.gedung_sector_line_id', 'val' => $params['line_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'line_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'sector_id', 'key' => 't3.gedung_sector_id', 'val' => $params['sector_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'sector_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gedung_id', 'key' => 't4.gedung_id', 'val' => $params['gedung_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gedung_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'sub_area_id', 'key' => 't5.sub_area_id', 'val' => $params['sub_area_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'sub_area_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'department_id', 'key' => 't1.department_id', 'val' => $params['department_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'department_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + if ($params['section_name']) { + array_push($where, ['field' => 'section_name', 'key' => 't1.section_name', 'val' => $params['section_name'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_question_section t1 + INNER JOIN gmbs_business_unit t2 ON t1.gmbs_business_unit_id = t2.id + INNER JOIN gedung_sector_line t3 ON t2.gedung_sector_line_id = t3.id + INNER JOIN gedung_sector t4 ON t3.gedung_sector_id = t4.id + INNER JOIN gedung t5 ON t4.gedung_id = t5.id + INNER JOIN sub_area t6 ON t5.sub_area_id = t6.id + INNER JOIN company t7 ON t6.company_id = t7.id + INNER JOIN department t8 ON t1.department_id = t8.id', + [ + 't1.id', + 't1.section_name', + 't1.gmbs_business_unit_id', + 't1.department_id', + 't2.bu_name', + 't2.gedung_sector_line_id as line_id', + 't3.gedung_sector_id as sector_id', + 't4.gedung_id', + 't5.sub_area_id', + 't6.company_id', + 't7.description as company_name', + 't6.description as sub_area_name', + 't5.gedung_name as gedung_name', + 't4.sector_name as sector_name', + 't3.line_number as line_name', + 't8.description as department_name' + ], + $where, + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_question_section t1 + INNER JOIN gmbs_business_unit t2 ON t1.gmbs_business_unit_id = t2.id + INNER JOIN gedung_sector_line t3 ON t2.gedung_sector_line_id = t3.id + INNER JOIN gedung_sector t4 ON t3.gedung_sector_id = t4.id + INNER JOIN gedung t5 ON t4.gedung_id = t5.id + INNER JOIN sub_area t6 ON t5.sub_area_id = t6.id + INNER JOIN company t7 ON t6.company_id = t7.id + INNER JOIN department t8 ON t1.department_id = t8.id', + [ + 'count(t1.id) as total', + ], + $where + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterRiskLevel($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmbs_ref_risk_level', + [ + ['key' => 'risk_level_name', 'val' => $data->risk_level_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmbs_ref_risk_level', + [ + ['key' => 'risk_level_name', 'val' => $data->risk_level_name, 'bind' => PDO::PARAM_STR], + ['key' => 'weight', 'val' => $data->weight, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterRiskLevel: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterRiskLevel: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterRiskLevel($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_ref_risk_level t1', + [ + 't1.*', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR] + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_ref_risk_level t1', + [ + 'count(t1.id) as total', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR] + ] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterWorkScopes($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmbs_ref_work_scopes', + [ + ['key' => 'scope_name', 'val' => $data->scope_name, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $data->description, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmbs_ref_work_scopes', + [ + ['key' => 'scope_name', 'val' => $data->scope_name, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $data->description, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterWorkScopes: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterWorkScopes: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterWorkScopes($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_ref_work_scopes t1', + [ + 't1.*', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR] + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_ref_work_scopes t1', + [ + 'count(t1.id) as total', + ], + [ + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR] + ] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataMasterActivities($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + foreach ($data->activities as $key => $value) { + $master = $this->dbBuilderInsert( + 'gmbs_activities', + [ + ['key' => 'order_no', 'val' => $value->order_no, 'bind' => PDO::PARAM_STR], + ['key' => 'is_publish', 'val' => $value->is_publish, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $value->description, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $value->description, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_question_category_id', 'val' => $value->gmbs_question_category_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_question_section_id', 'val' => $data->gmbs_question_section_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_risk_level_id', 'val' => $value->gmbs_ref_risk_level_id, 'bind' => PDO::PARAM_STR], + ['key' => 'reference_link', 'val' => $value->reference_link, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + + foreach ($value->answer_detail as $j => $vj) { + $detail = $this->dbBuilderInsert( + 'gmbs_answer_detail', + [ + ['key' => 'answer_score', 'val' => $vj->answer_score, 'bind' => PDO::PARAM_STR], + ['key' => 'answer_label', 'val' => $vj->answer_label, 'bind' => PDO::PARAM_STR], + ['key' => 'order', 'val' => $vj->order, 'bind' => PDO::PARAM_STR], + ['key' => 'qualitative_answer', 'val' => $vj->qualitative_answer, 'bind' => PDO::PARAM_STR], + ['key' => 'is_require_note', 'val' => $vj->is_require_note, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_activities_id', 'val' => $master, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$detail) { + return false; + } + } + } + } else { + foreach ($data->activities as $key => $value) { + $master_update = $this->dbBuilderUpdate( + 'gmbs_activities', + [ + ['key' => 'order_no', 'val' => $value->order_no, 'bind' => PDO::PARAM_STR], + ['key' => 'is_publish', 'val' => $value->is_publish, 'bind' => PDO::PARAM_STR], + ['key' => 'description', 'val' => $value->description, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_question_category_id', 'val' => $value->gmbs_question_category_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_question_section_id', 'val' => $data->gmbs_question_section_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_risk_level_id', 'val' => $value->gmbs_ref_risk_level_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_ref_work_scopes_id', 'val' => $value->gmbs_ref_work_scopes_id, 'bind' => PDO::PARAM_STR], + ['key' => 'reference_link', 'val' => $value->reference_link, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + + $this->dbBuilderDelete('gmbs_answer_detail', 'gmbs_activities_id', $data->id); + + foreach ($value->answer_detail as $j => $vj) { + $detail = $this->dbBuilderInsert( + 'gmbs_answer_detail', + [ + ['key' => 'answer_score', 'val' => $vj->answer_score, 'bind' => PDO::PARAM_STR], + ['key' => 'answer_label', 'val' => $vj->answer_label, 'bind' => PDO::PARAM_STR], + ['key' => 'order', 'val' => $vj->order, 'bind' => PDO::PARAM_STR], + ['key' => 'qualitative_answer', 'val' => $vj->qualitative_answer, 'bind' => PDO::PARAM_STR], + ['key' => 'is_require_note', 'val' => $vj->is_require_note, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_activities_id', 'val' => $data->id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$detail) { + return false; + } + } + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterActivities: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataMasterActivities: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataMasterActivities($params) + { + try { + + $where = []; + array_push($where, ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => '1', 'bind' => PDO::PARAM_STR]); + + array_push($where, ['field' => 'gmbs_question_category_id', 'key' => 't1.gmbs_question_category_id', 'val' => $params['gmbs_question_category_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gmbs_question_category_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gmbs_question_section_id', 'key' => 't1.gmbs_question_section_id', 'val' => $params['gmbs_question_section_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gmbs_question_section_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gmbs_ref_risk_level_id', 'key' => 't1.gmbs_ref_risk_level_id', 'val' => $params['gmbs_ref_risk_level_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gmbs_ref_risk_level_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gmbs_ref_work_scopes_id', 'key' => 't1.gmbs_ref_work_scopes_id', 'val' => $params['gmbs_ref_work_scopes_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gmbs_ref_work_scopes_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gmbs_business_unit_id', 'key' => 't3.gmbs_business_unit_id', 'val' => $params['gmbs_business_unit_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gmbs_business_unit_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'line_id', 'key' => 't6.gedung_sector_line_id', 'val' => $params['line_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'line_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'sector_id', 'key' => 't7.gedung_sector_id', 'val' => $params['sector_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'sector_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'gedung_id', 'key' => 't8.gedung_id', 'val' => $params['gedung_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'gedung_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'sub_area_id', 'key' => 't9.sub_area_id', 'val' => $params['sub_area_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'sub_area_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + array_push($where, ['field' => 'department_id', 'key' => 't3.department_id', 'val' => $params['department_id'], 'bind' => PDO::PARAM_STR, 'start_symbol' => ' ( ']); + array_push($where, ['field' => 'department_id', 'key' => '', 'val' => 'all', 'bind' => PDO::PARAM_STR, 'exp' => ' OR ', 'end_symbol' => ' ) ']); + + if ($params['description']) { + array_push($where, ['field' => 'description', 'key' => 't1.description', 'val' => $params['description'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['search']) { + array_push($where, ['field' => 'description', 'key' => 't1.description', 'val' => $params['search'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_activities t1 + INNER JOIN gmbs_question_category t2 ON t1.gmbs_question_category_id = t2.id + INNER JOIN gmbs_question_section t3 ON t1.gmbs_question_section_id = t3.id + INNER JOIN gmbs_ref_risk_level t4 ON t1.gmbs_ref_risk_level_id = t4.id + INNER JOIN gmbs_ref_work_scopes t5 ON t1.gmbs_ref_work_scopes_id = t5.id + INNER JOIN gmbs_business_unit t6 ON t3.gmbs_business_unit_id = t6.id + INNER JOIN gedung_sector_line t7 ON t6.gedung_sector_line_id = t7.id + INNER JOIN gedung_sector t8 ON t7.gedung_sector_id = t8.id + INNER JOIN gedung t9 ON t8.gedung_id = t9.id + INNER JOIN sub_area t10 ON t9.sub_area_id = t10.id + INNER JOIN ref_manufacture_sub_area t11 ON t11.sub_area_id = t10.id + INNER JOIN ref_manunfactures t12 ON t11.ref_manunfactures_id = t12.id + INNER JOIN department t13 ON t3.department_id = t13.id', + [ + 't1.id', + 't1.order_no', + 't1.is_publish', + 't1.description', + 't1.reference_link', + 't1.gmbs_question_category_id', + 't1.gmbs_question_section_id', + 't1.gmbs_ref_risk_level_id', + 't1.gmbs_ref_work_scopes_id', + 't2.category_name', + 't3.section_name', + 't4.risk_level_name', + 't5.scope_name', + 't12.plan_name as ref_manufacture', + 't10.description as sub_area', + 't9.gedung_name as gedung', + 't8.sector_name as sector', + 't7.line_number as line', + 't7.line_number as line', + 't13.description as department', + 't6.bu_name as bu_name', + ], + $where, + "ORDER BY t3.section_name ASC, t1.order_no ASC LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_activities t1 + INNER JOIN gmbs_question_category t2 ON t1.gmbs_question_category_id = t2.id + INNER JOIN gmbs_question_section t3 ON t1.gmbs_question_section_id = t3.id + INNER JOIN gmbs_ref_risk_level t4 ON t1.gmbs_ref_risk_level_id = t4.id + INNER JOIN gmbs_ref_work_scopes t5 ON t1.gmbs_ref_work_scopes_id = t5.id + INNER JOIN gmbs_business_unit t6 ON t3.gmbs_business_unit_id = t6.id + INNER JOIN gedung_sector_line t7 ON t6.gedung_sector_line_id = t7.id + INNER JOIN gedung_sector t8 ON t7.gedung_sector_id = t8.id + INNER JOIN gedung t9 ON t8.gedung_id = t9.id + INNER JOIN sub_area t10 ON t9.sub_area_id = t10.id', + [ + 'count(t1.id) as total', + ], + $where + ); + + foreach ($rs as $key => $value) { + $rs[$key]['answer_detail'] = $this->dbBuilderSelectJoin( + 'gmbs_answer_detail t1', + [ + 't1.*', + ], + [ + ['field' => 'gmbs_activities_id', 'key' => 't1.gmbs_activities_id', 'val' => $value['id']], + ] + ); + } + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataLineRunning($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + if (!isset($data->id)) { + $master = $this->dbBuilderInsert( + 'gmbs_line_running', + [ + ['key' => 'running_date', 'val' => date('Y-m-d', strtotime($data->running_date)), 'bind' => PDO::PARAM_STR], + ['key' => 'ref_shift_group_id', 'val' => $data->ref_shift_group_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gedung_sector_line_id', 'val' => $data->line_id, 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } else { + $master_update = $this->dbBuilderUpdate( + 'gmbs_line_running', + [ + ['key' => 'running_date', 'val' => date('Y-m-d', strtotime($data->running_date)), 'bind' => PDO::PARAM_STR], + ['key' => 'ref_shift_group_id', 'val' => $data->ref_shift_group_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gedung_sector_line_id', 'val' => $data->line_id, 'bind' => PDO::PARAM_STR], + ], + [ + ['key' => 'id', 'val' => $data->id, 'bind' => PDO::PARAM_INT], + ] + ); + + if (!$master_update) { + return false; + } + } + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataLineRunning: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataLineRunning: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataLineRunning($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_line_running t1 + INNER JOIN gedung_sector_line t2 ON t1.gedung_sector_line_id = t2.id + INNER JOIN gedung_sector t3 ON t2.gedung_sector_id = t3.id + INNER JOIN gedung t4 ON t3.gedung_id = t4.id + INNER JOIN sub_area t5 ON t4.sub_area_id = t5.id + INNER JOIN company t6 ON t5.company_id = t6.id + INNER JOIN ref_shift_group t7 ON t1.ref_shift_group_id = t7.id', + [ + 't1.id', + 't1.running_date', + 't1.ref_shift_group_id', + 't1.gedung_sector_line_id as line_id', + 't2.gedung_sector_id as sector_id', + 't3.gedung_id', + 't4.sub_area_id', + 't5.company_id', + 't6.description as company_name', + 't5.description as sub_area_name', + 't4.gedung_name as gedung_name', + 't3.sector_name as sector_name', + 't2.line_number as line_name', + 't7.shift_group_name as shift_group_name' + ], + [ + // ['field' => 'running_date','key' => 't1.running_date', 'val' => $params['running_date'], 'bind' => PDO::PARAM_STR,'opr'=>'LIKE'], + ], + "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_line_running t1 + INNER JOIN gedung_sector_line t2 ON t1.gedung_sector_line_id = t2.id + INNER JOIN gedung_sector t3 ON t2.gedung_sector_id = t3.id + INNER JOIN gedung t4 ON t3.gedung_id = t4.id + INNER JOIN sub_area t5 ON t4.sub_area_id = t5.id + INNER JOIN company t6 ON t5.company_id = t6.id', + [ + 'count(t1.id) as total', + ], + [] + ); + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function saveDataEventPic($data, $upload = false) + { + try { + if (!$upload) { + $this->registry->db->beginTransaction(); + } + + + foreach ($data->pic as $key => $value) { + if (!$value->id) { + $master = $this->dbBuilderInsert( + 'gmbs_event_pic', + [ + ['key' => 'pic_nik', 'val' => $value->nik, 'bind' => PDO::PARAM_STR], + ['key' => 'ref_shift_group_id', 'val' => $data->ref_shift_group_id, 'bind' => PDO::PARAM_STR], + ['key' => 'gmbs_department_group_shift_id', 'val' => $data->gmbs_department_group_shift_id, 'bind' => PDO::PARAM_STR], + ['key' => 'action_by', 'val' => \Helper::getSessionVar('username'), 'bind' => PDO::PARAM_STR], + ], + true + ); + + if (!$master) { + return false; + } + } + } + + foreach ($data->delete as $key => $value) { + if (!$value->id) { + $this->dbBuilderDelete('gmbs_event_pic', 'id', $value->id); + } + } + + + + + if (!$upload) { + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESINS"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return $this->sendResponse([], $message, $status); + } else { + return true; + } + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataEventPic: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-saveDataEventPic: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function viewDataEventPic($params) + { + try { + + $userCekAdmin = $this->getCekUserAdminSelf($params); + $sub_area_id = ''; + $department_id = ''; + + $where = []; + + + + if ($userCekAdmin) { + $sub_area_id = $userCekAdmin['sub_area_id']; + $department_id = $userCekAdmin['department_id']; + if ($userCekAdmin['is_admin'] == '0') { + array_push($where, ['field' => 'department_id', 'key' => 't9.department_id', 'val' => $department_id, 'bind' => PDO::PARAM_STR]); + array_push($where, ['field' => 'sub_area_id', 'key' => 't6.sub_area_id', 'val' => $sub_area_id, 'bind' => PDO::PARAM_STR]); + } + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_events t1 + INNER JOIN ref_manunfactures t2 ON t1.ref_manufactures_id = t2.id + LEFT JOIN gmbs_event_member_lines t3 ON t1.id = t3.gmbs_events_id + LEFT JOIN gedung_sector_line t4 ON t3.gedung_sector_line_id = t4.id + LEFT JOIN gedung_sector t5 ON t4.gedung_sector_id = t5.id + LEFT JOIN gedung t6 ON t5.gedung_id = t6.id + LEFT JOIN sub_area t7 ON t6.sub_area_id = t7.id + LEFT JOIN company t8 ON t7.company_id = t8.id + LEFT JOIN gmbs_event_member_line_departments t9 ON t9.gmbs_event_member_lines_id = t3.id + LEFT JOIN gmbs_department_group_shift t10 ON t10.gmbs_event_member_line_departments_id = t9.id + LEFT JOIN ref_shift_group t11 ON t10.ref_shift_group_id = t11.id + LEFT JOIN department t12 ON t9.department_id = t12.id', + [ + 't1.id', + 't1.description', + 't1.start_date', + 't1.end_date', + 't1.ref_manufactures_id', + 't2.plan_name' + ], + $where, + "GROUP BY t1.id ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}" + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_events t1 + INNER JOIN ref_manunfactures t2 ON t1.ref_manufactures_id = t2.id', + [ + 'count(t1.id) as total', + ], + [] + ); + + foreach ($rs as $key => $value) { + $where_line = []; + array_push($where_line, ['field' => 'gmbs_events_id', 'key' => 't1.gmbs_events_id', 'val' => $value['id'], 'bind' => PDO::PARAM_STR]); + if ($userCekAdmin) { + $sub_area_id = $userCekAdmin['sub_area_id']; + $department_id = $userCekAdmin['department_id']; + if ($userCekAdmin['is_admin'] == '0') { + array_push($where_line, ['field' => 'department_id', 'key' => 't7.department_id', 'val' => $department_id, 'bind' => PDO::PARAM_STR]); + array_push($where_line, ['field' => 'sub_area_id', 'key' => 't6.sub_area_id', 'val' => $sub_area_id, 'bind' => PDO::PARAM_STR]); + } + } + $rs[$key]['member_line'] = $this->dbBuilderSelectJoin( + 'gmbs_event_member_lines t1 + INNER JOIN gedung_sector_line t2 ON t1.gedung_sector_line_id = t2.id + INNER JOIN gedung_sector t3 ON t2.gedung_sector_id = t3.id + INNER JOIN gedung t4 ON t3.gedung_id = t4.id + INNER JOIN sub_area t5 ON t4.sub_area_id = t5.id + INNER JOIN company t6 ON t5.company_id = t6.id + INNER JOIN gmbs_event_member_line_departments t7 ON t7.gmbs_event_member_lines_id = t1.id + INNER JOIN gmbs_department_group_shift t8 ON t8.gmbs_event_member_line_departments_id = t7.id + INNER JOIN ref_shift_group t9 ON t8.ref_shift_group_id = t9.id + INNER JOIN department t10 ON t7.department_id = t10.id ', + [ + 't1.*', + 't2.gedung_sector_id as sector_id', + 't3.gedung_id', + 't4.sub_area_id', + 't5.company_id', + 't6.description as company_name', + 't5.description as sub_area_name', + 't4.gedung_name as gedung_name', + 't3.sector_name as sector_name', + 't2.line_number as line_name', + 't9.shift_group_name', + 't8.ref_shift_group_id', + 't8.id as gmbs_department_group_shift_id', + 't10.id as department_id', + 't10.description as department_name', + '(SELECT COUNT(*) FROM gmbs_event_pic WHERE gmbs_department_group_shift_id=t8.id) as total_pic' + ], + $where_line + ); + } + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataPicEvent($params) + { + try { + + $gmbs_event_pic = $this->dbBuilderSelectJoin( + 'gmbs_event_pic t1', + [ + 't1.id', + 't1.pic_nik as nik', + 'getEmpName(t1.pic_nik) as emp_name', + ], + [ + ['field' => 'gmbs_department_group_shift_id', 'key' => 't1.gmbs_department_group_shift_id', 'val' => $params['gmbs_department_group_shift_id'], 'bind' => PDO::PARAM_STR], + ] + ); + + + $rData['gmbs_event_pic'] = $gmbs_event_pic; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataEventGembaSelf($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'gmbs_events t1', + [ + 't1.*' + ], + [] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function viewDataMonitoringGembaSelf($params) + { + try { + + $where = []; + + array_push($where, ['field' => 'qualitative_answer', 'key' => 't3.qualitative_answer', 'val' => 'Tidak Standar', 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + + if ($params['event_id']) { + array_push($where, ['field' => 'gmbs_events_id', 'key' => 't8.gmbs_events_id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['ref_manunfactures_id']) { + array_push($where, ['field' => 'ref_manufactures_id', 'key' => 't9.ref_manufactures_id', 'val' => $params['ref_manunfactures_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['sub_area_id']) { + array_push($where, ['field' => 'sub_area_id', 'key' => 't14.sub_area_id', 'val' => $params['sub_area_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['gedung_id']) { + array_push($where, ['field' => 'gedung_id', 'key' => 't13.gedung_id', 'val' => $params['gedung_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['sector_id']) { + array_push($where, ['field' => 'gedung_sector_id', 'key' => 't12.gedung_sector_id', 'val' => $params['sector_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['line_id']) { + array_push($where, ['field' => 'gedung_sector_line_id', 'key' => 't11.gedung_sector_line_id', 'val' => $params['line_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['date']) { + array_push($where, ['field' => 'action_date', 'key' => 't1.action_date', 'val' => date('Y-m-d', strtotime($params['date'])), 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['department_id'] && $params['department_id'] != '') { + array_push($where, ['field' => 'department_id', 'key' => 't6.department_id', 'val' => $params['department_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + $limit = ''; + + if (isset($params['offset'])) { + $limit = "ORDER BY t1.id LIMIT {$params['offset']}, {$params['jumPage']}"; + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_event_pic_activities t1 + INNER JOIN gmbs_activities t2 ON t1.gmbs_activities_id = t2.id + INNER JOIN gmbs_answer_detail t3 ON t1.gmbs_answer_detail_id = t3.id + INNER JOIN gmbs_event_pic t4 ON t1.gmbs_event_pic_id = t4.id + INNER JOIN gmbs_department_group_shift t5 ON t4.gmbs_department_group_shift_id = t5.id + INNER JOIN gmbs_event_member_line_departments t6 ON t5.gmbs_event_member_line_departments_id = t6.id + INNER JOIN department t7 ON t6.department_id = t7.id + INNER JOIN gmbs_event_member_lines t8 ON t6.gmbs_event_member_lines_id = t8.id + INNER JOIN gmbs_events t9 ON t8.gmbs_events_id = t9.id + INNER JOIN gmbs_question_section t10 ON t2.gmbs_question_section_id = t10.id + INNER JOIN gmbs_business_unit t11 ON t10.gmbs_business_unit_id = t11.id + INNER JOIN gedung_sector_line t12 ON t11.gedung_sector_line_id = t12.id + INNER JOIN gedung_sector t13 ON t12.gedung_sector_id = t13.id + INNER JOIN gedung t14 ON t13.gedung_id = t14.id + LEFT JOIN gmbs_event_pic_activity_notes t15 ON t15.gmbs_event_pic_activities_id = t1.id', + [ + 't1.id', + 't7.description as department_name', + 't11.bu_name', + 't12.line_number as line_name', + 't10.section_name', + 't2.description as activities', + 't4.pic_nik', + 'getEmpName(t4.pic_nik) as pic_name', + 't15.note', + 't1.action_date as date_time' + ], + $where, + $limit + ); + + $sqlfilter = 'SELECT FOUND_ROWS() as filter'; + + $stmtfilter = $this->registry->db->prepare($sqlfilter); + $stmtfilter->execute(); + $rsfilter = $stmtfilter->fetchAll(PDO::FETCH_ASSOC); + + $rstotal = $this->dbBuilderSelectJoin( + 'gmbs_event_pic_activities t1 + INNER JOIN gmbs_activities t2 ON t1.gmbs_activities_id = t2.id + INNER JOIN gmbs_answer_detail t3 ON t1.gmbs_answer_detail_id = t3.id + INNER JOIN gmbs_event_pic t4 ON t1.gmbs_event_pic_id = t4.id + INNER JOIN gmbs_department_group_shift t5 ON t4.gmbs_department_group_shift_id = t5.id + INNER JOIN gmbs_event_member_line_departments t6 ON t5.gmbs_event_member_line_departments_id = t6.id + INNER JOIN department t7 ON t6.department_id = t7.id + INNER JOIN gmbs_event_member_lines t8 ON t6.gmbs_event_member_lines_id = t8.id + INNER JOIN gmbs_events t9 ON t8.gmbs_events_id = t9.id + INNER JOIN gmbs_question_section t10 ON t2.gmbs_question_section_id = t10.id + INNER JOIN gmbs_business_unit t11 ON t10.gmbs_business_unit_id = t11.id + INNER JOIN gedung_sector_line t12 ON t11.gedung_sector_line_id = t12.id + INNER JOIN gedung_sector t13 ON t12.gedung_sector_id = t13.id + INNER JOIN gedung t14 ON t13.gedung_id = t14.id + LEFT JOIN gmbs_event_pic_activity_notes t15 ON t15.gmbs_event_pic_activities_id = t1.id', + [ + 'count(t1.id) as total', + ], + $where + ); + + if (isset($rs) && count($rs) !== 0) { + $qImg = "SELECT * FROM gmbs_event_pic_activity_img WHERE gmbs_event_pic_activities_id = :id"; + $stmtImg = $this->registry->db->prepare($qImg); + + $pushData = array(); + + foreach ($rs as $value) { + $stmtImg->bindValue(':id', $value['id'], PDO::PARAM_STR); + $stmtImg->execute(); + $resImg = $stmtImg->fetchAll(PDO::FETCH_ASSOC); + + $value['photo'] = array(); + + if (isset($resImg) && count($resImg) !== 0) { + foreach ($resImg as $img) { + $value['photo'][] = array('img' => $this->registry->config->server_address . 'hcportal_docs/upload/self-genba/' . $img['img']); + } + } + + $pushData[] = $value; + } + } + + $total = $rstotal[0]['total']; + $rData['iTotalDisplayRecords'] = $total; + $rData['iTotalRecords'] = $total; + $rData['aData'] = $pushData; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function viewDataMonitoringGembaSelfGroupDepartment($params) + { + try { + + $where = []; + + if ($params['event_id']) { + array_push($where, ['field' => 'gmbs_events_id', 'key' => 't8.gmbs_events_id', 'val' => $params['event_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['ref_manunfactures_id']) { + array_push($where, ['field' => 'ref_manufactures_id', 'key' => 't9.ref_manufactures_id', 'val' => $params['ref_manunfactures_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['sub_area_id']) { + array_push($where, ['field' => 'sub_area_id', 'key' => 't14.sub_area_id', 'val' => $params['sub_area_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['gedung_id']) { + array_push($where, ['field' => 'gedung_id', 'key' => 't13.gedung_id', 'val' => $params['gedung_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['sector_id']) { + array_push($where, ['field' => 'gedung_sector_id', 'key' => 't12.gedung_sector_id', 'val' => $params['sector_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['line_id']) { + array_push($where, ['field' => 'gedung_sector_line_id', 'key' => 't11.gedung_sector_line_id', 'val' => $params['line_id'], 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + if ($params['date']) { + array_push($where, ['field' => 'action_date', 'key' => 't4.action_date', 'val' => date('Y-m-d', strtotime($params['date'])), 'bind' => PDO::PARAM_STR, 'opr' => 'LIKE']); + } + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_event_member_line_departments t1 + LEFT JOIN gmbs_department_group_shift t2 ON t2.gmbs_event_member_line_departments_id = t1.id + LEFT JOIN gmbs_event_pic t3 ON t3.gmbs_department_group_shift_id = t2.id + LEFT JOIN gmbs_event_pic_activities t4 ON t4.gmbs_event_pic_id = t3.id + LEFT JOIN gmbs_activities t5 ON t4.gmbs_activities_id = t5.id + LEFT JOIN gmbs_answer_detail t6 ON t4.gmbs_answer_detail_id = t6.id AND t6.qualitative_answer = "Tidak Standar" + INNER JOIN department t7 ON t1.department_id = t7.id + INNER JOIN gmbs_event_member_lines t8 ON t1.gmbs_event_member_lines_id = t8.id + INNER JOIN gmbs_events t9 ON t8.gmbs_events_id = t9.id + LEFT JOIN gmbs_question_section t10 ON t5.gmbs_question_section_id = t10.id + LEFT JOIN gmbs_business_unit t11 ON t10.gmbs_business_unit_id = t11.id + LEFT JOIN gedung_sector_line t12 ON t11.gedung_sector_line_id = t12.id + LEFT JOIN gedung_sector t13 ON t12.gedung_sector_id = t13.id + LEFT JOIN gedung t14 ON t13.gedung_id = t14.id', + [ + 't14.sub_area_id', + 't13.gedung_id', + 't12.gedung_sector_id', + 't11.gedung_sector_line_id', + 't8.gmbs_events_id', + 't9.ref_manufactures_id', + 't7.id as department_id', + 't7.description as department', + 't5.gmbs_question_section_id', + 'SUM(IF(t6.id is not null,1,0)) as total' + ], + $where, + "GROUP BY t7.id" + ); + + $rData['aData'] = $rs; + $arData = array($rData); + + return $rData; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataReffBusinessUnit($params) + { + try { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_ref_business_unit t1', + [ + 't1.*' + ], + [ + ['field' => 'ref_manunfactures_id', 'key' => 't1.ref_manunfactures_id', 'val' => $params['ref_manunfactures_id'], 'bind' => PDO::PARAM_STR], + ['field' => 'is_publish', 'key' => 't1.is_publish', 'val' => 1, 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function searchEmp($params) + { + try { + $sql = $this->sqlSearchEmp(); + $stmt = $this->registry->db->prepare($sql); + $stmt->bindValue(':search', '%' . $params['search'] . '%', PDO::PARAM_STR); + $stmt->bindValue(':department_id', $params['department_id'], PDO::PARAM_STR); + $stmt->bindValue(':sub_area_id', $params['sub_area_id'], PDO::PARAM_STR); + $stmt->execute(); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getCekUserAdminSelf($params) + { + try { + + $nik = \Helper::getSessionVar('username'); + $rs = $this->dbBuilderSelectJoin( + 'employement t1 + INNER JOIN emp_job t2 ON t1.nik=t2.nik AND t2.id=(SELECT id FROM emp_job WHERE nik = t1.nik AND effective_date<=now() ORDER BY effective_date DESC LIMIT 1) + INNER JOIN mpp_detail t3 ON t2.mpp_detail_id = t3.id + INNER JOIN org_layer t4 ON t3.org_layer_id = t4.id + INNER JOIN emp_personal_sub_area t5 ON t1.nik=t5.nik AND t5.id=(SELECT id FROM emp_personal_sub_area WHERE nik = t1.nik AND effective_date<=now() ORDER BY effective_date DESC LIMIT 1) + LEFT JOIN gmbs_ref_admin t6 ON t1.nik = t6.nik', + [ + 't1.nik', + 't4.entity_id', + 't4.division_id', + 't4.department_id', + 't5.sub_area_id', + 'IF(t6.id is not null,1,0) is_admin' + ], + [ + ['field' => 'nik', 'key' => 't1.nik', 'val' => $nik, 'bind' => PDO::PARAM_STR], + ] + ); + + + return $rs[0]; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataDivisionDepartment($params) + { + try { + $rs = $this->dbBuilderSelectJoin( + 'division_department t1 + INNER JOIN division t2 ON t1.division_id = t2.id + INNER JOIN department t3 ON t1.department_id = t3.id', + [ + 't1.department_id', + 't1.division_id', + 't2.description as division', + 't3.description as department' + ], + [ + // ['field' => 'nik','key' => 't1.nik', 'val' => $nik, 'bind' => PDO::PARAM_STR], + ] + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function deleteActivities($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_event_pic_activities t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_activities_id', 'key' => 't1.gmbs_activities_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_activities = $this->dbBuilderUpdate('gmbs_activities', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_activities) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_activities', 'id', $id); + } + } + + + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteActivities: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteActivities: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteWorkScopes($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + $rs = $this->dbBuilderSelectJoin( + 'gmbs_activities t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_ref_work_scopes_id', 'key' => 't1.gmbs_ref_work_scopes_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_ref_work_scopes = $this->dbBuilderUpdate('gmbs_ref_work_scopes', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_ref_work_scopes) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_ref_work_scopes', 'id', $id); + } + } + + + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteWorkScopes: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteWorkScopes: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteRiskLevel($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + $rs = $this->dbBuilderSelectJoin( + 'gmbs_activities t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_ref_risk_level', 'key' => 't1.gmbs_ref_risk_level', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_ref_risk_level = $this->dbBuilderUpdate('gmbs_ref_risk_level', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_ref_risk_level) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_ref_risk_level', 'id', $id); + } + } + + + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteRiskLevel: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteRiskLevel: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestionSectionSelf($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + $rs = $this->dbBuilderSelectJoin( + 'gmbs_activities t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_question_section_id', 'key' => 't1.gmbs_question_section_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_question_section = $this->dbBuilderUpdate('gmbs_question_section', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_question_section) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_question_section', 'id', $id); + } + } + + + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionSectionSelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionSectionSelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteQuestionCategorySelf($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + $rs = $this->dbBuilderSelectJoin( + 'gmbs_activities t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_question_category_id', 'key' => 't1.gmbs_question_category_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_question_category = $this->dbBuilderUpdate('gmbs_question_category', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_question_category) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_question_category', 'id', $id); + } + } + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionCategorySelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteQuestionCategorySelf: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteRefBusinessUnit($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + $rs = $this->dbBuilderSelectJoin( + 'gmbs_business_unit t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_ref_business_unit_id', 'key' => 't1.gmbs_ref_business_unit_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_ref_business_unit = $this->dbBuilderUpdate('gmbs_ref_business_unit', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_ref_business_unit) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_ref_business_unit', 'id', $id); + } + } + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteRefBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteRefBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteBusinessUnit($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + + if (!isset($data_array)) { + + $rs = $this->dbBuilderSelectJoin( + 'gmbs_question_section t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_business_unit_id', 'key' => 't1.gmbs_business_unit_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_business_unit = $this->dbBuilderUpdate('gmbs_business_unit', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_business_unit) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_business_unit', 'id', $id); + } + } else { + + if (count($data_array) == 0) { + $data_array = array(); + array_push($data_array, $id); + } + + foreach ($data_array as $key => $value) { + $id = $value; + $rs = $this->dbBuilderSelectJoin( + 'gmbs_question_section t1', + [ + 't1.*' + ], + [ + ['field' => 'gmbs_business_unit_id', 'key' => 't1.gmbs_business_unit_id', 'val' => $id, 'bind' => PDO::PARAM_STR], + ] + ); + + if (count($rs) > 0) { + $gmbs_business_unit = $this->dbBuilderUpdate('gmbs_business_unit', [ + ['key' => 'is_publish', 'val' => '0', 'bind' => PDO::PARAM_STR], + ], [ + ['key' => 'id', 'val' => $id, 'bind' => PDO::PARAM_INT], + ]); + + if (!$gmbs_business_unit) { + return false; + } + } else { + $this->dbBuilderDelete('gmbs_business_unit', 'id', $id); + } + } + } + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteBusinessUnit: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function deleteLineRunning($id, $data_array = array()) + { + try { + + $this->registry->db->beginTransaction(); + $data_array = json_decode($data_array, true); + + if (!$data_array) { + $data_array = array(); + } + + if (count($data_array) == 0) { + array_push($data_array, $id); + } + + + foreach ($data_array as $key => $value) { + $id = $value; + $this->dbBuilderDelete('gmbs_line_running', 'id', $id); + } + + + $this->registry->db->commit(); + + $message = "PAYROLL.MESSAGE.SUCCMESDEL"; + $status = "PAYROLL.MESSAGE.SUCCESS"; + + return true; + } catch (PDOException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteLineRunning: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESQUERY"; + -$status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } catch (ErrorException $e) { + $this->registry->db->rollBack(); + $this->registry->log->error('Gemba-deleteLineRunning: ' . $e->getMessage() . ', Line: ' . $e->getLine() . ', File: ' . $e->getFile() . ', User: ' . \Helper::getSessionVar('username')); + + $message = "PAYROLL.MESSAGE.FAILMESUNKNOWN"; + $status = "PAYROLL.MESSAGE.FAILED"; + + return $this->sendResponse([], $message, $status); + } + } + + public function getDataRefGedungSectorLine($params) + { + try { + $where = []; + + $rs = $this->dbBuilderSelectJoin( + 'gedung_sector_line t1 + INNER JOIN gedung_sector t2 ON t1.gedung_sector_id = t2.id + INNER JOIN gedung t3 ON t2.gedung_id = t3.id + INNER JOIN sub_area t4 ON t3.sub_area_id = t4.id + INNER JOIN company t5 ON t4.company_id = t5.id', + [ + 't1.id as gedung_sector_line_id', + 't1.line_number', + 't1.gedung_sector_id', + 't2.sector_name', + 't3.gedung_name', + 't4.description as sub_area', + 't5.description as company' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataRefShiftGroupAll($params) + { + try { + $where = []; + + $rs = $this->dbBuilderSelectJoin( + 'ref_shift_group t1 + INNER JOIN sub_area t2 ON t1.sub_area_id = t2.id + INNER JOIN company t3 ON t2.company_id = t3.id ', + [ + 't1.id as ref_shift_group_id', + 't1.shift_group_name', + 't2.description as sub_area', + 't3.description as company' + ], + $where + ); + + return $rs; + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getBusinessTitle($divisionId, $departmentId, $subAreaId) + { + try { + $sql = "SELECT bt.id as id,bt.description AS name + FROM ndc_business_titles bt + INNER JOIN org_layer ol ON ol.bt_id=bt.id + INNER JOIN sub_area sa ON ol.entity_id=sa.company_id + WHERE ol.division_id = :divisionId + AND ol.department_id = :departmentId + AND sa.id = :subAreaId + AND sa.country_id='IDN'"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':divisionId', $divisionId, PDO::PARAM_STR); + $stmt->bindParam(':departmentId', $departmentId, PDO::PARAM_STR); + $stmt->bindParam(':subAreaId', $subAreaId, PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getOrgLayer($divisionId, $departmentId, $subAreaId) + { + try { + $sql = " + SELECT + ol.id AS id, + ol.description AS name + FROM + org_layer ol + INNER JOIN sub_area sa ON sa.company_id = ol.entity_id + WHERE + sa.id = :subAreaId + AND sa.country_id = 'IDN' -- param country + AND ol.division_id = :divisionId + AND ol.department_id = :departmentId + GROUP BY + ol.id, + ol.description;"; + + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':divisionId', $divisionId, PDO::PARAM_STR); + $stmt->bindParam(':departmentId', $departmentId, PDO::PARAM_STR); + $stmt->bindParam(':subAreaId', $subAreaId, PDO::PARAM_STR); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getMpp($divisionId, $departmentId, $subAreaId, $olId) + { + try { + $sql = " + SELECT + mpp.id AS id, + mpp.description AS name + FROM + org_layer ol + INNER JOIN mpp_detail mpp ON ol.id = mpp.id + INNER JOIN mpp_detail_transaction mdt ON mpp.id = mdt.mpp_detail_id + AND mdt.effective_date =( + SELECT + MAX(effective_date) + FROM + mpp_detail_transaction + WHERE + mpp_detail_id = mpp.id + AND is_active = '1' + ORDER BY + effective_date DESC + LIMIT + 1 + ) + INNER JOIN sub_area sa ON sa.company_id = ol.entity_id + WHERE + sa.id = :subAreaId + AND sa.country_id = 'IDN' -- param country + AND ol.division_id = :divisionId + AND ol.department_id = :departmentId + AND ol.id = :olId + GROUP BY + mpp.id, + mpp.description; + "; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':divisionId', $divisionId, PDO::PARAM_STR); + $stmt->bindParam(':departmentId', $departmentId, PDO::PARAM_STR); + $stmt->bindParam(':subAreaId', $subAreaId, PDO::PARAM_STR); + $stmt->bindParam(':olId', $olId, PDO::PARAM_STR); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getLineListData() + { + try { + $sql = "select a.*, b.*, c.*, d.*, e.*, g.*, a.id as id, g.id as gmbs_business_unit_id + from gedung_sector_line a + INNER JOIN gedung_sector b on a.gedung_sector_id = b.id + INNER JOIN gedung c on b.gedung_id = c.id + INNER JOIN ref_manufacture_sub_area d on c.sub_area_id = d.sub_area_id + INNER JOIN ref_manunfactures e on d.ref_manunfactures_id = e.id + LEFT JOIN gmbs_business_unit g on a.id = g.gedung_sector_line_id;"; + + $stmt = $this->registry->db->prepare($sql); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function GetBusinessUnits($search = null) + { + try { + $sql = "SELECT id, bu_name as name FROM gmbs_business_unit WHERE is_publish = 1"; + if ($search !== null) { + $sql .= " AND bu_name LIKE :search"; + } + + $stmt = $this->registry->db->prepare($sql); + + if ($search !== null) { + $stmt->bindValue(':search', '%' . $search . '%', PDO::PARAM_STR); + } + + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getSector($buId = null, $search = null, $sectorId = null) + { + try { + $sql = "SELECT gedung_sector.id, + CASE + WHEN gedung_sector.sector_name = '-' THEN gedung.gedung_name + ELSE CONCAT(gedung.gedung_name, '-', gedung_sector.sector_name) + END as name + FROM + gedung_sector_line + INNER JOIN gedung_sector ON gedung_sector_line.gedung_sector_id = gedung_sector.id + INNER JOIN gedung ON gedung.id = gedung_sector.gedung_id + LEFT JOIN gmbs_business_unit ON gmbs_business_unit.gedung_sector_line_id = gedung_sector_line.id"; + $conditions = []; + $params = []; + + if ($sectorId !== null) { + $conditions[] = "gedung_sector.id = :sectorId"; + $params[':sectorId'] = $sectorId; + } + + if ($buId !== null) { + $conditions[] = "gmbs_business_unit.id = :buId"; + $params[':buId'] = $buId; + } + + if ($search !== null) { + $conditions[] = "(gedung.gedung_name LIKE :search OR + (gedung_sector.sector_name != '-' AND gedung_sector.sector_name LIKE :search) OR + CASE + WHEN gedung_sector.sector_name = '-' THEN gedung.gedung_name + ELSE CONCAT(gedung.gedung_name, '-', gedung_sector.sector_name) + END LIKE :search)"; + $params[':search'] = '%' . $search . '%'; + } + + if (!empty($conditions)) { + $sql .= " WHERE " . implode(" AND ", $conditions); + } + + $sql .= " GROUP BY gedung_sector.id"; + + $stmt = $this->registry->db->prepare($sql); + + foreach ($params as $key => &$val) { + $stmt->bindParam($key, $val, is_int($val) ? PDO::PARAM_INT : PDO::PARAM_STR); + } + + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getTeamMember($nik) { + try { + $sql = "SELECT c.id as mppId, a.nik, getEmpName(a.nik) as emp_name, a.grade + FROM employement a + INNER JOIN emp_job b ON a.nik=b.nik + AND b.effective_date=(SELECT max(ej.effective_date) + FROM emp_job ej + WHERE ej.nik=a.nik + AND ej.effective_date<=current_date()) + INNER JOIN mpp_detail c ON b.mpp_detail_id=c.id + INNER JOIN mpp_detail_transaction d ON c.id=d.mpp_detail_id + AND d.effective_date=(SELECT max(mt.effective_date) + FROM mpp_detail_transaction mt + WHERE mt.mpp_detail_id=c.id + AND mt.effective_date<=current_date()) + WHERE a.status='active' + AND LEFT(a.grade,1)>=3 + AND ( + a.nik = :nik + OR + d.level_code LIKE CONCAT( + '%', '-', + (SELECT md.id + FROM emp_job ej2 + INNER JOIN mpp_detail md ON ej2.mpp_detail_id = md.id + WHERE ej2.nik = :nik + AND ej2.effective_date = ( + SELECT MAX(ej3.effective_date) + FROM emp_job ej3 + WHERE ej3.nik = :nik + AND ej3.effective_date <= current_date() + ) + ), + '-', '%' + ) + ) + "; + + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':nik', $nik, PDO::PARAM_STR); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + + public function getGedungSectorLines($buId = null, $sectorId = null, $search = null) + { + try { + $sql = "SELECT + gedung_sector_line.id as id, gedung_sector_line.line_number as name + FROM + gedung_sector_line + INNER JOIN gedung_sector ON gedung_sector_line.gedung_sector_id = gedung_sector.id + INNER JOIN gedung ON gedung.id = gedung_sector.gedung_id + LEFT JOIN gmbs_business_unit ON gmbs_business_unit.gedung_sector_line_id = gedung_sector_line.id + WHERE 1=1"; + + $params = array(); + + if ($buId != null) { + $sql .= " AND gmbs_business_unit.id = :buId"; + $params[":buId"] = $buId; + } + + if ($sectorId !== null) { + $sql .= " AND gedung_sector.id = :sectorId"; + $params[':sectorId'] = $sectorId; + } + + if ($search !== null) { + $sql .= " AND gedung_sector_line.line_number LIKE :search"; + $params[':search'] = '%' . $search . '%'; + } + + $sql .= " GROUP BY gedung_sector_line.id LIMIT 10"; + + $stmt = $this->registry->db->prepare($sql); + foreach ($params as $key => $value) { + $stmt->bindValue($key, $value); + } + + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function searchEmployee($search) + { + try { + $search = '%' . $search . '%'; + $sql = " + SELECT + emp.nik, + CONCAT_WS( + ' ', + ep.title, + ep.first_name, + ep.middle_name, + ep.last_name + ) as name, + ep.first_name, + ep.last_name, + ep.id AS emp_id, + IFNULL(ep.`office_mail`,`emp_email`)AS email, + ep.`photo_address` AS profile_picture, + usr.`group` AS `group_id`, + g.`group` AS `group_name`, + job.job_title as position_name, + CASE + WHEN emp.flag_app = 'SAP' THEN 1 + ELSE 0 + END AS is_employee, + CASE + WHEN emp.status = 'active' THEN 1 + ELSE 0 + END AS is_active + FROM + emp_profiles ep + INNER JOIN employement emp ON ep.id = emp.emp_profile_id + INNER JOIN `user` usr ON emp.nik = usr.username + INNER JOIN `group` g ON usr.`group` = g.groupid + LEFT JOIN emp_job job ON emp.nik = job.nik + AND job.id = ( + SELECT + id + FROM + emp_job + WHERE + nik = emp.nik + ORDER BY + id DESC + LIMIT + 1 + ) + WHERE + emp.status = 'active' AND + ( + CONCAT_WS( + ' ', + IF(LENGTH(ep.title), ep.title, NULL), + IF(LENGTH(ep.first_name), ep.first_name, NULL), + IF(LENGTH(ep.middle_name), ep.middle_name, NULL), + IF(LENGTH(ep.last_name), ep.last_name, NULL) + ) LIKE :search OR (emp.nik LIKE :search) + ) LIMIT 10"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':search', $search, PDO::PARAM_STR); + + $stmt->execute(); + + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getRefManufactures() + { + try { + $sql = "SELECT * FROM ref_manunfactures"; + $stmt = $this->registry->db->prepare($sql); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getSubAreaFromManufacture($id) + { + try { + $sql = "SELECT id, description as name + FROM sub_area WHERE id IN + ( + SELECT sub_area_id FROM ref_manufacture_sub_area WHERE ref_manunfactures_id = :id + ) + "; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':id', $id, PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getDivisionFromSubArea($id) + { + try { + $sql = "SELECT divs.id AS id, divs.description AS name FROM org_layer ol + INNER JOIN division divs ON ol.division_id=divs.id + INNER JOIN sub_area sa ON sa.company_id=ol.entity_id + WHERE sa.id=:id + AND sa.country_id='IDN' + GROUP BY divs.id ,divs.description;"; + + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':id', $id, PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getDepartmentDivisionName($departmentId) + { + try { + $this->registry->log->error('departmentId: ' . $departmentId); + $sql = "SELECT department.id AS id, department.description as department, division.description as division + FROM department + INNER JOIN division ON division.id = department.division_id + WHERE department.id = :departmentId LIMIT 1"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':departmentId', $departmentId, PDO::PARAM_STR); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getDepartmentFromDivision($divisionId, $subAreaId) + { + try { + $sql = "SELECT dept.id AS id, dept.description AS name + FROM org_layer ol + INNER JOIN department dept ON ol.department_id=dept.id + INNER JOIN sub_area sa ON sa.company_id=ol.entity_id + WHERE sa.id=:subAreaId -- param area + AND ol.division_id=:divisionId -- param division + GROUP BY dept.id,dept.description;"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':subAreaId', $subAreaId, PDO::PARAM_INT); + $stmt->bindParam(':divisionId', $divisionId, PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getManufactureArea($id) + { + try { + $sql = "SELECT id, area as name FROM ref_manufacture_area WHERE ref_manunfactures_id = :id"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindParam(':id', $id, PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + public function getSubAreaByNik($nik) + { + try { + // First, check for admin subareas + $sqlAdmin = "SELECT DISTINCT(subarea_id) FROM user_admin_subarea WHERE username = :user"; + $stmtAdmin = $this->registry->db->prepare($sqlAdmin); + $stmtAdmin->bindValue(':user', $nik, PDO::PARAM_STR); + $stmtAdmin->execute(); + $rsAdmin = $stmtAdmin->fetchAll(PDO::FETCH_ASSOC); + + if ($rsAdmin) { + $subareaIds = array_column($rsAdmin, 'subarea_id'); + return $subareaIds; + } + + // If no admin subareas, check for personal subareas + $sql = "SELECT sub_area_id FROM emp_personal_sub_area + WHERE nik = :nik AND effective_date <= CURRENT_DATE + ORDER BY effective_date DESC, id DESC LIMIT 1"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindValue(':nik', $nik, PDO::PARAM_STR); + $stmt->execute(); + $rs = $stmt->fetch(PDO::FETCH_ASSOC); + return $rs ? [$rs['sub_area_id']] : []; + } catch (PDOException $e) { + $this->registry->log->error('module gemba: ' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba: ' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + return false; + } + } + + + public function viewDataMasterActivitiesDownload() + { + try { + $sql = "SELECT + t1.id, + t1.order_no, + t1.is_publish, + t1.description, + t1.gmbs_question_category_id, + t1.gmbs_question_section_id, + t1.gmbs_ref_risk_level_id, + t1.gmbs_ref_work_scopes_id, + t1.reference_link, + t1.gmbs_ref_risk_level_id, + t3.department_id, + t3.gmbs_business_unit_id + FROM gmbs_activities t1 + INNER JOIN gmbs_question_category t2 ON t1.gmbs_question_category_id = t2.id + INNER JOIN gmbs_question_section t3 ON t1.gmbs_question_section_id = t3.id + ORDER BY t3.section_name ASC"; + + $stmt = $this->registry->db->prepare($sql); + $stmt->execute(); + $rsdata = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $qDetail = "SELECT * FROM gmbs_answer_detail WHERE gmbs_activities_id = :id"; + + $stmtDetail = $this->registry->db->prepare($qDetail); + + $dataArr = array(); + + if (isset($rsdata) && count($rsdata) !== 0) { + foreach ($rsdata as $val) { + $stmtDetail->bindValue(':id', $val['id'], PDO::PARAM_STR); + $stmtDetail->execute(); + $rsdataDetail = $stmtDetail->fetchAll(PDO::FETCH_ASSOC); + + if (isset($rsdataDetail) && count($rsdataDetail) !== 0) { + foreach ($rsdataDetail as $valDetail) { + if ($valDetail['answer_label'] == 'YES') { + $val['answer_score_yes'] = $valDetail['answer_score']; + $val['is_require_note_yes'] = $valDetail['is_require_note']; + } else { + $val['answer_score_no'] = $valDetail['answer_score']; + $val['is_require_note_no'] = $valDetail['is_require_note']; + } + } + } + + $dataArr[] = $val; + } + } + + return $dataArr; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } + + public function getDataEmployee($empId) + { + $this->registry->log->error($empId); + try { + $sql = "select + a.first_name, + concat_ws( + ' ', + ifnull(a.middle_name, ''), + ifnull(a.last_name, '') + ) as last_name, + e.description as job_position, + e.division_id as division_id, + e.department_id as department_id, + e.id as org_layer_id, + bt.id as bt_id, + mpp.id as mpp_id, + emp_personal_sub_area.sub_area_id as sub_area_id, + a.photo_address AS profile_picture, + IFNULL(office_mail, emp_email) AS email, + ref_manufacture_sub_area.ref_manunfactures_id AS ref_manufactures_id +FROM + emp_profiles a + inner join employement b on a.id = b.emp_profile_id + inner join emp_job c on b.nik = c.nik + and c.effective_date =( + select + max(ej.effective_date) + from + emp_job ej + where + ej.nik = b.nik + and ej.effective_date <= current_date() + ) + inner join mpp_detail d on c.mpp_detail_id = d.id + inner join org_layer e on d.org_layer_id = e.id + INNER JOIN emp_personal_sub_area ON c.nik = emp_personal_sub_area.nik + INNER JOIN sub_area sa ON e.entity_id = sa.company_id + INNER JOIN ndc_business_titles bt ON bt.id = e.bt_id + LEFT JOIN ref_manufacture_sub_area ON ref_manufacture_sub_area.sub_area_id = emp_personal_sub_area.sub_area_id + INNER JOIN mpp_detail mpp ON e.id = mpp.id +where + a.id = :emp_id +ORDER BY + emp_personal_sub_area.effective_date DESC +LIMIT + 1;"; + $stmt = $this->registry->db->prepare($sql); + $stmt->bindValue(':emp_id', $empId, PDO::PARAM_INT); + $stmt->execute(); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + if (count($rs) == 0) { + return null; + } + return $rs[0]; + } catch (PDOException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } catch (ErrorException $e) { + $this->registry->log->error('module gemba :' . $e->getMessage() . ', user: ' . \Helper::getSessionVar('username')); + + return false; + } + } +} diff --git a/rsyslog.conf b/rsyslog.conf new file mode 100644 index 0000000..2beabc6 --- /dev/null +++ b/rsyslog.conf @@ -0,0 +1,29 @@ +# Load modules +module(load="imfile") + +# Monitor specific error log file +input(type="imfile" + File="/app/src/api/log/Error-*.log" + Tag="api_error_logs" + Severity="error" + Facility="local0") + +# Template to include severity +template(name="ErrorFormat" type="string" string="%syslogseverity-text%: %msg%\n") + +# Filter out GET and POST logs +:msg, contains, "GET " stop +:msg, contains, "POST " stop + +# Send error messages to stderr with severity +if $syslogtag contains 'api_error_logs' then { + action(type="omfile" file="/dev/stderr" template="ErrorFormat") +} + +# Optionally, you can add more specific filters here +if $msg contains "PHP Fatal error:" or $msg contains "PHP Warning:" then { + action(type="omfile" file="/dev/stderr" template="ErrorFormat") +} + +# Discard other logs +*.* stop