Skip to content

Commit 4e1d2b6

Browse files
authored
[Subscription Billing]Calculating initial dates correctly (#6352)
<!-- Thank you for submitting a Pull Request. If you're new to contributing to BCApps please read our pull request guideline below * https://github.com/microsoft/BCApps/Contributing.md --> #### Summary <!-- Provide a general summary of your changes --> This PR addresses two reported issues in Subscription Billing related to incorrect or missing updates of subscription line dates (`Subscription Line End Date` / `Service End Date`, `Term Until`, and `Cancellation Possible Until`). #### Fixed Issues 1. **Initial subscription dates not calculated correctly when Subsequent/Extension Term is defined** When posting Ship and Invoice from a Sales Order containing a Subscription Item with both Initial Term and Subsequent Term filled, the `Subscription Line Start Date` updated correctly, but `Service End Date` and `Term Until` remained empty. The root cause was logic that skipped initial end-date calculations when a Subsequent/Extension Term existed. Changes introduce a new internal procedure `CalculateInitialSubscriptionDates()` in **Subscription Line** that always calculates both `Service End Date` (via `CalculateInitialServiceEndDate()`) and `Term Until` (via `CalculateInitialTermUntilDate()`). Calls in **Sales Documents**, **Create Subscription Line**, **Post Sub. Contract Renewal**, and **Subscription Header** now use this consolidated procedure, ensuring initial dates are set correctly regardless of Subsequent/Extension Term presence. 2. **Cancellation Possible Until and Term Until not recalculated when Service Start Date is modified** On non-invoiced subscription lines (e.g., after "Extend Contract" or manual edit), changing `Service Start Date` did not automatically update `Cancellation Possible Until` or `Term Until`. The "Update Subscription Line Dates" action also failed to update these fields. The refactor ensures consistent date recalculation: - `CalculateInitialTermUntilDate()` now prioritizes existing `Subscription Line End Date` when set and always updates `Cancellation Possible Until` via `UpdateCancellationPossibleUntil()`. - Consolidated initial date calculation improves reliability when start dates change before invoicing. #### Additional Improvements - Simplified and standardized the `Extension Term` tooltip across multiple pages (e.g., Service Commitments, Planned Service Commitments, Customer Contract Lines) by removing outdated references to conditional end-date setting, reflecting the new always-calculate-initial behavior. - Added propagation of `Renewal Term` to **Sub. Contr. Analysis Entry** for better data consistency in contract analysis. These changes improve reliability of automatic date calculations, reduce manual corrections, and align behavior with expected subscription lifecycle rules without affecting existing renewal logic for subsequent periods. Technical code review from @samra-singhammer or @sit-zm required prior to approval by Microsoft. #### Work Item(s) <!-- Add the issue number here after the #. The issue needs to be open and approved. Submitting PRs with no linked issues or unapproved issues is highly discouraged. --> Fixes #6132 [AB#620493](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/620493)
1 parent b4f4247 commit 4e1d2b6

24 files changed

Lines changed: 208 additions & 176 deletions

src/Apps/W1/Subscription Billing/App/Billing/Codeunits/SalesDocuments.Codeunit.al

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,7 @@ codeunit 8063 "Sales Documents"
542542
SubscriptionLine.Validate("Calculation Base Amount", SubscriptionLine."Calculation Base Amount" * -1);
543543

544544
SubscriptionLine.UpdateNextPriceUpdate();
545-
SubscriptionLine.CalculateInitialTermUntilDate();
546-
SubscriptionLine.CalculateInitialServiceEndDate();
547-
SubscriptionLine.CalculateInitialCancellationPossibleUntilDate();
545+
SubscriptionLine.CalculateSubscriptionDates();
548546
SubscriptionLine.SetCurrencyData(SalesHeader."Currency Factor", SalesHeader."Posting Date", SalesHeader."Currency Code");
549547
SubscriptionLine.SetLCYFields(true);
550548
if SalesLine."No." = SubscriptionLine."Invoicing Item No." then begin

src/Apps/W1/Subscription Billing/App/Contract Renewal/Codeunits/PostSubContractRenewal.Codeunit.al

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ codeunit 8004 "Post Sub. Contract Renewal"
107107
TempServiceCommitment."Subscription Line End Date" := CalcDate('<-1D>', TempServiceCommitment."Subscription Line End Date");
108108
end;
109109
TempServiceCommitment.CopyFromSalesServiceCommitment(SalesServiceCommitment);
110-
TempServiceCommitment.CalculateInitialTermUntilDate();
111-
TempServiceCommitment.CalculateInitialServiceEndDate();
112-
TempServiceCommitment.CalculateInitialCancellationPossibleUntilDate();
110+
TempServiceCommitment.CalculateSubscriptionDates();
113111
TempServiceCommitment.SetCurrencyData(SalesHeader."Currency Factor", SalesHeader."Posting Date", SalesHeader."Currency Code");
114112
TempServiceCommitment.SetLCYFields(true);
115113
TempServiceCommitment.SetDefaultDimensions(true);
@@ -274,7 +272,7 @@ codeunit 8004 "Post Sub. Contract Renewal"
274272
end;
275273

276274
/// <summary>
277-
/// Updates the existing subscription line from planned subscription line. It is used for subscription renewal.
275+
/// Updates the existing subscription line from planned subscription line. It is used for subscription renewal.
278276
/// </summary>
279277
/// <param name="PlannedServiceCommitment">Record "Planned Subscription Line".</param>
280278
procedure ProcessPlannedServiceCommitment(PlannedServiceCommitment: Record "Planned Subscription Line")

src/Apps/W1/Subscription Billing/App/Contract Renewal/Pages/PlannedServiceCommitments.Page.al

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ page 8004 "Planned Service Commitments"
182182
}
183183
field("Extension Term"; Rec."Extension Term")
184184
{
185-
ToolTip = 'Specifies a date formula for automatic renewal after initial term and the rhythm of the update of "Notice possible to" and "Term Until". If the field is empty and the initial term or notice period is filled, the end of Subscription Line is automatically set to the end of the initial term or notice period.';
185+
ToolTip = 'Specifies a date formula for automatic renewal after initial term and the rhythm of the update of "Notice possible to" and "Term Until".';
186186
}
187187
field("Cancellation Possible Until"; Rec."Cancellation Possible Until")
188188
{

src/Apps/W1/Subscription Billing/App/ContractAnalysis/ContractAnalysisEntries.Page.al

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ page 8090 "Contract Analysis Entries"
142142
}
143143
field("Extension Term"; Rec."Extension Term")
144144
{
145-
ToolTip = 'Specifies a date formula for automatic renewal after initial term and the rhythm of the update of "Notice possible to" and "Term Until". If the field is empty and the initial term or notice period is filled, the end of Subscription Line is automatically set to the end of the initial term or notice period.';
145+
ToolTip = 'Specifies a date formula for automatic renewal after initial term and the rhythm of the update of "Notice possible to" and "Term Until".';
146146
}
147147
field("Billing Rhythm"; Rec."Billing Rhythm")
148148
{

src/Apps/W1/Subscription Billing/App/ContractAnalysis/SubContrAnalysisEntry.Table.al

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ table 8019 "Sub. Contr. Analysis Entry"
341341
Rec."Currency Factor Date" := ServiceCommitment."Currency Factor Date";
342342
Rec."Extension Term" := ServiceCommitment."Extension Term";
343343
Rec."Initial Term" := ServiceCommitment."Initial Term";
344+
Rec."Renewal Term" := ServiceCommitment."Renewal Term";
344345
Rec."Invoicing Item No." := ServiceCommitment."Invoicing Item No.";
345346
Rec."Next Billing Date" := ServiceCommitment."Next Billing Date";
346347
Rec."Notice Period" := ServiceCommitment."Notice Period";

src/Apps/W1/Subscription Billing/App/Customer Contracts/Pages/ClosedCustContLineSubp.Page.al

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ page 8080 "Closed Cust. Cont. Line Subp."
239239
field("Extension Term"; ServiceCommitment."Extension Term")
240240
{
241241
Caption = 'Subsequent Term';
242-
ToolTip = 'Specifies a date formula for automatic renewal after initial term and the rhythm of the update of "Notice possible to" and "Term Until". If the field is empty and the initial term or notice period is filled, the end of Subscription Line is automatically set to the end of the initial term or notice period.';
242+
ToolTip = 'Specifies a date formula for automatic renewal after initial term and the rhythm of the update of "Notice possible to" and "Term Until".';
243243
Editable = false;
244244
Visible = false;
245245
}

src/Apps/W1/Subscription Billing/App/Customer Contracts/Pages/CustomerContractLineSubp.Page.al

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ page 8068 "Customer Contract Line Subp."
386386
field("Extension Term"; ServiceCommitment."Extension Term")
387387
{
388388
Caption = 'Subsequent Term';
389-
ToolTip = 'Specifies a date formula for automatic renewal after initial term and the rhythm of the update of "Notice possible to" and "Term Until". If the field is empty and the initial term or notice period is filled, the end of Subscription Line is automatically set to the end of the initial term or notice period.';
389+
ToolTip = 'Specifies a date formula for automatic renewal after initial term and the rhythm of the update of "Notice possible to" and "Term Until".';
390390
Editable = false;
391391
Visible = false;
392392
}

src/Apps/W1/Subscription Billing/App/Customer Contracts/Pages/CustomerContractLines.Page.al

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ page 8075 "Customer Contract Lines"
182182
field("Extension Term"; ServiceCommitment."Extension Term")
183183
{
184184
Caption = 'Subsequent Term';
185-
ToolTip = 'Specifies a date formula for automatic renewal after initial term and the rhythm of the update of "Notice possible to" and "Term Until". If the field is empty and the initial term or notice period is filled, the end of Subscription Line is automatically set to the end of the initial term or notice period.';
185+
ToolTip = 'Specifies a date formula for automatic renewal after initial term and the rhythm of the update of "Notice possible to" and "Term Until".';
186186
}
187187
field("Billing Rhythm"; ServiceCommitment."Billing Rhythm")
188188
{

src/Apps/W1/Subscription Billing/App/Import/Codeunits/CreateSubscriptionLine.Codeunit.al

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ codeunit 8006 "Create Subscription Line"
118118
if ImportedServiceCommitment."Calculation Base Amount (LCY)" <> 0 then
119119
ServiceCommitment."Calculation Base Amount (LCY)" := ImportedServiceCommitment."Calculation Base Amount (LCY)";
120120

121-
ServiceCommitment.CalculateInitialTermUntilDate();
122121
if ServiceCommitment."Subscription Line End Date" = 0D then
123-
ServiceCommitment.CalculateInitialServiceEndDate();
124-
ServiceCommitment.CalculateInitialCancellationPossibleUntilDate();
122+
ServiceCommitment.CalculateSubscriptionDates()
123+
else
124+
ServiceCommitment.CalculateTermUntilDate();
125125

126126
ServiceCommitment.SetDefaultDimensions(true);
127127
ServiceCommitment."Renewal Term" := ServiceCommitment."Initial Term";

src/Apps/W1/Subscription Billing/App/Import/Pages/ImportedServiceCommitments.Page.al

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ page 8009 "Imported Service Commitments"
115115
}
116116
field("Extension Term"; Rec."Extension Term")
117117
{
118-
ToolTip = 'Specifies a date formula for automatic renewal after initial term and the rhythm of the update of "Notice possible to" and "Term Until". If the field is empty and the initial term or notice period is filled, the end of Subscription Line is automatically set to the end of the initial term or notice period.';
118+
ToolTip = 'Specifies a date formula for automatic renewal after initial term and the rhythm of the update of "Notice possible to" and "Term Until".';
119119
}
120120
field("Billing Rhythm"; Rec."Billing Rhythm")
121121
{

0 commit comments

Comments
 (0)