Example #1
0
 public static function RewriteClientFields(&$arFields, $bDualFields = true)
 {
     $arCompany = $companyEMail = $companyPhone = null;
     $arContact = $contactEMail = $contactPhone = null;
     $companyId = isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0;
     $contactId = isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : 0;
     if ($companyId > 0) {
         $arCompany = CCrmCompany::GetByID($companyId);
         // Get multifields values (EMAIL and PHONE)
         $arFieldsMulti = CCrmFieldMulti::GetEntityFields('COMPANY', $companyId, 'EMAIL', true, false);
         if (is_array($arFieldsMulti) && isset($arFieldsMulti[0]['VALUE'])) {
             $companyEMail = $arFieldsMulti[0]['VALUE'];
         }
         $arFieldsMulti = CCrmFieldMulti::GetEntityFields('COMPANY', $companyId, 'PHONE', true, false);
         if (is_array($arFieldsMulti) && isset($arFieldsMulti[0]['VALUE'])) {
             $companyPhone = $arFieldsMulti[0]['VALUE'];
         }
         unset($arFieldsMulti);
     }
     if ($contactId > 0) {
         $arContact = CCrmContact::GetByID($contactId);
         // Get multifields values (EMAIL and PHONE)
         $arFieldsMulti = CCrmFieldMulti::GetEntityFields('CONTACT', $contactId, 'EMAIL', true, false);
         if (is_array($arFieldsMulti) && isset($arFieldsMulti[0]['VALUE'])) {
             $contactEMail = $arFieldsMulti[0]['VALUE'];
         }
         $arFieldsMulti = CCrmFieldMulti::GetEntityFields('CONTACT', $contactId, 'PHONE', true, false);
         if (is_array($arFieldsMulti) && isset($arFieldsMulti[0]['VALUE'])) {
             $contactPhone = $arFieldsMulti[0]['VALUE'];
         }
         unset($arFieldsMulti);
     }
     if ($companyId > 0) {
         if (is_array($arCompany) && count($arCompany) > 0) {
             foreach (self::$clientFields as $k) {
                 $v = '';
                 if ($k === 'CLIENT_TITLE') {
                     if (isset($arCompany['TITLE'])) {
                         $v = $arCompany['TITLE'];
                     }
                 } elseif ($k === 'CLIENT_CONTACT' && $contactId > 0) {
                     if (isset($arContact['FULL_NAME'])) {
                         $v = $arContact['FULL_NAME'];
                     }
                 } elseif ($k === 'CLIENT_ADDR') {
                     $v = Bitrix\Crm\Format\CompanyAddressFormatter::format($arCompany, array('TYPE_ID' => \Bitrix\Crm\EntityAddress::Registered));
                 } elseif ($k === 'CLIENT_EMAIL') {
                     $v = $contactEMail != '' ? $contactEMail : $companyEMail;
                 } elseif ($k === 'CLIENT_PHONE') {
                     $v = $contactPhone != '' ? $contactPhone : $companyPhone;
                 }
                 if ($bDualFields) {
                     $arFields['~' . $k] = $v;
                 }
                 $arFields[$k] = $bDualFields ? htmlspecialcharsbx($v) : $v;
             }
         }
     } elseif ($contactId > 0) {
         if (is_array($arContact) && count($arContact) > 0) {
             foreach (self::$clientFields as $k) {
                 $v = '';
                 if ($k === 'CLIENT_TITLE') {
                     if (isset($arContact['FULL_NAME'])) {
                         $v = $arContact['FULL_NAME'];
                     }
                 } elseif ($k === 'CLIENT_CONTACT' && $contactId > 0) {
                     $v = '';
                 } elseif ($k === 'CLIENT_ADDR') {
                     $v = Bitrix\Crm\Format\ContactAddressFormatter::format($arContact);
                 } elseif ($k === 'CLIENT_EMAIL') {
                     $v = $contactEMail;
                 } elseif ($k === 'CLIENT_PHONE') {
                     $v = $contactPhone;
                 }
                 if ($bDualFields) {
                     $arFields['~' . $k] = $v;
                 }
                 $arFields[$k] = $bDualFields ? htmlspecialcharsbx($v) : $v;
             }
         }
     }
 }
