Hello everyone !
I am a begginer in 1C (totally) and I was wondering if there is someone capable to help me in a task that I need to do.Unfortunately as I said before I am a total beginner and my problem is something like this : I need to automatically check the quantity ( in stock )of products that are receipt by a document and this must happen when I post a document that expends them.So my question is simple "How to do that ?"
I have:
Catalog objects : "Products","Warehouses","Clients"
Document objects : "ReceiptOfGoods" and "ExpenseOfGoods" both creating movements in an Accumulation register "BalanceOfMaterials".
I need to get that done soon and thats why I am searching for help everywhere ( I study 1C at home with one book !) I would really be in debt to whoever post me an answer !
IN CONCLUSION : I would fall of my chair if someone posts me the CODE ... Remember that I am a complete novice here in 1C and I need that "check" in the comming week !
Thank you beforehand !
~Martin
Products in stock problem
Re: Products in stock problem
It's difficult to write code without information about your document and accumulation register specification.
You should check the quantity in document Posting event. And if you have no quantity you should set Cancel parameter to True to prevent data storing.
You should create Query object with SQL-like request to document Left join AccumulationRegister.BalanceOfMaterials.Balance(...). Then check records in the cycle through Query.Execute().Choose(). Please set the parameter DocumentRef through: Query.SetParameter("DocumentRef", ThisObject.Ref);
The query may be like this (please use Query Builder dialog to construct your own correctly):
SELECT
Doc.Product AS Product,
Doc.Warehouse AS Warehouse,
Doc.Quantity AS DocumentQuantity,
Balance.QuantityBalance AS BalanceQuantity,
FROM
Document.ReceiptOfGoods.Products AS Doc
LEFT JOIN
AccumulationRegister.BalanceOfMaterials.Balance(,
Product IN (
SELECT DISTINCT
Product
FROM
Document.ReceiptOfGoods.Products
WHERE Ref = &DocumentRef)
) AS Balance
ON
Doc.Product = Balance.Product
AND Doc.Warehouse = Balance.Warehouse
WHERE
Doc.Ref = &DocumentRef
You should check the quantity in document Posting event. And if you have no quantity you should set Cancel parameter to True to prevent data storing.
You should create Query object with SQL-like request to document Left join AccumulationRegister.BalanceOfMaterials.Balance(...). Then check records in the cycle through Query.Execute().Choose(). Please set the parameter DocumentRef through: Query.SetParameter("DocumentRef", ThisObject.Ref);
The query may be like this (please use Query Builder dialog to construct your own correctly):
SELECT
Doc.Product AS Product,
Doc.Warehouse AS Warehouse,
Doc.Quantity AS DocumentQuantity,
Balance.QuantityBalance AS BalanceQuantity,
FROM
Document.ReceiptOfGoods.Products AS Doc
LEFT JOIN
AccumulationRegister.BalanceOfMaterials.Balance(,
Product IN (
SELECT DISTINCT
Product
FROM
Document.ReceiptOfGoods.Products
WHERE Ref = &DocumentRef)
) AS Balance
ON
Doc.Product = Balance.Product
AND Doc.Warehouse = Balance.Warehouse
WHERE
Doc.Ref = &DocumentRef
-
- Posts: 4
- Joined: Thu Sep 03, 2009 2:52 pm
Re: Products in stock problem
Thanks Elisy !
You were very helpfull despite my lack of description ! I will try to fix that problem and get the work done.I have some time and now I am confident enough ( after I saw your comment )
Thank you again and keep up the good work !
EDIT: I understand the CODE that you've posted me.I've tried it but it's hard for me to get certain things ... Could you explain me the part with the example Query code? I don't know what you mean by
Balance.QuantityBalance AS BalanceQuantity, ... and this "Documents.ReceiptOfGoods.Products AS Doc" ( when I write "Documents.ReceiptOfGoods" out fom the query text , there is no such thing as "Products" after the dot )
Furthermore : my "Product" is a part of the tabular part of the document "ReceiptOfGoods" (the tabular part is called "Products")The "Product" being received is a row from the tabular part and not an Attribute.
My point is that I dont know how to SELECT that field from the tabular part which represents the "Product" that is being received !
~ I'm sorry for being soooo annoying and a waste of time ...
You were very helpfull despite my lack of description ! I will try to fix that problem and get the work done.I have some time and now I am confident enough ( after I saw your comment )
Thank you again and keep up the good work !
EDIT: I understand the CODE that you've posted me.I've tried it but it's hard for me to get certain things ... Could you explain me the part with the example Query code? I don't know what you mean by
Balance.QuantityBalance AS BalanceQuantity, ... and this "Documents.ReceiptOfGoods.Products AS Doc" ( when I write "Documents.ReceiptOfGoods" out fom the query text , there is no such thing as "Products" after the dot )
Furthermore : my "Product" is a part of the tabular part of the document "ReceiptOfGoods" (the tabular part is called "Products")The "Product" being received is a row from the tabular part and not an Attribute.
My point is that I dont know how to SELECT that field from the tabular part which represents the "Product" that is being received !
~ I'm sorry for being soooo annoying and a waste of time ...
Re: Products in stock problem
Let's clarify how you try to use Query expression because 1C Editor has no IntellySense feature for Queries and it cannot show you members after dot. Your program should be like this:
Query = New Query();
Query.Text =
"SELECT
| Doc.Product AS Product,
| Doc.Quantity AS DocumentQuantity
| FROM
| Document.ReceiptOfGoods.Products AS Doc
| WHERE
| Doc.Ref = &DocumentRef";
Query.SetParameter("DocumentRef", ThisObject.Ref);
DataReader = Query.Execute().Choose();
This code uses simplified query to view the problem. It selects all Product and Quantity from tabular part Products of ReceiptOfGoods document. If it runs correctly you can add SELECT with balance. The best way is to do this is right clicking on the "SELECT ..." expression and choose Query Builder...
Query = New Query();
Query.Text =
"SELECT
| Doc.Product AS Product,
| Doc.Quantity AS DocumentQuantity
| FROM
| Document.ReceiptOfGoods.Products AS Doc
| WHERE
| Doc.Ref = &DocumentRef";
Query.SetParameter("DocumentRef", ThisObject.Ref);
DataReader = Query.Execute().Choose();
This code uses simplified query to view the problem. It selects all Product and Quantity from tabular part Products of ReceiptOfGoods document. If it runs correctly you can add SELECT with balance. The best way is to do this is right clicking on the "SELECT ..." expression and choose Query Builder...
-
- Posts: 4
- Joined: Thu Sep 03, 2009 2:52 pm
Re: Products in stock problem
Thank you ! I've got it running now ! It works and I added several features to ensure correct output after incorrect user input Thank you again and I'm seeing forward to write comments and eventually ask far more speciffic questions in the future.
Return to “User input and data storing”
Who is online
Users browsing this forum: No registered users and 0 guests