<?php

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

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

    public function findMaxBNumberByOrganization(Organization $organization)
    {

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

        $qb->select('max(b.billNumberInteger) as billNumber')
            ->join('b.access','acc')
            ->andWhere('acc.organization=:org')
            ->orderBy('b.id', 'DESC')
            ->setParameter(':org',$organization)
            ->setMaxResults(1);

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

    }

}

?>
