feat: style resource printable columns

This commit is contained in:
Ahmed Bouhuolia
2024-05-31 18:12:09 +02:00
parent 08ad117331
commit 79be4266bb
13 changed files with 157 additions and 16 deletions

View File

@@ -4,16 +4,11 @@ body {
font-family: system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue","Noto Sans","Liberation Sans",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; font-family: system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue","Noto Sans","Liberation Sans",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
font-size: 12px; font-size: 12px;
line-height: 1.4; line-height: 1.4;
margin: 0;
} }
.sheet{
padding: 20px;
}
.sheet__title{ .sheet__title{
margin-bottom: 18px; margin-bottom: 18px;
} }
.sheet__title h2{ .sheet__title h2{
line-height: 1; line-height: 1;
margin-top: 0; margin-top: 0;
@@ -23,14 +18,13 @@ body {
.sheet__table { .sheet__table {
font-size: inherit; font-size: inherit;
line-height: inherit; line-height: inherit;
width: 100%;
} }
.sheet__table { .sheet__table {
table-layout: auto; table-layout: auto;
border-collapse: collapse; border-collapse: collapse;
width: 100%; width: 100%;
} }
.sheet__table thead tr th { .sheet__table thead tr th {
border-top: 1px solid #000; border-top: 1px solid #000;
border-bottom: 1px solid #000; border-bottom: 1px solid #000;
@@ -38,7 +32,6 @@ body {
padding: 8px; padding: 8px;
line-height: 1.2; line-height: 1.2;
} }
.sheet__table tbody tr td { .sheet__table tbody tr td {
padding: 4px 8px; padding: 4px 8px;
border-bottom: 1px solid #CCC; border-bottom: 1px solid #CCC;

View File

@@ -122,6 +122,10 @@ export type IModelMetaCollectionField = IModelMetaCollectionFieldCommon &
export type IModelMetaRelationField = IModelMetaRelationFieldCommon & export type IModelMetaRelationField = IModelMetaRelationFieldCommon &
IModelMetaRelationEnumerationField; IModelMetaRelationEnumerationField;
interface IModelPrintMeta{
pageTitle: string;
}
export interface IModelMeta { export interface IModelMeta {
defaultFilterField: string; defaultFilterField: string;
defaultSort: IModelMetaDefaultSort; defaultSort: IModelMetaDefaultSort;
@@ -134,6 +138,8 @@ export interface IModelMeta {
importAggregateOn?: string; importAggregateOn?: string;
importAggregateBy?: string; importAggregateBy?: string;
print?: IModelPrintMeta;
fields: { [key: string]: IModelMetaField }; fields: { [key: string]: IModelMetaField };
columns: { [key: string]: IModelMetaColumn }; columns: { [key: string]: IModelMetaColumn };
} }

View File

@@ -8,6 +8,9 @@ export default {
}, },
importable: true, importable: true,
exportable: true, exportable: true,
print: {
pageTitle: 'Chart of Accounts',
},
fields: { fields: {
name: { name: {
name: 'account.field.name', name: 'account.field.name',
@@ -133,6 +136,7 @@ export default {
}, },
createdAt: { createdAt: {
name: 'account.field.created_at', name: 'account.field.created_at',
printable: false,
}, },
}, },
fields2: { fields2: {

View File

@@ -6,6 +6,9 @@ export default {
sortOrder: 'DESC', sortOrder: 'DESC',
sortField: 'created_at', sortField: 'created_at',
}, },
print: {
pageTitle: 'Customers',
},
fields: { fields: {
first_name: { first_name: {
name: 'vendor.field.first_name', name: 'vendor.field.first_name',
@@ -127,100 +130,121 @@ export default {
balance: { balance: {
name: 'vendor.field.balance', name: 'vendor.field.balance',
type: 'number', type: 'number',
accessor: 'formattedBalance',
}, },
openingBalance: { openingBalance: {
name: 'vendor.field.opening_balance', name: 'vendor.field.opening_balance',
type: 'number', type: 'number',
printable: false
}, },
openingBalanceAt: { openingBalanceAt: {
name: 'vendor.field.opening_balance_at', name: 'vendor.field.opening_balance_at',
type: 'date', type: 'date',
printable: false
}, },
currencyCode: { currencyCode: {
name: 'vendor.field.currency', name: 'vendor.field.currency',
type: 'text', type: 'text',
printable: false
}, },
status: { status: {
name: 'vendor.field.status', name: 'vendor.field.status',
printable: false
}, },
note: { note: {
name: 'vendor.field.note', name: 'vendor.field.note',
printable: false
}, },
// Billing Address // Billing Address
billingAddress1: { billingAddress1: {
name: 'Billing Address 1', name: 'Billing Address 1',
column: 'billing_address1', column: 'billing_address1',
type: 'text', type: 'text',
printable: false
}, },
billingAddress2: { billingAddress2: {
name: 'Billing Address 2', name: 'Billing Address 2',
column: 'billing_address2', column: 'billing_address2',
type: 'text', type: 'text',
printable: false
}, },
billingAddressCity: { billingAddressCity: {
name: 'Billing Address City', name: 'Billing Address City',
column: 'billing_address_city', column: 'billing_address_city',
type: 'text', type: 'text',
printable: false
}, },
billingAddressCountry: { billingAddressCountry: {
name: 'Billing Address Country', name: 'Billing Address Country',
column: 'billing_address_country', column: 'billing_address_country',
type: 'text', type: 'text',
printable: false
}, },
billingAddressPostcode: { billingAddressPostcode: {
name: 'Billing Address Postcode', name: 'Billing Address Postcode',
column: 'billing_address_postcode', column: 'billing_address_postcode',
type: 'text', type: 'text',
printable: false
}, },
billingAddressState: { billingAddressState: {
name: 'Billing Address State', name: 'Billing Address State',
column: 'billing_address_state', column: 'billing_address_state',
type: 'text', type: 'text',
printable: false
}, },
billingAddressPhone: { billingAddressPhone: {
name: 'Billing Address Phone', name: 'Billing Address Phone',
column: 'billing_address_phone', column: 'billing_address_phone',
type: 'text', type: 'text',
printable: false
}, },
// Shipping Address // Shipping Address
shippingAddress1: { shippingAddress1: {
name: 'Shipping Address 1', name: 'Shipping Address 1',
column: 'shipping_address1', column: 'shipping_address1',
type: 'text', type: 'text',
printable: false
}, },
shippingAddress2: { shippingAddress2: {
name: 'Shipping Address 2', name: 'Shipping Address 2',
column: 'shipping_address2', column: 'shipping_address2',
type: 'text', type: 'text',
printable: false
}, },
shippingAddressCity: { shippingAddressCity: {
name: 'Shipping Address City', name: 'Shipping Address City',
column: 'shipping_address_city', column: 'shipping_address_city',
type: 'text', type: 'text',
printable: false
}, },
shippingAddressCountry: { shippingAddressCountry: {
name: 'Shipping Address Country', name: 'Shipping Address Country',
column: 'shipping_address_country', column: 'shipping_address_country',
type: 'text', type: 'text',
printable: false
}, },
shippingAddressPostcode: { shippingAddressPostcode: {
name: 'Shipping Address Postcode', name: 'Shipping Address Postcode',
column: 'shipping_address_postcode', column: 'shipping_address_postcode',
type: 'text', type: 'text',
printable: false
}, },
shippingAddressPhone: { shippingAddressPhone: {
name: 'Shipping Address Phone', name: 'Shipping Address Phone',
column: 'shipping_address_phone', column: 'shipping_address_phone',
type: 'text', type: 'text',
printable: false
}, },
shippingAddressState: { shippingAddressState: {
name: 'Shipping Address State', name: 'Shipping Address State',
column: 'shipping_address_state', column: 'shipping_address_state',
type: 'text', type: 'text',
printable: false
}, },
createdAt: { createdAt: {
name: 'vendor.field.created_at', name: 'vendor.field.created_at',
type: 'date', type: 'date',
printable: false
}, },
}, },
fields2: { fields2: {

View File

@@ -10,6 +10,9 @@ export default {
importable: true, importable: true,
exportFlattenOn: 'categories', exportFlattenOn: 'categories',
exportable: true, exportable: true,
print: {
pageTitle: 'Expenses',
},
fields: { fields: {
payment_date: { payment_date: {
name: 'expense.field.payment_date', name: 'expense.field.payment_date',
@@ -67,7 +70,7 @@ export default {
paymentReceive: { paymentReceive: {
name: 'expense.field.payment_account', name: 'expense.field.payment_account',
type: 'text', type: 'text',
accessor: 'paymentAccount.name' accessor: 'paymentAccount.name',
}, },
referenceNo: { referenceNo: {
name: 'expense.field.reference_no', name: 'expense.field.reference_no',
@@ -75,15 +78,18 @@ export default {
}, },
paymentDate: { paymentDate: {
name: 'expense.field.payment_date', name: 'expense.field.payment_date',
accessor: 'formattedDate',
type: 'date', type: 'date',
}, },
currencyCode: { currencyCode: {
name: 'expense.field.currency_code', name: 'expense.field.currency_code',
type: 'text', type: 'text',
printable: false,
}, },
exchangeRate: { exchangeRate: {
name: 'expense.field.exchange_rate', name: 'expense.field.exchange_rate',
type: 'number', type: 'number',
printable: false,
}, },
description: { description: {
name: 'expense.field.description', name: 'expense.field.description',
@@ -111,6 +117,7 @@ export default {
publish: { publish: {
name: 'expense.field.publish', name: 'expense.field.publish',
type: 'boolean', type: 'boolean',
printable: false,
}, },
}, },
fields2: { fields2: {

View File

@@ -127,6 +127,7 @@ export default {
name: 'item.field.type', name: 'item.field.type',
type: 'text', type: 'text',
exportable: true, exportable: true,
accessor: 'typeFormatted',
}, },
name: { name: {
name: 'item.field.name', name: 'item.field.name',
@@ -142,11 +143,13 @@ export default {
name: 'item.field.sellable', name: 'item.field.sellable',
type: 'boolean', type: 'boolean',
exportable: true, exportable: true,
printable: false,
}, },
purchasable: { purchasable: {
name: 'item.field.purchasable', name: 'item.field.purchasable',
type: 'boolean', type: 'boolean',
exportable: true, exportable: true,
printable: false,
}, },
sellPrice: { sellPrice: {
name: 'item.field.cost_price', name: 'item.field.cost_price',
@@ -163,12 +166,14 @@ export default {
type: 'text', type: 'text',
accessor: 'costAccount.name', accessor: 'costAccount.name',
exportable: true, exportable: true,
printable: false,
}, },
sellAccount: { sellAccount: {
name: 'item.field.sell_description', name: 'item.field.sell_description',
type: 'text', type: 'text',
accessor: 'sellAccount.name', accessor: 'sellAccount.name',
exportable: true, exportable: true,
printable: false,
}, },
inventoryAccount: { inventoryAccount: {
name: 'item.field.inventory_account', name: 'item.field.inventory_account',
@@ -180,11 +185,13 @@ export default {
name: 'Sell description', name: 'Sell description',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false,
}, },
purchaseDescription: { purchaseDescription: {
name: 'Purchase description', name: 'Purchase description',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false,
}, },
quantityOnHand: { quantityOnHand: {
name: 'item.field.quantity_on_hand', name: 'item.field.quantity_on_hand',
@@ -206,11 +213,13 @@ export default {
name: 'item.field.active', name: 'item.field.active',
fieldType: 'boolean', fieldType: 'boolean',
exportable: true, exportable: true,
printable: false,
}, },
createdAt: { createdAt: {
name: 'item.field.created_at', name: 'item.field.created_at',
type: 'date', type: 'date',
exportable: true, exportable: true,
printable: false,
}, },
}, },
fields2: { fields2: {

View File

@@ -11,6 +11,11 @@ export default {
importAggregator: 'group', importAggregator: 'group',
importAggregateOn: 'entries', importAggregateOn: 'entries',
importAggregateBy: 'journalNumber', importAggregateBy: 'journalNumber',
print: {
pageTitle: 'Manual Journals',
},
fields: { fields: {
date: { date: {
name: 'manual_journal.field.date', name: 'manual_journal.field.date',
@@ -63,6 +68,7 @@ export default {
date: { date: {
name: 'manual_journal.field.date', name: 'manual_journal.field.date',
type: 'date', type: 'date',
accessor: 'formattedDate',
}, },
journalNumber: { journalNumber: {
name: 'manual_journal.field.journal_number', name: 'manual_journal.field.journal_number',
@@ -83,10 +89,12 @@ export default {
currencyCode: { currencyCode: {
name: 'manual_journal.field.currency', name: 'manual_journal.field.currency',
type: 'text', type: 'text',
printable: false,
}, },
exchangeRate: { exchangeRate: {
name: 'manual_journal.field.exchange_rate', name: 'manual_journal.field.exchange_rate',
type: 'number', type: 'number',
printable: false,
}, },
description: { description: {
name: 'manual_journal.field.description', name: 'manual_journal.field.description',
@@ -120,13 +128,17 @@ export default {
publish: { publish: {
name: 'Publish', name: 'Publish',
type: 'boolean', type: 'boolean',
printable: false,
}, },
publishedAt: { publishedAt: {
name: 'Published At', name: 'Published At',
printable: false,
}, },
}, },
createdAt: { createdAt: {
name: 'Created At', name: 'Created At',
accessor: 'formattedCreatedAt',
printable: false,
}, },
}, },
fields2: { fields2: {

View File

@@ -11,6 +11,11 @@ export default {
importAggregator: 'group', importAggregator: 'group',
importAggregateOn: 'entries', importAggregateOn: 'entries',
importAggregateBy: 'estimateNumber', importAggregateBy: 'estimateNumber',
print: {
pageTitle: 'Sale Estimates'
},
fields: { fields: {
amount: { amount: {
name: 'estimate.field.amount', name: 'estimate.field.amount',
@@ -86,11 +91,13 @@ export default {
estimateDate: { estimateDate: {
name: 'Estimate Date', name: 'Estimate Date',
type: 'date', type: 'date',
accessor: 'formattedEstimateDate',
exportable: true, exportable: true,
}, },
expirationDate: { expirationDate: {
name: 'Expiration Date', name: 'Expiration Date',
type: 'date', type: 'date',
accessor: 'formattedExpirationDate',
exportable: true, exportable: true,
}, },
estimateNumber: { estimateNumber: {
@@ -112,26 +119,31 @@ export default {
name: 'Exchange Rate', name: 'Exchange Rate',
type: 'number', type: 'number',
exportable: true, exportable: true,
printable: false,
}, },
currencyCode: { currencyCode: {
name: 'Currency', name: 'Currency',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false,
}, },
note: { note: {
name: 'Note', name: 'Note',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false,
}, },
termsConditions: { termsConditions: {
name: 'Terms & Conditions', name: 'Terms & Conditions',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false,
}, },
delivered: { delivered: {
name: 'Delivered', name: 'Delivered',
type: 'boolean', type: 'boolean',
exportable: true, exportable: true,
printable: false,
}, },
entries: { entries: {
name: 'Entries', name: 'Entries',
@@ -153,6 +165,7 @@ export default {
}, },
description: { description: {
name: 'Item Description', name: 'Item Description',
printable: false,
}, },
amount: { amount: {
name: 'Item Amount', name: 'Item Amount',

View File

@@ -11,6 +11,10 @@ export default {
importAggregator: 'group', importAggregator: 'group',
importAggregateOn: 'entries', importAggregateOn: 'entries',
importAggregateBy: 'invoiceNo', importAggregateBy: 'invoiceNo',
print: {
pageTitle: 'Sale invoices',
},
fields: { fields: {
customer: { customer: {
name: 'invoice.field.customer', name: 'invoice.field.customer',
@@ -94,10 +98,12 @@ export default {
invoiceDate: { invoiceDate: {
name: 'invoice.field.invoice_date', name: 'invoice.field.invoice_date',
type: 'date', type: 'date',
accessor: 'invoiceDateFormatted',
}, },
dueDate: { dueDate: {
name: 'invoice.field.due_date', name: 'invoice.field.due_date',
type: 'date', type: 'date',
accessor: 'dueDateFormatted',
}, },
referenceNo: { referenceNo: {
name: 'invoice.field.reference_no', name: 'invoice.field.reference_no',
@@ -120,10 +126,12 @@ export default {
exchangeRate: { exchangeRate: {
name: 'invoice.field.exchange_rate', name: 'invoice.field.exchange_rate',
type: 'number', type: 'number',
printable: false,
}, },
currencyCode: { currencyCode: {
name: 'invoice.field.currency', name: 'invoice.field.currency',
type: 'text', type: 'text',
printable: false,
}, },
paidAmount: { paidAmount: {
name: 'Paid Amount', name: 'Paid Amount',
@@ -136,14 +144,17 @@ export default {
invoiceMessage: { invoiceMessage: {
name: 'invoice.field.invoice_message', name: 'invoice.field.invoice_message',
type: 'text', type: 'text',
printable: false,
}, },
termsConditions: { termsConditions: {
name: 'invoice.field.terms_conditions', name: 'invoice.field.terms_conditions',
type: 'text', type: 'text',
printable: false,
}, },
delivered: { delivered: {
name: 'invoice.field.delivered', name: 'invoice.field.delivered',
type: 'boolean', type: 'boolean',
printable: false,
}, },
entries: { entries: {
name: 'Entries', name: 'Entries',
@@ -165,6 +176,7 @@ export default {
}, },
description: { description: {
name: 'Item Description', name: 'Item Description',
printable: false,
}, },
amount: { amount: {
name: 'Item Amount', name: 'Item Amount',
@@ -202,18 +214,22 @@ export default {
exchangeRate: { exchangeRate: {
name: 'invoice.field.exchange_rate', name: 'invoice.field.exchange_rate',
fieldType: 'number', fieldType: 'number',
printable: false,
}, },
currencyCode: { currencyCode: {
name: 'invoice.field.currency', name: 'invoice.field.currency',
fieldType: 'text', fieldType: 'text',
printable: false,
}, },
invoiceMessage: { invoiceMessage: {
name: 'invoice.field.invoice_message', name: 'invoice.field.invoice_message',
fieldType: 'text', fieldType: 'text',
printable: false,
}, },
termsConditions: { termsConditions: {
name: 'invoice.field.terms_conditions', name: 'invoice.field.terms_conditions',
fieldType: 'text', fieldType: 'text',
printable: false,
}, },
entries: { entries: {
name: 'invoice.field.entries', name: 'invoice.field.entries',
@@ -249,6 +265,7 @@ export default {
delivered: { delivered: {
name: 'invoice.field.delivered', name: 'invoice.field.delivered',
fieldType: 'boolean', fieldType: 'boolean',
printable: false,
}, },
}, },
}; };

View File

@@ -98,6 +98,7 @@ export default {
}, },
receiptDate: { receiptDate: {
name: 'receipt.field.receipt_date', name: 'receipt.field.receipt_date',
accessor: 'formattedReceiptDate',
type: 'date', type: 'date',
}, },
receiptNumber: { receiptNumber: {
@@ -114,10 +115,12 @@ export default {
name: 'receipt.field.receipt_message', name: 'receipt.field.receipt_message',
column: 'receipt_message', column: 'receipt_message',
type: 'text', type: 'text',
printable: false,
}, },
statement: { statement: {
name: 'receipt.field.statement', name: 'receipt.field.statement',
type: 'text', type: 'text',
printable: false,
}, },
status: { status: {
name: 'receipt.field.status', name: 'receipt.field.status',
@@ -127,6 +130,7 @@ export default {
{ key: 'closed', label: 'receipt.field.status.closed' }, { key: 'closed', label: 'receipt.field.status.closed' },
], ],
exportable: true, exportable: true,
printable: false,
}, },
entries: { entries: {
name: 'Entries', name: 'Entries',
@@ -148,6 +152,7 @@ export default {
}, },
description: { description: {
name: 'Item Description', name: 'Item Description',
printable: false,
}, },
amount: { amount: {
name: 'Item Amount', name: 'Item Amount',
@@ -158,6 +163,7 @@ export default {
createdAt: { createdAt: {
name: 'receipt.field.created_at', name: 'receipt.field.created_at',
type: 'date', type: 'date',
printable: false,
}, },
}, },
fields2: { fields2: {

View File

@@ -131,21 +131,26 @@ export default {
openingBalance: { openingBalance: {
name: 'vendor.field.opening_balance', name: 'vendor.field.opening_balance',
type: 'number', type: 'number',
printable: false
}, },
openingBalanceAt: { openingBalanceAt: {
name: 'vendor.field.opening_balance_at', name: 'vendor.field.opening_balance_at',
type: 'date', type: 'date',
printable: false
}, },
currencyCode: { currencyCode: {
name: 'vendor.field.currency', name: 'vendor.field.currency',
type: 'text', type: 'text',
printable: false
}, },
status: { status: {
name: 'vendor.field.status', name: 'vendor.field.status',
printable: false
}, },
note: { note: {
name: 'vendor.field.note', name: 'vendor.field.note',
type: 'text', type: 'text',
printable: false
}, },
// Billing Address // Billing Address
billingAddress1: { billingAddress1: {
@@ -153,42 +158,49 @@ export default {
column: 'billing_address1', column: 'billing_address1',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
billingAddress2: { billingAddress2: {
name: 'Billing Address 2', name: 'Billing Address 2',
column: 'billing_address2', column: 'billing_address2',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
billingAddressCity: { billingAddressCity: {
name: 'Billing Address City', name: 'Billing Address City',
column: 'billing_address_city', column: 'billing_address_city',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
billingAddressCountry: { billingAddressCountry: {
name: 'Billing Address Country', name: 'Billing Address Country',
column: 'billing_address_country', column: 'billing_address_country',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
billingAddressPostcode: { billingAddressPostcode: {
name: 'Billing Address Postcode', name: 'Billing Address Postcode',
column: 'billing_address_postcode', column: 'billing_address_postcode',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
billingAddressState: { billingAddressState: {
name: 'Billing Address State', name: 'Billing Address State',
column: 'billing_address_state', column: 'billing_address_state',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
billingAddressPhone: { billingAddressPhone: {
name: 'Billing Address Phone', name: 'Billing Address Phone',
column: 'billing_address_phone', column: 'billing_address_phone',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
// Shipping Address // Shipping Address
shippingAddress1: { shippingAddress1: {
@@ -196,47 +208,55 @@ export default {
column: 'shipping_address1', column: 'shipping_address1',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
shippingAddress2: { shippingAddress2: {
name: 'Shipping Address 2', name: 'Shipping Address 2',
column: 'shipping_address2', column: 'shipping_address2',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
shippingAddressCity: { shippingAddressCity: {
name: 'Shipping Address City', name: 'Shipping Address City',
column: 'shipping_address_city', column: 'shipping_address_city',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
shippingAddressCountry: { shippingAddressCountry: {
name: 'Shipping Address Country', name: 'Shipping Address Country',
column: 'shipping_address_country', column: 'shipping_address_country',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
shippingAddressPostcode: { shippingAddressPostcode: {
name: 'Shipping Address Postcode', name: 'Shipping Address Postcode',
column: 'shipping_address_postcode', column: 'shipping_address_postcode',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
shippingAddressState: { shippingAddressState: {
name: 'Shipping Address State', name: 'Shipping Address State',
column: 'shipping_address_state', column: 'shipping_address_state',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
shippingAddressPhone: { shippingAddressPhone: {
name: 'Shipping Address Phone', name: 'Shipping Address Phone',
column: 'shipping_address_phone', column: 'shipping_address_phone',
type: 'text', type: 'text',
exportable: true, exportable: true,
printable: false
}, },
createdAt: { createdAt: {
name: 'vendor.field.created_at', name: 'vendor.field.created_at',
type: 'date', type: 'date',
exportable: true, exportable: true,
printable: false
}, },
}, },
fields2: { fields2: {

View File

@@ -40,20 +40,22 @@ export class ExportResourceService {
const data = await this.getExportableData(tenantId, resource); const data = await this.getExportableData(tenantId, resource);
const transformed = this.transformExportedData(tenantId, resource, data); const transformed = this.transformExportedData(tenantId, resource, data);
const exportableColumns = this.getExportableColumns(resourceMeta);
// Returns the csv, xlsx format. // Returns the csv, xlsx format.
if (format === ExportFormat.Csv || format === ExportFormat.Xlsx) { if (format === ExportFormat.Csv || format === ExportFormat.Xlsx) {
const exportableColumns = this.getExportableColumns(resourceMeta);
const workbook = this.createWorkbook(transformed, exportableColumns); const workbook = this.createWorkbook(transformed, exportableColumns);
return this.exportWorkbook(workbook, format); return this.exportWorkbook(workbook, format);
// Returns the pdf format. // Returns the pdf format.
} else if (format === ExportFormat.Pdf) { } else if (format === ExportFormat.Pdf) {
const printableColumns = this.getPrintableColumns(resourceMeta);
return this.exportPdf.pdf( return this.exportPdf.pdf(
tenantId, tenantId,
exportableColumns, printableColumns,
transformed, transformed,
'Accounts' resourceMeta?.print?.pageTitle
); );
} }
} }
@@ -146,6 +148,32 @@ export class ExportResourceService {
return processColumns(resourceMeta.columns); return processColumns(resourceMeta.columns);
} }
private getPrintableColumns(resourceMeta: IModelMeta) {
const processColumns = (
columns: { [key: string]: IModelMetaColumn },
parent = ''
) => {
return Object.entries(columns)
.filter(([_, value]) => value.printable !== false)
.flatMap(([key, value]) => {
if (value.type === 'collection' && value.collectionOf === 'object') {
return processColumns(value.columns, key);
} else {
const group = parent;
return [
{
name: value.name,
type: value.type || 'text',
accessor: value.accessor || key,
group,
},
];
}
});
};
return processColumns(resourceMeta.columns);
}
/** /**
* Creates a workbook from the provided data and columns. * Creates a workbook from the provided data and columns.
* @param {any[]} data - The data to be included in the workbook. * @param {any[]} data - The data to be included in the workbook.
@@ -157,7 +185,6 @@ export class ExportResourceService {
const worksheetData = data.map((item) => const worksheetData = data.map((item) =>
exportableColumns.map((col) => get(item, getDataAccessor(col))) exportableColumns.map((col) => get(item, getDataAccessor(col)))
); );
worksheetData.unshift(exportableColumns.map((col) => col.name)); worksheetData.unshift(exportableColumns.map((col) => col.name));
const worksheet = xlsx.utils.aoa_to_sheet(worksheetData); const worksheet = xlsx.utils.aoa_to_sheet(worksheetData);

View File

@@ -35,7 +35,10 @@ export const getDataAccessor = (col: any) => {
export const mapPdfRows = (columns: any, data: Record<string, any>) => { export const mapPdfRows = (columns: any, data: Record<string, any>) => {
return data.map((item) => { return data.map((item) => {
const cells = columns.map((column) => { const cells = columns.map((column) => {
return { key: column.accessor, value: get(item, column.accessor) }; return {
key: column.accessor,
value: get(item, getDataAccessor(column)),
};
}); });
return { cells, classNames: '' }; return { cells, classNames: '' };
}); });