<?php

namespace RxConnexionBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\ConvertInventoryItemRepository")
 * @ORM\Table(name="convert_inventory_item")
 * @ORM\HasLifecycleCallbacks()
 */

class ConvertInventoryItemEntity
{
    /**
     * @ORM\Column(type="bigint")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(name="quantity", type="decimal", precision=12, scale=2)
     */
    protected $quantity;

    /**
     * @ORM\Column(name="created_by", type="string", length=50)
     */
    protected $createdBy;

    /**
     * @ORM\Column(name="created_at", type="datetime")
     */
    protected $createdAt;

    /**
     * @ORM\Column(name="updated_by", type="string", length=50)
     */
    protected $updatedBy;

    /**
     * @ORM\Column(name="updated_at", type="datetime")
     */
    protected $updatedAt;

    /**
     * @ORM\ManyToOne(targetEntity="ConvertInventoryEntity", inversedBy="convertInventoryItems")
     * @ORM\JoinColumn(name="convert_inventory_id", referencedColumnName="id")
     */
    protected $convertInventory;

    /**
     * @ORM\ManyToOne(targetEntity="InventoryEntity", inversedBy="convertInventoryItems")
     * @ORM\JoinColumn(name="inventory_id", referencedColumnName="id")
     */
    protected $inventory;

    /**
    * @ORM\ManyToOne(targetEntity="RxConnexionBundle\Entity\InventorySerialNoEntity", inversedBy="convertInventoryItems")
    * @ORM\JoinColumn(name="inventory_serial_no_id", referencedColumnName="id")
    */
    protected $inventorySerialNo;

    /**
     * @ORM\OneToMany(targetEntity="InventoryMovementEntity", mappedBy="convertInventoryItem")
     */
    protected $inventoryMovements;

    /**
     * @ORM\OneToMany(targetEntity="ConvertInventoryItemInventorySerialNoEntity", mappedBy="convertInventoryItem")
     */
    protected $convertInventoryItemInventorySerialNos;

    /**
     * Set createdAt
     *
     * @ORM\PrePersist
     */
    public function setCreatedAtValue()
    {
        $this->createdBy = isSet($_COOKIE['username']) ? $_COOKIE['username'] : 'System';
        $this->createdAt = new \DateTime();
        $this->updatedBy = isSet($_COOKIE['username']) ? $_COOKIE['username'] : 'System';
        $this->updatedAt = new \DateTime();
    }

    /**
     * Set updatedAt
     *
     * @ORM\PreUpdate
     */
    public function setUpdatedAtValue()
    {
        $this->updatedBy = $_COOKIE['username'];
        $this->updatedAt = new \DateTime();
    }

    public function __construct($data=null)
    {
        if(!is_null($data)) {
            $this->id = $data->getId();
            $this->quantity = $data->getQuantity();
            $this->convertInventory = $data->getConvertInventory();
            $this->inventory = $data->getInventory();
        }

        $this->inventoryMovements = new ArrayCollection();
    }

    /*--------------------------------------------------------------------------------------------------------*/
    /*					User Defined Setters and Getters													  */
    /*--------------------------------------------------------------------------------------------------------*/

    public function getConvertInventoryItemInventorySerialNoByInventorySerialNoId($inventorySerialNo_id)
    {
        foreach ($this->getConvertInventoryItemInventorySerialNos() as $convertInventoryItemInventorySerialNo) {
            if($convertInventoryItemInventorySerialNo->getInventorySerialNo()->getId() == $inventorySerialNo_id)
                return $convertInventoryItemInventorySerialNo;
        }
        return null;
    }

    /*--------------------------------------------------------------------------------------------------------*/
    /*					Setters and Getters																	  */
    /*--------------------------------------------------------------------------------------------------------*/

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set quantity
     *
     * @param string $quantity
     * @return ConvertInventoryItemEntity
     */
    public function setQuantity($quantity)
    {
        $this->quantity = floatval(str_replace(',', '', $quantity));

        return $this;
    }

    /**
     * Get quantity
     *
     * @return float
     */
    public function getQuantity()
    {
        return $this->quantity;
    }

    /**
     * Set createdBy
     *
     * @param string $createdBy
     * @return ConvertInventoryItemEntity
     */
    public function setCreatedBy($createdBy)
    {
        $this->createdBy = $createdBy;

        return $this;
    }

