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

class InventoryMovementEntity
{
    /**
     * @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="source", type="string")
     */
    protected $source;

    /**
     * @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="InventoryEntity", inversedBy="inventoryMovements")
     * @ORM\JoinColumn(name="inventory_id", referencedColumnName="id")
     */
    protected $inventory;

//    /**
//     * @ORM\ManyToOne(targetEntity="PurchaseOrderBreakdownItemDeliveryEntity", inversedBy="inventoryMovements")
//     * @ORM\JoinColumn(name="purchase_order_breakdown_item_delivery_id", referencedColumnName="id")
//     */
//    protected $purchaseOrderBreakdownItemDelivery;

//    /**
//     * @ORM\ManyToOne(targetEntity="TransmittalItemEntity", inversedBy="inventoryMovements")
//     * @ORM\JoinColumn(name="transmittal_item_id", referencedColumnName="id")
//     */
//    protected $transmittalItem;

//    /**
//     * @ORM\ManyToOne(targetEntity="TransmittalItemDeliveryEntity", inversedBy="inventoryMovements")
//     * @ORM\JoinColumn(name="transmittal_item_delivery_id", referencedColumnName="id")
//     */
//    protected $transmittalItemDelivery;

    /**
     * @ORM\ManyToOne(targetEntity="AddInventoryItemEntity", inversedBy="inventoryMovements")
     * @ORM\JoinColumn(name="add_inventory_item_id", referencedColumnName="id")
     */
    protected $addInventoryItem;

//    /**
//     * @ORM\ManyToOne(targetEntity="UseInventoryItemEntity", inversedBy="inventoryMovements")
//     * @ORM\JoinColumn(name="use_inventory_item_id", referencedColumnName="id")
//     */
//    protected $useInventoryItem;

//    /**
//     * @ORM\ManyToOne(targetEntity="ConvertInventoryItemEntity", inversedBy="inventoryMovements")
//     * @ORM\JoinColumn(name="convert_inventory_item_id", referencedColumnName="id")
//     */
//    protected $convertInventoryItem;
//
//    /**
//     * @ORM\ManyToOne(targetEntity="ConvertInventoryItemBiEntity", inversedBy="inventoryMovements")
//     * @ORM\JoinColumn(name="convert_inventory_item_bi_id", referencedColumnName="id")
//     */
//    protected $convertInventoryItemBi;
//
    /**
     * @ORM\ManyToOne(targetEntity="TransferInventoryItemEntity", inversedBy="inventoryMovements")
     * @ORM\JoinColumn(name="transfer_inventory_item_id", referencedColumnName="id")
     */
    protected $transferInventoryItem;

    /**
     * @ORM\ManyToOne(targetEntity="TransferInventoryDeliveryItemEntity", inversedBy="inventoryMovements")
     * @ORM\JoinColumn(name="transfer_inventory_delivery_item_id", referencedColumnName="id")
     */
    protected $transferInventoryDeliveryItem;

    /**
     * @ORM\ManyToOne(targetEntity="TransferInventoryItemDeliveryEntity", inversedBy="inventoryMovements")
     * @ORM\JoinColumn(name="transfer_inventory_item_delivery_id", referencedColumnName="id")
     */
    protected $transferInventoryItemDelivery;
//
//    /**
//     * @ORM\ManyToOne(targetEntity="SalesOrderInventoryEntity", inversedBy="inventoryMovements")
//     * @ORM\JoinColumn(name="sales_order_inventory_id", referencedColumnName="id")
//     */
//    protected $salesOrderInventory;
//
//    /**
//     * @ORM\ManyToOne(targetEntity="SalesOrderReturnItemEntity", inversedBy="inventoryMovements")
//     * @ORM\JoinColumn(name="sales_order_return_item_id", referencedColumnName="id")
//     */
//    protected $salesOrderReturnItem;
//
//    /**
//     * @ORM\ManyToOne(targetEntity="JobOrderInventoryEntity", inversedBy="inventoryMovements")
//     * @ORM\JoinColumn(name="job_order_inventory_id", referencedColumnName="id")
//     */
//    protected $jobOrderInventory;

