Skip to content

Commit 9604166

Browse files
committed
Most of the changes after review
1 parent fb47d8f commit 9604166

20 files changed

+1037
-1213
lines changed

Apps/US/HybridGP_US/app/Permissions/HybridGPUSObjects.PermissionSet.al

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ permissionset 4713 "HybridGPUS - Objects"
1818
codeunit "GP IRS Form Data" = X,
1919
page "GP 1099 Migration Log" = X,
2020
page "GP 1099 Migration Log Factbox" = X,
21-
codeunit "GP US Migration Validator" = X,
22-
codeunit "Hybrid GP US Install" = X;
21+
codeunit "GP IRS1099 Migration Validator" = X;
2322
}
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
namespace Microsoft.DataMigration.GP;
2+
3+
using Microsoft.DataMigration;
4+
using Microsoft.Purchases.Vendor;
5+
using Microsoft.Purchases.Payables;
6+
using Microsoft.Finance.VAT.Reporting;
7+
8+
codeunit 42006 "GP IRS1099 Migration Validator"
9+
{
10+
trigger OnRun()
11+
var
12+
GPCompanyAdditionalSettings: Record "GP Company Additional Settings";
13+
begin
14+
if not GPCompanyAdditionalSettings.GetMigrateVendor1099Enabled() then
15+
exit;
16+
17+
ValidatorCodeLbl := GetValidatorCode();
18+
CompanyNameTxt := CompanyName();
19+
20+
RunVendor1099MigrationValidation(GPCompanyAdditionalSettings);
21+
22+
MigrationValidationMgmt.ReportCompanyValidated();
23+
end;
24+
25+
local procedure RunVendor1099MigrationValidation(var GPCompanyAdditionalSettings: Record "GP Company Additional Settings")
26+
var
27+
GPPM00200: Record "GP PM00200";
28+
Vendor: Record Vendor;
29+
VendorLedgerEntry: Record "Vendor Ledger Entry";
30+
IRS1099VendorFormBoxSetup: Record "IRS 1099 Vendor Form Box Setup";
31+
GPVendor1099MappingHelpers: Codeunit "GP Vendor 1099 Mapping Helpers";
32+
IRS1099Code: Code[10];
33+
ActualIRS1099Code: Code[20];
34+
TaxAmount: Decimal;
35+
VendorYear1099AmountDictionary: Dictionary of [Code[10], Decimal];
36+
EntityType: Text[50];
37+
VendorNo: Code[20];
38+
begin
39+
if CompanyValidationProgress.Get(CompanyNameTxt, ValidatorCodeLbl, ValidationStepVendor1099Lbl) then
40+
exit;
41+
42+
EntityType := Vendor1099EntityCaptionLbl;
43+
44+
if GPCompanyAdditionalSettings.GetMigrateVendor1099Enabled() then begin
45+
GPPM00200.SetRange(TEN99TYPE, 2, 5);
46+
GPPM00200.SetFilter(VENDORID, '<>%1', '');
47+
if GPPM00200.FindSet() then
48+
repeat
49+
VendorNo := CopyStr(GPPM00200.VENDORID.TrimEnd(), 1, MaxStrLen(VendorNo));
50+
Vendor.SetLoadFields("No.", Name, "Federal ID No.");
51+
if not Vendor.Get(VendorNo) then
52+
continue;
53+
54+
MigrationValidationMgmt.SetContext(ValidatorCodeLbl, EntityType, VendorNo);
55+
IRS1099Code := GPVendor1099MappingHelpers.GetIRS1099BoxCode(System.Date2DMY(System.Today(), 3), GPPM00200.TEN99TYPE, GPPM00200.TEN99BOXNUMBER);
56+
57+
Clear(ActualIRS1099Code);
58+
if IRS1099VendorFormBoxSetup.Get(Format(GPCompanyAdditionalSettings.Get1099TaxYear()), VendorNo) then
59+
ActualIRS1099Code := IRS1099VendorFormBoxSetup."Form Box No.";
60+
61+
MigrationValidationMgmt.ValidateAreEqual(Test_VEND1099IRS1099CODE_Tok, IRS1099Code, ActualIRS1099Code, IRS1099CodeLbl);
62+
MigrationValidationMgmt.ValidateAreEqual(Test_VEND1099FEDIDNO_Tok, CopyStr(GPPM00200.TXIDNMBR.TrimEnd(), 1, MaxStrLen(Vendor."Federal ID No.")), Vendor."Federal ID No.", FederalIdNoLbl);
63+
64+
Clear(VendorYear1099AmountDictionary);
65+
BuildVendor1099Entries(VendorNo, VendorYear1099AmountDictionary);
66+
foreach IRS1099Code in VendorYear1099AmountDictionary.Keys() do begin
67+
TaxAmount := VendorYear1099AmountDictionary.Get(IRS1099Code);
68+
69+
if TaxAmount > 0 then begin
70+
Clear(VendorLedgerEntry);
71+
VendorLedgerEntry.SetLoadFields(Description, Amount);
72+
VendorLedgerEntry.SetRange("Vendor No.", VendorNo);
73+
VendorLedgerEntry.SetRange("Document Type", VendorLedgerEntry."Document Type"::Payment);
74+
VendorLedgerEntry.SetRange(Description, IRS1099Code);
75+
76+
if not MigrationValidationMgmt.ValidateRecordExists(Test_VEND1099TRXEXISTS_Tok, VendorLedgerEntry.FindFirst(), StrSubstNo(MissingBoxAndAmountLbl, IRS1099Code, TaxAmount)) then
77+
continue;
78+
79+
VendorLedgerEntry.CalcFields(Amount);
80+
81+
MigrationValidationMgmt.ValidateAreEqual(Test_VEND1099TEN99BOX_Tok, IRS1099Code, VendorLedgerEntry.Description, Vendor1099BoxLbl);
82+
MigrationValidationMgmt.ValidateAreEqual(Test_VEND1099TEN99TRXAMT_Tok, TaxAmount, VendorLedgerEntry.Amount, Vendor1099BoxAmountLbl);
83+
end;
84+
end;
85+
86+
until GPPM00200.Next() = 0;
87+
end;
88+
89+
LogValidationProgress(ValidationStepVendor1099Lbl);
90+
Commit();
91+
end;
92+
93+
local procedure BuildVendor1099Entries(VendorNo: Code[20]; var VendorYear1099AmountDictionary: Dictionary of [Code[10], Decimal])
94+
var
95+
GPCompanyAdditionalSettings: Record "GP Company Additional Settings";
96+
GPPM00204: Record "GP PM00204";
97+
GPVendor1099MappingHelpers: Codeunit "GP Vendor 1099 Mapping Helpers";
98+
IRS1099Code: Code[10];
99+
TaxAmount: Decimal;
100+
TaxYear: Integer;
101+
begin
102+
TaxYear := GPCompanyAdditionalSettings.Get1099TaxYear();
103+
GPPM00204.SetRange(VENDORID, VendorNo);
104+
GPPM00204.SetRange(YEAR1, TaxYear);
105+
GPPM00204.SetFilter(TEN99AMNT, '>0');
106+
if GPPM00204.FindSet() then
107+
repeat
108+
IRS1099Code := GPVendor1099MappingHelpers.GetIRS1099BoxCode(TaxYear, GPPM00204.TEN99TYPE, GPPM00204.TEN99BOXNUMBER);
109+
if IRS1099Code <> '' then
110+
if VendorYear1099AmountDictionary.Get(IRS1099Code, TaxAmount) then
111+
VendorYear1099AmountDictionary.Set(IRS1099Code, TaxAmount + GPPM00204.TEN99AMNT)
112+
else
113+
VendorYear1099AmountDictionary.Add(IRS1099Code, GPPM00204.TEN99AMNT);
114+
until GPPM00204.Next() = 0;
115+
end;
116+
117+
local procedure LogValidationProgress(ValidationStep: Code[20])
118+
begin
119+
Clear(CompanyValidationProgress);
120+
CompanyValidationProgress.Validate("Company Name", CompanyNameTxt);
121+
CompanyValidationProgress.Validate("Validator Code", ValidatorCodeLbl);
122+
CompanyValidationProgress.Validate("Validation Step", ValidationStep);
123+
CompanyValidationProgress.Insert(true);
124+
end;
125+
126+
internal procedure GetValidatorCode(): Code[20]
127+
begin
128+
exit('GP-US');
129+
end;
130+
131+
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Hybrid Cloud Management", OnPrepareMigrationValidation, '', false, false)]
132+
local procedure OnPrepareMigrationValidation(ProductID: Text[250])
133+
var
134+
HybridGPWizard: Codeunit "Hybrid GP Wizard";
135+
begin
136+
if ProductID <> HybridGPWizard.ProductId() then
137+
exit;
138+
139+
RegisterValidator();
140+
141+
AddTest(Test_VEND1099IRS1099CODE_Tok, Vendor1099EntityCaptionLbl, IRS1099CodeLbl);
142+
AddTest(Test_VEND1099FEDIDNO_Tok, Vendor1099EntityCaptionLbl, FederalIdNoLbl);
143+
AddTest(Test_VEND1099TRXEXISTS_Tok, Vendor1099EntityCaptionLbl, Vendor1099MissingTrxLbl);
144+
AddTest(Test_VEND1099TEN99BOX_Tok, Vendor1099EntityCaptionLbl, Vendor1099TrxBoxNoLbl);
145+
AddTest(Test_VEND1099TEN99TRXAMT_Tok, Vendor1099EntityCaptionLbl, Vendor1099TrxAmtLbl);
146+
end;
147+
148+
local procedure RegisterValidator()
149+
var
150+
MigrationValidatorRegistry: Record "Migration Validator Registry";
151+
HybridGPWizard: Codeunit "Hybrid GP Wizard";
152+
ValidatorCode: Code[20];
153+
MigrationType: Text[250];
154+
ValidatorCodeunitId: Integer;
155+
begin
156+
ValidatorCode := GetValidatorCode();
157+
MigrationType := HybridGPWizard.ProductId();
158+
ValidatorCodeunitId := Codeunit::"GP IRS1099 Migration Validator";
159+
if not MigrationValidatorRegistry.Get(ValidatorCode) then begin
160+
MigrationValidatorRegistry.Validate("Validator Code", ValidatorCode);
161+
MigrationValidatorRegistry.Validate("Migration Type", MigrationType);
162+
MigrationValidatorRegistry.Validate(Description, ValidatorDescriptionLbl);
163+
MigrationValidatorRegistry.Validate("Codeunit Id", ValidatorCodeunitId);
164+
MigrationValidatorRegistry.Validate(Automatic, false);
165+
MigrationValidatorRegistry.Insert(true);
166+
end;
167+
end;
168+
169+
local procedure AddTest(Code: Code[30]; Entity: Text[50]; Description: Text)
170+
var
171+
MigrationValidationTest: Record "Migration Validation Test";
172+
begin
173+
if not MigrationValidationTest.Get(Code, GetValidatorCode()) then begin
174+
MigrationValidationTest.Validate(Code, Code);
175+
MigrationValidationTest.Validate("Validator Code", GetValidatorCode());
176+
MigrationValidationTest.Validate(Entity, Entity);
177+
MigrationValidationTest.Validate("Test Description", Description);
178+
MigrationValidationTest.Insert(true);
179+
end;
180+
end;
181+
182+
var
183+
CompanyValidationProgress: Record "Company Validation Progress";
184+
MigrationValidationMgmt: Codeunit "Migration Validation Mgmt.";
185+
ValidatorCodeLbl: Code[20];
186+
CompanyNameTxt: Text;
187+
FederalIdNoLbl: Label 'Federal ID No.';
188+
IRS1099CodeLbl: Label 'IRS 1099 Code';
189+
MissingBoxAndAmountLbl: Label 'Missing 1099 Box Payment. 1099 Box = %1, Amount = %2', Comment = '%1 = 1099 Box Code, %2 = Amount of the payment';
190+
Vendor1099BoxLbl: Label '1099 Box';
191+
Vendor1099BoxAmountLbl: Label '1099 Box Amount';
192+
Vendor1099MissingTrxLbl: Label 'Missing 1099 transaction';
193+
Vendor1099TrxBoxNoLbl: Label '1099 transaction Box No/Description';
194+
Vendor1099TrxAmtLbl: Label '1099 transaction amount';
195+
Vendor1099EntityCaptionLbl: Label 'Vendor 1099', MaxLength = 50;
196+
ValidationStepVendor1099Lbl: Label 'VENDOR1099', MaxLength = 20;
197+
ValidatorDescriptionLbl: Label 'GP IRS 1099 migration validator', MaxLength = 250;
198+
Test_VEND1099IRS1099CODE_Tok: Label 'VEND1099IRS1099CODE', Locked = true;
199+
Test_VEND1099FEDIDNO_Tok: Label 'VEND1099FEDIDNO', Locked = true;
200+
Test_VEND1099TRXEXISTS_Tok: Label 'VEND1099TRXEXISTS', Locked = true;
201+
Test_VEND1099TEN99BOX_Tok: Label 'VEND1099TEN99BOX', Locked = true;
202+
Test_VEND1099TEN99TRXAMT_Tok: Label 'VEND1099TEN99TRXAMT', Locked = true;
203+
}

0 commit comments

Comments
 (0)