예제 #1
0
global $APPLICATION;
$APPLICATION->RestartBuffer();
$ORDER_ID = intval($arParams["ORDER_ID"]);
$dbOrder = CSaleOrder::GetList(array("DATE_UPDATE" => "DESC"), array("LID" => SITE_ID, "ID" => $ORDER_ID));
$arOrder = $dbOrder->GetNext();
if ($arOrder) {
    if (strlen($arOrder["SUM_PAID"]) > 0) {
        $arOrder["PRICE"] -= $arOrder["SUM_PAID"];
    }
    $dbPaySysAction = CSalePaySystemAction::GetList(array(), array("PAY_SYSTEM_ID" => $arOrder["PAY_SYSTEM_ID"], "PERSON_TYPE_ID" => $arOrder["PERSON_TYPE_ID"]), false, false, array("ACTION_FILE", "PARAMS", "ENCODING"));
    if ($arPaySysAction = $dbPaySysAction->Fetch()) {
        if (strlen($arPaySysAction["ACTION_FILE"]) > 0) {
            CSalePaySystemAction::InitParamArrays($arOrder, $ID, $arPaySysAction["PARAMS"]);
            // USER_ID hack (0050242)
            $arInvoice = array();
            $dbInvoice = CCrmInvoice::GetList(array('ID' => 'DESC'), array('ID' => $ORDER_ID, 'PERMISSION' => 'READ'), false, false, array('ID', 'UF_CONTACT_ID', 'UF_COMPANY_ID'));
            if (is_object($dbInvoice)) {
                $arInvoice = $dbInvoice->Fetch();
            }
            unset($dbInvoice);
            if (is_array($arInvoice) && isset($arInvoice['UF_CONTACT_ID']) && isset($arInvoice['UF_COMPANY_ID'])) {
                $companyId = intval($arInvoice['UF_COMPANY_ID']);
                $contactId = intval($arInvoice['UF_CONTACT_ID']);
                $clientId = '';
                if ($companyId > 0) {
                    $clientId = 'C' . $companyId;
                } else {
                    $clientId = 'P' . $contactId;
                }
                $GLOBALS['SALE_INPUT_PARAMS']['ORDER']['USER_ID'] = $clientId;
                unset($companyId, $contactId, $clientId);
예제 #2
0
        $arResult['CURRENCY_ID'] = isset($arOwner['CURRENCY_ID']) ? $arOwner['CURRENCY_ID'] : CCrmCurrency::GetBaseCurrencyID();
        $arResult['SUM'] = isset($arOwner['OPPORTUNITY']) ? $arOwner['OPPORTUNITY'] : 0.0;
    } else {
        $arResult['TITLE'] = '';
        $arResult['CURRENCY_ID'] = CCrmCurrency::GetBaseCurrencyID();
        $arResult['SUM'] = 0.0;
    }
    $productRows = CCrmProductRow::LoadRows(CCrmOwnerTypeAbbr::Lead, $entityID);
    foreach ($productRows as &$productRow) {
        $productRow['FORMATTED_PRICE'] = CCrmCurrency::MoneyToString($productRow['PRICE'], $arResult['CURRENCY_ID']);
        $arResult['ITEMS'][] = $productRow;
    }
    unset($productRow);
    $arResult['FORMATTED_SUM'] = CCrmCurrency::MoneyToString($arResult['SUM'], $arResult['CURRENCY_ID']);
} elseif ($entityTypeID === CCrmOwnerType::Invoice) {
    $dbRes = CCrmInvoice::GetList(array(), array('ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ORDER_TOPIC', 'CURRENCY', 'PRICE', 'TAX_VALUE'));
    $arOwner = $dbRes ? $dbRes->Fetch() : null;
    if ($arOwner) {
        $arResult['TITLE'] = isset($arOwner['ORDER_TOPIC']) ? $arOwner['ORDER_TOPIC'] : '';
        $arResult['CURRENCY_ID'] = isset($arOwner['CURRENCY']) ? $arOwner['CURRENCY'] : CCrmCurrency::GetBaseCurrencyID();
        $arResult['SUM'] = isset($arOwner['PRICE']) ? round(doubleval($arOwner['PRICE']), 2) : 0.0;
        $arResult['TAX_SUM'] = isset($arOwner['TAX_VALUE']) ? round(doubleval($arOwner['TAX_VALUE']), 2) : 0.0;
    } else {
        $arResult['TITLE'] = '';
        $arResult['CURRENCY_ID'] = CCrmCurrency::GetBaseCurrencyID();
        $arResult['SUM'] = 0.0;
        $arResult['TAX_SUM'] = 0.0;
    }
    $rows = CCrmInvoice::GetProductRows($entityID);
    foreach ($rows as &$row) {
        $item = array('PRODUCT_NAME' => isset($row['PRODUCT_NAME']) ? $row['PRODUCT_NAME'] : '', 'PRICE' => isset($row['PRICE']) ? round(doubleval($row['PRICE']), 2) : 0.0, 'VAT_RATE' => isset($row['VAT_RATE']) ? round(doubleval($row['VAT_RATE']) * 100, 2) : 0.0, 'QUANTITY' => isset($row['QUANTITY']) ? intval($row['QUANTITY']) : 0);
예제 #3
0
 if (COption::GetOptionString('crm', '~CRM_REBUILD_INVOICE_ATTR', 'N') !== 'Y') {
     __CrmConfigPermsEndResonse(array('STATUS' => 'NOT_REQUIRED', 'SUMMARY' => GetMessage('CRM_CONFIG_PERMS_REBUILD_ATTR_NOT_REQUIRED_SUMMARY')));
 }
 $progressData = COption::GetOptionString('crm', '~CRM_REBUILD_INVOICE_ATTR_PROGRESS', '');
 $progressData = $progressData !== '' ? unserialize($progressData) : array();
 $lastItemID = isset($progressData['LAST_ITEM_ID']) ? intval($progressData['LAST_ITEM_ID']) : 0;
 $processedItemQty = isset($progressData['PROCESSED_ITEMS']) ? intval($progressData['PROCESSED_ITEMS']) : 0;
 $totalItemQty = isset($progressData['TOTAL_ITEMS']) ? intval($progressData['TOTAL_ITEMS']) : 0;
 if ($totalItemQty <= 0) {
     $totalItemQty = CCrmInvoice::GetList(array(), array('CHECK_PERMISSIONS' => 'N'), array(), false);
 }
 $filter = array('CHECK_PERMISSIONS' => 'N');
 if ($lastItemID > 0) {
     $filter['>ID'] = $lastItemID;
 }
 $dbResult = CCrmInvoice::GetList(array('ID' => 'ASC'), $filter, false, array('nTopCount' => 10), array('ID'));
 $itemIDs = array();
 $itemQty = 0;
 if (is_object($dbResult)) {
     while ($fields = $dbResult->Fetch()) {
         $itemIDs[] = intval($fields['ID']);
         $itemQty++;
     }
 }
 if ($itemQty > 0) {
     CCrmInvoice::RebuildEntityAccessAttrs($itemIDs);
     $progressData['TOTAL_ITEMS'] = $totalItemQty;
     $processedItemQty += $itemQty;
     $progressData['PROCESSED_ITEMS'] = $processedItemQty;
     $progressData['LAST_ITEM_ID'] = $itemIDs[$itemQty - 1];
     COption::SetOptionString('crm', '~CRM_REBUILD_INVOICE_ATTR_PROGRESS', serialize($progressData));
예제 #4
0
 public static function TryGetInfo($typeID, $ID, &$info, $bCheckPermissions = false)
 {
     $typeID = intval($typeID);
     $ID = intval($ID);
     if ($ID <= 0) {
         return array();
     }
     $result = null;
     switch ($typeID) {
         case self::Lead:
             $dbRes = CCrmLead::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $bCheckPermissions ? 'Y' : 'N'), false, false, array('TITLE'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             if (is_array($arRes)) {
                 $info = array('CAPTION' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '', 'IMAGE_ID' => 0);
                 return true;
             }
             break;
         case self::Contact:
             $dbRes = CCrmContact::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $bCheckPermissions ? 'Y' : 'N'), false, false, array('NAME', 'SECOND_NAME', 'LAST_NAME', 'PHOTO'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             if (is_array($arRes)) {
                 $info = array('CAPTION' => CUser::FormatName(\Bitrix\Crm\Format\PersonNameFormatter::getFormat(), array('LOGIN' => '', 'NAME' => isset($arRes['NAME']) ? $arRes['NAME'] : '', 'SECOND_NAME' => isset($arRes['SECOND_NAME']) ? $arRes['SECOND_NAME'] : '', 'LAST_NAME' => isset($arRes['LAST_NAME']) ? $arRes['LAST_NAME'] : ''), false, false), 'IMAGE_ID' => isset($arRes['PHOTO']) ? intval($arRes['PHOTO']) : 0);
                 return true;
             }
             break;
         case self::Company:
             $dbRes = CCrmCompany::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $bCheckPermissions ? 'Y' : 'N'), false, false, array('TITLE', 'LOGO'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             if (is_array($arRes)) {
                 $info = array('CAPTION' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '', 'IMAGE_ID' => isset($arRes['LOGO']) ? intval($arRes['LOGO']) : 0);
                 return true;
             }
             break;
         case self::Deal:
             $dbRes = CCrmDeal::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $bCheckPermissions ? 'Y' : 'N'), false, false, array('TITLE'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             if (is_array($arRes)) {
                 $info = array('CAPTION' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '', 'IMAGE_ID' => 0);
                 return true;
             }
             break;
         case self::Invoice:
             $dbRes = CCrmInvoice::GetList(array(), array('ID' => $ID), false, false, array('ORDER_TOPIC'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             if (is_array($arRes)) {
                 $info = array('CAPTION' => isset($arRes['ORDER_TOPIC']) ? $arRes['ORDER_TOPIC'] : '', 'IMAGE_ID' => 0);
                 return true;
             }
             break;
         case self::Quote:
             $dbRes = CCrmQuote::GetList(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $bCheckPermissions ? 'Y' : 'N'), false, false, array('TITLE'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             if (is_array($arRes)) {
                 $info = array('CAPTION' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '', 'IMAGE_ID' => 0);
                 return true;
             }
             break;
     }
     return false;
 }
예제 #5
0
 public static function UpdateSearch($arFilter, $ENTITY_TYPE, $bOverWrite = false)
 {
     if (!CModule::IncludeModule('search')) {
         return false;
     }
     $limit = 1000;
     switch ($ENTITY_TYPE) {
         case 'CONTACT':
             $obRes = CCrmContact::GetList(array('ID' => 'ASC'), $arFilter, array(), $limit);
             $sTitleID = 'FULL_NAME';
             break;
         case 'DEAL':
             $obRes = CCrmDeal::GetList(array('ID' => 'ASC'), $arFilter, array(), $limit);
             $sTitleID = 'TITLE';
             break;
         case 'INVOICE':
             $obRes = CCrmInvoice::GetList(array('ID' => 'DESC'), $arFilter, false, array('nTopCount' => $limit), array('*'));
             $sTitleID = 'ORDER_TOPIC';
             break;
         case 'QUOTE':
             $obRes = CCrmQuote::GetList(array('ID' => 'ASC'), $arFilter, false, array('nTopCount' => intval($limit)), array());
             $sTitleID = 'TITLE';
             break;
         case 'COMPANY':
             $obRes = CCrmCompany::GetList(array('ID' => 'ASC'), $arFilter, array(), $limit);
             $sTitleID = 'TITLE';
             break;
         default:
         case 'LEAD':
             $obRes = CCrmLead::GetList(array('ID' => 'ASC'), $arFilter, array(), $limit);
             $sTitleID = 'TITLE';
             $ENTITY_TYPE = 'LEAD';
             break;
     }
     if (!isset(self::$arMess[$ENTITY_TYPE])) {
         self::$arMess[$ENTITY_TYPE] = __IncludeLang($_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/components/bitrix/crm.' . strtolower($ENTITY_TYPE) . '.show/lang/' . LANGUAGE_ID . '/component.php', true);
     }
     $arAllResult = array();
     $qty = 0;
     $lastItemID = '';
     if (is_object($obRes)) {
         while (($arRow = $obRes->Fetch()) !== false) {
             $elementID = $arRow['ID'];
             $lastItemID = $ENTITY_TYPE . '.' . $elementID;
             if ($ENTITY_TYPE === 'INVOICE') {
                 $arResult = CCrmInvoice::BuildSearchCard($arRow, self::$bReIndex);
             } elseif ($ENTITY_TYPE === 'QUOTE') {
                 $arResult = CCrmQuote::BuildSearchCard($arRow, self::$bReIndex);
             } else {
                 $multiFields = array();
                 if ($ENTITY_TYPE === 'CONTACT' || $ENTITY_TYPE === 'COMPANY' || $ENTITY_TYPE === 'LEAD') {
                     $obMultiFieldRes = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => $ENTITY_TYPE, 'ELEMENT_ID' => $elementID));
                     while ($multiField = $obMultiFieldRes->Fetch()) {
                         $fieldValue = $multiField['VALUE'];
                         $fieldTypeID = $multiField['TYPE_ID'];
                         if ($fieldValue === '' || $fieldTypeID !== 'PHONE' && $fieldTypeID !== 'EMAIL') {
                             continue;
                         }
                         if (!isset($multiFields[$fieldTypeID])) {
                             $multiFields[$fieldTypeID] = array();
                         }
                         $multiFields[$fieldTypeID][] = $fieldValue;
                     }
                 }
                 $arResult = self::_buildEntityCard($arRow, $sTitleID, $ENTITY_TYPE, array('FM' => $multiFields));
             }
             if (self::$bReIndex) {
                 if (self::$oCallback) {
                     $res = call_user_func(array(self::$oCallback, self::$callback_method), $arResult);
                     if (!$res) {
                         return $lastItemID;
                     }
                 }
             } else {
                 CSearch::Index('crm', $ENTITY_TYPE . '.' . $arRow['ID'], $arResult, $bOverWrite);
             }
             $arAllResult[] = $arResult;
             $qty++;
         }
     }
     if (!self::$bReIndex && !empty($arFilter['ID']) && $qty === 0) {
         CSearch::DeleteIndex('crm', (int) $arFilter['ID']);
     }
     if (self::$bReIndex && $qty === $limit && $lastItemID !== '') {
         return $lastItemID;
     }
     return $arAllResult;
 }
예제 #6
0
$arResult['STATUS_LIST'] = CCrmStatus::GetStatusList('INVOICE_STATUS');
//$arResult['TYPE_LIST'] = CCrmStatus::GetStatusList('DEAL_TYPE');
$arResult['CURRENCY_LIST'] = CCrmCurrencyHelper::PrepareListItems();
$serviceURLTemplate = $arParams["SERVICE_URL_TEMPLATE"] ? $arParams["SERVICE_URL_TEMPLATE"] : '#SITE_DIR#bitrix/components/bitrix/mobile.crm.invoice.edit/ajax.php?site_id=#SITE#&sessid=#SID#';
$arResult['SERVICE_URL'] = CComponentEngine::makePathFromTemplate($serviceURLTemplate, array('SID' => bitrix_sessid()));
// CONTEXT_ID -->
$contextID = isset($arParams['CONTEXT_ID']) ? $arParams['CONTEXT_ID'] : '';
if ($contextID === '' && isset($_REQUEST['context_id'])) {
    $contextID = $_REQUEST['context_id'];
}
if ($contextID === '') {
    $contextID = "{$uid}_{$entityID}";
}
$arResult['CONTEXT_ID'] = $arParams['CONTEXT_ID'] = $contextID;
//<-- CONTEXT_ID
$dbFields = CCrmInvoice::GetList(array(), array('ID' => $entityID));
$arFields = $dbFields->GetNext();
if (!$arFields) {
    ShowError(GetMessage('CRM_INVOICE_VIEW_NOT_FOUND', array('#ID#' => $arParams['ENTITY_ID'])));
    return;
}
$arResult['PERMISSIONS'] = array('EDIT' => !$userPerms->HavePerm('INVOICE', BX_CRM_PERM_NONE, 'WRITE'), 'DELETE' => !$userPerms->HavePerm('INVOICE', BX_CRM_PERM_NONE, 'DELETE'));
CCrmMobileHelper::PrepareInvoiceItem($arFields, $arParams, array(), array('ENABLE_MULTI_FIELDS' => true, 'ENABLE_PAYER_INFO' => true));
$accountNumber = isset($arFields['~ACCOUNT_NUMBER']) ? $arFields['~ACCOUNT_NUMBER'] : '';
if ($accountNumber === '') {
    $accountNumber = $arFields['~ID'];
}
$arResult['EMAIL_SUBJECT'] = GetMessage('CRM_INVOICE_VIEW_EMAIL_SUBJECT', array('#NUMBER#' => $accountNumber));
$dealID = $arFields['~DEAL_ID'];
$contactID = $arFields['~CONTACT_ID'];
$companyID = $arFields['~COMPANY_ID'];
예제 #7
0
 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;
 }
예제 #8
0
        $dbUser = CUser::GetList($by = 'id', $order = 'asc', array('ID' => $arFields['~RESPONSIBLE_ID']), array('FIELDS' => array('ID', 'LOGIN', 'EMAIL', 'NAME', 'LAST_NAME', 'SECOND_NAME')));
        $user = $dbUser->Fetch();
        if ($user) {
            $arFields['~RESPONSIBLE_BY_LOGIN'] = $user['LOGIN'];
            $arFields['RESPONSIBLE_BY_LOGIN'] = htmlspecialcharsbx($user['LOGIN']);
            $arFields['~RESPONSIBLE_NAME'] = $user['NAME'];
            $arFields['RESPONSIBLE_NAME'] = htmlspecialcharsbx($user['NAME']);
            $arFields['~RESPONSIBLE_LAST_NAME'] = $user['LAST_NAME'];
            $arFields['RESPONSIBLE_LAST_NAME'] = htmlspecialcharsbx($user['LAST_NAME']);
            $arFields['~RESPONSIBLE_SECOND_NAME'] = $user['SECOND_NAME'];
            $arFields['RESPONSIBLE_SECOND_NAME'] = htmlspecialcharsbx($user['SECOND_NAME']);
        }
    }
} else {
    $arResult['MODE'] = 'UPDATE';
    $dbFields = CCrmInvoice::GetList(array(), array('ID' => $entityID, 'PERMISSION' => 'WRITE'));
    $arFields = $dbFields->GetNext();
    if (!$arFields) {
        ShowError(GetMessage('CRM_INVOICE_EDIT_NOT_FOUND', array('#ID#' => $arParams['ENTITY_ID'])));
        return;
    }
    $arFields['DATE_BILL_STAMP'] = isset($arFields['~DATE_BILL']) ? MakeTimeStamp($arFields['~DATE_BILL']) : 0;
    $arFields['DATE_PAY_BEFORE_STAMP'] = isset($arFields['~DATE_PAY_BEFORE']) ? MakeTimeStamp($arFields['~DATE_PAY_BEFORE']) : 0;
    if (isset($arFields['CURRENCY'])) {
        $currencyID = $arFields['CURRENCY'];
    }
    //HACK: MSSQL returns '.00' for zero value
    if (isset($arFields['~PRICE'])) {
        $arFields['~PRICE'] = $arFields['PRICE'] = floatval($arFields['~PRICE']);
    }
    if (isset($arFields['UF_COMPANY_ID'])) {
예제 #9
0
    if (is_numeric($search)) {
        $arFilter['ID'] = (int) $search;
    } else {
        if (preg_match('/(.*)\\[(\\d+?)\\]/i' . BX_UTF_PCRE_MODIFIER, $search, $arMatches)) {
            $arFilter['ID'] = (int) $arMatches[2];
            $arFilter['%ORDER_TOPIC'] = trim($arMatches[1]);
            $arFilter['LOGIC'] = 'OR';
        } else {
            $arFilter['%ORDER_TOPIC'] = $search;
        }
    }
    $arInvoiceStatusList = CCrmStatus::GetStatusListEx('INVOICE_STATUS');
    $arSelect = array('ID', 'ORDER_TOPIC', 'STATUS_ID');
    $arOrder = array('ORDER_TOPIC' => 'ASC');
    $arData = array();
    $obRes = CCrmInvoice::GetList($arOrder, $arFilter, false, intval($nPageTop) > 0 ? array('nTopCount' => $nPageTop) : false, $arSelect);
    $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();
 /**
  * @return boolean
  */
 public static function register($ownerID, array $entityFields = null, array $options = null)
 {
     if (!is_int($ownerID)) {
         $ownerID = (int) $ownerID;
     }
     if ($ownerID <= 0) {
         throw new Main\ArgumentException('Owner ID must be greater than zero.', 'ownerID');
     }
     if (!is_array($options)) {
         $options = array();
     }
     if (!is_array($entityFields)) {
         $dbResult = \CCrmDeal::GetListEx(array(), array('=ID' => $ownerID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('STAGE_ID', 'ASSIGNED_BY_ID', 'BEGINDATE', 'CLOSEDATE', 'OPPORTUNITY', 'CURRENCY_ID'));
         $entityFields = is_object($dbResult) ? $dbResult->Fetch() : null;
         if (!is_array($entityFields)) {
             return false;
         }
     }
     $sum = isset($entityFields['OPPORTUNITY']) ? (double) $entityFields['OPPORTUNITY'] : 0.0;
     $currencyID = isset($entityFields['CURRENCY_ID']) ? $entityFields['CURRENCY_ID'] : '';
     if ($currencyID === '') {
         $currencyID = \CCrmCurrency::GetBaseCurrencyID();
     }
     $sumData = \CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => $currencyID, 'SUM' => $sum));
     if (is_array($sumData)) {
         $sum = (double) $sumData['ACCOUNT_SUM'];
     }
     $stageID = isset($entityFields['STAGE_ID']) ? $entityFields['STAGE_ID'] : '';
     $semanticID = \CCrmDeal::GetSemanticID($stageID);
     $isLost = PhaseSemantics::isLost($semanticID);
     $responsibleID = isset($entityFields['ASSIGNED_BY_ID']) ? (int) $entityFields['ASSIGNED_BY_ID'] : 0;
     /** @var Date $startDate */
     $startDate = self::parseDateString(isset($entityFields['BEGINDATE']) ? $entityFields['BEGINDATE'] : '');
     if ($startDate === null) {
         $startDate = new Date();
     }
     /** @var Date $endDate */
     $endDate = self::parseDateString(isset($entityFields['CLOSEDATE']) ? $entityFields['CLOSEDATE'] : '');
     if ($endDate === null) {
         $endDate = new Date('9999-12-31', 'Y-m-d');
     }
     $accountCurrencyID = \CCrmCurrency::GetAccountCurrencyID();
     $results = array();
     $skipHistory = isset($options['SKIP_HISTORY']) ? (bool) $options['SKIP_HISTORY'] : false;
     if (!$skipHistory) {
         $dbResult = \CCrmInvoice::GetList(array('DATE_BILL' => 'ASC'), array('UF_DEAL_ID' => $ownerID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'PRICE', 'CURRENCY', 'DATE_BILL'));
         if (is_object($dbResult)) {
             while ($invoiceFields = $dbResult->Fetch()) {
                 $key = isset($invoiceFields['DATE_BILL']) ? $invoiceFields['DATE_BILL'] : '';
                 if ($key === '') {
                     continue;
                 }
                 $date = new Date($key);
                 if (!isset($results[$key])) {
                     $results[$key] = array('DATE' => $date, 'QTY' => 0, 'SUM' => 0.0);
                 }
                 $results[$key]['QTY']++;
                 $currencyID = isset($invoiceFields['CURRENCY']) ? $invoiceFields['CURRENCY'] : '';
                 $total = isset($invoiceFields['PRICE']) ? (double) $invoiceFields['PRICE'] : 0.0;
                 $accData = \CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => $currencyID, 'SUM' => $total));
                 if (is_array($accData)) {
                     $results[$key]['SUM'] += (double) $accData['ACCOUNT_SUM'];
                 }
             }
         }
     }
     DealInvoiceStatisticsTable::deleteByOwner($ownerID);
     if (empty($results)) {
         if ($semanticID === PhaseSemantics::SUCCESS) {
             //Creation of stub for successfully completed entity without invoices
             self::innerRegister(array('OWNER_ID' => $ownerID, 'CREATED_DATE' => new Date(), 'START_DATE' => $startDate, 'END_DATE' => $endDate, 'RESPONSIBLE_ID' => $responsibleID, 'STAGE_SEMANTIC_ID' => PhaseSemantics::SUCCESS, 'STAGE_ID' => $stageID, 'IS_LOST' => 'N', 'CURRENCY_ID' => $accountCurrencyID, 'INVOICE_SUM' => 0.0, 'INVOICE_QTY' => 0, 'TOTAL_INVOICE_SUM' => 0.0, 'TOTAL_INVOICE_QTY' => 0, 'TOTAL_SUM' => $sum));
         }
         return true;
     }
     $totals = array('QTY' => 0, 'SUM' => 0.0);
     foreach ($results as $result) {
         $totals['QTY'] += $result['QTY'];
         $totals['SUM'] += $result['SUM'];
         self::innerRegister(array('OWNER_ID' => $ownerID, 'CREATED_DATE' => $result['DATE'], 'START_DATE' => $startDate, 'END_DATE' => $endDate, 'RESPONSIBLE_ID' => $responsibleID, 'STAGE_SEMANTIC_ID' => $semanticID, 'STAGE_ID' => $stageID, 'IS_LOST' => $isLost ? 'Y' : 'N', 'CURRENCY_ID' => $accountCurrencyID, 'INVOICE_SUM' => $result['SUM'], 'INVOICE_QTY' => $result['QTY'], 'TOTAL_INVOICE_SUM' => $totals['SUM'], 'TOTAL_INVOICE_QTY' => $totals['QTY'], 'TOTAL_SUM' => $sum));
     }
     return true;
 }
예제 #11
0
$arSelect[] = 'CURRENCY';
$arSelect[] = 'UF_DEAL_ID';
$arSelect[] = 'UF_COMPANY_ID';
$arSelect[] = 'UF_CONTACT_ID';
$arSelect[] = 'UF_QUOTE_ID';
// fields for status change dialog
$arSelect[] = 'PAY_VOUCHER_DATE';
$arSelect[] = 'PAY_VOUCHER_NUM';
$arSelect[] = 'DATE_MARKED';
$arSelect[] = 'REASON_MARKED';
$arOptions = array();
if (isset($arSort['date_pay_before'])) {
    $arOptions['NULLS_LAST'] = true;
}
$arSelect = array_unique($arSelect, SORT_STRING);
$obRes = CCrmInvoice::GetList($arSort, $arFilter, false, $sExportType == '' ? $arNavParams : false, $arSelect, $arOptions);
if ($arResult['GADGET'] != 'Y' && $sExportType == '') {
    $obRes->NavStart($arNavParams['nPageSize'], false);
}
$arResult['INVOICE'] = array();
$arResult['INVOICE_ID'] = array();
$arResult['INVOICE_UF'] = array();
$now = time() + CTimeZone::GetOffset();
$currencyID = $CCrmInvoice::GetCurrencyID();
$totalPaidCurrencyId = $arParams['SUM_PAID_CURRENCY'] != '' ? $arParams['SUM_PAID_CURRENCY'] : CCrmCurrency::getInvoiceDefault();
$totalPaidNumber = 0;
$totalPaidSum = 0;
$arContactList = array();
$arCompanyList = array();
$arDealList = array();
$arQuoteList = array();
예제 #12
0
        if (isset($filter['ORDER_TOPIC'])) {
            $filter['~ORDER_TOPIC'] = "%{$filter['ORDER_TOPIC']}%";
            unset($filter['ORDER_TOPIC']);
        }
        if (isset($filter['ACCOUNT_NUMBER'])) {
            $filter['~ACCOUNT_NUMBER'] = "%{$filter['ACCOUNT_NUMBER']}%";
            unset($filter['ACCOUNT_NUMBER']);
        }
    }
}
//Setup default filter name ('NONE') if it is not assigned
if (!isset($arResult['GRID_FILTER_NAME']) || $arResult['GRID_FILTER_NAME'] === '') {
    $arResult['GRID_FILTER_NAME'] = GetMessage('M_CRM_INVOICE_LIST_FILTER_NONE');
}
$arResult['ITEMS'] = array();
$dbRes = CCrmInvoice::GetList($sort, $filter, false, $navParams, $select, array());
if (!is_object($dbRes)) {
    $arResult['NEXT_PAGE_URL'] = '';
} else {
    $dbRes->NavStart($navParams['nPageSize'], false);
    $arResult['PAGE_NAVNUM'] = intval($dbRes->NavNum);
    // pager index
    $arResult['PAGE_NUMBER'] = intval($dbRes->NavPageNomer);
    // current page index
    $arResult['PAGE_NAVCOUNT'] = intval($dbRes->NavPageCount);
    // page count
    $arResult['PAGER_PARAM'] = "PAGEN_{$arResult['PAGE_NAVNUM']}";
    $arResult['PAGE_NEXT_NUMBER'] = $arResult['PAGE_NUMBER'] + 1;
    $enums = array();
    while ($item = $dbRes->GetNext()) {
        CCrmMobileHelper::PrepareInvoiceItem($item, $arParams, $enums);
예제 #13
0
    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) {
        //$DB->Commit();
        $dbRes = CCrmInvoice::GetList(array(), array('ID' => $ID));
        $currentItem = $dbRes->GetNext();
        $formatParams = isset($_REQUEST['FORMAT_PARAMS']) ? $_REQUEST['FORMAT_PARAMS'] : array();
        CCrmMobileHelper::PrepareInvoiceItem($currentItem, $formatParams, array(), array('ENABLE_MULTI_FIELDS' => true, 'ENABLE_PAYER_INFO' => true));
        __CrmMobileInvoiceEditEndResonse(array('SAVED_ENTITY_ID' => $ID, 'SAVED_ENTITY_DATA' => CCrmMobileHelper::PrepareInvoiceData($currentItem)));
    } else {
        //$DB->Rollback();
        __CrmMobileInvoiceEditEndResonse(array('ERROR' => GetMessage('CRM_INVOICE_COULD_NOT_SAVE_STATUS')));
    }
} elseif ($action === 'RECALCULATE') {
    // Refresh invoice data according to client settings
    __IncludeLang(dirname(__FILE__) . '/lang/' . LANGUAGE_ID . '/' . basename(__FILE__));
    $data = isset($_REQUEST['SOURCE_DATA']) && is_array($_REQUEST['SOURCE_DATA']) ? $_REQUEST['SOURCE_DATA'] : array();
    if (count($data) == 0) {
        __CrmMobileInvoiceEditEndResonse(array('ERROR' => GetMessage('CRM_ENTITY_DATA_NOT_FOUND')));
    }
예제 #14
0
}
if (intval($_REQUEST['contact']) > 0) {
    $bCreateFromContact = true;
    $contactId = intval($_REQUEST['contact']);
}
$bCreateFrom = $bCreateFromQuote || $bCreateFromDeal || $bCreateFromCompany || $bCreateFromContact;
$bConvert = isset($arParams['CONVERT']) && $arParams['CONVERT'];
$bTaxMode = CCrmTax::isTaxMode();
if (($bEdit || $bCopy) && !empty($arResult['ELEMENT']['CURRENCY'])) {
    $currencyID = $arResult['ELEMENT']['CURRENCY'];
} else {
    $currencyID = CCrmInvoice::GetCurrencyID();
}
if ($bEdit || $bCopy) {
    $arFilter = array('ID' => $arParams['ELEMENT_ID'], 'PERMISSION' => 'WRITE');
    $obFields = CCrmInvoice::GetList(array(), $arFilter);
    $arFields = $obFields->GetNext();
    if ($arFields === false) {
        $bEdit = false;
        $bCopy = false;
    } else {
        $arEntityAttr = $CCrmInvoice->cPerms->GetEntityAttr('INVOICE', array($arParams['ELEMENT_ID']));
    }
    //HACK: MSSQL returns '.00' for zero value
    if (isset($arFields['~PRICE'])) {
        $arFields['~PRICE'] = $arFields['PRICE'] = floatval($arFields['~PRICE']);
    }
} else {
    $arFields = array('ID' => 0, 'DATE_INSERT' => ConvertTimeStamp(time(), 'FULL', SITE_ID));
    if ($bCreateFromQuote) {
        $arFields['UF_QUOTE_ID'] = $quoteId;
예제 #15
0
 public static function getList($params, $nav = 0)
 {
     if (!CCrmInvoice::CheckReadPermission(0)) {
         throw new RestException('Access denied.');
     }
     $order = CCrmInvoiceRestUtil::getParamArray($params, 'order', array('ID' => 'DESC'));
     $filter = CCrmInvoiceRestUtil::getParamArray($params, 'filter');
     $select = CCrmInvoiceRestUtil::getParamArray($params, 'select');
     $filter = self::prepareFilter($filter);
     $select = self::prepareSelect($select);
     $order = self::prepareOrder($order);
     if (!is_array($select) || count($select) === 0) {
         throw new RestException('Inadmissible fields for selection');
     }
     $dbResult = CCrmInvoice::GetList($order, $filter, false, self::getNavData($nav), $select);
     $result = array();
     while ($arRow = $dbResult->NavNext(false)) {
         $result[] = self::filterFields($arRow, 'list');
     }
     return self::setNavData($result, $dbResult);
 }