import React from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { extractLastNumber, extractLastNumberOrderId, } from '../../../../Services/Others'; import Logo from '../../../../Images/Logo.jpg'; import { GlobalprintSlNo, GlobalprintItem, GlobalprintMRP, GlobalprintDiscount, GlobalprintQuantity, GlobalprintRate, GlobalprintAmount, GlobalprintHsnCode, GlobalprintQrcodet, GlobalPritdummyData, changeReprintDataFound, GloabalFieldDetails, GlobalprintSignature, GlobalprinttermsAndConditions, GlobalSignatureImage, Globalnotes, GlobalthemeFormat, GlobalBillName, GlobalprintCashierName, GlobalprintLogo, GlobalprintTax, GlobalSelectedPrintHeaderColor, } from '../../../../Features/ThemeChange/ThemeChange'; import '../../../../Styles/BookingScreen/PrintTemplates/ThermalPrinter/PrintStyle1.scss'; import QRCode from 'react-qr-code'; import { GlobalUpiIDprint, PreferenceData, } from '../../../../Features/BookingScreen/BookingData/BookingData'; import signature from '../../../../Images/signatureimage.jpg'; import { isMobile } from 'react-device-detect'; const InvoiceTemplate = ({ index, totalQuantityFilter, Date1, CashierName, totalQuantity, OrderDetailGST, OrderDetailIGST, OrderDetailVAT, table2Data, UpiId, PaymentStatus, PrintLogo, PrintGreeting, base64Image, printDatas, isPdf, sportsAppPreference, MembershipApplied = null, }) => { const dispatch = useDispatch(); const GlobalUpiID = useSelector(GlobalUpiIDprint); const FieldDetails = useSelector(GloabalFieldDetails); console.log(table2Data, 'FieldDetails'); const SLNO = FieldDetails?.['Sl.No']; const Item = FieldDetails?.['Item']; console.log(Item, 'Item'); const MRP = FieldDetails?.['MRP']; const Discount = FieldDetails?.['Discount']; const Quantity = FieldDetails?.['Quantity']; const Tax = FieldDetails?.['Tax']; const Rate = FieldDetails?.['Rate']; const Amount = FieldDetails?.['Amount']; const HsnCode = FieldDetails?.['HsnCode']; const Qrcodet = FieldDetails?.['Qrcode']; const LogoField = FieldDetails?.['Logo']; const WeightasKg = FieldDetails?.['Weight']; const GlobalSlNo = useSelector(GlobalprintSlNo); const GlobalItem = useSelector(GlobalprintItem); const GlobalMRP = useSelector(GlobalprintMRP); const GlobalDiscount = useSelector(GlobalprintDiscount); const GlobalTax = useSelector(GlobalprintTax); 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); const GlobalBilltext = useSelector(GlobalBillName); const GlobalLogo = useSelector(GlobalprintLogo); const SettingData = useSelector(PreferenceData); const estimatePrintHeader = SettingData?.[0]?.SettingDtlDetails?.find( (setting) => setting?.SettingIdName?.toLowerCase() === 'estimateprintheader' )?.SettingValue === 'Y'; const keysLength = Object.keys(table2Data ?? {}).length; console.log(GlobalDiscount, Discount, 'Discount'); const SelectedHeaderColor = useSelector(GlobalSelectedPrintHeaderColor); let BankDetails = table2Data?.BankDetails; let TermsAndConditions = printDatas?.TermsandConditions; let SignatureImg = printDatas?.Signature; let Notestext = printDatas?.Notes; let BillName = printDatas?.PrintHdrName; let FormatTheme = printDatas?.PrintType == 'S' ? true : false; let PageSize = printDatas?.PageSize; const Signature = FieldDetails?.['signature']; const TermsnAdCondition = FieldDetails?.['terms&conditions']; console.log(BankDetails, 'GlobalthemeFormatr'); console.log(table2Data, 'FormatThemekjhjk', PaymentStatus); 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 TakeawayData = table2Data?.productDetails?.filter( (item) => item.BookingTypeName?.toLowerCase() === 'takeaway' ); const DineInData = table2Data?.productDetails?.filter( (item) => item.BookingTypeName?.toLowerCase() === 'dine in' ); let PaymentStatusSuccess = PaymentStatus?.filter( (ps) => ps.PaymentStatus === 'S' ); const isEditedBill = PaymentStatus?.some(payment => { const type = payment?.AdjustmentType?.toLowerCase(); return ( (type === 'extra' || type === 'refund') && payment?.BeforeAdjustment != null && payment?.AfterAdjustment != null ); }); const lastTransaction = PaymentStatus?.find( (ps) => ps.PaymentStatus === 'S' && ps?.LastOrderTran === 'Y' ) const TakeawayTotal = TakeawayData?.reduce( (accumulator, currentValue) => accumulator + currentValue.TotalAmt, 0, ); const PackageDetails = table2Data?.PackageDtl; const DineInTotal = DineInData?.reduce( (accumulator, currentValue) => accumulator + currentValue.TotalAmt, 0, ); const aggregatedPayments = PaymentStatusSuccess?.reduce( (acc, paymentdata) => { const paymentType = paymentdata?.PaymentTypeName; const amount = Number(paymentdata?.Amount); if (acc[paymentType]) { acc[paymentType] += amount; } else { acc[paymentType] = amount; } return acc; }, {}, ); const productsData = table2Data?.productDetails || []; const offers = table2Data?.OrderOfferDetails || []; let TotalOfferAmount = 0; console.log(table2Data, 'productsDatakl'); // Calculate SalesWiseOffers total amount offers.forEach((offer) => { if (offer.TableName === 'SalesWiseOffers') { TotalOfferAmount += offer.OfferAmount; } }); const hasMappedOffer = offers.some((offer) => ['ItemWiseOffers', 'BundleOffers', 'QuantityWiseOffers'].includes( offer.TableName ) ); if (hasMappedOffer) { const productTotal = productsData?.reduce( (acc, item) => acc + (item?.Type != 'C' ? item.OfferAmt : item.OfferValue || 0), 0 ); TotalOfferAmount += productTotal; } else { const Combothere = productsData?.filter((item) => item?.Type == 'C'); const CombothereTotal = Combothere?.reduce( (acc, item) => acc + (item.OfferValue || 0), 0 ); TotalOfferAmount += CombothereTotal; } const invoiceData = { company: { name: 'Prematix Software Solution Pvt Ltd.', address: '#589, 2nd floor, VP Chambers, 1st cross, 3rd block, Koramangala, Bengaluru- 560034.', phone: '9344270900', email: 'info@prematix.com', gstin: '29AAICP0469K1ZX', }, invoice: { state: 'Karnataka', stateCode: '29', date: '13/04/2024', number: 'BLR/01/2024-25', reverseCharge: '', placeOfSupply: '', dateOfSupply: '', vehicleNumber: '', transportationMode: '', }, billTo: { name: 'Ooty Boat House', address: 'No:2, North Lake Road,', state: 'Tamil Nadu', stateCode: '33', gstin: '', poNumber: 'BLR/14/2024', poDate: '11/04/2024', }, items: [ { sr: 1, name: 'Acrylic Scanner Box', hsn: '39204900', uom: 'INR', qty: 1, rate: 6501, amount: 6501, discount: 0, taxableValue: 6501, cgstRate: 0, cgstAmount: 0, sgstRate: 0, sgstAmount: 0, igstRate: 18.0, igstAmount: 1170, totalAmount: 7671, }, { sr: 2, name: '32" Wide Angle view display FHD', hsn: '84716030', uom: 'INR', qty: 1, rate: 48317, amount: 48317, discount: 0, taxableValue: 48317, cgstRate: 0, cgstAmount: 0, sgstRate: 0, sgstAmount: 0, igstRate: 18.0, igstAmount: 8697, totalAmount: 57014, }, { sr: 3, name: 'Service charges', hsn: '999630', uom: 'INR', qty: 1, rate: 25000, amount: 25000, discount: 0, taxableValue: 25000, cgstRate: 0, cgstAmount: 0, sgstRate: 0, sgstAmount: 0, igstRate: 18.0, igstAmount: 4500, totalAmount: 29500, }, ], totals: { beforeTax: 83660, igst: 15059, sgst: 0, cgst: 0, totalGst: 15059, afterTax: 98719, amountInWords: 'Ninety Eight Thousand Seven Hundred and Nineteen Rupees Only', }, bankDetails: { bankName: 'State Bank of India', accountNo: '34850253701', ifscCode: 'SBIN0006242', branchName: 'Mookandapalli', }, }; const chunkSize = isMobile ? 11 : PageSize == 'A5' ? 8 : 9; let dataSource = []; if (GlobaldummyData || TakeawayData?.length > 0) { dataSource = GlobaldummyData ? '' : TakeawayData; } else if (DineInData?.length > 0) { dataSource = DineInData; } 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' ? 4 : 6); console.log(table2Data, 'table2Datah'); const companyName = table2Data?.CompName; const companyAddress = table2Data?.AddressDetails?.[0]?.Address1 + (table2Data?.AddressDetails?.[0]?.Address2 || '') || '#589, 2nd floor, VP Chambers, 1st cross, 3rd block, Koramangala, Bengaluru- 560034.'; const companyPhone = table2Data?.BrMobile + ',' + table2Data?.BrMobile2 !== null ? table2Data?.BrMobile2 : ''; const companyEmail = table2Data?.CompanyEmail || 'info@prematix.com'; const companyGSTIN = table2Data?.CompGSTIN; // Billing Address (replace static values) const billToName = table2Data?.CustomerName || 'Ooty Boat House'; const billToAddress = table2Data?.CustomerAddress || 'No:2, North Lake Road,'; const billToState = table2Data?.CustomerState || 'Tamil Nadu'; const billToStateCode = table2Data?.CustomerStateCode || '33'; const billToGSTIN = table2Data?.CustomerGSTIN || ''; 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)}
{companyAddress}
{(companyPhone || GlobaldummyData) && (| S.No | ) : SLNO == true && (S.No | )} {GlobaldummyData ? GlobalItem && (Item | ) : Item == true && (Item | )} {GlobaldummyData ? GlobalHsnCode && (HSN | ) : HsnCode == true && (HSN{' '} | )} {GlobaldummyData ? GlobalQuantity && (Qty | ) : Quantity == true && ({' '} {WeightasKg ? 'Qty/Kg' : 'Qty'} | )} {/*UOM | UOM | */} {GlobaldummyData ? GlobalMRP && (MRP | ) : MRP == true && (MRP | )} {GlobaldummyData ? GlobalRate && (Rate | ) : Rate == true && (Rate | )} {GlobaldummyData ? GlobalDiscount && (Dis | ) : Discount == true && (Dis | )} {GlobaldummyData ? GlobalTax && (Tax % | ) : Tax && table2Data?.OrderType !== 'E' && (Tax % | )} {GlobaldummyData ? GlobalAmount && (Amount | ) : Amount == true && (Amount | )}
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {chunkIndex * chunkSize + idx + 1} | ) : SLNO == true && ({chunkIndex * chunkSize + idx + 1} | )} {GlobaldummyData ? GlobalItem && ({item?.ProdName} | ) : Item == true && (
{item?.ProdName}
{PackageDetails?.filter(
(pkg) => pkg.ProdId === item.ProdId
).length > 0 ? (
{PackageDetails?.filter(
(pkg) =>
pkg.ProdId === item.ProdId
)?.map((item, index) => (
{item.ParcelCount} PCS{' '}
{item.ParcelQty} PACK (
{item.ParcelType})
))}
) : (
({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 == true && ({item?.HSN} | )} {GlobaldummyData ? GlobalQuantity && ({item?.SalesQty} | ) : Quantity == true && ({item?.SalesQty} | )} {GlobaldummyData ? GlobalMRP && ({item?.MRP} | ) : MRP == true && ({item?.SinglePc === 'Y' ? item?.Rate : item?.MRP} | )} {GlobaldummyData ? GlobalRate && ({item?.Rate} | ) : Rate == true && ({' '} {item?.Rate} | )} {GlobaldummyData ? GlobalDiscount && ({item.discount} | ) : Discount == true && ({item?.Type != 'C' ? item?.OfferAmt || 0 : item?.OfferValue || 0} | )} {GlobaldummyData ? GlobalTax && ({item?.ProdTaxPercentage} | ) : Tax && table2Data?.OrderType !== 'E' && ({item?.ProdTaxPercentage || 0} | )} {GlobaldummyData ? GlobalAmount && ({item?.TotalAmt} | ) : Amount == true && ({item?.Type != 'C' ? item?.TotalAmt - item?.OfferAmt || 0 : item?.TotalAmt - item?.OfferValue || 0} | )}
Terms & Conditions
Terms & Conditions
Certified that the particulars given above are true and correct.
Company Name
) : !estimatePrintHeader && table2Data?.OrderType === 'E' ? ( '' ) : ({' '} "For" {companyName}
)}Authorised Signatory
{GlobaldummyData ? GlobalSignature && ((Common Seal)
Notes : 10 days Return policy
{Notestext}
{/*Terms & Conditions
Terms & Conditions
Certified that the particulars given above are true and correct.
Company Name
) : ({' '} "For" {companyName}
)}Authorised Signatory
{GlobaldummyData ? GlobalSignature && ((Common Seal)
Notes : 10 days Return policy
{Notestext}
{/*{companyAddress}
{(companyPhone || GlobaldummyData) && (| S.No | ) : SLNO == true && (S.No | )} {GlobaldummyData ? GlobalItem && (Item | ) : Item == true && (Item | )} {GlobaldummyData ? GlobalHsnCode && (HSN | ) : HsnCode == true && (HSN | )} {GlobaldummyData ? GlobalQuantity && (Qty | ) : Quantity == true && ({' '} {WeightasKg ? 'Qty/Kg' : 'Qty'} | )} {/*UOM | UOM | */} {GlobaldummyData ? GlobalMRP && (MRP | ) : MRP == true && (MRP | )} {GlobaldummyData ? GlobalRate && (Rate | ) : Rate == true && (Rate | )} {GlobaldummyData ? GlobalDiscount && (Dis | ) : Discount == true && (Dis | )} {GlobaldummyData ? GlobalTax && (Tax % | ) : Tax && table2Data?.OrderType !== 'E' && (Tax % | )} {GlobaldummyData ? GlobalAmount && (Amount | ) : Amount == true && (Amount | )} {/*Taxable | IGST | Total | */}|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Rate | Amount | ||||||||||||||||||||||
| {idx + 1} | ) : SLNO == true && ({idx + 1} | )} {GlobaldummyData ? GlobalItem && ({item?.ProdName} | ) : Item == true && (
{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 == true && ({item?.HSN} | )} {GlobaldummyData ? GlobalQuantity && ({item?.SalesQty} | ) : Quantity == true && ({item?.SalesQty} | )} {GlobaldummyData ? GlobalMRP && ({item?.MRP} | ) : MRP == true && ({item?.SinglePc === 'Y' ? item?.Rate : item?.MRP} | )} {GlobaldummyData ? GlobalRate && ({item?.Rate} | ) : Rate == true && ({' '} {item?.Rate} | )} {GlobaldummyData ? GlobalDiscount && ({item.discount} | ) : Discount == true && ({item?.Type != 'C' ? item?.OfferAmt || 0 : item?.OfferValue || 0} | )} {GlobaldummyData ? GlobalTax && ({item?.ProdTaxPercentage} | ) : Tax && table2Data?.OrderType !== 'E' && ({item?.ProdTaxPercentage || 0} | )} {GlobaldummyData ? GlobalAmount && ({item?.TotalAmt} | ) : Amount == true && ({item?.Type != 'C' ? item?.TotalAmt - item?.OfferAmt || 0 : item?.TotalAmt - item?.OfferValue || 0} | )}||||||
Extra Charges:{ExtraChargeTotal}
} */} {(TotalOfferAmount > 0 || table2Data?.OverallDisc > 0) && (Off : {( Number(TotalOfferAmount || 0) + Number(table2Data?.OverallDisc || 0) ).toFixed(2)}
)}Terms & Conditions
Terms & Conditions
Certified that the particulars given above are true and correct.
Company Name
) : ("For" {companyName}
)}Authorised Signatory
{GlobaldummyData ? GlobalSignature && ((Common Seal)
Notes : 10 days Return policy
{Notestext}
{/*