<?php

namespace AppBundle\Entity;
use Doctrine\Common\Collections\Collection;

/**
 * TravelInsurancePriceRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class TravelInsurancePriceRepository extends \Doctrine\ORM\EntityRepository
{
    /**
     * @param $insuranceId
     * @param $assessmentBasis
     *
     * @return TravelInsurancePrice|null
     */
    public function findOneByInsuranceIdAndAssessmentBasis($insuranceId, $assessmentBasis)
    {
        $qb = $this->createQueryBuilder('i');
        return $qb
            ->where($qb->expr()->eq('IDENTITY(i.insurance)', $insuranceId))
            //->where('IDENTITY(i.insurance) = '. $insuranceId)
            ->andWhere($qb->expr()->gte('i.border', $assessmentBasis))
            ->orderBy('i.border')
            ->setMaxResults(1)
            ->getQuery()
            ->getOneOrNullResult();
    }
}
