How to set up smartphones and PCs. Informational portal
  • home
  • OS
  • 1c parameters of the external printing plate. Output of printed forms with a request for data in the "Print documents" form from the BSP "Print" subsystem

1c parameters of the external printing plate. Output of printed forms with a request for data in the "Print documents" form from the BSP "Print" subsystem

Everybody has seen more than once how, in typical configurations based on BSP (Library of Standard Subsystems), printed forms built on the basis of a Tabular Document are displayed in a special "PrintDocuments" form. This form is a part of the "Print" subsystem from the BSP. When developing your printing forms, sometimes it is necessary to ask the user for additional data necessary for printing. This raises the question of how, in this case, to display the printable in the "Print Document" form. In this article I will consider how to implement the output of a printable to the mentioned form from the "Print" subsystem, if we want to request additional data from the user before outputting a printable. Two cases will be considered here: when the print form is implemented using the "Additional reports and processing" subsystem and when the print form is added to the configuration in the configurator mode, i.e. changes are made to the typical configuration.

The "PrintDocuments" form provides some additional functions when working with printable forms, such as:

  • button to print to the printer, directly in the form;
  • indication of the number of copies, printing form;
  • editing the generated printing plate;
  • the ability to save a printed form in various data formats (Excel, Word, PDF, etc.);
  • sending a printed form by e-mail;
  • convenient work with a set of documents.

This form is now used by 1C in all standard configurations for the output of printed forms of documents and directory elements. And of course, when developing our printing forms, in order not to go beyond the accepted practice, we should also display our printing forms using the provided tools.

When using standard methods of adding printable forms, the "Print" subsystem will do everything for us and display the printable as it should. For instance:

  1. When adding a print command to a document using the "Print" subsystem, we need to describe the print command in the AddPrintCommands procedure, indicating the print manager in which the Print procedure is implemented;
  2. When creating Additional processing, we need, in the processing object module in the ExternalProcessing Information function, to describe the command with the use type Call the server method and immediately implement the Print procedure, which in a certain way implements the call to the formation of the printable.

In such cases, as I have already said, the printing subsystem will output the printed form that we have formed by itself, as needed. Such methods imply the direct formation of the printing plate, i.e. transferred objects for printing to the print procedure, formed a spreadsheet document and displayed it on the screen.

But what if, before starting the formation of a spreadsheet document, you need to request some data from the user? Those. we need to show the form. In this case, the standard order of forming the printing form is violated and we need to think about how to transfer our printing form to the "PrintDocuments" form.

In this case, two situations are possible:

  1. When a printable is created with a configuration change;
  2. When a printable is created without changing the configuration, i.e. using the "Additional reports and processing" subsystem.

We create a printable by adding it through the configurator.

The first variation. Through the creation of processing with the team.

This option provides for adding processing directly to the Metadata Objects:

Consider a variant when we need to implement a printable form for a specific object, for example, a catalog item. To do this, we need to work in four processing locations:

  1. Create a command that will call the form of our printable;
  2. Create the form itself;
  3. Create a printable layout;
  4. Make changes to the processing manager module.

Create a team

We indicate in the properties of the command:

  • The group where we want the team to be displayed in the form;
  • The type of the parameter is just that reference or document, the printable of which we are making;
  • The parameter use mode is Multiple. To be able to display printable forms, at once by several elements selected in the list.

In the command module, open the processing form by transferring its selected directory elements for which it is necessary to generate printable forms. Let's not be clever here and slightly correct the typical code that is substituted by the platform in the command processing procedure:

& OnClient ProcedureCommandProcessing (CommandParameter, CommandParameters) // Insert the contents of the handler. FormParameters = New Structure ("PrintData", CommandParameter); OpenForm ("Processing.Printable.Form", Form Parameters, Command Execution Parameters.Source, Command Execution Parameters.Unique, Command Execution Parameters.Window, Command Execution Parameters.NavigationLink); End of Procedure

The procedure parameter Command Parameter contains the elements we have selected for printing.

Create a shape

Let's add a form to the processing, create a form attribute of the List of Values ​​type and the requisites for us to enter additional parameters for the printable:

DataForPrint - the ValuesList type;

Number of Lines - Number type.

My example will be purely demo, so let's conditionally define what my goal is to display in the printed line the representation of the selected element and the number of lines that we will select as an additional parameter on the form.

Go to the form module and write the following code:

