Get periods

@return array
An array of arrays as follows: array( array('id' => $id0, 'month' => $month0, 'startDate'=>$startDate0, 'endDate'=>$endDate0), array('id' => $id1, 'month' => $month1, 'startDate'=>$startDate1, 'endDate'=>$endDate1),…)
760603
public function getPeriods()
  {
    $periods = array();

    $this->Period->byOrganization($this->AuthenticationManager->getCurrentUserOrganizationId())->each(function($Period) use (&$periods)
    {
      array_push($periods, array('id'=> $Period->id, 'month' => $this->Lang->get('decima-accounting::period-management.' . $Period->month), 'startDate'=>$Period->start_date, 'endDate'=>$Period->end_date));
    });

    return $periods;
  }
815614
public function period($time) {
		$Dates = array();
		$NextDate = $this->start();
		while ($NextDate <= $this->_endDate) {
			$Dates[] = clone $NextDate;
			$NextDate->modify("+$time");
		}
		return new ArrayIterator($Dates);
	}
665963
private function getResumenPeriodo()
    {
        $resumen = [];
        foreach ($this->detalles as &$d) {
            // si el tipo de boleta no está en el resumen se crea
            if (!isset($resumen[$d['TpoDoc']])) {
                $resumen[$d['TpoDoc']] = [
                    'TpoDoc' => $d['TpoDoc'],
                    'TotAnulado' => false,
                    'TotalesServicio' => [],
                ];
            }
            // si no existe el tipo de servicio se agrega
            if (!isset($resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']])) {
                $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']] = [
                    'TpoServ' => $d['TpoServ'],
                    'PeriodoDevengado' => false,
                    'TotDoc' => false,
                    'TotMntExe' => false,
                    'TotMntNeto' => 0,
                    'TasaIVA' => 0,
                    'TotMntIVA' => 0,
                    'TotMntTotal' => false,
                    'TotMntNoFact' => false,
                    'TotMntPeriodo' => false,
                    'TotSaldoAnt' => false,
                    'TotVlrPagar' => false,
                    'TotTicket' => false,
                ];
            }
            // agregar detalle al resumen
            if (empty($d['Anulado'])) {
                // contabilizar documento
                $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotDoc'] += 1;
                // ir sumando valores
                $vals = ['MntExe'=>'TotMntExe', 'MntTotal'=>'TotMntTotal', 'MntNoFact'=>'TotMntNoFact', 'MntPeriodo'=>'TotMntPeriodo', 'SaldoAnt'=>'TotSaldoAnt', 'VlrPagar'=>'TotVlrPagar', 'TotTicketBoleta'=>'TotTicket'];
                foreach ($vals as $ori => $des) {
                    if ($d[$ori]) {
                        $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']][$des] += $d[$ori];
                    }
                }
                // determinar neto e iva
                $tasa = \sasco\LibreDTE\Sii::getIVA();
                $neto = round(($d['MntTotal'] - $d['MntExe']) / (1 + $tasa/100));
                if ($neto) {
                    $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntNeto'] += $neto;
                    $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TasaIVA'] = $tasa;
                    // WARNING: problema por aproximaciones al calcular el NETO e IVA a partir del BRUTO
                    //$resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntIVA'] = round($resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntNeto'] * ($tasa/100));
                    $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntIVA'] = $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntTotal'] - $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntExe'] - $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntNeto'];
                }
            }
            // documento anulado
            else if ($d['Anulado']=='A') {
                $resumen[$d['TpoDoc']]['TotAnulado'] += 1;
            }
        }
        // armar resumen verdadero
        $ResumenPeriodo = ['TotalesPeriodo'=>[]];
        foreach ($resumen as $r) {
            $ResumenPeriodo['TotalesPeriodo'][] = $r;
        }
        // entregar resumen
        return $ResumenPeriodo;
    }
588566
public function monthlyPerfomance($period = 2)
    {
        $categories = Category::all();
        foreach ($categories as $cat) {
            $records['categories'][] = $cat->name;
        }

        for ($m = $period; $m >= 0; $m--) {
            $from = Carbon::now();
            $from->day = 1;
            $from->subMonth($m);
            $to = Carbon::now();
            $to->day = 1;
            $to->subMonth($m);
            $to->endOfMonth();
            $records['interval'][$from->format('F Y')] = [];
            foreach ($categories as $cat) {
                $records['interval'][$from->format('F Y')][] = round($this->intervalPerformance($from, $to, $cat->id), 1);
            }
        }

        return $records;
    }
