Get invoices from Mirakl API

@param DateTime $startDate
@param DateTime $endDate
@return type
195902
private function getInvoices(DateTime $startDate, DateTime $endDate)
    {
        $offset = Mirakl::MIRAKL_API_MAX_PAGINATE;

        $invoicesData = $this->mirakl->getInvoices(
            $startDate,
            $endDate
        );

        $invoices = array_merge(array(), $invoicesData['invoices']);

        $total = $invoicesData['total_count'];

        while ($total % $offset !== $total) {

            $invoicesData = $this->mirakl->getInvoices(
                $startDate,
                $endDate,
                Mirakl::MIRAKL_API_MAX_PAGINATE,
                $offset
            );

            $invoices = array_merge($invoices, $invoicesData['invoices']);

            $offset += Mirakl::MIRAKL_API_MAX_PAGINATE;
        }

        return $invoices;
    }
1305320
public function getMostVisitedPagesForPeriod($startDate, $endDate, $maxResults = 20)
    {
        $pagesData = [];

        $answer = $this->performQuery($startDate, $endDate, 'ga:pageviews', ['dimensions' => 'ga:pagePath', 'sort' => '-ga:pageviews', 'max-results' => $maxResults]);

        if (is_null($answer->rows)) {
            return new Collection([]);
        }

        foreach ($answer->rows as $pageRow) {
            $pagesData[] = ['url' => $pageRow[0], 'pageViews' => $pageRow[1]];
        }

        return new Collection($pagesData);
    }
204158
public function getVisitorsAndPageViewsForPeriod($startDate, $endDate, $groupBy = 'date')
    {
        $visitorData = [];
        $answer = $this->performQuery($startDate, $endDate, 'ga:visits,ga:pageviews', ['dimensions' => 'ga:'.$groupBy]);

        foreach ($answer->rows as $dateRow) {
            $visitorData[] = [$groupBy => Carbon::createFromFormat(($groupBy == 'yearMonth' ? 'Ym' : 'Ymd'), $dateRow[0]), 'visitors' => $dateRow[1], 'pageViews' => $dateRow[2]];
        }

        return new Collection($visitorData);
    }
451353
public function getTopBrowsersForPeriod($startDate, $endDate, $maxResults)
    {
        $browserData = [];
        $answer = $this->performQuery($startDate, $endDate, 'ga:sessions', ['dimensions' => 'ga:browser', 'sort' => '-ga:sessions']);

        if (is_null($answer->rows)) {
            return new Collection([]);
        }

        foreach ($answer->rows as $browserRow) {
            $browserData[] = ['browser' => $browserRow[0], 'sessions' => $browserRow[1]];
        }

        $browserCollection = new Collection(array_slice($browserData, 0, $maxResults - 1));

        if (count($browserData) > $maxResults) {
            $otherBrowsers = new Collection(array_slice($browserData, $maxResults - 1));
            $otherBrowsersCount = array_sum($otherBrowsers->lists('sessions'));

            $browserCollection->put(null, ['browser' => 'other', 'sessions' => $otherBrowsersCount]);
        }

        return $browserCollection;
    }
389050
public static function calculateBusinessDaysBetweenTwoDates($startDate, $endDate, $holidays = [])
    {
        // Do strtotime calculations just once
        $endDate = strtotime($endDate);
        $startDate = strtotime($startDate);

        // The total number of days between the two dates. We compute the amount of seconds and divide it to 60*60*24
        // We add one ыусщтв to include both dates in the interval
        $days = ($endDate - $startDate) / 86400 + 1;

        $no_full_weeks = floor($days / 7);
        $no_remaining_days = fmod($days, 7);

        //It will return 1 if it's Monday,.. ,7 for Sunday
        $the_first_day_of_week = date("N", $startDate);
        $the_last_day_of_week = date("N", $endDate);

        // The two can be equal in leap years when february has 29 days, the equal sign is added here
        // In the first case the whole interval is within a week, in the second case the interval falls in two weeks.
        if ($the_first_day_of_week <= $the_last_day_of_week) {
            if ($the_first_day_of_week <= 6 && 6 <= $the_last_day_of_week) {
                $no_remaining_days--;
            }
            if ($the_first_day_of_week <= 7 && 7 <= $the_last_day_of_week) {
                $no_remaining_days--;
            }
        } else {
            // Fix an edge case where the start day was a Sunday and the end day was NOT a Saturday)

            // The day of the week for start is later than the day of the week for end
            if ($the_first_day_of_week == 7) {
                // if the start date is a Sunday, then we definitely subtract 1 day
                $no_remaining_days--;

                if ($the_last_day_of_week == 6) {
                    // if the end date is a Saturday, then we subtract another day
                    $no_remaining_days--;
                }
            } else {
                // the start date was a Saturday (or earlier), and the end date was (Mon..Fri)
                // so we skip an entire weekend and subtract 2 days
                $no_remaining_days -= 2;
            }
        }

        //The amount of business days is: (number of weeks between the two dates) * (5 working days) + the remainder
        // February in none leap years gave a remainder of 0 but still calculated weekends between first and last day, this is one way to fix it
        $workingDays = $no_full_weeks * 5;
        if ($no_remaining_days > 0) {
            $workingDays += $no_remaining_days;
        }

        //We subtract the holidays
        foreach ($holidays as $holiday) {
            $time_stamp = strtotime($holiday);
            // If the holiday doesn't fall in weekend
            if ($startDate <= $time_stamp && $time_stamp <= $endDate && date("N", $time_stamp) != 6 && date("N", $time_stamp) != 7) {
                $workingDays--;
            }
        }

        return $workingDays;
    }
