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

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

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

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

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

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

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

    /**
     * @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="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="PurchaseInvoiceEntity", inversedBy="purchaseInvoiceCreditPayments")
     * @ORM\JoinColumn(name="purchase_invoice_id", referencedColumnName="id")
     */
    protected $purchaseInvoice;

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

//    /**
//     * @ORM\OneToOne(targetEntity="TransactionLinkEntity", mappedBy="purchaseInvoiceCreditPayment")
//     */
//    protected $transactionLink;
//
//       /**
//     * @ORM\OneToOne(targetEntity="CheckTranEntity", mappedBy="purchaseInvoiceCreditPayment")
//     */
//    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->paymentMethod = $data->getPaymentMethod();
            $this->amount = $data->getAmount();
            $this->paymentDate = $data->getPaymentDateAsString();
            $this->checkNo = $data->getCheckNo();
            $this->checkDate = $data->getCheckDateAsString();
            $this->clearedDate = $data->getClearedDateAsString();
            $this->purchaseInvoice = $data->getPurchaseInvoice();
            $this->bank = $data->getBank();
            $this->remark = $data->getRemark();
//            $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 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 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 paymentMethod
     *
     * @param string $paymentMethod
     * @return PurchaseInvoiceCreditPaymentEntity
     */
    public function setPaymentMethod($paymentMethod)
    {
        $this->paymentMethod = $paymentMethod;
    
        return $this;
    }

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

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

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

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

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

    /**
     * Set remark
     *
     * @param string $remark
     * @return PurchaseInvoiceCreditPaymentEntity
     */
    public function setRemark($remark)
    {
        $this->remark = $remark;
    
        return $this;
    }

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

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

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

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

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

    /**
     * Set clearedDate
     *
     * @param \DateTime $clearedDate
     * @return PurchaseInvoiceCreditPaymentEntity
     */
    public function setClearedDate($clearedDate)
    {
        $this->clearedDate = !empty($clearedDate) ? new \DateTime($clearedDate)  : null;
    
        return $this;
    }

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

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

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

    /**
     * Set purchaseInvoice
     *
     * @param \RxConnexionBundle\Entity\PurchaseInvoiceEntity $purchaseInvoice
     * @return PurchaseInvoiceCreditPaymentEntity
     */
    public function setPurchaseInvoice(\RxConnexionBundle\Entity\PurchaseInvoiceEntity $purchaseInvoice = null)
    {
        $this->purchaseInvoice = $purchaseInvoice;
    
        return $this;
    }

    /**
     * Get purchaseInvoice
     *
     * @return \RxConnexionBundle\Entity\PurchaseInvoiceEntity
     */
    public function getPurchaseInvoice()
    {
        return $this->purchaseInvoice;
    }

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