Implement dynamic header and table color functionality
This commit is contained in:
parent
e4171e135b
commit
741290784d
|
|
@ -1,6 +1,6 @@
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { GloabalFieldDetails } from "../../../Features/ThemeChange/ThemeChange";
|
import { GloabalDCtoInvoiceFieldDetails, GloabalFieldDetails } from "../../../Features/ThemeChange/ThemeChange";
|
||||||
import { dateFormatChange1 } from "../../../Services/Others";
|
import { dateFormatChange1 } from "../../../Services/Others";
|
||||||
|
|
||||||
const PrintStyleDCToInvoice5 = ({ invoiceData, preference, printDatas }) => {
|
const PrintStyleDCToInvoice5 = ({ invoiceData, preference, printDatas }) => {
|
||||||
|
|
@ -18,7 +18,7 @@ const PrintStyleDCToInvoice5 = ({ invoiceData, preference, printDatas }) => {
|
||||||
VehicleNo
|
VehicleNo
|
||||||
} = invoiceData;
|
} = invoiceData;
|
||||||
|
|
||||||
const fieldDetails = useSelector(GloabalFieldDetails);
|
const fieldDetails = useSelector(GloabalDCtoInvoiceFieldDetails);
|
||||||
const signature = fieldDetails?.["signature"];
|
const signature = fieldDetails?.["signature"];
|
||||||
const termsAndConditions = fieldDetails?.["terms&conditions"];
|
const termsAndConditions = fieldDetails?.["terms&conditions"];
|
||||||
const termsAndConditionsData = printDatas?.TermsandConditions;
|
const termsAndConditionsData = printDatas?.TermsandConditions;
|
||||||
|
|
@ -45,6 +45,34 @@ const PrintStyleDCToInvoice5 = ({ invoiceData, preference, printDatas }) => {
|
||||||
const lastChunkRows = paginatedChunks.at(-1)?.length || 0;
|
const lastChunkRows = paginatedChunks.at(-1)?.length || 0;
|
||||||
const shouldFooterBeOnNewPage = lastChunkRows > (pageSize === "A5" ? 5 : 10);
|
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) => ({
|
const getPageStyle = (isFinalFooterPage) => ({
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
|
|
@ -61,12 +89,13 @@ const PrintStyleDCToInvoice5 = ({ invoiceData, preference, printDatas }) => {
|
||||||
DCNo={DCNo}
|
DCNo={DCNo}
|
||||||
InvoiceDate={InvoiceDate}
|
InvoiceDate={InvoiceDate}
|
||||||
VehicleNo={VehicleNo}
|
VehicleNo={VehicleNo}
|
||||||
|
headerStyle={headerStyle}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderFooter = () => (
|
const renderFooter = () => (
|
||||||
<div className="footer-section">
|
<div className="footer-section" style={{...footerColorStyle}}>
|
||||||
{(notesText || termsAndConditions || signature || printGreeting?.SettingValue === "Y") && (
|
{(notesText || termsAndConditions || signature || printGreeting?.SettingValue === "Y") && (
|
||||||
<>
|
<>
|
||||||
{notesText && <p className="footer-notes">{notesText}</p>}
|
{notesText && <p className="footer-notes">{notesText}</p>}
|
||||||
|
|
@ -112,12 +141,13 @@ const PrintStyleDCToInvoice5 = ({ invoiceData, preference, printDatas }) => {
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
{(chunkIndex === 0 || formatTheme) && <HeaderSection />}
|
{(chunkIndex === 0 || formatTheme) && <HeaderSection />}
|
||||||
<ProductTable data={dataChunk} />
|
<ProductTable data={dataChunk} tableHeaderStyle={tableHeaderStyle} tableBodyStyle={tableBodyStyle}rowtypeStyle={rowtypeStyle}/>
|
||||||
{isLastPage && <>
|
{isLastPage && <>
|
||||||
<Summary
|
<Summary
|
||||||
TotalAmount={TotalAmount}
|
TotalAmount={TotalAmount}
|
||||||
TaxAmount={TaxAmount}
|
TaxAmount={TaxAmount}
|
||||||
GrandTotal={GrandTotal}
|
GrandTotal={GrandTotal}
|
||||||
|
netAmountStyle={netAmountStyle}
|
||||||
/>
|
/>
|
||||||
<div className="footer-ruler" />
|
<div className="footer-ruler" />
|
||||||
<CustomerDetails
|
<CustomerDetails
|
||||||
|
|
@ -134,11 +164,12 @@ const PrintStyleDCToInvoice5 = ({ invoiceData, preference, printDatas }) => {
|
||||||
) : (
|
) : (
|
||||||
<div className="container">
|
<div className="container">
|
||||||
<HeaderSection />
|
<HeaderSection />
|
||||||
<ProductTable data={ProductDetails} />
|
<ProductTable data={ProductDetails} tableHeaderStyle={tableHeaderStyle} tableBodyStyle={tableBodyStyle}rowtypeStyle={rowtypeStyle}/>
|
||||||
<Summary
|
<Summary
|
||||||
TotalAmount={TotalAmount}
|
TotalAmount={TotalAmount}
|
||||||
TaxAmount={TaxAmount}
|
TaxAmount={TaxAmount}
|
||||||
GrandTotal={GrandTotal}
|
GrandTotal={GrandTotal}
|
||||||
|
netAmountStyle={netAmountStyle}
|
||||||
/>
|
/>
|
||||||
<div className="footer-ruler" />
|
<div className="footer-ruler" />
|
||||||
<CustomerDetails
|
<CustomerDetails
|
||||||
|
|
@ -156,8 +187,8 @@ export default PrintStyleDCToInvoice5;
|
||||||
|
|
||||||
// -------------------- COMPONENTS --------------------
|
// -------------------- COMPONENTS --------------------
|
||||||
|
|
||||||
const Header = ({ branch, InvoiceNo, DCNo, InvoiceDate, VehicleNo }) => (
|
const Header = ({ branch, InvoiceNo, DCNo, InvoiceDate, VehicleNo,headerStyle }) => (
|
||||||
<div className="header-section">
|
<div className="header-section" style={{...headerStyle}}>
|
||||||
<div className="header-section-wrapper">
|
<div className="header-section-wrapper">
|
||||||
<div className="header-company">{branch?.CompName}</div>
|
<div className="header-company">{branch?.CompName}</div>
|
||||||
<div>{branch?.Address1}-{branch?.City}-{branch?.Zip}</div>
|
<div>{branch?.Address1}-{branch?.City}-{branch?.Zip}</div>
|
||||||
|
|
@ -179,7 +210,7 @@ const Header = ({ branch, InvoiceNo, DCNo, InvoiceDate, VehicleNo }) => (
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const ProductTable = ({ data }) => {
|
const ProductTable = ({ data ,tableHeaderStyle,tableBodyStyle,rowtypeStyle}) => {
|
||||||
const columns = [
|
const columns = [
|
||||||
{ label: "S.No", key: "sno", width: "5%", align: 'center' },
|
{ label: "S.No", key: "sno", width: "5%", align: 'center' },
|
||||||
{ label: "Product", key: "ProdName", width: "35%", align: 'center' },
|
{ label: "Product", key: "ProdName", width: "35%", align: 'center' },
|
||||||
|
|
@ -194,7 +225,7 @@ const ProductTable = ({ data }) => {
|
||||||
<>
|
<>
|
||||||
<table className="product-table">
|
<table className="product-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr style={{...tableHeaderStyle}}>
|
||||||
{columns.map(col => (
|
{columns.map(col => (
|
||||||
<th key={col.key} style={{ width: col.width, textAlign: col.align, }} scope="col">{col.label}</th>
|
<th key={col.key} style={{ width: col.width, textAlign: col.align, }} scope="col">{col.label}</th>
|
||||||
))}
|
))}
|
||||||
|
|
@ -202,7 +233,17 @@ const ProductTable = ({ data }) => {
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{data.map((prod, index) => (
|
{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 className="text-center">{index + 1}</td>
|
||||||
<td>{prod.ProdName}</td>
|
<td>{prod.ProdName}</td>
|
||||||
<td className="text-center">{prod.ProdVariantName}</td>
|
<td className="text-center">{prod.ProdVariantName}</td>
|
||||||
|
|
@ -218,8 +259,8 @@ const ProductTable = ({ data }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Summary = ({ TotalAmount, TaxAmount, GrandTotal }) => (
|
const Summary = ({ TotalAmount, TaxAmount, GrandTotal,netAmountStyle }) => (
|
||||||
<div className="summary">
|
<div className="summary" style={{...netAmountStyle}}>
|
||||||
<div className="total-and-tax">
|
<div className="total-and-tax">
|
||||||
<div>Subtotal:</div>
|
<div>Subtotal:</div>
|
||||||
<div> ₹ {TotalAmount.toFixed(2)}</div>
|
<div> ₹ {TotalAmount.toFixed(2)}</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue