Return to Designer and open the Desktop common form.
Figure 6-48. Desktop common form
Click the Module tab. For now, the form module is empty.
Figure 6-49. Desktop Module tab
For each table (you have two) create a fill procedure. Start with the Balance table. According to project requirements, the table must show actual balance. Name the procedure FillBalance(). In the procedure, you need to get the actual balance from the Accounts register. Not to put too fine a point upon it (register methods and 1C:Enterprise script syntax), you can solve the task as follows:
Figure 6-50. FillBalance() procedure
The AccumulationRegisters.Accounts.Balance() method calls the Accounts accumulation register and retrieves the actual balance.
Balance.Load() method puts retrieved data into the Balance table.
To find out more about the methods you use, see the Syntax assistant, which is built into the 1C:Enterprise platform. Point to a method and press Ctrl+F1.
Type a similar script for the second table. Here you need to get turnovers from the Expenses register. Name it FillExpenses() as on the figure 6-51.
Figure 6-51. FillExpenses() procedure
Here the AccumulationRegisters.Expenses.Turnovers() method calls the Expenses accumulation register and retrieves turnovers by categories.
The Expenses.Load() method puts retrieved data into the Expenses table.
Only one step left to go: initiate execution of the procedures you have created. For this, use the predefined procedure that is executed when you open a form: OnOpen(). You do not need to type it, use a built-in mechanism instead. Click Procedures and functions (Ctrl+Alt+P).
Figure 6-52. Procedures and functions
By the way, this mechanism helps you find your custom procedures and functions too. In figure 6-52, you can see two of your procedures on the top.
In the opened list, find <OnOpen> and double-click it, or click it and then Go To.
Figure 6-53. Selecting <OnOpen>
In the procedure creation dialog, click Create on client and then click OK.
Figure 6-54. Variants of procedure creating
As a result, you have a new procedure that is executed when a user opens the form.
Figure 6-55. OnOpen() procedure
The only thing left to do is to add calls of the procedures that update the tables. You can just copy their names and do not forget to add semicolons (;) at the end of the lines.
You can also use another built-in mechanism. Start typing the name of the procedure and then press Ctrl+Space. In the list, move the cursor to the procedure or function and press Enter.
As a result, OnOpen() should contain calls of the update procedures, as in figure 6-56.
Figure 6-56. OnOpen() procedure
Start the application in 1C:Enterprise mode, confirm all changes, and check whether the procedures are executed correctly.
Figure 6-57. Filling the tables
Once you start the application, the balance table is filled. The turnover table is empty. Record one expense, for example, a dinner that cost you 3.
Create a new Expense document.
Figure 6-58. Creating a new Expense document
In the opened document fill Amount and proceed to Account.
Figure 6-59. Amount is filled, proceeding to Account
Consider that you paid in cash. Select Cash as an account. You can type it or click Select .
Figure 6-60. Selecting Account
When you click the Select button of the Purpose field, the application asks you to select the data type: Accounts or Categories. You are going to record an expense, so select Categories.
Figure 6-61. Selecting data type
Add a new item to the Expenses group. Name it Dinner. Then select it as a purpose in your document.
Figure 6-62. Purpose
If you want, fill Memo. Then click Post and close to make changes in the registers.
Figure 6-63. Posting the document
When you will return to the desktop, you will see that the turnover table is still empty.
Figure 6-64. Desktop
If you check the Expenses register (you can get to it through All functions), you see that it contains the record.
Figure 6-65. Expenses register
Is it a mistake? No. The point is that table updating is related to the OnOpen event, the tables are updated only when the desktop is opened. You did not reopen the form, you just returned to the opened form.
To activate table updating, you can restart the application in 1C:Enterprise mode, as well as close the desktop and open it again.
Figure 6-66. Closing the desktop
Figure 6-67. Opening the desktop
Now all data in the tables is actual. It may be considered that the tutorial task is completed.
However, asking a user to restart the application every time he or she wants to see actual financial indicators is too much. In addition, the application has only the most primitive features and register tables are available only through the system menu. The usability is awful. On the mobile device it makes even more inconveniences.
Spend a little more time to make your application user-friendly.