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

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

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

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

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

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

    /**
     * @ORM\Column(name="cleared_date", type="datetime", nullable=true)
     */
    protected $clearedDate;

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

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

    /**
     * @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="AddInventoryEntity", inversedBy="addInventoryPayments")
     * @ORM\JoinColumn(name="add_inventory_id", referencedColumnName="id")
     */
    protected $addInventory;

    /**
     * @ORM\ManyToOne(targetEntity="BankEntity", inversedBy="addInventoryPayments")
     * @ORM\JoinColumn(name="bank_id", referencedColumnName="id")
     */
    protected $bank;

//    /**
//     * @ORM\OneToOne(targetEntity="TransactionLinkEntity", mappedBy="addInventoryPayment")
//     */
//    protected $transactionLink;

//    /**
//     * @ORM\OneToOne(targetEntity="CheckTranEntity", mappedBy="addInventoryPayment")
//     */
//    protected $checkTran;


    /**
     * 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->type = $data->getType();
            $this->payDate = $data->getPayDateAsString();
            $this->amount = $data->getAmount();
            $this->checkDate = $data->getCheckDateAsString();
            $this->clearedDate = $data->getClearedDateAsString();
            $this->checkNo = $data->getCheckNo();
            $this->note = $data->getNote();
            $this->addInventory = $data->getAddInventory();
            $this->bank = $data->getBank();
//            $this->transactionLink = $data->getTransactionLink();
//            $this->checkTran = $data->getCheckTran();
        }
    }

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

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

        return base64_encode($this->id);
    }

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

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

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

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



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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set checkDate
     *
     * @param \DateTime $checkDate
     *
     * @return AddInventoryPaymentEntity
     */
    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 clearedDate
     *
     * @param \DateTime $clearedDate
     *
     * @return AddInventoryPaymentEntity
     */
    public function setClearedDate($clearedDate)
    {
        $this->clearedDate = empty($clearedDate) ? NULL : new \DateTime($clearedDate);

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set addInventory
     *
     * @param \RxConnexionBundle\Entity\AddInventoryEntity $addInventory
     *
     * @return AddInventoryPaymentEntity
     */
    public function setAddInventory(\RxConnexionBundle\Entity\AddInventoryEntity $addInventory = null)
    {
        $this->addInventory = $addInventory;

        return $this;
    }

    /**
     * Get addInventory
     *
     * @return \RxConnexionBundle\Entity\AddInventoryEntity
     */
    public function getAddInventory()
    {
        return $this->addInventory;
    }

    /**
     * Set bank
     *
     * @param \RxConnexionBundle\Entity\BankEntity $bank
     *
     * @return AddInventoryPaymentEntity
     */
    public function setBank(\RxConnexionBundle\Entity\BankEntity $bank = null)
    {
        $this->bank = $bank;

        return $this;
    }

    /**
     * Get bank
     *
     * @return \RxConnexionBundle\Entity\BankEntity
     */
    public function getBank()
    {
        return $this->bank;
    }
}
