From 0aec0be1d40ede44620a44eb357eff55d9ea92af Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Wed, 27 May 2026 13:05:54 +0100 Subject: [PATCH] Fixed error to function to create quotation --- .../create-purchaseorder-form.ts | 3 +- .../create-quotation-form.html | 18 ++- .../create-quotation-form.ts | 56 +++++++++- src/app/pages/stock/stock.html | 1 + src/app/pages/stock/stock.ts | 14 ++- src/app/services/api/.openapi-generator/FILES | 2 + src/app/services/api/api/api.ts | 5 +- src/app/services/api/api/customers.service.ts | 104 ++++++++++++++++++ .../api/model/create-quotation-dto.ts | 2 + .../services/api/model/get-customer-dto.ts | 16 +++ src/app/services/api/model/models.ts | 1 + 11 files changed, 206 insertions(+), 16 deletions(-) create mode 100644 src/app/services/api/api/customers.service.ts create mode 100644 src/app/services/api/model/get-customer-dto.ts diff --git a/src/app/components/create-purchaseorder-form/create-purchaseorder-form.ts b/src/app/components/create-purchaseorder-form/create-purchaseorder-form.ts index 48f4b63..168325c 100644 --- a/src/app/components/create-purchaseorder-form/create-purchaseorder-form.ts +++ b/src/app/components/create-purchaseorder-form/create-purchaseorder-form.ts @@ -72,9 +72,8 @@ export class CreatePurchaseorderForm { ); }); - const bestSupplier = this.getBestSupplier(); this.createPurchaseOrderForm.patchValue({ - supplierId: bestSupplier.id, + supplierId: this.getBestSupplier().id, }); } } diff --git a/src/app/components/create-quotation-form/create-quotation-form.html b/src/app/components/create-quotation-form/create-quotation-form.html index a749284..a70a780 100644 --- a/src/app/components/create-quotation-form/create-quotation-form.html +++ b/src/app/components/create-quotation-form/create-quotation-form.html @@ -1,4 +1,20 @@
+ + + Client + + + + + @for (customer of customers(); track customer.id) { + + } + + + + + Message @@ -15,7 +31,7 @@ - + diff --git a/src/app/components/create-quotation-form/create-quotation-form.ts b/src/app/components/create-quotation-form/create-quotation-form.ts index 05a4d64..0069596 100644 --- a/src/app/components/create-quotation-form/create-quotation-form.ts +++ b/src/app/components/create-quotation-form/create-quotation-form.ts @@ -1,4 +1,4 @@ -import {Component, input} from '@angular/core'; +import {Component, inject, input, OnInit, signal} from '@angular/core'; import { FormArray, FormBuilder, @@ -14,7 +14,10 @@ import {NzFormControlComponent, NzFormItemComponent, NzFormLabelComponent} from import {NzInputDirective} from "ng-zorro-antd/input"; import {NzInputNumberComponent} from "ng-zorro-antd/input-number"; import {NzTableComponent} from "ng-zorro-antd/table"; -import {GetProductDto} from "../../services/api"; +import {CustomersService, GetCustomerDto, GetProductDto, GetSupplierDto} from "../../services/api"; +import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select"; +import {firstValueFrom} from "rxjs"; +import {NzNotificationService} from "ng-zorro-antd/notification"; @Component({ selector: 'app-create-quotation-form', @@ -28,17 +31,36 @@ import {GetProductDto} from "../../services/api"; NzInputDirective, NzInputNumberComponent, NzTableComponent, - ReactiveFormsModule + ReactiveFormsModule, + NzOptionComponent, + NzSelectComponent ], templateUrl: './create-quotation-form.html', styleUrl: './create-quotation-form.css', }) -export class CreateQuotationForm { +export class CreateQuotationForm implements OnInit { + private customersService = inject(CustomersService); + private notificationService = inject(NzNotificationService); + + suppliers = input.required(); products = input.required(); + customers = signal([]); + + async ngOnInit() { + try { + const customers = await firstValueFrom(this.customersService.getAllCustomersEndpoint()) + this.customers.set(customers); + } catch { + this.notificationService.error('Erreur', 'Erreur de communication avec l\'API') + } + } + createQuotationForm: FormGroup = new FormGroup({ message: new FormControl(null, Validators.required), - purchaseConditions: new FormControl(null, Validators.required), + conditionsSale: new FormControl(null, Validators.required), + supplierId: new FormControl(null, Validators.required), + customerId: new FormControl(null, Validators.required), lines: new FormArray([], Validators.required), }) @@ -46,6 +68,24 @@ export class CreateQuotationForm { return this.createQuotationForm.get('lines') as FormArray; } + getDefaultSupplier() { + let defaultSupplier: GetSupplierDto = this.suppliers()[0]; + let maxProducts = 0; + + const selectedProducts = this.products().map(x => x.id); + + this.suppliers().forEach(x => { + const supplierProductsCount = x.prices.filter(p => selectedProducts.includes(p.productId)).length ?? 0; + + if (supplierProductsCount > maxProducts) { + maxProducts = supplierProductsCount; + defaultSupplier = x; + } + }) + + return defaultSupplier; + } + addProductToForm() { this.lines.clear(); this.products().forEach(x => { @@ -53,9 +93,13 @@ export class CreateQuotationForm { new FormGroup({ productId: new FormControl(x.id), name: new FormControl(x.name), - quantity: new FormControl(0, [Validators.required, Validators.min(0)]) + quantity: new FormControl(1, [Validators.required, Validators.min(1)]) }) ); }); + + this.createQuotationForm.patchValue({ + supplierId: this.getDefaultSupplier().id, + }); } } diff --git a/src/app/pages/stock/stock.html b/src/app/pages/stock/stock.html index bae4840..02f11c0 100644 --- a/src/app/pages/stock/stock.html +++ b/src/app/pages/stock/stock.html @@ -23,6 +23,7 @@ (ok)="onModalQuotationOk()" (cancel)="onModalQuotationCancel()"> diff --git a/src/app/pages/stock/stock.ts b/src/app/pages/stock/stock.ts index 5080422..7f78261 100644 --- a/src/app/pages/stock/stock.ts +++ b/src/app/pages/stock/stock.ts @@ -4,7 +4,7 @@ import {ModalButton} from "../../components/modal-button/modal-button"; import {CreatePurchaseorderForm} from "../../components/create-purchaseorder-form/create-purchaseorder-form"; import {NzNotificationService} from "ng-zorro-antd/notification"; import { - CreatePurchaseOrderDto, + CreatePurchaseOrderDto, CreateQuotationDto, GetProductDto, GetSupplierDto, PurchaseordersService, @@ -123,17 +123,19 @@ export class Stock implements OnInit { return; } - const quotation = { - message: this.createQuotation().createQuotationForm.get('message')!.value, - purchaseConditions: this.createQuotation().createQuotationForm.get('purchaseConditions')!.value, + const quotation: CreateQuotationDto = { + message: this.createQuotation().createQuotationForm.value.message, + conditionsSale: this.createQuotation().createQuotationForm.value.conditionsSale, + customerId: this.createQuotation().createQuotationForm.value.customerId, + supplierId: this.createQuotation().createQuotationForm.value.supplierId, products: orderLines }; try { await firstValueFrom(this.quotationsService.createQuotationEndpoint(quotation)); - this.notificationService.success('Succès', 'Bon de commande créé'); + this.notificationService.success('Succès', 'Devis créé'); } catch { - this.notificationService.error('Erreur', 'Erreur lors de la création du bon de commande.'); + this.notificationService.error('Erreur', 'Erreur lors de la création du devis.'); } } diff --git a/src/app/services/api/.openapi-generator/FILES b/src/app/services/api/.openapi-generator/FILES index 93654d7..9a756b8 100644 --- a/src/app/services/api/.openapi-generator/FILES +++ b/src/app/services/api/.openapi-generator/FILES @@ -4,6 +4,7 @@ README.md api.base.service.ts api.module.ts api/api.ts +api/customers.service.ts api/deliverers.service.ts api/deliverynotes.service.ts api/prices.service.ts @@ -31,6 +32,7 @@ model/create-purchase-product-dto.ts model/create-quotation-dto.ts model/create-supplier-dto.ts model/create-user-dto.ts +model/get-customer-dto.ts model/get-deliverer-dto.ts model/get-delivery-note-dto.ts model/get-price-dto.ts diff --git a/src/app/services/api/api/api.ts b/src/app/services/api/api/api.ts index 4a692c4..a0b0052 100644 --- a/src/app/services/api/api/api.ts +++ b/src/app/services/api/api/api.ts @@ -1,3 +1,6 @@ +export * from './customers.service'; +import {CustomersService} from './customers.service'; + export * from './deliverers.service'; import {DeliverersService} from './deliverers.service'; @@ -31,4 +34,4 @@ import {WarehouseproductsService} from './warehouseproducts.service'; export * from './warehouses.service'; import {WarehousesService} from './warehouses.service'; -export const APIS = [DeliverersService, DeliverynotesService, PricesService, ProductsService, PurchaseordersService, QuotationsService, SettingsService, SuppliersService, UsersService, WarehouseproductsService, WarehousesService]; +export const APIS = [CustomersService, DeliverersService, DeliverynotesService, PricesService, ProductsService, PurchaseordersService, QuotationsService, SettingsService, SuppliersService, UsersService, WarehouseproductsService, WarehousesService]; diff --git a/src/app/services/api/api/customers.service.ts b/src/app/services/api/api/customers.service.ts new file mode 100644 index 0000000..7ccd3da --- /dev/null +++ b/src/app/services/api/api/customers.service.ts @@ -0,0 +1,104 @@ +/** + * PyroFetes + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +/* tslint:disable:no-unused-variable member-ordering */ + +import {Inject, Injectable, Optional} from '@angular/core'; +import { + HttpClient, HttpHeaders, HttpParams, + HttpResponse, HttpEvent, HttpParameterCodec, HttpContext +} from '@angular/common/http'; +import {CustomHttpParameterCodec} from '../encoder'; +import {Observable} from 'rxjs'; + +// @ts-ignore +import {GetCustomerDto} from '../model/get-customer-dto'; + +// @ts-ignore +import {BASE_PATH, COLLECTION_FORMATS} from '../variables'; +import {Configuration} from '../configuration'; +import {BaseService} from '../api.base.service'; + + +@Injectable({ + providedIn: 'root' +}) +export class CustomersService extends BaseService { + + constructor(protected httpClient: HttpClient, @Optional() @Inject(BASE_PATH) basePath: string | string[], @Optional() configuration?: Configuration) { + super(basePath, configuration); + } + + /** + * @endpoint get /API/customers + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public getAllCustomersEndpoint(observe?: 'body', reportProgress?: boolean, options?: { + httpHeaderAccept?: 'application/json', + context?: HttpContext, + transferCache?: boolean + }): Observable>; + public getAllCustomersEndpoint(observe?: 'response', reportProgress?: boolean, options?: { + httpHeaderAccept?: 'application/json', + context?: HttpContext, + transferCache?: boolean + }): Observable>>; + public getAllCustomersEndpoint(observe?: 'events', reportProgress?: boolean, options?: { + httpHeaderAccept?: 'application/json', + context?: HttpContext, + transferCache?: boolean + }): Observable>>; + public getAllCustomersEndpoint(observe: any = 'body', reportProgress: boolean = false, options?: { + httpHeaderAccept?: 'application/json', + context?: HttpContext, + transferCache?: boolean + }): Observable { + + let localVarHeaders = this.defaultHeaders; + + const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ + 'application/json' + ]); + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); + } + + const localVarHttpContext: HttpContext = options?.context ?? new HttpContext(); + + const localVarTransferCache: boolean = options?.transferCache ?? true; + + + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + + let localVarPath = `/API/customers`; + const {basePath, withCredentials} = this.configuration; + return this.httpClient.request>('get', `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + responseType: responseType_, + ...(withCredentials ? {withCredentials} : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined ? {transferCache: localVarTransferCache} : {}), + reportProgress: reportProgress + } + ); + } + +} diff --git a/src/app/services/api/model/create-quotation-dto.ts b/src/app/services/api/model/create-quotation-dto.ts index 00cea1a..c5bd555 100644 --- a/src/app/services/api/model/create-quotation-dto.ts +++ b/src/app/services/api/model/create-quotation-dto.ts @@ -13,6 +13,8 @@ import {CreateProductQuotationDto} from './create-product-quotation-dto'; export interface CreateQuotationDto { message?: string | null; conditionsSale?: string | null; + customerId?: number; + supplierId?: number; products?: Array | null; } diff --git a/src/app/services/api/model/get-customer-dto.ts b/src/app/services/api/model/get-customer-dto.ts new file mode 100644 index 0000000..65fe9c3 --- /dev/null +++ b/src/app/services/api/model/get-customer-dto.ts @@ -0,0 +1,16 @@ +/** + * PyroFetes + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface GetCustomerDto { + id?: number; + note?: string | null; +} + diff --git a/src/app/services/api/model/models.ts b/src/app/services/api/model/models.ts index 074577e..706d060 100644 --- a/src/app/services/api/model/models.ts +++ b/src/app/services/api/model/models.ts @@ -10,6 +10,7 @@ export * from './create-purchase-product-dto'; export * from './create-quotation-dto'; export * from './create-supplier-dto'; export * from './create-user-dto'; +export * from './get-customer-dto'; export * from './get-deliverer-dto'; export * from './get-delivery-note-dto'; export * from './get-price-dto';