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

class PurchaseOrderEntity
{
    const STATUS_NEW = 'New';
    const STATUS_PENDING_OPE_DIV_MAN_SIG_FOR_PO = 'Pending Operations Division Manager Signature For PO';
    const STATUS_PENDING_FIN_OFF_SIG_FOR_PO = 'Pending Finance Officer Signature For PO';
    const STATUS_PENDING_FINAL_ADMIN_APP_FOR_PO = 'Pending Final Admin Approval For PO';
    const STATUS_APPROVED = 'Approved';
    const STATUS_SENT = 'Sent';
    const STATUS_RECEIVED = 'Received';
    const STATUS_VOIDED = 'Voided';
    const STATUS_CANCELLED = 'Cancelled';

    const PAYMENT_MODE_COD = 'COD';
    const PAYMENT_MODE_TERM = 'Term';

    /**
     * @ORM\Column(type="bigint")

     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

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

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

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

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

    /**
     * @ORM\Column(name="payment_mode", type="string", length=20, nullable=true)
     */
    protected $paymentMode;

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

    /**
     * @ORM\Column(name="wh_tax_rate", type="integer", nullable=true)
     */
    protected $whTaxRate;
    /**
     * @ORM\Column(name="wh_tax_less_vat", type="boolean", nullable=true)
     */
    protected $whTaxLessVat;
    /**
     * @ORM\Column(name="vat_rate", type="integer", nullable=true)
     */
    protected $vatRate;

    /**
     * @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="CanvassEntity", inversedBy="purchaseOrders")
     * @ORM\JoinColumn(name="canvass_id", referencedColumnName="id")
     */
    protected $canvass;

    /**
     * @ORM\ManyToOne(targetEntity="MaterialRequisitionEntity", inversedBy="purchaseOrders")
     * @ORM\JoinColumn(name="material_requisition_id", referencedColumnName="id")
     */
    protected $materialRequisition;

    /**
     * @ORM\ManyToOne(targetEntity="SupplierEntity", inversedBy="purchaseOrders")
     * @ORM\JoinColumn(name="supplier_id", referencedColumnName="id")
     */
    protected $supplier;

    /**
     * @ORM\ManyToOne(targetEntity="CurrencyEntity", inversedBy="purchaseOrders")
     * @ORM\JoinColumn(name="currency_id", referencedColumnName="id")
     */
    protected $currency;

//    /**
//     * @ORM\ManyToOne(targetEntity="WithholdingTaxRateEntity", inversedBy="purchaseOrders")
//     * @ORM\JoinColumn(name="withholding_tax_rate_id", referencedColumnName="id")
//     */
//    protected $withholdingTaxRate;

    /**
     * @ORM\OneToMany(targetEntity="PurchaseOrderItemEntity", mappedBy="purchaseOrder")
     */
    protected $purchaseOrderItems;

    /**
     * @ORM\OneToMany(targetEntity="PurchaseOrderBreakdownEntity", mappedBy="purchaseOrder")
     */
    protected $purchaseOrderBreakdowns;

    /**
     * @ORM\OneToMany(targetEntity="PurchaseOrderStatusEntity", mappedBy="purchaseOrder", cascade={"remove"})
     */
    protected $purchaseOrderStatuses;

    /**
     * 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();
//        $this->status = 'Pending Operations Division Manager Signature For PO';
        //Forced Approve RX doesn't have an approval for now
        $this->status = 'Approved';
        $this->approvalBatchNo = 0;
    }

    /**
     * Set updatedAt
     *
     * @ORM\PreUpdate
     */
    public function setUpdatedAtValue()
    {
        $this->updatedBy = $_COOKIE['username'];
        $this->updatedAt = new \DateTime();
        $this->deliveryDate = $this->getIsAllPoAlreadyReceived() ? new \DateTime() : null;
    }

    public function updateStatus() {

        if($this->status !== 'Voided') {

            $this->status = $this->getIsAllPoAlreadyReceived() ? 'Received' : ($this->getHasQuantityForPo() || $this->getHasNewPoStatus() ? 'New' : 'Sent');
        }

        return $this;
    }

