Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mandatory Setup fields for Intrastat #27919

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
// ------------------------------------------------------------------------------------------------
namespace Microsoft.Inventory.Intrastat;

using Microsoft.Foundation.Company;
using Microsoft.Foundation.Address;
using System.Utilities;
using Microsoft.Purchases.Document;
using Microsoft.Inventory.Transfer;
using Microsoft.Purchases.Posting;
using Microsoft.Sales.Posting;
using Microsoft.Sales.Document;
using Microsoft.Service.Document;

codeunit 4812 "Intrastat Report Doc. Compl."
{
var
IntrastatReportSetup: Record "Intrastat Report Setup";
MandatoryFieldErr: Label '%1 field cannot be empty.', Comment = '%1 - field name';

[EventSubscriber(ObjectType::Table, Database::"Sales Header", 'OnBeforeInsertEvent', '', false, false)]
local procedure DefaultSalesDocuments(var Rec: Record "Sales Header"; RunTrigger: Boolean)
Expand Down Expand Up @@ -73,6 +80,129 @@ codeunit 4812 "Intrastat Report Doc. Compl."
OnAfterDefaultServiceDocuments(Rec, IntrastatReportSetup);
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", OnAfterCheckSalesDoc, '', false, false)]
local procedure CheckIntrastatMandatoryFieldsOnSalesDoc(var SalesHeader: Record "Sales Header")
var
TempErrorMessage: Record "Error Message" temporary;
begin
if SalesHeader.IsTemporary() or (not IntrastatReportSetup.ReadPermission) then
exit;

if not IntrastatReportSetup.Get() then
exit;

if not IsIntrastatTransaction(SalesHeader."VAT Country/Region Code") then
exit;

if SalesHeader.Ship or SalesHeader.Receive then begin
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Transaction Type Mandatory", SalesHeader."Transaction Type", SalesHeader.FieldCaption("Transaction Type"));
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Transaction Spec. Mandatory", SalesHeader."Transaction Specification", SalesHeader.FieldCaption("Transaction Specification"));
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Shipment Method Mandatory", SalesHeader."Shipment Method Code", SalesHeader.FieldCaption("Shipment Method Code"));
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Transport Method Mandatory", SalesHeader."Transport Method", SalesHeader.FieldCaption("Transport Method"));

if TempErrorMessage.HasErrors(true) then
TempErrorMessage.ShowErrorMessages(true);
end;


end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch.-Post", OnAfterCheckPurchDoc, '', false, false)]
local procedure CheckIntrastatMandatoryFieldsOnPurchaseDoc(var PurchHeader: Record "Purchase Header")
var
TempErrorMessage: Record "Error Message" temporary;
begin
if PurchHeader.IsTemporary() or (not IntrastatReportSetup.ReadPermission) then
exit;

if not IntrastatReportSetup.Get() then
exit;

if not IsIntrastatTransaction(PurchHeader."VAT Country/Region Code") then
exit;

if PurchHeader.Ship or PurchHeader.Receive then begin
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Transaction Type Mandatory", PurchHeader."Transaction Type", PurchHeader.FieldCaption("Transaction Type"));
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Transaction Spec. Mandatory", PurchHeader."Transaction Specification", PurchHeader.FieldCaption("Transaction Specification"));
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Shipment Method Mandatory", PurchHeader."Shipment Method Code", PurchHeader.FieldCaption("Shipment Method Code"));
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Transport Method Mandatory", PurchHeader."Transport Method", PurchHeader.FieldCaption("Transport Method"));

if TempErrorMessage.HasErrors(true) then
TempErrorMessage.ShowErrorMessages(true);
end;
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"TransferOrder-Post Shipment", OnBeforeTransferOrderPostShipment, '', false, false)]
local procedure CheckIntrastatMandatoryFieldsOnTransferShipment(var TransferHeader: Record "Transfer Header")
var
TempErrorMessage: Record "Error Message" temporary;
begin
if TransferHeader.IsTemporary() or (not IntrastatReportSetup.ReadPermission) then
exit;

if not IntrastatReportSetup.Get() then
exit;

if TransferHeader."Trsf.-from Country/Region Code" = TransferHeader."Trsf.-to Country/Region Code" then
exit;

if (not IsIntrastatTransaction(TransferHeader."Trsf.-to Country/Region Code")) and (not IsIntrastatTransaction(TransferHeader."Trsf.-from Country/Region Code")) then
exit;

CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Transaction Type Mandatory", TransferHeader."Transaction Type", TransferHeader.FieldCaption("Transaction Type"));
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Transaction Spec. Mandatory", TransferHeader."Transaction Specification", TransferHeader.FieldCaption("Transaction Specification"));
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Shipment Method Mandatory", TransferHeader."Shipment Method Code", TransferHeader.FieldCaption("Shipment Method Code"));
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Transport Method Mandatory", TransferHeader."Transport Method", TransferHeader.FieldCaption("Transport Method"));

