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

class MaterialRequisitionEntity
{
    /**
     * @ORM\Column(type="bigint")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(name="material_requisition_no", type="string", nullable=true)
     */
    protected $materialRequisitionNo;

    /**
     * @ORM\Column(name="reference_no", type="string", nullable=true)
     */
    protected $referenceNo;

    /**
     * @ORM\Column(name="title", type="string", nullable=true)
     */
    protected $title;

    /**
     * @ORM\Column(name="request_date", type="datetime")
     */
    protected $requestDate;

    /**
     * @ORM\Column(name="required_date", type="datetime")
     */
    protected $requiredDate;

    /**
     * @ORM\Column(name="canvass_type", type="string", nullable=true)
     */
    protected $canvassType;

    /**
     * @ORM\Column(name="specific_purpose", type="text", nullable=true)
     */
    protected $specificPurpose;

    /**
     * @ORM\Column(name="note", type="text", nullable=true)
     */
    protected $note;

    /**
     * @ORM\Column(name="status", type="string", nullable=true)
     */
    protected $status;

    /**
     * @ORM\Column(name="approval_batch_no", type="integer")
     */
    protected $approvalBatchNo;

    /**
     * @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="HealthFacilityEntity", inversedBy="materialRequisitions")
     * @ORM\JoinColumn(name="health_facility_id", referencedColumnName="id")
     */
    protected $healthFacility;

//    /**
//     * @ORM\ManyToOne(targetEntity="DepartmentEntity", inversedBy="materialRequisitions")
//     * @ORM\JoinColumn(name="department_id", referencedColumnName="id")
//     */
//    protected $department;

    /**
     * @ORM\ManyToOne(targetEntity="RxConnexionBundle\Entity\AccountUserEntity", inversedBy="materialRequisitions")
     * @ORM\JoinColumn(name="account_user_id", referencedColumnName="id")
     */
    protected $accountUser;

    /**
     * @ORM\ManyToOne(targetEntity="PurposeEntity", inversedBy="materialRequisitions")
     * @ORM\JoinColumn(name="purpose_id", referencedColumnName="id")
     */
    protected $purpose;

    /**
     * @ORM\OneToMany(targetEntity="MaterialRequisitionStatusEntity", mappedBy="materialRequisition")
     */
    protected $materialRequisitionStatuses;

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

    /**
     * @ORM\OneToMany(targetEntity="CanvassEntity", mappedBy="materialRequisition")
     */
    protected $canvasses;

    /**
     * @ORM\OneToMany(targetEntity="PurchaseOrderEntity", mappedBy="materialRequisition")
     */
    protected $purchaseOrders;

    /**
     * @ORM\OneToMany(targetEntity="MaterialRequisitionNoteEntity", mappedBy="materialRequisition", cascade={"remove"})
     */
    protected $materialRequisitionNotes;

    /**
     * @ORM\OneToMany(targetEntity="TransferInventoryMatReqEntity", mappedBy="materialRequisition")
     */
    protected $transferInventoryMatReqs;

    /**
     * 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();
        $this->status = 'New';
        $this->approvalBatchNo = 0;
    }

    /**
     * Set updatedAt
     *
     * @ORM\PreUpdate
     */
    public function setUpdatedAtValue()
    {
        $this->updatedBy = $_COOKIE['username'];
        $this->updatedAt = new \DateTime();
    }

    public function updateStatus() {

        if($this->status === 'Active' || $this->status === 'Closed') {

            $isClosable = true;

            foreach($this->canvasses as $canvass) {
                if($canvass->getStatus() !== 'Approved' && $canvass->getStatus() !== 'Voided') $isClosable = false;
            }

            foreach($this->purchaseOrders as $purchaseOrder) {
                if($purchaseOrder->getStatus() !== 'Received' && $purchaseOrder->getStatus() !== 'Voided') $isClosable = false;
            }

            if($this->getHasQuantityForTransmittal()) $isClosable = false;

            $this->status = $isClosable ? 'Closed' : 'Active';
        }

        return $this;
    }

