From 8124d83e791f923ce8613da27b6fcf298c5c855d Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Sat, 13 Dec 2025 12:10:51 +0100 Subject: [PATCH] added edit quantity function --- .../purchase-order-table.html | 16 +++-- .../purchase-order-table.ts | 66 +++++++++++++++++-- .../quantity-form/quantity-form.css | 0 .../quantity-form/quantity-form.html | 11 ++++ .../components/quantity-form/quantity-form.ts | 40 +++++++++++ src/app/services/api/.openapi-generator/FILES | 2 + .../api/api/purchaseorders.service.ts | 66 +++++++++++++++++++ .../api/model/create-purchase-order-dto.ts | 17 +++++ .../create-purchase-order-product-dto.ts | 16 +++++ .../api/model/get-purchase-order-dto.ts | 2 +- .../api/model/get-purchase-product-dto.ts | 2 +- src/app/services/api/model/models.ts | 2 + 12 files changed, 228 insertions(+), 12 deletions(-) create mode 100644 src/app/components/quantity-form/quantity-form.css create mode 100644 src/app/components/quantity-form/quantity-form.html create mode 100644 src/app/components/quantity-form/quantity-form.ts create mode 100644 src/app/services/api/model/create-purchase-order-dto.ts create mode 100644 src/app/services/api/model/create-purchase-order-product-dto.ts diff --git a/src/app/components/purchase-order-table/purchase-order-table.html b/src/app/components/purchase-order-table/purchase-order-table.html index 7887718..97c9acd 100644 --- a/src/app/components/purchase-order-table/purchase-order-table.html +++ b/src/app/components/purchase-order-table/purchase-order-table.html @@ -32,7 +32,7 @@ - @for (product of purchaseOrder.getPurchaseProductDto; track product.productId) { + @for (product of purchaseOrder.products; track product.productId) { {{product.productName}} {{product.productReferences}} @@ -40,9 +40,9 @@ {{product.quantity}}
-
- -
+ + +
@@ -54,7 +54,7 @@
- + @@ -74,4 +74,10 @@ +
+ + \ No newline at end of file diff --git a/src/app/components/purchase-order-table/purchase-order-table.ts b/src/app/components/purchase-order-table/purchase-order-table.ts index 4e48c21..1772417 100644 --- a/src/app/components/purchase-order-table/purchase-order-table.ts +++ b/src/app/components/purchase-order-table/purchase-order-table.ts @@ -5,12 +5,16 @@ import {NzIconDirective} from "ng-zorro-antd/icon"; import {NzTableComponent} from "ng-zorro-antd/table"; import {PurchaseOrderForm} from "../purchase-order-form/purchase-order-form"; import {ModalButton} from "../modal-button/modal-button"; -import {GetPurchaseOrderDto, GetQuotationDto, PurchaseordersService} from "../../services/api"; +import { + GetPurchaseOrderDto, + GetPurchaseProductDto, + PurchaseordersService, + PurchaseproductsService +} from "../../services/api"; import {NzNotificationService} from "ng-zorro-antd/notification"; import {firstValueFrom} from "rxjs"; import {FileService} from "../../services/file.service"; -import {QuotationForm} from "../quotation-form/quotation-form"; -import {DelivererForm} from "../deliverer-form/deliverer-form"; +import {QuantityForm} from "../quantity-form/quantity-form"; @Component({ selector: 'app-purchase-order-table', @@ -21,7 +25,7 @@ import {DelivererForm} from "../deliverer-form/deliverer-form"; NzTableComponent, PurchaseOrderForm, ModalButton, - DelivererForm, + QuantityForm, ], templateUrl: './purchase-order-table.html', styleUrl: './purchase-order-table.css', @@ -30,9 +34,11 @@ export class PurchaseOrderTable implements OnInit { private purchaseOrdersService = inject(PurchaseordersService); private notificationService = inject(NzNotificationService); private fileService = inject(FileService); + private purchaseProductService = inject(PurchaseproductsService) purchaseOrders = signal([]); purchaseOrdersLoading = signal(false); modal = viewChild.required('modalNav'); + modalQuantity = viewChild.required('modalQuantity'); async ngOnInit() { await this.fetchPurchaseOrder(); @@ -111,6 +117,43 @@ export class PurchaseOrderTable implements OnInit { } } + async deleteProduct(productId: number, purchaseOrderId: number) { + this.purchaseOrdersLoading.set(true) + try { + await firstValueFrom(this.purchaseProductService.deletePurchaseProductEndpoint(productId, purchaseOrderId)) + this.notificationService.success( + 'Success', + 'Suppression effectuée' + ) + } catch (e) { + this.notificationService.error( + 'Erreur', + 'Impossible de supprimer la ligne' + ) + } + this.purchaseOrdersLoading.set(false) + await this.fetchPurchaseOrder(); + } + + async editQuantity(productId: number, purchaseOrderId: number, updateQuantityComponent: QuantityForm) { + if (updateQuantityComponent.quantityForm.invalid) { + this.notificationService.error( + 'Erreur', + 'Erreur d\'écriture dans le formulaire' + ) + return; + } + + try { + const quantity = updateQuantityComponent.quantityForm.getRawValue(); + await firstValueFrom(this.purchaseProductService.patchPurchaseProductQuantityEndpoint(productId, purchaseOrderId, quantity)) + + this.notificationService.success('Success', 'Quantité modifiée') + } catch (e) { + this.notificationService.error('Erreur', 'Erreur lors de la modification') + } + } + selectedPurchaseOrder: GetPurchaseOrderDto | null = null; openEditModal(purchaseOrder: GetPurchaseOrderDto) { this.selectedPurchaseOrder = { ...purchaseOrder }; @@ -130,5 +173,18 @@ export class PurchaseOrderTable implements OnInit { modal.isVisible = false; } - protected readonly PurchaseOrderForm = PurchaseOrderForm; + selectedQuantity: GetPurchaseProductDto | null = null; + openEditQuantityModal(quantity: GetPurchaseProductDto) { + this.selectedQuantity = { ...quantity }; + this.modalQuantity().showModal(); + } + + async onModalQuantityOk(productId: number, purchaseOrderId: number, updateQuantityComponent: QuantityForm, modal: ModalNav) { + if (!this.selectedQuantity) return; + + await this.editQuantity(productId, purchaseOrderId, updateQuantityComponent); + updateQuantityComponent.quantityForm.reset(); + modal.isVisible = false; + await this.fetchPurchaseOrder(); + } } diff --git a/src/app/components/quantity-form/quantity-form.css b/src/app/components/quantity-form/quantity-form.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/quantity-form/quantity-form.html b/src/app/components/quantity-form/quantity-form.html new file mode 100644 index 0000000..0d987c5 --- /dev/null +++ b/src/app/components/quantity-form/quantity-form.html @@ -0,0 +1,11 @@ +
+ + + Quantité + + + + + + +
diff --git a/src/app/components/quantity-form/quantity-form.ts b/src/app/components/quantity-form/quantity-form.ts new file mode 100644 index 0000000..fb3e87c --- /dev/null +++ b/src/app/components/quantity-form/quantity-form.ts @@ -0,0 +1,40 @@ +import {Component, effect, input} from '@angular/core'; +import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms"; +import {NzColDirective} from "ng-zorro-antd/grid"; +import {NzFlexDirective} from "ng-zorro-antd/flex"; +import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; +import {NzInputDirective} from "ng-zorro-antd/input"; +import {GetDelivererDto, GetPurchaseProductDto} from "../../services/api"; + +@Component({ + selector: 'app-quantity-form', + imports: [ + FormsModule, + NzColDirective, + NzFlexDirective, + NzFormControlComponent, + NzFormDirective, + NzFormItemComponent, + NzFormLabelComponent, + NzInputDirective, + ReactiveFormsModule + ], + templateUrl: './quantity-form.html', + styleUrl: './quantity-form.css', +}) +export class QuantityForm { + quantityForm: FormGroup = new FormGroup({ + quantity: new FormControl(null, [Validators.required]) + }) + + quantity= input(); + constructor() { + effect(() => { + if (this.quantity()) { + this.quantityForm.patchValue({ + quantity: this.quantity().quantity + }); + } + }); + } +} diff --git a/src/app/services/api/.openapi-generator/FILES b/src/app/services/api/.openapi-generator/FILES index a90289b..0c304de 100644 --- a/src/app/services/api/.openapi-generator/FILES +++ b/src/app/services/api/.openapi-generator/FILES @@ -23,6 +23,8 @@ model/connect-user-dto.ts model/create-deliverer-dto.ts model/create-delivery-note-dto.ts model/create-price-dto.ts +model/create-purchase-order-dto.ts +model/create-purchase-order-product-dto.ts model/create-purchase-product-dto.ts model/create-quotation-product-dto.ts model/create-setting-dto.ts diff --git a/src/app/services/api/api/purchaseorders.service.ts b/src/app/services/api/api/purchaseorders.service.ts index 117aff2..87a17a6 100644 --- a/src/app/services/api/api/purchaseorders.service.ts +++ b/src/app/services/api/api/purchaseorders.service.ts @@ -16,6 +16,8 @@ import { HttpClient, HttpHeaders, HttpParams, import { CustomHttpParameterCodec } from '../encoder'; import { Observable } from 'rxjs'; +// @ts-ignore +import { CreatePurchaseOrderDto } from '../model/create-purchase-order-dto'; // @ts-ignore import { GetPurchaseOrderDto } from '../model/get-purchase-order-dto'; // @ts-ignore @@ -37,6 +39,70 @@ export class PurchaseordersService extends BaseService { super(basePath, configuration); } + /** + * @endpoint post /API/purchaseOrders + * @param createPurchaseOrderDto + * @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 createPurchaseOrder(createPurchaseOrderDto: CreatePurchaseOrderDto, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; + public createPurchaseOrder(createPurchaseOrderDto: CreatePurchaseOrderDto, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public createPurchaseOrder(createPurchaseOrderDto: CreatePurchaseOrderDto, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public createPurchaseOrder(createPurchaseOrderDto: CreatePurchaseOrderDto, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + if (createPurchaseOrderDto === null || createPurchaseOrderDto === undefined) { + throw new Error('Required parameter createPurchaseOrderDto was null or undefined when calling createPurchaseOrder.'); + } + + 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; + + + // to determine the Content-Type header + const consumes: string[] = [ + 'application/json' + ]; + const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes); + if (httpContentTypeSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Content-Type', httpContentTypeSelected); + } + + 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/purchaseOrders`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request('post', `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + body: createPurchaseOrderDto, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), + reportProgress: reportProgress + } + ); + } + /** * @endpoint delete /API/purchaseOrders/{id} * @param id diff --git a/src/app/services/api/model/create-purchase-order-dto.ts b/src/app/services/api/model/create-purchase-order-dto.ts new file mode 100644 index 0000000..0b3b3c5 --- /dev/null +++ b/src/app/services/api/model/create-purchase-order-dto.ts @@ -0,0 +1,17 @@ +/** + * PyroFetes + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { CreatePurchaseOrderProductDto } from './create-purchase-order-product-dto'; + + +export interface CreatePurchaseOrderDto { + purchaseConditions?: string | null; + products?: Array | null; +} + diff --git a/src/app/services/api/model/create-purchase-order-product-dto.ts b/src/app/services/api/model/create-purchase-order-product-dto.ts new file mode 100644 index 0000000..256d725 --- /dev/null +++ b/src/app/services/api/model/create-purchase-order-product-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 CreatePurchaseOrderProductDto { + productId?: number; + quantity?: number; +} + diff --git a/src/app/services/api/model/get-purchase-order-dto.ts b/src/app/services/api/model/get-purchase-order-dto.ts index 9cde421..96950b2 100644 --- a/src/app/services/api/model/get-purchase-order-dto.ts +++ b/src/app/services/api/model/get-purchase-order-dto.ts @@ -13,6 +13,6 @@ import { GetPurchaseProductDto } from './get-purchase-product-dto'; export interface GetPurchaseOrderDto { id?: number; purchaseConditions?: string | null; - getPurchaseProductDto?: Array | null; + products?: Array | null; } diff --git a/src/app/services/api/model/get-purchase-product-dto.ts b/src/app/services/api/model/get-purchase-product-dto.ts index b7ad6ff..75b09fe 100644 --- a/src/app/services/api/model/get-purchase-product-dto.ts +++ b/src/app/services/api/model/get-purchase-product-dto.ts @@ -15,7 +15,7 @@ export interface GetPurchaseProductDto { productName?: string | null; productDuration?: number; productCaliber?: number; - productApprovalNumber?: number; + productApprovalNumber?: string | null; productWeight?: number; productNec?: number; productImage?: string | null; diff --git a/src/app/services/api/model/models.ts b/src/app/services/api/model/models.ts index d228c54..56ec3fb 100644 --- a/src/app/services/api/model/models.ts +++ b/src/app/services/api/model/models.ts @@ -2,6 +2,8 @@ export * from './connect-user-dto'; export * from './create-deliverer-dto'; export * from './create-delivery-note-dto'; export * from './create-price-dto'; +export * from './create-purchase-order-dto'; +export * from './create-purchase-order-product-dto'; export * from './create-purchase-product-dto'; export * from './create-quotation-product-dto'; export * from './create-setting-dto';