Вы не вошли - Войти
< назад

Пример отчета Остатки товаров

function run() {
       var date = context.inParams.Date;
       var lines = context.inParams.Lines || [];
       var linesList = context.inParams.LinesList || [];
       var showGoodGroups = context.inParams.ShowGoodGroups;
       var goods = context.inParams.Goods || [];
       var subdivs = context.inParams.Subdivs || [];
       var groupsCount = context.inParams.GroupsCount;
       
       var groupFields = [];
       linesList.forEach((line) => {
              switch(line)         switch(line) {
                     case              case 'Склады':
                            if                     if (lines.indexOf(line) >= 0) {
                                   groupFields.push(new                            groupFields.push(new TreeGroup('Склад'));
                            }                     }
                            break;                     break;
                     case              case 'Товары':
                            if                     if (lines.indexOf(line) >= 0) {
                                   groupFields.push(new                            groupFields.push(new TreeGroup({ fieldName: 'Товар', addGroups: showGoodGroups }));
                            }                     } else if (showGoodGroups) {
                                   groupFields.push(new                            groupFields.push(new TreeGroup({fieldName: 'Товар', addGroups: true, onlyGroups: true, maxGroupLevel: groupsCount }));
                            }                     }
                            break;                     break;
              }
       });
       
       var criteria = createRestQuery("Остатки товаров")
              .sum('Количество')
              .sum('Сумма')
              .onDate(date);
       
       groupFields.forEach((group) => {
              criteria.select(group.fieldName);
       });
       
       if (goods.length > 0)
              criteria.whereIn('Товар', getAllCodes('Товары', goods));

       if (subdivs.length > 0)
              criteria.whereIn('Склад', getAllCodes('Склады', subdivs));
       
       var result = context.repository.executeQuery(criteria);
       if (groupFields.length > 0)
              result = result.buildTree(groupFields, ['Количество', 'Сумма']);
       
       var rep = createReport('ОстаткиТоваров.tcrp');
       rep.addSection("Шапка");
       rep.setParameter("Период", "на: " + toString(date));
       if (subdivs.length > 0)
              rep.setParameter("Склады", "По складам: " + getDictNames("Склады", subdivs));
       if (goods.length > 0)
              rep.setParameter("Товары", "По товарам: " + getDictNames("Товары", goods));
       rep.addSection("Таблица");
       
       result.processLevels((r, level, group) =>
       {
              if (group == null)
                     return;

              var property = r.getProperty(group.fieldName);
              rep.addSection(level.toString());
              var typeName = property.field.objName;
              rep.setParameter("Type", typeName);
              rep.setParameter("Code", r[group.fieldName]);
              rep.setParameter("Код", r[group.fieldName]);
              rep.setParameter("Наим", r.getString(group.fieldName));
              if (typeName == "Товары")
                     rep.setParameter("Единица", property.getString("Единица измерения"));
              var qnt = r.Количество;
              var amount = r.Сумма;

              rep.setParameter("Кол", qnt);
              rep.setParameter("Цена", qnt != 0 ? amount / qnt : 0);
              rep.setParameter("Сум", amount);
       });
       
       result.toBegin();
       result.read();
       rep.addSection("Подвал");
       rep.setParameter("Кол", result.Количество);
       rep.setParameter("Сум", result.Сумма);
}