From 12509a49fd6738cacfce0b3098c6ca2972189dec Mon Sep 17 00:00:00 2001 From: Srinath Date: Tue, 3 Mar 2026 19:56:39 +0530 Subject: [PATCH] Implement dynamic header and table color functionality --- .../PurchasePrintTemplate/PurPrintstyle7.jsx | 292 +++++++++++------- 1 file changed, 177 insertions(+), 115 deletions(-) diff --git a/src/Pages/PurchaseQuotation/PurchasePrintTemplate/PurPrintstyle7.jsx b/src/Pages/PurchaseQuotation/PurchasePrintTemplate/PurPrintstyle7.jsx index 2780b01..1513837 100644 --- a/src/Pages/PurchaseQuotation/PurchasePrintTemplate/PurPrintstyle7.jsx +++ b/src/Pages/PurchaseQuotation/PurchasePrintTemplate/PurPrintstyle7.jsx @@ -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"; @@ -16,10 +27,10 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C const dispatch = useDispatch(); - const FieldDetails = printDatas?.FieldDetails?.reduce((acc, item) => { - acc[item.ConfigName] = true; - return acc; - }, {}); + const FieldDetails = printDatas?.FieldDetails?.reduce((acc, item) => { + acc[item.ConfigName] = true; + return acc; + }, {}); const SLNO = FieldDetails?.["Sl.No"]; const Item = FieldDetails?.["Item"]; @@ -29,12 +40,27 @@ 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 let SignatureImg = printDatas?.Signature let Notestext = printDatas?.Notes @@ -43,41 +69,66 @@ 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) - - - - - + const TakeawayData = table2Data?.[0]?.ProductDetails 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) { - paginatedChunks.push(dataSource?.slice(i, i + chunkSize)); + for (let i = 0; i < dataSource?.length; i += chunkSize) { + paginatedChunks.push(dataSource?.slice(i, i + chunkSize)); } 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 ( <> @@ -87,15 +138,15 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
0 ? ' print-page-break' : ''}`} style={{ display: "flex", flexDirection: "column", justifyContent: ((chunkIndex === paginatedChunks.length - 1) && (!shouldFooterBeOnNewPage)) && FormatTheme ? "space-between" : "", height: FormatTheme ? PageSize == "A5" ? '170mm' : "257mm" : "", }} key={chunkIndex}> -
+

-
-
{ table2Data?.[0]?.BrName}
+
+
{table2Data?.[0]?.BrName}
{GlobaldummyData ? 'BranchAddress, Town- 635XXX City - State' : (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 : '')}
- {
{BillName}
} + {
{BillName}
}

@@ -115,7 +166,7 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
- {(TakeawayData?.length > 0 ) && + {(TakeawayData?.length > 0) && <>
@@ -123,30 +174,41 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C - { SLNO == true && } - { Item == true && } - { HsnCode == true && } - { Quantity == true && } - {GlobaldummyData ? GlobalMRP && : MRP == true && } - {GlobaldummyData ? GlobalRate && : Rate == true && } - { Discount == true && } - { Amount == true && } + {SLNO == true && } + {Item == true && } + {HsnCode == true && } + {Quantity == true && } + {GlobaldummyData ? GlobalMRP && : MRP == true && } + {GlobaldummyData ? GlobalRate && : Rate == true && } + {Discount == true && } + {Amount == true && } {dataChunk?.map((item, index) => ( - - { SLNO == true && } - { Item == true && } - { HsnCode == true && } - { Quantity == true && } - { MRP == true && } + + {SLNO == true && } + {Item == true && } + {HsnCode == true && } + {Quantity == true && } + {MRP == true && } {Rate == true && } - { Discount == true && } - { Amount == true && } + {Discount == true && } + {Amount == true && } ))} @@ -161,10 +223,10 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C {((chunkIndex === paginatedChunks.length - 1) && (!shouldFooterBeOnNewPage)) && FormatTheme && <>
-
-
Items : { totalQuantityFilter?.length}
-
Qty : { totalQuantity}
- {(table2Data?.OverallDisc > 0 || TotalOfferAmount > 0) &&
Off : { Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}
} +
+
Items : {totalQuantityFilter?.length}
+
Qty : {totalQuantity}
+ {(table2Data?.OverallDisc > 0 || TotalOfferAmount > 0) &&
Off : {Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}
}
@@ -294,11 +356,11 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
Amount : ₹{GlobaldummyData ? '1,066' : Number(table2Data?.[0]?.NetAmount).toFixed(2)}
- - - - + + + + {table2Data?.CustSuppName && table2Data?.CustSuppName !== undefined && table2Data?.CustSuppName !== null && !GlobaldummyData &&
Customer : {table2Data?.CustSuppName}
@@ -315,6 +377,7 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C pageBreakBefore: "avoid", pageBreakInside: "avoid", minHeight: "auto", + ...footerColorStyle }} > { @@ -339,7 +402,7 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
) } - { Signature == true && (
+ {Signature == true && (

Signature

)} @@ -349,7 +412,7 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C - + }
@@ -376,10 +439,10 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C > <>
-
-
Items : { totalQuantityFilter?.length}
-
Qty : { totalQuantity}
- {(table2Data?.OverallDisc > 0 || TotalOfferAmount > 0) &&
Off : { Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}
} +
+
Items : {totalQuantityFilter?.length}
+
Qty : {totalQuantity}
+ {(table2Data?.OverallDisc > 0 || TotalOfferAmount > 0) &&
Off : {Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}
}
@@ -506,36 +569,28 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
-
Amount : ₹{ Number(table2Data?.[0]?.NetAmount).toFixed(2)}
+
Amount : ₹{Number(table2Data?.[0]?.NetAmount).toFixed(2)}
- - + + {table2Data?.CustSuppName && table2Data?.CustSuppName !== undefined && table2Data?.CustSuppName !== null && !GlobaldummyData &&
Customer : {table2Data?.CustSuppName}
} - - - - - -
- - -
{ (TermsnAdCondition == true && TermsAndConditions?.length > 0) && (
@@ -549,32 +604,27 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
) } - { Signature == true && (
+ {Signature == true && (

Signature

)}
- - -
}
- - :

-
-
{ table2Data?.[0]?.BrName}
+
+
{table2Data?.[0]?.BrName}
{ (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 : '')}
- {
{BillName}
} + {
{BillName}
}

@@ -582,7 +632,7 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
Bill No :{ - table2Data?.[0]?.QuotationNo && extractLastNumber(table2Data?.[0]?.QuotationNo) + table2Data?.[0]?.QuotationNo && extractLastNumber(table2Data?.[0]?.QuotationNo) }
@@ -604,30 +654,41 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
SItemHSNQtyMRPMRPRateRateDis AmtS.NoItemHSNQtyMRPMRPRateRateDis Amt
{chunkIndex * chunkSize + index + 1} -
{item?.ProdName}
-
({item?.Size ? item?.Size : "1"} {item?.SinglePc == 'Y' ? 'PCS' : item?.Type != "C" ? item?.UomName : "COMBO"})
-
{item?.HSN}{item?.Qty}{item?.SinglePc === 'Y' ? item?.Price : item?.MRP}
{chunkIndex * chunkSize + index + 1} +
{item?.ProdName}
+
({item?.Size ? item?.Size : "1"} {item?.SinglePc == 'Y' ? 'PCS' : item?.Type != "C" ? item?.UomName : "COMBO"})
+
{item?.HSN}{item?.Qty}{item?.SinglePc === 'Y' ? item?.Price : item?.MRP}{item?.Price}{item?.Type != "C" ? item?.OfferAmt || 0 : item?.OfferValue || 0}{item?.NetAmt?.toFixed(2)}{item?.Type != "C" ? item?.OfferAmt || 0 : item?.OfferValue || 0}{item?.NetAmt?.toFixed(2)}
- { SLNO == true && } - { Item == true && } - { HsnCode == true && } - { Quantity == true && } - { MRP == true && } - { Rate == true && } - { Discount == true && } - { Amount == true && } + {SLNO == true && } + {Item == true && } + {HsnCode == true && } + {Quantity == true && } + {MRP == true && } + {Rate == true && } + {Discount == true && } + {Amount == true && } {(GlobaldummyData ? products : TakeawayData)?.map((item, index) => ( - - { SLNO == true && } - { Item == true && } - { HsnCode == true && } - { Quantity == true && } - { MRP == true && } + + {SLNO == true && } + {Item == true && } + {HsnCode == true && } + {Quantity == true && } + {MRP == true && } {Rate == true && } - { Discount == true && } - { Amount == true && } + {Discount == true && } + {Amount == true && } ))} @@ -638,10 +699,10 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
-
-
Items : { totalQuantityFilter?.length}
-
Qty : { totalQuantity}
- {(table2Data?.OverallDisc > 0 || TotalOfferAmount > 0) &&
Off : { Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}
} +
+
Items : {totalQuantityFilter?.length}
+
Qty : {totalQuantity}
+ {(table2Data?.OverallDisc > 0 || TotalOfferAmount > 0) &&
Off : {Number(TotalOfferAmount + table2Data?.OverallDisc).toFixed(2)}
}
@@ -768,10 +829,10 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C
-
Amount : ₹{ Number(table2Data?.[0]?.NetAmount).toFixed(2)}
+
Amount : ₹{Number(table2Data?.[0]?.NetAmount).toFixed(2)}
- + @@ -791,6 +852,7 @@ const PurPrintStyle7 = ({ index, ExtraChargeTotal, Date1, totalQuantityFilter, C pageBreakBefore: "avoid", pageBreakInside: "avoid", minHeight: "auto", + ...footerColorStyle }} > {
SItemHSNQtyMRPRateDis AmtS.NoItemHSNQtyMRPRateDis Amt
{index + 1} -
{item?.ProdName}
-
({item?.Size ? item?.Size : "1"} {item?.SinglePc == 'Y' ? 'PCS' : item?.Type != "C" ? item?.UomName : "COMBO"})
-
{item?.HSN}{item?.Qty}{item?.SinglePc === 'Y' ? item?.Price : item?.MRP}
{index + 1} +
{item?.ProdName}
+
({item?.Size ? item?.Size : "1"} {item?.SinglePc == 'Y' ? 'PCS' : item?.Type != "C" ? item?.UomName : "COMBO"})
+
{item?.HSN}{item?.Qty}{item?.SinglePc === 'Y' ? item?.Price : item?.MRP}{item?.Price}{item?.Type != "C" ? item?.OfferAmt || 0 : item?.OfferValue || 0}{item?.NetAmt?.toFixed(2)}{item?.Type != "C" ? item?.OfferAmt || 0 : item?.OfferValue || 0}{item?.NetAmt?.toFixed(2)}