public static function PrepareInvoiceItem(&$item, &$params, $enums = array(), $options = array()) { $itemID = intval($item['~ID']); if (isset($params['INVOICE_SHOW_URL_TEMPLATE'])) { $item['SHOW_URL'] = CComponentEngine::makePathFromTemplate($params['INVOICE_SHOW_URL_TEMPLATE'], array('invoice_id' => $itemID)); } if (isset($params['INVOICE_EDIT_URL_TEMPLATE'])) { $item['EDIT_URL'] = CComponentEngine::makePathFromTemplate($params['INVOICE_EDIT_URL_TEMPLATE'], array('invoice_id' => $itemID)); } if (!isset($item['~ACCOUNT_NUMBER'])) { $item['~ACCOUNT_NUMBER'] = $item['ACCOUNT_NUMBER'] = ''; } if (!isset($item['~DATE_BILL'])) { $item['~DATE_BILL'] = $item['DATE_BILL'] = ''; } else { $item['~DATE_BILL'] = ConvertTimeStamp(MakeTimeStamp($item['~DATE_BILL']), 'SHORT', SITE_ID); $item['DATE_BILL'] = htmlspecialcharsbx($item['~DATE_BILL']); } if (!isset($item['~DATE_PAY_BEFORE'])) { $item['~DATE_PAY_BEFORE'] = $item['DATE_PAY_BEFORE'] = ''; $item['DATE_PAY_BEFORE_STAMP'] = 0; } if ($item['~DATE_PAY_BEFORE'] !== '') { $item['~DATE_PAY_BEFORE'] = ConvertTimeStamp(MakeTimeStamp($item['~DATE_PAY_BEFORE']), 'SHORT', SITE_ID); $item['DATE_PAY_BEFORE'] = htmlspecialcharsbx($item['~DATE_PAY_BEFORE']); } if (!isset($item['~ORDER_TOPIC'])) { $item['~ORDER_TOPIC'] = $item['ORDER_TOPIC'] = ''; } // COMMENTS --> if (!isset($item['~COMMENTS'])) { $item['~COMMENTS'] = $item['COMMENTS'] = ''; } if (!isset($item['~USER_DESCRIPTION'])) { $item['~USER_DESCRIPTION'] = $item['USER_DESCRIPTION'] = ''; } //<-- COMMENTS // STATUS --> if (!isset($item['~STATUS_ID'])) { $item['~STATUS_ID'] = $item['STATUS_ID'] = ''; } $statusID = $item['~STATUS_ID']; if ($statusID !== '') { $statuses = self::GetStatusList('INVOICE_STATUS'); if (!isset($statuses[$statusID])) { $item['~STATUS_TEXT'] = $item['STATUS_TEXT']; } else { $item['~STATUS_TEXT'] = $statuses[$statusID]; $item['STATUS_TEXT'] = htmlspecialcharsbx($item['~STATUS_TEXT']); } } //<-- STATUS //PRICE, CURRENCY --> $price = isset($item['~PRICE']) ? doubleval($item['~PRICE']) : 0.0; $item['~PRICE'] = $item['PRICE'] = $price; $currencyID = isset($item['~CURRENCY']) ? $item['~CURRENCY'] : ''; if ($currencyID === '') { $currencyID = $item['~CURRENCY'] = CCrmCurrency::GetBaseCurrencyID(); $item['CURRENCY'] = htmlspecialcharsbx($currencyID); } $item['~CURRENCY_NAME'] = CCrmCurrency::GetCurrencyName($currencyID); $item['CURRENCY_NAME'] = htmlspecialcharsbx($item['~CURRENCY_NAME']); $item['~FORMATTED_PRICE'] = CCrmCurrency::MoneyToString($price, $currencyID); $item['FORMATTED_PRICE'] = strip_tags($item['~FORMATTED_PRICE']); //<-- PRICE, CURRENCY //DEAL --> $dealID = isset($item['~UF_DEAL_ID']) ? intval($item['~UF_DEAL_ID']) : 0; $item['~DEAL_ID'] = $item['DEAL_ID'] = $dealID; if ($dealID <= 0) { $item['~DEAL_TITLE'] = $item['DEAL_TITLE'] = ''; } else { $item['~DEAL_TITLE'] = CCrmOwnerType::GetCaption(CCrmOwnerType::Deal, $dealID); $item['DEAL_TITLE'] = htmlspecialcharsbx($item['~DEAL_TITLE']); } //<-- DEAL // LOCATION --> if (is_array($options) && isset($options['ENABLE_LOCATION']) && $options['ENABLE_LOCATION']) { $properties = is_array($enums) && isset($enums['INVOICE_PROPERTIES']) && is_array($enums['INVOICE_PROPERTIES']) ? $enums['INVOICE_PROPERTIES'] : null; $locationID = is_array($properties) && isset($properties['PR_LOCATION']) ? intval($properties['PR_LOCATION']['VALUE']) : 0; $item['~LOCATION_ID'] = $item['LOCATION_ID'] = $locationID; $item['~LOCATION_NAME'] = $locationID > 0 ? CCrmInvoice::ResolveLocationName($locationID) : ''; $item['LOCATION_NAME'] = htmlspecialcharsbx($item['~LOCATION_NAME']); } //<-- LOCATION $enableMultiFields = is_array($options) && isset($options['ENABLE_MULTI_FIELDS']) && $options['ENABLE_MULTI_FIELDS']; //CONTACT --> $contactID = isset($item['UF_CONTACT_ID']) ? intval($item['UF_CONTACT_ID']) : 0; $item['~CONTACT_ID'] = $item['CONTACT_ID'] = $contactID; $contact = null; if ($contactID > 0) { $dbContact = CCrmContact::GetListEx(array(), array('=ID' => $contactID), false, false, array('NAME', 'SECOND_NAME', 'LAST_NAME', 'POST', 'PHOTO')); $contact = $dbContact ? $dbContact->Fetch() : null; } if (!$contact) { $item['~CONTACT_FULL_NAME'] = $item['CONTACT_FULL_NAME'] = $item['~CONTACT_POST'] = $item['CONTACT_POST'] = ''; $item['~CONTACT_PHOTO'] = $item['CONTACT_PHOTO'] = 0; if ($enableMultiFields) { $item['CONTACT_FM'] = array(); } } else { $item['~CONTACT_FULL_NAME'] = CUser::FormatName(\Bitrix\Crm\Format\PersonNameFormatter::getFormat(), array('LOGIN' => '', 'NAME' => isset($contact['NAME']) ? $contact['NAME'] : '', 'SECOND_NAME' => isset($contact['SECOND_NAME']) ? $contact['SECOND_NAME'] : '', 'LAST_NAME' => isset($contact['LAST_NAME']) ? $contact['LAST_NAME'] : ''), false, false); $item['CONTACT_FULL_NAME'] = htmlspecialcharsbx($item['~CONTACT_FULL_NAME']); $item['~CONTACT_POST'] = isset($contact['POST']) ? $contact['POST'] : ''; $item['CONTACT_POST'] = htmlspecialcharsbx($item['~CONTACT_POST']); $item['~CONTACT_PHOTO'] = $item['CONTACT_PHOTO'] = isset($contact['PHOTO']) ? intval($contact['PHOTO']) : 0; if ($enableMultiFields) { $item['CONTACT_FM'] = array(); $dbMultiFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'CONTACT', 'ELEMENT_ID' => $contactID)); if ($dbMultiFields) { while ($multiFields = $dbMultiFields->Fetch()) { $item['CONTACT_FM'][$multiFields['TYPE_ID']][] = array('VALUE' => $multiFields['VALUE'], 'VALUE_TYPE' => $multiFields['VALUE_TYPE']); } } } } //<-- CONTACT //COMPANY --> $companyID = isset($item['UF_COMPANY_ID']) ? intval($item['UF_COMPANY_ID']) : 0; $item['~COMPANY_ID'] = $item['COMPANY_ID'] = $companyID; $company = null; if ($companyID > 0) { $dbCompany = CCrmCompany::GetListEx(array(), array('=ID' => $companyID), false, false, array('TITLE', 'LOGO')); $company = $dbCompany ? $dbCompany->Fetch() : null; } if (!$company) { $item['~COMPANY_TITLE'] = $item['COMPANY_TITLE'] = ''; $item['~COMPANY_LOGO'] = $item['COMPANY_LOGO'] = 0; } else { $item['~COMPANY_TITLE'] = isset($company['TITLE']) ? $company['TITLE'] : ''; $item['COMPANY_TITLE'] = htmlspecialcharsbx($item['~COMPANY_TITLE']); $item['~COMPANY_LOGO'] = $item['COMPANY_LOGO'] = isset($company['LOGO']) ? intval($company['LOGO']) : 0; if ($enableMultiFields) { $item['COMPANY_FM'] = array(); $dbMultiFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'COMPANY', 'ELEMENT_ID' => $companyID)); if ($dbMultiFields) { while ($multiFields = $dbMultiFields->Fetch()) { $item['COMPANY_FM'][$multiFields['TYPE_ID']][] = array('VALUE' => $multiFields['VALUE'], 'VALUE_TYPE' => $multiFields['VALUE_TYPE']); } } } } //<-- COMPANY $personTypeID = CCrmInvoice::ResolvePersonTypeID($companyID, $contactID); // PAYER_INFO --> if (is_array($options) && isset($options['ENABLE_PAYER_INFO']) && $options['ENABLE_PAYER_INFO']) { if ($companyID <= 0 && $contactID <= 0) { $item['~PAYER_INFO'] = $item['PAYER_INFO'] = ''; } else { // Get invoice properties $properties = isset($item['INVOICE_PROPERTIES']) ? $item['INVOICE_PROPERTIES'] : null; if (!is_array($properties) && $personTypeID > 0) { $properties = CCrmInvoice::GetProperties($itemID, $personTypeID); if ($itemID <= 0) { CCrmInvoice::__RewritePayerInfo($companyID, $contactID, $properties); } } $item['~PAYER_INFO'] = is_array($properties) ? CCrmInvoice::__MakePayerInfoString($properties) : ''; $item['PAYER_INFO'] = htmlspecialcharsbx($item['~PAYER_INFO']); } } //<-- PAYER_INFO // PAY_SYSTEM --> if (!isset($item['~PAY_SYSTEM_ID'])) { $item['~PAY_SYSTEM_ID'] = $item['PAY_SYSTEM_ID'] = ''; } $paySystemID = $item['~PAY_SYSTEM_ID']; $paySystems = is_array($enums) && isset($enums['PAY_SYSTEMS']) && is_array($enums['PAY_SYSTEMS']) ? $enums['PAY_SYSTEMS'] : ($personTypeID > 0 ? CCrmPaySystem::GetPaySystemsListItems($personTypeID) : array()); if (isset($paySystems[$paySystemID])) { $item['~PAY_SYSTEM_NAME'] = $paySystems[$paySystemID]; $item['PAY_SYSTEM_NAME'] = htmlspecialcharsbx($item['~PAY_SYSTEM_NAME']); } else { $item['~PAY_SYSTEM_NAME'] = $item['PAY_SYSTEM_NAME'] = ''; } //<-- PAY_SYSTEM // RESPONSIBLE --> $responsibleID = isset($item['~RESPONSIBLE_ID']) ? intval($item['~RESPONSIBLE_ID']) : 0; $item['RESPONSIBLE_SHOW_URL'] = ''; $item['~RESPONSIBLE_FORMATTED_NAME'] = ''; if ($responsibleID > 0) { $item['RESPONSIBLE_SHOW_URL'] = $params['USER_PROFILE_URL_TEMPLATE'] !== '' ? CComponentEngine::makePathFromTemplate($params['USER_PROFILE_URL_TEMPLATE'], array('user_id' => $responsibleID)) : ''; $item['~RESPONSIBLE_FORMATTED_NAME'] = CUser::FormatName($params['NAME_TEMPLATE'], array('LOGIN' => isset($item['~RESPONSIBLE_LOGIN']) ? $item['~RESPONSIBLE_LOGIN'] : '', 'NAME' => isset($item['~RESPONSIBLE_NAME']) ? $item['~RESPONSIBLE_NAME'] : '', 'LAST_NAME' => isset($item['~RESPONSIBLE_LAST_NAME']) ? $item['~RESPONSIBLE_LAST_NAME'] : '', 'SECOND_NAME' => isset($item['~RESPONSIBLE_SECOND_NAME']) ? $item['~RESPONSIBLE_SECOND_NAME'] : ''), true, false); } $item['RESPONSIBLE_FORMATTED_NAME'] = htmlspecialcharsbx($item['~RESPONSIBLE_FORMATTED_NAME']); //<-- RESPONSIBLE }
$productRowQty = count($productRows); //Save initial row's order for ($i = 0; $i < $productRowQty; $i++) { $productRows[$i]['IDX'] = $i; } $ID = isset($data['ID']) ? intval($data['ID']) : 0; $companyID = isset($data['COMPANY_ID']) ? intval($data['COMPANY_ID']) : 0; if ($companyID > 0 && !CCrmCompany::CheckReadPermission($companyID, $curUserPrems)) { $companyID = 0; } $contactID = isset($data['CONTACT_ID']) ? intval($data['CONTACT_ID']) : 0; if ($contactID > 0 && !CCrmContact::CheckReadPermission($contactID, $curUserPrems)) { $contactID = 0; } $personTypeID = isset($data['PERSON_TYPE_ID']) ? intval($data['PERSON_TYPE_ID']) : 0; $resolvedPersonTypeID = $companyID > 0 || $contactID > 0 ? CCrmInvoice::ResolvePersonTypeID($companyID, $contactID) : 0; $paySystemID = isset($data['PAY_SYSTEM_ID']) ? intval($data['PAY_SYSTEM_ID']) : 0; $paySystems = CCrmPaySystem::GetPaySystemsListItems($resolvedPersonTypeID); $resolvedPaySystemID = 0; if ($personTypeID === $resolvedPersonTypeID && $paySystemID > 0 && array_key_exists($paySystemID, $paySystems)) { // Pay system does not changed $resolvedPaySystemID = $paySystemID; } elseif (!empty($paySystems)) { // Take first pay system $resolvedPaySystemID = array_shift(array_keys($paySystems)); } $arFields = array('ID' => $ID, 'PRODUCT_ROWS' => $productRows, 'PAY_SYSTEM_ID' => $resolvedPaySystemID, 'PERSON_TYPE_ID' => $resolvedPersonTypeID); $properties = CCrmInvoice::GetProperties($ID, $resolvedPersonTypeID); if (!is_array($properties)) { $properties = array(); }