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