added create quotation function and edit end delete product in quotation table
This commit is contained in:
@@ -11,8 +11,15 @@
|
||||
<app-create-purchaseorder-form #purchaseOrderForm></app-create-purchaseorder-form>
|
||||
</app-modal-button>
|
||||
|
||||
<app-modal-button #modalButtonQuotation type="default" name="Créer un devis" size="35%" class="ml-4" (click)="test()">
|
||||
<app-quotation-form #quotationForm></app-quotation-form>
|
||||
<app-modal-button #modalButtonQuotation
|
||||
type="default"
|
||||
name="Créer un devis"
|
||||
size="35%"
|
||||
class="ml-4"
|
||||
(click)="openQuotationForm()"
|
||||
(ok)="onModalQuotationOk()"
|
||||
(cancel)="onModalQuotationCancel()">
|
||||
<app-create-quotation-form #quotationForm></app-create-quotation-form>
|
||||
</app-modal-button>
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@ import {Component, inject, viewChild} from '@angular/core';
|
||||
import {StockTable} from "../../components/stock-table/stock-table";
|
||||
import {Search} from "../../components/search/search";
|
||||
import {ModalButton} from "../../components/modal-button/modal-button";
|
||||
import {PurchaseOrderForm} from "../../components/purchase-order-form/purchase-order-form";
|
||||
import {QuotationForm} from "../../components/quotation-form/quotation-form";
|
||||
import {ProductsService, PurchaseordersService} from "../../services/api";
|
||||
import {PurchaseordersService, QuotationsService} from "../../services/api";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
import {CreatePurchaseorderForm} from "../../components/create-purchaseorder-form/create-purchaseorder-form";
|
||||
import {CreateQuotationForm} from "../../components/create-quotation-form/create-quotation-form";
|
||||
|
||||
@Component({
|
||||
selector: 'app-stock',
|
||||
@@ -15,85 +15,22 @@ import {CreatePurchaseorderForm} from "../../components/create-purchaseorder-for
|
||||
StockTable,
|
||||
Search,
|
||||
ModalButton,
|
||||
QuotationForm,
|
||||
CreatePurchaseorderForm,
|
||||
CreateQuotationForm,
|
||||
],
|
||||
templateUrl: './stock.html',
|
||||
styleUrl: './stock.css',
|
||||
})
|
||||
|
||||
export class Stock {
|
||||
createQuotation = viewChild.required<QuotationForm>('quotationForm');
|
||||
createPurchaseOrder = viewChild.required<CreatePurchaseorderForm>('purchaseOrderForm');
|
||||
createQuotation = viewChild.required<CreateQuotationForm>('quotationForm');
|
||||
productTable = viewChild.required<StockTable>('stockTable');
|
||||
private productsService = inject(ProductsService);
|
||||
private purchaseordersService = inject(PurchaseordersService)
|
||||
private quotationsService = inject(QuotationsService)
|
||||
private notificationService = inject(NzNotificationService)
|
||||
modalButtonPurchaseOrder = viewChild.required<ModalButton>('modalButtonPurchaseOrder');
|
||||
|
||||
onProductSearch(query: string) {
|
||||
this.productTable().applySearch(query);
|
||||
}
|
||||
|
||||
async addPurchaseOrder() {
|
||||
if (this.createPurchaseOrder().createPurchaseOrderForm.invalid) return;
|
||||
|
||||
const orderLines = this.createPurchaseOrder().lines.value.map(line => ({
|
||||
productId: line.productId,
|
||||
quantity: line.quantity
|
||||
}));
|
||||
|
||||
try {
|
||||
const purchaseOrder = this.createPurchaseOrder().createPurchaseOrderForm.getRawValue();
|
||||
await firstValueFrom(this.purchaseordersService.createPurchaseOrder(purchaseOrder));
|
||||
this.notificationService.success('Succès', 'Bon de commande crée')
|
||||
}catch (e) {
|
||||
console.error(e);
|
||||
this.notificationService.error('Erreur', 'Erreur lors de la création du bon de commande.')
|
||||
}
|
||||
}
|
||||
|
||||
async onModalOk() {
|
||||
const form = this.createPurchaseOrder().createPurchaseOrderForm;
|
||||
|
||||
if (form.invalid) {
|
||||
this.notificationService.error('Erreur', 'Formulaire invalide');
|
||||
return;
|
||||
}
|
||||
|
||||
const orderLines = this.createPurchaseOrder().lines.value.map(line => ({
|
||||
productId: line.productId,
|
||||
quantity: line.quantity
|
||||
}));
|
||||
|
||||
if (orderLines.length === 0) {
|
||||
this.notificationService.error('Erreur', 'Aucun produit sélectionné');
|
||||
return;
|
||||
}
|
||||
|
||||
const purchaseOrder = {
|
||||
purchaseConditions: form.get('purchaseConditions')!.value,
|
||||
products: orderLines
|
||||
};
|
||||
console.log('DTO envoyé :', purchaseOrder);
|
||||
try {
|
||||
await firstValueFrom(
|
||||
this.purchaseordersService.createPurchaseOrder(purchaseOrder)
|
||||
);
|
||||
this.notificationService.success('Succès', 'Bon de commande créé');
|
||||
form.reset();
|
||||
this.modalButtonPurchaseOrder().isVisible = false;
|
||||
await this.productTable().fetchProducts();
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.notificationService.error('Erreur', 'Erreur lors de la création du bon de commande.');
|
||||
}
|
||||
}
|
||||
|
||||
onModalCancel() {
|
||||
this.modalButtonPurchaseOrder().isVisible = false;
|
||||
}
|
||||
modalButtonQuotation = viewChild.required<ModalButton>('modalButtonQuotation');
|
||||
|
||||
hasSelection = false;
|
||||
|
||||
@@ -101,8 +38,48 @@ export class Stock {
|
||||
this.hasSelection = value;
|
||||
}
|
||||
|
||||
test(){
|
||||
console.log(this.productTable().selectedIds);
|
||||
onProductSearch(query: string) {
|
||||
this.productTable().applySearch(query);
|
||||
}
|
||||
|
||||
async addPurchaseOrder() {
|
||||
const form = this.createPurchaseOrder().createPurchaseOrderForm;
|
||||
if (form.invalid) {
|
||||
this.notificationService.error('Erreur', 'Formulaire invalide');
|
||||
return;
|
||||
}
|
||||
const orderLines = this.createPurchaseOrder().lines.value.map(line => ({
|
||||
productId: line.productId,
|
||||
quantity: line.quantity
|
||||
}));
|
||||
if (orderLines.length === 0) {
|
||||
this.notificationService.error('Erreur', 'Aucun produit sélectionné');
|
||||
return;
|
||||
}
|
||||
const purchaseOrder = {
|
||||
purchaseConditions: form.get('purchaseConditions')!.value,
|
||||
products: orderLines
|
||||
};
|
||||
try {
|
||||
await firstValueFrom(
|
||||
this.purchaseordersService.createPurchaseOrder(purchaseOrder)
|
||||
);
|
||||
this.notificationService.success('Succès', 'Bon de commande créé');
|
||||
} catch (e) {
|
||||
this.notificationService.error('Erreur', 'Erreur lors de la création du bon de commande.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async onModalOk() {
|
||||
await this.addPurchaseOrder();
|
||||
this.createPurchaseOrder().createPurchaseOrderForm.reset();
|
||||
this.modalButtonPurchaseOrder().isVisible = false;
|
||||
await this.productTable().fetchProducts();
|
||||
}
|
||||
|
||||
onModalCancel() {
|
||||
this.modalButtonPurchaseOrder().isVisible = false;
|
||||
}
|
||||
|
||||
openPurchaseOrderForm() {
|
||||
@@ -111,4 +88,51 @@ export class Stock {
|
||||
);
|
||||
this.createPurchaseOrder().syncSelectedProducts(selectedProducts);
|
||||
}
|
||||
|
||||
async addQuotation() {
|
||||
if (this.createQuotation().createQuotationForm.invalid) {
|
||||
this.notificationService.error('Erreur', 'Formulaire invalide');
|
||||
return;
|
||||
}
|
||||
const orderLines = this.createQuotation().lines.value.map(line => ({
|
||||
productId: line.productId,
|
||||
quantity: line.quantity
|
||||
}));
|
||||
if (orderLines.length === 0) {
|
||||
this.notificationService.error('Erreur', 'Aucun produit sélectionné');
|
||||
return;
|
||||
}
|
||||
const quotation = {
|
||||
message: this.createQuotation().createQuotationForm.get('message')!.value,
|
||||
purchaseConditions: this.createQuotation().createQuotationForm.get('purchaseConditions')!.value,
|
||||
products: orderLines
|
||||
};
|
||||
try {
|
||||
await firstValueFrom(
|
||||
this.quotationsService.createQuotationEndpoint(quotation)
|
||||
);
|
||||
this.notificationService.success('Succès', 'Devis créé');
|
||||
} catch (e) {
|
||||
this.notificationService.error('Erreur', 'Erreur lors de la création du devis.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async onModalQuotationOk() {
|
||||
await this.addQuotation();
|
||||
this.createQuotation().createQuotationForm.reset();
|
||||
this.modalButtonQuotation().isVisible = false;
|
||||
await this.productTable().fetchProducts();
|
||||
}
|
||||
|
||||
onModalQuotationCancel() {
|
||||
this.modalButtonQuotation().isVisible = false;
|
||||
}
|
||||
|
||||
openQuotationForm() {
|
||||
const selectedProducts = this.productTable().products().filter(p =>
|
||||
this.productTable().selectedIds.includes(p.id)
|
||||
);
|
||||
this.createQuotation().syncSelectedProducts(selectedProducts);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user