Fixed error to function to create quotation
This commit is contained in:
@@ -72,9 +72,8 @@ export class CreatePurchaseorderForm {
|
||||
);
|
||||
});
|
||||
|
||||
const bestSupplier = this.getBestSupplier();
|
||||
this.createPurchaseOrderForm.patchValue({
|
||||
supplierId: bestSupplier.id,
|
||||
supplierId: this.getBestSupplier().id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,20 @@
|
||||
<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-label nzSpan="12" nzRequired>
|
||||
Message
|
||||
@@ -15,7 +31,7 @@
|
||||
</nz-form-label>
|
||||
|
||||
<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-item>
|
||||
|
||||
|
||||
@@ -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<GetSupplierDto[]>();
|
||||
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({
|
||||
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),
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
(ok)="onModalQuotationOk()"
|
||||
(cancel)="onModalQuotationCancel()">
|
||||
<app-create-quotation-form #quotationForm
|
||||
[suppliers]="suppliers()"
|
||||
[products]="selectedProducts()">
|
||||
</app-create-quotation-form>
|
||||
</app-modal-button>
|
||||
|
||||
@@ -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.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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 {
|
||||
message?: string | null;
|
||||
conditionsSale?: string | null;
|
||||
customerId?: number;
|
||||
supplierId?: number;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user