diff --git a/src/app/core/service/dossier.service.ts b/src/app/core/service/dossier.service.ts index 2572907..293ed52 100644 --- a/src/app/core/service/dossier.service.ts +++ b/src/app/core/service/dossier.service.ts @@ -18,7 +18,7 @@ export class DossierService { private configService: ConfigInitService, private fileService: FileService, private http: HttpClient - ) {} + ) { } findAll(closed: boolean): Observable { return this.http.post( @@ -36,8 +36,7 @@ export class DossierService { const direction = Direction[sortCriteria.direction]; return this.http.post>( - `${this.configService.getConfig()['BACKEND_URL']}/api/dossier/find-all-paged?closed=${closed}&page=${ - pageNumber - 1 + `${this.configService.getConfig()['BACKEND_URL']}/api/dossier/find-all-paged?closed=${closed}&page=${pageNumber - 1 }&size=${pageSize}&sort=${sortCriteria.property},${direction}`, {} ); @@ -50,6 +49,13 @@ export class DossierService { ); } + fromPrevious(): Observable { + return this.http.post( + `${this.configService.getConfig()['BACKEND_URL']}/api/dossier/new-from-previous`, + {} + ); + } + import(file: File): Observable { let formData = new FormData(); formData.append('zip', file); @@ -114,16 +120,19 @@ export class DossierService { ); } - newDossier(dossier: Dossier): Observable { - return this.http.post(`${this.configService.getConfig()['BACKEND_URL']}/api/dossier/new-dossier`, dossier); + newDossier(dossier: Dossier): Observable { + return this.http.post(`${this.configService.getConfig()['BACKEND_URL']}/api/dossier/new-dossier`, dossier); } - updateDossier(dossier: Dossier): Observable { - return this.http.post(`${this.configService.getConfig()['BACKEND_URL']}/api/dossier/update-dossier`, dossier); + updateDossier(dossier: Dossier): Observable { + return this.http.post( + `${this.configService.getConfig()['BACKEND_URL']}/api/dossier/update-dossier`, + dossier + ); } - recallForModification(dossier: Dossier): Observable { - return this.http.post( + recallForModification(dossier: Dossier): Observable { + return this.http.post( `${this.configService.getConfig()['BACKEND_URL']}/api/dossier/recall-for-modification`, dossier ); diff --git a/src/app/features/dossier/dossier-form/dossier-form.component.ts b/src/app/features/dossier/dossier-form/dossier-form.component.ts index ddf1565..b0eb067 100644 --- a/src/app/features/dossier/dossier-form/dossier-form.component.ts +++ b/src/app/features/dossier/dossier-form/dossier-form.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Input, OnInit, Optional, Output } from '@angular/core'; +import { Component, EventEmitter, Input, OnDestroy, OnInit, Optional, Output } from '@angular/core'; import { UntypedFormArray, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; import { Dossier, TvaAdvancePayment } from '@core/models/dossier'; import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'; @@ -10,7 +10,7 @@ import { InvoiceService } from '@core/service/invoice.service'; import { FeeDetailComponent } from '@feature/fee/fee-detail/fee-detail.component'; import { InvoiceDetailComponent } from '@feature/invoice/invoice-detail/invoice-detail.component'; import { DateUtils } from '@core/utils/date-utils'; -import { firstValueFrom } from 'rxjs'; +import { firstValueFrom, Subscription } from 'rxjs'; import { BillableClient } from '@core/models/billable-client'; import { BillableClientService } from '@core/service/billable-client.service'; @@ -19,7 +19,10 @@ import { BillableClientService } from '@core/service/billable-client.service'; templateUrl: './dossier-form.component.html', styleUrls: ['./dossier-form.component.scss'], }) -export class DossierFormComponent implements OnInit { +export class DossierFormComponent implements OnInit, OnDestroy { + dossierUpdatedSubscription: Subscription; + @Input() + dossierUpdatedEmitter: EventEmitter; @Input() dossier: Dossier; @Input() @@ -58,16 +61,31 @@ export class DossierFormComponent implements OnInit { private fb: UntypedFormBuilder ) { } - async ngOnInit() { + ngOnDestroy(): void { + this.dossierUpdatedSubscription?.unsubscribe(); + } + + ngOnInit() { + this.load(); + } + + async load() { this.dossierForm = this.createFormGroup(); await this.loadFees(); this.clients = await firstValueFrom(this.clientService.findAll()); await this.loadInvoices(); + if (this.dossierUpdatedSubscription) { + this.dossierUpdatedSubscription.unsubscribe(); + } + if (this.dossierUpdatedEmitter) { + this.dossierUpdatedEmitter.subscribe(async (d) => { + this.dossier = d; + await this.load(); + }); + } } async loadFees() { - this.expenses = []; - this.filteredExpenses = []; this.feeTotalVat = 0; this.feeTotalExclVat = 0; if (this.dossier?.feeIds?.length) { @@ -76,15 +94,17 @@ export class DossierFormComponent implements OnInit { for (let fee of fees) { this.feeTotalVat += fee.vat || 0; this.feeTotalExclVat += fee.priceHVAT || 0; - this.expenses.push(fee); - this.filteredExpenses.push(fee); } + this.expenses = fees; + this.filteredExpenses = fees; this.filteredExpenses.sort((e1, e2) => new Date(e2.date).getTime() - new Date(e1.date).getTime()); + } else { + this.expenses = []; + this.filteredExpenses = []; } } async loadInvoices() { - this.dossier.invoices = []; this.vatTotal = 0; this.invoiceTotalExclVat = 0; if (this.dossier?.invoiceIds?.length) { @@ -92,11 +112,13 @@ export class DossierFormComponent implements OnInit { for (let invoice of invoices) { this.vatTotal += invoice.taxes; this.invoiceTotalExclVat += invoice.subTotal; - this.dossier.invoices.push(invoice); } + this.dossier.invoices = invoices; this.dossier.invoices.sort( (e1, e2) => new Date(e2.dateOfInvoice).getTime() - new Date(e1.dateOfInvoice).getTime() ); + } else { + this.dossier.invoices = []; } } diff --git a/src/app/features/dossier/dossier-table-result/dossier-table-result.component.html b/src/app/features/dossier/dossier-table-result/dossier-table-result.component.html index d0fbc23..ef07b16 100644 --- a/src/app/features/dossier/dossier-table-result/dossier-table-result.component.html +++ b/src/app/features/dossier/dossier-table-result/dossier-table-result.component.html @@ -10,6 +10,10 @@ New +