& AtServer Procedure AtCreateAtServer (Cancel, StandardProcessing) PrintData.LoadValues ​​(Parameters.PrintData); EndProcedure & OnClient Procedure Print (Command) Print ControlClient.RunPrintCommand ("Process.PrintForm", // Print Manager "PrintForm", // Identifier GetObjectsTo Print (), // PrintObjectsThisObject, from which )); // Print parameters - arbitrary parameters to be passed to the print manager EndProcedure & OnServer Function GetObjectsForPrint () Array = DataForPrint.UploadValues ​​(); Return Array; EndFunction & OnServer Function GetPrintParameters () PrintParameters = New Structure; Print Parameters.Insert ("Form Header", "Print Form"); // One of the parameters for the "Print document" form. // Indicates the title of the printable output form. // Here we add our parameters, which we want to additionally transfer to the print manager. Print Parameters.Insert ("Number of Lines", Number of Lines); Return Print Options; EndFunction

We define the procedure AtCreateAtServer and in it we read from the parameter that we passed from the command when opening the form, the list of objects for which we need to generate a printable.

We create a Print command in the form and write its handler, in which we call the function of the common module Print ControlClient.RunCommandPrint, we set the necessary parameters of this function, namely:

  • Print manager - the name of the object in the manager module, which is defined by the Print function, which forms our printable;
  • Identifier - the identifier of the printable that you want to print. By this identifier, in the Print function of the manager module, we will select which printable form needs to be printed;
  • Objects of printing are directly those objects for which printing forms are formed;
  • Form owner;
  • Print parameters - here we form and transfer the structure with print parameters, immediately we transfer our additional parameters that we requested from the user in the processing form.

Actually, by calling the ExecutePrintCommand function from the processing form, we solve our problem of outputting the printable to the "PrintDocuments" form. Further, the "Print" subsystem will perform standard actions and bring the execution to the Print procedure, which we must define in the module of our processing manager.

Create a printable layout

Making changes to the processing manager module

From this moment on, we carry out standard actions for the development of printed forms using the "Print" subsystem from the BSP.

Add the following code to the manager module:

Procedure Print (ArrayObjects, Print Parameters, Print Form Collection, Print Objects, Output Parameters) Export If Print Control.You need to Print Layout (Print Form Collection, "Print Form") Then Print Control. ArrayObjects, Print Parameters), "Processing. Print Form. PF_MXL_ Print Form",); EndIf; EndProcedure & OnServer Function PrintLayout (ArrayObjects, PrintParameters) TabularDocument = New TabularDocument; // Create a spreadsheet document /////////////////////////////////////////// //////////////////////////////////////////////// ///////////////// // REDEFINED PART OF THE MODULE // // Here we form our printable Layout = Get Layout ("PF_MXL_PrintedForm"); For each Object From ArrayObjects Loop AreaHeat = Layout.GetArea ("Header"); RegionObject = Layout.GetScope ("Object"); TabularDocument.Display (AreaHap); RegionObject.Parameters ["Object"] = Object; TabularDocument.Display (ScopeObject); For N = 1 By PrintParameters ["Number of Lines"] Loop AreaRow = Layout.GetArea ("Line"); RegionString.Parameters ["String"] = Сч; TabularDocument.Output (AreaString); End of Cycle; TabularDocumentOfferHorizontalPageSplitter (); End of Cycle; // REDEFINED PART OF THE MODULE /////////////////////////////////////////// //////////////////////////////////////////////// ///////////////// Return Tabular Document; // Return the spreadsheet document EndFunction

Second option. Through the implementation of the print command.

This option is very similar to the first one in terms of printing. Its difference is in the way of creating a command that will be displayed in the interface and start our printing.

In this case, when defining the print command, we also use the "Print" subsystem from the BSP. Instead of defining a command to open processing in the processing itself, we need to go to the manager module of the object to which we want to add a printable, and set a description of the print command in the procedure Add Print Commands (Print Commands):

Procedure AddPrint Commands (Print Commands) Export Print Command = Print Commands.Add (); PrintCommand.ID = "PrintForm"; PrintCommand.Presentation = НСтр ("ru =" Printing plate printing ""); PrintCommand.Processor = "CommonModulePrintingForm.ProcessingPrintCommandPrintForm"; Print Command.Order = 100; End of Procedure

Here we add to all forms of the directory (I remind you that we are working with the directory counterparties), a print command with the name "Print Form". And here is the main point that must be taken into account. You can add two kinds of commands to a form:

1. Calling the Print procedure from the manager module;

2. Calling the client method.

This is exactly the call to the client method we need. The client method will allow us to call the processing form, in which we will ask the user for the data we need before printing.

To implement such a call, when defining a command, set a Handler for it (see the code above). The command handler receives a string containing the path to the client function, i.e. the path to the Export function of the shared module on the client. It is this function that will be called when we click on the print command that we add to the forms.

As you understand, for this to work, you need to create this very CommonModule and define the Export function. Therefore, we write the following code in our common module:

Function ProcessPrintModelCommandPrint (PrintParameters) Export // Paste the contents of the handler. Form Parameters = New Structure ("Print Data", Print Parameters.Print Objects); OpenForm ("Processing. Printing Form. Form", Form Parameters); EndFunction

Here we do the same as in the first implementation, open the printable form, only now our Print Data will be contained in the parameter passed to the Print Parameters function, or rather, in its Print Objects field.

