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

📄 customizablecsvimport.php

📁 国外的人才求职招聘最新版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
		$fedEx = $this->_getField(CustomImport::FIELD_FITWEXCEMPTIONS, $data);		$taxState = $this->_getField(CustomImport::FIELD_SITWSTATE, $data, false);		$stateTaxStatus = $this->_getField(CustomImport::FIELD_SITWSTATUS, $data);		$stateEx = $this->_getField(CustomImport::FIELD_SITWEXCEMPTIONS, $data);		$unemploymentState = $this->_getField(CustomImport::FIELD_SUISTATE, $data, false);		$workState = $this->_getField(CustomImport::FIELD_WORKSTATE, $data, false);		$taxInfo = $this-> _getTaxInfo($federalTaxStatus, $fedEx, $taxState, $stateTaxStatus, $stateEx, $unemploymentState, $workState);		$result = $empinfo->addEmpMain();		if (!$result) {			throw new CSVImportException("Error inserting employee", CSVImportException::UNKNOWN_ERROR);		}		$empNumber = $empinfo->getEmpId();		$empinfo->setEmpEthnicRace(0);		$empinfo->setEmpNation(0);		$result = $empinfo->updateEmpPers();		if (!$result) {			throw new CSVImportException("Error inserting personal info", CSVImportException::UNKNOWN_ERROR);		}		$result = $empinfo->updateEmpContact();		if (!$result) {			throw new CSVImportException("Error inserting contact details", CSVImportException::UNKNOWN_ERROR);		}		$empinfo->setEmpStatus('0');		$empinfo->setEmpJobTitle('0');		$empinfo->setEmpEEOCat('0');		$result = $empinfo->updateEmpJobInfo();		if (!$result) {			throw new CSVImportException("Error inserting job details", CSVImportException::UNKNOWN_ERROR);		}		// Save tax information		if (!empty($taxInfo)) {			$taxInfo->setEmpNumber($empNumber);			$taxInfo->updateEmpTax();		}		// Save Direct Debit information		if (!empty($dd1)) {			$dd1->setEmpNumber($empNumber);			$dd1->add();		}		if (!empty($dd2)) {			$dd2->setEmpNumber($empNumber);			$dd2->add();		}		return $empNumber;	}	/**	 * Get company structure	 *	 * Throws exception if matching company structure location not found.	 *	 * @param string $workStation	 * @return $string ID of matching company structure location.	 */	private function _getCompStructure($workStation) {		$conn = new DMLFunctions();		$workStation = mysql_real_escape_string($workStation);		$sql = "SELECT id FROM `hs_hr_compstructtree` WHERE `title` LIKE '" . $workStation . "%'";		$result = $conn->executeQuery($sql);		if ($result && mysql_num_rows($result) == 1) {			$row = mysql_fetch_row($result);			return $row[0];		} else {			throw new CSVImportException("Company structure: " . $workStation . " not found", CSVImportException::MISSING_WORKSTATION);		}	}	/**	 * Get the given field from the data row	 * @param string $fieldName The field name	 * @param array $data Array containing data for one CSV row	 * @param boolean $checkLength Should the length be checked?	 *	 * @return string value of field or null if field not defined	 */	private function _getField($fieldName, $data, $checkLength = true) {		$value = null;		$assignedFields = $this->customImport->getAssignedFields();		$key = array_search($fieldName, $assignedFields);		if ($key !== FALSE) {			$value = $data[$key];			if ($checkLength) {				$customImport = new CustomImport();				if (!$customImport->checkFieldLength($fieldName, $value)) {					if (strlen($value) > self::MAX_VAR_LENGTH_TO_PRINT) {						$valueSample = substr($value, 0, self::MAX_VAR_LENGTH_TO_PRINT) . '...';					} else {						$valueSample = $value;					}					throw new CSVImportException("Value '{$valueSample}' exceeds max length for field: $fieldName", CSVImportException::FIELD_TOO_LONG);				}			}		}		return $value;	}	/**	 * Format and return date	 * @param string $date date string	 * @return string formatted date or null if not a valid date	 */	private static function _getFormattedDate($date) {		$formattedDate = null;		$fmt = str_replace(' ', '/', $date);		$fmt = str_replace('-', '/', $date);		$dateStamp = strtotime($fmt);		if ($dateStamp > 0) {			$formattedDate = date("Y-m-d", $dateStamp);		}		return $formattedDate;	}	/**	 * Get a DirectDeposit object after validating input	 * Throws an error on invalid input data	 *	 * @return DirectDeposit object or null if none of the data is available.	 */	private function _getDirectDeposit($routing, $account, $amount, $accountType, $transactionType) {		// If all empty, return null		if (empty($routing) && empty($account)  && empty($amount) && empty($accountType) && empty($transactionType)) {			return null;		}		$transactionTypes = array (			EmpDirectDebit::TRANSACTION_TYPE_BLANK => 'Blank',			EmpDirectDebit::TRANSACTION_TYPE_PERCENTAGE => '%',			EmpDirectDebit::TRANSACTION_TYPE_FLAT => 'Flat',			EmpDirectDebit::TRANSACTION_TYPE_FLAT_MINUS => 'Flat-'		);		$accountTypes = array (			EmpDirectDebit::ACCOUNT_TYPE_CHECKING => "Y",			EmpDirectDebit::ACCOUNT_TYPE_SAVINGS => ""		);		$accountType = self::_getKeyFromMap($accountTypes, $accountType);		$transactionType = self::_getKeyFromMap($transactionTypes, $transactionType);		if (empty($routing) || empty($account)  || empty($amount) || empty($accountType) || empty($transactionType)) {			$invalid = array();			if (empty($routing)) {				$invalid[] = "Routing Number";			}			if (empty($account)) {				$invalid[] = "Account";			}			if (empty($amount)) {				$invalid[] = "Amount";			}			if (empty($accountType)) {				$invalid[] = "AccountType";			}			if (empty($transactionType)) {				$invalid[] = "TransactionType";			}			$msg = implode(',', $invalid);			// If at least one parameter is specifiec, all the rest should be specified as well.			throw new CSVImportException("Direct Debit data not complete invalid. Check following fields: $msg", CSVImportException::DD_DATA_INCOMPLETE);		} else {			// Validate routing number and amount			if (!CommonFunctions::isInt($routing)) {				throw new CSVImportException("Routing number not an integer: $routing", CSVImportException::INVALID_TYPE);			}			if (!is_numeric($amount)) {				throw new CSVImportException("Amount not a number: $amount", CSVImportException::INVALID_TYPE);			}			$dd = new EmpDirectDebit();			$dd->setRoutingNumber($routing);			$dd->setAccount($account);			$dd->setAmount($amount);			$dd->setAccountType($accountType);			$dd->setTransactionType($transactionType);			return $dd;		}	}	private function _getTaxInfo($federalTaxStatus, $fedEx, $taxState, $stateTaxStatus, $stateEx, $unemploymentState, $workState) {		$allStatuses = array(EmpTax::TAX_STATUS_MARRIED,EmpTax::TAX_STATUS_SINGLE,						EmpTax::TAX_STATUS_NONRESIDENTALIEN, EmpTax::TAX_STATUS_NOTAPPLICABLE);		$taxInfo = new EmpTax();		if (!empty($federalTaxStatus)) {			if (array_search($federalTaxStatus, $allStatuses) === FALSE) {				throw new CSVImportException("Invalid Federal tax status value $federalTaxStatus", CSVImportException::INVALID_TYPE);			}			$taxInfo->setFederalTaxStatus($federalTaxStatus);		}  		if (!empty($fedEx)) {			if (!CommonFunctions::isInt($fedEx)) {				throw new CSVImportException("Federal tax exemptions should be an integer: $fedEx", CSVImportException::INVALID_TYPE);			}			$taxInfo->setFederalTaxExceptions($fedEx);		}		if (!empty($taxState)) {			$state = $this->_getUSState($taxState);			$taxInfo->setTaxState($state);		}		if (!empty($stateTaxStatus)) {			if (array_search($federalTaxStatus, $allStatuses) === FALSE) {				throw new CSVImportException("Invalid State tax status value $stateTaxStatus", CSVImportException::INVALID_TYPE);			}			$taxInfo->setStateTaxStatus($stateTaxStatus);		}		if (!empty($stateEx)) {			if (!CommonFunctions::isInt($stateEx)) {				throw new CSVImportException("State tax exemptions should be an integer: $stateEx", CSVImportException::INVALID_TYPE);			}			$taxInfo->setStateTaxExceptions($stateEx);		}		if (!empty($unemploymentState)) {			$state = $this->_getUSState($unemploymentState);			$taxInfo->setTaxUnemploymentState($state);		}		if (!empty($workState)) {			$state = $this->_getUSState($workState);			$taxInfo->setTaxWorkState($state);		}		return $taxInfo;	}	/**	 * Check if passed value is a US State name or abbreviation and return the	 * correct state abbreviation. Throws an exception if not a correct state abbreviation	 *	 * @param string $state State name or abreviation	 * @return string state abbreviation	 */	private function _getUSState($state) {		if (array_key_exists($state, $this->usStateList)) {			return $state;		}		$key = array_search($state, $this->usStateList);		if ($key === false) {			throw new CSVImportException("Invalid value for state: $state", CSVImportException::INVALID_TYPE);		}		return $key;	}	/**	 * Get the key for the given value from the map (array)	 *	 * @param array $map Associative array	 * @param string $value Value to look for	 *	 * @return string value of the key or null if not found.	 */	private static function _getKeyFromMap($map, $value) {		$key = array_search($value, $map);		return ($key === FALSE) ? null : $key;	}}?>

⌨️ 快捷键说明

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