1325788
protected function parsePeriodFromDates($period)
    {
        if (substr_count($period, '-') != 1) {
            throw new Exception("Expecting 'date1-date2' syntax");
        }

        $result = [
            'min' => null,
            'max' => null,
        ];

        list($result['min'], $result['max']) = explode('-', $period);

        foreach ($result as $key => $value) {
            if (!$value) {
                $result[$key] = null;
                continue;
            }

            $result[$key] = new DateTime($value, $this->getTimezoneFrom());
        }

        return $result;
    }
325026
public static function getAll() : array
    {
        $months = [];

        for ($month = Month::JANUARY; $month <= Month::DECEMBER; $month++) {
            $months[] = Month::get($month);
        }

        return $months;
    }
704718
private function getFromTo(): array
    {
        if ($this->count < $this->perPage || $this->perPage === null) {
            $start = 1;
            $end = $this->count;
        } else {
            if ($this->hasMorePages()) {
                $end = $this->perPage * $this->currentPage;
                $start = ($end - $this->perPage) + 1;
            } else {
                $endTest = $this->perPage * $this->currentPage;
                $start = ($endTest - $this->perPage) + 1;

                $end = $start + $this->getCountOnLastPage();
            }
        }

        return ['from' => $start, 'to' => $end];
    }
216451
public function getDateRange()
    {
        $fields = $this->getFields();
        if (!empty($this->start) && empty($this->end)) {
            return 'since ' . $fields['start']->formattedValue;
        } elseif (empty($this->start) && !empty($this->end)) {
            return 'until ' . $fields['end']->formattedValue;
        } else {
            return implode(' – ', [$fields['start']->formattedValue, $fields['end']->formattedValue]);
        }
    }
78318
protected function getMonths()
    {
        $intSecondsPerMonth = ($this->isPositive()) ? DateTimeSpan::SECONDS_PER_MONTH : ((-1) * DateTimeSpan::SECONDS_PER_MONTH);
        $intMonths = floor($this->intSeconds / $intSecondsPerMonth);
        if ($this->isNegative()) {
            $intMonths = (-1) * $intMonths;
        }
        return $intMonths;
    }
474193
public static function rangeLastMonth()
    {
        $lastMonth = date('m') - 1;
        if ($lastMonth <= 0) {
            $lastMonth = 12;
        }
        $lastMonth = date('Y') . '-' . $lastMonth . '-01';

        return [self::toTs($lastMonth), self::toTs($lastMonth) + (86400 * (date('t', strtotime($lastMonth))-1))];
    }
1275912
public function toArray()
    {
        return array(
            'year' => $this->y,
            'month' => $this->m,
            'day' => $this->d,
            'hour' => $this->h,
            'minute' => $this->i,
            'second' => $this->s,
        );
    }
312823
public function getTimeperiod()
    {
        foreach (array_keys(self::$time_periods) as $time_period) {
            if (!is_null($this->spans($time_period))) {
                return $time_period;
            }
        }

        return;
    }
680915
private function analyticsDuration()
    {
        $start = input('start', date('Y-m-d', strtotime('-29 days')));
        $end = input('end', date('Y-m-d'));

        if (is_string($start)) {
            $start = \DateTime::createFromFormat('Y-m-d', $start);
        }

        if (is_string($end)) {
            $end = \DateTime::createFromFormat('Y-m-d', $end);
        }

        return Period::create($start, $end);
    }
653585
public function getDays()
    {
        $days = array();
        foreach ($this->getDatePeriod() as $date) {
            $days[] = $this->getFactory()->createDay($date);
        }

        return $days;
    }
50703
public function getDates()
    {
        static $dates = [];

        $class = get_class($this);

        if (! isset($dates[$class])) {
            static::$dispatcher->dispatch(
                new ConfigureModelDates($this, $this->dates)
            );

            $dates[$class] = $this->dates;
        }

        return $dates[$class];
    }
367904
public function getMonths() {
        $months = array();
        for ($i = 1; $i <= 12; $i++) {
            if ($i < 10)
                $months[$i] = '0' . $i;
            else
                $months[$i] = $i;
        }
        return $months;
    }
209099
public function getPeriodLabel()
	{
		$contexts = $this->contexts; // Protect the contexts
		try
		{
			// If there are only instant context and all the contexts have the same date...
			if ( ! $this->DurationContexts()->count() && count( $this->AllYears() ) == 1 )
			{
				$context = reset( $this->contexts );
				return $context['period']['endDate'];
			}
			else
			{
				$this->sortByStartDate();
				$startContext = reset( $this->contexts );
				$this->sortByEndDate();
				$endContext = end( $this->contexts );
				return "{$startContext['period']['startDate']} - {$endContext['period']['endDate']}";
			}
		}
		finally
		{
			$this->contexts = $contexts; // Restore
		}
	}