src/Entity/Building.php line 34

  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Serializer\Annotation\Ignore;
  10. #[ORM\Table(name: 'building')]
  11. #[ORM\UniqueConstraint(name: 'uniq_user_id_building_code', columns: ['user_id', 'code'])]
  12. #[ORM\Index(columns: ['address'])]
  13. #[ORM\Entity(repositoryClass: 'App\Repository\BuildingRepository')]
  14. #[UniqueEntity(
  15. fields: ['code', 'user'],
  16. errorPath: 'code',
  17. message: 'Ovaj kod zgrade je već u upotrebi.'
  18. )]
  19. class Building
  20. {
  21. public const PROFESSIONAL_MANAGEMENT = 0;
  22. public const COMPULSORY_MANAGEMENT = 1;
  23. public const TENANT_MANAGEMENT = 2;
  24. /**
  25. * @var array<string>
  26. */
  27. #[Ignore]
  28. public static array $DATATABLE_ORDER = [
  29. 'code',
  30. 'address',
  31. 'type',
  32. 'flats',
  33. 'buildingSize',
  34. 'population',
  35. 'constructionYear',
  36. 'comment',
  37. 'management',
  38. 'elevator'
  39. ];
  40. #[ORM\Column(name: 'id', type: 'integer')]
  41. #[ORM\Id]
  42. #[ORM\GeneratedValue(strategy: 'AUTO')]
  43. private int $id;
  44. #[ORM\Column(name: 'comment', type: 'string', length: 512, nullable: true)]
  45. private string|null $comment;
  46. #[ORM\Column(name: 'created_at', type: 'datetime', nullable: true)]
  47. private DateTime|null $createdAt;
  48. #[ORM\Column(name: 'updated_at', type: 'datetime', nullable: true)]
  49. private DateTime|null $updatedAt;
  50. #[Assert\Length(
  51. min: 2,
  52. max: 7,
  53. minMessage: 'Kod zgrade treba da ima minimum {{ limit }} karaktera.',
  54. maxMessage: 'Kod zgrade treba da ima maksimalno {{ limit }} karaktera.'
  55. )]
  56. #[Assert\NotBlank]
  57. #[ORM\Column(name: 'code', type: 'string', length: 64, nullable: true)]
  58. private string|null $code;
  59. #[ORM\Column(name: 'address', type: 'string', length: 255, nullable: true)]
  60. private string|null $address;
  61. #[ORM\Column(name: 'mat_id', type: 'string', length: 64, nullable: true)]
  62. private string|null $matId;
  63. #[ORM\Column(name: 'pib', type: 'string', length: 64, nullable: true)]
  64. private string|null $pib;
  65. #[ORM\Column(name: 'startingMoney', type: 'float', nullable: true, options: ['default' => 0.0])]
  66. private float|null $startingMoney;
  67. #[ORM\Column(name: 'bank_account', type: 'string', length: 128, nullable: true)]
  68. #[Assert\NotBlank]
  69. private string|null $bankAccount;
  70. #[ORM\Column(name: 'flats', type: 'integer', nullable: true, options: ['default' => 0])]
  71. private int|null $flats;
  72. #[ORM\Column(name: 'building_size', type: 'float', nullable: true, options: ['default' => 0.0])]
  73. private float|null $buildingSize;
  74. #[ORM\Column(name: 'population', type: 'integer', nullable: true, options: ['default' => 0])]
  75. private int|null $population;
  76. #[ORM\ManyToOne(targetEntity: 'App\Entity\User', cascade: ['persist'])]
  77. #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
  78. #[Ignore]
  79. private User $user;
  80. #[Assert\NotBlank]
  81. #[ORM\Column(name: 'post_code', type: 'string', length: 64, nullable: true)]
  82. #[Ignore]
  83. private string|null $postCode = '';
  84. #[Assert\NotBlank]
  85. #[ORM\Column(name: 'city', type: 'string', length: 64, nullable: true)]
  86. private string|null $city = '';
  87. #[Assert\NotBlank]
  88. #[ORM\Column(name: 'municipality', type: 'string', length: 64, nullable: true)]
  89. private string|null $municipality = '';
  90. #[ORM\Column(name: 'type', type: 'integer', nullable: true, options: ['default' => 1])]
  91. private int|null $type;
  92. /**
  93. * @var Collection<int, Equipment>
  94. */
  95. #[ORM\OneToMany(targetEntity: 'Equipment', mappedBy: 'building')]
  96. #[Ignore]
  97. private Collection $equipment;
  98. /**
  99. * @var Collection<int, BuildingDictionary>
  100. */
  101. #[ORM\OneToMany(targetEntity: 'BuildingDictionary', mappedBy: 'building', cascade: ['remove'])]
  102. #[Ignore]
  103. private Collection $buildingDictionaries;
  104. #[ORM\ManyToOne(targetEntity: 'App\Entity\Building', cascade: ['persist'])]
  105. #[ORM\JoinColumn(name: 'building_id_bs', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
  106. #[Ignore]
  107. private Building|null $buildingIdBs;
  108. #[Assert\Email(message: "The email '{{ value }}' is not a valid email.")]
  109. #[ORM\Column(name: 'email', type: 'string', nullable: true)]
  110. private string|null $email = null;
  111. #[ORM\OneToOne(targetEntity: 'Flat')]
  112. #[ORM\JoinColumn(name: 'main_flat_id', referencedColumnName: 'id', nullable: true)]
  113. #[Ignore]
  114. private Flat|null $mainFlat;
  115. #[ORM\Column(name: 'construction_year', type: 'string', length: 64, nullable: true)]
  116. private string|null $constructionYear;
  117. #[ORM\Column(name: 'active_status', type: 'integer', nullable: false, options: ['default' => 1])]
  118. private int $activeStatus;
  119. #[ORM\Column(name: 'createdBy', type: 'string', nullable: true)]
  120. private string|null $createdBy;
  121. #[ORM\Column(name: 'enableFlatUserCreate', type: 'boolean', options: ['default' => false])]
  122. private bool $enableFlatUserCreate = false;
  123. #[ORM\Column(name: 'elevator', type: 'integer', nullable: true, options: ['default' => null])]
  124. private int|null $elevator;
  125. #[ORM\Column(name: 'building_servicing', type: 'string', length: 64, nullable: true, options: ['default' => null])]
  126. private string|null $buildingServicing;
  127. #[ORM\Column(name: 'management', type: 'integer', nullable: true)]
  128. private int|null $management;
  129. /**
  130. * @return string
  131. */
  132. public function getCreatedBy(): string
  133. {
  134. return $this->createdBy;
  135. }
  136. public function __construct()
  137. {
  138. $this->equipment = new ArrayCollection();
  139. $this->buildingDictionaries = new ArrayCollection();
  140. }
  141. /**
  142. * @return bool
  143. */
  144. public function isEnableFlatUserCreate(): bool
  145. {
  146. return $this->enableFlatUserCreate;
  147. }
  148. /**
  149. * @param bool $enableFlatUserCreate
  150. */
  151. public function setEnableFlatUserCreate(bool $enableFlatUserCreate): void
  152. {
  153. $this->enableFlatUserCreate = $enableFlatUserCreate;
  154. }
  155. /**
  156. * @return Flat|null
  157. */
  158. public function getMainFlat(): ?Flat
  159. {
  160. return $this->mainFlat;
  161. }
  162. /**
  163. * @param Flat|null $mainFlat
  164. */
  165. public function setMainFlat(?Flat $mainFlat): void
  166. {
  167. $this->mainFlat = $mainFlat;
  168. }
  169. /**
  170. * @return float|null
  171. */
  172. public function getStartingMoney(): ?float
  173. {
  174. return $this->startingMoney;
  175. }
  176. /**
  177. * @param float|null $startingMoney
  178. */
  179. public function setStartingMoney(?float $startingMoney): void
  180. {
  181. $this->startingMoney = $startingMoney;
  182. }
  183. /**
  184. * @return Collection<int, Equipment>
  185. */
  186. public function getEquipment(): Collection
  187. {
  188. return $this->equipment;
  189. }
  190. /**
  191. * @param Equipment $equip
  192. * @return void
  193. */
  194. public function setEquipment(Equipment $equip): void
  195. {
  196. $this->equipment[] = $equip;
  197. }
  198. /**
  199. * @return Collection<int, BuildingDictionary>
  200. */
  201. #[Ignore]
  202. public function getBuildingDictionaries(): Collection
  203. {
  204. return $this->buildingDictionaries;
  205. }
  206. /**
  207. * @param BuildingDictionary $buildingDictionary
  208. * @return void
  209. */
  210. #[Ignore]
  211. public function setBuildingDictionary(BuildingDictionary $buildingDictionary): void
  212. {
  213. $this->buildingDictionaries[] = $buildingDictionary;
  214. }
  215. /**
  216. * Get id
  217. *
  218. * @return int
  219. */
  220. public function getId(): int
  221. {
  222. return $this->id;
  223. }
  224. /**
  225. * @param string|null $comment
  226. *
  227. * @return $this
  228. */
  229. public function setComment(?string $comment): self
  230. {
  231. $this->comment = $comment;
  232. return $this;
  233. }
  234. /**
  235. * Get comment
  236. *
  237. * @return string|null
  238. */
  239. public function getComment(): ?string
  240. {
  241. return $this->comment;
  242. }
  243. /**
  244. * @return string|null
  245. */
  246. public function getPostCode(): ?string
  247. {
  248. return $this->postCode;
  249. }
  250. /**
  251. * @param string|null $postCode
  252. */
  253. public function setPostCode(?string $postCode): void
  254. {
  255. $this->postCode = $postCode;
  256. }
  257. /**
  258. * @return string|null
  259. */
  260. public function getCity(): ?string
  261. {
  262. return $this->city;
  263. }
  264. /**
  265. * @param string|null $city
  266. */
  267. public function setCity(?string $city): void
  268. {
  269. $this->city = $city;
  270. }
  271. /**
  272. * @return string|null
  273. */
  274. public function getMunicipality(): ?string
  275. {
  276. return $this->municipality;
  277. }
  278. /**
  279. * @param string|null $municipality
  280. */
  281. public function setMunicipality(?string $municipality): void
  282. {
  283. $this->municipality = $municipality;
  284. }
  285. /**
  286. * Set address
  287. *
  288. * @param string|null $address
  289. *
  290. * @return Building
  291. */
  292. public function setAddress(?string $address): Building
  293. {
  294. $this->address = $address;
  295. return $this;
  296. }
  297. /**
  298. * @return Building|null
  299. */
  300. public function getBuildingIdBs(): ?Building
  301. {
  302. return $this->buildingIdBs;
  303. }
  304. /**
  305. * @param Building|null $buildingIdBs
  306. */
  307. public function setBuildingIdBs(?Building $buildingIdBs): void
  308. {
  309. $this->buildingIdBs = $buildingIdBs;
  310. }
  311. /**
  312. * Get address
  313. *
  314. * @return string|null
  315. */
  316. public function getAddress(): ?string
  317. {
  318. return $this->address;
  319. }
  320. /**
  321. * Set flats
  322. *
  323. * @param int|null $flats
  324. *
  325. * @return Building
  326. */
  327. public function setFlats(?int $flats): Building
  328. {
  329. $this->flats = $flats;
  330. return $this;
  331. }
  332. /**
  333. * Get flats
  334. *
  335. * @return int|null
  336. */
  337. public function getFlats(): ?int
  338. {
  339. return $this->flats;
  340. }
  341. /**
  342. * @param float|null $buildingSize
  343. *
  344. * @return $this
  345. */
  346. public function setBuildingSize(?float $buildingSize): self
  347. {
  348. $this->buildingSize = $buildingSize;
  349. return $this;
  350. }
  351. /**
  352. * Get population
  353. *
  354. * @return int|null
  355. */
  356. public function getPopulation(): ?int
  357. {
  358. return $this->population;
  359. }
  360. /**
  361. * Set pupulation
  362. *
  363. * @param int|null $population
  364. *
  365. * @return Building
  366. */
  367. public function setPopulation(?int $population): Building
  368. {
  369. $this->population = $population;
  370. return $this;
  371. }
  372. /**
  373. * Get buildingSize
  374. *
  375. * @return float|null
  376. */
  377. public function getBuildingSize(): ?float
  378. {
  379. return $this->buildingSize;
  380. }
  381. /**
  382. * @return User
  383. */
  384. public function getUser(): User
  385. {
  386. return $this->user;
  387. }
  388. /**
  389. * @param User $user
  390. */
  391. public function setUser(User $user): void
  392. {
  393. $this->user = $user;
  394. if (empty($this->createdBy)) {
  395. $this->createdBy = $user->getCreatedByValue();
  396. }
  397. }
  398. /**
  399. * @return int|null
  400. */
  401. public function getType(): ?int
  402. {
  403. return $this->type;
  404. }
  405. /**
  406. * @param int|null $type
  407. */
  408. public function setType(?int $type): void
  409. {
  410. $this->type = $type;
  411. }
  412. /**
  413. * @param int $increment
  414. */
  415. public function incrementPopulation(int $increment): void
  416. {
  417. $this->population = $this->population + $increment;
  418. }
  419. /**
  420. * @param int $decrement
  421. */
  422. public function decrementPopulation(int $decrement): void
  423. {
  424. $this->population = $this->population - $decrement;
  425. }
  426. /**
  427. * @param int|float $decrement
  428. */
  429. public function decrementBuildingSize(int|float $decrement): void
  430. {
  431. $this->buildingSize -= $decrement;
  432. }
  433. /**
  434. * @param int $changeSize
  435. */
  436. public function changeSumSize(int $changeSize): void
  437. {
  438. $this->buildingSize = $this->buildingSize + $changeSize;
  439. }
  440. /**
  441. * Set code
  442. *
  443. * @param string|null $code
  444. *
  445. * @return Building
  446. */
  447. public function setCode(?string $code): self
  448. {
  449. $this->code = $code;
  450. return $this;
  451. }
  452. /**
  453. * Get code
  454. *
  455. * @return string|null
  456. */
  457. public function getCode(): ?string
  458. {
  459. return $this->code;
  460. }
  461. /**
  462. * Set pib
  463. *
  464. * @param string|null $pib
  465. *
  466. * @return Building
  467. */
  468. public function setPib(?string $pib): self
  469. {
  470. $this->pib = $pib;
  471. return $this;
  472. }
  473. /**
  474. * Get code
  475. *
  476. * @return string|null
  477. */
  478. public function getPib(): ?string
  479. {
  480. return $this->pib;
  481. }
  482. /**
  483. * Set matId
  484. *
  485. * @param string|null $matId
  486. *
  487. * @return Building
  488. */
  489. public function setMatId(?string $matId): Building
  490. {
  491. $this->matId = $matId;
  492. return $this;
  493. }
  494. /**
  495. * Get matId
  496. *
  497. * @return string|null
  498. */
  499. public function getMatId(): ?string
  500. {
  501. return $this->matId;
  502. }
  503. /**
  504. * @return string|null
  505. */
  506. public function getEmail(): ?string
  507. {
  508. return $this->email;
  509. }
  510. /**
  511. * @param string|null $email
  512. */
  513. public function setEmail(?string $email): void
  514. {
  515. $this->email = $email;
  516. }
  517. /**
  518. * Set bankAccount
  519. *
  520. * @param string|null $bankAccount
  521. *
  522. * @return Building
  523. */
  524. public function setBankAccount(?string $bankAccount): Building
  525. {
  526. $this->bankAccount = $bankAccount;
  527. return $this;
  528. }
  529. /**
  530. * Get bankAccount
  531. *
  532. * @return string|null
  533. */
  534. public function getBankAccount(): ?string
  535. {
  536. return $this->bankAccount;
  537. }
  538. /**
  539. *
  540. */
  541. public function incrementFlatsNumber(): void
  542. {
  543. $this->flats++;
  544. }
  545. /**
  546. *
  547. */
  548. public function decrementFlatsNumber(): void
  549. {
  550. $this->flats--;
  551. }
  552. public function secretBillNumber(): string
  553. {
  554. return sprintf("%s%s", mb_substr($this->getAddress(), 0, 2), $this->getId());
  555. }
  556. /**
  557. * @return DateTime|null
  558. */
  559. public function getCreatedAt(): ?DateTime
  560. {
  561. return $this->createdAt;
  562. }
  563. /**
  564. * @param DateTime|null $createdAt
  565. */
  566. public function setCreatedAt(?DateTime $createdAt): void
  567. {
  568. $this->createdAt = $createdAt;
  569. }
  570. /**
  571. * @return DateTime|null
  572. */
  573. public function getUpdatedAt(): ?DateTime
  574. {
  575. return $this->updatedAt;
  576. }
  577. /**
  578. * @param DateTime|null $updatedAt
  579. */
  580. public function setUpdatedAt(?DateTime $updatedAt): void
  581. {
  582. $this->updatedAt = $updatedAt;
  583. }
  584. /**
  585. * @return string|null
  586. */
  587. public function getConstructionYear(): ?string
  588. {
  589. return $this->constructionYear;
  590. }
  591. /**
  592. * @param string|null $constructionYear
  593. */
  594. public function setConstructionYear(?string $constructionYear): void
  595. {
  596. $this->constructionYear = $constructionYear;
  597. }
  598. /**
  599. * @return int
  600. */
  601. public function getActiveStatus(): int
  602. {
  603. return $this->activeStatus;
  604. }
  605. /**
  606. * @param int $activeStatus
  607. */
  608. public function setActiveStatus(int $activeStatus): void
  609. {
  610. $this->activeStatus = $activeStatus;
  611. }
  612. /**
  613. * @return int|null
  614. */
  615. public function getElevator(): ?int
  616. {
  617. return $this->elevator;
  618. }
  619. /**
  620. * @param int|null $elevator
  621. */
  622. public function setElevator(?int $elevator): void
  623. {
  624. $this->elevator = $elevator;
  625. }
  626. /**
  627. * @return string|null
  628. */
  629. public function getBuildingServicing(): ?string
  630. {
  631. return $this->buildingServicing;
  632. }
  633. /**
  634. * @param string|null $buildingServicing
  635. */
  636. public function setBuildingServicing(?string $buildingServicing): void
  637. {
  638. $this->buildingServicing = $buildingServicing;
  639. }
  640. /**
  641. * @return int|null
  642. */
  643. public function isManagement(): ?int
  644. {
  645. return $this->management;
  646. }
  647. /**
  648. * @param int|null $management
  649. */
  650. public function setManagement(?int $management): void
  651. {
  652. $this->management = $management;
  653. }
  654. public function __toString()
  655. {
  656. return (string) $this->getAddress();
  657. }
  658. }