<?php

namespace RxConnexionBundle\Entity;

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

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\AccountingFileRepository")
 * @ORM\Table(name="accounting_file")
 */

class AccountingFileEntity extends BaseEntity
{
    /**
     * @ORM\Column(name="is_deleted", type="boolean")
     */
    protected $isDeleted;

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

    /**
     * @ORM\ManyToOne(targetEntity="RxConnexionBundle\Entity\FileTypeEntity", inversedBy="accountingFiles")
     * @ORM\JoinColumn(name="file_type_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $fileType;

    /**
     * @ORM\OneToMany(targetEntity="RxConnexionBundle\Entity\AccountingEncodeEntity", mappedBy="accountingFile", orphanRemoval=true, cascade={"persist", "remove"})
     */
    protected $accountingEncodes;


    public function __construct()
    {
        $this->accountingEncode = new ArrayCollection();
    }

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

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

    /**
     * Get startDateAsString
     *
     * @return string
     */
    public function getStartDateAsString() {

        $dttst = new DateTimeToStringTransformer();
        return !empty($this->startDate) ? date('m/d/Y', strtotime($dttst->transform($this->startDate))) : '';
    }

    /**
     * Get endDateAsString
     *
     * @return string
     */
    public function getEndDateAsString() {

        $dttst = new DateTimeToStringTransformer();
        return !empty($this->endDate) ? date('m/d/Y', strtotime($dttst->transform($this->endDate))) : '';
    }

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


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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set fileType
     *
     * @param \RxConnexionBundle\Entity\FileTypeEntity $fileType
     *
     * @return AccountingFileEntity
     */
    public function setFileType(\RxConnexionBundle\Entity\FileTypeEntity $fileType = null)
    {
        $this->fileType = $fileType;

        return $this;
    }

    /**
     * Get fileType
     *
     * @return \RxConnexionBundle\Entity\FileTypeEntity
     */
    public function getFileType()
    {
        return $this->fileType;
    }

    /**
     * Add accountingEncode
     *
     * @param \RxConnexionBundle\Entity\AccountingEncodeEntity $accountingEncode
     *
     * @return AccountingFileEntity
     */
    public function addAccountingEncode(\RxConnexionBundle\Entity\AccountingEncodeEntity $accountingEncode)
    {
        $this->accountingEncode[] = $accountingEncode;

        return $this;
    }

    /**
     * Remove accountingEncode
     *
     * @param \RxConnexionBundle\Entity\AccountingEncodeEntity $accountingEncode
     */
    public function removeAccountingEncode(\RxConnexionBundle\Entity\AccountingEncodeEntity $accountingEncode)
    {
        $this->accountingEncode->removeElement($accountingEncode);
    }

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

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