diff --git a/Apps/W1/HybridGP/app/Permissions/HybridGPEdit.PermissionSet.al b/Apps/W1/HybridGP/app/Permissions/HybridGPEdit.PermissionSet.al index ebcef2f80d..f226865d77 100644 --- a/Apps/W1/HybridGP/app/Permissions/HybridGPEdit.PermissionSet.al +++ b/Apps/W1/HybridGP/app/Permissions/HybridGPEdit.PermissionSet.al @@ -118,5 +118,6 @@ permissionset 4031 "HybridGP - Edit" tabledata "GP PM10200" = IMD, tabledata "GP PM30300" = IMD, tabledata "GP RM20201" = IMD, - tabledata "GP RM30201" = IMD; + tabledata "GP RM30201" = IMD, + tabledata "GP Migration Warnings" = IMD; } diff --git a/Apps/W1/HybridGP/app/Permissions/HybridGPObjects.PermissionSet.al b/Apps/W1/HybridGP/app/Permissions/HybridGPObjects.PermissionSet.al index 3b9a3ac574..5ba467de0b 100644 --- a/Apps/W1/HybridGP/app/Permissions/HybridGPObjects.PermissionSet.al +++ b/Apps/W1/HybridGP/app/Permissions/HybridGPObjects.PermissionSet.al @@ -153,5 +153,8 @@ permissionset 4029 "HybridGP - Objects" table "GP PM10200" = X, table "GP PM30300" = X, table "GP RM20201" = X, - table "GP RM30201" = X; + table "GP RM30201" = X, + table "GP Migration Warnings" = X, + page "GP Migration Warnings" = X, + page "GP Payment Terms" = X; } diff --git a/Apps/W1/HybridGP/app/Permissions/HybridGPRead.PermissionSet.al b/Apps/W1/HybridGP/app/Permissions/HybridGPRead.PermissionSet.al index b74d1ef91c..b56d7c119b 100644 --- a/Apps/W1/HybridGP/app/Permissions/HybridGPRead.PermissionSet.al +++ b/Apps/W1/HybridGP/app/Permissions/HybridGPRead.PermissionSet.al @@ -118,5 +118,6 @@ permissionset 4032 "HybridGP - Read" tabledata "GP PM10200" = R, tabledata "GP PM30300" = R, tabledata "GP RM20201" = R, - tabledata "GP RM30201" = R; + tabledata "GP RM30201" = R, + tabledata "GP Migration Warnings" = R; } diff --git a/Apps/W1/HybridGP/app/Permissions/INTELLIGENTCLOUDHGP.PermissionSetExt.al b/Apps/W1/HybridGP/app/Permissions/INTELLIGENTCLOUDHGP.PermissionSetExt.al index 68783bf7ef..758b386b16 100644 --- a/Apps/W1/HybridGP/app/Permissions/INTELLIGENTCLOUDHGP.PermissionSetExt.al +++ b/Apps/W1/HybridGP/app/Permissions/INTELLIGENTCLOUDHGP.PermissionSetExt.al @@ -110,5 +110,6 @@ permissionsetextension 4028 "INTELLIGENT CLOUD - HGP" extends "INTELLIGENT CLOUD tabledata "GP PM10200" = RIMD, tabledata "GP PM30300" = RIMD, tabledata "GP RM20201" = RIMD, - tabledata "GP RM30201" = RIMD; + tabledata "GP RM30201" = RIMD, + tabledata "GP Migration Warnings" = RIMD; } \ No newline at end of file diff --git a/Apps/W1/HybridGP/app/Permissions/d365basicHGP.permissionsetext.al b/Apps/W1/HybridGP/app/Permissions/d365basicHGP.permissionsetext.al index 780b489060..15a5e41e1b 100644 --- a/Apps/W1/HybridGP/app/Permissions/d365basicHGP.permissionsetext.al +++ b/Apps/W1/HybridGP/app/Permissions/d365basicHGP.permissionsetext.al @@ -109,5 +109,6 @@ permissionsetextension 4025 "D365 BASIC - HGP" extends "D365 BASIC" tabledata "GP PM10200" = RIMD, tabledata "GP PM30300" = RIMD, tabledata "GP RM20201" = RIMD, - tabledata "GP RM30201" = RIMD; + tabledata "GP RM30201" = RIMD, + tabledata "GP Migration Warnings" = RIMD; } \ No newline at end of file diff --git a/Apps/W1/HybridGP/app/Permissions/d365basicisvHGP.permissionsetext.al b/Apps/W1/HybridGP/app/Permissions/d365basicisvHGP.permissionsetext.al index 77edead572..8e17a96876 100644 --- a/Apps/W1/HybridGP/app/Permissions/d365basicisvHGP.permissionsetext.al +++ b/Apps/W1/HybridGP/app/Permissions/d365basicisvHGP.permissionsetext.al @@ -108,5 +108,6 @@ permissionsetextension 4026 "D365 BASIC ISV - HGP" extends "D365 BASIC ISV" tabledata "GP PM10200" = RIMD, tabledata "GP PM30300" = RIMD, tabledata "GP RM20201" = RIMD, - tabledata "GP RM30201" = RIMD; + tabledata "GP RM30201" = RIMD, + tabledata "GP Migration Warnings" = RIMD; } \ No newline at end of file diff --git a/Apps/W1/HybridGP/app/Permissions/d365teammemberHGP.permissionsetext.al b/Apps/W1/HybridGP/app/Permissions/d365teammemberHGP.permissionsetext.al index 9b1253e83b..22e44319b8 100644 --- a/Apps/W1/HybridGP/app/Permissions/d365teammemberHGP.permissionsetext.al +++ b/Apps/W1/HybridGP/app/Permissions/d365teammemberHGP.permissionsetext.al @@ -109,5 +109,6 @@ permissionsetextension 4027 "D365 TEAM MEMBER - HGP" extends "D365 TEAM MEMBER" tabledata "GP PM10200" = RIMD, tabledata "GP PM30300" = RIMD, tabledata "GP RM20201" = RIMD, - tabledata "GP RM30201" = RIMD; + tabledata "GP RM30201" = RIMD, + tabledata "GP Migration Warnings" = RIMD; } \ No newline at end of file diff --git a/Apps/W1/HybridGP/app/src/Migration/Accounts/GPAccountMigrator.codeunit.al b/Apps/W1/HybridGP/app/src/Migration/Accounts/GPAccountMigrator.codeunit.al index 237664c691..c8f41e5b40 100644 --- a/Apps/W1/HybridGP/app/src/Migration/Accounts/GPAccountMigrator.codeunit.al +++ b/Apps/W1/HybridGP/app/src/Migration/Accounts/GPAccountMigrator.codeunit.al @@ -14,6 +14,7 @@ codeunit 4017 "GP Account Migrator" PostingGroupDescriptionTxt: Label 'Migrated from GP', Locked = true; DescriptionTrxTxt: Label 'Migrated transaction', Locked = true; BeginningBalanceTrxTxt: Label 'Beginning Balance', Locked = true; + MigrationLogAreaTxt: Label 'Account', Locked = true; #if not CLEAN22 #pragma warning disable AA0207 @@ -28,6 +29,7 @@ codeunit 4017 "GP Account Migrator" var GPAccount: Record "GP Account"; GPCompanyAdditionalSettings: Record "GP Company Additional Settings"; + GPMigrationWarnings: Record "GP Migration Warnings"; AccountNum: Code[20]; begin if RecordIdToMigrate.TableNo() <> Database::"GP Account" then @@ -39,8 +41,10 @@ codeunit 4017 "GP Account Migrator" GPAccount.Get(RecordIdToMigrate); AccountNum := CopyStr(GPAccount.AcctNum.Trim(), 1, 20); - if AccountNum = '' then + if AccountNum = '' then begin + GPMigrationWarnings.InsertWarning(MigrationLogAreaTxt, 'Account Index: ' + Format(GPAccount.AcctIndex), 'Account is skipped because there is no account number.'); exit; + end; MigrateAccountDetails(GPAccount, Sender); end; diff --git a/Apps/W1/HybridGP/app/src/Migration/Support/GPPaymentTerms.Page.al b/Apps/W1/HybridGP/app/src/Migration/Support/GPPaymentTerms.Page.al new file mode 100644 index 0000000000..671302afdf --- /dev/null +++ b/Apps/W1/HybridGP/app/src/Migration/Support/GPPaymentTerms.Page.al @@ -0,0 +1,119 @@ +namespace Microsoft.DataMigration.GP; + +page 40134 "GP Payment Terms" +{ + ApplicationArea = All; + Caption = 'GP Payment Terms'; + PageType = Worksheet; + SourceTable = "GP Payment Terms"; + UsageCategory = Lists; + InsertAllowed = false; + DeleteAllowed = false; + Editable = true; + + layout + { + area(content) + { + repeater(General) + { + field(DateFormulaIsValid; DateFormulaIsValid) + { + Caption = 'Valid Date Formula'; + ToolTip = 'Indicates if the resulting date formula is valid.'; + Editable = false; + } + field(CalculatedDateFormula; CalculatedDateFormulaTxt) + { + Caption = 'Calculated Date Formula'; + ToolTip = 'Calculated Date Formula'; + Editable = false; + Style = Unfavorable; + StyleExpr = not DateFormulaIsValid; + } + field(PYMTRMID; Rec.PYMTRMID) + { + ToolTip = 'Specifies the value of the Payment Terms ID field.'; + } + field(DUETYPE; Rec.DUETYPE) + { + ToolTip = 'Specifies the value of the Due Type field.'; + } + field(DUEDTDS; Rec.DUEDTDS) + { + ToolTip = 'Specifies the value of the Due Date/Days field.'; + } + field(DISCTYPE; Rec.DISCTYPE) + { + ToolTip = 'Specifies the value of the Discount Type field.'; + } + field(DISCDTDS; Rec.DISCDTDS) + { + ToolTip = 'Specifies the value of the Discount Date/Days field.'; + } + field(DSCLCTYP; Rec.DSCLCTYP) + { + ToolTip = 'Specifies the value of the Discount Calculate Type field.'; + } + field(DSCPCTAM; Rec.DSCPCTAM) + { + ToolTip = 'Specifies the value of the Discount Percent Amount field.'; + } + field(TAX; Rec.TAX) + { + ToolTip = 'Specifies the value of the Tax field.'; + } + field(CBUVATMD; Rec.CBUVATMD) + { + ToolTip = 'Specifies the value of the CB_Use_VAT_Mode field.'; + } + field(USEGRPER; Rec.USEGRPER) + { + ToolTip = 'Specifies the value of the Use Grace Periods field.'; + } + field(CalculateDateFrom; Rec.CalculateDateFrom) + { + ToolTip = 'Specifies the value of the Calculate Date From field.'; + } + field(CalculateDateFromDays; Rec.CalculateDateFromDays) + { + ToolTip = 'Specifies the value of the Calculate Date From Days field.'; + } + field(DueMonth; Rec.DueMonth) + { + ToolTip = 'Specifies the value of the Due Month field.'; + } + field(DiscountMonth; Rec.DiscountMonth) + { + ToolTip = 'Specifies the value of the Discount Month field.'; + } + } + } + } + + trigger OnAfterGetRecord() + begin + UpdateRecordStatus(); + end; + + + trigger OnAfterGetCurrRecord() + begin + UpdateRecordStatus(); + end; + + trigger OnModifyRecord(): Boolean + begin + UpdateRecordStatus(); + exit(true); + end; + + local procedure UpdateRecordStatus() + begin + DateFormulaIsValid := Rec.GetCalculatedDateForumla(CalculatedDateFormulaTxt); + end; + + var + CalculatedDateFormulaTxt: Text[50]; + DateFormulaIsValid: Boolean; +} \ No newline at end of file diff --git a/Apps/W1/HybridGP/app/src/Migration/Support/GPPaymentTerms.table.al b/Apps/W1/HybridGP/app/src/Migration/Support/GPPaymentTerms.table.al index 137734a01f..b6629634f8 100644 --- a/Apps/W1/HybridGP/app/src/Migration/Support/GPPaymentTerms.table.al +++ b/Apps/W1/HybridGP/app/src/Migration/Support/GPPaymentTerms.table.al @@ -97,5 +97,33 @@ table 4026 "GP Payment Terms" Clustered = true; } } + + internal procedure GetCalculatedDateForumla(var CalculatedDateFormulaTxt: Text[50]): Boolean + var + HelperFunctions: Codeunit "Helper Functions"; + DueDateCalculation: DateFormula; + DiscountDateCalculation: DateFormula; + DueDateCalculationText: Text[50]; + DiscountDateCalculationText: Text[50]; + DateFormulaIsValid: Boolean; + begin + DateFormulaIsValid := false; + DiscountDateCalculationText := HelperFunctions.CalculateDiscountDateFormula(Rec); + CalculatedDateFormulaTxt := DiscountDateCalculationText; + if Evaluate(DiscountDateCalculation, DiscountDateCalculationText) then begin + if Rec.CalculateDateFrom = Rec.CalculateDateFrom::"Transaction Date" then begin + DueDateCalculationText := HelperFunctions.CalculateDueDateFormula(Rec, false, ''); + CalculatedDateFormulaTxt := DueDateCalculationText; + end else begin + DueDateCalculationText := HelperFunctions.CalculateDueDateFormula(Rec, true, CopyStr(DiscountDateCalculationText, 1, 32)); + CalculatedDateFormulaTxt := DueDateCalculationText; + end; + + if Evaluate(DueDateCalculation, DueDateCalculationText) then + DateFormulaIsValid := true; + end; + + exit(DateFormulaIsValid); + end; } diff --git a/Apps/W1/HybridGP/app/src/Migration/Support/HelperFunctions.codeunit.al b/Apps/W1/HybridGP/app/src/Migration/Support/HelperFunctions.codeunit.al index 10c979a117..5bc0ea659c 100644 --- a/Apps/W1/HybridGP/app/src/Migration/Support/HelperFunctions.codeunit.al +++ b/Apps/W1/HybridGP/app/src/Migration/Support/HelperFunctions.codeunit.al @@ -72,7 +72,8 @@ codeunit 4037 "Helper Functions" tabledata "Purchase Header" = rimd, tabledata "Purchase Line" = rimd, tabledata "Over-Receipt Code" = rimd, - tabledata "Accounting Period" = rimd; + tabledata "Accounting Period" = rimd, + tabledata "Data Migration Error" = rimd; var GPConfiguration: Record "GP Configuration"; @@ -599,7 +600,7 @@ codeunit 4037 "Helper Functions" end; end; - local procedure CalculateDueDateFormula(GPPaymentTerms: Record "GP Payment Terms"; Use_Discount_Calc: Boolean; Discount_Calc: Text[32]): Text[50] + internal procedure CalculateDueDateFormula(GPPaymentTerms: Record "GP Payment Terms"; Use_Discount_Calc: Boolean; Discount_Calc: Text[32]): Text[50] var working_number: integer; extra_month: integer; @@ -607,14 +608,17 @@ codeunit 4037 "Helper Functions" working_string: Text[20]; working_discount_calc: Text[50]; final_string: Text[50]; + MonthAsInteger: Integer; begin // BC Only supports GPPaymentTerms.CalculateDateFrom = Transaction Date // Set date formula to a string '<1M>' working_number := GPPaymentTerms.CalculateDateFromDays; // Always add this many days to the due date. + if working_number < 0 then + working_number := 0; if Use_Discount_Calc and (Discount_Calc <> '') then // Need to get the date formula text minus the brackets... - working_discount_calc := copystr(copystr(Discount_Calc, 2, (strlen(Discount_Calc) - 2)), 1, 50) + working_discount_calc := CopyStr(CopyStr(Discount_Calc, 2, (StrLen(Discount_Calc) - 2)), 1, 50) else // In case use discount is true, but the passed-in formula string is empty Use_Discount_Calc := false; @@ -623,7 +627,7 @@ codeunit 4037 "Helper Functions" if GPPaymentTerms.DUETYPE = GPPaymentTerms.DUETYPE::"Net Days" then if GPPaymentTerms.DUEDTDS > 0 then begin working_number := working_number + GPPaymentTerms.DUEDTDS; - working_string := '<' + format(working_number) + 'D>'; + working_string := '<' + Format(working_number, 0, 9) + 'D>'; end; // Get the first day of the current month, then add appropriate days. @@ -631,55 +635,61 @@ codeunit 4037 "Helper Functions" // giving you one extra day we need to remove. if GPPaymentTerms.DUETYPE = GPPaymentTerms.DUETYPE::Date then if GPPaymentTerms.DUEDTDS > 0 then - working_string := ''; + working_string := ''; // Go to the end of the current month, then add appropriate days if GPPaymentTerms.DUETYPE = GPPaymentTerms.DUETYPE::EOM then begin if GPPaymentTerms.DUEDTDS > 0 then working_number := working_number + GPPaymentTerms.DUEDTDS; if working_number > 0 then - working_string := '' + working_string := '' else working_string := ''; end; // Just add the number of initial days to the current date if GPPaymentTerms.DUETYPE = GPPaymentTerms.DUETYPE::None then - working_string := '<' + format(working_number) + 'D>'; + working_string := '<' + Format(working_number, 0, 9) + 'D>'; // Set the day of the next month // Need to remove one day, see the comments above for DUETYPE::Date if GPPaymentTerms.DUETYPE = GPPaymentTerms.DUETYPE::"Next Month" then begin if GPPaymentTerms.DUEDTDS > 0 then working_number := GPPaymentTerms.DUEDTDS; + + if working_number < 1 then + working_number := 1; + // First day of current month, + 1 month + the number of days - working_string := '<-CM+1M+' + format(working_number - 1) + 'D>'; + working_string := '<-CM+1M+' + Format(working_number - 1, 0, 9) + 'D>'; end; if GPPaymentTerms.DUETYPE = GPPaymentTerms.DUETYPE::Months then begin if GPPaymentTerms.DUEDTDS > 0 then extra_month := GPPaymentTerms.DUEDTDS; // Add the extra months, then the extra days - working_string := '<' + format(extra_month) + 'M+' + format(working_number) + 'D>'; + working_string := '<' + Format(extra_month, 0, 9) + 'M+' + Format(working_number, 0, 9) + 'D>'; end; - if GPPaymentTerms.DUETYPE = GPPaymentTerms.DUETYPE::"Month/Day" then - working_string := ''; + if GPPaymentTerms.DUETYPE = GPPaymentTerms.DUETYPE::"Month/Day" then begin + MonthAsInteger := GPPaymentTerms.DueMonth; + working_string := ''; + end; if GPPaymentTerms.DUETYPE = GPPaymentTerms.DUETYPE::Annual then begin if GPPaymentTerms.DUEDTDS > 0 then extra_year := GPPaymentTerms.DUEDTDS; // Add the extra months, then the extra days - working_string := '<' + format(extra_year) + 'Y+' + format(working_number) + 'D>' + working_string := '<' + Format(extra_year, 0, 9) + 'Y+' + Format(working_number, 0, 9) + 'D>' end; if Use_Discount_Calc then begin - final_string := copystr('<' + working_discount_calc, 1, 50); - if (copystr(working_string, 2, 1) = '-') or (copystr(working_string, 2, 1) = '+') then - final_string := final_string + copystr(working_string, 2) + final_string := CopyStr('<' + working_discount_calc, 1, 50); + if (CopyStr(working_string, 2, 1) = '-') or (CopyStr(working_string, 2, 1) = '+') then + final_string := final_string + CopyStr(working_string, 2) else if working_string <> '' then - final_string += '+' + copystr(working_string, 2) + final_string += '+' + CopyStr(working_string, 2) else final_string += '>'; exit(final_string); @@ -688,7 +698,7 @@ codeunit 4037 "Helper Functions" // Back in the calling proc, EVALUATE(variable,forumlastring) will set the variable to the correct formula end; - local procedure CalculateDiscountDateFormula(GPPaymentTerms: Record "GP Payment Terms"): Text[50] + internal procedure CalculateDiscountDateFormula(GPPaymentTerms: Record "GP Payment Terms"): Text[50] var working_number: integer; extra_month: integer; @@ -697,12 +707,14 @@ codeunit 4037 "Helper Functions" begin // Set date formula to a string '<1M>' working_number := GPPaymentTerms.CalculateDateFromDays; // Always add this many days to the due date. + if working_number < 0 then + working_number := 0; // Add base days + discount days if GPPaymentTerms.DISCTYPE = GPPaymentTerms.DISCTYPE::Days then if GPPaymentTerms.DISCDTDS > 0 then begin working_number := working_number + GPPaymentTerms.DISCDTDS; - working_string := '<' + format(working_number) + 'D>'; + working_string := '<' + Format(working_number, 0, 9) + 'D>'; end; // Get the first day of the current month, then add appropriate days. @@ -710,46 +722,50 @@ codeunit 4037 "Helper Functions" // giving you one extra day we need to remove. if GPPaymentTerms.DISCTYPE = GPPaymentTerms.DISCTYPE::Date then if GPPaymentTerms.DISCDTDS > 0 then - working_string := ''; + working_string := ''; // Go to the end of the current month, then add appropriate days if GPPaymentTerms.DISCTYPE = GPPaymentTerms.DISCTYPE::EOM then begin if GPPaymentTerms.DISCDTDS > 0 then working_number := working_number + GPPaymentTerms.DISCDTDS; if working_number > 0 then - working_string := '' + working_string := '' else working_string := ''; end; // Just add the number of initial days to the current date if GPPaymentTerms.DISCTYPE = GPPaymentTerms.DISCTYPE::None then - working_string := '<+' + format(working_number) + 'D>'; + working_string := '<+' + Format(working_number, 0, 9) + 'D>'; // Set the day of the next month // Need to remove one day, see the comments above for DISCTYPE::Date if GPPaymentTerms.DISCTYPE = GPPaymentTerms.DISCTYPE::"Next Month" then begin if GPPaymentTerms.DISCDTDS > 0 then working_number := GPPaymentTerms.DISCDTDS; + + if working_number < 1 then + working_number := 1; + // First day of current month, + 1 month + the number of days - working_string := '<-CM+1M+' + format(working_number - 1) + 'D>;' + working_string := '<-CM+1M+' + Format(working_number - 1, 0, 9) + 'D>;' end; if GPPaymentTerms.DISCTYPE = GPPaymentTerms.DISCTYPE::Months then begin if GPPaymentTerms.DISCDTDS > 0 then extra_month := GPPaymentTerms.DISCDTDS; // Add the extra months, then the extra days - working_string := '<' + format(extra_month) + 'M+' + format(working_number) + 'D>;' + working_string := '<' + Format(extra_month, 0, 9) + 'M+' + Format(working_number, 0, 9) + 'D>;' end; if GPPaymentTerms.DISCTYPE = GPPaymentTerms.DISCTYPE::"Month/Day" then - working_string := ''; + working_string := ''; if GPPaymentTerms.DISCTYPE = GPPaymentTerms.DISCTYPE::Annual then begin if GPPaymentTerms.DISCDTDS > 0 then extra_year := GPPaymentTerms.DISCDTDS; // Add the extra months, then the extra days - working_string := '<' + format(extra_year) + 'Y+' + format(working_number) + 'D>;' + working_string := '<' + Format(extra_year, 0, 9) + 'Y+' + Format(working_number, 0, 9) + 'D>;' end; exit(working_string); @@ -1069,6 +1085,88 @@ codeunit 4037 "Helper Functions" exit(UnpostedLines); end; + local procedure GetGLBatchCountWithUnpostedLinesForCompany(CompanyNameTxt: Text; TemplateName: Text; BatchNameFilter: text): Integer + var + GenJournalBatch: Record "Gen. Journal Batch"; + GenJournalLine: Record "Gen. Journal Line"; + UnpostedBatchCount: Integer; + begin + if not GenJournalBatch.ChangeCompany(CompanyNameTxt) then + exit; + + if not GenJournalLine.ChangeCompany(CompanyNameTxt) then + exit; + + GenJournalBatch.SetRange("Journal Template Name", TemplateName); + GenJournalBatch.SetFilter(Name, BatchNameFilter); + if GenJournalBatch.FindSet() then + repeat + GenJournalLine.SetRange("Journal Template Name", GenJournalBatch."Journal Template Name"); + GenJournalLine.SetRange("Journal Batch Name", GenJournalBatch.Name); + if not GenJournalLine.IsEmpty() then + UnpostedBatchCount := UnpostedBatchCount + 1; + until GenJournalBatch.Next() = 0; + + exit(UnpostedBatchCount); + end; + + local procedure GetItemBatchCountWithUnpostedLinesForCompany(CompanyNameTxt: Text): Integer + var + ItemJournalBatch: Record "Item Journal Batch"; + ItemJournalLine: Record "Item Journal Line"; + UnpostedBatchCount: Integer; + begin + if not ItemJournalBatch.ChangeCompany(CompanyNameTxt) then + exit; + + if not ItemJournalLine.ChangeCompany(CompanyNameTxt) then + exit; + + ItemJournalBatch.SetFilter(Name, 'GPITM*'); + if ItemJournalBatch.FindSet() then + repeat + ItemJournalLine.SetRange("Journal Batch Name", ItemJournalBatch.Name); + if not ItemJournalLine.IsEmpty() then + UnpostedBatchCount += UnpostedBatchCount + 1; + until ItemJournalBatch.Next() = 0; + + exit(UnpostedBatchCount); + end; + + internal procedure GetUnpostedBatchCountForCompany(CompanyNameTxt: Text; var TotalGLBatchCount: Integer; var TotalItemBatchCount: Integer) + var + HybridCompanyStatus: Record "Hybrid Company Status"; + GPCompanyAdditionalSettings: Record "GP Company Additional Settings"; + begin + TotalGLBatchCount := 0; + TotalItemBatchCount := 0; + + if not HybridCompanyStatus.Get(CompanyNameTxt) then + exit; + + if not (HybridCompanyStatus."Upgrade Status" = HybridCompanyStatus."Upgrade Status"::Completed) then + exit; + + + if not GPCompanyAdditionalSettings.Get(CompanyNameTxt) then + exit; + + if not GPCompanyAdditionalSettings."Skip Posting Account Batches" then + TotalGLBatchCount := GetGLBatchCountWithUnpostedLinesForCompany(CompanyNameTxt, GeneralTemplateNameTxt, PostingGroupCodeTxt + '*'); + + if not GPCompanyAdditionalSettings."Skip Posting Customer Batches" then + TotalGLBatchCount += GetGLBatchCountWithUnpostedLinesForCompany(CompanyNameTxt, GeneralTemplateNameTxt, CustomerBatchNameTxt); + + if not GPCompanyAdditionalSettings."Skip Posting Vendor Batches" then + TotalGLBatchCount += GetGLBatchCountWithUnpostedLinesForCompany(CompanyNameTxt, GeneralTemplateNameTxt, VendorBatchNameTxt); + + if not GPCompanyAdditionalSettings."Skip Posting Bank Batches" then + TotalGLBatchCount += GetGLBatchCountWithUnpostedLinesForCompany(CompanyNameTxt, GeneralTemplateNameTxt, BankBatchNameTxt); + + if not GPCompanyAdditionalSettings."Skip Posting Item Batches" then + TotalItemBatchCount := GetItemBatchCountWithUnpostedLinesForCompany(CompanyNameTxt); + end; + procedure PostGLTransactions() var GenJournalLine: Record "Gen. Journal Line"; @@ -1473,46 +1571,55 @@ codeunit 4037 "Helper Functions" var GPPaymentTerms: Record "GP Payment Terms"; PaymentTerms: Record "Payment Terms"; + GPMigrationWarnings: Record "GP Migration Warnings"; DueDateCalculation: DateFormula; DiscountDateCalculation: DateFormula; SeedValue: integer; PaymentTerm: Text[10]; DueDateCalculationText: Text[50]; DiscountDateCalculationText: Text[50]; + LogMigrationArea: Text[50]; + IsPaymentTermHandled: Boolean; begin + LogMigrationArea := 'Payment Terms'; SeedValue := 0; if GPPaymentTerms.FindSet() then begin repeat - if StrLen(DelChr(GPPaymentTerms.PYMTRMID, '>', ' ')) > 10 then begin - PaymentTerm := GeneratePaymentTerm(SeedValue, GPPaymentTerms.PYMTRMID); - PaymentTerms.Validate(Code, PaymentTerm); - SeedValue := SeedValue + 1; + IsPaymentTermHandled := false; + OnHandlePaymentTerm(GPPaymentTerms, IsPaymentTermHandled); + if not IsPaymentTermHandled then begin + if StrLen(DelChr(GPPaymentTerms.PYMTRMID, '>', ' ')) > 10 then begin + PaymentTerm := GeneratePaymentTerm(SeedValue, GPPaymentTerms.PYMTRMID); + PaymentTerms.Validate(Code, PaymentTerm); + SeedValue := SeedValue + 1; + end else + PaymentTerm := CopyStr(DelChr(GPPaymentTerms.PYMTRMID, '>', ' '), 1, 10); + + if not PaymentTerms.Get(PaymentTerm) then begin + PaymentTerms.Init(); + PaymentTerms.Validate(Code, PaymentTerm); + PaymentTerms.Validate(Description, DelChr(GPPaymentTerms.PYMTRMID, '>', ' ')); + PaymentTerms.Validate("Discount %", (GPPaymentTerms.DSCPCTAM / 100)); + + DiscountDateCalculationText := CalculateDiscountDateFormula(GPPaymentTerms); + Evaluate(DiscountDateCalculation, DiscountDateCalculationText); + PaymentTerms.Validate("Discount Date Calculation", DiscountDateCalculation); + + if GPPaymentTerms.CalculateDateFrom = GPPaymentTerms.CalculateDateFrom::"Transaction Date" then + DueDateCalculationText := CalculateDueDateFormula(GPPaymentTerms, false, '') + else + DueDateCalculationText := CalculateDueDateFormula(GPPaymentTerms, true, copystr(DiscountDateCalculationText, 1, 32)); + + Evaluate(DueDateCalculation, DueDateCalculationText); + PaymentTerms.Validate("Due Date Calculation", DueDateCalculation); + + PaymentTerms.Insert(true); + + GPPaymentTerms.PYMTRMID_New := PaymentTerm; + GPPaymentTerms.Modify(); + end; end else - PaymentTerm := CopyStr(DelChr(GPPaymentTerms.PYMTRMID, '>', ' '), 1, 10); - - if not PaymentTerms.Get(PaymentTerm) then begin - PaymentTerms.Init(); - PaymentTerms.Validate(Code, PaymentTerm); - PaymentTerms.Validate(Description, DelChr(GPPaymentTerms.PYMTRMID, '>', ' ')); - PaymentTerms.Validate("Discount %", (GPPaymentTerms.DSCPCTAM / 100)); - - DiscountDateCalculationText := CalculateDiscountDateFormula(GPPaymentTerms); - Evaluate(DiscountDateCalculation, DiscountDateCalculationText); - PaymentTerms.Validate("Discount Date Calculation", DiscountDateCalculation); - - if GPPaymentTerms.CalculateDateFrom = GPPaymentTerms.CalculateDateFrom::"Transaction Date" then - DueDateCalculationText := CalculateDueDateFormula(GPPaymentTerms, false, '') - else - DueDateCalculationText := CalculateDueDateFormula(GPPaymentTerms, true, copystr(DiscountDateCalculationText, 1, 32)); - - Evaluate(DueDateCalculation, DueDateCalculationText); - PaymentTerms.Validate("Due Date Calculation", DueDateCalculation); - - PaymentTerms.Insert(true); - - GPPaymentTerms.PYMTRMID_New := PaymentTerm; - GPPaymentTerms.Modify(); - end; + GPMigrationWarnings.InsertWarning(LogMigrationArea, PaymentTerm, 'Payment Term ' + GPPaymentTerms.PYMTRMID + ' was handled.'); until GPPaymentTerms.Next() = 0; SeedValue := 0; @@ -1996,4 +2103,9 @@ codeunit 4037 "Helper Functions" local procedure OnSkipPostingItemBatches(var SkipPosting: Boolean) begin end; + + [IntegrationEvent(false, false)] + local procedure OnHandlePaymentTerm(GPPaymentTerms: Record "GP Payment Terms"; var IsPaymentTermHandled: Boolean) + begin + end; } \ No newline at end of file diff --git a/Apps/W1/HybridGP/app/src/Migration/Support/PurchaseOrders/GPPOMigrator.codeunit.al b/Apps/W1/HybridGP/app/src/Migration/Support/PurchaseOrders/GPPOMigrator.codeunit.al index a8df2d1fda..ad0465841a 100644 --- a/Apps/W1/HybridGP/app/src/Migration/Support/PurchaseOrders/GPPOMigrator.codeunit.al +++ b/Apps/W1/HybridGP/app/src/Migration/Support/PurchaseOrders/GPPOMigrator.codeunit.al @@ -21,6 +21,7 @@ codeunit 40108 "GP PO Migrator" GPCodeTxt: Label 'GP', Locked = true; ItemJournalBatchNameTxt: Label 'GPPOITEMS', Comment = 'Item journal batch name for item adjustments', Locked = true; SimpleInvJnlNameTxt: Label 'DEFAULT', Comment = 'The default name of the item journal', Locked = true; + MigrationLogAreaTxt: Label 'PO', Locked = true; ItemJnlBatchLineNo: Integer; PostPurchaseOrderNoList: List of [Text]; InitialAutomaticCostAdjustmentType: Enum "Automatic Cost Adjustment Type"; @@ -35,6 +36,7 @@ codeunit 40108 "GP PO Migrator" GeneralLedgerSetup: Record "General Ledger Setup"; Vendor: Record Vendor; InventorySetup: Record "Inventory Setup"; + GPMigrationWarnings: Record "GP Migration Warnings"; DataMigrationErrorLogging: Codeunit "Data Migration Error Logging"; PurchaseDocumentType: Enum "Purchase Document Type"; PurchaseDocumentStatus: Enum "Purchase Document Status"; @@ -96,8 +98,9 @@ codeunit 40108 "GP PO Migrator" PurchaseLine.SetRange("Document Type", PurchaseLine."Document Type"::Order); PurchaseLine.SetRange("Document No.", PurchaseHeader."No."); if PurchaseLine.IsEmpty() then - PurchaseHeader.Delete(); - end; + PurchaseHeader.Delete() + end else + GPMigrationWarnings.InsertWarning(MigrationLogAreaTxt, GPPOP10100.PONUMBER, 'PO was skipped because the Vendor has not been migrated.'); until GPPOP10100.Next() = 0; PostReceivedPurchaseLines(); @@ -199,6 +202,7 @@ codeunit 40108 "GP PO Migrator" var PurchaseLine: Record "Purchase Line"; Item: Record Item; + FoundItem: Boolean; PurchaseDocumentType: Enum "Purchase Document Type"; PurchaseLineType: Enum "Purchase Line Type"; ItemNo: Code[20]; @@ -228,8 +232,11 @@ codeunit 40108 "GP PO Migrator" ItemNo := CopyStr(GPPOP10110.ITEMNMBR.Trim(), 1, MaxStrLen(ItemNo)); IsInventoryItem := false; - if Item.Get(ItemNo) then + Item.SetLoadFields(Type, "Over-Receipt Code"); + if Item.Get(ItemNo) then begin + FoundItem := true; IsInventoryItem := Item.Type = Item.Type::Inventory; + end; PurchaseLine.Init(); PurchaseLine."Document No." := PONumber; @@ -238,8 +245,9 @@ codeunit 40108 "GP PO Migrator" PurchaseLine."Buy-from Vendor No." := GPPOP10110.VENDORID; PurchaseLine.Type := PurchaseLineType::Item; - if GPPOP10110.NONINVEN = 1 then - CreateNonInventoryItem(GPPOP10110); + if not FoundItem then + if GPPOP10110.NONINVEN = 1 then + CreateNonInventoryItem(GPPOP10110); PurchaseLine.Validate("Gen. Bus. Posting Group", GPCodeTxt); PurchaseLine.Validate("Gen. Prod. Posting Group", GPCodeTxt); diff --git a/Apps/W1/HybridGP/app/src/codeunits/HybridGPWizard.codeunit.al b/Apps/W1/HybridGP/app/src/codeunits/HybridGPWizard.codeunit.al index 47604e0d59..5114af14dd 100644 --- a/Apps/W1/HybridGP/app/src/codeunits/HybridGPWizard.codeunit.al +++ b/Apps/W1/HybridGP/app/src/codeunits/HybridGPWizard.codeunit.al @@ -144,6 +144,7 @@ codeunit 4015 "Hybrid GP Wizard" HybridCompanyStatus: Record "Hybrid Company Status"; HybridReplicationDetail: Record "Hybrid Replication Detail"; GPMigrationErrorOverview: Record "GP Migration Error Overview"; + GPMigrationWarnings: Record "GP Migration Warnings"; begin GPCompanyMigrationSettings.Reset(); if GPCompanyMigrationSettings.FindSet() then @@ -163,6 +164,9 @@ codeunit 4015 "Hybrid GP Wizard" if not GPMigrationErrorOverview.IsEmpty() then GPMigrationErrorOverview.DeleteAll(); + + if not GPMigrationWarnings.IsEmpty() then + GPMigrationWarnings.DeleteAll(); end; [EventSubscriber(ObjectType::Table, Database::"Company", 'OnAfterDeleteEvent', '', false, false)] @@ -174,6 +178,7 @@ codeunit 4015 "Hybrid GP Wizard" HybridCompanyStatus: Record "Hybrid Company Status"; HybridReplicationDetail: Record "Hybrid Replication Detail"; GPMigrationErrorOverview: Record "GP Migration Error Overview"; + GPMigrationWarnings: Record "GP Migration Warnings"; begin if Rec.IsTemporary() then exit; @@ -197,6 +202,10 @@ codeunit 4015 "Hybrid GP Wizard" GPMigrationErrorOverview.SetRange("Company Name", Rec.Name); if not GPMigrationErrorOverview.IsEmpty() then GPMigrationErrorOverview.DeleteAll(); + + GPMigrationWarnings.SetRange("Company Name", Rec.Name); + if not GPMigrationWarnings.IsEmpty() then + GPMigrationWarnings.DeleteAll(); end; local procedure ProcessesAreRunning(): Boolean diff --git a/Apps/W1/HybridGP/app/src/pages/GPCompanyAddSettingsList.Page.al b/Apps/W1/HybridGP/app/src/pages/GPCompanyAddSettingsList.Page.al index 75e2bc72e8..cd1f9037ff 100644 --- a/Apps/W1/HybridGP/app/src/pages/GPCompanyAddSettingsList.Page.al +++ b/Apps/W1/HybridGP/app/src/pages/GPCompanyAddSettingsList.Page.al @@ -5,7 +5,7 @@ page 4051 "GP Company Add. Settings List" Caption = 'GP Company Additional Settings List'; PageType = ListPart; SourceTable = "GP Company Additional Settings"; - SourceTableView = sorting(Name) where("Name" = filter(<> ''), "Migration Completed" = const(false)); + SourceTableView = sorting(Name) where("Name" = filter(<> ''), "Migration Completed" = const(false), "Has Hybrid Company" = const(true)); DeleteAllowed = false; InsertAllowed = false; ModifyAllowed = true; diff --git a/Apps/W1/HybridGP/app/src/pages/GPMigrationWarnings.Page.al b/Apps/W1/HybridGP/app/src/pages/GPMigrationWarnings.Page.al new file mode 100644 index 0000000000..72b58f2335 --- /dev/null +++ b/Apps/W1/HybridGP/app/src/pages/GPMigrationWarnings.Page.al @@ -0,0 +1,35 @@ +page 40133 "GP Migration Warnings" +{ + ApplicationArea = All; + Caption = 'GP Migration Warnings'; + PageType = List; + SourceTable = "GP Migration Warnings"; + UsageCategory = Administration; + Editable = false; + + layout + { + area(content) + { + repeater(General) + { + field("Company Name"; Rec."Company Name") + { + ToolTip = 'Specifies the value of the Company Name field.'; + } + field("Migration Area"; Rec."Migration Area") + { + ToolTip = 'Specifies the value of the Migration Area field.'; + } + field(Context; Rec.Context) + { + ToolTip = 'Specifies the value of the Context field.'; + } + field("Warning Text"; Rec."Warning Text") + { + ToolTip = 'Specifies the value of the Warning Text field.'; + } + } + } + } +} \ No newline at end of file diff --git a/Apps/W1/HybridGP/app/src/pages/HybridGPErrorsOverviewFb.page.al b/Apps/W1/HybridGP/app/src/pages/HybridGPErrorsOverviewFb.page.al index 90c5459199..1c0df8a16b 100644 --- a/Apps/W1/HybridGP/app/src/pages/HybridGPErrorsOverviewFb.page.al +++ b/Apps/W1/HybridGP/app/src/pages/HybridGPErrorsOverviewFb.page.al @@ -1,3 +1,4 @@ +#if not CLEAN24 namespace Microsoft.DataMigration.GP; using Microsoft.DataMigration; @@ -10,6 +11,9 @@ page 40132 "Hybrid GP Errors Overview Fb" DelayedInsert = false; ModifyAllowed = false; SourceTable = "GP Migration Error Overview"; + ObsoleteState = Pending; + ObsoleteReason = 'Replaced by Hybrid GP Overview Fb'; + ObsoleteTag = '24.0'; layout { @@ -71,3 +75,4 @@ page 40132 "Hybrid GP Errors Overview Fb" MigrationErrorCount: Integer; FailedCompanyCount: Integer; } +#endif \ No newline at end of file diff --git a/Apps/W1/HybridGP/app/src/pages/HybridGPOverviewFb.Page.al b/Apps/W1/HybridGP/app/src/pages/HybridGPOverviewFb.Page.al new file mode 100644 index 0000000000..16a5d0f0bd --- /dev/null +++ b/Apps/W1/HybridGP/app/src/pages/HybridGPOverviewFb.Page.al @@ -0,0 +1,138 @@ +namespace Microsoft.DataMigration.GP; + +using Microsoft.DataMigration; + +page 40125 "Hybrid GP Overview Fb" +{ + ApplicationArea = All; + Caption = 'GP Migration Overview'; + PageType = CardPart; + + layout + { + area(Content) + { + cuegroup(Errors) + { + ShowCaption = false; + + field("Migration Errors"; MigrationErrorCount) + { + Caption = 'Migration Errors'; + ApplicationArea = Basic, Suite; + Style = Unfavorable; + StyleExpr = (MigrationErrorCount > 0); + ToolTip = 'Indicates the number of errors that occurred during the migration.'; + + trigger OnDrillDown() + begin + Page.Run(Page::"GP Migration Error Overview"); + end; + } + + field("Failed Companies"; FailedCompanyCount) + { + Caption = 'Failed Companies'; + ApplicationArea = Basic, Suite; + Style = Unfavorable; + StyleExpr = (FailedCompanyCount > 0); + ToolTip = 'Indicates the number of companies that failed to upgrade.'; + + trigger OnDrillDown() + begin + Page.Run(Page::"Hybrid GP Failed Companies"); + end; + } + } + + cuegroup(Other) + { + ShowCaption = false; + + field("Failed Batches"; FailedBatchCount) + { + Caption = 'Failed Batches'; + ApplicationArea = All; + Style = Unfavorable; + StyleExpr = (FailedBatchCount > 0); + ToolTip = 'Indicates the total number of failed batches, for all migrated companies.'; + + trigger OnDrillDown() + begin + Message(FailedBatchMsg); + end; + } + + field("Migration Warnings"; MigrationWarningCount) + { + Caption = 'Migration Warnings'; + ApplicationArea = All; + ToolTip = 'Indicates the number of migration warning entries.'; + + trigger OnDrillDown() + begin + Page.Run(Page::"GP Migration Warnings"); + end; + } + } + } + } + + trigger OnAfterGetRecord() + var + GPMigrationErrorOverview: Record "GP Migration Error Overview"; + begin + MigrationErrorCount := GPMigrationErrorOverview.Count(); + end; + + trigger OnAfterGetCurrRecord() + var + GPMigrationErrorOverview: Record "GP Migration Error Overview"; + HybridCompanyStatus: Record "Hybrid Company Status"; + GPMigrationWarnings: Record "GP Migration Warnings"; + HelperFunctions: Codeunit "Helper Functions"; + TotalGLBatchCount: Integer; + TotalItemBatchCount: Integer; + CompanyHasFailedBatches: Boolean; + begin + FailedBatchCount := 0; + FailedBatchMsg := 'One or more batches failed to post.\'; + + MigrationErrorCount := GPMigrationErrorOverview.Count(); + HybridCompanyStatus.SetRange("Upgrade Status", HybridCompanyStatus."Upgrade Status"::Failed); + FailedCompanyCount := HybridCompanyStatus.Count(); + MigrationWarningCount := GPMigrationWarnings.Count(); + + HybridCompanyStatus.Reset(); + HybridCompanyStatus.SetRange("Upgrade Status", HybridCompanyStatus."Upgrade Status"::Completed); + if HybridCompanyStatus.FindSet() then + repeat + TotalGLBatchCount := 0; + TotalItemBatchCount := 0; + + HelperFunctions.GetUnpostedBatchCountForCompany(HybridCompanyStatus.Name, TotalGLBatchCount, TotalItemBatchCount); + FailedBatchCount := FailedBatchCount + TotalGLBatchCount + TotalItemBatchCount; + CompanyHasFailedBatches := (TotalGLBatchCount > 0) or (TotalItemBatchCount > 0); + if CompanyHasFailedBatches then begin + if (TotalGLBatchCount > 0) and (TotalItemBatchCount > 0) then + FailedBatchMsg := FailedBatchMsg + HybridCompanyStatus.Name + ': GL batches: ' + Format(TotalGLBatchCount) + ', Item batches: ' + Format(TotalItemBatchCount) + '\'; + + if (TotalGLBatchCount > 0) and (TotalItemBatchCount = 0) then + FailedBatchMsg := FailedBatchMsg + HybridCompanyStatus.Name + ': GL batches: ' + Format(TotalGLBatchCount) + '\'; + + if (TotalGLBatchCount = 0) and (TotalItemBatchCount > 0) then + FailedBatchMsg := FailedBatchMsg + HybridCompanyStatus.Name + ': Item batches: ' + Format(TotalItemBatchCount) + '\'; + end; + until HybridCompanyStatus.Next() = 0; + + if FailedBatchCount = 0 then + FailedBatchMsg := 'No failed batches'; + end; + + var + MigrationErrorCount: Integer; + FailedCompanyCount: Integer; + FailedBatchCount: Integer; + FailedBatchMsg: Text; + MigrationWarningCount: Integer; +} \ No newline at end of file diff --git a/Apps/W1/HybridGP/app/src/pages/IntelligentCloudExtension.PageExt.al b/Apps/W1/HybridGP/app/src/pages/IntelligentCloudExtension.PageExt.al index 01deb07082..b5dca3cdbf 100644 --- a/Apps/W1/HybridGP/app/src/pages/IntelligentCloudExtension.PageExt.al +++ b/Apps/W1/HybridGP/app/src/pages/IntelligentCloudExtension.PageExt.al @@ -16,7 +16,17 @@ pageextension 4015 "Intelligent Cloud Extension" extends "Intelligent Cloud Mana ApplicationArea = Basic, Suite; Visible = false; } +#if not CLEAN24 part(Errors; "Hybrid GP Errors Overview Fb") + { + ApplicationArea = Basic, Suite; + Visible = false; + ObsoleteState = Pending; + ObsoleteReason = 'Replaced by Overview part.'; + ObsoleteTag = '24.0'; + } +#endif + part(Overview; "Hybrid GP Overview Fb") { ApplicationArea = Basic, Suite; Visible = FactBoxesVisible; @@ -104,12 +114,14 @@ pageextension 4015 "Intelligent Cloud Extension" extends "Intelligent Cloud Mana HybridCompany.SetRange(Replicate, true); HasCompletedSetupWizard := not HybridCompany.IsEmpty(); - GPConfiguration.GetSingleInstance(); - if GetHasCompletedMigration() then - if GPCompanyAdditionalSettings.GetMigrateHistory() then - if not GPConfiguration.HasHistoricalJobRan() then - ShowGPHistoricalJobNeedsToRunNotification(); + if HybridCompany.Get(CompanyName()) then begin + GPConfiguration.GetSingleInstance(); + if GetHasCompletedMigration() then + if GPCompanyAdditionalSettings.GetMigrateHistory() then + if not GPConfiguration.HasHistoricalJobRan() then + ShowGPHistoricalJobNeedsToRunNotification(); + end; end; local procedure GetHasCompletedMigration(): Boolean diff --git a/Apps/W1/HybridGP/app/src/tables/GPCompanyAdditionalSettings.table.al b/Apps/W1/HybridGP/app/src/tables/GPCompanyAdditionalSettings.table.al index e84655a8b3..f71908568d 100644 --- a/Apps/W1/HybridGP/app/src/tables/GPCompanyAdditionalSettings.table.al +++ b/Apps/W1/HybridGP/app/src/tables/GPCompanyAdditionalSettings.table.al @@ -436,6 +436,11 @@ table 40105 "GP Company Additional Settings" DataClassification = SystemMetadata; InitValue = false; } + field(42; "Has Hybrid Company"; Boolean) + { + FieldClass = FlowField; + CalcFormula = exist("Hybrid Company" where("Name" = field(Name))); + } } keys diff --git a/Apps/W1/HybridGP/app/src/tables/GPMigrationWarnings.Table.al b/Apps/W1/HybridGP/app/src/tables/GPMigrationWarnings.Table.al new file mode 100644 index 0000000000..8b6c282659 --- /dev/null +++ b/Apps/W1/HybridGP/app/src/tables/GPMigrationWarnings.Table.al @@ -0,0 +1,49 @@ +table 41006 "GP Migration Warnings" +{ + Caption = 'GP Migration Warnings'; + DataPerCompany = false; + DataClassification = SystemMetadata; + + fields + { + field(1; Id; Integer) + { + AutoIncrement = true; + Caption = 'Id'; + } + field(2; "Company Name"; Text[30]) + { + Caption = 'Company Name'; + } + field(3; "Migration Area"; Text[50]) + { + Caption = 'Migration Area'; + } + field(4; Context; Text[50]) + { + Caption = 'Context'; + } + field(5; "Warning Text"; Text[500]) + { + Caption = 'Warning Text'; + } + } + keys + { + key(PK; Id) + { + Clustered = true; + } + } + + procedure InsertWarning(MigrationArea: Text[50]; ContextValue: Text[50]; WarningText: Text[500]) + var + GPMigrationWarnings: Record "GP Migration Warnings"; + begin + GPMigrationWarnings."Company Name" := CopyStr(CompanyName(), 1, 30); + GPMigrationWarnings."Migration Area" := MigrationArea; + GPMigrationWarnings.Context := ContextValue; + GPMigrationWarnings."Warning Text" := WarningText; + GPMigrationWarnings.Insert(); + end; +} \ No newline at end of file diff --git a/Apps/W1/HybridGP/test/src/GPDataMigrationTests.codeunit.al b/Apps/W1/HybridGP/test/src/GPDataMigrationTests.codeunit.al index 47bd65e875..77ad816af2 100644 --- a/Apps/W1/HybridGP/test/src/GPDataMigrationTests.codeunit.al +++ b/Apps/W1/HybridGP/test/src/GPDataMigrationTests.codeunit.al @@ -1013,6 +1013,1016 @@ codeunit 139664 "GP Data Migration Tests" Assert.AreEqual(DueDateCalculation, PaymentTerms."Due Date Calculation", StrSubstNo('Invalid Due Date Calculation for %1', CurrentPaymentTerm)); end; + local procedure IsDateFormulaValid(DateFormulaTxt: Text): Boolean + var + DateFormulaObj: DateFormula; + begin + exit(Evaluate(DateFormulaObj, DateFormulaTxt)); + end; + + [Test] + procedure TestCalculateDueDateFormulaEmptyRecord() + var + GPPaymentTerms: Record "GP Payment Terms"; + DateFormulaText: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] An empty record is encountered. + GPPaymentTerms.DUETYPE := 0; + + // [THEN] The date formula string will be empty. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual('', DateFormulaText, 'The payment term date formula should be empty for an empty record.'); + + // Same for discount date formula + DateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual('', DateFormulaText, 'The payment term discount date formula should be empty for an empty record.'); + end; + + [Test] + procedure TestCalculateDueDateFormulaDueTypeNetDays() + var + GPPaymentTerms: Record "GP Payment Terms"; + DateFormulaText: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term is configured for Net Days + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Net Days"; + + // [WHEN] DUEDTDS < 1 + GPPaymentTerms.DUEDTDS := 0; + + // [THEN] The date formula string will be empty. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual('', DateFormulaText, 'The payment term date formula should be empty for DueType Net Days, DUEDTDS < 1.'); + + // [WHEN] DUEDTDS > 0 + GPPaymentTerms.DUEDTDS := 30; + + // [THEN] A valid payment term date formula will be generated. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(true, IsDateFormulaValid(DateFormulaText), 'The payment term date formula is invalid. ' + DateFormulaText); + Assert.AreEqual('<30D>', DateFormulaText, 'The payment term date formula is incorrect for DueType Net Days, DUEDTDS = 30.'); + end; + + [Test] + procedure TestCalculateDueDateFormulaDueTypeDate() + var + GPPaymentTerms: Record "GP Payment Terms"; + DateFormulaText: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term is configured for Date + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Date; + + // [WHEN] DUEDTDS < 1 + GPPaymentTerms.DUEDTDS := 0; + + // [THEN] The date formula string will be empty. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual('', DateFormulaText, 'The payment term date formula should be empty for DueType Date, DUEDTDS < 1.'); + + // [WHEN] DUEDTDS > 0 + GPPaymentTerms.DUEDTDS := 30; + + // [THEN] A valid payment term date formula will be generated. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(true, IsDateFormulaValid(DateFormulaText), 'The payment term date formula is invalid. ' + DateFormulaText); + Assert.AreEqual('', DateFormulaText, 'The payment term date formula is incorrect for DueType Date, DUEDTDS = 30.'); + end; + + [Test] + procedure TestCalculateDueDateFormulaDueTypeEOM() + var + GPPaymentTerms: Record "GP Payment Terms"; + DateFormulaText: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term is configured for EOM + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::EOM; + + // [WHEN] DUEDTDS < 1 + GPPaymentTerms.DUEDTDS := 0; + + // [THEN] The date formula string will have a correct value. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(true, IsDateFormulaValid(DateFormulaText), 'The payment term date formula is invalid. ' + DateFormulaText); + Assert.AreEqual('', DateFormulaText, 'The payment term date formula should be correct for DueType EOM, DUEDTDS < 1.'); + + // [WHEN] DUEDTDS > 0 + GPPaymentTerms.DUEDTDS := 2; + + // [THEN] A valid payment term date formula will be generated. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(true, IsDateFormulaValid(DateFormulaText), 'The payment term date formula is invalid. ' + DateFormulaText); + Assert.AreEqual('', DateFormulaText, 'The payment term date formula is incorrect for DueType EOM, DUEDTDS = 2.'); + end; + + [Test] + procedure TestCalculateDueDateFormulaDueTypeNone() + var + GPPaymentTerms: Record "GP Payment Terms"; + DateFormulaText: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term is configured for None + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::None; + + // [WHEN] CalculateDateFromDays < 1 + GPPaymentTerms.CalculateDateFromDays := 0; + + // [THEN] The date formula string will have a correct value. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(true, IsDateFormulaValid(DateFormulaText), 'The payment term date formula is invalid. ' + DateFormulaText); + Assert.AreEqual('<0D>', DateFormulaText, 'The payment term date formula should be correct for DueType None, CalculateDateFromDays < 1.'); + + // [WHEN] CalculateDateFromDays > 0 + GPPaymentTerms.CalculateDateFromDays := 2; + + // [THEN] A valid payment term date formula will be generated. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(true, IsDateFormulaValid(DateFormulaText), 'The payment term date formula is invalid. ' + DateFormulaText); + Assert.AreEqual('<2D>', DateFormulaText, 'The payment term date formula is incorrect for DueType None, CalculateDateFromDays = 2.'); + end; + + [Test] + procedure TestCalculateDueDateFormulaDueTypeNextMonth() + var + GPPaymentTerms: Record "GP Payment Terms"; + DateFormulaText: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term is configured for Next Month + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Next Month"; + + // [WHEN] DUEDTDS < 1 + GPPaymentTerms.DUEDTDS := 0; + + // [THEN] The date formula string will have a correct value. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(true, IsDateFormulaValid(DateFormulaText), 'The payment term date formula is invalid. ' + DateFormulaText); + Assert.AreEqual('<-CM+1M+0D>', DateFormulaText, 'The payment term date formula should be correct for DueType Next Month, DUEDTDS < 1.'); + + // [WHEN] DUEDTDS > 0 + GPPaymentTerms.DUEDTDS := 16; + + // [THEN] A valid payment term date formula will be generated. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(true, IsDateFormulaValid(DateFormulaText), 'The payment term date formula is invalid. ' + DateFormulaText); + Assert.AreEqual('<-CM+1M+15D>', DateFormulaText, 'The payment term date formula is incorrect for DueType Next Month, DUEDTDS = 16.'); + end; + + [Test] + procedure TestCalculateDueDateFormulaDueTypeMonths() + var + GPPaymentTerms: Record "GP Payment Terms"; + DateFormulaText: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term is configured for Months + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Months; + + // [WHEN] DUEDTDS < 1 + GPPaymentTerms.DUEDTDS := 0; + + // [THEN] The date formula string will have a correct value. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(true, IsDateFormulaValid(DateFormulaText), 'The payment term date formula is invalid. ' + DateFormulaText); + Assert.AreEqual('<0M+0D>', DateFormulaText, 'The payment term date formula should be correct for DueType Months, DUEDTDS < 1.'); + + // [WHEN] DUEDTDS > 0 + GPPaymentTerms.DUEDTDS := 1; + + // [THEN] A valid payment term date formula will be generated. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(true, IsDateFormulaValid(DateFormulaText), 'The payment term date formula is invalid. ' + DateFormulaText); + Assert.AreEqual('<1M+0D>', DateFormulaText, 'The payment term date formula is incorrect for DueType Months, DUEDTDS = 1.'); + end; + + [Test] + procedure TestCalculateDueDateFormulaDueTypeMonthDay() + var + GPPaymentTerms: Record "GP Payment Terms"; + DateFormulaText: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term is configured for Month/Day + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Month/Day"; + + // [WHEN] DueMonth and DUEDTDS < 1 + GPPaymentTerms.DueMonth := 0; + GPPaymentTerms.DUEDTDS := 0; + + // [THEN] The date formula string will have a correct value. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(false, IsDateFormulaValid(DateFormulaText), 'The payment term date formula should have been invalid. ' + DateFormulaText); + Assert.AreEqual('', DateFormulaText, 'The payment term date formula should be correct for DueType Month/Day, DUEDTDS < 1.'); + + // [WHEN] DueMonth and DUEDTDS > 0 + GPPaymentTerms.DueMonth := 1; + GPPaymentTerms.DUEDTDS := 1; + + // [THEN] A valid payment term date formula will be generated. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(true, IsDateFormulaValid(DateFormulaText), 'The payment term date formula is invalid. ' + DateFormulaText); + Assert.AreEqual('', DateFormulaText, 'The payment term date formula is incorrect for DueType Month/Day, DueMonth = 1, DUEDTDS = 1.'); + end; + + [Test] + procedure TestCalculateDueDateFormulaDueTypeAnnual() + var + GPPaymentTerms: Record "GP Payment Terms"; + DateFormulaText: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term is configured for Annual + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Annual; + + // [WHEN] CalculateDateFromDays and DUEDTDS < 1 + GPPaymentTerms.CalculateDateFromDays := 0; + GPPaymentTerms.DUEDTDS := 0; + + // [THEN] The date formula string will have a correct value. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(true, IsDateFormulaValid(DateFormulaText), 'The payment term date formula is invalid. ' + DateFormulaText); + Assert.AreEqual('<0Y+0D>', DateFormulaText, 'The payment term date formula should be correct for DueType Annual, DUEDTDS < 1.'); + + // [WHEN] CalculateDateFromDays and DUEDTDS > 0 + GPPaymentTerms.CalculateDateFromDays := 15; + GPPaymentTerms.DUEDTDS := 1; + + // [THEN] A valid payment term date formula will be generated. + DateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, false, ''); + Assert.AreEqual(true, IsDateFormulaValid(DateFormulaText), 'The payment term date formula is invalid. ' + DateFormulaText); + Assert.AreEqual('<1Y+15D>', DateFormulaText, 'The payment term date formula is incorrect for DueType Annual, CalculateDateFromDays = 15, DUEDTDS = 1.'); + end; + + [Test] + procedure TestCalculateDiscountDateFormulaDueTypeDays() + var + GPPaymentTerms: Record "GP Payment Terms"; + DiscountDateFormulaText: Text; + CombinedDateFormulaText: Text; + ExpectedDiscountDateFormulaMinusBrackets: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term discount is configured. + GPPaymentTerms.DISCTYPE := GPPaymentTerms.DISCTYPE::Days; + + // [WHEN] DISCDTDS < 1 + GPPaymentTerms.DISCDTDS := 0; + + // [THEN] The date formula string will be empty. + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual('', DiscountDateFormulaText, 'The payment term discount date formula should be empty.'); + + // [WHEN] DISCDTDS > 0 + GPPaymentTerms.DISCDTDS := 15; + + // [THEN] A valid payment term date formula will be generated. + ExpectedDiscountDateFormulaMinusBrackets := '15D'; + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>', DiscountDateFormulaText, 'The payment term discount date formula is incorrect.'); + + // [WHEN] Combined with Due Date calculation, the correct combined date formula text will be correct. + // [THEN] A valid payment term date formula will be generated. + + // Net Days + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Net Days"; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+30D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 1'); + + // Date + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Date; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+D30>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 2'); + + // EOM + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::EOM; + GPPaymentTerms.DUEDTDS := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+CM+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 3'); + + // None + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::None; + GPPaymentTerms.CalculateDateFromDays := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 4'); + + // Next Month + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Next Month"; + GPPaymentTerms.DUEDTDS := 16; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '-CM+1M+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 5'); + + // Months + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Months; + GPPaymentTerms.DUEDTDS := 1; + GPPaymentTerms.CalculateDateFromDays := 0; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+1M+0D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 6'); + + // Month/Day + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Month/Day"; + GPPaymentTerms.DueMonth := 1; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+M1+D1>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 7'); + + // Annual + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Annual; + GPPaymentTerms.CalculateDateFromDays := 15; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+1Y+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 8'); + end; + + [Test] + procedure TestCalculateDiscountDateFormulaDueTypeDate() + var + GPPaymentTerms: Record "GP Payment Terms"; + DiscountDateFormulaText: Text; + CombinedDateFormulaText: Text; + ExpectedDiscountDateFormulaMinusBrackets: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term discount is configured. + GPPaymentTerms.DISCTYPE := GPPaymentTerms.DISCTYPE::Date; + + // [WHEN] DISCDTDS < 1 + GPPaymentTerms.DISCDTDS := 0; + + // [THEN] The date formula string will be empty. + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual('', DiscountDateFormulaText, 'The payment term discount date formula should be empty.'); + + // [WHEN] DISCDTDS > 0 + GPPaymentTerms.DISCDTDS := 15; + + // [THEN] A valid payment term date formula will be generated. + ExpectedDiscountDateFormulaMinusBrackets := 'D15'; + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>', DiscountDateFormulaText, 'The payment term discount date formula is incorrect.'); + + // [WHEN] Combined with Due Date calculation, the correct combined date formula text will be correct. + // [THEN] A valid payment term date formula will be generated. + + // Net Days + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Net Days"; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+30D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 1'); + + // Date + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Date; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+D30>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 2'); + + // EOM + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::EOM; + GPPaymentTerms.DUEDTDS := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+CM+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 3'); + + // None + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::None; + GPPaymentTerms.CalculateDateFromDays := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 4'); + + // Next Month + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Next Month"; + GPPaymentTerms.DUEDTDS := 16; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '-CM+1M+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 5'); + + // Months + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Months; + GPPaymentTerms.DUEDTDS := 1; + GPPaymentTerms.CalculateDateFromDays := 0; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+1M+0D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 6'); + + // Month/Day + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Month/Day"; + GPPaymentTerms.DueMonth := 1; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+M1+D1>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 7'); + + // Annual + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Annual; + GPPaymentTerms.CalculateDateFromDays := 15; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+1Y+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 8'); + end; + + [Test] + procedure TestCalculateDiscountDateFormulaDueTypeEOM() + var + GPPaymentTerms: Record "GP Payment Terms"; + DiscountDateFormulaText: Text; + CombinedDateFormulaText: Text; + ExpectedDiscountDateFormulaMinusBrackets: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term discount is configured. + GPPaymentTerms.DISCTYPE := GPPaymentTerms.DISCTYPE::EOM; + + // [WHEN] DISCDTDS < 1 + GPPaymentTerms.DISCDTDS := 0; + + // [THEN] The date formula string will be correct. + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('', DiscountDateFormulaText, 'The payment term discount date formula is not correct.'); + + // [WHEN] DISCDTDS > 0 + GPPaymentTerms.DISCDTDS := 2; + + // [THEN] A valid date formula will be generated. + ExpectedDiscountDateFormulaMinusBrackets := 'CM+2D'; + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>', DiscountDateFormulaText, 'The payment term discount date formula is incorrect.'); + + // [WHEN] Combined with Due Date calculation, the correct combined date formula text will be correct. + // [THEN] A valid payment term date formula will be generated. + + // Net Days + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Net Days"; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+30D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 1'); + + // Date + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Date; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+D30>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 2'); + + // EOM + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::EOM; + GPPaymentTerms.DUEDTDS := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+CM+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 3'); + + // None + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::None; + GPPaymentTerms.CalculateDateFromDays := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 4'); + + // Next Month + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Next Month"; + GPPaymentTerms.DUEDTDS := 16; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '-CM+1M+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 5'); + + // Months + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Months; + GPPaymentTerms.DUEDTDS := 1; + GPPaymentTerms.CalculateDateFromDays := 0; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+1M+0D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 6'); + + // Month/Day + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Month/Day"; + GPPaymentTerms.DueMonth := 1; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+M1+D1>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 7'); + + // Annual + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Annual; + GPPaymentTerms.CalculateDateFromDays := 15; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+1Y+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 8'); + end; + + [Test] + procedure TestCalculateDiscountDateFormulaDueTypeNone() + var + GPPaymentTerms: Record "GP Payment Terms"; + DiscountDateFormulaText: Text; + CombinedDateFormulaText: Text; + ExpectedDiscountDateFormulaMinusBrackets: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term discount is configured. + GPPaymentTerms.DISCTYPE := GPPaymentTerms.DISCTYPE::None; + + // [WHEN] CalculateDateFromDays < 1 + GPPaymentTerms.CalculateDateFromDays := -1; + + // [THEN] The date formula string will be empty. + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('<+0D>', DiscountDateFormulaText, 'The payment term discount date formula is not correct.'); + + // [WHEN] CalculateDateFromDays > 0 + GPPaymentTerms.CalculateDateFromDays := 2; + + // [THEN] The date formula string will be empty. + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('<+2D>', DiscountDateFormulaText, 'The payment term discount date formula is not correct.'); + + // [THEN] A valid date formula will be generated. + ExpectedDiscountDateFormulaMinusBrackets := '+2D'; + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>', DiscountDateFormulaText, 'The payment term discount date formula is incorrect.'); + + // [WHEN] Combined with Due Date calculation, the correct combined date formula text will be correct. + // [THEN] A valid payment term date formula will be generated. + + // Net Days + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Net Days"; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+32D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 1'); + + // Date + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Date; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+D30>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 2'); + + // EOM + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::EOM; + GPPaymentTerms.DUEDTDS := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+CM+4D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 3'); + + // None + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::None; + GPPaymentTerms.CalculateDateFromDays := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 4'); + + // Next Month + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Next Month"; + GPPaymentTerms.DUEDTDS := 16; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '-CM+1M+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 5'); + + // Months + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Months; + GPPaymentTerms.DUEDTDS := 1; + GPPaymentTerms.CalculateDateFromDays := 0; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+1M+0D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 6'); + + // Month/Day + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Month/Day"; + GPPaymentTerms.DueMonth := 1; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+M1+D1>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 7'); + + // Annual + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Annual; + GPPaymentTerms.CalculateDateFromDays := 15; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+1Y+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 8'); + end; + + [Test] + procedure TestCalculateDiscountDateFormulaDueTypeNextMonth() + var + GPPaymentTerms: Record "GP Payment Terms"; + DiscountDateFormulaText: Text; + CombinedDateFormulaText: Text; + ExpectedDiscountDateFormulaMinusBrackets: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term discount is configured. + GPPaymentTerms.DISCTYPE := GPPaymentTerms.DISCTYPE::"Next Month"; + + // [WHEN] DISCDTDS < 1 + GPPaymentTerms.DISCDTDS := 0; + + // [THEN] The date formula string will be correct. + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('<-CM+1M+0D>;', DiscountDateFormulaText, 'The payment term discount date formula is not correct.'); + + // [WHEN] DISCDTDS > 0 + GPPaymentTerms.DISCDTDS := 3; + + // [THEN] A valid date formula will be generated. + ExpectedDiscountDateFormulaMinusBrackets := '-CM+1M+2D'; + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>;', DiscountDateFormulaText, 'The payment term discount date formula is incorrect.'); + + // [WHEN] Combined with Due Date calculation, the correct combined date formula text will be correct. + // [THEN] A valid payment term date formula will be generated. + + // Net Days + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Net Days"; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+30D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 1'); + + // Date + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Date; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+D30>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 2'); + + // EOM + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::EOM; + GPPaymentTerms.DUEDTDS := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+CM+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 3'); + + // None + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::None; + GPPaymentTerms.CalculateDateFromDays := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 4'); + + // Next Month + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Next Month"; + GPPaymentTerms.DUEDTDS := 16; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>-CM+1M+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 5'); + + // Months + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Months; + GPPaymentTerms.DUEDTDS := 1; + GPPaymentTerms.CalculateDateFromDays := 0; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+1M+0D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 6'); + + // Month/Day + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Month/Day"; + GPPaymentTerms.DueMonth := 1; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+M1+D1>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 7'); + + // Annual + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Annual; + GPPaymentTerms.CalculateDateFromDays := 15; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+1Y+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 8'); + end; + + [Test] + procedure TestCalculateDiscountDateFormulaDueTypeMonths() + var + GPPaymentTerms: Record "GP Payment Terms"; + DiscountDateFormulaText: Text; + CombinedDateFormulaText: Text; + ExpectedDiscountDateFormulaMinusBrackets: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term discount is configured. + GPPaymentTerms.DISCTYPE := GPPaymentTerms.DISCTYPE::Months; + + // [WHEN] CalculateDateFromDays and DISCDTDS < 1 + GPPaymentTerms.CalculateDateFromDays := 0; + GPPaymentTerms.DISCDTDS := 0; + + // [THEN] The date formula string will be correct. + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('<0M+0D>;', DiscountDateFormulaText, 'The payment term discount date formula is not correct.'); + + // [WHEN] DISCDTDS > 0 + GPPaymentTerms.DISCDTDS := 1; + + // [THEN] A valid date formula will be generated. + ExpectedDiscountDateFormulaMinusBrackets := '1M+0D'; + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>;', DiscountDateFormulaText, 'The payment term discount date formula is incorrect.'); + + // [WHEN] Combined with Due Date calculation, the correct combined date formula text will be correct. + // [THEN] A valid payment term date formula will be generated. + + // Net Days + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Net Days"; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+30D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 1'); + + // Date + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Date; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+D30>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 2'); + + // EOM + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::EOM; + GPPaymentTerms.DUEDTDS := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+CM+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 3'); + + // None + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::None; + GPPaymentTerms.CalculateDateFromDays := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 4'); + + // Next Month + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Next Month"; + GPPaymentTerms.DUEDTDS := 16; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>-CM+1M+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 5'); + + // Months + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Months; + GPPaymentTerms.DUEDTDS := 1; + GPPaymentTerms.CalculateDateFromDays := 0; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+1M+0D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 6'); + + // Month/Day + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Month/Day"; + GPPaymentTerms.DueMonth := 1; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+M1+D1>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 7'); + + // Annual + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Annual; + GPPaymentTerms.CalculateDateFromDays := 15; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+1Y+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 8'); + end; + + [Test] + procedure TestCalculateDiscountDateFormulaDueTypeMonthDay() + var + GPPaymentTerms: Record "GP Payment Terms"; + DiscountDateFormulaText: Text; + CombinedDateFormulaText: Text; + ExpectedDiscountDateFormulaMinusBrackets: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term discount is configured. + GPPaymentTerms.DISCTYPE := GPPaymentTerms.DISCTYPE::"Month/Day"; + + // [WHEN] DiscountMonth and DISCDTDS > 1 + GPPaymentTerms.DiscountMonth := 2; + GPPaymentTerms.DISCDTDS := 1; + + // [THEN] A valid date formula will be generated. + ExpectedDiscountDateFormulaMinusBrackets := 'M2+D1'; + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>', DiscountDateFormulaText, 'The payment term discount date formula is incorrect.'); + + // [WHEN] Combined with Due Date calculation, the correct combined date formula text will be correct. + // [THEN] A valid payment term date formula will be generated. + + // Net Days + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Net Days"; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+30D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 1'); + + // Date + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Date; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+D30>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 2'); + + // EOM + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::EOM; + GPPaymentTerms.DUEDTDS := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+CM+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 3'); + + // None + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::None; + GPPaymentTerms.CalculateDateFromDays := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 4'); + + // Next Month + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Next Month"; + GPPaymentTerms.DUEDTDS := 16; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '-CM+1M+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 5'); + + // Months + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Months; + GPPaymentTerms.DUEDTDS := 1; + GPPaymentTerms.CalculateDateFromDays := 0; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+1M+0D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 6'); + + // Month/Day + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Month/Day"; + GPPaymentTerms.DueMonth := 1; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+M1+D1>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 7'); + + // Annual + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Annual; + GPPaymentTerms.CalculateDateFromDays := 15; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '+1Y+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 8'); + end; + + [Test] + procedure TestCalculateDiscountDateFormulaDueTypeAnnual() + var + GPPaymentTerms: Record "GP Payment Terms"; + DiscountDateFormulaText: Text; + CombinedDateFormulaText: Text; + ExpectedDiscountDateFormulaMinusBrackets: Text; + begin + // [SCENARIO] GP Payment Terms staging table is populated. + // [GIVEN] Payment term date formula calculations are to be performed. + + // [WHEN] The payment term discount is configured. + GPPaymentTerms.DISCTYPE := GPPaymentTerms.DISCTYPE::Annual; + + // [WHEN] DISCDTDS < 1 + GPPaymentTerms.DISCDTDS := -1; + + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('<0Y+0D>;', DiscountDateFormulaText, 'The payment term discount date formula is incorrect.'); + + // [WHEN] DISCDTDS > 0 + GPPaymentTerms.DISCDTDS := 1; + + // [THEN] A valid date formula will be generated. + ExpectedDiscountDateFormulaMinusBrackets := '1Y+0D'; + DiscountDateFormulaText := HelperFunctions.CalculateDiscountDateFormula(GPPaymentTerms); + Assert.AreEqual(true, IsDateFormulaValid(DiscountDateFormulaText), 'The payment term discount date formula is invalid. ' + DiscountDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>;', DiscountDateFormulaText, 'The payment term discount date formula is incorrect.'); + + // [WHEN] Combined with Due Date calculation, the correct combined date formula text will be correct. + // [THEN] A valid payment term date formula will be generated. + + // Net Days + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Net Days"; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+30D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 1'); + + // Date + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Date; + GPPaymentTerms.DUEDTDS := 30; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+D30>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 2'); + + // EOM + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::EOM; + GPPaymentTerms.DUEDTDS := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+CM+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 3'); + + // None + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::None; + GPPaymentTerms.CalculateDateFromDays := 2; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+2D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 4'); + + // Next Month + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Next Month"; + GPPaymentTerms.DUEDTDS := 16; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>-CM+1M+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 5'); + + // Months + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Months; + GPPaymentTerms.DUEDTDS := 1; + GPPaymentTerms.CalculateDateFromDays := 0; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+1M+0D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 6'); + + // Month/Day + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::"Month/Day"; + GPPaymentTerms.DueMonth := 1; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+M1+D1>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 7'); + + // Annual + GPPaymentTerms.DUETYPE := GPPaymentTerms.DUETYPE::Annual; + GPPaymentTerms.CalculateDateFromDays := 15; + GPPaymentTerms.DUEDTDS := 1; + CombinedDateFormulaText := HelperFunctions.CalculateDueDateFormula(GPPaymentTerms, true, CopyStr(DiscountDateFormulaText, 1, 32)); + Assert.AreEqual(true, IsDateFormulaValid(CombinedDateFormulaText), 'The combined payment term date formula is invalid. ' + CombinedDateFormulaText); + Assert.AreEqual('<' + ExpectedDiscountDateFormulaMinusBrackets + '>+1Y+15D>', CombinedDateFormulaText, 'The combined payment term date formula is incorrect. 8'); + end; + local procedure CreateGPPaymentTermsRecords() var GPPaymentTerms: Record "GP Payment Terms";