src/Entity/System/OrderReturnLine.php line 16

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\System;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Table(name="ps_returns_lines")
  9. *
  10. * @ORM\Entity(repositoryClass="App\Repository\System\OrderReturnLineRepository")
  11. */
  12. class OrderReturnLine
  13. {
  14. /**
  15. * @ORM\Id()
  16. *
  17. * @ORM\GeneratedValue()
  18. *
  19. * @ORM\Column(type="integer", name="id_returns_lines")
  20. */
  21. private ?int $id;
  22. /**
  23. * @ORM\ManyToOne(targetEntity="App\Entity\System\OrderReturn", inversedBy="lines")
  24. *
  25. * @ORM\JoinColumn(name="id_returns", referencedColumnName="id_returns")
  26. */
  27. private ?OrderReturn $rma;
  28. /**
  29. * @ORM\ManyToOne(targetEntity="App\Entity\System\OrderDetail")
  30. *
  31. * @ORM\JoinColumn(name="order_detail_id", referencedColumnName="id_order_detail")
  32. */
  33. private ?OrderDetail $orderDetail;
  34. /**
  35. * @ORM\ManyToOne(targetEntity="App\Entity\System\OrderReturnLineStatus")
  36. *
  37. * @ORM\JoinColumn(name="status_id", referencedColumnName="id", nullable=false)
  38. */
  39. private OrderReturnLineStatus $status;
  40. /**
  41. * @ORM\Column(type="integer", name="product_qty", length=10)
  42. */
  43. private int $productQuantity;
  44. /**
  45. * @ORM\Column(type="float", options={"default" : 0.00})
  46. */
  47. private float $price;
  48. /**
  49. * @ORM\Column(type="float", options={"default" : 0.00})
  50. */
  51. private float $tax;
  52. /**
  53. * @ORM\Column(type="datetime")
  54. */
  55. private \DateTime $dateAdd;
  56. /**
  57. * @ORM\Column(type="datetime")
  58. */
  59. private \DateTime $dateUpd;
  60. /**
  61. * @ORM\Column(type="string", nullable=true)
  62. */
  63. private ?string $noteSat = null;
  64. /**
  65. * @ORM\Column(type="text", nullable=true)
  66. */
  67. private ?string $satDescription = null;
  68. /**
  69. * @ORM\Column(type="text", nullable=true, name="sat_comments")
  70. */
  71. private ?string $satComments = null;
  72. /**
  73. * @ORM\Column(type="text", nullable=true)
  74. */
  75. private ?string $adminComments = null;
  76. /**
  77. * @ORM\Column(type="boolean", options={"default" : 0})
  78. */
  79. private bool $productOk;
  80. /**
  81. * @ORM\Column(type="boolean", options={"default" : 0})
  82. */
  83. private bool $validate = false;
  84. /**
  85. * @ORM\Column(type="boolean", options={"default" : 0}, nullable=true)
  86. */
  87. private ?bool $refused = null;
  88. /**
  89. * @ORM\Column(type="boolean", options={"default" : 0}, nullable=true)
  90. */
  91. private ?bool $confirmed = null;
  92. /**
  93. * @ORM\Column(type="boolean", name="revisar", options={"default" : 0}, nullable=true)
  94. */
  95. private ?bool $revised = null;
  96. /**
  97. * @ORM\Column(type="integer", length=2)
  98. */
  99. private int $taxRate = 0;
  100. /**
  101. * @var string
  102. *
  103. * @ORM\Column(type="text")
  104. */
  105. private $returnReason;
  106. /**
  107. * @var Collection<int, OrderReturnLineComment>
  108. *
  109. * @ORM\OneToMany(targetEntity="OrderReturnLineComment", mappedBy="returnsLine")
  110. */
  111. private $comments;
  112. /**
  113. * @var float
  114. *
  115. * @ORM\Column(type="float", options={"default" : 0})
  116. */
  117. private $total;
  118. /**
  119. * @var float
  120. *
  121. * @ORM\Column(type="float", options={"default" : 0})
  122. */
  123. private $totalPaid;
  124. /**
  125. * @var bool
  126. *
  127. * @ORM\Column(name="product_100", type="boolean", options={"default" : 0})
  128. */
  129. private $product100;
  130. /**
  131. * @var int
  132. *
  133. * @ORM\Column(type="integer")
  134. */
  135. private $receivedQuantity;
  136. /**
  137. * @var int
  138. *
  139. * @ORM\Column(type="integer")
  140. */
  141. private $acceptedQuantity;
  142. public function __construct()
  143. {
  144. $this->comments = new ArrayCollection();
  145. }
  146. public static function createRmaLine(
  147. OrderReturn $rma,
  148. OrderDetail $orderDetail,
  149. \DateTime $creationDate,
  150. OrderReturnLineStatus $status,
  151. int $quantity,
  152. float $price,
  153. float $tax,
  154. string $returnReason,
  155. ): self {
  156. $rmaLine = new self();
  157. $rmaLine->dateAdd = $creationDate;
  158. $rmaLine->dateUpd = $creationDate;
  159. $rmaLine->status = $status;
  160. $rmaLine->rma = $rma;
  161. $rmaLine->orderDetail = $orderDetail;
  162. $rmaLine->productQuantity = $quantity;
  163. $rmaLine->price = $price;
  164. $rmaLine->tax = $tax;
  165. $rmaLine->validate = false;
  166. $rmaLine->returnReason = $returnReason;
  167. $rmaLine->total = $price * $quantity;
  168. $rmaLine->totalPaid = $price * $quantity;
  169. $rmaLine->productOk = false;
  170. $rmaLine->product100 = false;
  171. $rmaLine->receivedQuantity = 0;
  172. $rmaLine->acceptedQuantity = 0;
  173. $rmaLine->taxRate = (int)$orderDetail->getTaxRate();
  174. return $rmaLine;
  175. }
  176. public function getId(): ?int
  177. {
  178. return $this->id;
  179. }
  180. public function setId(int $id): self
  181. {
  182. $this->id = $id;
  183. return $this;
  184. }
  185. public function getRma(): OrderReturn
  186. {
  187. return $this->rma;
  188. }
  189. public function setRma(OrderReturn $rma): self
  190. {
  191. $this->rma = $rma;
  192. return $this;
  193. }
  194. public function getProductQuantity(): int
  195. {
  196. return $this->productQuantity;
  197. }
  198. public function setProductQuantity(int $productQuantity): self
  199. {
  200. $this->productQuantity = $productQuantity;
  201. return $this;
  202. }
  203. public function getPrice(): float
  204. {
  205. return $this->price;
  206. }
  207. public function setPrice(float $price): self
  208. {
  209. $this->price = $price;
  210. return $this;
  211. }
  212. public function getTaxRate(): int
  213. {
  214. return $this->taxRate;
  215. }
  216. public function setTaxRate(int $taxRate): self
  217. {
  218. $this->taxRate = $taxRate;
  219. return $this;
  220. }
  221. public function getOrderDetail(): OrderDetail
  222. {
  223. return $this->orderDetail;
  224. }
  225. public function getReturnReason(): ?string
  226. {
  227. return $this->returnReason;
  228. }
  229. public function setReturnReason(string $returnReason): void
  230. {
  231. $this->returnReason = $returnReason;
  232. }
  233. public function getStatus(): OrderReturnLineStatus
  234. {
  235. return $this->status;
  236. }
  237. public function setStatus(OrderReturnLineStatus $status): void
  238. {
  239. $this->status = $status;
  240. }
  241. /**
  242. * @return Collection<int, OrderReturnLineComment>
  243. */
  244. public function getComments(): Collection
  245. {
  246. return $this->comments;
  247. }
  248. public function getTotal(): float
  249. {
  250. return $this->total;
  251. }
  252. public function getTotalPaid(): float
  253. {
  254. return $this->totalPaid;
  255. }
  256. public function setTotal(float $total): self
  257. {
  258. $this->total = $total;
  259. return $this;
  260. }
  261. public function setTotalPaid(float $totalPaid): self
  262. {
  263. $this->totalPaid = $totalPaid;
  264. return $this;
  265. }
  266. public function getProduct100(): bool
  267. {
  268. return $this->product100;
  269. }
  270. public function isRefused(): bool
  271. {
  272. return $this->refused ?? false;
  273. }
  274. public function setRefused(bool $refused): void
  275. {
  276. $this->refused = $refused;
  277. }
  278. public function isConfirmed(): bool
  279. {
  280. return $this->confirmed ?? false;
  281. }
  282. public function setConfirmed(bool $confirmed): void
  283. {
  284. $this->confirmed = $confirmed;
  285. }
  286. public function getNoteSat(): ?string
  287. {
  288. return $this->noteSat;
  289. }
  290. public function setNoteSat(?string $noteSat): self
  291. {
  292. $this->noteSat = $noteSat;
  293. return $this;
  294. }
  295. public function getTax(): float
  296. {
  297. return $this->tax;
  298. }
  299. public function setTax(float $tax): self
  300. {
  301. $this->tax = $tax;
  302. return $this;
  303. }
  304. public function getReceivedQuantity(): int
  305. {
  306. return $this->receivedQuantity;
  307. }
  308. public function setReceivedQuantity(int $receivedQuantity): self
  309. {
  310. $this->receivedQuantity = $receivedQuantity;
  311. return $this;
  312. }
  313. public function getAcceptedQuantity(): int
  314. {
  315. return $this->acceptedQuantity;
  316. }
  317. public function setAcceptedQuantity(int $acceptedQuantity): self
  318. {
  319. $this->acceptedQuantity = $acceptedQuantity;
  320. return $this;
  321. }
  322. public function setProductOk(bool $productOk): self
  323. {
  324. $this->productOk = $productOk;
  325. return $this;
  326. }
  327. public function setProduct100(bool $product100): self
  328. {
  329. $this->product100 = $product100;
  330. return $this;
  331. }
  332. public function isProductOk(): bool
  333. {
  334. return $this->productOk;
  335. }
  336. public function isProductReview(): bool
  337. {
  338. if ($this->receivedQuantity === 0) {
  339. return true;
  340. }
  341. return $this->getProduct100() || $this->isProductOk();
  342. }
  343. public function getDamagedGoodsFee(): int
  344. {
  345. if ($this->getProduct100()) {
  346. return 100;
  347. }
  348. return 0;
  349. }
  350. public function getSatComments(): ?string
  351. {
  352. return $this->satComments;
  353. }
  354. public function setSatComments(?string $satComments): self
  355. {
  356. $this->satComments = $satComments;
  357. return $this;
  358. }
  359. /**
  360. * @return string[]
  361. */
  362. public function getCommentDetails(): array
  363. {
  364. return array_map(static function (OrderReturnLineComment $comment) {
  365. return $comment->getComments();
  366. }, $this->comments->toArray());
  367. }
  368. public function updateTax(): self
  369. {
  370. $this->tax = ($this->totalPaid * $this->taxRate) / 100;
  371. return $this;
  372. }
  373. public function getAdminComments(): ?string
  374. {
  375. return $this->adminComments;
  376. }
  377. public function setAdminComments(?string $adminComments): self
  378. {
  379. $this->adminComments = $adminComments;
  380. return $this;
  381. }
  382. public function getDateAdd(): \DateTime
  383. {
  384. return $this->dateAdd;
  385. }
  386. public function getDateUpd(): \DateTime
  387. {
  388. return $this->dateUpd;
  389. }
  390. public function getSatDescription(): ?string
  391. {
  392. return $this->satDescription;
  393. }
  394. public function isValidate(): bool
  395. {
  396. return $this->validate;
  397. }
  398. public function isRevised(): bool
  399. {
  400. return $this->revised ?? false;
  401. }
  402. public function setSatDescription(?string $satDescription): self
  403. {
  404. $this->satDescription = $satDescription;
  405. return $this;
  406. }
  407. public function setValidate(bool $validate): self
  408. {
  409. $this->validate = $validate;
  410. return $this;
  411. }
  412. public function setRevised(bool $revised): self
  413. {
  414. $this->revised = $revised;
  415. return $this;
  416. }
  417. }