<?php

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

/**
 * Class AccessBillingRepository
 * @package AppBundle\Entity\AccessAndFunction\Repository
 */
class AccessBillingRepository extends EntityRepository
{

    public function findAccessBillingByCustomerIdAndOrganization($entity,Organization $organization)
    {

        $customerId = $entity->getCustomerId();

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

        $qb
//            ->select('ab.customerId')
            ->join('ab.access','acc')
            ->andWhere('ab.customerId=:customerid')
            ->andWhere('acc.organization=:org')
            ->setParameter(':customerid',$customerId)
            ->setParameter(':org',$organization)
            ->setMaxResults(1);

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

    }

}
