<?php

namespace RxConnexionBundle\Entity;

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

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\LocationRepository")
 * @ORM\Table(name="location")
 * @ORM\HasLifecycleCallbacks()
 */
 
class LocationEntity
{
    /**
     * @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\ManyToOne(targetEntity="RxConnexionBundle\Entity\HealthFacilityEntity", inversedBy="locations")
     * @ORM\JoinColumn(name="health_facility_id", referencedColumnName="id")
     */
    protected $healthFacility;

//    /**
//     * @ORM\OneToOne(targetEntity="ProjectManagementEntity", inversedBy="location")
//     * @ORM\JoinColumn(name="project_management_id", referencedColumnName="id")
//     */
//    protected $projectManagement;

    /**
     * @ORM\OneToMany(targetEntity="InventoryEntity", mappedBy="location")
     */
    protected $inventories;

//    /**
//     * @ORM\OneToMany(targetEntity="FixedAssetEntity", mappedBy="location")
//     */
//    protected $fixedAssets;

    /**
     * @ORM\OneToMany(targetEntity="AddInventoryItemEntity", mappedBy="location")
     */
    protected $addInventoryItems;

//    /**
//     * @ORM\OneToMany(targetEntity="AddFixedAssetItemEntity", mappedBy="location")
//     */
//    protected $addFixedAssetItems;

    /**
     * @ORM\OneToMany(targetEntity="ConvertInventoryItemBiEntity", mappedBy="location")
     */
    protected $convertInventoryItemBis;

    /**
     * @ORM\OneToMany(targetEntity="MaterialRequisitionItemEntity", mappedBy="location")
     */
    protected $materialRequisitionItems;

    /**
     * @ORM\OneToMany(targetEntity="PurchaseOrderBreakdownItemDeliveryEntity", mappedBy="location")
     */
    protected $purchaseOrderBreakdownItemDeliveries;
//
//    /**
//     * @ORM\OneToMany(targetEntity="TransmittalItemDeliveryEntity", mappedBy="location")
//     */
//    protected $transmittalItemDeliveries;
//
    /**
     * @ORM\OneToMany(targetEntity="TransferInventoryItemDeliveryEntity", mappedBy="location")
     */
    protected $transferInventoryItemDeliveries;
//
//    /**
//     * @ORM\OneToMany(targetEntity="SalesOrderReturnItemEntity", mappedBy="location")
//     */
//    protected $salesOrderReturnItems;
//
    /**
     * @ORM\OneToMany(targetEntity="TransferInventoryEntity", mappedBy="locationFrom")
     */
    protected $transferInventoryLocationsFrom;

    /**
     * @ORM\OneToMany(targetEntity="TransferInventoryEntity", mappedBy="locationTo")
     */
    protected $transferInventoryLocationsTo;

    /**
     * @ORM\OneToMany(targetEntity="RxConnexionBundle\Entity\AccountUserLocationEntity", mappedBy="location")
     */
    protected $accountUserLocations;

    /** 
     * 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->code = $data->getCode();
            $this->description = $data->getDescription();
            $this->healthFacility = $data->getBranch();
    	}

    	$this->inventories = new ArrayCollection();
//        $this->fixedAssets = new ArrayCollection();
        $this->addInventoryItems = new ArrayCollection();
//    	$this->addFixedAssetItems = new ArrayCollection();
//    	$this->convertInventoryItemBis = new ArrayCollection();
//    	$this->materialRequisitionItems = new ArrayCollection();
//    	$this->purchaseOrderBreakdownItemDeliveries = new ArrayCollection();
//    	$this->transmittalItemDeliveries = new ArrayCollection();
    	$this->transferInventoryItemDeliveries = new ArrayCollection();
    	$this->transferInventoryLocationsFrom = new ArrayCollection();
    	$this->transferInventoryLocationsTo = new ArrayCollection();
//    	$this->salesOrderReturnItems = 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 LocationEntity
     */
    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 LocationEntity
     */
    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 LocationEntity
     */
    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 LocationEntity
     */
    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 LocationEntity
     */
    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 LocationEntity
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

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

    /**
     * Set branch
     *
     * @param \RxConnexionBundle\Entity\BranchEntity $branch
     *
     * @return LocationEntity
     */
    public function setBranch(\RxConnexionBundle\Entity\BranchEntity $branch = null)
    {
        $this->branch = $branch;

        return $this;
    }

