src/Entity/Carro.php line 18

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\Collection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Symfony\Component\Validator\ExecutionContext;
  8. use App\Entity\Pedido;
  9. use JMS\Serializer\Annotation as JMS;
  10. /**
  11.  * Carro
  12.  *
  13.  * @ORM\Entity
  14.  */
  15. class Carro
  16. {
  17.     const TIPO_PROMO_DIVISA 0;
  18.     const TIPO_PROMO_CUPON 1;
  19.     
  20.     /**
  21.      * @var integer
  22.      *
  23.      * @ORM\Column(name="id", type="integer")
  24.      * @ORM\Id
  25.      * @ORM\GeneratedValue(strategy="AUTO")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @Assert\Valid()
  30.      * @ORM\OneToMany(targetEntity="Pedido", mappedBy="pedidos",cascade={"persist"})
  31.      */
  32.     private $pedidos;
  33.     /**
  34.      * @ORM\ManyToOne(targetEntity="User")
  35.      * @ORM\JoinColumn(name="usuario", referencedColumnName="id", nullable=true)
  36.      */
  37.     private $usuario;
  38.     /**
  39.      * @var string
  40.      *
  41.      * @ORM\Column(name="codigoPromo", type="string", length=255, nullable=false)
  42.      */
  43.     private $codigoPromo;
  44.     
  45.     /**
  46.      * @var string
  47.      *
  48.      * @ORM\Column(name="tipoPromo", type="integer", options={"default":0})
  49.      */
  50.     private $tipoPromo;
  51.     /**
  52.      * @var boolean
  53.      *
  54.      * @ORM\Column(name="reserva", type="boolean")
  55.      */
  56.     private $reserva;
  57.     /**
  58.      * @var Oficina
  59.      *
  60.      * @ORM\Column(name="tienda", type="string", length=255, nullable=true)
  61.      */
  62.     private $oficina;
  63.     
  64.     
  65.     /**
  66.      * @var \DateTime
  67.      *
  68.      * @ORM\Column(name="fechaDisponible", type="datetime", nullable=true)
  69.      */
  70.     private $fechaDisponible;
  71.     /**
  72.      * @var \DateTime
  73.      *
  74.      * @ORM\Column(name="fechaCompra", type="datetime", nullable=true)
  75.      */
  76.     private $fechaCompra 'CURRENT_TIMESTAMP';
  77.     /**
  78.      * @var \DateTime
  79.      *
  80.      * @ORM\Column(name="fechaEntrega", type="date", nullable=true)
  81.      */
  82.     private $fechaEntrega;
  83. //    private $tipo = 0;
  84.     /**
  85.      * @var \Time
  86.      *
  87.      * @ORM\Column(name="horaEntrega", type="time", nullable=true)
  88.      */
  89.     private $horaEntrega;
  90.     /**
  91.      * @var string
  92.      *
  93.      * @ORM\Column(name="ciudad", type="string", length=255, nullable=false)
  94.      */
  95.     private $ciudad;
  96.     /**
  97.      * @var string
  98.      *
  99.      * @ORM\Column(name="provincia", type="string", length=255, nullable=true)
  100.      */
  101.     private $provincia;
  102.     /**
  103.      * @var string
  104.      *
  105.      * @ORM\Column(name="pais", type="string", length=255, nullable=false)
  106.      */
  107.     private $pais;
  108.     /**
  109.      * @var string
  110.      *
  111.      * @ORM\Column(name="direccion", type="string", length=255, nullable=false)
  112.      */
  113.     private $direccion;
  114.     /**
  115.      * @var string
  116.      *
  117.      * @Assert\Length(
  118.      *     min = 0,
  119.      *     max = 250,
  120.      *     maxMessage = "delivery.maxSize"
  121.      * )
  122.      * @ORM\Column(name="comentario", type="string", length=250, nullable=true)
  123.      */
  124.     private $comentario;
  125.     /**
  126.      * @ORM\ManyToOne(targetEntity="App\Entity\Cupon")
  127.      * @ORM\JoinColumn(name="cupon", referencedColumnName="id", nullable=true)
  128.      */
  129.     private $cupon;
  130.     /**
  131.      * @var string
  132.      *
  133.      * @ORM\Column(name="tipoPago", type="string", length=255, nullable=false)
  134.      */
  135.     private $tipoPago 0;
  136.     /**
  137.      * @ORM\ManyToOne(targetEntity="App\Entity\Invitado")
  138.      * @ORM\JoinColumn(name="invitado", referencedColumnName="id", nullable=true)
  139.      */
  140.     private $invitado;
  141.     private $terminado 0;
  142.     private $totalTransaccion 0;
  143.     private $descuentoPromo 0;
  144.     private $freeShipping 0;
  145.     private $totalEstimado 0;
  146.     private $codigoPostal;
  147.     private $gastosEnvio 0;
  148.     /**
  149.      * @ORM\Column(name="dni_envio", type="string", length=255, nullable=true)
  150.      */
  151.     protected $cardSend;
  152.     /**
  153.      * @ORM\Column(name="nombre_envio", type="string", length=255, nullable=true)
  154.      */
  155.     protected $nameSend;
  156.     /**
  157.      * @ORM\Column(name="titular", type="string", length=255, nullable=true)
  158.      */
  159.     protected $titular;
  160.     /**
  161.      * @var \DateTime
  162.      * @ORM\Column(name="fecha_prevision", type="date", nullable=true)
  163.      */
  164.     protected $fechaPrevision;
  165.     public function __construct()
  166.     {
  167.         $this->pedidos = new ArrayCollection();
  168.     }
  169.     /**
  170.      * Get id
  171.      *
  172.      * @return integer
  173.      */
  174.     public function getId()
  175.     {
  176.         return $this->id;
  177.     }
  178.     /**
  179.      * Set pedidos
  180.      *
  181.      * @param string $pedidos
  182.      * @return Carro
  183.      */
  184.     public function setPedidos($pedidos)
  185.     {
  186.         $this->pedidos $pedidos;
  187.         return $this;
  188.     }
  189.     /**
  190.      * Get pedidos
  191.      *
  192.      * @return Pedido[]|Collection
  193.      */
  194.     public function getPedidos()
  195.     {
  196.         return $this->pedidos;
  197.     }
  198.     /**
  199.      * Set codigoProm
  200.      *
  201.      * @param float $codigoProm
  202.      * @return Pedido
  203.      */
  204.     public function setCodigoPromo($codigoProm)
  205.     {
  206.         $this->codigoPromo $codigoProm;
  207.         return $this;
  208.     }
  209.     /**
  210.      * Get codigoProm
  211.      *
  212.      * @return float
  213.      */
  214.     public function getCodigoPromo()
  215.     {
  216.         if ($this->codigoPromo === null)
  217.             return '';
  218.         return $this->codigoPromo;
  219.     }
  220.     /**
  221.      * Get $pedido
  222.      *
  223.      * @return Carro
  224.      */
  225.     public function addPedido(Pedido $pedido)
  226.     {
  227.         $this->pedidos[]=$pedido;
  228.         return $this;
  229.     }
  230.     /**
  231.      * Remove pedido
  232.      *
  233.      * @return Carro
  234.      */
  235.     public function removePedido(Pedido $pedido)
  236.     {
  237.         $this->pedidos->removeElement($pedido);
  238.         return $this;
  239.     }
  240.     /**
  241.      * Set usuario
  242.      *
  243.      * @param string $usuario
  244.      * @return Carro
  245.      */
  246.     public function setUsuario($usuario)
  247.     {
  248.         $this->usuario $usuario;
  249.         return $this;
  250.     }
  251.     /**
  252.      * Get usuario
  253.      *
  254.      * @return string
  255.      */
  256.     public function getUsuario()
  257.     {
  258.         return $this->usuario;
  259.     }
  260.   /*  public setTipo($tipo){
  261.       $this->tipo=$tipo;
  262.       return $this;
  263.     }
  264.     public getTipo(){
  265.       return $this->tipo;
  266.     }*/
  267.     /**
  268.      * Set reserva
  269.      *
  270.      * @param boolean $reserva
  271.      * @return Carro
  272.      */
  273.     public function setReserva($reserva)
  274.     {
  275.         $this->reserva $reserva;
  276.         return $this;
  277.     }
  278.     /**
  279.      * Get reserva
  280.      *
  281.      * @return boolean
  282.      */
  283.     public function getReserva()
  284.     {
  285.         return $this->reserva;
  286.     }
  287.     /**
  288.      * Set oficina
  289.      *
  290.      * @param Oficina $oficina
  291.      * @return Pedido
  292.      */
  293.     public function setOficina($oficina)
  294.     {
  295.         $this->oficina $oficina;
  296.         return $this;
  297.     }
  298.     /**
  299.      * Get oficina
  300.      *
  301.      * @return Oficina
  302.      */
  303.     public function getOficina()
  304.     {
  305.         return $this->oficina;
  306.     }
  307.     
  308.     /**
  309.      * Set fechaDisponible
  310.      *
  311.      * @param \DateTime $fechaDisponible
  312.      */
  313.     public function setFechaDisponible($fechaDisponible)
  314.     {
  315.         $this->fechaDisponible $fechaDisponible;
  316.         return $this;
  317.     }
  318.     /**
  319.      * Get fechaDisponible
  320.      *
  321.      * @return \DateTime
  322.      */
  323.     public function getFechaDisponible()
  324.     {
  325.         return $this->fechaDisponible;
  326.     }
  327.     
  328.     /**
  329.      * Set fechaCompra
  330.      *
  331.      * @param \DateTime $fechaCompra
  332.      * @return Pedido
  333.      */
  334.     public function setFechaCompra($fechaCompra)
  335.     {
  336.         $this->fechaCompra $fechaCompra;
  337.         return $this;
  338.     }
  339.     /**
  340.      * Get fechaCompra
  341.      *
  342.      * @return \DateTime
  343.      */
  344.     public function getFechaCompra()
  345.     {
  346.         return $this->fechaCompra;
  347.     }
  348.     /**
  349.      * Set fechaEntrega
  350.      *
  351.      * @param \DateTime $fechaEntrega
  352.      * @return Pedido
  353.      */
  354.     public function setFechaEntrega($fechaEntrega)
  355.     {
  356.         $this->fechaEntrega $fechaEntrega;
  357.         return $this;
  358.     }
  359.     /**
  360.      * Get fechaEntrega
  361.      *
  362.      * @return \DateTime
  363.      */
  364.     public function getFechaEntrega()
  365.     {
  366.         return $this->fechaEntrega;
  367.     }
  368.     /**
  369.      * Set horaEntrega
  370.      *
  371.      * @param \DateTime $horaEntrega
  372.      * @return Pedido
  373.      */
  374.     public function setHoraEntrega($horaEntrega)
  375.     {
  376.         if(gettype($horaEntrega)=='string'){
  377.             $this->horaEntrega = new \Datetime($horaEntrega);
  378.         }
  379.         else{
  380.             $this->horaEntrega $horaEntrega;
  381.         }
  382.         return $this;
  383.     }
  384.     /**
  385.      * Get tipoPago
  386.      *
  387.      * @return \string
  388.      */
  389.     public function getTipoPago()
  390.     {
  391.         return $this->tipoPago;
  392.     }
  393.     /**
  394.      * Set tipoPago
  395.      *
  396.      * @param \string $tipoPago
  397.      * @return Pedido
  398.      */
  399.     public function setTipoPago($tipoPago)
  400.     {
  401.         $this->tipoPago $tipoPago;
  402.         return $this;
  403.     }
  404.     /**
  405.      * Get horaEntrega
  406.      *
  407.      * @return \DateTime
  408.      */
  409.     public function getHoraEntrega()
  410.     {
  411.         return $this->horaEntrega;
  412.     }
  413.     /**
  414.      * Set direccion
  415.      *
  416.      * @param string $direccion
  417.      * @return Pedido
  418.      */
  419.     public function setDireccion($direccion)
  420.     {
  421.         $this->direccion $direccion;
  422.         return $this;
  423.     }
  424.     /**
  425.      * Get direccion
  426.      *
  427.      * @return string
  428.      */
  429.     public function getDireccion()
  430.     {
  431.         return $this->direccion;
  432.     }
  433.     /**
  434.      * Set totalTransaccion
  435.      *
  436.      * @param string $totalTransaccion
  437.      * @return Pedido
  438.      */
  439.     public function setTotalTransaccion($totalTransaccion)
  440.     {
  441.         $this->totalTransaccion $totalTransaccion;
  442.         return $this;
  443.     }
  444.     /**
  445.      * Get totalTransaccion
  446.      *
  447.      * @return string
  448.      */
  449.     public function getTotalTransaccion()
  450.     {
  451.         return $this->totalTransaccion;
  452.     }
  453.     /**
  454.      * Set codigoPostal
  455.      *
  456.      * @param integer $codigoPostal
  457.      * @return Pedido
  458.      */
  459.     public function setCodigoPostal($codigoPostal)
  460.     {
  461.         $this->codigoPostal $codigoPostal;
  462.         return $this;
  463.     }
  464.     /**
  465.      * Get codigoPostal
  466.      *
  467.      * @return integer
  468.      */
  469.     public function getCodigoPostal()
  470.     {
  471.         return $this->codigoPostal;
  472.     }
  473.         /**
  474.          * Set cupon
  475.          *
  476.          * @param string $cupon
  477.          * @return Carro
  478.          */
  479.         public function setCupon($cupon)
  480.         {
  481.             $this->cupon $cupon;
  482.             return $this;
  483.         }
  484.         /**
  485.          * Get cupon
  486.          *
  487.          * @return Cupon
  488.          */
  489.         public function getCupon()
  490.         {
  491.             return $this->cupon;
  492.         }
  493.     /**
  494.      * Set ciudad
  495.      *
  496.      * @param string $ciudad
  497.      * @return Pedido
  498.      */
  499.     public function setCiudad($ciudad)
  500.     {
  501.         $this->ciudad $ciudad;
  502.         return $this;
  503.     }
  504.     /**
  505.      * Get ciudad
  506.      *
  507.      * @return string
  508.      */
  509.     public function getCiudad()
  510.     {
  511.         return $this->ciudad;
  512.     }
  513.     /**
  514.      * Set provincia
  515.      *
  516.      * @param string $provincia
  517.      * @return Pedido
  518.      */
  519.     public function setProvincia($provincia)
  520.     {
  521.         $this->provincia $provincia;
  522.         return $this;
  523.     }
  524.     /**
  525.      * Get provincia
  526.      *
  527.      * @return string
  528.      */
  529.     public function getProvincia()
  530.     {
  531.         return $this->provincia;
  532.     }
  533.     /**
  534.      * Set pais
  535.      *
  536.      * @param string $pais
  537.      * @return Pedido
  538.      */
  539.     public function setPais($pais)
  540.     {
  541.         $this->pais $pais;
  542.         return $this;
  543.     }
  544.     /**
  545.      * Get pais
  546.      *
  547.      * @return string
  548.      */
  549.     public function getPais()
  550.     {
  551.         return $this->pais;
  552.     }
  553.     /**
  554.      * Get comentario
  555.      *
  556.      * @return string
  557.      */
  558.     public function getComentario()
  559.     {
  560.         return $this->comentario;
  561.     }
  562.     /**
  563.      * Set comentario
  564.      *
  565.      * @param string $comentario
  566.      * @return Pedido
  567.      */
  568.     public function setComentario($comentario)
  569.     {
  570.         $this->comentario $comentario;
  571.         return $this;
  572.     }
  573.     /**
  574.      * Get invitado
  575.      *
  576.      * @return \Invitado
  577.      */
  578.     public function getInvitado()
  579.     {
  580.         return $this->invitado;
  581.     }
  582.     /**
  583.      * Set invitado
  584.      *
  585.      * @param string $invitado
  586.      * @return Carro
  587.      */
  588.     public function setInvitado($invitado)
  589.     {
  590.         $this->invitado $invitado;
  591.         return $this;
  592.     }
  593.     /**
  594.      * Get gastosEnvio
  595.      *
  596.      * @return $gastosEnvio
  597.      */
  598.     public function getGastosEnvio()
  599.     {
  600.         return $this->gastosEnvio;
  601.     }
  602.     /**
  603.      * Set gastosEnvio
  604.      *
  605.      * @param float $gastosEnvio
  606.      * @return Carro
  607.      */
  608.     public function setGastosEnvio($gastosEnvio)
  609.     {
  610.         $this->gastosEnvio $gastosEnvio;
  611.         return $this;
  612.     }
  613.     /**
  614.      * Get terminado
  615.      *
  616.      * @return \string
  617.      */
  618.     public function getTerminado()
  619.     {
  620.         return $this->terminado;
  621.     }
  622.     /**
  623.      * Set terminado
  624.      *
  625.      * @param \string $terminado
  626.      * @return Pedido
  627.      */
  628.     public function setTerminado($terminado)
  629.     {
  630.         $this->terminado $terminado;
  631.         return $this;
  632.     }
  633.     /**
  634.      * Get freeShipping
  635.      *
  636.      * @return \string
  637.      */
  638.     public function getFreeShipping()
  639.     {
  640.         return $this->freeShipping;
  641.     }
  642.     /**
  643.      * Set freeShipping
  644.      *
  645.      * @param \string $freeShipping
  646.      * @return Pedido
  647.      */
  648.     public function setFreeShipping($freeShipping)
  649.     {
  650.         $this->freeShipping $freeShipping;
  651.         return $this;
  652.     }
  653.     public function getVenta(){
  654.         $this->ventaERP;
  655.     }
  656.     public function setVenta($ventaERP){
  657.         $this->ventaERP=$ventaERP;
  658.     }
  659.     /**
  660.      * El tiempo máximo de antelación de las reservas es de 3 meses
  661.      * @Assert\IsTrue(message = "cart.maxAdvance")
  662.      */
  663.     public function isFechaEntregaLegal(){
  664.         $fechaValida=false;
  665.         //Es un paso anterior del carro
  666.         if($this->fechaEntrega==null){
  667.             return true;
  668.         }
  669.         else{
  670.             $date$this->fechaEntrega->format('Y-m-d');
  671.             if (strtotime('+3 month'time()) < strtotime($date)) {
  672.                 return false;
  673.             }
  674.         }
  675.         return true;
  676.     }
  677.     /**
  678.      * No se pueden comprar Euros online
  679.      * @Assert\IsTrue(message = "cart.payWithEuros")
  680.      */
  681.     public function isCompraLegal(){
  682.         if(!$this->reserva){
  683.             //echo "NO ES RESERVA";
  684.             foreach ($this->pedidos as $linea) {
  685.                 if($linea->getDivisaFinal()->getMaestro())
  686.                     return false;
  687.             }
  688.         }
  689.         return true;
  690.     }
  691.     /**
  692.      * Comprueba si la cantidad que va a comprar no excede
  693.      * de los 1.500€
  694.      * @Assert\IsTrue(message = "cart.maxQuantity")
  695.      */
  696.     public function isCantidadCompraLegal(){
  697.         $total=0;
  698.         foreach ($this->pedidos as $linea) {
  699.             if($linea->getDivisaFinal()->getMaestro())
  700.                 $total+=$linea->getCantidadFinal();
  701.             else
  702.                 $total+=$linea->getCantidadOrigen();
  703.         }
  704.         if(!$this->reserva){
  705.             if($total>2000)
  706.                 return false;
  707.             else
  708.                 return true;
  709.         }
  710.     }
  711.     /**
  712.      * Comprueba que la reserva no excede de los 6.000€
  713.      * @Assert\IsTrue(message = "cart.maxQuantityReservation")
  714.      */
  715.     public function isCantidadCompraLegal2(){
  716.      $total=0;
  717.         foreach ($this->pedidos as $linea) {
  718.             if($linea->getDivisaFinal()->getMaestro())
  719.                 $total+=$linea->getCantidadFinal();
  720.             else
  721.                 $total+=$linea->getCantidadOrigen();
  722.         }
  723.         if($this->reserva){
  724.             if($total>6000)
  725.                 return false;
  726.             else
  727.                 return true;
  728.         }
  729.     }
  730.     /**
  731.      * Restringimos las operaciones de reserva de EUR => Divisa con min
  732.      * en las operaciones de reserva
  733.      * @Assert\IsTrue(message = "cart.onlyBought")
  734.      */
  735.     public function isCantidadCompraLegal3(){
  736.         if($this->getReserva()){
  737.             foreach ($this->pedidos as $linea) {
  738.                 if($linea->getDivisaFinal()->getCompraMinima()!=0){
  739.                     return false;
  740.                 }
  741.             }
  742.         }
  743.         return true;
  744.     }
  745.     /**
  746.      * En caso de que se esté comprando una divisa con cantidadMínima
  747.      * nos aseguramos de que efectivamente la cantidad respeta el mínimo.
  748.      * Solo para operaciones de Euro => Divisa marcada con mínimo
  749.      * @Assert\IsTrue(message = "cart.minQuantity")
  750.      */
  751.     public function isCantidadCompraLegal4(){
  752.         foreach ($this->pedidos as $linea) {
  753.             if($linea->getDivisaFinal()->getCompraMinima()!=&& $linea->getDivisaFinal()->getCompraMinima()>$linea->getCantidadOrigen()){
  754.                 return false;
  755.             }
  756.         }
  757.         return true;
  758.     }
  759.     /**
  760.      * Comprueba que la oficina está abierta el día que se pretende
  761.      * reservar/comprar
  762.      * @Assert\IsTrue(message = "cart.officeClosedDay")
  763.      */
  764.     public function isFechaEntregaLegal2(){
  765.         $fechaValida=false;
  766.         //Paso anterior del carro
  767.         if ($this->oficina == null || $this->reserva == 0) {
  768.             return true;
  769.         }
  770.         else{
  771.             $date       $this->fechaEntrega->format('D');
  772.             $franjas    $this->oficina->getFranjas();
  773.             for($i=0;$i<count($franjas) && !$fechaValida;$i++){
  774.                 switch ($date) {
  775.                     case 'Mon':
  776.                         if($franjas[$i]->getLunes()) $fechaValida=1;
  777.                         break;
  778.                     case 'Tue':
  779.                         if($franjas[$i]->getMartes()) $fechaValida=1;
  780.                         break;
  781.                     case 'Wed':
  782.                         if($franjas[$i]->getMiercoles()) $fechaValida=1;
  783.                         break;
  784.                     case 'Thu':
  785.                         if($franjas[$i]->getJueves()) $fechaValida=1;
  786.                         break;
  787.                     case 'Fri':
  788.                         if($franjas[$i]->getViernes()) $fechaValida=1;
  789.                         break;
  790.                     case 'Sat':
  791.                         if($franjas[$i]->getSabado()) $fechaValida=1;
  792.                         break;
  793.                     case 'Sun':
  794.                         if($franjas[$i]->getDomingo()) $fechaValida=1;
  795.                         break;
  796.                     default:
  797.                         break;
  798.                 }
  799.             }
  800.             return $fechaValida;
  801.         }
  802.         return false;
  803.     }
  804.     /**
  805.      * Comprueba que la oficina está abierta a la hora que se pretende
  806.      * reservar
  807.      * Assert\IsTrue(message = "cart.officeClosedHour")
  808.      */
  809.     public function isHoraEntregaLegal(){
  810.         $horaValida false;
  811.         $horaEntrega=$this->horaEntrega;
  812.         //Es un paso anterior del carro
  813.         if($this->horaEntrega==null){
  814.             return true;
  815.         }
  816.         else{
  817.             $date       $this->fechaEntrega->format('D');
  818.             $franjas    $this->oficina->getFranjas();
  819.             //Pasamos por los dias y miramos si coincide con el introducido
  820.             for($i=0;$i<count($franjas) && !$horaValida;$i++){
  821.                 //Comparacion del dia del formulario con los de la oficina
  822.                 $diaDb=false;
  823.                 $horarios=$franjas[$i]->getFranjaHoras();
  824.                 for($j=0;$j<count($horarios);$j++){
  825.                     $horaEntrega=$this->horaEntrega->format('H:i');
  826.                     $horaInicio=$horarios[$j]->getHoraInicio()->format('H:i');
  827.                     $horaFin=$horarios[$j]->getHoraFin()->format('H:i');
  828.                     if($horaInicio<=$horaEntrega && $horaFin>=$horaEntrega){
  829.                         //El dia que nos han puesto se corresponde
  830.                         switch ($date) {
  831.                             case 'Mon':
  832.                                 if($franjas[$i]->getLunes()) $horaValida=1;
  833.                                 break;
  834.                             case 'Tue':
  835.                                 if($franjas[$i]->getMartes()) $horaValida=1;
  836.                                 break;
  837.                             case 'Wed':
  838.                                 if($franjas[$i]->getMiercoles()) $horaValida=1;
  839.                                 break;
  840.                             case 'Thu':
  841.                                 if($franjas[$i]->getJueves()) $horaValida=1;
  842.                                 break;
  843.                             case 'Fri':
  844.                                 if($franjas[$i]->getViernes()) $horaValida=1;
  845.                                 break;
  846.                             case 'Sat':
  847.                                 if($franjas[$i]->getSabado()) $horaValida=1;
  848.                                 break;
  849.                             case 'Sun':
  850.                                 if($franjas[$i]->getDomingo()) $horaValida=1;
  851.                                 break;
  852.                             default:
  853.                                 break;
  854.                         }
  855.                     }
  856.                 }
  857.             }
  858.         }
  859.         return $horaValida;
  860.     }
  861.     /**
  862.      * Se asegura de que la oficina tiene stock para las divisas del carro en el día solicitado
  863.      * En primer lugar mira que el Stock máximo no sea inferior a la cantidad que pretende comprar
  864.      * En segundo lugar busca el stock de esa oficina-dia (Clase Existencia) y mira que tenga capacidad
  865.      * @Assert\IsTrue(message = "cart.warning.noStock")
  866.      */
  867.     public function isStockLegal(){
  868.         //Si no se trata de un envio a domicilio
  869.         if($this->oficina){
  870.             $existencias=$this->oficina->getExistencias();
  871.             $stocks=$this->oficina->getStocks();
  872.             foreach ($stocks as $key => $stock) {
  873.                 foreach ($this->getPedidos() as $key => $pedido) {
  874.                     //Si la cantidad es superior al stock máximo y no se puede pedir a proveedor
  875.                     if($pedido->getDivisaFinal()->getId()==$stock->getDivisa()->getId() && !$stock->getCompraProveedor()){
  876.                         if($pedido->getCantidadFinal()>$stock->getStockMaximo()){
  877.                             return false;
  878.                         }
  879.                     }
  880.                 }
  881.                 $stock->getDivisa();
  882.             }
  883.             //Recoremos todas los stock/dia de la oficina
  884.             //Para cada dia hay un stock distinto
  885.             foreach ($existencias as $key => $existencia) {
  886.                 if($existencia->getDia()==$this->fechaEntrega){
  887.                         foreach ($this->getPedidos() as $key=>$pedido) {
  888.                             if($pedido->getDivisaFinal()->getId()==$existencia->getDivisa()->getId()){
  889.                                 if($existencia->getCantidad()<$pedido->getCantidadFinal()){
  890.                                     $this->oficina=null;
  891.                                     return false;
  892.                                 }
  893.                             }
  894.                         }
  895.                 }
  896.             }
  897.         }
  898.         //Si no hay entidades que correspondan el día de la entrega es porque
  899.         //el stock está al maximo
  900.         return true;
  901.     }
  902.     public function setTotalEstimado($totalEstimado){
  903.         $this->totalEstimado=$totalEstimado;
  904.     }
  905.     public function getShippingTime(){
  906.         foreach ($this->pedidos as $pedido){
  907.             if($pedido->getDivisaFinal()->getCompraMinima())
  908.             {
  909.                 return 48;
  910.             }
  911.         }
  912.         return 24;
  913.     }
  914.     public function getTotalEstimado(){
  915.         return $this->totalEstimado;
  916.     }
  917.     /**
  918.      * @return mixed
  919.      */
  920.     public function getNacex()
  921.     {
  922.         return $this->nacex;
  923.     }
  924.     /**
  925.      * @param mixed $nacex
  926.      */
  927.     public function setNacex($nacex)
  928.     {
  929.         $this->nacex $nacex;
  930.     }
  931.     /**
  932.      * @return mixed
  933.      */
  934.     public function getCardSend()
  935.     {
  936.         return $this->cardSend;
  937.     }
  938.     /**
  939.      * @param mixed $cardSend
  940.      */
  941.     public function setCardSend($cardSend)
  942.     {
  943.         $this->cardSend $cardSend;
  944.     }
  945.     /**
  946.      * @return mixed
  947.      */
  948.     public function getNameSend()
  949.     {
  950.         return $this->nameSend;
  951.     }
  952.     /**
  953.      * @param mixed $nameSend
  954.      */
  955.     public function setNameSend($nameSend)
  956.     {
  957.         $this->nameSend $nameSend;
  958.     }
  959.     /**
  960.      * @return mixed
  961.      */
  962.     public function getTitular()
  963.     {
  964.         return $this->titular;
  965.     }
  966.     /**
  967.      * @param mixed $titular
  968.      */
  969.     public function setTitular($titular)
  970.     {
  971.         $this->titular $titular;
  972.     }
  973.     
  974.     
  975.     /**
  976.      * @return integer
  977.      */
  978.     public function getTipoPromo()
  979.     {
  980.         return $this->tipoPromo;
  981.     }
  982.     /**
  983.      * @param integer $tipoPromo
  984.      */
  985.     public function setTipoPromo($tipoPromo)
  986.     {
  987.         $this->tipoPromo $tipoPromo;
  988.     }
  989.     /**
  990.      * Set descuentoPromo
  991.      *
  992.      * @param string $descuentoPromo
  993.      * @return Pedido
  994.      */
  995.     public function setDescuentoPromo($descuentoPromo)
  996.     {
  997.         $this->descuentoPromo $descuentoPromo;
  998.         return $this;
  999.     }
  1000.     /**
  1001.      * Get descuentoPromo
  1002.      *
  1003.      * @return string
  1004.      */
  1005.     public function getDescuentoPromo()
  1006.     {
  1007.         return $this->descuentoPromo;
  1008.     }
  1009. }