<?php

namespace RxConnexionBundle\Entity;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use RxConnexionBundle\Entity\Base\BaseEntity;
use JMS\Serializer\Annotation\Groups;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\ItemRepository")
 * @ORM\Table(name="item", indexes={@ORM\Index(name="IDX_SEARCH_000", columns={"description"})})
 */

class ItemEntity extends BaseEntity
{
    /**
     * @ORM\Column(type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $code;

    /**
     * @ORM\Column(type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $code2;

    /**
     * @ORM\Column(type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $brand;

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

    /**
     * @ORM\Column(type="string")
     * @Groups("forAudit")
     */
    protected $description;

    /**
     * @ORM\Column(name="start_date", type="datetime")
     * @Groups("forAudit")
     */
    protected $startDate;

    /**
     * @ORM\Column(name="end_date", type="datetime", nullable=true)
     * @Groups("forAudit")
     */
    protected $endDate;

    /**
     * @ORM\Column(name="is_deleted", type="boolean")
     */
    protected $isDeleted;

    /**
     * @ORM\Column(name="is_itemised", type="boolean")
     */
    protected $isItemised;

    /**
     * @ORM\Column(name="is_package", type="boolean")
     */
    protected $isPackage;

    /**
     * @ORM\Column(name="is_non_inventory", type="boolean")
     */
    protected $isNonInventory;

    /**
     * @ORM\OneToOne(targetEntity="DeviceEntity", mappedBy="item")
     */
    protected $device;

    /**
     * @ORM\ManyToOne(targetEntity="ItemSubCategoryEntity", inversedBy="items")
     * @ORM\JoinColumn(name="item_subcategory_id", referencedColumnName="id")
     * @Groups("forAudit")
     */
    protected $itemSubCategory;

    /**
     * @ORM\ManyToOne(targetEntity="CompanyEntity", inversedBy="items")
     * @ORM\JoinColumn(name="item_company_id", referencedColumnName="id")
     * @Groups("forAudit")
     */
    protected $itemCompany;

    /**
     * @ORM\ManyToOne(targetEntity="RxConnexionBundle\Entity\SupplierEntity", inversedBy="items")
     * @ORM\JoinColumn(name="supplier_id", referencedColumnName="id")
     * @Groups("forAudit")
     */
    protected $supplier;

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

    /**
     * @ORM\ManyToOne(targetEntity="ItemSizeEntity", inversedBy="items")
     * @ORM\JoinColumn(name="item_size_id", referencedColumnName="id")
     */
    protected $itemSize;

    /**
     * @ORM\ManyToOne(targetEntity="ItemUnitEntity", inversedBy="items")
     * @ORM\JoinColumn(name="item_unit_id", referencedColumnName="id")
     */
    protected $itemUnit;

    /**
     * @ORM\Column(name="package_item_quantity", type="decimal", precision=12, scale=2, nullable=true)
     */
    protected $packageItemQuantity;

    /**
     * @ORM\OneToMany(targetEntity="PatientBillingBreakdownEntity", mappedBy="item")
     */
    protected $patientBillingBreakdowns;

    /**
     * @ORM\OneToMany(targetEntity="ItemPriceEntity", mappedBy="item")
     */
    protected $itemPrices;

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

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

    /**
     * @ORM\OneToMany(targetEntity="RxConnexionBundle\Entity\TransferInventoryItemDefaultEntity", mappedBy="item")
     */
    protected $transferInventoryItemDefaults;

    /**
     * @ORM\OneToMany(targetEntity="RxConnexionBundle\Entity\ItemSupplierEntity", mappedBy="item")
     */
    protected $itemSuppliers;

    /**
     * @ORM\OneToMany(targetEntity="RxConnexionBundle\Entity\ItemPackageItemEntity", mappedBy="item")
     */
    protected $itemPackageItems;

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

    /**
     * @ORM\OneToMany(targetEntity="ItemUnitMeasurementEntity", mappedBy="item")
     */
    protected $itemUnitMeasurements;

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

    /**
     * @ORM\OneToMany(targetEntity="RxConnexionBundle\Entity\TransferInventoryItemEntity", mappedBy="item")
     */
    protected $transferInventoryItems;