    /**
     * Get branch
     *
     * @return \RxConnexionBundle\Entity\BranchEntity
     */
    public function getBranch()
    {
        return $this->branch;
    }

    /**
     * Add inventory
     *
     * @param \RxConnexionBundle\Entity\InventoryEntity $inventory
     *
     * @return LocationEntity
     */
    public function addInventory(\RxConnexionBundle\Entity\InventoryEntity $inventory)
    {
        $this->inventories[] = $inventory;

        return $this;
    }

    /**
     * Remove inventory
     *
     * @param \RxConnexionBundle\Entity\InventoryEntity $inventory
     */
    public function removeInventory(\RxConnexionBundle\Entity\InventoryEntity $inventory)
    {
        $this->inventories->removeElement($inventory);
    }

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

    /**
     * Add addInventoryItem
     *
     * @param \RxConnexionBundle\Entity\AddInventoryItemEntity $addInventoryItem
     *
     * @return LocationEntity
     */
    public function addAddInventoryItem(\RxConnexionBundle\Entity\AddInventoryItemEntity $addInventoryItem)
    {
        $this->addInventoryItems[] = $addInventoryItem;

        return $this;
    }

    /**
     * Remove addInventoryItem
     *
     * @param \RxConnexionBundle\Entity\AddInventoryItemEntity $addInventoryItem
     */
    public function removeAddInventoryItem(\RxConnexionBundle\Entity\AddInventoryItemEntity $addInventoryItem)
    {
        $this->addInventoryItems->removeElement($addInventoryItem);
    }

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

    /**
     * Set healthFacility
     *
     * @param \RxConnexionBundle\Entity\HealthFacilityEntity $healthFacility
     *
     * @return LocationEntity
     */
    public function setHealthFacility(\RxConnexionBundle\Entity\HealthFacilityEntity $healthFacility = null)
    {
        $this->healthFacility = $healthFacility;

        return $this;
    }

    /**
     * Get healthFacility
     *
     * @return \RxConnexionBundle\Entity\HealthFacilityEntity
     */
    public function getHealthFacility()
    {
        return $this->healthFacility;
    }

    /**
     * Add transferInventoryItemDelivery
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryItemDeliveryEntity $transferInventoryItemDelivery
     *
     * @return LocationEntity
     */
    public function addTransferInventoryItemDelivery(\RxConnexionBundle\Entity\TransferInventoryItemDeliveryEntity $transferInventoryItemDelivery)
    {
        $this->transferInventoryItemDeliveries[] = $transferInventoryItemDelivery;

        return $this;
    }

    /**
     * Remove transferInventoryItemDelivery
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryItemDeliveryEntity $transferInventoryItemDelivery
     */
    public function removeTransferInventoryItemDelivery(\RxConnexionBundle\Entity\TransferInventoryItemDeliveryEntity $transferInventoryItemDelivery)
    {
        $this->transferInventoryItemDeliveries->removeElement($transferInventoryItemDelivery);
    }

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

    /**
     * Add transferInventoryLocationsFrom
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryEntity $transferInventoryLocationsFrom
     *
     * @return LocationEntity
     */
    public function addTransferInventoryLocationsFrom(\RxConnexionBundle\Entity\TransferInventoryEntity $transferInventoryLocationsFrom)
    {
        $this->transferInventoryLocationsFrom[] = $transferInventoryLocationsFrom;

        return $this;
    }

    /**
     * Remove transferInventoryLocationsFrom
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryEntity $transferInventoryLocationsFrom
     */
    public function removeTransferInventoryLocationsFrom(\RxConnexionBundle\Entity\TransferInventoryEntity $transferInventoryLocationsFrom)
    {
        $this->transferInventoryLocationsFrom->removeElement($transferInventoryLocationsFrom);
    }

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

    /**
     * Add transferInventoryLocationsTo
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryEntity $transferInventoryLocationsTo
     *
     * @return LocationEntity
     */
    public function addTransferInventoryLocationsTo(\RxConnexionBundle\Entity\TransferInventoryEntity $transferInventoryLocationsTo)
    {
        $this->transferInventoryLocationsTo[] = $transferInventoryLocationsTo;

        return $this;
    }

