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
20 changes: 20 additions & 0 deletions src/app/features/quotes/pages/quote-list/quote-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,19 @@ import { LoginInfo } from 'src/app/models/interfaces';
[attr.d]="isQuoteCancelled(quote) ? 'M6 18L18 6M6 6l12 12' : 'M5 13l4 4L19 7'" />
</svg>
</button>

<!-- Create offer, Seller only when the quote is accepted -->
<button
*ngIf="selectedRole === 'seller' && getPrimaryState(quote) === 'accepted'"
[disabled]="isActionDisabled(quote, 'createOffer')"
(click)="createOffer(quote)"
[class]="getIconButtonClass(quote, 'createOffer', 'text-emerald-600 hover:text-emerald-700')"
title="Create Offer"
>
<svg class="h-5 w-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h14m-7 7V5"/>
</svg>
</button>
</ng-container>
</div>
</div>
Expand Down Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h1 class="mb-8 mt-4 text-4xl font-extrabold leading-none tracking-tight text-gr
<update-catalog [cat]="catalog_to_update"></update-catalog>
}
@if(show_create_custom_offer){
<app-custom-offer [offer]="offer_to_update"></app-custom-offer>
<app-custom-offer [offer]="offer_to_update" [partyId]="custom_offer_partyId"></app-custom-offer>
}
</div>
</div>
Expand Down
32 changes: 28 additions & 4 deletions src/app/pages/seller-offerings/seller-offerings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand All @@ -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$))
Expand Down Expand Up @@ -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') {
Expand All @@ -127,14 +134,31 @@ 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)
if (saved) this.activeSection = saved;
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(){
Expand Down
4 changes: 2 additions & 2 deletions src/app/services/event-message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
19 changes: 14 additions & 5 deletions src/app/shared/forms/offer/custom-offer/custom-offer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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]),
Expand All @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading