src/Entity/SupplierContract.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SupplierContractRepository;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Gedmo\Timestampable\Traits\TimestampableEntity;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Symfony\Component\HttpFoundation\File\UploadedFile;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. #[Vich\Uploadable]
  14. #[ORM\Entity(repositoryClassSupplierContractRepository::class)]
  15. #[ORM\Table(name'`supplier_contract`')]
  16. class SupplierContract
  17. {
  18.     use TimestampableEntity;
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue(strategy:"AUTO")]
  21.     #[ORM\Column(type"integer")]
  22.     protected ?int $id null;
  23.     #[ORM\ManyToOne(targetEntity:"App\Entity\Supplier"inversedBy:"contracts")]
  24.     #[ORM\JoinColumn(name"supplier_id"referencedColumnName"id"nullablefalse)]
  25.     protected $supplier;
  26.     #[ORM\Column(type"string"length255nullablefalse)]
  27.     protected $contract;
  28.     #[ORM\Column(type"string"length255nullablefalseoptions: ['default' => 'own'])]
  29.     protected $contract_type 'own';
  30.     #[ORM\Column(type"datetime"nullabletrue)]
  31.     protected $startedAt;
  32.     #[ORM\Column(type"datetime"nullabletrue)]
  33.     protected $finishedAt;
  34.     #[ORM\Column(type"decimal"precision20scale2nullabletrue)]
  35.     protected $amount;
  36.     #[ORM\Column(type"string"length255nullabletrue)]
  37.     protected $moneyType;
  38.     #[ORM\ManyToMany(targetEntity:"User")]
  39.     #[ORM\JoinTable(name"supplier_contract_managers")]
  40.     protected $managers;
  41.     #[ORM\ManyToMany(targetEntity:"User")]
  42.     #[ORM\JoinTable(name"supplier_contract_administrative_managers")]
  43.     protected $administrativeManagers;
  44.     #[ORM\Column(type"string"length255nullabletrue)]
  45.     protected $document null;
  46.     /**
  47.      * @var File
  48.      */
  49.     #[Vich\UploadableField(mapping"supplier_contracts"fileNameProperty"document")]
  50.     protected $documentFile;
  51.     #[ORM\Column(type"string"length255nullabletrue)]
  52.     protected $description;
  53.     #[Assert\Length(min3max100minMessage'El área debe tener al menos {{ limit }} caracteres'maxMessage'El área no puede tener más de {{ limit }} caracteres')]
  54.     #[ORM\Column(type"string"length100nullabletrue)]
  55.     protected $area;
  56.     #[ORM\Column(type"boolean")]
  57.     protected $enabled true;
  58.     public function __construct()
  59.     {
  60.         $this->managers = new ArrayCollection();
  61.         $this->administrativeManagers = new ArrayCollection();
  62.     }
  63.     /**
  64.      * @return int
  65.      */
  66.     public function getId()
  67.     {
  68.         return $this->id;
  69.     }
  70.     /**
  71.      * @return Supplier
  72.      */
  73.     public function getSupplier()
  74.     {
  75.         return $this->supplier;
  76.     }
  77.     /**
  78.      * @param Supplier $supplier
  79.      */
  80.     public function setSupplier(Supplier $supplier)
  81.     {
  82.         $this->supplier $supplier;
  83.     }
  84.     /**
  85.      * @return string
  86.      */
  87.     public function getContract()
  88.     {
  89.         return $this->contract;
  90.     }
  91.     /**
  92.      * @param string $contract
  93.      */
  94.     public function setContract(string $contract)
  95.     {
  96.         $this->contract $contract;
  97.     }
  98.     /**
  99.      * @return DateTime
  100.      */
  101.     public function getStartedAt(): ?DateTime
  102.     {
  103.         return $this->startedAt;
  104.     }
  105.     /**
  106.      * @param DateTime $startedAt
  107.      */
  108.     public function setStartedAt(DateTime $startedAt): void
  109.     {
  110.         $this->startedAt $startedAt;
  111.     }
  112.     /**
  113.      * @return DateTime
  114.      */
  115.     public function getFinishedAt(): ?DateTime
  116.     {
  117.         return $this->finishedAt;
  118.     }
  119.     /**
  120.      * @param DateTime $finishedAt
  121.      */
  122.     public function setFinishedAt(DateTime $finishedAt): void
  123.     {
  124.         $this->finishedAt $finishedAt;
  125.     }
  126.     /**
  127.      * @return mixed
  128.      */
  129.     public function getAmount()
  130.     {
  131.         return $this->amount;
  132.     }
  133.     /**
  134.      * @param mixed $amount
  135.      */
  136.     public function setAmount($amount): void
  137.     {
  138.         $this->amount $amount;
  139.     }
  140.     /**
  141.      * @return Collection
  142.      */
  143.     public function getManagers(): Collection
  144.     {
  145.         return $this->managers;
  146.     }
  147.     /**
  148.      * @param Collection $managers
  149.      */
  150.     public function setManagers(Collection $managers): void
  151.     {
  152.         $this->managers $managers;
  153.     }
  154.     public function addManager(User $manager)
  155.     {
  156.         if (!$this->managers->contains($manager)) {
  157.             $this->managers->add($manager);
  158.         }
  159.     }
  160.     public function removeManager(User $manager)
  161.     {
  162.         if ($this->managers->contains($manager)) {
  163.             $this->managers->removeElement($manager);
  164.         }
  165.     }
  166.     /**
  167.      * @return Collection
  168.      */
  169.     public function getAdministrativeManagers(): Collection
  170.     {
  171.         return $this->administrativeManagers;
  172.     }
  173.     /**
  174.      * @param Collection $administrativeManagers
  175.      */
  176.     public function setAdministrativeManagers(Collection $administrativeManagers): void
  177.     {
  178.         $this->administrativeManagers $administrativeManagers;
  179.     }
  180.     public function addAdministrativeManager(User $manager)
  181.     {
  182.         if (!$this->administrativeManagers->contains($manager)) {
  183.             $this->administrativeManagers->add($manager);
  184.         }
  185.     }
  186.     public function removeAdministrativeManager(User $manager)
  187.     {
  188.         if ($this->administrativeManagers->contains($manager)) {
  189.             $this->administrativeManagers->removeElement($manager);
  190.         }
  191.     }
  192.     /**
  193.      * @return string
  194.      */
  195.     public function getDocument()
  196.     {
  197.         return $this->document;
  198.     }
  199.     /**
  200.      * @param string $document
  201.      */
  202.     public function setDocument(string $document null)
  203.     {
  204.         $this->document $document;
  205.     }
  206.     /**
  207.      * @return File
  208.      */
  209.     public function getDocumentFile()
  210.     {
  211.         return $this->documentFile;
  212.     }
  213.     /**
  214.      * @param File $documentFile
  215.      */
  216.     public function setDocumentFile(File $documentFile)
  217.     {
  218.         $this->documentFile $documentFile;
  219.         if ($this->documentFile instanceof UploadedFile) {
  220.             $this->document $documentFile->getClientOriginalExtension();
  221.             $this->updatedAt = new \DateTime('now');
  222.         }
  223.     }
  224.     /**
  225.      * @return bool
  226.      */
  227.     public function isEnabled()
  228.     {
  229.         return $this->enabled;
  230.     }
  231.     /**
  232.      * @param bool $enabled
  233.      */
  234.     public function setEnabled(bool $enabled)
  235.     {
  236.         $this->enabled $enabled;
  237.     }
  238.     /**
  239.      * @return string
  240.      */
  241.     public function getMoneyType(): ?string
  242.     {
  243.         return $this->moneyType;
  244.     }
  245.     /**
  246.      * @param string|null $moneyType
  247.      */
  248.     public function setMoneyType(?string $moneyType): void
  249.     {
  250.         $this->moneyType $moneyType;
  251.     }
  252.     /**
  253.      * @return string
  254.      */
  255.     public function getDescription(): ?string
  256.     {
  257.         return $this->description;
  258.     }
  259.     /**
  260.      * @param string|null $description
  261.      */
  262.     public function setDescription(?string $description): void
  263.     {
  264.         $this->description $description;
  265.     }
  266.     /**
  267.      * @return string
  268.      */
  269.     public function getArea(): ?string
  270.     {
  271.         return $this->area;
  272.     }
  273.     /**
  274.      * @param string|null $area
  275.      */
  276.     public function setArea(?string $area): void
  277.     {
  278.         $this->area $area;
  279.     }
  280.     /**
  281.      * @return mixed
  282.      */
  283.     public function getContractType()
  284.     {
  285.         return $this->contract_type;
  286.     }
  287.     /**
  288.      * @param mixed $contract_type
  289.      */
  290.     public function setContractType($contract_type): void
  291.     {
  292.         $this->contract_type $contract_type;
  293.     }
  294.     /**
  295.      * @return string|null
  296.      */
  297.     public function getDocumentUrl(): ?string
  298.     {
  299.         if (!$this->document) {
  300.             return null;
  301.         }
  302.         
  303.         return '/download/supplier/contract/' $this->document;
  304.     }
  305.     public function __toString()
  306.     {
  307.         return sprintf('%s'$this->contract);
  308.     }
  309. }