After we have opened the processing form, all actions are similar to the first option.

The implementation of this option can be found in typical configurations, in the mechanisms associated with the seal of consent to the processing of personal data.

We create additional processing.

What if this is not our configuration and it is supported? And in general we do not want to go into the configuration and edit it?

In this case, we need to use the "Additional reports and processing" subsystem from the BSP.

With this solution, we need to write code in only two places, and they are all in our future additional processing:

1. Module of the processing object;

2. Module of the processing form.

In the object module, write the following code:

//////////////////////////////////////////////// ////////////////////////////// // SOFTWARE INTERFACE # ProgramInterface area // Returns information about external processing. ExternalProcessingData Function () Export RegistrationParameters = AdditionalReports ANDProcessing.ExternalProcessingInformation ("2.2.2.1"); Registration Parameters.View = AdditionalReportsAndProcessingClientServer.Processing ViewPrintableForm (); Registration Parameters. Version = "1.0"; NewCommand = RegistrationParameters.Command.Add (); NewCommand.Presentation = НСтр ("ru =" External printable with preliminary data request ""); NewCommand.Identifier = "ExternalPrintable"; NewCommand.Usage = AdditionalReportAndProcessingClientServer.CommandTypeFormOpening (); NewCommand.ShowNotification = True; NewCommand.Modifier = "PrintMXL"; Return Registration Parameters; EndFunction Procedure Print (PrintData, Print Form Collection, Print Objects, Output Parameters) Export If Print Control.You need to Print Layout (Print Form Collection, "External Print Form") Then Print Control. ),); EndIf; EndProcedure & AtServer Function Print Layout (PrintData) PrintParameters = PrintData.Value; // Receives print parameters from the first element of the ListValues ​​ArrayObjects = PrintData.Copy (); // Copy the list of ArrayObjects values. Delete (0); // Delete the lines of the copied element containing the Print Parameters TabularDocument = New TabularDocument; // Create a spreadsheet document /////////////////////////////////////////// //////////////////////////////////////////////// ///////////////// // REDEFINED PART OF THE MODULE // // Here we form our printable Layout = Get Layout ("Layout"); For each Object From ArrayObjects Loop AreaHeat = Layout.GetArea ("Header"); RegionObject = Layout.GetScope ("Object"); TabularDocument.Display (AreaHap); RegionObject.Parameters ["Object"] = Object; TabularDocument.Display (ScopeObject); For N = 1 By PrintParameters ["Number of Lines"] Loop AreaRow = Layout.GetArea ("Line"); RegionString.Parameters ["String"] = Сч; TabularDocument.Output (AreaString); End of Cycle; TabularDocumentOfferHorizontalPageSplitter (); End of Cycle; // REDEFINED PART OF THE MODULE /////////////////////////////////////////// //////////////////////////////////////////////// ///////////////// Return Tabular Document; // Return the spreadsheet document EndFunction # EndScope

There are two functions and one procedure.

The standard function for Additional processing is ExternalProcessing Information (), without it the system will not understand that this is additional processing. The important point here is to indicate that the command implemented in this processing has the type Opening a form... Those. we will open the form as we need it. What follows is the definition of the Print procedure and the function that directly forms our spreadsheet document.

Here you need to pay attention to the fact that the print command in this case should contain only 4 parameters, and not 5 as it is with the usual definition of the print command in the manager module. In this case, there is no parameter for transferring Print Parameters. Therefore, we will come to be creative in order to transfer, in addition to the objects themselves, for which the printable is formed, but also the parameters that we request from the user in the form.

And so we have defined additional processing, the command from which will open the processing form. Therefore, the next step is to create a processing form.

In this form, we need to create three props to store the values ​​that we will need in the future. Let's call these details as follows:

CommandID - type String

Assignment Objects - ValueList type

In the module of this form, write the following code:

& AtServer Procedure OnCreateAtServer (Failure, StandardProcessing) // When creating on the server, remember the standard parameters passed by the AdditionalReportsAndProcessing subsystem AdditionalProcessingRef = Parameters.AdditionalProcessingRef; CommandID = Parameters.CommandID; AssignmentObjects.LoadValues ​​(Parameters.AssignmentObjects); EndProcedure & OnClient Procedure Print (Command) // Get the uniqueness key of the opened form. UniqueKey = String (New UniqueIdentifier); // Defining and filling in standard parameters for the general form PrintDocumentsOpen Parameters = New Structure ("Data Source, Source Parameters"); OpenParameters.DataSource = AdditionalProcessingRef; OpenParameters.SourceParameters = New Structure ("CommandIdentifier, AssignmentObjects"); OpenParameters.SourceParameters.CommandIdentifier = CommandIdentifier; // Objects for printing and parameters entered in the form for processing // we will pass through the parameter Source Parameters.ObjectsDesignsOpen Parameters.ParametersSource.ObjectsDesigns = GetDesignObjectsAndPrintParameters (); OpenForm ("GeneralForm.PrintingDocuments", Opening Parameters, Form Owner, Unique Key); EndProcedure & OnServer Function GetAssignObjectsAndPrintParameters () PrintData = AssignmentObjects.Copy (); //////////////////////////////////////////////// //////////////////////////////////////////////// //////////// // REDEFINED PART OF THE MODULE // // Here we create a Print Parameters structure and fill it with those parameters // that need to be passed to the print function Print Parameters = New Structure; Print Parameters.Insert ("Number of Lines", Number of Lines); PrintData.Insert (0, PrintParameters); // REDEFINED PART OF THE MODULE /////////////////////////////////////////// //////////////////////////////////////////////// ///////////////// Return Print Data; EndFunction

