Skip to content

Commit b1746be

Browse files
sluFicodesSHENGXING LU
andauthored
offering external billing option implemented (#229)
* offering external billing option implemented * remove basetype (non existent in patch payload) --------- Co-authored-by: SHENGXING LU <slu@SHENGXINGs-MacBook-Air.local>
1 parent 9a11a38 commit b1746be

5 files changed

Lines changed: 77 additions & 4 deletions

File tree

src/app/shared/forms/offer/general-info/general-info.component.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@
88
<input data-cy="offerVersion" id="prod-version" type="text" [formControl]="versionControl"
99
class="mb-2 bg-gray-50 dark:bg-secondary-300 border border-gray-300 dark:border-secondary-200 dark:text-white text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"/>
1010
}
11+
@if (extBillingEnabledControl) {
12+
<div class="mb-2 flex items-center gap-3">
13+
<label class="font-bold text-lg dark:text-white">{{ 'CREATE_OFFER._ext_billing' | translate }}</label>
14+
<input data-cy="extBillingToggle" type="checkbox" [formControl]="extBillingEnabledControl"
15+
class="w-4 h-4 text-primary-100 bg-gray-100 border-gray-300 rounded focus:ring-primary-100 dark:focus:ring-primary-50 dark:ring-offset-gray-800 dark:bg-gray-700 dark:border-gray-600"/>
16+
</div>
17+
}
18+
@if (extBillingEnabledControl?.value && plaSpecIdControl) {
19+
<label for="plaSpecId" class="font-bold text-lg dark:text-white">{{ 'CREATE_OFFER._pla_spec_id' | translate }}</label>
20+
<input data-cy="plaSpecId" id="plaSpecId" type="url" [formControl]="plaSpecIdControl"
21+
class="bg-gray-50 dark:bg-secondary-300 border border-gray-300 dark:border-secondary-200 dark:text-white text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"
22+
[class.border-red-500]="plaSpecIdControl.invalid && plaSpecIdControl.touched"
23+
placeholder="https://external-billing-engine.example.com"/>
24+
@if (plaSpecIdControl.invalid && plaSpecIdControl.touched) {
25+
<p class="text-red-500 text-sm mt-1 mb-2">{{ 'CREATE_OFFER._pla_spec_id_required' | translate }}</p>
26+
}
27+
}
1128
@if (statusControl && formType === 'update') {
1229
<label class="font-bold text-lg col-span-2 dark:text-white">{{ 'CREATE_OFFER._status' | translate }}</label>
1330
<app-status-selector [formControl]="statusControl"></app-status-selector>

src/app/shared/forms/offer/general-info/general-info.component.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ interface GeneralInfo {
1616
status: string;
1717
description: string;
1818
version: string;
19+
extBillingEnabled: boolean;
20+
plaSpecId: string;
1921
}
2022

2123
@Component({
@@ -69,23 +71,48 @@ export class GeneralInfoComponent implements OnInit, OnDestroy {
6971
return control instanceof FormControl ? control : null;
7072
}
7173

74+
get extBillingEnabledControl(): FormControl | null {
75+
const control = this.formGroup.get('extBillingEnabled');
76+
return control instanceof FormControl ? control : null;
77+
}
78+
79+
get plaSpecIdControl(): FormControl | null {
80+
const control = this.formGroup.get('plaSpecId');
81+
return control instanceof FormControl ? control : null;
82+
}
83+
7284
ngOnInit() {
7385
console.log('📝 Initializing form in', this.formType, 'mode');
7486
this.isEditMode = this.formType === 'update';
7587

7688
if (this.isEditMode && this.data) {
7789
console.log('Initializing form in update mode with data:', this.data);
90+
const existingPlaSpecId = this.data.pricingLogicAlgorithm?.[0]?.plaSpecId ?? '';
7891
this.formGroup.addControl('name', new FormControl<string>(this.data.name, [Validators.required, Validators.maxLength(100), noWhitespaceValidator]));
7992
this.formGroup.addControl('status', new FormControl<string>(this.data.lifecycleStatus));
8093
this.formGroup.addControl('description', new FormControl<string>(this.data.description, Validators.maxLength(100000)));
8194
this.formGroup.addControl('version', new FormControl<string>(this.data.version, [Validators.required,Validators.pattern('^-?[0-9]\\d*(\\.\\d*)?$'), noWhitespaceValidator]));
82-
95+
this.formGroup.addControl('extBillingEnabled', new FormControl<boolean>(!!existingPlaSpecId));
96+
this.formGroup.addControl('plaSpecId', new FormControl<string>(existingPlaSpecId, !!existingPlaSpecId ? [Validators.required] : []));
97+
98+
this.formGroup.get('extBillingEnabled')!.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((enabled: boolean) => {
99+
const plaControl = this.formGroup.get('plaSpecId')!;
100+
if (enabled) {
101+
plaControl.setValidators([Validators.required]);
102+
} else {
103+
plaControl.clearValidators();
104+
}
105+
plaControl.updateValueAndValidity();
106+
});
107+
83108
// Store original value only in edit mode
84109
this.originalValue = {
85110
name: this.data.name,
86111
status: this.data.lifecycleStatus,
87112
description: this.data.description,
88-
version: this.data.version
113+
version: this.data.version,
114+
extBillingEnabled: !!existingPlaSpecId,
115+
plaSpecId: existingPlaSpecId
89116
};
90117
console.log('📝 Original value stored:', this.originalValue);
91118
} else {
@@ -94,6 +121,18 @@ export class GeneralInfoComponent implements OnInit, OnDestroy {
94121
this.formGroup.addControl('status', new FormControl<string>('Active', [Validators.required]));
95122
this.formGroup.addControl('description', new FormControl<string>(''));
96123
this.formGroup.addControl('version', new FormControl<string>('0.1', [Validators.required,Validators.pattern('^-?[0-9]\\d*(\\.\\d*)?$'), noWhitespaceValidator]));
124+
this.formGroup.addControl('extBillingEnabled', new FormControl<boolean>(false));
125+
this.formGroup.addControl('plaSpecId', new FormControl<string>(''));
126+
127+
this.formGroup.get('extBillingEnabled')!.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((enabled: boolean) => {
128+
const plaControl = this.formGroup.get('plaSpecId')!;
129+
if (enabled) {
130+
plaControl.setValidators([Validators.required]);
131+
} else {
132+
plaControl.clearValidators();
133+
}
134+
plaControl.updateValueAndValidity();
135+
});
97136
}
98137

99138
// Subscribe to form changes only in edit mode

src/app/shared/forms/offer/offer.component.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,6 @@ export class OfferComponent implements OnInit, OnDestroy{
535535
units: component.newValue.usageUnit
536536
};
537537

538-
priceComp['@baseType'] = "ProductOfferingPrice";
539-
priceComp['@schemaLocation'] = "https://raw.githubusercontent.com/laraminones/tmf-new-schemas/main/UsageSpecId.json";
540538
(priceComp as any).usageSpecId = component.newValue.usageSpecId;
541539

542540
console.log('----- here')
@@ -705,6 +703,10 @@ export class OfferComponent implements OnInit, OnDestroy{
705703
bundledProductOffering: this.offersBundle,
706704
place: [],
707705
version: generalInfo.version,
706+
...(generalInfo.extBillingEnabled && generalInfo.plaSpecId ? {
707+
pricingLogicAlgorithm: [{ name: 'external billing', plaSpecId: generalInfo.plaSpecId }]
708+
} : {}),
709+
708710
category: categories,
709711
productOfferingPrice: prices,
710712
validFor: {
@@ -818,6 +820,11 @@ export class OfferComponent implements OnInit, OnDestroy{
818820
basePayload.description = change.currentValue.description;
819821
basePayload.version = change.currentValue.version;
820822
basePayload.lifecycleStatus = change.currentValue.status;
823+
if (change.currentValue.extBillingEnabled && change.currentValue.plaSpecId) {
824+
basePayload.pricingLogicAlgorithm = [{ name: 'external billing', plaSpecId: change.currentValue.plaSpecId }];
825+
} else if (change.originalValue.extBillingEnabled && !change.currentValue.extBillingEnabled) {
826+
basePayload.pricingLogicAlgorithm = [];
827+
}
821828
break;
822829

823830
case 'productSpecification':

src/assets/i18n/en.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,9 @@
22732273
"_name": "Name",
22742274
"_description": "Description",
22752275
"_version": "Version",
2276+
"_ext_billing": "Set external billing",
2277+
"_pla_spec_id": "External billing engine URL",
2278+
"_pla_spec_id_required": "External billing engine URL is required",
22762279
"_preview": "Preview",
22772280
"_show_preview": "Show preview",
22782281
"_next": "Next",
@@ -2375,6 +2378,8 @@
23752378
"_name": "Name",
23762379
"_description": "Description",
23772380
"_version": "Version",
2381+
"_ext_billing": "Set external billing",
2382+
"_pla_spec_id": "External billing engine URL",
23782383
"_preview": "Preview",
23792384
"_show_preview": "Show preview",
23802385
"_next": "Next",

src/assets/i18n/es.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,9 @@
22732273
"_name": "Name",
22742274
"_description": "Description",
22752275
"_version": "Version",
2276+
"_ext_billing": "Set external billing",
2277+
"_pla_spec_id": "External billing engine URL",
2278+
"_pla_spec_id_required": "External billing engine URL is required",
22762279
"_preview": "Preview",
22772280
"_show_preview": "Show preview",
22782281
"_next": "Next",
@@ -2375,6 +2378,8 @@
23752378
"_name": "Name",
23762379
"_description": "Description",
23772380
"_version": "Version",
2381+
"_ext_billing": "Set external billing",
2382+
"_pla_spec_id": "External billing engine URL",
23782383
"_preview": "Preview",
23792384
"_show_preview": "Show preview",
23802385
"_next": "Next",

0 commit comments

Comments
 (0)