Example #2
0
 public static function __RewritePayerInfo($companyId, $contactId, &$arInvoiceProperties)
 {
     $arCompany = $companyEMail = $companyPhone = null;
     $arContact = $contactEMail = $contactPhone = null;
     if ($companyId > 0) {
         $arCompany = CCrmCompany::GetByID($companyId);
         // Get multifields values (EMAIL and PHONE)
         $arFieldsMulti = CCrmFieldMulti::GetEntityFields('COMPANY', $companyId, 'EMAIL', true, false);
         if (is_array($arFieldsMulti) && isset($arFieldsMulti[0]['VALUE'])) {
             $companyEMail = $arFieldsMulti[0]['VALUE'];
         }
         $arFieldsMulti = CCrmFieldMulti::GetEntityFields('COMPANY', $companyId, 'PHONE', true, false);
         if (is_array($arFieldsMulti) && isset($arFieldsMulti[0]['VALUE'])) {
             $companyPhone = $arFieldsMulti[0]['VALUE'];
         }
         unset($arFieldsMulti);
     }
     if ($contactId > 0) {
         $arContact = CCrmContact::GetByID($contactId);
         // Get multifields values (EMAIL and PHONE)
         $arFieldsMulti = CCrmFieldMulti::GetEntityFields('CONTACT', $contactId, 'EMAIL', true, false);
         if (is_array($arFieldsMulti) && isset($arFieldsMulti[0]['VALUE'])) {
             $contactEMail = $arFieldsMulti[0]['VALUE'];
         }
         $arFieldsMulti = CCrmFieldMulti::GetEntityFields('CONTACT', $contactId, 'PHONE', true, false);
         if (is_array($arFieldsMulti) && isset($arFieldsMulti[0]['VALUE'])) {
             $contactPhone = $arFieldsMulti[0]['VALUE'];
         }
         unset($arFieldsMulti);
     }
     if ($companyId > 0) {
         if (is_array($arCompany) && count($arCompany) > 0) {
             foreach ($arInvoiceProperties as $propertyKey => $property) {
                 $curVal = $arInvoiceProperties[$propertyKey]['VALUE'];
                 if ($property['FIELDS']['CODE'] === 'COMPANY' || $property['FIELDS']['CODE'] === 'COMPANY_NAME') {
                     if (isset($arCompany['TITLE'])) {
                         $curVal = $arCompany['TITLE'];
                     }
                 } elseif ($property['FIELDS']['CODE'] === 'CONTACT_PERSON' && $contactId > 0) {
                     if (isset($arContact['FULL_NAME'])) {
                         $curVal = $arContact['FULL_NAME'];
                     }
                 } elseif ($property['FIELDS']['CODE'] === 'COMPANY_ADR') {
                     $curVal = Bitrix\Crm\Format\CompanyAddressFormatter::format($arCompany, array('TYPE_ID' => \Bitrix\Crm\EntityAddress::Registered));
                 } elseif ($property['FIELDS']['CODE'] === 'INN') {
                     $todo = 'todo';
                     // TODO:
                 } elseif ($property['FIELDS']['CODE'] === 'KPP') {
                     $todo = 'todo';
                     // TODO:
                 } elseif ($property['FIELDS']['CODE'] === 'EMAIL') {
                     $curVal = $contactEMail != '' ? $contactEMail : $companyEMail;
                 } elseif ($property['FIELDS']['CODE'] === 'PHONE') {
                     $curVal = $contactPhone != '' ? $contactPhone : $companyPhone;
                 }
                 $arInvoiceProperties[$propertyKey]['VALUE'] = $curVal;
             }
         }
     } elseif ($contactId > 0) {
         if (is_array($arContact) && count($arContact) > 0) {
             foreach ($arInvoiceProperties as $propertyKey => $property) {
                 $curVal = $arInvoiceProperties[$propertyKey]['VALUE'];
                 if ($property['FIELDS']['CODE'] === 'FIO') {
                     if (isset($arContact['FULL_NAME'])) {
                         $curVal = $arContact['FULL_NAME'];
                     }
                 } elseif ($property['FIELDS']['CODE'] === 'EMAIL') {
                     $curVal = $contactEMail;
                 } elseif ($property['FIELDS']['CODE'] === 'PHONE') {
                     $curVal = $contactPhone;
                 } elseif ($property['FIELDS']['CODE'] === 'ADDRESS') {
                     $curVal = Bitrix\Crm\Format\ContactAddressFormatter::format($arContact);
                 }
                 $arInvoiceProperties[$propertyKey]['VALUE'] = $curVal;
             }
         }
     }
 }