How tos

How to enable the purchases of Resources in Dynamics NAV?

Author
Karen Higgins
Date
18/06/2008
Size
201,65 KB
Downloads
2340
Rating
43211
Popularity
Downloaded 5 times in the last two weeks
It is a common request for users to be able to purchase Resources. This How To details the steps in the modification. With this modification, entries with type Resource will post to the G/L Entry table, the Resource Ledger Entry table, and, if applicable, the Job Ledger Entry table.

Add resource as an option for the Type field.
Change No. field properties to set the table relation to resource if the type is resource.
Do this for tables listed below:
Table 39 Purchase Line
Table 121 Purch. Rcpt. Line
Table 123 Purch. Inv. Line
Table 125 Purch. Cr. Memo Line
Table 6651 Return Shipment Line

Modify the Table 39, No., OnValidate trigger.
Add RES as a local variable, type Record, Resource, then modify/insert the below code:
//  ERROR(Text003);
BEGIN
  RES.GET("No.");
  RES.TESTFIELD(Blocked,FALSE);
  RES.TESTFIELD("Gen. Prod. Posting Group");
  Description := RES.Name;
  VALIDATE("Unit Cost",RES."Unit Cost");
  VALIDATE("Direct Unit Cost",RES."Direct Unit Cost");
  "Gen. Prod. Posting Group" := RES."Gen. Prod. Posting Group";
  "VAT Prod. Posting Group" := RES."VAT Prod. Posting Group";
  "Tax Group Code" := RES."Tax Group Code";
  "Allow Item Charge Assignment" := FALSE;
  "Unit Price (LCY)" := RES."Unit Price";
  "Unit of Measure Code" := RES."Base Unit of Measure";
 END;
If using Jobs, modify the Table 39, Job No., OnValidate trigger per below:
//IF NOT (Type IN [Type::Item,Type::”G/L Account”]) THEN
IF NOT (Type IN [Type::Item,Type::”G/L Account”,Type::Resource]) THEN
Tables 203 & 207
Add Vendor as an option after Customer for the field Source Type.
Add Purchase as an option after Sale for the field Entry Type.
Change Source No. field properties to set the table relation to Vendor, if Source Type is vendor.

Codeunit 90
Add ResJnlLine as a Local Variable, type Record, table Res. Journal Line. Add ResJnlPostLine as a Local Variable, type Codeunit, Res. Jnl.-Post Line. Then modify/insert the code below.
//3: ERROR(Text015);
PurchLine.Type::Resource:

  IF PurchLine."Qty. to Invoice" <> 0 THEN BEGIN
    ResJnlLine.INIT;
    ResJnlLine."Posting Date" := "Posting Date";
    ResJnlLine."Document Date" := "Document Date";
    ResJnlLine."Reason Code" := "Reason Code";
    ResJnlLine."Resource No." := PurchLine."No.";
    ResJnlLine.Description := PurchLine.Description;
    ResJnlLine."Source Type" := ResJnlLine."Source Type"::Vendor;
    ResJnlLine."Source No." := PurchLine."Buy-from Vendor No.";
    ResJnlLine."Job No." := PurchLine."Job No.";
    ResJnlLine."Unit of Measure Code" := PurchLine."Unit of Measure Code";
    ResJnlLine."Shortcut Dimension 1 Code" := PurchLine."Shortcut Dimension 1 Code";
    ResJnlLine."Shortcut Dimension 2 Code" := PurchLine."Shortcut Dimension 2 Code";
    ResJnlLine."Gen. Bus. Posting Group" := PurchLine."Gen. Bus. Posting Group";
    ResJnlLine."Gen. Prod. Posting Group" := PurchLine."Gen. Prod. Posting Group";
    ResJnlLine."Entry Type" := ResJnlLine."Entry Type"::Purchase;
    ResJnlLine."Document No." := GenJnlLineDocNo;
    ResJnlLine."External Document No." := GenJnlLineExtDocNo;
    ResJnlLine.Quantity := PurchLine."Qty. to Invoice";
    ResJnlLine."Unit Cost" := PurchLine."Unit Cost (LCY)";
    ResJnlLine."Total Cost" := PurchLine."Unit Cost (LCY)" * ResJnlLine.Quantity;
    ResJnlLine."Unit Price" := PurchLine.Amount/PurchLine.Quantity;
    ResJnlLine."Total Price" := PurchLine.Amount;
    ResJnlLine."Source Code" := SrcCode;
    ResJnlLine.Chargeable := TRUE;
    ResJnlLine."Posting No. Series" := "Posting No. Series";
    ResJnlLine."Qty. per Unit of Measure" := PurchLine."Qty. per Unit of Measure";
    TempJnlLineDim.DELETEALL;
    TempDocDim.RESET;
    TempDocDim.SETRANGE("Table ID",DATABASE::"Purchase Line");
    TempDocDim.SETRANGE("Line No.",PurchLine."Line No.");
    DimMgt.CopyDocDimToJnlLineDim(TempDocDim,TempJnlLineDim);
    ResJnlPostLine.RunWithCheck(ResJnlLine,TempJnlLineDim);
  END;
Test your modifications.
Download code

Screenshots