Options

codeunit for sum up the values of Purch inv line

Hi Expects,
I have to find the inv amount using Inv line that has been invoiced using the reciept lines.
Can some one help me with the codeunit optimization.

the dataitem i choosed was:
Expanded Data Type Data Source Name Include Caption
1 DataItem Purch. Rcpt. Header <Purch. Rcpt. Header> No
0 Column "Purch. Rcpt. Header"."Buy-from Vendor No." VendorNo No
0 Column "Purch. Rcpt. Header"."No." GrnNo No
0 Column "Purch. Rcpt. Header"."Order No." PoNo No
0 Column "Purch. Rcpt. Header"."Order Date" PoDate No
0 Column "Purch. Rcpt. Header"."Document Date" GrnDate No
1 DataItem Purch. Rcpt. Line <Purch. Rcpt. Line> No
0 Column "Purch. Rcpt. Line".Quantity PoQuantity No
0 Column "Purch. Rcpt. Line"."Direct Unit Cost" * "Purch. Rcpt. Line".Quantity Amount No
0 Column "Purch. Rcpt. Line"."Quantity Invoiced" QtyInv No
1 DataItem Purch. Inv. Header <Purch. Inv. Header> No
0 Column "Purch. Inv. Header"."No." InvoiceNo No
0 Column "Purch. Inv. Header".Amount InvoiceAmount No
1 DataItem G/L Entry <G/L Entry> No
0 Column "G/L Entry".Amount PaymentAmount No
0 Column "G/L Entry"."Posting Date" PaymentDate No
0 Column "G/L Entry"."Document No." paymentDocNo No


Codeunit for this is:


Purch. Inv. Header - OnPreDataItem()
IF "Purch. Inv. Header"."Order No." = '' THEN BEGIN
sumamt := 0;
"Purch. Inv. Line".SETRANGE("Purch. Inv. Line"."Receipt No.","Purch. Rcpt. Line"."Document No.");
IF NOT "Purch. Inv. Line".GET("Purch. Rcpt. Line"."Document No.") THEN BEGIN
IF "Purch. Inv. Line"."Receipt No." = "Purch. Rcpt. Line"."Document No." THEN REPEAT
sumamt := sumamt + "Purch. Inv. Line".Amount;
UNTIL "Purch. Inv. Line".NEXT = 0;
"Purch. Inv. Header".Amount := sumamt;
"Purch. Inv. Header".INSERT;
END;
END;

this shows an error as :

Microsoft Dynamics NAV

The Purch. Inv. Header does not exist. Identification fields and values: No.=''
OK

As i have to sum the values for showing the purchase tracker report I coulnt end up getting the result.
Thanks in advance.

Answers

  • Options
    A_l_e_xA_l_e_x Member Posts: 4
    I don't know what you want to do exactly, but i think following code should work:
    IF "Purch. Inv. Header"."Order No." = '' THEN BEGIN
      "Purch. Inv. Line".Reset; //?? needed?
      "Purch. Inv. Line".SETRANGE("Purch. Inv. Line"."Receipt No.","Purch. Rcpt. Line"."Document No.");
      "Purch. Inv. Line".setrange("Receipt No.", "Purch. Rcpt. Line"."Document No.");
      "Purch. Inv. Line".Calcsums(Amount);
      //Modify header ?? 
      "Purch. Inv. Header".Amount := "Purch. Inv. Line".Amount;
      "Purch. Inv. Header".Modify(False);
      //Or Insert, but primary key has to be different....
      //if new record => 
      //"Purch. Inv. Header".Init;
      //"Purch. Inv Header"."No." := 'No....';
      //"Purch. Inv. Header".Amount := "Purch. Inv. Line".Amount;
      //"Purch. Inv. Header".Insert(False);
    END;
    
Sign In or Register to comment.