<?php

namespace RxConnexionBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\CurrencyRepository")
 * @ORM\Table(name="currency", indexes={@ORM\Index(name="IDX_SEARCH_000", columns={"description"})})
 * @ORM\HasLifecycleCallbacks()
 */
 
class CurrencyEntity
{
    /**
     * @ORM\Column(type="bigint")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
	protected $id;

    /**
     * @ORM\Column(name="code", type="string", nullable=true)
     */
	protected $code;
	
    /**
     * @ORM\Column(name="description", type="string")
     */
	protected $description;
	
    /**
     * @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\OneToMany(targetEntity="CanvassItemSupplierEntity", mappedBy="currency")
     */
    protected $canvassItemSuppliers;

    /**
     * @ORM\OneToMany(targetEntity="PurchaseOrderEntity", mappedBy="currency")
     */
    protected $purchaseOrders;
  
    /** 
     * 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()
    {
//        $this->canvassItemSuppliers = new ArrayCollection();
        $this->purchaseOrders = new ArrayCollection();
    }

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

    /**
     * Get idEncoded
     *
     * @return string
     */
    public function getIdEncoded() {

        return base64_encode($this->id);
    }
    
	/*--------------------------------------------------------------------------------------------------------*/
	/*					Setters and Getters																	  */
	/*--------------------------------------------------------------------------------------------------------*/

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

    /**
     * Set code
     *
     * @param string $code
     * @return CurrencyEntity
     */
    public function setCode($code)
    {
        $this->code = $code;
    
        return $this;
    }

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

    /**
     * Set description
     *
     * @param string $description
     * @return CurrencyEntity
     */
    public function setDescription($description)
    {
        $this->description = $description;
    
        return $this;
    }

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

    /**
     * Set createdBy
     *
     * @param string $createdBy
     * @return CurrencyEntity
     */
    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 CurrencyEntity
     */
    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 CurrencyEntity
     */
    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 CurrencyEntity
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;
    
        return $this;
    }

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

    /**
     * Add canvassItemSuppliers
     *
     * @param \RxConnexionBundle\Entity\CanvassItemSupplierEntity $canvassItemSuppliers
     * @return CurrencyEntity
     */
    public function addCanvassItemSupplier(\RxConnexionBundle\Entity\CanvassItemSupplierEntity $canvassItemSuppliers)
    {
        $this->canvassItemSuppliers[] = $canvassItemSuppliers;
    
        return $this;
    }

    /**
     * Remove canvassItemSuppliers
     *
     * @param \RxConnexionBundle\Entity\CanvassItemSupplierEntity $canvassItemSuppliers
     */
    public function removeCanvassItemSupplier(\RxConnexionBundle\Entity\CanvassItemSupplierEntity $canvassItemSuppliers)
    {
        $this->canvassItemSuppliers->removeElement($canvassItemSuppliers);
    }

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

    /**
     * Add purchaseOrders
     *
     * @param \RxConnexionBundle\Entity\PurchaseOrderEntity $purchaseOrders
     * @return CurrencyEntity
     */
    public function addPurchaseOrder(\RxConnexionBundle\Entity\PurchaseOrderEntity $purchaseOrders)
    {
        $this->purchaseOrders[] = $purchaseOrders;
    
        return $this;
    }

    /**
     * Remove purchaseOrders
     *
     * @param \RxConnexionBundle\Entity\PurchaseOrderEntity $purchaseOrders
     */
    public function removePurchaseOrder(\RxConnexionBundle\Entity\PurchaseOrderEntity $purchaseOrders)
    {
        $this->purchaseOrders->removeElement($purchaseOrders);
    }

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