src/Entity/WayBill.php line 22

Open in your IDE?
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: parcel
  5. * Date: 8/24/18
  6. * Time: 7:43 PM
  7. */
  8. namespace App\Entity;
  9. use App\Parcels\CustomConstraints\DestinationSetError;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use JMS\Serializer\Annotation as Serializer;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15. * @ORM\Entity(repositoryClass="App\Repository\WayBillRepository")
  16. * @ORM\Table(name="way_bill")
  17. */
  18. class WayBill {
  19. /**
  20. * @ORM\Id
  21. * @ORM\GeneratedValue(strategy="IDENTITY")
  22. * @ORM\Column(type="integer")
  23. */
  24. private $id;
  25. /**
  26. * @Assert\NotBlank(message="Please fill in parcel sender")
  27. * @ORM\Column(type="string")
  28. */
  29. private $senderName;
  30. /**
  31. * @Assert\NotBlank(message="Please fill in sender phone number")
  32. * @Assert\Length(max="12",
  33. * min="12",
  34. * maxMessage="the sender phone number must have 12 numerals",
  35. * maxMessage="the sender phone number must have at least 12 numerals" )
  36. * @ORM\Column(type="string", length=12)
  37. */
  38. private $senderPhoneNumber;
  39. /**
  40. * @Assert\NotBlank(message="Please fill in receiver name")
  41. * @ORM\Column(type="string")
  42. */
  43. private $receiverName;
  44. /**
  45. * @Assert\NotBlank(message="Please fill in the receiver Phone number")
  46. * @Assert\Length(max="12",
  47. * min="12",
  48. * maxMessage="the phone number must have 12 numerals",
  49. * maxMessage="the phone number must have at least 12 numerals" )
  50. * @ORM\Column(type="string", length=12)
  51. */
  52. private $receiverPhoneNumber;
  53. /**
  54. * @var Station
  55. *
  56. * @ORM\ManyToOne(targetEntity="App\Entity\Station")
  57. * @ORM\JoinColumns({
  58. * @ORM\JoinColumn(name="from_station_id", referencedColumnName="id")
  59. * })
  60. */
  61. private $fromStation;
  62. /**
  63. * @var Station
  64. * @DestinationSetError(message2="Destination cannot be the same as Origin Station", message1="Destination has an error Please Check again", message="Please Select Destination station")
  65. * @ORM\ManyToOne(targetEntity="App\Entity\Station")
  66. * @ORM\JoinColumns({
  67. * @ORM\JoinColumn(name="to_station_id", referencedColumnName="id")
  68. * })
  69. */
  70. private $toStation;
  71. // * @Serializer\Type("DateTime<'Y-m-d H:i:s>")
  72. /**
  73. * @Serializer\Type("DateTime<'Y-m-d H:i:s'>")
  74. * @ORM\Column(type="datetime")
  75. */
  76. private $createdAt;
  77. /**
  78. * @var User
  79. * @ORM\ManyToOne(targetEntity="User")
  80. * @ORM\JoinColumns({
  81. * @ORM\JoinColumn(name="created_by", referencedColumnName="id")
  82. * })
  83. */
  84. private $createdBy;
  85. ///* @Assert\NotBlank(message="Please enter amount")
  86. //* @Assert\NotNull(message="Please key in an amount")
  87. //* @Assert\Count(min=1, max="1", minMessage="Please enter an amount", maxMessage="Please enter only one amount")
  88. //* @Serializer\Type("Transaction")*/
  89. /**
  90. * @var Transaction $transaction
  91. * @Serializer\Type("App\Entity\Transaction")
  92. * @Assert\Valid()
  93. * @Assert\NotNull(message="Please Enter an amount for this transaction")
  94. * @ORM\OneToOne(targetEntity="Transaction", mappedBy="wayBill", cascade={"persist", "remove"})
  95. */
  96. private $transaction;
  97. /**
  98. * @Assert\NotBlank(message="Please enter a parcel")
  99. * @Assert\NotNull(message="Please key in a parcel")
  100. * @Assert\Count(min=1, minMessage="Please enter a parcel")
  101. * @Serializer\Type("ArrayCollection<App\Entity\Parcel>")
  102. * @ORM\OneToMany(targetEntity="App\Entity\Parcel", mappedBy="waybill", cascade={"persist", "remove"})
  103. */
  104. private $parcels;
  105. /**
  106. * @ORM\Column(type="boolean")
  107. */
  108. private $isCollected;
  109. /**
  110. * @ORM\Column(type="boolean")
  111. */
  112. private $isReceived;
  113. /**
  114. * @var User
  115. * @ORM\ManyToOne(targetEntity="User")
  116. * @ORM\JoinColumns({
  117. * @ORM\JoinColumn(name="received_by", referencedColumnName="id")
  118. * })
  119. */
  120. private $receivedBy;
  121. /**
  122. * @var Organization
  123. * @ORM\ManyToOne(targetEntity="App\Entity\Organization")
  124. * @ORM\JoinColumns({
  125. * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", nullable=true)
  126. * })
  127. */
  128. private $organization;
  129. /**
  130. * @Serializer\Type("App\Entity\CollectedParcel")
  131. * @ORM\OneToOne(targetEntity="App\Entity\CollectedParcel", mappedBy="waybill")
  132. */
  133. private $collectedParcel;
  134. /**
  135. * @ORM\Column(type="datetime", nullable=true)
  136. */
  137. private $receivedAt;
  138. /**
  139. * @ORM\Column(type="integer")
  140. */
  141. private $percelCount;
  142. /**
  143. * @ORM\Column(type="float")
  144. */
  145. private $longitude;
  146. /**
  147. * @ORM\Column(type="float")
  148. */
  149. private $latitude;
  150. /**
  151. * @Assert\NotBlank(message="Please enter the parcel value")
  152. * @ORM\Column(type="integer")
  153. */
  154. private $parcelValue;
  155. public function __construct(){
  156. $this->parcels = new ArrayCollection();
  157. }
  158. /**
  159. * @return mixed
  160. */
  161. public function getId()
  162. {
  163. return $this->id;
  164. }
  165. /**
  166. * @param mixed $id
  167. */
  168. public function setId($id)
  169. {
  170. $this->id = $id;
  171. }
  172. /**
  173. * @return mixed
  174. */
  175. public function getSenderName()
  176. {
  177. return $this->senderName;
  178. }
  179. /**
  180. * @param mixed $senderName
  181. */
  182. public function setSenderName($senderName)
  183. {
  184. $this->senderName = $senderName;
  185. }
  186. /**
  187. * @return mixed
  188. */
  189. public function getSenderPhoneNumber()
  190. {
  191. return $this->senderPhoneNumber;
  192. }
  193. /**
  194. * @param mixed $senderPhoneNumber
  195. */
  196. public function setSenderPhoneNumber($senderPhoneNumber)
  197. {
  198. $this->senderPhoneNumber = $senderPhoneNumber;
  199. }
  200. /**
  201. * @return mixed
  202. */
  203. public function getReceiverName()
  204. {
  205. return $this->receiverName;
  206. }
  207. /**
  208. * @param mixed $receiverName
  209. */
  210. public function setReceiverName($receiverName)
  211. {
  212. $this->receiverName = $receiverName;
  213. }
  214. /**
  215. * @return mixed
  216. */
  217. public function getReceiverPhoneNumber()
  218. {
  219. return $this->receiverPhoneNumber;
  220. }
  221. /**
  222. * @param mixed $receiverPhoneNumber
  223. */
  224. public function setReceiverPhoneNumber($receiverPhoneNumber)
  225. {
  226. $this->receiverPhoneNumber = $receiverPhoneNumber;
  227. }
  228. /**
  229. * @return Station
  230. */
  231. public function getFromStation()
  232. {
  233. return $this->fromStation;
  234. }
  235. /**
  236. * @param Station $fromStation
  237. */
  238. public function setFromStation($fromStation)
  239. {
  240. $this->fromStation = $fromStation;
  241. }
  242. /**
  243. * @return Station
  244. */
  245. public function getToStation()
  246. {
  247. return $this->toStation;
  248. }
  249. /**
  250. * @param Station $toStation
  251. */
  252. public function setToStation($toStation)
  253. {
  254. $this->toStation = $toStation;
  255. }
  256. /**
  257. * @return mixed
  258. */
  259. public function getIsCollected()
  260. {
  261. return $this->isCollected;
  262. }
  263. /**
  264. * @param mixed $isCollected
  265. */
  266. public function setIsCollected($isCollected)
  267. {
  268. $this->isCollected = $isCollected;
  269. }
  270. /**
  271. * @return mixed
  272. */
  273. public function getCreatedAt()
  274. {
  275. return $this->createdAt;
  276. }
  277. /**
  278. * @param mixed $createdAt
  279. */
  280. public function setCreatedAt($createdAt)
  281. {
  282. $this->createdAt = $createdAt;
  283. }
  284. /**
  285. * @return Organization
  286. */
  287. public function getOrganization()
  288. {
  289. return $this->organization;
  290. }
  291. /**
  292. * @param Organization $organization
  293. */
  294. public function setOrganization($organization)
  295. {
  296. $this->organization = $organization;
  297. }
  298. /**
  299. * @return User
  300. */
  301. public function getCreatedBy()
  302. {
  303. return $this->createdBy;
  304. }
  305. /**
  306. * @param User $createdBy
  307. */
  308. public function setCreatedBy($createdBy)
  309. {
  310. $this->createdBy = $createdBy;
  311. }
  312. /**
  313. * @return mixed
  314. */
  315. public function getParcels()
  316. {
  317. return $this->parcels;
  318. }
  319. /**
  320. * @param mixed $parcels
  321. */
  322. public function setParcels($parcels)
  323. {
  324. $this->parcels = $parcels;
  325. }
  326. public function addParcel(Parcel $parcel) {
  327. // $parcel->setInOfficeFrom(new \DateTime());
  328. // $parcel->setIsReceived(false);
  329. // $parcel->setIsEnRoute(false);
  330. // $parcel->setIsCollected(false);
  331. $parcel->setCreatedAt(new \DateTime());
  332. $parcel->setWaybill($this);
  333. $parcel->setIsInDelivery(false);
  334. $this->parcels->add($parcel);
  335. }
  336. public function removeParcel(Parcel $parcel)
  337. {
  338. $this->parcels->removeElement($parcel);
  339. }
  340. /**
  341. * @return Transaction
  342. */
  343. public function getTransaction()
  344. {
  345. return $this->transaction;
  346. }
  347. /**
  348. * @param Transaction $transaction
  349. */
  350. public function setTransaction(Transaction $transaction)
  351. {
  352. $this->transaction = $transaction;
  353. }
  354. public function addTransaction(DailyAccount $dailyAccount) {
  355. $this->transaction->setTaxPercentage(16);
  356. $taxPercentage = $this->transaction->getTaxPercentage();
  357. $taxAmount = round((($this->transaction->getAmount()*$taxPercentage)/116), 2);
  358. $balance = round(($this->transaction->getAmount() - $taxAmount), 2);
  359. $this->transaction->setStationExpenses(0);
  360. $this->transaction->setExpenses(0);
  361. $this->transaction->setOrganization($this->getOrganization());
  362. $this->transaction->setCreatedBy($this->createdBy);
  363. $this->transaction->setCreatedAt($this->createdAt);
  364. $this->transaction->setWayBill($this);
  365. $this->transaction->setTaxAmount($taxAmount);
  366. $this->transaction->setGrossAmount($this->transaction->getAmount());
  367. $this->transaction->setBalance($this->transaction->getAmount());
  368. $this->transaction->setStationBalance($this->transaction->getAmount());
  369. $this->transaction->setDailyAccount($dailyAccount);
  370. $this->transaction->setIsCancelled(false);
  371. $this->transaction->setIsComplete(false);
  372. $this->transaction->setPaidBy('CASH');
  373. $this->transaction->setIsPaid(false);
  374. $this->transaction->setMpesaAmount(0);
  375. $this->transaction->setCashAmount(0);
  376. $this->transaction->setIsFinal(false);
  377. }
  378. /**
  379. * @return mixed
  380. */
  381. public function getPercelCount()
  382. {
  383. return $this->percelCount;
  384. }
  385. /**
  386. * @param mixed $percelCount
  387. */
  388. public function setPercelCount($percelCount)
  389. {
  390. $this->percelCount = $percelCount;
  391. }
  392. /**
  393. * @return mixed
  394. */
  395. public function getCollectedParcel()
  396. {
  397. return $this->collectedParcel;
  398. }
  399. /**
  400. * @param mixed $collectedParcel
  401. */
  402. public function setCollectedParcel($collectedParcel)
  403. {
  404. $this->collectedParcel = $collectedParcel;
  405. }
  406. /**
  407. * @return mixed
  408. */
  409. public function getIsReceived()
  410. {
  411. return $this->isReceived;
  412. }
  413. /**
  414. * @param mixed $isReceived
  415. */
  416. public function setIsReceived($isReceived)
  417. {
  418. $this->isReceived = $isReceived;
  419. }
  420. /**
  421. * @return User
  422. */
  423. public function getReceivedBy()
  424. {
  425. return $this->receivedBy;
  426. }
  427. /**
  428. * @param User $receivedBy
  429. */
  430. public function setReceivedBy($receivedBy)
  431. {
  432. $this->receivedBy = $receivedBy;
  433. }
  434. /**
  435. * @return mixed
  436. */
  437. public function getReceivedAt()
  438. {
  439. return $this->receivedAt;
  440. }
  441. /**
  442. * @param mixed $receivedAt
  443. */
  444. public function setReceivedAt($receivedAt)
  445. {
  446. $this->receivedAt = $receivedAt;
  447. }
  448. /**
  449. * @return mixed
  450. */
  451. public function getParcelValue()
  452. {
  453. return $this->parcelValue;
  454. }
  455. /**
  456. * @param mixed $parcelValue
  457. */
  458. public function setParcelValue($parcelValue): void
  459. {
  460. $this->parcelValue = $parcelValue;
  461. }
  462. /**
  463. * @return mixed
  464. */
  465. public function getLongitude()
  466. {
  467. return $this->longitude;
  468. }
  469. /**
  470. * @param mixed $longitude
  471. */
  472. public function setLongitude($longitude): void
  473. {
  474. $this->longitude = $longitude;
  475. }
  476. /**
  477. * @return mixed
  478. */
  479. public function getLatitude()
  480. {
  481. return $this->latitude;
  482. }
  483. /**
  484. * @param mixed $latitude
  485. */
  486. public function setLatitude($latitude): void
  487. {
  488. $this->latitude = $latitude;
  489. }
  490. }