5802 - Inventory Posting To G/L - C/AL

VAR
  GLSetup : Record 98 - General Ledger Setup;
  InvtSetup : Record 313 - Inventory Setup;
  Currency : Record 4 - Currency;
  SourceCodeSetup : Record 242 - Source Code Setup;
  GlobalInvtPostBuf : TEMPORARY Record 48 - Invt. Posting Buffer;
  TempInvtPostBuf : ARRAY [4] OF TEMPORARY Record 48 - Invt. Posting Buffer;
  TempInvtPostToGLTestBuf : TEMPORARY Record 5822 - Invt. Post to G/L Test Buffer;
  TempJnlLineDim2 : TEMPORARY Record 356 - Journal Line Dimension;
  TempGLItemLedgRelation : TEMPORARY Record 5823 - G/L - Item Ledger Relation;
  GenJnlPostLine : Codeunit 12 - Gen. Jnl.-Post Line;
  GenJnlCheckLine : Codeunit 11 - Gen. Jnl.-Check Line;
  DimBufMgt : Codeunit 411 - Dimension Buffer Management;
  COGSAmt : Decimal;
  InvtAdjmtAmt : Decimal;
  DirCostAmt : Decimal;
  OvhdCostAmt : Decimal;
  VarPurchCostAmt : Decimal;
  VarMfgDirCostAmt : Decimal;
  VarMfgOvhdCostAmt : Decimal;
  WIPInvtAmt : Decimal;
  InvtAmt : Decimal;
  TotalCOGSAmt : Decimal;
  TotalInvtAdjmtAmt : Decimal;
  TotalDirCostAmt : Decimal;
  TotalOvhdCostAmt : Decimal;
  TotalVarPurchCostAmt : Decimal;
  TotalVarMfgDirCostAmt : Decimal;
  TotalVarMfgOvhdCostAmt : Decimal;
  TotalWIPInvtAmt : Decimal;
  TotalInvtAmt : Decimal;
  TotalExpCOGSAmt : Decimal;
  TotalExpInvtAdjmtAmt : Decimal;
  GlobalInvtPostBufEntryNo : Integer;
  PostBufDimNo : Integer;
  GLSetupRead : Boolean;
  SourceCodeSetupRead : Boolean;
  InvtSetupRead : Boolean;
  Text000 : TextConst 'ENU=%1 %2 on %3';
  Text001 : TextConst 'ENU=%1 - %2, %3,%4,%5,%6';
  Text002 : TextConst 'ENU="The following combination %1 = %2, %3 = %4, and %5 = %6 is not allowed."';
  RunOnlyCheck : Boolean;
  CalledFromItemPosting : Boolean;
  CalledFromTestReport : Boolean;
  GlobalPostPerPostGroup : Boolean;
  Text003 : TextConst 'ENU=%1 %2';