In the procedure AtCreateAtServer, we fill in our three props, which we have created to store the parameters passed to the processing form.

Next, we define the handler for the print button on the form. In this handler, we ourselves need to open the "Print documents" form, for this we need to prepare the Open Parameters of a certain structure. In this structure, at least two fields must be defined:

Source Parameters, which include CommandID and ObjectsPurpose:

Command Identifier - also saved when created on the server, this is the identifier of the command that called the form of our processing. Therefore, to the identifier, we will define what we need to print in the Print procedure in the object module.

ObjectsDesigns - it is in this field that we need to pass an array of objects for which the printable is formed, as well as the parameters requested from the user in the form.

How I define the targets can be seen in the function GetObjectsAssignments andPrint Options... Here I am copying our destinations from the form props, in place of the array element with index 0, I am pasting our print parameters.

In the future, the array defined in this way will be transferred from the "Print documents" form, as the first parameter of the Print procedure of the object module, which we defined earlier.

If we return to the definition of the module of the processing object and look at the PrintMoot function, in the first three lines of the function you can see how I extract our parameters and objects from the data passed to the Print procedure and then work with them.

Such manipulations with the TargetObjects parameter are conditioned by the specifics of the call to the Print object module procedure. You can track how parameters are passed and function calls are made by opening the PrintDocuments form module.

Result.

As a result of such manipulations, we will receive three commands on the form, from which we want to display the printable:

The numbering of the commands corresponds to the order of the implementation options.

All of these commands will perform the same actions:

Show request form for additional parameters

Output the generated printed forms in the "Print documents" form... This is exactly what we wanted:

P.S. As templates, for the implementation of my printing forms with a request for additional parameters, I unload both processing, which are involved in all three methods of forming a printing plate.

This article will tell you in detail how to create a printable for a beginner who does not know much about 1C 8. For example, let's take one of the most common configurations 1C 8 - Accounting 2.0... Creation of a printable 1C stages of writing:

  • Creation of a file of an external printing plate;
  • Creation of a printable layout;
  • Writing program code for displaying printable data on the screen;
  • Creation of parameters for auto-registration of a printable;
  • Connecting an external printing plate to the base 1C Enterprise.

Creation of a printing form 1C. Formulation of the problem

We are required in the configuration Accounting 2.0 create a printable for the document Receipt of goods and services... Print the following data in the header of the printable:

  • Organization;
  • Counterparty;
  • Counterparty agreement;
  • Date of admission.

In the form of a table, display the data of the tabular section Products document. The table should include the following columns:

  • Nomenclature;
  • Quantity;
  • Price;
  • Sum;
  • And also the price of the item for the current date (according to the type of prices from the document).

External processing file

Let's move on to solving the problem. First, let's open 1C 8 in the mode Configurator... It is in this mode that all developments on the 1C 8 platform are carried out. Now we need to create an external processing file. To do this, click on the menu File -> New ... or by the new file icon.

In the window that opens, select the item External processing.

Further in the field Name you must enter the name of the external treatment. In our case, let's call it simply: "Printing Form", the synonym field will be filled in automatically. Note that in the field Name, external processing, you should write the name without spaces and punctuation marks.

Add a props for external processing LinkOnObject and select for him type DocumentLink.Arrival of GoodsServices... To do this, in the 1C external processing metadata tree, select the item Requisites and press the button Add(green plus button). On the right side of the screen, the property window will open, in the field Name write - ReferenceObject. V field A type press the button with three dots.

In the type tree, open the branch DocumentLink, and find there the item Receipt of Goods / Services, put a tick in front of it and click OK.

Let's save the external processing file to the hard disk, for this we use the menu File -> Save, pictogram Save(blue diskette), or a keyboard shortcut Ctrl + S... Let's name the saved file "Printing Form".

Creation of a layout of a printing plate

Let's start creating a layout of the 1C printing form. The layout serves as a template for the output of the printable, so if you want your printable to look good, you should pay attention to it.

In the external processing metadata tree, add a new layout; in the layout designer window, we will not change anything and click the button Ready.

