Page 397 Sales Invoice Statistics

Base Application, Microsoft.Sales.History

src/Layers/W1/BaseApp/Sales/History/SalesInvoiceStatistics.Page.al396 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.Finance.Currency;using Microsoft.Finance.VAT.Calculation;using Microsoft.Inventory.Costing;using Microsoft.Sales.Customer;using Microsoft.Sales.Receivables;/// <summary>/// Displays statistical and financial information for a posted sales invoice including amounts, VAT, costs, and payment status./// </summary>page 397 "Sales Invoice Statistics"{    Caption = 'Sales Invoice Statistics';    Editable = false;    LinksAllowed = false;    PageType = ListPlus;    SourceTable = "Sales Invoice Header";    layout    {        area(content)        {            group(General)            {                Caption = 'General';                field("CustAmount + InvDiscAmount"; CustAmount + InvDiscAmount)                {                    ApplicationArea = Basic, Suite;                    AutoFormatExpression = Rec."Currency Code";                    AutoFormatType = 1;                    Caption = 'Amount';                    ToolTip = 'Specifies the net amount of all the lines in the sales document.';                }                field(InvDiscAmount; InvDiscAmount)                {                    ApplicationArea = Basic, Suite;                    AutoFormatExpression = Rec."Currency Code";                    AutoFormatType = 1;                    Caption = 'Inv. Discount Amount';                    ToolTip = 'Specifies the invoice discount amount for the sales document.';                }                field(CustAmount; CustAmount)                {                    ApplicationArea = Basic, Suite;                    AutoFormatExpression = Rec."Currency Code";                    AutoFormatType = 1;                    Caption = 'Total';                    ToolTip = 'Specifies the total amount, less any invoice discount amount, and excluding VAT for the sales document.';                }                field(VATAmount; VATAmount)                {                    ApplicationArea = Basic, Suite;                    AutoFormatExpression = Rec."Currency Code";                    AutoFormatType = 1;                    CaptionClass = '3,' + Format(VATAmountText);                    Caption = 'VAT Amount';                    ToolTip = 'Specifies the total VAT amount that has been calculated for all the lines in the sales document.';                }                field(AmountInclVAT; AmountInclVAT)                {                    ApplicationArea = Basic, Suite;                    AutoFormatExpression = Rec."Currency Code";                    AutoFormatType = 1;                    Caption = 'Total Incl. VAT';                    ToolTip = 'Specifies the total amount, including VAT, that will be posted to the customer''s account for all the lines in the sales document.';                }                field(AmountLCY; AmountLCY)                {                    ApplicationArea = Basic, Suite;                    AutoFormatType = 1;                    AutoFormatExpression = '';                    Caption = 'Sales (LCY)';                    ToolTip = 'Specifies your total sales turnover in the fiscal year.';                }                field(ProfitLCY; ProfitLCY)                {                    ApplicationArea = Basic, Suite;                    AutoFormatType = 1;                    AutoFormatExpression = '';                    Caption = 'Original Profit (LCY)';                    ToolTip = 'Specifies the original profit that was associated with the sales when they were originally posted.';                }                field(AdjustedProfitLCY; AdjProfitLCY)                {                    ApplicationArea = Basic, Suite;                    AutoFormatType = 1;                    AutoFormatExpression = '';                    Caption = 'Adjusted Profit (LCY)';                    ToolTip = 'Specifies the profit, taking into consideration changes in the purchase prices of the goods.';                }                field(ProfitPct; ProfitPct)                {                    AutoFormatType = 0;                    ApplicationArea = Basic, Suite;                    Caption = 'Original Profit %';                    DecimalPlaces = 1 : 1;                    ToolTip = 'Specifies the original percentage of profit that was associated with the sales when they were originally posted.';                }                field(AdjProfitPct; AdjProfitPct)                {                    AutoFormatType = 0;                    ApplicationArea = Basic, Suite;                    Caption = 'Adjusted Profit %';                    DecimalPlaces = 1 : 1;                    ToolTip = 'Specifies the percentage of profit for all sales, including changes that occurred in the purchase prices of the goods.';                }                field(LineQty; LineQty)                {                    AutoFormatType = 0;                    ApplicationArea = Basic, Suite;                    Caption = 'Quantity';                    DecimalPlaces = 0 : 5;                    ToolTip = 'Specifies the total quantity of G/L account entries, items and/or resources in the sales document.';                }                field(TotalParcels; TotalParcels)                {                    AutoFormatType = 0;                    ApplicationArea = Basic, Suite;                    Caption = 'Parcels';                    DecimalPlaces = 0 : 5;                    ToolTip = 'Specifies the total number of parcels in the sales document.';                }                field(TotalNetWeight; TotalNetWeight)                {                    AutoFormatType = 0;                    ApplicationArea = Basic, Suite;                    Caption = 'Net Weight';                    DecimalPlaces = 0 : 5;                    ToolTip = 'Specifies the total net weight of the items in the sales document.';                }                field(TotalGrossWeight; TotalGrossWeight)                {                    AutoFormatType = 0;                    ApplicationArea = Basic, Suite;                    Caption = 'Gross Weight';                    DecimalPlaces = 0 : 5;                    ToolTip = 'Specifies the total gross weight of the items in the sales document.';                }                field(TotalVolume; TotalVolume)                {                    AutoFormatType = 0;                    ApplicationArea = Basic, Suite;                    Caption = 'Volume';                    DecimalPlaces = 0 : 5;                    ToolTip = 'Specifies the total volume of the items in the sales document.';                }                field(CostLCY; CostLCY)                {                    ApplicationArea = Basic, Suite;                    AutoFormatType = 1;                    AutoFormatExpression = '';                    Caption = 'Original Cost (LCY)';                    ToolTip = 'Specifies the total cost, in LCY, of the G/L account entries, items and/or resources in the sales document.';                }                field(AdjustedCostLCY; TotalAdjCostLCY)                {                    ApplicationArea = Basic, Suite;                    AutoFormatType = 1;                    AutoFormatExpression = '';                    Caption = 'Adjusted Cost (LCY)';                    ToolTip = 'Specifies the total cost, in LCY, of the items in the posted sales invoice, adjusted for any changes in the original costs of these items.';                }                field("TotalAdjCostLCY - CostLCY"; TotalAdjCostLCY - CostLCY)                {                    ApplicationArea = Basic, Suite;                    AutoFormatType = 1;                    AutoFormatExpression = '';                    Caption = 'Cost Adjmt. Amount (LCY)';                    ToolTip = 'Specifies the difference between the original cost and the total adjusted cost of the items in the posted sales invoice.';                    trigger OnDrillDown()                    begin                        Rec.LookupAdjmtValueEntries();                    end;                }            }            part(Subform; "VAT Specification Subform")            {                ApplicationArea = Basic, Suite;                Editable = false;            }            group(Customer)            {                Caption = 'Customer';#pragma warning disable AA0100                field("Cust.""Balance (LCY)"""; Cust."Balance (LCY)")#pragma warning restore AA0100                {                    ApplicationArea = Basic, Suite;                    AutoFormatType = 1;                    Caption = 'Balance (LCY)';                    ToolTip = 'Specifies the balance in LCY on the customer''s account.';                }#pragma warning disable AA0100                field("Cust.""Credit Limit (LCY)"""; Cust."Credit Limit (LCY)")#pragma warning restore AA0100                {                    ApplicationArea = Basic, Suite;                    AutoFormatType = 1;                    Caption = 'Credit Limit (LCY)';                    ToolTip = 'Specifies the credit limit of the customer on the sales document. The value 0 represents unlimited credit.';                }                field(CreditLimitLCYExpendedPct; CreditLimitLCYExpendedPct)                {                    ApplicationArea = Basic, Suite;                    AutoFormatType = 1;                    AutoFormatExpression = '';                    Caption = 'Expended % of Credit Limit (LCY)';                    ExtendedDatatype = Ratio;                    ToolTip = 'Specifies the expended percentage of the credit limit in (LCY).';                }            }        }    }    actions    {    }    trigger OnAfterGetRecord()    var        CustLedgEntry: Record "Cust. Ledger Entry";    begin        ClearAll();        Currency.Initialize(Rec."Currency Code");        CalculateTotals();        VATAmount := AmountInclVAT - CustAmount;        InvDiscAmount := Round(InvDiscAmount, Currency."Amount Rounding Precision");        if VATPercentage <= 0 then            VATAmountText := Text000        else            VATAmountText := StrSubstNo(Text001, VATPercentage);        if Rec."Currency Code" = '' then            AmountLCY := CustAmount        else            AmountLCY :=              CurrExchRate.ExchangeAmtFCYToLCY(                WorkDate(), Rec."Currency Code", CustAmount, Rec."Currency Factor");        CustLedgEntry.SetCurrentKey("Document No.");        CustLedgEntry.SetRange("Document No.", Rec."No.");        CustLedgEntry.SetRange("Document Type", CustLedgEntry."Document Type"::Invoice);        CustLedgEntry.SetRange("Customer No.", Rec."Bill-to Customer No.");        if not CustLedgEntry.IsEmpty() then begin            CustLedgEntry.CalcSums("Sales (LCY)");            AmountLCY := CustLedgEntry."Sales (LCY)";        end;        OnAfterGetRecordOnBeforeCalculateProfitLCY(Rec, AmountLCY, CustAmount, InvDiscAmount, CostLCY);        ProfitLCY := AmountLCY - CostLCY;        if AmountLCY <> 0 then            ProfitPct := Round(100 * ProfitLCY / AmountLCY, 0.1);        AdjProfitLCY := AmountLCY - TotalAdjCostLCY;        OnAfterGetRecordOnAfterCalculateAdjProfitLCY(Rec, AdjProfitLCY);        if AmountLCY <> 0 then            AdjProfitPct := Round(100 * AdjProfitLCY / AmountLCY, 0.1);        if Cust.Get(Rec."Bill-to Customer No.") then            Cust.CalcFields("Balance (LCY)")        else            Clear(Cust);        case true of            Cust."Credit Limit (LCY)" = 0:                CreditLimitLCYExpendedPct := 0;            Cust."Balance (LCY)" / Cust."Credit Limit (LCY)" < 0:                CreditLimitLCYExpendedPct := 0;            Cust."Balance (LCY)" / Cust."Credit Limit (LCY)" > 1:                CreditLimitLCYExpendedPct := 10000;            else                CreditLimitLCYExpendedPct := Round(Cust."Balance (LCY)" / Cust."Credit Limit (LCY)" * 10000, 1);        end;        SalesInvLine.CalcVATAmountLines(Rec, TempVATAmountLine);        CurrPage.Subform.PAGE.SetTempVATAmountLine(TempVATAmountLine);        CurrPage.Subform.PAGE.InitGlobals(Rec."Currency Code", false, false, false, false, Rec."VAT Base Discount %");    end;    var        CurrExchRate: Record "Currency Exchange Rate";        Cust: Record Customer;        TempVATAmountLine: Record "VAT Amount Line" temporary;        TotalAdjCostLCY: Decimal;        VATAmount: Decimal;        ProfitLCY: Decimal;        ProfitPct: Decimal;        AdjProfitLCY: Decimal;        AdjProfitPct: Decimal;        LineQty: Decimal;        TotalNetWeight: Decimal;        TotalGrossWeight: Decimal;        TotalVolume: Decimal;        TotalParcels: Decimal;        CreditLimitLCYExpendedPct: Decimal;        VATPercentage: Decimal;        VATAmountText: Text[30];#pragma warning disable AA0074        Text000: Label 'VAT Amount';#pragma warning disable AA0470        Text001: Label '%1% VAT';#pragma warning restore AA0470#pragma warning restore AA0074    protected var        Currency: Record Currency;        SalesInvLine: Record "Sales Invoice Line";        AmountInclVAT: Decimal;        AmountLCY: Decimal;        CostLCY: Decimal;        CustAmount: Decimal;        InvDiscAmount: Decimal;    local procedure CalculateTotals()    var        CostCalcMgt: Codeunit "Cost Calculation Management";        IsHandled: Boolean;    begin        IsHandled := false;        OnBeforeCalculateTotals(            Rec, CustAmount, AmountInclVAT, InvDiscAmount, CostLCY, TotalAdjCostLCY,            LineQty, TotalNetWeight, TotalGrossWeight, TotalVolume, TotalParcels, IsHandled, VATpercentage);        if IsHandled then            exit;        SalesInvLine.SetRange("Document No.", Rec."No.");        OnCalculateTotalsOnAfterSalesInvLineSetFilters(SalesInvLine, Rec);        if SalesInvLine.Find('-') then            repeat                CustAmount += SalesInvLine.Amount;                AmountInclVAT += SalesInvLine."Amount Including VAT";                if Rec."Prices Including VAT" then                    InvDiscAmount += SalesInvLine."Inv. Discount Amount" / (1 + SalesInvLine.GetVATPct() / 100)                else                    InvDiscAmount += SalesInvLine."Inv. Discount Amount";                CostLCY += SalesInvLine.Quantity * SalesInvLine."Unit Cost (LCY)";                LineQty += SalesInvLine.Quantity;                TotalNetWeight += SalesInvLine.Quantity * SalesInvLine."Net Weight";                TotalGrossWeight += SalesInvLine.Quantity * SalesInvLine."Gross Weight";                TotalVolume += SalesInvLine.Quantity * SalesInvLine."Unit Volume";                if SalesInvLine."Units per Parcel" > 0 then                    TotalParcels += Round(SalesInvLine.Quantity / SalesInvLine."Units per Parcel", 1, '>');                if SalesInvLine."VAT %" <> VATPercentage then                    if VATPercentage = 0 then                        VATPercentage := SalesInvLine.GetVATPct()                    else                        VATPercentage := -1;                TotalAdjCostLCY +=                  CostCalcMgt.CalcSalesInvLineCostLCY(SalesInvLine) + CostCalcMgt.CalcSalesInvLineNonInvtblCostAmt(SalesInvLine);                OnCalculateTotalsOnAfterAddLineTotals(                    SalesInvLine, CustAmount, AmountInclVAT, InvDiscAmount, CostLCY, TotalAdjCostLCY,                    LineQty, TotalNetWeight, TotalGrossWeight, TotalVolume, TotalParcels, Rec)            until SalesInvLine.Next() = 0;    end;    [IntegrationEvent(false, false)]    local procedure OnAfterGetRecordOnAfterCalculateAdjProfitLCY(SalesInvoiceHeader: Record "Sales Invoice Header"; var AdjProfitLCY: Decimal)    begin    end;    [IntegrationEvent(false, false)]    local procedure OnBeforeCalculateTotals(SalesInvoiceHeader: Record "Sales Invoice Header"; var CustAmount: Decimal; var AmountInclVAT: Decimal; var InvDiscAmount: Decimal; var CostLCY: Decimal; var TotalAdjCostLCY: Decimal; var LineQty: Decimal; var TotalNetWeight: Decimal; var TotalGrossWeight: Decimal; var TotalVolume: Decimal; var TotalParcels: Decimal; var IsHandled: Boolean; var VATPercentage: Decimal)    begin    end;    [IntegrationEvent(false, false)]    local procedure OnCalculateTotalsOnAfterSalesInvLineSetFilters(var SalesInvoiceLine: Record "Sales Invoice Line"; SalesInvoiceHeader: Record "Sales Invoice Header")    begin    end;    [IntegrationEvent(false, false)]    local procedure OnCalculateTotalsOnAfterAddLineTotals(var SalesInvLine: Record "Sales Invoice Line"; var CustAmount: Decimal; var AmountInclVAT: Decimal; var InvDiscAmount: Decimal; var CostLCY: Decimal; var TotalAdjCostLCY: Decimal; var LineQty: Decimal; var TotalNetWeight: Decimal; var TotalGrossWeight: Decimal; var TotalVolume: Decimal; var TotalParcels: Decimal; SalesInvoiceHeader: Record "Sales Invoice Header")    begin    end;    [IntegrationEvent(false, false)]    local procedure OnAfterGetRecordOnBeforeCalculateProfitLCY(var SalesInvoiceHeader: Record "Sales Invoice Header"; var AmountLCY: Decimal; var CustAmount: Decimal; var InvDiscAmount: Decimal; var CostLCY: Decimal)    begin    end;}