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

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

    /**
     * @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="AddInventoryEntity", inversedBy="addInventoryItems")
     * @ORM\JoinColumn(name="add_inventory_id", referencedColumnName="id")
     */
    protected $addInventory;

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

    /**
     * @ORM\ManyToOne(targetEntity="RxConnexionBundle\Entity\LocationEntity", inversedBy="addInventoryItems")
     * @ORM\JoinColumn(name="location_id", referencedColumnName="id")
     */
    protected $location;
//    /**
//     * @ORM\ManyToOne(targetEntity="ItemUnitMeasurementEntity", inversedBy="addInventoryItems")
//     * @ORM\JoinColumn(name="item_unit_measurement_id", referencedColumnName="id")
//     */
//    protected $itemUnitMeasurement;

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

    /**
     * @ORM\OneToMany(targetEntity="InventoryPriceEntity", mappedBy="addInventoryItem")
     */
    protected $inventoryPrices;
//
//    /**
//     * @ORM\OneToMany(targetEntity="AddInventoryItemUnitMeasurementEntity", mappedBy="addInventoryItem", cascade={"remove"})
//     */
//    protected $addInventoryItemUnitMeasurements;

    /**
     * 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->price = $data->getPrice();
            $this->addInventory = $data->getAddInventory();
            $this->item = $data->getItem();
            $this->location = $data->getLocation();
//            $this->itemUnitMeasurement = $data->getItemUnitMeasurment();
        }

        $this->inventoryMovements = new ArrayCollection();
        $this->inventoryPrices = new ArrayCollection();
//        $this->materialRequisitionItemUnitMeasurements = new ArrayCollection();
//        $this->addInventoryItemUnitMeasurements = 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 AddInventoryItemEntity
     */
    public function setQuantity($quantity)
    {
        $this->quantity = str_replace(',', '', $quantity);

        return $this;
    }

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

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

        return $this;
    }

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


    /**
     * Set price
     *
     * @param string $price
     *
     * @return AddInventoryItemEntity
     */
    public function setPrice($price)
    {
        $this->price = $price;

        return $this;
    }

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

    /**
     * Set addInventory
     *
     * @param \RxConnexionBundle\Entity\AddInventoryEntity $addInventory
     *
     * @return AddInventoryItemEntity
     */
    public function setAddInventory(\RxConnexionBundle\Entity\AddInventoryEntity $addInventory = null)
    {
        $this->addInventory = $addInventory;

        return $this;
    }

    /**
     * Get addInventory
     *
     * @return \RxConnexionBundle\Entity\AddInventoryEntity
     */
    public function getAddInventory()
    {
        return $this->addInventory;
    }

    /**
     * Set item
     *
     * @param \RxConnexionBundle\Entity\ItemEntity $item
     *
     * @return AddInventoryItemEntity
     */
    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 AddInventoryItemEntity
     */
    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 inventoryMovement
     *
     * @param \RxConnexionBundle\Entity\InventoryMovementEntity $inventoryMovement
     *
     * @return AddInventoryItemEntity
     */
    public function addInventoryMovement(\RxConnexionBundle\Entity\InventoryMovementEntity $inventoryMovement)
    {
        $this->inventoryMovements[] = $inventoryMovement;

        return $this;
    }

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

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

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

        return $this;
    }

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

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