Пример #1
0
        $ary['MEASURE_CODE'] = isset($row['MEASURE_CODE']) ? intval($row['MEASURE_CODE']) : 0;
        $ary['MEASURE_NAME'] = isset($row['MEASURE_NAME']) ? $row['MEASURE_NAME'] : '';
        unset($row['ORDER_ID'], $row['NAME'], $row['DISCOUNT_PRICE'], $row['VAT_RATE'], $row['CUSTOM_PRICE']);
    }
    if ($arResult['ALLOW_LD_TAX']) {
        $row['PRICE'] = CCrmProductRow::CalculateExclusivePrice($row['PRICE'], $row['TAX_RATE']);
        $row['TAX_RATE'] = 0.0;
        $row['TAX_INCLUDED'] = 'N';
    }
    $exclusivePrice = CCrmProductRow::CalculateExclusivePrice($row['PRICE'], $row['TAX_RATE']);
    $discountTypeID = intval($row['DISCOUNT_TYPE_ID']);
    if ($discountTypeID === \Bitrix\Crm\Discount::MONETARY) {
        $row['PRICE_NETTO'] = $exclusivePrice + $row['DISCOUNT_SUM'];
    } else {
        $discoutRate = doubleval($row['DISCOUNT_RATE']);
        $discoutSum = $discoutRate < 100 ? \Bitrix\Crm\Discount::calculateDiscountSum($exclusivePrice, $discoutRate) : doubleval($row['DISCOUNT_SUM']);
        $row['PRICE_NETTO'] = $exclusivePrice + $discoutSum;
    }
    $row['PRICE_BRUTTO'] = CCrmProductRow::CalculateInclusivePrice($row['PRICE_NETTO'], $row['TAX_RATE']);
    $totalDiscount += round($row['QUANTITY'] * $row['DISCOUNT_SUM'], 2);
    //$totalSum += round($row['QUANTITY'] * $row['PRICE'], 2);
    //$totalTax += round($row['PRICE'] - $exclusivePrice, 2);
}
unset($row);
if (count($arResult['PRODUCT_ROWS']) > 0 && (!isset($arParams['TOTAL_SUM']) || !isset($arParams['TOTAL_TAX']))) {
    $enableSaleDiscount = false;
    $calcOptions = array();
    if ($arResult['ALLOW_LD_TAX']) {
        $calcOptions['LOCATION_ID'] = isset($arParams['LOCATION_ID']) ? $arParams['LOCATION_ID'] : '';
    }
    $result = CCrmSaleHelper::Calculate($arResult['PRODUCT_ROWS'], $currencyID, $personTypeId, $enableSaleDiscount, SITE_ID, $calcOptions);
Пример #2
0
    } else {
        echo CUtil::PhpToJSObject(array('DELETED_PRODUCT_ID' => $ID));
    }
} elseif ($mode === 'CALCULATE_TOTALS') {
    if ($perms->HavePerm($ownerName, BX_CRM_PERM_NONE, 'WRITE')) {
        echo CUtil::PhpToJSObject(array('ERROR' => 'PERMISSION_DENIED'));
        die;
    }
    $productRows = isset($_POST['PRODUCTS']) && is_array($_POST['PRODUCTS']) ? $_POST['PRODUCTS'] : array();
    $totalDiscount = 0.0;
    foreach ($productRows as &$productRow) {
        $productRow['ID'] = isset($productRow['ID']) ? intval($productRow['ID']) : 0;
        $productRow['PRODUCT_ID'] = isset($productRow['PRODUCT_ID']) ? intval($productRow['PRODUCT_ID']) : 0;
        $productRow['PRODUCT_NAME'] = isset($productRow['PRODUCT_NAME']) ? $productRow['PRODUCT_NAME'] : '';
        $productRow['QUANTITY'] = isset($productRow['QUANTITY']) ? doubleval($productRow['QUANTITY']) : 1.0;
        $productRow['DISCOUNT_TYPE_ID'] = isset($productRow['DISCOUNT_TYPE_ID']) && \Bitrix\Crm\Discount::isDefined(intval($productRow['DISCOUNT_TYPE_ID'])) ? intval($productRow['DISCOUNT_TYPE_ID']) : \Bitrix\Crm\Discount::PERCENTAGE;
        $productRow['DISCOUNT_RATE'] = isset($productRow['DISCOUNT_RATE']) ? doubleval($productRow['DISCOUNT_RATE']) : 0.0;
        $productRow['DISCOUNT_SUM'] = isset($productRow['DISCOUNT_SUM']) ? doubleval($productRow['DISCOUNT_SUM']) : 0.0;
        $productRow['PRICE'] = isset($productRow['PRICE']) ? doubleval($productRow['PRICE']) : 1.0;
        $productRow['CUSTOMIZED'] = isset($productRow['CUSTOMIZED']) && strtoupper($productRow['CUSTOMIZED']) === 'Y' ? 'Y' : 'N';
        if ($productRow['CUSTOMIZED'] === 'Y') {
            $productRow['TAX_RATE'] = isset($productRow['TAX_RATE']) ? doubleval($productRow['TAX_RATE']) : 0.0;
        }
        $totalDiscount += round($productRow['DISCOUNT_SUM'] * $productRow['QUANTITY'], 2);
    }
    unset($productRow);
    $currencyID = isset($_POST['CURRENCY_ID']) && $_POST['CURRENCY_ID'] !== '' ? $_POST['CURRENCY_ID'] : CCrmCurrency::GetBaseCurrencyID();
    $clientTypeName = isset($_POST['CLIENT_TYPE_NAME']) && $_POST['CLIENT_TYPE_NAME'] !== '' ? strtoupper($_POST['CLIENT_TYPE_NAME']) : 'CONTACT';
    $personTypeIDs = CCrmPaySystem::getPersonTypeIDs();
    if (empty($personTypeIDs)) {
        echo CUtil::PhpToJSObject(array('ERROR' => 'PERSON_TYPES_NOT_DEFINED'));
Пример #3
0
 public static function ProductRows2BasketItems($arProductRows, $srcCurrencyID = '', $dstCurrencyID = '')
 {
     $basketItems = array();
     $srcCurrencyID = strval($srcCurrencyID);
     $dstCurrencyID = strval($dstCurrencyID);
     if (strlen($srcCurrencyID) <= 0 || strlen($dstCurrencyID) <= 0) {
         $srcCurrencyID = $dstCurrencyID = '';
     }
     foreach ($arProductRows as $row) {
         $freshRow = array();
         $freshRow['ID'] = isset($row['ID']) ? intval($row['ID']) : 0;
         $freshRow['PRODUCT_ID'] = isset($row['PRODUCT_ID']) ? intval($row['PRODUCT_ID']) : 0;
         $freshRow['PRODUCT_NAME'] = isset($row['PRODUCT_NAME']) ? strval($row['PRODUCT_NAME']) : '';
         $freshRow['QUANTITY'] = isset($row['QUANTITY']) ? round(doubleval($row['QUANTITY']), 2) : 0.0;
         $freshRow['PRICE'] = isset($row['PRICE']) ? round(doubleval($row['PRICE']), 2) : 0.0;
         if ($dstCurrencyID != $srcCurrencyID) {
             $freshRow['PRICE'] = CCrmCurrency::ConvertMoney($freshRow['PRICE'], $srcCurrencyID, $dstCurrencyID);
         }
         $taxRate = isset($row['TAX_RATE']) ? round(doubleval($row['TAX_RATE']), 2) : 0.0;
         $freshRow['VAT_RATE'] = $taxRate / 100;
         $discountTypeID = isset($row['DISCOUNT_TYPE_ID']) ? intval($row['DISCOUNT_TYPE_ID']) : \Bitrix\Crm\Discount::UNDEFINED;
         if ($discountTypeID !== \Bitrix\Crm\Discount::PERCENTAGE && $discountTypeID !== \Bitrix\Crm\Discount::MONETARY) {
             $discountTypeID = \Bitrix\Crm\Discount::PERCENTAGE;
         }
         if ($discountTypeID === \Bitrix\Crm\Discount::PERCENTAGE) {
             $discountRate = isset($row['DISCOUNT_RATE']) ? round(doubleval($row['DISCOUNT_RATE']), 2) : 0.0;
             $exclusivePrice = CCrmProductRow::CalculateExclusivePrice($freshRow['PRICE'], $taxRate);
             $freshRow['DISCOUNT_PRICE'] = round(\Bitrix\Crm\Discount::calculateDiscountSum($exclusivePrice, $discountRate), 2);
         } else {
             $freshRow['DISCOUNT_PRICE'] = isset($row['DISCOUNT_SUM']) ? round(doubleval($row['DISCOUNT_SUM']), 2) : 0.0;
             if ($dstCurrencyID != $srcCurrencyID) {
                 $freshRow['DISCOUNT_PRICE'] = CCrmCurrency::ConvertMoney($freshRow['DISCOUNT_PRICE'], $srcCurrencyID, $dstCurrencyID);
             }
         }
         $freshRow['MEASURE_CODE'] = isset($row['MEASURE_CODE']) ? intval($row['MEASURE_CODE']) : 0;
         $freshRow['MEASURE_NAME'] = isset($row['MEASURE_NAME']) ? strval($row['MEASURE_NAME']) : '';
         $freshRow['CUSTOMIZED'] = isset($row['CUSTOMIZED']) ? $row['CUSTOMIZED'] === 'Y' ? 'Y' : 'N' : 'Y';
         $basketItems[] = $freshRow;
     }
     return $basketItems;
 }
Пример #4
0
 private static function PrepareShoppingCartItems(&$productRows, $currencyID, $siteId)
 {
     $items = array();
     foreach ($productRows as $k => &$v) {
         $item = array();
         $item['PRODUCT_ID'] = isset($v['PRODUCT_ID']) ? intval($v['PRODUCT_ID']) : 0;
         $isCustomized = isset($v['CUSTOMIZED']) && $v['CUSTOMIZED'] === 'Y';
         if ($item['PRODUCT_ID'] > 0 && !$isCustomized) {
             $item['MODULE'] = 'catalog';
             $item['PRODUCT_PROVIDER_CLASS'] = 'CCatalogProductProvider';
         } else {
             $item['MODULE'] = $item['PRODUCT_PROVIDER_CLASS'] = '';
         }
         if ($isCustomized) {
             $item['CUSTOM_PRICE'] = 'Y';
         }
         $item['TABLE_ROW_ID'] = $k;
         $item['QUANTITY'] = isset($v['QUANTITY']) ? doubleval($v['QUANTITY']) : 0;
         $item['QUANTITY_DEFAULT'] = $item['QUANTITY'];
         $item['PRICE'] = isset($v['PRICE']) ? doubleval($v['PRICE']) : 0.0;
         $item['PRICE_DEFAULT'] = $item['PRICE'];
         $item['CURRENCY'] = $currencyID;
         // discount info
         $item['CRM_PR_FIELDS'] = array();
         $item['CRM_PR_FIELDS']['DISCOUNT_TYPE_ID'] = isset($v['DISCOUNT_TYPE_ID']) ? intval($v['DISCOUNT_TYPE_ID']) : \Bitrix\Crm\Discount::PERCENTAGE;
         $item['CRM_PR_FIELDS']['DISCOUNT_RATE'] = isset($v['DISCOUNT_RATE']) ? round(doubleval($v['DISCOUNT_RATE']), 2) : 0.0;
         $item['CRM_PR_FIELDS']['DISCOUNT_SUM'] = isset($v['DISCOUNT_SUM']) ? round(doubleval($v['DISCOUNT_SUM']), 2) : 0.0;
         // tax info
         $taxRate = isset($v['TAX_RATE']) ? round(doubleval($v['TAX_RATE']), 2) : 0.0;
         $allowLDTax = CCrmTax::isTaxMode();
         if ($allowLDTax) {
             $item['CRM_PR_FIELDS']['TAX_RATE'] = 0.0;
             $item['CRM_PR_FIELDS']['TAX_INCLUDED'] = 'N';
         } else {
             $item['CRM_PR_FIELDS']['TAX_RATE'] = $taxRate;
             $item['CRM_PR_FIELDS']['TAX_INCLUDED'] = isset($v['TAX_INCLUDED']) && $v['TAX_INCLUDED'] === 'Y' ? 'Y' : 'N';
         }
         // price netto, price brutto
         $exclusivePrice = $taxRate !== 0.0 ? CCrmProductRow::CalculateExclusivePrice($item['PRICE'], $taxRate) : $item['PRICE'];
         if ($item['CRM_PR_FIELDS']['DISCOUNT_TYPE_ID'] === \Bitrix\Crm\Discount::MONETARY) {
             $priceNetto = $exclusivePrice + $item['CRM_PR_FIELDS']['DISCOUNT_SUM'];
             $item['CRM_PR_FIELDS']['PRICE_NETTO'] = round($priceNetto, 2);
         } else {
             $discoutRate = $item['CRM_PR_FIELDS']['DISCOUNT_RATE'];
             $discoutSum = $discoutRate < 100 ? \Bitrix\Crm\Discount::calculateDiscountByDiscountPrice($exclusivePrice, $discoutRate) : $item['CRM_PR_FIELDS']['DISCOUNT_SUM'];
             $priceNetto = $exclusivePrice + $discoutSum;
             $item['CRM_PR_FIELDS']['PRICE_NETTO'] = round($priceNetto, 2);
         }
         if ($item['CRM_PR_FIELDS']['DISCOUNT_SUM'] === 0.0) {
             $item['CRM_PR_FIELDS']['PRICE_BRUTTO'] = $item['PRICE'];
         } else {
             $item['CRM_PR_FIELDS']['PRICE_BRUTTO'] = round(CCrmProductRow::CalculateInclusivePrice($priceNetto, $item['CRM_PR_FIELDS']['TAX_RATE']), 2);
         }
         if (isset($v['VAT_RATE'])) {
             $item['VAT_RATE'] = $v['VAT_RATE'];
         } elseif (isset($v['TAX_RATE'])) {
             $item['VAT_RATE'] = $v['TAX_RATE'] / 100;
         }
         if (isset($v['MEASURE_CODE'])) {
             $item['MEASURE_CODE'] = $v['MEASURE_CODE'];
         }
         if (isset($v['MEASURE_NAME'])) {
             $item['MEASURE_NAME'] = $v['MEASURE_NAME'];
         }
         $item['NAME'] = isset($v['NAME']) ? $v['NAME'] : (isset($v['PRODUCT_NAME']) ? $v['PRODUCT_NAME'] : '');
         $item['LID'] = $siteId;
         $item['CAN_BUY'] = 'Y';
         $items[] =& $item;
         unset($item);
     }
     unset($v);
     return $items;
 }
Пример #5
0
 public static function SaveRows($ownerType, $ownerID, $arRows, $accountContext = null, $checkPerms = true, $regEvent = true, $syncOwner = true, $totalInfo = array())
 {
     $ownerType = strval($ownerType);
     $ownerID = intval($ownerID);
     if (!isset($ownerType[0]) || $ownerID <= 0 || !is_array($arRows)) {
         self::RegisterError('Invalid arguments are supplied.');
         return false;
     }
     if (!is_array($totalInfo)) {
         $totalInfo = array();
     }
     $owner = null;
     if (!is_array($accountContext)) {
         if ($ownerType === 'D') {
             $owner = CCrmDeal::GetByID($ownerID, $checkPerms);
         } elseif ($ownerType === CCrmQuote::OWNER_TYPE) {
             $owner = CCrmQuote::GetByID($ownerID);
         } elseif ($ownerType === 'L') {
             $owner = CCrmLead::GetByID($ownerID);
         }
     }
     // Preparing accounting context -->
     if (!is_array($accountContext)) {
         $accountContext = array();
         if (is_array($owner)) {
             if (isset($owner['CURRENCY_ID'])) {
                 $accountContext['CURRENCY_ID'] = $owner['CURRENCY_ID'];
             }
             if (isset($owner['EXCH_RATE'])) {
                 $accountContext['EXCH_RATE'] = $owner['EXCH_RATE'];
             }
         }
     }
     $currencyID = isset($accountContext['CURRENCY_ID']) ? $accountContext['CURRENCY_ID'] : CCrmCurrency::GetBaseCurrencyID();
     $exchRate = isset($accountContext['EXCH_RATE']) ? $accountContext['EXCH_RATE'] : null;
     // <-- Preparing accounting context
     $productIDs = array();
     $products = array();
     foreach ($arRows as &$arRow) {
         $productID = isset($arRow['PRODUCT_ID']) ? intval($arRow['PRODUCT_ID']) : 0;
         if ($productID > 0 && !in_array($productID, $productIDs, true)) {
             $productIDs[] = $productID;
         }
     }
     unset($arRow);
     if (!empty($productIDs)) {
         $dbProduct = CCrmProduct::GetList(array(), array('ID' => $productIDs), array('ID', 'NAME'));
         if (is_object($dbProduct)) {
             while ($product = $dbProduct->Fetch()) {
                 $products[intval($product['ID'])] = $product;
             }
         }
     }
     $measurelessProductIDs = array();
     $arSafeRows = array();
     foreach ($arRows as &$arRow) {
         //$rowID = isset($arRow['ID']) ? intval($arRow['ID']) : 0;
         $productID = $arRow['PRODUCT_ID'] = isset($arRow['PRODUCT_ID']) ? intval($arRow['PRODUCT_ID']) : 0;
         $productName = $arRow['PRODUCT_NAME'] = isset($arRow['PRODUCT_NAME']) ? $arRow['PRODUCT_NAME'] : '';
         $arRow['PRICE'] = isset($arRow['PRICE']) ? round(doubleval($arRow['PRICE']), 2) : 0.0;
         $arRow['QUANTITY'] = isset($arRow['QUANTITY']) ? round(doubleval($arRow['QUANTITY']), 4) : 1;
         $arRow['TAX_RATE'] = isset($arRow['TAX_RATE']) ? round(doubleval($arRow['TAX_RATE']), 2) : 0.0;
         $arRow['TAX_INCLUDED'] = isset($arRow['TAX_INCLUDED']) ? $arRow['TAX_INCLUDED'] === 'Y' ? 'Y' : 'N' : 'N';
         $arRow['MEASURE_CODE'] = isset($arRow['MEASURE_CODE']) ? intval($arRow['MEASURE_CODE']) : 0;
         $arRow['MEASURE_NAME'] = isset($arRow['MEASURE_NAME']) ? $arRow['MEASURE_NAME'] : '';
         $arRow['CUSTOMIZED'] = isset($arRow['CUSTOMIZED']) && strtoupper($arRow['CUSTOMIZED']) === 'Y' ? 'Y' : 'N';
         $arRow['SORT'] = isset($arRow['SORT']) ? intval($arRow['SORT']) : 0;
         if ($productID > 0 && $productName !== '' && isset($products[$productID])) {
             //Skip save product name if it equal to original
             $product = $products[$productID];
             $originalProductName = isset($product['NAME']) ? trim($product['NAME']) : '';
             if ($productName === $originalProductName) {
                 $productName = '';
             }
         }
         $price = $arRow['PRICE'];
         $arRow['DISCOUNT_TYPE_ID'] = isset($arRow['DISCOUNT_TYPE_ID']) ? intval($arRow['DISCOUNT_TYPE_ID']) : 0;
         if (!\Bitrix\Crm\Discount::isDefined($arRow['DISCOUNT_TYPE_ID'])) {
             $arRow['DISCOUNT_TYPE_ID'] = \Bitrix\Crm\Discount::PERCENTAGE;
             $arRow['DISCOUNT_RATE'] = 0.0;
         }
         $discountTypeID = $arRow['DISCOUNT_TYPE_ID'];
         if ($discountTypeID === \Bitrix\Crm\Discount::PERCENTAGE) {
             if (!isset($arRow['DISCOUNT_RATE'])) {
                 self::RegisterError("Discount Rate (DISCOUNT_RATE) is required if Percentage Discount Type (DISCOUNT_TYPE_ID) is defined.");
                 return false;
             }
             $discountRate = round(doubleval($arRow['DISCOUNT_RATE']), 2);
             if (isset($arRow['DISCOUNT_SUM'])) {
                 $discountSum = round(doubleval($arRow['DISCOUNT_SUM']), 2);
             } else {
                 $exclusivePrice = self::CalculateExclusivePrice($price, $arRow['TAX_RATE']);
                 $discountSum = round(\Bitrix\Crm\Discount::calculateDiscountSum($exclusivePrice, $discountRate), 2);
             }
         } else {
             if (!isset($arRow['DISCOUNT_SUM'])) {
                 self::RegisterError("Discount Sum (DISCOUNT_SUM) is required if Monetary Discount Type (DISCOUNT_TYPE_ID) is defined.");
                 return false;
             }
             $discountSum = round(doubleval($arRow['DISCOUNT_SUM']), 2);
             if (isset($arRow['DISCOUNT_RATE'])) {
                 $discountRate = round(doubleval($arRow['DISCOUNT_RATE']), 2);
             } else {
                 $exclusivePrice = self::CalculateExclusivePrice($price, $arRow['TAX_RATE']);
                 $discountRate = \Bitrix\Crm\Discount::calculateDiscountRate($exclusivePrice + $discountSum, $exclusivePrice);
             }
         }
         $measureCode = $arRow['MEASURE_CODE'];
         if ($productID > 0 && $measureCode <= 0) {
             if (!in_array($productID, $measurelessProductIDs, true)) {
                 $measurelessProductIDs[] = $productID;
             }
         }
         $safeRow = array('OWNER_TYPE' => $ownerType, 'OWNER_ID' => $ownerID, 'PRODUCT_ID' => $productID, 'PRODUCT_NAME' => $productName, 'PRICE' => $price, 'QUANTITY' => $arRow['QUANTITY'], 'DISCOUNT_TYPE_ID' => $discountTypeID, 'DISCOUNT_SUM' => $discountSum, 'DISCOUNT_RATE' => $discountRate, 'TAX_RATE' => $arRow['TAX_RATE'], 'TAX_INCLUDED' => isset($arRow['TAX_INCLUDED']) ? $arRow['TAX_INCLUDED'] === 'Y' ? 'Y' : 'N' : 'N', 'MEASURE_CODE' => $measureCode, 'MEASURE_NAME' => $arRow['MEASURE_NAME'], 'CUSTOMIZED' => 'Y', 'SORT' => $arRow['SORT']);
         $accData = CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => $currencyID, 'SUM' => $safeRow['PRICE'], 'EXCH_RATE' => $exchRate));
         if (is_array($accData)) {
             $safeRow['PRICE_ACCOUNT'] = $accData['ACCOUNT_SUM'];
         }
         $arSafeRows[] =& $safeRow;
         unset($safeRow);
     }
     unset($arRow);
     if (!empty($measurelessProductIDs)) {
         $defaultMeasureInfo = \Bitrix\Crm\Measure::getDefaultMeasure();
         $measureInfos = \Bitrix\Crm\Measure::getProductMeasures($measurelessProductIDs);
         foreach ($arSafeRows as &$safeRow) {
             if ($safeRow['MEASURE_CODE'] > 0) {
                 continue;
             }
             $productID = $safeRow['PRODUCT_ID'];
             if (isset($measureInfos[$productID]) && !empty($measureInfos[$productID])) {
                 $measureInfo = $measureInfos[$productID][0];
                 $safeRow['MEASURE_CODE'] = $measureInfo['CODE'];
                 $safeRow['MEASURE_NAME'] = $measureInfo['SYMBOL'];
             } elseif ($defaultMeasureInfo !== null) {
                 $safeRow['MEASURE_CODE'] = $defaultMeasureInfo['CODE'];
                 $safeRow['MEASURE_NAME'] = $defaultMeasureInfo['SYMBOL'];
             }
         }
         unset($safeRow);
     }
     $arPresentRows = self::LoadRows($ownerType, $ownerID, true);
     // Registering events -->
     if ($regEvent) {
         $arRowIDs = array();
         foreach ($arRows as &$arRow) {
             if (isset($arRow['ID'])) {
                 $arRowIDs[] = intval($arRow['ID']);
             }
             $rowID = isset($arRow['ID']) ? intval($arRow['ID']) : 0;
             if ($rowID <= 0) {
                 // Row was added
                 self::RegisterAddEvent($ownerType, $ownerID, $arRow, $checkPerms);
                 continue;
             }
             $arPresentRow = isset($arPresentRows[$rowID]) ? $arPresentRows[$rowID] : null;
             if ($arPresentRow) {
                 // Row was modified
                 self::RegisterUpdateEvent($ownerType, $ownerID, $arRow, $arPresentRow, $checkPerms);
             }
         }
         unset($arRow);
         foreach ($arPresentRows as $rowID => &$arPresentRow) {
             if (!in_array($rowID, $arRowIDs, true)) {
                 // Product  was removed
                 self::RegisterRemoveEvent($ownerType, $ownerID, $arPresentRow, $checkPerms);
             }
         }
     }
     // <-- Registering events
     $result = CCrmProductRow::DoSaveRows($ownerType, $ownerID, $arSafeRows);
     // Update list of taxes
     if (!isset($totalInfo['CURRENCY_ID'])) {
         $totalInfo['CURRENCY_ID'] = $currencyID;
     }
     self::UpdateTotalInfo($ownerType, $ownerID, $totalInfo);
     // Disable sum synchronization if product rows are empty
     if ($result && $syncOwner && (count($arPresentRows) > 0 || count($arSafeRows) > 0)) {
         self::SynchronizeOwner($ownerType, $ownerID, $checkPerms, $totalInfo);
     }
     return $result;
 }