In the new layout that opens, create several areas necessary for the output of the printable. All the areas of the layout we need will be horizontal, so to create a new area, select the required number of layout lines and go to the menu Table -> Names -> Assign Name or use the keyboard shortcut Ctrl + Shift + N, then enter the name of the area in the box. When creating a layout area, do not be afraid to make a mistake with the number of lines, you can always add or remove them. To delete a line of the 1C layout, select the required line and select the item in the context menu Delete... To add a new line to the layout, select any line in the layout and select the item Push apart.

Adding a layout header

First of all, let's create an area Cap, the data for the header of the printable will be displayed there. For this area, we need seven lines of the layout. Select them and, as I wrote above, press the keyboard shortcut Ctrl + Shift + N, in field Name write "Hat" and press the button OK.

Let's fill the layout area with the data we need. Usually no printable is complete without a heading, so let's create one in our header as well. Since in the title, in addition to the name of the printing form, we will also display the number of the document from which it was printed, we will set the title text in the layout with a parameter. A layout parameter is a specially designated layout cell, into which various data can be displayed using the built-in 1C 8 language. The heading should be displayed on the entire width of the printing form, so let's determine how many layout cells will be enough for us to print on the standard landscape orientation of the sheet.

Usually thirteen or fourteen layout cells are enough, select them in the first line of the area Cap and combine into one cell ( Context Menu -> Merge). After that, double-click on the resulting large cell and write the name of the parameter, in our case "TitleText". In order for the entered text to become a full-fledged parameter, right-click on the cell and select the item Properties... On a bookmark Layout find the field Filling and choose the value Parameter... Parameters in the 1C layout are indicated by brackets "<>».

The title of the printable should stand out among other text, so once again select the cell and, using the icons on the layout formatting panel, set the text alignment Center and font size 14.

After the title text, we will display in the area Cap data on the organization, counterparty, contract of the counterparty and the date of receipt of the goods. Since all this data is also taken from the document, we will also arrange them with parameters. In addition, before each parameter, an explanatory text should be written so that the user can easily understand where the organization is, and where is the counterparty, etc. All these actions are similar to creating a header, so I will not dwell on them in detail, I will give only a picture with what should be the result.

The figure shows how the layout options differ from normal text.

Adding a layout table header

The last thing we need to create in this area of ​​the layout is the table header, into which the data of the tabular section will be displayed. Products... The columns required for the table were described in the "Problem Statement" section. We will also create the table header using the concatenation of cells and writing text (column names). Select the borders of the table header using the tool Frame which is located in the layout formatting pane.

Adding a table to the layout

Let's create another area in the layout - Data... It will display the data table of the tabular section Products. We only need one line of layout for this area. To display all the rows of the tabular section in a printable form, we will fill in and display this area as many times as necessary. Columns in the area Data must match the columns of the table header, so filling it out is easy. The only difference is in the area Data we need parameters, not just text. Also note that, by default, numeric parameters are right-aligned and text parameters are left-aligned. To select columns, you also need to use the tool Frame.

Adding a footer to the layout

The last layout area we need is Basement... It will display totals by quantity and amount. Creation is similar to area creation Data, but in addition, the totals should be highlighted in bold.

As a result, you should get the following layout:

Creation of a printing form 1C. Programming

Let's start programming - this is the most important stage in creating a printing plate. First of all, we will go to the module of the object of the external printing form, this is where we will program. To do this, in the main window of external processing, click Actions -> Open Object Module.

In the module of the object of the external printing form, you need to create an export function Seal().

Function Print () Export End Functions

Please note that this function is required for external printing plates in configurations using a regular application. We will write all the subsequent program code necessary for displaying the printable inside this function.

Initializing Basic Variables

Let's create a variable TabDoc, which will contain the spreadsheet document - it is he who is the printable in which we will display the filled areas of the layout.

TabDoc = new TabularDocument;

Into a variable Layout we get the layout of the printing plate we have created. To do this, we use the built-in function Get Layout (<ИмяМакета>).

Layout = Get Layout ("Layout");

We will get all the areas of the layout into variables. For this we use the layout method GetArea (<ИмяОбласти>) .

Header Area = Layout.GetArea ("Header"); DataScope = Layout.GetScope ("Data"); AreaFooter = Layout.GetArea ("Footer");

Output of the printable header into a spreadsheet document

All required variables are initialized. Let's start filling and displaying the layout areas in a spreadsheet document. First of all, let's fill in the header of the printable, for this we need to pass in the parameter TextHeader, which we created in the layout, the text we need. To fill in the parameter values, the layout area has a special collection, which is called so - Parameters. From which through "." you can get any parameter. In the title text we will transfer the text: "Printable", as well as the document number.

AreaHaps.Parameters.TextHeader = "Printable" + ReferenceOnObject.Number;

Fill in the rest of the header parameters in a similar way, we get all the necessary values ​​for them from the props ReferenceObject, which contains a link to the document being printed.

