Using a ref type in a Tabular section

Understanding basics of 1C:Enterprise platform. To start working with 1C:Enterprise platform visit Getting started page

#1
People who like this:0Yes/0No
Active user
Rating: 5
Joined: Jun 4, 2013
Company:

hi ... I have a question

I'm trying to make a document that have a tabular section in it ... in that tabular section I took a ref from an attribute in a catalog ... but i can't use that ref in numeric calculation.

for example in the catalog the user enter a price for an item ... then in the document I want to take that price as a Ref then multiply it
with a quantity that the user enter it in the document

is there any way to convert that Ref to number ?!

and thanks in advance

 
#2
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

The common practice is to store prices in periodical information register. Where one of dimensions is the item (CatalogRef type), the resource is price (Numeric type) and period allows to store prices that are changed with time usually.
In that case to calculate the amount you will need to get the slice last with filter by item for date of your document and receive price. Then it is better to put that price to a column in your tabular section because a document stores the deal and price may be different from ones that are set in the information register (if there was applied a personal discount, for example). At this step you already have a price, now you can multiply it by the quantity and get the amount.

 
#3
People who like this:0Yes/0No
Active user
Rating: 3
Joined: Nov 1, 2011
Company:

As I understand you are trying to store prices in catalogue? Looks like bad decision.
Use tabular part attribute of numeric type.

 
#4
People who like this:0Yes/0No
Active user
Rating: 5
Joined: Jun 4, 2013
Company:

Alexey Alexandrovich,
My manager want it this way :).... i can't change it

 
#5
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

Explain the data structure then.

 
#6
People who like this:0Yes/0No
Active user
Rating: 5
Joined: Jun 4, 2013
Company:

sorry I'm a beginner but here is what I did :

I created a catalog called CatalogItem that contain specifications of items (description, price, price unit, taxes.....)

Then I created a document called (invoice) with a various attributes and a tubular called InvoiceItems in the tubular the first filed is items (you can choose the items you've entered in the item catalog from it, and its type is CatalogRef.CatalogItem ) then there is price, price unit, quantity, tax and total.

My manager wants that when you choose the items, the price,price unite and tax will change automatically based on items entry before.

To do that i changed the type of each one of them to (CatalogRef.CatalogItem).

Then i created a form and changed the data path of each one of them to (for example: Object.InvoiceItems.Items.Tax).

Then in the form in the items field i used a event handler <onchange> to multiply the price with quantity to get the total like this:

Code
&AtClient
Procedure InvoiceItemsQuantityOnChange(Item)
   ItemTables=Items.InvoiceItems.CurrentData;
   ItemTables.total =ItemTables.price * ItemTables.quantity; 
EndProcedure

But as you know it failed.

So that's it .. if you can help I'll be so thankful

 
#7
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

You should keep types of fields corresponding to what they are intended for.
Price, taxes and total should be Number.
Price unit may be a reference to Currencies catalog (you have not mentioned its type in your description)
Item should be a reference to Items catalog.

Next, the filling. You should understand where the data to be filled is stored. If it is not in the information register, as I suggested, then the simplier way is to store it in Items catalog, but in that case you have only current values.
If you store price in Items catalog as an attribute, you can get this value by using a dot. Note, that it is fine to get only 1 value, if you need to get more, you must use a query as a dot operator in this case performs a query, so when the item is changed you can set the price from the item, that was set.

The last thing is that you should perform this calculation on server. The OnChange handler calls a procedure with &AtServer directive. To call a server (requests to the database can be performed on server only), you need to add a procedure with &AtServer directive and call it from the client one:

Code
&AtClient
Procedure ItemsItemOnChange(Item)
   ItemsItemOnChangeAtServer();
EndProcedure

&AtServer
Procedure ItemsItemOnChangeAtServer()
   Row = Object.Items[Items.Items.CurrentRow];
   If Row.Quantity = 0 Then
      Row.Quantity = 1;
   EndIf;
   Row.Price = Row.Item.Price;
   Row.Total = Row.Price * Row.Quantity;
EndProcedure


I have attached an example for you.

P.S.: It would be better to rename CatalogItem catalog name into Items and InvoiceItems tabular section into Items too.

Download 1Cv8.dt (14.39 KB)
 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.