Compare commits
2 Commits
e66c95a65e
...
7041c5335b
| Author | SHA1 | Date | |
|---|---|---|---|
| 7041c5335b | |||
| c20a0c5daf |
@@ -104,15 +104,7 @@ export class PurchaseOrderTable implements OnInit {
|
||||
try {
|
||||
const deliverer = delivererForm.choiceDelivererForm.getRawValue();
|
||||
|
||||
const today = new Date();
|
||||
const date = today.toISOString().split('T')[0]; // yyyy-mm-dd
|
||||
|
||||
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}`;
|
||||
const date = new Date().toISOString().split('T')[0]; // yyyy-mm-dd
|
||||
|
||||
let trackingValue = 'TRK-';
|
||||
const idStr = purchaseOrder.id?.toString() ?? '';
|
||||
@@ -129,8 +121,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 +131,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;
|
||||
|
||||
@@ -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.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user