import React, { useMemo } from "react";
import { useSelector } from "react-redux";
import { GloabalFieldDetails } from "../../../Features/ThemeChange/ThemeChange";
import { dateFormatChange1 } from "../../../Services/Others";
const PrintStyleDCToInvoiceA4Standard = ({ invoiceData, preference, printDatas }) => {
const {
InvoiceNo,
DCNo,
InvoiceDate,
CustMobile,
GrandTotal,
TaxAmount,
TotalAmount,
ProductDetails,
AddressDetails,
CustName,
VehicleNo
} = invoiceData;
console.log(invoiceData, "invoiceData")
const fieldDetails = useSelector(GloabalFieldDetails);
const signature = fieldDetails?.["signature"];
const termsAndConditions = fieldDetails?.["terms&conditions"];
const termsAndConditionsData = printDatas?.TermsandConditions;
const signatureImg = printDatas?.Signature;
const notesText = printDatas?.Notes;
const formatTheme = printDatas?.PrintType === "S";
const pageSize = printDatas?.PageSize;
const branch = AddressDetails[0];
const bankDetails = branch?.BankDetails;
console.log(branch, "branchbranch")
const logo = branch?.CompLogo;
const printGreeting = preference?.[0]?.SettingDtlDetails?.find(
(i) => i.SettingIdName === 'PrintGreetings'
);
const chunkSize = pageSize === "A5" ? 8 : 11;
const paginatedChunks = useMemo(() => {
const chunks = [];
for (let i = 0; i < ProductDetails.length; i += chunkSize) {
chunks.push(ProductDetails.slice(i, i + chunkSize));
}
return chunks;
}, [ProductDetails, chunkSize]);
const lastChunkRows = paginatedChunks.at(-1)?.length || 0;
const shouldFooterBeOnNewPage = lastChunkRows > (pageSize === "A5" ? 5 : 10);
const getPageStyle = (isFinalFooterPage) => ({
display: "flex",
flexDirection: "column",
justifyContent: isFinalFooterPage ? "space-between" : "",
height: pageSize === "A5" ? "170mm" : "95vh",
maxHeight: "97vh"
});
const HeaderSection = () => (
<>
>
);
const renderFooter = () => (
<>
{(termsAndConditions || signature || bankDetails?.length > 0) && (
{(bankDetails?.length > 0) &&
Bank Details:
Bank Name: {bankDetails?.[0]?.BankName}
Account No.: {bankDetails?.[0]?.AccountNo}
IFSC Code: {bankDetails?.[0]?.IFSCCode}
Branch Name: {bankDetails?.[0]?.BankBranch}
}
{termsAndConditions && termsAndConditionsData?.length > 0 && (
Terms & Conditions
{termsAndConditionsData.map((item, idx) => (
- {item?.TermsandConditions}
))}
)}
{signature && (
Certified that the particulars given above are true and correct.
Authorised Signatory
(Common Seal)
)}
)}
{(notesText || printGreeting?.SettingValue === "Y") && (
<>
{notesText && {notesText}
}
{printGreeting?.SettingValue === "Y" && (
Thank You Visit Again
)}
>
)}
>
);
return (
<>
{formatTheme ? (
paginatedChunks.map((dataChunk, chunkIndex) => {
const isLastPage = chunkIndex === paginatedChunks.length - 1;
const isFinalFooterPage = isLastPage && !shouldFooterBeOnNewPage;
return (
0 ? ' print-page-break' : ''}`}
style={getPageStyle(isFinalFooterPage)}
>
{(chunkIndex === 0 || formatTheme) &&
}
{isLastPage &&
}
{!formatTheme && isFinalFooterPage && renderFooter()}
{formatTheme && isFinalFooterPage &&
{renderFooter()}
}
);
})
) : (
)}
>
);
};
export default PrintStyleDCToInvoiceA4Standard;
// -------------------- COMPONENTS --------------------
const Header = ({ logo, branch }) => (
<>
{/* {logo &&

} */}
{branch.CompName}
{branch.Address1}-{branch.City}-{branch?.Zip}
Phone: {branch.BrMobile}
{branch?.BrEmail &&
Email: {branch.BrEmail}
}
{branch?.BrGSTIN &&
GSTIN: {branch.BrGSTIN}
}
SALES INVOICE
>
);
const InvoiceMeta = ({ InvoiceNo, DCNo, InvoiceDate, CustMobile, VehicleNo, CustName }) => (
Details of Receiver | Billed to
Invoice No: {InvoiceNo}
Delivery No: {DCNo}
Date: {dateFormatChange1(InvoiceDate)}
{VehicleNo &&
Vehicle No: {VehicleNo}
}
{CustName &&
Customer Name: {CustName}
}
Customer Mobile No: {CustMobile || '-'}
);
const InvoiceAmountWords = ({ amount }) => {
const numberToWords = (num) => {
const a = [
"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten",
"Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen",
"Eighteen", "Nineteen"
];
const b = ["", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"];
if (num === 0) return "Zero";
if (num < 20) return a[num];
if (num < 100) return b[Math.floor(num / 10)] + (num % 10 ? " " + a[num % 10] : "");
if (num < 1000)
return a[Math.floor(num / 100)] + " Hundred" + (num % 100 ? " and " + numberToWords(num % 100) : "");
if (num < 100000)
return numberToWords(Math.floor(num / 1000)) + " Thousand" + (num % 1000 ? " " + numberToWords(num % 1000) : "");
return "Number too large";
};
return (
Total Invoice Amount in Words:
{numberToWords(amount)}
);
};
const ProductTable = ({ data }) => {
const columns = [
{ label: "S.No", key: "sno", width: "5%" },
{ label: "Product", key: "ProdName", width: "20%" },
{ label: "Variant", key: "ProdVariantName", width: "20%" },
{ label: "Qty", key: "Qty", width: "10%" },
{ label: "Rate", key: "ProductRate", width: "10%" },
{ label: "Tax", key: "TaxAmount", width: "10%" },
{ label: "Total", key: "TotalAmount", width: "15%" }
];
return (
{columns.map(col => (
| {col.label} |
))}
{data.map((prod, index) => (
| {index + 1} |
{prod.ProdName} |
{prod.ProdVariantName} |
{prod.Qty} |
{prod.ProductRate} |
{prod.TaxAmount} |
{prod.TotalAmount} |
))}
);
};
const Summary = ({ bankDetails, TotalAmount, TaxAmount, GrandTotal }) => (
<>
Subtotal: ₹ {TotalAmount.toFixed(2)}
Tax Amount: ₹ {TaxAmount.toFixed(2)}
Grand Total: ₹ {GrandTotal.toFixed(2)}
Total Amount Before Tax
₹ {TotalAmount.toFixed(2)}
Total Amount After Tax
₹ {(TotalAmount + TaxAmount).toFixed(2)}
₹ {(TotalAmount + TaxAmount).toFixed(2)}
>
);