added edit function
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
</nz-form-label>
|
||||
|
||||
<nz-form-control nzSpan="12" nzErrorTip="Ce champ est requis">
|
||||
<input nz-input placeholder="Conditions générales de vente" formControlName="purchaseCondition">
|
||||
<input nz-input placeholder="Conditions générales de vente" formControlName="purchaseConditions">
|
||||
</nz-form-control>
|
||||
</nz-form-item>
|
||||
</form>
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Component } from '@angular/core';
|
||||
import {Component, effect, input} from '@angular/core';
|
||||
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||
import {NzColDirective} from "ng-zorro-antd/grid";
|
||||
import {NzFlexDirective} from "ng-zorro-antd/flex";
|
||||
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
||||
import {NzInputDirective} from "ng-zorro-antd/input";
|
||||
import {GetPurchaseOrderDto, GetQuotationDto} from "../../services/api";
|
||||
|
||||
@Component({
|
||||
selector: 'app-purchase-order-form',
|
||||
@@ -23,6 +24,17 @@ import {NzInputDirective} from "ng-zorro-antd/input";
|
||||
})
|
||||
export class PurchaseOrderForm {
|
||||
purchaseOrderForm: FormGroup = new FormGroup({
|
||||
purchaseCondition: new FormControl<string>(null,[Validators.required])
|
||||
purchaseConditions: new FormControl<string>(null,[Validators.required])
|
||||
})
|
||||
|
||||
purchaseOrder= input<GetPurchaseOrderDto>();
|
||||
constructor() {
|
||||
effect(() => {
|
||||
if (this.purchaseOrder()) {
|
||||
this.purchaseOrderForm.patchValue({
|
||||
purchaseConditions: this.purchaseOrder().purchaseConditions,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,28 +54,24 @@
|
||||
</td>
|
||||
<td>
|
||||
<div style="justify-content: center; display: flex">
|
||||
<div>
|
||||
<nz-icon nzType="plus-circle" nzTheme="outline" (click)="delete(purchaseOrder.id)" class="cursor-pointer text-green-700"/>
|
||||
</div>
|
||||
<nz-icon nzType="plus-circle" nzTheme="outline" (click)="delete(purchaseOrder.id)" class="cursor-pointer text-green-700"/>
|
||||
<nz-divider nzType="vertical"></nz-divider>
|
||||
<app-modal-nav nameIcon="edit" name="Modification des conditions de vente" class="cursor-pointer">
|
||||
<app-purchase-order-form></app-purchase-order-form>
|
||||
</app-modal-nav>
|
||||
<nz-icon nzType="edit" nzTheme="outline" class="cursor-pointer" (click)="openEditModal(purchaseOrder)"></nz-icon>
|
||||
<nz-divider nzType="vertical"></nz-divider>
|
||||
<div>
|
||||
<nz-icon nzType="delete" nzTheme="outline" (click)="delete(purchaseOrder.id)" class="cursor-pointer text-red-700"/>
|
||||
</div>
|
||||
<nz-icon nzType="delete" nzTheme="outline" (click)="delete(purchaseOrder.id)" class="cursor-pointer text-red-700"/>
|
||||
<nz-divider nzType="vertical"></nz-divider>
|
||||
<div>
|
||||
<nz-icon nzType="export" nzTheme="outline" (click)="export(purchaseOrder.id)" class="cursor-pointer text-green-700"/>
|
||||
</div>
|
||||
<nz-icon nzType="export" nzTheme="outline" (click)="export(purchaseOrder.id)" class="cursor-pointer text-green-700"/>
|
||||
<nz-divider nzType="vertical"></nz-divider>
|
||||
<div>
|
||||
<nz-icon nzType="interaction" nzTheme="outline" (click)="transfer()" class="cursor-pointer text-blue-700"/>
|
||||
</div>
|
||||
<nz-icon nzType="interaction" nzTheme="outline" (click)="transfer()" class="cursor-pointer text-blue-700"/>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</nz-table>
|
||||
|
||||
<div class="hidden">
|
||||
<app-modal-nav #modalNav nameIcon="edit" [name]="'Modification des conditions de vente'" (ok)="onModalOk(selectedPurchaseOrder.id, purchaseOrderForm, modalNav)" (cancel)="onModalCancel(modalNav)">
|
||||
<app-purchase-order-form #purchaseOrderForm [purchaseOrder]="selectedPurchaseOrder"></app-purchase-order-form>
|
||||
</app-modal-nav>
|
||||
</div>
|
||||
@@ -1,14 +1,16 @@
|
||||
import {Component, inject, OnInit, signal} from '@angular/core';
|
||||
import {Component, inject, OnInit, signal, viewChild} from '@angular/core';
|
||||
import {ModalNav} from "../modal-nav/modal-nav";
|
||||
import {NzDividerComponent} from "ng-zorro-antd/divider";
|
||||
import {NzIconDirective} from "ng-zorro-antd/icon";
|
||||
import {NzTableComponent} from "ng-zorro-antd/table";
|
||||
import {PurchaseOrderForm} from "../purchase-order-form/purchase-order-form";
|
||||
import {ModalButton} from "../modal-button/modal-button";
|
||||
import {GetPurchaseOrderDto, PurchaseordersService} from "../../services/api";
|
||||
import {GetPurchaseOrderDto, GetQuotationDto, PurchaseordersService} from "../../services/api";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
import {FileService} from "../../services/file.service";
|
||||
import {QuotationForm} from "../quotation-form/quotation-form";
|
||||
import {DelivererForm} from "../deliverer-form/deliverer-form";
|
||||
|
||||
@Component({
|
||||
selector: 'app-purchase-order-table',
|
||||
@@ -19,6 +21,7 @@ import {FileService} from "../../services/file.service";
|
||||
NzTableComponent,
|
||||
PurchaseOrderForm,
|
||||
ModalButton,
|
||||
DelivererForm,
|
||||
],
|
||||
templateUrl: './purchase-order-table.html',
|
||||
styleUrl: './purchase-order-table.css',
|
||||
@@ -29,6 +32,7 @@ export class PurchaseOrderTable implements OnInit {
|
||||
private fileService = inject(FileService);
|
||||
purchaseOrders = signal<GetPurchaseOrderDto[]>([]);
|
||||
purchaseOrdersLoading = signal<boolean>(false);
|
||||
modal = viewChild.required<ModalNav>('modalNav');
|
||||
|
||||
async ngOnInit() {
|
||||
await this.fetchPurchaseOrder();
|
||||
@@ -87,4 +91,44 @@ export class PurchaseOrderTable implements OnInit {
|
||||
transfer() {
|
||||
return
|
||||
}
|
||||
|
||||
async edit(id: number, updatePurchaseOrderComponent: PurchaseOrderForm) {
|
||||
if (updatePurchaseOrderComponent.purchaseOrderForm.invalid) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur d\'écriture dans le formulaire'
|
||||
)
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const purchaseOrders = updatePurchaseOrderComponent.purchaseOrderForm.getRawValue();
|
||||
await firstValueFrom(this.purchaseOrdersService.patchPurchaseOrderPurchaseConditionsEndpoint(id, purchaseOrders))
|
||||
|
||||
this.notificationService.success('Success', 'Bon de commande modifié')
|
||||
} catch (e) {
|
||||
this.notificationService.error('Erreur', 'Erreur lors de la modification')
|
||||
}
|
||||
}
|
||||
|
||||
selectedPurchaseOrder: GetPurchaseOrderDto | null = null;
|
||||
openEditModal(purchaseOrder: GetPurchaseOrderDto) {
|
||||
this.selectedPurchaseOrder = { ...purchaseOrder };
|
||||
this.modal().showModal();
|
||||
}
|
||||
|
||||
async onModalOk(id: number, updatePurchaseOrderComponent: PurchaseOrderForm, modal: ModalNav) {
|
||||
if (!this.selectedPurchaseOrder) return;
|
||||
|
||||
await this.edit(id, updatePurchaseOrderComponent);
|
||||
updatePurchaseOrderComponent.purchaseOrderForm.reset();
|
||||
modal.isVisible = false;
|
||||
await this.fetchPurchaseOrder();
|
||||
}
|
||||
|
||||
onModalCancel(modal: ModalNav) {
|
||||
modal.isVisible = false;
|
||||
}
|
||||
|
||||
protected readonly PurchaseOrderForm = PurchaseOrderForm;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import {GetQuotationDto, QuotationsService} from "../../services/api";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
import {FileService} from "../../services/file.service";
|
||||
import {DelivereryNoteForm} from "../deliverery-note-form/deliverery-note-form";
|
||||
|
||||
@Component({
|
||||
selector: 'app-quotation-table',
|
||||
@@ -20,7 +19,6 @@ import {DelivereryNoteForm} from "../deliverery-note-form/deliverery-note-form";
|
||||
NzIconDirective,
|
||||
NzTableComponent,
|
||||
QuotationForm,
|
||||
DelivereryNoteForm,
|
||||
],
|
||||
templateUrl: './quotation-table.html',
|
||||
styleUrl: './quotation-table.css',
|
||||
|
||||
Reference in New Issue
Block a user