1313423
public static function initDatetimesInRange($start_datetime, $end_datetime, $hoursDifference = 1){
        $dates_in_range = [];
        $begin = new DateTime($start_datetime);
        $end = new DateTime($end_datetime);
        $endModify = $end->modify( '+'.$hoursDifference.' hour' ); 

        $interval = new DateInterval('PT'.$hoursDifference.'H');
        $daterange = new DatePeriod($begin, $interval ,$endModify);

        foreach($daterange as $date){
            $dates_in_range[$date->getTimestamp()] = $date->format("Y-m-d H:i:s");
        }
        return $dates_in_range;
    }
728225
public function getRouteCalendars($externalCoverageId, $externalRouteId, \DateTime $startDate, \DateTime $endDate)
    {
        $query = array(
            'api' => 'coverage',
            'parameters' => array(
                'region' => $externalCoverageId,
                'action' => 'calendars',
                'path_filter' => 'routes/'.$externalRouteId,
                'parameters' => '?start_date='.$startDate->format($this->dateFormat).'&end_date='.$endDate->format($this->dateFormat),
            ),
        );

        return $this->navitia_component->call($query);
    }
508476
public static LinkedHashSet<String> yearAndQuarter(Date startDate, Date endDate) {
		if (startDate == null || endDate == null) {
			return new LinkedHashSet<String>(0);
		}
		return yearAndQuarter(startDate.getTime(), endDate.getTime());
	}
705698
public function getCalendarsForRoute($externalCoverageId, $externalRouteId, \DateTime $startDate, \DateTime $endDate)
    {
        $calendarsData = $this->navitia->getRouteCalendars($externalCoverageId, $externalRouteId, $startDate, $endDate);
        $calendarsSorted = array();
        if (isset($calendarsData->calendars) && !empty($calendarsData->calendars)) {
            foreach ($calendarsData->calendars as $calendar) {
                //make it easier for template
                $calendarsSorted[$calendar->id] = $calendar;
            }
        }

        return $calendarsSorted;
    }
86600
public function listTransactions($startDate, $endDate, $filterBy = null)
    {
        $this->_filterBy = $filterBy;
        date_default_timezone_set("UTC");
        $dateFormat = 'Y-m-d\TH:i:s.00\Z';
        $current = new DateTime();
        $currentTime = $current->format($dateFormat);

        HpsInputValidation::checkDateNotFuture($startDate);
        HpsInputValidation::checkDateNotFuture($endDate);

        $xml = new DOMDocument();
        $hpsTransaction = $xml->createElement('hps:Transaction');
        $hpsReportActivity = $xml->createElement('hps:ReportActivity');
        $hpsReportActivity->appendChild($xml->createElement('hps:RptStartUtcDT', $startDate));
        $hpsReportActivity->appendChild($xml->createElement('hps:RptEndUtcDT', $endDate));
        $hpsTransaction->appendChild($hpsReportActivity);

        return $this->_submitTransaction($hpsTransaction, 'ReportActivity');
    }
898504
public static function getFacilityCheckIns($memberId, $startDate, $endDate) {
    return \Drupal::entityQuery('openy_campaign_member_checkin')
      ->condition('member', $memberId)
      ->condition('date', $startDate->format('U'), '>=')
      ->condition('date', $endDate->format('U'), '<')
      ->execute();
  }
938986
public function getByRangeUserId( $startDate, $endDate, $userId ) {

		$modelClass	= static::$modelClass;
		$modelTable	= $this->getModelTable();

		$conditions = [ "$modelTable.scheduledAt BETWEEN '$startDate' AND '$endDate'", 'userId' => $userId ];

		$query = $modelClass::queryWithUser( [ 'conditions' => $conditions ] );

		return $query->all();
	}
