<< Click to Display Table of Contents >> Navigation: Zetadocs SDK Guide > Creating a Per Tenant Extension > Accounts Payable Customization |
Zetadocs Accounts Payable Automation allows you to customize the how the purchase invoice is created in Business Central to satisfy specific business requirements. You can specify your own business validation logic or custom purchase invoice line types using a Per Tenant Extension.
Business Logic validation Example
The following code sample illustrates how to use the OnValidateReviewLine event to define specific business requirements or data consolidation, that runs during validation of the fields:
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Zetadocs Customize", 'OnValidateReviewLine', '', true, true)]
local procedure OnValidateReviewLine(var OnValidateReviewLineHandler: Codeunit "Zdd OnValidatePreviewLine")
var
reviewLine: Record "Zetadocs ADE Lines";
begin
OnValidateReviewLineHandler.GetReviewLine(reviewLine);
case reviewLine.ReviewLineType of
reviewLine.ReviewLineType::"Fixed Asset":
begin
if (reviewLine.Description = 'fail') then begin
Error('Because I should fail')
end;
if (reviewLine.Description = 'override') then begin
reviewLine.Description := 'My override';
end;
end;
end;
OnValidateReviewLineHandler.SetReviewLine(reviewLine);
end;
Custom Line types Example
Zetadocs supports the use of custom lines types on Business Central Purchase Invoices. The following code illustrates how to create new line types for Zetadocs and Business central.
enumextension 50680 "Zd Review Line Type extension" extends "Zetadocs Review Line Type"
{
value(50680; CustomTypeToItem)
{
Caption = 'Per Tenant Extension type to Item';
}
value(50681; CustomTypeToCustomePurchaseInvoiceType)
{
Caption = Per Tenant Extension type To Custom Purchase type';
}
}
enumextension 50681 "Zd Purchase Line Type extension" extends "Purchase Line Type"
{
value(50680; CustomPurchaseInvoice)
{
Caption = 'Per Tenant Ext Purchase type';
}
}
Once created, new line types can be used with the OnAddDefaultsToReviewLine, OnLookupReviewLine and OnEnumConversion events to adapt the Zetadocs logic to suit your requirements.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Zetadocs Customize", 'OnAddDefaultsToReviewLine', '', true, true)]
local procedure OnAddDefaultsToReviewLine(var onAddDefaultsToReviewLineHandler: Codeunit "Zdd OnAddDefaultsToReviewLine")
var
reviewLine: Record "Zetadocs ADE Lines" temporary;
begin
onAddDefaultsToReviewLineHandler.GetReviewLine(reviewLine);
case reviewLine.ReviewLineType of
reviewLine.ReviewLineType::CustomTypeToItem,
reviewLine.ReviewLineType::CustomTypeToCustomePurchaseInvoiceType:
begin
if (reviewLine.Description = '') then begin
reviewLine.Description := 'custom description from the Per Tenant Extension';
end;
if (reviewLine.ProductCode <> '') then begin
if reviewLine."Gen. Prod. Posting Group" = '' then reviewLine."Gen. Prod. Posting Group" := 'RETAIL';
if reviewLine."VAT Prod. Posting Group" = '' then reviewLine."VAT Prod. Posting Group" := 'VAT20';
end;
end;
end;
onAddDefaultsToReviewLineHandler.SetReviewLine(reviewLine);
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Zetadocs Customize", 'OnLookupReviewLine', '', true, true)]
local procedure OnLookupReviewLine(var onLookupReviewLineHandler: Codeunit "Zdd OnLookupReviewLine")
var
reviewLine: Record "Zetadocs ADE Lines";
item: Record Item;
onLookupText: Text;
fieldNameLookedUp: enum "Zetadocs Review Line Column";
begin
onLookupReviewLineHandler.GetLookupContext(reviewLine, onLookupText, fieldNameLookedUp);
if (fieldNameLookedUp = fieldNameLookedUp::ProductCode) then begin
case reviewLine.ReviewLineType of
reviewLine.ReviewLineType::CustomTypeToItem:
begin
Message('Lookup from Per Tenant Extension');
case reviewLine.ReviewDocumentType of
reviewLine.ReviewDocumentType::"Credit Memo",
reviewLine.ReviewDocumentType::"Return Order":
begin
item.SetRange(Blocked, FALSE);
end;
else begin
item.SetRange(Blocked, FALSE);
item.SetRange("Purchasing Blocked", FALSE);
end;
end;
if (Page.RunModal(0, item) = Action::LookupOK) then begin
onLookupReviewLineHandler.SetLookupValue(item."No.");
end;
end;
end;
end;
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Zetadocs Customize", 'OnEnumConversion', '', true, true)]
local procedure OnEnumConversion(var OnEnumConversionHandler: Codeunit "Zdd OnEnumConversion")
var
begin
OnEnumConversionHandler.AddOrUpdatePurchaseLineMapping("Zetadocs Review Line Type"::CustomTypeToItem, "Purchase Line Type"::Item);
OnEnumConversionHandler.AddOrUpdatePurchaseLineMapping("Zetadocs Review Line Type"::CustomTypeToCustomePurchaseInvoiceType, "Purchase Line Type"::CustomPurchaseInvoice);
end;