    /**
     * @ORM\OneToMany(targetEntity="RxConnexionBundle\Entity\ItemEntity", mappedBy="item" )
     */
    protected $items;

    /**
     * @ORM\OneToMany(targetEntity="RxConnexionBundle\Entity\ItemTaxCodeEntity", mappedBy="item", cascade={"persist", "remove"})
     */
    protected $itemTaxCodes;

    /**
     * @ORM\OneToMany(targetEntity="RxConnexionBundle\Entity\ItemAveCostEntity", mappedBy="item", cascade={"persist", "remove"})
     */
    protected $itemAveCost;

    /**
     * @ORM\OneToMany(targetEntity="RxConnexionBundle\Entity\PatientBillingInventoryEntity", mappedBy="item")
     */
    protected $patientBillingInventories;

    /**
     * Set createdAt
     *
     * @ORM\PrePersist
     */
    public function setCreatedAtValue()
    {
        parent::setCreatedAtValue();
        $this->isDeleted = 0;
    }

    public function __construct()
    {
        $this->patientBillingBreakdowns = new ArrayCollection();
        $this->itemUnitMeasurements = new ArrayCollection();
        $this->transferInventoryItemDefaults = new ArrayCollection();
        $this->convertInventoryItemBis = new ArrayCollection();
        $this->patientBillingInventories = new ArrayCollection();
    }

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

	/**
	 * Get aveCostByHealthFacility
	*/
	public function getAveCostByHealthFacility($healthFacility)
	{
		foreach ($this->getItemAveCost() as $item) {
			if($item->getHealthFacility() === $healthFacility) {
				return $item->getAveCost();
			}
		}
		return 0.00;
	}

    /**
     * Get firstInventoryByBranchIdAndStatus
     *
     * @param $branchId
     * @param $status
     *
     * @param bool $hasQty
     * @return \RxConnexionBundle\Entity\InventoryEntity|null
     */
    public function getFirstInventoryByBranchIdAndStatus($branchId, $status, $hasQty = false) {

        if(!$hasQty) {
            foreach ($this->inventories as $inventory) {
                if ($inventory->getHealthFacility()->getId() == $branchId && $status === $inventory->getStatus()) {
                    return $inventory;
                }
            }
        } else {
            foreach ($this->inventories as $inventory) {
                if ($inventory->getHealthFacility()->getId() == $branchId && $status === $inventory->getStatus() && $inventory->getQuantity() > 0) {
                    return $inventory;
                }
            }
        }

        return null;
    }

    /**
     * Get startDateAsString
     *
     * @return string
     */
    public function getStartDateAsString() {

        $dttst = new DateTimeToStringTransformer();
        return !empty($this->startDate) ? date('m/d/Y', strtotime($dttst->transform($this->startDate))) : '';
    }

    /**
     * Get endDateAsString
     *
     * @return string
     */
    public function getEndDateAsString() {

        $dttst = new DateTimeToStringTransformer();
        return !empty($this->endDate) ? date('m/d/Y', strtotime($dttst->transform($this->endDate))) : '';
    }

    /**
     * Get todayPrice
     *
     *@return string
     */

    public function getTodayPrice(){

        $todayPrice = 0;

        foreach ($this->itemPrices as $itemPrice){
            if($itemPrice->getEndDate() >= new \DateTime()){
                $todayPrice = $itemPrice->getPrice();
            }
        }

        return $todayPrice;
    }

    /**
     * Get inventoryCtrByBranchIdAndStatus
     *
     * @param $branchId
     * @param $status
     *
     * @return string
     */
    public function getInventoryCtrByBranchIdAndStatus($branchId, $status) {

        $ctr = 0;

        foreach($this->inventories as $inventory) {
            if($inventory->getHealthFacility()->getId() == $branchId && $inventory->getStatus() == $status) {
                $ctr++;
            }
        }

        return $ctr;
    }

    /**
     * Get inventoriesByBranchIdAndStatus
     *
     * @param $branchId
     * @param $status
     *
     * @return array
     */
    public function getInventoriesByBranchIdAndStatus($branchId, $status) {
        $inventories = array();
        foreach($this->inventories as $inventory) {
            if($inventory->getHealthFacility()->getId() == $branchId && $status === $inventory->getStatus() && $inventory->getQuantity() > 0 && !empty($inventory->getLocation())) {
                $inventories[] =$inventory;
            }
        }

        return $inventories;
    }

