import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { IInvoice , IInvoiceCreateInput , IInvoiceFindInput , IInvoiceUpdateInput } from '@gauzy/contracts' ; import { firstValueFrom } from 'rxjs' ; import { BehaviorSubject } from 'rxjs' ; import { toParams } from '@gauzy/common-angular' ; import { API_PREFIX } from '../constants/app.constants' ; @ Injectable ( ) export class InvoicesService { private source = new BehaviorSubject ( false ) ; currentData = this . source . asObservable ( ) ; constructor ( private http ) { } getAll ( relations ? , findInput ? ) { const data = JSON . stringify ( { relations , findInput } ) ; return firstValueFrom ( this . http . get < { items : IInvoice [ ] ; } > ( `${ API_PREFIX }/invoices` , { params : { data } } ) ) ; } getHighestInvoiceNumber ( tenantId ) { return firstValueFrom ( this . http . get < IInvoice > ( `${ API_PREFIX }/invoices/highest` , { params : toParams ( { tenantId } ) } ) ) ; } getById ( id , relations ? , findInput ? ) { const data = JSON . stringify ( { relations , findInput } ) ; return firstValueFrom ( this . http . get < IInvoice > ( `${ API_PREFIX }/invoices/${ id }` , { params : { data } } ) ) ; } getWithoutAuth ( id , token , relations ? ) { const data = JSON . stringify ( { relations } ) ; return firstValueFrom ( this . http . get < IInvoice > ( `${ API_PREFIX }/invoices/public/${ id }/${ token }` , { params : { data } } ) ) ; } add ( invoice ) { return firstValueFrom ( this . http . post < IInvoice > ( `${ API_PREFIX }/invoices` , invoice ) ) ; } update ( id , updateInput ) { return firstValueFrom ( this . http . put < IInvoice > ( `${ API_PREFIX }/invoices/${ id }` , updateInput ) ) ; } updateWithoutAuth ( id , updateInput ) { return firstValueFrom ( this . http . put < IInvoice > ( `${ API_PREFIX }/invoices/estimate/${ id }` , updateInput ) ) ; } edit ( invoice ) { return firstValueFrom ( this . http . put < IInvoice > ( `${ API_PREFIX }/invoices/${ invoice . id }` , invoice ) ) ; } generateLink ( id , isEstimate ) { return firstValueFrom ( this . http . put < any > ( `${ API_PREFIX }/invoices/generate/${ id }` , { params : { isEstimate } } ) ) ; } delete ( id ) { return firstValueFrom ( this . http . delete ( `${ API_PREFIX }/invoices/${ id }` ) ) ; } sendEmail ( email , invoiceNumber , invoiceId , isEstimate , organizationId , tenantId ) { return firstValueFrom ( this . http . put < any > ( `${ API_PREFIX }/invoices/email/${ email }` , { params : { isEstimate , invoiceNumber , invoiceId , organizationId , tenantId } } ) ) ; } changeValue ( message ) { this . source . next ( message ) ; } downloadInvoicePdf ( invoiceId ) { return this . http . get ( `${ API_PREFIX }/invoices/download/${ invoiceId }` , { responseType : 'blob' } ) ; } downloadInvoicePaymentPdf ( invoiceId ) { return this . http . get ( `${ API_PREFIX }/invoices/payment/download/${ invoiceId }` , { responseType : 'blob' } ) ; } }