Implement dynamic header and table color functionality

This commit is contained in:
Srinath 2026-03-05 12:11:53 +05:30
parent a2d91b2988
commit 14ace51dc7
1 changed files with 54 additions and 14 deletions

View File

@ -1,6 +1,6 @@
import { useMemo } from "react";
import { useSelector } from "react-redux";
import { GloabalFieldDetails } from "../../../Features/ThemeChange/ThemeChange";
import { GloabalDCtoInvoiceFieldDetails, GloabalFieldDetails } from "../../../Features/ThemeChange/ThemeChange";
import { dateFormatChange1 } from "../../../Services/Others";
@ -19,7 +19,7 @@ const PrintStyleDCToInvoice11 = ({ invoiceData, preference, printDatas }) => {
VehicleNo
} = invoiceData;
const fieldDetails = useSelector(GloabalFieldDetails);
const fieldDetails = useSelector(GloabalDCtoInvoiceFieldDetails);
const signature = fieldDetails?.["signature"];
const termsAndConditions = fieldDetails?.["terms&conditions"];
const termsAndConditionsData = printDatas?.TermsandConditions;
@ -53,9 +53,36 @@ const PrintStyleDCToInvoice11 = ({ invoiceData, preference, printDatas }) => {
height: pageSize === "A5" ? "170mm" : "98vh",
maxHeight: "98vh"
});
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 headerStyle = {
backgroundColor: headerColor?.background,
color: headerColor?.font,
}
const tableHeaderStyle = {
backgroundColor: tableHeaderColor?.background,
color: tableHeaderColor?.font,
}
const tableBodyStyle = {
backgroundColor: tableBodyColor?.background,
color: tableBodyColor?.font,
}
const rowtypeStyle = tableBodyColor?.rowType;
const footerColorStyle = {
backgroundColor: footerColor?.background,
color: footerColor?.font,
}
const netAmountStyle = {
backgroundColor: netAmtColor?.background,
color: netAmtColor?.font,
}
const renderFooter = () => (
<div className="footer-section">
<div className="footer-section" style={{...footerColorStyle}}>
{(notesText || termsAndConditions || signature || printGreeting?.SettingValue === "Y") && (
<>
{notesText && <p className="footer-notes">{notesText}</p>}
@ -94,6 +121,7 @@ const PrintStyleDCToInvoice11 = ({ invoiceData, preference, printDatas }) => {
branch={branch}
InvoiceNo={InvoiceNo}
DCNo={DCNo}
headerStyle={headerStyle}
/>
);
@ -112,13 +140,14 @@ const PrintStyleDCToInvoice11 = ({ invoiceData, preference, printDatas }) => {
>
<div>
{(chunkIndex === 0 || formatTheme) && <HeaderSection />}
<ProductTable data={dataChunk} />
<ProductTable data={dataChunk} tableHeaderStyle={tableHeaderStyle} tableBodyStyle={tableBodyStyle}rowtypeStyle={rowtypeStyle}/>
{isLastPage && (
<>
<Summary
TotalAmount={TotalAmount}
TaxAmount={TaxAmount}
GrandTotal={GrandTotal}
netAmountStyle={netAmountStyle}
/>
<CustomerDetails
CustMobile={CustMobile}
@ -137,11 +166,12 @@ const PrintStyleDCToInvoice11 = ({ invoiceData, preference, printDatas }) => {
) : (
<div className="container">
<HeaderSection />
<ProductTable data={ProductDetails} />
<ProductTable data={ProductDetails} tableHeaderStyle={tableHeaderStyle} tableBodyStyle={tableBodyStyle}rowtypeStyle={rowtypeStyle}/>
<Summary
TotalAmount={TotalAmount}
TaxAmount={TaxAmount}
GrandTotal={GrandTotal}
netAmountStyle={netAmountStyle}
/>
<CustomerDetails
CustMobile={CustMobile}
@ -159,9 +189,9 @@ export default PrintStyleDCToInvoice11;
// COMPONENTS
const Header = ({ branch, InvoiceNo, DCNo }) => (
<div className="header-section">
<div className="header-section-wrapper">
const Header = ({ branch, InvoiceNo, DCNo,headerStyle }) => (
<div className="header-section" >
<div className="header-section-wrapper" style={{...headerStyle}}>
<div className="header-company">{branch?.CompName}</div>
<div className="footer-dotted-line" />
<div className="branch-address">
@ -181,7 +211,7 @@ const Header = ({ branch, InvoiceNo, DCNo }) => (
</div>
);
const ProductTable = ({ data }) => {
const ProductTable = ({ data ,tableHeaderStyle,tableBodyStyle,rowtypeStyle}) => {
const columns = [
{ label: "S.No", key: "sno", width: "5%", align: 'center' },
{ label: "Product", key: "ProdName", width: "35%", align: 'center' },
@ -193,9 +223,9 @@ const ProductTable = ({ data }) => {
];
return (
<table className="product-table">
<table className="product-table" >
<thead>
<tr>
<tr style={{...tableHeaderStyle}}>
{columns.map(col => (
<th key={col.key} style={{ width: col.width, textAlign: col.align }}>{col.label}</th>
))}
@ -203,7 +233,17 @@ const ProductTable = ({ data }) => {
</thead>
<tbody>
{data.map((prod, index) => (
<tr key={prod.UniqueId}>
<tr key={prod.UniqueId} style={
index % 2 !== 1 && rowtypeStyle === "even"
? {
...tableBodyStyle
}
: index % 2 === 1 && rowtypeStyle === "odd"
? {
...tableBodyStyle
}
: {}
}>
<td className="text-center">{index + 1}</td>
<td>{prod.ProdName}</td>
<td className="text-center">{prod.ProdVariantName}</td>
@ -218,8 +258,8 @@ const ProductTable = ({ data }) => {
);
};
const Summary = ({ TotalAmount, TaxAmount, GrandTotal }) => (
<div className="summary">
const Summary = ({ TotalAmount, TaxAmount, GrandTotal ,netAmountStyle}) => (
<div className="summary" style={{...netAmountStyle}}>
<div className="summarydiv">
<div className="text-left">Subtotal</div>
<div className="text-right"> {TotalAmount.toFixed(2)}</div>