Configuring Cashback Transaction History in the Personal Account on 1C-Bitrix
Users don't understand where their current balance came from. 250 was credited — for which order? 100 was deducted — when and on what purchase? Without transparent transaction history, a loyalty program breeds distrust. Simply "showing a database table" is not enough: proper pagination, filtering by operation type, and correct timezone handling are all required.
Transaction Table
The operation history is stored in local_cashback_transactions. A structure sufficient to display everything needed:
CREATE TABLE local_cashback_transactions (
ID BIGINT AUTO_INCREMENT PRIMARY KEY,
USER_ID INT NOT NULL,
TYPE ENUM('accrual','debit','reserve','release','expire','manual') NOT NULL,
AMOUNT DECIMAL(10,2) NOT NULL,
ORDER_ID INT,
PAYMENT_ID INT,
DESCRIPTION VARCHAR(500),
CREATED_AT DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
EXPIRES_AT DATETIME,
INDEX idx_user_date (USER_ID, CREATED_AT DESC)
);
The index on (USER_ID, CREATED_AT DESC) is mandatory. Without it, fetching the last 6 months of history for an active user with thousands of transactions will result in a full table scan.
History Component
Create a component at /local/components/local/cashback.history/. Structure:
class.php — query logic
templates/.default/template.php — template
lang/ru/ — language files
class.php — extends CBitrixComponent:
class CashbackHistoryComponent extends CBitrixComponent
{
public function executeComponent(): void
{
if (!$this->getUser()->isAuthorized()) {
ShowError('Access denied');
return;
}
$userId = (int)$this->getUser()->GetID();
$pageNum = max(1, (int)($_GET['page'] ?? 1));
$pageSize = (int)($this->arParams['PAGE_SIZE'] ?? 20);
$typeFilter = $_GET['type'] ?? '';
$filter = ['USER_ID' => $userId];
if (in_array($typeFilter, ['accrual', 'debit', 'expire'])) {
$filter['TYPE'] = $typeFilter;
}
$totalCount = CashbackTransactionTable::getCount($filter);
$transactions = CashbackTransactionTable::getList([
'filter' => $filter,
'order' => ['CREATED_AT' => 'DESC'],
'limit' => $pageSize,
'offset' => ($pageNum - 1) * $pageSize,
'select' => ['ID', 'TYPE', 'AMOUNT', 'ORDER_ID', 'DESCRIPTION', 'CREATED_AT', 'EXPIRES_AT'],
])->fetchAll();
// Load order numbers in a single query
$orderIds = array_filter(array_column($transactions, 'ORDER_ID'));
$orderNumbers = [];
if ($orderIds) {
$res = \Bitrix\Sale\Internals\OrderTable::getList([
'filter' => ['ID' => $orderIds],
'select' => ['ID', 'ACCOUNT_NUMBER'],
]);
while ($row = $res->fetch()) {
$orderNumbers[$row['ID']] = $row['ACCOUNT_NUMBER'];
}
}
$this->arResult = [
'BALANCE' => CashbackBalanceTable::getBalance($userId),
'TRANSACTIONS' => $transactions,
'ORDER_NUMBERS' => $orderNumbers,
'TOTAL_COUNT' => $totalCount,
'PAGE_NUM' => $pageNum,
'PAGE_SIZE' => $pageSize,
'TYPE_FILTER' => $typeFilter,
];
$this->includeComponentTemplate();
}
}
Display and Pagination
The key point with pagination: the standard CDBResult with NavStart/NavNext is suitable for legacy components. For a D7 component — calculate $totalPages manually and generate URLs.
// template.php
$totalPages = (int)ceil($arResult['TOTAL_COUNT'] / $arResult['PAGE_SIZE']);
$typeLabels = [
'accrual' => 'Accrual',
'debit' => 'Deduction',
'reserve' => 'Reserve',
'release' => 'Reserve release',
'expire' => 'Expiry',
'manual' => 'Manual adjustment',
];
$amountSign = [
'accrual' => '+',
'debit' => '−',
'reserve' => '−',
'release' => '+',
'expire' => '−',
'manual' => '',
];
Timezone: dates in the database are UTC. Convert to the user's timezone:
$userTz = new \DateTimeZone(\CTimeZone::GetOffset() ? 'UTC' : date_default_timezone_get());
$dt = new \DateTime($transaction['CREATED_AT'], new \DateTimeZone('UTC'));
$dt->setTimezone($userTz);
echo $dt->format('d.m.Y H:i');
Alternatively, use the standard \Bitrix\Main\Type\DateTime::createFromTimestamp() — it respects the site's timezone settings.
Linking to Orders
Transactions of type accrual and debit should link to the corresponding order. Build the link using ACCOUNT_NUMBER, not ID — this is the public order number shown in the personal account:
/personal/order/detail/{ACCOUNT_NUMBER}/
If the order has been deleted — do not show the link, only display the number with a note "(order deleted)."
Cashback Expiry
If the business logic includes cashback expiration (e.g., after 12 months of inactivity), the EXPIRES_AT field is displayed for accrual transactions. A daily cron job finds expired cashback and creates an expire transaction:
// Cron: local midnight
$expired = CashbackTransactionTable::getList([
'filter' => [
'TYPE' => 'accrual',
'<EXPIRES_AT' => new \Bitrix\Main\Type\DateTime(),
'EXPIRED' => false,
],
]);
Scope of Work
- Transaction table with indexes
- Component
/local/components/local/cashback.history/with pagination and filtering - Timezone conversion, order linkage
- Cashback expiry mechanism (if required)
- Placement of the component in the personal account template
Timeline: 1–1.5 weeks for the component and template. 2–3 weeks including the expiry mechanism and admin interface for manual adjustments.