if TempErrorMessage.HasErrors(true) then
TempErrorMessage.ShowErrorMessages(true);
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"TransferOrder-Post Receipt", OnBeforeTransferOrderPostReceipt, '', false, false)]
local procedure CheckIntrastatMandatoryFieldsOnTransferReceipt(var TransferHeader: Record "Transfer Header")
var
TempErrorMessage: Record "Error Message" temporary;
begin
if TransferHeader.IsTemporary() or (not IntrastatReportSetup.ReadPermission) then
exit;

if not IntrastatReportSetup.Get() then
exit;

if TransferHeader."Trsf.-from Country/Region Code" = TransferHeader."Trsf.-to Country/Region Code" then
exit;

if (not IsIntrastatTransaction(TransferHeader."Trsf.-to Country/Region Code")) and (not IsIntrastatTransaction(TransferHeader."Trsf.-from Country/Region Code")) then
exit;

CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Transaction Type Mandatory", TransferHeader."Transaction Type", TransferHeader.FieldCaption("Transaction Type"));
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Transaction Spec. Mandatory", TransferHeader."Transaction Specification", TransferHeader.FieldCaption("Transaction Specification"));
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Shipment Method Mandatory", TransferHeader."Shipment Method Code", TransferHeader.FieldCaption("Shipment Method Code"));
CheckIntrastatMandatoryFields(TempErrorMessage, IntrastatReportSetup."Transport Method Mandatory", TransferHeader."Transport Method", TransferHeader.FieldCaption("Transport Method"));

if TempErrorMessage.HasErrors(true) then
TempErrorMessage.ShowErrorMessages(true);
end;

local procedure IsIntrastatTransaction(CountryCode: Code[10]): Boolean
var
CountryRegion: Record "Country/Region";
CompanyInformation: Record "Company Information";
begin
if not CountryRegion.Get(CountryCode) then
exit(false);
if CountryRegion."Intrastat Code" = '' then
exit(false);
CompanyInformation.Get();
exit(CompanyInformation."Country/Region Code" <> CountryCode);
end;

local procedure CheckIntrastatMandatoryFields(var TempErrorMessage: Record "Error Message" temporary; ValueMandatory: Boolean; FieldValue: Code[20]; FieldCaption: Text)
begin
if ValueMandatory and (FieldValue = '') then
TempErrorMessage.LogSimpleMessage(TempErrorMessage."Message Type"::Error, StrSubstNo(MandatoryFieldErr, FieldCaption));
end;

[IntegrationEvent(false, false)]
local procedure OnAfterDefaultPurchaseDocuments(var PurchaseHeader: Record "Purchase Header"; IntrastatReportSetup: Record "Intrastat Report Setup")
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ page 4810 "Intrastat Report Setup"
field("Def. 3-Party Trade VAT No."; Rec."Def. 3-Party Trade VAT No.") { }
field("Def. VAT for Unknown State"; Rec."Def. VAT for Unknown State") { }
field("Def. Country/Region Code"; Rec."Def. Country/Region Code") { }
field("Transaction Type Mandatory"; Rec."Transaction Type Mandatory") { }
field("Transaction Spec. Mandatory"; Rec."Transaction Spec. Mandatory") { }
field("Transport Method Mandatory"; Rec."Transport Method Mandatory") { }
field("Shipment Method Mandatory"; Rec."Shipment Method Mandatory") { }
}
group(Reporting)
{
Expand Down
20 changes: 20 additions & 0 deletions Apps/W1/Intrastat/app/src/Setup/IntrastatReportSetup.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,26 @@ table 4810 "Intrastat Report Setup"
Caption = 'Purchase Intrastat Info Based On';
ToolTip = 'Specifies based on which vendor code Intrastat settings are added to the document.';
}
field(38; "Transaction Type Mandatory"; Boolean)
{
Caption = 'Transaction Type Mandatory';
ToolTip = 'Specifies if the transaction type should be filled in on documents before posting';
}
field(39; "Transaction Spec. Mandatory"; Boolean)
{
Caption = 'Transaction Spec. Mandatory';
ToolTip = 'Specifies if the transaction specification should be filled in on documents before posting';
}
field(40; "Transport Method Mandatory"; Boolean)
{
Caption = 'Transport Method Mandatory';
ToolTip = 'Specifies if the transprot method should be filled in on documents before posting';
}
field(41; "Shipment Method Mandatory"; Boolean)
{
Caption = 'Shipment Method Mandatory';
ToolTip = 'Specifies if the shipment method should be filled in on documents before posting';
}
}

keys
Expand Down
Loading
Loading