    /**
     * Get inventoriesByBranchId
     *
     * @param $branchId
     *
     * @param bool $multiple
     * @return array|InventoryEntity
     */
    public function getInventoriesByBranchId($branchId, $multiple = true) {
        $inventories = array();
        foreach($this->inventories as $inventory) {
            if($inventory->getHealthFacility()->getId() == $branchId) {
                if($multiple) {
                    $inventories[] =$inventory;
                } else {
                    return $inventory;
                }
            }
        }

        return $multiple ? $inventories : null;
    }


    /**
     * Get allSerialNos
     * @return array
     */
    public function getAllSerialNos()
    {
        /**@var PurchaseOrderBreakdownItemDeliveryEntity $purchaseOrderBreakdownItemDelivery*/
        /**@var PurchaseOrderBreakdownItemDeliverySerialNoEntity $purchaseOrderBreakdownItemDeliverySerialNo*/
        /**@var MaterialRequisitionItemEntity $materialRequisitionItem*/
        /**@var PurchaseOrderItemEntity $purchaseOrderItem*/
        /**@var PurchaseOrderBreakdownItemEntity $purchaseOrderBreakdownItem*/
        $serialNos = [];
        foreach ($this->getMaterialRequisitionItems() as $materialRequisitionItem) {
            foreach ($materialRequisitionItem->getPurchaseOrderItems() as $purchaseOrderItem) {
                foreach ($purchaseOrderItem->getPurchaseOrderBreakdownItems() as $purchaseOrderBreakdownItem) {
                    foreach ($purchaseOrderBreakdownItem->getPurchaseOrderBreakdownItemDeliveries() as $purchaseOrderBreakdownItemDelivery) {
                        foreach ($purchaseOrderBreakdownItemDelivery->getPurchaseOrderBreakdownItemDeliverySerialNos() as $purchaseOrderBreakdownItemDeliverySerialNo) {
                            $serialNos[] = $purchaseOrderBreakdownItemDeliverySerialNo;
                        }
                    }
                }
            }
        }
        return $serialNos;
    }


    /**
     * Get availableInventorySerialNos
     * @return array
     */
    public function getAvailableInventorySerialNos()
    {
        /**@var InventoryEntity $inventory*/
        /**@var InventorySerialNoEntity $inventorySerialNo*/
        $serialNos = [];
        foreach ($this->getInventories() as $inventory) {
            foreach ($inventory->getInventorySerialNos() as $inventorySerialNo) {
                if($inventorySerialNo->getStatus() === InventorySerialNoEntity::STATUS_1) {
                    $serialNos[] = $inventorySerialNo;
                }
            }
        }
        return $serialNos;
    }


    /**
     * Get availableInventorySerialNosByHealthFacility
     * @param $healthFacility_id
     * @param string $returnType
     * @return array
     */
    public function getAvailableInventorySerialNosByHealthFacility($healthFacility_id, $returnType = 'object')
    {
        /**@var InventoryEntity $inventory*/
        /**@var InventorySerialNoEntity $inventorySerialNo*/
        $serialNos = [];
        foreach ($this->getInventories() as $inventory) {
            if($inventory->getHealthFacility()->getId() == $healthFacility_id) {
                foreach ($inventory->getInventorySerialNos() as $inventorySerialNo) {
                    if ($inventorySerialNo->getStatus() === InventorySerialNoEntity::STATUS_1) {
                        if($returnType === 'object') {
                            $serialNos[] = $inventorySerialNo;
                        } elseif($returnType === 'array') {
                            $serialNos[] = array(
                                'id' => $inventorySerialNo->getId(),
                                'serialNo' => $inventorySerialNo->getSerialNo(),
                            );
                        } elseif($returnType === 'imploded') {
                            $serialNos[] = implode('~', [$inventorySerialNo->getId(), $inventorySerialNo->getSerialNo()]);
                        }
                    }
                }
            }
        }
        return $serialNos;
    }