    /**
     * Remove transferInventoryLocationsTo
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryEntity $transferInventoryLocationsTo
     */
    public function removeTransferInventoryLocationsTo(\RxConnexionBundle\Entity\TransferInventoryEntity $transferInventoryLocationsTo)
    {
        $this->transferInventoryLocationsTo->removeElement($transferInventoryLocationsTo);
    }

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

    /**
     * Add purchaseOrderBreakdownItemDelivery
     *
     * @param \RxConnexionBundle\Entity\PurchaseOrderBreakdownItemDeliveryEntity $purchaseOrderBreakdownItemDelivery
     *
     * @return LocationEntity
     */
    public function addPurchaseOrderBreakdownItemDelivery(\RxConnexionBundle\Entity\PurchaseOrderBreakdownItemDeliveryEntity $purchaseOrderBreakdownItemDelivery)
    {
        $this->purchaseOrderBreakdownItemDeliveries[] = $purchaseOrderBreakdownItemDelivery;

        return $this;
    }

    /**
     * Remove purchaseOrderBreakdownItemDelivery
     *
     * @param \RxConnexionBundle\Entity\PurchaseOrderBreakdownItemDeliveryEntity $purchaseOrderBreakdownItemDelivery
     */
    public function removePurchaseOrderBreakdownItemDelivery(\RxConnexionBundle\Entity\PurchaseOrderBreakdownItemDeliveryEntity $purchaseOrderBreakdownItemDelivery)
    {
        $this->purchaseOrderBreakdownItemDeliveries->removeElement($purchaseOrderBreakdownItemDelivery);
    }

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

    /**
     * Add materialRequisitionItem
     *
     * @param \RxConnexionBundle\Entity\MaterialRequisitionItemEntity $materialRequisitionItem
     *
     * @return LocationEntity
     */
    public function addMaterialRequisitionItem(\RxConnexionBundle\Entity\MaterialRequisitionItemEntity $materialRequisitionItem)
    {
        $this->materialRequisitionItems[] = $materialRequisitionItem;

        return $this;
    }

    /**
     * Remove materialRequisitionItem
     *
     * @param \RxConnexionBundle\Entity\MaterialRequisitionItemEntity $materialRequisitionItem
     */
    public function removeMaterialRequisitionItem(\RxConnexionBundle\Entity\MaterialRequisitionItemEntity $materialRequisitionItem)
    {
        $this->materialRequisitionItems->removeElement($materialRequisitionItem);
    }

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

    /**
     * Add accountUserLocation
     *
     * @param \RxConnexionBundle\Entity\AccountUserLocationEntity $accountUserLocation
     *
     * @return LocationEntity
     */
    public function addAccountUserLocation(\RxConnexionBundle\Entity\AccountUserLocationEntity $accountUserLocation)
    {
        $this->accountUserLocations[] = $accountUserLocation;

        return $this;
    }

    /**
     * Remove accountUserLocation
     *
     * @param \RxConnexionBundle\Entity\AccountUserLocationEntity $accountUserLocation
     */
    public function removeAccountUserLocation(\RxConnexionBundle\Entity\AccountUserLocationEntity $accountUserLocation)
    {
        $this->accountUserLocations->removeElement($accountUserLocation);
    }

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

    /**
     * Add convertInventoryItemBi
     *
     * @param \RxConnexionBundle\Entity\ConvertInventoryItemBiEntity $convertInventoryItemBi
     *
     * @return LocationEntity
     */
    public function addConvertInventoryItemBi(\RxConnexionBundle\Entity\ConvertInventoryItemBiEntity $convertInventoryItemBi)
    {
        $this->convertInventoryItemBis[] = $convertInventoryItemBi;

        return $this;
    }

    /**
     * Remove convertInventoryItemBi
     *
     * @param \RxConnexionBundle\Entity\ConvertInventoryItemBiEntity $convertInventoryItemBi
     */
    public function removeConvertInventoryItemBi(\RxConnexionBundle\Entity\ConvertInventoryItemBiEntity $convertInventoryItemBi)
    {
        $this->convertInventoryItemBis->removeElement($convertInventoryItemBi);
    }

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