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 {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 {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
|
||||||
import {NzFormControlComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
import {NzFormControlComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
||||||
import {NzFlexDirective} from "ng-zorro-antd/flex";
|
import {NzFlexDirective} from "ng-zorro-antd/flex";
|
||||||
import {NzTableComponent} from "ng-zorro-antd/table";
|
import {NzTableComponent} from "ng-zorro-antd/table";
|
||||||
import {NzInputNumberComponent} from "ng-zorro-antd/input-number";
|
import {NzInputNumberComponent} from "ng-zorro-antd/input-number";
|
||||||
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
|
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
|
||||||
import {firstValueFrom} from "rxjs";
|
|
||||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-add-product-supplier-form',
|
selector: 'app-add-product-supplier-form',
|
||||||
@@ -27,26 +25,13 @@ import {NzNotificationService} from "ng-zorro-antd/notification";
|
|||||||
templateUrl: './add-product-supplier-form.html',
|
templateUrl: './add-product-supplier-form.html',
|
||||||
styleUrl: './add-product-supplier-form.css',
|
styleUrl: './add-product-supplier-form.css',
|
||||||
})
|
})
|
||||||
export class AddProductSupplierForm implements OnInit {
|
export class AddProductSupplierForm {
|
||||||
addProductForm: FormGroup = new FormGroup({
|
addProductForm: FormGroup = new FormGroup({
|
||||||
supplierId: new FormControl<number>(null, Validators.required),
|
supplierId: new FormControl<number>(null, Validators.required),
|
||||||
lines: new FormArray([], Validators.required),
|
lines: new FormArray([], Validators.required),
|
||||||
});
|
});
|
||||||
|
|
||||||
private suppliersServices = inject(SuppliersService);
|
suppliers = input.required<GetSupplierDto[]>();
|
||||||
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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get lines(): FormArray {
|
get lines(): FormArray {
|
||||||
return this.addProductForm.get('lines') as FormArray;
|
return this.addProductForm.get('lines') as FormArray;
|
||||||
|
|||||||
@@ -9,6 +9,20 @@
|
|||||||
</nz-form-control>
|
</nz-form-control>
|
||||||
</nz-form-item>
|
</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">
|
<div class="overflow-x-auto">
|
||||||
<nz-table [nzBordered]="true" class="mx-auto text-center">
|
<nz-table [nzBordered]="true" class="mx-auto text-center">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -18,7 +32,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody formArrayName="lines">
|
<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">
|
<tr [formGroupName]="i" class="text-center">
|
||||||
<td class="text-center">{{ line.value.name }}</td>
|
<td class="text-center">{{ line.value.name }}</td>
|
||||||
<td class="text-center">
|
<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 {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 {NzTableComponent} from "ng-zorro-antd/table";
|
||||||
import {NzInputNumberComponent} from "ng-zorro-antd/input-number";
|
import {NzInputNumberComponent} from "ng-zorro-antd/input-number";
|
||||||
import {NzColDirective} from "ng-zorro-antd/grid";
|
import {NzColDirective} from "ng-zorro-antd/grid";
|
||||||
import {NzFlexDirective} from "ng-zorro-antd/flex";
|
import {NzFlexDirective} from "ng-zorro-antd/flex";
|
||||||
import {NzFormControlComponent, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
import {NzFormControlComponent, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
||||||
import {NzInputDirective} from "ng-zorro-antd/input";
|
import {NzInputDirective} from "ng-zorro-antd/input";
|
||||||
|
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-create-purchaseorder-form',
|
selector: 'app-create-purchaseorder-form',
|
||||||
@@ -22,12 +23,17 @@ import {NzInputDirective} from "ng-zorro-antd/input";
|
|||||||
NzFormItemComponent,
|
NzFormItemComponent,
|
||||||
NzFormLabelComponent,
|
NzFormLabelComponent,
|
||||||
NzInputDirective,
|
NzInputDirective,
|
||||||
|
NzOptionComponent,
|
||||||
|
NzSelectComponent,
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class CreatePurchaseorderForm {
|
export class CreatePurchaseorderForm {
|
||||||
|
suppliers = input.required<GetSupplierDto[]>();
|
||||||
|
|
||||||
createPurchaseOrderForm: FormGroup = new FormGroup({
|
createPurchaseOrderForm: FormGroup = new FormGroup({
|
||||||
purchaseConditions: new FormControl<string | null>(null, Validators.required),
|
purchaseConditions: new FormControl<string | null>(null, Validators.required),
|
||||||
lines: new FormArray([], Validators.required),
|
lines: new FormArray([], Validators.required),
|
||||||
|
supplierId: new FormControl<number>(null, Validators.required),
|
||||||
})
|
})
|
||||||
|
|
||||||
get lines(): FormArray {
|
get lines(): FormArray {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody formArrayName="lines">
|
<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">
|
<tr [formGroupName]="i" class="text-center">
|
||||||
<td class="text-center">{{ line.value.name }}</td>
|
<td class="text-center">{{ line.value.name }}</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
name="Créer un bon de commande"
|
name="Créer un bon de commande"
|
||||||
size="35%"
|
size="35%"
|
||||||
class="ml-4">
|
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>
|
||||||
|
|
||||||
<app-modal-button #modalButtonQuotation
|
<app-modal-button #modalButtonQuotation
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
(click)="openSupplierForm()"
|
(click)="openSupplierForm()"
|
||||||
(ok)="onModalSupplierOk()"
|
(ok)="onModalSupplierOk()"
|
||||||
(cancel)="onModalSupplierCancel()">
|
(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>
|
</app-modal-button>
|
||||||
}
|
}
|
||||||
</div>
|
</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 {StockTable} from "../../components/stock-table/stock-table";
|
||||||
import {ModalButton} from "../../components/modal-button/modal-button";
|
import {ModalButton} from "../../components/modal-button/modal-button";
|
||||||
import {CreatePurchaseorderForm} from "../../components/create-purchaseorder-form/create-purchaseorder-form";
|
import {CreatePurchaseorderForm} from "../../components/create-purchaseorder-form/create-purchaseorder-form";
|
||||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
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 {firstValueFrom} from "rxjs";
|
||||||
import {CreateQuotationForm} from "../../components/create-quotation-form/create-quotation-form";
|
import {CreateQuotationForm} from "../../components/create-quotation-form/create-quotation-form";
|
||||||
import {AddProductSupplierForm} from "../../components/add-product-supplier-form/add-product-supplier-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',
|
styleUrl: './stock.css',
|
||||||
})
|
})
|
||||||
|
|
||||||
export class Stock {
|
export class Stock implements OnInit {
|
||||||
createPurchaseOrder = viewChild.required<CreatePurchaseorderForm>('purchaseOrderForm');
|
createPurchaseOrder = viewChild.required<CreatePurchaseorderForm>('purchaseOrderForm');
|
||||||
createQuotation = viewChild.required<CreateQuotationForm>('quotationForm');
|
createQuotation = viewChild.required<CreateQuotationForm>('quotationForm');
|
||||||
addProduct = viewChild.required<AddProductSupplierForm>('supplierForm');
|
addProduct = viewChild.required<AddProductSupplierForm>('supplierForm');
|
||||||
@@ -35,9 +40,20 @@ export class Stock {
|
|||||||
private notificationService = inject(NzNotificationService);
|
private notificationService = inject(NzNotificationService);
|
||||||
|
|
||||||
products = signal([]);
|
products = signal([]);
|
||||||
|
suppliers = signal<GetSupplierDto[]>([]);
|
||||||
|
|
||||||
productIds = [];
|
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() {
|
getSelectedProducts() {
|
||||||
return this.products().filter(x => this.productIds.includes(x.id));
|
return this.products().filter(x => this.productIds.includes(x.id));
|
||||||
}
|
}
|
||||||
@@ -77,8 +93,6 @@ export class Stock {
|
|||||||
products: orderLines
|
products: orderLines
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(purchaseOrder);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await firstValueFrom(this.purchaseOrdersService.createPurchaseOrder(purchaseOrder));
|
await firstValueFrom(this.purchaseOrdersService.createPurchaseOrder(purchaseOrder));
|
||||||
this.notificationService.success('Succès', 'Bon de commande créé');
|
this.notificationService.success('Succès', 'Bon de commande créé');
|
||||||
|
|||||||
Reference in New Issue
Block a user