Added automatic generation in dashboard when employees start application to generate product under limit during absence

This commit is contained in:
2026-05-27 17:59:41 +01:00
parent e66c95a65e
commit c20a0c5daf
3 changed files with 33 additions and 10 deletions
@@ -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);
}
@@ -11,8 +11,6 @@
export interface CreateDeliveryNoteDto {
trackingNumber?: string | null;
estimateDeliveryDate?: string;
expeditionDate?: string;
delivererId?: number;
supplierId?: number;
productQuantities?: { [key: string]: number; } | null;
+32 -2
View File
@@ -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<number, number> = {};
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.');
}