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); } } }