⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customizablecsvimport.php

📁 国外的人才求职招聘最新版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/** * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures * all the essential functionalities required for any enterprise. * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com * * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of * the GNU General Public License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program; * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA  02110-1301, USA * */require_once ROOT_PATH . '/lib/dao/DMLFunctions.php';require_once ROOT_PATH . '/lib/dao/SQLQBuilder.php';require_once ROOT_PATH . '/lib/confs/sysConf.php';require_once ROOT_PATH . '/lib/common/CommonFunctions.php';require_once ROOT_PATH . '/lib/models/eimadmin/import/CSVImportPlugin.php';require_once ROOT_PATH . '/lib/models/eimadmin/CustomImport.php';require_once ROOT_PATH . '/lib/models/hrfunct/EmpDirectDebit.php';require_once ROOT_PATH . '/lib/models/hrfunct/EmpInfo.php';require_once ROOT_PATH . '/lib/dao/DMLFunctions.php';/** * Class to generate CSV file for import to based on user defined * CustomImport. */class CustomizableCSVImport implements CSVImportPlugin {	const MAX_VAR_LENGTH_TO_PRINT = 25;	/** Custom import object */	private $customImport;	private $usStateList;	/**	 * Construct instance of Customizable CSV Import	 */	public function __construct($id) {		$this->customImport = CustomImport :: getCustomImport($id);		if (empty ($this->customImport)) {			throw new Exception("CustomImport with id = $id not found!");		}		$provinceInfo = new ProvinceInfo();		$states = $provinceInfo->getProvinceCodes('US');		$this->usStateList = array();		foreach ($states as $state) {			$this->usStateList[$state[1]] =	$state[2];		}	}	/**	 * Get descriptive name for this plugin	 *	 * @return Name for this plugin	 */	public function getName() {		return $this->customImport->getName();	}	/** Get number of header rows to skip */	public function getNumHeaderRows() {		$hasHeader = $this->customImport->getContainsHeader();		return $hasHeader ? 1 : 0;	}	/** Get number of csv columns expected */	public function getNumColumns() {		return $this->customImport->getFieldCount();	}	/**	 * Import CSV data to the system	 *	 * @param array data Array containing one row of CSV data	 */	public function importCSVData($data) {		$empinfo = new EmpInfo();		$firstName = $this->_getField(CustomImport :: FIELD_FIRSTNAME, $data);		$lastName = $this->_getField(CustomImport :: FIELD_LASTNAME, $data);		if (empty ($firstName) || empty ($lastName)) {			$compFields = implode(',', $this->customImport->getCompulsaryFields());			throw new CSVImportException("Following fields are compulsary: " . $compFields, CSVImportException :: COMPULSARY_FIELDS_MISSING_DATA);		}		$empinfo->setEmpFirstName($firstName);		$empinfo->setEmpLastName($lastName);		$middleName = $this->_getField(CustomImport :: FIELD_MIDDLENAME, $data);		$empinfo->setEmpMiddleName($middleName);		$empId = $this->_getField(CustomImport :: FIELD_EMPID, $data);		if (empty ($empId)) {			$empId = $empinfo->getLastId();		}		// check for duplicate employee ID		if ($empinfo->checkIfEmpIDInUse($empId)) {			throw new CSVImportException("Employee ID is in use: $empId", CSVImportException::DUPLICATE_EMPLOYEE_ID);		}		$empinfo->setEmployeeID($empId);		// Check for duplicate employee name		if ($empinfo->checkForEmployeeWithSameName($lastName, $firstName, $middleName)) {			throw new CSVImportException("Employee with same name exists: $lastName, $firstName $middleName", CSVImportException::DUPLICATE_EMPLOYEE_NAME);		}		$dobValue = $this->_getField(CustomImport :: FIELD_BIRTHDATE, $data);		$dob = self::_getFormattedDate($dobValue);		if ($dob) {			$empinfo->setEmpDOB($dob);		}		$custom1 = $this->_getField(CustomImport :: FIELD_CUSTOM1, $data);		if ($custom1) {			$empinfo->setCustom1($custom1);		}		$custom2 = $this->_getField(CustomImport :: FIELD_CUSTOM2, $data);		if ($custom2) {			$empinfo->setCustom1($custom2);		}		$custom3 = $this->_getField(CustomImport :: FIELD_CUSTOM3, $data);		if ($custom3) {			$empinfo->setCustom1($custom3);		}		$custom4 = $this->_getField(CustomImport :: FIELD_CUSTOM4, $data);		if ($custom4) {			$empinfo->setCustom1($custom4);		}		$custom5 = $this->_getField(CustomImport :: FIELD_CUSTOM5, $data);		if ($custom5) {			$empinfo->setCustom1($custom5);		}		$custom6 = $this->_getField(CustomImport :: FIELD_CUSTOM6, $data);		if ($custom6) {			$empinfo->setCustom1($custom6);		}		$custom7 = $this->_getField(CustomImport :: FIELD_CUSTOM7, $data);		if ($custom7) {			$empinfo->setCustom1($custom7);		}		$custom8 = $this->_getField(CustomImport :: FIELD_CUSTOM8, $data);		if ($custom8) {			$empinfo->setCustom1($custom8);		}		$custom9 = $this->_getField(CustomImport :: FIELD_CUSTOM9, $data);		if ($custom9) {			$empinfo->setCustom1($custom9);		}		$custom10 = $this->_getField(CustomImport :: FIELD_CUSTOM10, $data);		if ($custom10) {			$empinfo->setCustom1($custom10);		}		$joinedValue = $this->_getField(CustomImport :: FIELD_JOINEDDATE, $data);		$joined = self::_getFormattedDate($joinedValue);		if ($joined) {			$empinfo->setEmpJoinedDate($joined);		}		$genderValues = array (			1 => "M",			2 => "F"		);		$genderVal = $this->_getField(CustomImport :: FIELD_GENDER, $data, false);		if (!empty($genderVal)) {			$gender = self::_getKeyFromMap($genderValues, $genderVal);			if (empty($gender)) {				throw new CSVImportException("Invalid value for gender: $genderVal", CSVImportException::INVALID_TYPE);			}			$empinfo->setEmpGender($gender);		}		$ssn = $this->_getField(CustomImport :: FIELD_SSN, $data);		if ($ssn) {			$empinfo->setEmpSSNNo($ssn);		}		$street1 = $this->_getField(CustomImport :: FIELD_STREET1, $data);		if ($street1) {			$empinfo->setEmpStreet1($street1);		}		$street2 = $this->_getField(CustomImport :: FIELD_STREET2, $data);		if ($street2) {			$empinfo->setEmpStreet2($street2);		}		$city = $this->_getField(CustomImport :: FIELD_CITY, $data);		if ($city) {			$empinfo->setEmpCity($city);		}		$state = $this->_getField(CustomImport :: FIELD_STATE, $data);		if ($state) {			$empinfo->setEmpProvince($state);		}		$zipCode = $this->_getField(CustomImport :: FIELD_ZIP, $data);		if ($zipCode) {			$empinfo->setEmpZipCode($zipCode);		}		$homePhone = $this->_getField(CustomImport :: FIELD_HOME_PHONE, $data);		if ($homePhone) {			$empinfo->setEmpHomeTelephone($homePhone);		}		$mobile = $this->_getField(CustomImport :: FIELD_MOBILE_PHONE, $data);		if ($mobile) {			$empinfo->setEmpMobile($mobile);		}		$workPhone = $this->_getField(CustomImport :: FIELD_WORK_PHONE, $data);		if ($workPhone) {			$empinfo->setEmpWorkTelephone($workPhone);		}		$workEmail = $this->_getField(CustomImport :: FIELD_WORK_EMAIL, $data);		if ($workEmail) {			$empinfo->setEmpWorkEmail($workEmail);		}		$otherEmail = $this->_getField(CustomImport :: FIELD_OTHER_EMAIL, $data);		if ($otherEmail) {			$empinfo->setEmpOtherEmail($otherEmail);		}		$drivingLicence = $this->_getField(CustomImport :: FIELD_DRIVING_LIC, $data);		if ($drivingLicence) {			$empinfo->setEmpDriLicNo($drivingLicence);		}		$workStation = $this->_getField(CustomImport :: FIELD_WORKSTATION, $data);		if (!empty($workStation)) {			$workStationID = $this->_getCompStructure($workStation);			$empinfo->setEmpLocation($workStationID);		} else {			$empinfo->setEmpLocation('');		}		// First direct debit account		$routing = $this->_getField(CustomImport::FIELD_DD1ROUTING, $data);		$account = $this->_getField(CustomImport::FIELD_DD1ACCOUNT, $data);		$amount = $this->_getField(CustomImport::FIELD_DD1AMOUNT, $data);		$accountType = $this->_getField(CustomImport::FIELD_DD1CHECKING, $data, false);		$transactionType = $this->_getField(CustomImport::FIELD_DD1AMOUNTCODE, $data, false);		$dd1 = $this->_getDirectDeposit($routing, $account, $amount, $accountType, $transactionType);		// Second direct debit account		$routing = $this->_getField(CustomImport::FIELD_DD2ROUTING, $data);		$account = $this->_getField(CustomImport::FIELD_DD2ACCOUNT, $data);		$amount = $this->_getField(CustomImport::FIELD_DD2AMOUNT, $data);		$accountType = $this->_getField(CustomImport::FIELD_DD2CHECKING, $data, false);		$transactionType = $this->_getField(CustomImport::FIELD_DD2AMOUNTCODE, $data, false);		$dd2 = $this->_getDirectDeposit($routing, $account, $amount, $accountType, $transactionType);		// Employee Tax information		$federalTaxStatus = $this->_getField(CustomImport::FIELD_FITWSTATUS, $data);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -