<?php

namespace RxConnexionBundle\Entity;

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

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\PatientChartPaymentRepository")
 * @ORM\Table(name="patient_chart_payment")
 */

class PatientChartPaymentEntity extends BaseEntity
{
    const PAYMENT_TYPE_CASH = 'Cash';
    const PAYMENT_TYPE_CHECK = 'Check';

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

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

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

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

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

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

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

    /**
     * @ORM\Column(name="amount", type="decimal", precision=10, scale=2, nullable=true)
     * @Groups("forAudit")
     */
    protected $amount;

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

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

    /**
     * @ORM\ManyToOne(targetEntity="PatientChartEntity", inversedBy="payments")
     * @ORM\JoinColumn(name="patient_chart_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $patientChart;

    /**
     * @ORM\OneToMany(targetEntity="PatientChartPaymentProcedureEntity", mappedBy="patientChartPayment", cascade={"persist", "remove"}, orphanRemoval=true)
     */
    protected $procedures;

    /**
     * @ORM\OneToMany(targetEntity="PatientChartPaymentOtherProcedureEntity", mappedBy="patientChartPayment", cascade={"persist", "remove"}, orphanRemoval=true)
     */
    protected $otherProcedures;

    public function __construct()
    {
        $this->procedures = new ArrayCollection();
        $this->otherProcedures = new ArrayCollection();
    }

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

    /*--------------------------------------------------------------------------------------------------------*/
    /*					Use Defined Setters and Getters														  */
    /*--------------------------------------------------------------------------------------------------------*/

    /**
     * Get hasPatientChartProcedure
     *
     * @param \RxConnexionBundle\Entity\PatientChartProcedureEntity $patientChartProcedure
     * @return boolean
     */
    public function getHasPatientChartProcedure(\RxConnexionBundle\Entity\PatientChartProcedureEntity $patientChartProcedure) {

        $hasPatientChartProcedure = false;

        foreach($this->procedures as $patientChartProcedure_obj) {
            if($patientChartProcedure_obj->getPatientChartProcedure() === $patientChartProcedure) {
                $hasPatientChartProcedure = true;
                break;
            }
        }

        return $hasPatientChartProcedure;
    }

    /**
     * Get hasPatientChartOtherProcedure
     *
     * @param \RxConnexionBundle\Entity\PatientChartProcedureEntity $patientChartOtherProcedure
     * @return boolean
     */
    public function getHasPatientChartOtherProcedure(\RxConnexionBundle\Entity\PatientChartOtherProcedureEntity $patientChartOtherProcedure) {

        $hasPatientChartOtherProcedure = false;

        foreach($this->otherProcedures as $patientChartOtherProcedure_obj) {
            if($patientChartOtherProcedure_obj->getPatientChartOtherProcedure() === $patientChartOtherProcedure) {
                $hasPatientChartOtherProcedure = true;
                break;
            }
        }

        return $hasPatientChartOtherProcedure;
    }