AreaHaps.Parameters.Organization = ReferenceObject.Organization; AreaHaps.Parameters.Contractor = ReferenceObject.Contractor; AreaHaps.Parameters.ArrivalDate = ReferenceObject.Date; AreaHaps.Parameters.Contractor Agreement = ReferenceObject.Contractor Agreement;

All header parameters are filled in, we will display it in the spreadsheet document we created, for this we use the method Output (<Область>) .

TabDok.Display (AreaHap);

Writing a request for a printable handicap

Let's fill in and output the area Data... Creating a 1C printable also means writing a request, we need it to get the data of the tabular section Products and prices Nomenclatures for the current date we will use Inquiry... The 1C 8 query language is similar to SQL, or rather practically copies the capabilities of its SELECT operator, but the entire query is written in Russian. Therefore, if you are even remotely familiar with SQL, then you will easily understand the 1C 8 query language.

In this printed form, the request will be quite simple and many will say that it would be possible to do without it, but knowledge of the query language and the ability to use it correctly is one of the main skills of a 1C programmer. Queries allow using less resources to obtain the most complex data samples, and the query text is much easier to understand than in the program code written without using a query (or with minimal use of it). In addition, 1C 8 has a very good query designer that allows you to interactively collect a query from the required tables.

Let's create a variable that will contain the request.

Request = New Request;

We will compose the request text using the query constructor. First, let's write:

Request.Text = "";

Put the mouse cursor between the quotes, press the right mouse button. In the context menu that opens, select the item Query constructor, it will help us a lot in creating a 1C printing form. After that, the query designer window will open, it contains many tabs, but for our query only four are needed: "Tables and Fields", "Relationships", "Conditions", "Joins / Aliases".

For our query, we need two tables: the tabular section Products document Receipt of goods and services and a slice of the latest information register for the current date Item prices.

On the left side of the designer window, find the column Database... It contains a tree of all metadata objects, we will find the ones we need. To do this, open the branch Documentation and find the document Arrival of goods and services, open it and find the tabular section Products by dragging it to the query designer column Tables... You can drag and drop in three ways: by dragging and dropping, by double-clicking on the table, or by selecting it and pressing the ">" button. Let's open the branch Information Registers and find the table there PricesNomenclature.SliceLast, also drag it to the column Tables... These two tables are enough for our query.

Let's select the fields we need from the resulting tables. To do this, in the column Tables open the table and find the fields: Nomenclature, Amount, Price, Quantity and drag them to the third column of the constructor - Fields... Let's open the table , find the field Price and also drag it to Fields.

The structure of the tables and fields of our query is ready, now let's deal with the conditions. We need the data of the tabular section Products were taken not from all receipts, but only from the one that we print. To do this, we impose a condition on the table Arrival of goods... Let's go to the "Conditions" tab of the query designer. In a collumn Fields the tables we selected earlier are located, for the condition we need a field Link from the table Receipt of goods, services, goods, drag it to the Conditions window.

In 1C requests, you can use parameters, they are needed in order to transfer data to the request. For example, if we want to restrict the selection of documents to a specific document, then using a parameter, we can pass a link to this document to the request and use this parameter in the condition. This is exactly what we will do in our request.

After out the window Conditions we added a field Link, the query builder will itself create a parameter with the same name and place it after the "=" sign. This parameter can be renamed if desired. Parameters in the request text are marked with "&", but in this case you do not need to do this, since it is assumed that the second part of the condition contains a parameter, you just need to remember it. How to transfer a value to a 1C request parameter will be described below.

Since in the request we do not use a complete table of item prices, but a virtual one (a cut of the latter in this case), we need to set the conditions for the formation of this virtual table, in our case this is the cut date and a condition for the price type (prices must be selected that have a strictly defined price type - the one that is specified in the receipt document that we print).

To fill in the parameters of the virtual table, go to the tab Tables and fields the query constructor, in the column Tables select the table PricesNomenclatureSliceLast and press the button Virtual table parameters located at the top. In the window that opens, in the field Period you should set the parameter to which the date will be transmitted, on which the prices will be cut. In our case, this will be the current date (that is, today), therefore we will name the parameter "& CurrentDate". In the condition field we will write the conditions for the price type, we will also pass it in the parameter, which we will call "& TypePrice". The resulting condition will look like this (where Price Type- register measurement Item prices):

PriceType = & PriceType

The parameters of the virtual table are filled, press the button OK.

Now that we have limited the selection to only the document we need, we will create links between the query tables. If you do not do this, then the prices from the ItemNomenclatureSlicePrices table will not be linked to the item from the receipt. Let's go to the tab Connections query constructor. Create a link across the field Nomenclature between our two tables. To do this, press the button Add, in field Table 1 select the table Arrival of goods, and in the Table 2 field - PricesNomenclatureSliceLast. In the communication conditions, select the fields Nomenclature from both tables.

