method name) * @var array */ private $vendorFieldsPermissions = array( 'ssn' => 'isSsnPermission', 'encrypted_tin' => 'isTinPermission', 'foreign_tax_id' => 'isSsnPermission', 'encrypted_foreign_tin' => 'isTinPermission' ); /** * List of methods for post processing vendor field data (after extraction) * (field name => method name) * @var array */ private $vendorFieldPostProcessors = array( 'encrypted_tin' => 'decryptTin', 'encrypted_foreign_tin' => 'decryptTin' ); /** * Constructor * * @param int $vendor_id */ public function __construct($vendor_id, $wrapperObj) { $this->vendor_id = intval($vendor_id); $awsConfigs = yaml_parse_file(APPLICATION_PATH . '/configs/aws.yml'); $logger = Zend_Registry::get('applicationLoggerOA'); $owsFeaturesServiceClient = new FeatureService($logger); $userContext = AccountContext::fromLegacy((string)$_SESSION['S_USERID'], 'oa'); $isSapVendorIdEnabled = $owsFeaturesServiceClient->isVariant( 'sap_vendor_id', 'enabled', $userContext ); $isW8LOBEnabled = $owsFeaturesServiceClient->isVariant( 'w8_lob', 'enabled', $userContext ); $isTransferPricingCountryEnabled = $owsFeaturesServiceClient->isVariant( 'transfer_pricing_country', 'enabled', $userContext ); $isAddUSWhtTreatyOptFieldEnabled = $owsFeaturesServiceClient->isVariant( 'oa_add_us_wht_treaty_opt_field', 'enabled', $userContext ); if ($isSapVendorIdEnabled) { array_push($this->vendorFields, 'sap_vendor_id'); } if ($isW8LOBEnabled) { array_push($this->vendorFields, 'w8_lob'); } if ($isAddUSWhtTreatyOptFieldEnabled) { array_push($this->vendorFields, 'us_wht_treaty_opt_in'); } if ($isTransferPricingCountryEnabled) { array_push($this->vendorFields, 'transfer_pricing_country'); $this->vendorFieldsPermissions['transfer_pricing_country'] = 'isTinPermission'; } $this->set_vendor_data($wrapperObj); } /** * Fills array with vendor data from the database */ // @codingStandardsIgnoreStart protected function set_vendor_data($wrapperObj) { // @codingStandardsIgnoreEnd if ($this->vendor_id) { $sql = 'SELECT * FROM vendor WHERE vendor_id = ?'; $result = $wrapperObj->executeQuery($sql, [$this->vendor_id]); if ($result === false) { show_pdo_error($sql, $wrapperObj->getLastStatement()); } if ($RowData = $result[0]) { foreach ($RowData as $key => $value) { $checkPermissionMethod = (isset($this->vendorFieldsPermissions[$key])) ? $this->vendorFieldsPermissions[$key] : ''; if (in_array($key, $this->vendorFields) && (!$checkPermissionMethod || $this->{$checkPermissionMethod}($wrapperObj))) { $postProcessorMethod = (isset($this->vendorFieldPostProcessors[$key])) ? $this->vendorFieldPostProcessors[$key] : ''; $this->vendorData[$key] = (!empty($postProcessorMethod)) ? $this->{$postProcessorMethod}($value) : $value; } } } } } /** * Checking, if user has permissions for viewing Tax ID from ssn field * * @return boolean */ protected function isSsnPermission($wrapperObj = null) { return false; } /** * Checking, if user has permissions for viewing Tax ID from encrypted_tin field * * @return boolean */ protected function isTinPermission($wrapperObj) { return (check_user_role($wrapperObj, 25)); } /** * Returns decrypted Tax ID value * * @param string $value * @return string */ protected function decryptTin($value) { return Crypt::decrypt($value); } /** * If $field parameter is provided, returns corresponding field. * Returns array of vendor data otherwise * * @return string|array */ // @codingStandardsIgnoreStart public function get_vendor_data($field = '') { // @codingStandardsIgnoreEnd if ($field && in_array($field, $this->vendorFields)) { return $this->vendorData[$field]; } return $this->vendorData; } /** * Returns array of artists for a given vendor_id * * @return array */ // @codingStandardsIgnoreStart public function get_artists($wrapperObj) { // @codingStandardsIgnoreEnd $artistArr = array(); $sql = 'SELECT artist_id, name FROM artist_info WHERE vendor_id = ?'; $artist_result = $wrapperObj->executeQuery($sql, [$this->vendor_id]); if ($artist_result === false) { show_pdo_error($sql, $wrapperObj->getLastStatement()); } foreach ($artist_result as $RowData) { $key = $RowData['artist_id']; $artistArr[$key] = strtolower($RowData['name']); } return $artistArr; } }