- 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
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.
ВЫБРАТЬ
Продажи.Склад КАК Склад,
Продажи.Товар КАК Товар,
Продажи.КоличествоОборот КАК Количество,
Продажи.СуммаОборот КАК Сумма
ИЗ
РегистрНакопления.Продажи.Обороты(&НачалоПериода, &КонецПериода, , ) КАК Продажи&НачалоПериода and &КонецПериода automatically become report parameters.- 1Create a report and a schema
Отчеты→Добавить, nameПродажиПоСкладам. ClickОткрыть схему компоновки данных(Open data composition schema) next toОсновная схема компоновки данныхand create a new schema. - 2Data 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. - 3Set 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. - 4Run 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.
Схема = Отчеты.ПродажиПоСкладам.ПолучитьМакет("ОсновнаяСхемаКомпоновкиДанных");
Настройки = Схема.НастройкиПоУмолчанию;
Настройки.ПараметрыДанных.УстановитьЗначениеПараметра("НачалоПериода", НачалоМесяца(ТекущаяДатаСеанса()));
Настройки.ПараметрыДанных.УстановитьЗначениеПараметра("КонецПериода", КонецМесяца(ТекущаяДатаСеанса()));
КомпоновщикМакета = Новый КомпоновщикМакетаКомпоновкиДанных;
МакетКомпоновки = КомпоновщикМакета.Выполнить(Схема, Настройки);
Процессор = Новый ПроцессорКомпоновкиДанных;
Процессор.Инициализировать(МакетКомпоновки);
ТабДок = Новый ТабличныйДокумент;
ПроцессорВывода = Новый ПроцессорВыводаРезультатаКомпоновкиДанныхВТабличныйДокумент;
ПроцессорВывода.УстановитьДокумент(ТабДок);
ПроцессорВывода.Вывести(Процессор);ТабличныйДокумент (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.
- 1Add a template
On the
Макетыtab ofРасходТовараclickДобавить, typeТабличный документ, nameНакладная(delivery note). - 2Name the areas
Select the header rows and name them
ШапкаviaТаблица › Имена › Назначить имя…(Table › Names › Assign name); name the product rowСтрока. - 3Set up parameters
In a cell's properties set
Заполнение(Fill type) =ПараметрandПараметр=Номер(orДата,Товар,Количество). Give the parameter the same name as the document attribute.
// Модуль менеджера документа РасходТовара
Функция ПечатнаяФорма(Ссылка) Экспорт
Макет = Документы.РасходТовара.ПолучитьМакет("Накладная");
ОбластьШапка = Макет.ПолучитьОбласть("Шапка");
ОбластьСтрока = Макет.ПолучитьОбласть("Строка");
ТабДок = Новый ТабличныйДокумент;
ОбластьШапка.Параметры.Заполнить(Ссылка); // Номер, Дата, Склад
ТабДок.Вывести(ОбластьШапка);
Для Каждого СтрокаТЧ Из Ссылка.Товары Цикл
ОбластьСтрока.Параметры.Заполнить(СтрокаТЧ);
ТабДок.Вывести(ОбластьСтрока);
КонецЦикла;
Возврат ТабДок;
КонецФункцииПараметры.Заполнить() (Fill) copies properties with matching names automatically — no need to set each parameter separately.// Модуль команды «Печать накладной» (параметр команды: ДокументСсылка.РасходТовара)
&НаКлиенте
Процедура ОбработкаКоманды(ПараметрКоманды, ПараметрыВыполненияКоманды)
ТабДок = ПечатьНаСервере(ПараметрКоманды);
ТабДок.Показать("Накладная");
КонецПроцедуры
&НаСервере
Функция ПечатьНаСервере(Ссылка)
Возврат Документы.РасходТовара.ПечатнаяФорма(Ссылка);
КонецФункцииПоказать() (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.