New field in Cust Ledg Entry and Item Ledg Entry

akmanakman Member Posts: 67
Hi. I added a new field in the Sales Line table. In this field I have a different line amount than the original line amount field. I want the sum of all the lines of this field to be copied to a new field in the Customer Ledger Entry Table after the posting.
I also need a boolean field in the sales line table to be copied to a new field in the item ledger entry table after the posting.
How can I do those? If someone could help me it would be really great.

Answers

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    These are adjustments in your posting process. These need to be changed.

    For a Navision developer this is a releatively easy job, for a enduser I would not recomend doing it yourself.

    Are you a developer?
  • akmanakman Member Posts: 67
    I'm trying to be.
    I haven't tried to change a codeunit yet. Can you help me with this?
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Sure. I asume you have legal access to a developers license.

    The changes need to be made in codeunit 12, 22 and 80.

    In codeunit 80 the salesheader is being processed into sales shipments, invoices and creditmemo's

    Also the journal postings are prepared here.

    the customer entry is prepared here
    // Post customer entry
        Window.UPDATE(4,1);
        GenJnlLine.INIT;
        GenJnlLine."Posting Date" := "Posting Date";
        GenJnlLine."Document Date" := "Document Date";
        GenJnlLine.Description := "Posting Description";
        GenJnlLine."Shortcut Dimension 1 Code" := "Shortcut Dimension 1 Code";
        GenJnlLine."Shortcut Dimension 2 Code" := "Shortcut Dimension 2 Code";
        GenJnlLine."Reason Code" := "Reason Code";
        GenJnlLine."Account Type" := GenJnlLine."Account Type"::Customer;
        GenJnlLine."Account No." := "Bill-to Customer No.";
        GenJnlLine."Document Type" := GenJnlLineDocType;
        GenJnlLine."Document No." := GenJnlLineDocNo;
        GenJnlLine."External Document No." := GenJnlLineExtDocNo;
        GenJnlLine."Currency Code" := "Currency Code";
        GenJnlLine.Amount := -TotalSalesLine."Amount Including VAT";
        GenJnlLine."Source Currency Code" := "Currency Code";
        GenJnlLine."Source Currency Amount" := -TotalSalesLine."Amount Including VAT";
        GenJnlLine."Amount (LCY)" := -TotalSalesLineLCY."Amount Including VAT";
        IF SalesHeader."Currency Code" = '' THEN
          GenJnlLine."Currency Factor" := 1
        ELSE
          GenJnlLine."Currency Factor" :=  SalesHeader."Currency Factor";
        GenJnlLine.Correction := Correction;
        GenJnlLine."Sales/Purch. (LCY)" := -TotalSalesLineLCY.Amount;
        GenJnlLine."Profit (LCY)" := -(TotalSalesLineLCY.Amount - TotalSalesLineLCY."Unit Cost (LCY)");
        GenJnlLine."Inv. Discount (LCY)" := -TotalSalesLineLCY."Inv. Discount Amount";
        GenJnlLine."Sell-to/Buy-from No." := "Sell-to Customer No.";
        GenJnlLine."Salespers./Purch. Code" := "Salesperson Code";
        GenJnlLine."System-Created Entry" := TRUE;
        GenJnlLine."On Hold" := "On Hold";
        GenJnlLine."Applies-to Doc. Type" := "Applies-to Doc. Type";
        GenJnlLine."Applies-to Doc. No." := "Applies-to Doc. No.";
        GenJnlLine."Applies-to ID" := "Applies-to ID";
        GenJnlLine."Allow Application" := "Bal. Account No." = '';
        GenJnlLine."Due Date" := "Due Date";
        GenJnlLine."Payment Terms Code" := "Payment Terms Code";
        GenJnlLine."Pmt. Discount Date" := "Pmt. Discount Date";
        GenJnlLine."Payment Discount %" := "Payment Discount %";
        GenJnlLine."Source Type" := GenJnlLine."Source Type"::Customer;
        GenJnlLine."Source No." := "Bill-to Customer No.";
        GenJnlLine."Source Code" := SrcCode;
        GenJnlLine."Posting No. Series" := "Posting No. Series";
        GenJnlLine."Transaction Mode" := "Transaction Mode";
        GenJnlLine."Bank Account" := "Bank Account";
    
        TempJnlLineDim.DELETEALL;
        TempDocDim.RESET;
        TempDocDim.SETRANGE("Table ID",DATABASE::"Sales Header");
        DimMgt.CopyDocDimToJnlLineDim(TempDocDim,TempJnlLineDim);
        GenJnlPostLine.RunWithCheck(GenJnlLine,TempJnlLineDim);
    

    The Item entry here

    WITH SalesLine DO BEGIN
      ItemJnlLine.INIT;
      ItemJnlLine."Posting Date" := SalesHeader."Posting Date";
      ItemJnlLine."Document Date" := SalesHeader."Document Date";
      ItemJnlLine."Source Posting Group" := SalesHeader."Customer Posting Group";
      ItemJnlLine."Salespers./Purch. Code" := SalesHeader."Salesperson Code";
      ItemJnlLine."Country Code" := SalesHeader."VAT Country Code";
      ItemJnlLine."Reason Code" := SalesHeader."Reason Code";
      ItemJnlLine."Posting No. Series" := SalesHeader."Posting No. Series";
      ItemJnlLine."Item No." := "No.";
      ItemJnlLine.Description := Description;
      ItemJnlLine."Shortcut Dimension 1 Code" := "Shortcut Dimension 1 Code";
      ItemJnlLine."Shortcut Dimension 2 Code" := "Shortcut Dimension 2 Code";
      ItemJnlLine."Location Code" := "Location Code";
      ItemJnlLine."Bin Code" := "Bin Code";
      ItemJnlLine."Variant Code" := "Variant Code";
      ItemJnlLine."Inventory Posting Group" := "Posting Group";
      ItemJnlLine."Gen. Bus. Posting Group" := "Gen. Bus. Posting Group";
      ItemJnlLine."Gen. Prod. Posting Group" := "Gen. Prod. Posting Group";
      ItemJnlLine."Applies-to Entry" := "Appl.-to Item Entry";
      ItemJnlLine."Transaction Type" := "Transaction Type";
      ItemJnlLine."Transport Method" := "Transport Method";
      ItemJnlLine."Entry/Exit Point" := "Exit Point";
      ItemJnlLine.Area := Area;
      ItemJnlLine."Transaction Specification" := "Transaction Specification";
      ItemJnlLine."Drop Shipment" := "Drop Shipment";
      ItemJnlLine."Entry Type" := ItemJnlLine."Entry Type"::Sale;
      ItemJnlLine."Unit of Measure Code" := "Unit of Measure Code";
      ItemJnlLine."Qty. per Unit of Measure" := "Qty. per Unit of Measure";
      ItemJnlLine."Derived from Blanket Order" := "Blanket Order No." <> '';
      ItemJnlLine."Cross-Reference No." := "Cross-Reference No.";
      ItemJnlLine."Originally Ordered No." := "Originally Ordered No.";
      ItemJnlLine."Originally Ordered Var. Code" := "Originally Ordered Var. Code";
      ItemJnlLine."Out-of-Stock Substitution" := "Out-of-Stock Substitution";
      ItemJnlLine."Item Category Code" := "Item Category Code";
      ItemJnlLine.Nonstock := Nonstock;
      ItemJnlLine."Purchasing Code" := "Purchasing Code";
      ItemJnlLine."Product Group Code" := "Product Group Code";
      ItemJnlLine."Return Reason Code" := "Return Reason Code";
    
      ItemJnlLine."Planned Delivery Date" := "Planned Delivery Date";
      ItemJnlLine."Order Date" := SalesHeader."Order Date";
    
      ItemJnlLine."Serial No." := TrackingSpecification."Serial No.";
      ItemJnlLine."Lot No." := TrackingSpecification."Lot No.";
    

    You can add some new fields to the journal line tables 81 and 83 to copy your new data into the posting routines.

    When you have done that you can start modifying the posting routines.

    Just give a reply when you are ready for that.
  • akmanakman Member Posts: 67
    Thanks you for your quick reply!
    I have added the fields.
    One field from the sales line table must go to the customer ledger entry table (the sum of this field), and another field from the sales line must go to the item ledger entry table. The first field is decimal and the second is boolean.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    OK, if you added the fields to the journal lines and the entries and changed the code in codeunit 80 you can proceed to change codeunit 12 and 22. These codeunits create the customer enties and the item entries.

    In codeunit 12 look for this function
    PostCust()
    WITH GenJnlLine DO BEGIN
      IF Cust."No." <> "Account No." THEN
        Cust.GET("Account No.");
      Cust.TESTFIELD(Blocked,FALSE);
    
      IF "Posting Group" = '' THEN BEGIN
        Cust.TESTFIELD("Customer Posting Group");
        "Posting Group" := Cust."Customer Posting Group";
      END;
      CustPostingGr.GET("Posting Group");
      CustPostingGr.TESTFIELD("Receivables Account");
    
      DtldCustLedgEntry.LOCKTABLE;
      CustLedgEntry.LOCKTABLE;
    
      CustLedgEntry.INIT;
      CustLedgEntry."Customer No." := "Account No.";
      CustLedgEntry."Posting Date" := "Posting Date";
      CustLedgEntry."Document Date" := "Document Date";
      CustLedgEntry."Document Type" := "Document Type";
      CustLedgEntry."Document No." := "Document No.";
      CustLedgEntry."External Document No." := "External Document No.";
      CustLedgEntry.Description := Description;
      ...
    

    You can add your new field here

    In codeunit 22 look for this code
    InitItemLedgEntry(VAR ItemLedgEntry : Record "Item Ledger Entry")
    ItemLedgEntryNo := ItemLedgEntryNo + 1;
    
    WITH ItemJnlLine DO BEGIN
      ItemLedgEntry.INIT;
      ItemLedgEntry."Entry No." := ItemLedgEntryNo;
      ItemLedgEntry."Item No." := "Item No.";
      ItemLedgEntry."Posting Date" := "Posting Date";
      ItemLedgEntry."Document Date" := "Document Date";
      ItemLedgEntry."Entry Type" := "Entry Type";
      ItemLedgEntry."Source No." := "Source No.";
      ItemLedgEntry."Document No." := "Document No.";
      ItemLedgEntry."Transfer Order No." := "Transfer Order No.";
      ItemLedgEntry."External Document No." := "External Document No.";
      ItemLedgEntry.Description := Description;
      ItemLedgEntry."Location Code" := "Location Code";
      ItemLedgEntry."Applies-to Entry" := "Applies-to Entry";
      ItemLedgEntry."Source Type" := "Source Type";
      ItemLedgEntry."Transaction Type" := "Transaction Type";
      ItemLedgEntry."Transport Method" := "Transport Method";
      ItemLedgEntry."Country Code" := "Country Code";
      ItemLedgEntry."Entry/Exit Point" := "Entry/Exit Point";
      ItemLedgEntry.Area := Area;
      ItemLedgEntry."Transaction Specification" := "Transaction Specification";
      ItemLedgEntry."Drop Shipment" := "Drop Shipment";
      ItemLedgEntry."No. Series" := "Posting No. Series";
    

    Add your new field here.
  • akmanakman Member Posts: 67
    Thank you very much!
Sign In or Register to comment.