Hi all,
I am getting problem in finding the Unit Cost of items for Inventory Valuation.
Actually I want to find out the Unit Cost of the items, that is calculated as follows:
Unit Price= Purchase price + Processing Charge.
After purchasing any item(Raw material), it is send to the job worker for further processing and when it comes back (in the form of a component) the job worker charges the processing charge.
In navision, it has been implemented like this:
1. Raw Material is purchased and posted to navision using
Purchase Invoice
2. Raw Material is sent to Job worker using
Transfer Order
3. Component comes back from job worker using Transfer Order (Document No. is recorded)
4. Bill for the processing charge is raised using "
Purchase Invoice" G/L Account against the "
Document No." of the "
Transfer Order" through which the component comes back.
In this way a link has been created between "
transfer Order" and "
Purchase invoice".
As we can see there is no item information on the Purchase Invoice, so we have to look to transfer receipt Line for item information.
I am customizing the "Inventory Valuation" (1001) report.
so, I have written the following code under OnAfterGetRecord trigger of "value Entry" data item to find the "Purchase price" of the raw material, and its working fine
PurchInvLine.RESET;
PurchInvLine.SETRANGE("No.","Value Entry"."Item No.");
PurchInvLine.SETFILTER(Quantity,'>0');
IF PurchInvLine.FINDLAST THEN
Rate := PurchInvLine."Unit Cost";
Now, i am writing the code to find the processing charge of the item, code is:
Globals used are:
PurchInvLine->record->Purch. Inv. Line
TranRcptLine->record-> transfer Receipt Line
PurchInvHeader->record->Purch. Inv. Header
Rate & FinalRate->Decimal
ProcessingCharge->Decimal
PurchInvLine.RESET;
TranRcptLine.SETRANGE(TranRcptLine."Item No.","Value Entry"."Item No.");
PurchInvHeader.SETRANGE(PurchInvHeader."Transfer Receipt No.",TranRcptLine."Document No.");
PurchInvLine.SETRANGE(PurchInvLine."Document No.",PurchInvHeader."No.");
PurchInvLine.SETFILTER(Quantity,'>0');
IF PurchInvLine.FIND THEN
ProcessingCharge:=PurchInvLine."Unit Cost";
FinalRate :=Rate+ ProcessingCharge;
But i am getting value 0 for FinalRate.
what is wrong with the code, can anybody guide me......
Answers
Use debugger to see if there is any Value in fields you use for filtering.
For example for variable TranRcptLine you use only function setrange, and this function only filter this table.
Then you use reference to field TranRcptLine."Document No." which hasn`t any value.
You need to use function like: GET, FINDFIRST etc to retrive values form your records.
Something like:
But you need to be careful with FINDFIRST function becouse it impact performance issue in SQL database.
regards,
Depro
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
@mkpjsr: i noticed that you used a plain "FIND" instruction. Why?you won't find anything because the default value is '=' (again, take a look at online help for FIND instruction)
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
The suggestion mentioned will be the best because it will rule out any modifications to the system.
http://ssdynamics.co.in