Code Problem

mkpjsrmkpjsr 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
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

  • deprodepro Member Posts: 46
    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,
    Depro
  • ara3nara3n Member Posts: 9,256
    I suggest to use Charge Item instead and apply them to the posted document. .
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • BeliasBelias Member Posts: 2,998
    depro wrote:
    But you need to be careful with FINDFIRST function becouse it impact performance issue in SQL database.
    this is not true: take a look at online help to findifirst/findlast/findset instructions. In this case, a findfirst is the better choice.
    @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)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • ssinglassingla Member Posts: 2,973
    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.in
Sign In or Register to comment.