<?php
namespace Bundles\Instruments\Base\Entity;
use App\Entity\CurrencyPair;
use Bundles\Portfolios\Entity\Portfolio as Portfolio;
use Bundles\Instruments\Base\Repository\CashFlowsRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CashFlowsRepository::class)
*/
class CashFlows {
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Portfolio::class)
* @ORM\JoinColumn(nullable=false)
*/
private $Portfolio;
/**
* @ORM\ManyToOne(targetEntity=CurrencyPair::class)
* @ORM\JoinColumn(nullable=false)
*/
private $CurrencyPair;
/**
* @ORM\Column(type="decimal", precision=20, scale=0, nullable=true)
*/
private $cashAmount;
/**
* @ORM\Column(type="decimal", precision=20, scale=0)
*/
private $cashAmountMinor;
/**
* @ORM\Column(type="string")
*/
private $flowDate;
/**
* @ORM\Column(type="decimal", precision=10, scale=5, nullable=true)
*/
private $rate;
/**
* @ORM\Column(type="decimal", precision=10, scale=5, nullable=true)
*/
private $budgetRate;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $hedgeRatio;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $status;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $comment;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $additionalInfo;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $daysToExpire = 0;
/**
* tik committed forwardams. Susieti trade id su siuo flowsu
* @var array
*/
private $forwards = [];
/**
* tik committed forwardams. Susieti trade su siuo flowsu paheginta amounto suma (minor currency)
* @var int
*/
private $hedgedAmount = 0;
public function getId(): ?int {
return $this->id;
}
public function getComment(): ?string {
return $this->comment;
}
public function setComment(?string $comment): self {
$this->comment = $comment;
return $this;
}
public function setId(int|null $id): self {
$this->id = $id;
return $this;
}
public function getPortfolio(): ?Portfolio {
return $this->Portfolio;
}
public function setPortfolio(?Portfolio $Portfolio): self {
$this->Portfolio = $Portfolio;
return $this;
}
public function getCurrencyPair(): ?CurrencyPair {
return $this->CurrencyPair;
}
public function setCurrencyPair(?CurrencyPair $CurrencyPair): self {
$this->CurrencyPair = $CurrencyPair;
return $this;
}
public function getCashAmount(): ?float {
return $this->cashAmount;
}
public function setCashAmount(string $cashAmount): self {
$this->cashAmount = $cashAmount;
return $this;
}
public function getFlowDate(): ?string {
return $this->flowDate;
}
public function setFlowDate(string $flowDate): self {
$this->flowDate = $flowDate;
return $this;
}
public function getRate(): ?string {
return $this->rate;
}
public function setRate(string $rate): self {
$this->rate = $rate;
return $this;
}
public function getStatus(): ?bool {
return $this->status;
}
public function setStatus(?bool $status): self {
$this->status = $status;
return $this;
}
/**
* @return mixed
*/
public function getCashAmountMinor() {
// if(empty($this->cashAmountMinor)) {
// return $this->cashAmount * $this->rate;
// };
return $this->cashAmountMinor;
}
/**
* @param mixed $cashAmountMinor
*/
public function setCashAmountMinor($cashAmountMinor): self {
$this->cashAmountMinor = $cashAmountMinor;
return $this;
}
/**
* @return mixed
*/
public function getBudgetRate() {
return $this->budgetRate;
}
/**
* @param mixed $budgetRate
*/
public function setBudgetRate($budgetRate): void {
$this->budgetRate = $budgetRate;
}
/**
* @return mixed
*/
public function getAdditionalInfo() {
return $this->additionalInfo;
}
/**
* @param mixed $additionalInfo
*/
public function setAdditionalInfo($additionalInfo): void {
$this->additionalInfo = $additionalInfo;
}
/**
* @return mixed
*/
public function getHedgeRatio() {
return $this->hedgeRatio;
}
/**
* @param mixed $hedgeRatio
*/
public function setHedgeRatio($hedgeRatio): void {
$this->hedgeRatio = $hedgeRatio;
}
public function __toString() {
return $this->getFlowDate().' | '.round($this->getCashAmountMinor() / 1000, 1).'K | '.round($this->getBudgetRate(), 2);
}
public function getMinorCurrency() {
return $this->getCurrencyPair()->getCurrencyNameByNumber(2);
}
/**
* @return array
*/
public function getForwards(): array {
return $this->forwards;
}
/**
* @param int $forwardId
*/
public function addForward($forwardId): void {
$this->forwards[] = $forwardId;
}
/**
* @param array $forwards
*/
public function setForwards(array $forwards): void {
$this->forwards = $forwards;
}
/**
* @return int
*/
public function getHedgedAmount(): int {
return $this->hedgedAmount;
}
/**
* @param int $hedgedAmount
*/
public function addHedgedAmount(int $hedgedAmount): void {
$this->hedgedAmount += $hedgedAmount;
}
public function getDaysToExpire(): ?int {
if (empty($this->daysToExpire)) {
$this->daysToExpire = 1;
}
return $this->daysToExpire;
}
public function setDaysToExpire($expireDate): void {
$now = date_create();
$expireDate = date_create($expireDate);
$this->daysToExpire = $this->countWorkdaysBetweenDates($now, $expireDate);
}
public function countWorkdaysBetweenDates($startDate, $endDate): int {
// Ensure the end date is after the start date
if ($endDate < $startDate) {
throw new \InvalidArgumentException('End date must be greater than or equal to start date.');
}
// Create an interval of one day
$interval = new \DateInterval('P1D');
// Create a date period from start date to end date inclusive
$period = new \DatePeriod($startDate, $interval, $endDate->add($interval));
// Initialize weekday count
$weekdayCount = 0;
// Loop through each date in the period
foreach ($period as $date) {
// Get the day of the week as a number (1 for Monday, 7 for Sunday)
$dayOfWeek = $date->format('N');
// Check if the day is a weekday (1-5)
if ($dayOfWeek < 6) {
$weekdayCount++;
}
}
return $weekdayCount;
}
}