Пример #6
0
 protected function innerGetList($order, $filter, $select, $navigation, &$errors)
 {
     $ownerID = isset($filter['OWNER_ID']) ? intval($filter['OWNER_ID']) : 0;
     $ownerType = isset($filter['OWNER_TYPE']) ? $filter['OWNER_TYPE'] : '';
     if ($ownerID <= 0 || $ownerType === '') {
         if ($ownerID <= 0) {
             $errors[] = 'The field OWNER_ID is required in filer.';
         }
         if ($ownerType === '') {
             $errors[] = 'The field OWNER_TYPE is required in filer.';
         }
         return false;
     }
     if ($ownerType === 'I') {
         //Crutch for Invoices
         if (!CCrmInvoice::CheckReadPermission($ownerID)) {
             $errors[] = 'Access denied.';
             return false;
         }
         $result = array();
         $productRows = CCrmInvoice::GetProductRows($ownerID);
         foreach ($productRows as $productRow) {
             $price = isset($productRow['PRICE']) ? $productRow['PRICE'] : 0.0;
             $discountSum = isset($productRow['DISCOUNT_PRICE']) ? $productRow['DISCOUNT_PRICE'] : 0.0;
             $taxRate = isset($productRow['VAT_RATE']) ? $productRow['VAT_RATE'] * 100 : 0.0;
             $exclusivePrice = CCrmProductRow::CalculateExclusivePrice($price, $taxRate);
             $discountRate = \Bitrix\Crm\Discount::calculateDiscountRate($exclusivePrice + $discountSum, $exclusivePrice);
             $result[] = array('ID' => $productRow['ID'], 'OWNER_ID' => $ownerID, 'OWNER_TYPE' => 'I', 'PRODUCT_ID' => isset($productRow['PRODUCT_ID']) ? $productRow['PRODUCT_ID'] : 0, 'PRODUCT_NAME' => isset($productRow['PRODUCT_NAME']) ? $productRow['PRODUCT_NAME'] : '', 'PRICE' => $price, 'QUANTITY' => isset($productRow['QUANTITY']) ? $productRow['QUANTITY'] : 0, 'DISCOUNT_TYPE_ID' => \Bitrix\Crm\Discount::MONETARY, 'DISCOUNT_RATE' => $discountRate, 'DISCOUNT_SUM' => $discountSum, 'TAX_RATE' => $taxRate, 'TAX_INCLUDED' => 'Y', 'MEASURE_CODE' => isset($productRow['MEASURE_CODE']) ? $productRow['MEASURE_CODE'] : '', 'MEASURE_NAME' => isset($productRow['MEASURE_NAME']) ? $productRow['MEASURE_NAME'] : '', 'CUSTOMIZED' => isset($productRow['CUSTOM_PRICE']) ? $productRow['CUSTOM_PRICE'] : 'N');
         }
         return $result;
     }
     if (!CCrmAuthorizationHelper::CheckReadPermission(CCrmProductRow::ResolveOwnerTypeName($ownerType), $ownerID)) {
         $errors[] = 'Access denied.';
         return false;
     }
     return CCrmProductRow::GetList($order, $filter, false, $navigation, $select, array('IS_EXTERNAL_CONTEXT' => true));
 }