Hi Team,
I wrote the below code for reversal which is working fine but after the reverse action it display this “The journal lines were successfully posted. You are now in the TB-0000029 journal.” I want it to display “The journal lines were successfully reversed.” I also wanted to check the Reversed in the G/L entry.
WITH TBill DO BEGIN
IF CONFIRM(Text001+' '+"No."+' ?') = TRUE THEN BEGIN
IF TBill.Reversed THEN
ERROR(Text002,"PFA Name");
CMSetup.GET();
//Delete Lines Present on the General Journal Line
GenJnLine.RESET;
GenJnLine.SETRANGE(GenJnLine."Journal Template Name",CMSetup."Payment Voucher Template");
GenJnLine.SETRANGE(GenJnLine."Journal Batch Name","No.");
GenJnLine.DELETEALL;
Batch.INIT;
IF CMSetup.GET() THEN
Batch."Journal Template Name" := CMSetup."Payment Voucher Template";
Batch.Name := "No.";
IF NOT Batch.GET(Batch."Journal Template Name",Batch.Name) THEN
Batch.INSERT;
Lines.RESET;
Lines.SETRANGE("No.","No.");
IF Lines.FINDSET THEN BEGIN REPEAT //Name: IB, Date:04/09/2019
instrumentNo := COPYSTR(Lines."Instrument No.",1,20);
LineNo := LineNo + 1000;
//Post bank Entries
GenJnLine.INIT;
GenJnLine."Journal Template Name" := CMSetup."Payment Voucher Template";
GenJnLine."Journal Batch Name" := "No.";
GenJnLine."Line No." := LineNo;
GenJnLine."Account Type" := GenJnLine."Account Type"::"G/L Account";
IF InvestmentAccountSetup.GET(PFA,Fund,"Type of Investment") THEN
GenJnLine."Account No." := InvestmentAccountSetup."Asset Account";
GenJnLine."Posting Date" := Lines."Settlement Date";
GenJnLine."Document No." := instrumentNo;
GenJnLine.Description := Lines."Bill Series Code";
GenJnLine.Amount := -Lines.Consideration;
GenJnLine.VALIDATE(GenJnLine.Amount);
GenJnLine."Bal. Account Type" := GenJnLine."Bal. Account Type"::"Bank Account";
GenJnLine.VALIDATE("Bal. Account No.","Bank Account");
GenJnLine."External Document No." := "No.";
GenJnLine.VALIDATE(GenJnLine."Shortcut Dimension 1 Code",PFA);
GenJnLine.VALIDATE(GenJnLine."Shortcut Dimension 2 Code",Fund);
IF GenJnLine.Amount <> 0 THEN
GenJnLine.INSERT;
UNTIL Lines.NEXT = 0;
END;
CODEUNIT.RUN(CODEUNIT::"Gen. Jnl.-Post",GenJnLine); // This is what is doing it.
GLEntry.RESET;
GLEntry.SETRANGE(GLEntry."Journal Batch Name","No.");
GLEntry.SETRANGE(GLEntry.Reversed,FALSE);
IF GLEntry.FINDFIRST THEN BEGIN
Lines.RESET;
Lines.SETRANGE("No.","No.");
IF Lines.FINDSET THEN BEGIN REPEAT
IF Lines."Transaction Type" = Lines."Transaction Type"::Buy THEN BEGIN
//Ledger
//Reverse Previous Values
TBillLedger.RESET;
TBillLedger.SETRANGE("Bill Series Code",Lines."Bill Series Code");
TBillLedger.SETRANGE(PFA,PFA);
TBillLedger.SETRANGE(Fund,Fund);
TBillLedger.SETRANGE("Instrument No.",Lines."Instrument No.");
IF TBillLedger.FINDSET THEN
TBillLedger.MODIFYALL(Reversed,TRUE,TRUE);
TBillLedgerOld.RESET;
IF TBillLedgerOld.FINDLAST THEN
EntryNo := TBillLedgerOld."Entry No" +1
ELSE
EntryNo := 1;
TBillLedger.INIT;
TBillLedger."Entry No" := EntryNo;
TBillLedger.VALIDATE("Bill Series Code",Lines."Bill Series Code");
TBillLedger.PFA := Lines.PFA;
TBillLedger.Fund := Lines.Fund;
TBillLedger.VALIDATE("Instrument No.",Lines."Instrument No.");
TBillLedger."Transaction Type" := TBillLedger."Transaction Type"::Acquisition;
TBillLedger.Consideration := -Lines.Consideration;
TBillLedger."Face Value" := -Lines.Principal;
TBillLedger."Discounted Value" := -Lines."Discounted Amount";
TBillLedger."Trade Date" := Lines."Trade Date";
TBillLedger.VALIDATE("Value Date",Lines."Trade Date");
TBillLedger.Reversed := TRUE;
TBillLedger."Reversed By" := USERID;
TBillLedger."Reversed Date" := TODAY;
TBillLedger.INSERT(TRUE);
//TBill Investment
//Delete Previous Values
TBills.RESET;
TBills.SETRANGE("Bill Series Code",Lines."Bill Series Code");
TBills.SETRANGE(PFA,PFA);
TBills.SETRANGE(Fund,Fund);
TBills.SETRANGE("Transaction No.",Lines."Instrument No.");
IF TBills.FINDSET THEN
TBills.DELETEALL;
END;
UNTIL Lines.NEXT = 0;
COMMIT;
END;
Reversed := TRUE;
"Reversed By" := USERID;
"Reversed Date" := TODAY;
MODIFY;
END;
END;
END;
//End
Thanks.