Fixed error with estimateDeliveryDate in form to update the raw
This commit is contained in:
@@ -5,8 +5,7 @@
|
||||
</nz-form-label>
|
||||
|
||||
<nz-form-control nzSpan="9" nzErrorTip="Ce champ est requis">
|
||||
<nz-select formControlName="delivererId" [nzPlaceHolder]="'Choisir un transporteur'" nzShowSearch
|
||||
[nzFilterOption]="filter">
|
||||
<nz-select formControlName="delivererId" [nzPlaceHolder]="'Choisir un transporteur'" nzShowSearch>
|
||||
@for (deliverer of deliverers(); track deliverer.id) {
|
||||
<nz-option [nzValue]="deliverer.id" [nzLabel]="deliverer.transporter"></nz-option>
|
||||
}
|
||||
|
||||
@@ -31,14 +31,17 @@ export class DelivereryNoteForm implements OnInit {
|
||||
trackingNumber: new FormControl<string>(null),
|
||||
delivererId: new FormControl<number>(null, [Validators.required]),
|
||||
expeditionDate: new FormControl(null, [Validators.required]),
|
||||
estimatedDate: new FormControl(null),
|
||||
estimatedDate: new FormControl(null, [Validators.required]),
|
||||
realDeliveryDate: new FormControl(null)
|
||||
})
|
||||
|
||||
private deliverersService = inject(DeliverersService);
|
||||
private notificationService = inject(NzNotificationService);
|
||||
|
||||
deliverers = signal<GetDelivererDto[]>([]);
|
||||
|
||||
deliveryNote = input<GetDeliveryNoteDto>();
|
||||
|
||||
async fetchDeliverers() {
|
||||
try {
|
||||
const deliverers = await firstValueFrom(this.deliverersService.getAllDelivererEndpoint());
|
||||
@@ -52,12 +55,6 @@ export class DelivereryNoteForm implements OnInit {
|
||||
await this.fetchDeliverers();
|
||||
}
|
||||
|
||||
filter(input: string, option: any) {
|
||||
return option.nzLabel.toLowerCase().includes(input.toLowerCase());
|
||||
}
|
||||
|
||||
deliveryNote = input<GetDeliveryNoteDto>();
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
if (this.deliveryNote()) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<th>Date d'expédition</th>
|
||||
<th>Date de livraison estimée</th>
|
||||
<th>Date de livraison réelle</th>
|
||||
<th>Statut</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -20,6 +21,15 @@
|
||||
<td>{{ deliveryNote.expeditionDate | date: 'dd/MM/yyyy' }}</td>
|
||||
<td>{{ deliveryNote.estimateDeliveryDate | date: 'dd/MM/yyyy' }}</td>
|
||||
<td>{{ deliveryNote.realDeliveryDate | date: 'dd/MM/yyyy' }}</td>
|
||||
<td>
|
||||
@if (deliveryNote.estimateDeliveryDate >= date && deliveryNote.realDeliveryDate == null) {
|
||||
<p class="text-blue-900 font-semibold">En cours</p>
|
||||
} @else if (deliveryNote.realDeliveryDate == null) {
|
||||
<p class="text-red-600 font-semibold">En retard</p>
|
||||
} @else {
|
||||
<p class="text-green-800 font-semibold">Terminée</p>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<div style="justify-content: center; display: flex">
|
||||
<nz-icon nzType="check" nzTheme="outline" (click)="validate(deliveryNote.id)"
|
||||
|
||||
@@ -5,7 +5,7 @@ import {NzDividerComponent} from "ng-zorro-antd/divider";
|
||||
import {NzIconDirective} from "ng-zorro-antd/icon";
|
||||
import {NzTableComponent} from "ng-zorro-antd/table";
|
||||
import {DelivereryNoteForm} from "../deliverery-note-form/deliverery-note-form";
|
||||
import {DeliverynotesService, GetDeliveryNoteDto} from "../../services/api";
|
||||
import {DeliverynotesService, GetDeliveryNoteDto, UpdateDeliveryNoteDto} from "../../services/api";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
import {format} from "date-fns";
|
||||
@@ -32,8 +32,11 @@ export class DelivereryNoteTable implements OnInit {
|
||||
deliveryNotesLoading = signal<boolean>(false);
|
||||
modal = viewChild.required<ModalNav>('modalNav');
|
||||
|
||||
date: string = "";
|
||||
|
||||
async ngOnInit() {
|
||||
await this.fetchDeliveryNotes();
|
||||
this.date = new Date().toISOString().split('T')[0];
|
||||
}
|
||||
|
||||
async fetchDeliveryNotes() {
|
||||
@@ -123,34 +126,20 @@ export class DelivereryNoteTable implements OnInit {
|
||||
try {
|
||||
const raw = updateDelivereryNoteComponent.deliveryNoteForm.getRawValue();
|
||||
|
||||
// convertit proprement les dates (string OU Date)
|
||||
const toIso = (val: any) => {
|
||||
if (!val) return null;
|
||||
const toIso = (val: any) =>
|
||||
val ? new Date(val).toISOString().substring(0, 10) : null;
|
||||
|
||||
// si c’est déjà un string ISO "yyyy-MM-dd", on renvoie tel quel
|
||||
if (typeof val === 'string' && /^\d{4}-\d{2}-\d{2}/.test(val)) {
|
||||
return val.substring(0, 10);
|
||||
}
|
||||
|
||||
// sinon on reconstruit une Date
|
||||
const d = new Date(val);
|
||||
if (isNaN(d.getTime())) return null;
|
||||
|
||||
return d.toISOString().substring(0, 10); // yyyy-MM-dd
|
||||
};
|
||||
|
||||
const deliveryNoteDto = {
|
||||
const deliveryNoteDto: UpdateDeliveryNoteDto = {
|
||||
trackingNumber: raw.trackingNumber,
|
||||
delivererId: raw.delivererId,
|
||||
expeditionDate: toIso(raw.expeditionDate),
|
||||
estimatedDate: toIso(raw.estimatedDate),
|
||||
estimateDeliveryDate: toIso(raw.estimatedDate),
|
||||
realDeliveryDate: toIso(raw.realDeliveryDate)
|
||||
};
|
||||
|
||||
await firstValueFrom(this.deliveryNotesService.updateDeliveryNoteEndpoint(id, deliveryNoteDto));
|
||||
this.notificationService.success('Success', 'Bon de livraison modifié');
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.notificationService.error('Erreur', 'Erreur lors de la modification');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,9 +59,9 @@ In your Angular project:
|
||||
|
||||
```typescript
|
||||
|
||||
import { ApplicationConfig } from '@angular/core';
|
||||
import { provideHttpClient } from '@angular/common/http';
|
||||
import { provideApi } from '';
|
||||
import {ApplicationConfig} from '@angular/core';
|
||||
import {provideHttpClient} from '@angular/common/http';
|
||||
import {provideApi} from '';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
|
||||
Reference in New Issue
Block a user