    public function doVoid() {

        $isAllQuantityVoidedSelf = true;
        $isAllQuantityVoided = true;

        foreach($this->purchaseOrderItems as $purchaseOrderItem) {
            $purchaseOrderItem->getMaterialRequisitionItem()->updateQuantityVoided();
            if(!$purchaseOrderItem->getIsAllQuantityVoided()) $isAllQuantityVoidedSelf = false;
            if(!$purchaseOrderItem->getMaterialRequisitionItem()->getIsAllQuantityVoided()) $isAllQuantityVoided = false;

        }

        if($isAllQuantityVoidedSelf) $this->status = 'Voided';
        if($isAllQuantityVoided) $this->materialRequisition->doVoid();

        return $this;
    }

    public function doAddQuantity() {

        foreach($this->purchaseOrderItems as $purchaseOrderItem) {
            $purchaseOrderItem->getMaterialRequisitionItem()->updateQuantityAdded();
        }

        return $this;
    }

    public function __construct($data=null)
    {
        if(!is_null($data)) {
            $this->id = $data->getId();
            $this->batchNo = $data->getBatchNo();
            $this->status = $data->getStatus();
            $this->materialRequisition = $data->getMaterialRequisition();
            $this->canvass = $data->getCanvass();
            $this->supplier = $data->getSupplier();
            $this->currency = $data->getCurrency();
//            $this->withholdingTaxRate = $data->getWithholdingTaxRate();
            $this->deliveryDate = $data->getDeliveryDateAsString();
            $this->approvalBatchNo = $data->getApprovalBatchNo();
        }

        $this->purchaseOrderItems = new ArrayCollection();
        $this->purchaseOrderBreakdowns = new ArrayCollection();
        $this->purchaseOrderStatuses = new ArrayCollection();
    }

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

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

