diff --git a/packages/server/src/constants/metable-options.ts b/packages/server/src/constants/metable-options.ts index 31c3bcf1e..e16decd0c 100644 --- a/packages/server/src/constants/metable-options.ts +++ b/packages/server/src/constants/metable-options.ts @@ -1,4 +1,27 @@ -// import { getTransactionsLockingSettingsSchema } from '@/api/controllers/TransactionsLocking/utils'; +import { chain, mapKeys } from 'lodash'; + +const getTransactionsLockingSettingsSchema = (modules: string[]) => { + const moduleSchema = { + active: { type: 'boolean' }, + lock_to_date: { type: 'date' }, + unlock_from_date: { type: 'date' }, + unlock_to_date: { type: 'date' }, + lock_reason: { type: 'string' }, + unlock_reason: { type: 'string' }, + }; + return chain(modules) + .map((module: string) => { + return mapKeys(moduleSchema, (value, key: string) => `${module}.${key}`); + }) + .flattenDeep() + .reduce((result, value) => { + return { + ...result, + ...value, + }; + }, {}) + .value(); +}; export const SettingsOptions = { organization: { @@ -223,12 +246,12 @@ export const SettingsOptions = { 'locking-type': { type: 'string', }, - // ...getTransactionsLockingSettingsSchema([ - // 'all', - // 'sales', - // 'purchases', - // 'financial', - // ]), + ...getTransactionsLockingSettingsSchema([ + 'all', + 'sales', + 'purchases', + 'financial', + ]), }, features: { 'multi-warehouses': { diff --git a/packages/server/src/modules/Export/ExportPdf.ts b/packages/server/src/modules/Export/ExportPdf.ts index 88fc2923a..99f55dbb7 100644 --- a/packages/server/src/modules/Export/ExportPdf.ts +++ b/packages/server/src/modules/Export/ExportPdf.ts @@ -1,14 +1,13 @@ import { Injectable } from '@nestjs/common'; import { ChromiumlyTenancy } from '../ChromiumlyTenancy/ChromiumlyTenancy.service'; -import { TemplateInjectable } from '../TemplateInjectable/TemplateInjectable.service'; +import { renderExportResourceTableTemplateHtml } from '@bigcapital/pdf-templates'; import { mapPdfRows } from './utils'; @Injectable() export class ExportPdf { constructor( - private readonly templateInjectable: TemplateInjectable, private readonly chromiumlyTenancy: ChromiumlyTenancy, - ) {} + ) { } /** * Generates the pdf table sheet for the given data and columns. @@ -19,21 +18,18 @@ export class ExportPdf { * @returns */ public async pdf( - columns: { accessor: string }, + columns: { accessor: string; name?: string; style?: string; group?: string }[], data: Record, sheetTitle: string = '', sheetDescription: string = '' ) { const rows = mapPdfRows(columns, data); - const htmlContent = await this.templateInjectable.render( - 'modules/export-resource-table', - { - table: { rows, columns }, - sheetTitle, - sheetDescription, - } - ); + const htmlContent = renderExportResourceTableTemplateHtml({ + table: { rows, columns }, + sheetTitle, + sheetDescription, + }); // Convert the HTML content to PDF return this.chromiumlyTenancy.convertHtmlContent(htmlContent, { margins: { top: 0.2, bottom: 0.2, left: 0.2, right: 0.2 }, diff --git a/packages/webapp/src/containers/TransactionsLocking/components.tsx b/packages/webapp/src/containers/TransactionsLocking/components.tsx index 1b52f6535..7f6f84517 100644 --- a/packages/webapp/src/containers/TransactionsLocking/components.tsx +++ b/packages/webapp/src/containers/TransactionsLocking/components.tsx @@ -364,13 +364,18 @@ const TransLockingItemDesc = styled.p` `; const TransLockingIcon = styled.div` + --x-text-color: #93a1ba; + + .bp4-dark & { + --x-text-color: rgba(255, 255, 255, 0.6); + } border: 1px solid var(--color-transaction-locking-item-icon-border); height: 45px; width: 45px; text-align: center; line-height: 45px; border-radius: 8px; - color: #93a1ba; + color: var(--x-text-color); .bp4-icon { position: relative; @@ -395,15 +400,24 @@ export const TransLockingContent = styled.div` export const TransLockingReason = styled.div` font-size: 13px; + --x-text-color: #777; + .bp4-dark & { + --x-text-color: rgba(255, 255, 255, 0.6); + } strong { - color: #777; + color: var(--x-text-color); } `; const TransUnlockWrap = styled.div` + -x-border-color: #ddd; + + .bp4-dark & { + --x-border-color: rgba(255, 255, 255, 0.1); + } padding-top: 10px; - border-top: 1px solid #ddd; + border-top: 1px solid var(--x-border-color); margin-top: 10px; ${TransLockingReason} { diff --git a/shared/pdf-templates/src/components/ExportResourceTableTemplate.tsx b/shared/pdf-templates/src/components/ExportResourceTableTemplate.tsx new file mode 100644 index 000000000..42ac3c7f2 --- /dev/null +++ b/shared/pdf-templates/src/components/ExportResourceTableTemplate.tsx @@ -0,0 +1,119 @@ +import React from 'react'; +import { x } from '@xstyled/emotion'; +import { Box } from '../lib/layout/Box'; + +export interface ExportResourceTableColumn { + accessor: string; + name?: string; + style?: string; + group?: string; +} + +export interface ExportResourceTableCell { + key: string; + value: string; +} + +export interface ExportResourceTableRow { + cells: ExportResourceTableCell[]; + classNames?: string; +} + +export interface ExportResourceTableTemplateProps { + sheetTitle?: string; + sheetDescription?: string; + table: { + columns: ExportResourceTableColumn[]; + rows: ExportResourceTableRow[]; + }; + customCSS?: string; +} + +export function ExportResourceTableTemplate({ + sheetTitle, + sheetDescription, + table, + customCSS, +}: ExportResourceTableTemplateProps) { + return ( + + + {(sheetTitle || sheetDescription) && ( + + {sheetTitle && ( + + {sheetTitle} + + )} + {sheetDescription && ( + + {sheetDescription} + + )} + + )} + + + + + {table.columns.map((column) => { + let styleObj: React.CSSProperties | undefined; + if (column.style) { + try { + // Handle style as JSON string + styleObj = JSON.parse(column.style); + } catch { + // If parsing fails, ignore the style + styleObj = undefined; + } + } + return ( + + {column.name || column.accessor} + + ); + })} + + + + {table.rows.map((row, rowIndex) => ( + + {row.cells.map((cell) => ( + + + + ))} + + ))} + + + + {customCSS && ( + + )} + + + ); +} + diff --git a/shared/pdf-templates/src/index.ts b/shared/pdf-templates/src/index.ts index 51bae775e..5f9a7aee8 100644 --- a/shared/pdf-templates/src/index.ts +++ b/shared/pdf-templates/src/index.ts @@ -4,9 +4,11 @@ export * from './components/EstimatePaperTemplate'; export * from './components/ReceiptPaperTemplate'; export * from './components/PaymentReceivedPaperTemplate'; export * from './components/FinancialSheetTemplate'; +export * from './components/ExportResourceTableTemplate'; export * from './renders/render-invoice-paper-template'; export * from './renders/render-estimate-paper-template'; export * from './renders/render-receipt-paper-template'; export * from './renders/render-payment-received-paper-template'; export * from './renders/render-financial-sheet-template'; +export * from './renders/render-export-resource-table-template'; diff --git a/shared/pdf-templates/src/renders/render-export-resource-table-template.tsx b/shared/pdf-templates/src/renders/render-export-resource-table-template.tsx new file mode 100644 index 000000000..e4a1e6bf7 --- /dev/null +++ b/shared/pdf-templates/src/renders/render-export-resource-table-template.tsx @@ -0,0 +1,14 @@ +import { + ExportResourceTableTemplate, + ExportResourceTableTemplateProps, +} from '../components/ExportResourceTableTemplate'; +import { renderSSR } from './render-ssr'; + +export const renderExportResourceTableTemplateHtml = ( + props: ExportResourceTableTemplateProps +) => { + return renderSSR( + + ); +}; +