<?php
namespace Noahtech\Sistemas\InterjamaBundle\Repository;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use Noahtech\Sistemas\InterjamaBundle\Entity\McCajaMoneda;
class McCajaMonedaRepository extends EntityRepository {
public function save(McCajaMoneda $cajaMoneda) {
try {
$em = $this->getEntityManager();
$em->getConnection()->beginTransaction();
$em->persist($cajaMoneda);
$em->flush();
$em->getConnection()->commit();
return $cajaMoneda;
} catch (Exception $e) {
$em->getConnection()->rollback();
throw new \Symfony\Component\HttpKernel\Exception\HttpException(500, "Ocurrio un error con la transaccion.");
}
}
public function getAllMonedasByCaja($cajaId) {
$qb = $this->createQueryBuilder('cm');
$qb->where('cm.caja = :caja')->setParameter('caja', $cajaId);
$results = $qb->select('cm')->getQuery()->getResult();
return $results;
}
public function delete(McCajaMoneda $cajaMoneda) {
try {
$em = $this->getEntityManager();
$em->getConnection()->beginTransaction();
$em->remove($cajaMoneda);
$em->flush();
$em->getConnection()->commit();
return "Moneda eliminada con éxito";
} catch (Exception $e) {
$em->getConnection()->rollback();
throw new \Symfony\Component\HttpKernel\Exception\HttpException("Ocurrio un error con la transaccion.");
}
}
public function getByCajaAndMoneda($cajaId, $monedaId) {
$qb = $this->createQueryBuilder('cm');
$qb->where('cm.caja = :caja')->setParameter('caja', $cajaId);
$qb->andWhere('cm.moneda = :moneda')->setParameter('moneda', $monedaId);
$results = $qb->select('cm')->getQuery()->getOneOrNullResult();
return $results;
}
}