PROCEDURE Initialize(PostPerPostGroup : Boolean); BEGIN GlobalPostPerPostGroup := PostPerPostGroup; GlobalInvtPostBufEntryNo := 0; END;
PROCEDURE SetRunOnlyCheck(SetCalledFromItemPosting : Boolean;SetCheckOnly : Boolean;SetCalledFromTestReport : Boolean); BEGIN CalledFromItemPosting := SetCalledFromItemPosting; RunOnlyCheck := SetCheckOnly; CalledFromTestReport := SetCalledFromTestReport; TempGLItemLedgRelation.RESET; TempGLItemLedgRelation.DELETEALL; END;
PROCEDURE BufferInvtPosting(VAR ValueEntry : Record 5802 - Value Entry) : Boolean; VAR CostToPost : Decimal; CostToPostACY : Decimal; ExpCostToPost : Decimal; ExpCostToPostACY : Decimal; PostToGL : Boolean; BEGIN WITH ValueEntry DO BEGIN GetGLSetup; GetInvtSetup; IF (NOT InvtSetup."Expected Cost Posting to G/L") AND ("Expected Cost Posted to G/L" = 0) AND "Expected Cost" THEN EXIT(FALSE); IF NOT ("Entry Type" IN ["Entry Type"::"Direct Cost","Entry Type"::Revaluation]) AND NOT CalledFromTestReport THEN BEGIN TESTFIELD("Expected Cost",FALSE); TESTFIELD("Cost Amount (Expected)",0); TESTFIELD("Cost Amount (Expected) (ACY)",0); END; IF InvtSetup."Expected Cost Posting to G/L" THEN BEGIN CalcCostToPost(ExpCostToPost,"Cost Amount (Expected)","Expected Cost Posted to G/L",PostToGL); CalcCostToPost(ExpCostToPostACY,"Cost Amount (Expected) (ACY)","Exp. Cost Posted to G/L (ACY)",PostToGL); END; CalcCostToPost(CostToPost,"Cost Amount (Actual)","Cost Posted to G/L",PostToGL); CalcCostToPost(CostToPostACY,"Cost Amount (Actual) (ACY)","Cost Posted to G/L (ACY)",PostToGL); PostBufDimNo := 0; IF NOT PostToGL THEN EXIT(FALSE); CASE "Item Ledger Entry Type" OF "Item Ledger Entry Type"::Purchase: BEGIN CASE "Entry Type" OF "Entry Type"::"Direct Cost": BEGIN IF (ExpCostToPost <> 0) OR (ExpCostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::"Inventory (Interim)", GlobalInvtPostBuf."Account Type"::"Invt. Accrual (Interim)", ExpCostToPost,ExpCostToPostACY,TRUE); IF (CostToPost <> 0) OR (CostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Direct Cost Applied", CostToPost,CostToPostACY,FALSE); END; "Entry Type"::"Indirect Cost": InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Overhead Applied", CostToPost,CostToPostACY,FALSE); "Entry Type"::Variance: BEGIN TESTFIELD("Variance Type","Variance Type"::Purchase); InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Purchase Variance", CostToPost,CostToPostACY,FALSE); END; "Entry Type"::Revaluation: BEGIN IF (ExpCostToPost <> 0) OR (ExpCostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::"Inventory (Interim)", GlobalInvtPostBuf."Account Type"::"Invt. Accrual (Interim)", ExpCostToPost,ExpCostToPostACY,TRUE); IF (CostToPost <> 0) OR (CostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Inventory Adjmt.", CostToPost,CostToPostACY,FALSE); END; "Entry Type"::Rounding: InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Inventory Adjmt.", CostToPost,CostToPostACY,FALSE); ELSE ErrorNonValidCombination(ValueEntry); END; END; "Item Ledger Entry Type"::Sale: BEGIN CASE "Entry Type" OF "Entry Type"::"Direct Cost": BEGIN IF (ExpCostToPost <> 0) OR (ExpCostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::"Inventory (Interim)", GlobalInvtPostBuf."Account Type"::"COGS (Interim)", ExpCostToPost,ExpCostToPostACY,TRUE); IF (CostToPost <> 0) OR (CostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::COGS, CostToPost,CostToPostACY,FALSE); END; "Entry Type"::Revaluation: BEGIN IF (ExpCostToPost <> 0) OR (ExpCostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::"Inventory (Interim)", GlobalInvtPostBuf."Account Type"::"COGS (Interim)", ExpCostToPost,ExpCostToPostACY,TRUE); IF (CostToPost <> 0) OR (CostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Inventory Adjmt.", CostToPost,CostToPostACY,FALSE); END; "Entry Type"::Rounding: InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Inventory Adjmt.", CostToPost,CostToPostACY,FALSE); ELSE ErrorNonValidCombination(ValueEntry); END; END; "Item Ledger Entry Type"::"Positive Adjmt.", "Item Ledger Entry Type"::"Negative Adjmt.", "Item Ledger Entry Type"::Transfer: BEGIN CASE "Entry Type" OF "Entry Type"::"Direct Cost": BEGIN // Posting adjustments to Interim accounts (Service) IF (ExpCostToPost <> 0) OR (ExpCostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::"Inventory (Interim)", GlobalInvtPostBuf."Account Type"::"COGS (Interim)", ExpCostToPost,ExpCostToPostACY,TRUE); IF (CostToPost <> 0) OR (CostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Inventory Adjmt.", CostToPost,CostToPostACY,FALSE); END; "Entry Type"::Revaluation, "Entry Type"::Rounding: InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Inventory Adjmt.", CostToPost,CostToPostACY,FALSE); ELSE ErrorNonValidCombination(ValueEntry); END; END; "Item Ledger Entry Type"::Consumption: BEGIN CASE "Entry Type" OF "Entry Type"::"Direct Cost": InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"WIP Inventory", CostToPost,CostToPostACY,FALSE); "Entry Type"::Revaluation, "Entry Type"::Rounding: InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Inventory Adjmt.", CostToPost,CostToPostACY,FALSE); ELSE ErrorNonValidCombination(ValueEntry); END; END; "Item Ledger Entry Type"::Output: BEGIN CASE "Entry Type" OF "Entry Type"::"Direct Cost": BEGIN IF (ExpCostToPost <> 0) OR (ExpCostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::"Inventory (Interim)", GlobalInvtPostBuf."Account Type"::"WIP Inventory", ExpCostToPost,ExpCostToPostACY,TRUE); IF (CostToPost <> 0) OR (CostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"WIP Inventory", CostToPost,CostToPostACY,FALSE); END; "Entry Type"::"Indirect Cost": InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Overhead Applied", CostToPost,CostToPostACY,FALSE); "Entry Type"::Variance: BEGIN CASE "Variance Type" OF "Variance Type"::Material: InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Material Variance", CostToPost,CostToPostACY,FALSE); "Variance Type"::Capacity: InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Capacity Variance", CostToPost,CostToPostACY,FALSE); "Variance Type"::Subcontracted: InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Subcontracted Variance", CostToPost,CostToPostACY,FALSE); "Variance Type"::"Capacity Overhead": InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Cap. Overhead Variance", CostToPost,CostToPostACY,FALSE); "Variance Type"::"Manufacturing Overhead": InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Mfg. Overhead Variance", CostToPost,CostToPostACY,FALSE); ELSE ErrorNonValidCombination(ValueEntry); END; END; "Entry Type"::Revaluation: BEGIN IF (ExpCostToPost <> 0) OR (ExpCostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::"Inventory (Interim)", GlobalInvtPostBuf."Account Type"::"WIP Inventory", ExpCostToPost,ExpCostToPostACY,TRUE); IF (CostToPost <> 0) OR (CostToPostACY <> 0) THEN InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Inventory Adjmt.", CostToPost,CostToPostACY,FALSE); END; "Entry Type"::Rounding: InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::Inventory, GlobalInvtPostBuf."Account Type"::"Inventory Adjmt.", CostToPost,CostToPostACY,FALSE); ELSE ErrorNonValidCombination(ValueEntry); END; END; "Item Ledger Entry Type"::" ": BEGIN CASE "Entry Type" OF "Entry Type"::"Direct Cost": InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::"WIP Inventory", GlobalInvtPostBuf."Account Type"::"Direct Cost Applied", CostToPost,CostToPostACY,FALSE); "Entry Type"::"Indirect Cost": InitInvtPostBuf( ValueEntry, GlobalInvtPostBuf."Account Type"::"WIP Inventory", GlobalInvtPostBuf."Account Type"::"Overhead Applied", CostToPost,CostToPostACY,FALSE); ELSE ErrorNonValidCombination(ValueEntry); END; END; ELSE ErrorNonValidCombination(ValueEntry); END; END; IF UpdateGlobalInvtPostBuf(ValueEntry."Entry No.") THEN EXIT(TRUE); EXIT(CalledFromTestReport); END;
LOCAL PROCEDURE GetGLSetup(); BEGIN IF NOT GLSetupRead THEN BEGIN GLSetup.GET; IF GLSetup."Additional Reporting Currency" <> '' THEN Currency.GET(GLSetup."Additional Reporting Currency"); END; GLSetupRead := TRUE; END;
LOCAL PROCEDURE GetInvtSetup(); BEGIN IF NOT InvtSetupRead THEN InvtSetup.GET; InvtSetupRead := TRUE; END;
LOCAL PROCEDURE CalcCostToPost(VAR CostToPost : Decimal;AdjdCost : Decimal;VAR PostedCost : Decimal;VAR PostToGL : Boolean); BEGIN CostToPost := AdjdCost - PostedCost; IF CostToPost <> 0 THEN BEGIN IF NOT RunOnlyCheck THEN PostedCost := AdjdCost; PostToGL := TRUE; END; END;
LOCAL PROCEDURE InitInvtPostBuf(ValueEntry : Record 5802 - Value Entry;AccType : Option;BalAccType : Option;CostToPost : Decimal;CostToPostACY : Decimal;InterimAccount : Boolean); BEGIN PostBufDimNo := PostBufDimNo + 1; SetAccNo(TempInvtPostBuf[PostBufDimNo],ValueEntry,AccType,BalAccType); SetPostBufAmounts(TempInvtPostBuf[PostBufDimNo],CostToPost,CostToPostACY,InterimAccount); TempInvtPostBuf[PostBufDimNo]."Job No." := ValueEntry."Job No."; PostBufDimNo := PostBufDimNo + 1; SetAccNo(TempInvtPostBuf[PostBufDimNo],ValueEntry,BalAccType,AccType); SetPostBufAmounts(TempInvtPostBuf[PostBufDimNo],-CostToPost,-CostToPostACY,InterimAccount); TempInvtPostBuf[PostBufDimNo]."Job No." := ValueEntry."Job No."; END;
LOCAL PROCEDURE SetAccNo(VAR InvtPostBuf : Record 48 - Invt. Posting Buffer;ValueEntry : Record 5802 - Value Entry;AccType : Option;BalAccType : Option); VAR InvtPostSetup : Record 5813 - Inventory Posting Setup; GenPostingSetup : Record 252 - General Posting Setup; GLAccount : Record 15 - G/L Account; BEGIN WITH InvtPostBuf DO BEGIN "Account No." := ''; "Account Type" := AccType; "Bal. Account Type" := BalAccType; "Location Code" := ValueEntry."Location Code"; "Inventory Posting Group" := GetInvPostingGroupCode(ValueEntry,AccType = "Account Type"::"WIP Inventory",ValueEntry."Inventory Posting Group"); "Gen. Bus. Posting Group" := ValueEntry."Gen. Bus. Posting Group"; "Gen. Prod. Posting Group" := ValueEntry."Gen. Prod. Posting Group"; "Posting Date" := ValueEntry."Posting Date"; IF UseInvtPostSetup THEN BEGIN IF CalledFromItemPosting THEN InvtPostSetup.GET("Location Code","Inventory Posting Group") ELSE IF NOT InvtPostSetup.GET("Location Code","Inventory Posting Group") THEN EXIT; END ELSE BEGIN IF CalledFromItemPosting THEN GenPostingSetup.GET("Gen. Bus. Posting Group","Gen. Prod. Posting Group") ELSE IF NOT GenPostingSetup.GET("Gen. Bus. Posting Group","Gen. Prod. Posting Group") THEN EXIT; END; CASE "Account Type" OF "Account Type"::Inventory: BEGIN IF CalledFromItemPosting THEN InvtPostSetup.TESTFIELD("Inventory Account"); "Account No." := InvtPostSetup."Inventory Account"; END; "Account Type"::"Inventory (Interim)": BEGIN IF CalledFromItemPosting THEN InvtPostSetup.TESTFIELD("Inventory Account (Interim)"); "Account No." := InvtPostSetup."Inventory Account (Interim)"; END; "Account Type"::"WIP Inventory": BEGIN IF CalledFromItemPosting THEN InvtPostSetup.TESTFIELD("WIP Account"); "Account No." := InvtPostSetup."WIP Account"; END; "Account Type"::"Material Variance": BEGIN IF CalledFromItemPosting THEN InvtPostSetup.TESTFIELD("Material Variance Account"); "Account No." := InvtPostSetup."Material Variance Account"; END; "Account Type"::"Capacity Variance": BEGIN IF CalledFromItemPosting THEN InvtPostSetup.TESTFIELD("Capacity Variance Account"); "Account No." := InvtPostSetup."Capacity Variance Account"; END; "Account Type"::"Subcontracted Variance": BEGIN IF CalledFromItemPosting THEN InvtPostSetup.TESTFIELD("Subcontracted Variance Account"); "Account No." := InvtPostSetup."Subcontracted Variance Account"; END; "Account Type"::"Cap. Overhead Variance": BEGIN IF CalledFromItemPosting THEN InvtPostSetup.TESTFIELD("Cap. Overhead Variance Account"); "Account No." := InvtPostSetup."Cap. Overhead Variance Account"; END; "Account Type"::"Mfg. Overhead Variance": BEGIN IF CalledFromItemPosting THEN InvtPostSetup.TESTFIELD("Mfg. Overhead Variance Account"); "Account No." := InvtPostSetup."Mfg. Overhead Variance Account"; END; "Account Type"::"Inventory Adjmt.": BEGIN IF CalledFromItemPosting THEN GenPostingSetup.TESTFIELD("Inventory Adjmt. Account"); "Account No." := GenPostingSetup."Inventory Adjmt. Account"; END; "Account Type"::"Direct Cost Applied": BEGIN IF CalledFromItemPosting THEN GenPostingSetup.TESTFIELD("Direct Cost Applied Account"); "Account No." := GenPostingSetup."Direct Cost Applied Account"; END; "Account Type"::"Overhead Applied": BEGIN IF CalledFromItemPosting THEN GenPostingSetup.TESTFIELD("Overhead Applied Account"); "Account No." := GenPostingSetup."Overhead Applied Account"; END; "Account Type"::"Purchase Variance": BEGIN IF CalledFromItemPosting THEN GenPostingSetup.TESTFIELD("Purchase Variance Account"); "Account No." := GenPostingSetup."Purchase Variance Account"; END; "Account Type"::COGS: BEGIN IF CalledFromItemPosting THEN GenPostingSetup.TESTFIELD("COGS Account"); "Account No." := GenPostingSetup."COGS Account"; END; "Account Type"::"COGS (Interim)": BEGIN IF CalledFromItemPosting THEN GenPostingSetup.TESTFIELD("COGS Account (Interim)"); "Account No." := GenPostingSetup."COGS Account (Interim)"; END; "Account Type"::"Invt. Accrual (Interim)": BEGIN IF CalledFromItemPosting THEN GenPostingSetup.TESTFIELD("Invt. Accrual Acc. (Interim)"); "Account No." := GenPostingSetup."Invt. Accrual Acc. (Interim)"; END; END; IF "Account No." <> '' THEN BEGIN GLAccount.GET("Account No."); IF GLAccount.Blocked THEN BEGIN IF CalledFromItemPosting THEN GLAccount.TESTFIELD(Blocked,FALSE); IF NOT CalledFromTestReport THEN "Account No." := ''; END; END; END; END;
LOCAL PROCEDURE SetPostBufAmounts(VAR InvtPostBuf : Record 48 - Invt. Posting Buffer;CostToPost : Decimal;CostToPostACY : Decimal;InterimAccount : Boolean); BEGIN WITH InvtPostBuf DO BEGIN "Interim Account" := InterimAccount; Amount := CostToPost; "Amount (ACY)" := CostToPostACY; END; END;
LOCAL PROCEDURE UpdateGlobalInvtPostBuf(ValueEntryNo : Integer) : Boolean; VAR DimEntryNo : Integer; i : Integer; BEGIN WITH GlobalInvtPostBuf DO BEGIN DimEntryNo := GetDimEntryNo(ValueEntryNo); IF NOT CalledFromTestReport THEN FOR i := 1 TO PostBufDimNo DO BEGIN IF TempInvtPostBuf[i]."Account No." = '' THEN BEGIN CLEAR(TempInvtPostBuf); EXIT(FALSE); END; END; FOR i := 1 TO PostBufDimNo DO BEGIN GlobalInvtPostBuf := TempInvtPostBuf[i]; "Dimension Entry No." := DimEntryNo; Negative := (TempInvtPostBuf[i].Amount < 0) OR (TempInvtPostBuf[i]."Amount (ACY)" < 0); UpdateReportAmounts; IF FIND THEN BEGIN Amount := Amount + TempInvtPostBuf[i].Amount; "Amount (ACY)" := "Amount (ACY)" + TempInvtPostBuf[i]."Amount (ACY)"; MODIFY; END ELSE BEGIN GlobalInvtPostBufEntryNo := GlobalInvtPostBufEntryNo + 1; "Entry No." := GlobalInvtPostBufEntryNo; INSERT; END; IF NOT (RunOnlyCheck OR CalledFromTestReport) THEN BEGIN TempGLItemLedgRelation.INIT; TempGLItemLedgRelation."G/L Entry No." := "Entry No."; TempGLItemLedgRelation."Value Entry No." := ValueEntryNo; TempGLItemLedgRelation.INSERT; END; END; END; CLEAR(TempInvtPostBuf); EXIT(TRUE); END;
LOCAL PROCEDURE GetDimEntryNo(ValueEntryNo : Integer) : Integer; VAR LedgEntryDim : Record 355 - Ledger Entry Dimension; TempDimBufIn : TEMPORARY Record 360 - Dimension Buffer; DimEntryNo : Integer; BEGIN WITH LedgEntryDim DO BEGIN SETRANGE("Table ID",DATABASE::"Value Entry"); SETRANGE("Entry No.",ValueEntryNo); IF FIND('-') THEN REPEAT IF NOT TempDimBufIn.GET("Table ID","Entry No.","Dimension Code") THEN BEGIN TempDimBufIn.INIT; TempDimBufIn."Table ID" := "Table ID"; TempDimBufIn."Entry No." := "Entry No."; TempDimBufIn."Dimension Code" := "Dimension Code"; TempDimBufIn."Dimension Value Code" := "Dimension Value Code"; TempDimBufIn.INSERT; END; UNTIL NEXT = 0; END; IF TempDimBufIn.FIND('-') THEN BEGIN DimEntryNo := DimBufMgt.FindDimensions(TempDimBufIn); IF DimEntryNo = 0 THEN DimEntryNo := DimBufMgt.InsertDimensions(TempDimBufIn); END ELSE DimEntryNo := 0; EXIT(DimEntryNo); END;
LOCAL PROCEDURE UpdateReportAmounts(); BEGIN WITH GlobalInvtPostBuf DO BEGIN CASE "Account Type" OF "Account Type"::Inventory,"Account Type"::"Inventory (Interim)": InvtAmt += Amount; "Account Type"::"WIP Inventory": WIPInvtAmt += Amount; "Account Type"::"Inventory Adjmt.": InvtAdjmtAmt += Amount; "Account Type"::"Invt. Accrual (Interim)": InvtAdjmtAmt += Amount; "Account Type"::"Direct Cost Applied": DirCostAmt += Amount; "Account Type"::"Overhead Applied": OvhdCostAmt += Amount; "Account Type"::"Purchase Variance": VarPurchCostAmt += Amount; "Account Type"::COGS: COGSAmt += Amount; "Account Type"::"COGS (Interim)": COGSAmt += Amount; "Account Type"::"Material Variance","Account Type"::"Capacity Variance", "Account Type"::"Subcontracted Variance","Account Type"::"Cap. Overhead Variance": VarMfgDirCostAmt += Amount; "Account Type"::"Mfg. Overhead Variance": VarMfgOvhdCostAmt += Amount; END; END; END;
LOCAL PROCEDURE ErrorNonValidCombination(ValueEntry : Record 5802 - Value Entry); BEGIN WITH ValueEntry DO IF CalledFromTestReport THEN InsertTempInvtPostToGLTestBuf2(ValueEntry) ELSE ERROR( Text002, FIELDCAPTION("Item Ledger Entry Type"),"Item Ledger Entry Type", FIELDCAPTION("Entry Type"),"Entry Type", FIELDCAPTION("Expected Cost"),"Expected Cost") END;
LOCAL PROCEDURE InsertTempInvtPostToGLTestBuf2(ValueEntry : Record 5802 - Value Entry); BEGIN WITH ValueEntry DO BEGIN TempInvtPostToGLTestBuf."Line No." := GetNextLineNo; TempInvtPostToGLTestBuf."Posting Date" := "Posting Date"; TempInvtPostToGLTestBuf.Description := STRSUBSTNO(Text003,TABLECAPTION,"Entry No."); TempInvtPostToGLTestBuf.Amount := "Cost Amount (Actual)"; TempInvtPostToGLTestBuf."Value Entry No." := "Entry No."; TempInvtPostToGLTestBuf.INSERT; END; END;
LOCAL PROCEDURE GetNextLineNo() : Integer; BEGIN IF TempInvtPostToGLTestBuf.FINDLAST THEN EXIT(TempInvtPostToGLTestBuf."Line No." + 10000); EXIT(10000); END;
PROCEDURE PostInvtPostBufPerEntry(VAR ValueEntry : Record 5802 - Value Entry); VAR GenJnlLine : Record 81 - Gen. Journal Line; BEGIN WITH ValueEntry DO BEGIN PostInvtPostBuf( ValueEntry, "Document No.", "External Document No.", COPYSTR( STRSUBSTNO(Text000,"Entry Type","Source No.","Posting Date"), 1,MAXSTRLEN(GenJnlLine.Description)), FALSE); END; END;
PROCEDURE PostInvtPostBufPerPostGrp(DocNo : Code[20];Desc : Text[50]); VAR ValueEntry : Record 5802 - Value Entry; BEGIN PostInvtPostBuf(ValueEntry,DocNo,'',Desc,TRUE); END;
LOCAL PROCEDURE PostInvtPostBuf(VAR ValueEntry : Record 5802 - Value Entry;DocNo : Code[20];ExternalDocNo : Code[20];Desc : Text[50];PostPerPostGrp : Boolean); VAR GenJnlLine : Record 81 - Gen. Journal Line; TempJnlLineDim : TEMPORARY Record 356 - Journal Line Dimension; BEGIN WITH GlobalInvtPostBuf DO BEGIN RESET; IF NOT FINDSET THEN EXIT; GenJnlLine.INIT; GenJnlLine."Document No." := DocNo; GenJnlLine."External Document No." := ExternalDocNo; GenJnlLine.Description := Desc; GetSourceCodeSetup; GenJnlLine."Source Code" := SourceCodeSetup."Inventory Post Cost"; GenJnlLine."System-Created Entry" := TRUE; GenJnlLine."Job No." := "Job No."; REPEAT GenJnlLine.VALIDATE("Posting Date","Posting Date"); IF SetAmt(GenJnlLine,Amount,"Amount (ACY)") THEN BEGIN IF PostPerPostGrp THEN SetDesc(GenJnlLine,GlobalInvtPostBuf); GenJnlLine."Account No." := "Account No."; InsertJnlLineDim(GenJnlLine,TempJnlLineDim,"Dimension Entry No."); IF NOT CalledFromTestReport THEN IF NOT RunOnlyCheck THEN BEGIN IF NOT CalledFromItemPosting THEN GenJnlPostLine.SetOverDimErr; GenJnlPostLine.RunWithCheck(GenJnlLine,TempJnlLineDim) END ELSE GenJnlCheckLine.RunCheck(GenJnlLine,TempJnlLineDim) ELSE InsertTempInvtPostToGLTestBuf(GenJnlLine,TempJnlLineDim,ValueEntry); END; IF NOT CalledFromTestReport AND NOT RunOnlyCheck THEN CreateGLItemLedgRelation(ValueEntry); UNTIL NEXT = 0; DELETEALL; END; END;
LOCAL PROCEDURE GetSourceCodeSetup(); BEGIN IF NOT SourceCodeSetupRead THEN SourceCodeSetup.GET; SourceCodeSetupRead := TRUE; END;
LOCAL PROCEDURE SetAmt(VAR GenJnlLine : Record 81 - Gen. Journal Line;Amt : Decimal;AmtACY : Decimal) : Boolean; BEGIN WITH GenJnlLine DO BEGIN "Additional-Currency Posting" := "Additional-Currency Posting"::None; VALIDATE(Amount,Amt); GetGLSetup; IF GLSetup."Additional Reporting Currency" <> '' THEN BEGIN "Source Currency Code" := GLSetup."Additional Reporting Currency"; "Source Currency Amount" := AmtACY; IF (Amount = 0) AND ("Source Currency Amount" <> 0) THEN BEGIN "Additional-Currency Posting" := "Additional-Currency Posting"::"Additional-Currency Amount Only"; VALIDATE(Amount,"Source Currency Amount"); "Source Currency Amount" := 0; END; END; END; EXIT((Amt <> 0) OR (AmtACY <> 0)); END;
PROCEDURE SetDesc(VAR GenJnlLine : Record 81 - Gen. Journal Line;InvtPostBuf : Record 48 - Invt. Posting Buffer); BEGIN WITH InvtPostBuf DO BEGIN GenJnlLine.Description := COPYSTR( STRSUBSTNO( Text001, "Account Type","Bal. Account Type", "Location Code","Inventory Posting Group", "Gen. Bus. Posting Group","Gen. Prod. Posting Group"), 1,MAXSTRLEN(GenJnlLine.Description)); END; END;
LOCAL PROCEDURE InsertJnlLineDim(VAR GenJnlLine : Record 81 - Gen. Journal Line;VAR TempJnlLineDim : TEMPORARY Record 356 - Journal Line Dimension;DimEntryNo : Integer); VAR TempDimBufOut : TEMPORARY Record 360 - Dimension Buffer; BEGIN DimBufMgt.GetDimensions(DimEntryNo,TempDimBufOut); WITH GenJnlLine DO BEGIN "Shortcut Dimension 1 Code" := ''; "Shortcut Dimension 2 Code" := ''; TempJnlLineDim.DELETEALL; IF TempDimBufOut.FINDSET THEN REPEAT TempJnlLineDim.INIT; TempJnlLineDim."Table ID" := DATABASE::"Gen. Journal Line"; TempJnlLineDim."Journal Template Name" := "Journal Template Name"; TempJnlLineDim."Journal Batch Name" := "Journal Batch Name"; TempJnlLineDim."Journal Line No." := "Line No."; TempJnlLineDim."Allocation Line No." := 0; TempJnlLineDim."Dimension Code" := TempDimBufOut."Dimension Code"; TempJnlLineDim."Dimension Value Code" := TempDimBufOut."Dimension Value Code"; TempJnlLineDim.INSERT; IF TempDimBufOut."Dimension Code" = GLSetup."Shortcut Dimension 1 Code" THEN "Shortcut Dimension 1 Code" := TempDimBufOut."Dimension Value Code"; IF TempDimBufOut."Dimension Code" = GLSetup."Shortcut Dimension 2 Code" THEN "Shortcut Dimension 2 Code" := TempDimBufOut."Dimension Value Code"; UNTIL TempDimBufOut.NEXT = 0 END; END;
LOCAL PROCEDURE InsertTempInvtPostToGLTestBuf(GenJnlLine : Record 81 - Gen. Journal Line;VAR JnlLineDim : Record 356 - Journal Line Dimension;ValueEntry : Record 5802 - Value Entry); BEGIN WITH GenJnlLine DO BEGIN TempInvtPostToGLTestBuf."Line No." := GetNextLineNo; TempInvtPostToGLTestBuf."Posting Date" := "Posting Date"; TempInvtPostToGLTestBuf."Document No." := "Document No."; TempInvtPostToGLTestBuf.Description := Description; TempInvtPostToGLTestBuf."Account No." := "Account No."; TempInvtPostToGLTestBuf.Amount := Amount; TempInvtPostToGLTestBuf."Source Code" := "Source Code"; TempInvtPostToGLTestBuf."System-Created Entry" := TRUE; TempInvtPostToGLTestBuf."Value Entry No." := ValueEntry."Entry No."; TempInvtPostToGLTestBuf."Additional-Currency Posting" := "Additional-Currency Posting"; TempInvtPostToGLTestBuf."Source Currency Code" := "Source Currency Code"; TempInvtPostToGLTestBuf."Source Currency Amount" := "Source Currency Amount"; TempInvtPostToGLTestBuf."Inventory Account Type" := GlobalInvtPostBuf."Account Type"; IF GlobalInvtPostBuf.UseInvtPostSetup THEN BEGIN TempInvtPostToGLTestBuf."Location Code" := GlobalInvtPostBuf."Location Code"; TempInvtPostToGLTestBuf."Invt. Posting Group Code" := GetInvPostingGroupCode( ValueEntry, TempInvtPostToGLTestBuf."Inventory Account Type" = TempInvtPostToGLTestBuf."Inventory Account Type"::"WIP Inventory", GlobalInvtPostBuf."Inventory Posting Group") END ELSE BEGIN TempInvtPostToGLTestBuf."Gen. Bus. Posting Group" := GlobalInvtPostBuf."Gen. Bus. Posting Group"; TempInvtPostToGLTestBuf."Gen. Prod. Posting Group" := GlobalInvtPostBuf."Gen. Prod. Posting Group"; END; TempInvtPostToGLTestBuf.INSERT; END; IF NOT JnlLineDim.FINDSET THEN EXIT; REPEAT TempJnlLineDim2 := JnlLineDim; TempJnlLineDim2."Journal Line No." := TempInvtPostToGLTestBuf."Line No."; TempJnlLineDim2.INSERT; UNTIL JnlLineDim.NEXT = 0; END;
LOCAL PROCEDURE CreateGLItemLedgRelation(VAR ValueEntry : Record 5802 - Value Entry); VAR GLReg : Record 45 - G/L Register; BEGIN GenJnlPostLine.GetGLReg(GLReg); IF GlobalPostPerPostGroup THEN BEGIN TempGLItemLedgRelation.RESET; TempGLItemLedgRelation.SETRANGE("G/L Entry No.",GlobalInvtPostBuf."Entry No."); TempGLItemLedgRelation.FINDSET; REPEAT ValueEntry.GET(TempGLItemLedgRelation."Value Entry No."); UpdateValueEntry(ValueEntry); CreateGLItemLedgRelationEntry(GLReg); UNTIL TempGLItemLedgRelation.NEXT = 0; END ELSE BEGIN UpdateValueEntry(ValueEntry); CreateGLItemLedgRelationEntry(GLReg); END; END;
PROCEDURE CreateGLItemLedgRelationEntry(GLReg : Record 45 - G/L Register); VAR GLItemLedgRelation : Record 5823 - G/L - Item Ledger Relation; BEGIN GLItemLedgRelation.INIT; GLItemLedgRelation."G/L Entry No." := GLReg."To Entry No."; GLItemLedgRelation."Value Entry No." := TempGLItemLedgRelation."Value Entry No."; GLItemLedgRelation."G/L Register No." := GLReg."No."; GLItemLedgRelation.INSERT; TempGLItemLedgRelation."G/L Entry No." := GlobalInvtPostBuf."Entry No."; TempGLItemLedgRelation.DELETE; END;
LOCAL PROCEDURE UpdateValueEntry(VAR ValueEntry : Record 5802 - Value Entry); BEGIN WITH ValueEntry DO BEGIN IF GlobalInvtPostBuf."Interim Account" THEN BEGIN "Expected Cost Posted to G/L" := "Cost Amount (Expected)"; "Exp. Cost Posted to G/L (ACY)" := "Cost Amount (Expected) (ACY)"; END ELSE BEGIN "Cost Posted to G/L" := "Cost Amount (Actual)"; "Cost Posted to G/L (ACY)" := "Cost Amount (Actual) (ACY)"; END; IF NOT CalledFromItemPosting THEN MODIFY; END; END;
PROCEDURE GetTempInvtPostToGLTestBuf(VAR InvtPostToGLTestBuf : Record 5822 - Invt. Post to G/L Test Buffer;VAR JnlLineDim : Record 356 - Journal Line Dimension); BEGIN InvtPostToGLTestBuf.DELETEALL; JnlLineDim.DELETEALL; IF NOT TempInvtPostToGLTestBuf.FINDSET THEN EXIT; REPEAT InvtPostToGLTestBuf := TempInvtPostToGLTestBuf; InvtPostToGLTestBuf.INSERT; UNTIL TempInvtPostToGLTestBuf.NEXT = 0; IF NOT TempJnlLineDim2.FINDSET THEN EXIT; REPEAT JnlLineDim := TempJnlLineDim2; JnlLineDim.INSERT; UNTIL TempJnlLineDim2.NEXT = 0; END;
PROCEDURE GetAmtToPost(VAR NewCOGSAmt : Decimal;VAR NewInvtAdjmtAmt : Decimal;VAR NewDirCostAmt : Decimal;VAR NewOvhdCostAmt : Decimal;VAR NewVarPurchCostAmt : Decimal;VAR NewVarMfgDirCostAmt : Decimal;VAR NewVarMfgOvhdCostAmt : Decimal;VAR NewWIPInvtAmt : Decimal;VAR NewInvtAmt : Decimal;GetTotal : Boolean); BEGIN GetAmt(NewInvtAdjmtAmt,InvtAdjmtAmt,TotalInvtAdjmtAmt,GetTotal); GetAmt(NewDirCostAmt,DirCostAmt,TotalDirCostAmt,GetTotal); GetAmt(NewOvhdCostAmt,OvhdCostAmt,TotalOvhdCostAmt,GetTotal); GetAmt(NewVarPurchCostAmt,VarPurchCostAmt,TotalVarPurchCostAmt,GetTotal); GetAmt(NewVarMfgDirCostAmt,VarMfgDirCostAmt,TotalVarMfgDirCostAmt,GetTotal); GetAmt(NewVarMfgOvhdCostAmt,VarMfgOvhdCostAmt,TotalVarMfgOvhdCostAmt,GetTotal); GetAmt(NewWIPInvtAmt,WIPInvtAmt,TotalWIPInvtAmt,GetTotal); GetAmt(NewCOGSAmt,COGSAmt,TotalCOGSAmt,GetTotal); GetAmt(NewInvtAmt,InvtAmt,TotalInvtAmt,GetTotal); END;
LOCAL PROCEDURE GetAmt(VAR NewAmt : Decimal;VAR Amt : Decimal;VAR TotalAmt : Decimal;GetTotal : Boolean); BEGIN IF GetTotal THEN NewAmt := TotalAmt ELSE BEGIN NewAmt := Amt; TotalAmt := TotalAmt + Amt; Amt := 0; END; END;
PROCEDURE GetInvtPostBuf(VAR InvtPostBuf : Record 48 - Invt. Posting Buffer); BEGIN InvtPostBuf.DELETEALL; GlobalInvtPostBuf.RESET; IF GlobalInvtPostBuf.FINDSET THEN REPEAT InvtPostBuf := GlobalInvtPostBuf; InvtPostBuf.INSERT; UNTIL GlobalInvtPostBuf.NEXT = 0; END;
PROCEDURE GetDimBuf(DimEntryNo : Integer;VAR TempDimBuf : Record 360 - Dimension Buffer); BEGIN TempDimBuf.DELETEALL; DimBufMgt.GetDimensions(DimEntryNo,TempDimBuf); END;
LOCAL PROCEDURE GetInvPostingGroupCode(ValueEntry : Record 5802 - Value Entry;WIPInventory : Boolean;InvPostingGroupCode : Code[10]) : Code[10]; VAR Item : Record 27 - Item; BEGIN IF WIPInventory THEN IF ValueEntry."Source No." <> ValueEntry."Item No." THEN IF Item.GET(ValueEntry."Source No.") THEN EXIT(Item."Inventory Posting Group"); EXIT(InvPostingGroupCode); END;
BEGIN END.


Inventory Posting To G/L - OnRun( VAR Rec : Record 5802 - Value Entry)

VAR
  GenJnlLine : Record 81 - Gen. Journal Line;
BEGIN
  IF GlobalPostPerPostGroup THEN
    PostInvtPostBuf(Rec,"Document No.",'','',TRUE)
  ELSE
    PostInvtPostBuf(
      Rec,
      "Document No.",
      "External Document No.",
      COPYSTR(
        STRSUBSTNO(Text000,"Entry Type","Source No.","Posting Date"),
        1,MAXSTRLEN(GenJnlLine.Description)),
      FALSE);
END;
View
Navigation