<?php
namespace App\Entity\Feed;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
/**
* FeedTransaction
*
* @ORM\Table(name="tam_feed_transactions")
* @ORM\Entity(repositoryClass="App\Repository\Feed\FeedTransactionRepository")
* @ORM\HasLifecycleCallbacks
*/
class FeedTransaction
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Feed\FeedElement", inversedBy="transaction", cascade={"persist", "remove"})
* @ORM\JoinColumn(name="feed_element", referencedColumnName="id", onDelete="CASCADE", nullable=false)
*/
private $feedElement;
/**
* @var \DateTime
*
* @ORM\Column(name="date_created", type="datetime", nullable=false)
*/
private $dateCreated;
/**
* @var \DateTime
*
* @ORM\Column(name="date_transaction", type="datetime", nullable=true)
*/
private $dateTransaction;
/**
* @var float
*
* @ORM\Column(name="amount", type="float", precision=5, scale=2, nullable=true)
*/
private $amount;
/**
* @var float
*
* @ORM\Column(name="rate_currency", type="float", precision=5, scale=2, nullable=true)
*/
private $rateCurrency;
/**
* @var string
*
* @ORM\Column(name="order_id", type="text", nullable=true)
*/
private $orderId;
/**
* @var string
*
* @ORM\Column(name="order_status", type="text", nullable=true)
*/
private $orderStatus;
/**
* @var string
*
* @ORM\Column(name="result", type="text", nullable=true)
*/
private $result;
public function __construct()
{
$this->dateCreated = new \DateTime();
//$this->orderId = sha1(uniqid("TAMFeed_".$this->getDateCreated()->format('U'), true));
//$this->orderId = uniqid("TAMFeed_".$this->getDateCreated()->format('U'), true);
$hash = substr(bin2hex(random_bytes(ceil(5 / 2))), 0, 5);
$this->orderId = $this->getDateCreated()->format('Ymd').$hash;
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set feedElement
*
* @param FeedElement $feedElement
*
* @return FeedTransaction
*/
public function setFeedElement($feedElement)
{
$this->feedElement = $feedElement;
$feedElement->setTransaction($this);
return $this;
}
/**
* Get feedElement
*
* @return FeedElement
*/
public function getFeedElement()
{
return $this->feedElement;
}
/**
* Set dateCreated
*
* @param \DateTime $dateCreated
*
* @return FeedTransaction
*/
public function setDateCreated($dateCreated)
{
$this->dateCreated = $dateCreated;
return $this;
}
/**
* Get dateCreated
*
* @return \DateTime
*/
public function getDateCreated()
{
return $this->dateCreated;
}
/**
* Set dateTransaction
*
* @param \DateTime $dateTransaction
*
* @return FeedTransaction
*/
public function setDateTransaction($dateTransaction)
{
$this->dateTransaction = $dateTransaction;
return $this;
}
/**
* Get dateTransaction
*
* @return \DateTime
*/
public function getDateTransaction()
{
return $this->dateTransaction;
}
/**
* Set amount
*
* @param float $amount
*
* @return FeedTransaction
*/
public function setAmount($amount)
{
if($amount == "")
$this->amount = null;
else
$this->amount = str_replace(",", ".", $amount);
return $this;
}
/**
* Get amount
*
* @return float
*/
public function getAmount()
{
return $this->amount;
}
/**
* Set rateCurrency
*
* @param float $rateCurrency
*
* @return FeedTransaction
*/
public function setRateCurrency($rateCurrency)
{
if($rateCurrency == "")
$this->rateCurrency = null;
else
$this->rateCurrency = str_replace(",", ".", $rateCurrency);
return $this;
}
/**
* Get rateCurrency
*
* @return float
*/
public function getRateCurrency()
{
return $this->rateCurrency;
}
/**
* Set orderId
*
* @param string $orderId
*
* @return FeedTransaction
*/
public function setOrderId($orderId)
{
$this->orderId = $orderId;
return $this;
}
/**
* Get orderId
*
* @return string
*/
public function getOrderId()
{
return $this->orderId;
}
/**
* Set orderStatus
*
* @param string $orderStatus
*
* @return FeedTransaction
*/
public function setOrderStatus($orderStatus)
{
$this->orderStatus = $orderStatus;
return $this;
}
/**
* Get orderStatus
*
* @return string
*/
public function getOrderStatus()
{
return $this->orderStatus;
}
/**
* Set result
*
* @param string $result
*
* @return FeedTransaction
*/
public function setResult($result)
{
$this->result = $result;
return $this;
}
/**
* Get result
*
* @return string
*/
public function getResult()
{
return $this->result;
}
/***********************
* Lifecycle Callbacks
***********************/
/**
*
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpdate()
{
//$this->setDateUpdated(new \DateTime());
}
/***********************
* OTHER FUNCTION
***********************/
public function getArrayForJson($schemeAndBaseURL, $friend = false){
$array = array();
$array['id'] = $this->getId();
if($this->getDateTransaction()){
$array['dateTransaction'] = $this->getDateTransaction()->format("Y-m-d\TH:i:sP");
}
$array['result'] = $this->getResult();
return $array;
}
public function getInvoiceId(){
return "TAM".$this->getDateCreated()->format('Ym').sprintf("%06d", $this->getId());
}
}