Error message while posting the debit value and credit value into each account in NAV 2018

Hi Team,

I am trying to post into G/L Entry table but I was getting this error message of the sum of total debit and total credit out of balance instead of going into the separating account has mapped in the line document.

Below are my page and code;

IF CONFIRM(Text002+' '+JV."No."+' ?') = TRUE THEN BEGIN
  {IF JV.Status <> JV.Status::Released THEN
    ERROR(Text003,JV."No.");}
  IF JV.Posted THEN
    ERROR(Text004,JV."No.");

  //JV.TESTFIELD("Paying Bank Account");
  JV.TESTFIELD(Date);

  CMSetup.GET();
  //Delete Lines Present on the General Journal Line
  GenJnLine.RESET;
  GenJnLine.SETRANGE("Journal Template Name",CMSetup."Journal Voucher Template");
  GenJnLine.SETRANGE("Journal Batch Name",JV."No.");
  GenJnLine.DELETEALL;

  Batch.INIT;
  IF CMSetup.GET() THEN
    Batch."Journal Template Name" := CMSetup."Journal Voucher Template";
    Batch.Name := JV."No.";
    IF NOT Batch.GET(Batch."Journal Template Name",Batch.Name) THEN
      Batch.INSERT;

    //Post the Lines
    JVLines.SETRANGE(No,JV."No.");
    IF JVLines.FINDFIRST THEN BEGIN REPEAT

    //Post Bank Entries
    {LineNo := LineNo + 1000;
    GenJnLine.INIT;
    GenJnLine."Journal Template Name" := CMSetup."Journal Voucher Template";
    GenJnLine."Journal Batch Name" := JV."No.";
    GenJnLine."Line No." := LineNo;
    GenJnLine."Account Type" := GenJnLine."Account Type"::"Bank Account";
    GenJnLine."Account No." := JV."Paying Bank Account";
    GenJnLine."Posting Date" := JVLines.Date;
    GenJnLine."Document No." := JV."No.";
    GenJnLine.Description := COPYSTR(JVLines.Description,1,50);
    IF JVLines.Debit <> 0 THEN
      GenJnLine.Amount := JVLines.Debit
    ELSE
      GenJnLine.Amount := -JVLines.Credit;
    GenJnLine.VALIDATE(Amount);
    GenJnLine.VALIDATE("Shortcut Dimension 1 Code",JV."Global Dimension 1 Code");
    GenJnLine.VALIDATE("Shortcut Dimension 2 Code",JV."Global Dimension 2 Code");
    GenJnLine.VALIDATE("Shortcut Dimension 3 Code",JV."Global Dimension 3 Code");
    IF GenJnLine.Amount <> 0 THEN
      GenJnLine.INSERT;}
      //Debit post
    IF (JVLines.Debit = 0) THEN BEGIN
    LineNo := LineNo + 1000;
    GenJnLine.INIT;
    GenJnLine."Journal Template Name" := CMSetup."Journal Voucher Template";
    GenJnLine."Journal Batch Name" := JV."No.";
    GenJnLine."Line No." := LineNo;
    GenJnLine."Account Type" := GenJnLine."Account Type"::"G/L Account";
    GenJnLine."Account No." := JVLines."Account No";
    GenJnLine."Posting Date" := JVLines.Date;
    GenJnLine."Document No." := JV."No.";
    GenJnLine.Description := COPYSTR(JVLines.Description,1,50);
    IF JVLines.Debit <> 0 THEN
      GenJnLine.Amount := JVLines.Debit
    ELSE
      GenJnLine.Amount := -JVLines.Credit;
    GenJnLine.VALIDATE(Amount);
    GenJnLine.VALIDATE("Shortcut Dimension 1 Code",JV."Global Dimension 1 Code");
    GenJnLine.VALIDATE("Shortcut Dimension 2 Code",JV."Global Dimension 2 Code");
    GenJnLine.VALIDATE("Shortcut Dimension 3 Code",JV."Global Dimension 3 Code");
    IF GenJnLine.Amount <> 0 THEN
      GenJnLine.INSERT;
    //Balancing Account
     {LineNo := LineNo + 1000;
    GenJnLine.INIT;
    GenJnLine."Journal Template Name" := CMSetup."Journal Voucher Template";
    GenJnLine."Journal Batch Name" := JV."No.";
    GenJnLine."Line No." := LineNo;
    //GenJnLine."Account Type" := GenJnLine."Account Type"::"G/L Account";
    GenJnLine."Account Type" := GenJnLine."Bal. Account Type";
    GenJnLine."Account No." := JVLines."Account No";
    GenJnLine."Posting Date" := JVLines.Date;
    GenJnLine."Document No." := JV."No.";
    GenJnLine.Description := COPYSTR(JVLines.Description,1,50);
    IF JVLines.Debit <> 0 THEN
      GenJnLine.Amount := -JVLines.Debit
    ELSE
      GenJnLine.Amount := JVLines.Credit;
    GenJnLine.VALIDATE(Amount);
    GenJnLine.VALIDATE("Shortcut Dimension 1 Code",JV."Global Dimension 1 Code");
    GenJnLine.VALIDATE("Shortcut Dimension 2 Code",JV."Global Dimension 2 Code");
    GenJnLine.VALIDATE("Shortcut Dimension 3 Code",JV."Global Dimension 3 Code");
    IF GenJnLine.Amount <> 0 THEN
      GenJnLine.INSERT;}
      END ELSE IF (JVLines.Debit <> 0) THEN BEGIN
      //Credit post
    LineNo := LineNo + 1000;
    GenJnLine.INIT;
    GenJnLine."Journal Template Name" := CMSetup."Journal Voucher Template";
    GenJnLine."Journal Batch Name" := JV."No.";
    GenJnLine."Line No." := LineNo;
    GenJnLine."Account Type" := GenJnLine."Account Type"::"G/L Account";
    GenJnLine."Account No." := JVLines."Account No";
    GenJnLine."Posting Date" := JVLines.Date;
    GenJnLine."Document No." := JV."No.";
    GenJnLine.Description := COPYSTR(JVLines.Description,1,50);
    IF JVLines.Debit <> 0 THEN
      GenJnLine.Amount := -JVLines.Debit
    ELSE
      GenJnLine.Amount := JVLines.Credit;
    GenJnLine.VALIDATE(Amount);
    GenJnLine.VALIDATE("Shortcut Dimension 1 Code",JV."Global Dimension 1 Code");
    GenJnLine.VALIDATE("Shortcut Dimension 2 Code",JV."Global Dimension 2 Code");
    GenJnLine.VALIDATE("Shortcut Dimension 3 Code",JV."Global Dimension 3 Code");
    IF GenJnLine.Amount <> 0 THEN
      GenJnLine.INSERT;
    //Balancing Account
     {LineNo := LineNo + 1000;
    GenJnLine.INIT;
    GenJnLine."Journal Template Name" := CMSetup."Journal Voucher Template";
    GenJnLine."Journal Batch Name" := JV."No.";
    GenJnLine."Line No." := LineNo;
    //GenJnLine."Account Type" := GenJnLine."Account Type"::"G/L Account";
    GenJnLine."Account Type" := GenJnLine."Bal. Account Type";
    GenJnLine."Account No." := JVLines."Account No";
    GenJnLine."Posting Date" := JVLines.Date;
    GenJnLine."Document No." := JV."No.";
    GenJnLine.Description := COPYSTR(JVLines.Description,1,50);
    IF JVLines.Debit <> 0 THEN
      GenJnLine.Amount := JVLines.Debit
    ELSE
      GenJnLine.Amount := -JVLines.Credit;
    GenJnLine.VALIDATE(Amount);
    GenJnLine.VALIDATE("Shortcut Dimension 1 Code",JV."Global Dimension 1 Code");
    GenJnLine.VALIDATE("Shortcut Dimension 2 Code",JV."Global Dimension 2 Code");
    GenJnLine.VALIDATE("Shortcut Dimension 3 Code",JV."Global Dimension 3 Code");
    IF GenJnLine.Amount <> 0 THEN
      GenJnLine.INSERT;}


    END;
    UNTIL JVLines.NEXT = 0;
   END;
   CODEUNIT.RUN(CODEUNIT::"Gen. Jnl.-Post",GenJnLine);
   GLEntry.RESET;
   GLEntry.SETRANGE(GLEntry."Document No.",JV."No.");
   GLEntry.SETRANGE(GLEntry.Reversed,FALSE);
   IF GLEntry.FINDFIRST THEN BEGIN
     JV.Posted := TRUE;
     JV."Posted By" := USERID;
     JV."Posted Date" := TODAY;
     JV.MODIFY;
   END;
END;

Thanks.

Related
Recommended