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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ table 8002 "Planned Subscription Line"
if Format("Extension Term") = '' then
TestField("Notice Period", "Extension Term");
DateFormulaManagement.ErrorIfDateFormulaNegative("Extension Term");
CheckRatioBetweenBillingBasePeriodAndRhythm();
end;
}
field(23; "Billing Rhythm"; DateFormula)
Expand All @@ -206,6 +207,7 @@ table 8002 "Planned Subscription Line"
begin
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Rhythm");
CheckRatioBetweenBillingBasePeriodAndRhythm();
end;
}
field(24; "Cancellation Possible Until"; Date)
Expand Down Expand Up @@ -397,12 +399,6 @@ table 8002 "Planned Subscription Line"
key(Contract; "Subscription Contract No.", "Subscription Contract Line No.") { }
key(Quote; "Sales Quote No.", "Sales Quote Line No.") { }
}
trigger OnModify()
begin
xRec.Get(xRec."Entry No.");
if ((xRec."Billing Base Period" <> Rec."Billing Base Period") or (xRec."Billing Rhythm" <> Rec."Billing Rhythm")) then
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
end;

local procedure CheckServiceDates()
begin
Expand Down Expand Up @@ -437,6 +433,13 @@ table 8002 "Planned Subscription Line"
Validate(Price, 0);
end;

local procedure CheckRatioBetweenBillingBasePeriodAndRhythm()
var
begin
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
end;

var
Currency: Record Currency;
CurrExchRate: Record "Currency Exchange Rate";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ table 8068 "Sales Subscription Line"
trigger OnValidate()
begin
TestIfSalesOrderIsReleased();
DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Initial Term");
DateFormulaManagement.ErrorIfDateFormulaNegative("Initial Term");
end;
}
field(24; "Notice Period"; DateFormula)
Expand All @@ -190,7 +190,7 @@ table 8068 "Sales Subscription Line"
trigger OnValidate()
begin
TestIfSalesOrderIsReleased();
DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Notice Period");
DateFormulaManagement.ErrorIfDateFormulaNegative("Notice Period");
end;
}
field(25; "Extension Term"; DateFormula)
Expand All @@ -201,7 +201,7 @@ table 8068 "Sales Subscription Line"
TestIfSalesOrderIsReleased();
if Format("Extension Term") = '' then
TestField("Notice Period", "Extension Term");
DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Extension Term");
DateFormulaManagement.ErrorIfDateFormulaNegative("Extension Term");
end;
}
field(26; "Billing Base Period"; DateFormula)
Expand All @@ -212,8 +212,9 @@ table 8068 "Sales Subscription Line"
trigger OnValidate()
begin
TestIfSalesOrderIsReleased();
DateFormulaManagementGlobal.ErrorIfDateFormulaEmpty("Billing Base Period", FieldCaption("Billing Base Period"));
DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Billing Base Period");
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Base Period", FieldCaption("Billing Base Period"));
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Base Period");
CheckRatioBetweenBillingBasePeriodAndRhythm();
end;
}
field(27; "Billing Rhythm"; DateFormula)
Expand All @@ -224,8 +225,9 @@ table 8068 "Sales Subscription Line"
trigger OnValidate()
begin
TestIfSalesOrderIsReleased();
DateFormulaManagementGlobal.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
DateFormulaManagementGlobal.ErrorIfDateFormulaNegative("Billing Rhythm");
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Rhythm");
CheckRatioBetweenBillingBasePeriodAndRhythm();
end;
}
field(28; "Invoicing via"; Enum "Invoicing Via")
Expand Down Expand Up @@ -393,9 +395,6 @@ table 8068 "Sales Subscription Line"
trigger OnModify()
begin
TestIfSalesOrderIsReleased();
xRec.Get(xRec."Line No.");
if ((xRec."Billing Base Period" <> Rec."Billing Base Period") or (xRec."Billing Rhythm" <> Rec."Billing Rhythm")) then
DateFormulaManagementGlobal.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
end;

trigger OnDelete()
Expand Down Expand Up @@ -688,7 +687,6 @@ table 8068 "Sales Subscription Line"
var
SalesLineVAT: Record "Sales Line";
ContractRenewalMgt: Codeunit "Sub. Contract Renewal Mgt.";
DateFormulaManagement: Codeunit "Date Formula Management";
IsHandled: Boolean;
RhythmIdentifier: Code[20];
ContractRenewalPriceCalculationRatio: Decimal;
Expand Down Expand Up @@ -842,6 +840,13 @@ table 8068 "Sales Subscription Line"
SalesLine := NewSalesLine;
end;

