<?php

namespace RxConnexionBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use RxConnexionBundle\Entity\Base\BaseEntity;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\MaxDepth;

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\PatientLetterQuotationProductRepository")
 * @ORM\Table(name="patient_letter_quotation_product")
 * @ORM\HasLifecycleCallbacks()
 */
 
class PatientLetterQuotationProductEntity extends BaseEntity
{
    /**
     * @ORM\Column(type="bigint")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
	protected $id;

    /**
     * @ORM\Column(name="product_name", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $productName;

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

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

    /**
     * @ORM\ManyToOne(targetEntity="RxConnexionBundle\Entity\PatientLetterQuotationEntity", inversedBy="patientLetterQuotationProducts")
     * @ORM\JoinColumn(name="patient_letter_quotation_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $patientLetterQuotation;

    /**
     * Set createdAt
     *
     * @ORM\PrePersist
     */
    public function setCreatedAtValue()
    {
        parent::setCreatedAtValue();
        $this->isDeleted = 0;
    }

    /**
     * Remove the file from the disk
     *
     * @ORM\PreRemove
     */
    public function removeFile() {

        $file = $this->getUploadRootDir() . '/' . $this->parsedFileDesc;
        if(!empty($this->parsedFileDesc) && file_exists($file)) unlink($file);
    }

    public function __construct($data=null)
    {
    	if(!is_null($data)) {
    		$this->id = $data->getId();
    		$this->productName = $data->getFileDesc();
    		$this->amount_price = $data->getParsedFileDesc();
    		$this->patientLetterQuotation = $data->getPatientLetterQuotation();
    	}
    }

	/*--------------------------------------------------------------------------------------------------------*/
	/*					File Defined Setters and Getters													  */
	/*--------------------------------------------------------------------------------------------------------*/

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

        return base64_encode($this->id);
    }

    /**
     * Get uploadDir
     *
     * @return string
     */
    public function getUploadDir() {

        return 'uploads/fax_option_file/attachments';
    }

    /**
     * Get uploadRootDir
     *
     * @return string
     */
    public function getUploadRootDir() {

        return __DIR__ . '/../../../web/' . $this->getUploadDir();
    }

    /**
     * Get uploadDir
     *
     * @return string
     */
    public function getUploadDir2() {

        return 'uploads/covertedpdf';
    }

    /**
     * Get uploadRootDir
     *
     * @return string
     */
    public function getUploadRootDir2() {

        return __DIR__ . '/../../../web/' . $this->getUploadDir2();
    }

    /**
     * get fileWebPath
     *
     * @return string
     */
    public function getFileWebPath() {

        $parsedDesc = $this->parsedFileDesc;
        $file = $this->getUploadRootDir() . '/' . $parsedDesc;

        if(!empty($parsedDesc) && file_exists($file)) {
            return '/' . $this->getUploadDir() . '/' . $parsedDesc;
        } else {
            return '';
        }
    }
    
	/*--------------------------------------------------------------------------------------------------------*/
	/*					Setters and Getters																	  */
	/*--------------------------------------------------------------------------------------------------------*/


    /**
     * Set productName
     *
     * @param string $productName
     *
     * @return PatientLetterQuotationProductEntity
     */
    public function setProductName($productName)
    {
        $this->productName = $productName;

        return $this;
    }

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

    /**
     * Set amountPrice
     *
     * @param string $amountPrice
     *
     * @return PatientLetterQuotationProductEntity
     */
    public function setAmountPrice($amountPrice)
    {
        $this->amount_price = $amountPrice;

        return $this;
    }

    /**
     * Get amountPrice
     *
     * @return string
     */
    public function getAmountPrice()
    {
        return $this->amount_price;
    }

    /**
     * Set isDeleted
     *
     * @param boolean $isDeleted
     *
     * @return PatientLetterQuotationProductEntity
     */
    public function setIsDeleted($isDeleted)
    {
        $this->isDeleted = $isDeleted;

        return $this;
    }

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

    /**
     * Set patientLetterQuotation
     *
     * @param \RxConnexionBundle\Entity\PatientLetterQuotationEntity $patientLetterQuotation
     *
     * @return PatientLetterQuotationProductEntity
     */
    public function setPatientLetterQuotation(\RxConnexionBundle\Entity\PatientLetterQuotationEntity $patientLetterQuotation = null)
    {
        $this->patientLetterQuotation = $patientLetterQuotation;

        return $this;
    }

    /**
     * Get patientLetterQuotation
     *
     * @return \RxConnexionBundle\Entity\PatientLetterQuotationEntity
     */
    public function getPatientLetterQuotation()
    {
        return $this->patientLetterQuotation;
    }
}
