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(repositoryClass: SupplierContractRepository::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", nullable: false)]
  25. protected $supplier;
  26. #[ORM\Column(type: "string", length: 255, nullable: false)]
  27. protected $contract;
  28. #[ORM\Column(type: "string", length: 255, nullable: false, options: ['default' => 'own'])]
  29. protected $contract_type = 'own';
  30. #[ORM\Column(type: "datetime", nullable: true)]
  31. protected $startedAt;
  32. #[ORM\Column(type: "datetime", nullable: true)]
  33. protected $finishedAt;
  34. #[ORM\Column(type: "decimal", precision: 20, scale: 2, nullable: true)]
  35. protected $amount;
  36. #[ORM\Column(type: "string", length: 255, nullable: true)]
  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", length: 255, nullable: true)]
  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", length: 255, nullable: true)]
  52. protected $validationDocument = null;
  53. /**
  54. * @var File
  55. */
  56. #[Vich\UploadableField(mapping: "supplier_contracts", fileNameProperty: "validationDocument")]
  57. protected $validationDocumentFile;
  58. #[ORM\Column(type: "string", length: 255, nullable: true)]
  59. protected $adjudicationLetter = null;
  60. /**
  61. * @var File
  62. */
  63. #[Vich\UploadableField(mapping: "supplier_contracts", fileNameProperty: "adjudicationLetter")]
  64. protected $adjudicationLetterFile;
  65. #[ORM\Column(type: "string", length: 255, nullable: true)]
  66. protected $warranty = null;
  67. /**
  68. * @var File
  69. */
  70. #[Vich\UploadableField(mapping: "supplier_contracts", fileNameProperty: "warranty")]
  71. protected $warrantyFile;
  72. #[ORM\Column(type: "string", length: 255, nullable: true)]
  73. protected $description;
  74. #[Assert\Length(min: 3, max: 100, minMessage: 'El área debe tener al menos {{ limit }} caracteres', maxMessage: 'El área no puede tener más de {{ limit }} caracteres')]
  75. #[ORM\Column(type: "string", length: 100, nullable: true)]
  76. protected $area;
  77. #[ORM\Column(type: "boolean")]
  78. protected $enabled = true;
  79. public function __construct()
  80. {
  81. $this->managers = new ArrayCollection();
  82. $this->administrativeManagers = new ArrayCollection();
  83. }
  84. /**
  85. * @return int
  86. */
  87. public function getId()
  88. {
  89. return $this->id;
  90. }
  91. /**
  92. * @return Supplier
  93. */
  94. public function getSupplier()
  95. {
  96. return $this->supplier;
  97. }
  98. /**
  99. * @param Supplier $supplier
  100. */
  101. public function setSupplier(Supplier $supplier)
  102. {
  103. $this->supplier = $supplier;
  104. }
  105. /**
  106. * @return string
  107. */
  108. public function getContract()
  109. {
  110. return $this->contract;
  111. }
  112. /**
  113. * @param string $contract
  114. */
  115. public function setContract(string $contract)
  116. {
  117. $this->contract = $contract;
  118. }
  119. /**
  120. * @return DateTime
  121. */
  122. public function getStartedAt(): ?DateTime
  123. {
  124. return $this->startedAt;
  125. }
  126. /**
  127. * @param DateTime $startedAt
  128. */
  129. public function setStartedAt(DateTime $startedAt): void
  130. {
  131. $this->startedAt = $startedAt;
  132. }
  133. /**
  134. * @return DateTime
  135. */
  136. public function getFinishedAt(): ?DateTime
  137. {
  138. return $this->finishedAt;
  139. }
  140. /**
  141. * @param DateTime $finishedAt
  142. */
  143. public function setFinishedAt(DateTime $finishedAt): void
  144. {
  145. $this->finishedAt = $finishedAt;
  146. }
  147. /**
  148. * @return mixed
  149. */
  150. public function getAmount()
  151. {
  152. return $this->amount;
  153. }
  154. /**
  155. * @param mixed $amount
  156. */
  157. public function setAmount($amount): void
  158. {
  159. $this->amount = $amount;
  160. }
  161. /**
  162. * @return Collection
  163. */
  164. public function getManagers(): Collection
  165. {
  166. return $this->managers;
  167. }
  168. /**
  169. * @param Collection $managers
  170. */
  171. public function setManagers(Collection $managers): void
  172. {
  173. $this->managers = $managers;
  174. }
  175. public function addManager(User $manager)
  176. {
  177. if (!$this->managers->contains($manager)) {
  178. $this->managers->add($manager);
  179. }
  180. }
  181. public function removeManager(User $manager)
  182. {
  183. if ($this->managers->contains($manager)) {
  184. $this->managers->removeElement($manager);
  185. }
  186. }
  187. /**
  188. * @return Collection
  189. */
  190. public function getAdministrativeManagers(): Collection
  191. {
  192. return $this->administrativeManagers;
  193. }
  194. /**
  195. * @param Collection $administrativeManagers
  196. */
  197. public function setAdministrativeManagers(Collection $administrativeManagers): void
  198. {
  199. $this->administrativeManagers = $administrativeManagers;
  200. }
  201. public function addAdministrativeManager(User $manager)
  202. {
  203. if (!$this->administrativeManagers->contains($manager)) {
  204. $this->administrativeManagers->add($manager);
  205. }
  206. }
  207. public function removeAdministrativeManager(User $manager)
  208. {
  209. if ($this->administrativeManagers->contains($manager)) {
  210. $this->administrativeManagers->removeElement($manager);
  211. }
  212. }
  213. /**
  214. * @return string
  215. */
  216. public function getDocument()
  217. {
  218. return $this->document;
  219. }
  220. /**
  221. * @param string $document
  222. */
  223. public function setDocument(string $document = null)
  224. {
  225. $this->document = $document;
  226. }
  227. /**
  228. * @return File
  229. */
  230. public function getDocumentFile()
  231. {
  232. return $this->documentFile;
  233. }
  234. /**
  235. * @param File $documentFile
  236. */
  237. public function setDocumentFile(File $documentFile)
  238. {
  239. $this->documentFile = $documentFile;
  240. if ($this->documentFile instanceof UploadedFile) {
  241. $this->document = $documentFile->getClientOriginalExtension();
  242. $this->updatedAt = new \DateTime('now');
  243. }
  244. }
  245. /**
  246. * @return string|null
  247. */
  248. public function getValidationDocument(): ?string
  249. {
  250. return $this->validationDocument;
  251. }
  252. /**
  253. * @param string|null $validationDocument
  254. */
  255. public function setValidationDocument(?string $validationDocument): void
  256. {
  257. $this->validationDocument = $validationDocument;
  258. }
  259. /**
  260. * @return File|null
  261. */
  262. public function getValidationDocumentFile(): ?File
  263. {
  264. return $this->validationDocumentFile;
  265. }
  266. /**
  267. * @param File $validationDocumentFile
  268. */
  269. public function setValidationDocumentFile(File $validationDocumentFile): void
  270. {
  271. $this->validationDocumentFile = $validationDocumentFile;
  272. if ($this->validationDocumentFile instanceof UploadedFile) {
  273. $this->validationDocument = $validationDocumentFile->getClientOriginalExtension();
  274. $this->updatedAt = new \DateTime('now');
  275. }
  276. }
  277. /**
  278. * @return string|null
  279. */
  280. public function getAdjudicationLetter(): ?string
  281. {
  282. return $this->adjudicationLetter;
  283. }
  284. /**
  285. * @param string|null $adjudicationLetter
  286. */
  287. public function setAdjudicationLetter(?string $adjudicationLetter): void
  288. {
  289. $this->adjudicationLetter = $adjudicationLetter;
  290. }
  291. /**
  292. * @return File|null
  293. */
  294. public function getAdjudicationLetterFile(): ?File
  295. {
  296. return $this->adjudicationLetterFile;
  297. }
  298. /**
  299. * @param File $adjudicationLetterFile
  300. */
  301. public function setAdjudicationLetterFile(File $adjudicationLetterFile): void
  302. {
  303. $this->adjudicationLetterFile = $adjudicationLetterFile;
  304. if ($this->adjudicationLetterFile instanceof UploadedFile) {
  305. $this->adjudicationLetter = $adjudicationLetterFile->getClientOriginalExtension();
  306. $this->updatedAt = new \DateTime('now');
  307. }
  308. }
  309. /**
  310. * @return string|null
  311. */
  312. public function getWarranty(): ?string
  313. {
  314. return $this->warranty;
  315. }
  316. /**
  317. * @param string|null $warranty
  318. */
  319. public function setWarranty(?string $warranty): void
  320. {
  321. $this->warranty = $warranty;
  322. }
  323. /**
  324. * @return File|null
  325. */
  326. public function getWarrantyFile(): ?File
  327. {
  328. return $this->warrantyFile;
  329. }
  330. /**
  331. * @param File $warrantyFile
  332. */
  333. public function setWarrantyFile(File $warrantyFile): void
  334. {
  335. $this->warrantyFile = $warrantyFile;
  336. if ($this->warrantyFile instanceof UploadedFile) {
  337. $this->warranty = $warrantyFile->getClientOriginalExtension();
  338. $this->updatedAt = new \DateTime('now');
  339. }
  340. }
  341. /**
  342. * @return bool
  343. */
  344. public function isEnabled()
  345. {
  346. return $this->enabled;
  347. }
  348. /**
  349. * @param bool $enabled
  350. */
  351. public function setEnabled(bool $enabled)
  352. {
  353. $this->enabled = $enabled;
  354. }
  355. /**
  356. * @return string
  357. */
  358. public function getMoneyType(): ?string
  359. {
  360. return $this->moneyType;
  361. }
  362. /**
  363. * @param string|null $moneyType
  364. */
  365. public function setMoneyType(?string $moneyType): void
  366. {
  367. $this->moneyType = $moneyType;
  368. }
  369. /**
  370. * @return string
  371. */
  372. public function getDescription(): ?string
  373. {
  374. return $this->description;
  375. }
  376. /**
  377. * @param string|null $description
  378. */
  379. public function setDescription(?string $description): void
  380. {
  381. $this->description = $description;
  382. }
  383. /**
  384. * @return string
  385. */
  386. public function getArea(): ?string
  387. {
  388. return $this->area;
  389. }
  390. /**
  391. * @param string|null $area
  392. */
  393. public function setArea(?string $area): void
  394. {
  395. $this->area = $area;
  396. }
  397. /**
  398. * @return mixed
  399. */
  400. public function getContractType()
  401. {
  402. return $this->contract_type;
  403. }
  404. /**
  405. * @param mixed $contract_type
  406. */
  407. public function setContractType($contract_type): void
  408. {
  409. $this->contract_type = $contract_type;
  410. }
  411. /**
  412. * @return string|null
  413. */
  414. public function getDocumentUrl(): ?string
  415. {
  416. if (!$this->document) {
  417. return null;
  418. }
  419. return '/download/supplier/contract/' . $this->document;
  420. }
  421. /**
  422. * @return string|null
  423. */
  424. public function getValidationDocumentUrl(): ?string
  425. {
  426. if (!$this->validationDocument) {
  427. return null;
  428. }
  429. return '/download/supplier/contract/' . $this->validationDocument;
  430. }
  431. /**
  432. * @return string|null
  433. */
  434. public function getAdjudicationLetterUrl(): ?string
  435. {
  436. if (!$this->adjudicationLetter) {
  437. return null;
  438. }
  439. return '/download/supplier/contract/' . $this->adjudicationLetter;
  440. }
  441. /**
  442. * @return string|null
  443. */
  444. public function getWarrantyUrl(): ?string
  445. {
  446. if (!$this->warranty) {
  447. return null;
  448. }
  449. return '/download/supplier/contract/' . $this->warranty;
  450. }
  451. public function __toString()
  452. {
  453. return sprintf('%s', $this->contract);
  454. }
  455. }