Implement dynamic header and table color functionality

This commit is contained in:
Srinath 2026-03-03 19:55:09 +05:30
parent c4dadd7420
commit 6540340559
1 changed files with 121 additions and 36 deletions

View File

@ -1,7 +1,5 @@
import React from "react"; import React from "react";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { import {
GlobalPritdummyData, GlobalPritdummyData,
@ -9,6 +7,17 @@ import {
GlobalprinttermsAndConditions, GlobalprinttermsAndConditions,
Globalnotes, Globalnotes,
GlobalthemeFormat, GlobalthemeFormat,
GlobalSelectedPrintHeaderColor,
GlobalSelectedPrintHeaderFontColor,
GlobalSelectedTableHeaderColor,
GlobalSelectedTableHeaderFontColor,
GlobalSelectedTableBodyColor,
GlobalSelectedTableBodyFontColor,
GlobalRowType,
GlobalSelectedFooterColor,
GlobalSelectedFooterFontColor,
GlobalSelectedNetAmountColor,
GlobalSelectedNetAmountFontColor,
} from "../../../Features/ThemeChange/ThemeChange"; } from "../../../Features/ThemeChange/ThemeChange";
import { extractLastNumber } from "../../../Services/Others"; import { extractLastNumber } from "../../../Services/Others";
import "../../../Styles/BookingScreen/PrintTemplates/ThermalPrinter/PrintStyle2.scss"; import "../../../Styles/BookingScreen/PrintTemplates/ThermalPrinter/PrintStyle2.scss";
@ -32,9 +41,17 @@ const PurPrintstyle2 = ({ index, totalQuantityFilter, Date1, base64Image, Cashie
const HsnCode = FieldDetails?.["HsnCode"]; const HsnCode = FieldDetails?.["HsnCode"];
const GlobaldummyData = useSelector(GlobalPritdummyData); const GlobaldummyData = useSelector(GlobalPritdummyData);
const GlobaltermsAndConditions = useSelector(GlobalprinttermsAndConditions); const GlobaltermsAndConditions = useSelector(GlobalprinttermsAndConditions);
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 TermsAndConditions = printDatas?.TermsandConditions let TermsAndConditions = printDatas?.TermsandConditions
let SignatureImg = printDatas?.Signature let SignatureImg = printDatas?.Signature
@ -44,9 +61,12 @@ const PurPrintstyle2 = ({ index, totalQuantityFilter, Date1, base64Image, Cashie
let PageSize = printDatas?.PageSize let PageSize = printDatas?.PageSize
const Signature = FieldDetails?.["signature"]; const Signature = FieldDetails?.["signature"];
const TermsnAdCondition = FieldDetails?.["terms&conditions"]; const TermsnAdCondition = FieldDetails?.["terms&conditions"];
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;
const keysLength = Object.keys(table2Data ?? {}).length; const keysLength = Object.keys(table2Data ?? {}).length;
const dataSource = table2Data?.[0]?.ProductDetails; const dataSource = table2Data?.[0]?.ProductDetails;
if (keysLength > 0) { if (keysLength > 0) {
@ -88,7 +108,51 @@ const PurPrintstyle2 = ({ index, totalQuantityFilter, Date1, base64Image, Cashie
} }
const lastChunkRows = paginatedChunks.length > 0 ? paginatedChunks[paginatedChunks.length - 1].length : 0; const lastChunkRows = paginatedChunks.length > 0 ? paginatedChunks[paginatedChunks.length - 1].length : 0;
const shouldFooterBeOnNewPage = lastChunkRows > (PageSize == "A5" ? 5 : 13); const shouldFooterBeOnNewPage = lastChunkRows > (PageSize == "A5" ? 5 : 13);
console.log(FormatTheme, "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 ?
@ -101,7 +165,7 @@ const PurPrintstyle2 = ({ index, totalQuantityFilter, Date1, base64Image, Cashie
<div className={`container print-chunk${chunkIndex > 0 ? ' print-page-break' : ''}`} style={{ display: "flex", flexDirection: "column", justifyContent: ((chunkIndex === paginatedChunks.length - 1) && (!shouldFooterBeOnNewPage)) && FormatTheme ? "space-between" : "", height: FormatTheme ? PageSize == "A5" ? '170mm' : "257mm" : "", }} key={chunkIndex}> <div className={`container print-chunk${chunkIndex > 0 ? ' print-page-break' : ''}`} style={{ display: "flex", flexDirection: "column", justifyContent: ((chunkIndex === paginatedChunks.length - 1) && (!shouldFooterBeOnNewPage)) && FormatTheme ? "space-between" : "", height: FormatTheme ? PageSize == "A5" ? '170mm' : "257mm" : "", }} key={chunkIndex}>
{/* <div className="header" style={{ position: "fixed", top: 0, width: "100%" }}> */} {/* <div className="header" style={{ position: "fixed", top: 0, width: "100%" }}> */}
<div className="header" style={{ position: isMobile ? GlobaldummyData ? "absolute" : "fixed" : "", top: 0, width: "100%" }}> <div className="header" style={{ position: isMobile ? GlobaldummyData ? "absolute" : "fixed" : "", top: 0, width: "100%", ...headerStyle }}>
<div className='PrintStyle2-fistDiv' > <div className='PrintStyle2-fistDiv' >
<div style={{ display: 'flex', flexDirection: 'row' }}> <div style={{ display: 'flex', flexDirection: 'row' }}>
@ -146,20 +210,31 @@ const PurPrintstyle2 = ({ index, totalQuantityFilter, Date1, base64Image, Cashie
<table className="PrintStyle2-print-table"> <table className="PrintStyle2-print-table">
<thead> <thead>
<tr> <tr>
{SLNO && <th style={{ width: '8px' }}>S.No</th>} {SLNO && <th style={{ width: '8px', ...tableHeaderStyle }}>S.No</th>}
{Item && <th >Item</th>} {Item && <th style={{ ...tableHeaderStyle }} >Item</th>}
{HsnCode && <th style={{ width: '8px', textAlign: 'right' }}>HSN</th>} {HsnCode && <th style={{ width: '8px', textAlign: 'right', ...tableHeaderStyle }}>HSN</th>}
{Quantity && <th style={{ width: '8px', textAlign: 'right' }}>Qty</th>} {Quantity && <th style={{ width: '8px', textAlign: 'right', ...tableHeaderStyle }}>Qty</th>}
{MRP && <th style={{ width: '8px', textAlign: 'right' }}>MRP</th>} {MRP && <th style={{ width: '8px', textAlign: 'right', ...tableHeaderStyle }}>MRP</th>}
{Amount && <th style={{ width: '8px', textAlign: 'right' }}>Amt</th>} {Amount && <th style={{ width: '8px', textAlign: 'right', ...tableHeaderStyle }}>Amt</th>}
{Discount && <th style={{ width: '8px', textAlign: 'right' }}>Dis </th>} {Discount && <th style={{ width: '8px', textAlign: 'right', ...tableHeaderStyle }}>Dis </th>}
{Rate && <th style={{ width: '8px', textAlign: 'right' }}>Rate</th>} {Rate && <th style={{ width: '8px', textAlign: 'right', ...tableHeaderStyle }}>Rate</th>}
</tr> </tr>
</thead> </thead>
<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
}
: {}
} >
{SLNO && <td className="Re-print-body-Rate">{chunkIndex * chunkSize + index + 1}</td>} {SLNO && <td className="Re-print-body-Rate">{chunkIndex * chunkSize + index + 1}</td>}
{Item && {Item &&
<td className="Re-print-body-Product" style={{ display: 'flex', flexDirection: 'column' }}> <td className="Re-print-body-Product" style={{ display: 'flex', flexDirection: 'column' }}>
@ -196,7 +271,7 @@ const PurPrintstyle2 = ({ index, totalQuantityFilter, Date1, base64Image, Cashie
{((chunkIndex === paginatedChunks.length - 1) && (!shouldFooterBeOnNewPage)) && FormatTheme && {((chunkIndex === paginatedChunks.length - 1) && (!shouldFooterBeOnNewPage)) && FormatTheme &&
<> <>
<div className='PrintStyle2-ThirdDivMaster'> <div className='PrintStyle2-ThirdDivMaster' style={{...netAmountStyle}}>
<div className='PrintStyle2-ThirdP'> <div className='PrintStyle2-ThirdP'>
<div> <div>
<div style={{ textAlign: 'left', fontWeight: '600' }}>Qty</div> <div style={{ textAlign: 'left', fontWeight: '600' }}>Qty</div>
@ -362,16 +437,13 @@ const PurPrintstyle2 = ({ index, totalQuantityFilter, Date1, base64Image, Cashie
</div> </div>
<div className="page-footerA4Style11" <div className="page-footerA4Style11"
style={{ style={{
marginTop: "auto", marginTop: "auto",
pageBreakBefore: "avoid", pageBreakBefore: "avoid",
pageBreakInside: "avoid", pageBreakInside: "avoid",
minHeight: "auto", minHeight: "auto",
...footerColorStyle
}} }}
> >
{ {
@ -442,7 +514,7 @@ const PurPrintstyle2 = ({ index, totalQuantityFilter, Date1, base64Image, Cashie
}} }}
> >
<> <>
<div className='PrintStyle2-ThirdDivMaster'> <div className='PrintStyle2-ThirdDivMaster' style={{...netAmountStyle}}>
<div className='PrintStyle2-ThirdP'> <div className='PrintStyle2-ThirdP'>
<div> <div>
<div style={{ textAlign: 'left', fontWeight: '600' }}>Qty</div> <div style={{ textAlign: 'left', fontWeight: '600' }}>Qty</div>
@ -622,6 +694,7 @@ const PurPrintstyle2 = ({ index, totalQuantityFilter, Date1, base64Image, Cashie
pageBreakBefore: "avoid", pageBreakBefore: "avoid",
pageBreakInside: "avoid", pageBreakInside: "avoid",
minHeight: "auto", minHeight: "auto",
...footerColorStyle
}} }}
> >
{ {
@ -687,7 +760,7 @@ const PurPrintstyle2 = ({ index, totalQuantityFilter, Date1, base64Image, Cashie
<div className='PrintStyle2-fistDiv' > <div className='PrintStyle2-fistDiv' >
<div style={{ display: 'flex', flexDirection: 'row' }}> <div style={{ display: 'flex', flexDirection: 'row', ...headerStyle }}>
{(base64Image && PrintLogo?.SettingValue === "Y") ? <img className='PrintStyle2-BrandImage' src={GlobaldummyData ? Logo : base64Image} alt='image' /> : null} {(base64Image && PrintLogo?.SettingValue === "Y") ? <img className='PrintStyle2-BrandImage' src={GlobaldummyData ? Logo : base64Image} alt='image' /> : null}
</div> </div>
@ -729,20 +802,31 @@ const PurPrintstyle2 = ({ index, totalQuantityFilter, Date1, base64Image, Cashie
<table className="PrintStyle2-print-table"> <table className="PrintStyle2-print-table">
<thead> <thead>
<tr> <tr>
{SLNO && <th style={{ width: '8px' }}>S.No</th>} {SLNO && <th style={{ ...tableHeaderStyle, width: '8px' }}>S.No</th>}
{Item && <th >Item</th>} {Item && <th style={{ ...tableHeaderStyle }}>Item</th>}
{HsnCode && <th style={{ width: '8px', textAlign: 'right' }}>HSN</th>} {HsnCode && <th style={{ ...tableHeaderStyle, width: '8px', textAlign: 'right' }}>HSN</th>}
{Quantity && <th style={{ width: '8px', textAlign: 'right' }}>Qty</th>} {Quantity && <th style={{ ...tableHeaderStyle, width: '8px', textAlign: 'right' }}>Qty</th>}
{MRP && <th style={{ width: '8px', textAlign: 'right' }}>MRP</th>} {MRP && <th style={{ ...tableHeaderStyle, width: '8px', textAlign: 'right' }}>MRP</th>}
{Amount && <th style={{ width: '8px', textAlign: 'right' }}>Amt</th>} {Amount && <th style={{ ...tableHeaderStyle, width: '8px', textAlign: 'right' }}>Amt</th>}
{Discount && <th style={{ width: '8px', textAlign: 'right' }}>Dis </th>} {Discount && <th style={{ ...tableHeaderStyle, width: '8px', textAlign: 'right' }}>Dis </th>}
{Rate && <th style={{ width: '8px', textAlign: 'right' }}>Rate</th>} {Rate && <th style={{ ...tableHeaderStyle, width: '8px', textAlign: 'right' }}>Rate</th>}
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{(TakeawayData)?.map((item, index) => { {(TakeawayData)?.map((item, index) => {
return ( return (
<tr key={index} > <tr key={index}
style={
index % 2 !== 1 && rowtypeStyle === "even"
? {
...tableBodyStyle
}
: index % 2 === 1 && rowtypeStyle === "odd"
? {
...tableBodyStyle
}
: {}
}>
{SLNO && <td className="Re-print-body-Rate">{index + 1}</td>} {SLNO && <td className="Re-print-body-Rate">{index + 1}</td>}
{Item && {Item &&
<td className="Re-print-body-Product" style={{ display: 'flex', flexDirection: 'column' }}> <td className="Re-print-body-Product" style={{ display: 'flex', flexDirection: 'column' }}>
@ -776,7 +860,7 @@ const PurPrintstyle2 = ({ index, totalQuantityFilter, Date1, base64Image, Cashie
</div> </div>
<div className='PrintStyle2-ThirdDivMaster'> <div className='PrintStyle2-ThirdDivMaster' style={{...netAmountStyle}}>
<div className='PrintStyle2-ThirdP'> <div className='PrintStyle2-ThirdP'>
<div> <div>
<div style={{ textAlign: 'left', fontWeight: '600' }}>Qty</div> <div style={{ textAlign: 'left', fontWeight: '600' }}>Qty</div>
@ -928,6 +1012,7 @@ const PurPrintstyle2 = ({ index, totalQuantityFilter, Date1, base64Image, Cashie
pageBreakBefore: "avoid", pageBreakBefore: "avoid",
pageBreakInside: "avoid", pageBreakInside: "avoid",
minHeight: "auto", minHeight: "auto",
...footerColorStyle
}} }}
> >
{ {