added totalQuantity in stock page
This commit is contained in:
@@ -43,9 +43,8 @@
|
|||||||
<td>{{ product.caliber }}</td>
|
<td>{{ product.caliber }}</td>
|
||||||
<td>{{ product.weight }}</td>
|
<td>{{ product.weight }}</td>
|
||||||
<td>{{ product.duration }}</td>
|
<td>{{ product.duration }}</td>
|
||||||
<td> Quantité totale ??? </td>
|
<td>{{ product.totalQuantity }}</td>
|
||||||
<td>{{ product.minimalQuantity }}</td>
|
<td>{{ product.minimalQuantity }}</td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<div style="justify-content: center; display: flex">
|
<div style="justify-content: center; display: flex">
|
||||||
<nz-icon nzType="edit" nzTheme="outline" class="cursor-pointer" (click)="openEditModal(product)"></nz-icon>
|
<nz-icon nzType="edit" nzTheme="outline" class="cursor-pointer" (click)="openEditModal(product)"></nz-icon>
|
||||||
|
|||||||
@@ -6,10 +6,14 @@ import {StockForm} from "../stock-form/stock-form";
|
|||||||
import {NzDividerComponent} from "ng-zorro-antd/divider";
|
import {NzDividerComponent} from "ng-zorro-antd/divider";
|
||||||
import {FormsModule} from "@angular/forms";
|
import {FormsModule} from "@angular/forms";
|
||||||
import {NzCheckboxComponent} from "ng-zorro-antd/checkbox";
|
import {NzCheckboxComponent} from "ng-zorro-antd/checkbox";
|
||||||
import {GetProductDto, ProductsService} from "../../services/api";
|
import {GetProductDto, ProductsService, WarehouseproductsService} from "../../services/api";
|
||||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||||
import {firstValueFrom} from "rxjs";
|
import {firstValueFrom} from "rxjs";
|
||||||
|
|
||||||
|
interface ProductWithQuantity extends GetProductDto {
|
||||||
|
totalQuantity?: number;
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-stock-table',
|
selector: 'app-stock-table',
|
||||||
imports: [
|
imports: [
|
||||||
@@ -28,8 +32,9 @@ import {firstValueFrom} from "rxjs";
|
|||||||
|
|
||||||
export class StockTable implements OnInit {
|
export class StockTable implements OnInit {
|
||||||
private productsService = inject(ProductsService);
|
private productsService = inject(ProductsService);
|
||||||
|
private wareHousseProductsService = inject(WarehouseproductsService)
|
||||||
private notificationService = inject(NzNotificationService)
|
private notificationService = inject(NzNotificationService)
|
||||||
products = signal<GetProductDto[]>([]);
|
products = signal<ProductWithQuantity[]>([]);
|
||||||
productsLoading = signal<boolean>(false);
|
productsLoading = signal<boolean>(false);
|
||||||
updateProduct = viewChild.required<StockForm>('stockForm');
|
updateProduct = viewChild.required<StockForm>('stockForm');
|
||||||
modal = viewChild.required<ModalNav>('modalNav');
|
modal = viewChild.required<ModalNav>('modalNav');
|
||||||
@@ -84,19 +89,43 @@ export class StockTable implements OnInit {
|
|||||||
await this.fetchProducts();
|
await this.fetchProducts();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchProducts() {
|
async fetchTotalQuantity(product: ProductWithQuantity) {
|
||||||
this.productsLoading.set(true)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const products = await firstValueFrom(this.productsService.getAllProductsEndpoint())
|
const res = await firstValueFrom(
|
||||||
this.products.set(products);
|
this.wareHousseProductsService.getTotalQuantityEndpoint(product.id)
|
||||||
|
);
|
||||||
|
product.totalQuantity = res.totalQuantity;
|
||||||
|
} catch (e) {
|
||||||
|
product.totalQuantity = 0;
|
||||||
|
this.notificationService.error(
|
||||||
|
'Erreur',
|
||||||
|
`Impossible de récupérer la quantité pour le produit n°${product.id}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fetchProducts() {
|
||||||
|
this.productsLoading.set(true);
|
||||||
|
try {
|
||||||
|
const products = await firstValueFrom(this.productsService.getAllProductsEndpoint());
|
||||||
|
|
||||||
|
// transforme chaque produit en ProductWithQuantity
|
||||||
|
const productsWithQuantity: ProductWithQuantity[] = products.map(p => ({ ...p }));
|
||||||
|
|
||||||
|
this.products.set(productsWithQuantity);
|
||||||
|
|
||||||
|
// récupérer la quantité pour chaque produit en parallèle
|
||||||
|
await Promise.all(productsWithQuantity.map(p => this.fetchTotalQuantity(p)));
|
||||||
|
|
||||||
|
// déclencher la mise à jour du signal
|
||||||
|
this.products.set([...productsWithQuantity]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.notificationService.error(
|
this.notificationService.error(
|
||||||
'Erreur',
|
'Erreur',
|
||||||
'Erreur de communication avec l\'API'
|
'Erreur de communication avec l\'API'
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
this.productsLoading.set(false)
|
this.productsLoading.set(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(productId:number) {
|
async delete(productId:number) {
|
||||||
|
|||||||
Reference in New Issue
Block a user