src/Admin/Modules/Voucher/Entity/VoucherPackageVoucher.php line 23

  1. <?php
  2. namespace App\Admin\Modules\Voucher\Entity;
  3. use App\Modules\VoucherCart\Entity\VoucherOrderVoucher;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use App\Modules\User\Entity\User;
  10. use App\Admin\Modules\Store\Entity\StoreOrder;
  11. use App\Modules\TicketCart\Entity\TicketOrderTicket;
  12. use App\Admin\Modules\Contract\Entity\Contract;
  13. use App\Admin\Modules\Contract\Entity\ContractLead;
  14. use App\Admin\Modules\MeetingScheduler\Entity\Meeting;
  15. use App\Modules\RecommendationVoucherForm\Entity\RecommendationVoucherForm;
  16. /**
  17.  * @ORM\Table(name="voucher_package_voucher", uniqueConstraints={@ORM\UniqueConstraint(columns={"id_voucher_package", "number"})}, indexes={@ORM\Index(columns={"kind"}), @ORM\Index(columns={"type"}), @ORM\Index(columns={"email"}), @ORM\Index(columns={"sent_to_email"}), @ORM\Index(columns={"physically_handed_over_to"}), @ORM\Index(columns={"status"}), @ORM\Index(columns={"used_at"}), @ORM\Index(columns={"registered_at"}), @ORM\Index(columns={"added_at"})})
  18.  * @ORM\Entity(repositoryClass="App\Admin\Modules\Voucher\Repository\VoucherPackageVoucherRepository")
  19.  */
  20. class VoucherPackageVoucher
  21. {
  22.     const KIND_VOUCHER 1;
  23.     const KIND_TICKET 2;
  24.     
  25.     const TYPE_PACKAGE_VOUCHER 1;
  26.     const TYPE_INDIVIDUAL 2;
  27.     
  28.     const STATUS_UNREGISTERED 1;
  29.     const STATUS_REGISTERED 2;
  30.     const STATUS_USED 3;
  31.     
  32.     /**
  33.      * @var int
  34.      *
  35.      * @ORM\Id
  36.      * @ORM\Column(type="bigint", options={"unsigned"=true}))
  37.      * @ORM\GeneratedValue(strategy="AUTO")
  38.      */
  39.     protected $id;
  40.     
  41.     /**
  42.      * @var \App\Admin\Modules\Voucher\Entity\VoucherPackage
  43.      *
  44.      * @ORM\ManyToOne(targetEntity="App\Admin\Modules\Voucher\Entity\VoucherPackage", inversedBy="vouchers")
  45.      * @ORM\JoinColumns({
  46.      *   @ORM\JoinColumn(name="id_voucher_package", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  47.      * })
  48.      */
  49.     private $package;
  50.     /**
  51.      * @var string
  52.      *
  53.      * @ORM\Column(name="number", type="string", length=255, nullable=false)
  54.      */
  55.     protected $number;
  56.     /**
  57.      * @var int
  58.      *
  59.      * @ORM\Column(name="am_value", type="integer", nullable=true)
  60.      */
  61.     private $amValue;
  62.     /**
  63.      * @var int
  64.      *
  65.      * @ORM\Column(name="kind", type="smallint", nullable=false)
  66.      */
  67.     private $kind;
  68.     
  69.     /**
  70.      * @var int
  71.      *
  72.      * @ORM\Column(name="type", type="smallint", nullable=false)
  73.      */
  74.     private $type;
  75.     
  76.     /**
  77.      * @var string
  78.      *
  79.      * @ORM\Column(name="event_name", type="string", length=255, nullable=true)
  80.      */
  81.     protected $eventName;
  82.     /**
  83.      * @var string
  84.      *
  85.      * @ORM\Column(name="email", type="string", length=255, nullable=true)
  86.      */
  87.     protected $email;
  88.     /**
  89.      * @var string
  90.      *
  91.      * @ORM\Column(name="first_name", type="string", length=255, nullable=true)
  92.      */
  93.     protected $firstName;
  94.     /**
  95.      * @var string
  96.      *
  97.      * @ORM\Column(name="last_name", type="string", length=255, nullable=true)
  98.      */
  99.     protected $lastName;
  100.     /**
  101.      * @var string
  102.      *
  103.      * @ORM\Column(name="sent_to_email", type="string", length=255, nullable=true)
  104.      */
  105.     protected $sentToEmail;
  106.     /**
  107.      * @var string
  108.      *
  109.      * @ORM\Column(name="physically_handed_over_to", type="string", length=255, nullable=true)
  110.      */
  111.     protected $physicallyHandedOverTo;
  112.     /**
  113.      * @var int
  114.      *
  115.      * @ORM\Column(name="usage_count", type="integer", nullable=true)
  116.      */
  117.     private $usageCount;
  118.     /**
  119.      * @var int
  120.      *
  121.      * @ORM\Column(name="reusable_voucher_redeem_admin_notify_date", type="datetime", nullable=true)
  122.      */
  123.     private $reusableVoucherRedeemAdminNotifyDate;
  124.     /**
  125.      * @var int
  126.      *
  127.      * @ORM\Column(name="status", type="smallint", nullable=false)
  128.      */
  129.     private $status;
  130.     
  131.     /**
  132.      * @var \App\Modules\User\Entity\User
  133.      *
  134.      * @ORM\OneToOne(targetEntity="App\Modules\User\Entity\User", inversedBy="voucher")
  135.      * @ORM\JoinColumns({
  136.      *   @ORM\JoinColumn(name="id_user", referencedColumnName="id", nullable=true, onDelete="CASCADE")
  137.      * })
  138.      */
  139.     private $user;
  140.     /**
  141.      * @var \DateTime
  142.      *
  143.      * @ORM\Column(name="used_at", type="datetime", nullable=true)
  144.      */
  145.     private $usedAt;
  146.     
  147.     /**
  148.      * @var \DateTime
  149.      *
  150.      * @ORM\Column(name="registered_at", type="datetime", nullable=true)
  151.      */
  152.     private $registeredAt;
  153.     
  154.     /**
  155.      * @var \DateTime
  156.      *
  157.      * @ORM\Column(name="added_at", type="datetime", nullable=false)
  158.      * @Gedmo\Timestampable(on="create")
  159.      */
  160.     private $addedAt;
  161.     
  162.     /**
  163.      * @var \App\Admin\Modules\Voucher\Entity\VoucherPackageVoucherNote
  164.      *
  165.      * @ORM\OneToMany(targetEntity="App\Admin\Modules\Voucher\Entity\VoucherPackageVoucherNote", mappedBy="voucher", cascade={"persist"}, orphanRemoval=true)
  166.      * @ORM\OrderBy({"addedAt"="DESC"})
  167.      */
  168.     private $notes
  169.     
  170.     /**
  171.      * @var \App\Modules\VoucherCart\Entity\VoucherOrderVoucher
  172.      *
  173.      * @ORM\ManyToMany(targetEntity="App\Modules\VoucherCart\Entity\VoucherOrderVoucher", mappedBy="packageVouchers")
  174.      */
  175.     private $orderVoucher;    
  176.     
  177.     /**
  178.      * @var \App\Admin\Modules\Store\Entity\StoreOrder
  179.      *    
  180.      * @ORM\OneToMany(targetEntity="App\Admin\Modules\Store\Entity\StoreOrder", mappedBy="voucher")
  181.      **/
  182.     private $storeOrder;
  183.     /**
  184.      * @var \App\Modules\TicketCart\Entity\TicketOrderTicket
  185.      *    
  186.      * @ORM\ManyToMany(targetEntity="App\Modules\TicketCart\Entity\TicketOrderTicket", mappedBy="vouchers")
  187.      **/
  188.     private $ticket;
  189.      
  190.      /**
  191.      * @var \App\Admin\Modules\Contract\Entity\Contract
  192.      *
  193.      * @ORM\OneToMany(targetEntity="App\Admin\Modules\Contract\Entity\Contract", mappedBy="voucher")
  194.      */
  195.     private $contract
  196.     /**
  197.      * @var \App\Admin\Modules\Contract\Entity\ContractLead
  198.      *
  199.      * @ORM\OneToMany(targetEntity="App\Admin\Modules\Contract\Entity\ContractLead", mappedBy="voucher")
  200.      */
  201.     private $contractLead
  202.     /**
  203.      * @var \App\Admin\Modules\MeetingScheduler\Entity\Meeting
  204.      *
  205.      * @ORM\OneToMany(targetEntity="App\Admin\Modules\MeetingScheduler\Entity\Meeting", mappedBy="voucher")
  206.      */
  207.     private $meeting
  208.     /**
  209.      * @var \App\Modules\RecommendationVoucherForm\Entity\RecommendationVoucherForm
  210.      *
  211.      * @ORM\OneToMany(targetEntity="App\Modules\RecommendationVoucherForm\Entity\RecommendationVoucherForm", mappedBy="voucher")
  212.      */
  213.     private $recommendationVoucherForm
  214.     public function __construct()
  215.     {
  216.         $this->kind self::KIND_VOUCHER;
  217.         $this->type self::TYPE_PACKAGE_VOUCHER;
  218.         $this->status self::STATUS_UNREGISTERED;
  219.         $this->notes = new ArrayCollection();
  220.         $this->orderVoucher = new ArrayCollection();
  221.         $this->storeOrder = new ArrayCollection();
  222.         $this->ticket = new ArrayCollection();
  223.         $this->contract = new ArrayCollection();
  224.         $this->contractLead = new ArrayCollection();
  225.         $this->meeting = new ArrayCollection();
  226.         $this->recommendationVoucherForm = new ArrayCollection();
  227.     }
  228.     
  229.     private function _oneToOneGetFromCollection($propertyName)
  230.     {
  231.         if ($this->$propertyName && count($this->$propertyName))
  232.             return $this->$propertyName->first();
  233.         else
  234.             return null;        
  235.     }
  236.     
  237.     private function _oneToOneAddToCollection($propertyName$value)
  238.     {
  239.         if (!$this->$propertyName)
  240.             $this->$propertyName = new ArrayCollection();
  241.         elseif (count($this->$propertyName))
  242.             $this->$propertyName->removeElement($this->$propertyName->first());
  243.         
  244.         $value->setVoucher($this);
  245.         
  246.         $this->$propertyName[] = $value;
  247.         return $this;
  248.     }
  249.     
  250.     public function getId(): ?string
  251.     {
  252.         return $this->id;
  253.     }
  254.     
  255.     public function setStoreOrder(?StoreOrder $storeOrder): self
  256.     {
  257.         return $this->_oneToOneAddToCollection('storeOrder'$storeOrder);
  258.     }
  259.     public function getStoreOrder(): ?StoreOrder
  260.     {
  261.         return $this->_oneToOneGetFromCollection('storeOrder');
  262.     }    
  263.     
  264.     public function setTicket(?TicketOrderTicket $ticket): self
  265.     {
  266.         return $this->_oneToOneAddToCollection('ticket'$ticket);
  267.     }
  268.     public function getTicket(): ?TicketOrderTicket
  269.     {
  270.         return $this->_oneToOneGetFromCollection('ticket');
  271.     }    
  272.     public function setContract(?Contract $contract): self
  273.     {
  274.         return $this->_oneToOneAddToCollection('contract'$contract);
  275.     }
  276.     public function getContract(): ?Contract
  277.     {
  278.         return $this->_oneToOneGetFromCollection('contract');
  279.     }    
  280.     public function setContractLead(?ContractLead $contractLead): self
  281.     {
  282.         return $this->_oneToOneAddToCollection('contractLead'$contractLead);
  283.     }
  284.     public function getContractLead(): ?ContractLead
  285.     {
  286.         return $this->_oneToOneGetFromCollection('contractLead');
  287.     }    
  288.     public function setMeeting(?Meeting $meeting): self
  289.     {
  290.         return $this->_oneToOneAddToCollection('meeting'$meeting);
  291.     }
  292.     public function getMeeting(): ?Meeting
  293.     {
  294.         return $this->_oneToOneGetFromCollection('meeting');
  295.     }    
  296.     public function setRecommendationVoucherForm(?RecommendationVoucherForm $recommendationVoucherForm): self
  297.     {
  298.         return $this->_oneToOneAddToCollection('recommendationVoucherForm'$recommendationVoucherForm);
  299.     }
  300.     public function getRecommendationVoucherForm(): ?RecommendationVoucherForm
  301.     {
  302.         return $this->_oneToOneGetFromCollection('recommendationVoucherForm');
  303.     }    
  304.     public function getFullNumber()
  305.     {
  306.         return mb_strtoupper($this->package->getPrefixCode() . '-' $this->number'UTF-8');
  307.     }
  308.     
  309.     public function getVoucherValue()
  310.     {
  311.         return $this->amValue;
  312.     }
  313.     public function getNumber(): ?string
  314.     {
  315.         return $this->number;
  316.     }
  317.     public function setNumber(string $number): self
  318.     {
  319.         $this->number $number;
  320.         return $this;
  321.     }
  322.     public function getStatus(): ?int
  323.     {
  324.         return $this->status;
  325.     }
  326.     public function setStatus(int $status): self
  327.     {
  328.         $this->status $status;
  329.         return $this;
  330.     }
  331.     public function getPackage(): ?VoucherPackage
  332.     {
  333.         return $this->package;
  334.     }
  335.     public function setPackage(?VoucherPackage $package): self
  336.     {
  337.         $this->package $package;
  338.         return $this;
  339.     }
  340.     public function getUser(): ?User
  341.     {
  342.         return $this->user;
  343.     }
  344.     public function setUser(?User $userbool $setUserVoucher true): self
  345.     {
  346.         if ($user && $setUserVoucher)
  347.             $user->setVoucher($thisfalse);
  348.         $this->user $user;
  349.         return $this;
  350.     }
  351.     public function getRegisteredAt(): ?\DateTimeInterface
  352.     {
  353.         return $this->registeredAt;
  354.     }
  355.     public function setRegisteredAt(?\DateTimeInterface $registeredAt): self
  356.     {
  357.         $this->registeredAt $registeredAt;
  358.         return $this;
  359.     }
  360.     public function getAddedAt(): ?\DateTimeInterface
  361.     {
  362.         return $this->addedAt;
  363.     }
  364.     public function setAddedAt(\DateTimeInterface $addedAt): self
  365.     {
  366.         $this->addedAt $addedAt;
  367.         return $this;
  368.     }
  369.     public function getAmValue(): ?int
  370.     {
  371.         if ($this->amValue !== null)
  372.             return $this->amValue;
  373.         else
  374.             return $this->package $this->package->getAmValue() : null;
  375.     }
  376.     public function setAmValue(?int $amValue): self
  377.     {
  378.         $this->amValue $amValue;
  379.         return $this;
  380.     }
  381.     public function getType(): ?int
  382.     {
  383.         return $this->type;
  384.     }
  385.     public function setType(int $type): self
  386.     {
  387.         $this->type $type;
  388.         return $this;
  389.     }
  390.     public function getUsedAt(): ?\DateTimeInterface
  391.     {
  392.         return $this->usedAt;
  393.     }
  394.     public function setUsedAt(?\DateTimeInterface $usedAt): self
  395.     {
  396.         $this->usedAt $usedAt;
  397.         return $this;
  398.     }
  399.     /**
  400.      * @return Collection<int, VoucherPackageVoucherNote>
  401.      */
  402.     public function getNotes(): Collection
  403.     {
  404.         return $this->notes;
  405.     }
  406.     public function addNote(VoucherPackageVoucherNote $note): self
  407.     {
  408.         if (!$this->notes->contains($note)) {
  409.             $this->notes->add($note);
  410.             $note->setVoucher($this);
  411.         }
  412.         return $this;
  413.     }
  414.     public function removeNote(VoucherPackageVoucherNote $note): self
  415.     {
  416.         if ($this->notes->removeElement($note)) {
  417.             // set the owning side to null (unless already changed)
  418.             if ($note->getVoucher() === $this) {
  419.                 $note->setVoucher(null);
  420.             }
  421.         }
  422.         return $this;
  423.     }
  424.     /**
  425.      * @return Collection<int, VoucherOrderVoucher>
  426.      */
  427.     public function getOrderVoucher(): Collection
  428.     {
  429.         return $this->orderVoucher;
  430.     }
  431.     public function addOrderVoucher(VoucherOrderVoucher $orderVoucher): self
  432.     {
  433.         if (!$this->orderVoucher->contains($orderVoucher)) {
  434.             $this->orderVoucher->add($orderVoucher);
  435.             $orderVoucher->addPackageVoucher($this);
  436.         }
  437.         return $this;
  438.     }
  439.     public function removeOrderVoucher(VoucherOrderVoucher $orderVoucher): self
  440.     {
  441.         if ($this->orderVoucher->removeElement($orderVoucher)) {
  442.             $orderVoucher->removePackageVoucher($this);
  443.         }
  444.         return $this;
  445.     }
  446.     public function getKind(): ?int
  447.     {
  448.         return $this->kind;
  449.     }
  450.     public function setKind(int $kind): self
  451.     {
  452.         $this->kind $kind;
  453.         return $this;
  454.     }
  455.     public function getFirstName(): ?string
  456.     {
  457.         return $this->firstName;
  458.     }
  459.     public function setFirstName(?string $firstName): self
  460.     {
  461.         $this->firstName $firstName;
  462.         return $this;
  463.     }
  464.     public function getLastName(): ?string
  465.     {
  466.         return $this->lastName;
  467.     }
  468.     public function setLastName(?string $lastName): self
  469.     {
  470.         $this->lastName $lastName;
  471.         return $this;
  472.     }
  473.     public function getEventName(): ?string
  474.     {
  475.         return $this->eventName;
  476.     }
  477.     public function setEventName(?string $eventName): self
  478.     {
  479.         $this->eventName $eventName;
  480.         return $this;
  481.     }
  482.     public function getUsageCount(): ?int
  483.     {
  484.         return $this->usageCount;
  485.     }
  486.     public function setUsageCount(?int $usageCount): self
  487.     {
  488.         $this->usageCount $usageCount;
  489.         return $this;
  490.     }
  491.     public function getReusableVoucherRedeemAdminNotifyDate(): ?\DateTimeInterface
  492.     {
  493.         return $this->reusableVoucherRedeemAdminNotifyDate;
  494.     }
  495.     public function setReusableVoucherRedeemAdminNotifyDate(?\DateTimeInterface $reusableVoucherRedeemAdminNotifyDate): self
  496.     {
  497.         $this->reusableVoucherRedeemAdminNotifyDate $reusableVoucherRedeemAdminNotifyDate;
  498.         return $this;
  499.     }
  500.     public function getEmail(): ?string
  501.     {
  502.         return $this->email;
  503.     }
  504.     public function setEmail(?string $email): self
  505.     {
  506.         $this->email $email;
  507.         return $this;
  508.     }
  509.     public function getSentToEmail(): ?string
  510.     {
  511.         return $this->sentToEmail;
  512.     }
  513.     public function setSentToEmail(?string $sentToEmail): self
  514.     {
  515.         $this->sentToEmail $sentToEmail;
  516.         return $this;
  517.     }
  518.     public function getPhysicallyHandedOverTo(): ?string
  519.     {
  520.         return $this->physicallyHandedOverTo;
  521.     }
  522.     public function setPhysicallyHandedOverTo(?string $physicallyHandedOverTo): self
  523.     {
  524.         $this->physicallyHandedOverTo $physicallyHandedOverTo;
  525.         return $this;
  526.     }
  527. }