Added supplier in purchase order form
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
import {Component, inject, OnInit, signal} from '@angular/core';
|
||||
import {Component, input} from '@angular/core';
|
||||
import {FormArray, FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||
import {GetProductDto, GetSupplierDto, SuppliersService} from "../../services/api";
|
||||
import {GetProductDto, GetSupplierDto} from "../../services/api";
|
||||
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
|
||||
import {NzFormControlComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
||||
import {NzFlexDirective} from "ng-zorro-antd/flex";
|
||||
import {NzTableComponent} from "ng-zorro-antd/table";
|
||||
import {NzInputNumberComponent} from "ng-zorro-antd/input-number";
|
||||
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
|
||||
@Component({
|
||||
selector: 'app-add-product-supplier-form',
|
||||
@@ -27,26 +25,13 @@ import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
templateUrl: './add-product-supplier-form.html',
|
||||
styleUrl: './add-product-supplier-form.css',
|
||||
})
|
||||
export class AddProductSupplierForm implements OnInit {
|
||||
export class AddProductSupplierForm {
|
||||
addProductForm: FormGroup = new FormGroup({
|
||||
supplierId: new FormControl<number>(null, Validators.required),
|
||||
lines: new FormArray([], Validators.required),
|
||||
});
|
||||
|
||||
private suppliersServices = inject(SuppliersService);
|
||||
private notificationService = inject(NzNotificationService);
|
||||
|
||||
suppliers = signal<GetSupplierDto[]>([]);
|
||||
|
||||
async ngOnInit() {
|
||||
try {
|
||||
const suppliers = await firstValueFrom(this.suppliersServices.getAllSuppliersEndpoint());
|
||||
this.suppliers.set(suppliers);
|
||||
}
|
||||
catch {
|
||||
this.notificationService.error('Erreur', 'Erreur de communication avec l\'API');
|
||||
}
|
||||
}
|
||||
suppliers = input.required<GetSupplierDto[]>();
|
||||
|
||||
get lines(): FormArray {
|
||||
return this.addProductForm.get('lines') as FormArray;
|
||||
|
||||
@@ -9,6 +9,20 @@
|
||||
</nz-form-control>
|
||||
</nz-form-item>
|
||||
|
||||
<nz-form-item nz-flex>
|
||||
<nz-form-label nzSpan="12" nzRequired>
|
||||
Fournisseur
|
||||
</nz-form-label>
|
||||
|
||||
<nz-form-control nzSpan="12" nzErrorTip="Ce champ est requis">
|
||||
<nz-select formControlName="supplierId" nzPlaceHolder="Choisir un fournisseur" nzShowSearch>
|
||||
@for (supplier of suppliers(); track supplier.id){
|
||||
<nz-option [nzLabel]="supplier.name" [nzValue]="supplier.id"></nz-option>
|
||||
}
|
||||
</nz-select>
|
||||
</nz-form-control>
|
||||
</nz-form-item>
|
||||
|
||||
<div class="overflow-x-auto">
|
||||
<nz-table [nzBordered]="true" class="mx-auto text-center">
|
||||
<thead>
|
||||
@@ -18,7 +32,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody formArrayName="lines">
|
||||
@for (line of lines.controls.slice(); let i = $index; track i) {
|
||||
@for (line of lines.controls; let i = $index; track i) {
|
||||
<tr [formGroupName]="i" class="text-center">
|
||||
<td class="text-center">{{ line.value.name }}</td>
|
||||
<td class="text-center">
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {Component, input} from '@angular/core';
|
||||
import {FormBuilder, FormGroup, FormArray, Validators, ReactiveFormsModule, FormControl} from '@angular/forms';
|
||||
import {GetProductDto} from '../../services/api';
|
||||
import {GetProductDto, GetSupplierDto} from '../../services/api';
|
||||
import {NzTableComponent} from "ng-zorro-antd/table";
|
||||
import {NzInputNumberComponent} from "ng-zorro-antd/input-number";
|
||||
import {NzColDirective} from "ng-zorro-antd/grid";
|
||||
import {NzFlexDirective} from "ng-zorro-antd/flex";
|
||||
import {NzFormControlComponent, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
||||
import {NzInputDirective} from "ng-zorro-antd/input";
|
||||
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
|
||||
|
||||
@Component({
|
||||
selector: 'app-create-purchaseorder-form',
|
||||
@@ -22,12 +23,17 @@ import {NzInputDirective} from "ng-zorro-antd/input";
|
||||
NzFormItemComponent,
|
||||
NzFormLabelComponent,
|
||||
NzInputDirective,
|
||||
NzOptionComponent,
|
||||
NzSelectComponent,
|
||||
]
|
||||
})
|
||||
export class CreatePurchaseorderForm {
|
||||
suppliers = input.required<GetSupplierDto[]>();
|
||||
|
||||
createPurchaseOrderForm: FormGroup = new FormGroup({
|
||||
purchaseConditions: new FormControl<string | null>(null, Validators.required),
|
||||
lines: new FormArray([], Validators.required),
|
||||
supplierId: new FormControl<number>(null, Validators.required),
|
||||
})
|
||||
|
||||
get lines(): FormArray {
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody formArrayName="lines">
|
||||
@for (line of lines.controls.slice(); let i = $index; track i) {
|
||||
@for (line of lines.controls; let i = $index; track i) {
|
||||
<tr [formGroupName]="i" class="text-center">
|
||||
<td class="text-center">{{ line.value.name }}</td>
|
||||
<td class="text-center">
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
name="Créer un bon de commande"
|
||||
size="35%"
|
||||
class="ml-4">
|
||||
<app-create-purchaseorder-form #purchaseOrderForm></app-create-purchaseorder-form>
|
||||
<app-create-purchaseorder-form #purchaseOrderForm [suppliers]="suppliers()"></app-create-purchaseorder-form>
|
||||
</app-modal-button>
|
||||
|
||||
<app-modal-button #modalButtonQuotation
|
||||
@@ -30,7 +30,7 @@
|
||||
(click)="openSupplierForm()"
|
||||
(ok)="onModalSupplierOk()"
|
||||
(cancel)="onModalSupplierCancel()">
|
||||
<app-add-product-supplier-form #supplierForm></app-add-product-supplier-form>
|
||||
<app-add-product-supplier-form #supplierForm [suppliers]="suppliers()"></app-add-product-supplier-form>
|
||||
</app-modal-button>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import {Component, inject, signal, viewChild} from '@angular/core';
|
||||
import {Component, inject, OnInit, signal, viewChild} from '@angular/core';
|
||||
import {StockTable} from "../../components/stock-table/stock-table";
|
||||
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 {CreatePriceDto, PurchaseordersService, QuotationsService, SuppliersService} from "../../services/api";
|
||||
import {
|
||||
GetSupplierDto,
|
||||
PurchaseordersService,
|
||||
QuotationsService,
|
||||
SuppliersService
|
||||
} from "../../services/api";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
import {CreateQuotationForm} from "../../components/create-quotation-form/create-quotation-form";
|
||||
import {AddProductSupplierForm} from "../../components/add-product-supplier-form/add-product-supplier-form";
|
||||
@@ -21,7 +26,7 @@ import {AddProductSupplierForm} from "../../components/add-product-supplier-form
|
||||
styleUrl: './stock.css',
|
||||
})
|
||||
|
||||
export class Stock {
|
||||
export class Stock implements OnInit {
|
||||
createPurchaseOrder = viewChild.required<CreatePurchaseorderForm>('purchaseOrderForm');
|
||||
createQuotation = viewChild.required<CreateQuotationForm>('quotationForm');
|
||||
addProduct = viewChild.required<AddProductSupplierForm>('supplierForm');
|
||||
@@ -35,9 +40,20 @@ export class Stock {
|
||||
private notificationService = inject(NzNotificationService);
|
||||
|
||||
products = signal([]);
|
||||
suppliers = signal<GetSupplierDto[]>([]);
|
||||
|
||||
productIds = [];
|
||||
|
||||
async ngOnInit() {
|
||||
try {
|
||||
const suppliers = await firstValueFrom(this.suppliersService.getAllSuppliersEndpoint());
|
||||
this.suppliers.set(suppliers);
|
||||
}
|
||||
catch {
|
||||
this.notificationService.error('Erreur', 'Erreur de communication avec l\'API');
|
||||
}
|
||||
}
|
||||
|
||||
getSelectedProducts() {
|
||||
return this.products().filter(x => this.productIds.includes(x.id));
|
||||
}
|
||||
@@ -77,8 +93,6 @@ export class Stock {
|
||||
products: orderLines
|
||||
};
|
||||
|
||||
console.log(purchaseOrder);
|
||||
|
||||
try {
|
||||
await firstValueFrom(this.purchaseOrdersService.createPurchaseOrder(purchaseOrder));
|
||||
this.notificationService.success('Succès', 'Bon de commande créé');
|
||||
|
||||
Reference in New Issue
Block a user