namespace Microsoft.Sales.Reports;
using Microsoft.CRM.Team;
using Microsoft.Inventory.Costing;
using Microsoft.Sales.Receivables;
report 115 "Salesperson - Commission"
{
DefaultLayout = RDLC;
RDLCLayout = './Sales/Reports/SalespersonCommission.rdlc';
ApplicationArea = Suite;
Caption = 'Salesperson - Commission';
UsageCategory = ReportsAndAnalysis;
dataset
{
dataitem("Salesperson/Purchaser"; "Salesperson/Purchaser")
{
DataItemTableView = sorting(Code);
PrintOnlyIfDetail = true;
RequestFilterFields = "Code";
column(STRSUBSTNO_Text000_PeriodText_; StrSubstNo(PeriodTxt, PeriodText))
{
}
column(COMPANYNAME; COMPANYPROPERTY.DisplayName())
{
}
column(Salesperson_Purchaser__TABLECAPTION__________SalespersonFilter; TableCaption + ': ' + SalespersonFilter)
{
}
column(SalespersonFilter; SalespersonFilter)
{
}
column(Cust__Ledger_Entry__TABLECAPTION__________CustLedgEntryFilter; "Cust. Ledger Entry".TableCaption + ': ' + CustLedgEntryFilter)
{
}
column(CustLedgEntryFilter; CustLedgEntryFilter)
{
}
column(PageGroupNo; PageGroupNo)
{
}
column(Salesperson_Purchaser_Code; Code)
{
}
column(Salesperson_Purchaser_Name; Name)
{
}
column(Salesperson_Purchaser__Commission___; "Commission %")
{
}
column(Cust__Ledger_Entry___Sales__LCY__; "Cust. Ledger Entry"."Sales (LCY)")
{
}
column(Cust__Ledger_Entry___Profit__LCY__; "Cust. Ledger Entry"."Profit (LCY)")
{
}
column(SalesCommissionAmt; SalesCommissionAmt)
{
AutoFormatType = 1;
}
column(ProfitCommissionAmt; ProfitCommissionAmt)
{
AutoFormatType = 1;
}
column(AdjProfit; AdjProfit)
{
AutoFormatType = 1;
}
column(AdjProfitCommissionAmt; AdjProfitCommissionAmt)
{
AutoFormatType = 1;
}
column(Salesperson___CommissionCaption; Salesperson___CommissionCaptionLbl)
{
}
column(CurrReport_PAGENOCaption; CurrReport_PAGENOCaptionLbl)
{
}
column(All_amounts_are_in_LCYCaption; All_amounts_are_in_LCYCaptionLbl)
{
}
column(Cust__Ledger_Entry__Posting_Date_Caption; Cust__Ledger_Entry__Posting_Date_CaptionLbl)
{
}
column(Cust__Ledger_Entry__Document_No__Caption; "Cust. Ledger Entry".FieldCaption("Document No."))
{
}
column(Cust__Ledger_Entry__Customer_No__Caption; "Cust. Ledger Entry".FieldCaption("Customer No."))
{
}
column(Cust__Ledger_Entry__Sales__LCY__Caption; "Cust. Ledger Entry".FieldCaption("Sales (LCY)"))
{
}
column(Cust__Ledger_Entry__Profit__LCY__Caption; "Cust. Ledger Entry".FieldCaption("Profit (LCY)"))
{
}
column(SalesCommissionAmt_Control32Caption; SalesCommissionAmt_Control32CaptionLbl)
{
}
column(ProfitCommissionAmt_Control33Caption; ProfitCommissionAmt_Control33CaptionLbl)
{
}
column(AdjProfit_Control39Caption; AdjProfit_Control39CaptionLbl)
{
}
column(AdjProfitCommissionAmt_Control45Caption; AdjProfitCommissionAmt_Control45CaptionLbl)
{
}
column(Salesperson_Purchaser__Commission___Caption; FieldCaption("Commission %"))
{
}
column(TotalCaption; TotalCaptionLbl)
{
}
dataitem("Cust. Ledger Entry"; "Cust. Ledger Entry")
{
DataItemLink = "Salesperson Code" = field(Code);
DataItemTableView = sorting("Salesperson Code", "Posting Date") where("Document Type" = filter(Invoice | "Credit Memo"));
RequestFilterFields = "Posting Date";
column(Cust__Ledger_Entry__Posting_Date_; Format("Posting Date"))
{
}
column(Cust__Ledger_Entry__Document_No__; "Document No.")
{
}
column(Cust__Ledger_Entry__Customer_No__; "Customer No.")
{
}
column(Cust__Ledger_Entry__Sales__LCY__; "Sales (LCY)")
{
}
column(Cust__Ledger_Entry__Profit__LCY__; "Profit (LCY)")
{
}
column(SalesCommissionAmt_Control32; SalesCommissionAmt)
{
AutoFormatType = 1;
}
column(ProfitCommissionAmt_Control33; ProfitCommissionAmt)
{
AutoFormatType = 1;
}
column(AdjProfit_Control39; AdjProfit)
{
AutoFormatType = 1;
}
column(AdjProfitCommissionAmt_Control45; AdjProfitCommissionAmt)
{
AutoFormatType = 1;
}
column(Salesperson_Purchaser__Name; "Salesperson/Purchaser".Name)
{
}
trigger OnAfterGetRecord()
var
CostCalcMgt: Codeunit "Cost Calculation Management";
begin
SalesCommissionAmt := Round("Sales (LCY)" * "Salesperson/Purchaser"."Commission %" / 100);
ProfitCommissionAmt := Round("Profit (LCY)" * "Salesperson/Purchaser"."Commission %" / 100);
AdjProfit := "Profit (LCY)" + CostCalcMgt.CalcCustLedgAdjmtCostLCY("Cust. Ledger Entry");
AdjProfitCommissionAmt := Round(AdjProfit * "Salesperson/Purchaser"."Commission %" / 100);
end;
trigger OnPreDataItem()
begin
ClearAmounts();
end;
}
trigger OnAfterGetRecord()
begin
if PrintOnlyOnePerPageReq then
PageGroupNo := PageGroupNo + 1;
end;
trigger OnPreDataItem()
begin
PageGroupNo := 1;
ClearAmounts();
end;
}
}
requestpage
{
SaveValues = true;
layout
{
area(content)
{
group(Options)
{
Caption = 'Options';
field(PrintOnlyOnePerPage; PrintOnlyOnePerPageReq)
{
ApplicationArea = Suite;
Caption = 'New Page per Person';
ToolTip = 'Specifies if each person''s information is printed on a new page if you have chosen two or more persons to be included in the report.';
}
}
}
}
actions
{
}
}
labels
{
}
trigger OnPreReport()
begin
SalespersonFilter := "Salesperson/Purchaser".GetFilters();
CustLedgEntryFilter := "Cust. Ledger Entry".GetFilters();
PeriodText := "Cust. Ledger Entry".GetFilter("Posting Date");
end;
var
PeriodTxt: Label 'Period: %1', Comment = '%1 - period text';
SalespersonFilter: Text;
CustLedgEntryFilter: Text;
PeriodText: Text;
AdjProfit: Decimal;
ProfitCommissionAmt: Decimal;
AdjProfitCommissionAmt: Decimal;
SalesCommissionAmt: Decimal;
PrintOnlyOnePerPageReq: Boolean;
PageGroupNo: Integer;
Salesperson___CommissionCaptionLbl: Label 'Salesperson - Commission';
CurrReport_PAGENOCaptionLbl: Label 'Page';
All_amounts_are_in_LCYCaptionLbl: Label 'All amounts are in LCY';
Cust__Ledger_Entry__Posting_Date_CaptionLbl: Label 'Posting Date';
SalesCommissionAmt_Control32CaptionLbl: Label 'Sales Commission (LCY)';
ProfitCommissionAmt_Control33CaptionLbl: Label 'Profit Commission (LCY)';
AdjProfit_Control39CaptionLbl: Label 'Adjusted Profit (LCY)';
AdjProfitCommissionAmt_Control45CaptionLbl: Label 'Adjusted Profit Commission (LCY)';
TotalCaptionLbl: Label 'Total';
local procedure ClearAmounts()
begin
Clear(AdjProfit);
Clear(ProfitCommissionAmt);
Clear(AdjProfitCommissionAmt);
Clear(SalesCommissionAmt);
end;
}
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;
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;
Caption = 'Sales (LCY)';
ToolTip = 'Specifies your total sales turnover in the fiscal year.';
}
field(ProfitLCY; ProfitLCY)
{
ApplicationArea = Basic, Suite;
AutoFormatType = 1;
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;
Caption = 'Adjusted Profit (LCY)';
ToolTip = 'Specifies the profit, taking into consideration changes in the purchase prices of the goods.';
}
field(ProfitPct; ProfitPct)
{
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)
{
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)
{
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)
{
ApplicationArea = Basic, Suite;
Caption = 'Parcels';
DecimalPlaces = 0 : 5;
ToolTip = 'Specifies the total number of parcels in the sales document.';
}
field(TotalNetWeight; TotalNetWeight)
{
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)
{
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)
{
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;
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;
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;
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 OnLookup(var Text: Text): Boolean
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 information about the credit limit in LCY, for the customer who you created and posted this sales invoice for. ';
}
field(CreditLimitLCYExpendedPct; CreditLimitLCYExpendedPct)
{
ApplicationArea = Basic, Suite;
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;
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];
Text000: Label 'VAT Amount';
Text001: Label '%1% VAT';
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."VAT %" / 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."VAT %"
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;
}
André Arnaud de Cal...
292,494
Super User 2025 Season 1
Martin Dráb
231,309
Most Valuable Professional
nmaenpaa
101,156