Implement dynamic header and table color functionality
This commit is contained in:
parent
24ba1091ae
commit
88159b5787
|
|
@ -1,8 +1,9 @@
|
|||
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";
|
||||
import { isMobile } from "react-device-detect";
|
||||
import { style } from "../../Product/Printstyles";
|
||||
|
||||
const PrintStyleDCToInvoice2 = ({ invoiceData, preference, printDatas }) => {
|
||||
const {
|
||||
|
|
@ -19,7 +20,7 @@ const PrintStyleDCToInvoice2 = ({ 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;
|
||||
|
|
@ -46,6 +47,33 @@ const PrintStyleDCToInvoice2 = ({ invoiceData, preference, printDatas }) => {
|
|||
|
||||
const lastChunkRows = paginatedChunks.at(-1)?.length || 0;
|
||||
const shouldFooterBeOnNewPage = lastChunkRows > (pageSize === "A5" ? 5 : 10);
|
||||
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 getPageStyle = (isFinalFooterPage) => ({
|
||||
display: "flex",
|
||||
|
|
@ -64,12 +92,13 @@ const PrintStyleDCToInvoice2 = ({ invoiceData, preference, printDatas }) => {
|
|||
DCNo={DCNo}
|
||||
InvoiceDate={InvoiceDate}
|
||||
VehicleNo={VehicleNo}
|
||||
headerStyle={headerStyle}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
const renderFooter = () => (
|
||||
<div className="footer-section">
|
||||
<div className="footer-section" style={{...footerColorStyle}}>
|
||||
{(notesText || termsAndConditions || signature || printGreeting?.SettingValue === "Y") && (
|
||||
<>
|
||||
<hr className="dotted-line" />
|
||||
|
|
@ -115,13 +144,14 @@ const PrintStyleDCToInvoice2 = ({ invoiceData, preference, printDatas }) => {
|
|||
>
|
||||
<div>
|
||||
{(chunkIndex === 0 || formatTheme) && <HeaderSection />}
|
||||
<ProductTable data={dataChunk} />
|
||||
<ProductTable data={dataChunk} tableHeaderStyle={tableHeaderStyle} tableBodyStyle={tableBodyStyle}rowtypeStyle={rowtypeStyle} />
|
||||
{isLastPage && <>
|
||||
<hr className="footer-dotted-line" />
|
||||
<Summary
|
||||
TotalAmount={TotalAmount}
|
||||
TaxAmount={TaxAmount}
|
||||
GrandTotal={GrandTotal}
|
||||
netAmountStyle={netAmountStyle}
|
||||
/>
|
||||
<CustomerDetails
|
||||
CustMobile={CustMobile}
|
||||
|
|
@ -137,12 +167,13 @@ const PrintStyleDCToInvoice2 = ({ invoiceData, preference, printDatas }) => {
|
|||
) : (
|
||||
<div className="container">
|
||||
<HeaderSection />
|
||||
<ProductTable data={ProductDetails} />
|
||||
<ProductTable data={ProductDetails} tableHeaderStyle={tableHeaderStyle} tableBodyStyle={tableBodyStyle}rowtypeStyle={rowtypeStyle} />
|
||||
<hr className="footer-dotted-line" />
|
||||
<Summary
|
||||
TotalAmount={TotalAmount}
|
||||
TaxAmount={TaxAmount}
|
||||
GrandTotal={GrandTotal}
|
||||
netAmountStyle={netAmountStyle}
|
||||
/>
|
||||
<CustomerDetails
|
||||
CustMobile={CustMobile}
|
||||
|
|
@ -159,8 +190,8 @@ export default PrintStyleDCToInvoice2;
|
|||
|
||||
// -------------------- COMPONENTS --------------------
|
||||
|
||||
const Header = ({ logo, branch, InvoiceNo, DCNo, InvoiceDate, VehicleNo }) => (
|
||||
<div className="header-section">
|
||||
const Header = ({ logo, branch, InvoiceNo, DCNo, InvoiceDate, VehicleNo,headerStyle }) => (
|
||||
<div className="header-section" style={{...headerStyle}}>
|
||||
<div className="header-section-wrapper">
|
||||
{logo && <img src={logo} alt="Company Logo" className="header-logo" width={!isMobile ? '60px' : 'auto'} />}
|
||||
<div>
|
||||
|
|
@ -184,7 +215,7 @@ const Header = ({ logo, branch, InvoiceNo, DCNo, InvoiceDate, VehicleNo }) => (
|
|||
</div>
|
||||
);
|
||||
|
||||
const ProductTable = ({ data }) => {
|
||||
const ProductTable = ({ data ,tableHeaderStyle,tableBodyStyle,rowtypeStyle}) => {
|
||||
const columns = [
|
||||
{ label: "S.No", key: "sno", width: "5%" },
|
||||
{ label: "Product", key: "ProdName", width: "20%" },
|
||||
|
|
@ -199,7 +230,7 @@ const ProductTable = ({ data }) => {
|
|||
<>
|
||||
<table className="product-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<tr style={{...tableHeaderStyle}}>
|
||||
{columns.map(col => (
|
||||
<th key={col.key} style={{ width: col.width }} scope="col">{col.label}</th>
|
||||
))}
|
||||
|
|
@ -207,7 +238,18 @@ 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>{index + 1}</td>
|
||||
<td>{prod.ProdName}</td>
|
||||
<td>{prod.ProdVariantName}</td>
|
||||
|
|
@ -223,8 +265,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">
|
||||
<strong>Subtotal</strong>
|
||||
<span>:</span>
|
||||
|
|
|
|||
Loading…
Reference in New Issue