Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ tableextension 10035 "IRS 1099 Vendor Ledger Entry" extends "Vendor Ledger Entry
trigger OnValidate()
begin
IRS1099FormDocument.CheckIfVendLedgEntryAllowed(Rec."Entry No.");
if "IRS 1099 Reporting Period" <> '' then
Comment thread
ventselartur marked this conversation as resolved.
IRS1099VendorFormBox.CheckVendorSubjectFor1099Reporting(Rec."Vendor No.", "IRS 1099 Reporting Period");
Validate("IRS 1099 Form No.", '');
end;
}
Expand All @@ -35,6 +37,8 @@ tableextension 10035 "IRS 1099 Vendor Ledger Entry" extends "Vendor Ledger Entry
trigger OnValidate()
begin
IRS1099FormDocument.CheckIfVendLedgEntryAllowed(Rec."Entry No.");
if "IRS 1099 Form No." <> '' then
Comment thread
ventselartur marked this conversation as resolved.
IRS1099VendorFormBox.CheckVendorSubjectFor1099Reporting(Rec."Vendor No.", "IRS 1099 Reporting Period");
Validate("IRS 1099 Form Box No.", '');
Validate("IRS 1099 Reporting Amount", 0);
end;
Expand All @@ -47,6 +51,8 @@ tableextension 10035 "IRS 1099 Vendor Ledger Entry" extends "Vendor Ledger Entry
trigger OnValidate()
begin
IRS1099FormDocument.CheckIfVendLedgEntryAllowed(Rec."Entry No.");
if "IRS 1099 Form Box No." <> '' then
IRS1099VendorFormBox.CheckVendorSubjectFor1099Reporting(Rec."Vendor No.", "IRS 1099 Reporting Period");
"IRS 1099 Subject For Reporting" := "IRS 1099 Form Box No." <> '';
IRS1099VendorFormBox.UpdatePurchDocFormBoxNoFromVendLedgEntry(Rec);
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ codeunit 10037 "IRS 1099 Vendor Form Box"
end;
end;

procedure CheckVendorSubjectFor1099Reporting(VendorNo: Code[20]; PeriodNo: Code[20])
Comment thread
ventselartur marked this conversation as resolved.
Comment thread
ventselartur marked this conversation as resolved.
var
IRS1099VendorFormBoxSetup: Record "IRS 1099 Vendor Form Box Setup";
VendorNotSetupErrorInfo: ErrorInfo;
VendorNotSetupFor1099Err: Label 'Vendor %1 is not set up for IRS 1099 reporting in the reporting period %2.', Comment = '%1 = Vendor No., %2 = Period No.';
Comment thread
ventselartur marked this conversation as resolved.
OpenVendorFormBoxSetupLbl: Label 'Open IRS 1099 Vendor Form Box Setup';
begin
if PeriodNo = '' then
exit;
if IRS1099VendorFormBoxSetup.Get(PeriodNo, VendorNo) then
exit;

VendorNotSetupErrorInfo.Message := StrSubstNo(VendorNotSetupFor1099Err, VendorNo, PeriodNo);
VendorNotSetupErrorInfo.PageNo := Page::"IRS 1099 Vendor Form Box Setup";
VendorNotSetupErrorInfo.AddNavigationAction(OpenVendorFormBoxSetupLbl);
Error(VendorNotSetupErrorInfo);
end;

local procedure ShowIfVendorHas1099CodePrevPeriodButNotCurrNotificationId(): Guid
begin
exit('4b87dd95-f7ba-4e72-909b-76ca6a1d8b6a');
Expand Down
157 changes: 157 additions & 0 deletions src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ codeunit 148010 "IRS 1099 Document Tests"
PeriodNoFieldVisibleErr: Label 'Field Period No. should be visible.';
PeriodNoNotVisibleErr: Label 'Field Period No. should not be visible.';
ChangingPostingDateInPurchHeaderWhileHavingLineMsg: Label 'You have changed the Posting Date on the purchase header, which might affect the prices and discounts on the purchase lines.\You should review the lines and manually update prices and discounts if needed';
VendorNotSetupForIRS1099Err: Label 'Vendor %1 is not set up for IRS 1099 reporting in the reporting period %2.', Comment = '%1 = Vendor No., %2 = Period No.';


trigger OnRun()
Expand Down Expand Up @@ -1380,6 +1381,162 @@ codeunit 148010 "IRS 1099 Document Tests"
Assert.AreEqual(FormBoxNo[2], PurchCrMemoHdr."IRS 1099 Form Box No.", 'IRS 1099 Form Box No. in Purch. Cr. Memo Hdr. should be updated');
end;

[Test]
procedure ValidateIRS1099PeriodOnVendLedgEntryForNon1099Vendor()
var
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
VendorLedgEntry: Record "Vendor Ledger Entry";
VendNo: Code[20];
FormNo: Code[20];
PeriodNo: Code[20];
InvNo: Code[20];
begin
// [FEATURE] [AI test]
// [SCENARIO 620132] Setting IRS 1099 Reporting Period on vendor ledger entry of a vendor with no 1099 setup raises an error

Initialize();
// [GIVEN] IRS Reporting Period "P" with form "F" and form box "FB"
PeriodNo := LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(WorkDate());
FormNo := LibraryIRS1099FormBox.CreateSingleFormInReportingPeriod(WorkDate(), WorkDate());
LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(WorkDate(), WorkDate(), FormNo);

// [GIVEN] Vendor "V" with NO IRS 1099 form box setup (plain vendor)
VendNo := LibraryPurchase.CreateVendorNo();

// [GIVEN] Posted purchase invoice for vendor "V"
LibraryPurchase.CreatePurchHeader(PurchaseHeader, PurchaseHeader."Document Type"::Invoice, VendNo);
LibraryPurchase.CreatePurchaseLineWithUnitCost(PurchaseLine, PurchaseHeader, LibraryInventory.CreateItemNo(), 1, 100);
InvNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);

// [WHEN] Validate "IRS 1099 Reporting Period" in the vendor ledger entry
LibraryERM.FindVendorLedgerEntry(VendorLedgEntry, VendorLedgEntry."Document Type"::Invoice, InvNo);
// [THEN] An error is raised because vendor "V" has no 1099 setup for the period
asserterror VendorLedgEntry.Validate("IRS 1099 Reporting Period", PeriodNo);
Assert.ExpectedError(StrSubstNo(VendorNotSetupForIRS1099Err, VendNo, PeriodNo));
end;

[Test]
procedure ValidateIRS1099FormBoxOnVendLedgEntryFor1099Vendor()
var
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
VendorLedgEntry: Record "Vendor Ledger Entry";
VendNo: Code[20];
FormNo: Code[20];
FormBoxNo: Code[20];
PeriodNo: Code[20];
InvNo: Code[20];
begin
// [FEATURE] [AI test]
// [SCENARIO 620132] Vendor WITH 1099 setup can still validate form box on its ledger entry without error

Initialize();
// [GIVEN] IRS Reporting Period with Form "F" and Form Box "FB"
PeriodNo := LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(WorkDate());
FormNo := LibraryIRS1099FormBox.CreateSingleFormInReportingPeriod(WorkDate(), WorkDate());
FormBoxNo := LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(WorkDate(), WorkDate(), FormNo);

// [GIVEN] Vendor "V" WITH IRS 1099 form box setup
VendNo := LibraryIRS1099FormBox.CreateVendorNoWithFormBox(WorkDate(), WorkDate(), FormNo, FormBoxNo);

// [GIVEN] Posted purchase invoice for vendor "V"
LibraryPurchase.CreatePurchHeader(PurchaseHeader, PurchaseHeader."Document Type"::Invoice, VendNo);
LibraryPurchase.CreatePurchaseLineWithUnitCost(PurchaseLine, PurchaseHeader, LibraryInventory.CreateItemNo(), 1, 100);
InvNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);

