Report 1302 Standard Sales - Pro Forma Inv

Base Application, Microsoft.Sales.Document

src/Layers/W1/BaseApp/Sales/Document/StandardSalesProFormaInv.Report.al602 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.Document;using Microsoft.CRM.Contact;using Microsoft.CRM.Team;using Microsoft.Finance.Currency;using Microsoft.Finance.GeneralLedger.Setup;using Microsoft.Finance.VAT.Calculation;using Microsoft.Foundation.Address;using Microsoft.Foundation.Company;using Microsoft.Foundation.Shipping;using Microsoft.Inventory.Item;using Microsoft.Inventory.Location;using Microsoft.Sales.Customer;using Microsoft.Utilities;using System.Globalization;using System.Reflection;using System.Text;using System.Utilities;/// <summary>/// Generates a pro forma invoice document for sales orders before actual invoicing./// </summary>report 1302 "Standard Sales - Pro Forma Inv"{    Caption = 'Pro Forma Invoice';    DefaultRenderingLayout = "StandardSalesProFormaInv.rdlc";    WordMergeDataItem = Header;    dataset    {        dataitem(Header; "Sales Header")        {            DataItemTableView = sorting("Document Type", "No.");            RequestFilterFields = "No.", "Sell-to Customer No.", "No. Printed";            RequestFilterHeading = 'Pro Forma Invoice';            column(DocumentDate; Format("Document Date", 0, 4))            {            }            column(CompanyPicture; CompanyInformation.Picture)            {            }            column(CompanyEMail; CompanyInformation."E-Mail")            {            }            column(CompanyHomePage; CompanyInformation."Home Page")            {            }            column(CompanyPhoneNo; CompanyInformation."Phone No.")            {            }            column(CompanyVATRegNo; CompanyInformation.GetVATRegistrationNumber())            {            }            column(CompanyAddress1; CompanyAddress[1])            {            }            column(CompanyAddress2; CompanyAddress[2])            {            }            column(CompanyAddress3; CompanyAddress[3])            {            }            column(CompanyAddress4; CompanyAddress[4])            {            }            column(CompanyAddress5; CompanyAddress[5])            {            }            column(CompanyAddress6; CompanyAddress[6])            {            }            column(CompanyAddress7; CompanyAddress[7])            {            }            column(CompanyAddress8; CompanyAddress[8])            {            }            column(CustomerAddress1; CustomerAddress[1])            {            }            column(CustomerAddress2; CustomerAddress[2])            {            }            column(CustomerAddress3; CustomerAddress[3])            {            }            column(CustomerAddress4; CustomerAddress[4])            {            }            column(CustomerAddress5; CustomerAddress[5])            {            }            column(CustomerAddress6; CustomerAddress[6])            {            }            column(CustomerAddress7; CustomerAddress[7])            {            }            column(CustomerAddress8; CustomerAddress[8])            {            }            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")            {            }            column(YourReference; "Your Reference")            {            }            column(ExternalDocumentNo; "External Document No.")            {            }            column(DocumentNo; "No.")            {            }            column(CompanyLegalOffice; LegalOfficeTxt)            {            }            column(SalesPersonName; SalespersonPurchaserName)            {            }            column(ShipmentMethodDescription; ShipmentMethodDescription)            {            }            column(Currency; CurrencyCode)            {            }            column(CustomerVATRegNo; GetCustomerVATRegistrationNumber())            {            }            column(CustomerVATRegistrationNoLbl; GetCustomerVATRegistrationNumberLbl())            {            }            column(PageLbl; PageLbl)            {            }            column(DocumentTitleLbl; DocumentCaption())            {            }            column(YourReferenceLbl; FieldCaption("Your Reference"))            {            }            column(ExternalDocumentNoLbl; FieldCaption("External Document No."))            {            }            column(CompanyLegalOfficeLbl; LegalOfficeLbl)            {            }            column(SalesPersonLbl; SalesPersonLblText)            {            }            column(EMailLbl; CompanyInformation.FieldCaption("E-Mail"))            {            }            column(HomePageLbl; CompanyInformation.FieldCaption("Home Page"))            {            }            column(CompanyPhoneNoLbl; CompanyInformation.FieldCaption("Phone No."))            {            }            column(ShipmentMethodDescriptionLbl; DummyShipmentMethod.TableCaption())            {            }            column(CurrencyLbl; DummyCurrency.TableCaption())            {            }            column(ItemLbl; Item.TableCaption())            {            }            column(TariffLbl; Item.FieldCaption("Tariff No."))            {            }            column(UnitPriceLbl; Item.FieldCaption("Unit Price"))            {            }            column(CountryOfManufactuctureLbl; CountryOfManufactuctureLbl)            {            }            column(AmountLbl; Line.FieldCaption(Amount))            {            }            column(VATPctLbl; Line.FieldCaption("VAT %"))            {            }            column(VATAmountLbl; DummyVATAmountLine.VATAmountText())            {            }            column(TotalWeightLbl; TotalWeightLbl)            {            }            column(TotalAmountLbl; TotalAmountLbl)            {            }            column(TotalAmountInclVATLbl; TotalAmountInclVATLbl)            {            }            column(QuantityLbl; Line.FieldCaption(Quantity))            {            }            column(NetWeightLbl; Line.FieldCaption("Net Weight"))            {            }            column(DeclartionLbl; DeclartionLbl)            {            }            column(SignatureLbl; SignatureLbl)            {            }            column(SignatureNameLbl; SignatureNameLbl)            {            }            column(SignaturePositionLbl; SignaturePositionLbl)            {            }            column(VATRegNoLbl; CompanyInformation.GetVATRegistrationNumberLbl())            {            }            column(ShowWorkDescription; ShowWorkDescription) { }            dataitem(Line; "Sales Line")            {                DataItemLink = "Document Type" = field("Document Type"), "Document No." = field("No.");                DataItemLinkReference = Header;                DataItemTableView = sorting("Document No.", "Line No.");                column(ItemDescription; Description)                {                }                column(CountryOfManufacturing; Item."Country/Region of Origin Code")                {                }                column(Tariff; Item."Tariff No.")                {                }                column(Quantity; "Qty. to Invoice")                {                }                column(Price; FormattedLinePrice)                {                    AutoFormatExpression = "Currency Code";                    AutoFormatType = 2;                }                column(NetWeight; "Net Weight")                {                }                column(LineAmount; FormattedLineAmount)                {                    AutoFormatExpression = "Currency Code";                    AutoFormatType = 1;                }                column(VATPct; "VAT %")                {                }                column(VATAmount; FormattedVATAmount)                {                }                trigger OnAfterGetRecord()                var                    Location: Record Location;                    AutoFormatType: Enum "Auto Format";                begin                    GetItemForRec("No.");                    OnBeforeLineOnAfterGetRecord(Header, Line);                    if IsShipment() then                        if Location.RequireShipment("Location Code") and ("Quantity Shipped" = 0) then                            "Qty. to Invoice" := Quantity;                    if FormatDocument.HideDocumentLine(HideLinesWithZeroQuantity, Line, FieldNo("Qty. to Invoice")) then                        CurrReport.Skip();                    if Quantity = 0 then begin                        LinePrice := "Unit Price";                        LineAmount := 0;                        VATAmount := 0;                    end else begin                        LinePrice := Round(Amount / Quantity, Currency."Unit-Amount Rounding Precision");                        LineAmount := Round(Amount * "Qty. to Invoice" / Quantity, Currency."Amount Rounding Precision");                        VATAmount := Round(                            Amount * "VAT %" / 100 * "Qty. to Invoice" / Quantity, Currency."Amount Rounding Precision");                        TotalAmount += LineAmount;                        TotalWeight += Round("Qty. to Invoice" * "Net Weight");                        TotalVATAmount += VATAmount;                        TotalAmountInclVAT += Round("Amount Including VAT" * "Qty. to Invoice" / Quantity, Currency."Amount Rounding Precision");                    end;                    FormattedLinePrice := Format(LinePrice, 0, AutoFormat.ResolveAutoFormat(AutoFormatType::UnitAmountFormat, CurrencyCode));                    FormattedLineAmount := Format(LineAmount, 0, AutoFormat.ResolveAutoFormat(AutoFormatType::AmountFormat, CurrencyCode));                    FormattedVATAmount := Format(VATAmount, 0, AutoFormat.ResolveAutoFormat(AutoFormatType::AmountFormat, CurrencyCode));                end;                trigger OnPreDataItem()                begin                    TotalWeight := 0;                    TotalAmount := 0;                    TotalVATAmount := 0;                    TotalAmountInclVAT := 0;                    SetRange(Type, Type::Item);                    OnAfterLineOnPreDataItem(Header, Line);                end;            }            dataitem(WorkDescriptionLines; "Integer")            {                DataItemTableView = sorting(Number) where(Number = filter(1 .. 99999));                column(WorkDescriptionLineNumber; Number) { }                column(WorkDescriptionLine; WorkDescriptionLine) { }                trigger OnAfterGetRecord()                var                    TypeHelper: Codeunit "Type Helper";                begin                    if WorkDescriptionInStream.EOS() then                        CurrReport.Break();                    WorkDescriptionLine := TypeHelper.ReadAsTextWithSeparator(WorkDescriptionInStream, TypeHelper.LFSeparator());                end;                trigger OnPostDataItem()                begin                    Clear(WorkDescriptionInStream)                end;                trigger OnPreDataItem()                begin                    if not ShowWorkDescription then                        CurrReport.Break();                    Header."Work Description".CreateInStream(WorkDescriptionInStream, TextEncoding::UTF8);                end;            }            dataitem(Totals; "Integer")            {                DataItemTableView = sorting(Number);                MaxIteration = 1;                column(TotalWeight; TotalWeight)                {                }                column(TotalValue; FormattedTotalAmount)                {                }                column(TotalVATAmount; FormattedTotalVATAmount)                {                }                column(TotalAmountInclVAT; FormattedTotalAmountInclVAT)                {                }                trigger OnPreDataItem()                var                    AutoFormatType: Enum "Auto Format";                begin                    FormattedTotalAmount := Format(TotalAmount, 0, AutoFormat.ResolveAutoFormat(AutoFormatType::AmountFormat, CurrencyCode));                    FormattedTotalVATAmount := Format(TotalVATAmount, 0, AutoFormat.ResolveAutoFormat(AutoFormatType::AmountFormat, CurrencyCode));                    FormattedTotalAmountInclVAT := Format(TotalAmountInclVAT, 0, AutoFormat.ResolveAutoFormat(AutoFormatType::AmountFormat, CurrencyCode));                end;            }            trigger OnAfterGetRecord()            begin                CurrReport.Language := LanguageMgt.GetLanguageIdOrDefault("Language Code");                CurrReport.FormatRegion := LanguageMgt.GetFormatRegionOrDefault("Format Region");                FormatDocumentFields(Header);                if SellToContact.Get("Sell-to Contact No.") then;                if BillToContact.Get("Bill-to Contact No.") then;                CalcFields("Work Description");                ShowWorkDescription := "Work Description".HasValue();            end;        }    }    requestpage    {        layout        {            area(content)            {                group(Options)                {                    Caption = 'Options';                    field(HideLinesWithZeroQuantityControl; HideLinesWithZeroQuantity)                    {                        ApplicationArea = Basic, Suite;                        ToolTip = 'Specifies if the lines with zero quantity are printed.';                        Caption = 'Hide lines with zero quantity';                    }                }            }        }        actions        {        }    }    rendering    {        layout("StandardSalesProFormaInv.rdlc")        {            Type = RDLC;            LayoutFile = './Sales/Document/StandardSalesProFormaInv.rdlc';            Caption = 'Standard Sales Proforma Invoice (RDLC)';            Summary = 'The Standard Sales Proforma Invoice (RDLC) provides a detailed layout.';        }        layout("StandardSalesProFormaInv.docx")        {            Type = Word;            LayoutFile = './Sales/Document/StandardSalesProFormaInv.docx';            Caption = 'Standard Sales Proforma Invoice (Word)';            Summary = 'The Standard Sales Proforma Invoice (Word) provides a basic layout.';        }    }    labels    {    }    trigger OnInitReport()    var        IsHandled: Boolean;    begin        CompanyInformation.Get();        CompanyInformation.CalcFields(Picture);        IsHandled := false;        OnInitReportForGlobalVariable(IsHandled, LegalOfficeTxt, LegalOfficeLbl);    end;    var        DummyVATAmountLine: Record "VAT Amount Line";        DummyShipmentMethod: Record "Shipment Method";        DummyCurrency: Record Currency;        AutoFormat: Codeunit "Auto Format";        LanguageMgt: Codeunit Language;        FormatDocument: Codeunit "Format Document";        CountryOfManufactuctureLbl: Label 'Country';        TotalWeightLbl: Label 'Total Weight';        SalespersonPurchaserName: Text;        ShipmentMethodDescription: Text;        DocumentTitleLbl: Label 'Pro Forma Invoice';        PageLbl: Label 'Page';        DeclartionLbl: Label 'For customs purposes only.';        SignatureLbl: Label 'For and on behalf of the above named company:';        SignatureNameLbl: Label 'Name (in print) Signature';        SignaturePositionLbl: Label 'Position in company';        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';        LegalOfficeTxt, LegalOfficeLbl : Text;    protected var        CompanyInformation: Record "Company Information";        Item: Record Item;        Currency: Record Currency;        SellToContact: Record Contact;        BillToContact: Record Contact;        CompanyAddress: array[8] of Text[100];        CustomerAddress: array[8] of Text[100];        WorkDescriptionInStream: InStream;        SalesPersonLblText: Text[50];        TotalAmountLbl: Text[50];        TotalAmountInclVATLbl: Text[50];        FormattedLinePrice: Text;        FormattedLineAmount: Text;        FormattedVATAmount: Text;        FormattedTotalAmount: Text;        FormattedTotalVATAmount: Text;        FormattedTotalAmountInclVAT: Text;        WorkDescriptionLine: Text;        CurrencyCode: Code[10];        TotalWeight: Decimal;        TotalAmount: Decimal;        TotalVATAmount: Decimal;        TotalAmountInclVAT: Decimal;        LinePrice: Decimal;        LineAmount: Decimal;        VATAmount: Decimal;        ShowWorkDescription: Boolean;        HideLinesWithZeroQuantity: Boolean;    local procedure FormatDocumentFields(SalesHeader: Record "Sales Header")    var        GeneralLedgerSetup: Record "General Ledger Setup";        SalespersonPurchaser: Record "Salesperson/Purchaser";        ShipmentMethod: Record "Shipment Method";        ResponsibilityCenter: Record "Responsibility Center";        Customer: Record Customer;        FormatAddress: Codeunit "Format Address";        TotalAmounExclVATLbl: Text[50];    begin        FormatAddress.SetLanguageCode(SalesHeader."Language Code");        Customer.Get(SalesHeader."Sell-to Customer No.");        FormatDocument.SetSalesPerson(SalespersonPurchaser, SalesHeader."Salesperson Code", SalesPersonLblText);        SalespersonPurchaserName := SalespersonPurchaser.Name;        FormatDocument.SetShipmentMethod(ShipmentMethod, SalesHeader."Shipment Method Code", SalesHeader."Language Code");        ShipmentMethodDescription := ShipmentMethod.Description;        FormatAddress.GetCompanyAddr(SalesHeader."Responsibility Center", ResponsibilityCenter, CompanyInformation, CompanyAddress);        FormatAddress.SalesHeaderBillTo(CustomerAddress, SalesHeader);        if SalesHeader."Currency Code" = '' then begin            GeneralLedgerSetup.Get();            GeneralLedgerSetup.TestField("LCY Code");            CurrencyCode := GeneralLedgerSetup."LCY Code";            Currency.InitRoundingPrecision();        end else begin            CurrencyCode := SalesHeader."Currency Code";            Currency.Get(SalesHeader."Currency Code");        end;        FormatDocument.SetTotalLabels(SalesHeader."Currency Code", TotalAmountLbl, TotalAmountInclVATLbl, TotalAmounExclVATLbl);    end;    local procedure DocumentCaption(): Text    var        DocCaption: Text;    begin        OnBeforeGetDocumentCaption(Header, DocCaption);        if DocCaption <> '' then            exit(DocCaption);        exit(DocumentTitleLbl);    end;    local procedure GetItemForRec(ItemNo: Code[20])    var        IsHandled: Boolean;    begin        IsHandled := false;        OnBeforeGetItemForRec(ItemNo, IsHandled);        if IsHandled then            exit;        Item.Get(ItemNo);    end;    [IntegrationEvent(false, false)]    local procedure OnAfterLineOnPreDataItem(var SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line")    begin    end;    [IntegrationEvent(false, false)]    local procedure OnBeforeGetDocumentCaption(SalesHeader: Record "Sales Header"; var DocCaption: Text)    begin    end;    [IntegrationEvent(true, false)]    local procedure OnBeforeGetItemForRec(ItemNo: Code[20]; var IsHandled: Boolean)    begin    end;    [IntegrationEvent(false, false)]    local procedure OnBeforeLineOnAfterGetRecord(SalesHeader: Record "Sales Header"; var SalesLine: Record "Sales Line")    begin    end;    [IntegrationEvent(false, false)]    local procedure OnInitReportForGlobalVariable(var IsHandled: Boolean; var LegalOfficeTxt: Text; var LegalOfficeLbl: Text)    begin    end;}