Get unmatched payments within given days and direction

@param int    $daysBack Maximum age of payment
@param string $direction Incoming or outcoming payents in|out

@return array
321418
public function getPaymentsToProcess($daysBack = 1, $direction = 'in')
    {
        $result                                  = [];
        $this->banker->defaultUrlParams['order'] = 'datVyst@A';
        $payments                                = $this->banker->getColumnsFromFlexibee([
            'id',
            'kod',
            'varSym',
            'specSym',
            'sumCelkem',
            'buc',
            'smerKod',
            'mena',
            'datVyst'],
            ["sparovano eq false AND typPohybuK eq '".(($direction == 'out') ? 'typPohybu.vydej'
                : 'typPohybu.prijem' )."' AND storno eq false ".
            (is_null($daysBack) ? '' :
            "AND datVyst eq '".\FlexiPeeHP\FlexiBeeRW::timestampToFlexiDate(mktime(0,
                    0, 0, date("m"), date("d") - $daysBack, date("Y")))."' ")
            ], 'id');

        if ($this->banker->lastResponseCode == 200) {
            if (empty($payments)) {
                $result = [];
            } else {
                $result = $payments;
            }
        }
        return $result;
    }
615024
public function getUnspentOutputs($addresses, $confirmations=0, $limit=250) {
        if(!is_array($addresses))
            throw new FormatError('Must pass array argument.');

        $params = array(
            'format'=>'json',
            'limit'=>intval($limit),
            'confirmations'=>intval($confirmations),
            'active'=>implode('|', $addresses)
        );
        $json = $this->blockchain->get('unspent', $params);
        $outputs = Array();
        if(array_key_exists('unspent_outputs', $json)) {
            foreach ($json['unspent_outputs'] as $output) {
                $outputs[] = new UnspentOutput($output);
            }
        }
        return $outputs;
    }
481594
public static function getPreviousMonths($target, $withCurrent = true)
    {
        return self::getMonthSequence(array_keys(self::getMonths()), $target, $withCurrent);
    }
131551
protected function getGeoArea($days = 7, $maxResult = 100, $countryId = 225)
    {
        list($startDate, $endDate) = $this->calculateDays($days);

        $this->getGeoAreaForPeriod($startDate, $endDate, $maxResult,
            $countryId);
    }
267547
private function calculateNumberOfDays($numberOfDays)
    {
        $endDate = Carbon::today();
        $startDate = Carbon::today()->subDays($numberOfDays);

        return [$startDate, $endDate];
    }
724983
public function getMigrationsToExecute($direction, $to)
    {
        $result = parent::getMigrationsToExecute($direction, $to);
        $forcedInitialMigration = $this->getForcedInitialMigration();
        if ($forcedInitialMigration !== null && $direction === Version::DIRECTION_UP) {
            $allMigrations = $this->getMigrations();
            $allMigrationKeys = array_keys($allMigrations);
            $forcedInitialMigrationIndex = array_search($forcedInitialMigration->getVersion(), $allMigrationKeys, false);
            if ($forcedInitialMigrationIndex === false) {
                // This should never occur
                throw new Exception(t('Unable to find the forced migration with version %s', $forcedInitialMigration->getVersion()));
            }
            $forcedMigrationKeys = array_slice($allMigrationKeys, $forcedInitialMigrationIndex);
            $forcedMigrations = [];
            foreach (array_reverse($forcedMigrationKeys) as $forcedMigrationKey) {
                $migration = $allMigrations[$forcedMigrationKey];
                if ($migration->isMigrated() && !$migration->getMigration() instanceof RepeatableMigrationInterface) {
                    throw new Exception(t('The migration %s has already been executed, and can\'t be executed again.', $migration->getVersion()));
                }
                $forcedMigrations[$forcedMigrationKey] = $migration;
            }
            $forcedMigrations = array_reverse($forcedMigrations, true);
            $missingMigrations = array_diff_key($result, $forcedMigrations);
            if (count($missingMigrations) > 0) {
                throw new Exception(t('The forced migration is later than the one to be executed (%s)', reset($missingMigrations)->getVersion()));
            }
            $result = $forcedMigrations;
        }

        return $result;
    }
577098
private static function getNearestWeekday($currentYear, $currentMonth, $targetDay)
    {
        $tday = str_pad($targetDay, 2, '0', STR_PAD_LEFT);
        $target = DateTime::createFromFormat('Y-m-d', "$currentYear-$currentMonth-$tday");
        $currentWeekday = (int) $target->format('N');

        if ($currentWeekday < 6) {
            return $target;
        }

        $lastDayOfMonth = $target->format('t');

        foreach (array(-1, 1, -2, 2) as $i) {
            $adjusted = $targetDay + $i;
            if ($adjusted > 0 && $adjusted <= $lastDayOfMonth) {
                $target->setDate($currentYear, $currentMonth, $adjusted);
                if ($target->format('N') < 6 && $target->format('m') == $currentMonth) {
                    return $target;
                }
            }
        }
    }
268918
public function getStatisticData($lastDays = 10)
    {
        $dateTime = DateTimer::getDateTime4TimeStamp(strtotime('-' . $lastDays - 1 . ' days'));

        $numberList = $this->getStatisticDataNumberList($dateTime);
        $result = [];

        if ($this->defaultValues) {
            // set some default values
            $range = DateTimer::getDateRange4Period($dateTime, new DateTime());
            foreach ($range as $date) {
                $result[$date->format($this->format)] = 0;
            }
        }

        if ($numberList) {
            foreach ($numberList as $numberData) {
                /** @var DateTime $date */
                $date = $numberData['created'];
                $dateFormat = $date->format($this->format);

                if (!isset($result[$dateFormat])) {
                    $result[$dateFormat] = 0;
                }

                $result[$dateFormat] += $numberData['amount'];
            }
        }

        return $result;
    }
1243154
public function getFileErrors($order = 'error.counter', $direction = 'DESC')
    {
        $this->getAll(true);

        /** @var QueryBuilder $qb */
        $qb = $this->qb;

        return $qb
            ->andWhere('error.type = :type')
            ->setParameter('type', HttpError::TYPE_FILE)
            ->orderBy($order, $direction);
    }
103850
protected function getMigrationsForRollback(array $options)
    {
        if (($steps = $options['step'] ?? 0) > 0) {
            return $this->repository->getMigrations($steps);
        }

        return $this->repository->getLast();
    }
1082162
private function ageBetweenSiblingsQuery(int $total): array
    {
        $prefix = DB::connection()->getTablePrefix();

        return DB::table('link AS link1')
            ->join('link AS link2', static function (JoinClause $join): void {
                $join
                    ->on('link2.l_from', '=', 'link1.l_from')
                    ->on('link2.l_type', '=', 'link1.l_type')
                    ->on('link2.l_file', '=', 'link1.l_file');
            })
            ->join('dates AS child1', static function (JoinClause $join): void {
                $join
                    ->on('child1.d_gid', '=', 'link1.l_to')
                    ->on('child1.d_file', '=', 'link1.l_file')
                    ->where('child1.d_fact', '=', 'BIRT')
                    ->where('child1.d_julianday1', '<>', 0);
            })
            ->join('dates AS child2', static function (JoinClause $join): void {
                $join
                    ->on('child2.d_gid', '=', 'link2.l_to')
                    ->on('child2.d_file', '=', 'link2.l_file')
                    ->where('child2.d_fact', '=', 'BIRT')
                    ->whereColumn('child2.d_julianday2', '>', 'child1.d_julianday1');
            })
            ->where('link1.l_type', '=', 'CHIL')
            ->where('link1.l_file', '=', $this->tree->id())
            ->distinct()
            ->select(['link1.l_from AS family', 'link1.l_to AS ch1', 'link2.l_to AS ch2', DB::raw($prefix . 'child2.d_julianday2 - ' . $prefix . 'child1.d_julianday1 AS age')])
            ->orderBy('age', 'DESC')
            ->take($total)
            ->get()
            ->all();
    }
1108976
public function changeOrdering($direction)
    {
        $allowedDirections = array('asc', 'desc');
        $direction = strtolower($direction);
        $isInArray = in_array($direction, $allowedDirections, true);
        if (!empty($direction) && $isInArray) {
            if ($direction == 'asc') {
                $direction = 'desc';
            } else {
                $direction = 'asc';
            }
        }
        return $direction;
    }
181596
private function getNeighbor(Date $slugDate, $direction = 'next')
    {
        if (strcasecmp($direction, 'next') == 0) {
            $activeDate = 'ActiveDate.after';
            $orderBy = 'ActiveDate ASC';
            $slugDate = $slugDate->modify('+1 minute');
        } else {
            $activeDate = 'ActiveDate.before';
            $orderBy = 'ActiveDate DESC';
            $slugDate = $slugDate->modify('-1 minute');
        }

        $nq = new NodeQuery();
        $this->passthruTemplateVariable($nq, 'Elements.in');
        $this->passthruTemplateVariable($nq, 'OutTags.exist');
        $this->passthruTemplateVariable($nq, 'Meta.select');
        $this->passthruTemplateVariable($nq, 'OutTags.select');
        $this->passthruTemplateVariable($nq, 'InTags.select');
        $this->setMetaWhereParams($nq);
        $nq->setParameter($activeDate, $slugDate);
        $nq->setParameter('Status.isActive', true);
        $nq->setLimit(1);
        $nq->isRetrieveTotalRecords(false);
        $nq->setOrderBy($orderBy);

        return $this->RegulatedNodeService->findAll($nq)->getResults();
    }
1127716
static public function overdueDays($dueDate)
    {
        $dateDiff = date_diff(is_object($dueDate) ? $dueDate : FlexiBeeRO::flexiDateToDateTime($dueDate),
            new \DateTime());
        if ($dateDiff->invert == 1) {
            $ddif = $dateDiff->days * -1;
        } else {
            $ddif = $dateDiff->days;
        }

        return $ddif;
    }
581196
private function ageBetweenSiblingsNoList(int $total): array
    {
        $rows = $this->ageBetweenSiblingsQuery($total);

        foreach ($rows as $fam) {
            $family = Family::getInstance($fam->family, $this->tree);
            $child1 = Individual::getInstance($fam->ch1, $this->tree);
            $child2 = Individual::getInstance($fam->ch2, $this->tree);

            if ($child1->canShow() && $child2->canShow()) {
                // ! Single array (no list)
                return [
                    'child1' => $child1,
                    'child2' => $child2,
                    'family' => $family,
                    'age'    => $this->calculateAge((int) $fam->age),
                ];
            }
        }

        return [];
    }
240917
public function getOrdered($direction = 'asc') : array
    {
        $modules = $this->allEnabled();

        uasort($modules, function (Module $a, Module $b) use ($direction) {
            if ($a->order == $b->order) {
                return 0;
            }

            if ($direction == 'desc') {
                return $a->order < $b->order ? 1 : -1;
            }

            return $a->order > $b->order ? 1 : -1;
        });

        return $modules;
    }
168608
public function manageMandate(PayoneManageMandateTransfer $manageMandateTransfer)
    {
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT);
        $requestContainer = $paymentMethodMapper->mapManageMandate($manageMandateTransfer);
        $this->setStandardParameter($requestContainer);

        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
        $responseContainer = new ManageMandateResponseContainer($rawResponse);

        $manageMandateTransfer->setErrorCode($responseContainer->getErrorcode());
        $manageMandateTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
        $manageMandateTransfer->setStatus($responseContainer->getStatus());
        $manageMandateTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
        $manageMandateTransfer->setMandateIdentification($responseContainer->getMandateIdentification());
        $manageMandateTransfer->setMandateText($responseContainer->getMandateText());
        $manageMandateTransfer->setIban($responseContainer->getIban());
        $manageMandateTransfer->setBic($responseContainer->getBic());

        return $manageMandateTransfer;
    }