src/Entity/System/OrderReturnLine.php line 15

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