diff --git a/src/app/features/quotes/pages/quote-list/quote-list.component.ts b/src/app/features/quotes/pages/quote-list/quote-list.component.ts index 57eafcaf..969e7715 100644 --- a/src/app/features/quotes/pages/quote-list/quote-list.component.ts +++ b/src/app/features/quotes/pages/quote-list/quote-list.component.ts @@ -284,6 +284,19 @@ import { LoginInfo } from 'src/app/models/interfaces'; [attr.d]="isQuoteCancelled(quote) ? 'M6 18L18 6M6 6l12 12' : 'M5 13l4 4L19 7'" /> + + + @@ -848,6 +861,13 @@ export class QuoteListComponent implements OnInit { }); } + createOffer(quote: Quote) { + // we send the current quote ID to open the proper from + this.router.navigate(['/my-offerings'], { state: { + quoteId: quote.id + } }); + } + // Utility methods (migrated from QuoteRow.js) extractShortId(id: string | undefined): string { if (!id) return 'N/A'; diff --git a/src/app/pages/seller-offerings/seller-offerings.component.html b/src/app/pages/seller-offerings/seller-offerings.component.html index dd3903a4..d8af67da 100644 --- a/src/app/pages/seller-offerings/seller-offerings.component.html +++ b/src/app/pages/seller-offerings/seller-offerings.component.html @@ -107,7 +107,7 @@

} @if(show_create_custom_offer){ - + } diff --git a/src/app/pages/seller-offerings/seller-offerings.component.ts b/src/app/pages/seller-offerings/seller-offerings.component.ts index 9bbfa407..91040d80 100644 --- a/src/app/pages/seller-offerings/seller-offerings.component.ts +++ b/src/app/pages/seller-offerings/seller-offerings.component.ts @@ -11,8 +11,9 @@ import { LoginInfo } from 'src/app/models/interfaces'; import { initFlowbite } from 'flowbite'; import {EventMessageService} from "../../services/event-message.service"; import * as moment from 'moment'; -import { Subject } from 'rxjs'; +import { firstValueFrom, Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; +import { QuoteService } from 'src/app/features/quotes/services/quote.service'; @Component({ selector: 'app-seller-offerings', @@ -41,6 +42,7 @@ export class SellerOfferingsComponent implements OnInit, OnDestroy { serv_to_update:any; res_to_update:any; offer_to_update:any; + custom_offer_partyId:any=null; catalog_to_update:any; feedback:boolean=false; userInfo:any; @@ -59,7 +61,10 @@ export class SellerOfferingsComponent implements OnInit, OnDestroy { constructor( private localStorage: LocalStorageService, private cdr: ChangeDetectorRef, - private eventMessage: EventMessageService + private eventMessage: EventMessageService, + private router: Router, + private quoteService: QuoteService, + private api: ApiServiceService ) { this.eventMessage.messages$ .pipe(takeUntil(this.destroy$)) @@ -114,7 +119,9 @@ export class SellerOfferingsComponent implements OnInit, OnDestroy { this.goToUpdateOffer(); } if(ev.type === 'SellerCreateCustomOffer') { - this.offer_to_update=ev.value; + const evValue = ev.value as {offer: any, partyId?: string}; + this.offer_to_update = evValue.offer; + this.custom_offer_partyId = evValue.partyId || null; this.goToCreateCustomOffer(); } if(ev.type === 'SellerCatalogUpdate') { @@ -127,7 +134,7 @@ export class SellerOfferingsComponent implements OnInit, OnDestroy { }) } - ngOnInit() { + async ngOnInit() { this.userInfo = this.localStorage.getObject('login_items') as LoginInfo; const saved = localStorage.getItem('activeSection'); console.log(saved) @@ -135,6 +142,23 @@ export class SellerOfferingsComponent implements OnInit, OnDestroy { if (saved && this.sectionActions[saved]) { this.sectionActions[saved].call(this); // bind `this` context } + + const state = history.state as { quoteId?: string }; + console.log('Checking state') + console.log(state) + + if (state && state.quoteId) { + // If there's a quoteId in the state, open the offers section + const quote = await firstValueFrom(this.quoteService.getQuoteById(state.quoteId)); + const offerId = quote?.quoteItem?.[0]?.productOffering?.id; + let offer:any = null; + if (offerId) { + offer = await this.api.getProductById(offerId); + } + + const quoteBuyer = quote?.relatedParty?.find((party: any) => party.role.toLowerCase() === environment.BUYER_ROLE.toLowerCase()); + this.eventMessage.emitSellerCreateCustomOffer(offer, quoteBuyer?.id); + } } ngOnDestroy(){ diff --git a/src/app/services/event-message.service.ts b/src/app/services/event-message.service.ts index 984cf264..a09a24bc 100644 --- a/src/app/services/event-message.service.ts +++ b/src/app/services/event-message.service.ts @@ -109,8 +109,8 @@ export class EventMessageService { this.eventMessageSubject.next({ type: 'SellerUpdateOffer', value: offer }); } - emitSellerCreateCustomOffer(offer:any){ - this.eventMessageSubject.next({type: 'SellerCreateCustomOffer', value: offer}) + emitSellerCreateCustomOffer(offer:any, partyId?:string){ + this.eventMessageSubject.next({type: 'SellerCreateCustomOffer', value: {offer, partyId}}) } emitSellerCatalog(show:boolean){ diff --git a/src/app/shared/forms/offer/custom-offer/custom-offer.component.ts b/src/app/shared/forms/offer/custom-offer/custom-offer.component.ts index 824ad475..acee9bbc 100644 --- a/src/app/shared/forms/offer/custom-offer/custom-offer.component.ts +++ b/src/app/shared/forms/offer/custom-offer/custom-offer.component.ts @@ -8,13 +8,14 @@ import {PricePlansComponent} from "../price-plans/price-plans.component"; import {ProcurementModeComponent} from "../procurement-mode/procurement-mode.component" import {RelatedPartyIdComponent} from "../related-party-id/related-party-id.component" import {OfferSummaryComponent} from "../offer-summary/offer-summary.component" -import { lastValueFrom } from 'rxjs'; +import { lastValueFrom, firstValueFrom } from 'rxjs'; import {components} from "src/app/models/product-catalog"; import {EventMessageService} from "src/app/services/event-message.service"; import {FormChangeState, PricePlanChangeState} from "../../../../models/interfaces"; import {Subscription} from "rxjs"; import * as moment from 'moment'; import { environment } from 'src/environments/environment'; +import { QuoteService } from 'src/app/features/quotes/services/quote.service'; type ProductOffering_Create = components["schemas"]["ProductOffering_Create"]; type ProductOfferingPrice = components["schemas"]["ProductOfferingPrice"] @@ -62,7 +63,7 @@ export class CustomOfferComponent implements OnInit { constructor(private api: ApiServiceService, private eventMessage: EventMessageService, - private fb: FormBuilder) { + private fb: FormBuilder, private quoteService: QuoteService) { this.productOfferForm = this.fb.group({ prodSpec: new FormControl(null, [Validators.required]), @@ -78,8 +79,9 @@ export class CustomOfferComponent implements OnInit { console.log(this.offer) console.log(this.partyId) console.log('-------------------------------') + await this.loadOfferData(); - this.loadingData=false; + this.loadingData = false; } async loadOfferData() { @@ -170,12 +172,19 @@ export class CustomOfferComponent implements OnInit { })); const license = this.offer.productOfferingTerm.find((t: { name: string; }) => t.name === 'License'); - + + // Add the name of the organization/trading name to the offer name + let offerName = this.offer.name; + if (this.productOfferForm.get('partyInfo')?.value.tradingName) { + offerName = `${this.offer.name} - ${this.productOfferForm.get('partyInfo')?.value.tradingName}`; + } + const offer: any = { - name: this.offer.name, + name: offerName, description: this.offer?.description || '', lifecycleStatus: 'Active', isBundle: this.bundleChecked, + isSellable: false, // Ad-Hoc offer cannot be generally purchased bundledProductOffering: this.offersBundle, place: [], version: this.offer.version, diff --git a/src/app/shared/quote-request-modal/quote-request-modal.component.ts b/src/app/shared/quote-request-modal/quote-request-modal.component.ts index 121e5d37..57c93bfe 100644 --- a/src/app/shared/quote-request-modal/quote-request-modal.component.ts +++ b/src/app/shared/quote-request-modal/quote-request-modal.component.ts @@ -4,7 +4,7 @@ import { FormsModule, ReactiveFormsModule, FormBuilder, FormGroup, Validators } import {components} from "../../models/product-catalog"; type Product = components["schemas"]["ProductOffering"]; type ProductSpecification = components["schemas"]["ProductSpecification"]; -import { QuoteService } from 'src/app/services/quote.service'; +import { QuoteService } from 'src/app/features/quotes/services/quote.service'; import { EventMessageService } from 'src/app/services/event-message.service'; export interface QuoteRequestData {