Implement dynamic header and table color functionality

This commit is contained in:
Srinath 2026-03-03 19:56:39 +05:30
parent 282d8f23f6
commit 12509a49fd
1 changed files with 177 additions and 115 deletions

View File

@ -4,7 +4,18 @@ import { useDispatch, useSelector } from "react-redux";
import {
GlobalPritdummyData,
changeReprintDataFound,
GlobalprinttermsAndConditions
GlobalprinttermsAndConditions,
GlobalSelectedPrintHeaderColor,
GlobalSelectedPrintHeaderFontColor,
GlobalSelectedTableHeaderColor,
GlobalSelectedTableHeaderFontColor,
GlobalSelectedTableBodyColor,
GlobalSelectedTableBodyFontColor,
GlobalRowType,
GlobalSelectedFooterColor,
GlobalSelectedFooterFontColor,
GlobalSelectedNetAmountColor,
GlobalSelectedNetAmountFontColor,
} from '../../../Features/ThemeChange/ThemeChange';
import "../../../Styles/BookingScreen/PrintTemplates/ThermalPrinter/PrintStyle7.scss"
import { extractLastNumber } from "../../../Services/Others";
@ -29,10 +40,25 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
const Rate = FieldDetails?.["Rate"];
const Amount = FieldDetails?.["Amount"];
const HsnCode = FieldDetails?.["HsnCode"];
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 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
@ -43,32 +69,14 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
let PageSize = printDatas?.PageSize
const Signature = FieldDetails?.["signature"];
const TermsnAdCondition = FieldDetails?.["terms&conditions"];
const keysLength = Object.keys(table2Data ?? {}).length;
if (keysLength > 0) {
dispatch(changeReprintDataFound(true));
}
const TakeawayData = table2Data?.[0]?.ProductDetails
console.log(TakeawayData, "TakeawayData", table2Data)
let TotalOfferAmount = 0;
const chunkSize = PageSize == "A5" ? 8 : 11;
let dataSource = table2Data?.[0]?.ProductDetails;
// Paginate the data
const paginatedChunks = [];
for (let i = 0; i < dataSource?.length; i += chunkSize) {
@ -76,8 +84,51 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
}
const lastChunkRows = paginatedChunks.length > 0 ? paginatedChunks[paginatedChunks.length - 1].length : 0;
const shouldFooterBeOnNewPage = lastChunkRows > (PageSize == "A5" ? 5 : 10);
{ console.log(TakeawayData, "TakeawayDataTakeawayData") }
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 (
<>
@ -89,7 +140,7 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
<div className="header" style={{ position: isMobile ? GlobaldummyData ? "absolute" : "fixed" : "", top: 0, width: "100%" }}>
<hr class="star-line" />
<div className="PrintStyle7-print">
<div className="PrintStyle7-print" style={{...headerStyle}}>
<div style={{ fontSize: '16px', fontWeight: '600' }}> {table2Data?.[0]?.BrName}</div>
<div style={{ fontSize: '10px', fontWeight: '600' }} >{GlobaldummyData ?
'BranchAddress, Town- 635XXX City - State' :
@ -123,19 +174,30 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
<table className="PrintStyle7-print-table">
<thead>
<tr>
{ SLNO == true && <th style={{ width: '10px', }}>S</th>}
{ Item == true && <th>Item</th>}
{ HsnCode == true && <th style={{ width: '10px', }}>HSN</th>}
{ Quantity == true && <th style={{ width: '10px', }}>Qty</th>}
{GlobaldummyData ? GlobalMRP && <th style={{ width: '10px' }}>MRP</th> : MRP == true && <th style={{ width: '10px' }}>MRP</th>}
{GlobaldummyData ? GlobalRate && <th style={{ width: '10px' }}>Rate</th> : Rate == true && <th style={{ width: '10px' }}>Rate</th>}
{ Discount == true && <th style={{ width: '10px' }}>Dis </th>}
{ Amount == true && <th style={{ width: '10px', textAlign: 'right' }}>Amt</th>}
{SLNO == true && <th style={{ width: '10px', ...tableHeaderStyle }}>S.No</th>}
{Item == true && <th style={{ ...tableHeaderStyle }}>Item</th>}
{HsnCode == true && <th style={{ width: '10px', ...tableHeaderStyle }}>HSN</th>}
{Quantity == true && <th style={{ width: '10px', ...tableHeaderStyle }}>Qty</th>}
{GlobaldummyData ? GlobalMRP && <th style={{ width: '10px', ...tableHeaderStyle }}>MRP</th> : MRP == true && <th style={{...tableHeaderStyle, width: '10px' }}>MRP</th>}
{GlobaldummyData ? GlobalRate && <th style={{ width: '10px', ...tableHeaderStyle }}>Rate</th> : Rate == true && <th style={{...tableHeaderStyle, width: '10px' }}>Rate</th>}
{Discount == true && <th style={{ width: '10px', ...tableHeaderStyle }}>Dis </th>}
{Amount == true && <th style={{ width: '10px', textAlign: 'right', ...tableHeaderStyle }}>Amt</th>}
</tr>
</thead>
<tbody>
{dataChunk?.map((item, index) => (
<tr key={index} >
<tr key={index}
style={
index % 2 !== 1 && rowtypeStyle === "even"
? {
...tableBodyStyle
}
: index % 2 === 1 && rowtypeStyle === "odd"
? {
...tableBodyStyle
}
: {}
}>
{SLNO == true && <td style={{ textAlign: 'center' }}>{chunkIndex * chunkSize + index + 1}</td>}
{Item == true && <td style={{ display: 'flex', flexDirection: 'column' }}>
<div>{item?.ProdName}</div>
@ -161,7 +223,7 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
{((chunkIndex === paginatedChunks.length - 1) && (!shouldFooterBeOnNewPage)) && FormatTheme &&
<>
<div className='PrintStyle7-SecondDiv3'>
<div className='PrintStyle7-SecondDivMaster'>
<div className='PrintStyle7-SecondDivMaster' style={{ ...netAmountStyle }}>
<div style={{ fontWeight: "600" }}>Items : {totalQuantityFilter?.length}</div>
<div style={{ fontWeight: "600" }}>Qty : {totalQuantity}</div>
{(table2Data?.OverallDisc > 0 || TotalOfferAmount > 0) && <div style={{ fontWeight: "600" }}>Off : {Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}</div>}
@ -315,6 +377,7 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
pageBreakBefore: "avoid",
pageBreakInside: "avoid",
minHeight: "auto",
...footerColorStyle
}}
>
{
@ -376,7 +439,7 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
>
<>
<div className='PrintStyle7-SecondDiv3'>
<div className='PrintStyle7-SecondDivMaster'>
<div className='PrintStyle7-SecondDivMaster' style={{ ...netAmountStyle }}>
<div style={{ fontWeight: "600" }}>Items : {totalQuantityFilter?.length}</div>
<div style={{ fontWeight: "600" }}>Qty : {totalQuantity}</div>
{(table2Data?.OverallDisc > 0 || TotalOfferAmount > 0) && <div style={{ fontWeight: "600" }}>Off : {Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}</div>}
@ -519,23 +582,15 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
<div style={{ marginLeft: '13px', padding: 0, fontSize: "8px", fontWeight: "600" }}>Customer : {table2Data?.CustSuppName}</div>
</div>
}
<div className="page-footerA4Style11"
style={{
marginTop: "auto",
pageBreakBefore: "avoid",
pageBreakInside: "avoid",
minHeight: "auto",
...footerColorStyle
}}
>
<div style={{ display: "flex", width: "90%", padding: "0 1rem", justifyContent: GlobaltermsAndConditions ? "space-between" : "flex-end", alignItems: "center" }}>
{
(TermsnAdCondition == true && TermsAndConditions?.length > 0) && (<div style={{ margin: "8px 0", fontFamily: "sans-serif", width: "100%", display: "flex", flexDirection: "column", alignItems: "flex-start" }}>
@ -556,20 +611,15 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
</div>
</div>
</>
</div>
</div>
}
</div>
:
<div className="PrintStyle7MasterDiv" id={`SQPrintStyle7`} style={{ fontFamily: "'Courier New', Courier, monospace" }}>
<hr class="star-line" />
<div className="PrintStyle7-print">
<div className="PrintStyle7-print" style={{...headerStyle}}>
<div style={{ fontSize: '16px', fontWeight: '600' }}> {table2Data?.[0]?.BrName}</div>
<div style={{ fontSize: '10px', fontWeight: '600' }} >{
(table2Data?.[0]?.AddressDetails?.[0]?.Address1 || '') + (table2Data?.[0]?.AddressDetails?.[0]?.City ? (table2Data?.[0]?.AddressDetails?.[0]?.Address1 && table2Data?.[0]?.AddressDetails?.[0]?.City ? '-' : '') + table2Data?.[0]?.AddressDetails?.[0]?.City : '') + (table2Data?.[0]?.AddressDetails?.[0]?.Zip ? (table2Data?.[0]?.AddressDetails?.[0]?.City && table2Data?.[0]?.AddressDetails?.[0]?.Zip ? '-' : '') + table2Data?.[0]?.AddressDetails?.[0]?.Zip : '')}
@ -604,19 +654,30 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
<table className="PrintStyle7-print-table">
<thead>
<tr>
{ SLNO == true && <th style={{ width: '10px', }}>S</th>}
{ Item == true && <th>Item</th>}
{ HsnCode == true && <th style={{ width: '10px', }}>HSN</th>}
{ Quantity == true && <th style={{ width: '10px', }}>Qty</th>}
{ MRP == true && <th style={{ width: '10px' }}>MRP</th>}
{ Rate == true && <th style={{ width: '10px' }}>Rate</th>}
{ Discount == true && <th style={{ width: '10px' }}>Dis </th>}
{ Amount == true && <th style={{ width: '10px', textAlign: 'right' }}>Amt</th>}
{SLNO == true && <th style={{ width: '10px', ...tableHeaderStyle }}>S.No</th>}
{Item == true && <th style={{ ...tableHeaderStyle }}>Item</th>}
{HsnCode == true && <th style={{ width: '10px', ...tableHeaderStyle }}>HSN</th>}
{Quantity == true && <th style={{ width: '10px', ...tableHeaderStyle }}>Qty</th>}
{MRP == true && <th style={{ width: '10px', ...tableHeaderStyle }}>MRP</th>}
{Rate == true && <th style={{ width: '10px', ...tableHeaderStyle }}>Rate</th>}
{Discount == true && <th style={{ width: '10px', ...tableHeaderStyle }}>Dis </th>}
{Amount == true && <th style={{ width: '10px', textAlign: 'right', ...tableHeaderStyle }}>Amt</th>}
</tr>
</thead>
<tbody>
{(GlobaldummyData ? products : TakeawayData)?.map((item, index) => (
<tr key={index} >
<tr key={index}
style={
index % 2 !== 1 && rowtypeStyle === "even"
? {
...tableBodyStyle
}
: index % 2 === 1 && rowtypeStyle === "odd"
? {
...tableBodyStyle
}
: {}
}>
{SLNO == true && <td style={{ textAlign: 'center' }}>{index + 1}</td>}
{Item == true && <td style={{ display: 'flex', flexDirection: 'column' }}>
<div>{item?.ProdName}</div>
@ -638,7 +699,7 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
</div>
<div className='PrintStyle7-SecondDiv3'>
<div className='PrintStyle7-SecondDivMaster'>
<div className='PrintStyle7-SecondDivMaster' style={{ ...netAmountStyle }}>
<div style={{ fontWeight: "600" }}>Items : {totalQuantityFilter?.length}</div>
<div style={{ fontWeight: "600" }}>Qty : {totalQuantity}</div>
{(table2Data?.OverallDisc > 0 || TotalOfferAmount > 0) && <div style={{ fontWeight: "600" }}>Off : {Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}</div>}
@ -791,6 +852,7 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
pageBreakBefore: "avoid",
pageBreakInside: "avoid",
minHeight: "auto",
...footerColorStyle
}}
>
{