local procedure CheckRatioBetweenBillingBasePeriodAndRhythm()
var
begin
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
end;

[IntegrationEvent(false, false)]
local procedure OnCalculateBaseTypeElseCaseOnCalculateCalculationBaseAmountCustomer(SalesSubscriptionLine: Record "Sales Subscription Line"; SalesLine: Record "Sales Line"; var CalculatedBaseAmount: Decimal; var IsHandled: Boolean)
begin
Expand Down Expand Up @@ -876,7 +881,7 @@ table 8068 "Sales Subscription Line"
Currency: Record Currency;
CurrExchRate: Record "Currency Exchange Rate";
SalesLine: Record "Sales Line";
DateFormulaManagementGlobal: Codeunit "Date Formula Management";
DateFormulaManagement: Codeunit "Date Formula Management";
ServiceAmountIncreaseErr: Label '%1 cannot be greater than %2.', Comment = '%1 and %2 are numbers';
ReleasedSalesOrderExistsErr: Label 'Subscription Lines cannot be edited on orders with status = Released.';
CalculateBaseTypeOptionNotImplementedErr: Label 'Unknown option %1 for %2.\\ Object Name: %3, Procedure: %4', Comment = '%1=Format("Calculation Base Type"), %2 = Fieldcaption for "Calculation Base Type", %3 = Current object name, %4 = Current procedure name';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ table 8059 "Subscription Line"
begin
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Base Period", FieldCaption("Billing Base Period"));
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Base Period");
CheckRatioBetweenBillingBasePeriodAndRhythm();
end;
}
field(16; "Invoicing via"; Enum "Invoicing Via")
Expand Down Expand Up @@ -254,6 +255,7 @@ table 8059 "Subscription Line"
begin
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Rhythm");
CheckRatioBetweenBillingBasePeriodAndRhythm();
end;
}
field(24; "Cancellation Possible Until"; Date)
Expand Down Expand Up @@ -595,9 +597,6 @@ table 8059 "Subscription Line"

trigger OnModify()
begin
xRec.Get(xRec."Entry No.");
if ((xRec."Billing Base Period" <> Rec."Billing Base Period") or (xRec."Billing Rhythm" <> Rec."Billing Rhythm")) then
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
DisplayErrorIfContractLinesExist(ClosedContractLineExistErr, true);
SetUpdateRequiredOnBillingLines();
UpdateCustomerContractLineServiceCommitmentDescription();
Expand Down Expand Up @@ -1925,6 +1924,13 @@ table 8059 "Subscription Line"
end;
end;

local procedure CheckRatioBetweenBillingBasePeriodAndRhythm()
var
begin
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
end;

[IntegrationEvent(false, false)]
local procedure OnAfterUpdateNextBillingDate(var SubscriptionLine: Record "Subscription Line"; LastBillingToDate: Date)
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ table 8056 "Subscription Package Line"
trigger OnValidate()
begin
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Base Period");
CheckRatioBetweenBillingBasePeriodAndRhythm();
end;
}
field(11; "Billing Rhythm"; DateFormula)
Expand All @@ -117,6 +118,7 @@ table 8056 "Subscription Package Line"
begin
DateFormulaManagement.ErrorIfDateFormulaEmpty("Billing Rhythm", FieldCaption("Billing Rhythm"));
DateFormulaManagement.ErrorIfDateFormulaNegative("Billing Rhythm");
CheckRatioBetweenBillingBasePeriodAndRhythm();
end;
}
field(12; "Sub. Line Start Formula"; DateFormula)
Expand Down Expand Up @@ -221,12 +223,6 @@ table 8056 "Subscription Package Line"
Clustered = true;
}
}
trigger OnModify()
begin
xRec.Get(xRec."Subscription Package Code", xRec."Line No.");
if ((xRec."Billing Base Period" <> Rec."Billing Base Period") or (xRec."Billing Rhythm" <> Rec."Billing Rhythm")) then
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
end;

var
DateFormulaManagement: Codeunit "Date Formula Management";
Expand Down Expand Up @@ -303,4 +299,11 @@ table 8056 "Subscription Package Line"
begin
exit(Rec.Partner = Rec.Partner::Vendor);
end;

