Fixed error to function to create purchase order
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<div class="flex mt-2">
|
||||
@if (productIds.length) {
|
||||
@if (productIds().length) {
|
||||
<app-modal-button #modalButtonPurchaseOrder
|
||||
(click)="openPurchaseOrderForm()"
|
||||
(ok)="onModalPurchaseOrderOk()"
|
||||
@@ -8,7 +8,10 @@
|
||||
name="Créer un bon de commande"
|
||||
size="35%"
|
||||
class="ml-4">
|
||||
<app-create-purchaseorder-form #purchaseOrderForm [suppliers]="suppliers()"></app-create-purchaseorder-form>
|
||||
<app-create-purchaseorder-form #purchaseOrderForm
|
||||
[suppliers]="suppliers()"
|
||||
[products]="selectedProducts()">
|
||||
</app-create-purchaseorder-form>
|
||||
</app-modal-button>
|
||||
|
||||
<app-modal-button #modalButtonQuotation
|
||||
@@ -19,7 +22,9 @@
|
||||
(click)="openQuotationForm()"
|
||||
(ok)="onModalQuotationOk()"
|
||||
(cancel)="onModalQuotationCancel()">
|
||||
<app-create-quotation-form #quotationForm></app-create-quotation-form>
|
||||
<app-create-quotation-form #quotationForm
|
||||
[products]="selectedProducts()">
|
||||
</app-create-quotation-form>
|
||||
</app-modal-button>
|
||||
|
||||
<app-modal-button #modalButtonSupplier
|
||||
@@ -30,13 +35,16 @@
|
||||
(click)="openSupplierForm()"
|
||||
(ok)="onModalSupplierOk()"
|
||||
(cancel)="onModalSupplierCancel()">
|
||||
<app-add-product-supplier-form #supplierForm [suppliers]="suppliers()"></app-add-product-supplier-form>
|
||||
<app-add-product-supplier-form #supplierForm
|
||||
[suppliers]="suppliers()"
|
||||
[products]="selectedProducts()">
|
||||
</app-add-product-supplier-form>
|
||||
</app-modal-button>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<app-stock-table (selectionChange)="productIds = $event"
|
||||
<app-stock-table (selectionChange)="onSelectionChange($event)"
|
||||
(productsTables)="products.set($event)">
|
||||
</app-stock-table>
|
||||
</div>
|
||||
@@ -4,6 +4,8 @@ import {ModalButton} from "../../components/modal-button/modal-button";
|
||||
import {CreatePurchaseorderForm} from "../../components/create-purchaseorder-form/create-purchaseorder-form";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {
|
||||
CreatePurchaseOrderDto,
|
||||
GetProductDto,
|
||||
GetSupplierDto,
|
||||
PurchaseordersService,
|
||||
QuotationsService,
|
||||
@@ -39,35 +41,36 @@ export class Stock implements OnInit {
|
||||
private suppliersService = inject(SuppliersService);
|
||||
private notificationService = inject(NzNotificationService);
|
||||
|
||||
products = signal([]);
|
||||
products = signal<GetProductDto[]>([]);
|
||||
suppliers = signal<GetSupplierDto[]>([]);
|
||||
selectedProducts = signal([]);
|
||||
|
||||
productIds = [];
|
||||
productIds = signal<number[]>([]);
|
||||
|
||||
async ngOnInit() {
|
||||
try {
|
||||
const suppliers = await firstValueFrom(this.suppliersService.getAllSuppliersEndpoint());
|
||||
this.suppliers.set(suppliers);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
this.notificationService.error('Erreur', 'Erreur de communication avec l\'API');
|
||||
}
|
||||
}
|
||||
|
||||
getSelectedProducts() {
|
||||
return this.products().filter(x => this.productIds.includes(x.id));
|
||||
onSelectionChange(ids: number[]) {
|
||||
this.productIds.set(ids);
|
||||
this.selectedProducts.set(this.products().filter(x => ids.includes(x.id)));
|
||||
}
|
||||
|
||||
openPurchaseOrderForm() {
|
||||
this.createPurchaseOrder().addProductToForm(this.getSelectedProducts());
|
||||
this.createPurchaseOrder().addProductToForm();
|
||||
}
|
||||
|
||||
openQuotationForm() {
|
||||
this.createQuotation().addProductToForm(this.getSelectedProducts());
|
||||
this.createQuotation().addProductToForm();
|
||||
}
|
||||
|
||||
openSupplierForm() {
|
||||
this.addProduct().addProductToForm(this.getSelectedProducts());
|
||||
this.addProduct().addProductToForm();
|
||||
}
|
||||
|
||||
async addPurchaseOrder() {
|
||||
@@ -88,9 +91,10 @@ export class Stock implements OnInit {
|
||||
return;
|
||||
}
|
||||
|
||||
const purchaseOrder = {
|
||||
purchaseConditions: form.get('purchaseConditions')!.value,
|
||||
products: orderLines
|
||||
const purchaseOrder: CreatePurchaseOrderDto = {
|
||||
purchaseConditions: form.value.purchaseConditions,
|
||||
products: orderLines,
|
||||
supplierId: form.value.supplierId
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -163,7 +167,8 @@ export class Stock implements OnInit {
|
||||
);
|
||||
|
||||
success++;
|
||||
} catch {}
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
this.notificationService.success('Succès', `${success} produits ajoutés`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user