From c20a0c5daf026f2cf82dcaa7d8059155883aaea7 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Wed, 27 May 2026 17:59:41 +0100 Subject: [PATCH] Added automatic generation in dashboard when employees start application to generate product under limit during absence --- .../purchase-order-table.ts | 7 +--- .../api/model/create-delivery-note-dto.ts | 2 -- src/app/services/stock.alert.ts | 34 +++++++++++++++++-- 3 files changed, 33 insertions(+), 10 deletions(-) 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 2e94905..2d87837 100644 --- a/src/app/components/purchase-order-table/purchase-order-table.ts +++ b/src/app/components/purchase-order-table/purchase-order-table.ts @@ -109,10 +109,6 @@ export class PurchaseOrderTable implements OnInit { const futureDate = new Date(today); futureDate.setMonth(today.getMonth() + 2); - const yyyy = futureDate.getFullYear(); - const mm = (futureDate.getMonth() + 1).toString().padStart(2, '0'); - const dd = futureDate.getDate().toString().padStart(2, '0'); - const estimateDate = `${yyyy}-${mm}-${dd}`; let trackingValue = 'TRK-'; const idStr = purchaseOrder.id?.toString() ?? ''; @@ -129,8 +125,6 @@ export class PurchaseOrderTable implements OnInit { const deliveryNoteDto: CreateDeliveryNoteDto = { trackingNumber: trackingValue, - expeditionDate: date, - estimateDeliveryDate: estimateDate, delivererId: deliverer.delivererId, productQuantities: productQuantities, supplierId: purchaseOrder.supplierId @@ -141,6 +135,7 @@ export class PurchaseOrderTable implements OnInit { } catch { this.notificationService.error('Erreur', 'Erreur lors du transfert'); } + this.onModalCancel(this.modalDeliverer()); this.purchaseOrdersLoading.set(false); } diff --git a/src/app/services/api/model/create-delivery-note-dto.ts b/src/app/services/api/model/create-delivery-note-dto.ts index 49498e7..52d718e 100644 --- a/src/app/services/api/model/create-delivery-note-dto.ts +++ b/src/app/services/api/model/create-delivery-note-dto.ts @@ -11,8 +11,6 @@ export interface CreateDeliveryNoteDto { trackingNumber?: string | null; - estimateDeliveryDate?: string; - expeditionDate?: string; delivererId?: number; supplierId?: number; productQuantities?: { [key: string]: number; } | null; diff --git a/src/app/services/stock.alert.ts b/src/app/services/stock.alert.ts index 9d9ed74..de81c50 100644 --- a/src/app/services/stock.alert.ts +++ b/src/app/services/stock.alert.ts @@ -1,5 +1,12 @@ import {inject, Injectable} from '@angular/core'; -import {GetProductDto, GetSupplierDto, PurchaseordersService, WarehouseproductsService} from "./api"; +import { + CreateDeliveryNoteDto, + DeliverynotesService, + GetProductDto, GetPurchaseOrderDto, + GetSupplierDto, + PurchaseordersService, + WarehouseproductsService +} from "./api"; import {NzNotificationService} from "ng-zorro-antd/notification"; import {firstValueFrom} from "rxjs"; @@ -8,6 +15,7 @@ import {firstValueFrom} from "rxjs"; }) export class StockAlert { private purchaseOrdersService = inject(PurchaseordersService); + private deliveryNotesService = inject(DeliverynotesService); private notificationsService = inject(NzNotificationService); private wareHousseProductsService = inject(WarehouseproductsService); @@ -50,7 +58,7 @@ export class StockAlert { ); try { - await firstValueFrom(this.purchaseOrdersService.createPurchaseOrder({ + const purchaseOrder: GetPurchaseOrderDto = await firstValueFrom(this.purchaseOrdersService.createPurchaseOrder({ purchaseConditions: "Non précisée - Commande automatique pour réapprovisionnement", supplierId: supplier.id, products: productsWithQuantity.map(x => { @@ -61,6 +69,28 @@ export class StockAlert { }; }) })); + + const date = new Date().toISOString().split('T')[0]; + + let trackingValue = 'TRK-AUTO-'; + const idStr = purchaseOrder.id?.toString() ?? ''; + if (idStr.length < 2) trackingValue += '00' + idStr + '-' + date; + else if (idStr.length < 3) trackingValue += '0' + idStr + '-' + date; + else trackingValue += idStr.substring(0, 3) + date.replace(/-/g, ''); + + const productQuantities: Record = {}; + purchaseOrder.products?.forEach(p => { + if (p.productId != null && p.quantity != null) { + productQuantities[p.productId] = p.quantity; + } + }); + + await firstValueFrom(this.deliveryNotesService.createDeliveryNoteEndpoint({ + trackingNumber: trackingValue, + supplierId: supplier.id, + delivererId: 1, + productQuantities: productQuantities + })); } catch { this.notificationsService.error('Erreur', 'Erreur lors de la génération du bon de commande.'); }