Commit 059aeaab authored by Mat's avatar Mat
Browse files

newReference OFyymmdd01, chaque jour il doit repartir de 01

parent 558ce7e1
......@@ -19,14 +19,22 @@ class OffreAPIController extends MasterAPIController
{
$now = new \DateTime();
$today = $now->format('ymd');
$em = $this->getDoctrine()->getManager();
$num = $em->getRepository('PotageBundle:Offre')->findOneLastReference();
$num = $em->getRepository('PotageBundle:Offre')->findOneLastReference($today);
$last = intval(substr($num['reference'], -2));
$last++;
$last = sprintf("%02d", $last);
if ($num !== null)
{
$last = intval(substr($num['reference'], -2));
$last++;
$last = sprintf("%02d", $last);
}
else {
$last = '01';
}
return 'OF' . $now->format('ymd') . $last;
return 'OF' . $today . $last;
}
......
......@@ -14,13 +14,16 @@ class OffreRepository extends \Doctrine\ORM\EntityRepository
{
/**
* @param $pattern
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneLastReference()
public function findOneLastReference($pattern)
{
$qb = $this->createQueryBuilder('o')
->select('o.reference')
->where('o.reference LIKE :pattern')
->setParameter(':pattern', '%' . $pattern . '%')
->orderBy('o.reference', 'DESC')
->setMaxResults(1);
return $qb->getQuery()->getOneOrNullResult();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment