Utilities for printed forms

Utilities for printed forms (injectors) are designed to process data output to the template, including performing intermediate calculations and formatting.

The printed form for which the injector will be used must be defined in deploy.json, for example:

"registry": {
    "globals": {
        "di": {
            "pmListToDocx": {
                "module": "modules/registry/export/listToDocx",
                "initMethod": "init",
                "initLevel": 0,
                "options": {
                    "tplDir": "applications/khv-ticket-discount/export/list",
                    "log": "ion://sysLog",
                }
                ...
            }
            ...
        }
        ...
    }
    ...
}

In this case, the listToDocx module is used, so a list of all objects of a certain class will be uploaded to the printed form.

For each such class in tplDir, create a folder with the name of the namespace, into which then place a file with the name of the class you need to unload from this namespace, for example:

...\applications\khv-ticket-discount\export\list\khv-ticket-discount\ticketYear.docx

Thus, a list of all objects of the ticketYear@khv-ticket-discount class will be uploaded to the document.

The utility itself is a .js script connected to the application in the module format in deploy.json, for example:

"registry": {
    "globals": {
        "di": {
            "weekTicketStatsInjector": {
                "module": "applications/khv-ticket-discount/export/injectors/monthTicketStats",
                "options": {
                "dataRepo": "ion://dataRepo"
                }
                ...
            }
            ...
        }
        ...
    }
    ...
}

The .js file here is located at the “module” path.

After connecting, the utility must be included in the options of the printed form:

"registry": {
    "globals": {
        "di": {
            "pmListToDocx": {
                "module": "modules/registry/export/listToDocx",
                "initMethod": "init",
                "initLevel": 0,
                "options": {
                    "tplDir": "applications/khv-ticket-discount/export/list",
                    "log": "ion://sysLog",
                    "injectors": [
                        "ion://monthTicketStatsInjector"
                    ]
                }
                ...
            }
            ...
        }
        ...
    }
    ...
}

The injector script is compiled in the module format, provided that it must contain the this.inject function, into the parameter of which the object with the list of objects of the class specified earlier will be transferred to, for an example from this reference:

ticketYear@khv-ticket-discount

Example of the monthTicketStats.js file:

function monthTicketStatsInjector() {
  this.inject = function (value) {
    if (value && value.className === "ticketYear") {
      let expValueList = [];
      const periodBegF = value.periodBegF;
      const periodEndF = value.periodEndF;
      const areaF = value.areaF;
      let i = 0;
      value.list.forEach((vectorparams) => {
        if (vectorparams.person.area.code === areaF && vectorparams.dateAirGo >= periodBegF && vectorparams.dateAirGo <= periodEndF && ((vectorparams.state !== "canceled") && (vectorparams.state !== "returned"))) {
          expValueList[i++] = vectorparams;
        }
      });
      value.list = expValueList;
    }
    return value;
  };
}

module.exports = monthTicketStatsInjector;

Example of an export configuration for this form in deploy.js:

"registry": {
    "globals": {
        "di": {
            "export": {
                "options": {
                    "configs": {
                        "ticketYear@khv-ticket-discount": {
                            "pmListToDocx": {
                                "type": "list",
                                "caption": "Ежемесячный отчет",
                                "mimeType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
                                "extension": "docx",
                                "params": {
                                    "periodBegF": {
                                    "caption": "Период с",
                                    "type": "date"
                                },
                                "periodEndF": {
                                    "caption": "по",
                                    "type": "date"
                                },
                                "areaF": {
                                    "caption": "Район",
                                    "type": "reference",
                                    "className": "area@khv-ticket-discount"
                                }
                            },
                            "preprocessor": "ion://pmListToDocx",
                            "eagerLoading": [
                                "person",
                                "person.documents",
                                "person.area",
                                "route.pointDeparture",
                                "route.pointArrival",
                                "route.flight"
                            ],
                            "fileNameTemplate": "Ежемесячный отчет"
                        }
                    }
                }
            }
            ...
        }
        ...
    }
    ...
}

Here you should pay attention to the params field, you can specify the parameters available in the export form in the application web service in it . The following types of parameters are possible:

“string” - a string for entering text,

“date” - interactive calendar where you can select a required date

“reference” - a reference to the class, in this case, the export window will display a drop-down list of all objects of the class.

The passed parameters will be available in the script through the this.inject function parameter.