It should also be noted that in the query selection, we need to get all the rows from the tab part Products and prices only if there are any for the current date by the type of document prices. Thus, these tabs Products are required, but the price cut data is not. Therefore, in the links between these tables, it is necessary to use the so-called LEFT JOIN, and the left (or required) table will be Arrival of goods, and the right (or optional) PriceNomenclatureSliceLast. In order for the left join of the query tables to work as I described above, you must check the box Everything after the field Table 1.


The query is almost ready, there is only a little work left on the field aliases. Let's go to the bookmark Unions / Aliases and set an alias for the field PricesNomenclatureSliceLast.Price... The alias name will be - PriceToday, it is needed so that the names of the query selection fields and the names of the parameters in the layout of the printable are the same.

This completes the work in the query designer, press the OK button. After the constructor window closes, you will see that the line with the request text is filled and looks like this:

Zapros.Tekst = "SELECT | PostuplenieTovarovUslugTovary.Nomenklatura, | PostuplenieTovarovUslugTovary.Summa, | PostuplenieTovarovUslugTovary.Tsena, | PostuplenieTovarovUslugTovary.Kolichestvo, | TsenyNomenklaturySrezPoslednih.Tsena AS TsenaNaSegodnya | FROM | Dokument.PostuplenieTovarovUslug.Tovary AS PostuplenieTovarovUslugTovary | left join RegistrSvedeniy.TsenyNomenklatury.SrezPoslednih (| & CurrentDate, PriceType = &PriceType) AS PricesNomenclatureSliceLatest | ON Incoming GoodsServicesGoods.Nomenclature | = PricesNomenclaturesSliceLatest.Nomenclature | WHERE | Incoming GoodsServicesGoods.Link = & Link ";

Executing a request

Let's pass the necessary parameters to the request, for this we will use the request method SetParameter (<ИмяПараметра>,<Значение>). To get the current date, we will use the built-in function The current date(), it returns the date and time of the computer.

Let's execute a request to get a selection with the data we need. To do this, we first use the request method Execute () and then by the method Select().

Selection = Query.Run (). Select ();

Filling out the table of the printing form

As a result, in the variable Sample will contain a selection of query results, you can navigate through it using the method Next(), and to bypass it entirely, you need a loop Till... The construction will be as follows:

While Fetch.Next () Loop End of Loop;

It is in this loop that we will fill and display the layout area. Data... But first, let's initialize two variables of the numeric type. In them we will collect the totals for the quantity and amount that we need to bring to the area Basement.

TotalSum = 0; TotalQuantity = 0;

Inside the loop, we will fill the area Data data from the current selection element, into variables Total Amount and Total Quantity add the values ​​of the amount and quantity, and finally, display the area in the spreadsheet document using the method already familiar to us Output ()... Since the field names of our query completely coincide with the names of the scope parameters Data, then for filling we will use the built-in procedure FillPropertyValues ​​(<Приемник>, <Источник>), which copies the property values<Источника>in properties<Приемника>.

While Fetch.Next () Loop FillPropertyValues ​​(ScopeData.Parameters, Fetch); TotalSum = TotalSum + Sample.Sum; TotalQuantity = TotalQuantity + Sample.Quantity; TabDok.Display (ScopeData); End of Cycle;

Outputting the footer of a printing form to a spreadsheet document

It remains to fill and display the last area of ​​the layout - Basement... We have already prepared the data for filling, filling in and withdrawal is carried out according to the same scheme.

AreaBoard.Parameters.TotalQuantity = TotalQuantity; AreaBoard.Parameters.TotalSum = TotalSum; TabDok.Display (Area Basement);

The spreadsheet document is completely filled, it remains to display it on the screen so that the user can view the printable form and, if necessary, print it. But in typical 1C 8 configurations, the procedures of special modules are responsible for the output of external printing forms. Therefore, it is enough to return from the function Seal() completed spreadsheet document.

Return of TabDoc;

At this stage, the programming is over and the creation of the printing plate 1c is almost complete. Full function text Seal() I will not give it here, you can see it in the printable file, which can be downloaded at the bottom of the article.

Creation of a printing form 1C. Auto registration parameters

When connecting an external printing form to the base, the system does not automatically determine for which document or reference book the printing form is intended, it has to be selected manually. And if another person wrote the printed form, and you were only instructed to connect it, then the choice may become ambiguous. In order to avoid such problems, it is necessary to create a layout with auto-registration parameters in all external printable forms. If it is created and correctly formatted, the system automatically determines which document or reference book the printed form is intended for.

It is done as follows:

  • In external processing, we create a new layout. We call it "Autoregistration_Parameters" (it is important not to be mistaken!).
  • In the first cell of the layout, write Documentation.(or Reference books.) and the name of the document to which you want to connect the printable.

