src/Entity/Carro.php line 18
- <?php
- namespace App\Entity;
- use Doctrine\Common\Collections\Collection;
- use Doctrine\ORM\Mapping as ORM;
- use Doctrine\Common\Collections\ArrayCollection;
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Component\Validator\ExecutionContext;
- use App\Entity\Pedido;
- use JMS\Serializer\Annotation as JMS;
- /**
- * Carro
- *
- * @ORM\Entity
- */
- class Carro
- {
- const TIPO_PROMO_DIVISA = 0;
- const TIPO_PROMO_CUPON = 1;
- /**
- * @var integer
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @Assert\Valid()
- * @ORM\OneToMany(targetEntity="Pedido", mappedBy="pedidos",cascade={"persist"})
- */
- private $pedidos;
- /**
- * @ORM\ManyToOne(targetEntity="User")
- * @ORM\JoinColumn(name="usuario", referencedColumnName="id", nullable=true)
- */
- private $usuario;
- /**
- * @var string
- *
- * @ORM\Column(name="codigoPromo", type="string", length=255, nullable=false)
- */
- private $codigoPromo;
- /**
- * @var string
- *
- * @ORM\Column(name="tipoPromo", type="integer", options={"default":0})
- */
- private $tipoPromo;
- /**
- * @var boolean
- *
- * @ORM\Column(name="reserva", type="boolean")
- */
- private $reserva;
- /**
- * @var Oficina
- *
- * @ORM\Column(name="tienda", type="string", length=255, nullable=true)
- */
- private $oficina;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="fechaDisponible", type="datetime", nullable=true)
- */
- private $fechaDisponible;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="fechaCompra", type="datetime", nullable=true)
- */
- private $fechaCompra = 'CURRENT_TIMESTAMP';
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="fechaEntrega", type="date", nullable=true)
- */
- private $fechaEntrega;
- // private $tipo = 0;
- /**
- * @var \Time
- *
- * @ORM\Column(name="horaEntrega", type="time", nullable=true)
- */
- private $horaEntrega;
- /**
- * @var string
- *
- * @ORM\Column(name="ciudad", type="string", length=255, nullable=false)
- */
- private $ciudad;
- /**
- * @var string
- *
- * @ORM\Column(name="provincia", type="string", length=255, nullable=true)
- */
- private $provincia;
- /**
- * @var string
- *
- * @ORM\Column(name="pais", type="string", length=255, nullable=false)
- */
- private $pais;
- /**
- * @var string
- *
- * @ORM\Column(name="direccion", type="string", length=255, nullable=false)
- */
- private $direccion;
- /**
- * @var string
- *
- * @Assert\Length(
- * min = 0,
- * max = 250,
- * maxMessage = "delivery.maxSize"
- * )
- * @ORM\Column(name="comentario", type="string", length=250, nullable=true)
- */
- private $comentario;
- /**
- * @ORM\ManyToOne(targetEntity="App\Entity\Cupon")
- * @ORM\JoinColumn(name="cupon", referencedColumnName="id", nullable=true)
- */
- private $cupon;
- /**
- * @var string
- *
- * @ORM\Column(name="tipoPago", type="string", length=255, nullable=false)
- */
- private $tipoPago = 0;
- /**
- * @ORM\ManyToOne(targetEntity="App\Entity\Invitado")
- * @ORM\JoinColumn(name="invitado", referencedColumnName="id", nullable=true)
- */
- private $invitado;
- private $terminado = 0;
- private $totalTransaccion = 0;
- private $descuentoPromo = 0;
- private $freeShipping = 0;
- private $totalEstimado = 0;
- private $codigoPostal;
- private $gastosEnvio = 0;
- /**
- * @ORM\Column(name="dni_envio", type="string", length=255, nullable=true)
- */
- protected $cardSend;
- /**
- * @ORM\Column(name="nombre_envio", type="string", length=255, nullable=true)
- */
- protected $nameSend;
- /**
- * @ORM\Column(name="titular", type="string", length=255, nullable=true)
- */
- protected $titular;
- /**
- * @var \DateTime
- * @ORM\Column(name="fecha_prevision", type="date", nullable=true)
- */
- protected $fechaPrevision;
- public function __construct()
- {
- $this->pedidos = new ArrayCollection();
- }
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set pedidos
- *
- * @param string $pedidos
- * @return Carro
- */
- public function setPedidos($pedidos)
- {
- $this->pedidos = $pedidos;
- return $this;
- }
- /**
- * Get pedidos
- *
- * @return Pedido[]|Collection
- */
- public function getPedidos()
- {
- return $this->pedidos;
- }
- /**
- * Set codigoProm
- *
- * @param float $codigoProm
- * @return Pedido
- */
- public function setCodigoPromo($codigoProm)
- {
- $this->codigoPromo = $codigoProm;
- return $this;
- }
- /**
- * Get codigoProm
- *
- * @return float
- */
- public function getCodigoPromo()
- {
- if ($this->codigoPromo === null)
- return '';
- return $this->codigoPromo;
- }
- /**
- * Get $pedido
- *
- * @return Carro
- */
- public function addPedido(Pedido $pedido)
- {
- $this->pedidos[]=$pedido;
- return $this;
- }
- /**
- * Remove pedido
- *
- * @return Carro
- */
- public function removePedido(Pedido $pedido)
- {
- $this->pedidos->removeElement($pedido);
- return $this;
- }
- /**
- * Set usuario
- *
- * @param string $usuario
- * @return Carro
- */
- public function setUsuario($usuario)
- {
- $this->usuario = $usuario;
- return $this;
- }
- /**
- * Get usuario
- *
- * @return string
- */
- public function getUsuario()
- {
- return $this->usuario;
- }
- /* public setTipo($tipo){
- $this->tipo=$tipo;
- return $this;
- }
- public getTipo(){
- return $this->tipo;
- }*/
- /**
- * Set reserva
- *
- * @param boolean $reserva
- * @return Carro
- */
- public function setReserva($reserva)
- {
- $this->reserva = $reserva;
- return $this;
- }
- /**
- * Get reserva
- *
- * @return boolean
- */
- public function getReserva()
- {
- return $this->reserva;
- }
- /**
- * Set oficina
- *
- * @param Oficina $oficina
- * @return Pedido
- */
- public function setOficina($oficina)
- {
- $this->oficina = $oficina;
- return $this;
- }
- /**
- * Get oficina
- *
- * @return Oficina
- */
- public function getOficina()
- {
- return $this->oficina;
- }
- /**
- * Set fechaDisponible
- *
- * @param \DateTime $fechaDisponible
- */
- public function setFechaDisponible($fechaDisponible)
- {
- $this->fechaDisponible = $fechaDisponible;
- return $this;
- }
- /**
- * Get fechaDisponible
- *
- * @return \DateTime
- */
- public function getFechaDisponible()
- {
- return $this->fechaDisponible;
- }
- /**
- * Set fechaCompra
- *
- * @param \DateTime $fechaCompra
- * @return Pedido
- */
- public function setFechaCompra($fechaCompra)
- {
- $this->fechaCompra = $fechaCompra;
- return $this;
- }
- /**
- * Get fechaCompra
- *
- * @return \DateTime
- */
- public function getFechaCompra()
- {
- return $this->fechaCompra;
- }
- /**
- * Set fechaEntrega
- *
- * @param \DateTime $fechaEntrega
- * @return Pedido
- */
- public function setFechaEntrega($fechaEntrega)
- {
- $this->fechaEntrega = $fechaEntrega;
- return $this;
- }
- /**
- * Get fechaEntrega
- *
- * @return \DateTime
- */
- public function getFechaEntrega()
- {
- return $this->fechaEntrega;
- }
- /**
- * Set horaEntrega
- *
- * @param \DateTime $horaEntrega
- * @return Pedido
- */
- public function setHoraEntrega($horaEntrega)
- {
- if(gettype($horaEntrega)=='string'){
- $this->horaEntrega = new \Datetime($horaEntrega);
- }
- else{
- $this->horaEntrega = $horaEntrega;
- }
- return $this;
- }
- /**
- * Get tipoPago
- *
- * @return \string
- */
- public function getTipoPago()
- {
- return $this->tipoPago;
- }
- /**
- * Set tipoPago
- *
- * @param \string $tipoPago
- * @return Pedido
- */
- public function setTipoPago($tipoPago)
- {
- $this->tipoPago = $tipoPago;
- return $this;
- }
- /**
- * Get horaEntrega
- *
- * @return \DateTime
- */
- public function getHoraEntrega()
- {
- return $this->horaEntrega;
- }
- /**
- * Set direccion
- *
- * @param string $direccion
- * @return Pedido
- */
- public function setDireccion($direccion)
- {
- $this->direccion = $direccion;
- return $this;
- }
- /**
- * Get direccion
- *
- * @return string
- */
- public function getDireccion()
- {
- return $this->direccion;
- }
- /**
- * Set totalTransaccion
- *
- * @param string $totalTransaccion
- * @return Pedido
- */
- public function setTotalTransaccion($totalTransaccion)
- {
- $this->totalTransaccion = $totalTransaccion;
- return $this;
- }
- /**
- * Get totalTransaccion
- *
- * @return string
- */
- public function getTotalTransaccion()
- {
- return $this->totalTransaccion;
- }
- /**
- * Set codigoPostal
- *
- * @param integer $codigoPostal
- * @return Pedido
- */
- public function setCodigoPostal($codigoPostal)
- {
- $this->codigoPostal = $codigoPostal;
- return $this;
- }
- /**
- * Get codigoPostal
- *
- * @return integer
- */
- public function getCodigoPostal()
- {
- return $this->codigoPostal;
- }
- /**
- * Set cupon
- *
- * @param string $cupon
- * @return Carro
- */
- public function setCupon($cupon)
- {
- $this->cupon = $cupon;
- return $this;
- }
- /**
- * Get cupon
- *
- * @return Cupon
- */
- public function getCupon()
- {
- return $this->cupon;
- }
- /**
- * Set ciudad
- *
- * @param string $ciudad
- * @return Pedido
- */
- public function setCiudad($ciudad)
- {
- $this->ciudad = $ciudad;
- return $this;
- }
- /**
- * Get ciudad
- *
- * @return string
- */
- public function getCiudad()
- {
- return $this->ciudad;
- }
- /**
- * Set provincia
- *
- * @param string $provincia
- * @return Pedido
- */
- public function setProvincia($provincia)
- {
- $this->provincia = $provincia;
- return $this;
- }
- /**
- * Get provincia
- *
- * @return string
- */
- public function getProvincia()
- {
- return $this->provincia;
- }
- /**
- * Set pais
- *
- * @param string $pais
- * @return Pedido
- */
- public function setPais($pais)
- {
- $this->pais = $pais;
- return $this;
- }
- /**
- * Get pais
- *
- * @return string
- */
- public function getPais()
- {
- return $this->pais;
- }
- /**
- * Get comentario
- *
- * @return string
- */
- public function getComentario()
- {
- return $this->comentario;
- }
- /**
- * Set comentario
- *
- * @param string $comentario
- * @return Pedido
- */
- public function setComentario($comentario)
- {
- $this->comentario = $comentario;
- return $this;
- }
- /**
- * Get invitado
- *
- * @return \Invitado
- */
- public function getInvitado()
- {
- return $this->invitado;
- }
- /**
- * Set invitado
- *
- * @param string $invitado
- * @return Carro
- */
- public function setInvitado($invitado)
- {
- $this->invitado = $invitado;
- return $this;
- }
- /**
- * Get gastosEnvio
- *
- * @return $gastosEnvio
- */
- public function getGastosEnvio()
- {
- return $this->gastosEnvio;
- }
- /**
- * Set gastosEnvio
- *
- * @param float $gastosEnvio
- * @return Carro
- */
- public function setGastosEnvio($gastosEnvio)
- {
- $this->gastosEnvio = $gastosEnvio;
- return $this;
- }
- /**
- * Get terminado
- *
- * @return \string
- */
- public function getTerminado()
- {
- return $this->terminado;
- }
- /**
- * Set terminado
- *
- * @param \string $terminado
- * @return Pedido
- */
- public function setTerminado($terminado)
- {
- $this->terminado = $terminado;
- return $this;
- }
- /**
- * Get freeShipping
- *
- * @return \string
- */
- public function getFreeShipping()
- {
- return $this->freeShipping;
- }
- /**
- * Set freeShipping
- *
- * @param \string $freeShipping
- * @return Pedido
- */
- public function setFreeShipping($freeShipping)
- {
- $this->freeShipping = $freeShipping;
- return $this;
- }
- public function getVenta(){
- $this->ventaERP;
- }
- public function setVenta($ventaERP){
- $this->ventaERP=$ventaERP;
- }
- /**
- * El tiempo máximo de antelación de las reservas es de 3 meses
- * @Assert\IsTrue(message = "cart.maxAdvance")
- */
- public function isFechaEntregaLegal(){
- $fechaValida=false;
- //Es un paso anterior del carro
- if($this->fechaEntrega==null){
- return true;
- }
- else{
- $date= $this->fechaEntrega->format('Y-m-d');
- if (strtotime('+3 month', time()) < strtotime($date)) {
- return false;
- }
- }
- return true;
- }
- /**
- * No se pueden comprar Euros online
- * @Assert\IsTrue(message = "cart.payWithEuros")
- */
- public function isCompraLegal(){
- if(!$this->reserva){
- //echo "NO ES RESERVA";
- foreach ($this->pedidos as $linea) {
- if($linea->getDivisaFinal()->getMaestro())
- return false;
- }
- }
- return true;
- }
- /**
- * Comprueba si la cantidad que va a comprar no excede
- * de los 1.500€
- * @Assert\IsTrue(message = "cart.maxQuantity")
- */
- public function isCantidadCompraLegal(){
- $total=0;
- foreach ($this->pedidos as $linea) {
- if($linea->getDivisaFinal()->getMaestro())
- $total+=$linea->getCantidadFinal();
- else
- $total+=$linea->getCantidadOrigen();
- }
- if(!$this->reserva){
- if($total>2000)
- return false;
- else
- return true;
- }
- }
- /**
- * Comprueba que la reserva no excede de los 6.000€
- * @Assert\IsTrue(message = "cart.maxQuantityReservation")
- */
- public function isCantidadCompraLegal2(){
- $total=0;
- foreach ($this->pedidos as $linea) {
- if($linea->getDivisaFinal()->getMaestro())
- $total+=$linea->getCantidadFinal();
- else
- $total+=$linea->getCantidadOrigen();
- }
- if($this->reserva){
- if($total>6000)
- return false;
- else
- return true;
- }
- }
- /**
- * Restringimos las operaciones de reserva de EUR => Divisa con min
- * en las operaciones de reserva
- * @Assert\IsTrue(message = "cart.onlyBought")
- */
- public function isCantidadCompraLegal3(){
- if($this->getReserva()){
- foreach ($this->pedidos as $linea) {
- if($linea->getDivisaFinal()->getCompraMinima()!=0){
- return false;
- }
- }
- }
- return true;
- }
- /**
- * En caso de que se esté comprando una divisa con cantidadMínima
- * nos aseguramos de que efectivamente la cantidad respeta el mínimo.
- * Solo para operaciones de Euro => Divisa marcada con mínimo
- * @Assert\IsTrue(message = "cart.minQuantity")
- */
- public function isCantidadCompraLegal4(){
- foreach ($this->pedidos as $linea) {
- if($linea->getDivisaFinal()->getCompraMinima()!=0 && $linea->getDivisaFinal()->getCompraMinima()>$linea->getCantidadOrigen()){
- return false;
- }
- }
- return true;
- }
- /**
- * Comprueba que la oficina está abierta el día que se pretende
- * reservar/comprar
- * @Assert\IsTrue(message = "cart.officeClosedDay")
- */
- public function isFechaEntregaLegal2(){
- $fechaValida=false;
- //Paso anterior del carro
- if ($this->oficina == null || $this->reserva == 0) {
- return true;
- }
- else{
- $date = $this->fechaEntrega->format('D');
- $franjas = $this->oficina->getFranjas();
- for($i=0;$i<count($franjas) && !$fechaValida;$i++){
- switch ($date) {
- case 'Mon':
- if($franjas[$i]->getLunes()) $fechaValida=1;
- break;
- case 'Tue':
- if($franjas[$i]->getMartes()) $fechaValida=1;
- break;
- case 'Wed':
- if($franjas[$i]->getMiercoles()) $fechaValida=1;
- break;
- case 'Thu':
- if($franjas[$i]->getJueves()) $fechaValida=1;
- break;
- case 'Fri':
- if($franjas[$i]->getViernes()) $fechaValida=1;
- break;
- case 'Sat':
- if($franjas[$i]->getSabado()) $fechaValida=1;
- break;
- case 'Sun':
- if($franjas[$i]->getDomingo()) $fechaValida=1;
- break;
- default:
- break;
- }
- }
- return $fechaValida;
- }
- return false;
- }
- /**
- * Comprueba que la oficina está abierta a la hora que se pretende
- * reservar
- * Assert\IsTrue(message = "cart.officeClosedHour")
- */
- public function isHoraEntregaLegal(){
- $horaValida = false;
- $horaEntrega=$this->horaEntrega;
- //Es un paso anterior del carro
- if($this->horaEntrega==null){
- return true;
- }
- else{
- $date = $this->fechaEntrega->format('D');
- $franjas = $this->oficina->getFranjas();
- //Pasamos por los dias y miramos si coincide con el introducido
- for($i=0;$i<count($franjas) && !$horaValida;$i++){
- //Comparacion del dia del formulario con los de la oficina
- $diaDb=false;
- $horarios=$franjas[$i]->getFranjaHoras();
- for($j=0;$j<count($horarios);$j++){
- $horaEntrega=$this->horaEntrega->format('H:i');
- $horaInicio=$horarios[$j]->getHoraInicio()->format('H:i');
- $horaFin=$horarios[$j]->getHoraFin()->format('H:i');
- if($horaInicio<=$horaEntrega && $horaFin>=$horaEntrega){
- //El dia que nos han puesto se corresponde
- switch ($date) {
- case 'Mon':
- if($franjas[$i]->getLunes()) $horaValida=1;
- break;
- case 'Tue':
- if($franjas[$i]->getMartes()) $horaValida=1;
- break;
- case 'Wed':
- if($franjas[$i]->getMiercoles()) $horaValida=1;
- break;
- case 'Thu':
- if($franjas[$i]->getJueves()) $horaValida=1;
- break;
- case 'Fri':
- if($franjas[$i]->getViernes()) $horaValida=1;
- break;
- case 'Sat':
- if($franjas[$i]->getSabado()) $horaValida=1;
- break;
- case 'Sun':
- if($franjas[$i]->getDomingo()) $horaValida=1;
- break;
- default:
- break;
- }
- }
- }
- }
- }
- return $horaValida;
- }
- /**
- * Se asegura de que la oficina tiene stock para las divisas del carro en el día solicitado
- * En primer lugar mira que el Stock máximo no sea inferior a la cantidad que pretende comprar
- * En segundo lugar busca el stock de esa oficina-dia (Clase Existencia) y mira que tenga capacidad
- * @Assert\IsTrue(message = "cart.warning.noStock")
- */
- public function isStockLegal(){
- //Si no se trata de un envio a domicilio
- if($this->oficina){
- $existencias=$this->oficina->getExistencias();
- $stocks=$this->oficina->getStocks();
- foreach ($stocks as $key => $stock) {
- foreach ($this->getPedidos() as $key => $pedido) {
- //Si la cantidad es superior al stock máximo y no se puede pedir a proveedor
- if($pedido->getDivisaFinal()->getId()==$stock->getDivisa()->getId() && !$stock->getCompraProveedor()){
- if($pedido->getCantidadFinal()>$stock->getStockMaximo()){
- return false;
- }
- }
- }
- $stock->getDivisa();
- }
- //Recoremos todas los stock/dia de la oficina
- //Para cada dia hay un stock distinto
- foreach ($existencias as $key => $existencia) {
- if($existencia->getDia()==$this->fechaEntrega){
- foreach ($this->getPedidos() as $key=>$pedido) {
- if($pedido->getDivisaFinal()->getId()==$existencia->getDivisa()->getId()){
- if($existencia->getCantidad()<$pedido->getCantidadFinal()){
- $this->oficina=null;
- return false;
- }
- }
- }
- }
- }
- }
- //Si no hay entidades que correspondan el día de la entrega es porque
- //el stock está al maximo
- return true;
- }
- public function setTotalEstimado($totalEstimado){
- $this->totalEstimado=$totalEstimado;
- }
- public function getShippingTime(){
- foreach ($this->pedidos as $pedido){
- if($pedido->getDivisaFinal()->getCompraMinima())
- {
- return 48;
- }
- }
- return 24;
- }
- public function getTotalEstimado(){
- return $this->totalEstimado;
- }
- /**
- * @return mixed
- */
- public function getNacex()
- {
- return $this->nacex;
- }
- /**
- * @param mixed $nacex
- */
- public function setNacex($nacex)
- {
- $this->nacex = $nacex;
- }
- /**
- * @return mixed
- */
- public function getCardSend()
- {
- return $this->cardSend;
- }
- /**
- * @param mixed $cardSend
- */
- public function setCardSend($cardSend)
- {
- $this->cardSend = $cardSend;
- }
- /**
- * @return mixed
- */
- public function getNameSend()
- {
- return $this->nameSend;
- }
- /**
- * @param mixed $nameSend
- */
- public function setNameSend($nameSend)
- {
- $this->nameSend = $nameSend;
- }
- /**
- * @return mixed
- */
- public function getTitular()
- {
- return $this->titular;
- }
- /**
- * @param mixed $titular
- */
- public function setTitular($titular)
- {
- $this->titular = $titular;
- }
- /**
- * @return integer
- */
- public function getTipoPromo()
- {
- return $this->tipoPromo;
- }
- /**
- * @param integer $tipoPromo
- */
- public function setTipoPromo($tipoPromo)
- {
- $this->tipoPromo = $tipoPromo;
- }
- /**
- * Set descuentoPromo
- *
- * @param string $descuentoPromo
- * @return Pedido
- */
- public function setDescuentoPromo($descuentoPromo)
- {
- $this->descuentoPromo = $descuentoPromo;
- return $this;
- }
- /**
- * Get descuentoPromo
- *
- * @return string
- */
- public function getDescuentoPromo()
- {
- return $this->descuentoPromo;
- }
- }