code: private function findRevenues($type, \DateTime $from, \DateTime $to = null, $detailed = false)
      {
          if ($type === OrderStat::TYPE_DAY) {
              if (null === $to) {
                  $from = (clone $from)->modify('first day of this month');
                  $to = (clone $from)->modify('last day of this month');
              }
              $interval = new \DateInterval('P1D');
              $format = 'Y-m-d';
          } elseif ($type === OrderStat::TYPE_MONTH) {
              if (null === $to) {
                  $from = (clone $from)->modify('first day of january ' . $from->format('Y'));
                  $to = (clone $from)->modify('last day of december ' . $from->format('Y'));
              }
              $interval = new \DateInterval('P1M');
              $format = 'Y-m';
          } else {
              throw new InvalidArgumentException("Unexpected order stat type.");
          }
  
          $result = $this
              ->getRevenueQuery()
              ->setParameters([
                  'type' => $type,
                  'from' => $from->format($format),
                  'to'   => $to->format($format),
              ])
              ->getScalarResult();
  
          $data = $this->buildRevenueData($result, $detailed);
  
          $period = new \DatePeriod($from, $interval, $to);
  
          $defaults = $detailed ? [] : 0;
          if ($detailed) {
              foreach (SaleSources::getSources() as $source) {
                  $defaults[$source] = 0;
              }
          }
  
          /** @var \DateTime $d */
          foreach ($period as $d) {
              $index = $d->format($format);
              if (!isset($data[$index])) {
                  $data[$index] = $defaults;
              };
          }
          ksort($data);
  
          return $data;
      }
docs: Finds revenues.
  
  @param int            $type
  @param \DateTime      $from
  @param \DateTime|null $to
  @param bool           $detailed
  
  @return array