public static function FormatInvoiceStatusChanged($arData) { $info = GetMessage("CRM_INVOICE_EVENT_INFO_STATUS_CHANGED"); foreach ($arData as $param => $value) { if ($param == "STATUS_ID") { $res = CCrmStatusInvoice::getByID($value); $value = "\"" . $res["NAME"] . "\""; } $info = str_replace("#" . $param . "#", $value, $info); } return array("INFO" => $info); }
public static function PrepareInvoiceData(&$fields) { $statusID = $fields['~STATUS_ID']; $success = CCrmStatusInvoice::isStatusSuccess($statusID); $failed = CCrmStatusInvoice::isStatusFailed($statusID); $paymentTimeStamp = 0; $paymentDate = ''; $paymentDoc = ''; $paymentComment = ''; $cancelTimeStamp = 0; $cancelDate = ''; $cancelReason = ''; if ($success) { $paymentTimeStamp = MakeTimeStamp($fields['~PAY_VOUCHER_DATE']); $paymentDate = isset($fields['~PAY_VOUCHER_DATE']) ? ConvertTimeStamp($paymentTimeStamp, 'SHORT', SITE_ID) : ''; $paymentDoc = isset($fields['~PAY_VOUCHER_NUM']) ? $fields['~PAY_VOUCHER_NUM'] : ''; $paymentComment = isset($fields['~REASON_MARKED']) ? $fields['~REASON_MARKED'] : ''; } else { $cancelTimeStamp = MakeTimeStamp($fields['~DATE_MARKED']); $cancelDate = isset($fields['~DATE_MARKED']) ? ConvertTimeStamp($cancelTimeStamp, 'SHORT', SITE_ID) : ''; $cancelReason = isset($fields['~REASON_MARKED']) ? $fields['~REASON_MARKED'] : ''; } return array('ID' => $fields['~ID'], 'SHOW_URL' => $fields['SHOW_URL'], 'EDIT_URL' => isset($fields['EDIT_URL']) ? $fields['EDIT_URL'] : '', 'ACCOUNT_NUMBER' => $fields['~ACCOUNT_NUMBER'], 'ORDER_TOPIC' => $fields['~ORDER_TOPIC'], 'STATUS_ID' => $statusID, 'STATUS_TEXT' => $fields['~STATUS_TEXT'], 'PRICE' => $fields['~PRICE'], 'CURRENCY' => $fields['~CURRENCY'], 'FORMATTED_PRICE' => $fields['~FORMATTED_PRICE'], 'DEAL_ID' => $fields['~DEAL_ID'], 'DEAL_TITLE' => $fields['~DEAL_TITLE'], 'CONTACT_ID' => $fields['~CONTACT_ID'], 'CONTACT_FULL_NAME' => $fields['~CONTACT_FULL_NAME'], 'COMPANY_ID' => $fields['~COMPANY_ID'], 'COMPANY_TITLE' => $fields['~COMPANY_TITLE'], 'PAYMENT_TIME_STAMP' => $paymentTimeStamp, 'PAYMENT_DATE' => $paymentDate, 'PAYMENT_DOC' => $paymentDoc, 'PAYMENT_COMMENT' => $paymentComment, 'CANCEL_TIME_STAMP' => $cancelTimeStamp, 'CANCEL_DATE' => $cancelDate, 'CANCEL_REASON' => $cancelReason, 'IS_FINISHED' => $success || $failed, 'IS_SUCCESSED' => $success); }
public static function GetPaidSum($filter, $currencyId = '') { $totalPaidNumber = 0; $totalPaidSum = 0; if ($currencyId == '') { $currencyId = CCrmCurrency::GetBaseCurrencyID(); } $dbRes = CCrmInvoice::GetList(array('ID' => 'ASC'), $filter, false, false, array('PRICE', 'CURRENCY', 'STATUS_ID')); while ($arValues = $dbRes->Fetch()) { if (CCrmStatusInvoice::isStatusSuccess($arValues['STATUS_ID'])) { $totalPaidNumber++; $totalPaidSum += CCrmCurrency::ConvertMoney($arValues['PRICE'], $arValues['CURRENCY'], $currencyId); } } $result = array('num' => $totalPaidNumber, 'sum' => round($totalPaidSum, 2)); return $result; }
$arFiles = array(); while ($arRes = $obRes->Fetch()) { $arData[] = array('id' => $multi ? 'I_' . $arRes['ID'] : $arRes['ID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_invoice_show'), array('invoice_id' => $arRes['ID'])), 'title' => str_replace(array(';', ','), ' ', $arRes['ORDER_TOPIC']), 'desc' => isset($arInvoiceStatusList[$arRes['STATUS_ID']]) ? $arInvoiceStatusList[$arRes['STATUS_ID']] : '', 'type' => 'invoice'); } Header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); echo CUtil::PhpToJsObject($arData); die; } elseif (isset($_REQUEST['ACTION']) && $_REQUEST['ACTION'] === 'SAVE_PROGRESS') { CUtil::JSPostUnescape(); $errMessage = ''; $ID = isset($_REQUEST['ID']) ? intval($_REQUEST['ID']) : 0; $typeName = isset($_REQUEST['TYPE']) ? $_REQUEST['TYPE'] : ''; $statusID = isset($_REQUEST['VALUE']) ? $_REQUEST['VALUE'] : ''; // status sort array $statusSort = array(); $arInvoiceStatuses = CCrmStatusInvoice::GetStatus('INVOICE_STATUS'); foreach ($arInvoiceStatuses as $statusId => $statusInfo) { $statusSort[$statusId] = $statusInfo['SORT']; } unset($arInvoiceStatuses); $statusParams = array(); $statusParams['STATE_SUCCESS'] = isset($_REQUEST['VALUE']) && $_REQUEST['VALUE'] === 'P' ? true : false; $statusParams['STATE_FAILED'] = isset($_REQUEST['VALUE']) && $statusSort[$_REQUEST['VALUE']] >= $statusSort['D'] ? true : false; if ($statusParams['STATE_SUCCESS']) { $statusParams['PAY_VOUCHER_NUM'] = isset($_REQUEST['PAY_VOUCHER_NUM']) ? substr(trim($_REQUEST['PAY_VOUCHER_NUM']), 0, 20) : ''; $statusParams['DATE_MARKED'] = $statusParams['PAY_VOUCHER_DATE'] = isset($_REQUEST['PAY_VOUCHER_DATE']) ? trim($_POST['PAY_VOUCHER_DATE']) : null; $statusParams['REASON_MARKED'] = isset($_REQUEST['REASON_MARKED_SUCCESS']) ? substr(trim($_REQUEST['REASON_MARKED_SUCCESS']), 0, 255) : ''; } elseif ($statusParams['STATE_FAILED']) { $statusParams['DATE_MARKED'] = isset($_REQUEST['DATE_MARKED']) ? trim($_POST['DATE_MARKED']) : null; $statusParams['REASON_MARKED'] = isset($_REQUEST['REASON_MARKED']) ? substr(trim($_REQUEST['REASON_MARKED']), 0, 255) : ''; }
protected function innerDelete($ID, &$errors) { /** @global CMain $APPLICATION */ global $APPLICATION; if (!CCrmStatus::CheckDeletePermission($ID)) { $errors[] = 'Access denied.'; return false; } $statusInvoice = new CCrmStatusInvoice('INVOICE_STATUS'); $currentFields = $statusInvoice->getStatusById($ID); if (!is_array($currentFields)) { $errors[] = 'Status is not found.'; return false; } $statusId = intval($ID); if ($statusId === ($statusId & 0xff) && $statusId >= 65 && $statusId <= 90) { $statusId = chr($statusId); if (isset($currentFields['SYSTEM']) && $currentFields['SYSTEM'] === 'Y') { $errors[] = "Can't delete system status"; return false; } } unset($statusId); $result = $statusInvoice->Delete($ID); if ($result === false) { if ($e = $APPLICATION->GetException()) { $errors[] = $e->GetString(); } else { $errors[] = 'Error on deleting status.'; } } return $result !== false; }
$arParams['INVOICE_SHOW_URL_TEMPLATE'] = isset($arParams['INVOICE_SHOW_URL_TEMPLATE']) ? $arParams['INVOICE_SHOW_URL_TEMPLATE'] : ''; $arParams['INVOICE_EDIT_URL_TEMPLATE'] = isset($arParams['INVOICE_EDIT_URL_TEMPLATE']) ? $arParams['INVOICE_EDIT_URL_TEMPLATE'] : ''; $arParams['USER_PROFILE_URL_TEMPLATE'] = isset($arParams['USER_PROFILE_URL_TEMPLATE']) ? $arParams['USER_PROFILE_URL_TEMPLATE'] : ''; $arParams['NAME_TEMPLATE'] = isset($arParams['NAME_TEMPLATE']) ? str_replace(array('#NOBR#', '#/NOBR#'), array('', ''), $arParams['NAME_TEMPLATE']) : CSite::GetNameFormat(false); $arParams['UID'] = isset($arParams['UID']) ? $arParams['UID'] : ''; if (!isset($arParams['UID']) || $arParams['UID'] === '') { $arParams['UID'] = 'mobile_crm_invoice_list'; } $arResult['UID'] = $arParams['UID']; $contextID = isset($arParams['CONTEXT_ID']) ? $arParams['CONTEXT_ID'] : ''; if ($contextID === '' && isset($_REQUEST['context_id'])) { $contextID = $_REQUEST['context_id']; } $arResult['CONTEXT_ID'] = $arParams['CONTEXT_ID'] = $contextID; $arResult['FILTER'] = array(array('id' => 'ACCOUNT_NUMBER'), array('id' => 'ORDER_TOPIC'), array('id' => 'STATUS_ID'), array('id' => 'RESPONSIBLE_ID')); $arResult['FILTER_PRESETS'] = array('filter_my_unpaid' => array('name' => GetMessage('M_CRM_INVOICE_LIST_PRESET_MY_UNPAID'), 'fields' => array('RESPONSIBLE_ID' => $currentUserID, 'STATUS_ID' => CCrmStatusInvoice::getStatusIds('neutral'))), 'filter_my_paid' => array('name' => GetMessage('M_CRM_INVOICE_LIST_PRESET_MY_PAID'), 'fields' => array('RESPONSIBLE_ID' => $currentUserID, 'STATUS_ID' => CCrmStatusInvoice::getStatusIds('success')))); $itemPerPage = isset($arParams['ITEM_PER_PAGE']) ? intval($arParams['ITEM_PER_PAGE']) : 0; if ($itemPerPage <= 0) { $itemPerPage = 20; } $arParams['ITEM_PER_PAGE'] = $itemPerPage; $sort = array('ID' => 'ASC'); $filter = array(); $navParams = array('nPageSize' => $itemPerPage, 'iNumPage' => $enablePaging ? false : 1, 'bShowAll' => false); $select = array('ID', 'ACCOUNT_NUMBER', 'UF_DEAL_ID', 'UF_COMPANY_ID', 'UF_CONTACT_ID', 'PRICE', 'CURRENCY', 'STATUS_ID', 'ORDER_TOPIC', 'RESPONSIBLE_ID', 'RESPONSIBLE_LOGIN', 'RESPONSIBLE_NAME', 'RESPONSIBLE_LAST_NAME', 'RESPONSIBLE_SECOND_NAME'); $arOptions = array(); $navigation = CDBResult::GetNavParams($navParams); $CGridOptions = new CCrmGridOptions($arResult['UID']); $navParams = $CGridOptions->GetNavParams($navParams); $navParams['bShowAll'] = false; $arResult['GRID_FILTER_ID'] = '';
$arInvoice['PATH_TO_INVOICE_SHOW'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_INVOICE_SHOW'], array('invoice_id' => $entityID)); $arInvoice['PATH_TO_INVOICE_PAYMENT'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_INVOICE_PAYMENT'], array('invoice_id' => $entityID)); $arInvoice['PATH_TO_INVOICE_EDIT'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_INVOICE_EDIT'], array('invoice_id' => $entityID)); $arInvoice['PATH_TO_USER_PROFILE'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_USER_PROFILE'], array('user_id' => $arInvoice['RESPONSIBLE_ID'])); $arInvoice['PATH_TO_INVOICE_COPY'] = CHTTP::urlAddParams(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_INVOICE_EDIT'], array('invoice_id' => $entityID)), array('copy' => 1)); $arInvoice['PATH_TO_INVOICE_DELETE'] = CHTTP::urlAddParams($bInternal ? $APPLICATION->GetCurPage() : $arParams['PATH_TO_INVOICE_LIST'], array('action_' . $arResult['GRID_ID'] => 'delete', 'ID' => $entityID, 'sessid' => bitrix_sessid())); if (empty($arInvoice['~CURRENCY'])) { $arInvoice['~CURRENCY'] = $currencyID; $arInvoice['CURRENCY'] = htmlspecialcharsbx($currencyID); } $arInvoice['FORMATTED_PRICE'] = "<nobr>" . CCrmCurrency::MoneyToString($arInvoice['~PRICE'], $arInvoice['~CURRENCY']) . '</nobr>'; $arInvoice['FORMATTED_TAX_VALUE'] = "<nobr>" . CCrmCurrency::MoneyToString($arInvoice['~TAX_VALUE'], $arInvoice['~CURRENCY']) . '</nobr>'; $isStatusNeutral = false; $isStatusSuccess = CCrmStatusInvoice::isStatusSuccess($arInvoice['~STATUS_ID']); if (!$isStatusSuccess) { $isStatusNeutral = CCrmStatusInvoice::isStatusNeutral($arInvoice['~STATUS_ID']); } // calculate paid sum if ($isStatusSuccess) { $totalPaidNumber++; $totalPaidSum += CCrmCurrency::ConvertMoney($arInvoice['~PRICE'], $arInvoice['~CURRENCY'], $totalPaidCurrencyId); } // color coding $arInvoice['INVOICE_EXPIRED_FLAG'] = false; $arInvoice['INVOICE_IN_COUNTER_FLAG'] = false; if ($isStatusNeutral && !empty($arInvoice['DATE_PAY_BEFORE'])) { $tsDatePayBefore = MakeTimeStamp($arInvoice['DATE_PAY_BEFORE']); $tsNow = time() + CTimeZone::GetOffset(); $tsMax = mktime(00, 00, 00, date('m', $tsNow), date('d', $tsNow), date('Y', $tsNow)); if ($tsDatePayBefore < $tsMax) { $arInvoice['INVOICE_EXPIRED_FLAG'] = true;
$arFields['STATUS_TEXT'] = isset($arFields['STATUS_ID']) && isset($arResult['STATUS_LIST'][$arFields['STATUS_ID']]) ? $arResult['STATUS_LIST'][$arFields['STATUS_ID']] : ''; } $arResult['ELEMENT'] = $arFields; unset($arFields); if (empty($arResult['ELEMENT']['ID'])) { LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_INVOICE_LIST'], array())); } $bTaxMode = CCrmTax::isTaxMode(); $bStatusSuccess = false; $bStatusFailed = false; if (isset($arResult['ELEMENT']['STATUS_ID']) && $arResult['ELEMENT']['STATUS_ID'] !== '') { $bStatusSuccess = CCrmStatusInvoice::isStatusSuccess($arResult['ELEMENT']['STATUS_ID']); if ($bStatusSuccess) { $bStatusFailed = false; } else { $bStatusFailed = CCrmStatusInvoice::isStatusFailed($arResult['ELEMENT']['STATUS_ID']); } } $arResult['STATUS_SUCCESS'] = $arResult['ELEMENT']['STATUS_SUCCESS'] = $bStatusSuccess ? 'Y' : 'N'; $arResult['STATUS_FAILED'] = $arResult['ELEMENT']['STATUS_FAILED'] = $bStatusFailed ? 'Y' : 'N'; $arResult['ELEMENT']['REASON_MARKED_SUCCESS'] = $bStatusSuccess ? $arResult['ELEMENT']['REASON_MARKED'] : ''; if (!$bStatusFailed) { $arResult['ELEMENT']['REASON_MARKED'] = ''; } $currencyID = isset($arResult['ELEMENT']['CURRENCY']) ? $arResult['ELEMENT']['CURRENCY'] : CCrmInvoice::GetCurrencyID(); $dealID = isset($arResult['ELEMENT']['UF_DEAL_ID']) ? $arResult['ELEMENT']['UF_DEAL_ID'] : 0; $arResult['PATH_TO_DEAL_SHOW'] = $arResult['ELEMENT']['UF_DEAL_SHOW_URL'] = $dealID > 0 ? CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_DEAL_SHOW'], array('deal_id' => $dealID)) : ''; if ($dealID > 0) { $arResult['ELEMENT']['UF_DEAL_TITLE'] = CCrmOwnerType::GetCaption(CCrmOwnerType::Deal, $dealID, false); } $quoteID = isset($arResult['ELEMENT']['UF_QUOTE_ID']) ? $arResult['ELEMENT']['UF_QUOTE_ID'] : 0;
protected static function ensureLanguageDefined() { if (empty(self::$languageID)) { $arFilter = array('=LID' => SITE_ID, '=ACTIVE' => 'Y'); if (defined("ADMIN_SECTION")) { $arFilter = array('=DEF' => 'Y', '=ACTIVE' => 'Y'); } self::$languageID = LANGUAGE_ID; $arLang = \Bitrix\Main\SiteTable::getRow(array('filter' => $arFilter, 'select' => array('LANGUAGE_ID'), 'limit' => 1)); if (is_array($arLang) && !empty($arLang['LANGUAGE_ID'])) { self::$languageID = $arLang['LANGUAGE_ID']; } if (empty(self::$languageID)) { self::$languageID = 'en'; } } }
__CrmMobileInvoiceEditEndResonse(array('ERROR' => GetMessage('CRM_ENTITY_DATA_NOT_FOUND'))); } $ID = isset($data['ID']) ? intval($data['ID']) : 0; if ($ID <= 0) { __CrmMobileInvoiceEditEndResonse(array('ERROR' => GetMessage('CRM_ENTITY_ID_NOT_FOUND'))); } if (!CCrmAuthorizationHelper::CheckUpdatePermission(CCrmOwnerType::InvoiceName, $ID, $curUserPrems)) { __CrmMobileInvoiceEditEndResonse(array('ERROR' => GetMessage('CRM_ACCESS_DENIED'))); } $statusID = isset($data['STATUS_ID']) ? $data['STATUS_ID'] : ''; if ($statusID === '') { __CrmMobileInvoiceEditEndResonse(array('ERROR' => GetMessage('CRM_INVOICE_STATUS_NOT_FOUND'))); } $additionalData = isset($data['ADDITIONAL_DATA']) && is_array($data['ADDITIONAL_DATA']) ? $data['ADDITIONAL_DATA'] : null; $isSuccess = CCrmStatusInvoice::isStatusSuccess($statusID); $isFail = CCrmStatusInvoice::isStatusFailed($statusID); $statusParams = array('STATE_SUCCESS' => $isSuccess, 'STATE_FAILED' => $isFail); if ($isSuccess) { $timestamp = isset($additionalData['PAYMENT_TIME_STAMP']) ? max(intval($additionalData['PAYMENT_TIME_STAMP']), 0) : 0; $statusParams['PAY_VOUCHER_DATE'] = $timestamp > 0 ? ConvertTimeStamp($timestamp, 'SHORT', SITE_ID) : null; $statusParams['PAY_VOUCHER_NUM'] = isset($additionalData['PAYMENT_DOC']) ? substr(trim($additionalData['PAYMENT_DOC']), 0, 20) : ''; $statusParams['REASON_MARKED'] = isset($additionalData['PAYMENT_COMMENT']) ? substr(trim($additionalData['PAYMENT_COMMENT']), 0, 255) : ''; } elseif ($isFail) { $timestamp = isset($additionalData['CANCEL_TIME_STAMP']) ? max(intval($additionalData['CANCEL_TIME_STAMP']), 0) : 0; $statusParams['DATE_MARKED'] = $timestamp > 0 ? ConvertTimeStamp($timestamp, 'SHORT', SITE_ID) : null; $statusParams['REASON_MARKED'] = isset($additionalData['CANCEL_REASON']) ? substr(trim($additionalData['CANCEL_REASON']), 0, 255) : ''; } //$DB->StartTransaction(); $CCrmInvoice = new CCrmInvoice(false); $successed = $CCrmInvoice->SetStatus($ID, $statusID, $statusParams); if ($successed) {
$arResult['FIELDS']['tab_1'][] = array('id' => 'section_invoice_info', 'name' => GetMessage('CRM_SECTION_INVOICE_INFO'), 'type' => 'section'); $arResult['FIELDS']['tab_1'][] = array('id' => 'ACCOUNT_NUMBER', 'name' => GetMessage('CRM_FIELD_ACCOUNT_NUMBER'), 'params' => array('size' => 100), 'value' => isset($arResult['ELEMENT']['~ACCOUNT_NUMBER']) ? $arResult['ELEMENT']['~ACCOUNT_NUMBER'] : '', 'type' => 'text', 'required' => $bEdit, 'visible' => $bEdit); $arResult['FIELDS']['tab_1'][] = array('id' => 'ORDER_TOPIC', 'name' => GetMessage('CRM_FIELD_ORDER_TOPIC'), 'params' => array('size' => 255), 'value' => isset($arResult['ELEMENT']['~ORDER_TOPIC']) ? $arResult['ELEMENT']['~ORDER_TOPIC'] : '', 'type' => 'text', 'required' => true); $arResult['FIELDS']['tab_1'][] = array('id' => 'STATUS_ID', 'name' => GetMessage('CRM_FIELD_STATUS_ID'), 'items' => $arResult['STATUS_LIST'], 'params' => array('sale_order_marker' => 'Y'), 'type' => 'list', 'value' => isset($arResult['ELEMENT']['STATUS_ID']) ? $arResult['ELEMENT']['STATUS_ID'] : '', 'required' => true); // status dependent fields // <editor-fold defaultstate="collapsed" desc="status dependent fields ..."> $arResult['FIELDS']['tab_1'][] = array('id' => 'PAY_VOUCHER_DATE', 'name' => GetMessage('CRM_FIELD_PAY_VOUCHER_DATE'), 'params' => array('class' => 'bx-crm-dialog-input bx-crm-dialog-input-date', 'sale_order_marker' => 'Y'), 'type' => 'date_short', 'value' => !empty($arResult['ELEMENT']['PAY_VOUCHER_DATE']) ? ConvertTimeStamp(MakeTimeStamp($arResult['ELEMENT']['PAY_VOUCHER_DATE']), 'SHORT', SITE_ID) : ''); $arResult['FIELDS']['tab_1'][] = array('id' => 'PAY_VOUCHER_NUM', 'name' => GetMessage('CRM_FIELD_PAY_VOUCHER_NUM'), 'params' => array('size' => 20), 'value' => isset($arResult['ELEMENT']['~PAY_VOUCHER_NUM']) ? $arResult['ELEMENT']['~PAY_VOUCHER_NUM'] : '', 'type' => 'text'); $arResult['ELEMENT']['REASON_MARKED_SUCCESS'] = $arResult['ELEMENT']['~REASON_MARKED_SUCCESS'] = ''; if ($arResult['ELEMENT']['~STATUS_ID'] != '' && CCrmStatusInvoice::isStatusSuccess($arResult['ELEMENT']['~STATUS_ID'])) { $arResult['ELEMENT']['~REASON_MARKED_SUCCESS'] = $arResult['ELEMENT']['~REASON_MARKED']; $arResult['ELEMENT']['REASON_MARKED_SUCCESS'] = htmlspecialcharsbx($arResult['ELEMENT']['~REASON_MARKED']); } $arResult['FIELDS']['tab_1'][] = array('id' => 'REASON_MARKED_SUCCESS', 'name' => GetMessage('CRM_FIELD_REASON_MARKED_SUCCESS'), 'value' => isset($arResult['ELEMENT']['~REASON_MARKED_SUCCESS']) ? $arResult['ELEMENT']['~REASON_MARKED_SUCCESS'] : '', 'type' => 'textarea'); $arResult['FIELDS']['tab_1'][] = array('id' => 'DATE_MARKED', 'name' => GetMessage('CRM_FIELD_DATE_MARKED'), 'params' => array('class' => 'bx-crm-dialog-input bx-crm-dialog-input-date', 'sale_order_marker' => 'Y'), 'type' => 'date_short', 'value' => !empty($arResult['ELEMENT']['DATE_MARKED']) ? ConvertTimeStamp(MakeTimeStamp($arResult['ELEMENT']['DATE_MARKED']), 'SHORT', SITE_ID) : ''); if ($arResult['ELEMENT']['~STATUS_ID'] != '' && !CCrmStatusInvoice::isStatusFailed($arResult['ELEMENT']['~STATUS_ID'])) { $arResult['ELEMENT']['REASON_MARKED'] = $arResult['ELEMENT']['~REASON_MARKED'] = ''; } $arResult['FIELDS']['tab_1'][] = array('id' => 'REASON_MARKED', 'name' => GetMessage('CRM_FIELD_REASON_MARKED'), 'value' => isset($arResult['ELEMENT']['~REASON_MARKED']) ? $arResult['ELEMENT']['~REASON_MARKED'] : '', 'type' => 'textarea'); // </editor-fold> // if ($bEdit) // { // $arResult['FIELDS']['tab_1'][] = array( // 'id' => 'PAYED', // 'name' => GetMessage('CRM_FIELD_PAYED'), // 'type' => 'checkbox', // 'value' => ((isset($arResult['ELEMENT']['PAYED']) && $arResult['ELEMENT']['PAYED'] === 'Y') ? 'Y' : 'N') // ); // } $arResult['FIELDS']['tab_1'][] = array('id' => 'DATE_BILL', 'name' => GetMessage('CRM_FIELD_DATE_BILL'), 'params' => array('sale_order_marker' => 'Y'), 'type' => 'date_link', 'value' => !empty($arResult['ELEMENT']['DATE_BILL']) ? ConvertTimeStamp(MakeTimeStamp($arResult['ELEMENT']['DATE_BILL']), 'SHORT', SITE_ID) : ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'SHORT', SITE_ID)); $arResult['FIELDS']['tab_1'][] = array('id' => 'DATE_PAY_BEFORE', 'name' => GetMessage('CRM_FIELD_DATE_PAY_BEFORE'), 'params' => array('class' => 'bx-crm-dialog-input bx-crm-dialog-input-date', 'sale_order_marker' => 'Y'), 'type' => 'date_short', 'value' => !empty($arResult['ELEMENT']['DATE_PAY_BEFORE']) ? ConvertTimeStamp(MakeTimeStamp($arResult['ELEMENT']['DATE_PAY_BEFORE']), 'SHORT', SITE_ID) : '');
public static function update($params) { global $DB; $ID = CCrmInvoiceRestUtil::getParamScalar($params, 'id', 0); if ($ID <= 0) { throw new RestException('Invalid identifier.'); } $invoice = new CCrmInvoice(); if (!CCrmInvoice::CheckUpdatePermission($ID)) { throw new RestException('Access denied.'); } $fields = CCrmInvoiceRestUtil::getParamArray($params, 'fields'); $fields = self::filterFields($fields, 'update'); // sanitize $updateComments = isset($fields['COMMENTS']); $updateUserDescription = isset($fields['USER_DESCRIPTION']); $comments = $updateComments ? trim($fields['COMMENTS']) : ''; $userDescription = $updateUserDescription ? trim($fields['USER_DESCRIPTION']) : ''; $bSanitizeComments = $comments !== '' && strpos($comments, '<'); $bSanitizeUserDescription = $userDescription !== '' && strpos($userDescription, '<'); if ($bSanitizeComments || $bSanitizeUserDescription) { $sanitizer = new CBXSanitizer(); $sanitizer->ApplyDoubleEncode(false); $sanitizer->SetLevel(CBXSanitizer::SECURE_LEVEL_MIDDLE); //Crutch for for Chrome line break behaviour in HTML editor. $sanitizer->AddTags(array('div' => array())); if ($bSanitizeComments) { $fields['COMMENTS'] = $sanitizer->SanitizeHtml($fields['COMMENTS']); } if ($bSanitizeUserDescription) { $fields['USER_DESCRIPTION'] = $sanitizer->SanitizeHtml($fields['USER_DESCRIPTION']); } unset($sanitizer); } unset($bSanitizeComments, $bSanitizeUserDescription); if ($updateComments) { $fields['COMMENTS'] = $comments; } if ($updateUserDescription) { $fields['USER_DESCRIPTION'] = $userDescription; } unset($updateComments, $updateUserDescription, $comments, $userDescription); if (!is_array($fields) || count($fields) === 0) { throw new RestException('Invalid parameters.'); } $origFields = self::getInvoiceDataByID($ID); $origFields = self::filterFields($origFields, 'update'); foreach ($origFields as $fName => $fValue) { if (!array_key_exists($fName, $fields)) { $fields[$fName] = $fValue; } } $bStatusSuccess = CCrmStatusInvoice::isStatusSuccess($fields['STATUS_ID']); if ($bStatusSuccess) { $bStatusFailed = false; } else { $bStatusFailed = CCrmStatusInvoice::isStatusFailed($fields['STATUS_ID']); } if (!$invoice->CheckFields($fields, false, $bStatusSuccess, $bStatusFailed)) { if (!empty($invoice->LAST_ERROR)) { throw new RestException($invoice->LAST_ERROR); } else { throw new RestException('Error on check fields.'); } } $propsInfo = CCrmInvoice::GetPropertiesInfo($fields['PERSON_TYPE_ID']); $propsInfo = is_array($propsInfo[$fields['PERSON_TYPE_ID']]) ? $propsInfo[$fields['PERSON_TYPE_ID']] : array(); $invoiceProperties = array(); foreach ($propsInfo as $propCode => $arProp) { if (array_key_exists($propCode, $fields['INVOICE_PROPERTIES'])) { $invoiceProperties[$arProp['ID']] = $fields['INVOICE_PROPERTIES'][$propCode]; } else { if ($propCode === 'COMPANY_NAME' && array_key_exists('COMPANY', $fields['INVOICE_PROPERTIES'])) { $invoiceProperties[$arProp['ID']] = $fields['INVOICE_PROPERTIES']['COMPANY']; } else { if (is_array($origFields['INVOICE_PROPERTIES'])) { if (array_key_exists($propCode, $origFields['INVOICE_PROPERTIES'])) { $invoiceProperties[$arProp['ID']] = $origFields['INVOICE_PROPERTIES'][$propCode]; } else { if ($propCode === 'COMPANY_NAME' && array_key_exists('COMPANY', $fields['INVOICE_PROPERTIES'])) { $invoiceProperties[$arProp['ID']] = $origFields['INVOICE_PROPERTIES']['COMPANY']; } } } } } } $fields['INVOICE_PROPERTIES'] = $invoiceProperties; unset($propsInfo, $invoiceProperties, $propCode, $arProp); $DB->StartTransaction(); $ID = $invoice->Update($ID, $fields, array('UPDATE_SEARCH' => true)); if (!is_int($ID) || $ID <= 0) { $DB->Rollback(); if (!empty($invoice->LAST_ERROR)) { throw new RestException($invoice->LAST_ERROR); } else { throw new RestException('Error on updating invoice.'); } } else { $DB->Commit(); } return $ID; }