} elseif (isset($arSrcElement['OPPORTUNITY'])) { $arFields['OPPORTUNITY'] = $arSrcElement['OPPORTUNITY']; } if (isset($_POST['TAX_VALUE'])) { $arFields['TAX_VALUE'] = trim($_POST['TAX_VALUE']); } elseif (isset($arSrcElement['TAX_VALUE'])) { $arFields['TAX_VALUE'] = $arSrcElement['TAX_VALUE']; } if (isset($_POST['CURRENCY_ID'])) { $arFields['CURRENCY_ID'] = $_POST['CURRENCY_ID']; } elseif (isset($arSrcElement['CURRENCY_ID'])) { $arFields['CURRENCY_ID'] = $arSrcElement['CURRENCY_ID']; } // EXCH_RATE --> $currencyID = isset($arFields['CURRENCY_ID']) ? $arFields['CURRENCY_ID'] : ''; if (!($currencyID !== '' && CCrmCurrency::IsExists($currencyID))) { $currencyID = $arFields['CURRENCY_ID'] = CCrmCurrency::GetBaseCurrencyID(); } $arFields['EXCH_RATE'] = CCrmCurrency::GetExchangeRate($currencyID); // <-- EXCH_RATE if (isset($_POST['CONTACT_ID'])) { $contactID = intval($_POST['CONTACT_ID']); if ($contactID > 0 && CCrmContact::CheckReadPermission($contactID)) { $arFields['CONTACT_ID'] = $contactID; } else { $arFields['CONTACT_ID'] = 0; } } elseif (isset($arSrcElement['CONTACT_ID'])) { $arFields['CONTACT_ID'] = $arSrcElement['CONTACT_ID']; } if (isset($_POST['COMPANY_ID'])) {
$arFields['UF_COMPANY_ID'] = htmlspecialcharsbx($arDeal['COMPANY_ID']); } if (isset($arDeal['CONTACT_ID'])) { $arFields['~UF_CONTACT_ID'] = $arDeal['CONTACT_ID']; $arFields['UF_CONTACT_ID'] = htmlspecialcharsbx($arDeal['CONTACT_ID']); } if (isset($arDeal['ASSIGNED_BY_ID'])) { $arFields['~RESPONSIBLE_ID'] = $arDeal['ASSIGNED_BY_ID']; $arFields['RESPONSIBLE_ID'] = htmlspecialcharsbx($arDeal['ASSIGNED_BY_ID']); } if (isset($arDeal['COMMENTS'])) { $arFields['~COMMENTS'] = $arDeal['COMMENTS']; $arFields['COMMENTS'] = htmlspecialcharsbx($arDeal['COMMENTS']); } if (is_array($arDealProducts) && count($arDealProducts) > 0) { $dealCurrencyID = empty($arDeal['CURRENCY_ID']) || !CCrmCurrency::IsExists($arDeal['CURRENCY_ID']) ? CCrmCurrency::GetBaseCurrencyID() : $arDeal['CURRENCY_ID']; $freshRows = CCrmInvoice::ProductRows2BasketItems($arDealProducts, $dealCurrencyID, $currencyID); if (count($freshRows) > 0) { $arFields['PRODUCT_ROWS'] = $arResult['PRODUCT_ROWS'] = $freshRows; } unset($freshRows); } unset($arDealProducts); } unset($arDeal, $arDealProducts); // read product row settings $productRowSettings = array(); $arDealProductRowSettings = CCrmProductRow::LoadSettings('D', $dealId); if (is_array($arDealProductRowSettings)) { $productRowSettings['ENABLE_DISCOUNT'] = isset($arDealProductRowSettings['ENABLE_DISCOUNT']) ? $arDealProductRowSettings['ENABLE_DISCOUNT'] : false; $productRowSettings['ENABLE_TAX'] = isset($arDealProductRowSettings['ENABLE_TAX']) ? $arDealProductRowSettings['ENABLE_TAX'] : false;
public function map(EntityConversionMap $map, array $options = null) { $srcFields = $this->getSourceFields(); if (empty($srcFields)) { return array(); } $dstFields = array(); $dstEntityTypeID = $map->getDestinationEntityTypeID(); foreach ($map->getItems() as $item) { $dstFieldID = $item->getDestinationField(); //Skip empty binding if ($dstFieldID === '-') { continue; } $srcFieldID = $item->getSourceField(); if ((!isset($srcFields[$srcFieldID]) || $srcFields[$srcFieldID] === '') && $srcFieldID !== 'PRODUCT_ROWS') { $altSrcFieldID = ''; foreach ($item->getAlternativeSourceFields() as $fieldID) { if (isset($srcFields[$fieldID])) { $altSrcFieldID = $fieldID; break; } } if ($altSrcFieldID !== '') { $srcFieldID = $altSrcFieldID; } } if ($dstFieldID === '') { $dstFieldID = $srcFieldID; } if (strpos($srcFieldID, 'UF_') === 0 && strpos($dstFieldID, 'UF_') === 0) { self::mapUserField(\CCrmOwnerType::Deal, $srcFieldID, $srcFields, $dstEntityTypeID, $dstFieldID, $dstFields, $options); } elseif ($srcFieldID === 'PRODUCT_ROWS') { $productRows = \CCrmDeal::LoadProductRows($this->srcEntityID); if (count($productRows) > 0) { if ($dstEntityTypeID === \CCrmOwnerType::Invoice) { $currencyID = isset($srcFields['CURRENCY_ID']) ? $srcFields['CURRENCY_ID'] : ''; if ($currencyID === '' || !\CCrmCurrency::IsExists($currencyID)) { $currencyID = \CCrmCurrency::GetBaseCurrencyID(); } $actualRows = \CCrmInvoice::ProductRows2BasketItems($productRows, $currencyID, \CCrmInvoice::GetCurrencyID()); if (count($actualRows) > 0) { foreach ($actualRows as &$productRow) { unset($productRow['ID']); } unset($productRow); $dstFields[$dstFieldID] = $actualRows; } } else { foreach ($productRows as &$productRow) { unset($productRow['ID']); } unset($productRow); $dstFields[$dstFieldID] = $productRows; } } } elseif (isset($srcFields[$srcFieldID])) { $dstFields[$dstFieldID] = $srcFields[$srcFieldID]; } } if (!empty($dstFields)) { if ($dstEntityTypeID === \CCrmOwnerType::Invoice) { $dstFields['UF_DEAL_ID'] = $this->srcEntityID; //region Prepare Invoice Properties $dstFields['INVOICE_PROPERTIES'] = array(); $invoiceEntity = new \CCrmInvoice(false); $companyID = isset($dstFields['UF_COMPANY_ID']) ? (int) $dstFields['UF_COMPANY_ID'] : 0; $contactID = isset($dstFields['UF_CONTACT_ID']) ? (int) $dstFields['UF_CONTACT_ID'] : 0; $personTypeID = 0; $personTypes = \CCrmPaySystem::getPersonTypeIDs(); if ($companyID > 0 && isset($personTypes['COMPANY'])) { $personTypeID = $personTypes['COMPANY']; } elseif (isset($personTypes['CONTACT'])) { $personTypeID = $personTypes['CONTACT']; } $properties = $invoiceEntity->GetProperties(0, $personTypeID); if (is_array($properties)) { \CCrmInvoice::__RewritePayerInfo($companyID, $contactID, $invoiceProperties); foreach ($properties as $property) { $dstFields['INVOICE_PROPERTIES'][$property['FIELDS']['ID']] = $property['VALUE']; } } //endregion } elseif ($dstEntityTypeID === \CCrmOwnerType::Quote) { $dstFields['DEAL_ID'] = $this->srcEntityID; } } return $dstFields; }
public function map(EntityConversionMap $map, array $options = null) { $srcFields = $this->getSourceFields(); if (empty($srcFields)) { return array(); } $dstFields = array(); $dstEntityTypeID = $map->getDestinationEntityTypeID(); foreach ($map->getItems() as $item) { $dstFieldID = $item->getDestinationField(); //Skip empty binding if ($dstFieldID === '-') { continue; } $srcFieldID = $item->getSourceField(); if ((!isset($srcFields[$srcFieldID]) || $srcFields[$srcFieldID] === '') && $srcFieldID !== 'PRODUCT_ROWS') { $altSrcFieldID = ''; foreach ($item->getAlternativeSourceFields() as $fieldID) { if (isset($srcFields[$fieldID])) { $altSrcFieldID = $fieldID; break; } } if ($altSrcFieldID !== '') { $srcFieldID = $altSrcFieldID; } } if ($dstFieldID === '') { $dstFieldID = $srcFieldID; } if (strpos($srcFieldID, 'UF_') === 0 && strpos($dstFieldID, 'UF_') === 0) { self::mapUserField(\CCrmOwnerType::Quote, $srcFieldID, $srcFields, $dstEntityTypeID, $dstFieldID, $dstFields, $options); } elseif ($srcFieldID === 'PRODUCT_ROWS') { $productRows = \CCrmQuote::LoadProductRows($this->srcEntityID); if (count($productRows) > 0) { if ($dstEntityTypeID === \CCrmOwnerType::Invoice) { $currencyID = isset($srcFields['CURRENCY_ID']) ? $srcFields['CURRENCY_ID'] : ''; if ($currencyID === '' || !\CCrmCurrency::IsExists($currencyID)) { $currencyID = \CCrmCurrency::GetBaseCurrencyID(); } $actualRows = \CCrmInvoice::ProductRows2BasketItems($productRows, $currencyID, \CCrmInvoice::GetCurrencyID()); if (count($actualRows) > 0) { foreach ($actualRows as &$productRow) { unset($productRow['ID']); } unset($productRow); $dstFields[$dstFieldID] = $actualRows; } } else { foreach ($productRows as &$productRow) { unset($productRow['ID']); } unset($productRow); $dstFields[$dstFieldID] = $productRows; } } } elseif (isset($srcFields[$srcFieldID])) { $dstFields[$dstFieldID] = $srcFields[$srcFieldID]; } } if (!empty($dstFields) && $dstEntityTypeID === \CCrmOwnerType::Invoice) { $dstFields['UF_QUOTE_ID'] = $this->srcEntityID; } return $dstFields; }