Implement dynamic header and table color functionality

This commit is contained in:
Srinath 2026-03-04 16:30:34 +05:30
parent 6af7833a6d
commit ec26930ac7
1 changed files with 181 additions and 40 deletions

View File

@ -28,7 +28,17 @@ import {
GlobalprintLogo,
GlobalprintCredit,
GlobalprintTax,
GlobalSelectedPrintHeaderColor,
GlobalSelectedPrintHeaderColor,
GlobalSelectedPrintHeaderFontColor,
GlobalSelectedTableHeaderColor,
GlobalSelectedTableHeaderFontColor,
GlobalSelectedTableBodyFontColor,
GlobalSelectedTableBodyColor,
GlobalRowType,
GlobalSelectedFooterColor,
GlobalSelectedFooterFontColor,
GlobalSelectedNetAmountColor,
GlobalSelectedNetAmountFontColor,
} from '../../../../Features/ThemeChange/ThemeChange';
import '../../../../Styles/BookingScreen/PrintTemplates/ThermalPrinter/PrintStyle4.scss';
import {
@ -101,6 +111,17 @@ const Printstyle4 = ({
const GlobalCashierName = useSelector(GlobalprintCashierName);
const GlobalLogo = useSelector(GlobalprintLogo);
const GlobalCredit = useSelector(GlobalprintCredit);
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);
const SettingData = useSelector(PreferenceData);
const totalGSTData = [
(OrderDetailGST || []).reduce(
@ -144,9 +165,13 @@ const Printstyle4 = ({
const paymentTypeUPI = PaymentStatus?.find(
(ps) => ps.PaymentTypeName === 'UPI'
);
const SelectedHeaderColor = useSelector(GlobalSelectedPrintHeaderColor);
console.log(GlobalDiscount, Discount, 'Discount');
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;
let TermsAndConditions = printDatas?.TermsandConditions;
let SignatureImg = printDatas?.Signature;
@ -348,7 +373,51 @@ const Printstyle4 = ({
: 0;
const shouldFooterBeOnNewPage = lastChunkRows > (PageSize == 'A5' ? 5 : 10);
console.log(paginatedChunks, 'paginatedChunks')
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 ? (
@ -409,7 +478,7 @@ const Printstyle4 = ({
) : (
<div
className="PrintStyle4-fistDiv"
style={{ flexDirection: 'column' }}
style={{ flexDirection: 'column',...headerStyle }}
>
<div
style={{
@ -440,7 +509,6 @@ const Printstyle4 = ({
fontWeight: '600',
width: '100%',
textAlign: 'center',
color: SelectedHeaderColor,
}}
>
{GlobaldummyData ? 'XYZ Shop' : table2Data?.BrName}{' '}
@ -573,16 +641,17 @@ const Printstyle4 = ({
<tr>
{GlobaldummyData
? GlobalSlNo && (
<th style={{ width: '10px' }}>#</th>
<th style={{...tableHeaderStyle, width: '10px' }}>#</th>
)
: SLNO && <th style={{ width: '10px' }}>#</th>}
: SLNO && <th style={{...tableHeaderStyle, width: '10px' }}>#</th>}
{GlobaldummyData
? GlobalItem && <th>Item</th>
: Item && <th>Item</th>}
? GlobalItem && <th style={{...tableHeaderStyle,}}>Item</th>
: Item && <th style={{...tableHeaderStyle,}}>Item</th>}
{GlobaldummyData
? GlobalQuantity && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -593,6 +662,7 @@ const Printstyle4 = ({
: Quantity && (
<th
style={{
...tableHeaderStyle,
width: '30px',
textAlign: 'right',
}}
@ -604,6 +674,7 @@ const Printstyle4 = ({
? GlobalHsnCode && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -614,6 +685,7 @@ const Printstyle4 = ({
: HsnCode && (
<th
style={{
...tableHeaderStyle,
width: '30px',
textAlign: 'right',
}}
@ -625,6 +697,7 @@ const Printstyle4 = ({
? GlobalMRP && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'center',
}}
@ -635,6 +708,7 @@ const Printstyle4 = ({
: MRP && (
<th
style={{
...tableHeaderStyle,
width: '30px',
textAlign: 'right',
}}
@ -646,6 +720,7 @@ const Printstyle4 = ({
? GlobalDiscount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -656,6 +731,7 @@ const Printstyle4 = ({
: Discount && (
<th
style={{
...tableHeaderStyle,
width: '30px',
textAlign: 'right',
}}
@ -667,6 +743,7 @@ const Printstyle4 = ({
? GlobalRate && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -677,6 +754,7 @@ const Printstyle4 = ({
: Rate && (
<th
style={{
...tableHeaderStyle,
width: '40px',
textAlign: 'right',
}}
@ -688,6 +766,7 @@ const Printstyle4 = ({
? GlobalAmount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -698,6 +777,7 @@ const Printstyle4 = ({
: Amount && (
<th
style={{
...tableHeaderStyle,
width: '30px',
textAlign: 'right',
}}
@ -729,7 +809,18 @@ const Printstyle4 = ({
) ?? [];
return (
<tr key={index}>
<tr key={index}
style={
index % 2 !== 1 && rowtypeStyle === "even"
? {
...tableBodyStyle
}
: index % 2 === 1 && rowtypeStyle === "odd"
? {
...tableBodyStyle
}
: {}
}>
{/* SL NO */}
{GlobaldummyData
@ -864,16 +955,16 @@ const Printstyle4 = ({
<tr>
{GlobaldummyData
? GlobalSlNo && (
<th style={{ width: '10px' }}>#</th>
<th style={{...tableHeaderStyle, width: '10px' }}>#</th>
)
: SLNO && <th style={{ width: '10px' }}>#</th>}
: SLNO && <th style={{...tableHeaderStyle, width: '10px' }}>#</th>}
{GlobaldummyData
? GlobalItem && <th>Item</th>
: Item && <th>Item</th>}
? GlobalItem && <th style={{...tableHeaderStyle,}}>Item</th>
: Item && <th style={{...tableHeaderStyle,}}>Item</th>}
{GlobaldummyData
? GlobalQuantity && (
<th
style={{
style={{...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -884,6 +975,7 @@ const Printstyle4 = ({
: Quantity && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -895,6 +987,7 @@ const Printstyle4 = ({
? GlobalHsnCode && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -905,6 +998,7 @@ const Printstyle4 = ({
: HsnCode && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -916,6 +1010,7 @@ const Printstyle4 = ({
? GlobalMRP && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -926,6 +1021,7 @@ const Printstyle4 = ({
: MRP && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -937,6 +1033,7 @@ const Printstyle4 = ({
? GlobalDiscount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -947,6 +1044,7 @@ const Printstyle4 = ({
: Discount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -958,6 +1056,7 @@ const Printstyle4 = ({
? GlobalRate && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -968,6 +1067,7 @@ const Printstyle4 = ({
: Rate && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -979,6 +1079,7 @@ const Printstyle4 = ({
? GlobalAmount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -989,6 +1090,7 @@ const Printstyle4 = ({
: Amount && (
<th
style={{
...tableHeaderStyle,
width: '10px',
textAlign: 'right',
}}
@ -1001,7 +1103,18 @@ const Printstyle4 = ({
<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>{index + 1}</td>
: SLNO && (
@ -1157,6 +1270,7 @@ const Printstyle4 = ({
borderBottom: '1px dashed #000',
borderTop: '1px dashed #000',
padding: '5px 0',
...netAmountStyle
}}
>
{' '}
@ -1894,6 +2008,7 @@ const Printstyle4 = ({
pageBreakBefore: 'avoid',
pageBreakInside: 'avoid',
minHeight: 'auto',
...footerColorStyle
}}
>
{!estimatePrintHeader && table2Data?.OrderType === 'E' ? (
@ -2134,6 +2249,7 @@ const Printstyle4 = ({
borderBottom: '1px dashed #000',
borderTop: '1px dashed #000',
padding: '5px 0',
...netAmountStyle
}}
>
<div>Sub Total</div>
@ -2848,6 +2964,7 @@ const Printstyle4 = ({
pageBreakBefore: 'avoid',
pageBreakInside: 'avoid',
minHeight: 'auto',
...footerColorStyle
}}
>
{!estimatePrintHeader && table2Data?.OrderType === 'E' ? (
@ -3057,7 +3174,7 @@ const Printstyle4 = ({
) : (
<div
className="PrintStyle4-fistDiv"
style={{ flexDirection: 'column' }}
style={{ flexDirection: 'column',...headerStyle }}
>
<div
style={{
@ -3066,14 +3183,14 @@ const Printstyle4 = ({
alignItems: 'center',
}}
>
{/* {GlobaldummyData && GlobalLogo ? (
{GlobaldummyData && GlobalLogo ? (
<img
className="PrintStyle2-BrandImage"
src={Logo}
alt="image"
/>
) : null} */}
{/* {base64Image &&
) : null}
{base64Image &&
(PrintLogo?.SettingValue === 'Y' || LogoField) ? (
<img
className="PrintStyle2-BrandImage"
@ -3081,7 +3198,7 @@ const Printstyle4 = ({
alt="image"
width={100}
/>
) : null} */}
) : null}
<div
style={{
fontSize: '16px',
@ -3223,52 +3340,52 @@ const Printstyle4 = ({
<thead>
<tr>
{GlobaldummyData
? GlobalSlNo && <th style={{ width: '10px' }}>#</th>
: SLNO && <th style={{ width: '10px' }}>#</th>}
? GlobalSlNo && <th style={{...tableHeaderStyle, width: '10px' }}>#</th>
: SLNO && <th style={{...tableHeaderStyle, width: '10px' }}>#</th>}
{GlobaldummyData
? GlobalItem && <th>Item</th>
: Item && <th>Item</th>}
? GlobalItem && <th style={{...tableHeaderStyle,}}>Item</th>
: Item && <th style={{...tableHeaderStyle,}}>Item</th>}
{GlobaldummyData
? GlobalQuantity && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Qty
</th>
)
: Quantity && (
<th style={{ width: '30px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '30px', textAlign: 'right' }}>
Qty
</th>
)}
{GlobaldummyData
? GlobalHsnCode && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
HSN
</th>
)
: HsnCode && (
<th style={{ width: '30px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '30px', textAlign: 'right' }}>
HSN
</th>
)}
{GlobaldummyData
? GlobalMRP && (
<th style={{ width: '10px', textAlign: 'center' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'center' }}>
MRP
</th>
)
: MRP && (
<th style={{ width: '30px', textAlign: 'center' }}>
<th style={{...tableHeaderStyle, width: '30px', textAlign: 'center' }}>
MRP
</th>
)}
{GlobaldummyData
? GlobalDiscount && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Dis{' '}
</th>
)
: Discount && (
<th style={{ width: '25px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '25px', textAlign: 'right' }}>
Dis{' '}
</th>
)}
@ -3296,23 +3413,23 @@ const Printstyle4 = ({
)} */}
{GlobaldummyData
? GlobalRate && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Rate
</th>
)
: Rate && (
<th style={{ width: '40px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '40px', textAlign: 'right' }}>
Rate
</th>
)}
{GlobaldummyData
? GlobalAmount && (
<th style={{ width: '10px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '10px', textAlign: 'right' }}>
Amt
</th>
)
: Amount && (
<th style={{ width: '30px', textAlign: 'right' }}>
<th style={{...tableHeaderStyle, width: '30px', textAlign: 'right' }}>
Amt
</th>
)}
@ -3322,7 +3439,18 @@ const Printstyle4 = ({
{(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>{index + 1}</td>
: SLNO && <td>{index + 1}</td>}
@ -3661,7 +3789,18 @@ const Printstyle4 = ({
{(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>{index + 1}</td>
: SLNO && <td>{index + 1}</td>}
@ -3854,6 +3993,7 @@ const Printstyle4 = ({
borderBottom: '1px dashed #000',
borderTop: '1px dashed #000',
padding: '5px 0',
...netAmountStyle
}}
>
<div>Sub Total</div>
@ -4588,6 +4728,7 @@ const Printstyle4 = ({
pageBreakBefore: 'avoid',
pageBreakInside: 'avoid',
minHeight: 'auto',
...footerColorStyle
}}
>
{!estimatePrintHeader && table2Data?.OrderType === 'E' ? (