diff --git a/src/app/shared/forms/offer/general-info/general-info.component.html b/src/app/shared/forms/offer/general-info/general-info.component.html index 7bfd3064..2d4d6850 100644 --- a/src/app/shared/forms/offer/general-info/general-info.component.html +++ b/src/app/shared/forms/offer/general-info/general-info.component.html @@ -8,6 +8,23 @@ } +@if (extBillingEnabledControl) { +
+ + +
+} +@if (extBillingEnabledControl?.value && plaSpecIdControl) { + + + @if (plaSpecIdControl.invalid && plaSpecIdControl.touched) { +

{{ 'CREATE_OFFER._pla_spec_id_required' | translate }}

+ } +} @if (statusControl && formType === 'update') { diff --git a/src/app/shared/forms/offer/general-info/general-info.component.ts b/src/app/shared/forms/offer/general-info/general-info.component.ts index a0988e7b..f617c3c9 100644 --- a/src/app/shared/forms/offer/general-info/general-info.component.ts +++ b/src/app/shared/forms/offer/general-info/general-info.component.ts @@ -16,6 +16,8 @@ interface GeneralInfo { status: string; description: string; version: string; + extBillingEnabled: boolean; + plaSpecId: string; } @Component({ @@ -69,23 +71,48 @@ export class GeneralInfoComponent implements OnInit, OnDestroy { return control instanceof FormControl ? control : null; } + get extBillingEnabledControl(): FormControl | null { + const control = this.formGroup.get('extBillingEnabled'); + return control instanceof FormControl ? control : null; + } + + get plaSpecIdControl(): FormControl | null { + const control = this.formGroup.get('plaSpecId'); + return control instanceof FormControl ? control : null; + } + ngOnInit() { console.log('📝 Initializing form in', this.formType, 'mode'); this.isEditMode = this.formType === 'update'; if (this.isEditMode && this.data) { console.log('Initializing form in update mode with data:', this.data); + const existingPlaSpecId = this.data.pricingLogicAlgorithm?.[0]?.plaSpecId ?? ''; this.formGroup.addControl('name', new FormControl(this.data.name, [Validators.required, Validators.maxLength(100), noWhitespaceValidator])); this.formGroup.addControl('status', new FormControl(this.data.lifecycleStatus)); this.formGroup.addControl('description', new FormControl(this.data.description, Validators.maxLength(100000))); this.formGroup.addControl('version', new FormControl(this.data.version, [Validators.required,Validators.pattern('^-?[0-9]\\d*(\\.\\d*)?$'), noWhitespaceValidator])); - + this.formGroup.addControl('extBillingEnabled', new FormControl(!!existingPlaSpecId)); + this.formGroup.addControl('plaSpecId', new FormControl(existingPlaSpecId, !!existingPlaSpecId ? [Validators.required] : [])); + + this.formGroup.get('extBillingEnabled')!.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((enabled: boolean) => { + const plaControl = this.formGroup.get('plaSpecId')!; + if (enabled) { + plaControl.setValidators([Validators.required]); + } else { + plaControl.clearValidators(); + } + plaControl.updateValueAndValidity(); + }); + // Store original value only in edit mode this.originalValue = { name: this.data.name, status: this.data.lifecycleStatus, description: this.data.description, - version: this.data.version + version: this.data.version, + extBillingEnabled: !!existingPlaSpecId, + plaSpecId: existingPlaSpecId }; console.log('📝 Original value stored:', this.originalValue); } else { @@ -94,6 +121,18 @@ export class GeneralInfoComponent implements OnInit, OnDestroy { this.formGroup.addControl('status', new FormControl('Active', [Validators.required])); this.formGroup.addControl('description', new FormControl('')); this.formGroup.addControl('version', new FormControl('0.1', [Validators.required,Validators.pattern('^-?[0-9]\\d*(\\.\\d*)?$'), noWhitespaceValidator])); + this.formGroup.addControl('extBillingEnabled', new FormControl(false)); + this.formGroup.addControl('plaSpecId', new FormControl('')); + + this.formGroup.get('extBillingEnabled')!.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((enabled: boolean) => { + const plaControl = this.formGroup.get('plaSpecId')!; + if (enabled) { + plaControl.setValidators([Validators.required]); + } else { + plaControl.clearValidators(); + } + plaControl.updateValueAndValidity(); + }); } // Subscribe to form changes only in edit mode diff --git a/src/app/shared/forms/offer/offer.component.ts b/src/app/shared/forms/offer/offer.component.ts index 09fe3936..f179dde9 100644 --- a/src/app/shared/forms/offer/offer.component.ts +++ b/src/app/shared/forms/offer/offer.component.ts @@ -535,8 +535,6 @@ export class OfferComponent implements OnInit, OnDestroy{ units: component.newValue.usageUnit }; - priceComp['@baseType'] = "ProductOfferingPrice"; - priceComp['@schemaLocation'] = "https://raw.githubusercontent.com/laraminones/tmf-new-schemas/main/UsageSpecId.json"; (priceComp as any).usageSpecId = component.newValue.usageSpecId; console.log('----- here') @@ -705,6 +703,10 @@ export class OfferComponent implements OnInit, OnDestroy{ bundledProductOffering: this.offersBundle, place: [], version: generalInfo.version, + ...(generalInfo.extBillingEnabled && generalInfo.plaSpecId ? { + pricingLogicAlgorithm: [{ name: 'external billing', plaSpecId: generalInfo.plaSpecId }] + } : {}), + category: categories, productOfferingPrice: prices, validFor: { @@ -818,6 +820,11 @@ export class OfferComponent implements OnInit, OnDestroy{ basePayload.description = change.currentValue.description; basePayload.version = change.currentValue.version; basePayload.lifecycleStatus = change.currentValue.status; + if (change.currentValue.extBillingEnabled && change.currentValue.plaSpecId) { + basePayload.pricingLogicAlgorithm = [{ name: 'external billing', plaSpecId: change.currentValue.plaSpecId }]; + } else if (change.originalValue.extBillingEnabled && !change.currentValue.extBillingEnabled) { + basePayload.pricingLogicAlgorithm = []; + } break; case 'productSpecification': diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 41a92c1b..4fcf41c8 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -1834,6 +1834,9 @@ "_name": "Name", "_description": "Description", "_version": "Version", + "_ext_billing": "Set external billing", + "_pla_spec_id": "External billing engine URL", + "_pla_spec_id_required": "External billing engine URL is required", "_preview": "Preview", "_show_preview": "Show preview", "_next": "Next", @@ -1936,6 +1939,8 @@ "_name": "Name", "_description": "Description", "_version": "Version", + "_ext_billing": "Set external billing", + "_pla_spec_id": "External billing engine URL", "_preview": "Preview", "_show_preview": "Show preview", "_next": "Next", diff --git a/src/assets/i18n/es.json b/src/assets/i18n/es.json index 41a92c1b..4fcf41c8 100644 --- a/src/assets/i18n/es.json +++ b/src/assets/i18n/es.json @@ -1834,6 +1834,9 @@ "_name": "Name", "_description": "Description", "_version": "Version", + "_ext_billing": "Set external billing", + "_pla_spec_id": "External billing engine URL", + "_pla_spec_id_required": "External billing engine URL is required", "_preview": "Preview", "_show_preview": "Show preview", "_next": "Next", @@ -1936,6 +1939,8 @@ "_name": "Name", "_description": "Description", "_version": "Version", + "_ext_billing": "Set external billing", + "_pla_spec_id": "External billing engine URL", "_preview": "Preview", "_show_preview": "Show preview", "_next": "Next",