public static function getFilterCounter($filter) { if (!is_array($filter)) { $filter = array(); } if (empty($filter)) { return self::getAllCounter(); } $filter['ORDER_DISCOUNT_DATA.ID'] = null; $countQuery = new Main\Entity\Query(Sale\Internals\OrderTable::getEntity()); $countQuery->addSelect(new Main\Entity\ExpressionField('CNT', 'COUNT(1)')); $countQuery->setFilter($filter); $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch(); return (int) $totalCount['CNT']; }
/** * @return array */ protected static function getSelectFields() { $fields = array_keys(OrderTable::getEntity()->getScalarFields()); return array_merge($fields, array('DATE_INSERT_FORMAT', 'DATE_UPDATE_SHORT', 'DATE_STATUS_SHORT', 'DATE_CANCELED_SHORT', 'BY_RECOMMENDATION', 'LOCK_STATUS', 'LOCK_USER_NAME', 'DATE_INSERT_FORMAT', "RESPONSIBLE_ID", "RESPONSIBLE_LOGIN", "RESPONSIBLE_NAME", "RESPONSIBLE_LAST_NAME", "RESPONSIBLE_SECOND_NAME", "RESPONSIBLE_EMAIL", "RESPONSIBLE_WORK_POSITION", "RESPONSIBLE_PERSONAL_PHOTO", "RESPONSIBLE_GROUP_ID", "PAY_SYSTEM_ID", "DELIVERY_ID", "DEDUCTED", "RESERVED", "PRICE_DELIVERY", "ALLOW_DELIVERY", "DATE_ALLOW_DELIVERY", "EMP_ALLOW_DELIVERY_ID", "DELIVERY_DOC_NUM", "DELIVERY_DOC_DATE", "PAYED", "DATE_PAYED", "EMP_PAYED_ID", "STATUS_ID", "DATE_STATUS", "EMP_STATUS_ID", "DATE_INSERT_FORMAT", "USER_LOGIN", "USER_NAME", "USER_LAST_NAME", "USER_EMAIL", "DATE_PAY_BEFORE", "DATE_BILL", "ACCOUNT_NUMBER", "TRACKING_NUMBER")); }
} if (array_key_exists('=SOURCE.TRADING_PLATFORM_ID', $arFilterTmp) || in_array('SOURCE_NAME', $arSelectFields)) { $runtimeFields['SOURCE'] = array('data_type' => 'Bitrix\\Sale\\TradingPlatform\\OrderTable', 'reference' => array('ref.ORDER_ID' => 'this.ID'), 'join_type' => 'left'); $arSelectFields["SOURCE_NAME"] = 'SOURCE.TRADING_PLATFORM.NAME'; if ($searchIndex = array_search('SOURCE_NAME', $arSelectFields)) { unset($arSelectFields[$searchIndex]); } } $getListParams = array('order' => $arFilterOrder, 'filter' => $arFilterTmp, 'group' => $arGroupByTmp, 'select' => $arSelectFields, 'runtime' => $runtimeFields); if ($usePageNavigation) { $getListParams['limit'] = $navyParams['SIZEN']; $getListParams['offset'] = $navyParams['SIZEN'] * ($navyParams['PAGEN'] - 1); } $totalPages = 0; if ($usePageNavigation) { $countQuery = new \Bitrix\Main\Entity\Query(\Bitrix\Sale\Internals\OrderTable::getEntity()); $countQuery->addSelect(new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(1)')); $countQuery->setFilter($getListParams['filter']); foreach ($runtimeFields as $key => $field) { $countQuery->registerRuntimeField($key, $field); } $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch(); unset($countQuery); $totalCount = (int) $totalCount['CNT']; if ($totalCount > 0) { $totalPages = ceil($totalCount / $navyParams['SIZEN']); if ($navyParams['PAGEN'] > $totalPages) { $navyParams['PAGEN'] = $totalPages; } $getListParams['limit'] = $navyParams['SIZEN']; $getListParams['offset'] = $navyParams['SIZEN'] * ($navyParams['PAGEN'] - 1);
/** * Perform reading main data from database, no cache is used * @return void */ protected function obtainDataOrders() { $select = array('ID', 'LID', 'PERSON_TYPE_ID', 'PAYED', 'DATE_PAYED', 'EMP_PAYED_ID', 'CANCELED', 'DATE_CANCELED', 'EMP_CANCELED_ID', 'REASON_CANCELED', 'MARKED', 'DATE_MARKED', 'EMP_MARKED_ID', 'REASON_MARKED', 'STATUS_ID', 'DATE_STATUS', 'PAY_VOUCHER_NUM', 'PAY_VOUCHER_DATE', 'EMP_STATUS_ID', 'PRICE_DELIVERY', 'ALLOW_DELIVERY', 'DATE_ALLOW_DELIVERY', 'EMP_ALLOW_DELIVERY_ID', 'DEDUCTED', 'DATE_DEDUCTED', 'EMP_DEDUCTED_ID', 'REASON_UNDO_DEDUCTED', 'RESERVED', 'PRICE', 'CURRENCY', 'DISCOUNT_VALUE', 'SUM_PAID', 'USER_ID', 'PAY_SYSTEM_ID', 'DELIVERY_ID', 'DATE_INSERT', 'DATE_UPDATE', 'USER_DESCRIPTION', 'ADDITIONAL_INFO', 'COMMENTS', 'TAX_VALUE', 'STAT_GID', 'RECURRING_ID', 'RECOUNT_FLAG', 'DELIVERY_DOC_NUM', 'DELIVERY_DOC_DATE', 'STORE_ID', 'ORDER_TOPIC', 'RESPONSIBLE_ID', 'DATE_PAY_BEFORE', 'DATE_BILL', 'ACCOUNT_NUMBER', 'TRACKING_NUMBER', 'XML_ID'); $usePageNavigation = true; $navyParams = array(); $navyParams = \CDBResult::GetNavParams(); if ($navyParams['SHOW_ALL']) { $usePageNavigation = false; } else { $navyParams['PAGEN'] = (int) $navyParams['PAGEN']; $navyParams['SIZEN'] = (int) $navyParams['SIZEN']; } if (isset($this->arParams["ORDERS_PER_PAGE"]) && intval($this->arParams["ORDERS_PER_PAGE"]) > 0) { $navyParams['SIZEN'] = $this->arParams["ORDERS_PER_PAGE"]; } if (isset($_REQUEST['show_all']) && $_REQUEST['show_all'] == "Y") { $usePageNavigation = false; } $getListParams = array('order' => array($this->sortBy => $this->sortOrder), 'filter' => $this->filter, 'select' => $select); if ($usePageNavigation) { $getListParams['limit'] = $navyParams['SIZEN']; $getListParams['offset'] = $navyParams['SIZEN'] * ($navyParams['PAGEN'] - 1); } $totalPages = 0; if ($usePageNavigation) { $countQuery = new \Bitrix\Main\Entity\Query(\Bitrix\Sale\Internals\OrderTable::getEntity()); $countQuery->addSelect(new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(1)')); $countQuery->setFilter($getListParams['filter']); $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch(); unset($countQuery); $totalCount = (int) $totalCount['CNT']; if ($totalCount > 0) { $totalPages = ceil($totalCount / $navyParams['SIZEN']); if ($navyParams['PAGEN'] > $totalPages) { $navyParams['PAGEN'] = $totalPages; } $getListParams['limit'] = $navyParams['SIZEN']; $getListParams['offset'] = $navyParams['SIZEN'] * ($navyParams['PAGEN'] - 1); } else { $navyParams['PAGEN'] = 1; $getListParams['limit'] = $navyParams['SIZEN']; $getListParams['offset'] = 0; } } $this->dbQueryResult['ORDERS'] = new \CDBResult(\Bitrix\Sale\Internals\OrderTable::getList($getListParams)); if ($usePageNavigation) { $this->dbQueryResult['ORDERS']->NavStart($getListParams['limit'], $navyParams['SHOW_ALL'], $navyParams['PAGEN']); $this->dbQueryResult['ORDERS']->NavRecordCount = $totalCount; $this->dbQueryResult['ORDERS']->NavPageCount = $totalPages; $this->dbQueryResult['ORDERS']->NavPageNomer = $navyParams['PAGEN']; } else { $this->dbQueryResult['ORDERS']->NavStart($this->arParams["ORDERS_PER_PAGE"], false); } if (empty($this->dbQueryResult['ORDERS'])) { return; } while ($arOrder = $this->dbQueryResult['ORDERS']->GetNext()) { $arOBasket = array(); $dbBasket = CSaleBasket::GetList(array('NAME' => 'asc'), array("ORDER_ID" => $arOrder["ID"]), false, false, array('*')); while ($arBasket = $dbBasket->Fetch()) { if (CSaleBasketHelper::isSetItem($arBasket)) { continue; } $arOBasket[$arBasket['ID']] = $arBasket; } $arOShipment = array(); $dbShipment = \Bitrix\Sale\Internals\ShipmentTable::getList(array('select' => array('DELIVERY_NAME', 'SYSTEM', 'DELIVERY_ID'), 'filter' => array('ORDER_ID' => $arOrder['ID']))); while ($arShipment = $dbShipment->fetch()) { if ($arShipment['SYSTEM'] == 'Y') { continue; } $arOShipment[] = $arShipment; } $dbPayment = \Bitrix\Sale\Internals\PaymentTable::getList(array('select' => array('PAY_SYSTEM_NAME', 'PAY_SYSTEM_ID'), 'filter' => array('ORDER_ID' => $arOrder['ID']))); $arOPayment = array(); while ($arPayment = $dbPayment->fetch()) { $arOPayment[] = $arPayment; } $this->dbResult['ORDERS'][] = array("ORDER" => $arOrder, "BASKET_ITEMS" => $arOBasket, "SHIPMENT" => $arOShipment, "PAYMENT" => $arOPayment); } }