Connection to the base of an external printing plate

  • Run 1C 8 in the mode Company;
  • Go to the menu Service -> Additional reports and processing -> Additional external printable forms;
  • Click the button Add;
  • In the window that opens, click the icon Replace external processing file;
  • If you have created auto-registration parameters, then we agree to use them;
  • If you have not created auto-registration parameters, then in the tabular section Affiliation of the printing plate add the required document or directory;
  • Push the button OK.

After that, the external printable will be available in the menu Seal document Receipt of goods and services. The creation of the 1C printing form can be considered complete at this point.

Consider writing the simplest printable in 1s 8.1 - 8.2 on the example of the configuration Enterprise Accounting 2.0... Let's say you want to write an external printable for a document: display the basic data of the document, as well as from the tabular section Products: nomenclature, price, quantity and amount.

You can download the resulting example by.

In the configurator 1C Enterprises 8 create external processing ( File-> New-> External Processing), set the name, create the requisite required for the external printable ReferenceObject with type DocumentLink.Realization of GoodsServices.

Creation of a layout of a printing plate

Add new layout, leave the layout type Spreadsheet document... We create three areas on the layout: Hat, Data and Basement... This can be done by highlighting the required number of lines and clicking the menu Table-> Names-> Assign Name (Ctrl + Shift + N).

After that, we begin to place the text and parameters in the areas. We will display in the header name of the printing form, document number and organization, and also draw the borders of the table header and write the names of the columns. When creating a parameter in the properties of a cell, on the layout tab, set the property Filling in value Parameter.

In the area of Data create parameters for displaying the rows of the tabular section ( Nomenclature, price etc.), and in the area Basement for totals by quantity and amount.

Programming

Let's go to the module of the printable object Actions-> Open Object Module.

Let's create an export function, which is required for printable forms. Seal().

Function Print () Export EndFunction

In the function, create a variable for spreadsheet document, in which the printed form will be displayed, we get layout and layout areas.

TabDoc = new TabularDocument; Layout = Get Layout ("Layout"); Header Area = Layout.GetArea ("Header"); DataScope = Layout.GetScope ("Data"); AreaFooter = Layout.GetArea ("Footer");

Fill in the parameters hats and display it in spreadsheet document.

Captions.Parameters.TextHeader = + ReferenceObject.Number; AreaHaps.Parameters.Organization = ReferenceObject.Organization; TabDok.Display (Caps area);

To get the rows of the tabular section Products we use the request.

Request = new request; Request.SetParameter ("Link", LinkOnObject); Request.Text = "SELECT | Sale of goods, services, goods, nomenclature, | Sale of goods, services, goods, amount, | Sale of goods, services, goods, price, | Sales of goods, services, goods, quantity| FROM | Document.Realization ofGoodsServices.Goods AS Sale ofGoodsServicesGoods| WHERE | Implementation of GoodsServicesGoods.Link = & Link ";

Pass the props to the request parameter ReferenceObject to indicate in the condition WHERE that we only need the data of the document from which we display the printable. To get a fetch of a query, we first execute it and then fetch the rows.

Selection = Query.Run (). Select ();

Next, in the loop, fill in the parameters of the area Data for each line of the document selection and display them in spreadsheet document... Also, in the cycle, we calculate the total values quantity and sums... We will not fill in each parameter separately, but use the procedure FillPropertyValues ​​((<Приемник>, <Источник>) from global context, it copies the property values <Источника> in properties <Приемника> ... Matching is done by property names. You can read more about this in syntax assistant 1C Enterprise 8.

TotalSum = 0; TotalQuantity = 0; While Fetch.Next () Loop FillPropertyValues ​​(ScopeData.Parameters, Fetch); TotalSum = TotalSum + Sample.Sum; TotalQuantity = TotalQuantity + Sample.Quantity; TabDok.Display (ScopeData); End of Cycle;

Fill in and display the area Basement.

AreaBoard.Parameters.TotalQuantity = TotalQuantity; AreaBoard.Parameters.TotalSum = TotalSum; TabDok.Display (Area Basement);

Returning the filled spreadsheet document from the function Seal().

return of TabDoc;

If you are using one of the typical configurations, then after returning the spreadsheet document 1C will display the printed form itself. You can also use the spreadsheet document method for output Show().

5. Connecting a printable to a document

V typical configurations 1C 8 there is a directory for registering external printable forms ExternalProcessing... To connect, go to the menu in enterprise mode Service-> Additional reports and processing-> Additional external printable forms.

Add a new element of the directory, load the printable from disk and select the type of document.

Now in the doc Sale of goods and services a new printable will appear.

Auto registration of printable

In order to avoid having to manually select the type of document when connecting the printing form, you can configure auto registration... To do this, add a new layout and name it AutoRegister_Parameters(only this way) and in its first cell we write Documentation.<Наименование документа> (or Reference books.<Наименование справочника> ).

Now, when connecting a printable, we will be prompted to use auto-registration parameters.

Top related articles