import React from "react";
import { useSelector } from "react-redux";
import signature from "../../../Images/signatureimage.jpg";
import {
GlobalprintSlNo,
GlobalprintItem,
GlobalprintMRP,
GlobalprintDiscount,
GlobalprintQuantity,
GlobalprintRate,
GlobalprintAmount,
GlobalprintHsnCode,
GlobalprintQrcodet,
GlobalPritdummyData,
changeReprintDataFound,
GloabalFieldDetails,
GlobalprintSignature,
GlobalprinttermsAndConditions,
GlobalSignatureImage,
Globalnotes,
GlobalthemeFormat,
GlobalBillName,
} from "../../../Features/ThemeChange/ThemeChange";
import { useDispatch } from "react-redux";
import { extractLastNumber, extractLastNumberOrderId } from "../../../Services/Others";
import { isMobile } from "react-device-detect";
const PurchaseOrdStyle3 = ({
index,
totalQuantityFilter,
Date1,
totalQuantity,
OrderDetailGST,
OrderDetailIGST,
OrderDetailVAT,
table2Data,
PaymentStatus,
PrintLogo,
PrintGreeting,
printDatas,
}) => {
const dispatch = useDispatch();
// const FieldDetails = useSelector(GloabalFieldDetails);
const FieldDetails = printDatas?.FieldDetails?.reduce((acc, item) => {
acc[item.ConfigName] = true;
return acc;
}, {});
console.log(table2Data,'table2Data?.BrMobile');
const SLNO = FieldDetails?.["Sl.No"];
const Item = FieldDetails?.["Item"];
const MRP = FieldDetails?.["MRP"];
const Discount = FieldDetails?.["Discount"];
const Quantity = FieldDetails?.["Quantity"];
const Rate = FieldDetails?.["Rate"];
const Amount = FieldDetails?.["Amount"];
const HsnCode = FieldDetails?.["HsnCode"];
const Qrcodet = FieldDetails?.["Qrcode"];
const GlobalSlNo = useSelector(GlobalprintSlNo);
const GlobalItem = useSelector(GlobalprintItem);
const GlobalMRP = useSelector(GlobalprintMRP);
const GlobalDiscount = useSelector(GlobalprintDiscount);
const GlobalQuantity = useSelector(GlobalprintQuantity);
const GlobalRate = useSelector(GlobalprintRate);
const GlobalAmount = useSelector(GlobalprintAmount);
const GlobalHsnCode = useSelector(GlobalprintHsnCode);
const GlobalQrcodet = useSelector(GlobalprintQrcodet);
const GlobaldummyData = useSelector(GlobalPritdummyData);
const GlobalSignature = useSelector(GlobalprintSignature);
const GlobaltermsAndConditions = useSelector(GlobalprinttermsAndConditions);
const GlobalSignatureImages = useSelector(GlobalSignatureImage);
const GlobalIsnotes = useSelector(Globalnotes);
const GlobalthemeFormatr = useSelector(GlobalthemeFormat)
console.log(printDatas, "GlobalthemeFormatr");
let TermsAndConditions = printDatas?.TermsandConditions
let SignatureImg = printDatas?.Signature
let Notestext = printDatas?.Notes
let FormatTheme = printDatas?.PrintType == "S" ? true : false
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 currentDate = new Date();
const day = currentDate.getDate().toString().padStart(2, '0');
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const monthIndex = currentDate.getMonth();
const year = currentDate.getFullYear().toString().slice(-2);
const formattedDate = `${day}-${monthNames[monthIndex]}-${year}`;
const purchaseData = table2Data?.productDetails || [];
// Calculate SalesWiseOffers total amount
const products = [
{ ProdName: 'ITEM 1', Rate: 88.00, SalesQty: 2, MRP: 100, TotalAmt: 176, discount: 0, HSN: '01' },
{ ProdName: 'ITEM 2', Rate: 300.00, SalesQty: 1, MRP: 350, TotalAmt: 300, discount: 0, HSN: '02' },
{ ProdName: 'ITEM 3', Rate: 200.00, SalesQty: 1, MRP: 250, TotalAmt: 200, discount: 0, HSN: '03' },
{ ProdName: 'ITEM 4', Rate: 30.00, SalesQty: 1, MRP: 50, TotalAmt: 30, discount: 0, HSN: '04' },
{ ProdName: 'ITEM 5', Rate: 30.00, SalesQty: 1, MRP: 50, TotalAmt: 30, discount: 0, HSN: '05' },
{ ProdName: 'ITEM 6', Rate: 130.00, SalesQty: 1, MRP: 150, TotalAmt: 130, discount: 0, HSN: '06' },
{ ProdName: 'ITEM 7', Rate: 230.00, SalesQty: 1, MRP: 250, TotalAmt: 230, discount: 0, HSN: '08' },
];
const chunkSize =isMobile ? 16 : PageSize == "A5" ? 11 : 16;
let dataSource = [];
if (GlobaldummyData || purchaseData?.length > 0) {
dataSource = GlobaldummyData ? products : purchaseData;
}
// Paginate the data
const paginatedChunks = [];
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 > (isMobile ? 11 : PageSize == "A5" ? 5 : 10);
return (
<>
{FormatTheme ?
{paginatedChunks.map((dataChunk, chunkIndex) => (
//
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}>
0 ? ' print-page-break' : ''}`} style={{ display: "flex", flexDirection: "column", justifyContent: ((chunkIndex === paginatedChunks.length - 1) && (shouldFooterBeOnNewPage)) && FormatTheme ? "space-between" : "", height: FormatTheme ? PageSize == "A5" ? '170mm' : (isMobile ? "295mm" : "257mm") : "", }} key={chunkIndex}>
{/*
*/}
{GlobaldummyData ? 'XYZ Shop' : table2Data?.BrName}
{GlobaldummyData ?
'BranchAddress, Town- 635XXX City - State' :
(table2Data?.AddressDetails?.[0]?.Address1 || '') + (table2Data?.AddressDetails?.[0]?.City ? (table2Data?.AddressDetails?.[0]?.Address1 && table2Data?.AddressDetails?.[0]?.City ? '-' : '') + table2Data?.AddressDetails?.[0]?.City : '') + (table2Data?.AddressDetails?.[0]?.Zip ? (table2Data?.AddressDetails?.[0]?.City && table2Data?.AddressDetails?.[0]?.Zip ? '-' : '') + table2Data?.AddressDetails?.[0]?.Zip : '')}
{table2Data?.BrGSTIN &&
GST NO :{GlobaldummyData ? '334bhbsagbysfgbfgbu' : table2Data?.BrGSTIN}, CIN :u00045hhsgbubufsdug
}
Mobile : +91 {GlobaldummyData ? '986XXXXXXX' : table2Data?.BrMobile}
BILL NO :{GlobaldummyData ? '51' : table2Data?.OrderId && extractLastNumberOrderId(table2Data?.OrderId, table2Data?.FYStatus)}
{GlobaldummyData ? formattedDate : Date1}
{(purchaseData?.length > 0 || GlobaldummyData) &&
{GlobaldummyData ? GlobalSlNo &&
S.No
: SLNO &&
S.No
}
{GlobaldummyData ? GlobalItem &&
ITEM
: Item &&
ITEM
}
{GlobaldummyData ? GlobalHsnCode &&
HSN
: HsnCode &&
HSN
}
{GlobaldummyData ? GlobalMRP &&
MRP
: MRP &&
MRP
}
{GlobaldummyData ? GlobalQuantity &&
QTY
: Quantity &&
QTY
}
{GlobaldummyData ? GlobalRate &&
RATE
: Rate &&
RATE
}
{GlobaldummyData ? GlobalDiscount &&
DIS
: Discount &&
DIS
}
{GlobaldummyData ? GlobalAmount &&
AMT
: Amount &&
AMT
}
{dataChunk?.map((item, index) => (
{GlobaldummyData ? GlobalSlNo &&
{index + 1}
: SLNO &&
{chunkIndex * chunkSize + index + 1}
}
{GlobaldummyData ? GlobalItem &&
{item?.ProdName}
: Item &&
{item?.ProdName}
({item?.Size ? item?.Size : "1"} {item?.SinglePc == 'Y' ? 'PCS' : item?.Type != "C" ? item?.UomName : "COMBO"})
{item?.BrandName !== null ? item?.BrandName : ""}
{item?.ProductIdentifierDtls?.length > 0 ? (item?.ProductIdentifierDtls?.filter((items) => !(items.SerialNumber == "" || items.SerialNumber == null))
?.map(a => { return (
{a.SerialNumber}
) })) : ""} {item?.ProductIdentifierDtls?.length > 0 ? item?.ProductIdentifierDtls.filter((item1) => item1.IMEI1 !== "" || item1.IMEI2 !== "")
?.map(item2 => {
const imei1 = item2.IMEI1 || "";
const imei2 = item2.IMEI2 || "";
return (
{[imei1, imei2].filter(Boolean).join(",")}
);
}
) : ""}
}
{GlobaldummyData ? GlobalHsnCode &&
{item?.HSN}
: HsnCode &&
{item?.HSN}
}
{GlobaldummyData ? GlobalMRP &&
{item?.MRP}
: MRP &&
{item?.SinglePc === 'Y' ? item?.Rate : item?.MRP}
}
{GlobaldummyData ? GlobalQuantity &&
{item?.SalesQty}
: Quantity &&
{item?.SalesQty}
}
{GlobaldummyData ? GlobalRate &&
{item?.Rate}
: Rate &&
{item?.Rate}
}
{GlobaldummyData ? GlobalDiscount &&
{item?.discount}
: Discount &&
{item?.Type != "C" ? item?.OfferAmt || 0 : item?.OfferValue || 0}
}
{GlobaldummyData ? GlobalAmount &&
{item?.TotalAmt}
: Amount &&
{item?.Type != "C" ? item?.TotalAmt - item?.OfferAmt || 0 : item?.TotalAmt - item?.OfferValue || 0}
}
))}
}
{((chunkIndex === paginatedChunks.length - 1) && (!shouldFooterBeOnNewPage)) && FormatTheme &&
<>
{((OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) ||
(OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) ||
(OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0)) &&
<>
--------- GST Breakup Details -----------
{(OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) &&
|
Taxable Amount
|
CGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
|
SGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
|
Total Amount
|
{OrderDetailGST?.map((item) =>
|
{Number(item.WithOutTaxAmount).toFixed(2)}
|
{Number(item.CGST).toFixed(2)}
|
{Number(item.SGST).toFixed(2)}
|
{Number(item.TotalAmt).toFixed(2)} |
)
}
}
{(OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) &&
<>
|
Taxable Amount
|
IGST ({OrderDetailIGST?.[0]?.TaxPercentage}%)
|
Total Amount
|
{OrderDetailIGST?.map((item) =>
|
{Number(item.WithOutTaxAmount).toFixed(2)}
|
{Number(item.TaxAmt).toFixed(2)}
|
{Number(item.TotalAmt).toFixed(2)} |
)
}
>
}
{(OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0) &&
<>
|
Taxable Amount
|
VAT ({OrderDetailVAT?.[0]?.TaxPercentage}%)
|
Total Amount
|
{OrderDetailVAT?.map((item) =>
|
{Number(item.WithOutTaxAmount).toFixed(2)}
|
{Number(item.TaxAmt).toFixed(2)}
|
{Number(item.TotalAmt).toFixed(2)} |
)
}
>
}
>
}
{/*
*/}
{/*
*/}
Your Order No :{GlobaldummyData ? '01' : table2Data?.SalesId && extractLastNumber(table2Data?.SalesId)}
{GlobaldummyData &&
Customer : Customer Name
}
{table2Data?.CustSuppName && table2Data?.CustSuppName !== undefined && table2Data?.CustSuppName !== null && !GlobaldummyData &&
Customer : {table2Data?.CustSuppName}
}
{/*
*/}
{/*
*/}
{GlobaldummyData ? GlobalIsnotes &&
(
Notes : 10 days Return policy
) :
Notestext && (
)
}
{GlobaldummyData ? GlobaltermsAndConditions &&
(
Terms & Conditions
- Once goods are sold, they are not exchangeable or refundable.
- Please check the product before leaving the counter.
)
:
(TermsnAdCondition == true && TermsAndConditions?.length > 0) && (
Terms & Conditions
{TermsAndConditions?.map(item => (- {item?.TermsandConditions}
))}
{/* - Please check the product before leaving the counter.
*/}
)
}
{GlobaldummyData ? GlobalSignature && (
Signature
) : Signature == true && (
Signature
)}
{PrintGreeting?.SettingValue === "Y" &&
<>
{/*
*/}
Thank You
>
}
>
}
))}
{shouldFooterBeOnNewPage && FormatTheme &&
<>
{((OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) ||
(OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) ||
(OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0)) &&
<>
--------- GST Breakup Details -----------
{(OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) &&
|
Taxable Amount
|
CGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
|
SGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
|
Total Amount
|
{OrderDetailGST?.map((item) =>
|
{Number(item.WithOutTaxAmount).toFixed(2)}
|
{Number(item.CGST).toFixed(2)}
|
{Number(item.SGST).toFixed(2)}
|
{Number(item.TotalAmt).toFixed(2)} |
)
}
}
{(OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) &&
<>
|
Taxable Amount
|
IGST ({OrderDetailIGST?.[0]?.TaxPercentage}%)
|
Total Amount
|
{OrderDetailIGST?.map((item) =>
|
{Number(item.WithOutTaxAmount).toFixed(2)}
|
{Number(item.TaxAmt).toFixed(2)}
|
{Number(item.TotalAmt).toFixed(2)} |
)
}
>
}
{(OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0) &&
<>
|
Taxable Amount
|
VAT ({OrderDetailVAT?.[0]?.TaxPercentage}%)
|
Total Amount
|
{OrderDetailVAT?.map((item) =>
|
{Number(item.WithOutTaxAmount).toFixed(2)}
|
{Number(item.TaxAmt).toFixed(2)}
|
{Number(item.TotalAmt).toFixed(2)} |
)
}
>
}
>
}
{/*
*/}
Your Order No :{GlobaldummyData ? '01' : table2Data?.SalesId && extractLastNumber(table2Data?.SalesId)}
{GlobaldummyData &&
Customer : Customer Name
}
{table2Data?.CustSuppName && table2Data?.CustSuppName !== undefined && table2Data?.CustSuppName !== null && !GlobaldummyData &&
Customer : {table2Data?.CustSuppName}
}
{/*
*/}
{GlobaldummyData ? GlobalIsnotes &&
(
Notes : 10 days Return policy
) :
Notestext && (
)
}
{GlobaldummyData ? GlobaltermsAndConditions &&
(
Terms & Conditions
- Once goods are sold, they are not exchangeable or refundable.
- Please check the product before leaving the counter.
)
:
(TermsnAdCondition == true && TermsAndConditions?.length > 0) && (
Terms & Conditions
{TermsAndConditions?.map(item => (- {item?.TermsandConditions}
))}
{/* - Please check the product before leaving the counter.
*/}
)
}
{GlobaldummyData ? GlobalSignature && (
Signature
) : Signature == true && (
Signature
)}
{PrintGreeting?.SettingValue === "Y" &&
<>
{/*
*/}
Thank You
>
}
>
}
:
{GlobaldummyData ? 'XYZ Shop' : table2Data?.BrName}
{GlobaldummyData ?
'BranchAddress, Town- 635XXX City - State' :
(table2Data?.AddressDetails?.[0]?.Address1 || '') + (table2Data?.AddressDetails?.[0]?.City ? (table2Data?.AddressDetails?.[0]?.Address1 && table2Data?.AddressDetails?.[0]?.City ? '-' : '') + table2Data?.AddressDetails?.[0]?.City : '') + (table2Data?.AddressDetails?.[0]?.Zip ? (table2Data?.AddressDetails?.[0]?.City && table2Data?.AddressDetails?.[0]?.Zip ? '-' : '') + table2Data?.AddressDetails?.[0]?.Zip : '')}
{table2Data?.BrGSTIN &&
GST NO :{GlobaldummyData ? '334bhbsagbysfgbfgbu' : table2Data?.BrGSTIN}, CIN :u00045hhsgbubufsdug
}
Mobile : +91 {GlobaldummyData ? '986XXXXXXX' : table2Data?.BrMobile}
BILL NO :{GlobaldummyData ? '51' : table2Data?.OrderId && extractLastNumberOrderId(table2Data?.OrderId, table2Data?.FYStatus)}
{GlobaldummyData ? formattedDate : Date1}
{(purchaseData?.length > 0 || GlobaldummyData) &&
{GlobaldummyData ? GlobalSlNo &&
S.No
: SLNO &&
S.No
}
{GlobaldummyData ? GlobalItem &&
ITEM
: Item &&
ITEM
}
{GlobaldummyData ? GlobalHsnCode &&
HSN
: HsnCode &&
HSN
}
{GlobaldummyData ? GlobalMRP &&
MRP
: MRP &&
MRP
}
{GlobaldummyData ? GlobalQuantity &&
QTY
: Quantity &&
QTY
}
{GlobaldummyData ? GlobalRate &&
RATE
: Rate &&
RATE
}
{GlobaldummyData ? GlobalDiscount &&
DIS
: Discount &&
DIS
}
{GlobaldummyData ? GlobalAmount &&
AMT
: Amount &&
AMT
}
{(GlobaldummyData ? products : purchaseData)?.map((item, index) => (
{GlobaldummyData ? GlobalSlNo &&
{index + 1}
: SLNO &&
{index + 1}
}
{GlobaldummyData ? GlobalItem &&
{item?.ProdName}
: Item &&
{item?.ProdName}
({item?.Size ? item?.Size : "1"} {item?.SinglePc == 'Y' ? 'PCS' : item?.Type != "C" ? item?.UomName : "COMBO"})
{item?.BrandName !== null ? item?.BrandName : ""}
{item?.ProductIdentifierDtls?.length > 0 ? (item?.ProductIdentifierDtls?.filter((items) => !(items.SerialNumber == "" || items.SerialNumber == null))
?.map(a => { return (
{a.SerialNumber}
) })) : ""} {item?.ProductIdentifierDtls?.length > 0 ? item?.ProductIdentifierDtls.filter((item1) => item1.IMEI1 !== "" || item1.IMEI2 !== "")
?.map(item2 => {
const imei1 = item2.IMEI1 || "";
const imei2 = item2.IMEI2 || "";
return (
{[imei1, imei2].filter(Boolean).join(",")}
);
}
) : ""}
}
{GlobaldummyData ? GlobalHsnCode &&
{item?.HSN}
: HsnCode &&
{item?.HSN}
}
{GlobaldummyData ? GlobalMRP &&
{item?.MRP}
: MRP &&
{item?.SinglePc === 'Y' ? item?.Rate : item?.MRP}
}
{GlobaldummyData ? GlobalQuantity &&
{item?.SalesQty}
: Quantity &&
{item?.SalesQty}
}
{GlobaldummyData ? GlobalRate &&
{item?.Rate}
: Rate &&
{item?.Rate}
}
{GlobaldummyData ? GlobalDiscount &&
{item?.discount}
: Discount &&
{item?.Type != "C" ? item?.OfferAmt || 0 : item?.OfferValue || 0}
}
{GlobaldummyData ? GlobalAmount &&
{item?.TotalAmt}
: Amount &&
{item?.Type != "C" ? item?.TotalAmt - item?.OfferAmt || 0 : item?.TotalAmt - item?.OfferValue || 0}
}
))}
}
{/*
*/}
{((OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) ||
(OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) ||
(OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0)) &&
<>
--------- GST Breakup Details -----------
{(OrderDetailGST?.length > 0 && OrderDetailGST?.[0]?.TaxAmt > 0) &&
|
Taxable Amount
|
CGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
|
SGST ({(OrderDetailGST?.[0]?.TaxPercentage) / 2}%)
|
Total Amount
|
{OrderDetailGST?.map((item) =>
|
{Number(item.WithOutTaxAmount).toFixed(2)}
|
{Number(item.CGST).toFixed(2)}
|
{Number(item.SGST).toFixed(2)}
|
{Number(item.TotalAmt).toFixed(2)} |
)
}
}
{(OrderDetailIGST?.length > 0 && OrderDetailIGST?.[0]?.TaxAmt > 0) &&
<>
|
Taxable Amount
|
IGST ({OrderDetailIGST?.[0]?.TaxPercentage}%)
|
Total Amount
|
{OrderDetailIGST?.map((item) =>
|
{Number(item.WithOutTaxAmount).toFixed(2)}
|
{Number(item.TaxAmt).toFixed(2)}
|
{Number(item.TotalAmt).toFixed(2)} |
)
}
>
}
{(OrderDetailVAT?.length > 0 && OrderDetailVAT?.[0]?.TaxAmt > 0) &&
<>
|
Taxable Amount
|
VAT ({OrderDetailVAT?.[0]?.TaxPercentage}%)
|
Total Amount
|
{OrderDetailVAT?.map((item) =>
|
{Number(item.WithOutTaxAmount).toFixed(2)}
|
{Number(item.TaxAmt).toFixed(2)}
|
{Number(item.TotalAmt).toFixed(2)} |
)
}
>
}
>
}
{/*
*/}
Your Order No :{GlobaldummyData ? '01' : table2Data?.SalesId && extractLastNumber(table2Data?.SalesId)}
{table2Data?.CustSuppName && table2Data?.CustSuppName !== undefined && table2Data?.CustSuppName !== null && !GlobaldummyData &&
Customer : {table2Data?.CustSuppName}
}
{
Notestext && (
)
}
{
(TermsnAdCondition == true && TermsAndConditions?.length > 0) && (
Terms & Conditions
{TermsAndConditions?.map(item => (- {item?.TermsandConditions}
))}
{/* - Please check the product before leaving the counter.
*/}
)
}
{ Signature == true && (
Signature
)}
{PrintGreeting?.SettingValue === "Y" &&
<>
{/*
*/}
Thank You
>
}
{/*
print
*/}
}
>
);
};
export default PurchaseOrdStyle3;