added suppr and edit modal for supplier price
This commit is contained in:
@@ -45,7 +45,7 @@
|
|||||||
<div class="flex items-center justify-center space-x-2">
|
<div class="flex items-center justify-center space-x-2">
|
||||||
<nz-icon nzType="edit" nzTheme="outline"
|
<nz-icon nzType="edit" nzTheme="outline"
|
||||||
class="cursor-pointer text-gray-600 hover:text-gray-900"
|
class="cursor-pointer text-gray-600 hover:text-gray-900"
|
||||||
(click)="openEditProductModal(product)"></nz-icon>
|
(click)="openEditProductModal(product, supplier.id)"></nz-icon>
|
||||||
<nz-divider nzType="vertical"></nz-divider>
|
<nz-divider nzType="vertical"></nz-divider>
|
||||||
<nz-icon nzType="delete" nzTheme="outline" class="cursor-pointer text-red-600 hover:text-red-800"
|
<nz-icon nzType="delete" nzTheme="outline" class="cursor-pointer text-red-600 hover:text-red-800"
|
||||||
(click)="deleteProduct(product.productId, product.supplierId)"></nz-icon>
|
(click)="deleteProduct(product.productId, product.supplierId)"></nz-icon>
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
|
|
||||||
<div class="hidden">
|
<div class="hidden">
|
||||||
<app-modal-nav #productModal nameIcon="edit" [name]="'Modifier les prix des fournisseurs'"
|
<app-modal-nav #productModal nameIcon="edit" [name]="'Modifier les prix des fournisseurs'"
|
||||||
(ok)="onModalProductOk(selectedProduct?.id, selectedSupplier?.id, priceForm, productModal)"
|
(ok)="onModalProductOk(selectedProduct?.productId, selectedProductSupplierId, priceForm, productModal)"
|
||||||
(cancel)="onModalCancel(productModal)">
|
(cancel)="onModalCancel(productModal)">
|
||||||
<app-price-form #priceForm [price]="selectedProduct"></app-price-form>
|
<app-price-form #priceForm [price]="selectedProduct"></app-price-form>
|
||||||
</app-modal-nav>
|
</app-modal-nav>
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export class SupplierTable implements OnInit {
|
|||||||
productModal = viewChild.required<ModalNav>('productModal');
|
productModal = viewChild.required<ModalNav>('productModal');
|
||||||
selectedSupplier: GetSupplierDto | null = null;
|
selectedSupplier: GetSupplierDto | null = null;
|
||||||
selectedProduct: GetPriceDto | null = null;
|
selectedProduct: GetPriceDto | null = null;
|
||||||
|
selectedProductSupplierId: number | null = null;
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
await this.fetchSuppliers();
|
await this.fetchSuppliers();
|
||||||
@@ -82,8 +83,9 @@ export class SupplierTable implements OnInit {
|
|||||||
this.supplierModal().showModal();
|
this.supplierModal().showModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
openEditProductModal(product: GetPriceDto) {
|
openEditProductModal(product: GetPriceDto, supplierId: number) {
|
||||||
this.selectedProduct = { ...product };
|
this.selectedProduct = { ...product };
|
||||||
|
this.selectedProductSupplierId = supplierId;
|
||||||
this.productModal().showModal();
|
this.productModal().showModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,11 +100,14 @@ export class SupplierTable implements OnInit {
|
|||||||
|
|
||||||
async onModalProductOk(
|
async onModalProductOk(
|
||||||
productId: number | undefined,
|
productId: number | undefined,
|
||||||
supplierId: number | undefined,
|
supplierId: number | null | undefined,
|
||||||
updateProductComponent: PriceForm,
|
updateProductComponent: PriceForm,
|
||||||
modal: ModalNav
|
modal: ModalNav
|
||||||
) {
|
) {
|
||||||
if (!productId || !supplierId || !this.selectedProduct) return;
|
if (productId == null || supplierId == null || !this.selectedProduct) {
|
||||||
|
this.notificationService.error('Erreur', 'Identifiants produit/fournisseur manquants');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await this.editPrice(productId, supplierId, updateProductComponent);
|
await this.editPrice(productId, supplierId, updateProductComponent);
|
||||||
updateProductComponent.priceForm.reset();
|
updateProductComponent.priceForm.reset();
|
||||||
@@ -119,7 +124,6 @@ export class SupplierTable implements OnInit {
|
|||||||
this.notificationService.error('Erreur', 'Erreur d\'écriture dans le formulaire');
|
this.notificationService.error('Erreur', 'Erreur d\'écriture dans le formulaire');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const formValue = updateProductComponent.priceForm.getRawValue();
|
const formValue = updateProductComponent.priceForm.getRawValue();
|
||||||
const body = {
|
const body = {
|
||||||
@@ -127,9 +131,6 @@ export class SupplierTable implements OnInit {
|
|||||||
supplierId,
|
supplierId,
|
||||||
sellingPrice: Number(formValue.price),
|
sellingPrice: Number(formValue.price),
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('PATCH body =>', body);
|
|
||||||
|
|
||||||
await firstValueFrom(this.pricesService.patchPriceEndpoint(productId, supplierId, body));
|
await firstValueFrom(this.pricesService.patchPriceEndpoint(productId, supplierId, body));
|
||||||
this.notificationService.success('Success', 'Prix modifié');
|
this.notificationService.success('Success', 'Prix modifié');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user