        return base64_encode($this->id);
    }

    /**
     * Get hasQuantityForPo
     *
     * @return boolean
     */
    public function getHasQuantityForPo() {

        foreach($this->purchaseOrderItems as $purchaseOrderItem) {
            if($purchaseOrderItem->getQuantityForPo() > $purchaseOrderItem->getQuantityWithPo()) {
                return true;
            }
        }

        return false;
    }

    /**
     * Get isAllPoAlreadyReceived
     *
     * @return boolean
     */
    public function getIsAllPoAlreadyReceived() {

        foreach($this->purchaseOrderBreakdowns as $purchaseOrderBreakdown) {
            if($purchaseOrderBreakdown->getStatus() !== 'Received' && $purchaseOrderBreakdown->getStatus() !== 'Voided') {
                return false;
            }
        }

        return true;
    }

    /**
     * Get hasNewPoStatus
     *
     * @return boolean
     */
    public function getHasNewPoStatus() {

        foreach($this->purchaseOrderBreakdowns as $purchaseOrderBreakdown) {
            if($purchaseOrderBreakdown->getStatus() === 'New') {
                return true;
            }
        }

        return false;
    }

    /**
     * Get totalQuantity
     *
     * @return string
     */
    public function getTotalQuantity() {

        $totalQuantity = 0.00;

        foreach($this->purchaseOrderItems as $purchaseOrderItem) {
            $totalQuantity += $purchaseOrderItem->getQuantity() + $purchaseOrderItem->getQuantityAdded();
        }

        return $totalQuantity;
    }

    /**
     * Get totalDownPayment
     *
     * @return string
     */
    public function getTotalDownPayment() {

        $totalDownPayment = 0.00;

        foreach($this->purchaseOrderItems as $purchaseOrderItem) {
            $totalDownPayment += $purchaseOrderItem->getDownPayment();
        }

        return $totalDownPayment;
    }


    /**
     * Get totalQuantityVoided
     *
     * @return string
     */
    public function getTotalQuantityVoided() {

        $totalQuantityVoided = 0.00;

        foreach($this->purchaseOrderItems as $purchaseOrderItem) {
            $totalQuantityVoided += $purchaseOrderItem->getQuantityVoided();
        }

        return $totalQuantityVoided;
    }

    /**
     * Get totalQuantityAdded
     *
     * @return string
     */
    public function getTotalQuantityAdded() {

        $totalQuantityAdded = 0.00;

        foreach($this->purchaseOrderItems as $purchaseOrderItem) {
            $totalQuantityAdded += $purchaseOrderItem->getQuantityAdded();
        }

        return $totalQuantityAdded;
    }
    /**
     * Get totalQuantityWithPo
     *
     * @return string
     */
    public function getTotalQuantityWithPo() {

        $totalQuantityWithPo = 0.00;

        foreach($this->purchaseOrderItems as $purchaseOrderItem) {
            $totalQuantityWithPo += $purchaseOrderItem->getQuantityWithPo();
        }

        return $totalQuantityWithPo;
    }

    /**
     * Get isVoidable
     *
     * @return boolean
     */
    public function getIsVoidable() {

        return $this->status === 'Sent' || $this->status === 'Received' || $this->status === 'Voided' ? false : true;
    }

    /**
     * Get isCancellable
     *
     * @return boolean
     */
    public function getIsCancellable() {
        if($this->purchaseOrderBreakdowns->count()) {
            foreach($this->purchaseOrderBreakdowns as $purchaseOrderBreakdown) {
                if('Sent' === $purchaseOrderBreakdown->getStatus()) {
                    return false;
                }
            }
        }
        return true;
    }

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

    /**
     * Get poDateAsString
     *
     * @return string
     */
    public function getPoDateAsString()
    {
        $dttst = new DateTimeToStringTransformer();
        return !empty($this->poDate) ? date('m/d/Y', strtotime($dttst->transform($this->poDate))) : '';
    }
    /**
     * @param array $userData
     *
     * @return boolean
     */
    public function canApproveByUser($userData) {
        $canApproveByUser = false;
        $isAlreadyApproved = false;
        switch($this->status) {
            case 'Purchasing Officer Add PO':
                switch($userData['type']) {
                    case 'Super Admin':
                    case 'Admin':
                        $canApproveByUser = true;
                        break;
                    case 'Purchasing Manager':
                    case 'Purchasing Staff':
                        foreach($this->purchaseOrderStatuses as $purchaseOrderStatus) {
                            if($this->approvalBatchNo === $purchaseOrderStatus->getBatchNo() && $purchaseOrderStatus->getStatus() === 'Purchasing Officer Add PO' && $purchaseOrderStatus->getUser() && $purchaseOrderStatus->getUser()->getId() === $userData['id'])
                                $isAlreadyApproved = true;
                        }
                        if(!$isAlreadyApproved) $canApproveByUser = true;
                        break;
                }
                break;
            case 'Pending Operations Division Manager Signature For PO':
                switch($userData['type']) {
                    case 'Super Admin':
                    case 'Admin':
                        $canApproveByUser = true;
                        break;
                    case 'Operations Manager':
                        foreach($this->purchaseOrderStatuses as $purchaseOrderStatus) {
                            if($this->approvalBatchNo === $purchaseOrderStatus->getBatchNo() && $purchaseOrderStatus->getStatus() === 'Pending Operations Division Manager Signature For PO' && $purchaseOrderStatus->getUser() && $purchaseOrderStatus->getUser()->getId() === $userData['id'])
                                $isAlreadyApproved = true;
                        }
                        if(!$isAlreadyApproved) $canApproveByUser = true;
                        break;
                }
                break;
            case 'Pending Finance Officer Manager Signature For PO':
                switch($userData['type']) {
                    case 'Super Admin':
                    case 'Admin':
                        $canApproveByUser = true;
                        break;
                    case 'Finance Officer':
                        foreach($this->purchaseOrderStatuses as $purchaseOrderStatus) {
                            if($this->approvalBatchNo === $purchaseOrderStatus->getBatchNo() && $purchaseOrderStatus->getStatus() === 'Pending Finance Officer Manager Signature For PO' && $purchaseOrderStatus->getUser() && $purchaseOrderStatus->getUser()->getId() === $userData['id'])
                                $isAlreadyApproved = true;
                        }
                        if(!$isAlreadyApproved) $canApproveByUser = true;
                        break;
                }
                break;
            case 'Pending Final Admin Approval For PO':
                if(in_array($userData['type'], array('Super Admin', 'Admin'))) {
                    foreach($this->canvassStatuses as $canvassStatus) {
                        if($this->approvalBatchNo === $canvassStatus->getBatchNo() && $canvassStatus->getStatus() === 'Pending Final Admin Approval For PO' && $canvassStatus->getUser() && $canvassStatus->getUser()->getId() === $userData['id'])
                            $isAlreadyApproved = true;
                    }
                    if(!$isAlreadyApproved) $canApproveByUser = true;
                }
                break;
        }
        return $canApproveByUser;
    }
    /**
     * Get isApprovedByStatusAndUserFullName
     *
     * @param $status
     * @param $userFullName
     * @return boolean
     */
    public function isApprovedByStatusAndUserFullName($status, $userFullName) {
        $userFullName = strtoupper($userFullName);
        if($this->purchaseOrderStatuses->count()) {
            foreach($this->purchaseOrderStatuses as $purchaseOrderStatus) {
                if($status === $purchaseOrderStatus->getStatus() && 'Approved' === $purchaseOrderStatus->getApprovalDescription() &&
                    $userFullName === $purchaseOrderStatus->getUser()->getFullNameToUpper()) {
                    return true;
                }
            }
        }
        return false;
    }

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

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

    /**
     * Set batchNo
     *
     * @param string $batchNo
     * @return PurchaseOrderEntity
     */
    public function setBatchNo($batchNo)
    {
        $this->batchNo = floatval(str_replace(',', '', $batchNo));

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set canvass
     *
     * @param \RxConnexionBundle\Entity\CanvassEntity $canvass
     * @return PurchaseOrderEntity
     */
    public function setCanvass(\RxConnexionBundle\Entity\CanvassEntity $canvass = null)
    {
        $this->canvass = $canvass;

        return $this;
    }

    /**
     * Get canvass
     *
     * @return \RxConnexionBundle\Entity\CanvassEntity
     */
    public function getCanvass()
    {
        return $this->canvass;
    }

    /**
     * Set materialRequisition
     *
     * @param \RxConnexionBundle\Entity\MaterialRequisitionEntity $materialRequisition
     * @return PurchaseOrderEntity
     */
    public function setMaterialRequisition(\RxConnexionBundle\Entity\MaterialRequisitionEntity $materialRequisition = null)
    {
        $this->materialRequisition = $materialRequisition;

        return $this;
    }

    /**
     * Get materialRequisition
     *
     * @return \RxConnexionBundle\Entity\MaterialRequisitionEntity
     */
    public function getMaterialRequisition()
    {
        return $this->materialRequisition;
    }

    /**
     * Set supplier
     *
     * @param \RxConnexionBundle\Entity\SupplierEntity $supplier
     * @return PurchaseOrderEntity
     */
    public function setSupplier(\RxConnexionBundle\Entity\SupplierEntity $supplier = null)
    {
        $this->supplier = $supplier;

        return $this;
    }

    /**
     * Get supplier
     *
     * @return \RxConnexionBundle\Entity\SupplierEntity
     */
    public function getSupplier()
    {
        return $this->supplier;
    }

    /**
     * Add purchaseOrderItems
     *
     * @param \RxConnexionBundle\Entity\PurchaseOrderItemEntity $purchaseOrderItems
     * @return PurchaseOrderEntity
     */
    public function addPurchaseOrderItem(\RxConnexionBundle\Entity\PurchaseOrderItemEntity $purchaseOrderItems)
    {
        $this->purchaseOrderItems[] = $purchaseOrderItems;

        return $this;
    }

    /**
     * Remove purchaseOrderItems
     *
     * @param \RxConnexionBundle\Entity\PurchaseOrderItemEntity $purchaseOrderItems
     */
    public function removePurchaseOrderItem(\RxConnexionBundle\Entity\PurchaseOrderItemEntity $purchaseOrderItems)
    {
        $this->purchaseOrderItems->removeElement($purchaseOrderItems);
    }

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

    /**
     * Add purchaseOrderBreakdowns
     *
     * @param \RxConnexionBundle\Entity\PurchaseOrderBreakdownEntity $purchaseOrderBreakdowns
     * @return PurchaseOrderEntity
     */
    public function addPurchaseOrderBreakdown(\RxConnexionBundle\Entity\PurchaseOrderBreakdownEntity $purchaseOrderBreakdowns)
    {
        $this->purchaseOrderBreakdowns[] = $purchaseOrderBreakdowns;

        return $this;
    }

    /**
     * Remove purchaseOrderBreakdowns
     *
     * @param \RxConnexionBundle\Entity\PurchaseOrderBreakdownEntity $purchaseOrderBreakdowns
     */
    public function removePurchaseOrderBreakdown(\RxConnexionBundle\Entity\PurchaseOrderBreakdownEntity $purchaseOrderBreakdowns)
    {
        $this->purchaseOrderBreakdowns->removeElement($purchaseOrderBreakdowns);
    }

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

    /**
     * Set deliveryDate
     *
     * @param \DateTime $deliveryDate
     * @return PurchaseOrderEntity
     */
    public function setDeliveryDate($deliveryDate)
    {
        $this->deliveryDate = $deliveryDate;
    
        return $this;
    }

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

    /**
     * Set paymentMode
     *
     * @param string $paymentMode
     * @return PurchaseOrderEntity
     */
    public function setPaymentMode($paymentMode)
    {
        $this->paymentMode = $paymentMode;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set approvalBatchNo
     *
     * @param integer $approvalBatchNo
     * @return PurchaseOrderEntity
     */
    public function setApprovalBatchNo($approvalBatchNo)
    {
        $this->approvalBatchNo = $approvalBatchNo;

        return $this;
    }

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

    /**
     * Add purchaseOrderStatuses
     *
     * @param \RxConnexionBundle\Entity\PurchaseOrderStatusEntity $purchaseOrderStatuses
     * @return PurchaseOrderEntity
     */
    public function addPurchaseOrderStatus(\RxConnexionBundle\Entity\PurchaseOrderStatusEntity $purchaseOrderStatuses)
    {
        $this->purchaseOrderStatuses[] = $purchaseOrderStatuses;

        return $this;
    }

    /**
     * Remove purchaseOrderStatuses
     *
     * @param \RxConnexionBundle\Entity\PurchaseOrderStatusEntity $purchaseOrderStatuses
     */
    public function removePurchaseOrderStatus(\RxConnexionBundle\Entity\PurchaseOrderStatusEntity $purchaseOrderStatuses)
    {
        $this->purchaseOrderStatuses->removeElement($purchaseOrderStatuses);
    }

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

    /**
     * Set whTaxRate
     *
     * @param integer $whTaxRate
     * @return PurchaseOrderEntity
     */
    public function setWhTaxRate($whTaxRate)
    {
        $this->whTaxRate = $whTaxRate;

        return $this;
    }

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

    /**
     * Set whTaxLessVat
     *
     * @param boolean $whTaxLessVat
     * @return PurchaseOrderEntity
     */
    public function setWhTaxLessVat($whTaxLessVat)
    {
        $this->whTaxLessVat = $whTaxLessVat;

        return $this;
    }

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

    /**
     * Set vatRate
     *
     * @param integer $vatRate
     * @return PurchaseOrderEntity
     */
    public function setVatRate($vatRate)
    {
        $this->vatRate = $vatRate;

        return $this;
    }

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

    /**
     * Set currency
     *
     * @param \RxConnexionBundle\Entity\CurrencyEntity $currency
     * @return PurchaseOrderEntity
     */
    public function setCurrency(\RxConnexionBundle\Entity\CurrencyEntity $currency = null)
    {
        $this->currency = $currency;

        return $this;
    }

    /**
     * Get currency
     *
     * @return \RxConnexionBundle\Entity\CurrencyEntity
     */
    public function getCurrency()
    {
        return $this->currency;
    }
}
