Fixed error to function to create quotation

This commit is contained in:
2026-05-27 13:05:54 +01:00
parent a7ef707388
commit 0aec0be1d4
11 changed files with 206 additions and 16 deletions
@@ -72,9 +72,8 @@ export class CreatePurchaseorderForm {
); );
}); });
const bestSupplier = this.getBestSupplier();
this.createPurchaseOrderForm.patchValue({ this.createPurchaseOrderForm.patchValue({
supplierId: bestSupplier.id, supplierId: this.getBestSupplier().id,
}); });
} }
} }
@@ -1,4 +1,20 @@
<form [formGroup]="createQuotationForm"> <form [formGroup]="createQuotationForm">
<nz-form-item nz-flex>
<nz-form-label nzSpan="12" nzRequired>
Client
</nz-form-label>
<nz-form-control nzSpan="12" nzErrorTip="Ce champ est requis">
<nz-select formControlName="customerId" nzPlaceHolder="Choisir un client"
nzShowSearch>
@for (customer of customers(); track customer.id) {
<nz-option [nzLabel]="customer.note" [nzValue]="customer.id"></nz-option>
}
</nz-select>
</nz-form-control>
</nz-form-item>
<nz-form-item nz-flex> <nz-form-item nz-flex>
<nz-form-label nzSpan="12" nzRequired> <nz-form-label nzSpan="12" nzRequired>
Message Message
@@ -15,7 +31,7 @@
</nz-form-label> </nz-form-label>
<nz-form-control nzSpan="12" nzErrorTip="Ce champ est requis"> <nz-form-control nzSpan="12" nzErrorTip="Ce champ est requis">
<input nz-input placeholder="Conditions générales de vente" formControlName="purchaseConditions"> <input nz-input placeholder="Conditions générales de vente" formControlName="conditionsSale">
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
@@ -1,4 +1,4 @@
import {Component, input} from '@angular/core'; import {Component, inject, input, OnInit, signal} from '@angular/core';
import { import {
FormArray, FormArray,
FormBuilder, FormBuilder,
@@ -14,7 +14,10 @@ import {NzFormControlComponent, NzFormItemComponent, NzFormLabelComponent} from
import {NzInputDirective} from "ng-zorro-antd/input"; import {NzInputDirective} from "ng-zorro-antd/input";
import {NzInputNumberComponent} from "ng-zorro-antd/input-number"; import {NzInputNumberComponent} from "ng-zorro-antd/input-number";
import {NzTableComponent} from "ng-zorro-antd/table"; 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({ @Component({
selector: 'app-create-quotation-form', selector: 'app-create-quotation-form',
@@ -28,17 +31,36 @@ import {GetProductDto} from "../../services/api";
NzInputDirective, NzInputDirective,
NzInputNumberComponent, NzInputNumberComponent,
NzTableComponent, NzTableComponent,
ReactiveFormsModule ReactiveFormsModule,
NzOptionComponent,
NzSelectComponent
], ],
templateUrl: './create-quotation-form.html', templateUrl: './create-quotation-form.html',
styleUrl: './create-quotation-form.css', styleUrl: './create-quotation-form.css',
}) })
export class CreateQuotationForm { export class CreateQuotationForm implements OnInit {
private customersService = inject(CustomersService);
private notificationService = inject(NzNotificationService);
suppliers = input.required<GetSupplierDto[]>();
products = input.required<GetProductDto[]>(); products = input.required<GetProductDto[]>();
customers = signal<GetCustomerDto[]>([]);
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({ createQuotationForm: FormGroup = new FormGroup({
message: new FormControl<string>(null, Validators.required), message: new FormControl<string>(null, Validators.required),
purchaseConditions: new FormControl<string>(null, Validators.required), conditionsSale: new FormControl<string>(null, Validators.required),
supplierId: new FormControl<number>(null, Validators.required),
customerId: new FormControl<number>(null, Validators.required),
lines: new FormArray([], Validators.required), lines: new FormArray([], Validators.required),
}) })
@@ -46,6 +68,24 @@ export class CreateQuotationForm {
return this.createQuotationForm.get('lines') as FormArray; 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() { addProductToForm() {
this.lines.clear(); this.lines.clear();
this.products().forEach(x => { this.products().forEach(x => {
@@ -53,9 +93,13 @@ export class CreateQuotationForm {
new FormGroup({ new FormGroup({
productId: new FormControl(x.id), productId: new FormControl(x.id),
name: new FormControl(x.name), 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,
});
} }
} }
+1
View File
@@ -23,6 +23,7 @@
(ok)="onModalQuotationOk()" (ok)="onModalQuotationOk()"
(cancel)="onModalQuotationCancel()"> (cancel)="onModalQuotationCancel()">
<app-create-quotation-form #quotationForm <app-create-quotation-form #quotationForm
[suppliers]="suppliers()"
[products]="selectedProducts()"> [products]="selectedProducts()">
</app-create-quotation-form> </app-create-quotation-form>
</app-modal-button> </app-modal-button>
+8 -6
View File
@@ -4,7 +4,7 @@ import {ModalButton} from "../../components/modal-button/modal-button";
import {CreatePurchaseorderForm} from "../../components/create-purchaseorder-form/create-purchaseorder-form"; import {CreatePurchaseorderForm} from "../../components/create-purchaseorder-form/create-purchaseorder-form";
import {NzNotificationService} from "ng-zorro-antd/notification"; import {NzNotificationService} from "ng-zorro-antd/notification";
import { import {
CreatePurchaseOrderDto, CreatePurchaseOrderDto, CreateQuotationDto,
GetProductDto, GetProductDto,
GetSupplierDto, GetSupplierDto,
PurchaseordersService, PurchaseordersService,
@@ -123,17 +123,19 @@ export class Stock implements OnInit {
return; return;
} }
const quotation = { const quotation: CreateQuotationDto = {
message: this.createQuotation().createQuotationForm.get('message')!.value, message: this.createQuotation().createQuotationForm.value.message,
purchaseConditions: this.createQuotation().createQuotationForm.get('purchaseConditions')!.value, conditionsSale: this.createQuotation().createQuotationForm.value.conditionsSale,
customerId: this.createQuotation().createQuotationForm.value.customerId,
supplierId: this.createQuotation().createQuotationForm.value.supplierId,
products: orderLines products: orderLines
}; };
try { try {
await firstValueFrom(this.quotationsService.createQuotationEndpoint(quotation)); await firstValueFrom(this.quotationsService.createQuotationEndpoint(quotation));
this.notificationService.success('Succès', 'Bon de commande créé'); this.notificationService.success('Succès', 'Devis créé');
} catch { } 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.');
} }
} }
@@ -4,6 +4,7 @@ README.md
api.base.service.ts api.base.service.ts
api.module.ts api.module.ts
api/api.ts api/api.ts
api/customers.service.ts
api/deliverers.service.ts api/deliverers.service.ts
api/deliverynotes.service.ts api/deliverynotes.service.ts
api/prices.service.ts api/prices.service.ts
@@ -31,6 +32,7 @@ model/create-purchase-product-dto.ts
model/create-quotation-dto.ts model/create-quotation-dto.ts
model/create-supplier-dto.ts model/create-supplier-dto.ts
model/create-user-dto.ts model/create-user-dto.ts
model/get-customer-dto.ts
model/get-deliverer-dto.ts model/get-deliverer-dto.ts
model/get-delivery-note-dto.ts model/get-delivery-note-dto.ts
model/get-price-dto.ts model/get-price-dto.ts
+4 -1
View File
@@ -1,3 +1,6 @@
export * from './customers.service';
import {CustomersService} from './customers.service';
export * from './deliverers.service'; export * from './deliverers.service';
import {DeliverersService} from './deliverers.service'; import {DeliverersService} from './deliverers.service';
@@ -31,4 +34,4 @@ import {WarehouseproductsService} from './warehouseproducts.service';
export * from './warehouses.service'; export * from './warehouses.service';
import {WarehousesService} 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];
@@ -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<Array<GetCustomerDto>>;
public getAllCustomersEndpoint(observe?: 'response', reportProgress?: boolean, options?: {
httpHeaderAccept?: 'application/json',
context?: HttpContext,
transferCache?: boolean
}): Observable<HttpResponse<Array<GetCustomerDto>>>;
public getAllCustomersEndpoint(observe?: 'events', reportProgress?: boolean, options?: {
httpHeaderAccept?: 'application/json',
context?: HttpContext,
transferCache?: boolean
}): Observable<HttpEvent<Array<GetCustomerDto>>>;
public getAllCustomersEndpoint(observe: any = 'body', reportProgress: boolean = false, options?: {
httpHeaderAccept?: 'application/json',
context?: HttpContext,
transferCache?: boolean
}): Observable<any> {
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<Array<GetCustomerDto>>('get', `${basePath}${localVarPath}`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
...(withCredentials ? {withCredentials} : {}),
headers: localVarHeaders,
observe: observe,
...(localVarTransferCache !== undefined ? {transferCache: localVarTransferCache} : {}),
reportProgress: reportProgress
}
);
}
}
@@ -13,6 +13,8 @@ import {CreateProductQuotationDto} from './create-product-quotation-dto';
export interface CreateQuotationDto { export interface CreateQuotationDto {
message?: string | null; message?: string | null;
conditionsSale?: string | null; conditionsSale?: string | null;
customerId?: number;
supplierId?: number;
products?: Array<CreateProductQuotationDto> | null; products?: Array<CreateProductQuotationDto> | null;
} }
@@ -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;
}
+1
View File
@@ -10,6 +10,7 @@ export * from './create-purchase-product-dto';
export * from './create-quotation-dto'; export * from './create-quotation-dto';
export * from './create-supplier-dto'; export * from './create-supplier-dto';
export * from './create-user-dto'; export * from './create-user-dto';
export * from './get-customer-dto';
export * from './get-deliverer-dto'; export * from './get-deliverer-dto';
export * from './get-delivery-note-dto'; export * from './get-delivery-note-dto';
export * from './get-price-dto'; export * from './get-price-dto';