Announcements
I created a custom factbox for Sales Quote Details View in an AL Project. I would like to copy some lines from the Sales Line Subform and I ran into a problem when trying to copy Total Incl. Tax field. I tried to use the TotalSalesLine property found in the Sales Quote Subform and its connected procedures but its seems something is missing because the value displayed is always zero.
Can someone tell me what is missing in my code to make the field Total Incl. Tax work ?
This is my code:
Great.
You were right the problem was in the CalculateSalesLineCost procedure.
Hi,
Please correct the below code in Yellow.
local procedure CalculateSalesLineCost() ReturnValue: Decimal
begin
if Rec."Line Discount %" <> 0 then
ReturnValue := "Unit Cost" * Quantity * ("Line Discount %" / 100)
else
ReturnValue := "Unit Cost" * Quantity
end;
Thank you for the reply.
Your solution works when Line Discount is not defined but when I set it the factbox crashes and an error message is displayed:
Error: Overflow under conversion of Microsoft.Dynamics.Nav.Runtime.Decimal18 value 0.12 to System.Int32..
Hi chigivigi ,
Can you please try below code?
page 56001 "Sales Line Custom Factbox"
{
Caption = 'Sales Calculation';
PageType = CardPart;
SourceTable = "Sales Line";
layout
{
area(content)
{
group(SalesTotalCalculation)
{
Caption = 'Sales Total Calculation';
field("Total Amount Incl. VAT"; TotalSalesLine."Amount Including VAT")
{
ApplicationArea = Basic, Suite;
Caption = 'Total Amount Incl. VAT';
AutoFormatExpression = Currency.Code;
AutoFormatType = 1;
CaptionClass = DocumentTotals.GetTotalInclVATCaption(Currency.Code);
}
}
}
}
// trigger OnAfterGetCurrRecord()
// begin
// Rec.ClearSalesHeader();
// end;
trigger OnAfterGetRecord()
begin
Rec.CalcFields("Reserved Quantity", "Attached Doc Count");
SalesInfoPaneMgt.ResetItemNo();
GetTotalSalesHeader;
CalculateTotals();
end;
trigger OnOpenPage()
begin
SetOpenPage();
end;
var
Currency: Record Currency;
DocumentTotals: Codeunit "Document Totals";
SuppressTotals: Boolean;
TotalSalesHeader: Record "Sales Header";
protected var
SalesInfoPaneMgt: Codeunit "Sales Info-Pane Management";
ItemAvailFormsMgt: Codeunit "Item Availability Forms Mgt";
TotalSalesLine: Record "Sales Line";
VATAmount: Decimal;
InvoiceDiscountAmount: Decimal;
InvoiceDiscountPct: Decimal;
local procedure SetOpenPage()
begin
SuppressTotals := CurrentClientType() = ClientType::ODataV4;
end;
local procedure ShowNo(): Code[20]
begin
if Rec.Type <> Rec.Type::Item then
exit('');
exit(Rec."No.");
end;
local procedure GetTotalSalesHeader()
begin
DocumentTotals.GetTotalSalesHeaderAndCurrency(Rec, TotalSalesHeader, Currency);
end;
local procedure CalculateSalesLineCost() ReturnValue: Integer
begin
if Rec."Line Discount %" <> 0 then
ReturnValue := "Unit Cost" * Quantity * ("Line Discount %" / 100)
else
ReturnValue := "Unit Cost" * Quantity
end;
// procedure ClearTotalSalesHeader();
// begin
// Clear(TotalSalesHeader);
// end;
procedure CalculateTotals()
begin
OnBeforeCalculateTotals(TotalSalesLine, SuppressTotals);
if SuppressTotals then
exit;
DocumentTotals.SalesCheckIfDocumentChanged(Rec, xRec);
DocumentTotals.CalculateSalesSubPageTotals(TotalSalesHeader, TotalSalesLine, VATAmount, InvoiceDiscountAmount, InvoiceDiscountPct);
DocumentTotals.RefreshSalesLine(Rec);
end;
[IntegrationEvent(false, false)]
local procedure OnBeforeCalculateTotals(var TotalSalesLine: Record "Sales Line"; SuppressTotals: Boolean)
begin
end;
}
pageextension 56002 PageExtension56002 extends "Sales Quote"
{
layout
{
addbefore(Control1906127307)
{
part(CustomControl5653357897; "Sales Line Custom Factbox")
{
ApplicationArea = Suite;
Provider = SalesLines;
SubPageLink = "Document Type" = FIELD("Document Type"), "Document No." = FIELD("Document No."), "Line No." = FIELD("Line No.");
}
}
}
}
|
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156