src/Bundles/Instruments/Base/Entity/CashFlows.php line 13

Open in your IDE?
  1. <?php
  2. namespace Bundles\Instruments\Base\Entity;
  3. use App\Entity\CurrencyPair;
  4. use Bundles\Portfolios\Entity\Portfolio as Portfolio;
  5. use Bundles\Instruments\Base\Repository\CashFlowsRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=CashFlowsRepository::class)
  9. */
  10. class CashFlows {
  11. /**
  12. * @ORM\Id
  13. * @ORM\GeneratedValue
  14. * @ORM\Column(type="integer")
  15. */
  16. private $id;
  17. /**
  18. * @ORM\ManyToOne(targetEntity=Portfolio::class)
  19. * @ORM\JoinColumn(nullable=false)
  20. */
  21. private $Portfolio;
  22. /**
  23. * @ORM\ManyToOne(targetEntity=CurrencyPair::class)
  24. * @ORM\JoinColumn(nullable=false)
  25. */
  26. private $CurrencyPair;
  27. /**
  28. * @ORM\Column(type="decimal", precision=20, scale=0, nullable=true)
  29. */
  30. private $cashAmount;
  31. /**
  32. * @ORM\Column(type="decimal", precision=20, scale=0)
  33. */
  34. private $cashAmountMinor;
  35. /**
  36. * @ORM\Column(type="string")
  37. */
  38. private $flowDate;
  39. /**
  40. * @ORM\Column(type="decimal", precision=10, scale=5, nullable=true)
  41. */
  42. private $rate;
  43. /**
  44. * @ORM\Column(type="decimal", precision=10, scale=5, nullable=true)
  45. */
  46. private $budgetRate;
  47. /**
  48. * @ORM\Column(type="integer", nullable=true)
  49. */
  50. private $hedgeRatio;
  51. /**
  52. * @ORM\Column(type="boolean", nullable=true)
  53. */
  54. private $status;
  55. /**
  56. * @ORM\Column(type="text", nullable=true)
  57. */
  58. private $comment;
  59. /**
  60. * @ORM\Column(type="text", nullable=true)
  61. */
  62. private $additionalInfo;
  63. /**
  64. * @ORM\Column(type="integer", nullable=true)
  65. */
  66. private $daysToExpire = 0;
  67. /**
  68. * tik committed forwardams. Susieti trade id su siuo flowsu
  69. * @var array
  70. */
  71. private $forwards = [];
  72. /**
  73. * tik committed forwardams. Susieti trade su siuo flowsu paheginta amounto suma (minor currency)
  74. * @var int
  75. */
  76. private $hedgedAmount = 0;
  77. public function getId(): ?int {
  78. return $this->id;
  79. }
  80. public function getComment(): ?string {
  81. return $this->comment;
  82. }
  83. public function setComment(?string $comment): self {
  84. $this->comment = $comment;
  85. return $this;
  86. }
  87. public function setId(int|null $id): self {
  88. $this->id = $id;
  89. return $this;
  90. }
  91. public function getPortfolio(): ?Portfolio {
  92. return $this->Portfolio;
  93. }
  94. public function setPortfolio(?Portfolio $Portfolio): self {
  95. $this->Portfolio = $Portfolio;
  96. return $this;
  97. }
  98. public function getCurrencyPair(): ?CurrencyPair {
  99. return $this->CurrencyPair;
  100. }
  101. public function setCurrencyPair(?CurrencyPair $CurrencyPair): self {
  102. $this->CurrencyPair = $CurrencyPair;
  103. return $this;
  104. }
  105. public function getCashAmount(): ?float {
  106. return $this->cashAmount;
  107. }
  108. public function setCashAmount(string $cashAmount): self {
  109. $this->cashAmount = $cashAmount;
  110. return $this;
  111. }
  112. public function getFlowDate(): ?string {
  113. return $this->flowDate;
  114. }
  115. public function setFlowDate(string $flowDate): self {
  116. $this->flowDate = $flowDate;
  117. return $this;
  118. }
  119. public function getRate(): ?string {
  120. return $this->rate;
  121. }
  122. public function setRate(string $rate): self {
  123. $this->rate = $rate;
  124. return $this;
  125. }
  126. public function getStatus(): ?bool {
  127. return $this->status;
  128. }
  129. public function setStatus(?bool $status): self {
  130. $this->status = $status;
  131. return $this;
  132. }
  133. /**
  134. * @return mixed
  135. */
  136. public function getCashAmountMinor() {
  137. // if(empty($this->cashAmountMinor)) {
  138. // return $this->cashAmount * $this->rate;
  139. // };
  140. return $this->cashAmountMinor;
  141. }
  142. /**
  143. * @param mixed $cashAmountMinor
  144. */
  145. public function setCashAmountMinor($cashAmountMinor): self {
  146. $this->cashAmountMinor = $cashAmountMinor;
  147. return $this;
  148. }
  149. /**
  150. * @return mixed
  151. */
  152. public function getBudgetRate() {
  153. return $this->budgetRate;
  154. }
  155. /**
  156. * @param mixed $budgetRate
  157. */
  158. public function setBudgetRate($budgetRate): void {
  159. $this->budgetRate = $budgetRate;
  160. }
  161. /**
  162. * @return mixed
  163. */
  164. public function getAdditionalInfo() {
  165. return $this->additionalInfo;
  166. }
  167. /**
  168. * @param mixed $additionalInfo
  169. */
  170. public function setAdditionalInfo($additionalInfo): void {
  171. $this->additionalInfo = $additionalInfo;
  172. }
  173. /**
  174. * @return mixed
  175. */
  176. public function getHedgeRatio() {
  177. return $this->hedgeRatio;
  178. }
  179. /**
  180. * @param mixed $hedgeRatio
  181. */
  182. public function setHedgeRatio($hedgeRatio): void {
  183. $this->hedgeRatio = $hedgeRatio;
  184. }
  185. public function __toString() {
  186. return $this->getFlowDate().' | '.round($this->getCashAmountMinor() / 1000, 1).'K | '.round($this->getBudgetRate(), 2);
  187. }
  188. public function getMinorCurrency() {
  189. return $this->getCurrencyPair()->getCurrencyNameByNumber(2);
  190. }
  191. /**
  192. * @return array
  193. */
  194. public function getForwards(): array {
  195. return $this->forwards;
  196. }
  197. /**
  198. * @param int $forwardId
  199. */
  200. public function addForward($forwardId): void {
  201. $this->forwards[] = $forwardId;
  202. }
  203. /**
  204. * @param array $forwards
  205. */
  206. public function setForwards(array $forwards): void {
  207. $this->forwards = $forwards;
  208. }
  209. /**
  210. * @return int
  211. */
  212. public function getHedgedAmount(): int {
  213. return $this->hedgedAmount;
  214. }
  215. /**
  216. * @param int $hedgedAmount
  217. */
  218. public function addHedgedAmount(int $hedgedAmount): void {
  219. $this->hedgedAmount += $hedgedAmount;
  220. }
  221. public function getDaysToExpire(): ?int {
  222. if (empty($this->daysToExpire)) {
  223. $this->daysToExpire = 1;
  224. }
  225. return $this->daysToExpire;
  226. }
  227. public function setDaysToExpire($expireDate): void {
  228. $now = date_create();
  229. $expireDate = date_create($expireDate);
  230. $this->daysToExpire = $this->countWorkdaysBetweenDates($now, $expireDate);
  231. }
  232. public function countWorkdaysBetweenDates($startDate, $endDate): int {
  233. // Ensure the end date is after the start date
  234. if ($endDate < $startDate) {
  235. throw new \InvalidArgumentException('End date must be greater than or equal to start date.');
  236. }
  237. // Create an interval of one day
  238. $interval = new \DateInterval('P1D');
  239. // Create a date period from start date to end date inclusive
  240. $period = new \DatePeriod($startDate, $interval, $endDate->add($interval));
  241. // Initialize weekday count
  242. $weekdayCount = 0;
  243. // Loop through each date in the period
  244. foreach ($period as $date) {
  245. // Get the day of the week as a number (1 for Monday, 7 for Sunday)
  246. $dayOfWeek = $date->format('N');
  247. // Check if the day is a weekday (1-5)
  248. if ($dayOfWeek < 6) {
  249. $weekdayCount++;
  250. }
  251. }
  252. return $weekdayCount;
  253. }
  254. }