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

class PatientBillingInventoryEntity
{
    /**
     * @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="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\PatientBillingEntity", inversedBy="patientBillingInventories")
     * @ORM\JoinColumn(name="patient_billing_id", referencedColumnName="id")
     */
    protected $patientBilling;

    /**
     * @ORM\ManyToOne(targetEntity="InventoryEntity", inversedBy="patientBillingInventories")
     * @ORM\JoinColumn(name="inventory_id", referencedColumnName="id")
     */
    protected $inventory;

//    /**
//     * @ORM\OneToMany(targetEntity="JobOrderInventoryPriceEntity", mappedBy="jobOrderInventory")
//     */
//    protected $jobOrderInventoryPrices;

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

//    /**
//     * @ORM\OneToMany(targetEntity="InventoryPriceEntity", mappedBy="jobOrderInventory")
//     */
//    protected $inventoryPrices;

    /**
     * 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->patientBilling = $data->getPatientBilling();
//            $this->jobOrder = $data->getJobOrder();
            $this->inventory = $data->getInventory();
        }

//        $this->jobOrderInventoryPrices = new ArrayCollection();
        $this->inventoryMovements = new ArrayCollection();
//        $this->inventoryPrices = 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 quantity
     *
     * @param string $quantity
     *
     * @return PatientBillingInventoryEntity
     */
    public function setQuantity($quantity)
    {
        $this->quantity = str_replace(',', '', $quantity);

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set patientBilling
     *
     * @param \RxConnexionBundle\Entity\PatientBillingEntity $patientBilling
     *
     * @return PatientBillingInventoryEntity
     */
    public function setPatientBilling(\RxConnexionBundle\Entity\PatientBillingEntity $patientBilling = null)
    {
        $this->patientBilling = $patientBilling;

        return $this;
    }

    /**
     * Get patientBilling
     *
     * @return \RxConnexionBundle\Entity\PatientBillingEntity
     */
    public function getPatientBilling()
    {
        return $this->patientBilling;
    }

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

    /**
     * Add inventoryMovement
     *
     * @param \RxConnexionBundle\Entity\InventoryMovementEntity $inventoryMovement
     *
     * @return PatientBillingInventoryEntity
     */
    public function addInventoryMovement(\RxConnexionBundle\Entity\InventoryMovementEntity $inventoryMovement)
    {
        $this->inventoryMovements[] = $inventoryMovement;

        return $this;
    }

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

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