<?php
namespace App\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\RetirosRepository;
/**
* Retiros
*
* @ORM\Table(name="retiros")
* @ORM\Entity
*/
#[ORM\Entity(repositoryClass: RetirosRepository::class)]
class Retiros implements \Serializable
{
public const CREATED = 0;
public const VALIDATED = 1;
public const DENIED = 2;
public const TYPE_NORMAL = 1;
public const TYPE_ANTICPATED = 2;
const REQUEST_STATUS = [
'created' => self::CREATED,
'validated' => self::VALIDATED,
'denied' => self::DENIED
];
public const TRANSFERT_CRYPTO = 1;
public const TRANSFERT_BANK = 2;
/**
* @var int
*
* @ORM\Column(name="ID", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
/**
* @var int|null
*
* @ORM\Column(name="user_id", type="integer", nullable=true)
*/
#[ORM\Column(type: 'integer',nullable:true)]
private $userId;
/**
* @var string|null
*
* @ORM\Column(name="wallet", type="string", length=300, nullable=true)
*/
#[ORM\Column(type: 'string',length:300,nullable:true)]
private $wallet;
/**
* @var \DateTime|null
*
* @ORM\Column(name="fecha", type="datetime", nullable=true)
*/
#[ORM\Column(type: 'datetime',nullable:true)]
private $fecha;
/**
* @var float|null
*
* @ORM\Column(name="value", type="float", precision=10, scale=0, nullable=true)
*/
//montant du retrait réel
#[ORM\Column(type: 'float',precision:10,scale:0,nullable:true)]
private $value;
//montant du retrait demandé
#[ORM\Column(type: 'float',precision:10,scale:0,nullable:true)]
private $montantDemande;
/**
* @var string|null
*
* @ORM\Column(name="hash", type="string", length=300, nullable=true)
*/
#[ORM\Column(type: 'string',length:300,nullable:true)]
private $hash;
/**
* @var int|null
*
* @ORM\Column(name="state", type="integer", nullable=true)
*/
#[ORM\Column(type: 'integer',nullable:true)]
private $state = self::CREATED;
#[ORM\Column(type: 'string',length:300,nullable:true)]
private $note;
#[ORM\ManyToOne(targetEntity: Users::class)]
#[ORM\JoinColumn( nullable: false)]
private $user;
#[ORM\ManyToOne(targetEntity: LicenciasUser::class)]
#[ORM\JoinColumn( nullable: true)]
private $pack;
#[ORM\Column(type: 'datetime',nullable:true)]
private $validationDate;
#[ORM\Column(type: 'integer',nullable:true,options: ['default' => self::TYPE_NORMAL ])]
private $type = self::TYPE_NORMAL;
#[ORM\Column(type: 'float',precision:10,scale:0,nullable:true)]
private $fee;
#[ORM\Column(type: 'string',length:200,unique:false,nullable:true)]
private $document;
#[ORM\Column(type: 'float',precision:10,scale:0,nullable:true)]
private $amountWithCurrency;
#[ORM\Column(type: 'string',length:30,options: ['default' => "USDC"])]
private $currencyOfTransaction = "USDC";
#[ORM\Column(type: 'boolean',nullable:true, options: ['default' => true])]
private $wasNotificationSentByMail = true;
#[ORM\Column(type: 'integer',nullable:true,options: ['default' =>self::TRANSFERT_CRYPTO])]
private $transfertMode = self::TRANSFERT_CRYPTO;
#[ORM\Column(type: 'string', length: 255, nullable:true)]
private $iban;
#[ORM\Column(type: 'string', length: 255, nullable:true)]
private $swift;
#[ORM\Column(type: 'string', length: 255, nullable:true)]
private $banque;
#[ORM\Column(length: 255, nullable: true)]
private ?string $beneficiaire = null;
public function getId(): ?int
{
return $this->id;
}
public function getUserId(): ?int
{
return $this->userId;
}
public function setUserId(?int $userId): static
{
$this->userId = $userId;
return $this;
}
public function getWallet(): ?string
{
return $this->wallet;
}
public function setWallet(?string $wallet): static
{
$this->wallet = $wallet;
return $this;
}
public function getFecha(): ?\DateTimeInterface
{
return $this->fecha;
}
public function setFecha(?\DateTimeInterface $fecha): static
{
$this->fecha = $fecha;
return $this;
}
public function getValue(): ?float
{
return $this->value;
}
public function setValue($value): static
{
UsefulEntity::IsPositif($value,"valeur réel");
$montantDemande=$this->montantDemande!=null?$this->montantDemande:0;
$this->value = $value;
return $this;
}
public function getHash(): ?string
{
return $this->hash;
}
public function setHash(?string $hash): static
{
$this->hash = $hash;
return $this;
}
public function getState(): ?int
{
return $this->state;
}
public function setState(?int $state): static
{
$this->state = $state;
return $this;
}
/**
* Get the value of user
*/
public function getUser()
{
return $this->user;
}
/**
* Set the value of user
*
* @return self
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
public function getStringState(){
switch ($this->getState()) {
case self::DENIED:
return "Refusée";
case self::VALIDATED :
return "Validée";
default :
return "En cours";
}
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): static
{
$this->note = $note;
return $this;
}
public function getMontantDemande(): ?float
{
return $this->montantDemande;
}
public function setMontantDemande(?float $montantDemande): static
{
$this->montantDemande = $montantDemande;
return $this;
}
public function modifyValeurReelIntoValeurDemande(){
$this->setValue($this->getMontantDemande());
}
/**
* Get the value of pack
*/
public function getPack()
{
return $this->pack;
}
/**
* Set the value of pack
*
* @return self
*/
public function setPack($pack)
{
$this->pack = $pack;
return $this;
}
public function serialize()
{
return serialize([
'wallet' => $this->getWallet(),
'hash' => $this->getHash(),
'montantDemande' => $this->getMontantDemande(),
'type' => $this->getType(),
'fee' => $this->getFee(),
'transfertMode' => $this->getTransfertMode(),
'currencyOfTransaction' => $this->getCurrencyOfTransaction(),
'amountWithCurrency' => $this->getAmountWithCurrency(),
'beneficiaire' => $this->getBeneficiaire(),
'iban' => $this->getIban(),
'swift' => $this->getSwift(),
'banque' => $this->getBanque(),
]);
}
public function unserialize($serialized)
{
$data = unserialize($serialized);
$this->setWallet($data['wallet']);
$this->setHash($data['hash']);
$this->setMontantDemande($data['montantDemande']);
$this->setType($data['type']);
$this->setFee($data['fee']);
$this->setTransfertMode($data['transfertMode']);
$this->setCurrencyOfTransaction($data['currencyOfTransaction']);
$this->setAmountWithCurrency($data['amountWithCurrency']);
$this->setBeneficiaire($data['beneficiaire']);
$this->setIban($data['iban']);
$this->setSwift($data['swift']);
$this->setBanque($data['banque']);
}
public function getValidationDate(): ?\DateTimeInterface
{
return $this->validationDate;
}
public function setValidationDate(?\DateTimeInterface $validationDate): static
{
$this->validationDate = $validationDate;
return $this;
}
/**
* Get the value of type
*/
public function getType()
{
return $this->type;
}
/**
* Set the value of type
*
* @return self
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get the value of fee
*/
public function getFee()
{
return $this->fee;
}
/**
* Set the value of fee
*
* @return self
*/
public function setFee($fee)
{
$this->fee = $fee;
return $this;
}
public function getStringType(){
switch ($this->getType()) {
case self::TYPE_ANTICPATED:
return "Anticipé";
default :
return "Normal";
}
}
/**
* Get the value of document
*/
public function getDocument()
{
return $this->document;
}
/**
* Set the value of document
*
* @return self
*/
public function setDocument($document)
{
$this->document = $document;
return $this;
}
/**
* Get the value of currencyOfTransaction
*/
public function getCurrencyOfTransaction()
{
return $this->currencyOfTransaction;
}
/**
* Set the value of currencyOfTransaction
*
* @return self
*/
public function setCurrencyOfTransaction($currencyOfTransaction)
{
$this->currencyOfTransaction = $currencyOfTransaction;
return $this;
}
public function getArrayToExport(){
$ret = [];
$ret[] = $this->getFecha()->format('Y-m-d');
$ret[] = $this->getUser()->getName();
$ret[] = $this->getUser()->getSurname();
$ret[] = $this->getUser()->getUsername();
$ret[] = $this->getValue();
$ret[] = $this->getCurrencyOfTransaction();
$ret[] = $this->getHash();
$ret[] = $this->getStringState();
return $ret;
}
/**
* Get the value of wasNotificationSentByMail
*/
public function getWasNotificationSentByMail()
{
return $this->wasNotificationSentByMail;
}
/**
* Set the value of wasNotificationSentByMail
*
* @return self
*/
public function setWasNotificationSentByMail($wasNotificationSentByMail)
{
$this->wasNotificationSentByMail = $wasNotificationSentByMail;
return $this;
}
/**
* Get the value of transfertMode
*/
public function getTransfertMode()
{
return $this->transfertMode;
}
/**
* Set the value of transfertMode
*
* @return self
*/
public function setTransfertMode($transfertMode)
{
$this->transfertMode = $transfertMode;
return $this;
}
/**
* Get the value of iban
*/
public function getIban()
{
return $this->iban;
}
/**
* Set the value of iban
*
* @return self
*/
public function setIban($iban)
{
$this->iban = $iban;
return $this;
}
/**
* Get the value of swift
*/
public function getSwift()
{
return $this->swift;
}
/**
* Set the value of swift
*
* @return self
*/
public function setSwift($swift)
{
$this->swift = $swift;
return $this;
}
/**
* Get the value of banque
*/
public function getBanque()
{
return $this->banque;
}
/**
* Set the value of banque
*
* @return self
*/
public function setBanque($banque)
{
$this->banque = $banque;
return $this;
}
/**
* Get the value of beneficiaire
*/
public function getBeneficiaire()
{
return $this->beneficiaire;
}
/**
* Set the value of beneficiaire
*
* @return self
*/
public function setBeneficiaire($beneficiaire)
{
$this->beneficiaire = $beneficiaire;
return $this;
}
public function getTransfertLabel(){
switch($this->getTransfertMode()) {
case self::TRANSFERT_BANK:
return "Virement bancaire";
default:
return "Transaction crypto";
}
}
/**
* Get the value of amountWithCurrency
*/
public function getAmountWithCurrency()
{
return $this->amountWithCurrency;
}
/**
* Set the value of amountWithCurrency
*
* @return self
*/
public function setAmountWithCurrency($amountWithCurrency)
{
$this->amountWithCurrency = $amountWithCurrency;
return $this;
}
public function getPaymentLabel(){
switch($this->getTransfertMode()) {
case self::TRANSFERT_BANK:
return "Virement bancaire - ".$this->getCurrencyOfTransaction();
default:
return "Transfert ".$this->getCurrencyOfTransaction();
}
}
}