0

I have a react function am using to calcuate the total amount of revenue based on selected dates using react-datepicker. However, when i select the startdate and enddate am getting total of less one day. For instance if i select the period from 11th January 2023 to 17th January 2023, am getting the total for 11th January 2023 to 16th January 2023.

Revenue.js

startDate = (e) => {
    this.setState({
      startDate: e
    });
  };

  endDate = (e) => {
    this.setState({
      endDate: e
    });
  };

  getTotal = (customers) => {
    try {
      const reduced = customers?.reduce((acc, curr) => {
        const prop = curr.customerdetails._id;
        const existingTotal = acc?.[prop]?.total ?? 0;

        return {
          ...acc,
          [prop]: {
            id: prop,
            name: curr.customerdetails._id,
            total: existingTotal + curr.AmountPaid
          }
        };
      }, {});

      const total = Object.entries(reduced).reduce((acc, [key, value]) => {
        return acc + value.total;
      }, 0);
      return total;
    } catch (error) {
      console.log("error", error);
      return 0;
    }
  };

How can i improve this code inorder to get totals for the specific selected dates without missing totals from the selected dates. Thanks in advance

user20183888
  • 37
  • 1
  • 6

0 Answers0