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

class CanvassItemSupplierEntity
{
    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="canvass_date", type="datetime")
     */
    protected $canvassDate;

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

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

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

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

    /**
     * @ORM\Column(name="is_selected", type="boolean", nullable=true)
     */
    protected $isSelected;

    /**
     * @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="CanvassItemEntity", inversedBy="canvassItemSuppliers")
     * @ORM\JoinColumn(name="canvass_item_id", referencedColumnName="id")
     */
    protected $canvassItem;

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

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

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

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

    /**
     * @ORM\ManyToOne(targetEntity="ItemUnitMeasurementEntity", inversedBy="canvassItemSuppliers")
     * @ORM\JoinColumn(name="item_unit_measurement_id", referencedColumnName="id")
     */
    protected $itemUnitMeasurement;

    /**
     * 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->quantity = $data->getQuantity();
            $this->price = $data->getPrice();
            $this->downPayment = $data->getDownPayment();
            $this->isSelected = $data->getIsSelected();
            $this->note = $data->getNote();
            $this->canvassItem = $data->getCanvassItem();
            $this->supplier = $data->getSupplier();
            $this->itemUnitMeasurement = $data->getItemUnitMeasurement();
        }

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

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

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

        return base64_encode($this->id);
    }

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

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

    /**
     * Set quantity
     *
     * @param string $quantity
     * @return CanvassItemSupplierEntity
     */
    public function setQuantity($quantity)
    {
        $this->quantity = str_replace(',', '', $quantity);

        return $this;
    }

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

    /**
     * Set price
     *
     * @param string $price
     * @return CanvassItemSupplierEntity
     */
    public function setPrice($price)
    {
        $this->price = str_replace(',', '', $price);

        return $this;
    }

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

    /**
     * Set downPayment
     *
     * @param string $downPayment
     * @return CanvassItemSupplierEntity
     */
    public function setDownPayment($downPayment)
    {
        $this->downPayment = str_replace(',', '', $downPayment);

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set isSelected
     *
     * @param boolean $isSelected
     * @return CanvassItemSupplierEntity
     */
    public function setIsSelected($isSelected)
    {
        $this->isSelected = $isSelected;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set canvassItem
     *
     * @param \RxConnexionBundle\Entity\CanvassItemEntity $canvassItem
     * @return CanvassItemSupplierEntity
     */
    public function setCanvassItem(\RxConnexionBundle\Entity\CanvassItemEntity $canvassItem = null)
    {
        $this->canvassItem = $canvassItem;

        return $this;
    }

    /**
     * Get canvassItem
     *
     * @return \RxConnexionBundle\Entity\CanvassItemEntity
     */
    public function getCanvassItem()
    {
        return $this->canvassItem;
    }

    /**
     * Set supplier
     *
     * @param \RxConnexionBundle\Entity\SupplierEntity $supplier
     * @return CanvassItemSupplierEntity
     */
    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 CanvassItemSupplierEntity
     */
    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;
    }

    /**
     * Set itemUnitMeasurement
     *
     * @param \RxConnexionBundle\Entity\ItemUnitMeasurementEntity $itemUnitMeasurement
     * @return CanvassItemSupplierEntity
     */
    public function setItemUnitMeasurement(\RxConnexionBundle\Entity\ItemUnitMeasurementEntity $itemUnitMeasurement = null)
    {
        $this->itemUnitMeasurement = $itemUnitMeasurement;
    
        return $this;
    }

    /**
     * Get itemUnitMeasurement
     *
     * @return \RxConnexionBundle\Entity\ItemUnitMeasurementEntity
     */
    public function getItemUnitMeasurement()
    {
        return $this->itemUnitMeasurement;
    }

    /**
     * Set canvassDate
     *
     * @param \DateTime $canvassDate
     * @return CanvassItemSupplierEntity
     */
    public function setCanvassDate($canvassDate)
    {
        $this->canvassDate = !empty($canvassDate) ? new \DateTime($canvassDate) : null;

        return $this;
    }

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

    /**
     * Set currency
     *
     * @param \RxConnexionBundle\Entity\CurrencyEntity $currency
     * @return CanvassItemSupplierEntity
     */
    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;
    }

    /**
     * Set paymentMode
     *
     * @param string $paymentMode
     * @return CanvassItemSupplierEntity
     */
    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 CanvassItemSupplierEntity
     */
    public function setTerm($term)
    {
        $this->term = $term;

        return $this;
    }

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