    /**
     * Get packageItemsAsArray
     * @param null $healthFacility_id
     * @return array
     */
    public function getPackageItemsAsArray($healthFacility_id = null)
    {
        $items = [];
        /**@var self $item*/
        foreach ($this->getItems() as $item) {
            $items[] = array(
                'item_id' => $item->getId(),
                'item_description' => $item->getDescription(),
                'package_item_quantity' => $item->getPackageItemQuantity(),
                'is_itemised' => $item->getIsItemised(),
                'serial_nos' => !is_null($healthFacility_id) ? $item->getAvailableInventorySerialNosByHealthFacility($healthFacility_id, 'imploded') : $item->getAvailableInventorySerialNos()
            );
        }
        return $items;
    }

    /**
     * Get itemisedPackageItems
     * @return ArrayCollection
     */
    public function getItemisedPackageItems()
    {
        $items = new ArrayCollection();
        foreach ($this->getItems() as $item) {
            if($item->getIsItemised()) {
                $items->add($item);
            }
        }
        return $items;
    }

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


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

        return $this;
    }

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

    /**
     * Set type
     *
     * @param string $type
     *
     * @return ItemEntity
     */
    public function setType($type)
    {
        $this->type = $type;

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

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

        return $this;
    }

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

    /**
     * Add device
     *
     * @param \RxConnexionBundle\Entity\DeviceEntity $device
     *
     * @return ItemEntity
     */
    public function addDevice(\RxConnexionBundle\Entity\DeviceEntity $device)
    {
        $this->device[] = $device;

        return $this;
    }

    /**
     * Remove device
     *
     * @param \RxConnexionBundle\Entity\DeviceEntity $device
     */
    public function removeDevice(\RxConnexionBundle\Entity\DeviceEntity $device)
    {
        $this->device->removeElement($device);
    }

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

    /**
     * Set device
     *
     * @param \RxConnexionBundle\Entity\DeviceEntity $device
     *
     * @return ItemEntity
     */
    public function setDevice(\RxConnexionBundle\Entity\DeviceEntity $device = null)
    {
        $this->device = $device;

        return $this;
    }

    /**
     * Add patientBillingBreakdown
     *
     * @param \RxConnexionBundle\Entity\PatientBillingBreakdownEntity $patientBillingBreakdown
     *
     * @return ItemEntity
     */
    public function addPatientBillingBreakdown(\RxConnexionBundle\Entity\PatientBillingBreakdownEntity $patientBillingBreakdown)
    {
        $this->patientBillingBreakdowns[] = $patientBillingBreakdown;

        return $this;
    }

    /**
     * Remove patientBillingBreakdown
     *
     * @param \RxConnexionBundle\Entity\PatientBillingBreakdownEntity $patientBillingBreakdown
     */
    public function removePatientBillingBreakdown(\RxConnexionBundle\Entity\PatientBillingBreakdownEntity $patientBillingBreakdown)
    {
        $this->patientBillingBreakdowns->removeElement($patientBillingBreakdown);
    }

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

    /**
     * Set isDeleted
     *
     * @param boolean $isDeleted
     *
     * @return ItemEntity
     */
    public function setIsDeleted($isDeleted)
    {
        $this->isDeleted = $isDeleted;

        return $this;
    }

    /**
     * Get isDeleted
     *
     * @return boolean
     */
    public function getIsDeleted()
    {
        return $this->isDeleted;
    }

    /**
     * Set itemSubCategory
     *
     * @param \RxConnexionBundle\Entity\ItemSubCategoryEntity $itemSubCategory
     *
     * @return ItemEntity
     */
    public function setItemSubCategory(\RxConnexionBundle\Entity\ItemSubCategoryEntity $itemSubCategory = null)
    {
        $this->itemSubCategory = $itemSubCategory;

        return $this;
    }

    /**
     * Get itemSubCategory
     *
     * @return \RxConnexionBundle\Entity\ItemSubCategoryEntity
     */
    public function getItemSubCategory()
    {
        return $this->itemSubCategory;
    }

    /**
     * Add itemPrice
     *
     * @param \RxConnexionBundle\Entity\ItemPriceEntity $itemPrice
     *
     * @return ItemEntity
     */
    public function addItemPrice(\RxConnexionBundle\Entity\ItemPriceEntity $itemPrice)
    {
        $this->itemPrices[] = $itemPrice;

        return $this;
    }

    /**
     * Remove itemPrice
     *
     * @param \RxConnexionBundle\Entity\ItemPriceEntity $itemPrice
     */
    public function removeItemPrice(\RxConnexionBundle\Entity\ItemPriceEntity $itemPrice)
    {
        $this->itemPrices->removeElement($itemPrice);
    }

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

    /**
     * Set itemCompany
     *
     * @param \RxConnexionBundle\Entity\CompanyEntity $itemCompany
     *
     * @return ItemEntity
     */
    public function setItemCompany(\RxConnexionBundle\Entity\CompanyEntity $itemCompany = null)
    {
        $this->itemCompany = $itemCompany;

        return $this;
    }

    /**
     * Get itemCompany
     *
     * @return \RxConnexionBundle\Entity\CompanyEntity
     */
    public function getItemCompany()
    {
        return $this->itemCompany;
    }

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

        return $this;
    }

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

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

    /**
     * Add inventory
     *
     * @param \RxConnexionBundle\Entity\InventoryEntity $inventory
     *
     * @return ItemEntity
     */
    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 transferInventoryItemDefault
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryItemDefaultEntity $transferInventoryItemDefault
     *
     * @return ItemEntity
     */
    public function addTransferInventoryItemDefault(\RxConnexionBundle\Entity\TransferInventoryItemDefaultEntity $transferInventoryItemDefault)
    {
        $this->transferInventoryItemDefaults[] = $transferInventoryItemDefault;

        return $this;
    }

    /**
     * Remove transferInventoryItemDefault
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryItemDefaultEntity $transferInventoryItemDefault
     */
    public function removeTransferInventoryItemDefault(\RxConnexionBundle\Entity\TransferInventoryItemDefaultEntity $transferInventoryItemDefault)
    {
        $this->transferInventoryItemDefaults->removeElement($transferInventoryItemDefault);
    }

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

    /**
     * Add itemSupplier
     *
     * @param \RxConnexionBundle\Entity\ItemSupplierEntity $itemSupplier
     *
     * @return ItemEntity
     */
    public function addItemSupplier(\RxConnexionBundle\Entity\ItemSupplierEntity $itemSupplier)
    {
        $this->itemSuppliers[] = $itemSupplier;

        return $this;
    }

    /**
     * Remove itemSupplier
     *
     * @param \RxConnexionBundle\Entity\ItemSupplierEntity $itemSupplier
     */
    public function removeItemSupplier(\RxConnexionBundle\Entity\ItemSupplierEntity $itemSupplier)
    {
        $this->itemSuppliers->removeElement($itemSupplier);
    }

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

    /**
     * Add itemPackageItem
     *
     * @param \RxConnexionBundle\Entity\ItemPackageItemEntity $itemPackageItem
     *
     * @return ItemEntity
     */
    public function addItemPackageItem(\RxConnexionBundle\Entity\ItemPackageItemEntity $itemPackageItem)
    {
        $this->itemPackageItems[] = $itemPackageItem;

        return $this;
    }

    /**
     * Remove itemPackageItem
     *
     * @param \RxConnexionBundle\Entity\ItemPackageItemEntity $itemPackageItem
     */
    public function removeItemPackageItem(\RxConnexionBundle\Entity\ItemPackageItemEntity $itemPackageItem)
    {
        $this->itemPackageItems->removeElement($itemPackageItem);
    }

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

    /**
     * Add materialRequisitionItem
     *
     * @param \RxConnexionBundle\Entity\MaterialRequisitionItemEntity $materialRequisitionItem
     *
     * @return ItemEntity
     */
    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 itemUnitMeasurement
     *
     * @param \RxConnexionBundle\Entity\ItemUnitMeasurementEntity $itemUnitMeasurement
     *
     * @return ItemEntity
     */
    public function addItemUnitMeasurement(\RxConnexionBundle\Entity\ItemUnitMeasurementEntity $itemUnitMeasurement)
    {
        $this->itemUnitMeasurements[] = $itemUnitMeasurement;

        return $this;
    }

    /**
     * Remove itemUnitMeasurement
     *
     * @param \RxConnexionBundle\Entity\ItemUnitMeasurementEntity $itemUnitMeasurement
     */
    public function removeItemUnitMeasurement(\RxConnexionBundle\Entity\ItemUnitMeasurementEntity $itemUnitMeasurement)
    {
        $this->itemUnitMeasurements->removeElement($itemUnitMeasurement);
    }

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

    /**
     * Set supplier
     *
     * @param \RxConnexionBundle\Entity\SupplierEntity $supplier
     *
     * @return ItemEntity
     */
    public function setSupplier(\RxConnexionBundle\Entity\SupplierEntity $supplier = null)
    {
        $this->supplier = $supplier;

        return $this;
    }

    /**
     * Get supplier
     *
     * @return \RxConnexionBundle\Entity\SupplierEntity
     */
    public function getSupplier()
    {
        return $this->supplier;
    }

    /**
     * Add convertInventoryItemBi
     *
     * @param \RxConnexionBundle\Entity\ConvertInventoryItemBiEntity $convertInventoryItemBi
     *
     * @return ItemEntity
     */
    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;
    }

    /**
     * Set isItemised
     *
     * @param boolean $isItemised
     *
     * @return ItemEntity
     */
    public function setIsItemised($isItemised)
    {
        $this->isItemised = $isItemised;

        return $this;
    }

    /**
     * Get isItemised
     *
     * @return boolean
     */
    public function getIsItemised()
    {
        return $this->isItemised;
    }

    /**
     * Add transferInventoryItem
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryItemEntity $transferInventoryItem
     *
     * @return ItemEntity
     */
    public function addTransferInventoryItem(\RxConnexionBundle\Entity\TransferInventoryItemEntity $transferInventoryItem)
    {
        $this->transferInventoryItems[] = $transferInventoryItem;

        return $this;
    }

    /**
     * Remove transferInventoryItem
     *
     * @param \RxConnexionBundle\Entity\TransferInventoryItemEntity $transferInventoryItem
     */
    public function removeTransferInventoryItem(\RxConnexionBundle\Entity\TransferInventoryItemEntity $transferInventoryItem)
    {
        $this->transferInventoryItems->removeElement($transferInventoryItem);
    }

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

    /**
     * Set isPackage
     *
     * @param boolean $isPackage
     *
     * @return ItemEntity
     */
    public function setIsPackage($isPackage)
    {
        $this->isPackage = $isPackage;

        return $this;
    }

    /**
     * Get isPackage
     *
     * @return boolean
     */
    public function getIsPackage()
    {
        return $this->isPackage;
    }

    /**
     * Add itemTaxCode
     *
     * @param \RxConnexionBundle\Entity\ItemTaxCodeEntity $itemTaxCode
     *
     * @return ItemEntity
     */
    public function addItemTaxCode(\RxConnexionBundle\Entity\ItemTaxCodeEntity $itemTaxCode)
    {
        $this->itemTaxCodes[] = $itemTaxCode;

        return $this;
    }

    /**
     * Remove itemTaxCode
     *
     * @param \RxConnexionBundle\Entity\ItemTaxCodeEntity $itemTaxCode
     */
    public function removeItemTaxCode(\RxConnexionBundle\Entity\ItemTaxCodeEntity $itemTaxCode)
    {
        $this->itemTaxCodes->removeElement($itemTaxCode);
    }

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

    /**
     * Set patientBillingInventory
     *
     * @param \RxConnexionBundle\Entity\PatientBillingInventoryEntity $patientBillingInventory
     *
     * @return ItemEntity
     */
    public function setPatientBillingInventory(\RxConnexionBundle\Entity\PatientBillingInventoryEntity $patientBillingInventory = null)
    {
        $this->patientBillingInventory = $patientBillingInventory;

        return $this;
    }

    /**
     * Get patientBillingInventory
     *
     * @return \RxConnexionBundle\Entity\PatientBillingInventoryEntity
     */
    public function getPatientBillingInventory()
    {
        return $this->patientBillingInventory;
    }

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

    /**
     * Add item
     *
     * @param \RxConnexionBundle\Entity\ItemEntity $item
     *
     * @return ItemEntity
     */
    public function addItem(\RxConnexionBundle\Entity\ItemEntity $item)
    {
        $this->items[] = $item;

        return $this;
    }

    /**
     * Remove item
     *
     * @param \RxConnexionBundle\Entity\ItemEntity $item
     */
    public function removeItem(\RxConnexionBundle\Entity\ItemEntity $item)
    {
        $this->items->removeElement($item);
    }

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

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

    /**
     * Add patientBillingInventory
     *
     * @param \RxConnexionBundle\Entity\PatientBillingInventoryEntity $patientBillingInventory
     *
     * @return ItemEntity
     */
    public function addPatientBillingInventory(\RxConnexionBundle\Entity\PatientBillingInventoryEntity $patientBillingInventory)
    {
        $this->patientBillingInventories[] = $patientBillingInventory;

        return $this;
    }

    /**
     * Remove patientBillingInventory
     *
     * @param \RxConnexionBundle\Entity\PatientBillingInventoryEntity $patientBillingInventory
     */
    public function removePatientBillingInventory(\RxConnexionBundle\Entity\PatientBillingInventoryEntity $patientBillingInventory)
    {
        $this->patientBillingInventories->removeElement($patientBillingInventory);
    }

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

    /**
     * Set packageItemQuantity
     *
     * @param string $packageItemQuantity
     *
     * @return ItemEntity
     */
    public function setPackageItemQuantity($packageItemQuantity)
    {
        $this->packageItemQuantity = str_replace(',', '', $packageItemQuantity);

        return $this;
    }

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

    /**
     * Set code2
     *
     * @param string $code2
     *
     * @return ItemEntity
     */
    public function setCode2($code2)
    {
        $this->code2 = $code2;

        return $this;
    }

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

    /**
     * Set brand
     *
     * @param string $brand
     *
     * @return ItemEntity
     */
    public function setBrand($brand)
    {
        $this->brand = $brand;

        return $this;
    }

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

    /**
     * Set itemSize
     *
     * @param \RxConnexionBundle\Entity\ItemSizeEntity $itemSize
     *
     * @return ItemEntity
     */
    public function setItemSize(\RxConnexionBundle\Entity\ItemSizeEntity $itemSize = null)
    {
        $this->itemSize = $itemSize;

        return $this;
    }

    /**
     * Get itemSize
     *
     * @return \RxConnexionBundle\Entity\ItemSizeEntity
     */
    public function getItemSize()
    {
        return $this->itemSize;
    }

    /**
     * Set itemUnit
     *
     * @param \RxConnexionBundle\Entity\ItemUnitEntity $itemUnit
     *
     * @return ItemEntity
     */
    public function setItemUnit(\RxConnexionBundle\Entity\ItemUnitEntity $itemUnit = null)
    {
        $this->itemUnit = $itemUnit;

        return $this;
    }

    /**
     * Get itemUnit
     *
     * @return \RxConnexionBundle\Entity\ItemUnitEntity
     */
    public function getItemUnit()
    {
        return $this->itemUnit;
    }

    /**
     * Set isNonInventory
     *
     * @param boolean $isNonInventory
     *
     * @return ItemEntity
     */
    public function setIsNonInventory($isNonInventory)
    {
        $this->isNonInventory = $isNonInventory;

        return $this;
    }

    /**
     * Get isNonInventory
     *
     * @return boolean
     */
    public function getIsNonInventory()
    {
        return $this->isNonInventory;
    }

    /**
     * Add itemAveCode
     *
     * @param \RxConnexionBundle\Entity\ItemAveCostEntity $itemAveCode
     *
     * @return ItemEntity
     */
    public function addItemAveCode(\RxConnexionBundle\Entity\ItemAveCostEntity $itemAveCode)
    {
        $this->itemAveCost[] = $itemAveCode;

        return $this;
    }

    /**
     * Remove itemAveCode
     *
     * @param \RxConnexionBundle\Entity\ItemAveCostEntity $itemAveCode
     */
    public function removeItemAveCode(\RxConnexionBundle\Entity\ItemAveCostEntity $itemAveCode)
    {
        $this->itemAveCost->removeElement($itemAveCode);
    }

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