    /**
     * Get createdBy
     *
     * @return string 
     */
    public function getCreatedBy()
    {
        return $this->createdBy;
    }

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return ConvertInventoryItemEntity
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updatedBy
     *
     * @param string $updatedBy
     * @return ConvertInventoryItemEntity
     */
    public function setUpdatedBy($updatedBy)
    {
        $this->updatedBy = $updatedBy;

        return $this;
    }

    /**
     * Get updatedBy
     *
     * @return string 
     */
    public function getUpdatedBy()
    {
        return $this->updatedBy;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return ConvertInventoryItemEntity
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }

    /**
     * Set convertInventory
     *
     * @param \RxConnexionBundle\Entity\ConvertInventoryEntity $convertInventory
     * @return ConvertInventoryItemEntity
     */
    public function setConvertInventory(\RxConnexionBundle\Entity\ConvertInventoryEntity $convertInventory = null)
    {
        $this->convertInventory = $convertInventory;

        return $this;
    }

    /**
     * Get convertInventory
     *
     * @return \RxConnexionBundle\Entity\ConvertInventoryEntity
     */
    public function getConvertInventory()
    {
        return $this->convertInventory;
    }

    /**
     * Set inventory
     *
     * @param \RxConnexionBundle\Entity\InventoryEntity $inventory
     * @return ConvertInventoryItemEntity
     */
    public function setInventory(\RxConnexionBundle\Entity\InventoryEntity $inventory = null)
    {
        $this->inventory = $inventory;

        return $this;
    }

    /**
     * Get inventory
     *
     * @return \RxConnexionBundle\Entity\InventoryEntity
     */
    public function getInventory()
    {
        return $this->inventory;
    }

    /**
     * Add inventoryMovements
     *
     * @param \RxConnexionBundle\Entity\InventoryMovementEntity $inventoryMovements
     * @return ConvertInventoryItemEntity
     */
    public function addInventoryMovement(\RxConnexionBundle\Entity\InventoryMovementEntity $inventoryMovements)
    {
        $this->inventoryMovements[] = $inventoryMovements;

        return $this;
    }

    /**
     * Remove inventoryMovements
     *
     * @param \RxConnexionBundle\Entity\InventoryMovementEntity $inventoryMovements
     */
    public function removeInventoryMovement(\RxConnexionBundle\Entity\InventoryMovementEntity $inventoryMovements)
    {
        $this->inventoryMovements->removeElement($inventoryMovements);
    }

    /**
     * Get inventoryMovements
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getInventoryMovements()
    {
        return $this->inventoryMovements;
    }

    /**
     * Set inventorySerialNo
     *
     * @param \RxConnexionBundle\Entity\InventorySerialNoEntity $inventorySerialNo
     *
     * @return ConvertInventoryItemEntity
     */
    public function setInventorySerialNo(\RxConnexionBundle\Entity\InventorySerialNoEntity $inventorySerialNo = null)
    {
        $this->inventorySerialNo = $inventorySerialNo;

        return $this;
    }

    /**
     * Get inventorySerialNo
     *
     * @return \RxConnexionBundle\Entity\InventorySerialNoEntity
     */
    public function getInventorySerialNo()
    {
        return $this->inventorySerialNo;
    }

    /**
     * Add convertInventoryItemInventorySerialNo
     *
     * @param \RxConnexionBundle\Entity\ConvertInventoryItemInventorySerialNoEntity $convertInventoryItemInventorySerialNo
     *
     * @return ConvertInventoryItemEntity
     */
    public function addConvertInventoryItemInventorySerialNo(\RxConnexionBundle\Entity\ConvertInventoryItemInventorySerialNoEntity $convertInventoryItemInventorySerialNo)
    {
        $this->convertInventoryItemInventorySerialNos[] = $convertInventoryItemInventorySerialNo;

        return $this;
    }

    /**
     * Remove convertInventoryItemInventorySerialNo
     *
     * @param \RxConnexionBundle\Entity\ConvertInventoryItemInventorySerialNoEntity $convertInventoryItemInventorySerialNo
     */
    public function removeConvertInventoryItemInventorySerialNo(\RxConnexionBundle\Entity\ConvertInventoryItemInventorySerialNoEntity $convertInventoryItemInventorySerialNo)
    {
        $this->convertInventoryItemInventorySerialNos->removeElement($convertInventoryItemInventorySerialNo);
    }

    /**
     * Get convertInventoryItemInventorySerialNos
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getConvertInventoryItemInventorySerialNos()
    {
        return $this->convertInventoryItemInventorySerialNos;
    }
}
