<?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\ConvertInventoryItemBiRepository")
 * @ORM\Table(name="convert_inventory_item_bi")
 * @ORM\HasLifecycleCallbacks()
 */

class ConvertInventoryItemBiEntity
{
    /**
     * @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="total_cost", type="decimal", precision=12, scale=2, nullable=true)
     */
    protected $totalCost;

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

    /**
     * @ORM\Column(name="serial_no", type="string", length=50, nullable=true)
     */
    protected $serialNo;

    /**
     * @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="convertInventoryItemBis")
     * @ORM\JoinColumn(name="convert_inventory_id", referencedColumnName="id")
     */
    protected $convertInventory;

    /**
     * @ORM\ManyToOne(targetEntity="ItemEntity", inversedBy="convertInventoryItemBis")
     * @ORM\JoinColumn(name="item_id", referencedColumnName="id")
     */
    protected $item;

    /**
     * @ORM\ManyToOne(targetEntity="LocationEntity", inversedBy="convertInventoryItemBis")
     * @ORM\JoinColumn(name="location_id", referencedColumnName="id")
     */
    protected $location;

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

    /**
     * @ORM\OneToMany(targetEntity="InventoryPriceEntity", mappedBy="convertInventoryItemBi")
     */
    protected $inventoryPrices;

    /**
     * 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->totalCost = $data->getTotalCost();
            $this->convertInventory = $data->getConvertInventory();
            $this->item = $data->getItem();
            $this->location = $data->getLocation();
        }

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

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

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

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

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

        return $this;
    }

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

    /**
     * Set createdBy
     *
     * @param string $createdBy
     * @return ConvertInventoryItemBiEntity
     */
    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 ConvertInventoryItemBiEntity
     */
    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 ConvertInventoryItemBiEntity
     */
    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 ConvertInventoryItemBiEntity
     */
    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 ConvertInventoryItemBiEntity
     */
    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 item
     *
     * @param \RxConnexionBundle\Entity\ItemEntity $item
     * @return ConvertInventoryItemBiEntity
     */
    public function setItem(\RxConnexionBundle\Entity\ItemEntity $item = null)
    {
        $this->item = $item;
    
        return $this;
    }

    /**
     * Get item
     *
     * @return \RxConnexionBundle\Entity\ItemEntity
     */
    public function getItem()
    {
        return $this->item;
    }

    /**
     * Set location
     *
     * @param \RxConnexionBundle\Entity\LocationEntity $location
     * @return ConvertInventoryItemBiEntity
     */
    public function setLocation(\RxConnexionBundle\Entity\LocationEntity $location = null)
    {
        $this->location = $location;
    
        return $this;
    }

    /**
     * Get location
     *
     * @return \RxConnexionBundle\Entity\LocationEntity
     */
    public function getLocation()
    {
        return $this->location;
    }

    /**
     * Add inventoryMovements
     *
     * @param \RxConnexionBundle\Entity\InventoryMovementEntity $inventoryMovements
     * @return ConvertInventoryItemBiEntity
     */
    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 totalCost
     *
     * @param string $totalCost
     * @return ConvertInventoryItemBiEntity
     */
    public function setTotalCost($totalCost)
    {
        $this->totalCost = str_replace(',', '', $totalCost);
    
        return $this;
    }

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

    /**
     * Add inventoryPrices
     *
     * @param \RxConnexionBundle\Entity\InventoryPriceEntity $inventoryPrices
     * @return ConvertInventoryItemBiEntity
     */
    public function addInventoryPrice(\RxConnexionBundle\Entity\InventoryPriceEntity $inventoryPrices)
    {
        $this->inventoryPrices[] = $inventoryPrices;
    
        return $this;
    }

    /**
     * Remove inventoryPrices
     *
     * @param \RxConnexionBundle\Entity\InventoryPriceEntity $inventoryPrices
     */
    public function removeInventoryPrice(\RxConnexionBundle\Entity\InventoryPriceEntity $inventoryPrices)
    {
        $this->inventoryPrices->removeElement($inventoryPrices);
    }

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

    /**
     * Add convertInventoryItemBiInventorySerialNo
     *
     * @param \RxConnexionBundle\Entity\ConvertInventoryItemInventorySerialNoEntity $convertInventoryItemBiInventorySerialNo
     *
     * @return ConvertInventoryItemBiEntity
     */
    public function addConvertInventoryItemBiInventorySerialNo(\RxConnexionBundle\Entity\ConvertInventoryItemInventorySerialNoEntity $convertInventoryItemBiInventorySerialNo)
    {
        $this->convertInventoryItemBiInventorySerialNos[] = $convertInventoryItemBiInventorySerialNo;

        return $this;
    }

    /**
     * Remove convertInventoryItemBiInventorySerialNo
     *
     * @param \RxConnexionBundle\Entity\ConvertInventoryItemInventorySerialNoEntity $convertInventoryItemBiInventorySerialNo
     */
    public function removeConvertInventoryItemBiInventorySerialNo(\RxConnexionBundle\Entity\ConvertInventoryItemInventorySerialNoEntity $convertInventoryItemBiInventorySerialNo)
    {
        $this->convertInventoryItemBiInventorySerialNos->removeElement($convertInventoryItemBiInventorySerialNo);
    }

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

    /**
     * Set serialNo
     *
     * @param string $serialNo
     *
     * @return ConvertInventoryItemBiEntity
     */
    public function setSerialNo($serialNo)
    {
        $this->serialNo = $serialNo;

        return $this;
    }

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