src/Entity/Gauge/Invoice.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gauge;
  3. use App\Entity\Extension\BlameableTrait;
  4. use App\Entity\Extension\ImportableInterface;
  5. use App\Entity\Extension\TimestampableTrait;
  6. use App\Entity\File;
  7. use App\Entity\FileCategory;
  8. use App\Entity\Import\DataImport;
  9. use App\Utils\GaugeType;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use App\Repository\Gauge\InvoiceRepository;
  14. use App\Validator as AcmeAssert;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. /**
  17. * @ORM\Entity(repositoryClass=InvoiceRepository::class)
  18. * @ORM\Table(name="invoices", indexes={@ORM\Index(name="date_idx", columns={"date_from", "date_to"})})
  19. */
  20. class Invoice implements ImportableInterface
  21. {
  22. /**
  23. * @var int|null
  24. * @ORM\Id()
  25. * @ORM\GeneratedValue()
  26. * @ORM\Column(type="integer")
  27. */
  28. private ?int $id = null;
  29. /**
  30. * @var Gauge $gauge
  31. * @ORM\ManyToOne(targetEntity="App\Entity\Gauge\Gauge", inversedBy="invoices")
  32. * @ORM\JoinColumn(name="gauge_id", referencedColumnName="id", nullable=false)
  33. */
  34. private Gauge $gauge;
  35. /**
  36. * @var bool
  37. * @ORM\Column(name="credit_note", type="boolean", nullable=false, options={"default": 0})
  38. */
  39. private bool $creditNote = false;
  40. /**
  41. * @var string
  42. * @ORM\Column(type="string")
  43. */
  44. private string $invoiceNumber;
  45. /**
  46. * @var \DateTime
  47. * @AcmeAssert\DateTimeRange()
  48. * @ORM\Column(name="date_from", type="datetime", nullable=false)
  49. */
  50. protected \DateTime $dateFrom;
  51. /**
  52. * @var \DateTime
  53. * @AcmeAssert\DateTimeRange()
  54. * @ORM\Column(name="date_to", type="datetime", nullable=false)
  55. */
  56. protected \DateTime $dateTo;
  57. /**
  58. * @ORM\Column(type="float", options={"default" : 0})
  59. */
  60. private float $priceWithoutVat;
  61. /**
  62. * @ORM\Column(type="float")
  63. */
  64. private float $price;
  65. /**
  66. * @var File|null
  67. * @ORM\ManyToOne(targetEntity="App\Entity\File", inversedBy="invoices")
  68. * @ORM\JoinColumn(nullable=true)
  69. */
  70. private ?File $file = null;
  71. /**
  72. * @var string|null
  73. * @ORM\Column(type="text", nullable=true)
  74. */
  75. private ?string $note = null;
  76. /**
  77. * @var DataImport|null
  78. * @ORM\ManyToOne(targetEntity="App\Entity\Import\DataImport", inversedBy="invoices")
  79. * @ORM\JoinColumn(nullable=true)
  80. */
  81. private ?DataImport $import = null;
  82. /**
  83. * @var Collection|InvoiceValue[]
  84. * @ORM\OneToMany(targetEntity="App\Entity\Gauge\InvoiceValue", mappedBy="invoice", cascade={"all"})
  85. */
  86. private $values;
  87. /**
  88. * record_id in Revisio source database, also referencing an entry in RevisioRecord
  89. * @var ?RevisioRecord
  90. * @ORM\OneToOne(targetEntity="App\Entity\Gauge\RevisioRecord", cascade={"all"})
  91. * @ORM\JoinColumn(name="revisio_record_id", referencedColumnName="record_id", nullable=true)
  92. */
  93. private ?RevisioRecord $revisioRecord = null;
  94. use BlameableTrait;
  95. use TimestampableTrait;
  96. public function __construct()
  97. {
  98. $this->values = new ArrayCollection();
  99. }
  100. /**
  101. * @return int|null
  102. */
  103. public function getId(): ?int
  104. {
  105. return $this->id;
  106. }
  107. /**
  108. * @param int|null $id
  109. * @return Invoice
  110. */
  111. public function setId(?int $id): Invoice
  112. {
  113. $this->id = $id;
  114. return $this;
  115. }
  116. /**
  117. * @return bool
  118. */
  119. public function isCreditNote(): bool
  120. {
  121. return $this->creditNote;
  122. }
  123. /**
  124. * @param bool $creditNote
  125. * @return self
  126. */
  127. public function setCreditNote(bool $creditNote): self
  128. {
  129. $this->creditNote = $creditNote;
  130. return $this;
  131. }
  132. /**
  133. * @return Gauge
  134. */
  135. public function getGauge(): Gauge
  136. {
  137. return $this->gauge;
  138. }
  139. /**
  140. * @param Gauge $gauge
  141. * @return Invoice
  142. */
  143. public function setGauge(Gauge $gauge): Invoice
  144. {
  145. $this->gauge = $gauge;
  146. return $this;
  147. }
  148. /**
  149. * @return string
  150. */
  151. public function getInvoiceNumber(): string
  152. {
  153. return $this->invoiceNumber;
  154. }
  155. /**
  156. * @param string $invoiceNumber
  157. * @return Invoice
  158. */
  159. public function setInvoiceNumber(string $invoiceNumber): Invoice
  160. {
  161. $this->invoiceNumber = $invoiceNumber;
  162. return $this;
  163. }
  164. /**
  165. * @return \DateTime
  166. */
  167. public function getDateFrom(): \DateTime
  168. {
  169. return $this->dateFrom;
  170. }
  171. /**
  172. * @param \DateTime $dateFrom
  173. * @return Invoice
  174. */
  175. public function setDateFrom(\DateTime $dateFrom): Invoice
  176. {
  177. $this->dateFrom = $dateFrom;
  178. return $this;
  179. }
  180. /**
  181. * @return \DateTime
  182. */
  183. public function getDateTo(): \DateTime
  184. {
  185. return $this->dateTo;
  186. }
  187. /**
  188. * @param \DateTime $dateTo
  189. * @return Invoice
  190. */
  191. public function setDateTo(\DateTime $dateTo): Invoice
  192. {
  193. $this->dateTo = $dateTo;
  194. return $this;
  195. }
  196. /**
  197. * @return InvoiceValue[]|Collection
  198. */
  199. public function getValues()
  200. {
  201. return $this->values;
  202. }
  203. /**
  204. * @param InvoiceValue[]|Collection $values
  205. * @return Invoice
  206. */
  207. public function setValues($values)
  208. {
  209. $this->values = $values;
  210. return $this;
  211. }
  212. /**
  213. * @param InvoiceValue $value
  214. * @return $this
  215. */
  216. public function addValue(InvoiceValue $value): self
  217. {
  218. if (!$this->values->contains($value)) {
  219. $this->values->add($value);
  220. $value->setInvoice($this);
  221. }
  222. return $this;
  223. }
  224. /**
  225. * @param int $segment
  226. * @return float|null
  227. */
  228. public function getSegmentValue(int $segment) : ?float
  229. {
  230. foreach ($this->getValues() as $invValue) {
  231. if ($invValue->getSegment() === $segment) {
  232. return $invValue->getValue();
  233. }
  234. }
  235. return null;
  236. }
  237. /**
  238. * @param int $segment
  239. * @return InvoiceValue|null
  240. */
  241. public function getValueItemBySegment(int $segment) : ?InvoiceValue
  242. {
  243. foreach ($this->getValues() as $invValue) {
  244. if ($invValue->getSegment() === $segment) {
  245. return $invValue;
  246. }
  247. }
  248. return null;
  249. }
  250. /**
  251. * @return float
  252. */
  253. public function getPrice(): float
  254. {
  255. return $this->price;
  256. }
  257. /**
  258. * @param float $price
  259. * @return Invoice
  260. */
  261. public function setPrice(float $price): Invoice
  262. {
  263. $this->price = $price;
  264. return $this;
  265. }
  266. /**
  267. * @return File|null
  268. */
  269. public function getFile(): ?File
  270. {
  271. return $this->file;
  272. }
  273. /**
  274. * @param File|null $file
  275. * @return Invoice
  276. */
  277. public function setFile(?File $file): Invoice
  278. {
  279. $this->file = $file;
  280. if ($file !== null) {
  281. $file->addGauge($this->getGauge());
  282. }
  283. return $this;
  284. }
  285. /**
  286. * @return string
  287. */
  288. public function getFileCategoryMachineName(): string
  289. {
  290. $catNamesByType = [
  291. GaugeType::TYPE_ELECTRICITY_METER => FileCategory::INVOICES_ELECTRICITY,
  292. GaugeType::TYPE_HEAT_METER => FileCategory::INVOICES_HEAT,
  293. GaugeType::TYPE_GASOMETER => FileCategory::INVOICES_GAS,
  294. GaugeType::TYPE_WATER_METER => FileCategory::INVOICES_WATER,
  295. ];
  296. if (array_key_exists($this->getGauge()->getType(), $catNamesByType)) {
  297. return $catNamesByType[$this->getGauge()->getType()];
  298. }
  299. return FileCategory::INVOICES_OTHER;
  300. }
  301. public function getNote(): ?string
  302. {
  303. return $this->note;
  304. }
  305. public function setNote(?string $note): Invoice
  306. {
  307. $this->note = $note;
  308. return $this;
  309. }
  310. public function getPriceWithoutVat(): float
  311. {
  312. return $this->priceWithoutVat;
  313. }
  314. public function setPriceWithoutVat(float $priceWithoutVat): Invoice
  315. {
  316. $this->priceWithoutVat = $priceWithoutVat;
  317. return $this;
  318. }
  319. public function getImport(): ?DataImport
  320. {
  321. return $this->import;
  322. }
  323. public function setImport(?DataImport $import): Invoice
  324. {
  325. $this->import = $import;
  326. return $this;
  327. }
  328. /**
  329. * @return RevisioRecord|null
  330. */
  331. public function getRevisioRecord(): ?RevisioRecord
  332. {
  333. return $this->revisioRecord;
  334. }
  335. /**
  336. * @param RevisioRecord|null $revisioRecord
  337. * @return $this
  338. */
  339. public function setRevisioRecord(?RevisioRecord $revisioRecord): Invoice
  340. {
  341. $this->revisioRecord = $revisioRecord;
  342. return $this;
  343. }
  344. }