// [WHEN] Validate the IRS 1099 fields in the vendor ledger entry
LibraryERM.FindVendorLedgerEntry(VendorLedgEntry, VendorLedgEntry."Document Type"::Invoice, InvNo);
// [THEN] No error is raised for a vendor that has 1099 setup
VendorLedgEntry.Validate("IRS 1099 Reporting Period", PeriodNo);
VendorLedgEntry.Validate("IRS 1099 Form No.", FormNo);
VendorLedgEntry.Validate("IRS 1099 Form Box No.", FormBoxNo);
VendorLedgEntry.TestField("IRS 1099 Form Box No.", FormBoxNo);
end;

[Test]
procedure ValidateIRS1099FormAndFormBoxOnVendLedgEntryForNon1099Vendor()
var
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
VendorLedgEntry: Record "Vendor Ledger Entry";
VendNo: Code[20];
FormNo: Code[20];
FormBoxNo: Code[20];
PeriodNo: Code[20];
InvNo: Code[20];
begin
// [FEATURE] [AI test]
// [SCENARIO 620132] Setting IRS 1099 Form No. or Form Box No. on vendor ledger entry of a vendor with no 1099 setup raises an error

Initialize();
// [GIVEN] IRS Reporting Period "P" with form "F" and form box "FB"
PeriodNo := LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(WorkDate());
FormNo := LibraryIRS1099FormBox.CreateSingleFormInReportingPeriod(WorkDate(), WorkDate());
FormBoxNo := LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(WorkDate(), WorkDate(), FormNo);

// [GIVEN] Vendor "V" with NO IRS 1099 form box setup (plain vendor)
VendNo := LibraryPurchase.CreateVendorNo();

// [GIVEN] Posted purchase invoice for vendor "V", with IRS period set directly (bypassing validation)
LibraryPurchase.CreatePurchHeader(PurchaseHeader, PurchaseHeader."Document Type"::Invoice, VendNo);
LibraryPurchase.CreatePurchaseLineWithUnitCost(PurchaseLine, PurchaseHeader, LibraryInventory.CreateItemNo(), 1, 100);
InvNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
LibraryERM.FindVendorLedgerEntry(VendorLedgEntry, VendorLedgEntry."Document Type"::Invoice, InvNo);
VendorLedgEntry."IRS 1099 Reporting Period" := PeriodNo;
VendorLedgEntry.Modify();

// [WHEN] Validate "IRS 1099 Form No." in the vendor ledger entry
// [THEN] An error is raised because vendor "V" has no 1099 setup for the period
asserterror VendorLedgEntry.Validate("IRS 1099 Form No.", FormNo);
Assert.ExpectedError(StrSubstNo(VendorNotSetupForIRS1099Err, VendNo, PeriodNo));

// [WHEN] Validate "IRS 1099 Form Box No." in the vendor ledger entry
// [THEN] An error is raised because vendor "V" has no 1099 setup for the period
LibraryERM.FindVendorLedgerEntry(VendorLedgEntry, VendorLedgEntry."Document Type"::Invoice, InvNo);
VendorLedgEntry."IRS 1099 Reporting Period" := PeriodNo;
VendorLedgEntry."IRS 1099 Form No." := FormNo;
asserterror VendorLedgEntry.Validate("IRS 1099 Form Box No.", FormBoxNo);
Assert.ExpectedError(StrSubstNo(VendorNotSetupForIRS1099Err, VendNo, PeriodNo));
end;

