Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Under review by Community Managers

Under review

Thank you for your post! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

item tracking lines

Posted on by 2
Hi all, I create a custom card page and post it. when i post it without applying item tracking line then item tracking line then item ledger entries are creating but if i applying item tracking line then item ledger entries are not creating , here is the code of report that runs on posting action button. I want that item ledger entries should be created in both cases whether i applied  item tracking line fo item on line part or not.
Report 70000 "RGP Post"
{
    DefaultLayout = RDLC;
    RDLCLayout = './Layouts/RGPPost.rdlc';
 
    dataset
    {
    }
    requestpage
    {
        layout
        {
        }
        actions
        {
        }
    }
    labels
    {
    }
    trigger OnPreReport()
    begin
        Error('You can not directly run this report because it is batch Job Process');
    end;
 
    var
        Selection: Integer;
        Ship: Boolean;
        Receipt: Boolean;
        RGPLine: Record "RGP Line";
        LastEntryNo: Integer;
        RGPHeader: Record "RGP Header";
        LastAppEntryNo: Integer;
        ShipNo: Code[20];
        RecvNo: Code[20];
        NoSeriesMgt: Codeunit NoSeriesManagement;
        RcptRemQty: Decimal;
        AllowPostingFrom: Date;
        AllowPostingTo: Date;
        UserSetup: Record "User Setup";
        GLSetup: Record "General Ledger Setup";
        ItemJournalLine: Record "Item Journal Line";
        gvlineno: Integer;
        "ItemJnl.Post": Codeunit "Item Jnl.-Post";
        Issue: Boolean;
        itemqty: Decimal;
        itemrec: Record "Item Ledger Entry";
        ResponsibilityCenter: Record "Responsibility Center";
        UserMgt: Codeunit "User Setup Management";
        InvSetup: Record "Inventory Setup";
        ItemJnlPostBatch: Codeunit "Item Jnl.-Post Batch";
         
        RGPLine2: Record "RGP Line";
        DocNoForMessage: Code[20];
        // Text000: label '&Ship,&Receive';
        Text000: label '&Ship';
        //Text001: label '&Receive,&Ship'
        Text001: label '&Receive';
        Text002: label 'There is nothing to post';
        Text004: label 'You can''t change Description because quantity already shipped.';
        Text005: label 'is not within your range of allowed posting dates';
        Text006: label '&Receive,&Issue';
        RGPLineUpdate: Record "RGP Line";
        RGPQty: Decimal;
        RGPReceivedQty: Decimal;
        RGPHeadUpdate: Record "RGP Header";
        RGPShippedQty: Decimal;
        PostedRGPHeader: Record "Posted RGP Header";
        ILE: Record "Item Ledger Entry";
        PostedRGPHeader1: Record "Posted RGP Header";
 
    procedure PostRGP(var RGPHead: Record "RGP Header")
    begin
        InvSetup.Get;
        "CheckHeader/LineDimensions"();
        /*   if RGPHead."Posting Date" <> WorkDate then
              Error('Posting Date should be equal to WORKDATE'); */
        RGPHeader.Copy(RGPHead);
        If RGPHeader."Document Type" = RGPHeader."Document Type"::"RGP Outbound" then;
        if DateNotAllowed(RGPHeader."Posting Date") then RGPHeader.FieldError("Posting Date", Text005);
        case RGPHeader."Document Type" of
            RGPHeader."document type"::"RGP Outbound":
                begin
                    Selection := StrMenu(Text000, 1);
                    if Selection = 0 then exit;
                    Ship := Selection in [1, 1];
                    Receipt := Selection in [2, 2];
                    PostRGPOutbound();
                    //>>001
                    if Ship then Message('RGP Shipment %1 Posted successfully', DocNoForMessage);
                    if Receipt then Message('RGP Receipt %1 Posted Successfully', DocNoForMessage);
                    // UpdateHeaderforReceipt;
                    //<<001
                end;
            RGPHeader."document type"::"RGP Inbound":
                begin
                    Selection := StrMenu(Text001, 1);
                    if Selection = 0 then exit;
                    //Ship := Selection in [2, 2];
                    Receipt := Selection in [1, 1];
                    PostRGPInbound();
                    //>>001
                    if Ship then Message('RGP Shipment %1 Posted successfully', DocNoForMessage);
                    if Receipt then Message('RGP Receipt %1 Posted Successfully', DocNoForMessage);
                    //  UpdateHeaderforReceipt;
                    //<<001
                end;
            RGPHeader."document type"::"NRGP Outbound":
                begin
                    if not Confirm('Do you want to post NRGP Outbound', false) then exit;
                    CheckNRGPOutShipment();
                    PostNRGPOutShipment();
                    //>>001
                    Message('NRGP Shipment %1 Posted successfully', DocNoForMessage);
                    //<<001
                end;
            RGPHeader."document type"::"NRGP Inbound":
                begin
                    if not Confirm('Do you want to post NRGP Inbound', false) then exit;
                    CheckNRGPInReceipt();
                    PostNRGPInReceipt();
                    //>>001
                    Message('NRGP Receipt %1 Posted Successfully', DocNoForMessage);
                    //<<001
                end;
        end;
        Commit;
    end;
 
    procedure PostRGPOutbound()
    kjhgf: page 54;
    begin
        if Ship then begin
            CheckRGPOutShipment();
            PostRGPOutShipment();
            UpdateHeaderForShipment();
        end;
        if Receipt then begin
            CheckRGPOutReceipt();
            PostRGPOutReceipt();
        end;
        UpdateHeaderforReceipt();
    end;
 
    procedure PostRGPInbound()
    begin
        if Receipt then begin
            CheckRGPInReceipt();
            PostRGPInReceipt();
        end;
        if Ship then begin
            CheckRGPInShipment();
            PostRGPInShipment();
            UpdateHeaderForShipment();
        end;
        UpdateHeaderforReceipt();
    end;
 
    procedure CheckRGPOutShipment()
    begin
        if RGPHeader."Posted Shipment No." <> '' then InvSetup.TestField("Posted RGP Shipt. No.");
        RGPHeader.TestField(RGPHeader."Posting Date");
        RGPHeader.TestField(RGPHeader."Party No.");
        RGPLine.SetRange("Document Type", RGPHeader."Document Type");
        RGPLine.SetRange("Document No.", RGPHeader."No.");
        RGPLine.SetFilter("Quantity to Ship", '<>%1', 0);
        if RGPLine.Find('-') then begin
            repeat
                RGPLine.TestField(RGPLine.Quantity);
                // RGPLine.TestField(RGPLine."Location Code");
                if RGPLine.Type = RGPLine.Type::Item then RGPLine.TestField(RGPLine."Unit Of Measure Code");
                RGPLine.TestField(RGPLine."Consumed by Sub.Contractor", false);
                RGPLine.TestField(RGPLine."Qty. to Consume by Sub.Cont", 0);
            until RGPLine.Next = 0;
        end
        else
            Error(Text002);
    end;
 
    procedure PostRGPOutShipment()
    var
        RGPShipmentHeader: Record "Posted RGP Header";
        RGPShipmentLine: Record "Posted RGP Line";
    begin
        if RGPHeader."Posted Shipment No." <> '' then
            ShipNo := RGPHeader."Posted Shipment No."
        else begin
            NoSeriesMgt.InitSeries(InvSetup."Posted RGP Shipt. No.", RGPHeader."Posted Shpmt. No Series", RGPHeader."Posting Date", ShipNo, RGPHeader."Posted Shpmt. No Series");
        end;
        RGPShipmentHeader.Init;
        RGPShipmentHeader.TransferFields(RGPHeader);
        RGPShipmentHeader."Posting Type" := RGPShipmentHeader."posting type"::Shipment;
        RGPShipmentHeader."No." := ShipNo;
        RGPShipmentHeader."User ID" := RGPHeader."User ID";
        RGPShipmentHeader."Pre-Assigned No." := RGPHeader."No.";
        RGPShipmentHeader."Posting Date" := RGPHeader."Posting Date";
        RGPShipmentHeader.Insert;
       
        RGPHeader.Posted := true;
        RGPHeader.Modify;
       
        DocNoForMessage := RGPShipmentHeader."No."; //001
        if RGPLine.Find('-') then begin
            repeat
                RGPShipmentLine.Init;
                RGPShipmentLine.TransferFields(RGPLine);
                RGPShipmentLine."Posting Type" := RGPShipmentLine."posting type"::Shipment;
                RGPShipmentLine."Document No." := ShipNo;
                RGPShipmentLine."User ID" := RGPHeader."User ID";
                RGPShipmentLine."Posting Date" := RGPShipmentHeader."Posting Date"; //gitl dev
                RGPShipmentLine."Pre-Assigned No." := RGPLine."Document No.";
                RGPShipmentLine."Pre-Assigned Line No." := RGPLine."Line No.";
                RGPShipmentLine."Posting Date" := RGPHeader."Posting Date";
                RGPShipmentLine.Insert;
            until RGPLine.Next = 0;
        end;
        InsertJnlLine(RGPShipmentHeader."No.");
        // CreateRGPOutwardEntry(RGPShipmentHeader);
        UpdateRGPLines(true);
    end;
 
    procedure UpdateRGPLines(ShiporReceive: Boolean)
    begin
        if RGPLine.Find('-') then
            repeat
                if Ship and (RGPLine."Document Type" = RGPLine."document type"::"RGP Outbound") then begin
                    RGPLine."Quantity Shipped" := RGPLine."Quantity Shipped" + RGPLine."Quantity to Ship";
                    RGPLine."Outstanding Ship Quantity" := RGPLine.Quantity - RGPLine."Quantity Shipped";
                    RGPLine."Quantity to Ship" := 0;
                    RGPLine."Shortcut Dimension 1 Code" := RGPHeader."Shortcut Dimension 1 Code";
                    RGPLine."Shortcut Dimension 2 Code" := RGPHeader."Shortcut Dimension 2 Code";
                    if (RGPLine."Document Type" = RGPLine."document type"::"NRGP Outbound") or (RGPLine."Document Type" = RGPLine."document type"::"NRGP Inbound") or (RGPLine."Document Type" = RGPLine."document type"::"RGP Outbound") then
                        RGPLine."Outstanding Rcpt. Quantity" := 0
                    else begin
                        RGPLine."Outstanding Rcpt. Quantity" := RGPLine."Quantity Shipped" - RGPLine."Quantity Received" - RGPLine."Qty Consumed by Sub.Cont";
                    end;
                end;
                if Receipt and (RGPLine."Document Type" = RGPLine."document type"::"RGP Outbound") then begin
                    RGPLine."Quantity Received" := RGPLine."Quantity Received" + RGPLine."Quantity to Receive";
                    RGPLine."Outstanding Rcpt. Quantity" := RGPLine."Quantity Shipped" - RGPLine."Quantity Received";
                    RGPLine."Quantity to Receive" := 0;
                end;
                if Receipt and (RGPLine."Document Type" = RGPLine."document type"::"RGP Inbound") then begin
                    RGPLine."Quantity Received" := RGPLine."Quantity Received" + RGPLine."Quantity to Receive";
                    RGPLine."Outstanding Rcpt. Quantity" := RGPLine.Quantity - RGPLine."Quantity Received";
                    //RGPLine."Outstanding Ship Quantity" := RGPLine."Quantity Received" - RGPLine."Quantity Shipped";
                    RGPLine."Quantity to Receive" := 0;
                end;
                if Ship and (RGPLine."Document Type" = RGPLine."document type"::"RGP Inbound") then begin
                    RGPLine."Quantity Shipped" := RGPLine."Quantity Shipped" + RGPLine."Quantity to Ship";
                    RGPLine."Outstanding Ship Quantity" := RGPLine."Quantity Received" - RGPLine."Quantity Shipped";
                    RGPLine."Quantity to Ship" := 0;
                end;
                if (RGPLine."Document Type" = RGPLine."document type"::"NRGP Outbound") or (RGPLine."Document Type" = RGPLine."document type"::"RGP Outbound") then begin
                    RGPLine."Quantity Shipped" := RGPLine."Quantity Shipped" + RGPLine."Quantity to Ship";
                    RGPLine."Outstanding Ship Quantity" := RGPLine.Quantity - RGPLine."Quantity Shipped";
                    RGPLine."Quantity to Ship" := 0;
                end;
                if RGPLine."Document Type" = RGPLine."document type"::"NRGP Inbound" then begin
                    RGPLine."Quantity Received" := RGPLine."Quantity Received" + RGPLine."Quantity to Receive";
                    RGPLine."Outstanding Rcpt. Quantity" := RGPLine.Quantity - RGPLine."Quantity Received";
                    RGPLine."Quantity to Receive" := 0;
                end;
                RGPLine."Gate Entry No." := '';
                RGPLine."Gate Entry Line No." := 0;
                RGPLine."Item Journal Template Name" := '';
                RGPLine."Item Journal Batch Name" := '';
                RGPLine."Item Line No." := 0;
                RGPLine."Ship Tracking" := false;
                RGPLine."Receipt Tracking" := false;
                RGPLine.Modify;
            until RGPLine.Next = 0;
    end;
    /* procedure CreateRGPOutwardEntry(PostedRGPShipment: Record "Posted RGP Header")
    var
        RGPGateEntryHeader: Record "RGP Gate Entry Header";
        RGPGateEntryLine: Record "RGP Gate Entry Line";
        PRGPLine: Record "Posted RGP Line";
    begin
        RGPGateEntryHeader.Init();
        RGPGateEntryHeader."No." := NoSeriesMgt.GetNextNo(InvSetup."RGP Outward Gate Entry Nos.", WorkDate(), true);
        RGPGateEntryHeader."Entry Type" := RGPGateEntryHeader."Entry Type"::Outward;
        RGPGateEntryHeader."Location Code" := PostedRGPShipment."Location Code";
        RGPGateEntryHeader."Document Date" := PostedRGPShipment."Posting Date";
        RGPGateEntryHeader."Source Type" := RGPGateEntryHeader."Source Type"::"RGP Outbound";
        RGPGateEntryHeader."Source No." := PostedRGPShipment."No.";
        RGPGateEntryHeader."Posting Date" := PostedRGPShipment."Posting Date";
        RGPGateEntryHeader."LR/RR No." := PostedRGPShipment."LR No.";
        RGPGateEntryHeader.Insert();
 
        PRGPLine.Reset();
        PRGPLine.SetRange("Document No.", PostedRGPShipment."No.");
        PRGPLine.SetRange("Document Type", PostedRGPShipment."Document Type");
        If PRGPLine.FindFirst() then
            repeat
                RGPGateEntryLine.Init();
                RGPGateEntryLine."Gate Entry No." := RGPGateEntryHeader."No.";
                RGPGateEntryLine."Entry Type" := RGPGateEntryLine."Entry Type"::Outward;
                RGPGateEntryLine."Line No." += 10000;
                RGPGateEntryLine."Challan Date" := WorkDate();
                RGPGateEntryLine."Source Type" := RGPGateEntryLine."Source Type"::"RGP Outbound";
                RGPGateEntryLine.Validate("Source No.", PostedRGPShipment."No.");
                RGPGateEntryLine.Validate("Item No", PRGPLine."No.");
                RGPGateEntryLine."Item Description" := PRGPLine.Description;
                RGPGateEntryLine.Quantity := PRGPLine.Quantity;
                RGPGateEntryLine.Insert();
            until PRGPLine.Next() = 0;
 
    end; */
    procedure PostRGPOutReceipt()
    var
        RGPRcptHeader: Record "Posted RGP Header";
        RGPRcptLine: Record "Posted RGP Line";
    begin
        if RGPHeader."Posted Receipt No." <> '' then
            RecvNo := RGPHeader."Posted Receipt No."
        else begin
            NoSeriesMgt.InitSeries(InvSetup."Posted RGP Rcpt. No.", RGPHeader."Posted Rect. No Series", RGPHeader."Posting Date", RecvNo, RGPHeader."Posted Rect. No Series");
        end;
        case RGPHeader."Document Type" of
            RGPHeader."document type"::"RGP Outbound":
                begin
                    //GateEntryAttachment.SetRange("Source Type",GateEntryAttachment."source type"::"RGP Inbound") 
                    //GateEntryAttachment.SetRange("Source No.", "No.");    
                end;
        //"Document Type"::"NRGP Inbound":
        //   BEGIN
        //     GateEntryAttachment.SETRANGE("Source Type",GateEntryAttachment."Source Type"::"10");
        //     GateEntryAttachment.SETRANGE("Source No.","No.");       
        //    END;
        end;
         
        /* if GateEntryAttachment.Find('-') then begin
            repeat
                PostedGateEntryAttachment.Init;
                PostedGateEntryAttachment.TransferFields(GateEntryAttachment);
                PostedGateEntryAttachment."Receipt No." := RecvNo;
                PostedGateEntryAttachment.Insert;
                PostedGateEntryLine.Get(GateEntryAttachment."Entry Type", GateEntryAttachment."Gate Entry No.",
                                        GateEntryAttachment."Line No.");
                PostedGateEntryLine.TestField(Status, PostedGateEntryLine.Status::Open);
                PostedGateEntryLine.Status := PostedGateEntryLine.Status::Close;
                PostedGateEntryLine.Modify;
            until GateEntryAttachment.Next = 0;
            //GateEntryAttachment.LOCKTABLE(TRUE,TRUE);
            GateEntryAttachment.DeleteAll;
        end; */
       
        RGPRcptHeader.Init;
        RGPRcptHeader.TransferFields(RGPHeader);
        RGPRcptHeader."Posting Type" := RGPRcptHeader."posting type"::Receipt;
        RGPRcptHeader."No." := RecvNo;
        RGPRcptHeader."User ID" := RGPHeader."User ID";
        RGPRcptHeader."Pre-Assigned No." := RGPHeader."No.";
        RGPRcptHeader.Remarks := RGPHeader."Receipt Remarks";
        RGPRcptHeader."Posting Date" := RGPHeader."Posting Date";
        RGPRcptHeader.Insert;
        DocNoForMessage := RGPRcptHeader."No."; //001
        if RGPLine.Find('-') then begin
            // RGPLine.TESTFIELD("Gate Entry No.");
            repeat
                RGPRcptLine.Init;
                RGPRcptLine.TransferFields(RGPLine);
                RGPRcptLine."Posting Type" := RGPRcptLine."posting type"::Receipt;
                RGPRcptLine."Document No." := RecvNo;
                RGPRcptLine."User ID" := RGPHeader."User ID";
                RGPRcptLine.Quantity := RGPLine."Quantity to Receive";
                RGPRcptLine."Posting Date" := RGPRcptHeader."Posting Date"; //gitl dev
                RGPRcptLine."Pre-Assigned No." := RGPLine."Document No.";
                RGPRcptLine."Pre-Assigned Line No." := RGPLine."Line No.";
                RGPRcptLine."Posting Date" := RGPHeader."Posting Date";
                RGPRcptLine.Insert;
            until RGPLine.Next = 0;
        end;
        InsertJnlLine(RGPRcptHeader."No.");
        UpdateRGPLines(true);
    end;
 
    procedure CheckRGPOutReceipt()
    begin
        if RGPHeader."Posted Receipt No." <> '' then InvSetup.TestField("Posted RGP Rcpt. No.");
        RGPHeader.TestField(RGPHeader."Posting Date");
        RGPHeader.TestField(RGPHeader."Party No.");
        RGPLine.SetRange("Document Type", RGPHeader."Document Type");
        RGPLine.SetRange("Document No.", RGPHeader."No.");
        RGPLine.SetFilter("Quantity to Receive", '<>%1', 0);
        if RGPLine.Find('-') then begin
            repeat
                RGPLine.TestField(RGPLine.Quantity);
                 
                if RGPLine.Type = RGPLine.Type::Item then RGPLine.TestField(RGPLine."Unit Of Measure Code");
                RGPLine.TestField(RGPLine."Consumed by Sub.Contractor", false);
                RGPLine.TestField(RGPLine."Qty. to Consume by Sub.Cont", 0);
            until RGPLine.Next = 0;
        end
        else
            Error(Text002);
        //VT-SY 270819
        /*
                GateEntryAttachment.RESET;
                IF RGPHeader."Document Type" = RGPHeader."Document Type"::"RGP Outbound" THEN
                  GateEntryAttachment.SETRANGE(GateEntryAttachment."Source Type",GateEntryAttachment."Source Type"::"RGP Outbound");
                GateEntryAttachment.SETRANGE(GateEntryAttachment."Source No.",RGPHeader."No.");
                IF NOT GateEntryAttachment.FINDFIRST THEN ERROR('Attach gate entry before receipt');
                */
    end;
 
    procedure UpdateHeaderForShipment()
    begin
        RGPHeader.Shipped := true;
        RGPHeader.Modify;
    end;
 
    procedure DateNotAllowed(PostingDate: Date): Boolean
    begin
        if (AllowPostingFrom = 0D) and (AllowPostingTo = 0D) then begin
            if UserId <> '' then
                if UserSetup.Get(UserId) then begin
                    AllowPostingFrom := UserSetup."Allow Posting From";
                    AllowPostingTo := UserSetup."Allow Posting To";
                end;
            if (AllowPostingFrom = 0D) and (AllowPostingTo = 0D) then begin
                GLSetup.Get;
                AllowPostingFrom := GLSetup."Allow Posting From";
                AllowPostingTo := GLSetup."Allow Posting To";
            end;
            if AllowPostingTo = 0D then AllowPostingTo := 99991231D;
        end;
        exit((PostingDate < AllowPostingFrom) or (PostingDate > AllowPostingTo));
    end;
 
    procedure "//ash"()
    begin
    end;
 
    procedure ILEPOST()
    begin
    end;
 
    procedure InsertJnlLine(DocumentNo: Code[20])
    var
        Match: Boolean;
        IJLien: Record "Item Journal Line";
        itemrec1: Record Item;
    begin
        InvSetup.TestField("RGP Template Name");
        InvSetup.TestField("RGP Batch Name");
        InvSetup.TestField("RGP In-Transist Location");
        ItemJournalLine.Reset;
        ItemJournalLine.SetRange(ItemJournalLine."Journal Template Name", InvSetup."RGP Template Name");
        ItemJournalLine.SetRange(ItemJournalLine."Journal Batch Name", InvSetup."RGP Batch Name");
        if ItemJournalLine.Find('+') then begin
            //gvlineno := ItemJournalLine."Line No.";   
            ItemJournalLine.DeleteAll;
        end;
        
        /*  ItemJournalLine.SetRange(ItemJournalLine."RGP Tracking Creted", false);
         if ItemJournalLine.Find('-') then
             ItemJournalLine.DeleteAll; */
        
        if (RGPLine.Find('-')) and (RGPLine.Type = RGPLine.Type::Item) then
            repeat
                if (RGPLine."Item Journal Template Name" <> '') and (RGPLine."Item Journal Batch Name" <> '') then begin
                    if ItemJournalLine.Get(RGPLine."Item Journal Template Name", RGPLine."Item Journal Batch Name", RGPLine."Item Line No.") then begin
                        Match := true;
                        if not ((ItemJournalLine."Journal Template Name" = InvSetup."RGP Template Name") and (ItemJournalLine."Journal Batch Name" = InvSetup."RGP Batch Name") and (ItemJournalLine."Item No." = RGPLine."No.") and (ItemJournalLine."Variant Code" = RGPLine."Variant Code")) then Clear(Match);
                        if (RGPLine."Document Type" = RGPLine."document type"::"RGP Outbound") then begin
                            if Ship then begin
                                if not ((ItemJournalLine."Entry Type" = ItemJournalLine."entry type"::Transfer) and (ItemJournalLine."Location Code" = RGPLine."Location Code") and (ItemJournalLine."New Location Code" = InvSetup."RGP In-Transist Location")) then Clear(Match);
                            end
                            else if Receipt then begin
                                if not ((ItemJournalLine."Entry Type" = ItemJournalLine."entry type"::Transfer) and (ItemJournalLine."Location Code" = InvSetup."RGP In-Transist Location") and (ItemJournalLine."New Location Code" = RGPLine."Location Code")) then Clear(Match);
                            end;
                        end;
                        //  Else
                        If ((RGPLine."Document Type" = RGPLine."document type"::"RGP Inbound")) then begin //vis
                            if Receipt then begin
                                if not ((ItemJournalLine."Entry Type" = ItemJournalLine."entry type"::Transfer) and (ItemJournalLine."Location Code" = RGPLine."Location Code") and (ItemJournalLine."New Location Code" = 'MAINSTORE')) then Clear(Match);
                            end;
                        end
                        else  
                            if (RGPLine."Document Type" = RGPLine."document type"::"RGP Inbound") then begin
                                if Receipt then begin
                                    if not ((ItemJournalLine."Entry Type" = ItemJournalLine."entry type"::"Positive Adjmt.") and (ItemJournalLine."Location Code" = RGPLine."Location Code")) then Clear(Match);
                                end
                                else if Ship then begin
                                    if not ((ItemJournalLine."Entry Type" = ItemJournalLine."entry type"::"Negative Adjmt.") and (ItemJournalLine."Location Code" = RGPLine."Location Code")) then Clear(Match);
                                end;
                                ItemJournalLine.Validate("Unit Amount", RGPLine."Direct Unit Cost"); //ANIL
                            end
                            else if (RGPLine."Document Type" = RGPLine."document type"::"NRGP Outbound") then begin
                                if not ((ItemJournalLine."Entry Type" = ItemJournalLine."entry type"::"Negative Adjmt.") and (ItemJournalLine."Location Code" = RGPLine."Location Code")) then Clear(Match);
                                ItemJournalLine.Validate("Unit Amount", RGPLine."Direct Unit Cost"); //ANIL
                            end
                            else if (RGPLine."Document Type" = RGPLine."document type"::"NRGP Inbound") then begin
                                if not ((ItemJournalLine."Entry Type" = ItemJournalLine."entry type"::"Positive Adjmt.") and (ItemJournalLine."Location Code" = RGPLine."Location Code")) then Clear(Match);
                                ItemJournalLine.Validate("Unit Amount", RGPLine."Direct Unit Cost"); //ANIL
                            end;
                        if Ship or (RGPLine."Document Type" = RGPLine."document type"::"NRGP Outbound") or (RGPLine."Document Type" = RGPLine."document type"::"RGP Outbound") then begin
                            if not (ItemJournalLine.Quantity = RGPLine."Quantity to Ship") then Clear(Match);
                        end
                        else if Receipt or (RGPLine."Document Type" = RGPLine."document type"::"NRGP Inbound") or (RGPLine."Document Type" = RGPLine."Document Type"::"RGP Inbound") then begin
                            if not (ItemJournalLine.Quantity = RGPLine."Quantity to Receive") then Clear(Match);
                        end;
                       
                        if not Match then Error('Please recreate Item Tracking Line');
                        Message('%1', DocumentNo);
                        ItemJournalLine."Document No." := DocumentNo;
                      
                        ItemJournalLine.Modify;
                    end; //else
                         
                end
                else begin
                    Message('%1', DocumentNo);
                    If ItemRec1.Get(RGPLine."No.") then;
                    if itemrec1.type = itemrec1.Type::Inventory then begin
                        gvlineno := gvlineno + 10000;
                        ItemJournalLine.Init;
                        ItemJournalLine."Journal Template Name" := InvSetup."RGP Template Name";
                        ItemJournalLine."Journal Batch Name" := InvSetup."RGP Batch Name";
                        ItemJournalLine."Line No." := gvlineno;
                        ItemJournalLine."Item No." := RGPLine."No.";
                        ItemJournalLine."Gen. Prod. Posting Group" := RGPLine."Gen. Prod. Posting Group";
                        ItemJournalLine.Validate(ItemJournalLine."Item No.");
                        ItemJournalLine."Variant Code" := RGPLine."Variant Code";
                        case RGPHeader."Party Type" of
                            RGPHeader."party type"::Vendor:
                                begin
                                    ItemJournalLine."Source Type" := ItemJournalLine."source type"::Vendor;
                                    ItemJournalLine."Source No." := RGPHeader."Party No.";
                                end;
                            RGPHeader."party type"::Customer:
                                begin
                                    ItemJournalLine."Source Type" := ItemJournalLine."source type"::Customer;
                                    ItemJournalLine."Source No." := RGPHeader."Party No.";
                                end
                        end;
                        ItemJournalLine."Posting Date" := RGPHeader."Posting Date";
                        ItemJournalLine."Order Type" := ItemJournalLine."order type"::Transfer; //APCL_DN
                        if ItemJournalLine."Entry Type" = ItemJournalLine."entry type"::Transfer then begin
                            ItemJournalLine.Validate(ItemJournalLine."New Shortcut Dimension 1 Code", RGPLine."Shortcut Dimension 1 Code");
                            ItemJournalLine.Validate(ItemJournalLine."New Shortcut Dimension 2 Code", RGPLine."Shortcut Dimension 2 Code");
                        end;
                        //gitl dev
                        ItemJournalLine."Document No." := DocumentNo;
                        if Ship or (RGPLine."Document Type" = RGPLine."document type"::"NRGP Outbound") then //or (RGPLine."Document Type" = RGPLine."document type"::"RGP Outbound") then
                            ItemJournalLine.Quantity := RGPLine."Quantity to Ship"
                        else if Receipt or (RGPLine."Document Type" = RGPLine."document type"::"RGP Inbound") then begin
                            //RGPHeader.Get(RGPLine."Document No.", RGPLine."Document No.");
                            PostedRGPHeader.Get(RGPHeader."RGP Outbound No.");
                            ItemJournalLine."Entry Type" := ItemJournalLine."entry type"::Transfer;
                            ItemJournalLine.Validate("Location Code", RGPLine."Location Code");
                            ItemJournalLine.Validate("New Location Code", PostedRGPHeader."Location Code");
                            ItemJournalLine.Quantity := RGPLine."Quantity to Receive";
                          
                            ItemJournalLine.Validate("Applies-to Entry", RGPLine."Entry No.");
                        end;
                        //MESSAGE('%1..%2',ItemJournalLine.Quantity,RGPLine."Quantity to Receive");
                        ItemJournalLine.Validate(Quantity);
                        if (RGPLine."Document Type" = RGPLine."document type"::"RGP Outbound") then begin
                            if Ship then begin
                                ItemJournalLine."Entry Type" := ItemJournalLine."entry type"::Transfer;
                                ItemJournalLine.Validate("Location Code", RGPLine."Location Code");
                                ItemJournalLine.Validate("New Location Code", InvSetup."RGP In-Transist Location");
                            end; //else
                                 //If (RGPLine."Document Type" = RGPLine."document type"::"RGP Inbound") then begin
                                 //if Receipt then begin
                                 /* ItemJournalLine."Entry Type" := ItemJournalLine."entry type"::Transfer;
                                              if ItemJournalLine."Source Type" = ItemJournalLine."source type"::Vendor then begin
                                                  ItemJournalLine.Validate("Location Code", InvSetup."RGP Vendor Location");
                                                  ItemJournalLine.Validate("New Location Code", RGPLine."Location Code");
 
                                                  PostedRGPHeader.Reset;
                                                  PostedRGPHeader.SetRange("No.", DocumentNo);
                                                  if PostedRGPHeader.FindFirst then begin
                                                      PostedRGPHeader1.Reset;
                                                      PostedRGPHeader1.SetRange("Pre-Assigned No.", PostedRGPHeader."Pre-Assigned No.");
                                                      PostedRGPHeader1.SetRange("Posting Type", PostedRGPHeader1."posting type"::Shipment);
                                                      if PostedRGPHeader1.FindFirst then begin
                                                          //////
                                                          ILE.Reset;
                                                          ILE.SetRange("Document No.", PostedRGPHeader1."No.");
                                                          ILE.SetRange("Location Code", InvSetup."RGP Vendor Location");
                                                          ILE.SetRange("Item No.", RGPLine."No.");
                                                          if ILE.FindFirst then
                                                              ItemJournalLine.Validate("Applies-to Entry", ILE."Entry No.");
                                                      end;
                                                  end;
                                              end;
                                              if ItemJournalLine."Source Type" = ItemJournalLine."source type"::Customer then begin
                                                  ItemJournalLine.Validate("Location Code", InvSetup."RGP Customer Location");
                                                  ItemJournalLine.Validate("New Location Code", RGPLine."Location Code");
                                                  PostedRGPHeader.Reset;
                                                  PostedRGPHeader.SetRange("No.", DocumentNo);
                                                  if PostedRGPHeader.FindFirst then begin
                                                      PostedRGPHeader1.Reset;
                                                      PostedRGPHeader1.SetRange("Pre-Assigned No.", PostedRGPHeader."Pre-Assigned No.");
                                                      PostedRGPHeader1.SetRange("Posting Type", PostedRGPHeader1."posting type"::Shipment);
                                                      if PostedRGPHeader1.FindFirst then begin
                                                          ILE.Reset;
                                                          ILE.SetRange("Document No.", PostedRGPHeader1."No.");
                                                          ILE.SetRange("Location Code", InvSetup."RGP Customer Location");
                                                          ILE.SetRange("Item No.", RGPLine."No.");
                                                          if ILE.FindFirst then
                                                              ItemJournalLine.Validate("Applies-to Entry", ILE."Entry No.");
                                                      end;
                                                  end; */
                                 //end;
                        end;
                        //end;
                        /* else
                            if (RGPLine."Document Type" = RGPLine."document type"::"RGP Inbound") then begin
                                if Receipt then begin
                                    ItemJournalLine."Entry Type" := ItemJournalLine."entry type"::"Positive Adjmt.";
                                    ItemJournalLine.Validate("Location Code", RGPLine."Location Code");
                                end else
                                    if Ship then begin
                                        ItemJournalLine."Entry Type" := ItemJournalLine."entry type"::"Negative Adjmt.";
                                        ItemJournalLine.Validate("Location Code", RGPLine."Location Code");
                                    end;
                                ItemJournalLine.Validate("Unit Amount", RGPLine."Direct Unit Cost");//ANIL
                            end else
                                if (RGPLine."Document Type" = RGPLine."document type"::"NRGP Outbound") then begin
                                    ItemJournalLine."Entry Type" := ItemJournalLine."entry type"::"Negative Adjmt.";
                                    ItemJournalLine.Validate("Location Code", RGPLine."Location Code");
                                    ItemJournalLine.Validate("Unit Amount", RGPLine."Direct Unit Cost");//ANIL
                                end else
                                    if (RGPLine."Document Type" = RGPLine."document type"::"NRGP Inbound") then begin
                                        ItemJournalLine."Entry Type" := ItemJournalLine."entry type"::"Positive Adjmt.";
                                        ItemJournalLine.Validate("Location Code", RGPLine."Location Code");
                                        ItemJournalLine.Validate("Unit Amount", RGPLine."Direct Unit Cost");//ANIL
                                    end; */
                        //gitl dev
                        // Message(ItemJournalLine."Gen. Prod. Posting Group");
                        if (RGPLine."Document Type" = RGPLine."document type"::"NRGP Outbound") then begin
                            ItemJournalLine."Entry Type" := ItemJournalLine."entry type"::"Negative Adjmt.";
                            ItemJournalLine.Validate("Location Code", RGPLine."Location Code");
                            ItemJournalLine.Validate("Unit Amount", RGPLine."Direct Unit Cost"); //ANIL
                        end
                        else if (RGPLine."Document Type" = RGPLine."document type"::"NRGP Inbound") then begin
                            ItemJournalLine."Entry Type" := ItemJournalLine."entry type"::"Positive Adjmt.";
                            ItemJournalLine.Validate("Location Code", RGPLine."Location Code");
                            ItemJournalLine.Validate("Unit Amount", RGPLine."Direct Unit Cost"); //ANIL
                        end;
                        if ItemJournalLine."Entry Type" = ItemJournalLine."Entry Type"::Transfer then begin
                            ItemJournalLine.Validate(ItemJournalLine."New Shortcut Dimension 1 Code", RGPLine."Shortcut Dimension 1 Code");
                            ItemJournalLine.Validate(ItemJournalLine."New Shortcut Dimension 2 Code", RGPLine."Shortcut Dimension 2 Code");
                        end;
                        ItemJournalLine.Validate(ItemJournalLine."Shortcut Dimension 1 Code", RGPLine."Shortcut Dimension 1 Code");
                        ItemJournalLine.Validate(ItemJournalLine."Shortcut Dimension 2 Code", RGPLine."Shortcut Dimension 2 Code");
                        if ItemJournalLine.Insert() then begin
                            ItemJournalLine.Modify();
                        end;
                    end;
                end;
            until RGPLine.Next = 0;
        ItemJournalLine.Reset;
        // ItemJournalLine.SetRange(ItemJournalLine."Journal Template Name", InvSetup."RGP Template Name");
        //ItemJournalLine.SetRange(ItemJournalLine."Journal Batch Name", InvSetup."RGP Batch Name");
       
        ItemJournalLine.SetRange(ItemJournalLine."RGP Tracking Creted", false);
        
        if RGPLine.Type = RGPLine.Type::Item then;
        If ItemRec1.Get(RGPLine."No.") then;
        if itemrec1.type = itemrec1.Type::Inventory then ItemJnlPostBatch.Run(ItemJournalLine);
        // IJLien.Reset();
        // IJLien.SetRange("Journal Template Name", ItemJournalLine."Journal Template Name");
        // IJLien.SetRange("Journal Batch Name", ItemJournalLine."Journal Batch Name");
        // if IJLien.FindFirst() then
        //     Page.run(Page::"Item Reclass. Journal", IJLien)
    end;
 
    procedure PostNRGPInbound()
    begin
    end;
 
    procedure CheckRGPInReceipt()
    begin
        if RGPHeader."Posted Receipt No." <> '' then InvSetup.TestField("Posted RGP Rcpt. No.");
        RGPHeader.TestField(RGPHeader."Posting Date");
        RGPHeader.TestField(RGPHeader."Party No.");
        RGPLine.SetRange("Document Type", RGPHeader."Document Type");
        RGPLine.SetRange("Document No.", RGPHeader."No.");
        RGPLine.SetFilter("Quantity to Receive", '<>%1', 0);
        if RGPLine.Find('-') then begin
            repeat
                RGPLine.TestField(RGPLine.Quantity);
                if RGPLine.Type = RGPLine.Type::Item then RGPLine.TestField(RGPLine."Unit Of Measure Code");
                RGPLine.TestField(RGPLine."Consumed by Sub.Contractor", false);
                RGPLine.TestField(RGPLine."Qty. to Consume by Sub.Cont", 0);
            until RGPLine.Next = 0;
        end
        else
            Error(Text002);
    end;
 
    procedure PostRGPInReceipt()
    var
        RGPRcptHeader: Record "Posted RGP Header";
        RGPRcptLine: Record "Posted RGP Line";
    begin
        if RGPHeader."Posted Receipt No." <> '' then
            RecvNo := RGPHeader."Posted Receipt No."
        else begin
            NoSeriesMgt.InitSeries(InvSetup."Posted RGP Rcpt. No.", RGPHeader."Posted Rect. No Series", RGPHeader."Posting Date", RecvNo, RGPHeader."Posted Rect. No Series");
        end;
        RGPRcptHeader.Init;
        RGPRcptHeader.TransferFields(RGPHeader);
        RGPRcptHeader."Posting Type" := RGPRcptHeader."posting type"::Receipt;
        RGPRcptHeader."No." := RecvNo;
        RGPRcptHeader."User ID" := RGPHeader."User ID";
        RGPRcptHeader."Pre-Assigned No." := RGPHeader."No.";
        RGPRcptHeader.Remarks := RGPHeader."Receipt Remarks";
        RGPRcptHeader."Posting Date" := RGPHeader."Posting Date";
        RGPRcptHeader.Insert;
        DocNoForMessage := RGPRcptHeader."No.";
        case RGPHeader."Document Type" of
            RGPHeader."document type"::"RGP Inbound":
                begin
                    //GateEntryAttachment.SetRange("Source Type",GateEntryAttachment."source type"::"RGP Inbound")VTRS;
                    //      GateEntryAttachment.SetRange("Source No.", "No.");   //VT-RAhul
                end;
            RGPHeader."document type"::"NRGP Inbound":
                begin
                   
                end;
        end;
        
        /*  if GateEntryAttachment.Find('-') then begin
             repeat
                 PostedGateEntryAttachment.Init;
                 PostedGateEntryAttachment.TransferFields(GateEntryAttachment);
                 PostedGateEntryAttachment."Receipt No." := RecvNo;
                 PostedGateEntryAttachment.Insert;
                 PostedGateEntryLine.Get(GateEntryAttachment."Entry Type", GateEntryAttachment."Gate Entry No.",
                   GateEntryAttachment."Line No.");
                 PostedGateEntryLine.TestField(Status, PostedGateEntryLine.Status::Open);
                 PostedGateEntryLine.Status := PostedGateEntryLine.Status::Close;
                 PostedGateEntryLine.Modify;
             until GateEntryAttachment.Next = 0;
             //GateEntryAttachment.LOCKTABLE(TRUE,TRUE);
             GateEntryAttachment.DeleteAll;
         end; */
        
        if RGPLine.Find('-') then begin
            //   RGPLine.TESTFIELD(RGPLine."Gate Entry No.");
            repeat
                RGPRcptLine.Init;
                RGPRcptLine.TransferFields(RGPLine);
                RGPRcptLine."Posting Type" := RGPRcptLine."posting type"::Receipt;
                RGPRcptLine."Document No." := RecvNo;
                RGPRcptLine."User ID" := RGPHeader."User ID";
                // VT-RAHUL
                RGPRcptLine.Quantity := RGPLine."Quantity to Receive";
                // VT-RAHUL
                RGPRcptLine."Posting Date" := RGPRcptHeader."Posting Date"; //gitl dev
                RGPRcptLine."Pre-Assigned No." := RGPLine."Document No.";
                RGPRcptLine."Pre-Assigned Line No." := RGPLine."Line No.";
                RGPRcptLine."Posting Date" := RGPHeader."Posting Date";
                RGPRcptLine.Insert;
            until RGPLine.Next = 0;
        end;
        InsertJnlLine(RGPRcptHeader."No.");
        UpdateRGPLines(true);
    end;
 
    procedure CheckRGPInShipment()
    begin
        if RGPHeader."Posted Shipment No." <> '' then InvSetup.TestField("Posted RGP Shipt. No.");
        RGPHeader.TestField(RGPHeader."Posting Date");
        RGPHeader.TestField(RGPHeader."Party No.");
        RGPLine.SetRange("Document Type", RGPHeader."Document Type");
        RGPLine.SetRange("Document No.", RGPHeader."No.");
        RGPLine.SetFilter("Quantity to Ship", '<>%1', 0);
        if RGPLine.Find('-') then begin
            repeat
                RGPLine.TestField(RGPLine.Quantity);
                // RGPLine.TestField(RGPLine."Location Code");
                if RGPLine.Type = RGPLine.Type::Item then RGPLine.TestField(RGPLine."Unit Of Measure Code");
                RGPLine.TestField(RGPLine."Consumed by Sub.Contractor", false);
                RGPLine.TestField(RGPLine."Qty. to Consume by Sub.Cont", 0);
                itemqty := 0;
                itemrec.Reset;
                itemrec.SetFilter("Item No.", RGPLine."No.");
                itemrec.SetFilter(itemrec."Variant Code", RGPLine."Variant Code");
                itemrec.SetFilter("Location Code", RGPLine."Location Code");
                if itemrec.Find('-') then
                    repeat
                        itemqty := itemqty + itemrec.Quantity;
                    until itemrec.Next = 0;
            until RGPLine.Next = 0;
        end
        else
            Error(Text002);
    end;
 
    procedure PostRGPInShipment()
    var
        RGPShipmentHeader: Record "Posted RGP Header";
        RGPShipmentLine: Record "Posted RGP Line";
    begin
        if RGPHeader."Posted Shipment No." <> '' then
            ShipNo := RGPHeader."Posted Shipment No."
        else begin
            NoSeriesMgt.InitSeries(InvSetup."Posted RGP Shipt. No.", RGPHeader."Posted Shpmt. No Series", RGPHeader."Posting Date", ShipNo, RGPHeader."Posted Shpmt. No Series");
        end;
        RGPShipmentHeader.Init;
        RGPShipmentHeader.TransferFields(RGPHeader);
        RGPShipmentHeader."No." := ShipNo;
        RGPShipmentHeader."User ID" := RGPHeader."User ID";
        RGPShipmentHeader."Pre-Assigned No." := RGPHeader."No.";
        RGPShipmentHeader."Posting Date" := RGPHeader."Posting Date";
        RGPShipmentHeader.Insert;
        //VT-MS>>
        RGPHeader.Posted := true;
        RGPHeader.Modify;
        //VT-MS<<
        DocNoForMessage := RGPShipmentHeader."No.";
        if RGPLine.Find('-') then begin
            repeat
                RGPShipmentLine.Init;
                RGPShipmentLine.TransferFields(RGPLine);
                RGPShipmentLine."Document No." := ShipNo;
                RGPShipmentLine."User ID" := RGPHeader."User ID";
                RGPShipmentLine."Pre-Assigned No." := RGPLine."Document No.";
                RGPShipmentLine."Pre-Assigned Line No." := RGPLine."Line No.";
                RGPShipmentLine."Posting Date" := RGPShipmentHeader."Posting Date"; //gitl dev
                RGPShipmentLine."Posting Date" := RGPHeader."Posting Date";
                RGPShipmentLine.Insert;
            until RGPLine.Next = 0;
        end;
        InsertJnlLine(RGPShipmentHeader."No.");
        UpdateRGPLines(true);
    end;
 
    procedure PostNRGPOutShipment()
    var
        RGPShipmentHeader: Record "Posted RGP Header";
        RGPShipmentLine: Record "Posted RGP Line";
    begin
        if RGPHeader."Posted Shipment No." <> '' then
            ShipNo := RGPHeader."Posted Shipment No."
        else begin
            NoSeriesMgt.InitSeries(InvSetup."Posted NRGP Shpt.No.", RGPHeader."Posted Shpmt. No Series", RGPHeader."Posting Date", ShipNo, RGPHeader."Posted Shpmt. No Series");
        end;
        RGPShipmentHeader.Init;
        RGPShipmentHeader.TransferFields(RGPHeader);
        RGPShipmentHeader."Posting Type" := RGPShipmentHeader."posting type"::Shipment;
        RGPShipmentHeader."No." := ShipNo;
        RGPShipmentHeader."User ID" := RGPHeader."User ID";
        RGPShipmentHeader."Pre-Assigned No." := RGPHeader."No.";
        RGPShipmentHeader."Posting Date" := RGPHeader."Posting Date";
        RGPShipmentHeader.Insert;
        //VT-MS>>
        RGPHeader.Posted := true;
        RGPHeader.Modify;
        //VT-MS<<
        DocNoForMessage := RGPShipmentHeader."No.";
        /*
      RGPLedgerEntry.LOCKTABLE;
      IF RGPLedgerEntry.FIND('+') THEN
        LastEntryNo:=RGPLedgerEntry."Entry No."
      ELSE
        LastEntryNo := 0;
 
      RGPAppEntry.LOCKTABLE;
      IF RGPAppEntry.FIND('+') THEN
        LastAppEntryNo:=RGPAppEntry."Entry No."
      ELSE
        LastAppEntryNo := 0;
        */
        if RGPLine.Find('-') then begin
            repeat
                RGPShipmentLine.Init;
                RGPShipmentLine.TransferFields(RGPLine);
                RGPShipmentLine."Posting Type" := RGPShipmentLine."posting type"::Shipment;
                RGPShipmentLine."Document No." := ShipNo;
                RGPShipmentLine."User ID" := RGPHeader."User ID";
                RGPShipmentLine."Pre-Assigned No." := RGPLine."Document No.";
                RGPShipmentLine."Pre-Assigned Line No." := RGPLine."Line No.";
                RGPShipmentLine."Posting Date" := RGPHeader."Posting Date";
                RGPShipmentLine.Insert;
            //InsertRGPLedgEntry();
            // InsertRGPAppEntry();
            until RGPLine.Next = 0;
        end;
        InsertJnlLine(RGPShipmentHeader."No.");
        UpdateRGPLines(true);
    end;
 
    procedure CheckNRGPOutShipment()
    begin
        if RGPHeader."Posted Shipment No." <> '' then InvSetup.TestField("Posted NRGP Shpt.No.");
        RGPHeader.TestField(RGPHeader."Posting Date");
        RGPHeader.TestField(RGPHeader."Party No.");
        RGPLine.SetRange("Document Type", RGPHeader."Document Type");
        RGPLine.SetRange("Document No.", RGPHeader."No.");
        RGPLine.SetFilter("Quantity to Ship", '<>%1', 0);
        if RGPLine.Find('-') then begin
            repeat
                RGPLine.TestField(RGPLine.Quantity);
                // RGPLine.TestField(RGPLine."Location Code");
                if RGPLine.Type = RGPLine.Type::Item then RGPLine.TestField(RGPLine."Unit Of Measure Code");
            until RGPLine.Next = 0;
        end
        else
            Error(Text002);
    end;
 
    procedure CheckNRGPInReceipt()
    begin
        if RGPHeader."Posted Receipt No." <> '' then InvSetup.TestField("Posted NRGP Rcpt. No.");
        RGPHeader.TestField(RGPHeader."Posting Date");
        RGPHeader.TestField(RGPHeader."Party No.");
        RGPLine.SetRange("Document Type", RGPHeader."Document Type");
        RGPLine.SetRange("Document No.", RGPHeader."No.");
        RGPLine.SetFilter("Quantity to Receive", '<>%1', 0);
        if RGPLine.Find('-') then begin
            repeat
                RGPLine.TestField(RGPLine.Quantity);
                if RGPLine.Type = RGPLine.Type::Item then RGPLine.TestField(RGPLine."Unit Of Measure Code");
                RGPLine.TestField(RGPLine."Consumed by Sub.Contractor", false);
                RGPLine.TestField(RGPLine."Qty. to Consume by Sub.Cont", 0);
            until RGPLine.Next = 0;
        end
        else
            Error(Text002);
    end;
 
    procedure PostNRGPInReceipt()
    var
        RGPRcptHeader: Record "Posted RGP Header";
        RGPRcptLine: Record "Posted RGP Line";
    begin
        if RGPHeader."Posted Receipt No." <> '' then
            RecvNo := RGPHeader."Posted Receipt No."
        else begin
            NoSeriesMgt.InitSeries(InvSetup."Posted NRGP Rcpt. No.", RGPHeader."Posted Rect. No Series", RGPHeader."Posting Date", RecvNo, RGPHeader."Posted Rect. No Series");
        end;
        RGPRcptHeader.Init;
        RGPRcptHeader.TransferFields(RGPHeader);
        RGPRcptHeader."Posting Type" := RGPRcptHeader."posting type"::Receipt;
        RGPRcptHeader."No." := RecvNo;
        RGPRcptHeader."User ID" := RGPHeader."User ID";
        RGPRcptHeader."Pre-Assigned No." := RGPHeader."No.";
        RGPRcptHeader.Remarks := RGPHeader."Receipt Remarks";
        RGPRcptHeader."Posting Date" := RGPHeader."Posting Date";
        RGPRcptHeader.Insert;
        DocNoForMessage := RGPRcptHeader."No."; //001
        /*
        RGPLedgerEntry.LOCKTABLE;
        IF RGPLedgerEntry.FIND('+') THEN
          LastEntryNo:=RGPLedgerEntry."Entry No."
        ELSE
          LastEntryNo := 0;
       
        RGPAppEntry.LOCKTABLE;
        IF RGPAppEntry.FIND('+') THEN
          LastAppEntryNo:=RGPAppEntry."Entry No."
        ELSE
          LastAppEntryNo := 0;
         */
        if RGPLine.Find('-') then begin
            //RGPLine.TESTFIELD(RGPLine."Gate Entry No.");
            repeat
                RGPRcptLine.Init;
                RGPRcptLine.TransferFields(RGPLine);
                RGPRcptLine."Posting Type" := RGPRcptLine."posting type"::Receipt;
                RGPRcptLine."Document No." := RecvNo;
                RGPRcptLine."User ID" := RGPHeader."User ID";
                RGPRcptLine."Pre-Assigned No." := RGPLine."Document No.";
                RGPRcptLine."Pre-Assigned Line No." := RGPLine."Line No.";
                RGPRcptLine."Posting Date" := RGPHeader."Posting Date";
                RGPRcptLine.Insert;
            //InsertRGPLedgEntry();
            until RGPLine.Next = 0;
        end;
        InsertJnlLine(RGPRcptHeader."No.");
        UpdateRGPLines(true);
    end;
 
    procedure "CheckHeader/LineDimensions"()
    var
        RGPLineLocal: Record "Posted RGP Line";
    begin
        RGPLineLocal.Reset;
        RGPLineLocal.SetRange(RGPLineLocal."Document Type", RGPHeader."Document Type");
        RGPLineLocal.SetRange(RGPLineLocal."Document No.", RGPHeader."No.");
        if RGPLineLocal.Find('-') then
            repeat
                if (RGPLineLocal."Shortcut Dimension 1 Code" <> RGPHeader."Shortcut Dimension 1 Code") or (RGPLineLocal."Shortcut Dimension 1 Code" <> RGPHeader."Shortcut Dimension 1 Code") then Error('Dimension in header & Line are different');
            until RGPLineLocal.Next = 0;
    end;
 
    local procedure UpdateHeaderforReceipt()
    begin
        RGPQty := 0;
        RGPReceivedQty := 0;
        RGPShippedQty := 0;
        RGPLineUpdate.Reset;
        RGPLineUpdate.SetRange("Document Type", RGPHeader."Document Type");
        RGPLineUpdate.SetRange("Document No.", RGPHeader."No.");
        if RGPLineUpdate.FindSet then
            repeat
                RGPQty += RGPLineUpdate.Quantity;
                RGPReceivedQty += RGPLineUpdate."Quantity Received";
                RGPShippedQty += RGPLineUpdate."Quantity Shipped";
               
                RGPLineUpdate."Outstanding Rcpt. Quantity" := RGPLineUpdate."Quantity Shipped" - RGPLineUpdate."Quantity Received";
            
            until RGPLineUpdate.Next = 0;
        if RGPQty = RGPReceivedQty then begin
            RGPHeader.Validate("Document Status", RGPHeader."document status"::Completed);
        end;
        if RGPQty = RGPShippedQty then begin
            RGPHeader.Validate("Document Status", RGPHeader."document status"::Completed);
        end;
        if RGPQty <> RGPReceivedQty then begin
            if RGPShippedQty <> 0 then begin
                RGPHeader.Validate("Document Status", RGPHeader."document status"::Partial);
            end
            else begin
                RGPHeader.Validate("Document Status", RGPHeader."document status"::Partial);
            end;
        end;
        if RGPQty = RGPShippedQty then begin
            if RGPHeader."Document Type" = RGPHeader."Document Type"::"RGP Outbound" then RGPHeader.Validate("Document Status", RGPHeader."document status"::Completed);
        end;
        RGPHeader.Modify;
    end;
}
Categories:

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans