Skip to content
Educora
Advanced20 min12 / 14

Reports (DCS) and print forms

Build flexible reports with the Data Composition System (`СКД`) without writing code, run a schema programmatically, and create print forms such as a delivery note from spreadsheet document templates.

Check yourself
In this lesson you will learn
  • Explain the parts of a DCS schema and build a simple report
  • Run a composition schema from code and output the result to a spreadsheet document
  • Create a print form using template areas and parameters

Aysel, an accountant, wants sales by warehouse today, by product tomorrow and for just one customer the day after. Instead of asking a developer every time, she changes the report's settings herself. The Data Composition System — СКД (DCS) — makes this possible. In the second half of the lesson we create document print forms — the delivery notes that come out on paper.

The Data Composition System

Definition
Composition schema

It describes what data a report gets: data sets (usually a query), resources (totals), parameters and calculated fields. Settings decide how the data is shown: groupings, filters, sorting and conditional appearance.

1C Query
ВЫБРАТЬ
    Продажи.Склад КАК Склад,
    Продажи.Товар КАК Товар,
    Продажи.КоличествоОборот КАК Количество,
    Продажи.СуммаОборот КАК Сумма
ИЗ
    РегистрНакопления.Продажи.Обороты(&НачалоПериода, &КонецПериода, , ) КАК Продажи
The query for a DCS data set. &НачалоПериода and &КонецПериода automatically become report parameters.
  1. 1
    Create a report and a schema

    Отчеты → Добавить, name ПродажиПоСкладам. Click Открыть схему компоновки данных (Open data composition schema) next to Основная схема компоновки данных and create a new schema.

  2. 2
    Data set and resources

    On the Наборы данных tab add Набор данных - запрос (query data set) and write the query in the wizard. On the Ресурсы tab make Количество and Сумма resources — they will be summed per group.

  3. 3
    Set up the settings

    On the Настройки tab add a grouping by Склад with Детальные записи (detailed records) inside it; tick the fields in Выбранные поля (selected fields). Include the report in a subsystem.

  4. 4
    Run it

    Press F5, open the report, choose the period and click Сформировать (Generate). The platform built the form itself — users can change groupings via Настройки… (Settings) and save variants.

Running a schema from code

Sometimes you need the result programmatically — for example to email a report. The chain is: schema + settings → template composer → composition processor → output processor. The code runs on the server.

1C
Схема = Отчеты.ПродажиПоСкладам.ПолучитьМакет("ОсновнаяСхемаКомпоновкиДанных");
Настройки = Схема.НастройкиПоУмолчанию;
Настройки.ПараметрыДанных.УстановитьЗначениеПараметра("НачалоПериода", НачалоМесяца(ТекущаяДатаСеанса()));
Настройки.ПараметрыДанных.УстановитьЗначениеПараметра("КонецПериода", КонецМесяца(ТекущаяДатаСеанса()));

КомпоновщикМакета = Новый КомпоновщикМакетаКомпоновкиДанных;
МакетКомпоновки = КомпоновщикМакета.Выполнить(Схема, Настройки);

Процессор = Новый ПроцессорКомпоновкиДанных;
Процессор.Инициализировать(МакетКомпоновки);

ТабДок = Новый ТабличныйДокумент;
ПроцессорВывода = Новый ПроцессорВыводаРезультатаКомпоновкиДанныхВТабличныйДокумент;
ПроцессорВывода.УстановитьДокумент(ТабДок);
ПроцессорВывода.Вывести(Процессор);
The result is a ТабличныйДокумент (spreadsheet document) that can be saved to a file (for example PDF or XLSX). For a table, use ПроцессорВыводаРезультатаКомпоновкиДанныхВКоллекциюЗначений.

Print forms

A print form is built on a template (Макет) of type Табличный документ (spreadsheet document). The template has named areas (for example Шапка header, Строка row, Подвал footer) and parameters in its cells. The code takes the areas, fills the parameters and outputs them one after another into a new spreadsheet document.

  1. 1
    Add a template

    On the Макеты tab of РасходТовара click Добавить, type Табличный документ, name Накладная (delivery note).

  2. 2
    Name the areas

    Select the header rows and name them Шапка via Таблица › Имена › Назначить имя… (Table › Names › Assign name); name the product row Строка.

  3. 3
    Set up parameters

    In a cell's properties set Заполнение (Fill type) = Параметр and Параметр = Номер (or Дата, Товар, Количество). Give the parameter the same name as the document attribute.

1C
// Модуль менеджера документа РасходТовара
Функция ПечатнаяФорма(Ссылка) Экспорт
    Макет = Документы.РасходТовара.ПолучитьМакет("Накладная");
    ОбластьШапка = Макет.ПолучитьОбласть("Шапка");
    ОбластьСтрока = Макет.ПолучитьОбласть("Строка");

    ТабДок = Новый ТабличныйДокумент;
    ОбластьШапка.Параметры.Заполнить(Ссылка);   // Номер, Дата, Склад
    ТабДок.Вывести(ОбластьШапка);

    Для Каждого СтрокаТЧ Из Ссылка.Товары Цикл
        ОбластьСтрока.Параметры.Заполнить(СтрокаТЧ);
        ТабДок.Вывести(ОбластьСтрока);
    КонецЦикла;
    Возврат ТабДок;
КонецФункции
Параметры.Заполнить() (Fill) copies properties with matching names automatically — no need to set each parameter separately.
1C
// Модуль команды «Печать накладной» (параметр команды: ДокументСсылка.РасходТовара)
&НаКлиенте
Процедура ОбработкаКоманды(ПараметрКоманды, ПараметрыВыполненияКоманды)
    ТабДок = ПечатьНаСервере(ПараметрКоманды);
    ТабДок.Показать("Накладная");
КонецПроцедуры

&НаСервере
Функция ПечатьНаСервере(Ссылка)
    Возврат Документы.РасходТовара.ПечатнаяФорма(Ссылка);
КонецФункции
The form is prepared on the server and opened on screen on the client with Показать() (Show).

Key points

  • DCS: the schema answers “what data”, the settings answer “how to show it”.
  • Resources give group totals; users can change groupings and save variants themselves.
  • From code: КомпоновщикМакета → ПроцессорКомпоновки → ПроцессорВывода.
  • Print form = a Табличный документ template + named areas + parameters.
  • The form is built on the server and opened on the client with Показать().

Check yourself

10 questions. Every correct answer earns XP.

1 / 10
Where do you define the fields that are summed per group in a DCS report?