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.
admin1
December 12, 2018, 7:06pm
3
I thought it was just me who needed new glasses. [emoticon:4191f5ee34e248a29fa0dbe8d975f74a]
1.) The picture was small due to requirement size upload which 320 by 240.
2.) "GenJnLine.“Account Type”::“Bank Account” It has been commented out from the code with {}
3.) Thanks.
I think the picture is better now. Thanks
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
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 BEGIN
GenJnLine.Amount := JVLines.Debit;
GenJnLine.VALIDATE(Amount)
END 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 BEGIN
GenJnLine.Amount := -JVLines.Debit;
GenJnLine.VALIDATE(Amount)
END 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;
That is the update code above. And the error message below:
Its sum up both the total debit and total credit together instead of posting them into their accounts
if I understood correctly (picture is too small to catch data) you have 2 fields - Debit and Credit and we have value in the either Debit or Credit.
first you need to define where is Amount - something like:
If Debit = 0 then SourceAmount := Credit else SourceAmount = Debit.
the result - you receive just 1 Amount field only and you need to create 2 lines (like below) in this temporary CU:
LineNo := 10000;
GenJnLine.INIT;
GenJnLine.“Journal Template Name” := ‘PAYMENT’;
GenJnLine.“Journal Batch Name” := ‘GENERAL’;
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);
GenJnLine.VALIDATE(Amount, SourceAmount);
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
LineNo := LineNo + 10000;
GenJnLine.INIT;
GenJnLine.“Journal Template Name” := ‘PAYMENT’;
GenJnLine.“Journal Batch Name” := ‘GENERAL’;
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);
GenJnLine.VALIDATE(Amount, -SourceAmount);
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”);
GenJnLine.INSERT;
The total Balance of the Journal should be 0.
Next, post these 2 lines and see correctness of posting.
if posting wrong just change SourceAmount calculation condition like (for example):
If Debit = 0 then SourceAmount := -Credit else SourceAmount = -Debit.
main point - you need to find right conditions for SourceAmount calculation.
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
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" := JV.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;
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;
Its working fine now,
Thank you all.
PalleA
January 7, 2019, 5:40pm
9
Your code might be working - BUT there are probably several issues you should consider when coding stuff like this
You do not need two lines in order to post something in debit and credit - it can be done in one line in GenJnlLine.
Line 4+5 is nonsense there is no need to ask a user if he/she whants to post something and then raise an error if it is already posted.
Line 8 should also be executed before the confirm dialog
If you want to post a number of lines you should use GenJnlLine as tempoary and therefore lines 12-15 and more are not needed
Your GLEntry record with a RESET is not good. When you do Reset alle filteres are removed and you switch to the primary key which is Entry No. When you then do a filtering it is SLOW and you cannot be sure that you get the right record.
Line 51-52 needs more filtering on GLEntries, because the same document no can be used on many different records.
7)Line 53 is wrong - When you use FINDFIRST you should ALWAYS use parameters.
And there are more issues.
You have probably been doing development in another language, but CAL/AL is VERY different from other programming languges.
I am sorry to say but looking at your code tells me that you really should ask for an instructor based development training course.
[mention:74275055534c437ab13054c27a1ed5fb:e9ed411860ed4f2ba0265705b8793d05]
I think you want to say for FINDSET not FINDFIRST [emoticon:c4563cd7d5574777a71c318021cbbcc8]