private function _save($ot_id = 0) { $this->load->library("WorkflowSystem"); if ($_POST) { $post = $this->input->post(NULL, TRUE); $ot_date = $post['input_ot_date']; $ot_time_from = $post['input_ot_time_from']; $ot_time_to = $post['input_ot_time_to']; $ot_remark = $post['input_ot_remark']; $data = array(); $data['wot_date'] = dbDateFormatFromThaiUn543($ot_date); $data['wot_time_from'] = $ot_time_from; $data['wot_time_to'] = $ot_time_to; $data["wot_remark"] = $ot_remark; $data['wot_request_hour'] = timeDiff($ot_time_from, $ot_time_to); $data['wot_request_by'] = $this->user_id; $data['wot_workflow_id'] = $this->workflow_start_id; $data['wot_status_id'] = 1; if ($ot_id === 0) { $data['wot_request_date'] = getDateTimeNow(); $ot_id = $this->ot->insert($data); insert_log_ot($ot_id, 'add', 'ส่งใบคำขอทำงานล่วงเวลา'); $this->workflowsystem->set_require_data($ot_id, "overtime", "request"); } else { $data['wot_latest_update'] = getDateTimeNow(); $where = array("wot_id" => $ot_id); $affected = $this->ot->update($data, $where); insert_log_ot($ot_id, 'edit', 'แก้ไขใบคำขอทำงานล่วงเวลา'); $this->workflowsystem->set_require_data($ot_id, "overtime", "editrequest"); } //run workflow $process = $this->workflowsystem->run(); //alert after all process if ($ot_id > 0 && $process == 'success') { echo swalc("บันทึกเรียบร้อย", '', 'success', 'window.location.href = "' . site_url('Overtime') . '"'); } else { if ($ot_id > 0 && $process != 'success') { echo swalc("บันทึกเรียบร้อย", 'แต่ไม่สามารถส่งอีเมล์ได้', 'warning', 'window.location.href = "' . site_url('Overtime') . '"'); } else { echo swalc("ผิดพลาด กรุณาลองใหม่ภายหลัง", '', 'error', 'window.location.href = "' . site_url('Overtime') . '"'); } } } }
private function _save() { //get post data $post = $this->input->post(NULL, TRUE); $hid = intval($post["hd_hid"]); $name = $post["input_name"]; $desc = $post["input_desc"]; $date = dbDateFormatFromThaiUn543($post["input_date"]); //set data $data = array(); $data["HDate"] = $date; $data["HName"] = $name; $data["HDesc"] = $desc; //insert if ($hid !== 0) { $where = array("HID" => $hid); $this->holiday->update($data, $where); } else { $this->holiday->insert($data); } }
public function EditEmployee() { if ($_POST) { $empData = $this->input->post(null, true); $empID = $empData["hdEmpID"]; if (isset($empData['txtPassword']) && $empData['txtPassword'] != '') { $data = array(); //เรื่องของรหัสผ่านแก้ที่ Table T_Users $data['Password'] = $empData['txtPassword']; $where['User_EmpID'] = $empID; $this->users->edit($data, $where); } $where = array(); $where['EmpID'] = $empID; $data = array(); $data['EmpNameTitleThai'] = $empData['ddlNameTitleThai']; $data['EmpFirstnameThai'] = $empData['txtFirstnameThai']; $data['EmpLastnameThai'] = $empData['txtLastnameThai']; $data['EmpNameTitleEnglish'] = $empData['ddlNameTitleEnglish']; $data['EmpFirstnameEnglish'] = $empData['txtFirstnameEnglish']; $data['EmpLastnameEnglish'] = $empData['txtLastnameEnglish']; $data['Emp_PositionID'] = $empData['ddlPosition']; $data['Emp_DepartmentID'] = $empData['ddlDepartment']; $data["Emp_SectionID"] = $empData["ddlSection"]; $data["Emp_UnitID"] = $empData["ddlUnit"]; $data["Emp_GroupID"] = $empData["ddlGroup"]; $data["EmpBirthDay"] = intval($empData["ddlBirthDayYear"]) > 0 ? intval($empData["ddlBirthDayYear"]) - 543 : 0 . "-" . $empData["ddlBirthDayMonth"] . "-" . $empData["ddlBirthDayDay"]; $data['EmpBirthPlace'] = $empData['txtBirthPlace']; $data['EmpIDCard'] = $empData['txtIDCard']; $data['EmpAddressNumber'] = $empData['txtAddressNumber']; $data['EmpAddressMoo'] = $empData['txtAddressMoo']; $data['EmpAddressRoad'] = $empData['txtAddressRoad']; $data['Emp_DistrictID'] = $empData['ddlAddressDistrict']; $data['Emp_AmphurID'] = $empData['ddlAddressAmphur']; $data['Emp_ProvinceID'] = $empData['ddlAddressProvince']; $data['Emp_ZipcodeID'] = $empData['ddlAddressZipcode']; //dbDateFormatFromThai is function from common_helper $data['EmpStartWorkDate'] = dbDateFormatFromThaiUn543($empData['txtStartWorkDate']); $data['EmpSuccessTrialWorkDate'] = dbDateFormatFromThaiUn543($empData['txtSuccessTrialWorkDate']); $data['EmpSalary'] = $empData['txtSalary']; $data['EmpCallname'] = $empData['txtCallName']; $data['EmpTelephone'] = $empData['txtTelePhone']; $data['EmpMobilePhone'] = $empData['txtMobilePhone']; $data['EmpEmail'] = $empData['txtEmail']; $data['EmpSex'] = !isset($empData['rdoSex']) ? 0 : $empData['rdoSex']; $data['EmpHeight'] = $empData['txtHeight']; $data['EmpWeight'] = $empData['txtWeight']; $data['EmpBlood'] = $empData['txtBlood']; $data['EmpNationality'] = $empData['txtNationality']; $data['EmpRace'] = $empData['txtRace']; $data['EmpReligion'] = $empData['txtReligion']; $data['Emp_MARSID'] = !isset($empData['rdoMartialStatus']) ? 0 : $empData['rdoMartialStatus']; $data['EmpMilitaryStatus'] = !isset($empData['rdoMilitaryStatus']) ? 0 : $empData['rdoMilitaryStatus']; $data['EmpMilitaryReason'] = $empData['txtMilitaryReason']; $data["EmpNumberOfChildren"] = $empData["txtNumberOfChildren"]; $data["EmpNumberOfBrother"] = $empData["txtNumberOfBrother"]; $data['Emp_BankID'] = $empData['ddlBank']; $data['EmpBankBranch'] = $empData['txtBankAccountBranch']; $data['EmpBankNumber'] = $empData['txtBankAccountNumber']; $data['Emp_BankTypeID'] = $empData['ddlBankAccountType']; $data['EmpFriendNameTitleThai'] = $empData['ddlNameTitleFriend']; $data['EmpFriendFirstnameThai'] = $empData['txtFirstnameFriend']; $data['EmpFriendLastnameThai'] = $empData['txtLastnameFriend']; $data['EmpFriendAddressNumber'] = $empData['txtAddressNumberFriend']; $data['EmpFriendAddressMoo'] = $empData['txtAddressMooFriend']; $data['EmpFriendAddressRoad'] = $empData['txtAddressRoadFriend']; $data['EmpFriend_DistrictID'] = $empData['ddlAddressDistrictFriend']; $data['EmpFriend_AmphurID'] = $empData['ddlAddressAmphurFriend']; $data['EmpFriend_ProvinceID'] = $empData['ddlAddressProvinceFriend']; $data['EmpFriend_ZipcodeID'] = $empData['ddlAddressZipcodeFriend']; $data["EmpFriendTelephone"] = $empData["txtTelePhoneFriend"]; $data["EmpFriendMobilePhone"] = $empData["txtMobilePhoneFriend"]; $data['EmpFatherNameTitleThai'] = $empData['ddlNameTitleFather']; $data['EmpFatherFirstnameThai'] = $empData['txtFirstnameFather']; $data['EmpFatherLastnameThai'] = $empData['txtLastnameFather']; $data['EmpFatherAddressNumber'] = $empData['txtAddressNumberFather']; $data['EmpFatherAddressMoo'] = $empData['txtAddressMooFather']; $data['EmpFatherAddressRoad'] = $empData['txtAddressRoadFather']; $data['EmpFather_DistrictID'] = $empData['ddlAddressDistrictFather']; $data['EmpFather_AmphurID'] = $empData['ddlAddressAmphurFather']; $data['EmpFather_ProvinceID'] = $empData['ddlAddressProvinceFather']; $data['EmpFather_ZipcodeID'] = $empData['ddlAddressZipcodeFather']; $data["EmpFatherTelephone"] = $empData["txtTelePhoneFather"]; $data["EmpFatherMobilePhone"] = $empData["txtMobilePhoneFather"]; $data['EmpMotherNameTitleThai'] = $empData['ddlNameTitleMother']; $data['EmpMotherFirstnameThai'] = $empData['txtFirstnameMother']; $data['EmpMotherLastnameThai'] = $empData['txtLastnameMother']; $data['EmpMotherAddressNumber'] = $empData['txtAddressNumberMother']; $data['EmpMotherAddressMoo'] = $empData['txtAddressMooMother']; $data['EmpMotherAddressRoad'] = $empData['txtAddressRoadMother']; $data['EmpMother_DistrictID'] = $empData['ddlAddressDistrictMother']; $data['EmpMother_AmphurID'] = $empData['ddlAddressAmphurMother']; $data['EmpMother_ProvinceID'] = $empData['ddlAddressProvinceMother']; $data['EmpMother_ZipcodeID'] = $empData['ddlAddressZipcodeMother']; $data["EmpMotherTelephone"] = $empData["txtTelePhoneMother"]; $data["EmpMotherMobilePhone"] = $empData["txtMobilePhoneMother"]; $data['EmpHouseRegAddressNumber'] = $empData['txtAddressNumberHouseReg']; $data['EmpHouseRegAddressMoo'] = $empData['txtAddressMooHouseReg']; $data['EmpHouseRegAddressRoad'] = $empData['txtAddressRoadHouseReg']; $data['EmpHouseReg_DistrictID'] = $empData['ddlAddressDistrictHouseReg']; $data['EmpHouseReg_AmphurID'] = $empData['ddlAddressAmphurHouseReg']; $data['EmpHouseReg_ProvinceID'] = $empData['ddlAddressProvinceHouseReg']; $data['EmpHouseReg_ZipcodeID'] = $empData['ddlAddressZipcodeHouseReg']; $data['EmpLatestUpdate'] = date('Y-m-d H:i:s'); $this->employees->edit($data, $where); $userID = floatval($this->users->getUserIDByEmpID($empID)); //upload edit $contFile = array("fuEmpPicture", "fuIDCard", "fuAddress", "fuDocRegisterJob", "fuBank"); foreach ($contFile as $file) { $nowPath = $this->uploadImg($file, $this->config->item('upload_employee') . intval($userID)); if ($nowPath != "") { $this->employees->updateImage($empID, $file, $nowPath); } } //insert emp headman level 1 - 3 [ddlHeadman_level_1,ddlHeadman_level_2,ddlHeadman_level_3] //if edit delete old data $this->empheadman->delete_from_user_id($userID); for ($i = 1; $i <= 3; $i++) { $headman_user_id = intval($empData['ddlHeadman_level_' . $i]); if ($headman_user_id > 0) { $this->empheadman->insert(array('eh_user_id' => $userID, 'eh_headman_user_id' => $headman_user_id, 'eh_headman_level' => $i)); } } //insert emp history work if have $ehw_company = $empData['history_work_company']; $ehw_position = $empData['history_work_position']; $ehw_district = $empData['history_work_district']; $ehw_desc = $empData['history_work_desc']; $ehw_date_from_day = $empData['history_work_date_from_day']; $ehw_date_from_month = $empData['history_work_date_from_month']; $ehw_date_from_year = $empData['history_work_date_from_year']; //year thai $ehw_date_to_day = $empData['history_work_date_to_day']; $ehw_date_to_month = $empData['history_work_date_to_month']; $ehw_date_to_year = $empData['history_work_date_to_year']; $this->hiswork->delete_from_user_id($userID); for ($i = 0; $i < count($ehw_company); $i++) { if ($ehw_company[$i] != "") { $this->hiswork->insert(array('ehw_user_id' => $userID, 'ehw_company' => $ehw_company[$i], 'ehw_position' => $ehw_position[$i], 'ehw_district' => $ehw_district[$i], 'ehw_desc' => $ehw_desc[$i], 'ehw_date_from' => dbDateFormatFromThai($ehw_date_from_day[$i] . '/' . $ehw_date_from_month[$i] . '/' . $ehw_date_from_year[$i]), 'ehw_date_to' => dbDateFormatFromThai($ehw_date_to_day[$i] . '/' . $ehw_date_to_month[$i] . '/' . $ehw_date_to_year[$i]))); } } //insert emp history study if have $ehs_academy = $empData['history_study_academy']; $ehs_education_level = $empData['history_study_education_level']; $ehs_bachelor = $empData['history_study_bachelor']; $ehs_major = $empData['history_study_major']; $ehs_desc = $empData['history_study_desc']; $ehs_year_start = $empData['history_study_year_start']; $ehs_year_end = $empData['history_study_year_end']; $ehs_grade_avg = $empData['history_study_grade_avg']; $ehs_degree = $empData['history_study_degree']; $this->hisstudy->delete_from_user_id($userID); for ($i = 0; $i < count($ehs_academy); $i++) { if ($ehs_academy[$i] != "") { $this->hisstudy->insert(array('ehs_user_id' => $userID, 'ehs_education_level_id' => $ehs_education_level[$i], 'ehs_academy' => $ehs_academy[$i], 'ehs_bachelor' => $ehs_bachelor[$i], 'ehs_major' => $ehs_major[$i], 'ehs_desc' => $ehs_desc[$i], 'ehs_year_start' => year_english_from_thai($ehs_year_start[$i]), 'ehs_year_end' => year_english_from_thai($ehs_year_end[$i]), 'ehs_grade_avg' => $ehs_grade_avg[$i], 'ehs_degree' => $ehs_degree[$i])); } } //insert shift work $this->empshiftwork->deleteByUserId($userID); if (isset($empData["hdShiftworkId"]) && count($empData["hdShiftworkId"] > 0)) { for ($i = 0; $i < count($empData["hdShiftworkId"]); $i++) { $dataSw = array(); $dataSw["esw_userid"] = $userID; $dataSw["esw_swid"] = $empData["hdShiftworkId"][$i]; $this->empshiftwork->insert($dataSw); } } swalc("บันทึกเรียบร้อยแล้ว", "", "success", "window.location.href = '" . site_url("hr/Employees/Detail/" . $empID) . "'"); } }
public function insertEmp($empData) { $data = array(); $data['EmpID'] = $empData['txtEmpID']; $data['EmpNameTitleThai'] = $empData['ddlNameTitleThai']; $data['EmpFirstnameThai'] = $empData['txtFirstnameThai']; $data['EmpLastnameThai'] = $empData['txtLastnameThai']; $data['EmpNameTitleEnglish'] = $empData['ddlNameTitleEnglish']; $data['EmpFirstnameEnglish'] = $empData['txtFirstnameEnglish']; $data['EmpLastnameEnglish'] = $empData['txtLastnameEnglish']; $data['Emp_PositionID'] = $empData['ddlPosition']; $data['Emp_DepartmentID'] = $empData['ddlDepartment']; $data["Emp_SectionID"] = $empData["ddlSection"]; $data["Emp_UnitID"] = $empData["ddlUnit"]; $data["Emp_GroupID"] = $empData["ddlGroup"]; $data["EmpBirthDay"] = intval($empData["ddlBirthDayYear"]) > 0 ? intval($empData["ddlBirthDayYear"]) - 543 : 0 . "-" . $empData["ddlBirthDayMonth"] . "-" . $empData["ddlBirthDayDay"]; $data['EmpBirthPlace'] = $empData['txtBirthPlace']; $data['EmpIDCard'] = $empData['txtIDCard']; $data['EmpAddressNumber'] = $empData['txtAddressNumber']; $data['EmpAddressMoo'] = $empData['txtAddressMoo']; $data['EmpAddressRoad'] = $empData['txtAddressRoad']; $data['Emp_DistrictID'] = $empData['ddlAddressDistrict']; $data['Emp_AmphurID'] = $empData['ddlAddressAmphur']; $data['Emp_ProvinceID'] = $empData['ddlAddressProvince']; $data['Emp_ZipcodeID'] = $empData['ddlAddressZipcode']; //dbDateFormatFromThai is function from common_helper $data['EmpStartWorkDate'] = dbDateFormatFromThaiUn543($empData['txtStartWorkDate']); $data['EmpSuccessTrialWorkDate'] = dbDateFormatFromThaiUn543($empData['txtSuccessTrialWorkDate']); $data['EmpSalary'] = $empData['txtSalary']; $data['EmpCallname'] = $empData['txtCallName']; $data['EmpTelephone'] = $empData['txtTelePhone']; $data['EmpMobilePhone'] = $empData['txtMobilePhone']; $data['EmpEmail'] = $empData['txtEmail']; $data['EmpSex'] = !isset($empData['rdoSex']) ? 0 : $empData['rdoSex']; $data['EmpHeight'] = $empData['txtHeight']; $data['EmpWeight'] = $empData['txtWeight']; $data['EmpBlood'] = $empData['txtBlood']; $data['EmpNationality'] = $empData['txtNationality']; $data['EmpRace'] = $empData['txtRace']; $data['EmpReligion'] = $empData['txtReligion']; $data['Emp_MARSID'] = !isset($empData['rdoMartialStatus']) ? 0 : $empData['rdoMartialStatus']; $data['EmpMilitaryStatus'] = !isset($empData['rdoMilitaryStatus']) ? 0 : $empData['rdoMilitaryStatus']; $data['EmpMilitaryReason'] = $empData['txtMilitaryReason']; $data["EmpNumberOfChildren"] = $empData["txtNumberOfChildren"]; $data["EmpNumberOfBrother"] = $empData["txtNumberOfBrother"]; $data['Emp_BankID'] = $empData['ddlBank']; $data['EmpBankBranch'] = $empData['txtBankAccountBranch']; $data['EmpBankNumber'] = $empData['txtBankAccountNumber']; $data['Emp_BankTypeID'] = $empData['ddlBankAccountType']; $data['EmpFriendNameTitleThai'] = $empData['ddlNameTitleFriend']; $data['EmpFriendFirstnameThai'] = $empData['txtFirstnameFriend']; $data['EmpFriendLastnameThai'] = $empData['txtLastnameFriend']; $data['EmpFriendAddressNumber'] = $empData['txtAddressNumberFriend']; $data['EmpFriendAddressMoo'] = $empData['txtAddressMooFriend']; $data['EmpFriendAddressRoad'] = $empData['txtAddressRoadFriend']; $data['EmpFriend_DistrictID'] = $empData['ddlAddressDistrictFriend']; $data['EmpFriend_AmphurID'] = $empData['ddlAddressAmphurFriend']; $data['EmpFriend_ProvinceID'] = $empData['ddlAddressProvinceFriend']; $data['EmpFriend_ZipcodeID'] = $empData['ddlAddressZipcodeFriend']; $data["EmpFriendTelephone"] = $empData["txtTelePhoneFriend"]; $data["EmpFriendMobilePhone"] = $empData["txtMobilePhoneFriend"]; $data['EmpFatherNameTitleThai'] = $empData['ddlNameTitleFather']; $data['EmpFatherFirstnameThai'] = $empData['txtFirstnameFather']; $data['EmpFatherLastnameThai'] = $empData['txtLastnameFather']; $data['EmpFatherAddressNumber'] = $empData['txtAddressNumberFather']; $data['EmpFatherAddressMoo'] = $empData['txtAddressMooFather']; $data['EmpFatherAddressRoad'] = $empData['txtAddressRoadFather']; $data['EmpFather_DistrictID'] = $empData['ddlAddressDistrictFather']; $data['EmpFather_AmphurID'] = $empData['ddlAddressAmphurFather']; $data['EmpFather_ProvinceID'] = $empData['ddlAddressProvinceFather']; $data['EmpFather_ZipcodeID'] = $empData['ddlAddressZipcodeFather']; $data["EmpFatherTelephone"] = $empData["txtTelePhoneFather"]; $data["EmpFatherMobilePhone"] = $empData["txtMobilePhoneFather"]; $data['EmpMotherNameTitleThai'] = $empData['ddlNameTitleMother']; $data['EmpMotherFirstnameThai'] = $empData['txtFirstnameMother']; $data['EmpMotherLastnameThai'] = $empData['txtLastnameMother']; $data['EmpMotherAddressNumber'] = $empData['txtAddressNumberMother']; $data['EmpMotherAddressMoo'] = $empData['txtAddressMooMother']; $data['EmpMotherAddressRoad'] = $empData['txtAddressRoadMother']; $data['EmpMother_DistrictID'] = $empData['ddlAddressDistrictMother']; $data['EmpMother_AmphurID'] = $empData['ddlAddressAmphurMother']; $data['EmpMother_ProvinceID'] = $empData['ddlAddressProvinceMother']; $data['EmpMother_ZipcodeID'] = $empData['ddlAddressZipcodeMother']; $data["EmpMotherTelephone"] = $empData["txtTelePhoneMother"]; $data["EmpMotherMobilePhone"] = $empData["txtMobilePhoneMother"]; $data['EmpHouseRegAddressNumber'] = $empData['txtAddressNumberHouseReg']; $data['EmpHouseRegAddressMoo'] = $empData['txtAddressMooHouseReg']; $data['EmpHouseRegAddressRoad'] = $empData['txtAddressRoadHouseReg']; $data['EmpHouseReg_DistrictID'] = $empData['ddlAddressDistrictHouseReg']; $data['EmpHouseReg_AmphurID'] = $empData['ddlAddressAmphurHouseReg']; $data['EmpHouseReg_ProvinceID'] = $empData['ddlAddressProvinceHouseReg']; $data['EmpHouseReg_ZipcodeID'] = $empData['ddlAddressZipcodeHouseReg']; $data['Emp_StatusID'] = 1; $data['EmpCreatedDate'] = date('Y-m-d H:i:s'); $data['EmpLatestUpdate'] = date('Y-m-d H:i:s'); $this->db->insert($this->table, $data); }
public function save() { if ($_POST) { //get post $pData = $this->input->post(NULL, TRUE); //input data $leaveTypeID = $pData["ddlLeaveType"]; //ประเภทการลา $leave_because = $pData['txtBecause']; $leave_start_date = dbDateFormatFromThaiUn543($pData["txtStartDate"]); //วันที่ลา $leave_start_time = $pData["txtStartTime"]; //เวลาที่ลา $leave_end_date = dbDateFormatFromThaiUn543($pData["txtEndDate"]); //วันสิ้นสุดที่ลา $leave_end_time = $pData["txtEndTime"]; //เวลาสิ้นสุดของวันที่ลา //hidden data $this->user_id = $pData["hdUserID"]; $this->emp_id = $pData["hdEmpID"]; $leaveID = $pData["hdLID"]; $pagetype = $pData['hd_pagetype']; $pass = $this->leave->checkExistsDate($this->user_id, $leave_start_date, $leave_end_date, $leaveID); if (!$pass) { echo swalc("ลาไม่ได้นะ", "วันที่คุณลามีการลาอยู่แล้ว", "error", "history.back();"); } else { if ($pagetype == 'add') { $data = array(); $data["L_LTID"] = $leaveTypeID; $data["L_UserID"] = $this->user_id; $data["LBecause"] = $leave_because; $data["LStartDate"] = $leave_start_date; $data["LStartTime"] = $leave_start_time; $data["LEndDate"] = $leave_end_date; $data["LEndTime"] = $leave_end_time; $data["L_WFID"] = 1; $data["L_StatusID"] = 1; $data["LCreatedDate"] = getDateTimeNow(); $data["LLatestUpdate"] = getDateTimeNow(); $leaveID = $this->leave->insertLeave($data); $uploadPath = $this->config->item('upload_employee') . $this->user_id . '/leave/'; $uploadPath = uploadFileControl("fuDocument", $uploadPath, $leaveID, "leave"); } else { if ($pagetype == 'edit' || $pagetype == "editdoc") { //Get old data for insert into log after update new leave data. $query = $this->leave->getDetailByLeaveID($leaveID); $query = $query->row_array(); $old_leave_detail = $query; //ใช้สำหรับส่งไปฟังก์ชั่นส่งเมล์หาหัวหน้า $old_start_date = dateThaiFormatFromDB($query["LStartDate"]); $old_start_time = $query["LStartTime"]; $old_end_date = dateThaiFormatFromDB($query["LEndDate"]); $old_end_time = $query["LEndTime"]; $old_data = array(); $old_data["LL_LID"] = $leaveID; $old_data["LL_Type"] = "edit"; $old_data["LLDetail"] = "แก้ไขใบลา จากขอลาวันที่ " . $old_start_date . " " . $old_start_time . " จนถึงวันที่ " . $old_end_date . " " . $old_end_time . " แก้ไขเป็นขอลาวันที่ " . $leave_start_date . " " . $leave_start_time . " จนถึงวันที่ " . $leave_end_date . " " . $leave_end_time; $old_data["LLDate"] = getDateTimeNow(); $old_date["LLBy"] = $this->user_id; $return_wfid = $old_leave_detail["LReturn_WFID"] == NULL ? 1 : $old_leave_detail["LReturn_WFID"]; if ($pagetype !== "editdoc") { $data = array(); $data["L_LTID"] = $leaveTypeID; $data["L_UserID"] = $this->user_id; $data["LBecause"] = $leave_because; $data["LStartDate"] = $leave_start_date; $data["LStartTime"] = $leave_start_time; $data["LEndDate"] = $leave_end_date; $data["LEndTime"] = $leave_end_time; $data["L_WFID"] = $return_wfid; $data["L_StatusID"] = 1; $data["LLatestUpdate"] = getDateTimeNow(); $data["LReturn_WFID"] = NULL; $where = array(); $where["LID"] = $leaveID; $this->leave->update($data, $where); } else { $data = array(); $data["L_WFID"] = $return_wfid; $data["LLatestUpdate"] = getDateTimeNow(); $data["LReturn_WFID"] = NULL; $where = array(); $where["LID"] = $leaveID; $this->leave->update($data, $where); $old_data["LL_LID"] = $leaveID; $old_data["LL_Type"] = "editdoc"; $old_data["LLDetail"] = "อัพโหลดเอกสารเพิ่มเติม"; $old_data["LLDate"] = getDateTimeNow(); $old_date["LLBy"] = $this->user_id; } $uploadPath = $this->config->item('upload_employee') . $this->user_id . '/leave/'; $uploadPath = uploadFileControl("fuDocument", $uploadPath, $leaveID, "editleave"); //update log for change data $this->load->model('Leavelog_model', 'leavelog'); $this->leavelog->insert($old_data); } } /*********************************************************************************** * คำนวณจำนวนวันลาแล้วบันทึกลง T_LeaveTimeDetail จะเก็บเกี่ยวกับจำนวนชั่วโมงในการลาของแต่ละวัน * โดยคำนวณจาก T_Config ที่เก็บเวลาเริ่มทำงาน + เวลาสิ้นสุดการทำงาน โดยหักลบด้วย เวลาพัก * จะได้ชั่วโมงทำงานที่แท้จริง จากนั้นเอามาหักลบจากที่ลา เช่นลาตอน 4 โมงเย็น เลิกงาน 6 โมงเย็น * ก็บันทึกลงไปใน T_LeaveTimeDetail ว่า ลา 2 ชั่วโมงของวันที่ 23/03/2558 * จากนั้นเวลาเอาไปคิดว่าลาไปจำนวนกี่วันแล้วก็ใช้สูตร จำนวนชั่วโมงที่ลา / เวลาทำงาน * แล้วบันทึกลงไปใน T_LeaveQuota ***********************************************************************************/ /* This sector is find total work hour of day */ $query = $this->configuration->getWorkTime(); $workTimeStart = $query["workTimeStart"]; //เวลาเริ่มทำงาน $workTimeEnd = $query["workTimeEnd"]; //เวลาเลิกงาน $query = $this->configuration->getBreakTime(); $breakTimeStart = $query["breakTimeStart"]; //เวลาเริ่มพัก $breakTimeEnd = $query["breakTimeEnd"]; //เวลาเลิกพัก $workHour = timeDiff($workTimeStart, $workTimeEnd); $breakHour = timeDiff($breakTimeStart, $breakTimeEnd); $totalWorkHour = $workHour - $breakHour; //Normal about time is 8 hours. /** * วนลูปเพื่อเช็คแต่ละวันใช้ลาไปวันละกี่ชั่วโมง * 1. ใช้ function get ว่าระหว่างวันที่เริ่ม กับ วันที่สิ้นสุดลามีวันอะไรบ้างลงใน array * 2. หาจำนวนชั่วโมงของวันที่ลาว่าลากี่ชั่วโมง * 3. บันทึกลง T_LeaveTimeDetail */ $dateLeave = createDateRangeArray($leave_start_date, $leave_end_date); $totalLeaveHour = 0; $numHour = 0; $dataTime = array(); $dataTime["LTD_LID"] = $leaveID; $dataTime["LTDDate"] = ""; $dataTime["LTDHour"] = ""; $dataWorkDate = $this->configuration->getWorkDate(); $workDayStart = $dataWorkDate["workDateStart"]; $workDayEnd = $dataWorkDate["workDateEnd"]; //ต้องคำนวณด้วยว่าเป็นวันทำงานหรือเปล่า อย่างเช่นตอนนี้มีการผิดพลาดเกิดขึ้นเมื่อลา //วันศุกร์ - วันจันทร์ ตย. วันศุกร์ลา 9:00 - วันจันทร์ 9:00 จะถูกนับเป็น 4 วัน //ต้องเอาวันที่หยุดใน config มาหักลบด้วย ถึงจะได้ตัวเลขที่แท้จริง for ($i = 0; $i < count($dateLeave); $i++) { if (checkWeekDay($dateLeave[$i]) >= $workDayStart && checkWeekDay($dateLeave[$i]) <= $workDayEnd) { //เช็คว่าวันที่ลาอยู่ระหว่างวันทำงานหรือไม่ if (count($dateLeave) == 1) { $numHour = timeDiff($leave_start_time, $leave_end_time); if ($numHour > 6) { $numHour = $numHour - $breakHour; } $totalLeaveHour = $totalLeaveHour + $numHour; } else { if ($dateLeave[$i] == $leave_start_date) { $numHour = timeDiff($leave_start_time, $workTimeEnd); if ($numHour > 6) { $numHour = $numHour - $breakHour; } //ถ้าเป็นวันเริ่มต้นให้เอาเวลาของวันเริ่มมาคำนวณหาจำนวนชั่วโมงการลา $totalLeaveHour = $totalLeaveHour + $numHour; } else { $numHour = $totalWorkHour; //ถ้าเป็นวันที่อยู่ระหว่างวันเริ่มกับวันสิ้นสุดให้เอาจำนวนชั่วโมงที่ทำงานมาเลย $totalLeaveHour = $totalLeaveHour + $totalWorkHour; } if ($dateLeave[$i] == $leave_end_date) { $numHour = timeDiff($workTimeStart, $leave_end_time); //ถ้าเป็นวันสิ้นสุดการลาให้เอาเวลาของวันสิ้นสุดมาคำนวณหาจำนวนชั่วโมงการลา $totalLeaveHour = $totalLeaveHour + $numHour; } } $dataTime["LTDDate"] = $dateLeave[$i]; $dataTime["LTDHour"] = $numHour; //case edit delete old leave time detail if ($pagetype == 'edit') { $this->leavetimedetail->deleteByLeaveID($leaveID); } $this->leavetimedetail->insertTime($dataTime); } } /** * เอาจำนวนชั่วโมงทั้งหมด มาหารจำนวนชั่วโมงที่ต้องทำงานแต่ละวัน หาว่าใช้ไปกี่วัน * แล้วบันทึกลงไปที่ T_LeaveQuota **/ //change to calculate all leave request to get quota $this->leavequota->calculate_quota($this->user_id, $leaveTypeID); //ใช้การคำนวณร่วมกับ leavetimedetail //หลังจากบันทึกทุกอย่างเสร็จแล้ว ส่ง อีเมล์บอกหัวหน้างานของตัวเองว่ามีการขอลา //insert log log_leave("send leave request", $leaveID, "ส่งใบลา", $this->user_id); //run workflow system $this->load->library("WorkflowSystem"); $process = ''; if ($pagetype == 'add') { $this->workflowsystem->set_require_data($leaveID, "leave", "request"); $process = $this->workflowsystem->run(); //$process = $this->send_mail_to_leave_headman($leaveID,1); } else { if ($pagetype == 'edit') { $this->workflowsystem->set_require_data($leaveID, "leave", "edit request"); $process = $this->workflowsystem->run(); //$process = $this->send_mail_to_leave_headman($leaveID,1,'edit',$old_leave_detail); } else { if ($pagetype == 'editdoc') { $this->workflowsystem->set_require_data($leaveID, "leave", "edit document"); $process = $this->workflowsystem->run(); //$process = $this->send_mail_to_leave_headman($leaveID,1,'edit',$old_leave_detail); } } } if ($process != 'success') { echo swalc('ผิดพลาด!!', 'ระบบบันทึกการลาของคุณแล้ว แต่ไม่สามารถส่งอีเมล์ถึงหัวหน้าของคุณได้<br/>' + $this->phpmailer->ErrorInfo, 'error', "window.location.href = '" . site_url("Leave") . "'"); } else { echo swalc('สำเร็จ!!', 'บันทึกการลาของคุณพร้อมส่งอีเมล์ให้หัวหน้าเรียบร้อยแล้ว', 'success', "window.location.href = '" . site_url("Leave") . "'"); } } } }
private function _save($ot_id = 0) { $this->load->library("WorkflowSystem"); if ($_POST) { $post = $this->input->post(NULL, TRUE); $ot_request_by = $post['input_team']; $ot_date = $post['input_ot_date']; $ot_time_from = $post['input_ot_time_from']; $ot_time_to = $post['input_ot_time_to']; $ot_remark = $post['input_ot_remark']; $data = array(); $data['wot_date'] = dbDateFormatFromThaiUn543($ot_date); $data['wot_time_from'] = $ot_time_from; $data['wot_time_to'] = $ot_time_to; $data["wot_remark"] = $ot_remark; $data['wot_request_hour'] = timeDiff($ot_time_from, $ot_time_to); $data['wot_request_by'] = $ot_request_by; $data['wot_workflow_id'] = $this->workflow_end_id; $data['wot_status_id'] = 1; $data['wot_headman_user_id_send_instead'] = $this->user_id; if ($ot_id === 0) { $data['wot_request_date'] = getDateTimeNow(); $ot_id = $this->ot->insert($data); insert_log_ot($ot_id, 'headman add instead', 'ส่งใบคำขอทำงานล่วงเวลาแทนผู้ใต้บังคับบัญชา'); $this->workflowsystem->set_require_data($ot_id, "overtime", "success"); } //run workflow $process = $this->workflowsystem->run(); //alert after all process if ($ot_id > 0 && $process == 'success') { echo swalc("บันทึกเรียบร้อย", '', 'success', 'window.location.href = "' . site_url('headman/Sendotinsteadteam') . '"'); } else { if ($ot_id > 0 && $process != 'success') { echo swalc("บันทึกเรียบร้อย", 'แต่ไม่สามารถส่งอีเมล์ได้', 'warning', 'window.location.href = "' . site_url('headman/Sendotinsteadteam') . '"'); } else { echo swalc("ผิดพลาด กรุณาลองใหม่ภายหลัง", '', 'error', 'window.location.href = "' . site_url('headman/Sendotinsteadteam') . '"'); } } } }
private function _save() { //get post value $post = $this->input->post(null, true); $news_id = intval($post["hd_news_id"]); $newstype_id = $post["input_newstype"]; $news_topic = $post["input_topic"]; $news_detail = $post["input_detail"]; $news_show_start_date = $post["input_show_start_date"] == "" ? "" : dbDateFormatFromThaiUn543($post["input_show_start_date"]); $news_show_end_date = $post["input_show_end_date"] == "" ? "" : dbDateFormatFromThaiUn543($post["input_show_end_date"]); //set data for insert $data = array(); $data["news_newstype_id"] = $newstype_id; $data["news_topic"] = $news_topic; $data["news_detail"] = $news_detail; $data["news_show_start_date"] = $news_show_start_date; $data["news_show_end_date"] = $news_show_end_date; $data["news_create_by"] = $this->user_id; $data["news_create_date"] = date('Y-m-d H:i:s'); $data["news_latest_update_by"] = $this->user_id; $data["news_latest_update_date"] = date('Y-m-d H:i:s'); $data["news_status"] = 1; //insert or edit news if ($news_id === 0) { $news_id = $this->news->insert($data); } else { $where = array("news_id" => $news_id); $this->news->update($data, $where); } }