    /**
     * Get paymentDateAsString
     *
     * @return string
     */
    public function getPaymentDateAsString() {

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

    /**
     * Get checkDateAsString
     *
     * @return string
     */
    public function getCheckDateAsString() {

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

    /**
     * Get paymentProcedureByProcedureId
     *
     * @param $procedureId
     * @return \RxConnexionBundle\Entity\PatientChartPaymentProcedureEntity | null
     */
    public function getPaymentProcedureByProcedureId($procedureId) {
        if($this->procedures->count()){
            foreach ($this->procedures as $procedure){
                if($procedure->getPatientChartProcedure()->getId() == $procedureId){
                    return $procedure;
                }
            }
        }
        return null;
    }

    /**
     * Get paymentOtherProcedureByOtherProcedureId
     *
     * @param $otherProcedureId
     * @return \RxConnexionBundle\Entity\PatientChartPaymentOtherProcedureEntity | null
     */
    public function getPaymentOtherProcedureByOtherProcedureId($otherProcedureId) {
        if($this->otherProcedures->count()){
            foreach ($this->otherProcedures as $otherProcedure){
                if($otherProcedure->getPatientChartOtherProcedure()->getId() == $otherProcedureId){
                    return $otherProcedure;
                }
            }
        }
        return null;
    }

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

    /**
     * Set paymentType
     *
     * @param string $paymentType
     *
     * @return PatientChartPaymentEntity
     */
    public function setPaymentType($paymentType)
    {
        $this->paymentType = $paymentType;

        return $this;
    }

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

    /**
     * Set orNo
     *
     * @param string $orNo
     *
     * @return PatientChartPaymentEntity
     */
    public function setOrNo($orNo)
    {
        $this->orNo = $orNo;

        return $this;
    }

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

    /**
     * Set drNo
     *
     * @param string $drNo
     *
     * @return PatientChartPaymentEntity
     */
    public function setDrNo($drNo)
    {
        $this->drNo = $drNo;

        return $this;
    }

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

    /**
     * Set checkNo
     *
     * @param string $checkNo
     *
     * @return PatientChartPaymentEntity
     */
    public function setCheckNo($checkNo)
    {
        $this->checkNo = $checkNo;

        return $this;
    }

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

    /**
     * Set barcode
     *
     * @param string $barcode
     *
     * @return PatientChartPaymentEntity
     */
    public function setBarcode($barcode)
    {
        $this->barcode = $barcode;

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set amount
     *
     * @param string $amount
     *
     * @return PatientChartPaymentEntity
     */
    public function setAmount($amount)
    {
        $this->amount = str_replace(',', '', $amount);

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set patientChart
     *
     * @param \RxConnexionBundle\Entity\PatientChartEntity $patientChart
     *
     * @return PatientChartPaymentEntity
     */
    public function setPatientChart(\RxConnexionBundle\Entity\PatientChartEntity $patientChart = null)
    {
        $this->patientChart = $patientChart;

        return $this;
    }

    /**
     * Get patientChart
     *
     * @return \RxConnexionBundle\Entity\PatientChartEntity
     */
    public function getPatientChart()
    {
        return $this->patientChart;
    }

    /**
     * Add procedure
     *
     * @param \RxConnexionBundle\Entity\PatientChartPaymentProcedureEntity $procedure
     *
     * @return PatientChartPaymentEntity
     */
    public function addProcedure(\RxConnexionBundle\Entity\PatientChartPaymentProcedureEntity $procedure)
    {
        $procedure->setPatientChartPayment($this);
        $this->procedures[] = $procedure;

        return $this;
    }

    /**
     * Remove procedure
     *
     * @param \RxConnexionBundle\Entity\PatientChartPaymentProcedureEntity $procedure
     */
    public function removeProcedure(\RxConnexionBundle\Entity\PatientChartPaymentProcedureEntity $procedure)
    {
        $this->procedures->removeElement($procedure);
    }

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

    /**
     * Add otherProcedure
     *
     * @param \RxConnexionBundle\Entity\PatientChartPaymentOtherProcedureEntity $otherProcedure
     *
     * @return PatientChartPaymentEntity
     */
    public function addOtherProcedure(\RxConnexionBundle\Entity\PatientChartPaymentOtherProcedureEntity $otherProcedure)
    {
        $otherProcedure->setPatientChartPayment($this);
        $this->otherProcedures[] = $otherProcedure;

        return $this;
    }

    /**
     * Remove otherProcedure
     *
     * @param \RxConnexionBundle\Entity\PatientChartPaymentOtherProcedureEntity $otherProcedure
     */
    public function removeOtherProcedure(\RxConnexionBundle\Entity\PatientChartPaymentOtherProcedureEntity $otherProcedure)
    {
        $this->otherProcedures->removeElement($otherProcedure);
    }

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

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

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

        return $this;
    }

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

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

        return $this;
    }

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