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

class PurchaseInvoicePaymentEntity
{
    const PAYMENT_METHOD_CASH = 'Cash';
    const PAYMENT_METHOD_CHECK = 'Check';
    const PAYMENT_METHOD_CREDIT = 'Credit';
    const PAYMENT_METHOD_CREDIT_CARD = 'Credit Card';

    /**
     * @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="wh_tax_amount", type="decimal", precision=18, scale=2, nullable=true)
     */
    protected $whTaxAmount;

    /**
     * @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="term", type="integer", nullable=true)
     */
    protected $term;

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

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

//    /**
//     * @ORM\OneToOne(targetEntity="TransactionLinkEntity", mappedBy="purchaseInvoicePaymentAdvance")
//     */
//    protected $transactionLinkAdvance;
//
//    /**
//     * @ORM\OneToOne(targetEntity="TransactionLinkEntity", mappedBy="purchaseInvoicePayment")
//     */
//    protected $transactionLink;
//
//    /**
//     * @ORM\OneToOne(targetEntity="TransactionLinkEntity", mappedBy="purchaseInvoicePaymentReverse", cascade={"remove"})
//     */
//    protected $transactionLinkReverse;
//
//    /**
//     * @ORM\OneToOne(targetEntity="CheckTranEntity", mappedBy="purchaseInvoicePayment")
//     */
//    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->remark = $data->getRemark();
            $this->term = $data->getTerm();
//            $this->transactionLinkAdvance = $data->getTransactionLinkAdvance();
//            $this->transactionLink = $data->getTransactionLink();
//            $this->transactionLinkReverse = $data->getTransactionLinkReverse();
            $this->bank = $data->getBank();
//            $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 PurchaseInvoicePaymentEntity
     */
    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 PurchaseInvoicePaymentEntity
     */
    public function setAmount($amount)
    {
        $this->amount = floatval(str_replace(',','', $amount));
    
        return $this;
    }

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

    /**
     * Set remark
     *
     * @param string $remark
     * @return PurchaseInvoicePaymentEntity
     */
    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 PurchaseInvoicePaymentEntity
     */
    public function setCheckNo($checkNo)
    {
        $this->checkNo = $checkNo;
    
        return $this;
    }

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

    /**
     * Set createdBy
     *
     * @param string $createdBy
     * @return PurchaseInvoicePaymentEntity
     */
    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 PurchaseInvoicePaymentEntity
     */
    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 PurchaseInvoicePaymentEntity
     */
    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 PurchaseInvoicePaymentEntity
     */
    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 PurchaseInvoicePaymentEntity
     */
    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 PurchaseInvoicePaymentEntity
     */
    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;
    }

    /**
     * Set paymentDate
     *
     * @param \DateTime $paymentDate
     * @return PurchaseInvoicePaymentEntity
     */
    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 checkDate
     *
     * @param \DateTime $checkDate
     * @return PurchaseInvoicePaymentEntity
     */
    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 PurchaseInvoicePaymentEntity
     */
    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 whTaxAmount
     *
     * @param string $whTaxAmount
     * @return PurchaseInvoicePaymentEntity
     */
    public function setWhTaxAmount($whTaxAmount)
    {
        $this->whTaxAmount = $whTaxAmount;

        return $this;
    }

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

    /**
     * Set term
     *
     * @param integer $term
     * @return PurchaseInvoicePaymentEntity
     */
    public function setTerm($term)
    {
        $this->term = $term;

        return $this;
    }

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