mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: Map the invoice preview data
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import moment from 'moment';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ServiceError } from '@/exceptions';
|
||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { PaymentLink } from '@/system/models';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { GeneratePaymentLinkTransformer } from './GeneratePaymentLinkTransformer';
|
||||
import { GetInvoicePaymentLinkMetaTransformer } from './GetInvoicePaymentLinkTransformer';
|
||||
import { initalizeTenantServices } from '@/api/middleware/TenantDependencyInjection';
|
||||
|
||||
@@ -46,7 +45,7 @@ export class GetInvoicePaymentLinkMetadata {
|
||||
|
||||
const invoice = await SaleInvoice.query()
|
||||
.findById(paymentLink.resourceId)
|
||||
.withGraphFetched('entries')
|
||||
.withGraphFetched('entries.item')
|
||||
.withGraphFetched('customer')
|
||||
.throwIfNotFound();
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ItemEntryTransformer } from './ItemEntryTransformer';
|
||||
import { SaleInvoiceTransformer } from './SaleInvoiceTransformer';
|
||||
|
||||
export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer {
|
||||
@@ -33,6 +34,9 @@ export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer
|
||||
'dueDate',
|
||||
'dueDateFormatted',
|
||||
'invoiceNo',
|
||||
'invoiceMessage',
|
||||
'termsConditions',
|
||||
'entries',
|
||||
];
|
||||
};
|
||||
|
||||
@@ -43,4 +47,50 @@ export class GetInvoicePaymentLinkMetaTransformer extends SaleInvoiceTransformer
|
||||
public companyName() {
|
||||
return 'Bigcapital Technology, Inc.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the entries of the sale invoice.
|
||||
* @param {ISaleInvoice} invoice
|
||||
* @returns {}
|
||||
*/
|
||||
protected entries = (invoice) => {
|
||||
return this.item(
|
||||
invoice.entries,
|
||||
new GetInvoicePaymentLinkEntryMetaTransformer(),
|
||||
{
|
||||
currencyCode: invoice.currencyCode,
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
class GetInvoicePaymentLinkEntryMetaTransformer extends ItemEntryTransformer {
|
||||
/**
|
||||
* Include these attributes to item entry object.
|
||||
* @returns {Array}
|
||||
*/
|
||||
public includeAttributes = (): string[] => {
|
||||
return [
|
||||
'quantity',
|
||||
'quantityFormatted',
|
||||
'rate',
|
||||
'rateFormatted',
|
||||
'total',
|
||||
'totalFormatted',
|
||||
'itemName',
|
||||
'description',
|
||||
];
|
||||
};
|
||||
|
||||
itemName(entry) {
|
||||
return entry.item.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude these attributes from payment link object.
|
||||
* @returns {Array}
|
||||
*/
|
||||
public excludeAttributes = (): string[] => {
|
||||
return ['*'];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user