Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
06ede7d
Demo static pdf
abbasmithaiwala Apr 16, 2025
8fcbaa6
Added header to demo static pdf
abbasmithaiwala Apr 16, 2025
d78d0c0
Added Pdf Header Settings and frontend to test it
abbasmithaiwala Apr 17, 2025
91d3112
Minor Changes
abbasmithaiwala Apr 17, 2025
6ad49b9
Minor Changes
abbasmithaiwala Apr 17, 2025
c0e8082
Proper type usage
abbasmithaiwala Apr 17, 2025
42cbcc7
Added header right strings
abbasmithaiwala Apr 17, 2025
5efa2ff
Fixed layout for header right strings
abbasmithaiwala Apr 17, 2025
50e90ad
Fixed title layout
abbasmithaiwala Apr 17, 2025
bbcd8b8
Changed eslint to biome
abbasmithaiwala Apr 18, 2025
4ec6885
Shifted data into data folder
abbasmithaiwala Apr 18, 2025
aa6c5fd
Made changes in package json and stuff
abbasmithaiwala Apr 18, 2025
5625342
Made data more dynamic
abbasmithaiwala Apr 18, 2025
185c600
Made header right strings dynamic
abbasmithaiwala Apr 18, 2025
9e08d13
Made modular components
abbasmithaiwala Apr 18, 2025
50ec132
Layout changes
abbasmithaiwala Apr 18, 2025
6af7e4c
Layout changes
abbasmithaiwala Apr 18, 2025
cfa7355
Custom styling in company Details
abbasmithaiwala Apr 18, 2025
6522355
refactored to make it more short & readable
krishna-404 Apr 18, 2025
50cfc49
Merge pull request #1 from teziapp/pdf-abbas
abbasmithaiwala Apr 18, 2025
c9efc36
Restructured components and added filename for download
abbasmithaiwala Apr 19, 2025
b586268
Changed components to ts files
abbasmithaiwala Apr 19, 2025
b74db6b
Minor Changes
abbasmithaiwala Apr 19, 2025
83a4724
Made different section for godname
abbasmithaiwala Apr 19, 2025
71f2079
Fixed Type errors
abbasmithaiwala Apr 19, 2025
acbeee5
Minor Changes
abbasmithaiwala Apr 19, 2025
ceab9ae
Merge branch 'main' into pdf-merge
abbasmithaiwala Apr 21, 2025
8554cf9
Merged main into pdf-merge
abbasmithaiwala Apr 21, 2025
b7a2db6
Merge branch 'main' into pdf-merge
abbasmithaiwala Apr 21, 2025
5ac0522
Added Download pdf functionality which currently uses static data
abbasmithaiwala Apr 21, 2025
552191c
headerSettings refactored into one
abbasmithaiwala Apr 21, 2025
8212bb5
More Modular
abbasmithaiwala Apr 21, 2025
8792069
Layout and schema changes
abbasmithaiwala Apr 21, 2025
26ccd2a
Decreased logo size
abbasmithaiwala Apr 21, 2025
c6ecb8d
Minor Changes
abbasmithaiwala Apr 21, 2025
600a434
Minor Changes
abbasmithaiwala Apr 21, 2025
9e80c76
Minor Changes
abbasmithaiwala Apr 21, 2025
9ef55d4
Minor Changes
abbasmithaiwala Apr 21, 2025
841737b
Shifted toolbar components into new file
abbasmithaiwala Apr 21, 2025
30e9029
Fixed dev dep issues
abbasmithaiwala Apr 21, 2025
ff5bafa
Fixed dev dep issues
abbasmithaiwala Apr 21, 2025
81aba86
Made toolbar components an array
abbasmithaiwala Apr 21, 2025
de8870a
Moved all the styles into main docDef
abbasmithaiwala Apr 22, 2025
0e0a3c1
Minor Changes
abbasmithaiwala Apr 22, 2025
127bdf4
Moved header into content
abbasmithaiwala Apr 22, 2025
9c015ba
Added image headers functionality
abbasmithaiwala Apr 22, 2025
7785530
Added proper passing of headers
abbasmithaiwala Apr 22, 2025
f0f3e47
Minor changes
abbasmithaiwala Apr 22, 2025
566824a
Removed unused styles
abbasmithaiwala Apr 22, 2025
051a1d2
Removed css.d.ts
abbasmithaiwala Apr 24, 2025
7a9a5e7
Used pdfmake imagedef type eveywhere and also used head method for im…
abbasmithaiwala Apr 24, 2025
83749e9
Moved static styles from headerRightStrings to docDef
abbasmithaiwala Apr 24, 2025
a5d4996
Moved all the header components to headerRegularPdfMake
abbasmithaiwala Apr 24, 2025
0990e61
Removed using different helper functions
abbasmithaiwala Apr 24, 2025
95dcd5e
Minor changes
abbasmithaiwala Apr 24, 2025
1ae245c
Minor changes
abbasmithaiwala Apr 24, 2025
65d8df8
added primary table title, subtitle
abbasmithaiwala Apr 24, 2025
4df2226
Primary Table file
abbasmithaiwala Apr 25, 2025
28b22ef
Minor Changes
abbasmithaiwala Apr 25, 2025
3c097ad
Minor Changes
abbasmithaiwala Apr 25, 2025
f001719
Minor Changes
abbasmithaiwala Apr 25, 2025
1fc2b0b
Minor Changes
abbasmithaiwala Apr 25, 2025
355fb36
fixed primarytable issue
abbasmithaiwala Apr 25, 2025
f3356be
Minor Changes
abbasmithaiwala Apr 25, 2025
a071913
Outstanding Primary table progress
abbasmithaiwala Apr 25, 2025
3c7ecab
Removed unused simple table
abbasmithaiwala Apr 25, 2025
3c992d1
Fixed layout colspan for ledgerRightString
abbasmithaiwala Apr 25, 2025
fd11272
Mapped supplier data
abbasmithaiwala Apr 25, 2025
2bb002e
Layout changes
abbasmithaiwala Apr 25, 2025
edefe55
More data
abbasmithaiwala Apr 25, 2025
edd9e34
Made colspan in primary table dynamic
abbasmithaiwala Apr 25, 2025
6331762
Two column layout for totals and ledgerRightStrings
abbasmithaiwala Apr 25, 2025
cd6a7aa
two column layout for supplier and ledger right string
abbasmithaiwala Apr 25, 2025
56b035d
Added table cell summable style and fixed breaking title cell issue
abbasmithaiwala Apr 25, 2025
30a000c
Minor Changes
abbasmithaiwala Apr 25, 2025
f5e952a
Fixed the subtitle row right strings and total error
abbasmithaiwala Apr 25, 2025
f2fdd8b
Major Layout changes
abbasmithaiwala Apr 25, 2025
a25094d
More data
abbasmithaiwala Apr 25, 2025
1a7fe0d
Minor Changes
abbasmithaiwala Apr 25, 2025
4a53612
Made the header repeat on every page
abbasmithaiwala Apr 26, 2025
c04b429
Header on first page
abbasmithaiwala Apr 26, 2025
97e9cfe
Fixed the header on every page layout
abbasmithaiwala Apr 26, 2025
9733cd9
Fixed the break line issue
abbasmithaiwala Apr 26, 2025
4149fee
Fixed repeating rows
abbasmithaiwala Apr 26, 2025
befb748
Fixed header margin issues
abbasmithaiwala Apr 26, 2025
ccefdd5
Decreased page margins
abbasmithaiwala Apr 26, 2025
8e59b9c
Made borders darker
abbasmithaiwala Apr 26, 2025
8ef0f58
Added color fill in supplier row
abbasmithaiwala Apr 26, 2025
e5a2177
Outstanding i.e. title row not repeating when header on every page is…
abbasmithaiwala Apr 27, 2025
50e5826
Decreased margin in header right string
abbasmithaiwala Apr 27, 2025
b148b2b
Title row repeating issue fixed
abbasmithaiwala Apr 27, 2025
521cf76
Updated some types
abbasmithaiwala Apr 28, 2025
42d312e
Reverted types
abbasmithaiwala Apr 28, 2025
2d4997f
Removed unnecessary property
abbasmithaiwala Apr 28, 2025
a36ffc3
Made primary table code more modular
abbasmithaiwala Apr 28, 2025
c80bcf5
Fixed headerline breaking issue
abbasmithaiwala Apr 28, 2025
04f3144
Minor Changes
abbasmithaiwala Apr 28, 2025
ee0ee84
Simpler header logic
abbasmithaiwala Apr 28, 2025
7f6bc76
Minor Changes
abbasmithaiwala Apr 28, 2025
63da4c4
Removed unnecessary code
abbasmithaiwala Apr 28, 2025
a45ff17
Minor Changes
abbasmithaiwala Apr 28, 2025
5c14404
Minor changes
abbasmithaiwala Apr 28, 2025
d4b229c
minor changes
abbasmithaiwala Apr 28, 2025
7deda3a
Shifted types
abbasmithaiwala Apr 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ dist-ssr
*.sw?

