Implement dynamic header and table color functionality

This commit is contained in:
Srinath 2026-03-03 19:56:13 +05:30
parent b659bec211
commit 282d8f23f6
1 changed files with 122 additions and 32 deletions

View File

@ -5,6 +5,17 @@ import {
GlobalPritdummyData,
changeReprintDataFound,
GlobalprinttermsAndConditions,
GlobalSelectedPrintHeaderColor,
GlobalSelectedPrintHeaderFontColor,
GlobalSelectedTableHeaderColor,
GlobalSelectedTableHeaderFontColor,
GlobalSelectedTableBodyColor,
GlobalSelectedTableBodyFontColor,
GlobalRowType,
GlobalSelectedFooterColor,
GlobalSelectedFooterFontColor,
GlobalSelectedNetAmountColor,
GlobalSelectedNetAmountFontColor,
} from "../../../Features/ThemeChange/ThemeChange";
import "../../../Styles/BookingScreen/PrintTemplates/ThermalPrinter/PrintStyle6.scss";
import { extractLastNumber } from "../../../Services/Others";
@ -44,10 +55,20 @@ const PurPrintstyle6 = ({
const Rate = FieldDetails?.["Rate"];
const Amount = FieldDetails?.["Amount"];
const HsnCode = FieldDetails?.["HsnCode"];
const GlobaldummyData = useSelector(GlobalPritdummyData);
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
@ -58,6 +79,12 @@ const PurPrintstyle6 = ({
let PageSize = printDatas?.PageSize
const Signature = FieldDetails?.["signature"];
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;
@ -90,19 +117,60 @@ const PurPrintstyle6 = ({
}
const lastChunkRows = paginatedChunks.length > 0 ? 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 ?
<div id={`SQPrintStyle6`} className="PrintStyle6MasterDiv" style={{ fontFamily: "'Courier New', Courier, monospace", position: "relative", width: "100%", minHeight: isMobile ? (PageSize === "A5" ? "210mm" : "297mm") : "auto" }}>
{paginatedChunks.map((dataChunk, 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: isMobile ? GlobaldummyData ? "absolute" : "fixed" : "", top: 0, width: "100%" }}>
<div className="PrintStyle6-firstDiv">
<div className="PrintStyle6-firstDiv" style={{...headerStyle}}>
<div className="P6HdBrnchName" style={{ fontSize: 'clamp(1.2rem, 2.5vw, 1.8rem)', fontWeight: '600' }}>
{GlobaldummyData ? "XYZ Shop" : table2Data?.[0]?.BrName}
</div>
@ -140,31 +208,31 @@ const PurPrintstyle6 = ({
<table className="PrintStyle6-print-table">
<thead>
<tr>
{SLNO && <th style={{ width: "10px", }}>S.No</th>}
{SLNO && <th style={{ width: "10px", ...tableHeaderStyle }}>S.No</th>}
{(
<th style={{ width: "10px", }}>
<th style={{ width: "10px", ...tableHeaderStyle }}>
{Item && "ITEM /DES/"}{" "}
{Quantity && "QTY"}
</th>
)}
{HsnCode && (
<th style={{ width: "10px", textAlign: "right", }}>HSN</th>
<th style={{ width: "10px", textAlign: "right", ...tableHeaderStyle }}>HSN</th>
)}
{MRP && (
<th style={{ width: "10px", textAlign: "right", }}>MRP</th>
<th style={{ width: "10px", textAlign: "right", ...tableHeaderStyle }}>MRP</th>
)}
{Discount && (
<th style={{ width: "10px", textAlign: "right", }}>
<th style={{ width: "10px", textAlign: "right", ...tableHeaderStyle }}>
Dis{" "}
</th>
)}
{Rate && (
<th style={{ width: "10px", textAlign: "right", }}>
<th style={{ width: "10px", textAlign: "right", ...tableHeaderStyle }}>
Rate
</th>
)}
{Amount && (
<th style={{ width: "10px", textAlign: "right", }}>
<th style={{ width: "10px", textAlign: "right", ...tableHeaderStyle }}>
Amt
</th>
)}
@ -174,7 +242,17 @@ const PurPrintstyle6 = ({
{dataChunk?.map(
(item, index) => {
return (
<tr key={index}>
<tr key={index} style={
index % 2 !== 1 && rowtypeStyle === "even"
? {
...tableBodyStyle
}
: index % 2 === 1 && rowtypeStyle === "odd"
? {
...tableBodyStyle
}
: {}
}>
{SLNO && <td>{chunkIndex * chunkSize + index + 1}</td>}
{(
<td
@ -381,7 +459,7 @@ const PurPrintstyle6 = ({
</div>
<div className="PrintStyle6-secondDiv">
<div className="PrintStyle6-secondDiv" style={{...netAmountStyle}}>
<div style={{ textAlign: "left", fontSize: "clamp(1rem, 2.5vw, 1.2rem)", fontWeight: '600' }}>
Amount
</div>
@ -449,6 +527,7 @@ const PurPrintstyle6 = ({
pageBreakBefore: "avoid",
pageBreakInside: "avoid",
minHeight: "auto",
...footerColorStyle
}}
>
{GlobaldummyData ? GlobalIsnotes &&
@ -533,7 +612,7 @@ const PurPrintstyle6 = ({
<hr className="PrintStyle6-HrLine" />
<div className="align-style6" style={{ display: "flex", alignItems: "center", justifyContent: "space-evenly", margin: "0rem 1.5rem", fontSize: "clamp(0.65rem, 2.5vw, 1rem)", fontWeight: '600' }}>
<div className="align-style6" style={{ ...netAmountStyle, display: "flex", alignItems: "center", justifyContent: "space-evenly", margin: "0rem 1.5rem", fontSize: "clamp(0.65rem, 2.5vw, 1rem)", fontWeight: '600' }}>
<div>
<div>Items :{GlobaldummyData ? "8" : totalQuantityFilter?.length} </div>
</div>
@ -671,7 +750,7 @@ const PurPrintstyle6 = ({
<div className="PrintStyle6-secondDiv">
<div className="PrintStyle6-secondDiv"style={{...netAmountStyle}}>
<div style={{ textAlign: "left", fontSize: "clamp(1rem, 2.5vw, 1.2rem)", fontWeight: '600'}}>
Amount
</div>
@ -727,6 +806,7 @@ const PurPrintstyle6 = ({
pageBreakBefore: "avoid",
pageBreakInside: "avoid",
minHeight: "auto",
...footerColorStyle
}}
>
{
@ -769,7 +849,7 @@ const PurPrintstyle6 = ({
</div>
:
<div id={`SQPrintStyle6`} className="PrintStyle6MasterDiv" style={{ fontFamily: "'Courier New', Courier, monospace" }}>
<div className="PrintStyle6-firstDiv">
<div className="PrintStyle6-firstDiv" style={{...headerStyle}}>
<div className="P6HdBrnchName" style={{ fontSize: 'clamp(1.2rem, 2.5vw, 1.8rem)', fontWeight: '600' }}>
{table2Data?.[0]?.BrName}
</div>
@ -782,8 +862,6 @@ const PurPrintstyle6 = ({
<div style={{ fontSize: "clamp(0.65rem, 2.5vw, 1rem)", }}>
Mobile : {table2Data?.[0]?.BrMobile}
</div>
{<div style={{ textTransform: 'uppercase', fontSize: "clamp(0.75rem, 2.5vw, 1rem)", fontWeight: '600' }}>{BillName}</div>}
</div>
@ -805,31 +883,31 @@ const PurPrintstyle6 = ({
<table className="PrintStyle6-print-table">
<thead>
<tr>
{SLNO && <th style={{ width: "10px", }}>S.No</th>}
{SLNO && <th style={{ width: "10px", ...tableHeaderStyle }}>S.No</th>}
{(
<th style={{ width: "10px", }}>
<th style={{ width: "10px", ...tableHeaderStyle }}>
{Item && "ITEM /DES/"}{" "}
{Quantity && "QTY"}
</th>
)}
{HsnCode && (
<th style={{ width: "10px", textAlign: "right", }}>HSN</th>
<th style={{ width: "10px", textAlign: "right", ...tableHeaderStyle }}>HSN</th>
)}
{MRP && (
<th style={{ width: "10px", textAlign: "right", }}>MRP</th>
<th style={{ width: "10px", textAlign: "right", ...tableHeaderStyle }}>MRP</th>
)}
{Discount && (
<th style={{ width: "10px", textAlign: "right", }}>
<th style={{ width: "10px", textAlign: "right", ...tableHeaderStyle }}>
Dis{" "}
</th>
)}
{Rate && (
<th style={{ width: "10px", textAlign: "right", }}>
<th style={{ width: "10px", textAlign: "right", ...tableHeaderStyle }}>
Rate
</th>
)}
{Amount && (
<th style={{ width: "10px", textAlign: "right", }}>
<th style={{ width: "10px", textAlign: "right", ...tableHeaderStyle }}>
Amt
</th>
)}
@ -839,7 +917,18 @@ const PurPrintstyle6 = ({
{(TakeawayData)?.map(
(item, index) => {
return (
<tr key={index}>
<tr key={index}
style={
index % 2 !== 1 && rowtypeStyle === "even"
? {
...tableBodyStyle
}
: index % 2 === 1 && rowtypeStyle === "odd"
? {
...tableBodyStyle
}
: {}
}>
{SLNO && <td>{index + 1}</td>}
{(
<td
@ -906,7 +995,7 @@ const PurPrintstyle6 = ({
}
<div className="align-style6" style={{ display: "flex", alignItems: "center", justifyContent: "space-evenly", margin: "0rem 1.5rem", fontSize: "clamp(0.65rem, 2.5vw, 1rem)", fontWeight: '600' }}>
<div className="align-style6" style={{ ...netAmountStyle, display: "flex", alignItems: "center", justifyContent: "space-evenly", margin: "0rem 1.5rem", fontSize: "clamp(0.65rem, 2.5vw, 1rem)", fontWeight: '600' }}>
<div>
<div>Items :{GlobaldummyData ? "8" : totalQuantityFilter?.length} </div>
</div>
@ -1045,7 +1134,7 @@ const PurPrintstyle6 = ({
{/* <div className="align-style"> <div>Qty : </div> <div>{GlobaldummyData ? '9' : totalQuantity}</div> </div> */}
<div className="PrintStyle6-secondDiv">
<div className="PrintStyle6-secondDiv" style={{...netAmountStyle}}>
<div style={{ textAlign: "left", fontSize: "clamp(1rem, 2.5vw, 1.2rem)", fontWeight: '600'}}>
Amount
</div>
@ -1097,6 +1186,7 @@ const PurPrintstyle6 = ({
pageBreakBefore: "avoid",
pageBreakInside: "avoid",
minHeight: "auto",
...footerColorStyle
}}
>
{