local procedure CheckRatioBetweenBillingBasePeriodAndRhythm()
var
begin
if (Format("Billing Base Period") <> '') and (Format("Billing Rhythm") <> '') then
DateFormulaManagement.CheckIntegerRatioForDateFormulas("Billing Base Period", FieldCaption("Billing Base Period"), "Billing Rhythm", FieldCaption("Billing Rhythm"));
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,6 @@ codeunit 139685 "Contract Test Library"
Clear(ServiceCommitment."Billing Base Period");
Clear(ServiceCommitment."Billing Rhythm");
Evaluate(ServiceCommitment."Billing Base Period", BillingBasePeriodText);
ServiceCommitment.Validate("Billing Base Period");
Evaluate(ServiceCommitment."Billing Rhythm", BillingRhythmText);
ServiceCommitment.Validate("Billing Rhythm");
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ codeunit 139915 "Sales Service Commitment Test"
NoOfServiceObjects: Integer;
NotCreatedProperlyErr: Label 'Subscription Lines are not created properly.';
SalesServiceCommitmentCannotBeDeletedErr: Label 'The Sales Subscription Line cannot be deleted, because it is the last line with Process Contract Renewal. Please delete the Sales line in order to delete the Sales Subscription Line.', Locked = true;
NaturalNumberRatioErr: Label 'The ratio of ''%1'' and ''%2'' or vice versa must give a natural number.', Comment = '%1=Field Caption, %2=Field Caption';

#region Tests

Expand Down Expand Up @@ -1267,6 +1268,38 @@ codeunit 139915 "Sales Service Commitment Test"
LibrarySales.CreateSalesLine(SalesLine, SalesHeader, Enum::"Sales Line Type"::Item, Item."No.", LibraryRandom.RandIntInRange(1, 100));
end;

[Test]
procedure PreventInvalidDateFormulaRatioForSalesSubscriptionLine()
var
TwelveMonthsDateFormula: DateFormula;
FifteenMonthsDateFormula: DateFormula;
begin
// [SCENARIO] When a Sales Subscription Line has been created with a Billing Base Period and a Billing Rhythm that do not have a valid ratio, the error is thrown as soon as an invalid date formula is entered

// [GIVEN] When a Sales Subscription Line with Billing Base Period and Billing Rhythm equal to 12M has been created
Initialize();
Evaluate(TwelveMonthsDateFormula, '<12M>');
ServiceCommPackageLine.Validate("Billing Base Period", TwelveMonthsDateFormula);
ServiceCommPackageLine.Validate("Billing Rhythm", TwelveMonthsDateFormula);
ServiceCommPackageLine.Modify(false);
ContractTestLibrary.SetupSalesServiceCommitmentItemAndAssignToServiceCommitmentPackage(Item, Enum::"Item Service Commitment Type"::"Service Commitment Item", ServiceCommitmentPackage.Code);
LibrarySales.CreateSalesHeader(SalesHeader, SalesHeader."Document Type"::Quote, '');
LibrarySales.CreateSalesLine(SalesLine, SalesHeader, Enum::"Sales Line Type"::Item, Item."No.", LibraryRandom.RandIntInRange(1, 100));

Commit(); // retain data after asserterror

// [WHEN] An invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm
Evaluate(FifteenMonthsDateFormula, '<15M>');

// [THEN] Error expected when invalid date formula is entered for Billing Base Period or Billing Rhythm
SalesServiceCommitment.FilterOnSalesLine(SalesLine);
SalesServiceCommitment.FindFirst();
asserterror SalesServiceCommitment.Validate("Billing Base Period", FifteenMonthsDateFormula);
Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, SalesServiceCommitment.FieldCaption("Billing Base Period"), SalesServiceCommitment.FieldCaption("Billing Rhythm")));
asserterror SalesServiceCommitment.Validate("Billing Rhythm", FifteenMonthsDateFormula);
Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, SalesServiceCommitment.FieldCaption("Billing Base Period"), SalesServiceCommitment.FieldCaption("Billing Rhythm")));
end;

[Test]
procedure RunNormalSalesServiceCommitmentDeletion()
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ codeunit 148156 "Service Commitment Test"
LibrarySales: Codeunit "Library - Sales";
LibraryTestInitialize: Codeunit "Library - Test Initialize";
PackageLineMissingInvoicingItemNoErr: Label 'The %1 %2 can not be used with Item %3, because at least one of the Service Commitment Package lines is missing an %4.', Locked = true;
NaturalNumberRatioErr: Label 'The ratio of ''%1'' and ''%2'' or vice versa must give a natural number.', Comment = '%1=Field Caption, %2=Field Caption';

#region Tests