915153
public function getHoursLoggedFor($startDate, $endDate, $project = null, $branches = null)
    {
        $response = $this->summaries($startDate, $endDate, $project, $branches);

        return $this->calculateHoursLogged($response);
    }
984215
public static long getMinutesDifference(Date startDate, Date endDate) {
		long startTime = startDate.getTime();
		long endTime = endDate.getTime();
		long diffTime = endTime - startTime;
		long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(diffTime);
		return diffInMinutes;
	}
835808
public function getrecord($endtime, $pageindex, $pagesize, $starttime)
    {
        $recond_array = [
            'endtime'   => $endtime,
            'pageindex' => $pageindex,
            'pagesize'  => $pagesize,
            'starttime' => $starttime,
        ];

        $this->apitype = 'customservice';

        $this->module = 'msgrecord';

        $res = $this->_post('getrecord', $recond_array);

        return $res;
    }
632859
protected function processOptimalSubperiods($startDate, $endDate)
    {
        while ($startDate->isEarlier($endDate)
            || $startDate == $endDate) {
            $endOfPeriod = null;

            $month        = new Month($startDate);
            $endOfMonth   = $month->getDateEnd();
            $startOfMonth = $month->getDateStart();

            $year        = new Year($startDate);
            $endOfYear   = $year->getDateEnd();
            $startOfYear = $year->getDateStart();

            if ($startDate == $startOfYear
                && ($endOfYear->isEarlier($endDate)
                    || $endOfYear == $endDate
                    || $endOfYear->isLater($this->today)
                )
                // We don't use the year if
                // the end day is in this year, is before today, and year not finished
                && !($endDate->isEarlier($this->today)
                    && $this->today->toString('Y') == $endOfYear->toString('Y')
                    && $this->today->compareYear($endOfYear) == 0)
            ) {
                $this->addSubperiod($year);
                $endOfPeriod = $endOfYear;
            } elseif ($startDate == $startOfMonth
                && ($endOfMonth->isEarlier($endDate)
                    || $endOfMonth == $endDate
                    || $endOfMonth->isLater($this->today)
                )
                // We don't use the month if
                // the end day is in this month, is before today, and month not finished
                && !($endDate->isEarlier($this->today)
                    && $this->today->toString('Y') == $endOfMonth->toString('Y')
                    && $this->today->compareMonth($endOfMonth) == 0)
            ) {
                $this->addSubperiod($month);
                $endOfPeriod = $endOfMonth;
            } else {
                // From start date,
                //  Process end of week
                $week        = new Week($startDate);
                $startOfWeek = $week->getDateStart();
                $endOfWeek   = $week->getDateEnd();

                $firstDayNextMonth      = $startDate->addPeriod(2, 'month')->setDay(1);
                $useMonthsNextIteration = $firstDayNextMonth->isEarlier($endDate);

                if ($useMonthsNextIteration
                    && $endOfWeek->isLater($endOfMonth)
                ) {
                    $this->fillArraySubPeriods($startDate, $endOfMonth, 'day');
                    $endOfPeriod = $endOfMonth;
                } //   If end of this week is later than end date, we use days
                elseif ($this->isEndOfWeekLaterThanEndDate($endDate, $endOfWeek) &&
                    ($endOfWeek->isEarlier($this->today)
                        || $startOfWeek->toString() != $startDate->toString()
                        || $endDate->isEarlier($this->today))
                ) {
                    $this->fillArraySubPeriods($startDate, $endDate, 'day');
                    break 1;
                } elseif ($startOfWeek->isEarlier($startDate)
                    && $endOfWeek->isEarlier($this->today)
                ) {
                    $this->fillArraySubPeriods($startDate, $endOfWeek, 'day');
                    $endOfPeriod = $endOfWeek;
                } else {
                    $this->addSubperiod($week);
                    $endOfPeriod = $endOfWeek;
                }
            }
            $startDate = $endOfPeriod->addDay(1);
        }
    }
220070
public function getUserSummary($beginDate = '',$endDate = ''){
        if(strtotime($beginDate) > strtotime($endDate)){
            return false;
        }
        $date = date('Y-m-d',strtotime('+6 day',strtotime($beginDate)));
        if(strtotime($endDate) > strtotime($date)){
            $endDate = $date;
        }
        $url = $this->apiUrl.'/datacube/getusersummary?access_token='.$this->getAccessToken();
        $data = '{
            "begin_date" : "'.$beginDate.'",
            "end_date" : "'.$endDate.'"
        }';
        $result = $this->curl($url,$data);
        return $this->get($result);
    }