function parseData($postArr) { $dd = new EmpDirectDebit(); $dd->setEmpNumber($postArr['txtEmpID']); $dd->setDDSeqNo($postArr['DDSeqNo']); $dd->setRoutingNumber($postArr['DDRoutingNumber']); $dd->setAccount($postArr['DDAccount']); $dd->setAmount($postArr['DDAmount']); $dd->setAccountType($postArr['DDAccountType']); $dd->setTransactionType($postArr['cmbTransactionType']); return $dd; }
/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $conf = new Conf(); $this->connection = mysql_connect($conf->dbhost . ":" . $conf->dbport, $conf->dbuser, $conf->dbpass); mysql_select_db($conf->dbname); $this->_truncateTables(); // insert some test data $this->_runQuery("INSERT INTO hs_hr_custom_export(export_id, name, fields, headings) VALUES (1, 'Export 1', 'empId,lastName,firstName,middleName,street1,street2,city', '')"); $this->_runQuery("INSERT INTO hs_hr_custom_export(export_id, name, fields, headings) VALUES (2, 'Export 2', 'empId,lastName,firstName,city', 'Employee Id,Last Name,First Name,City')"); $this->_runQuery("INSERT INTO hs_hr_custom_export(export_id, name, fields, headings) VALUES (3, 'Export 3', 'empId,street1,street2,city', 'Employee Id,Address1, Address2, City')"); // insert some employee data $sql = "INSERT INTO hs_hr_employee" . "(emp_number, employee_id, emp_lastname, emp_firstname, emp_middle_name, " . "emp_nick_name, emp_smoker, ethnic_race_code, emp_birthday, nation_code, " . "emp_gender, emp_marital_status, emp_ssn_num, emp_sin_num, emp_other_id, " . "emp_dri_lice_num, emp_dri_lice_exp_date, emp_military_service, emp_status, " . "job_title_code, eeo_cat_code, work_station, " . "emp_street1, emp_street2, city_code, coun_code, provin_code, emp_zipcode, " . "emp_hm_telephone, emp_mobile, emp_work_telephone, emp_work_email, " . "sal_grd_code, joined_date,\temp_oth_email, " . "custom1, custom2, custom3, custom4, custom5, " . "custom6, custom7, custom8, custom9, custom10) VALUES (" . "'10', 'E1921A', 'Karunadasa', 'Kamal', 'K', " . "NULL, NULL, NULL, '1974-11-20', NULL, " . "1, NULL, '987654320', '', '', " . "null, NULL, NULL, 'EST001', " . "NULL, NULL, NULL, " . "'111 Main Street', 'SUITE A29', 'Houston', 'US', 'TX', '77845', " . "'', '', '', NULL, " . "NULL, '1997-12-11', NULL, " . "'c1', 'c2', 'c3', 'c4', 'c5'," . "'c6', 'c7', 'c8', 'c9', 'c10'" . ")"; if (KeyHandlerOld::keyExists()) { $key = KeyHandlerOld::readKey(); $sql = str_replace("'987654320'", "AES_ENCRYPT('987654320', '{$key}')", $sql); } $this->_runQuery($sql); $sql = "INSERT into hs_hr_emp_us_tax(emp_number, tax_federal_status, tax_federal_exceptions, " . "tax_state, tax_state_status, tax_state_exceptions, tax_unemp_state,tax_work_state) VALUES (" . "10, 'NRA', 2, 'MD', 'NA', 3, 'VA', 'AZ')"; $this->_runQuery($sql); // Add direct debit information $dd = new EmpDirectDebit(); $dd->setEmpNumber(10); $dd->setRoutingNumber(11111); $dd->setAccount('AC 1'); $dd->setAmount(121); $dd->setAccountType('CHECKING'); $dd->setTransactionType('BLANK'); $this->assertTrue($dd->add(), mysql_error()); $dd = new EmpDirectDebit(); $dd->setEmpNumber(10); $dd->setRoutingNumber(22222); $dd->setAccount('AC #2'); $dd->setAmount(23); $dd->setAccountType('SAVINGS'); $dd->setTransactionType('FLATMINUS'); $this->assertTrue($dd->add(), mysql_error()); }
/** * @todo Implement testGetValue(). */ public function testGetValue() { // Direct $field = new CSVField('name', CSVField::FIELD_TYPE_DIRECT); $row = array('id' => '1', 'name' => 'Ranasinghe', 'age' => 39); $ddList = array(); $this->assertEquals('Ranasinghe', $field->getValue($row, $ddList)); // invalid (unavailable) name $field = new CSVField('middle_name', CSVField::FIELD_TYPE_DIRECT); $this->assertEquals('', $field->getValue($row, $ddList)); // Date $field = new CSVField('joined_date', CSVField::FIELD_TYPE_DATE); $row = array('id' => '1', 'name' => 'Ranasinghe', 'joined_date' => '2003-01-20'); $ddList = array(); $expected = LocaleUtil::getInstance()->formatDate($row['joined_date']); $this->assertEquals($expected, $field->getValue($row, $ddList)); // invalid (unavailable) name $field = new CSVField('birth_date', CSVField::FIELD_TYPE_DATE); $this->assertEquals('', $field->getValue($row, $ddList)); // From Map $genderMap = array(1 => "M", 2 => "F"); $field = new CSVField('sex', CSVField::FIELD_TYPE_FROMMAP, $genderMap); $row = array('id' => '1', 'name' => 'Ranasinghe', 'sex' => 1, 'joined_date' => '2003-01-20'); $ddList = array(); $this->assertEquals('M', $field->getValue($row, $ddList)); // invalid (unavailable) name $field = new CSVField('gender', CSVField::FIELD_TYPE_FROMMAP, $genderMap); $this->assertEquals('', $field->getValue($row, $ddList)); // direct debit $dd1 = new EmpDirectDebit(); $dd1->setEmpNumber(1); $dd1->setDDSeqNo(1); $dd1->setRoutingNumber(121212); $dd1->setAccount('An account'); $dd1->setAmount(100); $dd1->setAccountType('CHECKING'); $dd1->setTransactionType('BLANK'); $dd2 = new EmpDirectDebit(); $dd2->setEmpNumber(222); $dd2->setDDSeqNo(2); $dd2->setRoutingNumber(444444); $dd2->setAccount('My Account'); $dd2->setAmount(200); $dd2->setAccountType('SAVINGS'); $dd2->setTransactionType('PERC'); $ddList = array($dd1); $field = new CSVField('DD1_Amount', CSVField::FIELD_TYPE_DIRECT_DEBIT); $this->assertEquals(100, $field->getValue($row, $ddList)); $field = new CSVField('DD1_Routing', CSVField::FIELD_TYPE_DIRECT_DEBIT); $this->assertEquals(121212, $field->getValue($row, $ddList)); $field = new CSVField('DD1_Account', CSVField::FIELD_TYPE_DIRECT_DEBIT); $this->assertEquals('An account', $field->getValue($row, $ddList)); $field = new CSVField('DD1_AmountCode', CSVField::FIELD_TYPE_DIRECT_DEBIT); $this->assertEquals('Blank', $field->getValue($row, $ddList)); $field = new CSVField('DD1_Checking', CSVField::FIELD_TYPE_DIRECT_DEBIT); $this->assertEquals('Y', $field->getValue($row, $ddList)); // Second direct debit settings $ddList = array($dd1, $dd2); $field = new CSVField('DD2_Checking', CSVField::FIELD_TYPE_DIRECT_DEBIT); $this->assertEquals('', $field->getValue($row, $ddList)); $field = new CSVField('DD2_AmountCode', CSVField::FIELD_TYPE_DIRECT_DEBIT); $this->assertEquals('%', $field->getValue($row, $ddList)); // invalid (unavailable) name $field = new CSVField('DD1_AAAmount', CSVField::FIELD_TYPE_DIRECT_DEBIT); try { $field->getValue($row, $ddList); $this->fail("Exception expected"); } catch (Exception $e) { } }
/** * 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; } }
/** * Build a EmpDirectDebit object from the database results row * * @param array $row associative array containing database data * * @return EmpDirectDebit object */ private function _buildObject($row) { $dd = new EmpDirectDebit(); $dd->setEmpNumber($row[self::DB_FIELD_EMP_NUMBER]); $dd->setDDSeqNo($row[self::DB_FIELD_SEQNO]); $dd->setRoutingNumber($row[self::DB_FIELD_ROUTING_NUM]); $dd->setAccount($row[self::DB_FIELD_ACCOUNT]); $dd->setAmount($row[self::DB_FIELD_AMOUNT]); $dd->setAccountType($row[self::DB_FIELD_ACCOUNT_TYPE]); $dd->setTransactionType($row[self::DB_FIELD_TRANSACTION_TYPE]); return $dd; }