Expand Down Expand Up @@ -308,6 +309,54 @@ codeunit 148156 "Service Commitment Test"
asserterror ServiceCommitment.Modify(true);
end;

[Test]
procedure PreventInvalidDateFormulaRatioForSubscriptionLine()
var
FifteenMonthsDateFormula: DateFormula;
begin
// [SCENARIO] When a Subscription Line has been created with a Billing Base Period and a Billing Rhythm that do not have a valid ratio, the error is thrown as soon as an invalid date formula is entered

// [GIVEN] A single Subscription Line with Billing Base Period and Billing Rhythm equal to 12M has been created
Initialize();
ContractTestLibrary.CreateServiceObjectForItemWithServiceCommitments(ServiceObject, Enum::"Invoicing Via"::Contract, false, Item, 1, 0, '<12M>', '<12M>');

Commit(); // retain data after asserterror

// [WHEN] An invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm
Evaluate(FifteenMonthsDateFormula, '<15M>');

// [THEN] Error expected when invalid date formula is entered for Billing Base Period or Billing Rhythm
ServiceCommitment.SetRange("Subscription Header No.", ServiceObject."No.");
ServiceCommitment.FindFirst();
asserterror ServiceCommitment.Validate("Billing Base Period", FifteenMonthsDateFormula);
Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommitment.FieldCaption("Billing Base Period"), ServiceCommitment.FieldCaption("Billing Rhythm")));
asserterror ServiceCommitment.Validate("Billing Rhythm", FifteenMonthsDateFormula);
Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommitment.FieldCaption("Billing Base Period"), ServiceCommitment.FieldCaption("Billing Rhythm")));
end;

[Test]
procedure PreventInvalidDateFormulaRatioForSubscriptionPackageLine()
var
FifteenMonthsDateFormula: DateFormula;
begin
// [SCENARIO] When a Subscription Package Line has been created with a Billing Base Period and a Billing Rhythm that do not have a valid ratio, the error is thrown as soon as an invalid date formula is entered

// [GIVEN] A single Subscription Package Line with Billing Base Period and Billing Rhythm equal to 12M has been created
Initialize();
ContractTestLibrary.CreateServiceCommitmentPackageWithLine('', ServiceCommitmentPackage, ServiceCommPackageLine);
Commit(); // retain data after asserterror

// [WHEN] An invalid date formula is created for the purpose of validating Billing Base Period and Billing Rhythm
Evaluate(FifteenMonthsDateFormula, '<15M>');

// [THEN] Error expected when invalid date formula is entered for Billing Base Period or Billing Rhythm
asserterror ServiceCommPackageLine.Validate("Billing Base Period", FifteenMonthsDateFormula);
Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommPackageLine.FieldCaption("Billing Base Period"), ServiceCommPackageLine.FieldCaption("Billing Rhythm")));
asserterror ServiceCommPackageLine.Validate("Billing Rhythm", FifteenMonthsDateFormula);
Assert.ExpectedError(StrSubstNo(NaturalNumberRatioErr, ServiceCommPackageLine.FieldCaption("Billing Base Period"), ServiceCommPackageLine.FieldCaption("Billing Rhythm")));
end;


[Test]
[HandlerFunctions('ExchangeRateSelectionModalPageHandler,MessageHandler')]
procedure TestOverdueServiceCommitments()
Expand Down Expand Up @@ -463,14 +512,14 @@ codeunit 148156 "Service Commitment Test"

local procedure ValidateDateFormulaCombinations(DateFormulaText1: Text; DateFormulaText2: Text)
var
DateFormula1: DateFormula;
EvaluatedDateFormula: DateFormula;
begin
ServiceCommPackageLine.Get(ServiceCommPackageLine."Subscription Package Code", ServiceCommPackageLine."Line No.");
Evaluate(DateFormula1, DateFormulaText1);
ServiceCommPackageLine."Billing Base Period" := DateFormula1;
Evaluate(DateFormula1, DateFormulaText2);
ServiceCommPackageLine."Billing Rhythm" := DateFormula1;
ServiceCommPackageLine.Modify(true);
Evaluate(EvaluatedDateFormula, DateFormulaText1);
ServiceCommPackageLine."Billing Base Period" := EvaluatedDateFormula;
Evaluate(EvaluatedDateFormula, DateFormulaText2);
ServiceCommPackageLine.Validate("Billing Rhythm", EvaluatedDateFormula);
ServiceCommPackageLine.Modify(false);
end;

#endregion Procedures
Expand Down
Loading
Loading