    public function doVoid() {

        $this->status = 'Voided';

        if(count($this->canvasses)) {

            foreach($this->canvasses as $canvass)
                $canvass->setStatus('Voided');
        }

        return $this;
    }

    public function doCancel() {

        foreach($this->canvasses as $canvass) {
            if($canvass->getStatus() === 'Supplier Canvassing') $canvass->setStatus('Cancelled');
        }

        $this->status = 'New';

        return $this;
    }

    public function doCancelPurchaseOrder(){

        foreach ($this->purchaseOrders as $purchaseOrder){
            $purchaseOrder->setStatus('Cancelled');
        }

        foreach ($this->canvasses as $canvass){
            $canvass->setStatus('Supplier Canvassing');
        }

        return $this;
    }

    public function updateQuantityCanvassed() {

        foreach($this->materialRequisitionItems as $materialRequisitionItem) {
            $materialRequisitionItem->updateQuantityCanvassed();
        }

        return $this;
    }

    public function updateQuantityVoided() {

        foreach($this->materialRequisitionItems as $materialRequisitionItem) {
            $materialRequisitionItem->updateQuantityVoided();
        }

        return $this;
    }

    public function __construct($data=null)
    {
        if(!is_null($data)) {
            $this->id = $data->getId();
            $this->materialRequisitionNo = $data->getMaterialRequisitionNo();
            $this->referenceNo = $data->getReferenceNo();
            $this->title = $data->getTitle();
            $this->requestDate = $data->getRequestDateAsString();
            $this->canvassType = $data->getCanvassType();
            $this->specificPurpose = $data->getSpecificPurpose();
            $this->note = $data->getNote();
            $this->status = $data->getStatus();
            $this->approvalBatchNo = $data->getApprovalBatchNo();
            $this->healthFacility = $data->getHealthFacility();
            $this->accountUser = $data->getAccountUser();
            $this->purpose = $data->getPurpose();
            $this->requiredDate = $data->getRequiredDateAsString();
        }

        $this->materialRequisitionStatuses = new ArrayCollection();
        $this->materialRequisitionItems = new ArrayCollection();
        $this->canvasses = new ArrayCollection();
        $this->purchaseOrders = new ArrayCollection();
    }

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

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