[Test]
procedure ClearIRS1099PeriodOnVendLedgEntryForNon1099Vendor()
var
PurchaseHeader: Record "Purchase Header";
PurchaseLine: Record "Purchase Line";
VendorLedgEntry: Record "Vendor Ledger Entry";
VendNo: Code[20];
FormNo: Code[20];
PeriodNo: Code[20];
InvNo: Code[20];
begin
// [FEATURE] [AI test]
// [SCENARIO 620132] Clearing IRS 1099 Reporting Period on a non-1099 vendor ledger entry does not raise an error

Initialize();
// [GIVEN] IRS Reporting Period "P" with form "F" and form box "FB"
PeriodNo := LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(WorkDate());
FormNo := LibraryIRS1099FormBox.CreateSingleFormInReportingPeriod(WorkDate(), WorkDate());
LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(WorkDate(), WorkDate(), FormNo);

// [GIVEN] Vendor "V" with NO IRS 1099 form box setup
VendNo := LibraryPurchase.CreateVendorNo();

// [GIVEN] Posted purchase invoice for vendor "V", with IRS period set directly (bypassing validation)
LibraryPurchase.CreatePurchHeader(PurchaseHeader, PurchaseHeader."Document Type"::Invoice, VendNo);
LibraryPurchase.CreatePurchaseLineWithUnitCost(PurchaseLine, PurchaseHeader, LibraryInventory.CreateItemNo(), 1, 100);
InvNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, true, true);
LibraryERM.FindVendorLedgerEntry(VendorLedgEntry, VendorLedgEntry."Document Type"::Invoice, InvNo);
VendorLedgEntry."IRS 1099 Reporting Period" := PeriodNo;
VendorLedgEntry.Modify();

// [WHEN] Clear "IRS 1099 Reporting Period" by validating with ''
// [THEN] No error is raised (clearing must always be allowed)
VendorLedgEntry.Validate("IRS 1099 Reporting Period", '');
VendorLedgEntry.TestField("IRS 1099 Reporting Period", '');
end;

local procedure Initialize()
var
IRSReportingPeriod: Record "IRS Reporting Period";
Expand Down
10 changes: 8 additions & 2 deletions src/Apps/US/IRSForms/test/src/IRS1099VendorTests.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ codeunit 148011 "IRS 1099 Vendor Tests"
var
VendorLedgerEntry: Record "Vendor Ledger Entry";
VendorLedgerEntriesPage: TestPage "Vendor Ledger Entries";
NewPeriodNo, FormNo, NewFormNo, FormBoxNo, NewFormBoxNo : Code[20];
VendNo, NewPeriodNo, FormNo, NewFormNo, FormBoxNo, NewFormBoxNo : Code[20];
IRSAmount: Decimal;
NewDate: Date;
begin
Expand All @@ -187,7 +187,13 @@ codeunit 148011 "IRS 1099 Vendor Tests"
NewPeriodNo := LibraryIRSReportingPeriod.CreateOneDayReportingPeriod(NewDate);
NewFormNo := LibraryIRS1099FormBox.CreateSingleFormInReportingPeriod(NewDate);
NewFormBoxNo := LibraryIRS1099FormBox.CreateSingleFormBoxInReportingPeriod(NewDate, NewFormNo);
IRSAmount := IRSAmount / 3;
// [GIVEN] The entry belongs to a vendor set up for IRS 1099 reporting in both periods
VendNo := LibraryIRS1099FormBox.CreateVendorNoWithFormBox(WorkDate(), FormNo, FormBoxNo);
LibraryIRS1099FormBox.AssignFormBoxForVendorInPeriod(VendNo, NewDate, NewDate, NewFormNo, NewFormBoxNo);
VendorLedgerEntry."Vendor No." := VendNo;
VendorLedgerEntry.Modify();

IRSAmount := Round(IRSAmount / 3);
// [GIVEN] Vendor Ledger Entries page opened and filtered by Entry No.
VendorLedgerEntriesPage.OpenEdit();
VendorLedgerEntriesPage.Filter.SetFilter("Entry No.", Format(VendorLedgerEntry."Entry No."));
Expand Down
Loading