Code Problem

mkpjsr
Member Posts: 587
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
Now, i am writing the code to find the processing charge of the item, code is:
But i am getting value 0 for FinalRate.
what is wrong with the code, can anybody guide me......
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......
0
Answers
-
Hi mkpjsr,
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:PurchInvLine.RESET; TranRcptLine.SETRANGE(TranRcptLine."Item No.","Value Entry"."Item No."); IF TranRcptLine.FINDFIRST THEN PurchInvHeader.SETRANGE(PurchInvHeader."Transfer Receipt No.",TranRcptLine."Document No.");
But you need to be careful with FINDFIRST function becouse it impact performance issue in SQL database.
regards,
Depro0 -
I suggest to use Charge Item instead and apply them to the posted document. .0
-
depro wrote:But you need to be careful with FINDFIRST function becouse it impact performance issue in SQL database.
@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)0 -
ara3n wrote:I suggest to use Charge Item instead and apply them to the posted document. .
The suggestion mentioned will be the best because it will rule out any modifications to the system.CA Sandeep Singla
http://ssdynamics.co.in0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions