<?php

namespace AppBundle\Entity\Billing\Repository;
use AppBundle\Entity\Organization\Organization;
use Doctrine\ORM\EntityRepository;

/**
 * Class  AccessIntangible
 */
class AccessIntangibleRepository extends EntityRepository
{

    public function findLicensesAccessIntangible(Organization $organization)
    {


        $qb = $this->createQueryBuilder('a');

        $qb->innerJoin('AppBundle:Product\Intangible', 'i', 'WITH', 'a.intangible = i.id')
            ->innerJoin('AppBundle:AccessAndFunction\Access', 'acc', 'WITH', 'a.access = acc.id')
            ->where('i.label LIKE :licence')
            ->andWhere('a.endDate IS NULL')
            ->andWhere('acc.organization=:org')
            ->setParameter(':org',$organization)
            ->setParameter('licence', '%licence%');

        return $qb->getQuery()->getResult();

    }

    public function getArchivedAccessIntangible($enDate, $organizationId)
    {
        $filter = $this->_em->getFilters()->enable('activity_year');
        $filter->setParameter('disabledFilter', 1);
        $qb = $this->createQueryBuilder('access_intangible');

        $qb
            ->innerJoin('access_intangible.access', 'access')
            ->innerJoin('access.organization', 'organization')
            ->andWhere('access_intangible.endDate = :enDate')
            ->andWhere('organization.id = :id')
            ->setParameter('id', $organizationId)
            ->setParameter('enDate', $enDate)
        ;

        $filter->setParameter('disabledFilter', 0);
        return $qb->getQuery()->getResult();
    }

}

?>
