Printing a report for the current document no. in general journal lines
-
Printing a report for the current document no. in general journal lines
Hello guys,
I have a case in Gen. Journal Line (81), page: Fisc. Payment Journal (61122, Worksheet) when clicking an Post and Print button in the ribbon, it posts the current general journal lines and it also generates an Payment report that prints all the posted general journal lines historically ever posted and not just the prints it for the current document no currently posting. Below you can find the code that does this. NOTE: this code acts like standard code and I do not have access to edit it, so whatever I do I need to work on extensions or new files.
action(“Post and &Print”)
{
ApplicationArea = Basic, Suite;
Caption = ‘Post and &Print’;
Image = PostPrint;
Promoted = true;
PromotedCategory = Category8;
PromotedIsBig = true;
ShortCutKey = ‘Shift+F9’;
ToolTip = ‘Finalize and prepare to print the document or journal. The values and quantities are posted to the related accounts. A report request window where you can specify what to include on the print-out.’;
trigger OnAction()
begin
CODEUNIT.Run(CODEUNIT::”Gen. Jnl.-Post+Print”, Rec);
CurrentJnlBatchName := GetRangeMax(“Journal Batch Name”);
SetJobQueueVisibility();
CurrPage.Update(false);
end;
}
[EventSubscriber(ObjectType::Codeunit, Codeunit::”Batch Posting Print Mgt.”, ‘OnBeforeGLRegPostingReportPrint’, ”, true, true)]
local procedure “Batch Posting Print Mgt._OnBeforeGLRegPostingReportPrint”(var ReportID: Integer; ReqWindow: Boolean; SystemPrinter: Boolean; var GLRegister: Record “G/L Register”; var Handled: Boolean
)
var
GeneralLedgerEntries: Record “G/L Entry”;
BankAccountLedgerEntriesAmount: Record “Bank Account Ledger Entry”;
BankAccountLedgerEntriesAmountNegative: Record “Bank Account Ledger Entry”;
R1: Report “DTI Payment from Bank”;
R2: Report “DTI Cash Mandate from Bank”;
SelectionMngt: Codeunit SelectionFilterManagement;
RecRef: RecordRef;
LastDocumentNo: Code[20];
TotalDocumentNo: Text;
TotalPostingDate: Text;
TotalPostingDateDate: Date;
begin
Clear(LastDocumentNo);
Clear(TotalDocumentNo);
Clear(TotalPostingDate);
GeneralLedgerEntries.Reset();
GeneralLedgerEntries.SetFilter(“Entry No.”, ‘%1..%2’, GLRegister.”From Entry No.”, GLRegister.”To Entry No.”);
GeneralLedgerEntries.SetCurrentKey(“Document No.”);
GeneralLedgerEntries.Ascending();
if GeneralLedgerEntries.FindSet() then begin
Clear(RecRef);
RecRef.GetTable(GeneralLedgerEntries);
Evaluate(TotalPostingDateDate, SelectionMngt.GetSelectionFilter(RecRef, GeneralLedgerEntries.FieldNo(“Posting Date”)));
BankAccountLedgerEntriesAmount.Reset();
BankAccountLedgerEntriesAmount.SetFilter(“Document No.”, SelectionMngt.GetSelectionFilter(RecRef, GeneralLedgerEntries.FieldNo(“Document No.”)));
BankAccountLedgerEntriesAmount.SetFilter(“Posting Date”, ‘%1’, TotalPostingDateDate);
BankAccountLedgerEntriesAmountNegative.Copy(BankAccountLedgerEntriesAmount);
BankAccountLedgerEntriesAmount.SetFilter(Amount, ‘>%1’, 0);
if BankAccountLedgerEntriesAmount.FindSet() then begin
Clear(RecRef);
RecRef.GetTable(BankAccountLedgerEntriesAmount);
R1.setDocNoFilter(SelectionMngt.GetSelectionFilter(RecRef, BankAccountLedgerEntriesAmount.FieldNo(“Entry No.”)), ”);
Report.Print(Report::”R1″, ”);
end;
BankAccountLedgerEntriesAmountNegative.Copy(BankAccountLedgerEntriesAmount);
BankAccountLedgerEntriesAmountNegative.SetFilter(Amount, ‘<%1’, 0);
if BankAccountLedgerEntriesAmountNegative.FindSet() then begin
Clear(RecRef);
RecRef.GetTable(BankAccountLedgerEntriesAmountNegative);
R2.setDocNoFilter(SelectionMngt.GetSelectionFilter(RecRef, R2.FieldNo(“Entry No.”)), ”);
Report.Print(Report::”R2 ”);
end;
Handled := true;
end;
end;
How do I make it that when clicking the button, to make it possible to print the report first for the current document no. posting and the continue to post the lines. I thought to do it on an event subscriber [EventSubscriber(ObjectType::Codeunit, Codeunit::”Gen. Jnl.-Post+Print”, ‘OnBeforePostJournalBatch’, ”, true, true)] but i am not sure if this is the right approach, any ideas?
THANK YOU IN ADVANCE š
Log in to reply.