*storybook.log

.cursor
1,090 changes: 719 additions & 371 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
"dist"
],
"peerDependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@mui/icons-material": "^7.0.2",
"@mui/material": "^7.0.2",
"@mui/x-date-pickers": "^8.0.0",
"material-react-table": "^3.2.1"
"material-react-table": "^3.2.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"pdfmake": "^0.2.18"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
Expand Down Expand Up @@ -53,7 +54,9 @@
"typescript-eslint": "^8.26.1",
"vite": "^6.3.1",
"vite-plugin-dts": "^4.5.3",
"vitest": "^3.1.1"
"vitest": "^3.1.1",
"@types/pdfmake": "^0.2.11"

},
"eslintConfig": {
"extends": [
Expand Down
20 changes: 20 additions & 0 deletions src/components/smart_report_mrt/handleDownloadPdf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { getPdfMakeDocDefinition } from "../../pdf/getPdfMakeDocDefinition";
import { downloadPdf } from "../../pdf/generatePdf";
import {
headerSettings,
tableData,
sampleContent
} from "../../pdf/staticpdfContent";

export const handleDownloadPdf = async () => {
const docDefinition = await getPdfMakeDocDefinition(
{
content: sampleContent,
},
headerSettings,
tableData // Include the ledger data from staticpdfContent
);

// Download the PDF
downloadPdf(docDefinition, 'document.pdf');
};
30 changes: 18 additions & 12 deletions src/components/smart_report_mrt/smart_report_mrt.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import TableViewIcon from '@mui/icons-material/TableView';
import ViewModuleIcon from '@mui/icons-material/ViewModule';
import PictureAsPdfIcon from '@mui/icons-material/PictureAsPdf';
import { Button } from "@mui/material";
import { MaterialReactTable, MaterialReactTableProps, MRT_RowData } from "material-react-table";
import { useState } from "react";
import "./smart_report_mrt.css";

import { handleDownloadPdf } from "./handleDownloadPdf";
/*
TODO: (Responsive Card View)
- Add a field `showInCardView` to the column definition. Default to false.
Expand All @@ -29,16 +29,22 @@ export const SmartReportMRT = <T extends MRT_RowData>(props: MaterialReactTableP
muiTableBodyCellProps = {({ cell }) => ({
'data-label': cell.column.columnDef.header,
})}
renderTopToolbar = {() => (
<div className="top-toolbar">
<Button
onClick={() => setForceTableView(!forceTableView)}
startIcon={forceTableView ? <ViewModuleIcon /> : <TableViewIcon />}
>
{forceTableView ? 'Switch to Card View' : null}
</Button>
</div>
)}
renderTopToolbar = {() => [
<Button
key="viewToggle"
onClick={() => setForceTableView(!forceTableView)}
startIcon={forceTableView ? <ViewModuleIcon /> : <TableViewIcon />}
>
{forceTableView ? 'Switch to Card View' : null}
</Button>,
<Button
key="downloadPdf"
onClick={handleDownloadPdf}
startIcon={<PictureAsPdfIcon />}
>
Download PDF
</Button>
]}

{...props}
/>
Expand Down
9 changes: 9 additions & 0 deletions src/pdf/generatePdf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as pdfMake from 'pdfmake/build/pdfmake';
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
import { TDocumentDefinitions } from 'pdfmake/interfaces';

(pdfMake as any).vfs = (pdfFonts as any).vfs;

export const openPdf = (docDefinition: TDocumentDefinitions) => pdfMake.createPdf(docDefinition).open();

export const downloadPdf = (docDefinition: TDocumentDefinitions, filename: 'document.pdf') => pdfMake.createPdf(docDefinition).download(filename);
118 changes: 118 additions & 0 deletions src/pdf/getPdfMakeDocDefinition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { Content, TDocumentDefinitions, ImageDefinition } from 'pdfmake/interfaces';
import { getHeaderDefinition } from './headers/getHeaderDefinition';
import { HeaderSettings } from './types/PdfMake';
import { generatePrimaryTable, TableData } from './outstanding/primaryTable';

export const getPdfMakeDocDefinition = async (
inputDocDefinition: Omit<TDocumentDefinitions, 'header'>,
headerSettings?: HeaderSettings,
tableData?: TableData[]
) => {
let docDefinition: TDocumentDefinitions = {
pageMargins: [20, 10, 20, 20],
...inputDocDefinition,
};

if (headerSettings) {
// Get header images and styles
const { images, styles } = await getHeaderDefinition(headerSettings);

// Add images to document definition
docDefinition.images = {
...(docDefinition.images || {}),
...(images as Record<string, string | ImageDefinition>),
};

// Add styles to document definition
docDefinition.styles = {
...(docDefinition.styles || {}),
...styles,
ledgerTitle: {
alignment: 'center',
bold: true,
fontSize: 14,
},
ledgerSubtitle: {
alignment: 'center',
bold: true,
fontSize: 10
},
ledgerRightStrings: {
alignment: 'right',
fontSize: 8,
},
supplierRightStrings: {
alignment: 'right',
fontSize: 8,
fillColor: '#eeeeee'
},
ledgerTotals: {
alignment: 'left',
fontSize: 8
},
ledgerCell: {
fontSize: 8,
alignment: 'left',
margin: [0, 2, 0, 2]
},
ledgerHeader: {
fontSize: 10,
bold: true,
alignment: 'left',
fillColor: '#eeeeee',
margin: [0, 2, 0, 2],
},
tableCellSummable:{
alignment: 'right',
fontSize: 8,
margin: [0, 2, 0, 2]
}
};

// Get existing content as array
const existingContent = Array.isArray(docDefinition.content)
? docDefinition.content
: docDefinition.content
? [docDefinition.content]
: [];

// Create an array for content
const contentArray: Content[] = [];

// Add primary table with repeating header if data is provided
if (tableData && tableData.length > 0) {
// Always include the header content on at least the first page
const { content: headerContent } = await getHeaderDefinition(headerSettings);

// Generate the table with repeating headers only if headerOnEveryPage is true
const table = await generatePrimaryTable({
data: tableData,
headerSettings,
});

// If header should not repeat on every page, add it separately before the table
if (!headerSettings.headerOnEveryPage) {
contentArray.push(
headerContent as Content,
{ text: '', margin: [0, 10, 0, 0] } as Content
);
}

contentArray.push(table);
} else {
// If no table data, add the header content separately
const { content } = await getHeaderDefinition(headerSettings);
contentArray.push(
content as Content,
{ text: '', margin: [0, 10, 0, 0] } as Content
);
}

// Add the existing content
contentArray.push(...existingContent);

docDefinition.content = contentArray;
}

return docDefinition;
};
11 changes: 11 additions & 0 deletions src/pdf/headers/getHeaderDefinition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { HeaderSettings } from "../types/PdfMake";
import { getHeaderRegularDocDef } from "./templates/headerRegularPdfMake";

export const headerTemplates = {
regular: getHeaderRegularDocDef
}

export const getHeaderDefinition = (headerSettings: HeaderSettings) => {
const { template } = headerSettings;
return headerTemplates[template](headerSettings);
}
87 changes: 87 additions & 0 deletions src/pdf/headers/templates/headerRegularPdfMake.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { HeaderSettings } from '../../types/PdfMake';
import { StyleDictionary, ImageDefinition } from 'pdfmake/interfaces';
import { checkImageValidGetDef } from '../../utils/fetchValidImageURL';

// Main function to assemble the header
export const getHeaderRegularDocDef = async ({
headerContent,
headerRightStrings,
}: HeaderSettings) => {
// Get validated image if available
const logoSection = headerContent.image
? await checkImageValidGetDef({
url: headerContent.image.url,
...(headerContent.image.headers && { headers: headerContent.image.headers }),
} as ImageDefinition)
: undefined;

const styles: StyleDictionary = {
headerContent: {
alignment: 'left',
margin: [0, 0, 0, 5],
fontSize: 10,
bold: false,
},
headerImage: {
alignment: 'center',
margin: [10, 10, 0, 0],
},
headerRightStrings: {
margin: [0, 0, 10, 5],
alignment: 'right',
fontSize: 10,
bold: false,
},
headerTopSection: {
alignment: 'center',
color: 'red',
fontSize: 8,
bold: true,
margin: [0, 0, 0, 0],
},
};

// Set up images dictionary with the validated URL
const images = logoSection?.image || {};

const docDef = {
images, // Use the image dictionary with headerLogo key
content: [
// Add top section above the table if it exists
...(headerContent.topSection ? [{ stack: headerContent.topSection }] : []),
{
table: {
widths: ['20%', '40%', '40%'],
body: [
[
...(logoSection?.imageDef && images.headerLogo
? [
{
image: 'headerLogo', // Reference the image key
fit: [100, 100],
margin: [0, 0, 0, 0],
style: 'headerImage',
},
]
: [{ text: '' }]),
headerContent.content ? { stack: headerContent.content } : { text: '' },
headerRightStrings ? { stack: headerRightStrings } : { text: '' },
],
],
},
layout: 'noBorders',
},
{
table: {
headerRows: 1,
widths: ['*'],
body: [[''], ['']],
},
layout: 'headerLineOnly',
},
],
styles,
};

return docDef;
};
Loading