Report 410 Blanket Purchase Order
src/Layers/W1/BaseApp/Purchases/Document/BlanketPurchaseOrder.Report.al749 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.Purchases.Document;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.Foundation.Shipping;using Microsoft.Inventory.Location;using Microsoft.Purchases.Posting;using Microsoft.Purchases.Setup;using Microsoft.Purchases.Vendor;using Microsoft.Utilities;using System.Email;using System.Globalization;using System.Utilities;report 410 "Blanket Purchase Order"{ Caption = 'Blanket Purchase Order'; PreviewMode = PrintLayout; WordMergeDataItem = "Purchase Header"; DefaultRenderingLayout = RDLCLayout; dataset { dataitem("Purchase Header"; "Purchase Header") { DataItemTableView = sorting("Document Type", "No.") where("Document Type" = const("Blanket Order")); RequestFilterFields = "No.", "Buy-from Vendor No.", "No. Printed"; RequestFilterHeading = 'Blanket Purchase Order'; column(No2_PurchHdr; "No.") { } column(DocumentDateCaption; DocumentDateCaptionLbl) { } column(HomePageCaption; HomePageCaptionLbl) { } column(EMailCaption; EMailCaptionLbl) { } column(BuyFromContactPhoneNoLbl; BuyFromContactPhoneNoLbl) { } column(BuyFromContactMobilePhoneNoLbl; BuyFromContactMobilePhoneNoLbl) { } column(BuyFromContactEmailLbl; BuyFromContactEmailLbl) { } column(PayToContactPhoneNoLbl; PayToContactPhoneNoLbl) { } column(PayToContactMobilePhoneNoLbl; PayToContactMobilePhoneNoLbl) { } column(PayToContactEmailLbl; PayToContactEmailLbl) { } column(BuyFromContactPhoneNo; BuyFromContact."Phone No.") { } column(BuyFromContactMobilePhoneNo; BuyFromContact."Mobile Phone No.") { } column(BuyFromContactEmail; BuyFromContact."E-Mail") { } column(PayToContactPhoneNo; PayToContact."Phone No.") { } column(PayToContactMobilePhoneNo; PayToContact."Mobile Phone No.") { } column(PayToContactEmail; PayToContact."E-Mail") { } dataitem(CopyLoop; "Integer") { DataItemTableView = sorting(Number); dataitem(PageLoop; "Integer") { DataItemTableView = sorting(Number) where(Number = const(1)); column(BlankPOCopyText; StrSubstNo(BlanketPurchaseOrderLbl, CopyText)) { } column(VendAddr1; VendAddr[1]) { } column(CompanyAddr1; CompanyAddr[1]) { } column(VendAddr2; VendAddr[2]) { } column(CompanyAddr2; CompanyAddr[2]) { } column(VendAddr3; VendAddr[3]) { } column(CompanyAddr3; CompanyAddr[3]) { } column(VendAddr4; VendAddr[4]) { } column(CompanyAddr4; CompanyAddr[4]) { } column(VendAddr5; VendAddr[5]) { } column(CompanyInfoPhNo; CompanyInfo."Phone No.") { } column(VendAddr6; VendAddr[6]) { } column(CompanyInfoVatRegNo; CompanyInfo."VAT Registration No.") { } column(CompanyInfoGiroNo; CompanyInfo."Giro No.") { } column(CompanyInfoBankName; CompanyInfo."Bank Name") { } column(CompanyInfoBankAccNo; CompanyInfo."Bank Account No.") { } column(CompanyInfoHomePage; CompanyInfo."Home Page") { } column(CompanyInfoEMail; CompanyInfo."E-Mail") { } column(CompanyPicture; DummyCompanyInfo.Picture) { } column(PayToVendNo_PurchHdr; "Purchase Header"."Pay-to Vendor No.") { } column(DocumentDate_PurchHdr; Format("Purchase Header"."Document Date", 0, 4)) { } column(VATNoText; VATNoText) { } column(VATRegNo_PurchHdr; "Purchase Header"."VAT Registration No.") { } column(ExpRcptDate_PurchHdr; Format("Purchase Header"."Expected Receipt Date")) { } column(PurchaserText; PurchaserText) { } column(SalesPurchPersonName; SalesPurchPerson.Name) { } column(No1_PurchHdr; "Purchase Header"."No.") { } column(ReferenceText; ReferenceText) { } column(YourRef_PurchHdr; "Purchase Header"."Your Reference") { } column(VendAddr7; VendAddr[7]) { } column(VendAddr8; VendAddr[8]) { } column(CompanyAddr5; CompanyAddr[5]) { } column(CompanyAddr6; CompanyAddr[6]) { } column(CompanyAddr7; CompanyAddr[7]) { } column(CompanyAddr8; CompanyAddr[8]) { } column(OutputNo; OutputNo) { } column(ShptMethodDesc; ShipmentMethod.Description) { } column(CompanyInfoPhNoCaption; CompanyInfoPhNoCaptionLbl) { } column(CompanyInfoVatRegNoCaption; CompanyInfoVatRegNoCaptionLbl) { } column(CompanyInfoGiroNoCaption; CompanyInfoGiroNoCaptionLbl) { } column(CompanyInfoBankNameCaption; CompanyInfoBankNameCaptionLbl) { } column(CompanyInfoBankAccNoCaption; CompanyInfoBankAccNoCaptionLbl) { } column(ExpectedDateCaption; ExpectedDateCaptionLbl) { } column(BlanketPurchOrderNoCaption; BlanketPurchOrderNoCaptionLbl) { } column(PageCaption; PageCaptionLbl) { } column(UOM_PurchLineCaption; "Purchase Line".FieldCaption("Unit of Measure")) { } column(Quantity_PurchLineCaption; "Purchase Line".FieldCaption(Quantity)) { } column(Description_PurchLineCaption; "Purchase Line".FieldCaption(Description)) { } column(ShipmentMethodDescCaption; ShipmentMethodDescCaptionLbl) { } column(PurchLineExpectedReceiptDateCaption; PurchLineExpectedReceiptDateCaptionLbl) { } column(PurchLineNoCaption; PurchLineNoCaptionLbl) { } column(PurchLineVendItemNoCaption; PurchLineVendItemNoCaptionLbl) { } column(PayToVendNo_PurchHdrCaption; "Purchase Header".FieldCaption("Pay-to Vendor No.")) { } dataitem(DimensionLoop1; "Integer") { DataItemLinkReference = "Purchase Header"; DataItemTableView = sorting(Number) where(Number = filter(1 ..)); column(DimText; DimText) { } column(Number1_IntegerLine; 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("Purchase Line"; "Purchase Line") { DataItemLink = "Document Type" = field("Document Type"), "Document No." = field("No."); DataItemLinkReference = "Purchase Header"; DataItemTableView = sorting("Document Type", "Document No.", "Line No."); trigger OnAfterGetRecord() begin if FirstLineHasBeenOutput then Clear(DummyCompanyInfo.Picture); FirstLineHasBeenOutput := true; end; trigger OnPreDataItem() begin FirstLineHasBeenOutput := false; DummyCompanyInfo.Picture := CompanyInfo.Picture; CurrReport.Break(); end; } dataitem(RoundLoop; "Integer") { DataItemTableView = sorting(Number); column(ShowInternalInfo; ShowInternalInfo) { } column(Type_PurchLine; Format("Purchase Line".Type, 0, 2)) { } column(Description_PurchLine; "Purchase Line".Description) { } column(Quantity_PurchLine; "Purchase Line".Quantity) { } column(UOM_PurchLine; "Purchase Line"."Unit of Measure") { } column(ExpRcptDate_PurchLine; Format("Purchase Line"."Expected Receipt Date")) { } column(No_PurchLine; "Purchase Line"."No.") { } column(VendItemNo_PurchLine; "Purchase Line"."Vendor Item No.") { } dataitem(DimensionLoop2; "Integer") { DataItemTableView = sorting(Number) where(Number = filter(1 ..)); column(DimText1; DimText) { } column(Number2_IntegerLine; 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 Number = 1 then TempPurchaseLine.Find('-') else TempPurchaseLine.Next(); "Purchase Line" := TempPurchaseLine; DimSetEntry2.SetRange("Dimension Set ID", "Purchase Line"."Dimension Set ID"); end; trigger OnPostDataItem() begin TempPurchaseLine.DeleteAll(); end; trigger OnPreDataItem() begin MoreLines := TempPurchaseLine.Find('+'); while MoreLines and (TempPurchaseLine.Description = '') and (TempPurchaseLine."Description 2" = '') and (TempPurchaseLine."No." = '') and (TempPurchaseLine.Quantity = 0) and (TempPurchaseLine.Amount = 0) do MoreLines := TempPurchaseLine.Next(-1) <> 0; if not MoreLines then CurrReport.Break(); TempPurchaseLine.SetRange("Line No.", 0, TempPurchaseLine."Line No."); SetRange(Number, 1, TempPurchaseLine.Count); end; } dataitem(Total; "Integer") { DataItemTableView = sorting(Number) where(Number = const(1)); } dataitem(Total2; "Integer") { DataItemTableView = sorting(Number) where(Number = const(1)); column(BuyFrmVendNo_PurchHdr; "Purchase Header"."Buy-from Vendor No.") { IncludeCaption = false; } column(BuyFrmVendNo_PurchHdrCaption; "Purchase Header".FieldCaption("Buy-from Vendor No.")) { } trigger OnPreDataItem() begin if "Purchase Header"."Buy-from Vendor No." = "Purchase Header"."Pay-to Vendor No." then CurrReport.Break(); end; } dataitem(Total3; "Integer") { DataItemTableView = sorting(Number) where(Number = const(1)); column(SelltoCustNo_PurchHdr; "Purchase Header"."Sell-to Customer No.") { } column(ShipToAddr1; ShipToAddr[1]) { } column(ShipToAddr2; ShipToAddr[2]) { } column(ShipToAddr3; ShipToAddr[3]) { } column(ShipToAddr4; ShipToAddr[4]) { } column(ShipToAddr5; ShipToAddr[5]) { } column(ShipToAddr6; ShipToAddr[6]) { } column(ShipToAddr7; ShipToAddr[7]) { } column(ShipToAddr8; ShipToAddr[8]) { } column(ShiptoAddressCaption; ShiptoAddressCaptionLbl) { } column(ShipToPhoneNo; "Purchase Header"."Ship-to Phone No.") { } trigger OnPreDataItem() begin if ("Purchase Header"."Sell-to Customer No." = '') and (ShipToAddr[1] = '') then CurrReport.Break(); end; } } trigger OnAfterGetRecord() begin FirstLineHasBeenOutput := false; Clear(TempPurchaseLine); Clear(PurchPost); TempPurchaseLine.DeleteAll(); PurchPost.GetPurchLines("Purchase Header", TempPurchaseLine, 0); if Number > 1 then begin CopyText := FormatDocument.GetCOPYText(); OutputNo += 1; end; end; trigger OnPostDataItem() begin if not IsReportInPreviewMode() then Codeunit.Run(Codeunit::"Purch.Header-Printed", "Purchase Header"); end; trigger OnPreDataItem() begin OutputNo := 1; NoOfLoops := Abs(NoOfCopies) + 1; CopyText := ''; SetRange(Number, 1, NoOfLoops); end; } trigger OnAfterGetRecord() begin FirstLineHasBeenOutput := false; CurrReport.Language := LanguageMgt.GetLanguageIdOrDefault("Language Code"); CurrReport.FormatRegion := LanguageMgt.GetFormatRegionOrDefault("Format Region"); FormatAddr.SetLanguageCode("Language Code"); FormatAddressFields("Purchase Header"); FormatDocumentFields("Purchase Header"); if BuyFromContact.Get("Buy-from Contact No.") then; if PayToContact.Get("Pay-to Contact No.") then; DimSetEntry1.SetRange("Dimension Set ID", "Dimension Set ID"); if not IsReportInPreviewMode() then if ArchiveDocument then ArchiveManagement.StorePurchDocument("Purchase Header", LogInteraction); end; trigger OnPreDataItem() begin FirstLineHasBeenOutput := false; end; } } requestpage { SaveValues = true; layout { area(content) { group(Options) { Caption = 'Options'; field(NoOfCopies; NoOfCopies) { ApplicationArea = Suite; Caption = 'No. of Copies'; ToolTip = 'Specifies how many copies of the document to print.'; } field(ShowInternalInfo; ShowInternalInfo) { ApplicationArea = Suite; Caption = 'Show Internal Information'; ToolTip = 'Specifies if you want the printed report to show information that is only for internal use.'; } field(ArchiveDocument; ArchiveDocument) { ApplicationArea = Suite; Caption = 'Archive Document'; ToolTip = 'Specifies whether to archive the order.'; trigger OnValidate() begin if not ArchiveDocument then LogInteraction := false; end; } field(LogInteraction; LogInteraction) { ApplicationArea = Suite; Caption = 'Log Interaction'; Enabled = LogInteractionEnable; ToolTip = 'Specifies if you want the program to log this interaction.'; } } } } actions { } trigger OnInit() begin InitLogInteraction(); LogInteractionEnable := LogInteraction; ArchiveDocument := PurchSetup."Archive Blanket Orders"; end; } rendering { layout(RDLCLayout) { Type = RDLC; LayoutFile = './Purchases/Document/BlanketPurchaseOrder.rdlc'; Summary = 'Report layout made in the legacy RDLC format. Use an RDLC editor to modify the layout.'; } } labels { } trigger OnInitReport() begin CompanyInfo.SetAutoCalcFields(Picture); CompanyInfo.Get(); PurchSetup.Get(); end; trigger OnPostReport() begin if LogInteraction and not IsReportInPreviewMode() then if "Purchase Header".FindSet() then repeat "Purchase Header".CalcFields("No. of Archived Versions"); SegManagement.LogDocument( 12, "Purchase Header"."No.", "Purchase Header"."Doc. No. Occurrence", "Purchase Header"."No. of Archived Versions", Database::Vendor, "Purchase Header"."Pay-to Vendor No.", "Purchase Header"."Purchaser Code", '', "Purchase Header"."Posting Description", ''); until "Purchase Header".Next() = 0; end; trigger OnPreReport() begin OnBeforeOnPreReport("Purchase Header"); end; var DummyCompanyInfo: Record "Company Information"; DimSetEntry1: Record "Dimension Set Entry"; DimSetEntry2: Record "Dimension Set Entry"; RespCenter: Record "Responsibility Center"; PurchSetup: Record "Purchases & Payables Setup"; BuyFromContact: Record Contact; PayToContact: Record Contact; LanguageMgt: Codeunit Language; PurchPost: Codeunit "Purch.-Post"; FormatAddr: Codeunit "Format Address"; SegManagement: Codeunit SegManagement; ArchiveManagement: Codeunit ArchiveManagement; VATNoText: Text[80]; ReferenceText: Text[80]; MoreLines: Boolean; NoOfCopies: Integer; NoOfLoops: Integer; CopyText: Text[30]; DimText: Text[120]; OldDimText: Text[75]; ShowInternalInfo: Boolean; Continue: Boolean; LogInteraction: Boolean; OutputNo: Integer; ArchiveDocument: Boolean; LogInteractionEnable: Boolean; BlanketPurchaseOrderLbl: Label 'Blanket Purchase Order %1', Comment = '%1 = Document No.'; CompanyInfoPhNoCaptionLbl: Label 'Phone No.'; CompanyInfoVatRegNoCaptionLbl: Label 'VAT Registration No.'; CompanyInfoGiroNoCaptionLbl: Label 'Giro No.'; CompanyInfoBankNameCaptionLbl: Label 'Bank'; CompanyInfoBankAccNoCaptionLbl: Label 'Account No.'; ExpectedDateCaptionLbl: Label 'Expected Date'; BlanketPurchOrderNoCaptionLbl: Label 'Blanket Purchase Order No.'; PageCaptionLbl: Label 'Page'; ShipmentMethodDescCaptionLbl: Label 'Shipment Method'; HeaderDimensionsCaptionLbl: Label 'Header Dimensions'; PurchLineExpectedReceiptDateCaptionLbl: Label 'Expected Date'; PurchLineNoCaptionLbl: Label 'Our No.'; PurchLineVendItemNoCaptionLbl: Label 'No.'; LineDimensionsCaptionLbl: Label 'Line Dimensions'; ShiptoAddressCaptionLbl: Label 'Ship-to Address'; DocumentDateCaptionLbl: Label 'Document Date'; HomePageCaptionLbl: Label 'Home Page'; EMailCaptionLbl: Label 'Email'; BuyFromContactPhoneNoLbl: Label 'Buy-from Contact Phone No.'; BuyFromContactMobilePhoneNoLbl: Label 'Buy-from Contact Mobile Phone No.'; BuyFromContactEmailLbl: Label 'Buy-from Contact E-Mail'; PayToContactPhoneNoLbl: Label 'Pay-to Contact Phone No.'; PayToContactMobilePhoneNoLbl: Label 'Pay-to Contact Mobile Phone No.'; PayToContactEmailLbl: Label 'Pay-to Contact E-Mail'; protected var TempPurchaseLine: Record "Purchase Line" temporary; CompanyInfo: Record "Company Information"; ShipmentMethod: Record "Shipment Method"; SalesPurchPerson: Record "Salesperson/Purchaser"; FormatDocument: Codeunit "Format Document"; FirstLineHasBeenOutput: Boolean; VendAddr: array[8] of Text[100]; ShipToAddr: array[8] of Text[100]; CompanyAddr: array[8] of Text[100]; PurchaserText: Text[50]; procedure InitializeRequest(NewNoOfCopies: Integer; NewShowInternalInfo: Boolean; NewLogInteraction: Boolean) begin NoOfCopies := NewNoOfCopies; ShowInternalInfo := NewShowInternalInfo; LogInteraction := NewLogInteraction; end; local procedure InitLogInteraction() begin LogInteraction := SegManagement.FindInteractionTemplateCode(Enum::"Interaction Log Entry Document Type"::"Purch. Blnkt. Ord.") <> ''; end; local procedure IsReportInPreviewMode(): Boolean var MailManagement: Codeunit "Mail Management"; begin exit(CurrReport.Preview() or MailManagement.IsHandlingGetEmailBody()); end; local procedure FormatAddressFields(PurchaseHeader: Record "Purchase Header") begin FormatAddr.GetCompanyAddr(PurchaseHeader."Responsibility Center", RespCenter, CompanyInfo, CompanyAddr); FormatAddr.PurchHeaderPayTo(VendAddr, PurchaseHeader); FormatAddr.PurchHeaderShipTo(ShipToAddr, PurchaseHeader); end; local procedure FormatDocumentFields(PurchaseHeader: Record "Purchase Header") begin FormatDocument.SetPurchaser(SalesPurchPerson, PurchaseHeader."Purchaser Code", PurchaserText); FormatDocument.SetShipmentMethod(ShipmentMethod, PurchaseHeader."Shipment Method Code", PurchaseHeader."Language Code"); ReferenceText := FormatDocument.SetText(PurchaseHeader."Your Reference" <> '', PurchaseHeader.FieldCaption("Your Reference")); VATNoText := FormatDocument.SetText(PurchaseHeader."VAT Registration No." <> '', PurchaseHeader.FieldCaption("VAT Registration No.")); end; [IntegrationEvent(false, false)] local procedure OnBeforeOnPreReport(var PurchaseHeader: Record "Purchase Header") begin end;}