ALAppExtensions
ALAppExtensions copied to clipboard
[Event Request] codeunit 827 "Service Post Invoice Events"
Hi,
Is it possible to change code like below?
codeunit 817 "Service Post Invoice" Changes
procedure PrepareLine(DocumentHeaderVar: Variant; DocumentLineVar: Variant; DocumentLineACYVar: Variant)
var
ServiceHeader: Record "Service Header";
ServiceLine: Record "Service Line";
ServiceLineACY: Record "Service Line";
GenPostingSetup: Record "General Posting Setup";
InvoicePostingBuffer: Record "Invoice Posting Buffer";
ServCost: Record "Service Cost";
TotalVAT: Decimal;
TotalVATACY: Decimal;
TotalAmount: Decimal;
TotalAmountACY: Decimal;
TotalVATBase: Decimal;
TotalVATBaseACY: Decimal;
SalesAccount: Code[20]; //***NEW***
IsHandled: Boolean;
begin
ServiceHeader := DocumentHeaderVar;
ServiceLine := DocumentLineVar;
ServiceLineACY := DocumentLineACYVar;
IsHandled := false;
ServicePostInvoiceEvents.RunOnBeforePrepareLine(ServiceHeader, ServiceLine, ServiceLineACY, IsHandled);
if IsHandled then
exit;
SalesSetup.Get();
if not ApplicationAreaMgmt.IsSalesTaxEnabled() then
if (ServiceLine."Gen. Bus. Posting Group" <> GenPostingSetup."Gen. Bus. Posting Group") or
(ServiceLine."Gen. Prod. Posting Group" <> GenPostingSetup."Gen. Prod. Posting Group")
then begin
GenPostingSetup.Get(ServiceLine."Gen. Bus. Posting Group", ServiceLine."Gen. Prod. Posting Group");
GenPostingSetup.TestField(Blocked, false);
end;
InvoicePostingBuffer.PrepareService(ServiceLine);
TotalVAT := ServiceLine."Amount Including VAT" - ServiceLine.Amount;
TotalVATACY := ServiceLineACY."Amount Including VAT" - ServiceLineACY.Amount;
TotalAmount := ServiceLine.Amount;
TotalAmountACY := ServiceLineACY.Amount;
TotalVATBase := ServiceLine."VAT Base Amount";
TotalVATBaseACY := ServiceLineACY."VAT Base Amount";
if SalesSetup."Discount Posting" in
[SalesSetup."Discount Posting"::"Invoice Discounts", SalesSetup."Discount Posting"::"All Discounts"]
then begin
CalcInvoiceDiscountPosting(InvoicePostingBuffer, ServiceLine, ServiceLineACY, ServiceHeader);
if (InvoicePostingBuffer.Amount <> 0) or (InvoicePostingBuffer."Amount (ACY)" <> 0) then begin
InvoicePostingBuffer.SetAccount(
GenPostingSetup.GetSalesInvDiscAccount(), TotalVAT, TotalVATACY, TotalAmount, TotalAmountACY);
InvoicePostingBuffer.UpdateVATBase(TotalVATBase, TotalVATBaseACY);
if ServiceLine."Line Discount %" = 100 then begin
InvoicePostingBuffer."VAT Base Amount" := 0;
InvoicePostingBuffer."VAT Base Amount (ACY)" := 0;
InvoicePostingBuffer."VAT Amount" := 0;
InvoicePostingBuffer."VAT Amount (ACY)" := 0;
end;
UpdateInvoicePostingBuffer(InvoicePostingBuffer, ServiceLine);
end;
end;
if SalesSetup."Discount Posting" in
[SalesSetup."Discount Posting"::"Line Discounts", SalesSetup."Discount Posting"::"All Discounts"]
then begin
CalcLineDiscountPosting(InvoicePostingBuffer, ServiceLine, ServiceLineACY, ServiceHeader);
if (InvoicePostingBuffer.Amount <> 0) or (InvoicePostingBuffer."Amount (ACY)" <> 0) then begin
InvoicePostingBuffer.SetAccount(
GenPostingSetup.GetSalesLineDiscAccount(), TotalVAT, TotalVATACY, TotalAmount, TotalAmountACY);
InvoicePostingBuffer.UpdateVATBase(TotalVATBase, TotalVATBaseACY);
UpdateInvoicePostingBuffer(InvoicePostingBuffer, ServiceLine);
end;
end;
//***OLD***BEGIN
InvoicePostingBuffer.SetAmounts(
TotalVAT, TotalVATACY, TotalAmount, TotalAmountACY, ServiceLine."VAT Difference", TotalVATBase, TotalVATBaseACY);
case ServiceLine.Type of
ServiceLine.Type::"G/L Account":
InvoicePostingBuffer.SetAccount(ServiceLine."No.", TotalVAT, TotalVATACY, TotalAmount, TotalAmountACY);
ServiceLine.Type::Cost:
begin
ServCost.Get(ServiceLine."No.");
InvoicePostingBuffer.SetAccount(ServCost."Account No.", TotalVAT, TotalVATACY, TotalAmount, TotalAmountACY);
end
else
if ServiceLine."Document Type" = ServiceLine."Document Type"::"Credit Memo" then
InvoicePostingBuffer.SetAccount(
GenPostingSetup.GetSalesCrMemoAccount(), TotalVAT, TotalVATACY, TotalAmount, TotalAmountACY)
else
InvoicePostingBuffer.SetAccount(
GenPostingSetup.GetSalesAccount(), TotalVAT, TotalVATACY, TotalAmount, TotalAmountACY);
end;
InvoicePostingBuffer.UpdateVATBase(TotalVATBase, TotalVATBaseACY);
ServicePostInvoiceEvents.RunOnPrepareLineOnAfterFillInvoicePostingBuffer(InvoicePostingBuffer, ServiceLine, ServiceLineACY, SuppressCommit);
UpdateInvoicePostingBuffer(InvoicePostingBuffer, ServiceLine);
end;
//***OLD***END
//***NEW***BEGIN
IsHandled := false;
ServicePostInvoiceEvents.RunOnPrepareLineOnBeforeSetAmounts(
ServiceLine, ServiceLineACY, InvoicePostingBuffer,
TotalVAT, TotalVATACY, TotalAmount, TotalAmountACY, TotalVATBase, TotalVATBaseACY, IsHandled);
if not IsHandled then
InvoicePostingBuffer.SetAmounts(
TotalVAT, TotalVATACY, TotalAmount, TotalAmountACY, ServiceLine."VAT Difference", TotalVATBase, TotalVATBaseACY);
ServicePostInvoiceEvents.RunOnPrepareLineOnAfterSetAmounts(InvoicePostingBuffer, ServiceLine);
SalesAccount := GetSalesAccount(ServiceLine, GenPostingSetup);
ServicePostInvoiceEvents.RunOnPrepareLineOnBeforeSetAccount(ServiceHeader, ServiceLine, SalesAccount);
InvoicePostingBuffer.SetAccount(SalesAccount, TotalVAT, TotalVATACY, TotalAmount, TotalAmountACY);
InvoicePostingBuffer.UpdateVATBase(TotalVATBase, TotalVATBaseACY);
ServicePostInvoiceEvents.RunOnPrepareLineOnAfterFillInvoicePostingBuffer(InvoicePostingBuffer, ServiceLine, ServiceLineACY, SuppressCommit);
UpdateInvoicePostingBuffer(InvoicePostingBuffer, ServiceLine);
end;
local procedure GetSalesAccount(ServiceLine: Record "Service Line"; GenPostingSetup: Record "General Posting Setup") SalesAccountNo: Code[20]
var
ServCost: Record "Service Cost";
IsHandled: Boolean;
begin
IsHandled := false;
ServicePostInvoiceEvents.RunOnBeforeGetSalesAccount(ServiceLine, GenPostingSetup, SalesAccountNo, IsHandled);
if not IsHandled then
case ServiceLine.Type of
ServiceLine.Type::"G/L Account":
SalesAccountNo := ServiceLine."No.";
ServiceLine.Type::Cost:
begin
ServCost.Get(ServiceLine."No.");
SalesAccountNo := ServCost."Account No.";
end;
else
if ServiceLine."Document Type" = ServiceLine."Document Type"::"Credit Memo" then
SalesAccountNo := GenPostingSetup.GetSalesCrMemoAccount()
else
SalesAccountNo := GenPostingSetup.GetSalesAccount();
end;
ServicePostInvoiceEvents.RunOnAfterGetSalesAccount(ServiceLine, GenPostingSetup, SalesAccountNo);
end;
//***NEW***END
codeunit 827 "Service Post Invoice Events" Changes
codeunit 827 "Service Post Invoice Events"
{
//***NEW***BEGIN
procedure RunOnPrepareLineOnBeforeSetAmounts(ServiceLine: Record "Service Line"; ServiceLineACY: Record "Service Line"; var InvoicePostingBuffer: Record "Invoice Posting Buffer"; var TotalVAT: Decimal; var TotalVATACY: Decimal; var TotalAmount: Decimal; var TotalAmountACY: Decimal; var TotalVATBase: Decimal; var TotalVATBaseACY: Decimal; var IsHandled: Boolean)
begin
OnPrepareLineOnBeforeSetAmounts(ServiceLine, ServiceLineACY, InvoicePostingBuffer, TotalVAT, TotalVATACY, TotalAmount, TotalAmountACY, TotalVATBase, TotalVATBaseACY, IsHandled);
end;
[IntegrationEvent(false, false)]
local procedure OnPrepareLineOnBeforeSetAmounts(ServiceLine: Record "Service Line"; ServiceLineACY: Record "Service Line"; var InvoicePostingBuffer: Record "Invoice Posting Buffer"; var TotalVAT: Decimal; var TotalVATACY: Decimal; var TotalAmount: Decimal; var TotalAmountACY: Decimal; var TotalVATBase: Decimal; var TotalVATBaseACY: Decimal; var IsHandled: Boolean)
begin
end;
procedure RunOnPrepareLineOnAfterSetAmounts(var InvoicePostingBuffer: Record "Invoice Posting Buffer"; ServiceLine: Record "Service Line")
begin
OnPrepareLineOnAfterSetAmounts(InvoicePostingBuffer, ServiceLine);
end;
[IntegrationEvent(false, false)]
local procedure OnPrepareLineOnAfterSetAmounts(var InvoicePostingBuffer: Record "Invoice Posting Buffer"; ServiceLine: Record "Service Line")
begin
end;
procedure RunOnPrepareLineOnBeforeSetAccount(ServiceHeader: Record "Service Header"; ServiceLine: Record "Service Line"; var SalesAccount: Code[20])
begin
OnPrepareLineOnBeforeSetAccount(ServiceHeader, ServiceLine, SalesAccount);
end;
[IntegrationEvent(false, false)]
local procedure OnPrepareLineOnBeforeSetAccount(ServiceHeader: Record "Service Header"; ServiceLine: Record "Service Line"; var SalesAccount: Code[20])
begin
end;
procedure RunOnBeforeGetSalesAccount(ServiceLine: Record "Service Line"; GenPostingSetup: Record "General Posting Setup"; var SalesAccountNo: Code[20]; var IsHandled: Boolean)
begin
OnBeforeGetSalesAccount(ServiceLine, GenPostingSetup, SalesAccountNo, IsHandled);
end;
[IntegrationEvent(false, false)]
local procedure OnBeforeGetSalesAccount(ServiceLine: Record "Service Line"; GenPostingSetup: Record "General Posting Setup"; var SalesAccountNo: Code[20]; var IsHandled: Boolean)
begin
end;
procedure RunOnAfterGetSalesAccount(ServiceLine: Record "Service Line"; GenPostingSetup: Record "General Posting Setup"; var SalesAccountNo: Code[20])
begin
OnAfterGetSalesAccount(ServiceLine, GenPostingSetup, SalesAccountNo);
end;
[IntegrationEvent(false, false)]
local procedure OnAfterGetSalesAccount(ServiceLine: Record "Service Line"; GenPostingSetup: Record "General Posting Setup"; var SalesAccountNo: Code[20])
begin
end;
//***NEW***END
}
Hi, any update on this request?
Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. Please do not reply to this, as we do not monitor closed issues. If you have follow-up questions or requests, please create a new issue where you reference this one.
Build ID: 49880.