mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-13 11:20:31 +00:00
feat: wip configure resources to be exportable
This commit is contained in:
@@ -85,42 +85,34 @@ export default {
|
||||
billNumber: {
|
||||
name: 'Bill No.',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
referenceNo: {
|
||||
name: 'Reference No.',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
billDate: {
|
||||
name: 'Date',
|
||||
type: 'date',
|
||||
exportable: true,
|
||||
},
|
||||
dueDate: {
|
||||
name: 'Due Date',
|
||||
type: 'date',
|
||||
exportable: true,
|
||||
},
|
||||
vendorId: {
|
||||
name: 'Vendor',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
exchangeRate: {
|
||||
name: 'Exchange Rate',
|
||||
type: 'number',
|
||||
exportable: true,
|
||||
},
|
||||
note: {
|
||||
name: 'Note',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
open: {
|
||||
name: 'Open',
|
||||
type: 'boolean',
|
||||
exportable: true,
|
||||
},
|
||||
},
|
||||
fields2: {
|
||||
|
||||
@@ -72,38 +72,31 @@ export default {
|
||||
vendor: {
|
||||
name: 'bill_payment.field.vendor',
|
||||
type: 'relation',
|
||||
exportable: true,
|
||||
accessor: 'vendor.displayName',
|
||||
},
|
||||
paymentDate: {
|
||||
name: 'bill_payment.field.payment_date',
|
||||
type: 'date',
|
||||
required: true,
|
||||
exportable: true,
|
||||
},
|
||||
paymentNumber: {
|
||||
name: 'bill_payment.field.payment_number',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
paymentAccountId: {
|
||||
name: 'bill_payment.field.payment_account',
|
||||
type: 'relation',
|
||||
exportable: true,
|
||||
},
|
||||
exchangeRate: {
|
||||
name: 'bill_payment.field.exchange_rate',
|
||||
type: 'number',
|
||||
exportable: true,
|
||||
},
|
||||
statement: {
|
||||
name: 'bill_payment.field.statement',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
reference: {
|
||||
name: 'bill_payment.field.reference',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
},
|
||||
fields2: {
|
||||
|
||||
@@ -12,6 +12,7 @@ export default {
|
||||
sortOrder: 'DESC',
|
||||
sortField: 'name',
|
||||
},
|
||||
exportable: true,
|
||||
importable: true,
|
||||
importAggregator: 'group',
|
||||
importAggregateOn: 'entries',
|
||||
@@ -81,6 +82,41 @@ export default {
|
||||
fieldType: 'date',
|
||||
},
|
||||
},
|
||||
columns: {
|
||||
customer: {
|
||||
name: 'Customer',
|
||||
type: 'relation',
|
||||
accessor: 'customer.displayName',
|
||||
},
|
||||
exchangeRate: {
|
||||
name: 'Exchange Rate',
|
||||
type: 'number',
|
||||
},
|
||||
creditNoteDate: {
|
||||
name: 'Credit Note Date',
|
||||
type: 'date',
|
||||
},
|
||||
referenceNo: {
|
||||
name: 'Reference No.',
|
||||
type: 'text',
|
||||
},
|
||||
note: {
|
||||
name: 'Note',
|
||||
type: 'text',
|
||||
},
|
||||
termsConditions: {
|
||||
name: 'Terms & Conditions',
|
||||
type: 'text',
|
||||
},
|
||||
creditNoteNumber: {
|
||||
name: 'Credit Note Number',
|
||||
type: 'text',
|
||||
},
|
||||
open: {
|
||||
name: 'Open',
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
fields2: {
|
||||
customerId: {
|
||||
name: 'Customer',
|
||||
|
||||
@@ -95,129 +95,157 @@ export default {
|
||||
firstName: {
|
||||
name: 'vendor.field.first_name',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
lastName: {
|
||||
name: 'vendor.field.last_name',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
displayName: {
|
||||
name: 'vendor.field.display_name',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
email: {
|
||||
name: 'vendor.field.email',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
workPhone: {
|
||||
name: 'vendor.field.work_phone',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
personalPhone: {
|
||||
name: 'vendor.field.personal_pone',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
companyName: {
|
||||
name: 'vendor.field.company_name',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
website: {
|
||||
name: 'vendor.field.website',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
createdAt: {
|
||||
name: 'vendor.field.created_at',
|
||||
type: 'date',
|
||||
exportable: true,
|
||||
},
|
||||
balance: {
|
||||
name: 'vendor.field.balance',
|
||||
type: 'number',
|
||||
exportable: true,
|
||||
},
|
||||
openingBalance: {
|
||||
name: 'vendor.field.opening_balance',
|
||||
type: 'number',
|
||||
exportable: true,
|
||||
},
|
||||
openingBalanceAt: {
|
||||
name: 'vendor.field.opening_balance_at',
|
||||
type: 'date',
|
||||
exportable: true,
|
||||
},
|
||||
currencyCode: {
|
||||
name: 'vendor.field.currency',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
status: {
|
||||
name: 'vendor.field.status',
|
||||
exportable: true,
|
||||
},
|
||||
// Billing Address
|
||||
billingAddress1: {
|
||||
name: 'Billing Address 1',
|
||||
column: 'billing_address1',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
billingAddress2: {
|
||||
name: 'Billing Address 2',
|
||||
column: 'billing_address2',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
billingAddressCity: {
|
||||
name: 'Billing Address City',
|
||||
column: 'billing_address_city',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
billingAddressCountry: {
|
||||
name: 'Billing Address Country',
|
||||
column: 'billing_address_country',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
billingAddressPostcode: {
|
||||
name: 'Billing Address Postcode',
|
||||
column: 'billing_address_postcode',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
billingAddressState: {
|
||||
name: 'Billing Address State',
|
||||
column: 'billing_address_state',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
billingAddressPhone: {
|
||||
name: 'Billing Address Phone',
|
||||
column: 'billing_address_phone',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
// Shipping Address
|
||||
shippingAddress1: {
|
||||
name: 'Shipping Address 1',
|
||||
column: 'shipping_address1',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
shippingAddress2: {
|
||||
name: 'Shipping Address 2',
|
||||
column: 'shipping_address2',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
shippingAddressCity: {
|
||||
name: 'Shipping Address City',
|
||||
column: 'shipping_address_city',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
shippingAddressCountry: {
|
||||
name: 'Shipping Address Country',
|
||||
column: 'shipping_address_country',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
shippingAddressPostcode: {
|
||||
name: 'Shipping Address Postcode',
|
||||
column: 'shipping_address_postcode',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
shippingAddressPhone: {
|
||||
name: 'Shipping Address Phone',
|
||||
column: 'shipping_address_phone',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
shippingAddressState: {
|
||||
name: 'Shipping Address State',
|
||||
column: 'shipping_address_state',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
},
|
||||
fields2: {
|
||||
|
||||
@@ -8,7 +8,7 @@ export default {
|
||||
sortField: 'name',
|
||||
},
|
||||
importable: true,
|
||||
exportabe: true,
|
||||
exportable: true,
|
||||
fields: {
|
||||
payment_date: {
|
||||
name: 'expense.field.payment_date',
|
||||
@@ -65,6 +65,7 @@ export default {
|
||||
columns: {
|
||||
paymentReceive: {
|
||||
name: 'expense.field.payment_account',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
referenceNo: {
|
||||
|
||||
@@ -5,6 +5,7 @@ export default {
|
||||
sortOrder: 'DESC',
|
||||
},
|
||||
importable: true,
|
||||
exportable: true,
|
||||
fields: {
|
||||
name: {
|
||||
name: 'item_category.field.name',
|
||||
|
||||
@@ -4,6 +4,7 @@ export default {
|
||||
sortOrder: 'DESC',
|
||||
sortField: 'estimate_date',
|
||||
},
|
||||
exportable: true,
|
||||
importable: true,
|
||||
importAggregator: 'group',
|
||||
importAggregateOn: 'entries',
|
||||
@@ -73,6 +74,59 @@ export default {
|
||||
columnType: 'date',
|
||||
},
|
||||
},
|
||||
columns: {
|
||||
customer: {
|
||||
name: 'Customer',
|
||||
type: 'text',
|
||||
accessor: 'customer.displayName',
|
||||
exportable: true,
|
||||
},
|
||||
estimateDate: {
|
||||
name: 'Estimate Date',
|
||||
type: 'date',
|
||||
exportable: true,
|
||||
},
|
||||
expirationDate: {
|
||||
name: 'Expiration Date',
|
||||
type: 'date',
|
||||
exportable: true,
|
||||
},
|
||||
estimateNumber: {
|
||||
name: 'Estimate No.',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
reference: {
|
||||
name: 'Reference No.',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
exchangeRate: {
|
||||
name: 'Exchange Rate',
|
||||
type: 'number',
|
||||
exportable: true,
|
||||
},
|
||||
currencyCode: {
|
||||
name: 'Currency',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
note: {
|
||||
name: 'Note',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
termsConditions: {
|
||||
name: 'Terms & Conditions',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
delivered: {
|
||||
name: 'Delivered',
|
||||
type: 'boolean',
|
||||
exportable: true,
|
||||
},
|
||||
},
|
||||
fields2: {
|
||||
customerId: {
|
||||
name: 'Customer',
|
||||
|
||||
@@ -4,6 +4,7 @@ export default {
|
||||
sortOrder: 'DESC',
|
||||
sortField: 'created_at',
|
||||
},
|
||||
exportable: true,
|
||||
importable: true,
|
||||
importAggregator: 'group',
|
||||
importAggregateOn: 'entries',
|
||||
|
||||
@@ -4,6 +4,7 @@ export default {
|
||||
sortOrder: 'DESC',
|
||||
sortField: 'created_at',
|
||||
},
|
||||
exportable: true,
|
||||
importable: true,
|
||||
importAggregator: 'group',
|
||||
importAggregateOn: 'entries',
|
||||
|
||||
@@ -95,129 +95,157 @@ export default {
|
||||
firstName: {
|
||||
name: 'vendor.field.first_name',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
lastName: {
|
||||
name: 'vendor.field.last_name',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
displayName: {
|
||||
name: 'vendor.field.display_name',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
email: {
|
||||
name: 'vendor.field.email',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
workPhone: {
|
||||
name: 'vendor.field.work_phone',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
personalPhone: {
|
||||
name: 'vendor.field.personal_pone',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
companyName: {
|
||||
name: 'vendor.field.company_name',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
website: {
|
||||
name: 'vendor.field.website',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
createdAt: {
|
||||
name: 'vendor.field.created_at',
|
||||
type: 'date',
|
||||
exportable: true,
|
||||
},
|
||||
balance: {
|
||||
name: 'vendor.field.balance',
|
||||
type: 'number',
|
||||
exportable: true,
|
||||
},
|
||||
openingBalance: {
|
||||
name: 'vendor.field.opening_balance',
|
||||
type: 'number',
|
||||
exportable: true,
|
||||
},
|
||||
openingBalanceAt: {
|
||||
name: 'vendor.field.opening_balance_at',
|
||||
type: 'date',
|
||||
exportable: true,
|
||||
},
|
||||
currencyCode: {
|
||||
name: 'vendor.field.currency',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
status: {
|
||||
name: 'vendor.field.status',
|
||||
exportable: true,
|
||||
},
|
||||
// Billing Address
|
||||
billingAddress1: {
|
||||
name: 'Billing Address 1',
|
||||
column: 'billing_address1',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
billingAddress2: {
|
||||
name: 'Billing Address 2',
|
||||
column: 'billing_address2',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
billingAddressCity: {
|
||||
name: 'Billing Address City',
|
||||
column: 'billing_address_city',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
billingAddressCountry: {
|
||||
name: 'Billing Address Country',
|
||||
column: 'billing_address_country',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
billingAddressPostcode: {
|
||||
name: 'Billing Address Postcode',
|
||||
column: 'billing_address_postcode',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
billingAddressState: {
|
||||
name: 'Billing Address State',
|
||||
column: 'billing_address_state',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
billingAddressPhone: {
|
||||
name: 'Billing Address Phone',
|
||||
column: 'billing_address_phone',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
// Shipping Address
|
||||
shippingAddress1: {
|
||||
name: 'Shipping Address 1',
|
||||
column: 'shipping_address1',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
shippingAddress2: {
|
||||
name: 'Shipping Address 2',
|
||||
column: 'shipping_address2',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
shippingAddressCity: {
|
||||
name: 'Shipping Address City',
|
||||
column: 'shipping_address_city',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
shippingAddressCountry: {
|
||||
name: 'Shipping Address Country',
|
||||
column: 'shipping_address_country',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
shippingAddressPostcode: {
|
||||
name: 'Shipping Address Postcode',
|
||||
column: 'shipping_address_postcode',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
shippingAddressState: {
|
||||
name: 'Shipping Address State',
|
||||
column: 'shipping_address_state',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
},
|
||||
shippingAddressPhone: {
|
||||
name: 'Shipping Address Phone',
|
||||
column: 'shipping_address_phone',
|
||||
type: 'text',
|
||||
exportable: true,
|
||||
}
|
||||
},
|
||||
fields2: {
|
||||
|
||||
@@ -12,6 +12,7 @@ export default {
|
||||
sortOrder: 'DESC',
|
||||
sortField: 'name',
|
||||
},
|
||||
exportable: true,
|
||||
importable: true,
|
||||
importAggregator: 'group',
|
||||
importAggregateOn: 'entries',
|
||||
@@ -76,6 +77,37 @@ export default {
|
||||
fieldType: 'date',
|
||||
},
|
||||
},
|
||||
columns: {
|
||||
vendorId: {
|
||||
name: 'Vendor',
|
||||
type: 'relation',
|
||||
accessor: 'vendor.displayName',
|
||||
},
|
||||
exchangeRate: {
|
||||
name: 'Echange Rate',
|
||||
type: 'text',
|
||||
},
|
||||
vendorCreditNumber: {
|
||||
name: 'Vendor Credit No.',
|
||||
type: 'text',
|
||||
},
|
||||
referenceNo: {
|
||||
name: 'Refernece No.',
|
||||
type: 'text',
|
||||
},
|
||||
vendorCreditDate: {
|
||||
name: 'Vendor Credit Date',
|
||||
type: 'date',
|
||||
},
|
||||
note: {
|
||||
name: 'Note',
|
||||
type: 'text',
|
||||
},
|
||||
open: {
|
||||
name: 'Open',
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
fields2: {
|
||||
vendorId: {
|
||||
name: 'Vendor',
|
||||
@@ -122,7 +154,7 @@ export default {
|
||||
relationModel: 'Item',
|
||||
relationImportMatch: ['name', 'code'],
|
||||
required: true,
|
||||
importHint: "Matches the item name or code."
|
||||
importHint: 'Matches the item name or code.',
|
||||
},
|
||||
rate: {
|
||||
name: 'Rate',
|
||||
|
||||
@@ -16,7 +16,11 @@ export class CreditNotesExportable extends Exportable {
|
||||
*/
|
||||
public exportable(tenantId: number, query: ICreditNotesQueryDTO) {
|
||||
const parsedQuery = {
|
||||
sortOrder: 'desc',
|
||||
columnSortBy: 'created_at',
|
||||
...query,
|
||||
page: 1,
|
||||
pageSize: 12000,
|
||||
} as ICreditNotesQueryDTO;
|
||||
|
||||
return this.getCreditNotes
|
||||
|
||||
@@ -15,7 +15,11 @@ export class ExpensesExportable extends Exportable {
|
||||
*/
|
||||
public exportable(tenantId: number, query: IExpensesFilter) {
|
||||
const parsedQuery = {
|
||||
sortOrder: 'desc',
|
||||
columnSortBy: 'created_at',
|
||||
...query,
|
||||
page: 1,
|
||||
pageSize: 12000,
|
||||
} as IExpensesFilter;
|
||||
|
||||
return this.expensesApplication
|
||||
|
||||
@@ -14,6 +14,7 @@ import { BillPaymentExportable } from '../Purchases/BillPayments/BillPaymentExpo
|
||||
import { ManualJournalsExportable } from '../ManualJournals/ManualJournalExportable';
|
||||
import { CreditNotesExportable } from '../CreditNotes/CreditNotesExportable';
|
||||
import { VendorCreditsExportable } from '../Purchases/VendorCredits/VendorCreditsExportable';
|
||||
import { ItemCategoriesExportable } from '../ItemCategories/ItemCategoriesExportable';
|
||||
|
||||
@Service()
|
||||
export class ExportableResources {
|
||||
@@ -32,6 +33,7 @@ export class ExportableResources {
|
||||
private importables = [
|
||||
{ resource: 'Account', exportable: AccountsExportable },
|
||||
{ resource: 'Item', exportable: ItemsExportable },
|
||||
{ resource: 'ItemCategory', exportable: ItemCategoriesExportable },
|
||||
{ resource: 'Customer', exportable: CustomersExportable },
|
||||
{ resource: 'Vendor', exportable: VendorsExportable },
|
||||
{ resource: 'Expense', exportable: ExpensesExportable },
|
||||
@@ -43,7 +45,7 @@ export class ExportableResources {
|
||||
{ resource: 'BillPayment', exportable: BillPaymentExportable },
|
||||
{ resource: 'ManualJournal', exportable: ManualJournalsExportable },
|
||||
{ resource: 'CreditNote', exportable: CreditNotesExportable },
|
||||
{ resource: 'VendorCredit', exportable: VendorCreditsExportable }
|
||||
{ resource: 'VendorCredit', exportable: VendorCreditsExportable },
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,7 @@ import ResourceService from '../Resource/ResourceService';
|
||||
import { ExportableResources } from './ExportResources';
|
||||
import { ServiceError } from '@/exceptions';
|
||||
import { Errors } from './common';
|
||||
import { IModelMeta } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class ExportResourceService {
|
||||
@@ -22,40 +23,94 @@ export class ExportResourceService {
|
||||
*/
|
||||
async export(tenantId: number, resourceName: string, format: string = 'csv') {
|
||||
const resource = sanitizeResourceName(resourceName);
|
||||
const resourceMeta = this.resourceService.getResourceMeta(
|
||||
tenantId,
|
||||
resource
|
||||
);
|
||||
const exportable =
|
||||
this.exportableResources.registry.getExportable(resource);
|
||||
const resourceMeta = this.getResourceMeta(tenantId, resource);
|
||||
|
||||
if (!resourceMeta.exportable) {
|
||||
this.validateResourceMeta(resourceMeta);
|
||||
|
||||
const data = await this.getExportableData(tenantId, resource);
|
||||
const exportableColumns = this.getExportableColumns(resourceMeta);
|
||||
|
||||
const workbook = this.createWorkbook(data, exportableColumns);
|
||||
|
||||
return this.exportWorkbook(workbook, format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves metadata for a specific resource.
|
||||
* @param {number} tenantId - The tenant identifier.
|
||||
* @param {string} resource - The name of the resource.
|
||||
* @returns The metadata of the resource.
|
||||
*/
|
||||
private getResourceMeta(tenantId: number, resource: string) {
|
||||
return this.resourceService.getResourceMeta(tenantId, resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates if the resource metadata is exportable.
|
||||
* @param {any} resourceMeta - The metadata of the resource.
|
||||
* @throws {ServiceError} If the resource is not exportable or lacks columns.
|
||||
*/
|
||||
private validateResourceMeta(resourceMeta: any) {
|
||||
if (!resourceMeta.exportable || !resourceMeta.columns) {
|
||||
throw new ServiceError(Errors.RESOURCE_NOT_EXPORTABLE);
|
||||
}
|
||||
const data = await exportable.exportable(tenantId, {});
|
||||
}
|
||||
|
||||
const exportableColumns = Object.entries(resourceMeta.columns)
|
||||
.filter(([_, value]) => value.exportable)
|
||||
/**
|
||||
* Fetches exportable data for a given resource.
|
||||
* @param {number} tenantId - The tenant identifier.
|
||||
* @param {string} resource - The name of the resource.
|
||||
* @returns A promise that resolves to the exportable data.
|
||||
*/
|
||||
private async getExportableData(tenantId: number, resource: string) {
|
||||
const exportable =
|
||||
this.exportableResources.registry.getExportable(resource);
|
||||
return exportable.exportable(tenantId, {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts columns that are marked as exportable from the resource metadata.
|
||||
* @param {IModelMeta} resourceMeta - The metadata of the resource.
|
||||
* @returns An array of exportable columns.
|
||||
*/
|
||||
private getExportableColumns(resourceMeta: IModelMeta) {
|
||||
return Object.entries(resourceMeta.columns)
|
||||
.filter(([_, value]) => value.exportable !== false)
|
||||
.map(([key, value]) => ({
|
||||
name: value.name,
|
||||
type: value.type,
|
||||
accessor: value.accessor || key,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a workbook from the provided data and columns.
|
||||
* @param {any[]} data - The data to be included in the workbook.
|
||||
* @param {any[]} exportableColumns - The columns to be included in the workbook.
|
||||
* @returns The created workbook.
|
||||
*/
|
||||
private createWorkbook(data: any[], exportableColumns: any[]) {
|
||||
const workbook = xlsx.utils.book_new();
|
||||
const worksheetData = data.map((item) =>
|
||||
exportableColumns.map((col) => item[col.accessor])
|
||||
);
|
||||
worksheetData.unshift(exportableColumns.map((col) => col.name)); // Add header row
|
||||
worksheetData.unshift(exportableColumns.map((col) => col.name));
|
||||
|
||||
const worksheet = xlsx.utils.aoa_to_sheet(worksheetData);
|
||||
xlsx.utils.book_append_sheet(workbook, worksheet, 'Exported Data');
|
||||
return workbook;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports the workbook in the specified format.
|
||||
* @param {any} workbook - The workbook to be exported.
|
||||
* @param {string} format - The format to export the workbook in.
|
||||
* @returns The exported workbook data.
|
||||
*/
|
||||
private exportWorkbook(workbook: any, format: string) {
|
||||
if (format.toLowerCase() === 'csv') {
|
||||
// Convert to CSV using the xlsx package
|
||||
return xlsx.write(workbook, { type: 'buffer', bookType: 'csv' });
|
||||
} else if (format.toLowerCase() === 'xlsx') {
|
||||
// Write to XLSX format
|
||||
return xlsx.write(workbook, { type: 'buffer', bookType: 'xlsx' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ export class GetManualJournals {
|
||||
tenantId: number,
|
||||
filterDTO: IManualJournalsFilter
|
||||
): Promise<{
|
||||
manualJournals: IManualJournal;
|
||||
manualJournals: IManualJournal[];
|
||||
pagination: IPaginationMeta;
|
||||
filterMeta: IFilterMeta;
|
||||
}> => {
|
||||
|
||||
@@ -9,7 +9,7 @@ export class ManualJournalsExportable extends Exportable {
|
||||
private manualJournalsApplication: ManualJournalsApplication;
|
||||
|
||||
/**
|
||||
* Retrieves the accounts data to exportable sheet.
|
||||
* Retrieves the manual journals data to exportable sheet.
|
||||
* @param {number} tenantId
|
||||
* @returns
|
||||
*/
|
||||
|
||||
@@ -14,7 +14,11 @@ export class BillPaymentExportable extends Exportable {
|
||||
*/
|
||||
public exportable(tenantId: number, query: any) {
|
||||
const parsedQuery = {
|
||||
page: 1,
|
||||
pageSize: 12,
|
||||
...query,
|
||||
sortOrder: 'desc',
|
||||
columnSortBy: 'created_at',
|
||||
} as any;
|
||||
|
||||
return this.billPaymentsApplication
|
||||
|
||||
@@ -31,7 +31,7 @@ export class GetBillPayments {
|
||||
tenantId: number,
|
||||
filterDTO: IBillPaymentsFilter
|
||||
): Promise<{
|
||||
billPayments: IBillPayment;
|
||||
billPayments: IBillPayment[];
|
||||
pagination: IPaginationMeta;
|
||||
filterMeta: IFilterMeta;
|
||||
}> {
|
||||
|
||||
@@ -99,7 +99,7 @@ export class BillsApplication {
|
||||
tenantId: number,
|
||||
filterDTO: IBillsFilter
|
||||
): Promise<{
|
||||
bills: IBill;
|
||||
bills: IBill[];
|
||||
pagination: IPaginationMeta;
|
||||
filterMeta: IFilterMeta;
|
||||
}> {
|
||||
|
||||
@@ -15,7 +15,11 @@ export class BillsExportable extends Exportable {
|
||||
*/
|
||||
public exportable(tenantId: number, query: IBillsFilter) {
|
||||
const parsedQuery = {
|
||||
sortOrder: 'desc',
|
||||
columnSortBy: 'created_at',
|
||||
...query,
|
||||
page: 1,
|
||||
pageSize: 12000,
|
||||
} as IBillsFilter;
|
||||
|
||||
return this.billsApplication
|
||||
|
||||
@@ -9,14 +9,18 @@ export class VendorCreditsExportable extends Exportable {
|
||||
private getVendorCredits: ListVendorCredits;
|
||||
|
||||
/**
|
||||
* Retrieves the accounts data to exportable sheet.
|
||||
* Retrieves the vendor credits data to exportable sheet.
|
||||
* @param {number} tenantId -
|
||||
* @param {IVendorCreditsQueryDTO} query -
|
||||
* @returns {}
|
||||
*/
|
||||
public exportable(tenantId: number, query: IVendorCreditsQueryDTO) {
|
||||
const parsedQuery = {
|
||||
sortOrder: 'desc',
|
||||
columnSortBy: 'created_at',
|
||||
...query,
|
||||
page: 1,
|
||||
pageSize: 12000,
|
||||
} as IVendorCreditsQueryDTO;
|
||||
|
||||
return this.getVendorCredits
|
||||
|
||||
@@ -15,7 +15,11 @@ export class SaleEstimatesExportable extends Exportable {
|
||||
*/
|
||||
public exportable(tenantId: number, query: ISalesInvoicesFilter) {
|
||||
const parsedQuery = {
|
||||
sortOrder: 'desc',
|
||||
columnSortBy: 'created_at',
|
||||
...query,
|
||||
page: 1,
|
||||
pageSize: 12000,
|
||||
} as ISalesInvoicesFilter;
|
||||
|
||||
return this.saleEstimatesApplication
|
||||
|
||||
@@ -15,7 +15,11 @@ export class SaleInvoicesExportable extends Exportable {
|
||||
*/
|
||||
public exportable(tenantId: number, query: ISalesInvoicesFilter) {
|
||||
const parsedQuery = {
|
||||
sortOrder: 'desc',
|
||||
columnSortBy: 'created_at',
|
||||
...query,
|
||||
page: 1,
|
||||
pageSize: 120000,
|
||||
} as ISalesInvoicesFilter;
|
||||
|
||||
return this.saleInvoicesApplication
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ISalesInvoicesFilter, ISalesReceiptsFilter } from '@/interfaces';
|
||||
import { ISalesReceiptsFilter } from '@/interfaces';
|
||||
import { Exportable } from '@/services/Export/Exportable';
|
||||
import { SaleReceiptApplication } from './SaleReceiptApplication';
|
||||
|
||||
@@ -15,8 +15,12 @@ export class SaleReceiptsExportable extends Exportable {
|
||||
*/
|
||||
public exportable(tenantId: number, query: ISalesReceiptsFilter) {
|
||||
const parsedQuery = {
|
||||
sortOrder: 'desc',
|
||||
columnSortBy: 'created_at',
|
||||
...query,
|
||||
} as ISalesInvoicesFilter;
|
||||
page: 1,
|
||||
pageSize: 12,
|
||||
} as ISalesReceiptsFilter;
|
||||
|
||||
return this.saleReceiptsApp
|
||||
.getSaleReceipts(tenantId, parsedQuery)
|
||||
|
||||
Reference in New Issue
Block a user