    /**
     * 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->source = $data->getSource();
            $this->inventory = $data->getInventory();
//            $this->purchaseOrderBreakdownItemDelivery = $data->getPurchaseOrderBreakdownItemDelivery();
//            $this->transmittalItem = $data->getTransmittalItem();
//            $this->transmittalItemDelivery = $data->getTransmittalItemDelivery();
            $this->addInventoryItem = $data->getAddInventoryItem();
//            $this->useInventoryItem = $data->getUseInventoryItem();
//            $this->convertInventoryItem = $data->getConvertInventoryItem();
//            $this->convertInventoryItemBi = $data->getConvertInventoryItemBi();
            $this->transferInventoryItem = $data->getTransferInventoryItem();
            $this->transferInventoryDeliveryItem  = $data->getTransferInventoryDeliveryItem();
            $this->transferInventoryItemDelivery  = $data->getTransferInventoryItemDelivery();
//            $this->salesOrderInventory = $data->getSalesOrderInventory();
//            $this->salesOrderReturnItem = $data->getSalesOrderReturnItem();
//            $this->jobOrderInventory = $data->getJobOrderInventory();
        }
    }

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

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


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

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

        return $this;
    }

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

    /**
     * Set source
     *
     * @param string $source
     *
     * @return InventoryMovementEntity
     */
    public function setSource($source)
    {
        $this->source = $source;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set inventory
     *
     * @param \RxConnexionBundle\Entity\InventoryEntity $inventory
     *
     * @return InventoryMovementEntity
     */
    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;
    }

    /**
     * Set addInventoryItem
     *
     * @param \RxConnexionBundle\Entity\AddInventoryItemEntity $addInventoryItem
     *
     * @return InventoryMovementEntity
     */
    public function setAddInventoryItem(\RxConnexionBundle\Entity\AddInventoryItemEntity $addInventoryItem = null)
    {
        $this->addInventoryItem = $addInventoryItem;

        return $this;
    }

    /**
     * Get addInventoryItem
     *
     * @return \RxConnexionBundle\Entity\AddInventoryItemEntity
     */
    public function getAddInventoryItem()
    {
        return $this->addInventoryItem;
    }

    /**
     * Set transferInventoryItem
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryItemEntity $transferInventoryItem
     *
     * @return InventoryMovementEntity
     */
    public function setTransferInventoryItem(\RxConnexionBundle\Entity\TransferInventoryItemEntity $transferInventoryItem = null)
    {
        $this->transferInventoryItem = $transferInventoryItem;

        return $this;
    }

    /**
     * Get transferInventoryItem
     *
     * @return \RxConnexionBundle\Entity\TransferInventoryItemEntity
     */
    public function getTransferInventoryItem()
    {
        return $this->transferInventoryItem;
    }

    /**
     * Set transferInventoryDeliveryItem
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryDeliveryItemEntity $transferInventoryDeliveryItem
     *
     * @return InventoryMovementEntity
     */
    public function setTransferInventoryDeliveryItem(\RxConnexionBundle\Entity\TransferInventoryDeliveryItemEntity $transferInventoryDeliveryItem = null)
    {
        $this->transferInventoryDeliveryItem = $transferInventoryDeliveryItem;

        return $this;
    }

    /**
     * Get transferInventoryDeliveryItem
     *
     * @return \RxConnexionBundle\Entity\TransferInventoryDeliveryItemEntity
     */
    public function getTransferInventoryDeliveryItem()
    {
        return $this->transferInventoryDeliveryItem;
    }

    /**
     * Set transferInventoryItemDelivery
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryItemDeliveryEntity $transferInventoryItemDelivery
     *
     * @return InventoryMovementEntity
     */
    public function setTransferInventoryItemDelivery(\RxConnexionBundle\Entity\TransferInventoryItemDeliveryEntity $transferInventoryItemDelivery = null)
    {
        $this->transferInventoryItemDelivery = $transferInventoryItemDelivery;

        return $this;
    }

    /**
     * Get transferInventoryItemDelivery
     *
     * @return \RxConnexionBundle\Entity\TransferInventoryItemDeliveryEntity
     */
    public function getTransferInventoryItemDelivery()
    {
        return $this->transferInventoryItemDelivery;
    }
}
