Implement dynamic header and table color functionality

This commit is contained in:
Srinath 2026-03-04 16:31:47 +05:30
parent 4a27698a59
commit d4a94da912
1 changed files with 198 additions and 51 deletions

View File

@ -29,6 +29,16 @@ import {
GlobalprintCredit,
GlobalprintTax,
GlobalSelectedPrintHeaderColor,
GlobalSelectedPrintHeaderFontColor,
GlobalSelectedTableHeaderColor,
GlobalSelectedTableHeaderFontColor,
GlobalSelectedTableBodyFontColor,
GlobalSelectedTableBodyColor,
GlobalRowType,
GlobalSelectedFooterColor,
GlobalSelectedFooterFontColor,
GlobalSelectedNetAmountColor,
GlobalSelectedNetAmountFontColor,
} from '../../../../Features/ThemeChange/ThemeChange';
import Logo from '../../../../Images/Logo.jpg';
import {
@ -150,6 +160,22 @@ const Printstyle8 = ({
);
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 printColors = printDatas?.PrintColors;
const headerColor = printColors?.find(obj => obj.headerColor)?.headerColor;
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;
console.log(GlobalDiscount, Discount, 'Discount');
@ -361,7 +387,51 @@ const Printstyle8 = ({
? paginatedChunks[paginatedChunks.length - 1].length
: 0;
const shouldFooterBeOnNewPage = lastChunkRows > (PageSize == 'A5' ? 5 : 13);
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 (
<>
{FormatTheme ? (
@ -419,7 +489,7 @@ const Printstyle8 = ({
{!estimatePrintHeader && table2Data?.OrderType === 'E' ? (
''
) : (
<div className="PrintStyle8-fistDiv" style={{}}>
<div className="PrintStyle8-fistDiv" style={{...headerStyle}}>
{/* <h3>{table2Data?.BrName}</h3> */}
<div
@ -449,7 +519,6 @@ const Printstyle8 = ({
style={{
fontSize: 'clamp(1.25rem, 2.5vw, 1.75rem)',
fontWeight: '600',
color: SelectedHeaderColor,
}}
>
{GlobaldummyData ? 'XYZ Shop' : table2Data?.BrName}
@ -562,6 +631,7 @@ const Printstyle8 = ({
? GlobalSlNo && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'center',
}}
@ -572,6 +642,7 @@ const Printstyle8 = ({
: SLNO && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'center',
}}
@ -580,12 +651,13 @@ const Printstyle8 = ({
</th>
)}
{GlobaldummyData
? GlobalItem && <th>Dis</th>
: Item && <th>Des</th>}
? GlobalItem && <th style={{...tableHeaderStyle,}}>Dis</th>
: Item && <th style={{...tableHeaderStyle,}}>Des</th>}
{GlobaldummyData
? GlobalHsnCode && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -596,6 +668,7 @@ const Printstyle8 = ({
: HsnCode && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -607,6 +680,7 @@ const Printstyle8 = ({
? GlobalMRP && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -617,6 +691,7 @@ const Printstyle8 = ({
: MRP && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -628,6 +703,7 @@ const Printstyle8 = ({
? GlobalRate && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -638,6 +714,7 @@ const Printstyle8 = ({
: Rate && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -649,6 +726,7 @@ const Printstyle8 = ({
? GlobalDiscount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -659,6 +737,7 @@ const Printstyle8 = ({
: Discount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -670,6 +749,7 @@ const Printstyle8 = ({
? GlobalTax && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -681,6 +761,7 @@ const Printstyle8 = ({
table2Data?.OrderType !== 'E' && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -692,6 +773,7 @@ const Printstyle8 = ({
? GlobalQuantity && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -702,6 +784,7 @@ const Printstyle8 = ({
: Quantity && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -713,6 +796,7 @@ const Printstyle8 = ({
? GlobalAmount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -723,6 +807,7 @@ const Printstyle8 = ({
: Amount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -735,7 +820,18 @@ const Printstyle8 = ({
<tbody>
{dataChunk?.map((item, index) => {
return (
<tr key={index}>
<tr key={index}
style={
index % 2 !== 1 && rowtypeStyle === "even"
? {
...tableBodyStyle
}
: index % 2 === 1 && rowtypeStyle === "odd"
? {
...tableBodyStyle
}
: {}
}>
{GlobaldummyData
? GlobalSlNo && (
<td style={{ textAlign: 'center' }}>
@ -931,6 +1027,7 @@ const Printstyle8 = ({
? GlobalSlNo && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'center',
}}
@ -941,6 +1038,7 @@ const Printstyle8 = ({
: SLNO && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'center',
}}
@ -949,12 +1047,13 @@ const Printstyle8 = ({
</th>
)}
{GlobaldummyData
? GlobalItem && <th>Dis</th>
: Item && <th>Des</th>}
? GlobalItem && <th style={{...tableHeaderStyle,}}>Dis</th>
: Item && <th style={{...tableHeaderStyle,}}>Des</th>}
{GlobaldummyData
? GlobalHsnCode && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -965,6 +1064,7 @@ const Printstyle8 = ({
: HsnCode && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -976,6 +1076,7 @@ const Printstyle8 = ({
? GlobalMRP && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -986,6 +1087,7 @@ const Printstyle8 = ({
: MRP && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -997,6 +1099,7 @@ const Printstyle8 = ({
? GlobalRate && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -1007,6 +1110,7 @@ const Printstyle8 = ({
: Rate && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -1018,6 +1122,7 @@ const Printstyle8 = ({
? GlobalDiscount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -1028,6 +1133,7 @@ const Printstyle8 = ({
: Discount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -1039,6 +1145,7 @@ const Printstyle8 = ({
? GlobalTax && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -1050,6 +1157,7 @@ const Printstyle8 = ({
table2Data?.OrderType !== 'E' && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -1061,6 +1169,7 @@ const Printstyle8 = ({
? GlobalQuantity && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -1071,6 +1180,7 @@ const Printstyle8 = ({
: Quantity && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -1082,6 +1192,7 @@ const Printstyle8 = ({
? GlobalAmount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -1092,6 +1203,7 @@ const Printstyle8 = ({
: Amount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -1104,7 +1216,18 @@ const Printstyle8 = ({
<tbody>
{dataChunk?.map((item, index) => {
return (
<tr key={index}>
<tr key={index}
style={
index % 2 !== 1 && rowtypeStyle === "even"
? {
...tableBodyStyle
}
: index % 2 === 1 && rowtypeStyle === "odd"
? {
...tableBodyStyle
}
: {}
}>
{GlobaldummyData
? GlobalSlNo && (
<td style={{ textAlign: 'center' }}>
@ -1256,7 +1379,7 @@ const Printstyle8 = ({
FormatTheme && (
<>
<hr className="PrintStyle8-print-dottline" />
<div style={{ fontSize: '12px' }}>
<div style={{ fontSize: '12px',...netAmountStyle }}>
<div
style={{
display: 'flex',
@ -2051,6 +2174,7 @@ const Printstyle8 = ({
pageBreakBefore: 'avoid',
pageBreakInside: 'avoid',
minHeight: 'auto',
...footerColorStyle
}}
>
{!estimatePrintHeader && table2Data?.OrderType === 'E' ? (
@ -2262,7 +2386,7 @@ const Printstyle8 = ({
>
<>
<hr className="PrintStyle8-print-dottline" />
<div style={{ fontSize: '12px' }}>
<div style={{ fontSize: '12px',...netAmountStyle }}>
<div
style={{
display: 'flex',
@ -3036,6 +3160,7 @@ const Printstyle8 = ({
pageBreakBefore: 'avoid',
pageBreakInside: 'avoid',
minHeight: 'auto',
...footerColorStyle
}}
>
{!estimatePrintHeader && table2Data?.OrderType === 'E' ? (
@ -3234,7 +3359,7 @@ const Printstyle8 = ({
{!estimatePrintHeader && table2Data?.OrderType === 'E' ? (
''
) : (
<div className="PrintStyle8-fistDiv" style={{}}>
<div className="PrintStyle8-fistDiv" style={{...headerStyle}}>
{/* <h3>{table2Data?.BrName}</h3> */}
<div
style={{
@ -3263,7 +3388,6 @@ const Printstyle8 = ({
style={{
fontSize: 'clamp(1.25rem, 2.5vw, 1.75rem)',
fontWeight: '600',
color: SelectedHeaderColor,
}}
>
{GlobaldummyData ? 'XYZ Shop' : table2Data?.BrName}
@ -3370,95 +3494,95 @@ const Printstyle8 = ({
<tr>
{GlobaldummyData
? GlobalSlNo && (
<th style={{ width: '10px', textAlign: 'center' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'center' }}>
S.No
</th>
)
: SLNO && (
<th style={{ width: '10px', textAlign: 'center' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'center' }}>
S.No
</th>
)}
{GlobaldummyData
? GlobalItem && (
<th style={{ textAlign: 'left' }}>Dis</th>
<th style={{...tableHeaderStyle, textAlign: 'left' }}>Dis</th>
)
: Item && <th>Des</th>}
: Item && <th style={{...tableHeaderStyle,}}>Des</th>}
{GlobaldummyData
? GlobalHsnCode && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
HSN
</th>
)
: HsnCode && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{ ...tableHeaderStyle,width: '10px', textAlign: 'right' }}>
HSN
</th>
)}
{GlobaldummyData
? GlobalMRP && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{ ...tableHeaderStyle,width: '10px', textAlign: 'right' }}>
MRP
</th>
)
: MRP && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
MRP
</th>
)}
{GlobaldummyData
? GlobalRate && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Rate
</th>
)
: Rate && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Rt
</th>
)}
{GlobaldummyData
? GlobalDiscount && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
(%)
</th>
)
: Discount && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
(%)
</th>
)}
{GlobaldummyData
? GlobalTax && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Tax %
</th>
)
: Tax &&
table2Data?.OrderType !== 'E' && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Tax %
</th>
)}
{GlobaldummyData
? GlobalQuantity && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Qty
</th>
)
: Quantity && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
{WeightasKg ? 'Qty/Kg' : 'Qty'}
</th>
)}
{GlobaldummyData
? GlobalAmount && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Amt
</th>
)
: Amount && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Amt
</th>
)}
@ -3468,7 +3592,18 @@ const Printstyle8 = ({
{(GlobaldummyData ? products : TakeawayData)?.map(
(item, index) => {
return (
<tr key={index}>
<tr key={index}
style={
index % 2 !== 1 && rowtypeStyle === "even"
? {
...tableBodyStyle
}
: index % 2 === 1 && rowtypeStyle === "odd"
? {
...tableBodyStyle
}
: {}
}>
{GlobaldummyData
? GlobalSlNo && (
<td style={{ textAlign: 'center' }}>
@ -3632,93 +3767,93 @@ const Printstyle8 = ({
<tr>
{GlobaldummyData
? GlobalSlNo && (
<th style={{ width: '10px', textAlign: 'center' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'center' }}>
S.No
</th>
)
: SLNO && (
<th style={{ width: '10px', textAlign: 'center' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'center' }}>
S.No
</th>
)}
{GlobaldummyData
? GlobalItem && <th>Dis</th>
: Item && <th>Des</th>}
? GlobalItem && <th style={{...tableHeaderStyle,}}>Dis</th>
: Item && <th style={{...tableHeaderStyle,}}>Des</th>}
{GlobaldummyData
? GlobalHsnCode && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
HSN
</th>
)
: HsnCode && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
HSN
</th>
)}
{GlobaldummyData
? GlobalMRP && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
MRP
</th>
)
: MRP && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
MRP
</th>
)}
{GlobaldummyData
? GlobalRate && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Rate
</th>
)
: Rate && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Rt
</th>
)}
{GlobaldummyData
? GlobalDiscount && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
(%)
</th>
)
: Discount && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
(%)
</th>
)}
{GlobaldummyData
? GlobalTax && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Tax %
</th>
)
: Tax &&
table2Data?.OrderType !== 'E' && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Tax %
</th>
)}
{GlobaldummyData
? GlobalQuantity && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Qty
</th>
)
: Quantity && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
{WeightasKg ? 'Qty/Kg' : 'Qty'}
</th>
)}
{GlobaldummyData
? GlobalAmount && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Amt
</th>
)
: Amount && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Amt
</th>
)}
@ -3728,7 +3863,18 @@ const Printstyle8 = ({
{(GlobaldummyData ? products : DineInData)?.map(
(item, index) => {
return (
<tr key={index}>
<tr key={index}
style={
index % 2 !== 1 && rowtypeStyle === "even"
? {
...tableBodyStyle
}
: index % 2 === 1 && rowtypeStyle === "odd"
? {
...tableBodyStyle
}
: {}
}>
{GlobaldummyData
? GlobalSlNo && (
<td style={{ textAlign: 'center' }}>
@ -3878,7 +4024,7 @@ const Printstyle8 = ({
</>
)}
<hr className="PrintStyle8-print-dottline" />
<div style={{ fontSize: '12px' }}>
<div style={{ fontSize: '12px',...netAmountStyle }}>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<div style={{ width: '40%' }}>Items </div>
<div> : </div>
@ -4590,6 +4736,7 @@ const Printstyle8 = ({
pageBreakBefore: 'avoid',
pageBreakInside: 'avoid',
minHeight: 'auto',
...footerColorStyle
}}
>
{!estimatePrintHeader && table2Data?.OrderType === 'E' ? (