Implement dynamic header and table color functionality

This commit is contained in:
Srinath 2026-03-03 19:54:52 +05:30
parent 807a5c2606
commit c4dadd7420
1 changed files with 123 additions and 47 deletions

View File

@ -8,6 +8,17 @@ import {
Globalnotes, Globalnotes,
GlobalthemeFormat, GlobalthemeFormat,
GlobalBillName, GlobalBillName,
GlobalSelectedPrintHeaderColor,
GlobalSelectedPrintHeaderFontColor,
GlobalSelectedTableHeaderColor,
GlobalSelectedTableHeaderFontColor,
GlobalSelectedTableBodyColor,
GlobalSelectedTableBodyFontColor,
GlobalRowType,
GlobalSelectedFooterColor,
GlobalSelectedFooterFontColor,
GlobalSelectedNetAmountColor,
GlobalSelectedNetAmountFontColor,
} from "../../../Features/ThemeChange/ThemeChange"; } from "../../../Features/ThemeChange/ThemeChange";
import "../../../Styles/BookingScreen/PrintTemplates/ThermalPrinter/PrintStyle1.scss"; import "../../../Styles/BookingScreen/PrintTemplates/ThermalPrinter/PrintStyle1.scss";
import { ApplicationPreferences } from "../../../Features/BrachLogin/BranchLogin"; import { ApplicationPreferences } from "../../../Features/BrachLogin/BranchLogin";
@ -36,7 +47,6 @@ const PurPrintStyle1 = ({
// console.log(FieldDetailss, "FieldDetails") // console.log(FieldDetailss, "FieldDetails")
const SLNO = FieldDetails?.["Sl.No"]; const SLNO = FieldDetails?.["Sl.No"];
const Item = FieldDetails?.["Item"]; const Item = FieldDetails?.["Item"];
console.log(Item, "Item")
const MRP = FieldDetails?.["MRP"]; const MRP = FieldDetails?.["MRP"];
const Discount = FieldDetails?.["Discount"]; const Discount = FieldDetails?.["Discount"];
const Quantity = FieldDetails?.["Quantity"]; const Quantity = FieldDetails?.["Quantity"];
@ -44,8 +54,17 @@ const PurPrintStyle1 = ({
const Amount = FieldDetails?.["Amount"]; const Amount = FieldDetails?.["Amount"];
const HsnCode = FieldDetails?.["HsnCode"]; const HsnCode = FieldDetails?.["HsnCode"];
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 GlobaldummyData = useSelector(GlobalPritdummyData); const GlobaldummyData = useSelector(GlobalPritdummyData);
const GlobaltermsAndConditions = useSelector(GlobalprinttermsAndConditions); const GlobaltermsAndConditions = useSelector(GlobalprinttermsAndConditions);
const GlobalIsnotes = useSelector(Globalnotes); const GlobalIsnotes = useSelector(Globalnotes);
@ -65,9 +84,14 @@ const PurPrintStyle1 = ({
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 dataSource = table2Data?.[0]?.ProductDetails; const dataSource = table2Data?.[0]?.ProductDetails;
console.log(table2Data, "dataSource")
if (keysLength > 0) { if (keysLength > 0) {
dispatch(changeReprintDataFound(true)); dispatch(changeReprintDataFound(true));
} }
@ -135,7 +159,51 @@ const PurPrintStyle1 = ({
console.log(paginatedChunks, "paginatedChunkspaginatedChunkspaginatedChunks") console.log(paginatedChunks, "paginatedChunkspaginatedChunkspaginatedChunks")
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 : 10); const shouldFooterBeOnNewPage = lastChunkRows > (PageSize == "A5" ? 5 : 10);
console.log(PageSize == "A5" ? '210mm' : "297mm", "aggregatedPaymentsaggregatedPayments"); 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 (
@ -149,10 +217,9 @@ const PurPrintStyle1 = ({
{paginatedChunks.map((dataChunk, chunkIndex) => ( {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 ? "" : "", height: FormatTheme ? PageSize == "A5" ? '170mm' : (isMobile ? "257mm" : "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 ? "" : "", height: FormatTheme ? PageSize == "A5" ? '170mm' : (isMobile ? "257mm" : "257mm") : "", }} key={chunkIndex}>
{console.log(dataChunk, "dataChunkdataChunkdataChunk")}
{/* <div className="header" style={{ position: GlobaldummyData ? "absolute" : "fixed", top: 0, width: "100%" }}> */} {/* <div className="header" style={{ position: GlobaldummyData ? "absolute" : "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%" }}>
<div className="PrintStyle1-print" > <div className="PrintStyle1-print" style={{...headerStyle}} >
<div <div
style={{ fontSize: "clamp(2rem, 2.5vw, 2rem)", fontWeight: "600" }} style={{ fontSize: "clamp(2rem, 2.5vw, 2rem)", fontWeight: "600" }}
> >
@ -229,12 +296,6 @@ const PurPrintStyle1 = ({
</div> </div>
</div> </div>
{/* orderdetails */}
{/* <hr className="PrintStyle1-print-dottline" /> */}
{/* itemdata (loop) */}
</div> </div>
<div style={{ marginTop: GlobaldummyData ? "9rem" : "0rem" }} className="print-body"> <div style={{ marginTop: GlobaldummyData ? "9rem" : "0rem" }} className="print-body">
@ -257,21 +318,21 @@ const PurPrintStyle1 = ({
<table className="PrintStyle1-print-table"> <table className="PrintStyle1-print-table">
<thead> <thead>
<tr> <tr>
{SLNO == true && <th style={{ width: "10px" }}>S.No</th>} {SLNO == true && <th style={{...tableHeaderStyle,width: "10px" }}>S.No</th>}
{Item == true && <th>Item</th>} {Item == true && <th style={{...tableHeaderStyle}}>Item</th>}
{HsnCode == true && ( {HsnCode == true && (
<th style={{ width: "10px" }}>HSN</th> <th style={{...tableHeaderStyle, width: "10px" }}>HSN</th>
)} )}
{Quantity == true && ( {Quantity == true && (
<th style={{ width: "10px" }}>Qty</th> <th style={{...tableHeaderStyle, width: "10px" }}>Qty</th>
)} )}
{MRP == true && <th style={{ width: "10px" }}>MRP</th>} {MRP == true && <th style={{...tableHeaderStyle, width: "10px" }}>MRP</th>}
{Rate == true && <th style={{ width: "10px" }}>Rate</th>} {Rate == true && <th style={{...tableHeaderStyle, width: "10px" }}>Rate</th>}
{Discount == true && ( {Discount == true && (
<th style={{ width: "10px" }}>Dis </th> <th style={{...tableHeaderStyle, width: "10px" }}>Dis </th>
)} )}
{Amount == true && ( {Amount == true && (
<th style={{ width: "10px", textAlign: "right" }}> <th style={{...tableHeaderStyle, width: "10px", textAlign: "right" }}>
Amt Amt
</th> </th>
)} )}
@ -282,7 +343,18 @@ const PurPrintStyle1 = ({
{dataChunk?.map( {dataChunk?.map(
(item, index) => ( (item, index) => (
<tr key={index}> <tr key={index}
style={
index % 2 !== 1 && rowtypeStyle === "even"
? {
...tableBodyStyle
}
: index % 2 === 1 && rowtypeStyle === "odd"
? {
...tableBodyStyle
}
: {}
}>
{SLNO == true && ( {SLNO == true && (
<td style={{ textAlign: "center" }}> <td style={{ textAlign: "center" }}>
{chunkIndex * chunkSize + index + 1} {chunkIndex * chunkSize + index + 1}
@ -392,11 +464,12 @@ const PurPrintStyle1 = ({
style={{ style={{
display: "flex", display: "flex",
justifyContent: "space-around", justifyContent: "space-around",
width: "95%", width: "100%",
whiteSpace: "nowrap", whiteSpace: "nowrap",
fontSize: "10px", fontSize: "10px",
flexWrap: "wrap", flexWrap: "wrap",
gap: "2px" gap: "2px",
...netAmountStyle
}} }}
> >
<div <div
@ -607,13 +680,7 @@ const PurPrintStyle1 = ({
marginTop: "5px", marginTop: "5px",
}} }}
> >
</div> </div>
{/* <hr className="PrintStyle1-print-dottline" /> */} {/* <hr className="PrintStyle1-print-dottline" /> */}
<div className="page-footerA4Style11" <div className="page-footerA4Style11"
@ -622,6 +689,7 @@ const PurPrintStyle1 = ({
pageBreakBefore: "avoid", pageBreakBefore: "avoid",
pageBreakInside: "avoid", pageBreakInside: "avoid",
minHeight: "auto", minHeight: "auto",
...footerColorStyle
}} }}
> >
{ {
@ -690,11 +758,12 @@ const PurPrintStyle1 = ({
style={{ style={{
display: "flex", display: "flex",
justifyContent: "space-around", justifyContent: "space-around",
width: "95%", width: "100%",
whiteSpace: "nowrap", whiteSpace: "nowrap",
fontSize: "10px", fontSize: "10px",
flexWrap: "wrap", flexWrap: "wrap",
gap: "2px" gap: "2px",
...netAmountStyle
}} }}
> >
<div <div
@ -918,6 +987,7 @@ const PurPrintStyle1 = ({
pageBreakBefore: "avoid", pageBreakBefore: "avoid",
pageBreakInside: "avoid", pageBreakInside: "avoid",
minHeight: "auto", minHeight: "auto",
...footerColorStyle
}} }}
> >
{ {
@ -974,11 +1044,12 @@ const PurPrintStyle1 = ({
style={{ style={{
display: "flex", display: "flex",
justifyContent: "space-around", justifyContent: "space-around",
width: "95%", width: "100%",
whiteSpace: "nowrap", whiteSpace: "nowrap",
fontSize: "10px", fontSize: "10px",
flexWrap: "wrap", flexWrap: "wrap",
gap: "2px" gap: "2px",
...netAmountStyle
}} }}
> >
<div <div
@ -1198,6 +1269,7 @@ const PurPrintStyle1 = ({
pageBreakBefore: "avoid", pageBreakBefore: "avoid",
pageBreakInside: "avoid", pageBreakInside: "avoid",
minHeight: "auto", minHeight: "auto",
...footerColorStyle
}} }}
> >
{ {
@ -1254,16 +1326,12 @@ const PurPrintStyle1 = ({
} }
</div > : </div > :
<div <div
className="PrintStyle1MasterDiv" className="PrintStyle1MasterDiv"
id={`SQPrintStyle1`} id={`SQPrintStyle1`}
style={{ fontFamily: "'Courier New', Courier, monospace" }} style={{ fontFamily: "'Courier New', Courier, monospace" }}
> >
<div className="PrintStyle1-print"> <div className="PrintStyle1-print" style={{...headerStyle}}>
<div <div
style={{ fontSize: "clamp(2rem, 2.5vw, 2rem)", fontWeight: "600" }} style={{ fontSize: "clamp(2rem, 2.5vw, 2rem)", fontWeight: "600" }}
> >
@ -1340,7 +1408,18 @@ const PurPrintStyle1 = ({
<tbody> <tbody>
{(TakeawayData)?.map( {(TakeawayData)?.map(
(item, index) => ( (item, index) => (
<tr key={index}> <tr key={index}
style={
index % 2 !== 1 && rowtypeStyle === "even"
? {
...tableBodyStyle
}
: index % 2 === 1 && rowtypeStyle === "odd"
? {
...tableBodyStyle
}
: {}
}>
{SLNO == true && ( {SLNO == true && (
<td style={{ textAlign: "center" }}> <td style={{ textAlign: "center" }}>
{index + 1} {index + 1}
@ -1447,11 +1526,12 @@ const PurPrintStyle1 = ({
style={{ style={{
display: "flex", display: "flex",
justifyContent: "space-around", justifyContent: "space-around",
width: "95%", width: "100%",
whiteSpace: "nowrap", whiteSpace: "nowrap",
fontSize: "10px", fontSize: "10px",
flexWrap: "wrap", flexWrap: "wrap",
gap: "2px" gap: "2px",
...netAmountStyle
}} }}
> >
<div <div
@ -1659,11 +1739,6 @@ const PurPrintStyle1 = ({
> >
</div> </div>
<hr className="PrintStyle1-print-dottline" /> <hr className="PrintStyle1-print-dottline" />
<div className="page-footerA4Style11" <div className="page-footerA4Style11"
@ -1672,6 +1747,7 @@ const PurPrintStyle1 = ({
pageBreakBefore: "avoid", pageBreakBefore: "avoid",
pageBreakInside: "avoid", pageBreakInside: "avoid",
minHeight: "auto", minHeight: "auto",
...footerColorStyle
}} }}
> >
{ {