<?php
namespace App\Entity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* Transaction
*
* @ORM\Table(name="Transaction")
* @ORM\Entity(repositoryClass="App\Entity\TransactionRepository")
* @UniqueEntity(fields={"invoiceNumber"})
*/
class Transaction
{
public static function createWithId($id)
{
$instance = new self();
$instance->id = $id;
return $instance;
}
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var DateTime
*
* @ORM\Column(name="transaction_date", type="datetime", nullable=true)
*/
private $date;
/**
* If price is not null, the transaction is considered an invoice
*
* @var integer
*
* @ORM\Column(name="prix", type="integer", nullable=true)
*/
private $prix;
/**
* @var integer
*
* @ORM\Column(name="credits", type="integer", nullable=true)
*/
private $credits;
/**
* @var boolean
*
* @ORM\Column(name="is_cart", type="boolean")
*/
private $cart;
/**
* @var boolean
*
* @ORM\Column(name="is_confirmed", type="boolean")
*/
private $confirmed;
/**
* @var string
*
* @ORM\Column(name="invoice_number", type="string", length=255, nullable=true, unique=true)
*/
private $invoiceNumber;
/**
* @var array
*
* @ORM\Column(name="demande_ids", type="simple_array", nullable=true)
*/
private $demandeIds;
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="Demande", inversedBy="transactions")
* @ORM\JoinTable(name="TransactionDemande")
*/
private $demandes;
/**
* @var ?Prestataire
*
* @ORM\ManyToOne(targetEntity="Prestataire", inversedBy="transactions")
* @ORM\JoinColumn(name="prestataire_id", referencedColumnName="id", nullable=true)
*/
private ?Prestataire $prestataire;
/**
* @var Payment
*/
private $payment;
/**
* Constructor
*/
public function __construct()
{
$this->demandes = new ArrayCollection();
$this->demandeIds = array();
$this->cart = 0;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set date
*
* @param DateTime $date
*
* @return Transaction
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set prix
*
* @param integer $prix
*
* @return Transaction
*/
public function setPrix($prix)
{
$this->prix = $prix;
return $this;
}
/**
* Get prix
*
* @return integer
*/
public function getPrix()
{
return $this->prix;
}
/**
* Set credits
*
* @param integer $credits
*
* @return Transaction
*/
public function setCredits($credits)
{
$this->credits = $credits;
return $this;
}
/**
* Get credits
*
* @return integer
*/
public function getCredits()
{
return $this->credits;
}
/**
* @param boolean $cart
*
* @return Transaction
*/
public function setCart($cart)
{
$this->cart = $cart;
return $this;
}
/**
* @return boolean
*/
public function isCart()
{
return $this->cart;
}
/**
* @param boolean $confirmed
*
* @return Transaction
*/
public function setConfirmed($confirmed)
{
$this->confirmed = $confirmed;
return $this;
}
/**
* @return boolean
*/
public function isConfirmed()
{
return $this->confirmed;
}
/**
* @param Demande $demande
*
* @return Transaction
*/
public function addDemande(Demande $demande)
{
$this->demandes[] = $demande;
$this->addDemandeId($demande->getId());
return $this;
}
/**
* @param Demande $demande
*/
public function removeDemande(Demande $demande)
{
$this->demandes->removeElement($demande);
$this->removeDemandeId($demande->getId());
}
/**
* @return Collection
*/
public function getDemandes()
{
return $this->demandes;
}
/**
* @param ?Prestataire $prestataire
*
* @return Transaction
*/
public function setPrestataire(?Prestataire $prestataire = null)
{
$this->prestataire = $prestataire;
return $this;
}
/**
* @return ?Prestataire
*/
public function getPrestataire()
{
return $this->prestataire;
}
/**
* @return mixed
*/
public function getPayment()
{
return $this->payment;
}
/**
* @param mixed $payment
*/
public function setPayment($payment)
{
$this->payment = $payment;
}
/**
* @param array $demandeIds
* @return Transaction
*/
public function setDemandeIds($demandeIds)
{
$this->demandeIds = $demandeIds;
return $this;
}
/**
* @return array
*/
public function getDemandeIds()
{
return $this->demandeIds;
}
public function addDemandeId($demandeId)
{
$demandeIds = $this->getDemandeIds();
$demandeIds[] = $demandeId;
$this->setDemandeIds(array_unique($demandeIds));
}
public function removeDemandeId($demandeId)
{
$demandeIds = $this->getDemandeIds();
$offset = array_search($demandeId, $demandeIds);
if ($offset !== false) {
unset($demandeIds[$offset]);
$this->setDemandeIds($demandeIds);
}
}
public function getDemandesForDisplay()
{
$demandes = array();
foreach ($this->getDemandeIds() as $demandeId) {
$demandes[$demandeId] = $demandeId;
}
foreach ($this->getDemandes() as $demande) {
$demandes[$demande->getId()] = $demande;
}
return $demandes;
}
/**
* Get cart
*
* @return boolean
*/
public function getCart()
{
return $this->cart;
}
/**
* Get confirmed
*
* @return boolean
*/
public function getConfirmed()
{
return $this->confirmed;
}
/**
* @return string
*/
public function getInvoiceNumber()
{
return $this->invoiceNumber;
}
public function getInvoiceFilename()
{
return sprintf('exacompare-facture-%s.pdf', $this->getInvoiceNumber());
}
/**
* @param string $invoiceNumber
*/
public function setInvoiceNumber($invoiceNumber)
{
$this->invoiceNumber = $invoiceNumber;
}
}