<?php

namespace RxConnexionBundle\Entity;

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

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\AccountingBillingRepository")
 * @ORM\Table(name="accounting_billing")
 */

class AccountingBillingEntity extends BaseEntity
{
    const TYPE_INVOICE = 'Invoice';
    const TYPE_PAYMENT = 'Payment';
    const TYPE_REFUND = 'Refund';

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

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

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

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

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

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

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

    /**
     * @ORM\ManyToOne(targetEntity="RxConnexionBundle\Entity\PatientBillingEntity", inversedBy="accountingBillings")
     * @ORM\JoinColumn(name="patient_billing_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $patientBilling;

    /**
     * @ORM\ManyToOne(targetEntity="RxConnexionBundle\Entity\PatientPaymentEntity", inversedBy="accountingBillings")
     * @ORM\JoinColumn(name="patient_payment_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $patientPayment;

    /**
     * @ORM\ManyToOne(targetEntity="RxConnexionBundle\Entity\PatientBillingRefundEntity", inversedBy="accountingBillings")
     * @ORM\JoinColumn(name="patient_billing_refund_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $patientBillingRefund;

    public function __construct($data=null)
    {
        if(!is_null($data)) {
            $this->id = $data->getId();
        }
    }

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

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


    /**
     * Get encodeDateAsString
     *
     * @return string
     */
    public function getEncodeDateAsString() {

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

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

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


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



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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set number
     *
     * @param string $number
     *
     * @return AccountingBillingEntity
     */
    public function setNumber($number)
    {
        $this->number = $number;

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set checkDate
     *
     * @param \DateTime $checkDate
     *
     * @return AccountingBillingEntity
     */
    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 patientBilling
     *
     * @param \RxConnexionBundle\Entity\PatientBillingEntity $patientBilling
     *
     * @return AccountingBillingEntity
     */
    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 amount
     *
     * @param string $amount
     *
     * @return AccountingBillingEntity
     */
    public function setAmount($amount)
    {
        $this->amount = $amount;

        return $this;
    }

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

    /**
     * Set patientPayment
     *
     * @param \RxConnexionBundle\Entity\PatientPaymentEntity $patientPayment
     *
     * @return AccountingBillingEntity
     */
    public function setPatientPayment(\RxConnexionBundle\Entity\PatientPaymentEntity $patientPayment = null)
    {
        $this->patientPayment = $patientPayment;

        return $this;
    }

    /**
     * Get patientPayment
     *
     * @return \RxConnexionBundle\Entity\PatientPaymentEntity
     */
    public function getPatientPayment()
    {
        return $this->patientPayment;
    }

    /**
     * Set patientBillingRefund
     *
     * @param \RxConnexionBundle\Entity\PatientBillingRefundEntity $patientBillingRefund
     *
     * @return AccountingBillingEntity
     */
    public function setPatientBillingRefund(\RxConnexionBundle\Entity\PatientBillingRefundEntity $patientBillingRefund = null)
    {
        $this->patientBillingRefund = $patientBillingRefund;

        return $this;
    }

    /**
     * Get patientBillingRefund
     *
     * @return \RxConnexionBundle\Entity\PatientBillingRefundEntity
     */
    public function getPatientBillingRefund()
    {
        return $this->patientBillingRefund;
    }
}
