src/Entity/Feed/FeedTransaction.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Feed;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. /**
  7.  * FeedTransaction
  8.  *
  9.  * @ORM\Table(name="tam_feed_transactions")
  10.  * @ORM\Entity(repositoryClass="App\Repository\Feed\FeedTransactionRepository")
  11.  * @ORM\HasLifecycleCallbacks
  12.  */
  13. class FeedTransaction
  14. {
  15.     /**
  16.      * @var int
  17.      *
  18.      * @ORM\Column(name="id", type="integer")
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue(strategy="IDENTITY")
  21.      */
  22.     private $id;
  23.     
  24.     /**
  25.      * @ORM\OneToOne(targetEntity="App\Entity\Feed\FeedElement", inversedBy="transaction", cascade={"persist", "remove"})
  26.      * @ORM\JoinColumn(name="feed_element", referencedColumnName="id",  onDelete="CASCADE", nullable=false)
  27.      */
  28.     private $feedElement;
  29.     
  30.     /**
  31.      * @var \DateTime
  32.      *
  33.      * @ORM\Column(name="date_created", type="datetime", nullable=false)
  34.      */
  35.     private $dateCreated;
  36.     
  37.     /**
  38.      * @var \DateTime
  39.      *
  40.      * @ORM\Column(name="date_transaction", type="datetime", nullable=true)
  41.      */
  42.     private $dateTransaction;
  43.     
  44.     /**
  45.      * @var float
  46.      *
  47.      * @ORM\Column(name="amount", type="float", precision=5, scale=2, nullable=true)
  48.      */
  49.     private $amount;
  50.     
  51.     /**
  52.      * @var float
  53.      *
  54.      * @ORM\Column(name="rate_currency", type="float", precision=5, scale=2, nullable=true)
  55.      */
  56.     private $rateCurrency;
  57.     
  58.     /**
  59.      * @var string
  60.      *
  61.      * @ORM\Column(name="order_id", type="text", nullable=true)
  62.      */
  63.     private $orderId;
  64.     
  65.     /**
  66.      * @var string
  67.      *
  68.      * @ORM\Column(name="order_status", type="text", nullable=true)
  69.      */
  70.     private $orderStatus;
  71.     
  72.     /**
  73.      * @var string
  74.      *
  75.      * @ORM\Column(name="result", type="text", nullable=true)
  76.      */
  77.     private $result;
  78.     
  79.     
  80.     public function __construct()
  81.     {
  82.        
  83.         $this->dateCreated = new \DateTime();
  84.         //$this->orderId = sha1(uniqid("TAMFeed_".$this->getDateCreated()->format('U'), true));
  85.         //$this->orderId = uniqid("TAMFeed_".$this->getDateCreated()->format('U'), true);
  86.         $hash substr(bin2hex(random_bytes(ceil(2))), 05);
  87.         $this->orderId $this->getDateCreated()->format('Ymd').$hash;
  88.         
  89.     }
  90.     /**
  91.      * Get id
  92.      *
  93.      * @return int
  94.      */
  95.     public function getId()
  96.     {
  97.         return $this->id;
  98.     }
  99.     
  100.     /**
  101.      * Set feedElement
  102.      *
  103.      * @param FeedElement $feedElement
  104.      *
  105.      * @return FeedTransaction
  106.      */
  107.     public function setFeedElement($feedElement)
  108.     {
  109.         $this->feedElement $feedElement;
  110.         $feedElement->setTransaction($this);
  111.         return $this;
  112.     }
  113.     /**
  114.      * Get feedElement
  115.      *
  116.      * @return FeedElement
  117.      */
  118.     public function getFeedElement()
  119.     {
  120.         return $this->feedElement;
  121.     }
  122.     
  123.     /**
  124.      * Set dateCreated
  125.      *
  126.      * @param \DateTime $dateCreated
  127.      *
  128.      * @return FeedTransaction
  129.      */
  130.     public function setDateCreated($dateCreated)
  131.     {
  132.         $this->dateCreated $dateCreated;
  133.         return $this;
  134.     }
  135.     /**
  136.      * Get dateCreated
  137.      *
  138.      * @return \DateTime
  139.      */
  140.     public function getDateCreated()
  141.     {
  142.         return $this->dateCreated;
  143.     }
  144.     
  145.     /**
  146.      * Set dateTransaction
  147.      *
  148.      * @param \DateTime $dateTransaction
  149.      *
  150.      * @return FeedTransaction
  151.      */
  152.     public function setDateTransaction($dateTransaction)
  153.     {
  154.         $this->dateTransaction $dateTransaction;
  155.         return $this;
  156.     }
  157.     /**
  158.      * Get dateTransaction
  159.      *
  160.      * @return \DateTime
  161.      */
  162.     public function getDateTransaction()
  163.     {
  164.         return $this->dateTransaction;
  165.     }
  166.     
  167.     /**
  168.      * Set amount
  169.      *
  170.      * @param float $amount
  171.      *
  172.      * @return FeedTransaction
  173.      */
  174.     public function setAmount($amount)
  175.     {
  176.         if($amount == "")
  177.             $this->amount null;
  178.         else
  179.             $this->amount str_replace(",""."$amount);
  180.         return $this;
  181.     }
  182.     /**
  183.      * Get amount
  184.      *
  185.      * @return float
  186.      */
  187.     public function getAmount()
  188.     {
  189.         return $this->amount;
  190.     }
  191.     
  192.     /**
  193.      * Set rateCurrency
  194.      *
  195.      * @param float $rateCurrency
  196.      *
  197.      * @return FeedTransaction
  198.      */
  199.     public function setRateCurrency($rateCurrency)
  200.     {
  201.         if($rateCurrency == "")
  202.             $this->rateCurrency null;
  203.         else
  204.             $this->rateCurrency str_replace(",""."$rateCurrency);
  205.         return $this;
  206.     }
  207.     /**
  208.      * Get rateCurrency
  209.      *
  210.      * @return float
  211.      */
  212.     public function getRateCurrency()
  213.     {
  214.         return $this->rateCurrency;
  215.     }
  216.     
  217.     /**
  218.      * Set orderId
  219.      *
  220.      * @param string $orderId
  221.      *
  222.      * @return FeedTransaction
  223.      */
  224.     public function setOrderId($orderId)
  225.     {
  226.         $this->orderId $orderId;
  227.         return $this;
  228.     }
  229.     /**
  230.      * Get orderId
  231.      *
  232.      * @return string
  233.      */
  234.     public function getOrderId()
  235.     {
  236.         return $this->orderId;
  237.     }
  238.     
  239.     /**
  240.      * Set orderStatus
  241.      *
  242.      * @param string $orderStatus
  243.      *
  244.      * @return FeedTransaction
  245.      */
  246.     public function setOrderStatus($orderStatus)
  247.     {
  248.         $this->orderStatus $orderStatus;
  249.         return $this;
  250.     }
  251.     /**
  252.      * Get orderStatus
  253.      *
  254.      * @return string
  255.      */
  256.     public function getOrderStatus()
  257.     {
  258.         return $this->orderStatus;
  259.     }
  260.     
  261.     /**
  262.      * Set result
  263.      *
  264.      * @param string $result
  265.      *
  266.      * @return FeedTransaction
  267.      */
  268.     public function setResult($result)
  269.     {
  270.         $this->result $result;
  271.         return $this;
  272.     }
  273.     /**
  274.      * Get result
  275.      *
  276.      * @return string
  277.      */
  278.     public function getResult()
  279.     {
  280.         return $this->result;
  281.     }
  282.         
  283.     
  284.     /***********************
  285.      * Lifecycle Callbacks
  286.      ***********************/
  287.      
  288.     /**
  289.      *
  290.      * @ORM\PrePersist()
  291.      * @ORM\PreUpdate()
  292.      */
  293.     public function preUpdate()
  294.     {
  295.         //$this->setDateUpdated(new \DateTime());
  296.     }
  297.     
  298.     
  299.     /***********************
  300.      * OTHER FUNCTION
  301.      ***********************/
  302.      
  303.      
  304.      
  305.      public function getArrayForJson($schemeAndBaseURL$friend false){
  306.         $array = array();
  307.         $array['id'] = $this->getId();
  308.         if($this->getDateTransaction()){
  309.             $array['dateTransaction'] = $this->getDateTransaction()->format("Y-m-d\TH:i:sP");
  310.         }
  311.         $array['result'] = $this->getResult();
  312.         
  313.         return $array;
  314.         
  315.     }
  316.     
  317.     
  318.     public function getInvoiceId(){
  319.         return "TAM".$this->getDateCreated()->format('Ym').sprintf("%06d"$this->getId());
  320.     }
  321.     
  322.     
  323. }