        return base64_encode($this->id);
    }

    /**
     * Get materialRequisitionItemById
     *
     * @param $id
     * @return \RxConnexionBundle\Entity\MaterialRequisitionItemEntity|null
     */
    public function getMaterialRequisitionItemById($id) {

        $materialRequisitionItem = null;

        foreach($this->materialRequisitionItems as $materialRequisitionItem_obj) {
            if($materialRequisitionItem_obj->getId() == $id) {
                $materialRequisitionItem = $materialRequisitionItem_obj;
                break;
            }
        }

        return $materialRequisitionItem;
    }

    /**
     * @param array $userData
     *
     * @return boolean
     */
    public function canApproveByUser($userData) {

        $canApproveByUser = false;
        $isAlreadyApproved = false;

        switch($this->status) {
            case 'Pending Branch Manager Approval':

                switch($userData['type']) {
                    case 'Super Admin':
                    case 'Admin':
                        $canApproveByUser = true;
                        break;
                    case 'Branch Manager':

                        foreach($this->materialRequisitionStatuses as $materialRequisitionStatus) {
                            if($this->approvalBatchNo === $materialRequisitionStatus->getBatchNo() && $materialRequisitionStatus->getStatus() === 'Pending Branch Manager Approval' && $materialRequisitionStatus->getUser() && $materialRequisitionStatus->getUser()->getId() === $userData['id'])
                                $isAlreadyApproved = true;
                        }

                        if(!$isAlreadyApproved) $canApproveByUser = true;

                        break;
                }

                break;
            case 'Pending Admin Approval':

                if(in_array($userData['type'], array('Super Admin', 'Admin'))) {

                    foreach($this->materialRequisitionStatuses as $materialRequisitionStatus) {
                        if($this->approvalBatchNo === $materialRequisitionStatus->getBatchNo() && $materialRequisitionStatus->getStatus() === 'Pending Admin Approval' && $materialRequisitionStatus->getUser() && $materialRequisitionStatus->getUser()->getId() === $userData['id'])
                            $isAlreadyApproved = true;
                    }

                    if(!$isAlreadyApproved) $canApproveByUser = true;
                }

                break;
        }

        return $canApproveByUser;
    }

    /**
     * Get hasItemForSupplierCanvassing
     *
     * @return boolean
     */
    public function getHasItemForSupplierCanvassing() {

        $hasItemForSupplierCanvassing = false;

         foreach($this->materialRequisitionItems as $materialRequisitionItem) {
            if($materialRequisitionItem->getQuantityForCanvassing() > 0) {
                $hasItemForSupplierCanvassing = true;
                break;
            }

           /* if(count($materialRequisitionItem->getMaterialRequisitionItemUnitMeasurements())){
                $hasItemForSupplierCanvassing =  true;
                break;
            }*/
        }

        return $hasItemForSupplierCanvassing;
    }

    /**
     * Get transmittals
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getTransmittals() {

        $transmittals = array();

        foreach($this->materialRequisitionItems as $materialRequisitionItem) {
            if($materialRequisitionItem->getTransmittalItems()) {
                foreach($materialRequisitionItem->getTransmittalItems() as $transmittalItem) {
                    if(!in_array($transmittalItem->getTransmittal(), $transmittals)) $transmittals[] = $transmittalItem->getTransmittal();
                }
            }
        }

        return new ArrayCollection($transmittals);
    }

    /**
     * Get hasQuantityForTransmittal
     *
     * @return boolean
     */
    public function getHasQuantityForTransmittal() {

        $hasQuantityForTransmittal = false;

        if($this->canvassType === 'Main') {

            foreach($this->materialRequisitionItems as $materialRequisitionItem) {
                if($materialRequisitionItem->getTransmittalItems()) {

                    $totalQuantityReceived = 0;
                    foreach($materialRequisitionItem->getTransmittalItems() as $transmittalItem) {
                        $totalQuantityReceived += $transmittalItem->getQuantityReceived();
                    }

                    if($totalQuantityReceived != $materialRequisitionItem->getQuantity()) $hasQuantityForTransmittal = true;
                } else {
                    $hasQuantityForTransmittal = true;
                }
            }
        }

        return $hasQuantityForTransmittal;
    }

    /**
     * Get isVoidable
     *
     * @return boolean
     */
    public function getIsVoidable() {

        $isVoidable = $this->status === 'Closed' || $this->status === 'Voided' ? false : true;

        if(count($this->canvasses)) {
            foreach($this->canvasses as $canvass) {
                if($canvass->getStatus() === 'Supplier Canvassing') $isVoidable = false;
            }
        }

        if(count($this->purchaseOrders)) {
            foreach($this->purchaseOrders as $purchaseOrder) {
                if($purchaseOrder->getStatus() !== 'Voided' && $purchaseOrder->getStatus() !== 'Cancelled') $isVoidable = false;
            }
        }

        return $isVoidable;
    }

    /**
     * Get purchaseOrderIsCancellable
     *
     * @return boolean
     */
    public function getPurchaseOrderIsCancellable() {

        $isCancellable = true;

        foreach($this->purchaseOrders as $purchaseOrder) {
            foreach ($purchaseOrder->getPurchaseOrderBreakdowns() as $purchaseOrderBreakdown){
                if($purchaseOrderBreakdown->getStatus() == 'Sent'){
                    $isCancellable = false;
                }
            }
        }

        return $isCancellable;
    }

    /**
     * Get isCancellable
     *
     * @return boolean
     */
    public function getIsCancellable() {

        $isCancellable = true;

        foreach($this->canvasses as $canvass) {
            if(in_array($canvass->getStatus(), array(
                'Pending Purchasing Manager Approval',
                'Pending Admin Approval',
                'Approved'
            ))) $isCancellable = false;
        }

        return $isCancellable;
    }

    /**
     * Get quantityAdded
     *
     * @return integer
     */
    public function getQuantityAdded() {

        $quantityAdded = 0;

        foreach($this->materialRequisitionItems as $item) {
            $quantityAdded += $item->getQuantityAdded();
        }

        return $quantityAdded;
    }

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

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

    /**
     * Get requestDateAsString
     *
     * @return string
     */
    public function getRequestDateAsString()
    {
        $dttst = new DateTimeToStringTransformer();
        return !empty($this->requestDate) ? date('m/d/Y', strtotime($dttst->transform($this->requestDate))) : '';
    }

    /**
     * Get requiredDateAsString
     *
     * @return string
     */
    public function getRequiredDateAsString()
    {
        $dttst = new DateTimeToStringTransformer();
        return !empty($this->requiredDate) ? date('m/d/Y', strtotime($dttst->transform($this->requiredDate))) : '';
    }

    /**
     * Set materialRequisitionNo
     *
     * @param string $materialRequisitionNo
     * @return MaterialRequisitionEntity
     */
    public function setMaterialRequisitionNo($materialRequisitionNo)
    {
        $this->materialRequisitionNo = $materialRequisitionNo;

        return $this;
    }

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

    /**
     * Set referenceNo
     *
     * @param string $referenceNo
     * @return MaterialRequisitionEntity
     */
    public function setReferenceNo($referenceNo)
    {
        $this->referenceNo = $referenceNo;

        return $this;
    }

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

    /**
     * Set title
     *
     * @param string $title
     * @return MaterialRequisitionEntity
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

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

    /**
     * Set requestDate
     *
     * @param \DateTime $requestDate
     * @return MaterialRequisitionEntity
     */
    public function setRequestDate($requestDate)
    {
        $this->requestDate = empty($requestDate) ? NULL : new \DateTime($requestDate);

        return $this;
    }

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

    /**
     * Set canvassType
     *
     * @param string $canvassType
     * @return MaterialRequisitionEntity
     */
    public function setCanvassType($canvassType)
    {
        $this->canvassType = $canvassType;

        return $this;
    }

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

    /**
     * Set specificPurpose
     *
     * @param string $specificPurpose
     * @return MaterialRequisitionEntity
     */
    public function setSpecificPurpose($specificPurpose)
    {
        $this->specificPurpose = $specificPurpose;

        return $this;
    }

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

    /**
     * Set note
     *
     * @param string $note
     * @return MaterialRequisitionEntity
     */
    public function setNote($note)
    {
        $this->note = $note;

        return $this;
    }

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

    /**
     * Set status
     *
     * @param string $status
     * @return MaterialRequisitionEntity
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

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

    /**
     * Set approvalBatchNo
     *
     * @param integer $approvalBatchNo
     * @return MaterialRequisitionEntity
     */
    public function setApprovalBatchNo($approvalBatchNo)
    {
        $this->approvalBatchNo = str_replace(',', '', $approvalBatchNo);

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set purpose
     *
     * @param \RxConnexionBundle\Entity\PurposeEntity $purpose
     * @return MaterialRequisitionEntity
     */
    public function setPurpose(\RxConnexionBundle\Entity\PurposeEntity $purpose = null)
    {
        $this->purpose = $purpose;

        return $this;
    }

    /**
     * Get purpose
     *
     * @return \RxConnexionBundle\Entity\PurposeEntity
     */
    public function getPurpose()
    {
        return $this->purpose;
    }

    /**
     * Add materialRequisitionStatuses
     *
     * @param \RxConnexionBundle\Entity\MaterialRequisitionStatusEntity $materialRequisitionStatuses
     * @return MaterialRequisitionEntity
     */
    public function addMaterialRequisitionStatus(\RxConnexionBundle\Entity\MaterialRequisitionStatusEntity $materialRequisitionStatuses)
    {
        $this->materialRequisitionStatuses[] = $materialRequisitionStatuses;

        return $this;
    }

    /**
     * Remove materialRequisitionStatuses
     *
     * @param \RxConnexionBundle\Entity\MaterialRequisitionStatusEntity $materialRequisitionStatuses
     */
    public function removeMaterialRequisitionStatus(\RxConnexionBundle\Entity\MaterialRequisitionStatusEntity $materialRequisitionStatuses)
    {
        $this->materialRequisitionStatuses->removeElement($materialRequisitionStatuses);
    }

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

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

        return $this;
    }

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

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

    /**
     * Add canvasses
     *
     * @param \RxConnexionBundle\Entity\CanvassEntity $canvasses
     * @return MaterialRequisitionEntity
     */
    public function addCanvass(\RxConnexionBundle\Entity\CanvassEntity $canvasses)
    {
        $this->canvasses[] = $canvasses;

        return $this;
    }

    /**
     * Remove canvasses
     *
     * @param \RxConnexionBundle\Entity\CanvassEntity $canvasses
     */
    public function removeCanvass(\RxConnexionBundle\Entity\CanvassEntity $canvasses)
    {
        $this->canvasses->removeElement($canvasses);
    }

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

    /**
     * Add purchaseOrders
     *
     * @param \RxConnexionBundle\Entity\PurchaseOrderEntity $purchaseOrders
     * @return MaterialRequisitionEntity
     */
    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;
    }

    /**
     * Set requiredDate
     *
     * @param \DateTime $requiredDate
     * @return MaterialRequisitionEntity
     */
    public function setRequiredDate($requiredDate)
    {
        $this->requiredDate = empty($requiredDate) ? NULL : new \DateTime($requiredDate);
    
        return $this;
    }

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

    /**
     * Add materialRequisitionNotes
     *
     * @param \RxConnexionBundle\Entity\MaterialRequisitionNoteEntity $materialRequisitionNotes
     * @return MaterialRequisitionEntity
     */
    public function addMaterialRequisitionNote(\RxConnexionBundle\Entity\MaterialRequisitionNoteEntity $materialRequisitionNotes)
    {
        $this->materialRequisitionNotes[] = $materialRequisitionNotes;

        return $this;
    }

    /**
     * Remove materialRequisitionNotes
     *
     * @param \RxConnexionBundle\Entity\MaterialRequisitionNoteEntity $materialRequisitionNotes
     */
    public function removeMaterialRequisitionNote(\RxConnexionBundle\Entity\MaterialRequisitionNoteEntity $materialRequisitionNotes)
    {
        $this->materialRequisitionNotes->removeElement($materialRequisitionNotes);
    }

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

    /**
     * Add transferInventoryMatReqs
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryMatReqEntity $transferInventoryMatReqs
     * @return MaterialRequisitionEntity
     */
    public function addTransferInventoryMatReq(\RxConnexionBundle\Entity\TransferInventoryMatReqEntity $transferInventoryMatReqs)
    {
        $this->transferInventoryMatReqs[] = $transferInventoryMatReqs;

        return $this;
    }

    /**
     * Remove transferInventoryMatReqs
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryMatReqEntity $transferInventoryMatReqs
     */
    public function removeTransferInventoryMatReq(\RxConnexionBundle\Entity\TransferInventoryMatReqEntity $transferInventoryMatReqs)
    {
        $this->transferInventoryMatReqs->removeElement($transferInventoryMatReqs);
    }

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

    /**
     * Set healthFacility
     *
     * @param \RxConnexionBundle\Entity\HealthFacilityEntity $healthFacility
     *
     * @return MaterialRequisitionEntity
     */
    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;
    }

    /**
     * Set accountUser
     *
     * @param \RxConnexionBundle\Entity\AccountUserEntity $accountUser
     *
     * @return MaterialRequisitionEntity
     */
    public function setAccountUser(\RxConnexionBundle\Entity\AccountUserEntity $accountUser = null)
    {
        $this->accountUser = $accountUser;

        return $this;
    }

    /**
     * Get accountUser
     *
     * @return \RxConnexionBundle\Entity\AccountUserEntity
     */
    public function getAccountUser()
    {
        return $this->accountUser;
    }
}
