Implement dynamic header and table color functionality

This commit is contained in:
Srinath 2026-03-03 19:59:22 +05:30
parent 83fe92d412
commit b63567aa91
1 changed files with 89 additions and 14 deletions

View File

@ -1,6 +1,19 @@
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { GlobalPritdummyData } from '../../../Features/ThemeChange/ThemeChange'; import {
GlobalPritdummyData,
GlobalSelectedPrintHeaderFontColor,
GlobalSelectedTableHeaderColor,
GlobalSelectedTableHeaderFontColor,
GlobalSelectedTableBodyColor,
GlobalSelectedTableBodyFontColor,
GlobalRowType,
GlobalSelectedFooterColor,
GlobalSelectedFooterFontColor,
GlobalSelectedNetAmountColor,
GlobalSelectedNetAmountFontColor,
GlobalSelectedPrintHeaderColor,
} from '../../../Features/ThemeChange/ThemeChange';
import { isMobile } from 'react-device-detect'; import { isMobile } from 'react-device-detect';
import { extractLastNumberOrderId } from '../../../Services/Others'; import { extractLastNumberOrderId } from '../../../Services/Others';
import moment from 'moment'; import moment from 'moment';
@ -18,6 +31,17 @@ const PurPrintstyleInvoice = ({
}) => { }) => {
const GlobaldummyData = useSelector(GlobalPritdummyData); const GlobaldummyData = useSelector(GlobalPritdummyData);
const SelectedHeaderColor = useSelector(GlobalSelectedPrintHeaderColor);
const SelectedHeaderFontColor = useSelector(GlobalSelectedPrintHeaderFontColor);
const SelectedTableHeaderColor = useSelector(GlobalSelectedTableHeaderColor);
const SelectedTableHeaderFontColor = useSelector(GlobalSelectedTableHeaderFontColor);
const SelectedTableBodyColor = useSelector(GlobalSelectedTableBodyColor);
const SelectedTableBodyFontColor = useSelector(GlobalSelectedTableBodyFontColor);
const SelectedRowType = useSelector(GlobalRowType);
const SelectedTableFooterColor = useSelector(GlobalSelectedFooterColor);
const SelectedTableFooterFontColor = useSelector(GlobalSelectedFooterFontColor);
const SelectedNetAmountColor = useSelector(GlobalSelectedNetAmountColor);
const SelectedNetAmountFontColor = useSelector(GlobalSelectedNetAmountFontColor);
let BillName = printDatas?.PrintHdrName let BillName = printDatas?.PrintHdrName
// Function to convert number to words // Function to convert number to words
const numberToWords = (num) => { const numberToWords = (num) => {
@ -92,9 +116,12 @@ const PurPrintstyleInvoice = ({
let PageSize = printDatas?.PageSize let PageSize = printDatas?.PageSize
const TakeawayData = table2Data?.ProductDetails let printColors = printDatas?.PrintColors;
const headerColor = printColors?.find(obj => obj.headerColor)?.headerColor;
const DineInData = table2Data?.ProductDetails const tableHeaderColor = printColors?.find(obj => obj.tableHeaderColor)?.tableHeaderColor;
const tableBodyColor = printColors?.find(obj => obj.tableBodyColor)?.tableBodyColor;
const footerColor = printColors?.find(obj => obj.footerColor)?.footerColor;
const netAmtColor = printColors?.find(obj => obj.netAmtColor)?.netAmtColor;
const cgstTotal = OrderDetailGST && OrderDetailGST.length > 0 const cgstTotal = OrderDetailGST && OrderDetailGST.length > 0
? Number(OrderDetailGST.reduce((sum, item) => sum + (item.CGST || 0), 0))?.toFixed(2) ? Number(OrderDetailGST.reduce((sum, item) => sum + (item.CGST || 0), 0))?.toFixed(2)
@ -158,7 +185,51 @@ const PurPrintstyleInvoice = ({
if (shouldFooterBeOnNewPage && paginatedChunks.length > 0) { if (shouldFooterBeOnNewPage && paginatedChunks.length > 0) {
paginatedChunks.push([]); // Empty chunk for footer-only page paginatedChunks.push([]); // Empty chunk for footer-only page
} }
const headerStyle = {
backgroundColor: GlobaldummyData
? SelectedHeaderColor
: headerColor?.background,
color: GlobaldummyData
? SelectedHeaderFontColor
: headerColor?.font,
}
const tableHeaderStyle = {
backgroundColor: GlobaldummyData
? SelectedTableHeaderColor
: tableHeaderColor?.background,
color: GlobaldummyData
? SelectedTableHeaderFontColor
: tableHeaderColor?.font,
}
const tableBodyStyle = {
backgroundColor: GlobaldummyData
? SelectedTableBodyColor
: tableBodyColor?.background,
color: GlobaldummyData
? SelectedTableBodyFontColor
: tableBodyColor?.font,
}
const rowtypeStyle = GlobaldummyData ? SelectedRowType : tableBodyColor?.rowType;
const footerColorStyle = {
backgroundColor: GlobaldummyData
? SelectedTableFooterColor
: footerColor?.background,
color: GlobaldummyData
? SelectedTableFooterFontColor
: footerColor?.font,
}
const netAmountStyle = {
backgroundColor: GlobaldummyData
? SelectedNetAmountColor
: netAmtColor?.background,
color: GlobaldummyData
? SelectedNetAmountFontColor
: netAmtColor?.font,
}
return ( return (
<div id={`TaxInvoice`} style={{ <div id={`TaxInvoice`} style={{
@ -207,7 +278,7 @@ const PurPrintstyleInvoice = ({
<> <>
<div style={{ textAlign: 'center', marginBottom: '10px', display: "flex", justifyContent: "space-between", alignItems: "center", }}> <div style={{ textAlign: 'center', marginBottom: '10px', display: "flex", justifyContent: "space-between", alignItems: "center", }}>
<div></div> <div></div>
<h2 style={{ margin: '0', fontSize: '20px', fontWeight: '700' }}>{table2Data?.OrderType === "E" ? "Estimate" : (BillName ? BillName : "Tax Invoice")}</h2> <h2 style={{ margin: '0', fontSize: '20px', fontWeight: '700', }}>{table2Data?.OrderType === "E" ? "Estimate" : (BillName ? BillName : "Tax Invoice")}</h2>
<div> <div>
<div style={{ fontSize: '10px', marginTop: '2px' }}>(ORIGINAL FOR RECIPIENT)</div> <div style={{ fontSize: '10px', marginTop: '2px' }}>(ORIGINAL FOR RECIPIENT)</div>
</div> </div>
@ -232,7 +303,7 @@ const PurPrintstyleInvoice = ({
textAlign: 'left' textAlign: 'left'
}}> }}>
<div style={{ fontWeight: '700', fontSize: '15px', }}> <div style={{ fontWeight: '700', fontSize: '15px', ...headerStyle }}>
{invoiceData.companyName} {invoiceData.companyName}
</div> </div>
<div style={{ fontWeight: '700', fontSize: '12px', }}>{invoiceData.companyspecname}</div> <div style={{ fontWeight: '700', fontSize: '12px', }}>{invoiceData.companyspecname}</div>
@ -374,6 +445,7 @@ const PurPrintstyleInvoice = ({
// borderRight: '1px solid #000', // borderRight: '1px solid #000',
borderBottom: '1px solid #000', borderBottom: '1px solid #000',
borderTop: '1px solid #000', borderTop: '1px solid #000',
...tableHeaderStyle
}}> }}>
<div style={{ padding: '8px 4px', borderRight: '1px solid #000', textAlign: 'center' }}>SL.No</div> <div style={{ padding: '8px 4px', borderRight: '1px solid #000', textAlign: 'center' }}>SL.No</div>
<div style={{ padding: '8px 4px', borderRight: '1px solid #000', textAlign: 'center' }}>Description of Goods</div> <div style={{ padding: '8px 4px', borderRight: '1px solid #000', textAlign: 'center' }}>Description of Goods</div>
@ -392,6 +464,9 @@ const PurPrintstyleInvoice = ({
display: 'grid', display: 'grid',
gridTemplateColumns: '5% 40% 12% 10% 12% 8% 13%', gridTemplateColumns: '5% 40% 12% 10% 12% 8% 13%',
// borderRight: '1px solid #000', // borderRight: '1px solid #000',
...(rowtypeStyle === (index % 2 === 0 ? "even" : "odd")
? tableBodyStyle
: {}),
}}> }}>
<div style={{ padding: '8px 4px', borderRight: '1px solid #000', textAlign: 'center', fontWeight: '700' }}>{chunkIndex * chunkSize + index + 1}</div> <div style={{ padding: '8px 4px', borderRight: '1px solid #000', textAlign: 'center', fontWeight: '700' }}>{chunkIndex * chunkSize + index + 1}</div>
@ -555,7 +630,7 @@ const PurPrintstyleInvoice = ({
</div> </div>
<div style={{ borderRight: '1px solid #000' }}></div> <div style={{ borderRight: '1px solid #000' }}></div>
<div style={{ borderRight: '1px solid #000' }}></div> <div style={{ borderRight: '1px solid #000' }}></div>
<div style={{ padding: '8px 6px', textAlign: 'right', }}> <div style={{ padding: '8px 6px', textAlign: 'right',...netAmountStyle }}>
{Number(invoiceData.grandTotal).toLocaleString('en-IN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })} {Number(invoiceData.grandTotal).toLocaleString('en-IN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
</div> </div>
</div> </div>