Report 6646 Sales - Return Receipt
src/Layers/W1/BaseApp/Sales/History/SalesReturnReceipt.Report.al678 lines, Copyright (c) Microsoft Corporation. MIT
// ------------------------------------------------------------------------------------------------// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the MIT License. See License.txt in the project root for license information.// ------------------------------------------------------------------------------------------------namespace Microsoft.Sales.History;using Microsoft.CRM.Contact;using Microsoft.CRM.Interaction;using Microsoft.CRM.Segment;using Microsoft.CRM.Team;using Microsoft.Finance.Dimension;using Microsoft.Foundation.Address;using Microsoft.Foundation.Company;using Microsoft.Inventory.Location;using Microsoft.Sales.Customer;using Microsoft.Sales.Setup;using Microsoft.Utilities;using System.Email;using System.Globalization;using System.Utilities;/// <summary>/// Generates a printable document for posted sales return receipts showing items received from customers./// </summary>report 6646 "Sales - Return Receipt"{ Caption = 'Sales - Return Receipt'; DefaultRenderingLayout = "SalesReturnReceipt.rdlc"; WordMergeDataItem = "Return Receipt Header"; dataset { dataitem("Return Receipt Header"; "Return Receipt Header") { DataItemTableView = sorting("No."); RequestFilterFields = "No.", "Sell-to Customer No.", "No. Printed"; RequestFilterHeading = 'Posted Return Receipt'; column(No_ReturnRcptHeader; "No.") { } column(SellToContactPhoneNoLbl; SellToContactPhoneNoLbl) { } column(SellToContactMobilePhoneNoLbl; SellToContactMobilePhoneNoLbl) { } column(SellToContactEmailLbl; SellToContactEmailLbl) { } column(BillToContactPhoneNoLbl; BillToContactPhoneNoLbl) { } column(BillToContactMobilePhoneNoLbl; BillToContactMobilePhoneNoLbl) { } column(BillToContactEmailLbl; BillToContactEmailLbl) { } column(SellToContactPhoneNo; SellToContact."Phone No.") { } column(SellToContactMobilePhoneNo; SellToContact."Mobile Phone No.") { } column(SellToContactEmail; SellToContact."E-Mail") { } column(BillToContactPhoneNo; BillToContact."Phone No.") { } column(BillToContactMobilePhoneNo; BillToContact."Mobile Phone No.") { } column(BillToContactEmail; BillToContact."E-Mail") { } dataitem(CopyLoop; "Integer") { DataItemTableView = sorting(Number); dataitem(PageLoop; "Integer") { DataItemTableView = sorting(Number) where(Number = const(1)); column(CompanyInfo1Picture; CompanyInfo1.Picture) { } column(CompanyInfo2Picture; CompanyInfo2.Picture) { } column(CompanyInfo3Picture; CompanyInfo3.Picture) { } column(SalesReturnRcptCopyText; StrSubstNo(Text002, CopyText)) { } column(ShipToAddr1; ShipToAddr[1]) { } column(CompanyAddr1; CompanyAddr[1]) { } column(ShipToAddr2; ShipToAddr[2]) { } column(CompanyAddr2; CompanyAddr[2]) { } column(ShipToAddr3; ShipToAddr[3]) { } column(CompanyAddr3; CompanyAddr[3]) { } column(ShipToAddr4; ShipToAddr[4]) { } column(CompanyAddr4; CompanyAddr[4]) { } column(ShipToAddr5; ShipToAddr[5]) { } column(CompanyInfoPhoneNo; CompanyInfo."Phone No.") { } column(ShipToAddr6; ShipToAddr[6]) { } column(CompanyInfoVATRegNo; CompanyInfo."VAT Registration No.") { } column(CompanyInfoHomePage; CompanyInfo."Home Page") { } column(CompanyInfoEmail; CompanyInfo."E-Mail") { } column(CompanyInfoGiroNo; CompanyInfo."Giro No.") { } column(CompanyInfoBankName; CompanyInfo."Bank Name") { } column(CompanyInfoBankAccountNo; CompanyInfo."Bank Account No.") { } column(SellCustNo_ReturnRcptHdr; "Return Receipt Header"."Sell-to Customer No.") { } column(SellCustNo_ReturnRcptHdrCaption; "Return Receipt Header".FieldCaption("Sell-to Customer No.")) { } column(DocDate_ReturnRcptHeader; Format("Return Receipt Header"."Document Date", 0, 4)) { } column(SalesPersonText; SalesPersonText) { } column(SalesPurchPersonName; SalesPurchPerson.Name) { } column(No1_ReturnRcptHeader; "Return Receipt Header"."No.") { } column(ReferenceText; ReferenceText) { } column(YourRef_ReturnRcptHeader; "Return Receipt Header"."Your Reference") { } column(ShipToAddr7; ShipToAddr[7]) { } column(ShipToAddr8; ShipToAddr[8]) { } column(CompanyAddr5; CompanyAddr[5]) { } column(CompanyAddr6; CompanyAddr[6]) { } column(CompanyAddr7; CompanyAddr[7]) { } column(CompanyAddr8; CompanyAddr[8]) { } column(ShptDt_ReturnRcptHeader; Format("Return Receipt Header"."Shipment Date")) { } column(OutputNo; OutputNo) { } column(PageCaption; StrSubstNo(Text003, '')) { } column(CompanyInfoPhoneNoCaption; CompanyInfoPhoneNoCaptionLbl) { } column(CompanyInfoVATRegNoCptn; CompanyInfoVATRegNoCptnLbl) { } column(CompanyInfoGiroNoCaption; CompanyInfoGiroNoCaptionLbl) { } column(CompanyInfoBankNameCptn; CompanyInfoBankNameCptnLbl) { } column(CompanyInfoBankAccNoCptn; CompanyInfoBankAccNoCptnLbl) { } column(ReturnReceiptHeaderNoCptn; ReturnReceiptHeaderNoCptnLbl) { } column(ReturnRcptHdrShptDtCptn; ReturnRcptHdrShptDtCptnLbl) { } column(DocumentDateCaption; DocumentDateCaptionLbl) { } column(HomePageCaption; HomePageCaptionLbl) { } column(EmailCaption; EmailCaptionLbl) { } dataitem(DimensionLoop1; "Integer") { DataItemLinkReference = "Return Receipt Header"; DataItemTableView = sorting(Number) where(Number = filter(1 ..)); column(DimText; DimText) { } column(DimensionLoop1Number; Number) { } column(HeaderDimensionsCaption; HeaderDimensionsCaptionLbl) { } trigger OnAfterGetRecord() begin if Number = 1 then begin if not DimSetEntry1.FindSet() then CurrReport.Break(); end else if not Continue then CurrReport.Break(); Clear(DimText); Continue := false; repeat OldDimText := DimText; if DimText = '' then DimText := StrSubstNo('%1 - %2', DimSetEntry1."Dimension Code", DimSetEntry1."Dimension Value Code") else DimText := StrSubstNo( '%1; %2 - %3', DimText, DimSetEntry1."Dimension Code", DimSetEntry1."Dimension Value Code"); if StrLen(DimText) > MaxStrLen(OldDimText) then begin DimText := OldDimText; Continue := true; exit; end; until DimSetEntry1.Next() = 0; end; trigger OnPreDataItem() begin if not ShowInternalInfo then CurrReport.Break(); end; } dataitem("Return Receipt Line"; "Return Receipt Line") { DataItemLink = "Document No." = field("No."); DataItemLinkReference = "Return Receipt Header"; DataItemTableView = sorting("Document No.", "Line No."); column(ShowInternalInfo; ShowInternalInfo) { } column(TypeInt; TypeInt) { } column(Desc_ReturnReceiptLine; Description) { } column(UOM_ReturnReceiptLine; "Unit of Measure") { } column(Qty_ReturnReceiptLine; Quantity) { } column(No_ReturnReceiptLine; "No.") { } column(UOM_ReturnReceiptLineCaption; FieldCaption("Unit of Measure")) { } column(Qty_ReturnReceiptLineCaption; FieldCaption(Quantity)) { } column(Desc_ReturnReceiptLineCaption; FieldCaption(Description)) { } column(No_ReturnReceiptLineCaption; FieldCaption("No.")) { } column(LineNo_ReturnReceiptLine; "Line No.") { } dataitem(DimensionLoop2; "Integer") { DataItemTableView = sorting(Number) where(Number = filter(1 ..)); column(DimText1; DimText) { } column(DimensionLoop2Number; Number) { } column(LineDimensionsCaption; LineDimensionsCaptionLbl) { } trigger OnAfterGetRecord() begin if Number = 1 then begin if not DimSetEntry2.FindSet() then CurrReport.Break(); end else if not Continue then CurrReport.Break(); Clear(DimText); Continue := false; repeat OldDimText := DimText; if DimText = '' then DimText := StrSubstNo('%1 - %2', DimSetEntry2."Dimension Code", DimSetEntry2."Dimension Value Code") else DimText := StrSubstNo( '%1; %2 - %3', DimText, DimSetEntry2."Dimension Code", DimSetEntry2."Dimension Value Code"); if StrLen(DimText) > MaxStrLen(OldDimText) then begin DimText := OldDimText; Continue := true; exit; end; until DimSetEntry2.Next() = 0; end; trigger OnPreDataItem() begin if not ShowInternalInfo then CurrReport.Break(); end; } trigger OnAfterGetRecord() begin if (not ShowCorrectionLines) and Correction then CurrReport.Skip(); DimSetEntry2.SetRange("Dimension Set ID", "Dimension Set ID"); TypeInt := Type.AsInteger(); end; trigger OnPreDataItem() begin MoreLines := Find('+'); while MoreLines and (Description = '') and ("No." = '') and (Quantity = 0) do MoreLines := Next(-1) <> 0; if not MoreLines then CurrReport.Break(); SetFilter("Line No.", '<=%1', "Line No."); end; } dataitem(Total; "Integer") { DataItemTableView = sorting(Number) where(Number = const(1)); } dataitem(Total2; "Integer") { DataItemTableView = sorting(Number) where(Number = const(1)); column(BilltoCustNo_ReturnRcptHdr; "Return Receipt Header"."Bill-to Customer No.") { } column(CustAddr1; CustAddr[1]) { } column(CustAddr2; CustAddr[2]) { } column(CustAddr3; CustAddr[3]) { } column(CustAddr4; CustAddr[4]) { } column(CustAddr5; CustAddr[5]) { } column(CustAddr6; CustAddr[6]) { } column(CustAddr7; CustAddr[7]) { } column(CustAddr8; CustAddr[8]) { } column(BilltoAddressCaption; BilltoAddressCaptionLbl) { } trigger OnPreDataItem() begin if not ShowCustAddr then CurrReport.Break(); end; } } trigger OnAfterGetRecord() begin if Number > 1 then begin CopyText := FormatDocument.GetCOPYText(); OutputNo += 1; end; end; trigger OnPostDataItem() begin if not IsReportInPreviewMode() then CODEUNIT.Run(CODEUNIT::"Return Receipt - Printed", "Return Receipt Header"); end; trigger OnPreDataItem() begin NoOfLoops := 1 + Abs(NoOfCopies); CopyText := ''; SetRange(Number, 1, NoOfLoops); OutputNo := 1; end; } trigger OnAfterGetRecord() var Language: Codeunit Language; begin CurrReport.Language := Language.GetLanguageIdOrDefault("Language Code"); CurrReport.FormatRegion := Language.GetFormatRegionOrDefault("Format Region"); FormatAddr.SetLanguageCode("Language Code"); FormatAddressFields("Return Receipt Header"); FormatDocumentFields("Return Receipt Header"); if SellToContact.Get("Sell-to Contact No.") then; if BillToContact.Get("Bill-to Contact No.") then; DimSetEntry1.SetRange("Dimension Set ID", "Dimension Set ID"); end; trigger OnPostDataItem() begin OnAfterPostDataItem("Return Receipt Header"); end; } } requestpage { SaveValues = true; layout { area(content) { group(Options) { Caption = 'Options'; field(NoOfCopies; NoOfCopies) { ApplicationArea = SalesReturnOrder; Caption = 'No. of Copies'; ToolTip = 'Specifies how many copies of the document to print.'; } field(ShowInternalInfo; ShowInternalInfo) { ApplicationArea = SalesReturnOrder; Caption = 'Show Internal Information'; ToolTip = 'Specifies if you want the printed report to show information that is only for internal use.'; } field(ShowCorrectionLines; ShowCorrectionLines) { ApplicationArea = SalesReturnOrder; Caption = 'Show Correction Lines'; ToolTip = 'Specifies if the correction lines of an undoing of quantity posting will be shown on the report.'; } field(LogInteraction; LogInteraction) { ApplicationArea = SalesReturnOrder; Caption = 'Log Interaction'; Enabled = LogInteractionEnable; ToolTip = 'Specifies if you want the program to record the sales return receipts you print as Interactions and add them to the Interaction Log Entry table.'; } } } } actions { } trigger OnInit() begin InitLogInteraction(); LogInteractionEnable := LogInteraction; end; } rendering { layout("SalesReturnReceipt.rdlc") { Type = RDLC; LayoutFile = './Sales/History/SalesReturnReceipt.rdlc'; Caption = 'Standard Sales Return Receipt (RDLC)'; Summary = 'The Standard Sales Return Receipt (RDLC) provides a detailed layout.'; } layout("SimpleSalesReturnReceipt.docx") { Type = Word; LayoutFile = './Sales/History/SimpleSalesReturnReceipt.docx'; Caption = 'Standard Sales Return Receipt (Word)'; Summary = 'The Standard Sales Return Receipt (Word) provides a basic layout.'; } } labels { } trigger OnInitReport() begin CompanyInfo.Get(); SalesSetup.Get(); FormatDocument.SetLogoPosition(SalesSetup."Logo Position on Documents", CompanyInfo1, CompanyInfo2, CompanyInfo3); OnAfterInitReport(); end; trigger OnPostReport() begin if LogInteraction and not IsReportInPreviewMode() then if "Return Receipt Header".FindSet() then repeat SegManagement.LogDocument(20, "Return Receipt Header"."No.", 0, 0, DATABASE::Customer, "Return Receipt Header"."Bill-to Customer No.", "Return Receipt Header"."Salesperson Code", "Return Receipt Header"."Campaign No.", "Return Receipt Header"."Posting Description", ''); until "Return Receipt Header".Next() = 0; end; trigger OnPreReport() begin OnAfterPreReport("Return Receipt Header", NoOfCopies, ShowCorrectionLines, LogInteraction, ShowInternalInfo); end; var SalesPurchPerson: Record "Salesperson/Purchaser"; DimSetEntry1: Record "Dimension Set Entry"; DimSetEntry2: Record "Dimension Set Entry"; RespCenter: Record "Responsibility Center"; SalesSetup: Record "Sales & Receivables Setup"; SellToContact: Record Contact; BillToContact: Record Contact; FormatAddr: Codeunit "Format Address"; FormatDocument: Codeunit "Format Document"; SegManagement: Codeunit SegManagement; CustAddr: array[8] of Text[100]; ShipToAddr: array[8] of Text[100]; CompanyAddr: array[8] of Text[100]; SalesPersonText: Text[20]; ReferenceText: Text[80]; CopyText: Text[30]; DimText: Text[120]; OldDimText: Text[75]; MoreLines: Boolean; ShowCustAddr: Boolean; ShowInternalInfo: Boolean; Continue: Boolean; NoOfCopies: Integer; NoOfLoops: Integer; ShowCorrectionLines: Boolean; LogInteraction: Boolean; OutputNo: Integer; TypeInt: Integer; LogInteractionEnable: Boolean;#pragma warning disable AA0074 Text002: Label 'Sales - Return Receipt %1', Comment = '%1 = Document No.';#pragma warning disable AA0470 Text003: Label 'Page %1';#pragma warning restore AA0470#pragma warning restore AA0074 CompanyInfoPhoneNoCaptionLbl: Label 'Phone No.'; CompanyInfoVATRegNoCptnLbl: Label 'VAT Reg. No.'; CompanyInfoGiroNoCaptionLbl: Label 'Giro No.'; CompanyInfoBankNameCptnLbl: Label 'Bank'; CompanyInfoBankAccNoCptnLbl: Label 'Account No.'; ReturnReceiptHeaderNoCptnLbl: Label 'Receipt No.'; ReturnRcptHdrShptDtCptnLbl: Label 'Shipment Date'; DocumentDateCaptionLbl: Label 'Document Date'; HomePageCaptionLbl: Label 'Home Page'; EmailCaptionLbl: Label 'Email'; HeaderDimensionsCaptionLbl: Label 'Header Dimensions'; LineDimensionsCaptionLbl: Label 'Line Dimensions'; BilltoAddressCaptionLbl: Label 'Bill-to Address'; SellToContactPhoneNoLbl: Label 'Sell-to Contact Phone No.'; SellToContactMobilePhoneNoLbl: Label 'Sell-to Contact Mobile Phone No.'; SellToContactEmailLbl: Label 'Sell-to Contact E-Mail'; BillToContactPhoneNoLbl: Label 'Bill-to Contact Phone No.'; BillToContactMobilePhoneNoLbl: Label 'Bill-to Contact Mobile Phone No.'; BillToContactEmailLbl: Label 'Bill-to Contact E-Mail'; protected var CompanyInfo: Record "Company Information"; CompanyInfo1: Record "Company Information"; CompanyInfo2: Record "Company Information"; CompanyInfo3: Record "Company Information"; /// <summary> /// Initializes the log interaction setting based on interaction template configuration. /// </summary> procedure InitLogInteraction() begin LogInteraction := SegManagement.FindInteractionTemplateCode(Enum::"Interaction Log Entry Document Type"::"Sales Return Receipt") <> ''; end; local procedure IsReportInPreviewMode(): Boolean var MailManagement: Codeunit "Mail Management"; begin exit(CurrReport.Preview or MailManagement.IsHandlingGetEmailBody()); end; local procedure FormatAddressFields(ReturnReceiptHeader: Record "Return Receipt Header") begin FormatAddr.GetCompanyAddr(ReturnReceiptHeader."Responsibility Center", RespCenter, CompanyInfo, CompanyAddr); FormatAddr.SalesRcptShipTo(ShipToAddr, ReturnReceiptHeader); ShowCustAddr := FormatAddr.SalesRcptBillTo(CustAddr, ShipToAddr, ReturnReceiptHeader); end; local procedure FormatDocumentFields(ReturnReceiptHeader: Record "Return Receipt Header") begin FormatDocument.SetSalesPerson(SalesPurchPerson, ReturnReceiptHeader."Salesperson Code", SalesPersonText); ReferenceText := FormatDocument.SetText(ReturnReceiptHeader."Your Reference" <> '', ReturnReceiptHeader.FieldCaption("Your Reference")); end; [IntegrationEvent(true, false)] local procedure OnAfterInitReport() begin end; [IntegrationEvent(true, false)] local procedure OnAfterPostDataItem(var ReturnReceiptHeader: Record "Return Receipt Header") begin end; [IntegrationEvent(true, false)] local procedure OnAfterPreReport(var ReturnReceiptHeader: Record "Return Receipt Header"; var NoOfCopies: Integer; var ShowCorrectionLines: Boolean; var LogInteraction: Boolean; var ShowInternalInfo: Boolean) begin end;}