Using react How to show the invoices based on currency.

From one component to another component using the react we can use the props filter to get the filtered table values using this Methode we show the invoices based on the currency.

useEffect(() => {
        const fetchOpenInvoices = async () => {
            try {
                if (!selectedCustomerCode) return; // Check if selectedCustomerCode is null or undefined
                const filter = doc(firestore, "customer", selectedCustomerCode.setSelectedCustomerCode);
                const dataCollection = query(collection(firestore, "invoice"), where("cu_id", "==", filter));
                const querySnapshot = await getDocs(dataCollection);
                const invoices = querySnapshot.docs.filter(doc => doc.data().currency === selectedCurrency).map(doc => {
                    const invoiceId = doc.id;
                    const appliedAmountForInvoice = appliedAmount.find(item => item.invoiceId === invoiceId);
                    return {
                    id: doc.id,
                    invoiceNo: doc.data().invoice_number,
                    date: doc.data().sales_effective_date,
                    amount: doc.data().total,
                    dueDate: doc.data().sales_effective_date,
                    amountDue: doc.data().amount_due,
                    currency: doc.data().currency,
                    amountApplied: appliedAmountForInvoice ? appliedAmountForInvoice.appliedAmount : '',
                    salesRepName: doc.data().salesRep
                }});
                const filteredInvoices = invoices.filter(invoice => invoice.currency === selectedCurrency);
                // console.log('Test-Rohit filteredInvoices', filteredInvoices);
                setOpenInvoices(invoices);
            } catch (error) {
                setOpenInvoices([]);
                console.error('Error fetching open invoices:', error);
            }
        };


        fetchOpenInvoices();
    }, [selectedCustomerCode, selectedInvoicesId, cashAmt, cardAmt, chequeAmt, gtyChqAmt]);

Leave a comment

Your email address will not be published. Required fields are marked *