diff --git a/src/app/core/models/invoice.ts b/src/app/core/models/invoice.ts index 6b5ae3b..d7f0ad3 100644 --- a/src/app/core/models/invoice.ts +++ b/src/app/core/models/invoice.ts @@ -38,6 +38,7 @@ export interface Invoice { taxRate?: number; imported?: boolean; importedDate?: Date; + specialNote?: string; } export interface InvoiceFreemarkerTemplate { diff --git a/src/app/features/invoice/invoice-detail/invoice-detail.component.html b/src/app/features/invoice/invoice-detail/invoice-detail.component.html index df4918d..909fe60 100644 --- a/src/app/features/invoice/invoice-detail/invoice-detail.component.html +++ b/src/app/features/invoice/invoice-detail/invoice-detail.component.html @@ -70,18 +70,24 @@ [value]="invoice.total | currency:'€'" placeholder="total"> - +
-
- +
+ +
+ +
+

; + templates: InvoiceFreemarkerTemplate[]; @Input() clients: BillableClient[]; @@ -66,10 +66,10 @@ export class InvoiceDetailComponent implements OnInit { ]), freemarkerTemplateId: new UntypedFormControl( { - value: this.invoice.freemarkerTemplateId, + value: this.templates.some(templ => templ.id === this.invoice.freemarkerTemplateId) ? this.invoice.freemarkerTemplateId : null, disabled: this.invoice.locked, }, - [] + [Validators.required] ), selectedClient: new UntypedFormControl( { @@ -110,6 +110,8 @@ export class InvoiceDetailComponent implements OnInit { billToCity: new UntypedFormControl({ value: this.invoice?.billTo?.city, disabled: this.invoice.locked }, [ Validators.required, ]), + specialNote: new UntypedFormControl({ value: this.invoice?.specialNote, disabled: this.invoice.locked }, [ + ]), billToAddress: new UntypedFormControl({ value: this.invoice?.billTo?.address, disabled: this.invoice.locked }, [ Validators.required, ]), @@ -147,6 +149,13 @@ export class InvoiceDetailComponent implements OnInit { set file(file) { this.invoiceForm.get('file').patchValue(file); } + get specialNote() { + return this.invoiceForm.get('specialNote').value; + } + + set specialNote(note) { + this.invoiceForm.get('specialNote').patchValue(note); + } drop(files: NgxFileDropEntry[]) { for (const droppedFile of files) { @@ -193,6 +202,7 @@ export class InvoiceDetailComponent implements OnInit { let toSave = { invoiceNumber: this.invoiceForm.get('invoiceNumber').value, freemarkerTemplateId: this.invoiceForm.get('freemarkerTemplateId').value, + specialNote: this.invoiceForm.get('specialNote').value, maxDaysToPay: this.invoiceForm.get('maxDaysToPay').value, dateOfInvoice: DateUtils.getDateFromInput(this.invoiceForm.get('dateOfInvoice').value), taxRate: this.invoiceForm.get('taxRate').value, diff --git a/src/app/features/invoice/invoice-table-result/invoice-table-result.component.ts b/src/app/features/invoice/invoice-table-result/invoice-table-result.component.ts index 8dfd8ca..1b061e2 100644 --- a/src/app/features/invoice/invoice-table-result/invoice-table-result.component.ts +++ b/src/app/features/invoice/invoice-table-result/invoice-table-result.component.ts @@ -76,12 +76,12 @@ export class InvoiceTableResultComponent implements OnInit, OnApplicationEvent { async openModal(invoice: Invoice) { this.clients = await firstValueFrom(this.billableClientService.findByContractStatus(ContractStatus.ONGOING)); - + const templates = await firstValueFrom(this.invoiceService.listTemplates()); const ngbModalRef = this.modalService.open(InvoiceDetailComponent, { size: 'xl', }); ngbModalRef.componentInstance.invoice = invoice; - ngbModalRef.componentInstance.templates$ = this.invoiceService.listTemplates(); + ngbModalRef.componentInstance.templates = templates; ngbModalRef.componentInstance.clients = this.clients; ngbModalRef.componentInstance.onSaveInvoice.subscribe((invoiceForm) => { ngbModalRef.close(); @@ -168,18 +168,23 @@ export class InvoiceTableResultComponent implements OnInit, OnApplicationEvent { } templateModal() { - const ngbModalRef = this.modalService.open(TemplateComponent, { - size: 'lg', - }); - ngbModalRef.componentInstance.templates$ = this.invoiceService.listTemplates(); - ngbModalRef.componentInstance.onSaveTemplate.subscribe(async (formData) => { - ngbModalRef.close(); - await firstValueFrom(this.invoiceService.addTemplate(formData)); - }); - ngbModalRef.componentInstance.onDeleteTemplate.subscribe(async (template) => { - ngbModalRef.close(); - await firstValueFrom(this.invoiceService.deleteTemplate(template)); - }); + this.invoiceService.listTemplates().subscribe(templates => { + const ngbModalRef = this.modalService.open(TemplateComponent, { + size: 'lg', + }); + ngbModalRef.componentInstance.templates = templates ; + ngbModalRef.componentInstance.onSaveTemplate.subscribe(async (formData) => { + ngbModalRef.close(); + await firstValueFrom(this.invoiceService.addTemplate(formData)); + this.toastService.showSuccess("Will add the template"); + }); + ngbModalRef.componentInstance.onDeleteTemplate.subscribe(async (template) => { + ngbModalRef.close(); + await firstValueFrom(this.invoiceService.deleteTemplate(template)); + this.toastService.showSuccess("Will delete the template"); + }); + }) + } setSort(propertyName: string) { diff --git a/src/app/features/invoice/invoice.module.ts b/src/app/features/invoice/invoice.module.ts index c64c9ed..247b4ef 100644 --- a/src/app/features/invoice/invoice.module.ts +++ b/src/app/features/invoice/invoice.module.ts @@ -10,6 +10,7 @@ import { NgbDatepickerModule, NgbDropdownModule, NgbPaginationModule, NgbNavModu import { InvoiceTableResultComponent } from './invoice-table-result/invoice-table-result.component'; import { NgxFileDropModule } from 'ngx-file-drop'; import { TemplateComponent } from './template/template.component'; +import { AutosizeModule } from 'ngx-autosize'; @NgModule({ declarations: [ @@ -25,6 +26,7 @@ import { TemplateComponent } from './template/template.component'; FontAwesomeModule, ReactiveFormsModule, NgbDatepickerModule, + AutosizeModule, NgbTooltipModule, NgbDropdownModule, FormsModule, diff --git a/src/app/features/invoice/template/template.component.html b/src/app/features/invoice/template/template.component.html index 1859300..422e6d9 100644 --- a/src/app/features/invoice/template/template.component.html +++ b/src/app/features/invoice/template/template.component.html @@ -10,7 +10,7 @@
  • Current Templates - +
    • diff --git a/src/app/features/invoice/template/template.component.ts b/src/app/features/invoice/template/template.component.ts index e7f8bb3..9588aa9 100644 --- a/src/app/features/invoice/template/template.component.ts +++ b/src/app/features/invoice/template/template.component.ts @@ -15,7 +15,7 @@ import { WindowRefService } from '@core/service/window.service'; }) export class TemplateComponent implements OnInit { @Input() - templates$: Observable; + templates: InvoiceFreemarkerTemplate[]; @Output() onSaveTemplate: EventEmitter = new EventEmitter();